AlertRuleController.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. package com.gyee.alarm.controller;
  2. import com.alibaba.fastjson.JSONObject;
  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.AlarmRuleService;
  9. import com.gyee.alarm.service.TokenService;
  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.context.request.RequestContextHolder;
  23. import org.springframework.web.context.request.ServletRequestAttributes;
  24. import org.springframework.web.multipart.MultipartFile;
  25. import javax.annotation.Resource;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;
  28. import java.io.IOException;
  29. import java.util.*;
  30. @Slf4j
  31. @RestController
  32. @RequestMapping("/alertrule")
  33. @CrossOrigin
  34. @Api(value = "自定义报警规则", tags = "自定义报警规则")
  35. public class AlertRuleController {
  36. @Autowired
  37. private AlarmRuleService alarmRuleService;
  38. @Resource
  39. private IProEconAlarmTypeService proEconAlarmTypeService;
  40. @Resource
  41. private TokenService tokenService;
  42. @GetMapping(value = "/querywtalarmdesclist")
  43. @ApiOperation(value = "通过场站、型号和部件查询报警描述信息", notes = "通过场站、型号和部件查询报警描述信息")
  44. @ApiImplicitParams({
  45. @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
  46. @ApiImplicitParam(name = "modelId", value = "型号", required = true, dataType = "string", paramType = "query"),
  47. @ApiImplicitParam(name = "components", value = "部件", required = true, dataType = "string", paramType = "query")})
  48. public AjaxResult queryWtAlarmDescList(String wpId, String modelId,String components) {
  49. List<AlarmConfigurationVo> vos=new ArrayList<>();
  50. if (StringUtils.notEmp(wpId) && StringUtils.notEmp(modelId) && StringUtils.notEmp(components)) {
  51. vos= alarmRuleService.queryWtAlarmDescList(wpId, modelId,components);
  52. }
  53. if (StringUtils.notEmp(vos)) {
  54. return AjaxResult.successData(AjaxStatus.success.code, vos);
  55. } else {
  56. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  57. }
  58. }
  59. @GetMapping(value = "/querymodellist")
  60. @ApiOperation(value = "查询型号信息", notes = "查询型号信息")
  61. public AjaxResult queryModelList(String wpId) {
  62. List<String> modells=new ArrayList<>();
  63. if(StringUtils.notEmp( wpId) && CacheContext.wpwtmap.containsKey(wpId))
  64. {
  65. List<ProBasicEquipment> wtls=CacheContext.wpwtmap.get(wpId);
  66. for(ProBasicEquipment wt:wtls)
  67. {
  68. if(!modells.contains(wt.getModelId()))
  69. {
  70. modells.add(wt.getModelId());
  71. }
  72. }
  73. }else if(StringUtils.notEmp( wpId) && CacheContext.subWtsMap.containsKey(wpId))
  74. {
  75. List<ProBasicEquipment> wtls=CacheContext.subWtsMap.get(wpId);
  76. for(ProBasicEquipment wt:wtls)
  77. {
  78. if(!modells.contains(wt.getModelId()))
  79. {
  80. modells.add(wt.getModelId());
  81. }
  82. }
  83. }else
  84. {
  85. List<ProEconEquipmentmodel> wtls=CacheContext.equipmentmodels;
  86. for(ProEconEquipmentmodel wt:wtls)
  87. {
  88. if(!modells.contains(wt.getId()))
  89. {
  90. modells.add(wt.getId());
  91. }
  92. }
  93. }
  94. if (StringUtils.notEmp(modells)) {
  95. return AjaxResult.successData(AjaxStatus.success.code, modells);
  96. } else {
  97. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  98. }
  99. }
  100. @GetMapping(value = "/list")
  101. @ApiOperation(value = "查询报警关联部件名称", notes = "查询报警关联部件名称")
  102. public AjaxResult queryTree() {
  103. List<AlarmRuleVo> alertrules = alarmRuleService.queryTree();
  104. if (StringUtils.notEmp(alertrules)) {
  105. return AjaxResult.successData(AjaxStatus.success.code, alertrules);
  106. } else {
  107. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  108. }
  109. }
  110. @GetMapping(value = "/queryalarmswitchllist")
  111. @ApiOperation(value = "查询报警开关", notes = "查询报警开关")
  112. public AjaxResult queryAlarmSwitchlList() {
  113. List<ProEconAlarmSwitch> vos = CacheContext.asls;
  114. if (StringUtils.notEmp(vos)) {
  115. return AjaxResult.successData(AjaxStatus.success.code, vos);
  116. } else {
  117. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  118. }
  119. }
  120. @GetMapping(value = "/queryalarmtypellist")
  121. @ApiOperation(value = "查询报警类型和预警类型", notes = "查询报警类型和预警类型")
  122. public AjaxResult queryalAarmTypelList() {
  123. Map<String, List<ProEconAlarmType>> map = new HashMap<>();
  124. List<ProEconAlarmType> typels = proEconAlarmTypeService.list();
  125. List<ProEconAlarmType> fjbjls = new ArrayList<>();
  126. List<ProEconAlarmType> gfbjls = new ArrayList<>();
  127. List<ProEconAlarmType> yjls = new ArrayList<>();
  128. List<ProEconAlarmType> sdls = new ArrayList<>();
  129. if (!typels.isEmpty()) {
  130. for (ProEconAlarmType type : typels) {
  131. if (type.getCategory().equals(AlarmType.FJBJ.getCode())) {
  132. fjbjls.add(type);
  133. }else if (type.getCategory().equals(AlarmType.GFBJ.getCode())) {
  134. gfbjls.add(type);
  135. } else if (type.getCategory().equals(AlarmType.YJ.getCode())) {
  136. yjls.add(type);
  137. } else if (type.getCategory().equals(AlarmType.SD.getCode())) {
  138. sdls.add(type);
  139. }
  140. }
  141. }
  142. map.put("fjbj", fjbjls);
  143. map.put("gfbj", gfbjls);
  144. map.put("yj", yjls);
  145. map.put("sd", sdls);
  146. if (StringUtils.notEmp(map)) {
  147. return AjaxResult.successData(AjaxStatus.success.code, map);
  148. } else {
  149. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  150. }
  151. }
  152. @GetMapping(value = "/querywpllist")
  153. @ApiOperation(value = "查询场站列表", notes = "查询场站列表")
  154. public AjaxResult queryWplList(String types) {
  155. HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
  156. List<ProBasicPowerstation> wpls = tokenService.getWpls(request);
  157. List<ProBasicPowerstation> vos = new ArrayList<>();
  158. if(!wpls.isEmpty())
  159. {
  160. for(ProBasicPowerstation wp:wpls)
  161. {
  162. if(StringUtils.notEmp(types))
  163. {
  164. if(types.equals(AlarmTypeValue.WT.getCode()) && wp.getId().contains("FDC"))
  165. {
  166. vos.add(wp);
  167. }else if(types.equals(AlarmTypeValue.IN.getCode()) && wp.getId().contains("GDC"))
  168. {
  169. vos.add(wp);
  170. }else if(types.equals(AlarmTypeValue.BT.getCode()))
  171. {
  172. List<ProBasicSubStation> subwpls = tokenService.getSubwpls(request);
  173. return AjaxResult.successData(AjaxStatus.success.code, subwpls);
  174. }
  175. }else
  176. {
  177. vos =wpls;
  178. }
  179. }
  180. }
  181. if (StringUtils.notEmp(vos)) {
  182. return AjaxResult.successData(AjaxStatus.success.code, vos);
  183. } else {
  184. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  185. }
  186. }
  187. @GetMapping(value = "/querywtlist")
  188. @ApiOperation(value = "通过场站获得设备信息", notes = "通过场站获得设备信息")
  189. @ApiImplicitParams({
  190. @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query")})
  191. public AjaxResult queryWtList(String wpId) {
  192. List<ProBasicEquipment> wtls = new ArrayList<>();
  193. if (StringUtils.notEmp(wpId) && CacheContext.wpwtmap.containsKey(wpId)) {
  194. wtls = CacheContext.wpwtmap.get(wpId);
  195. }
  196. if (StringUtils.notEmp(wtls)) {
  197. return AjaxResult.successData(AjaxStatus.success.code, wtls);
  198. } else {
  199. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  200. }
  201. }
  202. @GetMapping(value = "/querywtpointlist")
  203. @ApiOperation(value = "通过场站和型号查询测点信息", notes = "通过场站和型号查询测点信息")
  204. @ApiImplicitParams({
  205. @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
  206. @ApiImplicitParam(name = "modelId", value = "型号", required = true, dataType = "string", paramType = "query")})
  207. public AjaxResult queryWtPointlList(String wpId, String modelId) {
  208. Map<String, List<ProBasicEquipmentPoint>> map = new HashMap<>();
  209. if (StringUtils.notEmp(wpId) && StringUtils.notEmp(modelId) && CacheContext.wpwtmap.containsKey(wpId)) {
  210. List<ProBasicEquipment> wtls = CacheContext.wpwtmap.get(wpId);
  211. List<ProBasicEquipmentPoint> ailist = new ArrayList<>();
  212. List<ProBasicEquipmentPoint> dilist = new ArrayList<>();
  213. List<ProBasicEquipmentPoint> list = new ArrayList<>();
  214. for (ProBasicEquipment wt : wtls) {
  215. if (wt.getModelId().equals(modelId) && CacheContext.wtpAimap.containsKey(wt.getId())) {
  216. Map<String, ProBasicEquipmentPoint> wtpointmap = CacheContext.wtpAimap.get(wt.getId());
  217. for (Map.Entry<String, ProBasicEquipmentPoint> entry : wtpointmap.entrySet()) {
  218. if (entry.getKey().contains("AI")) {
  219. ailist.add(entry.getValue());
  220. } else if (entry.getKey().contains("DI")) {
  221. dilist.add(entry.getValue());
  222. }
  223. list.add(entry.getValue());
  224. }
  225. break;
  226. }
  227. }
  228. map.put("ai", ailist);
  229. map.put("di", dilist);
  230. map.put("total", list);
  231. }
  232. if (StringUtils.notEmp(map)) {
  233. return AjaxResult.successData(AjaxStatus.success.code, map);
  234. } else {
  235. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  236. }
  237. }
  238. @GetMapping(value = "/querysubllist")
  239. @ApiOperation(value = "获得升压站列表信息", notes = "获得升压站列表信息")
  240. public AjaxResult querySublList() {
  241. HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
  242. List<ProBasicSubStation> subwpls = tokenService.getSubwpls(request);
  243. if (StringUtils.notEmp(subwpls)) {
  244. return AjaxResult.successData(AjaxStatus.success.code, subwpls);
  245. } else {
  246. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  247. }
  248. }
  249. @GetMapping(value = "/queryalarmrule")
  250. @ApiOperation(value = "根据主键获得报警规则", notes = "根据主键获得报警规则")
  251. @ApiImplicitParams({
  252. @ApiImplicitParam(name = "id", value = "报警规则主键", required = true, dataType = "string", paramType = "query")})
  253. public AjaxResult queryAlarmRule(String id) {
  254. ProEconAlarmRule alarmRule = null;
  255. if (StringUtils.notEmp(id)) {
  256. alarmRule = alarmRuleService.selectByAlertruleId(id);
  257. }
  258. if (StringUtils.notEmp(alarmRule)) {
  259. return AjaxResult.successData(AjaxStatus.success.code, alarmRule);
  260. } else {
  261. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  262. }
  263. }
  264. @GetMapping(value = "/querysubpointllist")
  265. @ApiOperation(value = "获得升压站主键获得测点信息", notes = "获得升压站主键获得测点信息")
  266. public AjaxResult querySubPointlList(String subId) {
  267. Map<String, List<ProBasicPowerstationPoint>> map = new HashMap<>();
  268. if (StringUtils.notEmp(subId) && CacheContext.subwppointmap.containsKey(subId)) {
  269. Map<String, ProBasicPowerstationPoint> submap = CacheContext.subwppointmap.get(subId);
  270. List<ProBasicPowerstationPoint> ailist = new ArrayList<>();
  271. List<ProBasicPowerstationPoint> dilist = new ArrayList<>();
  272. List<ProBasicPowerstationPoint> list = new ArrayList<>();
  273. for (Map.Entry<String, ProBasicPowerstationPoint> entry : submap.entrySet()) {
  274. if (entry.getKey().contains("AI")) {
  275. ailist.add(entry.getValue());
  276. } else if (entry.getKey().contains("DI")) {
  277. dilist.add(entry.getValue());
  278. }
  279. list.add(entry.getValue());
  280. }
  281. map.put("ai", ailist);
  282. map.put("di", dilist);
  283. map.put("total", list);
  284. }
  285. if (StringUtils.notEmp(map)) {
  286. return AjaxResult.successData(AjaxStatus.success.code, map);
  287. } else {
  288. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  289. }
  290. }
  291. @GetMapping(value = "/querywpbyymodellist")
  292. @ApiOperation(value = "通过场站编号获得型号下拉列表", notes = "通过场站编号获得型号下拉列表")
  293. public AjaxResult queryWpByModelList() {
  294. Map<String, Set<ProEconEquipmentmodel>> wpByEmMap = CacheContext.wpByEmMap;
  295. if (StringUtils.notEmp(wpByEmMap)) {
  296. return AjaxResult.successData(AjaxStatus.success.code, wpByEmMap);
  297. } else {
  298. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  299. }
  300. }
  301. @GetMapping(value = "/queryctalarmdesclist")
  302. @ApiOperation(value = "通过场站、型号和部件查询报警描述信息", notes = "通过场站、型号和部件查询报警描述信息")
  303. @ApiImplicitParams({
  304. @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
  305. @ApiImplicitParam(name = "modelId", value = "型号", required = true, dataType = "string", paramType = "query"),
  306. @ApiImplicitParam(name = "components", value = "部件", required = true, dataType = "string", paramType = "query")})
  307. public AjaxResult queryCtAlarmDescList(String wpId, String modelId,String components) {
  308. List<AlarmConfigurationVo> vos=new ArrayList<>();
  309. if (StringUtils.notEmp(wpId) && StringUtils.notEmp(modelId) && StringUtils.notEmp(components)) {
  310. vos= alarmRuleService.queryCtAlarmDescList(wpId, modelId,components);
  311. }
  312. if (StringUtils.notEmp(vos)) {
  313. return AjaxResult.successData(AjaxStatus.success.code, vos);
  314. } else {
  315. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  316. }
  317. }
  318. //@UserLoginToken
  319. @PostMapping(value = "/save")
  320. @ResponseBody
  321. @ApiOperation(value = "进行修改和保存", notes = "进行修改和保存")
  322. public AjaxResult saveAndUpdateAlertrule(HttpServletRequest request, @RequestBody ProEconAlarmRule alarmRule) throws Exception {
  323. if (StringUtils.notEmp(alarmRule)) {
  324. int result = alarmRuleService.saveAndUpdateAlertrule(alarmRule);
  325. return AjaxResult.successData(AjaxStatus.success.code, result);
  326. } else {
  327. return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
  328. }
  329. }
  330. @DeleteMapping(value = "/delete")
  331. @ApiOperation(value = "删除", notes = "删除")
  332. @ApiImplicitParams({
  333. @ApiImplicitParam(name = "id", value = "自定义报警主键", required = true, dataType = "string", paramType = "query")})
  334. public AjaxResult deleteAlertrule(String id) {
  335. int i = alarmRuleService.deleteAlertrule(id);
  336. if (StringUtils.notEmp(i)) {
  337. return AjaxResult.successData(AjaxStatus.success.code, i);
  338. } else {
  339. return AjaxResult.successData(AjaxStatus.error.code, "error");
  340. }
  341. }
  342. //@UserLoginToken
  343. @GetMapping(value = "/page")
  344. @ApiOperation(value = "分页查询", notes = "分页查询")
  345. @ApiImplicitParams({
  346. @ApiImplicitParam(name = "pageNum", value = "页号", required = true, dataType = "Integer", paramType = "query"),
  347. @ApiImplicitParam(name = "pageSize", value = "每页显示多少行", required = true, dataType = "Integer", paramType = "query"),
  348. @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "query"),
  349. @ApiImplicitParam(name = "wpId", value = "风场编号", required = false, dataType = "string", paramType = "query"),
  350. @ApiImplicitParam(name = "modelId", value = "型号编号", required = false, dataType = "string", paramType = "query"),
  351. @ApiImplicitParam(name = "rank", value = "级别", required = false, dataType = "string", paramType = "query"),
  352. @ApiImplicitParam(name = "category", value = "类别(booststation:升压站报警,windturbine:风机报警,inverter:逆变器)", required = false, dataType = "string", paramType = "query"),
  353. @ApiImplicitParam(name = "enabled", value = "是否可用", required = false, dataType = "string", paramType = "query"),
  354. @ApiImplicitParam(name = "relatedparts", value = "部件", required = false, dataType = "string", paramType = "query")})
  355. public AjaxResult queryByPage(HttpServletRequest request,
  356. @RequestParam(value = "pageNum") Integer pageNum,
  357. @RequestParam(value = "pageSize") Integer pageSize,
  358. @RequestParam(value = "name", required = false) String name,
  359. @RequestParam(value = "wpId", required = false) String wpId,
  360. @RequestParam(value = "modelId", required = false) String modelId,
  361. @RequestParam(value = "rank", required = false) Integer rank,
  362. @RequestParam(value = "category", required = false) String category,
  363. @RequestParam(value = "enabled", required = false) Boolean enabled,
  364. @RequestParam(value = "relatedparts", required = false) String relatedparts
  365. ) {
  366. Page<ProEconAlarmRule> page = new Page(pageNum, pageSize);
  367. IPage<ProEconAlarmRule> pageResult = alarmRuleService.pageQueryAll(page, name, wpId, modelId, rank, category, enabled, relatedparts);
  368. if (StringUtils.notEmp(pageResult)) {
  369. return AjaxResult.successData(AjaxStatus.success.code, pageResult);
  370. } else {
  371. return AjaxResult.successData(AjaxStatus.error.code, "error");
  372. }
  373. }
  374. //@UserLoginToken
  375. @PostMapping(value = "/save-batch")
  376. @ResponseBody
  377. @ApiOperation(value = "批量保存", notes = "分页查询")
  378. public AjaxResult saveAlertruleBatch(HttpServletRequest request, @RequestBody List<ProEconAlarmRule> lst) throws Exception {
  379. boolean allCheck = true;
  380. for (ProEconAlarmRule alertrule : lst) {
  381. String msg = "";
  382. boolean result = true;
  383. if (StringUtils.isBlank(alertrule.getName())) {
  384. msg = "报警名称不能为空";
  385. result = false;
  386. } else if (StringUtils.isBlank(alertrule.getDescription())) {
  387. msg = "规则描述不能为空";
  388. result = false;
  389. } else if (StringUtils.isBlank(alertrule.getExpression())) {
  390. msg = "报警规则不能为空";
  391. result = false;
  392. } else if (StringUtils.empty(alertrule.getRank())) {
  393. msg = "报警级别不能为空";
  394. result = false;
  395. } else if (StringUtils.isBlank(alertrule.getStationId())) {
  396. msg = "风场不能为空";
  397. result = false;
  398. } else if (StringUtils.isBlank(alertrule.getCategory())) {
  399. msg = "报警类别不能为空";
  400. result = false;
  401. } else if (StringUtils.isBlank(alertrule.getUniformCode())) {
  402. msg = "统一编码不能为空";
  403. result = false;
  404. }
  405. if (alertrule.getCategory().equals(AlarmCustomType.WT.getCode())) {
  406. if (StringUtils.isBlank(alertrule.getModelId())) {
  407. msg = "风机型号不能为空";
  408. result = false;
  409. }
  410. }
  411. if (result != true) {
  412. allCheck = false;
  413. if (!result) {
  414. return AjaxResult.successData(AjaxStatus.error.code, msg);
  415. }
  416. }
  417. }
  418. if (allCheck) {
  419. for (ProEconAlarmRule alertRule : lst) {
  420. int result = alarmRuleService.saveAndUpdateAlertrule(alertRule);
  421. if (result <= 0) {
  422. return AjaxResult.successData(AjaxStatus.error.code, alertRule.getName() + ":" + "操作数据库失败");
  423. }
  424. }
  425. return AjaxResult.successData(AjaxStatus.success.code, "ok");
  426. } else {
  427. return AjaxResult.successData(AjaxStatus.error.code, "error");
  428. }
  429. }
  430. @GetMapping("/get-import-template")
  431. @ApiOperation(value = "获得导入模板")
  432. public void importTemplate(HttpServletResponse response) throws IOException {
  433. // 手动创建导出 demo
  434. Date current = com.gyee.common.util.DateUtils.getCurrentDate();
  435. Calendar calendar = Calendar.getInstance();
  436. calendar.setTime(current);
  437. calendar.add(Calendar.DAY_OF_MONTH, -1);
  438. Date previousDay = calendar.getTime();
  439. List<ProEconAlarmRule> list = Arrays.asList(
  440. ProEconAlarmRule.builder().id("").name("单机变桨电池柜温度1温度传感器异常值").description("温度等于850度或者温度小于零下40度")
  441. .expression("AI242 == 850 || AI242 <-40").tag("").rank(4).modelId("UP2000")
  442. .category("windturbine").range("parts")
  443. .stationId("SXJ_KGDL_GJY_FDC_STA").projectId("SXJ_KGDL_GJYF01_EG").lineId("SXJ_KGDL_GJYF01_LN").deviceId("SXJ_KGDL_GJY_F_WT_0001_EQ")
  444. .electricalId("").relatedParts("BJXT").createTime(DateUtils.truncate(previousDay))
  445. .enable(true).uniformCode("AI091")
  446. .build(),
  447. ProEconAlarmRule.builder().id("").name("单机变桨电池柜温度1温度传感器异常值").description("温度等于850度或者温度小于零下40度")
  448. .expression("AI242 == 850 || AI242 <-40").tag("").rank(4).modelId("UP2000")
  449. .category("windturbine").range("parts")
  450. .stationId("SXJ_KGDL_GJY_FDC_STA").projectId("SXJ_KGDL_GJYF01_EG").lineId("SXJ_KGDL_GJYF01_LN").deviceId("SXJ_KGDL_GJY_F_WT_0001_EQ")
  451. .electricalId("").relatedParts("BJXT").createTime(DateUtils.truncate(previousDay))
  452. .enable(true).uniformCode("AI091")
  453. .build()
  454. );
  455. // 输出
  456. ExcelUtils.write(response, "导入模板.xls", "导入模板", ProEconAlarmRule.class, list);
  457. }
  458. @PostMapping("/import")
  459. @ApiOperation(value = "导入", notes = "导入")
  460. public AjaxResult importExcel(@RequestParam("file") MultipartFile file) throws Exception {
  461. List<ProEconAlarmRule> list = ExcelUtils.read(file, ProEconAlarmRule.class);
  462. if (com.gyee.common.model.StringUtils.notEmp(list) && !list.isEmpty()) {
  463. boolean allCheck = true;
  464. for (ProEconAlarmRule alertrule : list) {
  465. String msg = "";
  466. boolean result = true;
  467. if (StringUtils.isBlank(alertrule.getName())) {
  468. msg = "报警名称不能为空";
  469. result = false;
  470. } else if (StringUtils.isBlank(alertrule.getDescription())) {
  471. msg = "规则描述不能为空";
  472. result = false;
  473. } else if (StringUtils.isBlank(alertrule.getExpression())) {
  474. msg = "报警规则不能为空";
  475. result = false;
  476. } else if (StringUtils.empty(alertrule.getRank())) {
  477. msg = "报警级别不能为空";
  478. result = false;
  479. } else if (StringUtils.isBlank(alertrule.getStationId())) {
  480. msg = "风场不能为空";
  481. result = false;
  482. } else if (StringUtils.isBlank(alertrule.getCategory())) {
  483. msg = "报警类别不能为空";
  484. result = false;
  485. } else if (StringUtils.isBlank(alertrule.getUniformCode())) {
  486. msg = "统一编码不能为空";
  487. result = false;
  488. }
  489. if (alertrule.getCategory().equals(AlarmCustomType.WT.getCode())) {
  490. if (StringUtils.isBlank(alertrule.getModelId())) {
  491. msg = "风机型号不能为空";
  492. result = false;
  493. }
  494. }
  495. if (result != true) {
  496. allCheck = false;
  497. if (!result) {
  498. return AjaxResult.successData(AjaxStatus.error.code, msg);
  499. }
  500. }
  501. if (allCheck) {
  502. alarmRuleService.saveAndUpdateAlertrule(alertrule);
  503. }
  504. }
  505. }
  506. if (com.gyee.common.model.StringUtils.isNotNull(list)) {
  507. return AjaxResult.successData(AjaxStatus.success.code, list);
  508. } else {
  509. return AjaxResult.successData(AjaxStatus.error.code, "error");
  510. }
  511. }
  512. }