Selaa lähdekoodia

Merge remote-tracking branch 'origin/master'

周箭河 5 vuotta sitten
vanhempi
commit
0762adca40

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/GoodsDao.java

@@ -45,7 +45,7 @@ public interface GoodsDao extends BaseDAO<Integer, Goods> {
      * @date 2020/9/4
      * @time 14:39
      */
-    void batchInsert(@Param("goodsList") List<Goods> goodsList);
+    void batchInsert(List<Goods> goodsList);
 
     /**
      * @describe 批量更新商品

+ 3 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -16,7 +16,9 @@ import java.util.List;
 
 public interface GoodsService extends BaseService<Integer, Goods> {
 
-    void addGoodsProcurement(Goods goods, Integer operatorId);
+    void addGoods(Goods goods, Integer operatorId);
+
+    void addGoodsProcurement(GoodsProcurement goodsProcurement);
 
     /**
      * @describe 更新商品状态

+ 70 - 18
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,17 +66,10 @@ 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())){
-				throw new BizException("此货号组合商品已存在");
-			}
-			existsGood.setStockCount(existsGood.getStockCount()+goods.getStockCount());
-			existsGood.setTaxStockCount(existsGood.getTaxStockCount()+existsGood.getTaxStockCount());
-			existsGood.setSellCount(0);
-			goodsDao.update(existsGood);
+			throw new BizException("商品货号重复");
 		}else{
 			if(Objects.isNull(goods.getStockCount())){
 				goods.setStockCount(0);
@@ -95,6 +83,37 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	}
 
 	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void addGoodsProcurement(GoodsProcurement goodsProcurement) {
+		Goods existsGood = goodsDao.get(goodsProcurement.getGoodsId());
+
+		if(Objects.isNull(existsGood)){
+			throw new BizException("商品不存在");
+		}
+
+		if(StringUtils.isNotBlank(existsGood.getComplementGoodsIdList())){
+			throw new BizException("此商品为组合商品");
+		}
+
+		if(Objects.isNull(goodsProcurement.getStockCount())){
+			goodsProcurement.setStockCount(0);
+		}
+		if(Objects.isNull(goodsProcurement.getTaxStockCount())){
+			goodsProcurement.setTaxStockCount(0);
+		}
+
+		existsGood.setStockCount(existsGood.getStockCount()+goodsProcurement.getStockCount());
+		existsGood.setTaxStockCount(existsGood.getTaxStockCount()+goodsProcurement.getTaxStockCount());
+		goodsDao.update(existsGood);
+
+		String batchNo = idGeneratorService.generatorId("payment") + "";
+		goodsProcurement.setBatchNo(batchNo);
+		goodsProcurementDao.insert(goodsProcurement);
+
+		sellOrderBatchNoAllot();
+	}
+
+	@Override
 	public void updateGoodsStatus(Integer goodsId, Integer status) {
 		if(Objects.isNull(goodsId)){
 			throw new BizException("请指定商品");
@@ -231,6 +250,40 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 			int taxStockCount = goods.stream().mapToInt(Goods::getTaxStockCount).sum();
 			existsGood.setStockCount((Objects.isNull(existsGood.getStockCount())?0:existsGood.getStockCount()) + stockCount);
 			existsGood.setTaxStockCount((Objects.isNull(existsGood.getTaxStockCount())?0:existsGood.getTaxStockCount()) + taxStockCount);
+			Goods newGoods = goods.get(0);
+			if(Objects.nonNull(newGoods.getGoodsCategoryId())&&!newGoods.getGoodsCategoryId().equals(existsGood.getGoodsCategoryId())){
+				existsGood.setGoodsCategoryId(newGoods.getGoodsCategoryId());
+			}
+			if(Objects.nonNull(newGoods.getName())&&!newGoods.getName().equals(existsGood.getName())){
+				existsGood.setName(newGoods.getName());
+			}
+			if(Objects.nonNull(newGoods.getType())&&!newGoods.getType().equals(existsGood.getType())){
+				existsGood.setType(newGoods.getType());
+			}
+			if(Objects.nonNull(newGoods.getSpecification())&&!newGoods.getSpecification().equals(existsGood.getSpecification())){
+				existsGood.setSpecification(newGoods.getSpecification());
+			}
+			if(Objects.nonNull(newGoods.getMarketPrice())&&!newGoods.getMarketPrice().equals(existsGood.getMarketPrice())){
+				existsGood.setMarketPrice(newGoods.getMarketPrice());
+			}
+			if(Objects.nonNull(newGoods.getDiscountPrice())&&!newGoods.getDiscountPrice().equals(existsGood.getDiscountPrice())){
+				existsGood.setDiscountPrice(newGoods.getDiscountPrice());
+			}
+			if(Objects.nonNull(newGoods.getGroupPurchasePrice())&&!newGoods.getGroupPurchasePrice().equals(existsGood.getGroupPurchasePrice())){
+				existsGood.setGroupPurchasePrice(newGoods.getGroupPurchasePrice());
+			}
+			if(Objects.nonNull(newGoods.getImage())&&!newGoods.getImage().equals(existsGood.getImage())){
+				existsGood.setImage(newGoods.getImage());
+			}
+			if(Objects.nonNull(newGoods.getStockType())&&!newGoods.getStockType().equals(existsGood.getStockType())){
+				existsGood.setStockType(newGoods.getStockType());
+			}
+			if(Objects.nonNull(newGoods.getBrief())&&!newGoods.getBrief().equals(existsGood.getBrief())){
+				existsGood.setBrief(newGoods.getBrief());
+			}
+			if(Objects.nonNull(newGoods.getStockWarning())&&!newGoods.getStockWarning().equals(existsGood.getStockWarning())){
+				existsGood.setStockWarning(newGoods.getStockWarning());
+			}
 		}
 
 		if(!CollectionUtils.isEmpty(existsGoods)){
@@ -252,8 +305,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 			gp.setGoodsId(existsSnIdMap.get(goods.getSn()));
 			gp.setGoodsCategoryId(goods.getGoodsCategoryId());
 			gp.setSupplyChannel(goods.getSupplyChannel());
-			gp.setDiscountPrice(goods.getCostPrice()
-			);
+			gp.setDiscountPrice(goods.getCostPrice());
 			gp.setAgreeCostPrice(goods.getAgreeCostPrice());
 			gp.setStockCount(goods.getStockCount());
 			gp.setTaxStockCount(goods.getTaxStockCount());
@@ -402,7 +454,7 @@ 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())) {
@@ -426,7 +478,7 @@ 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())) {

+ 13 - 7
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -7,7 +7,6 @@ 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.dto.RepairGoodsDto;
 import com.ym.mec.biz.dal.entity.*;
@@ -258,12 +257,15 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         StudentGoodsSell studentGoodsSell = studentGoodsSellDao.get(goodsSellId);
         Integer studentId = studentGoodsSell.getUserId();
         studentDao.lockUser(studentId);
-//        SysUser student = sysUserFeignService.queryUserById(studentId);
         List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(studentGoodsSell.getGoodsJson(),GoodsSellDto.class);
         List<Integer> goodsIds = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
-
-        Map<Integer, BigDecimal> map = getMap("goods", "id_", "market_price_", goodsIds, Integer.class, BigDecimal.class);
+        Map<Integer, String> integerStringMap = getMap("goods", "id_", "type_", goodsIds, Integer.class, String.class);
+        Map<Integer, BigDecimal> map = getMap("goods", "id_", "discount_price_", goodsIds, Integer.class, BigDecimal.class);
         for (GoodsSellDto goodsSellDto : goodsSellDtos) {
+            goodsSellDto.setGoodsType(integerStringMap.get(goodsSellDto.getGoodsId()));
+            if(StringUtils.isNotEmpty(goodsSellDto.getComplementGoodsIdList())){
+                goodsSellDto.setGoodsSellDtos(goodsService.queryGoodsSellDtos(goodsSellDto.getComplementGoodsIdList()));
+            }
             goodsSellDto.setGoodsPrice(map.get(goodsSellDto.getGoodsId()));
             goodsSellDto.setTotalGoodsPrice(map.get(goodsSellDto.getGoodsId()).multiply(new BigDecimal(goodsSellDto.getGoodsNum())));
         }
@@ -772,6 +774,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         Map<Integer,BigDecimal> parentGoodsCutTotalPriceMap = new HashMap<>();
         //组合商品附加金额
         Map<Integer,BigDecimal> parentGoodsAddTotalPriceMap = new HashMap<>();
+        //组合商品实际总价
+        Map<Integer,BigDecimal> parentGoodsTotalPriceMap = new HashMap<>();
         //应付总额
         BigDecimal totalActual = totalAmount.subtract(marketAmount);
         //可用应付
@@ -800,6 +804,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             for (GoodsSellDto sellDto : goodsSellDto.getGoodsSellDtos()) {
                 totalGoodsPrice = totalGoodsPrice.add(sellDto.getTotalGoodsPrice());
             }
+            parentGoodsTotalPriceMap.put(sellOrder.getParentGoodsId(),totalGoodsPrice);
             //如果组合价大于预计总价
             if (parentTotalGoodsPrice.compareTo(totalGoodsPrice) == 1){
                 parentGoodsAddTotalPriceMap.put(sellOrder.getParentGoodsId(),parentTotalGoodsPrice.subtract(totalGoodsPrice));
@@ -817,18 +822,19 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 
             //获取组合商品销售总价
             GoodsSellDto goodsSellDto = collect.get(parentGoodsId).get(0);
-            BigDecimal divide = goodsSellDto.getGoodsPrice();
+//            BigDecimal divide = goodsSellDto.getGoodsPrice();
 
             //获取子商品明细map
             List<GoodsSellDto> sellDtos = goodsSellDto.getGoodsSellDtos();
             Map<Integer, List<GoodsSellDto>> subGoodsMap = sellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
             List<Integer> integers = new ArrayList<>(subGoodsMap.keySet());
+            BigDecimal divide = parentGoodsTotalPriceMap.get(parentGoodsId);
             for (int i = 0; i < integers.size(); i++) {
                 GoodsSellDto sellDto = subGoodsMap.get(integers.get(i)).get(0);
                 //获取比例
                 BigDecimal ratioAmount = sellDto.getTotalGoodsPrice().divide(divide, 6, BigDecimal.ROUND_HALF_UP);
 
-                if(addTotalPrice.doubleValue() > 0l){
+                if(addTotalPrice != null && addTotalPrice.doubleValue() > 0l){
                     //如果是最后一件商品
                     if(i == integers.size() - 1){
                         sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().add(usableParentGoodsAddTotalPrice));
@@ -839,7 +845,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                         usableParentGoodsAddTotalPrice = usableParentGoodsAddTotalPrice.subtract(multiply);
                     }
                     sellDto.setGoodsPrice(sellDto.getTotalGoodsPrice());
-                }else if(cutTotalPrice.doubleValue() > 0l){
+                }else if(cutTotalPrice != null && cutTotalPrice.doubleValue() > 0l){
                     //如果是最后一件商品
                     if(i == integers.size() - 1){
                         sellDto.setTotalGoodsPrice(sellDto.getTotalGoodsPrice().subtract(usableParentGoodsCutTotalPrice));

+ 2 - 2
mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml

@@ -63,13 +63,13 @@
         #{clientShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
         #{stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler})
     </insert>
-    <insert id="batchInsert">
+    <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
         INSERT INTO goods
         (goods_category_id_,name_,brand_,specification_,image_,market_price_,
         discount_price_,group_purchase_price_,brief_,desc_,update_time_,create_time_,type_,agree_cost_price_,sn_,
         stock_count_,tax_stock_count_,client_show_,stock_warning_,stock_type_)
         VALUES
-        <foreach collection="goodsList" separator="," item="goods">
+        <foreach collection="list" separator="," item="goods">
             (#{goods.goodsCategoryId},#{goods.name},#{goods.brand},#{goods.specification},#{goods.image},#{goods.marketPrice},
             #{goods.discountPrice},#{goods.groupPurchasePrice},#{goods.brief},#{goods.desc},now(),now(),
             #{goods.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{goods.agreeCostPrice},#{goods.sn},

+ 15 - 1
mec-web/src/main/java/com/ym/mec/web/controller/GoodsController.java

@@ -2,6 +2,7 @@ package com.ym.mec.web.controller;
 
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
+import com.ym.mec.biz.dal.entity.GoodsProcurement;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -38,7 +39,20 @@ public class GoodsController extends BaseController {
         if (sysUser == null) {
             return failed("用户信息获取失败");
         }
-        goodsService.addGoodsProcurement(goods,sysUser.getId());
+        goodsService.addGoods(goods,sysUser.getId());
+        return succeed();
+    }
+
+    @ApiOperation(value = "新增商品清单")
+    @PostMapping("/addGoodsProcurement")
+    @PreAuthorize("@pcs.hasPermissions('goods/addGoodsProcurement')")
+    public Object addGoodsProcurement(GoodsProcurement goodsProcurement){
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null) {
+            return failed("用户信息获取失败");
+        }
+        goodsProcurement.setOperatorId(sysUser.getId());
+        goodsService.addGoodsProcurement(goodsProcurement);
         return succeed();
     }
 

+ 1 - 1
mec-web/src/main/resources/columnMapper.ini

@@ -10,7 +10,7 @@
 商品团购价(元) = groupPurchasePrice
 商品采购价1(元) = costPrice
 商品图片(插入一张图片) = image
-商品明细 = desc
+商品明细 = brief
 商品采购价2(元) = agreeCostPrice
 内部库存 = stockCount
 税务库存 = taxStockCount