diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java index 550acd1c..fa885a54 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java @@ -419,23 +419,44 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { double priceForYesterDay = 0.0; for (ApplicationInRecord applicationInRecordP : applicationInRecordPForToday) { // 获取当前入库类型(1物料2组合) - Integer flagForGroup = applicationInRecordP.getFlagForGroup(); sumForToday += (double) applicationInRecordP.getQuantity() / 100; - if (applicationInRecordP.getPrice() != null) { - priceForToday += applicationInRecordP.getPrice() * (double) (applicationInRecordP.getQuantity() / 100); - } else { + + Integer mid = applicationInRecordP.getMid(); + Material materialById = materialMapper.findMaterialById(mid); + if (materialById.getPrice() != null) { priceForToday += 0; + } else { + if ("-1".equals(applicationInRecordP.getAirUnit()) || materialById.getUnit().equals(applicationInRecordP.getAirUnit())) { + priceForToday += materialById.getPrice() * (double) applicationInRecordP.getQuantity() / 100; + } else { + Map paramForSplitInfo = new HashMap<>(); + paramForSplitInfo.put("newUnit", applicationInRecordP.getAirUnit()); + paramForSplitInfo.put("mid", mid); + SplitInfo splitInfoByMidAndUnit = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo); + int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfoByMidAndUnit, -1); + priceForToday += materialById.getPrice() / scale * (double) applicationInRecordP.getQuantity() / 100; + } } - } for (ApplicationInRecord applicationInRecordP : applicationInRecordPForYesterday) { sumForYesterDay += (double) applicationInRecordP.getQuantity() / 100; - if (applicationInRecordP.getPrice() != null) { - priceForYesterDay += applicationInRecordP.getPrice() * (double) (applicationInRecordP.getQuantity() / 100); - } else { + Integer mid = applicationInRecordP.getMid(); + Material materialById = materialMapper.findMaterialById(mid); + if (materialById.getPrice() != null) { priceForYesterDay += 0; + } else { + if ("-1".equals(applicationInRecordP.getAirUnit()) || materialById.getUnit().equals(applicationInRecordP.getAirUnit())) { + priceForYesterDay += materialById.getPrice() * (double) applicationInRecordP.getQuantity() / 100; + } else { + Map paramForSplitInfo = new HashMap<>(); + paramForSplitInfo.put("newUnit", applicationInRecordP.getAirUnit()); + paramForSplitInfo.put("mid", mid); + SplitInfo splitInfoByMidAndUnit = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo); + int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfoByMidAndUnit, -1); + priceForYesterDay += materialById.getPrice() / scale * (double) applicationInRecordP.getQuantity() / 100; + } } } Map result = new HashMap<>(); @@ -536,7 +557,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { } catch (ExecutionException e) { e.printStackTrace(); } - countForToday += ObjectFormatUtil.toInteger(((Map) o).get("count")); + countForToday += ObjectFormatUtil.toDouble(((Map) o).get("count")); priceForToday += Double.parseDouble(((Map) o).get("price").toString()); } } @@ -592,25 +613,55 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { List applicationOutMinForCompleteForToday = depositoryRecordMapper.findApplicationOutMinForComplete(mapForToday); // 如果获取已经出库的数量(昨天) List applicationOutMinForCompleteForYesterday = depositoryRecordMapper.findApplicationOutMinForComplete(mapForYesterday); - for (int i = 0; i < applicationOutMinForCompleteForToday.size(); i++) { - ApplicationOutRecordMin recordMin = applicationOutMinForCompleteForToday.get(i); - countForToday += recordMin.getQuantity(); + for (ApplicationOutRecordMin recordMin : applicationOutMinForCompleteForToday) { + countForToday += (double) recordMin.getQuantity() / 100.0; // 获取当前出库物料 Inventory materialById = materialMapper.findInventoryById(recordMin.getMid()); - // 计算当前出库金额 - double price_out = materialById.getPrice() * recordMin.getQuantity(); + double quantity = (double) recordMin.getQuantity() / 100.0; + double price_out = 0.0; + if (recordMin.getUnit().equals(materialById.getUnit())) { + if (materialById.getPrice() != null) { + price_out = materialById.getPrice() * quantity; + } + } else { + Map paramForSplitInfo = new HashMap<>(); + paramForSplitInfo.put("newUnit", recordMin.getUnit()); + paramForSplitInfo.put("mid", materialById.getMid()); + SplitInfo splitInfo = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo); + int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); + if (materialById.getPrice() != null) { + price_out = materialById.getPrice() / scale * quantity; + } + } + + BigDecimal bg = new BigDecimal(price_out / 100); price_out = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); priceForToday += price_out; } - for (int i = 0; i < applicationOutMinForCompleteForYesterday.size(); i++) { - ApplicationOutRecordMin recordMin = applicationOutMinForCompleteForYesterday.get(i); - countForYesterday += recordMin.getQuantity(); + for (ApplicationOutRecordMin recordMin : applicationOutMinForCompleteForYesterday) { + countForYesterday += (double) recordMin.getQuantity() / 100.0; // 获取当前出库物料 - Material materialById = materialMapper.findMaterialById(recordMin.getMid()); - // 计算当前出库金额 - double price_out = materialById.getPrice() * recordMin.getQuantity(); + Inventory materialById = materialMapper.findInventoryById(recordMin.getMid()); + double quantity = (double) recordMin.getQuantity() / 100.0; + double price_out = 0.0; + if (recordMin.getUnit().equals(materialById.getUnit())) { + if (materialById.getPrice() != null) { + price_out = materialById.getPrice() * quantity; + } + } else { + Map paramForSplitInfo = new HashMap<>(); + paramForSplitInfo.put("newUnit", recordMin.getUnit()); + paramForSplitInfo.put("mid", materialById.getMid()); + SplitInfo splitInfo = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo); + int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); + if (materialById.getPrice() != null) { + price_out = materialById.getPrice() / scale * quantity; + } + } + + BigDecimal bg = new BigDecimal(price_out / 100); price_out = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); priceForYesterday += price_out; @@ -1394,7 +1445,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { insertForSplitInventory.put("flagForApproval", false); splitUnitService.addSplitInventory(insertForSplitInventory); - Integer new_id = ObjectFormatUtil.toInteger(insertForSplitInventory.get("newInMid")); + Integer new_id = ObjectFormatUtil.toInteger(insertForSplitInventory.get("applicationInIdForOut")); depositoryRecordMapper.deleteApplicationInRecordById(new_id); @@ -3042,7 +3093,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { // 如果当前入库的数量大于拆单规定的进制数量 // 计算要进的数目 - int quantity_in = (int)(realQuantity / splitInfo.getQuantity()); + int quantity_in = (int) (realQuantity / splitInfo.getQuantity()); // 更新处理数量 disposeQuantity += quantity_in; // 拆单库存实际入库的数量 @@ -3078,7 +3129,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { } else { applicationInPlace(map, true); // map.put("applicationInId", map.get("id")); - depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(map.get("id"))); + depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(map.get("applicationInId"))); // map.remove("id"); } @@ -3118,7 +3169,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { // 如果当前入库的数量大于拆单规定的进制数量 // 计算要进的数目 - int quantity_in = (int)(realQuantity / splitInfo.getQuantity()); + int quantity_in = (int) (realQuantity / splitInfo.getQuantity()); // 更新处理数量 disposeQuantity += quantity_in; // 拆单库存实际入库的数量 @@ -3281,7 +3332,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { // 如果当前入库的数量大于拆单规定的进制数量 // 计算要进的数目 - int quantity_in = (int)(realQuantity / splitInfo.getQuantity()); + int quantity_in = (int) (realQuantity / splitInfo.getQuantity()); // 更新处理数量 disposeQuantity += quantity_in; // 拆单库存实际入库的数量 @@ -3857,11 +3908,17 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { double sum = 0.0; double count = 0; for (ApplicationInRecord applicationInRecordP : applicationInRecordPAll) { - double price = 0.0; - if (applicationInRecordP.getPrice() != null) { - price = applicationInRecordP.getPrice(); + Material materialById = materialMapper.findMaterialById(applicationInRecordP.getMid()); + if ("-1".equals(applicationInRecordP.getAirUnit()) || materialById.getUnit().equals(applicationInRecordP.getAirUnit())) { + sum += materialById.getPrice() / 100 * (double) applicationInRecordP.getQuantity() / 100; + } else { + Map paramForSplitInfo = new HashMap<>(); + paramForSplitInfo.put("newUnit", applicationInRecordP.getAirUnit()); + paramForSplitInfo.put("mid", applicationInRecordP.getMid()); + SplitInfo splitInfoByMidAndUnit = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo); + int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfoByMidAndUnit, -1); + sum += materialById.getPrice() / scale / 100 * (double) applicationInRecordP.getQuantity() / 100; } - sum += price * applicationInRecordP.getQuantity() / 10000; count += (double) applicationInRecordP.getQuantity() / 100; } BigDecimal bg = new BigDecimal(sum); @@ -4385,7 +4442,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { insertForSplitInventory.put("placeId", placeAndMaterialByMidAndPid.getPid()); insertForSplitInventory.put("type", "in"); splitUnitService.addSplitInventory(insertForSplitInventory); - Integer new_id = ObjectFormatUtil.toInteger(insertForSplitInventory.get("newInMid")); + Integer new_id = ObjectFormatUtil.toInteger(insertForSplitInventory.get("applicationInId")); depositoryRecordMapper.deleteApplicationInRecordById(new_id); } } @@ -4601,9 +4658,22 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { Inventory materialById = materialMapper.findInventoryById(recordMin.getMid()); // 计算当前出库金额 double price_out = 0.0; - if (materialById.getPrice() != null) { - price_out = materialById.getPrice() * quantity; + if (recordMin.getUnit().equals(materialById.getUnit())) { + if (materialById.getPrice() != null) { + price_out = materialById.getPrice() * quantity; + } + } else { + Map paramForSplitInfo = new HashMap<>(); + paramForSplitInfo.put("newUnit", recordMin.getUnit()); + paramForSplitInfo.put("mid", materialById.getMid()); + SplitInfo splitInfo = splitUnitMapper.findSplitInfoByMidAndUnit(paramForSplitInfo); + int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); + if (materialById.getPrice() != null) { + price_out = materialById.getPrice() / scale * quantity; + } } + + BigDecimal bg = new BigDecimal(price_out / 100); price_out = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); price += price_out; diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/SplitUnitServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/SplitUnitServiceImpl.java index 58f35526..558cf0e2 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/SplitUnitServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/SplitUnitServiceImpl.java @@ -172,6 +172,7 @@ public class SplitUnitServiceImpl implements SplitUnitService { if ("in".equals(type) && !flagForApproval) { // 如果是入库并且不需要审批 result = realInInventoryToDepository(quantity, splitInventory, map, splitInfoForUnit, placeAndMaterialByMidAndPid, false); + map.put("applicationInIdForOut",map.get("applicationInId")); map.remove("applicationInId"); } else if ("in".equals(type)) { // 如果是入库且需要审批