futian.liu
2023-12-01 b3dc06734af35528496c192368586d5d8a61b42a
consum-base/src/main/java/com/consum/base/service/LWarehouseFlowCoreService.java
@@ -1,30 +1,34 @@
package com.consum.base.service;
import com.consum.base.core.util.LockManage;
import com.consum.base.core.utils.LockManage;
import com.consum.model.po.*;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.NumberGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * @ClassName LWarehouseFlowService
 * @Date 2023/10/24
 * @Description
 * @Version 1.0
 **/
@Service
@Slf4j
@Transactional(propagation = Propagation.REQUIRED)
public class LWarehouseFlowCoreService {
    private final JdbcTemplate jdbcTemplate;
@@ -34,14 +38,22 @@
    private LWhGoodsRecordService lWhGoodsRecordService;
    private BaseGoodsTemplateServiceImpl baseGoodsTemplateService;
    @Value("${spring.datasource.dataBaseName}")
    private String dataBaseName;
    @PostConstruct
    public void init() {
        this.simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).withCatalogName(dataBaseName).withProcedureName("InsertL_WH_GOODS");
    }
    @Autowired
    public LWarehouseFlowCoreService(JdbcTemplate jdbcTemplate, LWarehouseFlowService lWarehouseFlowService, LWhGoodsService lWhGoodsService, BaseGoodsTemplateServiceImpl baseGoodsTemplateService, LWhGoodsRecordService lWhGoodsRecordService) {
    public LWarehouseFlowCoreService(JdbcTemplate jdbcTemplate, LWarehouseFlowService lWarehouseFlowService, LWhGoodsService lWhGoodsService,
                                     BaseGoodsTemplateServiceImpl baseGoodsTemplateService, LWhGoodsRecordService lWhGoodsRecordService) {
        this.jdbcTemplate = jdbcTemplate;
        this.lWarehouseFlowService = lWarehouseFlowService;
        this.baseGoodsTemplateService = baseGoodsTemplateService;
        this.lWhGoodsService = lWhGoodsService;
        this.lWhGoodsRecordService = lWhGoodsRecordService;
        this.simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).withProcedureName("InsertL_WH_GOODS");
    }
    /**
@@ -69,8 +81,8 @@
        //采购方式(1:集采;2=自采)
        short buyType = lWhFormProcure.getBuyType().shortValue();
        //采购时间
        Long procureTime = lWhFormProcure.getProcureTime();
        Long procureTime2 = lWhFormProcure.getProcureTime();
        Long procureTime = procureTime2 == null ? dealTime : procureTime2;
        // 插入流水总表
        int flowInsertFlag = lWarehouseFlowService.insert(warehouseFlow);
        if (flowInsertFlag == 0) {
@@ -118,24 +130,28 @@
            Object warehouseModelLockObj = LockManage.acquireLock(warehouseType, warehouseId, baseGoodsModelsId);
            synchronized (warehouseModelLockObj) {
                // 获得锁后查询该型号的期初数量
                int goodsModelNum = lWhGoodsService.queryGoodsModelNum(warehouseType, warehouseId, baseGoodsModelsId, (short) 1, null);
                int goodsModelNum = lWhGoodsService.queryGoodsModelNum(warehouseType, warehouseId, baseGoodsModelsId, 1, null);
                whGoodsRecord.setInitialCount(goodsModelNum);
                whGoodsRecord.setThisCount(modelCount);
                whGoodsRecord.setEndCount(goodsModelNum + modelCount);
                long totalPrice = 0;
                //将同型号的物品插入 库存物品详情
                List<LWhProcureModel> lWhProcureModels = sameModelList.get(baseGoodsModelsId);
                lWhProcureModels.forEach(item -> {
                for (LWhProcureModel item : lWhProcureModels) {
                    //供应商
                    String supplier = item.getSupplier();
                    //价格
                    Long price = item.getPrice();
                    //物品个数
                    Integer counts = item.getCounts();
                    totalPrice = totalPrice + counts * price;
                    sameGoodsInsertMore(warehouseFlowId, warehouseType, warehouseId, whGoodsRecordId, (short) 1, warehouseName,
                            classification, tempGoodsId, goodsName, baseGoodsModelsId, modelName,
                            supplier, buyType, goodsUnit, price, procureTime, 1, dealTime, counts);
                });
                }
                ;
                whGoodsRecord.setTotalPrice(totalPrice);
            }
            lWhGoodsRecordService.insert(whGoodsRecord);
        });
@@ -145,9 +161,7 @@
    /**
     * 同样规格的物品 插入多次,
     * 同时将主键记录在 进出库流水明细【L_WH_GOODS_RECORD_DETAILS】,
     * 更新 物品仓库保管记录【L_GOODS_WH_RECORD】
     * 同样规格的物品 插入多次, 同时将主键记录在 进出库流水明细【L_WH_GOODS_RECORD_DETAILS】, 更新 物品仓库保管记录【L_GOODS_WH_RECORD】
     *
     * @param pWarehouseId         仓库id
     * @param pWarehouseName       仓库名称
@@ -164,7 +178,8 @@
     * @param pStates              状态
     * @param pTimes               插入条数
     */
    public void sameGoodsInsertMore(long pWarehouseFlowId, Integer warehouseType, long pWarehouseId, long pWhGoodsRecordId, short pRecordType, String pWarehouseName, short pCostType,
    public void sameGoodsInsertMore(long pWarehouseFlowId, Integer warehouseType, long pWarehouseId, long pWhGoodsRecordId, short pRecordType,
                                    String pWarehouseName, short pCostType,
                                    long pBaseGoodsTemplateId, String pGoodsTemplateName, long pBaseGoodsModelsId,
                                    String pBaseGoodsModelsName, String pSupplier, short pBuyType,
                                    String pUnit, long pPrice, long pProcureDate,