diff --git a/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java b/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java new file mode 100644 index 0000000..75b268a --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/controller/DeviceController.java @@ -0,0 +1,106 @@ +package com.isu.gaswellwatch.controller; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.isu.gaswellwatch.annotation.OperationLog; +import com.isu.gaswellwatch.dto.DeviceCreateDTO; +import com.isu.gaswellwatch.dto.DeviceEditDTO; +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 jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +/** + * 设备管理 + * + * @author scwsl + * @date 2024-11-17 + */ +@RestController +@RequiredArgsConstructor +@RequestMapping("/device") +public class DeviceController { + + private final DeviceService deviceService; + + /** + * 查询设备列表 + */ + @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) { + return Response.succeed(deviceService.page(currentPage, pageSize, gasWellName,gasStationName,deviceTypeId)); + } + + /** + * 获取设备基础信息 + */ + @GetMapping(value = "/getDevice") + public Response getDevice(@RequestParam Long id) { + return Response.succeed(deviceService.getDevice(id)); + } + + /** + *新增设备 + */ + @PostMapping(value = "/add") + @OperationLog(description = "新增设备", type = LogType.ADD) + public Response add(@RequestBody @Valid DeviceCreateDTO deviceCreateDTO) { + deviceService.add(deviceCreateDTO); + return Response.succeed(); + } + + /** + * 修改设备 + */ + @PostMapping("/edit") + @OperationLog(description = "修改设备", type = LogType.UPDATE) + public Response edit(@RequestBody @Valid DeviceEditDTO deviceEditDTO) { + deviceService.edit(deviceEditDTO); + return Response.succeed(); + } + + /** + * 删除设备 + */ + @GetMapping("/delete") + @OperationLog(description = "删除设备", type = LogType.DELETE) + public Response delete(@RequestParam Long id) { + deviceService.delete(id); + return Response.succeed(); + } + + /** + * 获取设备控制数据 + */ + @GetMapping("/getDeviceControlData") + public Response getDeviceControlData(@RequestParam Long id) { + deviceService.getDeviceControlData(id); + return Response.succeed(); + } + + /** + * 获取设备历史数据 + */ + @GetMapping("/getDeviceHistoryData") + public Response getDeviceHistoryData(@RequestParam Long id) { + deviceService.getDeviceHistoryData(id); + return Response.succeed(); + } + + /** + * 获取设备日志数据 + */ + @GetMapping("/getDeviceLogData") + public Response getDeviceLogData(@RequestParam Long id) { + deviceService.getDeviceLogData(id); + return Response.succeed(); + } + + +} diff --git a/src/main/java/com/isu/gaswellwatch/controller/GasWellController.java b/src/main/java/com/isu/gaswellwatch/controller/GasWellController.java index 0ac8ffe..7e247e9 100644 --- a/src/main/java/com/isu/gaswellwatch/controller/GasWellController.java +++ b/src/main/java/com/isu/gaswellwatch/controller/GasWellController.java @@ -1,16 +1,8 @@ package com.isu.gaswellwatch.controller; -import java.util.Collection; -import java.util.List; - -import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -19,11 +11,9 @@ import com.isu.gaswellwatch.entity.Response; import com.isu.gaswellwatch.enums.LogType; import com.isu.gaswellwatch.dto.GasWellCreateRequest; import com.isu.gaswellwatch.dto.GasWellEditRequest; -import com.isu.gaswellwatch.vo.GasWellPageQuery; import com.isu.gaswellwatch.vo.GasWellVO; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.isu.gaswellwatch.annotation.OperationLog; -import jakarta.annotation.Resource; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java b/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java new file mode 100644 index 0000000..8f62837 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/dao/DeviceDao.java @@ -0,0 +1,23 @@ +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 org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +@Mapper +@Repository +public interface DeviceDao extends BaseMapper { + + Page page(Page page, + @Param("gasWellName") String gasWellName, + @Param("gasStationName") String gasStationName, + @Param("deviceTypeId") Long deviceTypeId); + + +} + diff --git a/src/main/java/com/isu/gaswellwatch/dao/GasWellDao.java b/src/main/java/com/isu/gaswellwatch/dao/GasWellDao.java index 1a97add..ec5069c 100644 --- a/src/main/java/com/isu/gaswellwatch/dao/GasWellDao.java +++ b/src/main/java/com/isu/gaswellwatch/dao/GasWellDao.java @@ -4,6 +4,7 @@ import java.util.Collection; import java.util.List; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.isu.gaswellwatch.vo.GasWellVO; @@ -74,4 +75,7 @@ public interface GasWellDao extends BaseMapper { */ int deleteGasWellByIds(Collection ids); + void bindDevice(@Param("gasWellId")Long gasWellId,@Param("deviceId") Long deviceId); + + void unbindDevice(Long id); } diff --git a/src/main/java/com/isu/gaswellwatch/dto/DeviceCreateDTO.java b/src/main/java/com/isu/gaswellwatch/dto/DeviceCreateDTO.java new file mode 100644 index 0000000..b94c62a --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/dto/DeviceCreateDTO.java @@ -0,0 +1,54 @@ +package com.isu.gaswellwatch.dto; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 设备对象 Device + * + * @author scwsl + * @date 2024-11-17 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class DeviceCreateDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** 设备类型 */ + @NotNull(message = "设备类型不能为空") + private Long deviceType; + + /** 设备编号 */ + @NotBlank(message = "设备编号不能为空") + private String code; + + /** 集气站 */ + private String gasStation; + + /** 设备品牌 */ + @NotNull(message = "设备品牌不能为空") + private Long product; + + /** 网关通讯地址 */ + @NotBlank(message = "网关通讯地址不能为空") + private String gatewaySn; + + /** 描述 */ + private String details; + + /** 所属气井 */ + @NotNull(message = "所属气井不能为空") + private Long gasWell; + + + +} diff --git a/src/main/java/com/isu/gaswellwatch/dto/DeviceEditDTO.java b/src/main/java/com/isu/gaswellwatch/dto/DeviceEditDTO.java new file mode 100644 index 0000000..ea7d69d --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/dto/DeviceEditDTO.java @@ -0,0 +1,40 @@ +package com.isu.gaswellwatch.dto; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 设备对象 Device + * + * @author scwsl + * @date 2024-11-17 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class DeviceEditDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** 主键 */ + @NotNull(message = "设备ID不能为空") + private Long id; + + /** 集气站 */ + private String gasStation; + + /** 网关通讯地址 */ + private String gatewaySn; + + /** 描述 */ + private String details; + + + +} diff --git a/src/main/java/com/isu/gaswellwatch/entity/Device.java b/src/main/java/com/isu/gaswellwatch/entity/Device.java new file mode 100644 index 0000000..ffaee17 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/entity/Device.java @@ -0,0 +1,56 @@ +package com.isu.gaswellwatch.entity; + +import com.baomidou.mybatisplus.extension.activerecord.Model; +import com.isu.gaswellwatch.vo.DepartmentVO; +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 Device 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/java/com/isu/gaswellwatch/service/DeviceService.java b/src/main/java/com/isu/gaswellwatch/service/DeviceService.java new file mode 100644 index 0000000..3633c9f --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/service/DeviceService.java @@ -0,0 +1,29 @@ +package com.isu.gaswellwatch.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.isu.gaswellwatch.dto.DepartmentDTO; +import com.isu.gaswellwatch.dto.DepartmentEditDTO; +import com.isu.gaswellwatch.dto.DeviceCreateDTO; +import com.isu.gaswellwatch.dto.DeviceEditDTO; +import com.isu.gaswellwatch.entity.Device; + +public interface DeviceService extends IService { + + Page page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName, Long deviceTypeId); + + void add(DeviceCreateDTO deviceCreateDTO); + + void edit(DeviceEditDTO deviceEditDTO); + + void delete(Long id); + + Device getDevice(Long id); + + void getDeviceControlData(Long id); + + void getDeviceHistoryData(Long id); + + void getDeviceLogData(Long id); +} + diff --git a/src/main/java/com/isu/gaswellwatch/service/GasWellService.java b/src/main/java/com/isu/gaswellwatch/service/GasWellService.java index 3c8a484..dd16b32 100644 --- a/src/main/java/com/isu/gaswellwatch/service/GasWellService.java +++ b/src/main/java/com/isu/gaswellwatch/service/GasWellService.java @@ -72,4 +72,14 @@ public interface GasWellService extends IService { */ int deleteGasWellByIds(Collection ids); + /** + * 绑定气井设备 + * + * @param gasWellId 气井主键 + * @param deviceId 设备主键 + * @return 结果 + */ + void bindDevice(Long gasWellId, Long deviceId); + + void unbindDevice(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 new file mode 100644 index 0000000..1b57036 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/service/impl/DeviceServiceImpl.java @@ -0,0 +1,102 @@ +package com.isu.gaswellwatch.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.isu.gaswellwatch.config.SnowflakeConfig; +import com.isu.gaswellwatch.dao.DepartmentDao; +import com.isu.gaswellwatch.dao.DeviceDao; +import com.isu.gaswellwatch.dto.DepartmentDTO; +import com.isu.gaswellwatch.dto.DepartmentEditDTO; +import com.isu.gaswellwatch.dto.DeviceCreateDTO; +import com.isu.gaswellwatch.dto.DeviceEditDTO; +import com.isu.gaswellwatch.entity.BlockDepartment; +import com.isu.gaswellwatch.entity.Department; +import com.isu.gaswellwatch.entity.Device; +import com.isu.gaswellwatch.exception.BusinessException; +import com.isu.gaswellwatch.service.BlockDepartmentService; +import com.isu.gaswellwatch.service.DepartmentService; +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 jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service("deviceService") +@Transactional(rollbackFor = Exception.class) +public class DeviceServiceImpl extends ServiceImpl implements DeviceService { + + @Resource + private SnowflakeConfig snowflakeConfig; + + @Resource + private DeviceDao deviceDao; + @Resource + 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); + + //TODO 从Redis获取设备数据 + + return ConverterUtil.convertPage(page, Device.class); + } + + @Override + public void add(DeviceCreateDTO deviceCreateDTO){ + //查重 + List list = list(new LambdaQueryWrapper().eq(Device::getId, deviceCreateDTO.getCode())); + if(CollectionUtil.isNotEmpty(list)) { + throw new BusinessException("已有相同设备编码,请重新输入"); + } + Device device = ConverterUtil.convert(deviceCreateDTO, Device.class); + //code必须为整形,用于在缓存中查询设备的上报数据 + device.setId(Long.valueOf(deviceCreateDTO.getCode())); + save(device); + + //在气井中绑定设备 + gasWellService.bindDevice(deviceCreateDTO.getGasWell(),device.getId()); + } + + @Override + public void edit(DeviceEditDTO deviceEditDTO){ + updateById(ConverterUtil.convert(deviceEditDTO, Device.class)); + } + + @Override + public void delete(Long id){ + //删除设备 + removeById(id); + //解绑气井 + gasWellService.unbindDevice(id); + } + + @Override + public Device getDevice(Long id) { + return null; + } + + @Override + public void getDeviceControlData(Long id) { + + } + + @Override + public void getDeviceHistoryData(Long id) { + + } + + @Override + public void getDeviceLogData(Long id) { + + } + + +} + diff --git a/src/main/java/com/isu/gaswellwatch/service/impl/GasWellServiceImpl.java b/src/main/java/com/isu/gaswellwatch/service/impl/GasWellServiceImpl.java index dfb287d..50e425e 100644 --- a/src/main/java/com/isu/gaswellwatch/service/impl/GasWellServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/service/impl/GasWellServiceImpl.java @@ -134,4 +134,15 @@ public class GasWellServiceImpl extends ServiceImpl implem return gasWellDao.deleteGasWellByIds(ids); } + @Override + public void bindDevice(Long gasWellId, Long deviceId) { + gasWellDao.bindDevice(gasWellId,deviceId); + } + + @Override + public void unbindDevice(Long id) { + gasWellDao.unbindDevice(id); + } + + } diff --git a/src/main/resources/mapper/DeviceDao.xml b/src/main/resources/mapper/DeviceDao.xml new file mode 100644 index 0000000..236dd43 --- /dev/null +++ b/src/main/resources/mapper/DeviceDao.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mapper/GasWellMapper.xml b/src/main/resources/mapper/GasWellMapper.xml index a1d5bdb..1382237 100644 --- a/src/main/resources/mapper/GasWellMapper.xml +++ b/src/main/resources/mapper/GasWellMapper.xml @@ -65,6 +65,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + + update gas_well set device_id = #{deviceId} where id = #{gasWellId} + + + + update gas_well set device_id = null where id = #{gasWellId} + + delete from gas_well where id = #{id}