refactor(iot): 优化设备记录查询接口
- 修改 DeviceController 中记录查询接口的路径 - 新增 RecordDataService 接口的 query 方法 - 实现 RecordDataServiceImpl 中的 query 方法 - 在 RecordDataRepository 中添加 selectByClientId 方法 - 新增 RecordDataMapper.xml 文件,定义 selectByClientId 方法的 SQL 查询
This commit is contained in:
parent
45bb5af901
commit
38f868cfd3
@ -17,6 +17,7 @@ import com.zsc.edu.gateway.modules.iot.device.vo.DeviceVo;
|
|||||||
import com.zsc.edu.gateway.modules.iot.record.entity.DataWarningVo;
|
import com.zsc.edu.gateway.modules.iot.record.entity.DataWarningVo;
|
||||||
import com.zsc.edu.gateway.modules.iot.record.entity.RecordData;
|
import com.zsc.edu.gateway.modules.iot.record.entity.RecordData;
|
||||||
import com.zsc.edu.gateway.modules.iot.record.entity.RecordDataStatusVo;
|
import com.zsc.edu.gateway.modules.iot.record.entity.RecordDataStatusVo;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.record.repo.RecordDataRepository;
|
||||||
import com.zsc.edu.gateway.modules.iot.record.service.RecordDataService;
|
import com.zsc.edu.gateway.modules.iot.record.service.RecordDataService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -34,6 +35,7 @@ import java.util.List;
|
|||||||
@RequestMapping("api/rest/device")
|
@RequestMapping("api/rest/device")
|
||||||
public class DeviceController {
|
public class DeviceController {
|
||||||
|
|
||||||
|
private final RecordDataRepository recordDataRepository;
|
||||||
DeviceService service;
|
DeviceService service;
|
||||||
|
|
||||||
RecordDataService recordService;
|
RecordDataService recordService;
|
||||||
@ -114,12 +116,11 @@ public class DeviceController {
|
|||||||
/**
|
/**
|
||||||
* 查询设备上报记录
|
* 查询设备上报记录
|
||||||
*/
|
*/
|
||||||
@GetMapping("record/data")
|
@GetMapping("record/data/list")
|
||||||
@PreAuthorize("hasAuthority('iot:device:query')")
|
@PreAuthorize("hasAuthority('iot:device:query')")
|
||||||
public Page<RecordData> recordData(Page<RecordData> page, String clientId) {
|
public IPage<RecordData> recordData(Page<RecordData> page, String clientId) {
|
||||||
return recordService.page(page, new LambdaQueryWrapper<RecordData>().eq(RecordData::getClientId, clientId));
|
return recordService.query(page, clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询设备信息数量
|
* 查询设备信息数量
|
||||||
*/
|
*/
|
||||||
|
@ -20,4 +20,6 @@ public interface RecordDataRepository extends BaseMapper<RecordData> {
|
|||||||
|
|
||||||
@Select("SELECT COUNT(*) FROM iot_record_data WHERE content->>'warning' IS NOT NULL AND (content->>'warning')::int & #{bitPosition} = #{bitPosition}")
|
@Select("SELECT COUNT(*) FROM iot_record_data WHERE content->>'warning' IS NOT NULL AND (content->>'warning')::int & #{bitPosition} = #{bitPosition}")
|
||||||
long countWarningsByBit(@Param("bitPosition") int bitPosition);
|
long countWarningsByBit(@Param("bitPosition") int bitPosition);
|
||||||
|
|
||||||
|
List<RecordData> selectByClientId(@Param("clientId") String clientId);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.zsc.edu.gateway.modules.iot.record.service;
|
package com.zsc.edu.gateway.modules.iot.record.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.zsc.edu.gateway.modules.iot.record.entity.DataWarningVo;
|
import com.zsc.edu.gateway.modules.iot.record.entity.DataWarningVo;
|
||||||
import com.zsc.edu.gateway.modules.iot.record.entity.RecordData;
|
import com.zsc.edu.gateway.modules.iot.record.entity.RecordData;
|
||||||
@ -18,4 +20,6 @@ public interface RecordDataService extends IService<RecordData> {
|
|||||||
RecordDataStatusVo recordDataStatus();
|
RecordDataStatusVo recordDataStatus();
|
||||||
|
|
||||||
DataWarningVo dataWarning();
|
DataWarningVo dataWarning();
|
||||||
|
|
||||||
|
IPage<RecordData> query(Page<RecordData> page, String clientId);
|
||||||
}
|
}
|
@ -2,6 +2,8 @@ package com.zsc.edu.gateway.modules.iot.record.service.impl;
|
|||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.zsc.edu.gateway.modules.iot.record.entity.DataWarningVo;
|
import com.zsc.edu.gateway.modules.iot.record.entity.DataWarningVo;
|
||||||
import com.zsc.edu.gateway.modules.iot.record.entity.RecordData;
|
import com.zsc.edu.gateway.modules.iot.record.entity.RecordData;
|
||||||
@ -21,6 +23,8 @@ import java.util.List;
|
|||||||
@Service
|
@Service
|
||||||
public class RecordDataServiceImpl extends ServiceImpl<RecordDataRepository, RecordData> implements RecordDataService {
|
public class RecordDataServiceImpl extends ServiceImpl<RecordDataRepository, RecordData> implements RecordDataService {
|
||||||
|
|
||||||
|
private final RecordDataRepository recordDataRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecordData recordData(String clientId, JSONObject data) {
|
public RecordData recordData(String clientId, JSONObject data) {
|
||||||
RecordData recordData = new RecordData();
|
RecordData recordData = new RecordData();
|
||||||
@ -56,4 +60,12 @@ public class RecordDataServiceImpl extends ServiceImpl<RecordDataRepository, Rec
|
|||||||
return dataWarningVo;
|
return dataWarningVo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<RecordData> query(Page<RecordData> page, String clientId) {
|
||||||
|
List<RecordData> recordDataList = recordDataRepository.selectByClientId(clientId);
|
||||||
|
page.setRecords(recordDataList);
|
||||||
|
page.setTotal(recordDataList.size());
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,10 @@ package com.zsc.edu.gateway.modules.system.entity;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.zsc.edu.gateway.modules.system.vo.UserVo;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门
|
* 部门
|
||||||
|
18
src/main/resources/mappers/iot/RecordDataMapper.xml
Normal file
18
src/main/resources/mappers/iot/RecordDataMapper.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.zsc.edu.gateway.modules.iot.record.repo.RecordDataRepository">
|
||||||
|
<resultMap id="BaseResultMap" type="com.zsc.edu.gateway.modules.iot.record.entity.RecordData">
|
||||||
|
<id column="id" property="id"/>
|
||||||
|
<result column="client_id" property="clientId"/>
|
||||||
|
<result column="content" property="content" typeHandler="com.zsc.edu.gateway.framework.json.JsonbTypeHandler"/>
|
||||||
|
<result column="record_time" property="recordTime"/>
|
||||||
|
<result column="dept_id" property="deptId"/>
|
||||||
|
</resultMap>
|
||||||
|
<select id="selectByClientId" resultMap="BaseResultMap">
|
||||||
|
select *
|
||||||
|
from iot_record_data
|
||||||
|
where client_id = #{clientId}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue
Block a user