diff --git a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java index f5d6d132..8d056673 100644 --- a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java +++ b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java @@ -452,8 +452,9 @@ public class OssClient { // MinIO 单独处理 if (StringUtils.isNotEmpty(domain)) { // 如果 domain 以 "https://" 或 "http://" 开头 - return (domain.startsWith(Constants.HTTPS) || domain.startsWith(Constants.HTTP)) ? - domain + StringUtils.SLASH + properties.getBucketName() : header + domain + StringUtils.SLASH + properties.getBucketName(); +// return (domain.startsWith(Constants.HTTPS) || domain.startsWith(Constants.HTTP)) ? +// domain + StringUtils.SLASH + properties.getBucketName() : header + domain + StringUtils.SLASH + properties.getBucketName(); + return StringUtils.SLASH + properties.getBucketName(); } return header + endpoint + StringUtils.SLASH + properties.getBucketName(); } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/xcx/XResidentPersonController.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/xcx/XResidentPersonController.java index 08163dac..17c52272 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/xcx/XResidentPersonController.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/xcx/XResidentPersonController.java @@ -54,6 +54,7 @@ public class XResidentPersonController extends BaseController { vo.setUserRoles(loginUser.getUserRoles()); vo.setUnitId(loginUser.getUnitId()); vo.setUnitName(loginUser.getUnitName()); + vo.setTenantId(loginUser.getTenantId()); return R.ok(vo); } @@ -81,10 +82,9 @@ public class XResidentPersonController extends BaseController { /** * 新增入驻员工 */ - @SaCheckPermission("xcx:person:add") - @Log(title = "入驻员工", businessType = BusinessType.INSERT) @RepeatSubmit() - @PostMapping() + @PostMapping("/add") + @Log(title = "入驻员工", businessType = BusinessType.INSERT) public R add(@Validated(AddGroup.class) @RequestBody ResidentPersonBo bo) { return toAjax(residentPersonService.insertByBo(bo)); } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/CostHouseChargeBo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/CostHouseChargeBo.java index e1f3a3f9..cf0cf572 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/CostHouseChargeBo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/CostHouseChargeBo.java @@ -95,5 +95,7 @@ public class CostHouseChargeBo extends BaseEntity { private String remark; + private String chargeTime; + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/ServiceWorkOrdersBo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/ServiceWorkOrdersBo.java index f5ee41df..d56e33af 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/ServiceWorkOrdersBo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/ServiceWorkOrdersBo.java @@ -120,4 +120,9 @@ public class ServiceWorkOrdersBo extends BaseEntity { */ private String isTimeOut; + /** + * 租户ID + */ + private String tenantId; + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/smartDevicesBo/TbMeterInfoBo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/smartDevicesBo/TbMeterInfoBo.java index 73db1b9f..dffffffd 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/smartDevicesBo/TbMeterInfoBo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/smartDevicesBo/TbMeterInfoBo.java @@ -112,5 +112,14 @@ public class TbMeterInfoBo extends BaseEntity { */ private String remark; + /** + * 白天预警阈值 + */ + private BigDecimal dayWarning; + + /** + * 夜间预警阈值 + */ + private BigDecimal nightWarning; } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/entity/smartDevices/TbMeterInfo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/entity/smartDevices/TbMeterInfo.java index f363203d..9401e141 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/entity/smartDevices/TbMeterInfo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/entity/smartDevices/TbMeterInfo.java @@ -108,5 +108,15 @@ public class TbMeterInfo extends TenantEntity { */ private String hostIp; + /** + * 白天预警阈值 + */ + private BigDecimal dayWarning; + + /** + * 夜间预警阈值 + */ + private BigDecimal nightWarning; + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/enums/MeterTypeEnum.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/enums/MeterTypeEnum.java new file mode 100644 index 00000000..fd7b8da4 --- /dev/null +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/enums/MeterTypeEnum.java @@ -0,0 +1,35 @@ +package org.dromara.property.domain.enums; + +import lombok.Getter; + +/** + * @author lsm + * @apiNote MeterTypeEnum + * @since 2025/9/15 + */ +@Getter +public enum MeterTypeEnum { + + /** + * 电表 + */ + ELECTRIC_METER(1L, 1963167455478624257L), + + /** + * 水表 + */ + WATER_METER(2L, 1963167729677053953L), + + /** + * 气表 + */ + GAS_METER(3L, 0L); + + private final Long code; + private final Long orderType; + + MeterTypeEnum(Long code, Long orderType) { + this.code = code; + this.orderType = orderType; + } +} diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/smartDevicesVo/TbMeterInfoVo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/smartDevicesVo/TbMeterInfoVo.java index 2ec7ef46..d48e52b3 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/smartDevicesVo/TbMeterInfoVo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/smartDevicesVo/TbMeterInfoVo.java @@ -144,5 +144,16 @@ public class TbMeterInfoVo implements Serializable { @ExcelProperty(value = "备注") private String remark; + /** + * 白天预警阈值 + */ + @ExcelProperty(value = "白天预警阈值") + private BigDecimal dayWarning; + + /** + * 夜间预警阈值 + */ + @ExcelProperty(value = "夜间预警阈值") + private BigDecimal nightWarning; } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/dubbo/RemoteResidentPersonServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/dubbo/RemoteResidentPersonServiceImpl.java index e6b60a87..499dda9d 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/dubbo/RemoteResidentPersonServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/dubbo/RemoteResidentPersonServiceImpl.java @@ -80,7 +80,7 @@ public class RemoteResidentPersonServiceImpl implements RemoteResidentPersonServ return TenantHelper.dynamic(tenantId, () -> { ResidentPersonVo vo = residentPersonService.queryByPhone(phone, tenantId); if (ObjectUtil.isEmpty(vo)) { - throw new ResidentPersonException("入驻员工"); + throw new ResidentPersonException("入驻员工不存在"); } if (vo.getIsAudit() == null || vo.getIsAudit() != 1) { throw new ResidentPersonException("当前员工未审核"); diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/CostHouseChargeServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/CostHouseChargeServiceImpl.java index 3c8d0e3e..81662af3 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/CostHouseChargeServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/CostHouseChargeServiceImpl.java @@ -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,9 +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")) { @@ -245,6 +256,49 @@ public class CostHouseChargeServiceImpl implements ICostHouseChargeService { return flag; } + /** + * 水电气费计算 + */ + private BigDecimal meterCharge(String location, BigDecimal roomArea, Long meterType, CostHouseChargeBo bo) { + if (StringUtils.isNotBlank(location)) { + String[] roomIds = location.split(","); + Map 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 entry : floorData.entrySet()) { + floorArea += entry.getValue().getArea(); + Map meterRecord = tbMeterRecordService.getEnergyTrend(entry.getKey().toString(), null, meterType, null, bo.getChargeTime(), null); + Map 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; + } + /** * 房屋退费 * diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/ServiceWorkOrdersServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/ServiceWorkOrdersServiceImpl.java index c3df7575..e98e0777 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/ServiceWorkOrdersServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/ServiceWorkOrdersServiceImpl.java @@ -223,12 +223,19 @@ public class ServiceWorkOrdersServiceImpl implements IServiceWorkOrdersService { //查询工单类型 ServiceWorkOrdersType serviceWorkOrdersType = typesMapper.selectById(bo.getType()); ServiceWorkOrders add = MapstructUtils.convert(bo, ServiceWorkOrders.class); - LoginUser user = LoginHelper.getLoginUser(); + assert add != null; add.setOrderNo("GD" + IdUtil.getSnowflakeNextIdStr()); add.setStatus(WorkOrderStatusEnum.CREATE_ORDER.getValue()); - add.setInitiatorPeople(user.getNickname()); add.setProcessingWeight(serviceWorkOrdersType.getProcessingWeight()); add.setIsTimeOut("0"); + + // 传入用户名时,不使用token中的值,避免自动生成工单引发token报错 + if (!StringUtils.isNotBlank(bo.getInitiatorName())){ + LoginUser user = LoginHelper.getLoginUser(); + assert user != null; + add.setInitiatorPeople(user.getNickname()); + } + Date originalDate = new Date(); // 当前时间 Date newDate = DateUtil.offsetHour(originalDate, serviceWorkOrdersType.getCompletionNumber()); add.setPlanCompleTime(newDate); diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterRecordServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterRecordServiceImpl.java index f82f2fa4..ff396837 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterRecordServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterRecordServiceImpl.java @@ -13,10 +13,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.dromara.property.domain.bo.ServiceWorkOrdersBo; import org.dromara.property.domain.bo.smartDevicesBo.TbMeterInfoBo; import org.dromara.property.domain.enums.MeterRecordTypeEnum; +import org.dromara.property.domain.enums.MeterTypeEnum; import org.dromara.property.domain.vo.smartDevicesVo.TbMeterInfoVo; import org.dromara.property.rocketmq.domain.MeterResult; +import org.dromara.property.service.IServiceWorkOrdersService; import org.dromara.property.service.smartDevicesService.ITbMeterInfoService; import org.springframework.stereotype.Service; import org.dromara.property.domain.bo.smartDevicesBo.TbMeterRecordBo; @@ -27,9 +30,12 @@ import org.dromara.property.service.smartDevicesService.ITbMeterRecordService; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; +import java.time.YearMonth; +import java.time.ZoneId; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * 抄记录Service业务层处理 @@ -44,6 +50,7 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService { private final TbMeterRecordMapper baseMapper; private final ITbMeterInfoService tbMeterInfoService; + private final IServiceWorkOrdersService serviceWorkOrdersService; /** * 查询抄记录 @@ -242,7 +249,36 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService { } else { bo.setCommunicationState(1L); } - tbMeterInfoService.updateByBo(bo); + boolean infoFlag = tbMeterInfoService.updateByBo(bo); + Assert.isTrue(infoFlag, "更新设备信息失败"); + + + // 当前读数超出阈值,自动上报工单 + int hour = record.getReadingTime().toInstant().atZone(ZoneId.systemDefault()).getHour(); + ServiceWorkOrdersBo ordersBo = new ServiceWorkOrdersBo(); + ordersBo.setTenantId(info.getTenantId()); + ordersBo.setInitiatorName("超级管理员"); + + // 判断是白天还是夜间 + boolean isDaytime = hour > 8 && hour <= 20; + BigDecimal threshold = isDaytime ? info.getDayWarning() : info.getNightWarning(); + // 如果阈值为0,则不处理(阈值不为0且读数大于阈值,自动上报) + if (threshold.compareTo(BigDecimal.ZERO) != 0 && record.getCurrentReading().compareTo(threshold) > 0) { + // 根据仪表类型设置工单名称和类型 + String orderName = "能耗异常"; + Long orderType = 0L; + if (Objects.equals(info.getMeterType(), MeterTypeEnum.ELECTRIC_METER.getCode())) { + orderName = isDaytime ? "电表日间阈值报警" : "电表夜间阈值报警"; + orderType = MeterTypeEnum.ELECTRIC_METER.getOrderType(); + } else if (Objects.equals(info.getMeterType(), MeterTypeEnum.WATER_METER.getCode())) { + orderName = isDaytime ? "水表日间阈值报警" : "水表夜间阈值报警"; + orderType = MeterTypeEnum.WATER_METER.getOrderType(); + } + ordersBo.setOrderName(orderName); + ordersBo.setType(orderType); + boolean orderFlag = serviceWorkOrdersService.insertByBo(ordersBo); + Assert.isTrue(orderFlag, "自动上报工单失败"); + } record.setReadingMethod(MeterRecordTypeEnum.AUTO_RECORD.getCode()); recordNew.add(record); @@ -267,50 +303,75 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService { public Map getEnergyTrend(String floorId, String meterId, Long meterType, String day, String month, String year) { Map resultMap = new HashMap<>(); - String yesterday = DateUtil.format(DateUtil.offsetDay(DateUtil.parse(day), -1), "yyyy-MM-dd"); - // todayHour - Map todayMap = trendHourData(floorId, meterId, meterType, day); - // yesterdayHour - Map 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 todayMap = trendHourData(floorId, meterId, meterType, day); + // yesterdayHour + Map yesterdayMap = trendHourData(floorId, meterId, meterType, yesterday); - Map hourMap = new HashMap<>(); - hourMap.put("today", todayMap); - hourMap.put("yesterday", yesterdayMap); + Map 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 nowMonthMap = trendDayData(floorId, meterId, meterType, monthArr[0], monthArr[1]); + // lastMonth + Map lastMonthMap = trendDayData(floorId, meterId, meterType, monthArr[0], lastMonth); - String[] monthArr = month.split("-"); - String lastMonth = Integer.parseInt(monthArr[1]) - 1 + ""; - // nowMonth - Map nowMonthMap = trendDayData(floorId, meterId, meterType, monthArr[0], monthArr[1]); - // lastMonth - Map lastMonthMap = trendDayData(floorId, meterId, meterType, monthArr[0], lastMonth); + Map dayMap = new HashMap<>(); + dayMap.put("nowMonth", nowMonthMap); + dayMap.put("lastMonth", lastMonthMap); + resultMap.put("day", dayMap); + } - Map dayMap = new HashMap<>(); - dayMap.put("nowMonth", nowMonthMap); - dayMap.put("lastMonth", lastMonthMap); + if (!StrUtil.isBlank(year)) { + String lastYear = Integer.parseInt(year) - 1 + ""; + // nowYear + Map nowYearMap = trendMonthData(floorId, meterId, meterType, year); + // lastYear + Map lastYearMap = trendMonthData(floorId, meterId, meterType, lastYear); - String lastYear = Integer.parseInt(year) - 1 + ""; - // nowYear - Map nowYearMap = trendMonthData(floorId, meterId, meterType, year); - // lastYear - Map lastYearMap = trendMonthData(floorId, meterId, meterType, lastYear); - - Map monthMap = new HashMap<>(); - monthMap.put("nowYear", nowYearMap); - monthMap.put("lastYear", lastYearMap); - - resultMap.put("hour", hourMap); - resultMap.put("day", dayMap); - resultMap.put("month", monthMap); + Map monthMap = new HashMap<>(); + monthMap.put("nowYear", nowYearMap); + monthMap.put("lastYear", lastYearMap); + resultMap.put("month", monthMap); + } return resultMap; } private Map trendHourData(String floorId, String meterId, Long meterType, String day) { Map hourMap = new HashMap<>(); - List> hourList = baseMapper.getHourTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, day); - List 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> sqlList = baseMapper.getHourTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, day); + + // 创建小时--能耗的映射,缺失的小时自动补0 + List hourData = IntStream.rangeClosed(0, 23) + .mapToObj(hour -> { + // 查找对应小时的数据 + Optional> 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 +379,33 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService { private Map trendDayData(String floorId, String meterId, Long meterType, String year, String month) { Map dayMap = new HashMap<>(); - List> dayList = baseMapper.getDayTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year, month); - List 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> 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 dayData = IntStream.rangeClosed(1, yearMonth.lengthOfMonth()) + .mapToObj(day -> { + // 查找对应月份的数据 + Optional> 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 +413,32 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService { private Map trendMonthData(String floorId, String meterId, Long meterType, String year) { Map resultMap = new HashMap<>(); - List> monthList = baseMapper.getMonthTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year); - List 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> sqlList = baseMapper.getMonthTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year); + + // 创建月份--能耗的映射,缺失的月份自动补0 + List monthData = IntStream.rangeClosed(1, 12) + .mapToObj(month -> { + // 查找对应月份的数据 + Optional> 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; diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterRecordService.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterRecordService.java index 795ee91e..7714d315 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterRecordService.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterRecordService.java @@ -14,7 +14,7 @@ import java.util.Map; * 抄记录Service接口 * * @author lsm - * @date 2025-07-19 + * @since 2025-07-19 */ public interface ITbMeterRecordService { diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/bo/SisAlarmEventsBo.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/bo/SisAlarmEventsBo.java index 22498858..9b7a9216 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/bo/SisAlarmEventsBo.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/bo/SisAlarmEventsBo.java @@ -126,4 +126,17 @@ public class SisAlarmEventsBo extends BaseEntity { private Date finishTime; private String description; + + /** + * 0: 按id降序 + * 1:按id升序 + * 2:按创建时间降序 + * 3:按创建时间升序 + * 4:按指派时间降序 + * 5 按指派时间升序 + * 6 按完成时间升序 + * 7 按完成时间升序 + */ + private Integer orderBy = 0; + } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisAlarmEventsServiceImpl.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisAlarmEventsServiceImpl.java index d7c1ff90..d6469be7 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisAlarmEventsServiceImpl.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisAlarmEventsServiceImpl.java @@ -99,6 +99,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService { @Override public TableDataInfo queryPageList(SisAlarmEventsBo bo, PageQuery pageQuery) { LambdaQueryWrapper lqw = buildQueryWrapper(bo); + lqw.orderByDesc(SisAlarmEvents::getId); Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); return TableDataInfo.build(result); @@ -137,6 +138,24 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService { Date end = DateUtil.endOfDay(bo.getReportTime()); lqw.between(SisAlarmEvents::getReportTime, start, end); } + + if (bo.getOrderBy() == 0) { + lqw.orderByDesc(SisAlarmEvents::getId); + } else if (bo.getOrderBy() == 1) { + lqw.orderByAsc(SisAlarmEvents::getId); + } else if (bo.getOrderBy() == 2) { + lqw.orderByDesc(SisAlarmEvents::getCreateTime); + } else if (bo.getOrderBy() == 3) { + lqw.orderByAsc(SisAlarmEvents::getCreateTime); + } else if (bo.getOrderBy() == 4) { + lqw.orderByDesc(SisAlarmEvents::getSolveTime); + } else if (bo.getOrderBy() == 5) { + lqw.orderByAsc(SisAlarmEvents::getSolveTime); + } else if (bo.getOrderBy() == 6) { + lqw.orderByAsc(SisAlarmEvents::getFinishTime); + } else if (bo.getOrderBy() == 7) { + lqw.orderByAsc(SisAlarmEvents::getFinishTime); + } return lqw; } @@ -292,7 +311,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService { events.setSolvePhone(bo.getSolvePhone()); events.setSolveEmail(bo.getSolveEmail()); events.setSolveName(bo.getSolveName()); - events.setSolveDeptId(bo.getSolveDeptId()); + events.setSolveDeptId(attendInfo.getDeptId()); events.setSolveTime(now); events.setState(AlarmStatus.CONFIRMED.getCode()); int i = this.baseMapper.updateById(events);