| | |
| | | package com.consum.base.service; |
| | | |
| | | import com.consum.base.core.util.LockManage; |
| | | import com.consum.model.po.*; |
| | | import com.walker.infrastructure.utils.CollectionUtils; |
| | | import com.walker.infrastructure.utils.NumberGenerator; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | |
| | | 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 java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | import com.consum.base.core.utils.IdUtil; |
| | | import com.consum.base.core.utils.LockManage; |
| | | import com.consum.model.po.BaseWarehouse; |
| | | import com.consum.model.po.LWarehouseFlow; |
| | | import com.consum.model.po.LWhFormProcure; |
| | | import com.consum.model.po.LWhGoodsRecord; |
| | | import com.consum.model.po.LWhProcureModel; |
| | | import com.walker.infrastructure.utils.CollectionUtils; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @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 SimpleJdbcCall simpleJdbcCall; |
| | | private LWarehouseFlowService lWarehouseFlowService; |
| | | private LWhGoodsService lWhGoodsService; |
| | | private LWhGoodsRecordService lWhGoodsRecordService; |
| | | private LWhFormTransferService lWhFormTransferService; |
| | | private LWhFormOutputCoreService lWhFormOutputCoreService; |
| | | private BaseGoodsTemplateServiceImpl baseGoodsTemplateService; |
| | | private LWhGoodsRecordService lWhGoodsRecordServiceImpl; |
| | | private BaseGoodsTemplateService 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, BaseGoodsTemplateService baseGoodsTemplateService, |
| | | LWhGoodsRecordService lWhGoodsRecordServiceImpl) { |
| | | 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"); |
| | | this.lWhGoodsRecordServiceImpl = lWhGoodsRecordServiceImpl; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param warehouseFlow |
| | | * @return |
| | | */ |
| | | public int buyInsertWareFlow(List<LWhProcureModel> goodsModelNumList, LWhFormProcure lWhFormProcure, LWarehouseFlow warehouseFlow) { |
| | | public int buyInsertWareFlow(List<LWhProcureModel> goodsModelNumList, LWhFormProcure lWhFormProcure, |
| | | LWarehouseFlow warehouseFlow) { |
| | | if (CollectionUtils.isEmpty(goodsModelNumList)) { |
| | | log.error("没有要入库的物品"); |
| | | return 0; |
| | |
| | | } |
| | | // 查询仓库信息 |
| | | Long warehouseFlowId = warehouseFlow.getId(); |
| | | Integer warehouseType = warehouseFlow.getWarehouseType(); |
| | | Long warehouseId = warehouseFlow.getWarehouseId(); |
| | | Long dealTime = warehouseFlow.getDealTime(); |
| | | BaseWarehouse baseWarehouses = lWarehouseFlowService.get(new BaseWarehouse(warehouseId)); |
| | | String warehouseName = baseWarehouses.getWarehouseName(); |
| | | //采购方式(1:集采;2=自采) |
| | | // 采购方式(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) { |
| | | return 0; |
| | | } |
| | | |
| | | //统计各型号数量 |
| | | Map<Long, Integer> countsSumByBaseGoodsModelsId = goodsModelNumList.stream() |
| | | .collect(Collectors.groupingBy(LWhProcureModel::getBaseGoodsModelsId, |
| | | Collectors.summingInt(LWhProcureModel::getCounts))); |
| | | // 统计各型号数量 |
| | | Map<Long, Integer> countsSumByBaseGoodsModelsId = goodsModelNumList.stream().collect(Collectors |
| | | .groupingBy(LWhProcureModel::getBaseGoodsModelsId, Collectors.summingInt(LWhProcureModel::getCounts))); |
| | | Map<Long, List<LWhProcureModel>> sameModelList = goodsModelNumList.stream() |
| | | // 按型号分 |
| | | .collect(Collectors.groupingBy(LWhProcureModel::getBaseGoodsModelsId)); |
| | | // 按型号分 |
| | | .collect(Collectors.groupingBy(LWhProcureModel::getBaseGoodsModelsId)); |
| | | countsSumByBaseGoodsModelsId.forEach((baseGoodsModelsId, modelCount) -> { |
| | | //查询型号信息 |
| | | // 查询型号信息 |
| | | Map<String, Object> tempGoodsInfo = baseGoodsTemplateService.queryGoodsInfoByModelId(baseGoodsModelsId); |
| | | //价值类型 |
| | | String classificationObj = (String) tempGoodsInfo.get("classification"); |
| | | // 价值类型 |
| | | String classificationObj = (String)tempGoodsInfo.get("classification"); |
| | | Short classificationT = 3; |
| | | if (classificationObj != null) { |
| | | classificationT = (short) ((classificationObj).charAt(0) - 64); |
| | | classificationT = (short)((classificationObj).charAt(0) - 64); |
| | | } |
| | | short classification = classificationT; |
| | | Long tempGoodsId = (Long) tempGoodsInfo.get("goodsid"); |
| | | String goodsName = (String) tempGoodsInfo.get("goodsname"); |
| | | String modelName = (String) tempGoodsInfo.get("modelname"); |
| | | String goodsUnit = (String) tempGoodsInfo.get("unit"); |
| | | Long tempGoodsId = (Long)tempGoodsInfo.get("goodsid"); |
| | | String goodsName = (String)tempGoodsInfo.get("goodsname"); |
| | | String modelName = (String)tempGoodsInfo.get("modelname"); |
| | | String goodsUnit = (String)tempGoodsInfo.get("unit"); |
| | | |
| | | // 插入 各规格物品的进出库记录 L_WH_GOODS_RECORD |
| | | long whGoodsRecordId = NumberGenerator.getLongSequenceNumberNano(); |
| | | long whGoodsRecordId = IdUtil.generateId(); |
| | | LWhGoodsRecord whGoodsRecord = new LWhGoodsRecord(); |
| | | whGoodsRecord.setId(whGoodsRecordId); |
| | | whGoodsRecord.setWarehouseId(warehouseId); |
| | |
| | | whGoodsRecord.setBaseGoodsModelsId(baseGoodsModelsId); |
| | | whGoodsRecord.setBaseGoodsModelsName(modelName); |
| | | whGoodsRecord.setDealTime(dealTime); |
| | | //本次调整类型 1=调增;2=调减 |
| | | // 本次调整类型 1=调增;2=调减 |
| | | whGoodsRecord.setThisType(1); |
| | | |
| | | //通过LockManage获得锁 |
| | | Object warehouseModelLockObj = LockManage.acquireLock(warehouseId, baseGoodsModelsId); |
| | | // 通过LockManage获得锁 |
| | | Object warehouseModelLockObj = LockManage.acquireLock(warehouseType, warehouseId, baseGoodsModelsId); |
| | | synchronized (warehouseModelLockObj) { |
| | | // 获得锁后查询该型号的期初数量 |
| | | int goodsModelNum = lWhGoodsService.queryGoodsModelNum(warehouseId, baseGoodsModelsId, (short) 1, null); |
| | | List<Long> warehouseIds = new ArrayList<>(Arrays.asList(warehouseId)); |
| | | int goodsModelNum = |
| | | lWhGoodsService.queryGoodsModelNum(warehouseType, warehouseIds, 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, |
| | | classification, tempGoodsId, goodsName, baseGoodsModelsId, modelName, |
| | | supplier, buyType, goodsUnit, price, procureTime, 1, dealTime, counts); |
| | | }); |
| | | 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); |
| | | lWhGoodsRecordServiceImpl.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 pCostType 物品价值类型 |
| | | * @param pWarehouseId 仓库id |
| | | * @param pWarehouseName 仓库名称 |
| | | * @param pCostType 物品价值类型 |
| | | * @param pBaseGoodsTemplateId 物品模板ID |
| | | * @param pGoodsTemplateName 物品模板名称 |
| | | * @param pBaseGoodsModelsId 物品型号ID |
| | | * @param pGoodsTemplateName 物品模板名称 |
| | | * @param pBaseGoodsModelsId 物品型号ID |
| | | * @param pBaseGoodsModelsName 物品型号名称 |
| | | * @param pUnit 物品单位 |
| | | * @param pSupplier 物品供应商 |
| | | * @param pBuyType 物品购买类型 |
| | | * @param pPrice 物品价格 |
| | | * @param pProcureDate 采购日期 |
| | | * @param pStates 状态 |
| | | * @param pTimes 插入条数 |
| | | * @param pUnit 物品单位 |
| | | * @param pSupplier 物品供应商 |
| | | * @param pBuyType 物品购买类型 |
| | | * @param pPrice 物品价格 |
| | | * @param pProcureDate 采购日期 |
| | | * @param pStates 状态 |
| | | * @param pTimes 插入条数 |
| | | */ |
| | | public void sameGoodsInsertMore(long pWarehouseFlowId, 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_ID", pWarehouseId) |
| | | .addValue("p_WH_GOODS_RECORD_ID", pWhGoodsRecordId) |
| | | .addValue("p_RECORD_TYPE", pRecordType) |
| | | .addValue("p_WAREHOUSE_NAME", pWarehouseName) |
| | | .addValue("p_COST_TYPE", pCostType) |
| | | .addValue("p_BASE_GOODS_TEMPLATE_ID", pBaseGoodsTemplateId) |
| | | .addValue("p_GOODS_TEMPLATE_NAME", pGoodsTemplateName) |
| | | .addValue("p_BASE_GOODS_MODELS_ID", pBaseGoodsModelsId) |
| | | .addValue("p_BASE_GOODS_MODELS_NAME", pBaseGoodsModelsName) |
| | | .addValue("p_SUPPLIER", pSupplier) |
| | | .addValue("p_BUY_TYPE", pBuyType) |
| | | .addValue("p_UNIT", pUnit) |
| | | .addValue("p_PRICE", pPrice) |
| | | .addValue("p_PROCURE_DATE", pProcureDate) |
| | | .addValue("p_STATES", pStates) |
| | | .addValue("p_DEAL_TIME", pDealTime) |
| | | .addValue("p_times", pTimes); |
| | | 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) |
| | | .addValue("p_WAREHOUSE_NAME", pWarehouseName).addValue("p_COST_TYPE", pCostType) |
| | | .addValue("p_BASE_GOODS_TEMPLATE_ID", pBaseGoodsTemplateId) |
| | | .addValue("p_GOODS_TEMPLATE_NAME", pGoodsTemplateName) |
| | | .addValue("p_BASE_GOODS_MODELS_ID", pBaseGoodsModelsId) |
| | | .addValue("p_BASE_GOODS_MODELS_NAME", pBaseGoodsModelsName).addValue("p_SUPPLIER", pSupplier) |
| | | .addValue("p_BUY_TYPE", pBuyType).addValue("p_UNIT", pUnit).addValue("p_PRICE", pPrice) |
| | | .addValue("p_PROCURE_DATE", pProcureDate).addValue("p_STATES", pStates).addValue("p_DEAL_TIME", pDealTime) |
| | | .addValue("p_times", pTimes); |
| | | Map<String, Object> out = simpleJdbcCall.execute(in); |
| | | 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; |
| | | } |
| | | } |