|
|
|
@@ -794,6 +794,31 @@ public class WxEnergyServiceImpl implements WxEnergyService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Map<Long,String> getFloorBuildingMoney(WxEnergyMeterReading reading,boolean isFloor) { |
|
|
|
List<Map> list = null; |
|
|
|
if (isFloor) { |
|
|
|
list = wxEnergyMeterReadingMapper.findFloorSumMoney(reading); |
|
|
|
}else { |
|
|
|
wxEnergyMeterReadingMapper.findBuildingSumMoney(reading); |
|
|
|
} |
|
|
|
|
|
|
|
if (null != list && list.size() > 0 ) { |
|
|
|
Map<Long, String> buildinMap = new HashMap<Long, String>(); |
|
|
|
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<Long,String> buildingFloorMoney = null; |
|
|
|
Map<Long,String> 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<WxBillDaily> billList = new ArrayList<WxBillDaily>(); |
|
|
|
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); |
|
|
|
|