|
@@ -1,18 +1,30 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.ym.mec.biz.dal.dao.GoodsDao;
|
|
|
+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.enums.GoodsType;
|
|
|
-import com.ym.mec.biz.dal.enums.TemplateTypeEnum;
|
|
|
+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;
|
|
|
import com.ym.mec.common.entity.UploadReturnBean;
|
|
|
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.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;
|
|
@@ -20,14 +32,17 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.InputStream;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implements GoodsService {
|
|
@@ -37,6 +52,18 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
private GoodsDao goodsDao;
|
|
|
@Autowired
|
|
|
private UploadFileService uploadFileService;
|
|
|
+ @Autowired
|
|
|
+ private IdGeneratorService idGeneratorService;
|
|
|
+ @Autowired
|
|
|
+ private GoodsProcurementDao goodsProcurementDao;
|
|
|
+ @Autowired
|
|
|
+ private SysConfigDao sysConfigDao;
|
|
|
+ @Autowired
|
|
|
+ private SysMessageService sysMessageService;
|
|
|
+ @Autowired
|
|
|
+ private TeacherDao teacherDao;
|
|
|
+ @Autowired
|
|
|
+ private SellOrderDao sellOrderDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, Goods> getDAO() {
|
|
@@ -44,6 +71,72 @@ 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.nonNull(existsGood)){
|
|
|
+ if(Objects.nonNull(existsGood.getComplementGoodsIdList())){
|
|
|
+ throw new BizException("此货号组合商品已存在");
|
|
|
+ }
|
|
|
+ existsGood.setStockCount(existsGood.getStockCount()+goods.getStockCount());
|
|
|
+ existsGood.setTaxStockCount(existsGood.getTaxStockCount()+existsGood.getTaxStockCount());
|
|
|
+ goodsDao.update(existsGood);
|
|
|
+ }else{
|
|
|
+ goodsDao.insert(goods);
|
|
|
+ existsGood=goods;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotBlank(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
|
|
|
+ public void updateGoodsStatus(Integer goodsId, Integer status) {
|
|
|
+ if(Objects.isNull(goodsId)){
|
|
|
+ throw new BizException("请指定商品");
|
|
|
+ }
|
|
|
+ if(Objects.isNull(status)){
|
|
|
+ throw new BizException("请指定状态");
|
|
|
+ }
|
|
|
+ Goods goods = goodsDao.get(goodsId);
|
|
|
+ if(Objects.isNull(goods)){
|
|
|
+ throw new BizException("商品不存在");
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(goods.getComplementGoodsIdList())){
|
|
|
+ if(status==0){
|
|
|
+ List<Goods> goodsList = goodsDao.getWithComplementGoodsAndStatus(goodsId, 1);
|
|
|
+ if(!CollectionUtils.isEmpty(goodsList)){
|
|
|
+ String goodsNames = StringUtils.join(goodsList.stream().map(Goods::getName).collect(Collectors.toList()));
|
|
|
+ throw new BizException("{}等商品还在销售中", goodsNames);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(status==1){
|
|
|
+ List<Integer> goodsIds = Arrays.stream(goods.getComplementGoodsIdList().split(",")).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
|
|
|
+ List<Goods> goodList = goodsDao.getGoodies(goodsIds);
|
|
|
+ List<String> goodsNames = goodList.stream().filter(g -> YesOrNoEnum.NO.equals(g.getStatus())).map(Goods::getName).collect(Collectors.toList());
|
|
|
+ if(!CollectionUtils.isEmpty(goodsNames)){
|
|
|
+ throw new BizException("{}商品还未上架", StringUtils.join(goodsNames));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ goods.setStatus(status==0?YesOrNoEnum.NO:YesOrNoEnum.YES);
|
|
|
+ goodsDao.update(goods);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public List<Goods> findGoodsBySubId(Integer subjectId,String type) {
|
|
|
return goodsDao.findGoodsBySubId(subjectId,type);
|
|
|
}
|
|
@@ -63,8 +156,8 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public List<Goods> importGoods(MultipartFile file) throws Exception {
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public List<Goods> importGoods(MultipartFile file, Integer operatorId) throws Exception {
|
|
|
Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
|
|
|
InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
|
|
|
Map<String,String> columns = IniFileUtil.readIniFile(inputStream, TemplateTypeEnum.GOODS.getMsg());
|
|
@@ -83,7 +176,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
continue;
|
|
|
}
|
|
|
String columnValue = columns.get(s);
|
|
|
- if(null == row.get(s) || StringUtils.isEmpty(row.get(s).toString())){
|
|
|
+ if(null == row.get(s) || StringUtils.isBlank(row.get(s).toString())){
|
|
|
LOGGER.error("商品导入异常:参数{}不可为空 param:{}",columnValue,objectMap);
|
|
|
continue valueIsNull;
|
|
|
}
|
|
@@ -127,13 +220,262 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
goods = JSONObject.parseObject(objectMap.toJSONString(),Goods.class);
|
|
|
goodsList.add(goods);
|
|
|
} catch (Exception ex) {
|
|
|
- throw new BizException("导入数据出错");
|
|
|
+ throw new BizException("导入数据出错", ex);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(goodsList.size() != 0){
|
|
|
- goodsDao.batchInsert(goodsList);
|
|
|
+ if(CollectionUtils.isEmpty(goodsList)){
|
|
|
+ return goodsList;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> goodsSnList = goodsList.stream().map(Goods::getSn).collect(Collectors.toList());
|
|
|
+ List<Goods> existsGoods = goodsDao.findBySns(goodsSnList);
|
|
|
+ List<String> existsSns = existsGoods.stream().map(Goods::getSn).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<String, List<Goods>> snGoodsMap = goodsList.stream().collect(Collectors.groupingBy(Goods::getSn));
|
|
|
+ for (Goods existsGood : existsGoods) {
|
|
|
+ List<Goods> goods = snGoodsMap.get(existsGood.getSn());
|
|
|
+ int stockCount = goods.stream().mapToInt(Goods::getStockCount).sum();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!CollectionUtils.isEmpty(existsGoods)){
|
|
|
+ goodsDao.batchUpdate(existsGoods);
|
|
|
+ }
|
|
|
+ List<Goods> newGoods = goodsList.stream().filter(g -> !existsSns.contains(g.getSn())).collect(Collectors.toList());
|
|
|
+ if(!CollectionUtils.isEmpty(newGoods)){
|
|
|
+ goodsDao.batchInsert(newGoods);
|
|
|
}
|
|
|
+
|
|
|
+ String batchNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+ Map<String, Integer> existsSnIdMap = existsGoods.stream().collect(Collectors.toMap(Goods::getSn, g -> g.getId()));
|
|
|
+ Map<String, Integer> newSnIdMap = newGoods.stream().collect(Collectors.toMap(Goods::getSn, g -> g.getId()));
|
|
|
+ existsSnIdMap.putAll(newSnIdMap);
|
|
|
+
|
|
|
+ List<GoodsProcurement> goodsProcurements = new ArrayList<>();
|
|
|
+ for (Goods goods : goodsList) {
|
|
|
+ GoodsProcurement gp = new GoodsProcurement();
|
|
|
+ gp.setGoodsId(existsSnIdMap.get(goods.getSn()));
|
|
|
+ gp.setGoodsCategoryId(goods.getGoodsCategoryId());
|
|
|
+ gp.setSupplyChannel(goods.getSupplyChannel());
|
|
|
+ gp.setDiscountPrice(goods.getCostPrice()
|
|
|
+ );
|
|
|
+ gp.setAgreeCostPrice(goods.getAgreeCostPrice());
|
|
|
+ gp.setStockCount(goods.getStockCount());
|
|
|
+ gp.setTaxStockCount(goods.getTaxStockCount());
|
|
|
+ gp.setOperatorId(operatorId);
|
|
|
+ gp.setBatchNo(batchNo);
|
|
|
+ goodsProcurements.add(gp);
|
|
|
+ }
|
|
|
+ goodsProcurementDao.batchInsert(goodsProcurements);
|
|
|
+
|
|
|
+ sellOrderBatchNoAllot();
|
|
|
+
|
|
|
return goodsList;
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void repertoryWarn() {
|
|
|
+ //预警手机号
|
|
|
+ String repertoryWarnPhone = sysConfigDao.findConfigValue("repertory_warn_phone");
|
|
|
+ if(StringUtils.isEmpty(repertoryWarnPhone)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BasicUserDto sysUser = teacherDao.findUserByPhone(repertoryWarnPhone);
|
|
|
+ if(sysUser == null || sysUser.getUserId() == null){
|
|
|
+ throw new BizException("库存预警手机号不存在");
|
|
|
+ }
|
|
|
+ Map<Integer, String> receivers = new HashMap<>(1);
|
|
|
+ receivers.put(sysUser.getUserId(), repertoryWarnPhone);
|
|
|
+ //内部库存预警
|
|
|
+ String innerRepertoryWarnNum = sysConfigDao.findConfigValue("inner_repertory_warn_num");
|
|
|
+ if(StringUtils.isNotEmpty(innerRepertoryWarnNum)){
|
|
|
+ String goodsNames = goodsDao.getInnerRepertoryWarnName(innerRepertoryWarnNum);
|
|
|
+ if(StringUtils.isNotEmpty(goodsNames)){
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.YIMEI, MessageTypeEnum.SMS_GOODS_REPERTORY_WARN, receivers, null, 0, null,null,
|
|
|
+ goodsNames,"内部");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //外部库存预警
|
|
|
+ String outerRepertoryWarnNum = sysConfigDao.findConfigValue("outer_repertory_warn_num");
|
|
|
+ if(StringUtils.isNotEmpty(outerRepertoryWarnNum)){
|
|
|
+ String goodsNames = goodsDao.getOuterRepertoryWarnName(outerRepertoryWarnNum);
|
|
|
+ if(StringUtils.isNotEmpty(goodsNames)){
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.YIMEI, MessageTypeEnum.SMS_GOODS_REPERTORY_WARN, receivers, null, 0, null,null,
|
|
|
+ goodsNames,"税务");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sellOrderBatchNoAllot() {
|
|
|
+ List<SellOrder> noneBatchNoSellOrders = sellOrderDao.getNoneBatchNoSellOrders();
|
|
|
+ if(CollectionUtils.isEmpty(noneBatchNoSellOrders)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<SellOrder> updateSellOrders = new ArrayList<>();
|
|
|
+ for (SellOrder noneBatchNoSellOrder : noneBatchNoSellOrders) {
|
|
|
+ GoodsProcurement goodsProcurement = null;
|
|
|
+ if(StockType.INTERNAL.equals(noneBatchNoSellOrder.getStockType())||(StockType.ALL.equals(noneBatchNoSellOrder.getStockType())&&AccountType.INTERNAL.equals(noneBatchNoSellOrder.getAccountType()))){
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(noneBatchNoSellOrder.getGoodsId());
|
|
|
+ if(Objects.nonNull(goodsProcurement)){
|
|
|
+ goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
|
|
|
+ }
|
|
|
+ }else if(StockType.EXTERNAL.equals(noneBatchNoSellOrder.getStockType())||(StockType.ALL.equals(noneBatchNoSellOrder.getStockType())&&AccountType.EXTERNAL.equals(noneBatchNoSellOrder.getAccountType()))){
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithTaxStockSurplusProcurement(noneBatchNoSellOrder.getGoodsId());
|
|
|
+ if(Objects.nonNull(goodsProcurement)){
|
|
|
+ goodsProcurement.setTaxStockSoldNum(new AtomicInteger(goodsProcurement.getTaxStockSoldNum()).incrementAndGet());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(Objects.nonNull(goodsProcurement)){
|
|
|
+ goodsProcurementDao.update(goodsProcurement);
|
|
|
+ noneBatchNoSellOrder.setBatchNo(goodsProcurement.getBatchNo());
|
|
|
+ noneBatchNoSellOrder.setSellCost(goodsProcurement.getDiscountPrice());
|
|
|
+ updateSellOrders.add(noneBatchNoSellOrder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(updateSellOrders)){
|
|
|
+ sellOrderDao.batchUpdate(updateSellOrders);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public List<SellOrder> subtractStock(List<Integer> goodsIds, AccountType accountType) {
|
|
|
+ if(CollectionUtils.isEmpty(goodsIds)){
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Goods> tempGoodsList = goodsDao.lockGoods(new ArrayList<>(goodsIds));
|
|
|
+ Map<Integer, Goods> idTempGoodsMap = tempGoodsList.stream().collect(Collectors.toMap(Goods::getId, g -> g));
|
|
|
+ List<GoodsProcurement> goodsProcurements = new ArrayList<>();
|
|
|
+ for (Integer goodsId : goodsIds) {
|
|
|
+ Goods tempGoods = idTempGoodsMap.get(goodsId);
|
|
|
+ List<Goods> childGoods = new ArrayList<>();
|
|
|
+ if(StringUtils.isBlank(tempGoods.getComplementGoodsIdList())){
|
|
|
+ childGoods.add(tempGoods);
|
|
|
+ }else{
|
|
|
+ List<Integer> complementGoodsIds = Arrays.stream(tempGoods.getComplementGoodsIdList().split(",")).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
|
|
|
+ childGoods = goodsDao.getGoodies(complementGoodsIds);
|
|
|
+ }
|
|
|
+ for (Goods goods : childGoods) {
|
|
|
+ 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());
|
|
|
+ if(Objects.nonNull(goodsProcurement)){
|
|
|
+ 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());
|
|
|
+ if(Objects.nonNull(goodsProcurement)){
|
|
|
+ goodsProcurement.setTaxStockSoldNum(new AtomicInteger(goodsProcurement.getTaxStockSoldNum()).incrementAndGet());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ goods.setSellCount(new AtomicInteger(goods.getSellCount()).incrementAndGet());
|
|
|
+
|
|
|
+ goodsDao.update(goods);
|
|
|
+ if(Objects.nonNull(goodsProcurement)){
|
|
|
+ goodsProcurementDao.update(goodsProcurement);
|
|
|
+ }else{
|
|
|
+ goodsProcurement = new GoodsProcurement(goods.getId());
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(tempGoods.getComplementGoodsIdList())){
|
|
|
+ goodsProcurement.setParentGoodsId(tempGoods.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ goodsProcurements.add(goodsProcurement);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SellOrder> sellOrders = new ArrayList<>();
|
|
|
+
|
|
|
+ List<GoodsProcurement> singleGoodsList = goodsProcurements.stream().filter(g -> Objects.isNull(g.getParentGoodsId())&&Objects.nonNull(g.getBatchNo())).collect(Collectors.toList());
|
|
|
+ if(!CollectionUtils.isEmpty(singleGoodsList)){
|
|
|
+ Map<String, List<Integer>> batchNoGoodsIdMap = singleGoodsList.stream().collect(Collectors.groupingBy(GoodsProcurement::getBatchNo, Collectors.mapping(GoodsProcurement::getGoodsId, Collectors.toList())));
|
|
|
+ for (Map.Entry<String, List<Integer>> batchNoGoodsIdMapEntry : batchNoGoodsIdMap.entrySet()) {
|
|
|
+ Map<Integer, Long> goodsNumMap = batchNoGoodsIdMapEntry.getValue().stream().collect(Collectors.groupingBy(gid -> gid, Collectors.counting()));
|
|
|
+ for (Map.Entry<Integer, Long> goodsNumMapEntry : goodsNumMap.entrySet()) {
|
|
|
+ Goods goods = idTempGoodsMap.get(goodsNumMapEntry.getKey());
|
|
|
+ SellOrder sellOrder = new SellOrder();
|
|
|
+ sellOrder.setGoodsId(goodsNumMapEntry.getKey());
|
|
|
+ sellOrder.setNum(goodsNumMapEntry.getValue().intValue());
|
|
|
+ sellOrder.setStockType(goods.getStockType());
|
|
|
+ sellOrder.setAccountType(accountType);
|
|
|
+ sellOrder.setBatchNo(batchNoGoodsIdMapEntry.getKey());
|
|
|
+ GoodsProcurement goodsProcurement = goodsProcurementDao.getWithGoodsAndBatchNo(sellOrder.getGoodsId(), sellOrder.getBatchNo());
|
|
|
+ sellOrder.setSellCost(goodsProcurement.getDiscountPrice().multiply(new BigDecimal(sellOrder.getNum())));
|
|
|
+ sellOrders.add(sellOrder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<GoodsProcurement> groupGoodsList = goodsProcurements.stream().filter(g -> Objects.nonNull(g.getParentGoodsId())||Objects.isNull(g.getBatchNo())).collect(Collectors.toList());
|
|
|
+ if(!CollectionUtils.isEmpty(groupGoodsList)){
|
|
|
+ for (GoodsProcurement goodsProcurement : groupGoodsList) {
|
|
|
+ Goods goods = goodsDao.get(goodsProcurement.getGoodsId());
|
|
|
+ SellOrder sellOrder = new SellOrder();
|
|
|
+ sellOrder.setParentGoodsId(goodsProcurement.getParentGoodsId());
|
|
|
+ sellOrder.setGoodsId(goodsProcurement.getGoodsId());
|
|
|
+ sellOrder.setNum(1);
|
|
|
+ sellOrder.setStockType(goods.getStockType());
|
|
|
+ sellOrder.setAccountType(accountType);
|
|
|
+ sellOrder.setBatchNo(goodsProcurement.getBatchNo());
|
|
|
+ if(Objects.nonNull(goodsProcurement.getBatchNo())){
|
|
|
+ sellOrder.setSellCost(goodsProcurement.getDiscountPrice().multiply(new BigDecimal(sellOrder.getNum())));
|
|
|
+ }
|
|
|
+ sellOrders.add(sellOrder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return sellOrders;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public void increaseStock(List<SellOrder> sellOrders, AccountType accountType) {
|
|
|
+ if(CollectionUtils.isEmpty(sellOrders)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Integer> goodsIdList = new HashSet<>();
|
|
|
+ sellOrders.forEach(so -> {
|
|
|
+ if(Objects.nonNull(so.getParentGoodsId())){
|
|
|
+ goodsIdList.add(so.getParentGoodsId());
|
|
|
+ }else{
|
|
|
+ goodsIdList.add(so.getGoodsId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ for (SellOrder sellOrder : sellOrders) {
|
|
|
+ Goods goods = goodsDao.get(sellOrder.getGoodsId());
|
|
|
+ GoodsProcurement goodsProcurement = goodsProcurementDao.getWithGoodsAndBatchNo(sellOrder.getGoodsId(), sellOrder.getBatchNo());
|
|
|
+ if(StockType.INTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.INTERNAL.equals(accountType))){
|
|
|
+ goods.setStockCount(new AtomicInteger(goods.getStockCount()).addAndGet(sellOrder.getNum()));
|
|
|
+ if(Objects.nonNull(goodsProcurement)){
|
|
|
+ goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).addAndGet(-sellOrder.getNum()));
|
|
|
+ }
|
|
|
+ }else if(StockType.EXTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.EXTERNAL.equals(accountType))){
|
|
|
+ goods.setTaxStockCount(new AtomicInteger(goods.getTaxStockCount()).addAndGet(sellOrder.getNum()));
|
|
|
+ if(Objects.nonNull(goodsProcurement)){
|
|
|
+ goodsProcurement.setTaxStockSoldNum(new AtomicInteger(goodsProcurement.getTaxStockSoldNum()).addAndGet(-sellOrder.getNum()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ goods.setSellCount(new AtomicInteger(goods.getSellCount()).addAndGet(-sellOrder.getNum()));
|
|
|
+
|
|
|
+ goodsDao.update(goods);
|
|
|
+ goodsProcurementDao.update(goodsProcurement);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<GoodsSellDto> queryGoodsSellDtos(String goodsId) {
|
|
|
+ return goodsDao.queryGoodsSellDtos(goodsId);
|
|
|
+ }
|
|
|
+}
|