From cfff5df7d01a49e61b8e4be10d89754462d43b5a Mon Sep 17 00:00:00 2001 From: zcxlsm Date: Thu, 28 Aug 2025 15:05:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor(property):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=83=BD=E6=BA=90=E8=B6=8B=E5=8A=BF=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=80=BC=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TbMeterRecordController.java | 7 +- .../vo/smartDevicesVo/TbMeterInfoVo.java | 5 ++ .../TbMeterRecordServiceImpl.java | 43 ++++++++++- .../ITbMeterRecordService.java | 3 +- .../TbMeterReocordMapper.xml | 4 +- .../sis/controller/SisVisitorController.java | 75 +++++++++---------- .../sdk/e8/service/E8PlatformApiService.java | 2 + 7 files changed, 89 insertions(+), 50 deletions(-) diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterRecordController.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterRecordController.java index 998c8208..2c4fbbd2 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterRecordController.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterRecordController.java @@ -1,6 +1,7 @@ package org.dromara.property.controller.smartDevicesController; import java.util.List; +import java.util.Map; import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; @@ -115,13 +116,13 @@ public class TbMeterRecordController extends BaseController { * @param year 年份 */ @GetMapping("/trend") - public R getEnergyTrend(@RequestParam(required = false) String floorId, + public R> getEnergyTrend(@RequestParam(required = false) String floorId, @RequestParam(required = false) String meterId, @RequestParam Long meterType, @RequestParam String day, @RequestParam String month, @RequestParam String year) { - tbMeterRecordService.getEnergyTrend(floorId, meterId, meterType, day, month, year); - return R.ok(); + Map resultMap = tbMeterRecordService.getEnergyTrend(floorId, meterId, meterType, day, month, year); + return R.ok(resultMap); } } 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 467f85c3..2ec7ef46 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 @@ -133,6 +133,11 @@ public class TbMeterInfoVo implements Serializable { @ExcelProperty(value = "采集器IP") private String hostIp; + /** + * 租户编号 + */ + private String tenantId; + /** * 备注 */ 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 bcbdb9c2..13793fdd 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 @@ -194,6 +194,7 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService { record.setMeterType(info.getMeterType()); record.setReaderId(1L); record.setReadingTime(DateUtil.parse(result.getRecordTime(), "yyyy-MM-dd HH:mm:ss")); + record.setTenantId(info.getTenantId()); // 获取当前读数 BigDecimal currentReading = BigDecimal.valueOf( @@ -234,16 +235,50 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService { * @param year 年份 */ @Override - public void getEnergyTrend(String floorId, String meterId, Long meterType, String day, String month, String year) { + public Map getEnergyTrend(String floorId, String meterId, Long meterType, String day, String month, String year) { + Map resultMap = new HashMap<>(); + // hour List> hourList = baseMapper.getHourTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, day); - log.info("小时数据:{}", hourList); + Map 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); + // day String[] monthArr = month.split("-"); List> dayList = baseMapper.getDayTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, monthArr[0], monthArr[1]); - log.info("天数据:{}", dayList); + Map 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); + // month List> monthList = baseMapper.getMonthTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year); - log.info("月数据:{}", monthList); + Map 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); + + + resultMap.put("hour", hourMap); + resultMap.put("day", dayMap); + resultMap.put("month", monthMap); + 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 b084f76a..795ee91e 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 @@ -8,6 +8,7 @@ import org.dromara.property.rocketmq.domain.MeterResult; import java.util.Collection; import java.util.List; +import java.util.Map; /** * 抄记录Service接口 @@ -84,5 +85,5 @@ public interface ITbMeterRecordService { * @param month 月份 * @param year 年份 */ - void getEnergyTrend(String floorId, String meterId, Long meterType, String day, String month, String year); + Map getEnergyTrend(String floorId, String meterId, Long meterType, String day, String month, String year); } diff --git a/ruoyi-modules/Property/src/main/resources/mapper/Property/smartDevicesService/TbMeterReocordMapper.xml b/ruoyi-modules/Property/src/main/resources/mapper/Property/smartDevicesService/TbMeterReocordMapper.xml index e3fca9c9..b56d55e2 100644 --- a/ruoyi-modules/Property/src/main/resources/mapper/Property/smartDevicesService/TbMeterReocordMapper.xml +++ b/ruoyi-modules/Property/src/main/resources/mapper/Property/smartDevicesService/TbMeterReocordMapper.xml @@ -15,8 +15,8 @@ AND a.meter_id = #{meterId} - GROUP BY CONCAT_WS(':', HOUR(reading_time), '00') - ORDER BY hour + GROUP BY CONCAT_WS(':', HOUR(reading_time), '00'), HOUR(reading_time) + ORDER BY HOUR(reading_time) diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisVisitorController.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisVisitorController.java index c0ce0a21..588bd650 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisVisitorController.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisVisitorController.java @@ -4,6 +4,8 @@ package org.dromara.sis.controller; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateUtil; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -17,6 +19,7 @@ import org.dromara.sis.service.ISisPersonLibImgService; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; @@ -40,46 +43,38 @@ public class SisVisitorController { * 查询人员通行记录 */ @GetMapping("/list") - public TableDataInfo list(QueryDto dto) { + public TableDataInfo list(@RequestParam(required = false) String beginTime, + @RequestParam(required = false) String endTime, + @NotNull(message = "页码不能为空") @RequestParam Integer pageNum, + @NotNull(message = "页数不能为空") @RequestParam Integer pageSize, + @RequestParam(required = false) String personName, + @RequestParam(required = false) Integer recordType) { + AccessRecordFindReq req = new AccessRecordFindReq(); + if (beginTime != null && !beginTime.isEmpty()) { + req.setStartTime(DateUtil.format(DateUtil.parse(beginTime), "yyyy-MM-dd 00:00:00")); + } else { + // 默认设置为7天前 + req.setStartTime(DateUtil.format(DateUtil.offset(new Date(), DateField.DAY_OF_MONTH, -7), "yyyy-MM-dd 00:00:00")); + } + if (endTime != null && !endTime.isEmpty()) { + req.setEndTime(DateUtil.format(DateUtil.parse(endTime), "yyyy-MM-dd 23:59:59")); + } else { + // 默认设置为今天 + req.setEndTime(DateUtil.format(new Date(), "yyyy-MM-dd 23:59:59")); + } - TableDataInfo tableDataInfo = new TableDataInfo(); - List accessRecordFindResList = new ArrayList<>(); - AccessRecordFindRes accessRecordFindRes = new AccessRecordFindRes(); - accessRecordFindRes.setDeviceName("4#岗亭09"); - accessRecordFindRes.setDoorName("4#岗亭09"); - accessRecordFindRes.setDeviceType(1102); - accessRecordFindRes.setReaderName(""); - accessRecordFindRes.setGatewayType(1); - accessRecordFindRes.setCustomerName("德隆吴鹏"); - accessRecordFindRes.setOrganFullPath("主楼11楼"); - accessRecordFindRes.setPictureUrl("https://bpic.588ku.com/back_list_pic/23/04/21/ef5e2a3dd5cfc336fdcf2fd000474f0f.jpg"); - accessRecordFindRes.setCardType(34); - accessRecordFindRes.setRecordType(2); - accessRecordFindRes.setActionTime(new Date()); - accessRecordFindResList.add(accessRecordFindRes); - tableDataInfo.setRows(accessRecordFindResList); - tableDataInfo.setTotal(1); - tableDataInfo.setCode(200); - return tableDataInfo; -// -// dto.setPageIndex(1); -// dto.setMaxResultCount(20); -// -// // 10秒内 -// String starTime = DateUtil.format(DateUtil.offset(new Date(), DateField.SECOND, -10), "yyyy-MM-dd HH:mm:ss"); -// String endTime = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); -// -// AccessRecordFindReq lift = new AccessRecordFindReq(); -// lift.setStartTime(starTime); -// lift.setEndTime(endTime); -// lift.setRecordType(2); -// // 9号电梯 -// lift.setDeviceId(550757939925061L); -// dto.setQueryDto(lift); -//// TableDataInfo nineLiftList = e8PlatformApi.getPageAccessRecordList(dto); -// TableDataInfo pageAccessRecordList = new TableDataInfo(); -// -// return e8PlatformApi.getPageAccessRecordList(dto); - //如果pageAccessRecordList报错就捕获并封装 + if (personName != null && !personName.isEmpty()) { + req.setCustomerName(personName); + } + + if (recordType != null) { + req.setRecordType(recordType); + } + + QueryDto dto = new QueryDto(); + dto.setQueryDto(req); + dto.setPageIndex(pageNum); + dto.setMaxResultCount(pageSize); + return e8PlatformApi.getPageAccessRecordList(dto); } } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/e8/service/E8PlatformApiService.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/e8/service/E8PlatformApiService.java index 6a0096ee..673c7090 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/e8/service/E8PlatformApiService.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/e8/service/E8PlatformApiService.java @@ -422,6 +422,8 @@ public class E8PlatformApiService implements E8PlatformApi { tableData.setTotal(Long.parseLong(result.get("total").toString())); // 从结果映射中获取项目列表,转换为访问记录信息列表后设置到分页对象中 tableData.setRows(JSONUtil.toList(JSONUtil.toJsonStr(result.get("item")), AccessRecordFindRes.class)); + tableData.setCode(200); + tableData.setMsg("查询成功"); // 返回填充了数据的分页对象 return tableData; }