123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package com.hb.proj.base.controller;
- import java.util.List;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import com.hb.proj.allconfig.AccessToken;
- import com.hb.proj.allconfig.SysLog;
- import com.hb.proj.base.service.DeviceService;
- import com.hb.proj.model.DevicePO;
- import com.hb.proj.model.DeviceVO;
- import com.hb.proj.utils.RequestParams;
- import com.hb.proj.utils.RespVO;
- import com.hb.proj.utils.RespVOBuilder;
- import com.hb.xframework.dao.util.PageModel;
- import jakarta.validation.constraints.NotBlank;
- @RestController
- @RequestMapping("/base/device")
- @Validated
- public class DeviceController {
- @Autowired
- private DeviceService service;
-
- @Autowired
- private SynGatherComp synComp;
-
-
- /**
- * 加载某类设备的基本信息
- * @param devType 设备类型
- * @return
- */
- @RequestMapping("/loadByType")
- public RespVO<List<DeviceVO>> loadByType(@NotBlank(message="设备类型不应为空") String devType){
- return RespVOBuilder.ok(service.loadByType(devType));
- }
-
-
- /**
- * 查询设备列表
- * @apiNote 查询参数类型列表
- * @param params 查询参数
- * @param pageNum 页码
- * @param pageSize 每页记录数
- * @return
- */
- @RequestMapping("/query")
- public RespVO<PageModel<DeviceVO>> query(RequestParams params,
- @RequestParam(value = "currentPage", defaultValue = "1") Integer pageNum,
- @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize) {
- return RespVOBuilder.ok(service.query(params.getObjectMap(), pageNum, pageSize));
- }
-
-
- /**
- * 获得单个设备数据
- * @param deviceId 设备记录id
- * @return
- */
- @RequestMapping("/get")
- public RespVO<DeviceVO> get(@NotBlank(message = "缺少记录号") String deviceId){
- return RespVOBuilder.ok(service.get(deviceId));
- }
-
-
- /**
- * 删除单个设备
- * @param deviceId 待删除记录id
- * @return
- */
- @RequestMapping("/delete")
- @SysLog("删除设备信息:{arg0}")
- public RespVO<Object> delete(String deviceId){
- service.delete(deviceId);
- return RespVOBuilder.ok();
- }
-
- /**
- * 增加新设备
- * @param device 设备实体对象
- * @param token 当前登录实体
- * @return
- */
- @RequestMapping("/add")
- public RespVO<String> add(@Validated DevicePO device,AccessToken token){
- if(service.existDevice(device.getDeviceCode(),null)) {
- return RespVOBuilder.error("该设备编码已存在,勿重复添加");
- }
- device.setModifyBy(token.getUsName());
- String devId=service.add(device);
- synComp.synAllDev();
- return RespVOBuilder.ok(devId);
-
- }
-
-
- /**
- * 更新设备信息
- * @param device 设备实体对象
- * @param token 当前登录实体
- * @return
- */
- @RequestMapping("/update")
- public RespVO<Object> update(@Validated DevicePO device,AccessToken token){
- if(service.existDevice(device.getDeviceCode(), device.getDeviceId())) {
- return RespVOBuilder.error("该设备编码已存在,勿重复添加");
- }
-
- DeviceVO dbDev=service.get(device.getDeviceId());
- if(dbDev==null) {
- return RespVOBuilder.error("设备不存在");
- }
- device.setWellId(dbDev.getWellId()); //避免更新时丢失已关联的井
- device.setModifyBy(token.getUsName());
- service.update(device);
-
- if(device.getDeviceCode().equals(dbDev.getDeviceCode())) { //更改了设备编号,同步通知采集程序
- synComp.synAllDev();
- }
-
- return RespVOBuilder.ok();
-
-
- }
-
- /**
- * 同步采集程序对所有设备重加载
- * @return
- */
- @RequestMapping("/synGather")
- public RespVO<Object> synGather(){
- boolean rst=synComp.synAllDev();
- if(rst) {
- return RespVOBuilder.ok();
- }
- else {
- return RespVOBuilder.error("同步失败");
- }
- }
- }
|