|
@@ -0,0 +1,290 @@
|
|
|
+package com.gyee.alarm.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.gyee.alarm.model.auto.ProEconAlarmRule;
|
|
|
+import com.gyee.alarm.model.vo.AjaxResult;
|
|
|
+import com.gyee.alarm.model.vo.AjaxStatus;
|
|
|
+import com.gyee.alarm.model.vo.AlarmRuleVo;
|
|
|
+import com.gyee.alarm.service.AlarmRuleService;
|
|
|
+
|
|
|
+import com.gyee.alarm.util.ExcelUtils;
|
|
|
+import com.gyee.alarm.util.SnowflakeGenerator;
|
|
|
+import com.gyee.alarm.util.StringUtils;
|
|
|
+
|
|
|
+import com.gyee.common.util.DateUtils;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+import org.codehaus.groovy.syntax.TokenUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/alertrule")
|
|
|
+@CrossOrigin
|
|
|
+public class AlertRuleController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AlarmRuleService alarmRuleService;
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping(value = "/list")
|
|
|
+ public List<AlarmRuleVo> queryTree() {
|
|
|
+ List<AlarmRuleVo> alertrules = alarmRuleService.queryTree();
|
|
|
+ return alertrules;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //@UserLoginToken
|
|
|
+ @PostMapping(value = "/save")
|
|
|
+ @ResponseBody
|
|
|
+
|
|
|
+ public AjaxResult saveAlertrule(HttpServletRequest request, @RequestBody ProEconAlarmRule alarmRule) throws Exception {
|
|
|
+
|
|
|
+ int result = alarmRuleService.saveAndUpdateAlertrule(alarmRule);
|
|
|
+
|
|
|
+ return AjaxResult.successData(AjaxStatus.success.code, result);
|
|
|
+
|
|
|
+ }
|
|
|
+ @PostMapping(value = "/update")
|
|
|
+ @ResponseBody
|
|
|
+
|
|
|
+ public AjaxResult updateAlertrule(HttpServletRequest request, @RequestBody ProEconAlarmRule alarmRule) throws Exception {
|
|
|
+
|
|
|
+ int result = alarmRuleService.saveAndUpdateAlertrule(alarmRule);
|
|
|
+ return AjaxResult.successData(AjaxStatus.success.code, result);
|
|
|
+
|
|
|
+ }
|
|
|
+ @DeleteMapping(value = "/delete")
|
|
|
+ public int deleteAlertrule(ProEconAlarmRule alarmRule) {
|
|
|
+ return alarmRuleService.deleteAlertrule(alarmRule);
|
|
|
+ }
|
|
|
+
|
|
|
+ //@UserLoginToken
|
|
|
+ @GetMapping(value = "/page")
|
|
|
+ public IPage<ProEconAlarmRule> queryByPage(HttpServletRequest request,
|
|
|
+ @RequestParam(value = "pagenum") Integer pageNum,
|
|
|
+ @RequestParam(value = "pagesize") Integer pageSize,
|
|
|
+ @RequestParam(value = "name", required = false) String name,
|
|
|
+ @RequestParam(value = "station", required = false) String station,
|
|
|
+ @RequestParam(value = "modelId", required = false) String modelId,
|
|
|
+ @RequestParam(value = "rank", required = false) String rank,
|
|
|
+ @RequestParam(value = "category", required = false) String category,
|
|
|
+ @RequestParam(value = "enabled",required = false) String enabled,
|
|
|
+ @RequestParam(value = "relatedparts",required = false) String relatedparts
|
|
|
+ ) {
|
|
|
+ Page<ProEconAlarmRule> page = new Page(pageNum, pageSize);
|
|
|
+
|
|
|
+ IPage<ProEconAlarmRule> pageResult = alarmRuleService.pageQueryAll(page, name,station,modelId,rank,category,enabled,relatedparts);
|
|
|
+
|
|
|
+ return pageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ private AjaxResult dataCheck(ProEconAlarmRule alertrule) {
|
|
|
+
|
|
|
+ String msg = "";
|
|
|
+ boolean result = true;
|
|
|
+ if (StringUtils.isBlank(alertrule.getName())) {
|
|
|
+ msg = "报警名称不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.isBlank(alertrule.getDescription())) {
|
|
|
+ msg = "规则描述不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.isBlank(alertrule.getExpression())) {
|
|
|
+ msg = "报警规则不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.empty(alertrule.getRank())) {
|
|
|
+ msg = "报警级别不能为空";
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ else if (StringUtils.isBlank(alertrule.getStationId())) {
|
|
|
+ msg = "风场不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.isBlank(alertrule.getCategory())) {
|
|
|
+ msg = "报警类别不能为空";
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ if (alertrule.getCategory().equals("1")) {
|
|
|
+ if (StringUtils.isBlank(alertrule.getModelId())) {
|
|
|
+ msg = "风机型号不能为空";
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (result) {
|
|
|
+ return AjaxResult.successData(AjaxStatus.success.code, result);
|
|
|
+ } else {
|
|
|
+ return AjaxResult.successData(AjaxStatus.error.code, result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //@UserLoginToken
|
|
|
+ @PostMapping(value = "/save-batch")
|
|
|
+ @ResponseBody
|
|
|
+ public AjaxResult saveAlertruleBatch(HttpServletRequest request,@RequestBody List<ProEconAlarmRule> lst) throws Exception {
|
|
|
+
|
|
|
+
|
|
|
+ boolean allCheck = true;
|
|
|
+
|
|
|
+ for (ProEconAlarmRule alertrule : lst) {
|
|
|
+ String msg = "";
|
|
|
+ boolean result = true;
|
|
|
+ if (StringUtils.isBlank(alertrule.getName())) {
|
|
|
+ msg = "报警名称不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.isBlank(alertrule.getDescription())) {
|
|
|
+ msg = "规则描述不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.isBlank(alertrule.getExpression())) {
|
|
|
+ msg = "报警规则不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.empty(alertrule.getRank())) {
|
|
|
+ msg = "报警级别不能为空";
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ else if (StringUtils.isBlank(alertrule.getStationId())) {
|
|
|
+ msg = "风场不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.isBlank(alertrule.getCategory())) {
|
|
|
+ msg = "报警类别不能为空";
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ if (alertrule.getCategory().equals("1")) {
|
|
|
+ if (StringUtils.isBlank(alertrule.getModelId())) {
|
|
|
+ msg = "风机型号不能为空";
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ( result!= true) {
|
|
|
+ allCheck = false;
|
|
|
+ if (!result) {
|
|
|
+ return AjaxResult.successData(AjaxStatus.error.code, msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (allCheck) {
|
|
|
+ for (ProEconAlarmRule alertRule : lst) {
|
|
|
+ int result = alarmRuleService.saveAndUpdateAlertrule(alertRule);
|
|
|
+ if (result <= 0) {
|
|
|
+ return AjaxResult.successData(AjaxStatus.error.code, alertRule.getName() + ":" + "操作数据库失败");
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return AjaxResult.successData(AjaxStatus.success.code, "ok");
|
|
|
+ } else {
|
|
|
+ return AjaxResult.successData(AjaxStatus.success.code, "ok");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/get-import-template")
|
|
|
+ @ApiOperation(value = "获得导入模板")
|
|
|
+ public void importTemplate(HttpServletResponse response) throws IOException {
|
|
|
+ // 手动创建导出 demo
|
|
|
+ Date current = com.gyee.common.util.DateUtils.getCurrentDate();
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(current);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
+ Date previousDay = calendar.getTime();
|
|
|
+
|
|
|
+ List<ProEconAlarmRule> list = Arrays.asList(
|
|
|
+ ProEconAlarmRule.builder().id("").name("单机变桨电池柜温度1温度传感器异常值").description("温度等于850度或者温度小于零下40度")
|
|
|
+ .expression("AI242 == 850 || AI242 <-40").tag("").rank(4).modelId("TZ-2000")
|
|
|
+ .category("1").range("0")
|
|
|
+ .stationId("ZK_FDC").projectId("ZK_FDC").lineId("ZK_FDC").deviceId("ZK_FDC")
|
|
|
+ .electricalId("").relatedParts("BJ").createTime(DateUtils.truncate(previousDay))
|
|
|
+ .enable(true)
|
|
|
+ .build(),
|
|
|
+
|
|
|
+ ProEconAlarmRule.builder().id("").name("单机变桨电池柜温度2超限报警").description("温度等于850度或者温度小于零下40度")
|
|
|
+ .expression("(AI243>=65 || AI243<-10)").tag("").rank(4).modelId("TZ-2000")
|
|
|
+ .category("1").range("0")
|
|
|
+ .stationId("ZK_FDC").projectId("ZK_FDC").lineId("ZK_FDC").deviceId("ZK_FDC")
|
|
|
+ .electricalId("").relatedParts("BJ").createTime(DateUtils.truncate(previousDay))
|
|
|
+ .enable(true)
|
|
|
+ .build()
|
|
|
+
|
|
|
+ );
|
|
|
+
|
|
|
+ // 输出
|
|
|
+ ExcelUtils.write(response, "导入模板.xls", "导入模板", ProEconAlarmRule.class, list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/import")
|
|
|
+ @ApiOperation(value = "导入",notes = "导入")
|
|
|
+ public AjaxResult importExcel(@RequestParam("file") MultipartFile file) throws Exception {
|
|
|
+ List<ProEconAlarmRule> list = ExcelUtils.read(file, ProEconAlarmRule.class);
|
|
|
+
|
|
|
+ if(com.gyee.common.model.StringUtils.notEmp(list) && !list.isEmpty())
|
|
|
+ {
|
|
|
+ boolean allCheck = true;
|
|
|
+ for(ProEconAlarmRule alertrule:list)
|
|
|
+ {
|
|
|
+ String msg = "";
|
|
|
+ boolean result = true;
|
|
|
+ if (StringUtils.isBlank(alertrule.getName())) {
|
|
|
+ msg = "报警名称不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.isBlank(alertrule.getDescription())) {
|
|
|
+ msg = "规则描述不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.isBlank(alertrule.getExpression())) {
|
|
|
+ msg = "报警规则不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.empty(alertrule.getRank())) {
|
|
|
+ msg = "报警级别不能为空";
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ else if (StringUtils.isBlank(alertrule.getStationId())) {
|
|
|
+ msg = "风场不能为空";
|
|
|
+ result = false;
|
|
|
+ } else if (StringUtils.isBlank(alertrule.getCategory())) {
|
|
|
+ msg = "报警类别不能为空";
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ if (alertrule.getCategory().equals("1")) {
|
|
|
+ if (StringUtils.isBlank(alertrule.getModelId())) {
|
|
|
+ msg = "风机型号不能为空";
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ( result!= true) {
|
|
|
+ allCheck = false;
|
|
|
+ if (!result) {
|
|
|
+ return AjaxResult.successData(AjaxStatus.error.code, msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(allCheck)
|
|
|
+ {
|
|
|
+ alertrule.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ alertrule.setCreateTime(new Date());
|
|
|
+
|
|
|
+ alarmRuleService.saveAndUpdateAlertrule(alertrule);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (com.gyee.common.model.StringUtils.isNotNull(list)) {
|
|
|
+ return AjaxResult.successData(AjaxStatus.success.code, list);
|
|
|
+ } else {
|
|
|
+ return AjaxResult.successData(AjaxStatus.error.code, "ok");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|