refactor(Property): 1
This commit is contained in:
@@ -81,10 +81,9 @@ public class XResidentPersonController extends BaseController {
|
||||
/**
|
||||
* 新增入驻员工
|
||||
*/
|
||||
@SaCheckPermission("xcx:person:add")
|
||||
@Log(title = "入驻员工", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
@Log(title = "入驻员工", businessType = BusinessType.INSERT)
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody ResidentPersonBo bo) {
|
||||
return toAjax(residentPersonService.insertByBo(bo));
|
||||
}
|
||||
|
@@ -214,6 +214,8 @@ public class CostHouseChargeServiceImpl implements ICostHouseChargeService {
|
||||
}
|
||||
//类型为5,则为水费
|
||||
if (Objects.equals(remoteDictDataVo.getDictValue(), "5")) {
|
||||
|
||||
|
||||
}
|
||||
//类型为6,则为电费
|
||||
if (Objects.equals(remoteDictDataVo.getDictValue(), "6")) {
|
||||
@@ -245,6 +247,13 @@ public class CostHouseChargeServiceImpl implements ICostHouseChargeService {
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 水电气费计算
|
||||
*/
|
||||
private void meterCharge(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 房屋退费
|
||||
*
|
||||
|
@@ -27,9 +27,11 @@ import org.dromara.property.service.smartDevicesService.ITbMeterRecordService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.YearMonth;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* 抄记录Service业务层处理
|
||||
@@ -267,50 +269,75 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService {
|
||||
public Map<String, Object> getEnergyTrend(String floorId, String meterId, Long meterType, String day, String month, String year) {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
|
||||
String yesterday = DateUtil.format(DateUtil.offsetDay(DateUtil.parse(day), -1), "yyyy-MM-dd");
|
||||
// todayHour
|
||||
Map<String, Object> todayMap = trendHourData(floorId, meterId, meterType, day);
|
||||
// yesterdayHour
|
||||
Map<String, Object> yesterdayMap = trendHourData(floorId, meterId, meterType, yesterday);
|
||||
if (!StrUtil.isBlank(day)) {
|
||||
String yesterday = DateUtil.format(DateUtil.offsetDay(DateUtil.parse(day), -1), "yyyy-MM-dd");
|
||||
// todayHour
|
||||
Map<String, Object> todayMap = trendHourData(floorId, meterId, meterType, day);
|
||||
// yesterdayHour
|
||||
Map<String, Object> yesterdayMap = trendHourData(floorId, meterId, meterType, yesterday);
|
||||
|
||||
Map<String, Object> hourMap = new HashMap<>();
|
||||
hourMap.put("today", todayMap);
|
||||
hourMap.put("yesterday", yesterdayMap);
|
||||
Map<String, Object> hourMap = new HashMap<>();
|
||||
hourMap.put("today", todayMap);
|
||||
hourMap.put("yesterday", yesterdayMap);
|
||||
resultMap.put("hour", hourMap);
|
||||
}
|
||||
|
||||
if (!StrUtil.isBlank(month)) {
|
||||
String[] monthArr = month.split("-");
|
||||
String lastMonth = Integer.parseInt(monthArr[1]) - 1 + "";
|
||||
// nowMonth
|
||||
Map<String, Object> nowMonthMap = trendDayData(floorId, meterId, meterType, monthArr[0], monthArr[1]);
|
||||
// lastMonth
|
||||
Map<String, Object> lastMonthMap = trendDayData(floorId, meterId, meterType, monthArr[0], lastMonth);
|
||||
|
||||
String[] monthArr = month.split("-");
|
||||
String lastMonth = Integer.parseInt(monthArr[1]) - 1 + "";
|
||||
// nowMonth
|
||||
Map<String, Object> nowMonthMap = trendDayData(floorId, meterId, meterType, monthArr[0], monthArr[1]);
|
||||
// lastMonth
|
||||
Map<String, Object> lastMonthMap = trendDayData(floorId, meterId, meterType, monthArr[0], lastMonth);
|
||||
Map<String, Object> dayMap = new HashMap<>();
|
||||
dayMap.put("nowMonth", nowMonthMap);
|
||||
dayMap.put("lastMonth", lastMonthMap);
|
||||
resultMap.put("day", dayMap);
|
||||
}
|
||||
|
||||
Map<String, Object> dayMap = new HashMap<>();
|
||||
dayMap.put("nowMonth", nowMonthMap);
|
||||
dayMap.put("lastMonth", lastMonthMap);
|
||||
if (!StrUtil.isBlank(year)) {
|
||||
String lastYear = Integer.parseInt(year) - 1 + "";
|
||||
// nowYear
|
||||
Map<String, Object> nowYearMap = trendMonthData(floorId, meterId, meterType, year);
|
||||
// lastYear
|
||||
Map<String, Object> lastYearMap = trendMonthData(floorId, meterId, meterType, lastYear);
|
||||
|
||||
String lastYear = Integer.parseInt(year) - 1 + "";
|
||||
// nowYear
|
||||
Map<String, Object> nowYearMap = trendMonthData(floorId, meterId, meterType, year);
|
||||
// lastYear
|
||||
Map<String, Object> lastYearMap = trendMonthData(floorId, meterId, meterType, lastYear);
|
||||
|
||||
Map<String, Object> monthMap = new HashMap<>();
|
||||
monthMap.put("nowYear", nowYearMap);
|
||||
monthMap.put("lastYear", lastYearMap);
|
||||
|
||||
resultMap.put("hour", hourMap);
|
||||
resultMap.put("day", dayMap);
|
||||
resultMap.put("month", monthMap);
|
||||
Map<String, Object> monthMap = new HashMap<>();
|
||||
monthMap.put("nowYear", nowYearMap);
|
||||
monthMap.put("lastYear", lastYearMap);
|
||||
resultMap.put("month", monthMap);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
private Map<String, Object> trendHourData(String floorId, String meterId, Long meterType, String day) {
|
||||
Map<String, Object> hourMap = new HashMap<>();
|
||||
List<Map<String, Object>> hourList = baseMapper.getHourTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, day);
|
||||
List<String[]> hourData = new ArrayList<>();
|
||||
hourList.forEach(item -> hourData.add(new String[]{item.get("hour").toString(), item.get("total_consumption").toString()}));
|
||||
Float total = hourList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue();
|
||||
List<Map<String, Object>> sqlList = baseMapper.getHourTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, day);
|
||||
|
||||
// 创建小时--能耗的映射,缺失的小时自动补0
|
||||
List<String[]> hourData = IntStream.rangeClosed(0, 23)
|
||||
.mapToObj(hour -> {
|
||||
// 查找对应小时的数据
|
||||
Optional<Map<String, Object>> hourResult = sqlList.stream()
|
||||
.filter(item -> Integer.parseInt(item.get("hour").toString().split(":")[0]) == hour)
|
||||
.findFirst();
|
||||
|
||||
// 存在则使用实际值,否则使用0
|
||||
String consumption = hourResult
|
||||
.map(item -> item.get("total_consumption").toString())
|
||||
.orElse(BigDecimal.ZERO.toString());
|
||||
|
||||
return new String[]{hour + ":00", consumption};
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 计算总能耗(直接使用sqlList中的数据求和,避免二次计算)
|
||||
Float total = sqlList.stream()
|
||||
.map(item -> new BigDecimal(item.get("total_consumption").toString()))
|
||||
.reduce(BigDecimal::add)
|
||||
.orElse(BigDecimal.ZERO)
|
||||
.floatValue();
|
||||
|
||||
hourMap.put("total", total);
|
||||
hourMap.put("data", hourData);
|
||||
return hourMap;
|
||||
@@ -318,10 +345,33 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService {
|
||||
|
||||
private Map<String, Object> trendDayData(String floorId, String meterId, Long meterType, String year, String month) {
|
||||
Map<String, Object> dayMap = new HashMap<>();
|
||||
List<Map<String, Object>> dayList = baseMapper.getDayTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year, month);
|
||||
List<String[]> dayData = new ArrayList<>();
|
||||
dayList.forEach(item -> dayData.add(new String[]{item.get("day").toString(), item.get("total_consumption").toString()}));
|
||||
Float total = dayList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue();
|
||||
List<Map<String, Object>> sqlList = baseMapper.getDayTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year, month);
|
||||
|
||||
YearMonth yearMonth = YearMonth.of(Integer.parseInt(year), Integer.parseInt(month));
|
||||
// 创建月份--能耗的映射,缺失的月份自动补0
|
||||
List<String[]> dayData = IntStream.rangeClosed(1, yearMonth.lengthOfMonth())
|
||||
.mapToObj(day -> {
|
||||
// 查找对应月份的数据
|
||||
Optional<Map<String, Object>> dayResult = sqlList.stream()
|
||||
.filter(item -> Integer.parseInt(item.get("day").toString()) == day)
|
||||
.findFirst();
|
||||
|
||||
// 存在则使用实际值,否则使用0
|
||||
String consumption = dayResult
|
||||
.map(item -> item.get("total_consumption").toString())
|
||||
.orElse(BigDecimal.ZERO.toString());
|
||||
|
||||
return new String[]{String.valueOf(day), consumption};
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
// 计算总能耗(直接使用sqlList中的数据求和,避免二次计算)
|
||||
Float total = sqlList.stream()
|
||||
.map(item -> new BigDecimal(item.get("total_consumption").toString()))
|
||||
.reduce(BigDecimal::add)
|
||||
.orElse(BigDecimal.ZERO)
|
||||
.floatValue();
|
||||
dayMap.put("total", total);
|
||||
dayMap.put("data", dayData);
|
||||
return dayMap;
|
||||
@@ -329,10 +379,32 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService {
|
||||
|
||||
private Map<String, Object> trendMonthData(String floorId, String meterId, Long meterType, String year) {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
List<Map<String, Object>> monthList = baseMapper.getMonthTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year);
|
||||
List<String[]> monthData = new ArrayList<>();
|
||||
monthList.forEach(item -> monthData.add(new String[]{item.get("month").toString(), item.get("total_consumption").toString()}));
|
||||
Float total = monthList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue();
|
||||
List<Map<String, Object>> sqlList = baseMapper.getMonthTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year);
|
||||
|
||||
// 创建月份--能耗的映射,缺失的月份自动补0
|
||||
List<String[]> monthData = IntStream.rangeClosed(1, 12)
|
||||
.mapToObj(month -> {
|
||||
// 查找对应月份的数据
|
||||
Optional<Map<String, Object>> monthResult = sqlList.stream()
|
||||
.filter(item -> Integer.parseInt(item.get("month").toString()) == month)
|
||||
.findFirst();
|
||||
|
||||
// 存在则使用实际值,否则使用0
|
||||
String consumption = monthResult
|
||||
.map(item -> item.get("total_consumption").toString())
|
||||
.orElse(BigDecimal.ZERO.toString());
|
||||
|
||||
return new String[]{String.valueOf(month), consumption};
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 计算总能耗(直接使用sqlList中的数据求和,避免二次计算)
|
||||
Float total = sqlList.stream()
|
||||
.map(item -> new BigDecimal(item.get("total_consumption").toString()))
|
||||
.reduce(BigDecimal::add)
|
||||
.orElse(BigDecimal.ZERO)
|
||||
.floatValue();
|
||||
|
||||
resultMap.put("total", total);
|
||||
resultMap.put("data", monthData);
|
||||
return resultMap;
|
||||
|
Reference in New Issue
Block a user