diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/StockTakingServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/StockTakingServiceImpl.java index 99269e8f..894bfa9d 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/StockTakingServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/StockTakingServiceImpl.java @@ -750,7 +750,8 @@ public class StockTakingServiceImpl implements StockTakingService { // 更新物料与库位对应关系的数量 placeAndMaterialByMidAndPid.setQuantity(newNumberForMatrialAndPlace); - } else { + } + else { // 如果是拆单单位 // 更新当前库位数量 newNumberForPlace = placeById.getQuantity() + inventory; @@ -772,50 +773,56 @@ public class StockTakingServiceImpl implements StockTakingService { // 查找当前拆单记录对应的库存记录 SplitInventory splitInventory = splitUnitService.findSplitInventoryByIidAndSid(placeAndMaterialByMidAndPid.getId(), splitInfo.getId()); - int realQuantity = Math.round(inventory) + splitInventory.getSaveQuantity(); - // 定义当前进制 - int scale = splitInfo.getQuantity(); - if (realQuantity >= scale) { - // 如果当前盘点的数量大于拆单规定的进制数量 + if(splitInventory != null){ + int realQuantity = Math.round(inventory) + splitInventory.getSaveQuantity(); + // 定义当前进制 + int scale = splitInfo.getQuantity(); + if (realQuantity >= scale) { + // 如果当前盘点的数量大于拆单规定的进制数量 + // 计算当前进制下的进位数量 + int disposeQuantity = (int) Math.round(Math.floor((double) inventory / scale)); - // 计算当前进制下的进位数量 - int disposeQuantity = (int) Math.round(Math.floor((double) inventory / scale)); + // 计算要进的数目 + int quantity_in = (realQuantity / scale); + // 更新处理数量 + disposeQuantity += quantity_in; - // 计算要进的数目 - int quantity_in = (realQuantity / scale); - // 更新处理数量 - disposeQuantity += quantity_in; + // 当前盘点后实际数量 + realQuantity = realQuantity - quantity_in * scale; - // 当前盘点后实际数量 - realQuantity = realQuantity - quantity_in * scale; + // 设置当前数量为实际数量 + splitInventory.setSaveQuantity(realQuantity); - // 设置当前数量为实际数量 - splitInventory.setSaveQuantity(realQuantity); + // 修改当前拆单库存 + splitUnitMapper.updateSplitInventory(splitInventory); + if (splitInfo.getParentId() != null) { + SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); + map.put("price", String.valueOf(inventoryById.getPrice() / 100)); + map.put("quantity", String.valueOf(disposeQuantity)); + splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, placeAndMaterialByMidAndPid.getId(), map, inventory, splitInfo); + } else { + placeById.setQuantity(placeById.getQuantity() + disposeQuantity); + placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() + disposeQuantity); + } - // 修改当前拆单库存 - splitUnitMapper.updateSplitInventory(splitInventory); - if (splitInfo.getParentId() != null) { - SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); - map.put("price", String.valueOf(inventoryById.getPrice() / 100)); - map.put("quantity", String.valueOf(disposeQuantity)); - splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, placeAndMaterialByMidAndPid.getId(), map, inventory, splitInfo); - } else { - placeById.setQuantity(placeById.getQuantity() + disposeQuantity); - placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() + disposeQuantity); } + else { + // 如果不需要进位 - } else { - // 如果不需要进位 - - // 修改当前库存 - splitInventory.setSaveQuantity(realQuantity); - // 修改拆单库存 - splitUnitMapper.updateSplitInventory(splitInventory); + // 修改当前库存 + splitInventory.setSaveQuantity(realQuantity); + // 修改拆单库存 + splitUnitMapper.updateSplitInventory(splitInventory); + } + }else{ + int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); } + } - } else { + } + else { // 如果盘亏 if ("-1".equals(unit)) { @@ -840,7 +847,8 @@ public class StockTakingServiceImpl implements StockTakingService { placeAndMaterialByMidAndPid.setQuantity(newNumberForMatrialAndPlace); - } else { + } + else { // 如果是拆单单位 // 用于查找对应的拆单记录 Map paramForSplitInfo = new HashMap<>(); @@ -1166,7 +1174,8 @@ public class StockTakingServiceImpl implements StockTakingService { // 更新物料与库位对应关系的数量 placeAndMaterialByMidAndPid.setQuantity(newNumberForMatrialAndPlace); - } else { + } + else { // 如果是拆单单位 // 更新当前库位数量 newNumberForPlace = placeById.getQuantity() + inventory; @@ -1188,50 +1197,74 @@ public class StockTakingServiceImpl implements StockTakingService { // 查找当前拆单记录对应的库存记录 SplitInventory splitInventory = splitUnitService.findSplitInventoryByIidAndSid(placeAndMaterialByMidAndPid.getId(), splitInfo.getId()); - int realQuantity = Math.round(inventory) + splitInventory.getSaveQuantity(); - // 定义当前进制 - int scale = splitInfo.getQuantity(); - if (realQuantity >= scale) { - // 如果当前盘点的数量大于拆单规定的进制数量 + if(splitInventory != null){ + int realQuantity = Math.round(inventory) + splitInventory.getSaveQuantity(); + // 定义当前进制 + int scale = splitInfo.getQuantity(); + if (realQuantity >= scale) { + // 如果当前盘点的数量大于拆单规定的进制数量 - // 计算当前进制下的进位数量 - int disposeQuantity = (int) Math.round(Math.floor((double) inventory / scale)); + // 计算当前进制下的进位数量 + int disposeQuantity = (int) Math.round(Math.floor((double) inventory / scale)); - // 计算要进的数目 - int quantity_in = (realQuantity / scale); - // 更新处理数量 - disposeQuantity += quantity_in; + // 计算要进的数目 + int quantity_in = (realQuantity / scale); + // 更新处理数量 + disposeQuantity += quantity_in; - // 当前盘点后实际数量 - realQuantity = realQuantity - quantity_in * scale; + // 当前盘点后实际数量 + realQuantity = realQuantity - quantity_in * scale; - // 设置当前数量为实际数量 - splitInventory.setSaveQuantity(realQuantity); + // 设置当前数量为实际数量 + splitInventory.setSaveQuantity(realQuantity); + + // 修改当前拆单库存 + splitUnitMapper.updateSplitInventory(splitInventory); + if (splitInfo.getParentId() != null) { + SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); + map.put("price", String.valueOf(inventoryById.getPrice() / 100)); + map.put("quantity", String.valueOf(disposeQuantity)); + splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, placeAndMaterialByMidAndPid.getId(), map, inventory, splitInfo); + } else { + placeById.setQuantity(placeById.getQuantity() + disposeQuantity); + placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() + disposeQuantity); + } - // 修改当前拆单库存 - splitUnitMapper.updateSplitInventory(splitInventory); - if (splitInfo.getParentId() != null) { - SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); - map.put("price", String.valueOf(inventoryById.getPrice() / 100)); - map.put("quantity", String.valueOf(disposeQuantity)); - splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, disposeQuantity, placeAndMaterialByMidAndPid.getId(), map, inventory, splitInfo); - } else { - placeById.setQuantity(placeById.getQuantity() + disposeQuantity); - placeAndMaterialByMidAndPid.setQuantity(placeAndMaterialByMidAndPid.getQuantity() + disposeQuantity); } + else { + // 如果不需要进位 - } else { - // 如果不需要进位 + // 修改当前库存 + splitInventory.setSaveQuantity(realQuantity); + // 修改拆单库存 + splitUnitMapper.updateSplitInventory(splitInventory); + } + } + else{ + + // 获取进制数目 + int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); + + Map insertForSplitInventory = new HashMap<>(); + + insertForSplitInventory.put("mid",inventoryById.getMid()); + insertForSplitInventory.put("mcode",inventoryById.getCode()); + insertForSplitInventory.put("price",inventoryById.getPrice() / scale); + insertForSplitInventory.put("quantity",inventory); + insertForSplitInventory.put("unit",unit); + insertForSplitInventory.put("depositoryId",mainRecord.getDepositoryId()); + insertForSplitInventory.put("placeId",placeAndMaterialByMidAndPid.getPid()); + insertForSplitInventory.put("type","in"); + splitUnitService.addSplitInventory(insertForSplitInventory); + Integer new_id = ObjectFormatUtil.toInteger(insertForSplitInventory.get("newInMid")); + depositoryRecordMapper.deleteApplicationInRecordById(new_id); - // 修改当前库存 - splitInventory.setSaveQuantity(realQuantity); - // 修改拆单库存 - splitUnitMapper.updateSplitInventory(splitInventory); } } - } else { + } + else { // 如果盘亏 if ("-1".equals(unit)) { @@ -1256,7 +1289,8 @@ public class StockTakingServiceImpl implements StockTakingService { placeAndMaterialByMidAndPid.setQuantity(newNumberForMatrialAndPlace); - } else { + } + else { // 如果是拆单单位 // 用于查找对应的拆单记录 @@ -1269,21 +1303,53 @@ public class StockTakingServiceImpl implements StockTakingService { // 查找当前拆单记录对应的库存记录 SplitInventory splitInventory = splitUnitService.findSplitInventoryByIidAndSid(placeAndMaterialByMidAndPid.getId(), splitInfo.getId()); - if (splitInventory.getSaveQuantity() - inventory > 0) { - // 如果当前数量没有下溢 + if(splitInventory != null){ + // 如果存在拆单记录 + if (splitInventory.getSaveQuantity() - inventory > 0) { + // 如果当前数量没有下溢 - // 设置当前拆单库存的数量 - splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() - inventory); - // 修改拆单库存 - splitUnitMapper.updateSplitInventory(splitInventory); - } else { - // 如果发生下溢 + // 设置当前拆单库存的数量 + splitInventory.setSaveQuantity(splitInventory.getSaveQuantity() - inventory); + // 修改拆单库存 + splitUnitMapper.updateSplitInventory(splitInventory); + } + else { + // 如果发生下溢 - // 设置当前拆单库存的数量 - splitInventory.setSaveQuantity(0); - // 修改拆单库存 - splitUnitMapper.updateSplitInventory(splitInventory); + // 设置当前拆单库存的数量 + splitInventory.setSaveQuantity(0); + // 修改拆单库存 + splitUnitMapper.updateSplitInventory(splitInventory); + } + } else{ + // 如果不存在 + + + // 获取进制 + int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); + // 获取当前盘点数目 + int now_inventory = placeAndMaterialByMidAndPid.getQuantity() * scale; + + // 更新当前库存 + inventoryById.setQuantity(inventoryById.getQuantity() - placeAndMaterialByMidAndPid.getQuantity()); + placeAndMaterialByMidAndPid.setQuantity(0); + + // 当前盘点数目 + int new_inventory = now_inventory - inventory; + Map insertForSplitInventory = new HashMap<>(); + + insertForSplitInventory.put("mid",inventoryById.getMid()); + insertForSplitInventory.put("mcode",inventoryById.getCode()); + insertForSplitInventory.put("price",inventoryById.getPrice() / scale); + insertForSplitInventory.put("quantity",new_inventory); + insertForSplitInventory.put("unit",unit); + insertForSplitInventory.put("depositoryId",mainRecord.getDepositoryId()); + insertForSplitInventory.put("placeId",placeAndMaterialByMidAndPid.getPid()); + insertForSplitInventory.put("type","in"); + splitUnitService.addSplitInventory(insertForSplitInventory); + Integer new_id = ObjectFormatUtil.toInteger(insertForSplitInventory.get("newInMid")); + depositoryRecordMapper.deleteApplicationInRecordById(new_id); } @@ -1377,6 +1443,7 @@ public class StockTakingServiceImpl implements StockTakingService { StringBuilder QyWxUid = new StringBuilder(); + String stockTakingResult = "驳回"; // 获取主单 StockTaking mainRecord = stockTakingMapper.selectStockTakingById(ObjectFormatUtil.toInteger(mainId)); @@ -1421,8 +1488,6 @@ public class StockTakingServiceImpl implements StockTakingService { // 获取库位详情 Place placeById = placeMapper.findPlaceById(placeId); Integer depositoryId = mainRecord.getDepositoryId(); - // 获取仓库详情 - Depository depositoryById = depositoryMapper.findDepositoryById(depositoryId); // 获取所有子单 List minRecordList = stockTakingMapper.selectStockTakingChildByMainId(ObjectFormatUtil.toInteger(mainId));