瀏覽代碼

feat:课程计费逻辑调整

Joburgess 4 年之前
父節點
當前提交
4aeecc1d90

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

@@ -89,6 +89,8 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      */
     void sellOrderBatchNoAllot();
 
+    void getGoodsTest(List<Integer> goodsIds);
+
     /**
      * @describe 扣减商品库存
      * @author Joburgess

+ 36 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -466,6 +466,42 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 
 	@Override
 	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
+	public void getGoodsTest(List<Integer> goodsIds) {
+		goodsDao.lockGoods(new ArrayList<>(goodsIds));
+		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.getGoodies(complementGoodsIds);
+			}
+			for (Goods goods : childGoods) {
+				GoodsProcurement goodsProcurement;
+				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);
+			}
+		}
+	}
+
+	@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();

+ 9 - 0
mec-web/src/main/java/com/ym/mec/web/controller/GoodsController.java

@@ -19,6 +19,7 @@ import java.util.Objects;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import com.ym.mec.biz.dal.entity.Goods;
@@ -121,4 +122,12 @@ public class GoodsController extends BaseController {
     public Object findGoodsBySubId(Integer subjectId,String type){
         return succeed(goodsService.findGoodsBySubId(subjectId,type));
     }
+
+    @GetMapping("getGoodsTest")
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResponseResult getGoodsTest(Integer goodsId){
+        goodsService.getGoodsTest(Arrays.asList(goodsId));
+//        goodsService.subtractStock(Arrays.asList(goodsId), AccountType.INTERNAL);
+        return succeed();
+    }
 }