refactor(property): 优化能源趋势查询接口返回值类型

This commit is contained in:
2025-08-28 15:05:01 +08:00
parent 76c0aa74f1
commit cfff5df7d0
7 changed files with 89 additions and 50 deletions

View File

@@ -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<Void> getEnergyTrend(@RequestParam(required = false) String floorId,
public R<Map<String, Object>> 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<String, Object> resultMap = tbMeterRecordService.getEnergyTrend(floorId, meterId, meterType, day, month, year);
return R.ok(resultMap);
}
}

View File

@@ -133,6 +133,11 @@ public class TbMeterInfoVo implements Serializable {
@ExcelProperty(value = "采集器IP")
private String hostIp;
/**
* 租户编号
*/
private String tenantId;
/**
* 备注
*/

View File

@@ -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<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);
log.info("小时数据:{}", hourList);
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);
// 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]);
log.info("天数据:{}", dayList);
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);
// month
List<Map<String, Object>> monthList = baseMapper.getMonthTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year);
log.info("月数据:{}", monthList);
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);
resultMap.put("hour", hourMap);
resultMap.put("day", dayMap);
resultMap.put("month", monthMap);
return resultMap;
}
}

View File

@@ -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<String, Object> getEnergyTrend(String floorId, String meterId, Long meterType, String day, String month, String year);
}

View File

@@ -15,8 +15,8 @@
<if test="meterId != '' and meterId != null">
AND a.meter_id = #{meterId}
</if>
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)
</select>

View File

@@ -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<AccessRecordFindRes> list(QueryDto dto) {
public TableDataInfo<AccessRecordFindRes> 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<AccessRecordFindRes> 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<AccessRecordFindRes> nineLiftList = e8PlatformApi.getPageAccessRecordList(dto);
// TableDataInfo<AccessRecordFindRes> 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);
}
}

View File

@@ -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;
}