| | |
| | | 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 |
| | | * @Author cy |
| | | * @Date 2023/10/24 |
| | | * @Description |
| | | * @Version 1.0 |
| | | **/ |
| | | @Service |
| | | @Slf4j |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public class LWarehouseFlowCoreService { |
| | | |
| | | private final JdbcTemplate jdbcTemplate; |
| | |
| | | private LWarehouseFlowService lWarehouseFlowService; |
| | | private LWhGoodsService lWhGoodsService; |
| | | private LWhGoodsRecordService lWhGoodsRecordService; |
| | | private LWhFormTransferService lWhFormTransferService; |
| | | private LWhFormOutputCoreService lWhFormOutputCoreService; |
| | | 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, LWhFormTransferService lWhFormTransferService, LWhFormOutputCoreService lWhFormOutputCoreService, 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.lWhFormTransferService = lWhFormTransferService; |
| | | this.lWhFormOutputCoreService = lWhFormOutputCoreService; |
| | | this.lWhGoodsService = lWhGoodsService; |
| | | this.lWhGoodsRecordService = lWhGoodsRecordService; |
| | | this.simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).withProcedureName("InsertL_WH_GOODS"); |
| | | } |
| | | |
| | | /** |
| | |
| | | //采购方式(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) { |
| | |
| | | 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(); |
| | | sameGoodsInsertMore(warehouseFlowId, warehouseId, whGoodsRecordId, (short) 1, warehouseName, |
| | | 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); |
| | | }); |
| | |
| | | return 1; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 同样规格的物品 插入多次, |
| | | * 同时将主键记录在 进出库流水明细【L_WH_GOODS_RECORD_DETAILS】, |
| | | * 更新 物品仓库保管记录【L_GOODS_WH_RECORD】 |
| | | * 同样规格的物品 插入多次, 同时将主键记录在 进出库流水明细【L_WH_GOODS_RECORD_DETAILS】, 更新 物品仓库保管记录【L_GOODS_WH_RECORD】 |
| | | * |
| | | * @param pWarehouseId 仓库id |
| | | * @param pWarehouseName 仓库名称 |
| | |
| | | * @param pStates 状态 |
| | | * @param pTimes 插入条数 |
| | | */ |
| | | public void sameGoodsInsertMore(long pWarehouseFlowId, 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, |
| | | int pStates, long pDealTime, int pTimes) { |
| | | SqlParameterSource in = new MapSqlParameterSource() |
| | | .addValue("p_WAREHOUSE_FLOW_ID", pWarehouseFlowId) |
| | | .addValue("p_WAREHOUSE_TYPE", warehouseType) |
| | | .addValue("p_WAREHOUSE_ID", pWarehouseId) |
| | | .addValue("p_WH_GOODS_RECORD_ID", pWhGoodsRecordId) |
| | | .addValue("p_RECORD_TYPE", pRecordType) |
| | |
| | | System.out.println("Procedure result: " + out); |
| | | } |
| | | |
| | | /** |
| | | * 调拨出库 |
| | | * |
| | | * @param outWarehouseId 出库单 |
| | | * @return |
| | | */ |
| | | public int outInsertWareFlow(Long outWarehouseId) { |
| | | // 出库时候,按 先入库的先出库,同时入库的,按价格高的先出库 |
| | | // List<Long> outGoodsId = lWhGoodsService.queryOutGoodsId(outWarehouseId, baseGoodsModelsId, queryModelStatus, buyType, goodsModelNum); |
| | | // 修改物品的状态为 状态(0=在途调拨;1=入库未分发;2=已下发;3=报废) |
| | | // 修改 所属仓库仓库编号WAREHOUSE_ID、仓库名称WAREHOUSE_NAME,此时不要同步进 物品仓库保管记录【L_GOODS_WH_RECORD】!入库时再同步 |
| | | |
| | | |
| | | // 新增记录 进出库流水总表[L_WAREHOUSE_FLOW] 各规格物品的进出库【L_WH_GOODS_RECORD】进出库流水明细[L_WH_GOODS_RECORD_DETAILS] |
| | | |
| | | |
| | | return 0; |
| | | } |
| | | } |