|
@@ -7,11 +7,10 @@ import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.biz.dal.dao.GoodsDao;
|
|
|
import com.ym.mec.biz.dal.dao.GoodsProcurementDao;
|
|
|
import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
+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.enums.GoodsType;
|
|
|
-import com.ym.mec.biz.dal.enums.MessageTypeEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.TemplateTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.*;
|
|
|
import com.ym.mec.biz.service.GoodsService;
|
|
|
import com.ym.mec.biz.service.SysMessageService;
|
|
|
import com.ym.mec.biz.service.UploadFileService;
|
|
@@ -23,6 +22,7 @@ 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;
|
|
@@ -38,6 +38,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -84,8 +86,8 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
gp.setSupplyChannel(goods.getSupplyChannel());
|
|
|
gp.setDiscountPrice(goods.getDiscountPrice());
|
|
|
gp.setAgreeCostPrice(goods.getAgreeCostPrice());
|
|
|
- gp.setTotalQuantity(goods.getStockCount());
|
|
|
- gp.setTaxQuantity(goods.getTaxStockCount());
|
|
|
+ gp.setStockCount(goods.getStockCount());
|
|
|
+ gp.setTaxStockCount(goods.getTaxStockCount());
|
|
|
gp.setOperatorId(operatorId);
|
|
|
gp.setBatchNo(batchNo);
|
|
|
|
|
@@ -218,8 +220,8 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
gp.setSupplyChannel(goods.getSupplyChannel());
|
|
|
gp.setDiscountPrice(goods.getDiscountPrice());
|
|
|
gp.setAgreeCostPrice(goods.getAgreeCostPrice());
|
|
|
- gp.setTotalQuantity(goods.getStockCount());
|
|
|
- gp.setTaxQuantity(goods.getTaxStockCount());
|
|
|
+ gp.setStockCount(goods.getStockCount());
|
|
|
+ gp.setTaxStockCount(goods.getTaxStockCount());
|
|
|
gp.setOperatorId(operatorId);
|
|
|
gp.setBatchNo(batchNo);
|
|
|
goodsProcurements.add(gp);
|
|
@@ -264,17 +266,50 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public String subtractStock(List<Integer> goodsIds) {
|
|
|
- List result = new ArrayList();
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public List<Goods> subtractStock(List<Integer> goodsIds, AccountType accountType) {
|
|
|
if(CollectionUtils.isEmpty(goodsIds)){
|
|
|
- return JSONObject.toJSONString(result);
|
|
|
+ return Collections.emptyList();
|
|
|
}
|
|
|
- List<Goods> tempGoods = goodsDao.getGoodies(goodsIds);
|
|
|
- List<Integer> realGoodIds = new ArrayList<>();
|
|
|
- for (Goods tempGood : tempGoods) {
|
|
|
|
|
|
+ Map<Integer, Long> goodsSellNumMap = goodsIds.stream().collect(Collectors.groupingBy(s -> s, Collectors.counting()));
|
|
|
+
|
|
|
+ List<Goods> tempGoodsList = goodsDao.lockGoods(new ArrayList<>(goodsIds));
|
|
|
+ Map<Integer, Integer> singleGoodsSellNumMap = new HashMap<>();
|
|
|
+ Map<Integer, Goods> idTempGoodsMap = tempGoodsList.stream().collect(Collectors.toMap(Goods::getId, g -> g));
|
|
|
+ List<Integer> singleGoodsIds = new ArrayList<>();
|
|
|
+ for (Integer goodsId : goodsIds) {
|
|
|
+ Goods tempGoods = idTempGoodsMap.get(goodsId);
|
|
|
+ if(StringUtils.isBlank(tempGoods.getComplementGoodsIdList())){
|
|
|
+ singleGoodsIds.add(tempGoods.getId());
|
|
|
+ }else{
|
|
|
+ List<Integer> complementGoodsIds = Arrays.stream(tempGoods.getComplementGoodsIdList().split(",")).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
|
|
|
+ singleGoodsIds.addAll(complementGoodsIds);
|
|
|
+ }
|
|
|
}
|
|
|
+ List<Goods> singleGoodsList = goodsDao.getGoodies(singleGoodsIds);
|
|
|
+ Map<Integer, Goods> idSingleGoodsMap = singleGoodsList.stream().collect(Collectors.toMap(Goods::getId, g -> g));
|
|
|
+ for (Integer singleGoodsId : singleGoodsIds) {
|
|
|
+ Goods goods = idSingleGoodsMap.get(singleGoodsId);
|
|
|
+ GoodsProcurement goodsProcurement = null;
|
|
|
+ if(StockType.INTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.INTERNAL.equals(accountType))){
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
|
|
|
+ goods.setStockCount(new AtomicInteger(goods.getStockCount()).decrementAndGet());
|
|
|
+ goodsProcurement.setStockCount(new AtomicInteger(goodsProcurement.getStockCount()).decrementAndGet());
|
|
|
+ goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
|
|
|
+ }else if(StockType.EXTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.EXTERNAL.equals(accountType))){
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithTaxStockSurplusProcurement(goods.getId());
|
|
|
+ goods.setTaxStockCount(new AtomicInteger(goods.getTaxStockCount()).decrementAndGet());
|
|
|
+ goodsProcurement.setTaxStockCount(new AtomicInteger(goodsProcurement.getTaxStockCount()).decrementAndGet());
|
|
|
+ goodsProcurement.setTaxStockSoldNum(new AtomicInteger(goodsProcurement.getTaxStockSoldNum()).incrementAndGet());
|
|
|
+ }
|
|
|
+ if(Objects.isNull(goodsProcurement)){
|
|
|
+ throw new BizException("商品类型不明");
|
|
|
+ }
|
|
|
+ goodsDao.update(goods);
|
|
|
+ goodsProcurementDao.update(goodsProcurement);
|
|
|
+ }
|
|
|
+
|
|
|
return null;
|
|
|
}
|
|
|
}
|