From 24795e3b17a2e217f9c18e44183059bd0d77d773 Mon Sep 17 00:00:00 2001 From: qinjie <463333974@qq.com> Date: Mon, 25 Nov 2024 15:48:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DeviceController.java | 13 +++-- .../com/isu/gaswellwatch/dao/DeviceDao.java | 12 ++-- .../com/isu/gaswellwatch/entity/Device.java | 6 +- .../isu/gaswellwatch/entity/Dictionary.java | 2 + .../com/isu/gaswellwatch/entity/GasWell.java | 2 + .../gaswellwatch/service/DeviceService.java | 5 +- .../service/impl/DeviceServiceImpl.java | 11 ++-- .../com/isu/gaswellwatch/vo/DeviceVO.java | 57 +++++++++++++++++++ src/main/resources/mapper/DeviceDao.xml | 30 ++++++++-- 9 files changed, 111 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/isu/gaswellwatch/vo/DeviceVO.java diff --git a/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java b/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java index 75b268a..6f93259 100644 --- a/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java +++ b/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java @@ -8,6 +8,7 @@ import com.isu.gaswellwatch.entity.Device; import com.isu.gaswellwatch.entity.Response; import com.isu.gaswellwatch.enums.LogType; import com.isu.gaswellwatch.service.DeviceService; +import com.isu.gaswellwatch.vo.DeviceVO; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -29,11 +30,11 @@ public class DeviceController { * 查询设备列表 */ @GetMapping(value = "/page") - public Response> page(@RequestParam(defaultValue = "1") Integer currentPage, - @RequestParam(defaultValue = "10") Integer pageSize, - @RequestParam(required = false) String gasWellName, - @RequestParam(required = false) String gasStationName, - @RequestParam Long deviceTypeId) { + public Response> page(@RequestParam(defaultValue = "1") Integer currentPage, + @RequestParam(defaultValue = "10") Integer pageSize, + @RequestParam(required = false) String gasWellName, + @RequestParam(required = false) String gasStationName, + @RequestParam Long deviceTypeId) { return Response.succeed(deviceService.page(currentPage, pageSize, gasWellName,gasStationName,deviceTypeId)); } @@ -41,7 +42,7 @@ public class DeviceController { * 获取设备基础信息 */ @GetMapping(value = "/getDevice") - public Response getDevice(@RequestParam Long id) { + public Response getDevice(@RequestParam Long id) { return Response.succeed(deviceService.getDevice(id)); } diff --git a/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java b/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java index 8f62837..7dae7ee 100644 --- a/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java +++ b/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java @@ -2,9 +2,8 @@ package com.isu.gaswellwatch.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.isu.gaswellwatch.entity.Department; 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.Param; import org.springframework.stereotype.Repository; @@ -13,11 +12,12 @@ import org.springframework.stereotype.Repository; @Repository public interface DeviceDao extends BaseMapper { - Page page(Page page, - @Param("gasWellName") String gasWellName, - @Param("gasStationName") String gasStationName, - @Param("deviceTypeId") Long deviceTypeId); + Page page(Page page, + @Param("gasWellName") String gasWellName, + @Param("gasStationName") String gasStationName, + @Param("deviceTypeId") Long deviceTypeId); + DeviceVO getDeviceById(@Param("id") Long id); } diff --git a/src/main/java/com/isu/gaswellwatch/entity/Device.java b/src/main/java/com/isu/gaswellwatch/entity/Device.java index ffaee17..ff45139 100644 --- a/src/main/java/com/isu/gaswellwatch/entity/Device.java +++ b/src/main/java/com/isu/gaswellwatch/entity/Device.java @@ -25,7 +25,7 @@ public class Device extends Model { private Long id; /** 设备类型 */ - private Dictionary deviceType; + private Long deviceType; /** 设备编号 */ private String code; @@ -34,7 +34,7 @@ public class Device extends Model { private String gasStation; /** 设备品牌 */ - private Dictionary product; + private Long product; /** 网关通讯地址 */ private String gatewaySn; @@ -43,7 +43,7 @@ public class Device extends Model { private String details; /** 所属气井 */ - private GasWell gasWell; + private Long gasWell; /** 创建时间 */ private String createTime; diff --git a/src/main/java/com/isu/gaswellwatch/entity/Dictionary.java b/src/main/java/com/isu/gaswellwatch/entity/Dictionary.java index d24d2b3..0ccd8c4 100644 --- a/src/main/java/com/isu/gaswellwatch/entity/Dictionary.java +++ b/src/main/java/com/isu/gaswellwatch/entity/Dictionary.java @@ -2,6 +2,7 @@ package com.isu.gaswellwatch.entity; import com.baomidou.mybatisplus.extension.activerecord.Model; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; @@ -15,6 +16,7 @@ import java.util.Date; @Builder @AllArgsConstructor @NoArgsConstructor +@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) public class Dictionary extends Model { private Long id; diff --git a/src/main/java/com/isu/gaswellwatch/entity/GasWell.java b/src/main/java/com/isu/gaswellwatch/entity/GasWell.java index 499e47e..46a465d 100644 --- a/src/main/java/com/isu/gaswellwatch/entity/GasWell.java +++ b/src/main/java/com/isu/gaswellwatch/entity/GasWell.java @@ -1,5 +1,6 @@ package com.isu.gaswellwatch.entity; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; @@ -19,6 +20,7 @@ import java.time.LocalDateTime; @NoArgsConstructor @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) +@JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL) public class GasWell extends Model { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/isu/gaswellwatch/service/DeviceService.java b/src/main/java/com/isu/gaswellwatch/service/DeviceService.java index 3633c9f..12eff8c 100644 --- a/src/main/java/com/isu/gaswellwatch/service/DeviceService.java +++ b/src/main/java/com/isu/gaswellwatch/service/DeviceService.java @@ -7,10 +7,11 @@ import com.isu.gaswellwatch.dto.DepartmentEditDTO; import com.isu.gaswellwatch.dto.DeviceCreateDTO; import com.isu.gaswellwatch.dto.DeviceEditDTO; import com.isu.gaswellwatch.entity.Device; +import com.isu.gaswellwatch.vo.DeviceVO; public interface DeviceService extends IService { - Page page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName, Long deviceTypeId); + Page page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName, Long deviceTypeId); void add(DeviceCreateDTO deviceCreateDTO); @@ -18,7 +19,7 @@ public interface DeviceService extends IService { void delete(Long id); - Device getDevice(Long id); + DeviceVO getDevice(Long id); void getDeviceControlData(Long id); diff --git a/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java b/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java index 1b57036..029f789 100644 --- a/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java @@ -21,6 +21,7 @@ import com.isu.gaswellwatch.service.DeviceService; import com.isu.gaswellwatch.service.GasWellService; import com.isu.gaswellwatch.utils.ConverterUtil; import com.isu.gaswellwatch.vo.DepartmentVO; +import com.isu.gaswellwatch.vo.DeviceVO; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -40,12 +41,12 @@ public class DeviceServiceImpl extends ServiceImpl implements private GasWellService gasWellService; @Override - public Page page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName,Long deviceTypeId){ - Page page = deviceDao.page(new Page<>(currentPage, pageSize),gasWellName,gasStationName,deviceTypeId); + public Page page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName,Long deviceTypeId){ + Page page = deviceDao.page(new Page<>(currentPage, pageSize),gasWellName,gasStationName,deviceTypeId); //TODO 从Redis获取设备数据 - return ConverterUtil.convertPage(page, Device.class); + return ConverterUtil.convertPage(page, DeviceVO.class); } @Override @@ -78,8 +79,8 @@ public class DeviceServiceImpl extends ServiceImpl implements } @Override - public Device getDevice(Long id) { - return null; + public DeviceVO getDevice(Long id) { + return deviceDao.getDeviceById(id); } @Override diff --git a/src/main/java/com/isu/gaswellwatch/vo/DeviceVO.java b/src/main/java/com/isu/gaswellwatch/vo/DeviceVO.java new file mode 100644 index 0000000..cd80642 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/DeviceVO.java @@ -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 { + + 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; + + + +} diff --git a/src/main/resources/mapper/DeviceDao.xml b/src/main/resources/mapper/DeviceDao.xml index 236dd43..5847b9e 100644 --- a/src/main/resources/mapper/DeviceDao.xml +++ b/src/main/resources/mapper/DeviceDao.xml @@ -1,8 +1,8 @@ - + - + @@ -20,9 +20,22 @@ - 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 @@ -39,10 +52,17 @@ + +