提交 5dc6e292 authored 作者: Whispa's avatar Whispa

improvements

上级 f24368a3
package com.example.afrishop_v3.config;
import org.apache.commons.beanutils.BeanUtilsBean;
import java.lang.reflect.InvocationTargetException;
public class NullAwareBeanUtilsBean extends BeanUtilsBean{
@Override
public void copyProperty(Object dest, String name, Object value)
throws IllegalAccessException, InvocationTargetException {
if(value==null)return;
super.copyProperty(dest, name, value);
}
}
......@@ -46,35 +46,111 @@ public class AuthController extends Controller {
private final TbCfCouponRepository couponRepository;
private final TbCfToicouponRepository toicouponRepository;
private final NetworkRepository networkRepository;
// @PersistenceContext(unitName = "afrishop_v3")
private final EntityManager entityManager;
// private final TbCfOrderRepository cfOrderRepository;
// private final SecondOrderRepository secondOrderRepository;
// private final SecondAddressRepository secondAddressRepository;
// private final SecondUserRepository secondUserRepository;
private final PasswordEncoder encoder;
private final DomainProperties domainProperties;
private final JwtUtils jwtUtils;
private static Logger logger = LoggerFactory.getLogger(AuthController.class);
public AuthController(AuthenticationManager authenticationManager, UserRepository userRepository, EmailHelper emailHelper, TbCfCouponRepository couponRepository, TbCfToicouponRepository toicouponRepository, NetworkRepository networkRepository, EntityManager entityManager, PasswordEncoder encoder, DomainProperties domainProperties, JwtUtils jwtUtils) {
public AuthController(DomainProperties domainProperties,PasswordEncoder encoder,JwtUtils jwtUtils,AuthenticationManager authenticationManager, UserRepository userRepository, EmailHelper emailHelper, TbCfCouponRepository couponRepository, TbCfToicouponRepository toicouponRepository, NetworkRepository networkRepository, EntityManager entityManager) {
this.authenticationManager = authenticationManager;
this.userRepository = userRepository;
this.emailHelper = emailHelper;
this.couponRepository = couponRepository;
this.toicouponRepository = toicouponRepository;
this.networkRepository = networkRepository;
this.entityManager = entityManager;
//this.secondAddressRepository = secondAddressRepository;
this.entityManager = entityManager;
this.encoder = encoder;
this.domainProperties = domainProperties;
this.jwtUtils = jwtUtils;
// this.cfOrderRepository = cfOrderRepository;
// this.secondOrderRepository = secondOrderRepository;
// this.secondUserRepository = secondUserRepository;
}
// @GetMapping("count")
// public Result count(){
//
// List<TbCfOrder> cfOrders = cfOrderRepository.findAll(PageRequest.of(0, 5)).toList();
// List<TbCfOrder2> cfOrders2 = secondOrderRepository.findAll(PageRequest.of(0, 5)).toList();
//
// LinkedHashMap<String, Object> hashMap = new LinkedHashMap<>();
//
// hashMap.put("orders",cfOrders);
// hashMap.put("orders2",cfOrders2);
//
// return new Result<>(hashMap);
// }
// private Result scanSecondDatabase(LoginRequest loginRequest) {
// Result<Object> notFound = new Result<>(ResultCodeEnum.VALIDATE_ERROR.getCode(), "User not found");
//
// Optional<TbCfUserInfo2> firstByAccount = secondUserRepository.findFirstByAccount(loginRequest.getAccount());
// if( firstByAccount.isPresent() ){
// TbCfUserInfo userInfo = new TbCfUserInfo();
// TbCfUserInfo2 userInfo2 = firstByAccount.get();
// String userId = userInfo.getUserId();
// BeanUtilsBean notNull=new NullAwareBeanUtilsBean();
// try {
// notNull.copyProperties(userInfo,userInfo2);
// } catch (InvocationTargetException | IllegalAccessException e) {
// System.out.println(e.getMessage());
// }
//
// List<TbCfOrder2> allByUserId = secondOrderRepository.findAllByUserId(userId);
//
// List<TbCfOrder> orderList = allByUserId.stream().map(v->{
// TbCfOrder tbCfOrder = new TbCfOrder();
// try {
// notNull.copyProperties(tbCfOrder,v);
// } catch (IllegalAccessException | InvocationTargetException e) {
// System.out.println(e.getMessage());
// }
// return tbCfOrder;
// }).collect(Collectors.toList());
//
// List<TbCfAddress2> addresses = secondAddressRepository.findAllByUserId(userId);
//
// List<TbCfAddress> collectAddresses = addresses.stream().map(v -> {
// TbCfAddress address = new TbCfAddress();
// try {
// notNull.copyProperties(address, v);
// } catch (IllegalAccessException | InvocationTargetException e) {
// System.out.println(e.getMessage());
// }
// return address;
// }).collect(Collectors.toList());
//
// LinkedHashMap<String, Object> hashMap = new LinkedHashMap<>();
//
// hashMap.put("addresses",collectAddresses);
// hashMap.put("orders",orderList);
// hashMap.put("user",userInfo);
//
// return new Result<>(hashMap);
//
// }
//
// return notFound;
// }
//Sign in using email/phone and password
@PostMapping("/signin")
public Result authenticateUser(@RequestBody LoginRequest loginRequest) {
Optional<TbCfUserInfo> byAccount = userRepository.findFirstByAccount(loginRequest.getAccount());
Optional<TbCfUserInfo> byAccount = userRepository.findFirstByAccount(loginRequest.getAccount());
Result<Object> notFound = new Result<>(ResultCodeEnum.VALIDATE_ERROR.getCode(), "User not found");
if (!byAccount.isPresent()) {
//
// boolean b = userRepository.existsByAccount(loginRequest.getAccount());
......
......@@ -10,6 +10,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.math.BigDecimal;
import java.math.RoundingMode;
......@@ -25,11 +26,15 @@ public class BonusController extends Controller {
private final UserRepository userRepository;
private final PostRepository postRepository;
private final NetworkRepository networkRepository;
// @PersistenceContext(unitName = "afrishop_v3")
private final EntityManager entityManager;
private final AuthenticationUser user;
private final TbCfOrderRepository orderRepository;
public BonusController(BonusRepository repository, TbCfStationItemRepository itemRepository, UserRepository userRepository, PostRepository postRepository, NetworkRepository networkRepository, EntityManager entityManager, AuthenticationUser user, TbCfOrderRepository orderRepository) {
public BonusController(BonusRepository repository, TbCfStationItemRepository itemRepository, UserRepository userRepository, PostRepository postRepository, NetworkRepository networkRepository, AuthenticationUser user, TbCfOrderRepository orderRepository,EntityManager entityManager) {
this.repository = repository;
this.itemRepository = itemRepository;
this.userRepository = userRepository;
......@@ -114,7 +119,7 @@ public class BonusController extends Controller {
nativeQuery.setParameter("year", year);
List<Bonus> bonuses = repository.findAllByUser_IdAndCreateDateMonthAndCreateDateYear(byId.get(), month, year, PageRequest.of(pageNo, pageSize)).toList();
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("total", BigDecimal.valueOf((double)nativeQuery.getSingleResult()).setScale(3,RoundingMode.HALF_UP));
hashMap.put("total", BigDecimal.valueOf((double)nativeQuery.getSingleResult()).setScale(3,RoundingMode.HALF_UP));
hashMap.put("list", bonuses);
return hashMap;
}
......
......@@ -9,15 +9,18 @@ import com.example.afrishop_v3.repository.TbCfExpressTemplateRepository;
import com.example.afrishop_v3.repository.TbCfItemSkuRepository;
import com.example.afrishop_v3.repository.TbCfStationItemRepository;
import com.example.afrishop_v3.security.services.AuthenticationUser;
import com.example.afrishop_v3.service.SpiderService;
import com.example.afrishop_v3.util.ValidateUtils;
import com.example.afrishop_v3.util.WordposHelper;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.relational.core.sql.In;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URISyntaxException;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
......@@ -30,13 +33,16 @@ public class CartController extends Controller {
private final TbCfExpressTemplateRepository templateRepository;
private final TbCfItemSkuRepository itemSkuRepository;
private final AuthenticationUser user;
private final SpiderService spiderService;
private static Logger logger = LoggerFactory.getLogger(CartController.class);
public CartController(TbCfCartRecordRRepository repository, TbCfStationItemRepository itemRepository, TbCfExpressTemplateRepository templateRepository, TbCfItemSkuRepository itemSkuRepository, AuthenticationUser user) {
public CartController(TbCfCartRecordRRepository repository, TbCfStationItemRepository itemRepository, TbCfExpressTemplateRepository templateRepository, TbCfItemSkuRepository itemSkuRepository, AuthenticationUser user, SpiderService spiderService) {
this.repository = repository;
this.itemRepository = itemRepository;
this.templateRepository = templateRepository;
this.itemSkuRepository = itemSkuRepository;
this.user = user;
this.spiderService = spiderService;
}
//Change number of the cart item
......@@ -77,21 +83,50 @@ public class CartController extends Controller {
String itemSkuId = itemDetail.getItemSkuId();
if (itemSkuId == null)
return new Result(ResultCodeEnum.SERVICE_ERROR.getCode(), "Item sku not found");
String targetUrl = itemDetail.getTargetUrl();
Result skuNotFound = new Result(ResultCodeEnum.SERVICE_ERROR.getCode(), "Item sku not found");
if (itemSkuId == null && targetUrl == null)
return skuNotFound;
Optional<TbCfItemSkus> skuOptional = itemSkuRepository.findById(itemSkuId);
BigDecimal price = null;
if (!skuOptional.isPresent())
return new Result(ResultCodeEnum.SERVICE_ERROR.getCode(), "Item sku not found");
if(itemSkuId != null) {
BigDecimal price = skuOptional.get().getSkuPrice();
Optional<TbCfItemSkus> skuOptional = itemSkuRepository.findById(itemSkuId);
if (!skuOptional.isPresent()) {
return skuNotFound;
}
price = skuOptional.get().getSkuPrice();
}
if (targetUrl != null && itemSkuId == null){
try {
JSONObject detail = spiderService.getItemDetail(targetUrl);
JSONObject data = detail.getJSONObject("data");
if( data != null ){
JSONArray priceList = data.getJSONArray("originalPriceList");
if( priceList.isEmpty() ){
return skuNotFound;
}else
price = BigDecimal.valueOf(priceList.getJSONObject(0).getDouble("price"));
}else {
return skuNotFound;
}
} catch (InterruptedException | IOException | ExecutionException | URISyntaxException | TimeoutException e) {
logger.debug(e.getMessage());
return skuNotFound;
}
}
if (price == null || price.compareTo(BigDecimal.ZERO) <= 0) {
return new Result(ResultCodeEnum.SERVICE_ERROR.getCode(), "The price of the goods is incorrect");
String s = "The price of the goods is incorrect";
logger.debug(s);
return new Result(ResultCodeEnum.SERVICE_ERROR.getCode(), s);
}
itemDetail.setItemPrice(price);
Optional<TbCfCartRecordR> optionalItem;
......
......@@ -380,7 +380,7 @@ public class FlutterWaveController extends Controller {
return new Result(ResultCodeEnum.VALIDATE_ERROR.getCode(), "Invalid order status");
}
if (bonusRepository.existsByOrderId(orderId)) {
if (bonusRepository.existsByOrderId(order.getOrderId())) {
return new Result(ResultCodeEnum.VALIDATE_ERROR.getCode(), "Transaction already done !!!");
}
......
......@@ -20,12 +20,10 @@ import java.util.stream.Collectors;
public class NetworkController {
private final NetworkRepository repository;
private final UserRepository userRepository;
private final EntityManager manager;
public NetworkController(NetworkRepository repository, UserRepository userRepository, EntityManager manager) {
public NetworkController(NetworkRepository repository, UserRepository userRepository) {
this.repository = repository;
this.userRepository = userRepository;
this.manager = manager;
}
......
......@@ -28,8 +28,11 @@ import java.util.concurrent.TimeoutException;
@RequestMapping("/spider")
public class SpiderController {
@Autowired
private SpiderService spiderService;
private final SpiderService spiderService;
public SpiderController(SpiderService spiderService) {
this.spiderService = spiderService;
}
@PostMapping("/item/detail")
public Result getItemDetail(@RequestBody DetailParamVo detailParamVo) throws InterruptedException, ExecutionException, URISyntaxException, IOException, TimeoutException {
......
......@@ -88,6 +88,8 @@ public class TbCfCartRecordR {
private BigDecimal itemPrice;
private String itemSkuId;
@Transient
private String targetUrl;
@Formula(value = "(SELECT st.discount_price FROM tb_cf_station_item st WHERE st.item_id=item_id limit 1)")
private BigDecimal realItemPrice;
......@@ -125,6 +127,10 @@ public class TbCfCartRecordR {
this.itemPrice = itemPrice;
}
public String getTargetUrl() {
return targetUrl;
}
/**
* 设置:购物车记录id
*/
......
......@@ -25,6 +25,7 @@ import java.util.stream.Collectors;
*/
@Entity
@Data
@Table(name = "tb_cf_order")
@Where(clause = "enable_flag = 1")
public class TbCfOrder {
......
......@@ -4,12 +4,15 @@ import com.example.afrishop_v3.inter_face.OrderCount;
import com.example.afrishop_v3.models.TbCfItemOrderR;
import com.example.afrishop_v3.models.TbCfOrder;
import com.example.afrishop_v3.models.TbCfUserInfo;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
......@@ -35,4 +38,6 @@ public interface TbCfOrderRepository extends PagingAndSortingRepository<TbCfOrde
@Query(value = "SELECT t1.*,t2.order_item_id ordersId,t2.order_status orderStatus,t2.item_num itemNum FROM tb_cf_item_detail t1 LEFT JOIN tb_cf_item_order_r t2 ON t1.item_id = t2.item_id LEFT JOIN tb_cf_order t3 ON t2.order_id = t3.order_id WHERE t2.enable_flag = 1 AND t2.order_id =:orderId",nativeQuery = true)
List getAllByItemList(String orderId);
}
......@@ -30,11 +30,14 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
// jsr250Enabled = true,
prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
UserDetailsServiceImpl userDetailsService;
private final UserDetailsServiceImpl userDetailsService;
@Autowired
private AuthEntryPointJwt unauthorizedHandler;
private final AuthEntryPointJwt unauthorizedHandler;
public WebSecurityConfig(UserDetailsServiceImpl userDetailsService, AuthEntryPointJwt unauthorizedHandler) {
this.userDetailsService = userDetailsService;
this.unauthorizedHandler = unauthorizedHandler;
}
@Bean
public AuthTokenFilter authenticationJwtTokenFilter() {
......@@ -66,7 +69,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests().antMatchers("/api/auth/**", "/search/image/**", "/itemStation/**", "/startPage/**",
"/goodsType/**", "/home/**", "/spider/**", "/store/**", "/shopify/**", "/community/**", "/version/**",
"/flutterwave/notify/**", "/dpo/notify/**", "/advertisement/**", "/website/**","/paypal/**","/discover/bonus/**","/problem/**","/cube/**").permitAll()
"/flutterwave/notify/**", "/dpo/notify/**", "/advertisement/**", "/website/**", "/paypal/**", "/discover/bonus/**", "/problem/**", "/cube/**").permitAll()
.antMatchers("/api/test/**").permitAll()
.anyRequest().authenticated();
......
......@@ -5,10 +5,15 @@ server:
spring:
datasource:
url: jdbc:mysql://159.138.48.71:3306/test?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
url: jdbc:mysql://159.138.48.71:3306/chinafrica_ref?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
username: root
driver-class-name: com.mysql.cj.jdbc.Driver
password: Diaoyunnuli.8
secondsource:
url: jdbc:mysql://165.22.82.105:3306/chinafrica?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
username: root
driver-class-name: com.mysql.cj.jdbc.Driver
password: clement123
redis:
#Redis数据库分片索引(默认为0)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论