增加设备基础信息接口
This commit is contained in:
parent
05c2c43e54
commit
13cec6586b
|
@ -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<Device>> 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<Device> getDevice(@RequestParam Long id) {
|
||||
return Response.succeed(deviceService.getDevice(id));
|
||||
}
|
||||
|
||||
/**
|
||||
*新增设备
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
@OperationLog(description = "新增设备", type = LogType.ADD)
|
||||
public Response<String> add(@RequestBody @Valid DeviceCreateDTO deviceCreateDTO) {
|
||||
deviceService.add(deviceCreateDTO);
|
||||
return Response.succeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
@OperationLog(description = "修改设备", type = LogType.UPDATE)
|
||||
public Response<String> edit(@RequestBody @Valid DeviceEditDTO deviceEditDTO) {
|
||||
deviceService.edit(deviceEditDTO);
|
||||
return Response.succeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备
|
||||
*/
|
||||
@GetMapping("/delete")
|
||||
@OperationLog(description = "删除设备", type = LogType.DELETE)
|
||||
public Response<String> delete(@RequestParam Long id) {
|
||||
deviceService.delete(id);
|
||||
return Response.succeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备控制数据
|
||||
*/
|
||||
@GetMapping("/getDeviceControlData")
|
||||
public Response<String> getDeviceControlData(@RequestParam Long id) {
|
||||
deviceService.getDeviceControlData(id);
|
||||
return Response.succeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备历史数据
|
||||
*/
|
||||
@GetMapping("/getDeviceHistoryData")
|
||||
public Response<String> getDeviceHistoryData(@RequestParam Long id) {
|
||||
deviceService.getDeviceHistoryData(id);
|
||||
return Response.succeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备日志数据
|
||||
*/
|
||||
@GetMapping("/getDeviceLogData")
|
||||
public Response<String> getDeviceLogData(@RequestParam Long id) {
|
||||
deviceService.getDeviceLogData(id);
|
||||
return Response.succeed();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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.*;
|
||||
|
||||
|
|
|
@ -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<Device> {
|
||||
|
||||
Page<Device> page(Page<Object> page,
|
||||
@Param("gasWellName") String gasWellName,
|
||||
@Param("gasStationName") String gasStationName,
|
||||
@Param("deviceTypeId") Long deviceTypeId);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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<GasWell> {
|
|||
*/
|
||||
int deleteGasWellByIds(Collection<Long> ids);
|
||||
|
||||
void bindDevice(@Param("gasWellId")Long gasWellId,@Param("deviceId") Long deviceId);
|
||||
|
||||
void unbindDevice(Long id);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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<Device> {
|
||||
|
||||
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;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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<Device> {
|
||||
|
||||
Page<Device> 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);
|
||||
}
|
||||
|
|
@ -72,4 +72,14 @@ public interface GasWellService extends IService<GasWell> {
|
|||
*/
|
||||
int deleteGasWellByIds(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 绑定气井设备
|
||||
*
|
||||
* @param gasWellId 气井主键
|
||||
* @param deviceId 设备主键
|
||||
* @return 结果
|
||||
*/
|
||||
void bindDevice(Long gasWellId, Long deviceId);
|
||||
|
||||
void unbindDevice(Long id);
|
||||
}
|
||||
|
|
|
@ -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<DeviceDao, Device> implements DeviceService {
|
||||
|
||||
@Resource
|
||||
private SnowflakeConfig snowflakeConfig;
|
||||
|
||||
@Resource
|
||||
private DeviceDao deviceDao;
|
||||
@Resource
|
||||
private GasWellService gasWellService;
|
||||
|
||||
@Override
|
||||
public Page<Device> page(Integer currentPage, Integer pageSize, String gasWellName, String gasStationName,Long deviceTypeId){
|
||||
Page<Device> 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<Device> list = list(new LambdaQueryWrapper<Device>().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) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -134,4 +134,15 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?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.isu.gaswellwatch.dao.DepartmentDao">
|
||||
|
||||
<resultMap id="DeviceMap" type="com.isu.gaswellwatch.entity.Device">
|
||||
<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"/>
|
||||
<association property="deviceType" javaType="com.isu.gaswellwatch.entity.Dictionary" select="getDic" column="device_type">
|
||||
</association>
|
||||
<association property="product" javaType="com.isu.gaswellwatch.entity.Dictionary" select="getDic" column="product">
|
||||
</association>
|
||||
<association property="gasWell" javaType="com.isu.gaswellwatch.entity.GasWell" >
|
||||
<id column="gasWellId" property="id"/>
|
||||
<result column="gasWellName" property="name"/>
|
||||
</association>
|
||||
</resultMap>
|
||||
|
||||
<select id="page" resultType="com.isu.gaswellwatch.entity.Device">
|
||||
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>
|
||||
<if test="gasWellName!=null and gasWellName!='' ">
|
||||
and g.name LIKE CONCAT('%',#{gasWellName},'%')
|
||||
</if>
|
||||
<if test="gasStationName!=null and gasStationName!='' ">
|
||||
and u.gas_station LIKE CONCAT('%',#{gasStationName},'%')
|
||||
</if>
|
||||
<if test="deviceTypeId!=null and deviceTypeId!='' ">
|
||||
and u.device_type = #{deviceTypeId}
|
||||
</if>
|
||||
</where>
|
||||
order by u.id desc
|
||||
</select>
|
||||
|
||||
<select id="getDic" parameterType="java.lang.Long" resultType="com.isu.gaswellwatch.entity.Dictionary">
|
||||
SELECT d.*
|
||||
FROM Dictionary d
|
||||
where d.id=#{dicId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -65,6 +65,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="bindDevice">
|
||||
update gas_well set device_id = #{deviceId} where id = #{gasWellId}
|
||||
</update>
|
||||
|
||||
<update id="unbindDevice">
|
||||
update gas_well set device_id = null where id = #{gasWellId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteGasWellById" parameterType="Long">
|
||||
delete from gas_well where id = #{id}
|
||||
</delete>
|
||||
|
|
Loading…
Reference in New Issue