|
@@ -447,14 +447,50 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
- public void getGoodsTest(Integer goodsId) {
|
|
|
- List<Goods> tempGoodsList = goodsDao.lockGoods(Arrays.asList(goodsId));
|
|
|
- Goods goods = goodsDao.get(goodsId);
|
|
|
- if(!tempGoodsList.get(0).getSellCount().equals(goods.getSellCount())){
|
|
|
- System.out.println("-----------------------------------" + goods);
|
|
|
+ public void getGoodsTest(List<Integer> goodsIds) {
|
|
|
+ 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 = goodsDao.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.lockGoods(complementGoodsIds);
|
|
|
+ }
|
|
|
+ for (Goods goods : childGoods) {
|
|
|
+ GoodsProcurement goodsProcurement = null;
|
|
|
+ if(StockType.INTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.INTERNAL.equals(AccountType.INTERNAL))){
|
|
|
+ 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.EXTERNAL))){
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
- goods.setSellCount(new AtomicInteger(goods.getSellCount()).incrementAndGet());
|
|
|
- goodsDao.update(goods);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -468,7 +504,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
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);
|
|
|
+ Goods tempGoods = tempGoodsList.get(goodsId);
|
|
|
List<Goods> childGoods = new ArrayList<>();
|
|
|
if(StringUtils.isBlank(tempGoods.getComplementGoodsIdList())){
|
|
|
childGoods.add(tempGoods);
|