소스 검색

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

zouxuan 5 년 전
부모
커밋
02dba91c25

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -16,6 +16,8 @@ import java.util.List;
 
 public interface GoodsService extends BaseService<Integer, Goods> {
 
+    void addGoods(Goods goods, Integer operatorId);
+
     void addGoodsProcurement(Goods goods, Integer operatorId);
 
     /**

+ 59 - 23
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -2,18 +2,14 @@ package com.ym.mec.biz.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.ym.mec.auth.api.client.SysUserFeignService;
-import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.BasicUserDto;
-import com.ym.mec.biz.dal.dto.GoodsBatchNoDto;
 import com.ym.mec.biz.dal.dto.GoodsSellDto;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.GoodsProcurement;
 import com.ym.mec.biz.dal.entity.SellOrder;
 import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.service.GoodsService;
-import com.ym.mec.biz.service.SellOrderService;
 import com.ym.mec.biz.service.SysMessageService;
 import com.ym.mec.biz.service.UploadFileService;
 import com.ym.mec.common.dal.BaseDAO;
@@ -24,7 +20,6 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.excel.IniFileUtil;
 import com.ym.mec.util.excel.POIUtil;
-import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.usermodel.PictureData;
 import org.slf4j.Logger;
@@ -71,8 +66,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	}
 
 	@Override
-	@Transactional(rollbackFor = Exception.class)
-	public void addGoodsProcurement(Goods goods, Integer operatorId) {
+	public void addGoods(Goods goods, Integer operatorId) {
 		Goods existsGood = goodsDao.findBySn(goods.getSn());
 		if(Objects.nonNull(existsGood)){
 			if(Objects.nonNull(existsGood.getComplementGoodsIdList())){
@@ -80,26 +74,56 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 			}
 			existsGood.setStockCount(existsGood.getStockCount()+goods.getStockCount());
 			existsGood.setTaxStockCount(existsGood.getTaxStockCount()+existsGood.getTaxStockCount());
+			existsGood.setSellCount(0);
 			goodsDao.update(existsGood);
 		}else{
+			if(Objects.isNull(goods.getStockCount())){
+				goods.setStockCount(0);
+			}
+			if(Objects.isNull(goods.getTaxStockCount())){
+				goods.setTaxStockCount(0);
+			}
+			goods.setSellCount(0);
 			goodsDao.insert(goods);
-			existsGood=goods;
 		}
+	}
 
-		if(StringUtils.isBlank(existsGood.getComplementGoodsIdList())){
-			String batchNo = idGeneratorService.generatorId("payment") + "";
-			GoodsProcurement gp = new GoodsProcurement();
-			gp.setGoodsId(existsGood.getId());
-			gp.setGoodsCategoryId(goods.getGoodsCategoryId());
-			gp.setSupplyChannel(goods.getSupplyChannel());
-			gp.setDiscountPrice(goods.getDiscountPrice());
-			gp.setAgreeCostPrice(goods.getAgreeCostPrice());
-			gp.setStockCount(goods.getStockCount());
-			gp.setTaxStockCount(goods.getTaxStockCount());
-			gp.setOperatorId(operatorId);
-			gp.setBatchNo(batchNo);
-			goodsProcurementDao.insert(gp);
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void addGoodsProcurement(Goods goods, Integer operatorId) {
+		Goods existsGood = goodsDao.findBySn(goods.getSn());
+
+		if(Objects.isNull(existsGood)){
+			throw new BizException("商品不存在");
+		}
+
+		if(StringUtils.isNotBlank(existsGood.getComplementGoodsIdList())){
+			throw new BizException("此商品为组合商品");
+		}
+
+		if(Objects.isNull(goods.getStockCount())){
+			goods.setStockCount(0);
+		}
+		if(Objects.isNull(goods.getTaxStockCount())){
+			goods.setTaxStockCount(0);
 		}
+
+		existsGood.setStockCount(existsGood.getStockCount()+goods.getStockCount());
+		existsGood.setTaxStockCount(existsGood.getTaxStockCount()+existsGood.getTaxStockCount());
+		goodsDao.update(existsGood);
+
+		String batchNo = idGeneratorService.generatorId("payment") + "";
+		GoodsProcurement gp = new GoodsProcurement();
+		gp.setGoodsId(existsGood.getId());
+		gp.setGoodsCategoryId(goods.getGoodsCategoryId());
+		gp.setSupplyChannel(goods.getSupplyChannel());
+		gp.setDiscountPrice(goods.getDiscountPrice());
+		gp.setAgreeCostPrice(goods.getAgreeCostPrice());
+		gp.setStockCount(goods.getStockCount());
+		gp.setTaxStockCount(goods.getTaxStockCount());
+		gp.setOperatorId(operatorId);
+		gp.setBatchNo(batchNo);
+		goodsProcurementDao.insert(gp);
 	}
 
 	@Override
@@ -410,7 +434,13 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 					sellOrder.setAccountType(accountType);
 					sellOrder.setBatchNo(batchNoGoodsIdMapEntry.getKey());
 					GoodsProcurement goodsProcurement = goodsProcurementDao.getWithGoodsAndBatchNo(sellOrder.getGoodsId(), sellOrder.getBatchNo());
-					sellOrder.setSellCost(goodsProcurement.getDiscountPrice().multiply(new BigDecimal(sellOrder.getNum())));
+					sellOrder.setSellCost(goodsProcurement.getDiscountPrice());
+					Map<String, BigDecimal> CostMap = new HashMap<>();
+					CostMap.put("sellCost", goodsProcurement.getDiscountPrice());
+					if (Objects.nonNull(goodsProcurement.getAgreeCostPrice())) {
+						CostMap.put("SellCost2", goodsProcurement.getAgreeCostPrice());
+					}
+					sellOrder.setSellCost2(JSON.toJSONString(CostMap));
 					sellOrders.add(sellOrder);
 				}
 			}
@@ -428,7 +458,13 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 				sellOrder.setAccountType(accountType);
 				sellOrder.setBatchNo(goodsProcurement.getBatchNo());
 				if(Objects.nonNull(goodsProcurement.getBatchNo())){
-					sellOrder.setSellCost(goodsProcurement.getDiscountPrice().multiply(new BigDecimal(sellOrder.getNum())));
+					sellOrder.setSellCost(goodsProcurement.getDiscountPrice());
+					Map<String, BigDecimal> CostMap = new HashMap<>();
+					CostMap.put("sellCost", goodsProcurement.getDiscountPrice());
+					if (Objects.nonNull(goodsProcurement.getAgreeCostPrice())) {
+						CostMap.put("SellCost2", goodsProcurement.getAgreeCostPrice());
+					}
+					sellOrder.setSellCost2(JSON.toJSONString(CostMap));
 				}
 				sellOrders.add(sellOrder);
 			}

+ 50 - 36
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentRouteOrderServiceImpl.java

@@ -10,18 +10,21 @@ import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
 import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
+import com.ym.mec.biz.service.GoodsService;
 import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.collection.MapUtil;
+import org.apache.ibatis.javassist.expr.NewArray;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentRouteOrder> implements StudentPaymentRouteOrderService {
@@ -38,6 +41,8 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     private SellOrderDao sellOrderDao;
     @Autowired
     private GoodsDao goodsDao;
+    @Autowired
+    private GoodsService goodsService;
 
     @Override
     public BaseDAO<Long, StudentPaymentRouteOrder> getDAO() {
@@ -107,10 +112,15 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
             BigDecimal hasRouteAmount = BigDecimal.ZERO;
             BigDecimal goodsTotalPrice = BigDecimal.ZERO;
 
+            List<Integer> goodsIdList = new ArrayList<>();
             for (Map.Entry<Integer, Integer> goodsMap : studentPaymentRouteOrderDto.getGoodies().entrySet()) {
                 Goods goods = goodsDao.get(goodsMap.getKey());
                 goodsTotalPrice = goodsTotalPrice.add(goods.getGroupPurchasePrice().multiply(new BigDecimal(goodsMap.getValue())));
+                for (int i = 0; i < goodsMap.getValue(); i++) {
+                    goodsIdList.add(goodsMap.getKey());
+                }
             }
+            List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIdList, AccountType.INTERNAL);
 
             int i = 1;
             for (Map.Entry<Integer, Integer> goodsMap : studentPaymentRouteOrderDto.getGoodies().entrySet()) {
@@ -126,45 +136,49 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
                 hasRouteAmount = hasRouteAmount.add(actualAmount);
                 i++;
 
-                Map<String, BigDecimal> CostMap = new HashMap<>();
-                CostMap.put("sellCost", goods.getDiscountPrice());
-                if (goods.getAgreeCostPrice() != null) {
-                    CostMap.put("SellCost2", goods.getAgreeCostPrice());
+                int complementNum = goods.getComplementGoodsIdList() == null ? 1 : goods.getComplementGoodsIdList().split(",").length;
+                int goodsNum = goodsMap.getValue() * complementNum;
+                BigDecimal complementPrice = goods.getGroupPurchasePrice().multiply(new BigDecimal(goodsMap.getValue()));
+                Map<Integer, BigDecimal> complementGoodsPrice = new HashMap<>();
+                complementGoodsPrice.put(goods.getId(), goods.getGroupPurchasePrice());
+                if (goods.getComplementGoodsIdList() != null) {
+                    List<Goods> complementGoodies = goodsDao.findGoodsByIds(goods.getComplementGoodsIdList());
+                    complementGoodsPrice = complementGoodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getGroupPurchasePrice));
+                    complementPrice = complementGoodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add).multiply(new BigDecimal(goodsMap.getValue()));
                 }
 
-                SellOrder sellOrder = new SellOrder();
-                sellOrder.setSellTime(studentPaymentRouteOrderDto.getPayTime());
-                sellOrder.setOrganId(studentPaymentRouteOrderDto.getOrganId());
-                sellOrder.setCooperationOrganId(studentPaymentRouteOrderDto.getSchoolId());
-                sellOrder.setTransNo(studentPaymentRouteOrderDto.getTransNo());
-                sellOrder.setOrderId(studentPaymentRouteOrderDto.getId());
-                sellOrder.setOrderNo(orderNo);
-                sellOrder.setGoodsId(goods.getId());
-                sellOrder.setGoodsName(goods.getName());
-                sellOrder.setActualAmount(actualAmount);
-                sellOrder.setBalanceAmount(BigDecimal.ZERO);
-                sellOrder.setExpectAmount(actualAmount);
-                sellOrder.setSellCost(goods.getDiscountPrice());
-                sellOrder.setSellCost2(JSON.toJSONString(CostMap));
-                sellOrder.setNum(goodsMap.getValue());
-                sellOrder.setUserId(studentPaymentRouteOrderDto.getUserId());
-                sellOrder.setPaymentChannel(studentPaymentRouteOrderDto.getPaymentChannel());
-                sellOrder.setMerNo(studentPaymentRouteOrderDto.getMerNos());
-                sellOrder.setAccountType(AccountType.INTERNAL);
-                sellOrder.setSellTime(studentPaymentRouteOrderDto.getCreateTime());
-                sellOrder.setCreateIme(nowDate);
-                sellOrder.setUpdateTime(nowDate);
-                sellOrder.setType(SellTypeEnum.SCHOOL_BUY);
-
-                //库存类型
-                if(goods.getStockType().equals(StockType.ALL)){
-                    sellOrder.setStockType(StockType.INTERNAL);
-                }else {
-                    sellOrder.setStockType(goods.getStockType());
+                BigDecimal hasRouteSellOrderActualAmount = BigDecimal.ZERO;
+                for (SellOrder sellOrder : sellOrderList) {
+                    if (!goodsMap.getKey().equals(sellOrder.getParentGoodsId()) && !goodsMap.getKey().equals(sellOrder.getParentGoodsId())) {
+                        continue;
+                    }
+                    BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
+                    if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
+                        sellOrderActualAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(actualAmount).divide(complementPrice, 2, BigDecimal.ROUND_HALF_UP);
+                    }
+                    hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
+                    goodsNum = goodsNum - sellOrder.getNum();
+                    if (goodsNum <= 0) {
+                        sellOrderActualAmount = actualAmount.subtract(hasRouteSellOrderActualAmount);
+                    }
+                    sellOrder.setSellTime(studentPaymentRouteOrderDto.getPayTime());
+                    sellOrder.setOrganId(studentPaymentRouteOrderDto.getOrganId());
+                    sellOrder.setCooperationOrganId(studentPaymentRouteOrderDto.getSchoolId());
+                    sellOrder.setTransNo(studentPaymentRouteOrderDto.getTransNo());
+                    sellOrder.setOrderId(studentPaymentRouteOrderDto.getId());
+                    sellOrder.setOrderNo(orderNo);
+                    sellOrder.setActualAmount(sellOrderActualAmount);
+                    sellOrder.setBalanceAmount(BigDecimal.ZERO);
+                    sellOrder.setExpectAmount(sellOrderActualAmount);
+                    sellOrder.setUserId(studentPaymentRouteOrderDto.getUserId());
+                    sellOrder.setPaymentChannel(studentPaymentRouteOrderDto.getPaymentChannel());
+                    sellOrder.setMerNo(studentPaymentRouteOrderDto.getMerNos());
+                    sellOrder.setSellTime(studentPaymentRouteOrderDto.getCreateTime());
+                    sellOrder.setCreateIme(nowDate);
+                    sellOrder.setUpdateTime(nowDate);
+                    sellOrder.setType(SellTypeEnum.SCHOOL_BUY);
+                    sellOrders.add(sellOrder);
                 }
-                //批次号 TODO
-
-                sellOrders.add(sellOrder);
             }
             sellOrderDao.batchInsert(sellOrders);
         }

+ 12 - 0
mec-web/src/main/java/com/ym/mec/web/controller/GoodsController.java

@@ -42,6 +42,18 @@ public class GoodsController extends BaseController {
         return succeed();
     }
 
+    @ApiOperation(value = "新增商品清单")
+    @PostMapping("/addGoodsProcurement")
+    @PreAuthorize("@pcs.hasPermissions('goods/addGoodsProcurement')")
+    public Object addGoodsProcurement(Goods goods){
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null) {
+            return failed("用户信息获取失败");
+        }
+        goodsService.addGoodsProcurement(goods,sysUser.getId());
+        return succeed();
+    }
+
     @ApiOperation(value = "删除商品(教材、辅件)")
     @PostMapping("/del/{id}")
     @PreAuthorize("@pcs.hasPermissions('goods/del')")