设备接口修改

This commit is contained in:
qinjie 2024-11-25 15:48:00 +08:00
parent 2235da9352
commit 24795e3b17
9 changed files with 111 additions and 27 deletions

View File

@ -8,6 +8,7 @@ import com.isu.gaswellwatch.entity.Device;
import com.isu.gaswellwatch.entity.Response; import com.isu.gaswellwatch.entity.Response;
import com.isu.gaswellwatch.enums.LogType; import com.isu.gaswellwatch.enums.LogType;
import com.isu.gaswellwatch.service.DeviceService; import com.isu.gaswellwatch.service.DeviceService;
import com.isu.gaswellwatch.vo.DeviceVO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -29,11 +30,11 @@ public class DeviceController {
* 查询设备列表 * 查询设备列表
*/ */
@GetMapping(value = "/page") @GetMapping(value = "/page")
public Response<Page<Device>> page(@RequestParam(defaultValue = "1") Integer currentPage, public Response<Page<DeviceVO>> page(@RequestParam(defaultValue = "1") Integer currentPage,
@RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String gasWellName, @RequestParam(required = false) String gasWellName,
@RequestParam(required = false) String gasStationName, @RequestParam(required = false) String gasStationName,
@RequestParam Long deviceTypeId) { @RequestParam Long deviceTypeId) {
return Response.succeed(deviceService.page(currentPage, pageSize, gasWellName,gasStationName,deviceTypeId)); return Response.succeed(deviceService.page(currentPage, pageSize, gasWellName,gasStationName,deviceTypeId));
} }
@ -41,7 +42,7 @@ public class DeviceController {
* 获取设备基础信息 * 获取设备基础信息
*/ */
@GetMapping(value = "/getDevice") @GetMapping(value = "/getDevice")
public Response<Device> getDevice(@RequestParam Long id) { public Response<DeviceVO> getDevice(@RequestParam Long id) {
return Response.succeed(deviceService.getDevice(id)); return Response.succeed(deviceService.getDevice(id));
} }

View File

@ -2,9 +2,8 @@ package com.isu.gaswellwatch.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.entity.Department;
import com.isu.gaswellwatch.entity.Device; import com.isu.gaswellwatch.entity.Device;
import com.isu.gaswellwatch.vo.DepartmentVO; import com.isu.gaswellwatch.vo.DeviceVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -13,11 +12,12 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface DeviceDao extends BaseMapper<Device> { public interface DeviceDao extends BaseMapper<Device> {
Page<Device> page(Page<Object> page, Page<DeviceVO> page(Page<Object> page,
@Param("gasWellName") String gasWellName, @Param("gasWellName") String gasWellName,
@Param("gasStationName") String gasStationName, @Param("gasStationName") String gasStationName,
@Param("deviceTypeId") Long deviceTypeId); @Param("deviceTypeId") Long deviceTypeId);
DeviceVO getDeviceById(@Param("id") Long id);
} }

View File

@ -25,7 +25,7 @@ public class Device extends Model<Device> {
private Long id; private Long id;
/** 设备类型 */ /** 设备类型 */
private Dictionary deviceType; private Long deviceType;
/** 设备编号 */ /** 设备编号 */
private String code; private String code;
@ -34,7 +34,7 @@ public class Device extends Model<Device> {
private String gasStation; private String gasStation;
/** 设备品牌 */ /** 设备品牌 */
private Dictionary product; private Long product;
/** 网关通讯地址 */ /** 网关通讯地址 */
private String gatewaySn; private String gatewaySn;
@ -43,7 +43,7 @@ public class Device extends Model<Device> {
private String details; private String details;
/** 所属气井 */ /** 所属气井 */
private GasWell gasWell; private Long gasWell;
/** 创建时间 */ /** 创建时间 */
private String createTime; private String createTime;

View File

@ -2,6 +2,7 @@ package com.isu.gaswellwatch.entity;
import com.baomidou.mybatisplus.extension.activerecord.Model; import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -15,6 +16,7 @@ import java.util.Date;
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class Dictionary extends Model<Dictionary> { public class Dictionary extends Model<Dictionary> {
private Long id; private Long id;

View File

@ -1,5 +1,6 @@
package com.isu.gaswellwatch.entity; package com.isu.gaswellwatch.entity;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -19,6 +20,7 @@ import java.time.LocalDateTime;
@NoArgsConstructor @NoArgsConstructor
@ToString(callSuper = true) @ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL)
public class GasWell extends Model<GasWell> { public class GasWell extends Model<GasWell> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -7,10 +7,11 @@ import com.isu.gaswellwatch.dto.DepartmentEditDTO;
import com.isu.gaswellwatch.dto.DeviceCreateDTO; import com.isu.gaswellwatch.dto.DeviceCreateDTO;
import com.isu.gaswellwatch.dto.DeviceEditDTO; import com.isu.gaswellwatch.dto.DeviceEditDTO;
import com.isu.gaswellwatch.entity.Device; import com.isu.gaswellwatch.entity.Device;
import com.isu.gaswellwatch.vo.DeviceVO;
public interface DeviceService extends IService<Device> { public interface DeviceService extends IService<Device> {
Page<Device> page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName, Long deviceTypeId); Page<DeviceVO> page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName, Long deviceTypeId);
void add(DeviceCreateDTO deviceCreateDTO); void add(DeviceCreateDTO deviceCreateDTO);
@ -18,7 +19,7 @@ public interface DeviceService extends IService<Device> {
void delete(Long id); void delete(Long id);
Device getDevice(Long id); DeviceVO getDevice(Long id);
void getDeviceControlData(Long id); void getDeviceControlData(Long id);

View File

@ -21,6 +21,7 @@ import com.isu.gaswellwatch.service.DeviceService;
import com.isu.gaswellwatch.service.GasWellService; import com.isu.gaswellwatch.service.GasWellService;
import com.isu.gaswellwatch.utils.ConverterUtil; import com.isu.gaswellwatch.utils.ConverterUtil;
import com.isu.gaswellwatch.vo.DepartmentVO; import com.isu.gaswellwatch.vo.DepartmentVO;
import com.isu.gaswellwatch.vo.DeviceVO;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -40,12 +41,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements
private GasWellService gasWellService; private GasWellService gasWellService;
@Override @Override
public Page<Device> page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName,Long deviceTypeId){ public Page<DeviceVO> page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName,Long deviceTypeId){
Page<Device> page = deviceDao.page(new Page<>(currentPage, pageSize),gasWellName,gasStationName,deviceTypeId); Page<DeviceVO> page = deviceDao.page(new Page<>(currentPage, pageSize),gasWellName,gasStationName,deviceTypeId);
//TODO 从Redis获取设备数据 //TODO 从Redis获取设备数据
return ConverterUtil.convertPage(page, Device.class); return ConverterUtil.convertPage(page, DeviceVO.class);
} }
@Override @Override
@ -78,8 +79,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceDao, Device> implements
} }
@Override @Override
public Device getDevice(Long id) { public DeviceVO getDevice(Long id) {
return null; return deviceDao.getDeviceById(id);
} }
@Override @Override

View File

@ -0,0 +1,57 @@
package com.isu.gaswellwatch.vo;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.isu.gaswellwatch.entity.Dictionary;
import com.isu.gaswellwatch.entity.GasWell;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 设备对象 Device
*
* @author scwsl
* @date 2024-11-17
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DeviceVO extends Model<DeviceVO> {
private static final long serialVersionUID = 1L;
/** 主键 */
private Long id;
/** 设备类型 */
private Dictionary deviceType;
/** 设备编号 */
private String code;
/** 集气站 */
private String gasStation;
/** 设备品牌 */
private Dictionary product;
/** 网关通讯地址 */
private String gatewaySn;
/** 描述 */
private String details;
/** 所属气井 */
private GasWell gasWell;
/** 创建时间 */
private String createTime;
/** 更新时间 */
private String updateTime;
}

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.isu.gaswellwatch.dao.DepartmentDao"> <mapper namespace="com.isu.gaswellwatch.dao.DeviceDao">
<resultMap id="DeviceMap" type="com.isu.gaswellwatch.entity.Device"> <resultMap id="DeviceVOMap" type="com.isu.gaswellwatch.vo.DeviceVO">
<id column="id" property="id"/> <id column="id" property="id"/>
<result column="code" property="code"/> <result column="code" property="code"/>
<result column="gas_station" property="gasStation"/> <result column="gas_station" property="gasStation"/>
@ -20,9 +20,22 @@
</association> </association>
</resultMap> </resultMap>
<select id="page" resultType="com.isu.gaswellwatch.entity.Device"> <resultMap id="DeviceMap" type="com.isu.gaswellwatch.entity.Device" autoMapping="true">
<id column="id" property="id"/>
<result column="code" property="code"/>
<result column="gas_station" property="gasStation"/>
<result column="gateway_sn" property="gatewaySn"/>
<result column="details" property="details"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result property="deviceType" column="device_type"/>
<result property="product" column="product"/>
<result property="gasWell" column="gas_well"/>
</resultMap>
<select id="page" resultMap="DeviceVOMap">
select u.id, u.device_type, u.code, u.gas_station, u.product, u.gateway_sn, select u.id, u.device_type, u.code, u.gas_station, u.product, u.gateway_sn,
u.gas_well, u.details, u.create_time, u.update_time,g.name as gasWellName,g.id as gasWellId, u.gas_well, u.details, u.create_time, u.update_time,g.name as gasWellName,g.id as gasWellId
from device u left join gas_well g on u.gas_well = g.id from device u left join gas_well g on u.gas_well = g.id
<where> <where>
<if test="gasWellName!=null and gasWellName!='' "> <if test="gasWellName!=null and gasWellName!='' ">
@ -39,10 +52,17 @@
</select> </select>
<select id="getDic" parameterType="java.lang.Long" resultType="com.isu.gaswellwatch.entity.Dictionary"> <select id="getDic" parameterType="java.lang.Long" resultType="com.isu.gaswellwatch.entity.Dictionary">
SELECT d.* SELECT d.id,d.type,d.code,d.name,d.value,d.sort
FROM Dictionary d FROM Dictionary d
where d.id=#{dicId} where d.id=#{dicId}
</select> </select>
<select id="getDeviceById" resultMap="DeviceVOMap">
select u.id, u.device_type, u.code, u.gas_station, u.product, u.gateway_sn,
u.gas_well, u.details, u.create_time, u.update_time,g.name as gasWellName,g.id as gasWellId
from device u left join gas_well g on u.gas_well = g.id
where u.id = #{id}
</select>
</mapper> </mapper>