| | |
| | | import com.walker.infrastructure.utils.CollectionUtils; |
| | | import com.walker.infrastructure.utils.NumberGenerator; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | 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.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class LWhFormOutputCoreService { |
| | | private final JdbcTemplate jdbcTemplate; |
| | | private SimpleJdbcCall simpleJdbcCall; |
| | | |
| | | private BaseGoodsTemplateServiceImpl baseGoodsTemplateService; |
| | | private LWhGoodsService lWhGoodsService; |
| | | private CodeGeneratorService codeGeneratorService; |
| | |
| | | private LWhFormTransferService lWhFormTransferService; |
| | | private LWhFormOutputService lWhFormOutputService; |
| | | private LWarehouseFlowService lWarehouseFlowService; |
| | | private LWhGoodsRecordDetailsService lWhGoodsRecordDetailsService; |
| | | private LWhGoodsRecordService lWhGoodsRecordService; |
| | | |
| | | @Autowired |
| | | public LWhFormOutputCoreService(BaseGoodsTemplateServiceImpl baseGoodsTemplateService, |
| | |
| | | LWhFormTransferService lWhFormTransferService, |
| | | LWhFormOutputService lWhFormOutputService, |
| | | LWarehouseFlowService lWarehouseFlowService, |
| | | JdbcTemplate jdbcTemplate |
| | | ) { |
| | | LWhGoodsRecordDetailsService lWhGoodsRecordDetailsService, |
| | | LWhGoodsRecordService lWhGoodsRecordService) { |
| | | this.baseGoodsTemplateService = baseGoodsTemplateService; |
| | | this.lWhGoodsService = lWhGoodsService; |
| | | this.codeGeneratorService = codeGeneratorService; |
| | |
| | | this.lWhFormTransferService = lWhFormTransferService; |
| | | this.lWhFormOutputService = lWhFormOutputService; |
| | | this.lWarehouseFlowService = lWarehouseFlowService; |
| | | this.jdbcTemplate = jdbcTemplate; |
| | | this.simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).withProcedureName("insert_WH_GOODS_RECORD_DETAILS"); |
| | | this.lWhGoodsRecordDetailsService = lWhGoodsRecordDetailsService; |
| | | this.lWhGoodsRecordService = lWhGoodsRecordService; |
| | | } |
| | | |
| | | |
| | |
| | | return null; |
| | | } |
| | | // 要出物品的仓库id |
| | | Integer outWarehouseType = lWhFormOutput.getOutWarehouseType(); |
| | | Long outWarehouseId = lWhFormOutput.getWarehouseId(); |
| | | String warehouseName = lWhFormOutput.getWarehouseName(); |
| | | |
| | |
| | | whGoodsRecord.setThisCount(counts); |
| | | |
| | | //通过LockManage获得锁 |
| | | Object warehouseModelLockObj = LockManage.acquireLock(outWarehouseId, baseGoodsModelsId); |
| | | Object warehouseModelLockObj = LockManage.acquireLock(outWarehouseType, outWarehouseId, baseGoodsModelsId); |
| | | synchronized (warehouseModelLockObj) { |
| | | // 获得锁后查询该型号的期初数量 |
| | | int goodsModelNum = lWhGoodsService.queryGoodsModelNum(outWarehouseId, baseGoodsModelsId, queryModelStatus, buyType); |
| | | int goodsModelNum = lWhGoodsService.queryGoodsModelNum(outWarehouseType, outWarehouseId, baseGoodsModelsId, queryModelStatus, buyType); |
| | | if (goodsModelNum < counts) { |
| | | log.error("出库失败!型号{} 的数量不足,需要调拨{}个,仓库中现存{}个", baseGoodsModelsId, counts, goodsModelNum); |
| | | // 手动回滚 |
| | |
| | | whGoodsRecord.setEndCount(goodsModelNum - counts); |
| | | |
| | | //出库时候,按 先入库的先出库,同时入库的,按价格高的先出库 |
| | | List<Long> outGoodsId = lWhGoodsService.queryOutGoodsId(outWarehouseId, baseGoodsModelsId, queryModelStatus, buyType, goodsModelNum); |
| | | lWhGoodsService.modGoodsTransfering(outGoodsId, inWarehouseId, inWarehouseName, modGoodsTransferingStatus); |
| | | List<Long> outGoodsId = lWhGoodsService.queryOutGoodsId(outWarehouseType, outWarehouseId, baseGoodsModelsId, queryModelStatus, buyType, goodsModelNum); |
| | | lWhGoodsService.modGoodsTransfering(outGoodsId, outWarehouseType, inWarehouseId, inWarehouseName, modGoodsTransferingStatus); |
| | | // 批量插入 进出库流水明细[L_WH_GOODS_RECORD_DETAILS] |
| | | sameGoodsInsertMore(outGoodsId, whGoodsRecordId, (short) 0); |
| | | lWhGoodsRecordDetailsService.sameGoodsInsertMore(outGoodsId, whGoodsRecordId, (short) 0); |
| | | lWhGoodsRecordService.insert(whGoodsRecord); |
| | | } |
| | | }); |
| | | LWarehouseFlow warehouseFlow = new LWarehouseFlow(); |
| | |
| | | return lWarehouseFlowId; |
| | | } |
| | | |
| | | public void sameGoodsInsertMore(List<Long> outGoodsId, long whGoodsRecordId, short thisType) { |
| | | SqlParameterSource in = new MapSqlParameterSource() |
| | | .addValue("WHGOODSIDList", StringUtils.join(outGoodsId)) |
| | | .addValue("WH_GOODS_RECORD_ID", whGoodsRecordId) |
| | | .addValue("THIS_TYPE", thisType); |
| | | |
| | | Map<String, Object> out = simpleJdbcCall.execute(in); |
| | | System.out.println("Procedure result: " + out); |
| | | } |
| | | } |