Joburgess пре 4 година
родитељ
комит
1e1eee6937

+ 6 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsCategoryService.java

@@ -2,10 +2,13 @@ package com.ym.mec.biz.service;
 
 import com.ym.mec.biz.dal.dto.SubjectGoodsDto;
 import com.ym.mec.biz.dal.entity.GoodsCategory;
+import com.ym.mec.biz.dal.enums.AccountType;
 import com.ym.mec.biz.dal.page.GoodsCategoryQueryInfo;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.BaseService;
 
+import java.util.List;
+
 public interface GoodsCategoryService extends BaseService<Integer, GoodsCategory> {
     /**
      * 新增、修改商品类型
@@ -26,4 +29,6 @@ public interface GoodsCategoryService extends BaseService<Integer, GoodsCategory
      * @param goodsIds
      */
     void updateSubjectGoods(Long subjectGoodsMapperId, String goodsIds);
-}
+
+    void goodsTest(List<Integer> goodsIds);
+}

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

@@ -119,5 +119,5 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      */
     List<GoodsSellDto> queryGoodsSellDtos(String goodsId);
 
-    void getGoodsTest(Integer goodsId);
+    void getGoodsTest(List<Integer> goodsIds);
 }

+ 17 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsCategoryServiceImpl.java

@@ -6,15 +6,18 @@ import com.ym.mec.biz.dal.dto.SubjectGoodsDto;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.GoodsCategory;
 import com.ym.mec.biz.dal.entity.SubjectGoodsMapper;
+import com.ym.mec.biz.dal.enums.AccountType;
 import com.ym.mec.biz.dal.enums.GoodsType;
 import com.ym.mec.biz.dal.page.GoodsCategoryQueryInfo;
 import com.ym.mec.biz.service.GoodsCategoryService;
+import com.ym.mec.biz.service.GoodsService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.collection.MapUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
@@ -82,4 +85,17 @@ public class GoodsCategoryServiceImpl extends BaseServiceImpl<Integer, GoodsCate
 		subjectGoodsMapper.setUpdateTime(new Date());
 		subjectGoodsMapperDao.update(subjectGoodsMapper);
 	}
-}
+
+	@Autowired
+	private GoodsService goodsService;
+
+	@Override
+	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+	public void goodsTest(List<Integer> goodsIds) {
+		goodsTest1(goodsIds);
+	}
+
+	public void goodsTest1(List<Integer> goodsIds) {
+		goodsService.subtractStock(goodsIds, AccountType.INTERNAL);
+	}
+}

+ 44 - 8
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -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);

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

@@ -4,6 +4,7 @@ import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.entity.GoodsCategory;
 import com.ym.mec.biz.dal.entity.GoodsProcurement;
+import com.ym.mec.biz.dal.enums.AccountType;
 import com.ym.mec.biz.service.GoodsCategoryService;
 import com.ym.mec.common.entity.HttpResponseResult;
 import io.swagger.annotations.Api;
@@ -12,6 +13,7 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 
+import java.util.Arrays;
 import java.util.Date;
 import java.util.Objects;
 
@@ -122,7 +124,9 @@ public class GoodsController extends BaseController {
 
     @GetMapping("getGoodsTest")
     public HttpResponseResult getGoodsTest(Integer goodsId){
-        goodsService.getGoodsTest(goodsId);
+//        goodsService.getGoodsTest(Arrays.asList(goodsId));
+//        goodsService.subtractStock(Arrays.asList(goodsId), AccountType.INTERNAL);
+        goodsCategoryService.goodsTest(Arrays.asList(goodsId));
         return succeed();
     }
 }