Joburgess пре 5 година
родитељ
комит
759cf1cef0

+ 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);
 
     /**

+ 41 - 9
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())){
@@ -95,6 +89,44 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	}
 
 	@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
 	public void updateGoodsStatus(Integer goodsId, Integer status) {
 		if(Objects.isNull(goodsId)){
 			throw new BizException("请指定商品");
@@ -402,7 +434,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 +458,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())) {

+ 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')")