feat(Property): 新增水电气费用计算功能
This commit is contained in:
@@ -95,5 +95,7 @@ public class CostHouseChargeBo extends BaseEntity {
|
||||
private String remark;
|
||||
|
||||
|
||||
private String chargeTime;
|
||||
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,9 @@ package org.dromara.property.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
@@ -25,6 +27,9 @@ import org.dromara.property.domain.vo.*;
|
||||
import org.dromara.property.domain.vo.residentVo.ResidentPersonVo;
|
||||
import org.dromara.property.domain.vo.residentVo.ResidentUnitVo;
|
||||
import org.dromara.property.mapper.*;
|
||||
import org.dromara.property.service.ITbFloorService;
|
||||
import org.dromara.property.service.ITbRoomService;
|
||||
import org.dromara.property.service.smartDevicesService.ITbMeterRecordService;
|
||||
import org.dromara.system.api.RemoteDictService;
|
||||
import org.dromara.system.api.RemoteUserService;
|
||||
import org.dromara.system.api.domain.vo.RemoteDictDataVo;
|
||||
@@ -62,6 +67,10 @@ public class CostHouseChargeServiceImpl implements ICostHouseChargeService {
|
||||
@DubboReference
|
||||
private RemoteDictService remoteDictService;
|
||||
|
||||
private final ITbRoomService tbRoomService;
|
||||
private final ITbFloorService tbFloorService;
|
||||
private final ITbMeterRecordService tbMeterRecordService;
|
||||
|
||||
/**
|
||||
* 查询房屋收费
|
||||
*
|
||||
@@ -185,7 +194,7 @@ public class CostHouseChargeServiceImpl implements ICostHouseChargeService {
|
||||
ResidentUnitVo residentUnitVo = residentUnitMapper.selectVoById(add.getResidentUnitId());
|
||||
add.setResidentUnitId(residentUnitVo.getId());
|
||||
add.setArea(residentUnitVo.getArea());
|
||||
BigDecimal area = new BigDecimal(add.getArea());
|
||||
BigDecimal area = BigDecimal.valueOf(add.getArea());
|
||||
CostItemsVo costItemsVo = costItemsMapper.selectVoById(add.getCostItemsId());
|
||||
BigDecimal unitPrice = costItemsVo.getUnitPrice();
|
||||
// //向上取整
|
||||
@@ -214,11 +223,11 @@ public class CostHouseChargeServiceImpl implements ICostHouseChargeService {
|
||||
}
|
||||
//类型为5,则为水费
|
||||
if (Objects.equals(remoteDictDataVo.getDictValue(), "5")) {
|
||||
|
||||
|
||||
add.setAmountReceivable(meterCharge(residentUnitVo.getLocation(), area, 2L, bo));
|
||||
}
|
||||
//类型为6,则为电费
|
||||
if (Objects.equals(remoteDictDataVo.getDictValue(), "6")) {
|
||||
add.setAmountReceivable(meterCharge(residentUnitVo.getLocation(), area, 1L, bo));
|
||||
}
|
||||
//类型为8,则为气费
|
||||
if (Objects.equals(remoteDictDataVo.getDictValue(), "8")) {
|
||||
@@ -250,8 +259,44 @@ public class CostHouseChargeServiceImpl implements ICostHouseChargeService {
|
||||
/**
|
||||
* 水电气费计算
|
||||
*/
|
||||
private void meterCharge(){
|
||||
private BigDecimal meterCharge(String location, BigDecimal roomArea, Long meterType, CostHouseChargeBo bo) {
|
||||
if (StringUtils.isNotBlank(location)) {
|
||||
String[] roomIds = location.split(",");
|
||||
Map<Long, TbFloorVo> floorData = new HashMap<>(); // 存储去重的楼层数据
|
||||
|
||||
for (String item : roomIds) {
|
||||
TbRoomVo roomVo = tbRoomService.queryById(Long.valueOf(item));
|
||||
if (roomVo != null) {
|
||||
Long floorId = roomVo.getFloorId();
|
||||
// 保存楼层数据(如果尚未存在)
|
||||
if (!floorData.containsKey(floorId)) {
|
||||
// 假设您有获取楼层信息的方法,这里需要根据实际情况调整
|
||||
TbFloorVo floorVo = tbFloorService.queryById(floorId);
|
||||
if (floorVo != null) {
|
||||
floorData.put(floorId, floorVo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Float floorArea = 0f;
|
||||
Float meterEnergy = 0f;
|
||||
for (Map.Entry<Long, TbFloorVo> entry : floorData.entrySet()) {
|
||||
floorArea += entry.getValue().getArea();
|
||||
Map<String, Object> meterRecord = tbMeterRecordService.getEnergyTrend(entry.getKey().toString(), null, meterType, null, bo.getChargeTime(), null);
|
||||
Map<String, Object> resultMap = Convert.convert(new TypeReference<>() {
|
||||
}, meterRecord.get("nowMonth"));
|
||||
meterEnergy += Convert.convert(Float.class, resultMap.get("total"));
|
||||
}
|
||||
|
||||
BigDecimal floorAreaBD = Convert.toBigDecimal(floorArea);
|
||||
BigDecimal meterEnergyBD = Convert.toBigDecimal(meterEnergy);
|
||||
|
||||
return roomArea.divide(floorAreaBD, 10, RoundingMode.HALF_UP)
|
||||
.multiply(meterEnergyBD)
|
||||
.multiply(Convert.toBigDecimal(0.9));
|
||||
}
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -14,7 +14,7 @@ import java.util.Map;
|
||||
* 抄记录Service接口
|
||||
*
|
||||
* @author lsm
|
||||
* @date 2025-07-19
|
||||
* @since 2025-07-19
|
||||
*/
|
||||
public interface ITbMeterRecordService {
|
||||
|
||||
|
Reference in New Issue
Block a user