AlarmConfigurationController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. package com.gyee.alarm.controller;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.gyee.alarm.init.CacheContext;
  6. import com.gyee.alarm.model.auto.*;
  7. import com.gyee.alarm.model.vo.*;
  8. import com.gyee.alarm.service.AlarmConfigurationService;
  9. import com.gyee.alarm.service.AlarmRuleService;
  10. import com.gyee.alarm.service.auto.IProEconAlarmTypeService;
  11. import com.gyee.alarm.util.ExcelUtils;
  12. import com.gyee.alarm.util.SnowflakeGenerator;
  13. import com.gyee.alarm.util.StringUtils;
  14. import com.gyee.common.util.DateUtils;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiImplicitParam;
  17. import io.swagger.annotations.ApiImplicitParams;
  18. import io.swagger.annotations.ApiOperation;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.web.bind.annotation.*;
  22. import org.springframework.web.multipart.MultipartFile;
  23. import javax.annotation.Resource;
  24. import javax.servlet.http.HttpServletRequest;
  25. import javax.servlet.http.HttpServletResponse;
  26. import java.io.IOException;
  27. import java.util.*;
  28. @Slf4j
  29. @RestController
  30. @RequestMapping("/alarmconfiguration")
  31. @CrossOrigin
  32. @Api(value = "报警规则", tags = "报警规则")
  33. public class AlarmConfigurationController {
  34. @Autowired
  35. private AlarmConfigurationService alarmConfigurationService;
  36. @GetMapping(value = "/querywtalarmdesclist")
  37. @ApiOperation(value = "通过场站、型号和部件查询报警描述信息", notes = "通过场站、型号和部件查询报警描述信息")
  38. @ApiImplicitParams({
  39. @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
  40. @ApiImplicitParam(name = "modelId", value = "型号", required = true, dataType = "string", paramType = "query"),
  41. @ApiImplicitParam(name = "components", value = "部件", required = true, dataType = "string", paramType = "query")})
  42. public AjaxResult queryWtAlarmDescList(String wpId, String modelId,String components) {
  43. List<AlarmConfigurationVo> vos=new ArrayList<>();
  44. if (StringUtils.notEmp(wpId) && StringUtils.notEmp(modelId) && StringUtils.notEmp(components)) {
  45. vos= alarmConfigurationService.queryWtAlarmDescList(wpId, modelId,components);
  46. }
  47. if (StringUtils.notEmp(vos)) {
  48. return AjaxResult.successData(AjaxStatus.success.code, vos);
  49. } else {
  50. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  51. }
  52. }
  53. //@UserLoginToken
  54. @PostMapping(value = "/save")
  55. @ResponseBody
  56. @ApiOperation(value = "进行修改和保存", notes = "进行修改和保存")
  57. public AjaxResult saveAndUpdateAlertrule(HttpServletRequest request, @RequestBody ProEconAlarmConfiguration alarmRule) throws Exception {
  58. if (StringUtils.notEmp(alarmRule)) {
  59. boolean result = alarmConfigurationService.saveAndUpdateAlertrule(alarmRule);
  60. return AjaxResult.successData(AjaxStatus.success.code, result);
  61. } else {
  62. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  63. }
  64. }
  65. @DeleteMapping(value = "/delete")
  66. @ApiOperation(value = "删除", notes = "删除")
  67. @ApiImplicitParams({
  68. @ApiImplicitParam(name = "id", value = "报警主键", required = true, dataType = "string", paramType = "query")})
  69. public AjaxResult deleteAlertrule(String id) {
  70. boolean i = alarmConfigurationService.deleteAlertrule(id);
  71. if (StringUtils.notEmp(i)) {
  72. return AjaxResult.successData(AjaxStatus.success.code, i);
  73. } else {
  74. return AjaxResult.successData(AjaxStatus.error.code, "error");
  75. }
  76. }
  77. //@UserLoginToken
  78. @GetMapping(value = "/page")
  79. @ApiOperation(value = "分页查询", notes = "分页查询")
  80. @ApiImplicitParams({
  81. @ApiImplicitParam(name = "pagenum", value = "页号", required = true, dataType = "Integer", paramType = "query"),
  82. @ApiImplicitParam(name = "pagesize", value = "每页显示多少行", required = true, dataType = "Integer", paramType = "query"),
  83. @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "query"),
  84. @ApiImplicitParam(name = "wpId", value = "风场编号", required = false, dataType = "string", paramType = "query"),
  85. @ApiImplicitParam(name = "modelId", value = "型号编号", required = false, dataType = "string", paramType = "query"),
  86. @ApiImplicitParam(name = "alarmType", value = "报警类型", required = false, dataType = "string", paramType = "query")})
  87. public AjaxResult queryByPage(HttpServletRequest request,
  88. @RequestParam(value = "pagenum") Integer pageNum,
  89. @RequestParam(value = "pagesize") Integer pageSize,
  90. @RequestParam(value = "name", required = false) String name,
  91. @RequestParam(value = "wpId", required = false) String wpId,
  92. @RequestParam(value = "modelId", required = false) String modelId,
  93. @RequestParam(value = "alarmType", required = false) String alarmType
  94. ) {
  95. Page<ProEconAlarmConfiguration> page = new Page(pageNum, pageSize);
  96. IPage<ProEconAlarmConfiguration> pageResult = alarmConfigurationService.pageQueryAll(page, name, wpId, modelId,alarmType);
  97. IPage<ProEconAlarmConfigurationVo> result=new Page<>();
  98. result.setPages(pageResult.getPages());
  99. result.setCurrent(pageResult.getCurrent());
  100. result.setSize(pageResult.getSize());
  101. result.setTotal(pageResult.getTotal());
  102. List<ProEconAlarmConfigurationVo> vos=new ArrayList<>();
  103. if(!pageResult.getRecords().isEmpty())
  104. {
  105. for(ProEconAlarmConfiguration ac:pageResult.getRecords())
  106. {
  107. ProEconAlarmConfigurationVo vo= new ProEconAlarmConfigurationVo();
  108. BeanUtil.copyProperties( ac,vo);
  109. if(CacheContext.wpmap.containsKey(ac.getStationId()))
  110. {
  111. vo.setStationName(CacheContext.wpmap.get(ac.getStationId()).getName());
  112. }
  113. if(CacheContext.alarmTypeMap.containsKey(ac.getComponents()))
  114. {
  115. vo.setComponentsName(CacheContext.alarmTypeMap.get(ac.getComponents()).getName());
  116. }
  117. vos.add(vo);
  118. }
  119. }
  120. result.setRecords(vos);
  121. if (StringUtils.notEmp(result)) {
  122. return AjaxResult.successData(AjaxStatus.success.code, result);
  123. } else {
  124. return AjaxResult.successData(AjaxStatus.error.code, "error");
  125. }
  126. }
  127. @GetMapping("/get-import-template")
  128. @ApiOperation(value = "获得导入模板")
  129. public void importTemplate(HttpServletResponse response) throws IOException {
  130. // 手动创建导出 demo
  131. Date current = DateUtils.getCurrentDate();
  132. Calendar calendar = Calendar.getInstance();
  133. calendar.setTime(current);
  134. calendar.add(Calendar.DAY_OF_MONTH, -1);
  135. Date previousDay = calendar.getTime();
  136. List<ProEconAlarmConfiguration> list = Arrays.asList(
  137. ProEconAlarmConfiguration.builder().id("").tagId("1").deviceId("SXJ_KGDL_HSM_F_WT_0001_EQ").suffix("")
  138. .rank(3).uniformCode("AI242").stationId("SXJ_KGDL_HSM_FDC_STA").modelId("/HW3-S2500(121)")
  139. .alarmType("windturbine").deviceType("windturbine").components("CLX").subcomponents("")
  140. .description("温度等于850度或者温度小于零下40度")
  141. .characteristic("正常停机").resetTable(false).enable(true)
  142. .build(),
  143. ProEconAlarmConfiguration.builder().id("").tagId("1").deviceId("SXJ_KGDL_HSM_F_WT_0002_EQ").suffix("")
  144. .rank(3).uniformCode("AI242").stationId("SXJ_KGDL_HSM_FDC_STA").modelId("/HW3-S2500(121)")
  145. .alarmType("windturbine").deviceType("windturbine").components("CLX").subcomponents("")
  146. .description("温度等于850度或者温度小于零下40度")
  147. .characteristic("正常停机").resetTable(false).enable(true)
  148. .build()
  149. );
  150. // 输出
  151. ExcelUtils.write(response, "导入模板.xls", "导入模板", ProEconAlarmConfiguration.class, list);
  152. }
  153. @PostMapping("/import")
  154. @ApiOperation(value = "导入", notes = "导入")
  155. public AjaxResult importExcel(@RequestParam("file") MultipartFile file) throws Exception {
  156. List<ProEconAlarmConfiguration> list = ExcelUtils.read(file, ProEconAlarmConfiguration.class);
  157. if (com.gyee.common.model.StringUtils.notEmp(list) && !list.isEmpty()) {
  158. boolean allCheck = true;
  159. for (ProEconAlarmConfiguration alertrule : list) {
  160. String msg = "";
  161. boolean result = true;
  162. if (StringUtils.isBlank(alertrule.getDescription())) {
  163. msg = "报警名称不能为空";
  164. result = false;
  165. }else if (StringUtils.empty(alertrule.getTriggerType())) {
  166. msg = "触发类型不能为空";
  167. result = false;
  168. } else if (StringUtils.empty(alertrule.getResetTable())) {
  169. msg = "是否可以复位不能为空";
  170. result = false;
  171. } else if (StringUtils.isBlank(alertrule.getDeviceId())) {
  172. msg = "设备不能为空";
  173. result = false;
  174. } else if (alertrule.getEnable()) {
  175. msg = "是否可用不能为空";
  176. result = false;
  177. } else if (StringUtils.empty(alertrule.getRank())) {
  178. msg = "报警级别不能为空";
  179. result = false;
  180. } else if (StringUtils.isBlank(alertrule.getStationId())) {
  181. msg = "风场不能为空";
  182. result = false;
  183. } else if (StringUtils.isBlank(alertrule.getAlarmType())) {
  184. msg = "报警类别不能为空";
  185. result = false;
  186. } else if (StringUtils.isBlank(alertrule.getDeviceType())) {
  187. msg = "报警设备类型不能为空";
  188. result = false;
  189. }else if (StringUtils.isBlank(alertrule.getUniformCode())) {
  190. msg = "统一编码不能为空";
  191. result = false;
  192. }else if (StringUtils.isBlank(alertrule.getCharacteristic())) {
  193. msg = "特性不能为空";
  194. result = false;
  195. }
  196. if (alertrule.getComponents().equals(AlarmTypeValue.WT.getCode())) {
  197. if (StringUtils.isBlank(alertrule.getModelId())) {
  198. msg = "风机型号不能为空";
  199. result = false;
  200. }
  201. else if (StringUtils.empty(alertrule.getComponents())) {
  202. msg = "关联部件不能为空";
  203. result = false;
  204. }
  205. }else if (alertrule.getComponents().equals(AlarmTypeValue.BT.getCode())) {
  206. if (StringUtils.isBlank(alertrule.getTagId())) {
  207. msg = "测点不能为空";
  208. result = false;
  209. }
  210. }
  211. if (result != true) {
  212. allCheck = false;
  213. if (!result) {
  214. return AjaxResult.successData(AjaxStatus.error.code, msg);
  215. }
  216. }
  217. if (allCheck) {
  218. alarmConfigurationService.saveAndUpdateAlertrule(alertrule);
  219. }
  220. }
  221. }
  222. if (com.gyee.common.model.StringUtils.isNotNull(list)) {
  223. return AjaxResult.successData(AjaxStatus.success.code, list);
  224. } else {
  225. return AjaxResult.successData(AjaxStatus.error.code, "error");
  226. }
  227. }
  228. }