|
@@ -1,72 +1,71 @@
|
|
|
-/*
|
|
|
- * 文 件 名: ChargingBillServiceImpl
|
|
|
- * 版 权: 浩鲸云计算科技股份有限公司
|
|
|
- * 描 述: <描述>
|
|
|
- * 修 改 人: lvwenbin
|
|
|
- * 修改时间: 2024/9/2
|
|
|
- * 跟踪单号: <跟踪单号>
|
|
|
- * 修改单号: <修改单号>
|
|
|
- * 修改内容: <修改内容>
|
|
|
- */
|
|
|
package com.ruoyi.ems.service.impl;
|
|
|
|
|
|
import com.huashe.common.utils.DateUtils;
|
|
|
import com.ruoyi.ems.domain.Area;
|
|
|
import com.ruoyi.ems.domain.AreaAttr;
|
|
|
-import com.ruoyi.ems.domain.ChargingBill;
|
|
|
import com.ruoyi.ems.domain.CoChargingConfig;
|
|
|
-import com.ruoyi.ems.domain.CoChargingConfigRel;
|
|
|
import com.ruoyi.ems.domain.MeterDevice;
|
|
|
-import com.ruoyi.ems.domain.MeterReading;
|
|
|
-import com.ruoyi.ems.enums.MeterObjTag;
|
|
|
import com.ruoyi.ems.enums.MeterObjType;
|
|
|
-import com.ruoyi.ems.mapper.AreaAttrMapper;
|
|
|
-import com.ruoyi.ems.mapper.AreaMapper;
|
|
|
+import com.ruoyi.ems.mapper.ElecConsumptionMapper;
|
|
|
import com.ruoyi.ems.mapper.MeterReadingMapper;
|
|
|
+import com.ruoyi.ems.mapper.WaterConsumptionMapper;
|
|
|
+import com.ruoyi.ems.model.ChargingBillVO;
|
|
|
+import com.ruoyi.ems.model.ElecConsumptionVO;
|
|
|
import com.ruoyi.ems.model.QueryChargingBill;
|
|
|
+import com.ruoyi.ems.model.QueryDevice;
|
|
|
import com.ruoyi.ems.model.QueryMeter;
|
|
|
+import com.ruoyi.ems.model.WaterConsumptionVO;
|
|
|
+import com.ruoyi.ems.service.IAreaAttrService;
|
|
|
+import com.ruoyi.ems.service.IAreaService;
|
|
|
import com.ruoyi.ems.service.IChargingBillService;
|
|
|
import com.ruoyi.ems.service.ICoChargingConfigService;
|
|
|
import com.ruoyi.ems.service.IMeterDeviceService;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.apache.commons.collections4.MapUtils;
|
|
|
+import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.YearMonth;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
-import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
- * 账单服务接口
|
|
|
- * <功能详细描述>
|
|
|
+ * 计费账单服务实现
|
|
|
*
|
|
|
- * @author lvwenbin
|
|
|
- * @version [版本号, 2024/9/2]
|
|
|
- * @see [相关类/方法]
|
|
|
- * @since [产品/模块版本]
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2024-12-20
|
|
|
*/
|
|
|
@Service
|
|
|
public class ChargingBillServiceImpl implements IChargingBillService {
|
|
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(ChargingBillServiceImpl.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
- private MeterReadingMapper meterReadingMapper;
|
|
|
+ private IAreaService areaService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAreaAttrService attrService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ElecConsumptionMapper elecConsumptionMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private AreaMapper areaMapper;
|
|
|
+ private WaterConsumptionMapper waterConsumptionMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private AreaAttrMapper areaAttrMapper;
|
|
|
+ private MeterReadingMapper meterReadingMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ICoChargingConfigService coChargingConfigService;
|
|
@@ -74,408 +73,648 @@ public class ChargingBillServiceImpl implements IChargingBillService {
|
|
|
@Autowired
|
|
|
private IMeterDeviceService meterDeviceService;
|
|
|
|
|
|
- /**
|
|
|
- * 查询商户计费账单列表
|
|
|
- *
|
|
|
- * @param queryParam 查询参数
|
|
|
- * @return 返回列表
|
|
|
- */
|
|
|
@Override
|
|
|
- public List<ChargingBill> selectCoChargingBill(QueryChargingBill queryParam) {
|
|
|
- // TODO 查询计费配置待改造,支持每个区域不同的计费方式,目前只支持园区级统一计费
|
|
|
- // 查询园区内部计费配置
|
|
|
- CoChargingConfig chargingCfg = coChargingConfigService.selectByArea(queryParam.getAreaCode());
|
|
|
+ public ChargingBillVO selectOverviewTotal(QueryChargingBill param) {
|
|
|
+ ChargingBillVO vo = new ChargingBillVO();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Area area = areaService.selectAreaByCode(param.getAreaCode());
|
|
|
+ CoChargingConfig config = coChargingConfigService.selectByArea(area.getAreaCode());
|
|
|
+ vo.setObjCode(param.getAreaCode());
|
|
|
+ vo.setObjName(area.getAreaName());
|
|
|
+ vo.setMeteredTime(param.getStartTime());
|
|
|
+
|
|
|
+ // 1. 商户自用数据计算
|
|
|
+ if (param.getIncludeAuto()) {
|
|
|
+ // 1.1 商户用电-自动抄表数据
|
|
|
+ List<MeterDevice> elecADevs = meterDeviceService.selectMeterDeviceByObj(area.getAreaCode(), 45, 0,
|
|
|
+ MeterObjType.METER_AREA, null);
|
|
|
+ ChargingBillVO.ElecAutoStatistics elecAStatistics = selectElecAutoStats(param, config, elecADevs);
|
|
|
+ vo.setElecAutoStats(elecAStatistics);
|
|
|
+
|
|
|
+ // 1.2 商户用水-自动抄表数据
|
|
|
+ List<MeterDevice> waterADevs = meterDeviceService.selectMeterDeviceByObj(area.getAreaCode(), 70, 0,
|
|
|
+ MeterObjType.METER_AREA, null);
|
|
|
+ ChargingBillVO.WaterStatistics waterAStatistics = selectWaterAutoStats(param, config, waterADevs);
|
|
|
+ vo.setWaterAutoStats(waterAStatistics);
|
|
|
+ }
|
|
|
|
|
|
- // 计算个户账单
|
|
|
- Map<String, ChargingBill> coBillMap = clacCoBill(queryParam, chargingCfg);
|
|
|
+ if (param.getIncludeManual()) {
|
|
|
+ // 1.3 商户用电-手动抄表数据
|
|
|
+ List<MeterDevice> elecMDevs = meterDeviceService.selectMeterDeviceByObj(area.getAreaCode(), 45, 1,
|
|
|
+ MeterObjType.METER_AREA, null);
|
|
|
+ ChargingBillVO.ElecManualStatistics elecMStatistics = selectElecManualStats(param, config, elecMDevs);
|
|
|
+ vo.setElecManualStats(elecMStatistics);
|
|
|
+
|
|
|
+ // 1.4 商户用水-手动抄表数据
|
|
|
+ List<MeterDevice> waterMDevs = meterDeviceService.selectMeterDeviceByObj(area.getAreaCode(), 70, 1,
|
|
|
+ MeterObjType.METER_AREA, null);
|
|
|
+ ChargingBillVO.WaterStatistics waterMStatistics = selectWaterManualStats(param, config, waterMDevs);
|
|
|
+ vo.setWaterManualStats(waterMStatistics);
|
|
|
+ }
|
|
|
|
|
|
- // 计算公摊账单
|
|
|
- Map<String, ChargingBill> sharedMap = clacSharedBill(queryParam, chargingCfg);
|
|
|
+ if (param.getIncludeShared()) {
|
|
|
+ // 2. 公摊数据计算
|
|
|
+ ChargingBillVO.SharedData sharedData = calculateSharedData(param, config, false);
|
|
|
+ vo.setSharedData(sharedData);
|
|
|
+ }
|
|
|
|
|
|
- return mergeBill(queryParam, coBillMap, sharedMap);
|
|
|
+ ChargingBillVO.TotalStatistics total = calculateTotal(vo);
|
|
|
+ vo.setTotalStats(total);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ logger.error("查询个总览异常", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<ChargingBill> selectTagChargingBill(QueryChargingBill queryParam) {
|
|
|
- // 查询园区内部计费配置
|
|
|
- CoChargingConfig chargingCfg = coChargingConfigService.selectByArea(queryParam.getAreaCode());
|
|
|
+ public List<ChargingBillVO> selectOverviewList(QueryChargingBill param) {
|
|
|
+ List<ChargingBillVO> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 解析时间范围
|
|
|
+ Date startDate = DateUtils.stringToDate(param.getStartTime(), "yyyyMM");
|
|
|
+ Date endDate = DateUtils.stringToDate(param.getEndTime(), "yyyyMM");
|
|
|
+
|
|
|
+ // 按月循环查询
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(startDate);
|
|
|
+
|
|
|
+ while (!calendar.getTime().after(endDate)) {
|
|
|
+ QueryChargingBill monthQuery = new QueryChargingBill();
|
|
|
+ BeanUtils.copyProperties(param, monthQuery);
|
|
|
+ String monthStr = DateUtils.dateToString(calendar.getTime(), "yyyyMM");
|
|
|
+ monthQuery.setStartTime(monthStr);
|
|
|
+ monthQuery.setEndTime(monthStr);
|
|
|
+
|
|
|
+ ChargingBillVO bill = selectOverviewTotal(monthQuery);
|
|
|
+ bill.setMeteredTime(monthStr);
|
|
|
+ resultList.add(bill);
|
|
|
+
|
|
|
+ // 下一个月
|
|
|
+ calendar.add(Calendar.MONTH, 1);
|
|
|
+ }
|
|
|
|
|
|
- Map<String, Long> individualMap = getQuantityByTag(queryParam, MeterObjTag.INDIVIDUAL);
|
|
|
- Map<String, Long> sharedMap = getQuantityByTag(queryParam, MeterObjTag.SHARED);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ logger.error("查询总览列表异常", e);
|
|
|
+ }
|
|
|
|
|
|
- List<ChargingBill> retList = new ArrayList<>();
|
|
|
- Date start = DateUtils.stringToDate(queryParam.getStartTime(), "yyyyMM");
|
|
|
- Date end = DateUtils.stringToDate(queryParam.getEndTime(), "yyyyMM");
|
|
|
- String objName = getObjName(queryParam);
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
|
|
|
- do {
|
|
|
- String time = DateUtils.dateToString(start, "yyyyMM");
|
|
|
+ @Override
|
|
|
+ public ChargingBillVO selectSellerEmsBill(QueryChargingBill param) {
|
|
|
+ ChargingBillVO vo = new ChargingBillVO();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Area area = areaService.selectAreaByCode(param.getAreaCode());
|
|
|
+ String rootArea = getRootArea(area);
|
|
|
+ CoChargingConfig config = coChargingConfigService.selectByArea(rootArea);
|
|
|
+ vo.setObjCode(param.getAreaCode());
|
|
|
+ vo.setObjName(area.getAreaName());
|
|
|
+ vo.setMeteredTime(param.getStartTime());
|
|
|
+
|
|
|
+ // 1. 商户自用数据计算
|
|
|
+ if (param.getIncludeAuto()) {
|
|
|
+ // 1.1 商户用电-自动抄表数据
|
|
|
+ List<MeterDevice> elecADevs = meterDeviceService.selectMeterDeviceByObj(rootArea, 45, 0,
|
|
|
+ MeterObjType.METER_AREA, param.getAreaCode());
|
|
|
+ ChargingBillVO.ElecAutoStatistics elecAStatistics = selectElecAutoStats(param, config, elecADevs);
|
|
|
+ vo.setElecAutoStats(elecAStatistics);
|
|
|
+
|
|
|
+ // 1.2 商户用水-自动抄表数据
|
|
|
+ List<MeterDevice> waterADevs = meterDeviceService.selectMeterDeviceByObj(rootArea, 70, 0,
|
|
|
+ MeterObjType.METER_AREA, param.getAreaCode());
|
|
|
+ ChargingBillVO.WaterStatistics waterAStatistics = selectWaterAutoStats(param, config, waterADevs);
|
|
|
+ vo.setWaterAutoStats(waterAStatistics);
|
|
|
+ }
|
|
|
|
|
|
- ChargingBill bill = new ChargingBill();
|
|
|
- bill.setObjCode(queryParam.getObjArea());
|
|
|
- bill.setMeteredTime(time);
|
|
|
- bill.setObjName(objName);
|
|
|
+ if (param.getIncludeManual()) {
|
|
|
+ // 1.3 商户用电-手动抄表数据
|
|
|
+ List<MeterDevice> elecMDevs = meterDeviceService.selectMeterDeviceByObj(rootArea, 45, 1,
|
|
|
+ MeterObjType.METER_AREA, param.getAreaCode());
|
|
|
+ ChargingBillVO.ElecManualStatistics elecMStatistics = selectElecManualStats(param, config, elecMDevs);
|
|
|
+ vo.setElecManualStats(elecMStatistics);
|
|
|
+
|
|
|
+ // 1.4 商户用水-手动抄表数据
|
|
|
+ List<MeterDevice> waterMDevs = meterDeviceService.selectMeterDeviceByObj(rootArea, 70, 1,
|
|
|
+ MeterObjType.METER_AREA, param.getAreaCode());
|
|
|
+ ChargingBillVO.WaterStatistics waterMStatistics = selectWaterManualStats(param, config, waterMDevs);
|
|
|
+ vo.setWaterManualStats(waterMStatistics);
|
|
|
+ }
|
|
|
|
|
|
- long individual = (null != individualMap.get(time)) ? individualMap.get(time) : 0L;
|
|
|
- bill.setMeteredValue((double) individual);
|
|
|
- bill.setMeteredPrice(calcPrice(queryParam.getMeterCls(), individual, chargingCfg));
|
|
|
+ if (param.getIncludeShared()) {
|
|
|
+ // 2. 公摊数据计算
|
|
|
+ ChargingBillVO.SharedData sharedData = calculateSharedData(param, config, true);
|
|
|
+ vo.setSharedData(sharedData);
|
|
|
+ }
|
|
|
|
|
|
- long shared = (null != sharedMap.get(time)) ? sharedMap.get(time) : 0L;
|
|
|
- bill.setSharedValue(shared);
|
|
|
- bill.setSharedPrice(calcPrice(queryParam.getMeterCls(), shared, chargingCfg));
|
|
|
+ ChargingBillVO.TotalStatistics total = calculateTotal(vo);
|
|
|
+ vo.setTotalStats(total);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ logger.error("查询个户账单异常", e);
|
|
|
+ }
|
|
|
|
|
|
- bill.setTotalValue(individual + shared);
|
|
|
- bill.setTotalPrice(clacTotalPrice(bill));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
|
|
|
- retList.add(bill);
|
|
|
+ @Override
|
|
|
+ public List<ChargingBillVO> selectSellerHistoryBills(QueryChargingBill param) {
|
|
|
+ List<ChargingBillVO> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 解析时间范围
|
|
|
+ Date startDate = DateUtils.stringToDate(param.getStartTime(), "yyyyMM");
|
|
|
+ Date endDate = DateUtils.stringToDate(param.getEndTime(), "yyyyMM");
|
|
|
+
|
|
|
+ // 按月循环查询
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(startDate);
|
|
|
+
|
|
|
+ while (!calendar.getTime().after(endDate)) {
|
|
|
+ QueryChargingBill monthQuery = new QueryChargingBill();
|
|
|
+ BeanUtils.copyProperties(param, monthQuery);
|
|
|
+ String monthStr = DateUtils.dateToString(calendar.getTime(), "yyyyMM");
|
|
|
+ monthQuery.setStartTime(monthStr);
|
|
|
+ monthQuery.setEndTime(monthStr);
|
|
|
+
|
|
|
+ ChargingBillVO bill = selectSellerEmsBill(monthQuery);
|
|
|
+ bill.setMeteredTime(monthStr);
|
|
|
+ resultList.add(bill);
|
|
|
+
|
|
|
+ // 下一个月
|
|
|
+ calendar.add(Calendar.MONTH, 1);
|
|
|
+ }
|
|
|
|
|
|
- start = DateUtils.adjustMonth(start, 1);
|
|
|
}
|
|
|
- while (start.before(end) || start.equals(end));
|
|
|
+ catch (Exception e) {
|
|
|
+ logger.error("查询历史账单列表异常", e);
|
|
|
+ }
|
|
|
|
|
|
- return retList;
|
|
|
+ return resultList;
|
|
|
}
|
|
|
|
|
|
- private List<ChargingBill> mergeBill(QueryChargingBill queryParam, Map<String, ChargingBill> coBillMap,
|
|
|
- Map<String, ChargingBill> sharedMap) {
|
|
|
- List<ChargingBill> retList = new ArrayList<>();
|
|
|
- Date start = DateUtils.stringToDate(queryParam.getStartTime(), "yyyyMM");
|
|
|
- Date end = DateUtils.stringToDate(queryParam.getEndTime(), "yyyyMM");
|
|
|
- String objName = getObjName(queryParam);
|
|
|
+ /**
|
|
|
+ * 商户用电-自动抄表数据统计
|
|
|
+ *
|
|
|
+ * @param param 查询条件
|
|
|
+ * @param elecADevs 商户绑定表计列表
|
|
|
+ * @return 商用用电-自动抄表数据统计
|
|
|
+ */
|
|
|
+ private ChargingBillVO.ElecAutoStatistics selectElecAutoStats(QueryChargingBill param, CoChargingConfig config,
|
|
|
+ List<MeterDevice> elecADevs) {
|
|
|
+ ChargingBillVO.ElecAutoStatistics stats = new ChargingBillVO.ElecAutoStatistics();
|
|
|
|
|
|
- do {
|
|
|
- String time = DateUtils.dateToString(start, "yyyyMM");
|
|
|
+ if (CollectionUtils.isNotEmpty(elecADevs)) {
|
|
|
+ // 构建查询参数
|
|
|
+ QueryMeter queryMeter = buildQueryMeter(param, 45);
|
|
|
|
|
|
- ChargingBill bill = new ChargingBill();
|
|
|
- bill.setObjCode(queryParam.getObjArea());
|
|
|
- bill.setMeteredTime(time);
|
|
|
- bill.setObjName(objName);
|
|
|
+ // 获取区域绑定的设备
|
|
|
+ Set<String> devices = elecADevs.stream().map(MeterDevice::getDeviceCode).collect(Collectors.toSet());
|
|
|
|
|
|
- ChargingBill coBill = coBillMap.get(time);
|
|
|
+ // 查询电量数据
|
|
|
+ ElecConsumptionVO consumption = elecConsumptionMapper.selectAreaElecConsumptionSummaryByDevices(queryMeter,
|
|
|
+ devices);
|
|
|
|
|
|
- if (null != coBill) {
|
|
|
- bill.setMeteredValue(coBill.getMeteredValue());
|
|
|
- bill.setMeteredPrice(coBill.getMeteredPrice());
|
|
|
+ if (consumption != null && consumption.getTotalElecQuantity() != null) {
|
|
|
+ BeanUtils.copyProperties(consumption, stats);
|
|
|
+ stats.setTotalQuantity(consumption.getTotalElecQuantity());
|
|
|
+ stats.setTotalCost(calculateCost(consumption.getTotalElecQuantity(), 45, config));
|
|
|
}
|
|
|
-
|
|
|
- ChargingBill sharedBill = sharedMap.get(time);
|
|
|
-
|
|
|
- if (null != sharedBill) {
|
|
|
- bill.setSharedPrice(sharedBill.getSharedPrice());
|
|
|
- bill.setSharedComputeType(sharedBill.getSharedComputeType());
|
|
|
+ else {
|
|
|
+ stats.setTotalQuantity(BigDecimal.ZERO);
|
|
|
+ stats.setTotalCost(BigDecimal.ZERO);
|
|
|
}
|
|
|
-
|
|
|
- bill.setTotalPrice(clacTotalPrice(bill));
|
|
|
-
|
|
|
- retList.add(bill);
|
|
|
-
|
|
|
- start = DateUtils.adjustMonth(start, 1);
|
|
|
}
|
|
|
- while (start.before(end) || start.equals(end));
|
|
|
+ else {
|
|
|
+ stats.setTotalQuantity(BigDecimal.ZERO);
|
|
|
+ stats.setTotalCost(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
|
|
|
- return retList;
|
|
|
+ return stats;
|
|
|
}
|
|
|
|
|
|
- private Map<String, ChargingBill> clacCoBill(QueryChargingBill queryParam, CoChargingConfig chargingCfg) {
|
|
|
- Map<String, ChargingBill> retMap = null;
|
|
|
+ /**
|
|
|
+ * 商户用水-自动抄表数据统计
|
|
|
+ *
|
|
|
+ * @param param 查询条件
|
|
|
+ * @param waterADevs 商户绑定表计列表
|
|
|
+ * @return 商用用水-自动抄表数据统计
|
|
|
+ */
|
|
|
+ private ChargingBillVO.WaterStatistics selectWaterAutoStats(QueryChargingBill param, CoChargingConfig config,
|
|
|
+ List<MeterDevice> waterADevs) {
|
|
|
+ ChargingBillVO.WaterStatistics stats = new ChargingBillVO.WaterStatistics();
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(waterADevs)) {
|
|
|
+ // 构建查询参数
|
|
|
+ QueryMeter queryMeter = buildQueryMeter(param, 70);
|
|
|
|
|
|
- List<MeterDevice> meterDevices = meterDeviceService.selectMeterDeviceByObj(queryParam.getAreaCode(), MeterObjType.METER_AREA, queryParam.getObjArea(),
|
|
|
- queryParam.getMeterCls());
|
|
|
+ // 获取区域绑定的设备
|
|
|
+ Set<String> devices = waterADevs.stream().map(MeterDevice::getDeviceCode).collect(Collectors.toSet());
|
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(meterDevices) ) {
|
|
|
- // TODO 当有多个设备时,需要融合计算
|
|
|
- MeterDevice meterDevice = meterDevices.get(0);
|
|
|
- QueryMeter recParam = new QueryMeter();
|
|
|
- recParam.setAreaCode(meterDevice.getAreaCode());
|
|
|
- recParam.setDeviceCode(meterDevice.getDeviceCode());
|
|
|
- recParam.setStartRecTime(queryParam.getStartTime());
|
|
|
- recParam.setEndRecTime(queryParam.getEndTime());
|
|
|
+ // 查询电量数据
|
|
|
+ WaterConsumptionVO consumption = waterConsumptionMapper.selectAreaWaterConsumptionSummaryByDevices(
|
|
|
+ queryMeter, devices);
|
|
|
|
|
|
- List<MeterReading> recList = meterReadingMapper.selectList(recParam);
|
|
|
- List<ChargingBill> billList = convertToChargingBill(queryParam, chargingCfg, recList);
|
|
|
- retMap = billList.stream().collect(Collectors.toMap(ChargingBill::getMeteredTime, Function.identity()));
|
|
|
+ if (consumption != null && consumption.getTotalWaterQuantity() != null) {
|
|
|
+ stats.setTotalQuantity(consumption.getTotalWaterQuantity());
|
|
|
+ stats.setTotalCost(calculateCost(consumption.getTotalWaterQuantity(), 70, config));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ stats.setTotalQuantity(BigDecimal.ZERO);
|
|
|
+ stats.setTotalCost(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ stats.setTotalQuantity(BigDecimal.ZERO);
|
|
|
+ stats.setTotalCost(BigDecimal.ZERO);
|
|
|
}
|
|
|
|
|
|
- return MapUtils.isNotEmpty(retMap) ? retMap : new HashMap<>();
|
|
|
+ return stats;
|
|
|
}
|
|
|
|
|
|
- private Map<String, ChargingBill> clacSharedBill(QueryChargingBill queryParam, CoChargingConfig chargingCfg) {
|
|
|
- Map<String, ChargingBill> retMap = null;
|
|
|
+ /**
|
|
|
+ * 商户用电-自动抄表数据统计
|
|
|
+ *
|
|
|
+ * @param param 查询条件
|
|
|
+ * @param elecMDevs 商户绑定表计列表
|
|
|
+ * @return 商用用电-手动动抄表数据统计
|
|
|
+ */
|
|
|
+ private ChargingBillVO.ElecManualStatistics selectElecManualStats(QueryChargingBill param, CoChargingConfig config,
|
|
|
+ List<MeterDevice> elecMDevs) {
|
|
|
+ ChargingBillVO.ElecManualStatistics stats = new ChargingBillVO.ElecManualStatistics();
|
|
|
|
|
|
- if (queryParam.getMeterCls() == 45) {
|
|
|
- retMap = clacElecSharedPrice(queryParam, chargingCfg);
|
|
|
- }
|
|
|
- else if (queryParam.getMeterCls() == 70) {
|
|
|
- retMap = clacWaterSharedPrice(queryParam, chargingCfg);
|
|
|
- }
|
|
|
+ if (CollectionUtils.isNotEmpty(elecMDevs)) {
|
|
|
+ QueryMeter queryMeter = new QueryMeter();
|
|
|
+ queryMeter.setAreaCode(param.getAreaCode());
|
|
|
+ queryMeter.setStartRecTime(param.getStartTime());
|
|
|
+ queryMeter.setEndRecTime(param.getEndTime());
|
|
|
|
|
|
- return MapUtils.isNotEmpty(retMap) ? retMap : new HashMap<>();
|
|
|
- }
|
|
|
+ // 获取区域绑定的设备
|
|
|
+ Set<String> devices = elecMDevs.stream().map(MeterDevice::getDeviceCode).collect(Collectors.toSet());
|
|
|
|
|
|
- private List<ChargingBill> convertToChargingBill(QueryChargingBill queryParam, CoChargingConfig chargingCfg,
|
|
|
- List<MeterReading> recList) {
|
|
|
- List<ChargingBill> retList = new ArrayList<>();
|
|
|
-
|
|
|
- for (MeterReading rec : recList) {
|
|
|
- ChargingBill bill = new ChargingBill();
|
|
|
- bill.setMeteredValue(rec.getIncrease().doubleValue());
|
|
|
- bill.setMeteredTime(rec.getMeterMonth());
|
|
|
-
|
|
|
- // 计算商户个体费用
|
|
|
- if (null != chargingCfg) {
|
|
|
- if (queryParam.getMeterCls() == 45) {
|
|
|
- bill.setMeteredPrice(calcPrice(rec.getIncrease(), chargingCfg.getElecUnitPrice()));
|
|
|
- }
|
|
|
- else if (queryParam.getMeterCls() == 70) {
|
|
|
- bill.setMeteredPrice(calcPrice(rec.getIncrease(), chargingCfg.getWaterUnitPrice()));
|
|
|
- }
|
|
|
- }
|
|
|
+ BigDecimal quantity = meterReadingMapper.selectSummaryByDevices(queryMeter, devices);
|
|
|
|
|
|
- retList.add(bill);
|
|
|
+ if (quantity != null) {
|
|
|
+ stats.setTotalQuantity(quantity);
|
|
|
+ stats.setTotalCost(calculateCost(quantity, 45, config));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ stats.setTotalQuantity(BigDecimal.ZERO);
|
|
|
+ stats.setTotalCost(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ stats.setTotalQuantity(BigDecimal.ZERO);
|
|
|
+ stats.setTotalCost(BigDecimal.ZERO);
|
|
|
}
|
|
|
|
|
|
- return retList;
|
|
|
+ return stats;
|
|
|
}
|
|
|
|
|
|
- private Map<String, ChargingBill> clacElecSharedPrice(QueryChargingBill queryParam, CoChargingConfig chargingCfg) {
|
|
|
- Map<String, ChargingBill> retMap = new HashMap<>();
|
|
|
- // 参与公摊的分区ID
|
|
|
- Set<String> coSet = getCoSet(chargingCfg);
|
|
|
-
|
|
|
- // 电价公摊计算
|
|
|
- if (chargingCfg.getElecGtComputeType() > 0 && coSet.contains(queryParam.getObjArea())) {
|
|
|
- QueryMeter param = new QueryMeter(queryParam.getAreaCode(), MeterObjTag.SHARED.getTagValue(),
|
|
|
- queryParam.getMeterCls(), queryParam.getStartTime(), queryParam.getEndTime());
|
|
|
- List<MeterReading> totalReadings = meterReadingMapper.selectByTag(param);
|
|
|
- Map<String, List<MeterReading>> groupedRecs = totalReadings.stream()
|
|
|
- .collect(Collectors.groupingBy(MeterReading::getMeterMonth));
|
|
|
+ /**
|
|
|
+ * 商户用水-手动抄表数据统计
|
|
|
+ *
|
|
|
+ * @param param 查询条件
|
|
|
+ * @param waterMDevs 商户绑定表计列表
|
|
|
+ * @return 商用用水-手动抄表数据统计
|
|
|
+ */
|
|
|
+ private ChargingBillVO.WaterStatistics selectWaterManualStats(QueryChargingBill param, CoChargingConfig config,
|
|
|
+ List<MeterDevice> waterMDevs) {
|
|
|
+ ChargingBillVO.WaterStatistics stats = new ChargingBillVO.WaterStatistics();
|
|
|
|
|
|
- for (Map.Entry<String, List<MeterReading>> entry : groupedRecs.entrySet()) {
|
|
|
- String meterTime = entry.getKey();
|
|
|
- List<MeterReading> sharedReadings = entry.getValue();
|
|
|
+ if (CollectionUtils.isNotEmpty(waterMDevs)) {
|
|
|
+ QueryMeter queryMeter = new QueryMeter();
|
|
|
+ queryMeter.setAreaCode(param.getAreaCode());
|
|
|
+ queryMeter.setStartRecTime(param.getStartTime());
|
|
|
+ queryMeter.setEndRecTime(param.getEndTime());
|
|
|
|
|
|
- // 公摊价格计算
|
|
|
- Double price = clacSharedPrice(sharedReadings, coSet, queryParam.getObjArea(),
|
|
|
- chargingCfg.getElecGtComputeType(), chargingCfg.getElecUnitPrice());
|
|
|
+ // 获取区域绑定的设备
|
|
|
+ Set<String> devices = waterMDevs.stream().map(MeterDevice::getDeviceCode).collect(Collectors.toSet());
|
|
|
|
|
|
- ChargingBill bill = new ChargingBill();
|
|
|
- bill.setSharedPrice(price);
|
|
|
- bill.setSharedComputeType(chargingCfg.getElecGtComputeType());
|
|
|
+ BigDecimal quantity = meterReadingMapper.selectSummaryByDevices(queryMeter, devices);
|
|
|
|
|
|
- retMap.put(meterTime, bill);
|
|
|
+ if (quantity != null) {
|
|
|
+ stats.setTotalQuantity(quantity);
|
|
|
+ stats.setTotalCost(calculateCost(quantity, 70, config));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ stats.setTotalQuantity(BigDecimal.ZERO);
|
|
|
+ stats.setTotalCost(BigDecimal.ZERO);
|
|
|
}
|
|
|
}
|
|
|
+ else {
|
|
|
+ stats.setTotalQuantity(BigDecimal.ZERO);
|
|
|
+ stats.setTotalCost(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
|
|
|
- return retMap;
|
|
|
+ return stats;
|
|
|
}
|
|
|
|
|
|
- private Map<String, ChargingBill> clacWaterSharedPrice(QueryChargingBill queryParam, CoChargingConfig chargingCfg) {
|
|
|
- Map<String, ChargingBill> retMap = new HashMap<>();
|
|
|
- // 参与公摊的分区ID
|
|
|
- Set<String> coSet = getCoSet(chargingCfg);
|
|
|
-
|
|
|
- // 水价公摊计算
|
|
|
- if (chargingCfg.getWaterGtComputeType() > 0 && coSet.contains(queryParam.getObjArea())) {
|
|
|
- QueryMeter param = new QueryMeter(queryParam.getAreaCode(), MeterObjTag.SHARED.getTagValue(),
|
|
|
- queryParam.getMeterCls(), queryParam.getStartTime(), queryParam.getEndTime());
|
|
|
- List<MeterReading> totalReadings = meterReadingMapper.selectByTag(param);
|
|
|
- Map<String, List<MeterReading>> groupedRecs = totalReadings.stream()
|
|
|
- .collect(Collectors.groupingBy(MeterReading::getMeterMonth));
|
|
|
-
|
|
|
- for (Map.Entry<String, List<MeterReading>> entry : groupedRecs.entrySet()) {
|
|
|
- String meterTime = entry.getKey();
|
|
|
- List<MeterReading> sharedReadings = entry.getValue();
|
|
|
-
|
|
|
- // 公摊价格计算
|
|
|
- Double price = clacSharedPrice(sharedReadings, coSet, queryParam.getObjArea(),
|
|
|
- chargingCfg.getWaterGtComputeType(), chargingCfg.getWaterUnitPrice());
|
|
|
-
|
|
|
- ChargingBill bill = new ChargingBill();
|
|
|
- bill.setObjCode(queryParam.getObjArea());
|
|
|
- bill.setSharedPrice(price);
|
|
|
- bill.setSharedComputeType(chargingCfg.getElecGtComputeType());
|
|
|
-
|
|
|
- retMap.put(meterTime, bill);
|
|
|
+ /**
|
|
|
+ * 计算公摊数据
|
|
|
+ */
|
|
|
+ private ChargingBillVO.SharedData calculateSharedData(QueryChargingBill param, CoChargingConfig config,
|
|
|
+ boolean isGtForArea) {
|
|
|
+ ChargingBillVO.SharedData sharedData = new ChargingBillVO.SharedData();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 1. 查询公摊用量
|
|
|
+ BigDecimal totalElecShared = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalWaterShared = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ // 查询公摊电表-自动表统计数据
|
|
|
+ QueryDevice queryElecMDev = buildQueryDev(param.getAreaCode(), 45, 1, 0);
|
|
|
+ List<MeterDevice> sharedElecMDevs = meterDeviceService.selectMeterDevByTag("MeterDev_Gt_45", queryElecMDev);
|
|
|
+ ChargingBillVO.ElecAutoStatistics elecAStatistics = selectElecAutoStats(param, config, sharedElecMDevs);
|
|
|
+ totalElecShared = totalElecShared.add(elecAStatistics.getTotalQuantity());
|
|
|
+
|
|
|
+ // 查询公摊电表-手动表统计数据
|
|
|
+ queryElecMDev = buildQueryDev(param.getAreaCode(), 45, 1, 1);
|
|
|
+ sharedElecMDevs = meterDeviceService.selectMeterDevByTag("MeterDev_Gt_45", queryElecMDev);
|
|
|
+ ChargingBillVO.ElecManualStatistics elecManualStatistics = selectElecManualStats(param, config,
|
|
|
+ sharedElecMDevs);
|
|
|
+ totalElecShared = totalElecShared.add(elecManualStatistics.getTotalQuantity());
|
|
|
+
|
|
|
+ // 查询公摊水表-自动表统计数据
|
|
|
+ QueryDevice queryWaterMDev = buildQueryDev(param.getAreaCode(), 70, 1, 0);
|
|
|
+ List<MeterDevice> sharedWaterMDevs = meterDeviceService.selectMeterDevByTag("MeterDev_Gt_70",
|
|
|
+ queryWaterMDev);
|
|
|
+ ChargingBillVO.WaterStatistics waterAStatistics = selectWaterAutoStats(param, config, sharedWaterMDevs);
|
|
|
+ totalWaterShared = totalWaterShared.add(waterAStatistics.getTotalQuantity());
|
|
|
+
|
|
|
+ // 查询公摊电表-手动表统计数据
|
|
|
+ queryWaterMDev = buildQueryDev(param.getAreaCode(), 70, 1, 1);
|
|
|
+ sharedWaterMDevs = meterDeviceService.selectMeterDevByTag("MeterDev_Gt_70", queryWaterMDev);
|
|
|
+ ChargingBillVO.WaterStatistics waterMStatistics = selectWaterManualStats(param, config, sharedWaterMDevs);
|
|
|
+ totalWaterShared = totalWaterShared.add(waterMStatistics.getTotalQuantity());
|
|
|
+
|
|
|
+ // 3. 计算当前区域应承担的公摊
|
|
|
+ if (isGtForArea) {
|
|
|
+ BigDecimal elecSharedForArea = calculateSharedForArea(totalElecShared, config.getElecGtComputeType(),
|
|
|
+ config.getAreaCode(), param.getAreaCode());
|
|
|
+ BigDecimal waterSharedForArea = calculateSharedForArea(totalWaterShared, config.getWaterGtComputeType(),
|
|
|
+ config.getAreaCode(), param.getAreaCode());
|
|
|
+
|
|
|
+ sharedData.setElecSharedQuantity(elecSharedForArea);
|
|
|
+ sharedData.setElecSharedCost(calculateCost(elecSharedForArea, 45, config));
|
|
|
+ sharedData.setWaterSharedQuantity(waterSharedForArea);
|
|
|
+ sharedData.setWaterSharedCost(calculateCost(waterSharedForArea, 70, config));
|
|
|
+ sharedData.setElecSharedType(config.getElecGtComputeType());
|
|
|
+ sharedData.setWaterSharedType(config.getWaterGtComputeType());
|
|
|
+ sharedData.setElecSharedTypeName(getSharedTypeName(config.getElecGtComputeType()));
|
|
|
+ sharedData.setWaterSharedTypeName(getSharedTypeName(config.getWaterGtComputeType()));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sharedData.setElecSharedQuantity(totalElecShared);
|
|
|
+ sharedData.setElecSharedCost(calculateCost(totalElecShared, 45, config));
|
|
|
+ sharedData.setWaterSharedQuantity(totalWaterShared);
|
|
|
+ sharedData.setWaterSharedCost(calculateCost(totalWaterShared, 70, config));
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
- return retMap;
|
|
|
- }
|
|
|
-
|
|
|
- private Map<String, Long> getQuantityByTag(QueryChargingBill queryParam, MeterObjTag tag) {
|
|
|
- Map<String, Long> retMap = new HashMap<>();
|
|
|
-
|
|
|
- QueryMeter param = new QueryMeter(queryParam.getAreaCode(), tag.getTagValue(),
|
|
|
- queryParam.getMeterCls(), queryParam.getStartTime(), queryParam.getEndTime());
|
|
|
- List<MeterReading> totalReadings = meterReadingMapper.selectByTag(param);
|
|
|
- Map<String, List<MeterReading>> groupedRecs = totalReadings.stream()
|
|
|
- .collect(Collectors.groupingBy(MeterReading::getMeterMonth));
|
|
|
-
|
|
|
- for (Map.Entry<String, List<MeterReading>> entry : groupedRecs.entrySet()) {
|
|
|
- String meterTime = entry.getKey();
|
|
|
- List<MeterReading> sharedReadings = entry.getValue();
|
|
|
-
|
|
|
- // 公摊用量
|
|
|
- Long sharedQuantity = sumSharedReadings(sharedReadings);
|
|
|
- retMap.put(meterTime, sharedQuantity);
|
|
|
+ catch (Exception e) {
|
|
|
+ logger.error("计算公摊数据异常", e);
|
|
|
}
|
|
|
|
|
|
- return retMap;
|
|
|
+ return sharedData;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 计算公摊价
|
|
|
- *
|
|
|
- * @return 价格
|
|
|
+ * 计算合计
|
|
|
*/
|
|
|
- private Double clacSharedPrice(List<MeterReading> sharedReadings, Set<String> coSet, String objCode,
|
|
|
- int gtComputeType, Double unitPrice) {
|
|
|
- double sharedPrice = 0.0;
|
|
|
+ private ChargingBillVO.TotalStatistics calculateTotal(ChargingBillVO billVO) {
|
|
|
+ ChargingBillVO.TotalStatistics total = new ChargingBillVO.TotalStatistics();
|
|
|
+
|
|
|
+ // 电量合计
|
|
|
+ BigDecimal elecQuantity = BigDecimal.ZERO;
|
|
|
+ BigDecimal elecCost = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ if (billVO.getElecAutoStats() != null) {
|
|
|
+ elecQuantity = elecQuantity.add(billVO.getElecAutoStats().getTotalQuantity() != null ?
|
|
|
+ billVO.getElecAutoStats().getTotalQuantity() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+ elecCost = elecCost.add(billVO.getElecAutoStats().getTotalCost() != null ?
|
|
|
+ billVO.getElecAutoStats().getTotalCost() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+ }
|
|
|
|
|
|
- // 公摊用量
|
|
|
- Long sharedQuantity = sumSharedReadings(sharedReadings);
|
|
|
+ if (billVO.getElecManualStats() != null) {
|
|
|
+ elecQuantity = elecQuantity.add(billVO.getElecManualStats().getTotalQuantity() != null ?
|
|
|
+ billVO.getElecManualStats().getTotalQuantity() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+ elecCost = elecCost.add(billVO.getElecManualStats().getTotalCost() != null ?
|
|
|
+ billVO.getElecManualStats().getTotalCost() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+ }
|
|
|
|
|
|
- // 公摊总价
|
|
|
- Double sharedPriceSum = calcPrice(sharedQuantity, unitPrice);
|
|
|
+ // 水量合计
|
|
|
+ BigDecimal waterQuantity = BigDecimal.ZERO;
|
|
|
+ BigDecimal waterCost = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ if (billVO.getWaterAutoStats() != null) {
|
|
|
+ waterQuantity = waterQuantity.add(billVO.getWaterAutoStats().getTotalQuantity() != null ?
|
|
|
+ billVO.getWaterAutoStats().getTotalQuantity() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+ waterCost = waterCost.add(billVO.getWaterAutoStats().getTotalCost() != null ?
|
|
|
+ billVO.getWaterAutoStats().getTotalCost() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+ }
|
|
|
|
|
|
- // 按户数公摊
|
|
|
- if (gtComputeType == 1) {
|
|
|
- sharedPrice = sharedPriceByCount(sharedPriceSum, coSet.size());
|
|
|
+ if (billVO.getWaterManualStats() != null) {
|
|
|
+ waterQuantity = waterQuantity.add(billVO.getWaterManualStats().getTotalQuantity() != null ?
|
|
|
+ billVO.getWaterManualStats().getTotalQuantity() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+ waterCost = waterCost.add(billVO.getWaterManualStats().getTotalCost() != null ?
|
|
|
+ billVO.getWaterManualStats().getTotalCost() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
}
|
|
|
- // 按面积公摊
|
|
|
- else if (gtComputeType == 2) {
|
|
|
- sharedPrice = sharedPriceByArea(sharedPriceSum, objCode, coSet);
|
|
|
+
|
|
|
+ // 公摊合计
|
|
|
+ BigDecimal sharedCost = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ if (billVO.getSharedData() != null) {
|
|
|
+ elecQuantity = elecQuantity.add(billVO.getSharedData().getElecSharedQuantity() != null ?
|
|
|
+ billVO.getSharedData().getElecSharedQuantity() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+ elecCost = elecCost.add(billVO.getSharedData().getElecSharedCost() != null ?
|
|
|
+ billVO.getSharedData().getElecSharedCost() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+ waterQuantity = waterQuantity.add(billVO.getSharedData().getWaterSharedQuantity() != null ?
|
|
|
+ billVO.getSharedData().getWaterSharedQuantity() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+ waterCost = waterCost.add(billVO.getSharedData().getWaterSharedCost() != null ?
|
|
|
+ billVO.getSharedData().getWaterSharedCost() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+
|
|
|
+ sharedCost = sharedCost.add(billVO.getSharedData().getElecSharedCost() != null ?
|
|
|
+ billVO.getSharedData().getElecSharedCost() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
+ sharedCost = sharedCost.add(billVO.getSharedData().getWaterSharedCost() != null ?
|
|
|
+ billVO.getSharedData().getWaterSharedCost() :
|
|
|
+ BigDecimal.ZERO);
|
|
|
}
|
|
|
|
|
|
- return sharedPrice;
|
|
|
+ total.setElecTotalQuantity(elecQuantity);
|
|
|
+ total.setElecTotalCost(elecCost);
|
|
|
+ total.setWaterTotalQuantity(waterQuantity);
|
|
|
+ total.setWaterTotalCost(waterCost);
|
|
|
+ total.setSharedTotalCost(sharedCost);
|
|
|
+ total.setGrandTotalCost(elecCost.add(waterCost));
|
|
|
+
|
|
|
+ return total;
|
|
|
}
|
|
|
|
|
|
- private Double sharedPriceByCount(Double price, int count) {
|
|
|
- BigDecimal bd1 = new BigDecimal(price.toString());
|
|
|
- BigDecimal bd2 = new BigDecimal(String.valueOf(count));
|
|
|
- BigDecimal res = bd1.divide(bd2, 3, RoundingMode.HALF_UP);
|
|
|
- return res.doubleValue();
|
|
|
+ /**
|
|
|
+ * 构建QueryMeter参数
|
|
|
+ */
|
|
|
+ private QueryMeter buildQueryMeter(QueryChargingBill queryParam, Integer meterCls) {
|
|
|
+ QueryMeter queryMeter = new QueryMeter();
|
|
|
+ BeanUtils.copyProperties(queryParam, queryMeter);
|
|
|
+ queryMeter.setMeterCls(meterCls);
|
|
|
+
|
|
|
+ // 处理起始日期
|
|
|
+ LocalDateTime startDateTime = YearMonth.parse(queryParam.getStartTime(), DateTimeFormatter.ofPattern("yyyyMM"))
|
|
|
+ .atDay(1).atStartOfDay();
|
|
|
+ queryMeter.setStartRecTime(startDateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
|
|
|
+ // 处理结束日期
|
|
|
+ LocalDateTime endDateTime = YearMonth.parse(queryParam.getEndTime(), DateTimeFormatter.ofPattern("yyyyMM"))
|
|
|
+ .atEndOfMonth().atTime(23, 59, 59);
|
|
|
+ queryMeter.setEndRecTime(endDateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
|
|
|
+ return queryMeter;
|
|
|
}
|
|
|
|
|
|
- private double sharedPriceByArea(Double sharedPriceSum, String objCode, Set<String> coSet) {
|
|
|
- List<AreaAttr> attrObjs = areaAttrMapper.selectAreaAttrList(coSet);
|
|
|
- Map<String, AreaAttr> map = attrObjs.stream()
|
|
|
- .collect(Collectors.toMap(AreaAttr::getAreaCode, Function.identity()));
|
|
|
- AreaAttr attr = map.get(objCode);
|
|
|
+ /**
|
|
|
+ * 计算费用
|
|
|
+ */
|
|
|
+ private BigDecimal calculateCost(BigDecimal quantity, Integer meterCls, CoChargingConfig config) {
|
|
|
+ if (quantity == null || quantity.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
|
|
|
- // 计算总面积
|
|
|
- Long areas = sumSharedAreas(attrObjs);
|
|
|
+ try {
|
|
|
+ if (config == null) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
|
|
|
- BigDecimal bd1 = new BigDecimal(sharedPriceSum.toString());
|
|
|
- BigDecimal bd2 = new BigDecimal(areas.toString());
|
|
|
- BigDecimal bd3 = new BigDecimal(attr.getUsableArea().toString());
|
|
|
+ BigDecimal unitPrice = BigDecimal.ZERO;
|
|
|
+ if (meterCls == 45) {
|
|
|
+ unitPrice = new BigDecimal(String.valueOf(config.getElecUnitPrice()));
|
|
|
+ }
|
|
|
+ else if (meterCls == 70) {
|
|
|
+ unitPrice = new BigDecimal(String.valueOf(config.getWaterUnitPrice()));
|
|
|
+ }
|
|
|
|
|
|
- // 计算当前区块面积占总建筑面积的比例
|
|
|
- BigDecimal bl = bd3.divide(bd2, 3, RoundingMode.HALF_UP);
|
|
|
- BigDecimal res = bd1.multiply(bl);
|
|
|
- return res.doubleValue();
|
|
|
- }
|
|
|
+ return quantity.multiply(unitPrice).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
|
- private Long sumSharedReadings(List<MeterReading> sharedReadings) {
|
|
|
- long sum = 0;
|
|
|
- for (MeterReading rec : sharedReadings) {
|
|
|
- sum += rec.getIncrease();
|
|
|
}
|
|
|
- return sum;
|
|
|
+ catch (Exception e) {
|
|
|
+ logger.error("计算费用异常", e);
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private Long sumSharedAreas(List<AreaAttr> attrObjs) {
|
|
|
- long sum = 0;
|
|
|
- for (AreaAttr attr : attrObjs) {
|
|
|
- sum += attr.getUsableArea();
|
|
|
- }
|
|
|
- return sum;
|
|
|
+ private QueryDevice buildQueryDev(String areaCode, Integer meterCls, Integer enable, Integer colMode) {
|
|
|
+ QueryDevice queryDevice = new QueryDevice();
|
|
|
+ queryDevice.setAreaCode(areaCode);
|
|
|
+ queryDevice.setMeterCls(meterCls);
|
|
|
+ queryDevice.setDeviceEnable(enable);
|
|
|
+ queryDevice.setColMode(colMode);
|
|
|
+ return queryDevice;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 计算用量总价
|
|
|
- *
|
|
|
- * @param meterCls 计量类别
|
|
|
- * @param dosage 用量
|
|
|
- * @param chargingCfg 价格配置
|
|
|
- * @return 返回总价
|
|
|
+ * 根据公摊方式计算区域应承担的公摊量
|
|
|
*/
|
|
|
- private Double calcPrice(int meterCls, Long dosage, CoChargingConfig chargingCfg) {
|
|
|
- if (meterCls == 45) {
|
|
|
- return calcPrice(dosage, chargingCfg.getElecUnitPrice());
|
|
|
- }
|
|
|
- else if (meterCls == 70) {
|
|
|
- return calcPrice(dosage, chargingCfg.getWaterUnitPrice());
|
|
|
+ private BigDecimal calculateSharedForArea(BigDecimal totalShared, Integer sharedType, String rootArea,
|
|
|
+ String areaCode) {
|
|
|
+ if (totalShared == null || totalShared.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
}
|
|
|
|
|
|
- return null;
|
|
|
+ try {
|
|
|
+ switch (sharedType) {
|
|
|
+ case 0: // 不计入
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+
|
|
|
+ case 1: // 户数均摊
|
|
|
+ // 查询需要公摊的商户数量
|
|
|
+ List<Area> areas1 = areaService.selectAreaByTag("Area_Seller");
|
|
|
+ areas1 = areas1.stream()
|
|
|
+ .filter(area -> ArrayUtils.contains(StringUtils.split(area.getAncestors(), ","), rootArea))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ int count = areas1.size();
|
|
|
+ if (count > 0) {
|
|
|
+ return totalShared.divide(new BigDecimal(count), 2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+
|
|
|
+ case 2: // 面积均摊
|
|
|
+ List<Area> areas2 = areaService.selectAreaByTag("Area_Seller");
|
|
|
+ List<String> areaCodes = areas2.stream()
|
|
|
+ .filter(area -> ArrayUtils.contains(StringUtils.split(area.getAncestors(), ","), rootArea))
|
|
|
+ .map(Area::getAreaCode).collect(Collectors.toList());
|
|
|
+ List<AreaAttr> attrList = attrService.selectAreaAttrList(areaCodes);
|
|
|
+
|
|
|
+ BigDecimal totalA = BigDecimal.ZERO;
|
|
|
+ BigDecimal currentA = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ for (AreaAttr attr : attrList) {
|
|
|
+ if (StringUtils.equals(areaCode, attr.getAreaCode())) {
|
|
|
+ currentA = new BigDecimal(String.valueOf(attr.getUsableArea()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算总面积
|
|
|
+ totalA = totalA.add(new BigDecimal(String.valueOf(attr.getUsableArea())));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (totalA.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ return totalShared.multiply(currentA).divide(totalA, 2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+
|
|
|
+ default:
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ logger.error("计算区域公摊异常", e);
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 计算用量总价
|
|
|
- *
|
|
|
- * @param dosage 用量
|
|
|
- * @param unitPrice 价格配置
|
|
|
- * @return 返回总价
|
|
|
+ * 获取公摊类型名称
|
|
|
*/
|
|
|
- private Double calcPrice(Long dosage, Double unitPrice) {
|
|
|
- BigDecimal bd1 = new BigDecimal(dosage.toString());
|
|
|
- BigDecimal bd2 = new BigDecimal(unitPrice.toString());
|
|
|
- BigDecimal res = bd1.multiply(bd2);
|
|
|
- return res.setScale(3, RoundingMode.HALF_UP).doubleValue();
|
|
|
- }
|
|
|
-
|
|
|
- private Double clacTotalPrice(ChargingBill bill) {
|
|
|
- if (null != bill.getMeteredPrice() && null != bill.getSharedPrice()) {
|
|
|
- BigDecimal bd1 = new BigDecimal(bill.getMeteredPrice().toString());
|
|
|
- BigDecimal bd2 = new BigDecimal(bill.getSharedPrice().toString());
|
|
|
- return bd1.add(bd2).setScale(3, RoundingMode.HALF_UP).doubleValue();
|
|
|
+ private String getSharedTypeName(Integer type) {
|
|
|
+ if (type == null) {
|
|
|
+ return "未知";
|
|
|
}
|
|
|
- else if (null == bill.getMeteredPrice() && null != bill.getSharedPrice()) {
|
|
|
- return bill.getSharedPrice();
|
|
|
- }
|
|
|
- else if (null != bill.getMeteredPrice() && null == bill.getSharedPrice()) {
|
|
|
- return bill.getMeteredPrice();
|
|
|
- }
|
|
|
- else {
|
|
|
- return null;
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case 0:
|
|
|
+ return "不计入";
|
|
|
+ case 1:
|
|
|
+ return "户数均摊";
|
|
|
+ case 2:
|
|
|
+ return "面积均摊";
|
|
|
+ default:
|
|
|
+ return "未知";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Set<String> getCoSet(CoChargingConfig chargingCfg) {
|
|
|
- Set<String> coSet;
|
|
|
+ private String getRootArea(Area area) {
|
|
|
+ String ancestors = area.getAncestors();
|
|
|
+ String[] ancestorsArr = StringUtils.split(ancestors, ",");
|
|
|
|
|
|
- if (null != chargingCfg) {
|
|
|
- coSet = chargingCfg.getRelCoList().stream().map(CoChargingConfigRel::getAreaCode)
|
|
|
- .collect(Collectors.toSet());
|
|
|
+ if (ancestorsArr.length < 2) {
|
|
|
+ return area.getAreaCode();
|
|
|
}
|
|
|
else {
|
|
|
- coSet = new HashSet<>();
|
|
|
+ return ancestorsArr[1];
|
|
|
}
|
|
|
-
|
|
|
- return coSet;
|
|
|
- }
|
|
|
-
|
|
|
- private String getObjName(QueryChargingBill queryParam) {
|
|
|
- String areaPath = queryParam.getAreaPath();
|
|
|
- List<String> areaCodes = Arrays.asList(StringUtils.split(areaPath, "/"));
|
|
|
- List<Area> areaList = areaMapper.selectByCodes(new HashSet<>(areaCodes));
|
|
|
- Map<String, Area> map = areaList.stream().collect(Collectors.toMap(Area::getAreaCode, Function.identity()));
|
|
|
-
|
|
|
- List<String> names = new ArrayList<>();
|
|
|
-
|
|
|
- for (String areaCode : areaCodes) {
|
|
|
- Area area = map.get(areaCode);
|
|
|
-
|
|
|
- if (null != area) {
|
|
|
- names.add(StringUtils.isNotBlank(area.getShortName()) ? area.getShortName() : area.getAreaName());
|
|
|
- }
|
|
|
- else {
|
|
|
- names.add("未知");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return StringUtils.join(names, "/");
|
|
|
}
|
|
|
}
|