diff --git a/mallinkAdmin/src/main/resources/db/migration/V202407019.sql b/mallinkAdmin/src/main/resources/db/migration/V202407019.sql index d5add412e..80ffe4bbe 100644 --- a/mallinkAdmin/src/main/resources/db/migration/V202407019.sql +++ b/mallinkAdmin/src/main/resources/db/migration/V202407019.sql @@ -806,6 +806,107 @@ alter table wx_bill_other_deposit_97 add column set_off varchar(30) COMMENT alter table wx_bill_other_deposit_98 add column set_off varchar(30) COMMENT '抵扣金额'; alter table wx_bill_other_deposit_99 add column set_off varchar(30) COMMENT '抵扣金额'; +alter table wx_bill_daily_0 modify column price_detail text ; +alter table wx_bill_daily_1 modify column price_detail text ; +alter table wx_bill_daily_2 modify column price_detail text ; +alter table wx_bill_daily_3 modify column price_detail text ; +alter table wx_bill_daily_4 modify column price_detail text ; +alter table wx_bill_daily_5 modify column price_detail text ; +alter table wx_bill_daily_6 modify column price_detail text ; +alter table wx_bill_daily_7 modify column price_detail text ; +alter table wx_bill_daily_8 modify column price_detail text ; +alter table wx_bill_daily_9 modify column price_detail text ; +alter table wx_bill_daily_10 modify column price_detail text ; +alter table wx_bill_daily_11 modify column price_detail text ; +alter table wx_bill_daily_12 modify column price_detail text ; +alter table wx_bill_daily_13 modify column price_detail text ; +alter table wx_bill_daily_14 modify column price_detail text ; +alter table wx_bill_daily_15 modify column price_detail text ; +alter table wx_bill_daily_16 modify column price_detail text ; +alter table wx_bill_daily_17 modify column price_detail text ; +alter table wx_bill_daily_18 modify column price_detail text ; +alter table wx_bill_daily_19 modify column price_detail text ; +alter table wx_bill_daily_20 modify column price_detail text ; +alter table wx_bill_daily_21 modify column price_detail text ; +alter table wx_bill_daily_22 modify column price_detail text ; +alter table wx_bill_daily_23 modify column price_detail text ; +alter table wx_bill_daily_24 modify column price_detail text ; +alter table wx_bill_daily_25 modify column price_detail text ; +alter table wx_bill_daily_26 modify column price_detail text ; +alter table wx_bill_daily_27 modify column price_detail text ; +alter table wx_bill_daily_28 modify column price_detail text ; +alter table wx_bill_daily_29 modify column price_detail text ; +alter table wx_bill_daily_30 modify column price_detail text ; +alter table wx_bill_daily_31 modify column price_detail text ; +alter table wx_bill_daily_32 modify column price_detail text ; +alter table wx_bill_daily_33 modify column price_detail text ; +alter table wx_bill_daily_34 modify column price_detail text ; +alter table wx_bill_daily_35 modify column price_detail text ; +alter table wx_bill_daily_36 modify column price_detail text ; +alter table wx_bill_daily_37 modify column price_detail text ; +alter table wx_bill_daily_38 modify column price_detail text ; +alter table wx_bill_daily_39 modify column price_detail text ; +alter table wx_bill_daily_40 modify column price_detail text ; +alter table wx_bill_daily_41 modify column price_detail text ; +alter table wx_bill_daily_42 modify column price_detail text ; +alter table wx_bill_daily_43 modify column price_detail text ; +alter table wx_bill_daily_44 modify column price_detail text ; +alter table wx_bill_daily_45 modify column price_detail text ; +alter table wx_bill_daily_46 modify column price_detail text ; +alter table wx_bill_daily_47 modify column price_detail text ; +alter table wx_bill_daily_48 modify column price_detail text ; +alter table wx_bill_daily_49 modify column price_detail text ; +alter table wx_bill_daily_50 modify column price_detail text ; +alter table wx_bill_daily_51 modify column price_detail text ; +alter table wx_bill_daily_52 modify column price_detail text ; +alter table wx_bill_daily_53 modify column price_detail text ; +alter table wx_bill_daily_54 modify column price_detail text ; +alter table wx_bill_daily_55 modify column price_detail text ; +alter table wx_bill_daily_56 modify column price_detail text ; +alter table wx_bill_daily_57 modify column price_detail text ; +alter table wx_bill_daily_58 modify column price_detail text ; +alter table wx_bill_daily_59 modify column price_detail text ; +alter table wx_bill_daily_60 modify column price_detail text ; +alter table wx_bill_daily_61 modify column price_detail text ; +alter table wx_bill_daily_62 modify column price_detail text ; +alter table wx_bill_daily_63 modify column price_detail text ; +alter table wx_bill_daily_64 modify column price_detail text ; +alter table wx_bill_daily_65 modify column price_detail text ; +alter table wx_bill_daily_66 modify column price_detail text ; +alter table wx_bill_daily_67 modify column price_detail text ; +alter table wx_bill_daily_68 modify column price_detail text ; +alter table wx_bill_daily_69 modify column price_detail text ; +alter table wx_bill_daily_70 modify column price_detail text ; +alter table wx_bill_daily_71 modify column price_detail text ; +alter table wx_bill_daily_72 modify column price_detail text ; +alter table wx_bill_daily_73 modify column price_detail text ; +alter table wx_bill_daily_74 modify column price_detail text ; +alter table wx_bill_daily_75 modify column price_detail text ; +alter table wx_bill_daily_76 modify column price_detail text ; +alter table wx_bill_daily_77 modify column price_detail text ; +alter table wx_bill_daily_78 modify column price_detail text ; +alter table wx_bill_daily_79 modify column price_detail text ; +alter table wx_bill_daily_80 modify column price_detail text ; +alter table wx_bill_daily_81 modify column price_detail text ; +alter table wx_bill_daily_82 modify column price_detail text ; +alter table wx_bill_daily_83 modify column price_detail text ; +alter table wx_bill_daily_84 modify column price_detail text ; +alter table wx_bill_daily_85 modify column price_detail text ; +alter table wx_bill_daily_86 modify column price_detail text ; +alter table wx_bill_daily_87 modify column price_detail text ; +alter table wx_bill_daily_88 modify column price_detail text ; +alter table wx_bill_daily_89 modify column price_detail text ; +alter table wx_bill_daily_90 modify column price_detail text ; +alter table wx_bill_daily_91 modify column price_detail text ; +alter table wx_bill_daily_92 modify column price_detail text ; +alter table wx_bill_daily_93 modify column price_detail text ; +alter table wx_bill_daily_94 modify column price_detail text ; +alter table wx_bill_daily_95 modify column price_detail text ; +alter table wx_bill_daily_96 modify column price_detail text ; +alter table wx_bill_daily_97 modify column price_detail text ; +alter table wx_bill_daily_98 modify column price_detail text ; +alter table wx_bill_daily_99 modify column price_detail text ; + diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxEnergyMeterReadingMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxEnergyMeterReadingMapper.java index d73660882..3750cd4dd 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxEnergyMeterReadingMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxEnergyMeterReadingMapper.java @@ -17,7 +17,7 @@ public interface WxEnergyMeterReadingMapper extends CommonMapper findBuildingSumMoney(WxEnergyMeterReading wxBillRent); + List findBuildingSumMoney(WxEnergyMeterReading wxBillRent); - Map findFloorSumMoney(WxEnergyMeterReading wxBillRent); + List findFloorSumMoney(WxEnergyMeterReading wxBillRent); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxEnergyServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxEnergyServiceImpl.java index 6e9236634..2a487cf10 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxEnergyServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxEnergyServiceImpl.java @@ -794,6 +794,31 @@ public class WxEnergyServiceImpl implements WxEnergyService { } } + private Map getFloorBuildingMoney(WxEnergyMeterReading reading,boolean isFloor) { + List list = null; + if (isFloor) { + list = wxEnergyMeterReadingMapper.findFloorSumMoney(reading); + }else { + wxEnergyMeterReadingMapper.findBuildingSumMoney(reading); + } + + if (null != list && list.size() > 0 ) { + Map buildinMap = new HashMap(); + for (int i = 0 ; i < list.size() ; i++) { + Map bup = list.get(i); + BigDecimal are = (BigDecimal)bup.get("money"); + if (null != are) { + buildinMap.put((Long)bup.get("building_id"), are.toPlainString()); + }else { + buildinMap.put((Long)bup.get("building_id"), "0"); + } + + } + return buildinMap; + } + return null; + } + @Override public Integer calcuteReading(WxEnergyReadingCalcute record, MallUserInfo user) { //根据科目,区间,计算生成账单。 @@ -843,13 +868,17 @@ public class WxEnergyServiceImpl implements WxEnergyService { } String publicTotalArea = "0"; - String publicTotalMoney = "0"; + BigDecimal publicTotalMoney = new BigDecimal(0); + BigDecimal b0 = new BigDecimal(0); Map buildingFloorMoney = null; Map buildingFloorArea = null; if (fees.getPublicCalcute().intValue() == EnumEnergyPublicCalcuteRule.ALL.getCode().intValue()) { //全部就查询所有公共表的费用 reading.setIsPublic(EnumYesOrNo.YES.getCode()); - publicTotalMoney = wxEnergyMeterReadingMapper.findAllSumMoney(reading); + String publicMoney = wxEnergyMeterReadingMapper.findAllSumMoney(reading); + if (StringUtils.isNotBlank(publicMoney)) { + publicTotalMoney = new BigDecimal(publicMoney); + } //公摊总面积 WxMallFloor mf = new WxMallFloor(); mf.updateTenantInfo(record); @@ -864,7 +893,7 @@ public class WxEnergyServiceImpl implements WxEnergyService { }else if (fees.getPublicCalcute().intValue() == EnumEnergyPublicCalcuteRule.BUILDING.getCode().intValue()) { //如果是按楼栋计算,则要把每个楼栋的金额都要算出来 reading.setIsPublic(EnumYesOrNo.YES.getCode()); - buildingFloorMoney = wxEnergyMeterReadingMapper.findBuildingSumMoney(reading); + buildingFloorMoney = getFloorBuildingMoney(reading,false); //各楼座总面积 WxMallFloor mf = new WxMallFloor(); mf.updateTenantInfo(record); @@ -875,7 +904,7 @@ public class WxEnergyServiceImpl implements WxEnergyService { }else if (fees.getPublicCalcute().intValue() == EnumEnergyPublicCalcuteRule.FLOOR.getCode().intValue()) { //查询各楼层的费用 reading.setIsPublic(EnumYesOrNo.YES.getCode()); - buildingFloorMoney = wxEnergyMeterReadingMapper.findFloorSumMoney(reading); + buildingFloorMoney = getFloorBuildingMoney(reading,true); //各楼层面积 //各楼座总面积 WxMallFloor mf = new WxMallFloor(); @@ -886,69 +915,77 @@ public class WxEnergyServiceImpl implements WxEnergyService { } } - boolean allSuccess = true; List billList = new ArrayList(); for (int i = 0 ; i< readingList.size() ; i ++) { WxEnergyMeterReading mr = readingList.get(i); - try { - //用户表账单 - WxMerchant merchant = shopMerchantMap.get(mr.getShopId()); - if (null == merchant) { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"铺位["+mr.getShopNumber()+"]未找到出租商户"); - } - WxEnergyMeter meter = meterMap.get(mr.getMeterId()); - if (null == meter) { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"表["+mr.getMeterName()+"]不存在"); + //用户表账单 + WxMerchant merchant = shopMerchantMap.get(mr.getShopId()); + if (null == merchant) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"铺位["+mr.getShopNumber()+"]未找到出租商户"); + } + WxEnergyMeter meter = meterMap.get(mr.getMeterId()); + if (null == meter) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"表["+mr.getMeterName()+"]不存在"); + } + WxShop shop = shopMap.get(mr.getShopId()); + WxBillDaily userBill = mr.generateUserBill(record, merchant, user, meter); + userBill.setEnergyFeesId(fees.getId()); + if (null != userBill) { + billList.add(userBill); + } + /* + * 总表(分摊账单) + * 如果科目是根据总面积公摊,则根据总面积计算 + * 如果科目是根据楼栋公摊,则根据当前记录的楼栋面积计算 + * 如果科目是根据楼层公摊,则根据当前记录的楼层面积计算 + */ + WxBillDaily publicBill = null; + if (fees.getPublicCalcute().intValue() == EnumEnergyPublicCalcuteRule.ALL.getCode().intValue()) { + if (publicTotalMoney.compareTo(b0) > 0 ) { + String needPay = publicTotalMoney.multiply(new BigDecimal(shop.getRentArea())).divide(new BigDecimal(publicTotalArea)).setScale(2,RoundingMode.HALF_UP).toPlainString(); + publicBill = mr.generatePublicBill(record, merchant, user, needPay); } - WxShop shop = shopMap.get(mr.getShopId()); - WxBillDaily userBill = mr.generateUserBill(record, merchant, user, meter); - userBill.setEnergyFeesId(fees.getId()); - if (null != userBill) { - billList.add(userBill); + }else if (fees.getPublicCalcute().intValue() == EnumEnergyPublicCalcuteRule.BUILDING.getCode().intValue()) { + String buildingArea = buildingFloorArea.get(mr.getBuildingId()); + if (StringUtils.isBlank(buildingArea) || new BigDecimal(buildingArea).compareTo(new BigDecimal(0)) <= 0 ) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"楼层可用面积未配置完全。"); } - /* - * 总表(分摊账单) - * 如果科目是根据总面积公摊,则根据总面积计算 - * 如果科目是根据楼栋公摊,则根据当前记录的楼栋面积计算 - * 如果科目是根据楼层公摊,则根据当前记录的楼层面积计算 - */ - WxBillDaily publicBill = null; - if (fees.getPublicCalcute().intValue() == EnumEnergyPublicCalcuteRule.ALL.getCode().intValue()) { - String needPay = new BigDecimal(publicTotalMoney).multiply(new BigDecimal(shop.getRentArea())).divide(new BigDecimal(publicTotalArea)).setScale(2,RoundingMode.HALF_UP).toPlainString(); - publicBill = mr.generatePublicBill(record, merchant, user, needPay); - }else if (fees.getPublicCalcute().intValue() == EnumEnergyPublicCalcuteRule.BUILDING.getCode().intValue()) { - String buildingArea = buildingFloorArea.get(mr.getBuildingId()); - if (StringUtils.isBlank(buildingArea) || new BigDecimal(buildingArea).compareTo(new BigDecimal(0)) <= 0 ) { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"楼层可用面积未配置完全。"); - } - String buildingMoney = buildingFloorMoney.get(mr.getBuildingId()); - if (StringUtils.isBlank(buildingMoney) || new BigDecimal(buildingMoney).compareTo(new BigDecimal(0)) <= 0 ) { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"楼栋总费用未获取到。"); - } - String needPay = new BigDecimal(buildingMoney).multiply(new BigDecimal(shop.getRentArea())).divide(new BigDecimal(buildingArea)).setScale(2,RoundingMode.HALF_UP).toPlainString(); - publicBill = mr.generatePublicBill(record, merchant, user, needPay); - }else if (fees.getPublicCalcute().intValue() == EnumEnergyPublicCalcuteRule.FLOOR.getCode().intValue()) { - String floorArea = buildingFloorArea.get(mr.getFloorId()); - if (StringUtils.isBlank(floorArea) || new BigDecimal(floorArea).compareTo(new BigDecimal(0)) <= 0 ) { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"楼层可用面积未配置完全。"); - } - String floorMoney = buildingFloorMoney.get(mr.getFloorId()); - if (StringUtils.isBlank(floorMoney) || new BigDecimal(floorMoney).compareTo(new BigDecimal(0)) <= 0 ) { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"楼栋总费用未获取到。"); + BigDecimal buildingMoney = new BigDecimal(0); + if (null != buildingFloorMoney ) { + String bMoney = buildingFloorMoney.get(mr.getBuildingId()); + if (StringUtils.isNotBlank(bMoney)) { + buildingMoney = new BigDecimal(bMoney); } - String needPay = new BigDecimal(floorMoney).multiply(new BigDecimal(shop.getRentArea())).divide(new BigDecimal(floorArea)).setScale(2,RoundingMode.HALF_UP).toPlainString(); + } + if (buildingMoney.compareTo(b0) > 0 ) { + String needPay = buildingMoney.multiply(new BigDecimal(shop.getRentArea())).divide(new BigDecimal(buildingArea)).setScale(2,RoundingMode.HALF_UP).toPlainString(); publicBill = mr.generatePublicBill(record, merchant, user, needPay); } + }else if (fees.getPublicCalcute().intValue() == EnumEnergyPublicCalcuteRule.FLOOR.getCode().intValue()) { + String floorArea = buildingFloorArea.get(mr.getFloorId()); + if (StringUtils.isBlank(floorArea) || new BigDecimal(floorArea).compareTo(new BigDecimal(0)) <= 0 ) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"楼层可用面积未配置完全。"); + } - if (null != publicBill) { - publicBill.setEnergyFeesId(fees.getId()); - billList.add(publicBill); + BigDecimal floorMoney = new BigDecimal(0); + if (null != buildingFloorMoney ) { + String fMoney = buildingFloorMoney.get(mr.getFloorId()); + if (StringUtils.isNotBlank(fMoney)) { + floorMoney = new BigDecimal(fMoney); + } } - }catch(Exception e) { - logger.error("计算失败:"+mr.getId(),e); - allSuccess = false; + if (floorMoney.compareTo(b0) > 0 ) { + String needPay = floorMoney.multiply(new BigDecimal(shop.getRentArea())).divide(new BigDecimal(floorArea)).setScale(2,RoundingMode.HALF_UP).toPlainString(); + publicBill = mr.generatePublicBill(record, merchant, user, needPay); + } + } + + if (null != publicBill) { + publicBill.setEnergyFeesId(fees.getId()); + billList.add(publicBill); } } + boolean allSuccess = true; if (billList.size() > 0 ) { try { //先把之前的未付的账单全部删除掉,已支付的账单先不处理 @@ -960,7 +997,6 @@ public class WxEnergyServiceImpl implements WxEnergyService { }catch(Exception e) { logger.error("insert bills error.",e); allSuccess = false; - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"生成账单失败,请重试。"); } WxEnergyReadingCalcute c = new WxEnergyReadingCalcute(); c.updateTenantInfo(record);