DeviceController.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package com.hb.proj.base.controller;
  2. import java.util.List;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.validation.annotation.Validated;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RequestParam;
  7. import org.springframework.web.bind.annotation.RestController;
  8. import com.hb.proj.allconfig.AccessToken;
  9. import com.hb.proj.allconfig.SysLog;
  10. import com.hb.proj.base.service.DeviceService;
  11. import com.hb.proj.model.DevicePO;
  12. import com.hb.proj.model.DeviceVO;
  13. import com.hb.proj.utils.RequestParams;
  14. import com.hb.proj.utils.RespVO;
  15. import com.hb.proj.utils.RespVOBuilder;
  16. import com.hb.xframework.dao.util.PageModel;
  17. import jakarta.validation.constraints.NotBlank;
  18. @RestController
  19. @RequestMapping("/base/device")
  20. @Validated
  21. public class DeviceController {
  22. @Autowired
  23. private DeviceService service;
  24. @Autowired
  25. private SynGatherComp synComp;
  26. /**
  27. * 加载某类设备的基本信息
  28. * @param devType 设备类型
  29. * @return
  30. */
  31. @RequestMapping("/loadByType")
  32. public RespVO<List<DeviceVO>> loadByType(@NotBlank(message="设备类型不应为空") String devType){
  33. return RespVOBuilder.ok(service.loadByType(devType));
  34. }
  35. /**
  36. * 查询设备列表
  37. * @apiNote 查询参数类型列表
  38. * @param params 查询参数
  39. * @param pageNum 页码
  40. * @param pageSize 每页记录数
  41. * @return
  42. */
  43. @RequestMapping("/query")
  44. public RespVO<PageModel<DeviceVO>> query(RequestParams params,
  45. @RequestParam(value = "currentPage", defaultValue = "1") Integer pageNum,
  46. @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize) {
  47. return RespVOBuilder.ok(service.query(params.getObjectMap(), pageNum, pageSize));
  48. }
  49. /**
  50. * 获得单个设备数据
  51. * @param deviceId 设备记录id
  52. * @return
  53. */
  54. @RequestMapping("/get")
  55. public RespVO<DeviceVO> get(@NotBlank(message = "缺少记录号") String deviceId){
  56. return RespVOBuilder.ok(service.get(deviceId));
  57. }
  58. /**
  59. * 删除单个设备
  60. * @param deviceId 待删除记录id
  61. * @return
  62. */
  63. @RequestMapping("/delete")
  64. @SysLog("删除设备信息:{arg0}")
  65. public RespVO<Object> delete(String deviceId){
  66. service.delete(deviceId);
  67. return RespVOBuilder.ok();
  68. }
  69. /**
  70. * 增加新设备
  71. * @param device 设备实体对象
  72. * @param token 当前登录实体
  73. * @return
  74. */
  75. @RequestMapping("/add")
  76. public RespVO<String> add(@Validated DevicePO device,AccessToken token){
  77. if(service.existDevice(device.getDeviceCode(),null)) {
  78. return RespVOBuilder.error("该设备编码已存在,勿重复添加");
  79. }
  80. device.setModifyBy(token.getUsName());
  81. String devId=service.add(device);
  82. synComp.synAllDev();
  83. return RespVOBuilder.ok(devId);
  84. }
  85. /**
  86. * 更新设备信息
  87. * @param device 设备实体对象
  88. * @param token 当前登录实体
  89. * @return
  90. */
  91. @RequestMapping("/update")
  92. public RespVO<Object> update(@Validated DevicePO device,AccessToken token){
  93. if(service.existDevice(device.getDeviceCode(), device.getDeviceId())) {
  94. return RespVOBuilder.error("该设备编码已存在,勿重复添加");
  95. }
  96. DeviceVO dbDev=service.get(device.getDeviceId());
  97. if(dbDev==null) {
  98. return RespVOBuilder.error("设备不存在");
  99. }
  100. device.setWellId(dbDev.getWellId()); //避免更新时丢失已关联的井
  101. device.setModifyBy(token.getUsName());
  102. service.update(device);
  103. if(device.getDeviceCode().equals(dbDev.getDeviceCode())) { //更改了设备编号,同步通知采集程序
  104. synComp.synAllDev();
  105. }
  106. return RespVOBuilder.ok();
  107. }
  108. /**
  109. * 同步采集程序对所有设备重加载
  110. * @return
  111. */
  112. @RequestMapping("/synGather")
  113. public RespVO<Object> synGather(){
  114. boolean rst=synComp.synAllDev();
  115. if(rst) {
  116. return RespVOBuilder.ok();
  117. }
  118. else {
  119. return RespVOBuilder.error("同步失败");
  120. }
  121. }
  122. }