master #3

Merged
bichangxiong merged 5 commits from master into prod 2025-08-29 18:47:07 +08:00
3 changed files with 76 additions and 43 deletions

View File

@@ -239,13 +239,15 @@ public class ServiceWorkOrdersServiceImpl implements IServiceWorkOrdersService {
LocalDate today = LocalDate.now();
// 1. 获取今日排班人员(优先查缓存,未命中则查询数据库并缓存)
List<AttendanceUserGroup> attendanceUserGroups = RedisUtils.getCacheList(DateUtil.today());
if (CollUtil.isEmpty(attendanceUserGroups)) {
attendanceUserGroups = attendanceUserGroupMapper.selectList(
List<AttendanceUserGroup> attendanceUserGroupList = attendanceUserGroupMapper.selectList(
new LambdaQueryWrapper<AttendanceUserGroup>()
.le(AttendanceUserGroup::getStartDate, today)
.ge(AttendanceUserGroup::getEndDate, today)
.orderByAsc(AttendanceUserGroup::getCreateTime)
.eq(AttendanceUserGroup::getDeptId, serviceWorkOrders.getCreateDept())
.orderByAsc(AttendanceUserGroup::getStartDate)
);
if (CollUtil.isEmpty(attendanceUserGroups)|| attendanceUserGroups.size() != attendanceUserGroupList.size()) {
attendanceUserGroups=attendanceUserGroupList;
Assert.isTrue(CollUtil.isNotEmpty(attendanceUserGroups), "暂无排班人员");
// 缓存当天排班数据(假设当天不会变)
RedisUtils.setCacheList(DateUtil.today(), attendanceUserGroups);

View File

@@ -121,7 +121,8 @@ public class CleanOrderServiceImpl implements ICleanOrderService {
private LambdaQueryWrapper<CleanOrder>buildQueryWrapper(CleanOrderBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<CleanOrder> lqw = Wrappers.lambdaQuery();
lqw.orderByAsc(CleanOrder::getId);
lqw.orderByDesc(CleanOrder::getCreateTime)
.orderByDesc(CleanOrder::getUpdateTime);
// lqw.eq(StringUtils.isNotBlank(bo.getLocation()), CleanOrder::getLocation, bo.getLocation());
// lqw.eq(StringUtils.isNotBlank(bo.getArea()), CleanOrder::getArea, bo.getArea());

View File

@@ -238,50 +238,80 @@ 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<>();
// hour
List<Map<String, Object>> hourList = baseMapper.getHourTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, 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<>();
String[] hourCategories = hourList.stream()
.map(map -> map.get("hour").toString())
.toArray(String[]::new);
BigDecimal[] hourData = hourList.stream()
.map(map -> new BigDecimal(map.get("total_consumption").toString()))
.toArray(BigDecimal[]::new);
hourMap.put("categories", hourCategories);
hourMap.put("data", hourData);
hourMap.put("total" , hourList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue());
hourMap.put("today", todayMap);
hourMap.put("yesterday", yesterdayMap);
// day
String[] monthArr = month.split("-");
List<Map<String, Object>> dayList = baseMapper.getDayTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, monthArr[0], monthArr[1]);
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<>();
String[] dayCategories = dayList.stream()
.map(map -> map.get("day").toString())
.toArray(String[]::new);
BigDecimal[] dayData = dayList.stream()
.map(map -> new BigDecimal(map.get("total_consumption").toString()))
.toArray(BigDecimal[]::new);
dayMap.put("categories", dayCategories);
dayMap.put("data", dayData);
dayMap.put("total", dayList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue());
dayMap.put("nowMonth", nowMonthMap);
dayMap.put("lastMonth", lastMonthMap);
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);
// month
List<Map<String, Object>> monthList = baseMapper.getMonthTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year);
Map<String, Object> monthMap = new HashMap<>();
String[] monthCategories = monthList.stream()
.map(map -> map.get("month").toString())
.toArray(String[]::new);
BigDecimal[] monthData = monthList.stream()
.map(map -> new BigDecimal(map.get("total_consumption").toString()))
.toArray(BigDecimal[]::new);
monthMap.put("categories", monthCategories);
monthMap.put("data", monthData);
monthMap.put("total", monthList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue());
monthMap.put("nowYear", nowYearMap);
monthMap.put("lastYear", lastYearMap);
resultMap.put("hour", hourMap);
resultMap.put("day", dayMap);
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();
hourMap.put("total", total);
hourMap.put("data", hourData);
return hourMap;
}
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();
dayMap.put("total", total);
dayMap.put("data", dayData);
return dayMap;
}
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();
resultMap.put("total", total);
resultMap.put("data", monthData);
return resultMap;
}
}