|
|
@@ -8,14 +8,20 @@ import com.xingxi.business.Carts.domain.Carts;
|
|
|
import com.xingxi.business.Carts.mapper.CartsMapper;
|
|
|
import com.xingxi.common.core.domain.entity.SysUser;
|
|
|
import com.xingxi.common.enums.EDelFlag;
|
|
|
+import com.xingxi.common.enums.ERoleKey;
|
|
|
import com.xingxi.common.enums.EYesNo;
|
|
|
+import com.xingxi.common.utils.DateUtils;
|
|
|
import com.xingxi.common.utils.StringUtils;
|
|
|
+import com.xingxi.master.product.domain.Prod;
|
|
|
+import com.xingxi.master.product.domain.ProdAttrPrice;
|
|
|
+import com.xingxi.master.product.mapper.ProdAttrPriceMapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -26,6 +32,8 @@ class CartsServiceImpl implements CartsServiceI {
|
|
|
|
|
|
@Autowired
|
|
|
CartsMapper cartsMapper;
|
|
|
+ @Autowired
|
|
|
+ ProdAttrPriceMapper prodAttrPriceMapper;
|
|
|
|
|
|
@Override
|
|
|
public CartsResponse add(UserContext userContext, CartsRequest request) {
|
|
|
@@ -69,26 +77,133 @@ class CartsServiceImpl implements CartsServiceI {
|
|
|
|
|
|
List<Carts> exiCarts = cartsMapper.selectCartsList(cond);
|
|
|
|
|
|
- return new CartsResponse(exiCarts);
|
|
|
+ BigDecimal sum = BigDecimal.ZERO;
|
|
|
+ for (Carts carts : exiCarts) {
|
|
|
+ ProdAttrPrice condPrice = new ProdAttrPrice();
|
|
|
+ condPrice.setProdAttrId(carts.getProdAttrId());
|
|
|
+ condPrice.setProdId(carts.getProdId());
|
|
|
+ condPrice.setBuyerRoleKey(ERoleKey.CUSTOMER.getCode());
|
|
|
+
|
|
|
+ List<ProdAttrPrice> priceList = prodAttrPriceMapper.selectProdAttrPriceList(condPrice);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(priceList)) {
|
|
|
+ if (carts.getCheckFlag().equals(EYesNo.YES.getVal())) {
|
|
|
+ sum = sum.add(new BigDecimal(carts.getQuantity()).multiply(priceList.get(0).getPrice()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new CartsResponse(exiCarts, sum.toPlainString());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CartsResponse checked(UserContext userContext, CartsRequest request) {
|
|
|
- return null;
|
|
|
+
|
|
|
+ SysUser currentUser = userContext.getCurrentUser();
|
|
|
+ Long userId = currentUser.getUserId();
|
|
|
+
|
|
|
+ Carts updCarts = cartsMapper.selectCartsById(request.getId());
|
|
|
+
|
|
|
+ updCarts.setCheckFlag(EYesNo.YES.getVal().equals(updCarts.getCheckFlag()) ? EYesNo.NO.getVal() : EYesNo.YES.getVal());
|
|
|
+ updCarts.setUpdateUser(userContext.getCurrentUser().getUserId().toString());
|
|
|
+ updCarts.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ cartsMapper.updateCarts(updCarts);
|
|
|
+
|
|
|
+ Carts cond = new Carts();
|
|
|
+ cond.setUserId(userId);
|
|
|
+ cond.setDelFlag(EDelFlag.NO.getVal());
|
|
|
+
|
|
|
+ List<Carts> exiCarts = cartsMapper.selectCartsList(cond);
|
|
|
+ BigDecimal sum = BigDecimal.ZERO;
|
|
|
+ for (Carts carts : exiCarts) {
|
|
|
+ ProdAttrPrice condPrice = new ProdAttrPrice();
|
|
|
+ condPrice.setProdAttrId(carts.getProdAttrId());
|
|
|
+ condPrice.setProdId(carts.getProdId());
|
|
|
+ condPrice.setBuyerRoleKey(ERoleKey.CUSTOMER.getCode());
|
|
|
+
|
|
|
+ List<ProdAttrPrice> priceList = prodAttrPriceMapper.selectProdAttrPriceList(condPrice);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(priceList)) {
|
|
|
+ if (carts.getCheckFlag().equals(EYesNo.YES.getVal())) {
|
|
|
+ sum = sum.add(new BigDecimal(carts.getQuantity()).multiply(priceList.get(0).getPrice()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return new CartsResponse(exiCarts, sum.toPlainString());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CartsResponse checkedAll(UserContext userContext, CartsRequest request) {
|
|
|
- return null;
|
|
|
+ SysUser currentUser = userContext.getCurrentUser();
|
|
|
+ Long userId = currentUser.getUserId();
|
|
|
+
|
|
|
+ Carts cond = new Carts();
|
|
|
+ cond.setUserId(userId);
|
|
|
+ cond.setDelFlag(EDelFlag.NO.getVal());
|
|
|
+
|
|
|
+ List<Carts> exiCarts = cartsMapper.selectCartsList(cond);
|
|
|
+ BigDecimal sum = BigDecimal.ZERO;
|
|
|
+ for (Carts carts : exiCarts) {
|
|
|
+ carts.setCheckFlag(EYesNo.YES.getVal());
|
|
|
+ carts.setUpdateUser(userContext.getCurrentUser().getUserId().toString());
|
|
|
+ carts.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ cartsMapper.updateCarts(carts);
|
|
|
+
|
|
|
+ ProdAttrPrice condPrice = new ProdAttrPrice();
|
|
|
+ condPrice.setProdAttrId(carts.getProdAttrId());
|
|
|
+ condPrice.setProdId(carts.getProdId());
|
|
|
+ condPrice.setBuyerRoleKey(ERoleKey.CUSTOMER.getCode());
|
|
|
+
|
|
|
+ List<ProdAttrPrice> priceList = prodAttrPriceMapper.selectProdAttrPriceList(condPrice);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(priceList)) {
|
|
|
+ sum = sum.add(new BigDecimal(carts.getQuantity()).multiply(priceList.get(0).getPrice()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return new CartsResponse(exiCarts, sum.toPlainString());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CartsResponse uncheckedAll(UserContext userContext, CartsRequest request) {
|
|
|
- return null;
|
|
|
+ SysUser currentUser = userContext.getCurrentUser();
|
|
|
+ Long userId = currentUser.getUserId();
|
|
|
+
|
|
|
+ Carts cond = new Carts();
|
|
|
+ cond.setUserId(userId);
|
|
|
+ cond.setDelFlag(EDelFlag.NO.getVal());
|
|
|
+
|
|
|
+ List<Carts> exiCarts = cartsMapper.selectCartsList(cond);
|
|
|
+ BigDecimal sum = BigDecimal.ZERO;
|
|
|
+ for (Carts carts : exiCarts) {
|
|
|
+ carts.setCheckFlag(EYesNo.YES.getVal());
|
|
|
+ carts.setUpdateUser(userContext.getCurrentUser().getUserId().toString());
|
|
|
+ carts.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ cartsMapper.updateCarts(carts);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new CartsResponse(exiCarts, sum.toPlainString());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CartsResponse delete(UserContext userContext, CartsRequest request) {
|
|
|
- return null;
|
|
|
+
|
|
|
+ SysUser currentUser = userContext.getCurrentUser();
|
|
|
+ Long userId = currentUser.getUserId();
|
|
|
+
|
|
|
+ cartsMapper.logicDeleteCartsById(request.getId());
|
|
|
+
|
|
|
+ Carts cond = new Carts();
|
|
|
+ cond.setUserId(userId);
|
|
|
+ List<Carts> exiCarts = cartsMapper.selectCartsList(cond);
|
|
|
+ BigDecimal sum = BigDecimal.ZERO;
|
|
|
+ for (Carts carts : exiCarts) {
|
|
|
+ carts.setCheckFlag(EYesNo.YES.getVal());
|
|
|
+ carts.setUpdateUser(userContext.getCurrentUser().getUserId().toString());
|
|
|
+ carts.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ cartsMapper.updateCarts(carts);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new CartsResponse(exiCarts, sum.toPlainString());
|
|
|
}
|
|
|
}
|