AlarmConfigNewController.java 8.7 KB
package com.skua.modules.controller;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.skua.modules.alarmtmp.entity.AlarmDataSame;
import com.skua.modules.alarmtmp.entity.AlarmRuleLevelConfigTemplate;
import com.skua.modules.alarmtmp.service.*;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.util.DateUtils;

import com.skua.modules.system.datestandard.entity.SysMonitorMetricInfo;
import com.skua.modules.system.datestandard.service.ISysMonitorMetricInfoService;
import com.skua.modules.system.service.IPgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.*;

/**
 * @Description
 * @Date 2020-12-16 17:08
 * @Param
 * @return
 **/
@Slf4j
@RestController
@RequestMapping("/alarm/configNew")
@Api(tags = "关联报警配置")
public class AlarmConfigNewController {


    @Autowired
    private AlarmRecordHistoryService alarmRecordHistoryService;

    @Autowired
    private AlarmRuleConfigService alarmRuleConfigService;
    @Autowired
    private IAlarmRuleLevelConfigTemplateService alarmRuleLevelConfigTemplateService;
    @Autowired
    private AlarmLevelStandardConfigService alarmLevelStandardConfigService;
    @Autowired
    private IPgService pgService;
    @Autowired
    private IAlarmDataSameService alarmDataSameService;
    @Autowired
    private ISysMonitorMetricInfoService sysMonitorMetricInfoService;


    private List<String> getDateRange(String startTime, String endTime) {
        ArrayList rs = new ArrayList();

        try {
            String pattern = "yyyy-MM-dd HH";
            Calendar sc = Calendar.getInstance();
            Calendar ec = Calendar.getInstance();
            sc.setTime(DateUtils.parse(startTime, pattern));
            ec.setTime(DateUtils.parse(endTime, pattern));

            while (sc.compareTo(ec) < 1) {
                rs.add(DateUtils.format(sc.getTime(), pattern));
                sc.add(Calendar.HOUR_OF_DAY, 1);
            }
        } catch (ParseException var8) {
            var8.printStackTrace();
        }

        return rs;
    }

    /**
     * <pre>
     *	报警配置同步更新采集数据标签分类变更数据
     * </pre>
     * @return
     * @author Li Yuanyuan, 2023年3月27日 上午9:40:52
     * @Description: 采集数据标签不和机构有关联关系,数据标签分类变更,直接影响所有机构配置规则变更,这里直接批量更新
     */
    @AutoLog(value = "同步更新报警配置类型")
    @ApiOperation(value = "同步更新报警配置类型", notes = "同步更新报警配置类型")
    @GetMapping(value = "/updateAlarmRuleType")
    public Result<String> updateAlarmRuleType(){
    	Result<String> result = new Result<>();
    	alarmRuleConfigService.updateAlarmRuleTypeFormMetricDict();
    	result.setMessage("更新报警类型成功");
        result.setSuccess(true);
        return result;
    }
    
    /**
     * 仪表和设备短信报警配置
     */
    @AutoLog(value = "仪表和设备短信报警配置")
    @ApiOperation(value = "仪表和设备短信报警配置", notes = "仪表和设备短信报警配置")
    @GetMapping(value = "/getAlarmConfigTemplateByType")
    public Result<Map<String, Object>> getAlarmConfigTemplateByType(String type, String departId) {
        Result<Map<String, Object>> result = new Result<>();
        Map<String, Object> data = alarmRuleConfigService.getAlarmConfigTemplateByType(type, departId);
        result.setResult(data);
        result.setSuccess(true);
        return result;

    }
    
    /**
     * 一键配置报警(未配置过的)
     */
    @AutoLog(value = "总一键配仪表和设备报警")
    @ApiOperation(value = "总一键配仪表和设备报警", notes = "总一键配仪表和设备报警")
    @GetMapping(value = "/totalAddAllAlarmConfigByType")
    public Result totalAddAllAlarmConfigByType() {

        Result result = new Result<>();
        alarmRuleConfigService.totalAddAllAlarmConfigByType();
        result.setMessage("一键配置成功");
        result.setSuccess(true);
        return result;

    }

    /**
     * 仪表和设备短信报警配置修改
     */
    @AutoLog(value = "仪表和设备短信报警配置修改")
    @ApiOperation(value = "仪表和设备短信报警配置修改", notes = "仪表和设备短信报警配置修改")
    @PostMapping(value = "/updAlarmConfigTemplateByType")
    public Result updAlarmConfigTemplateByType(@RequestBody AlarmRuleLevelConfigTemplate alarmRuleLevelConfigTemplate) {
        Result result = new Result<>();
        alarmRuleConfigService.updAlarmConfigTemplateByType(alarmRuleLevelConfigTemplate);
        result.setMessage("修改成功");
        result.setSuccess(true);
        return result;

    }

    /**
     * 关联报警配置添加和编辑
     */
    @AutoLog(value = "关联报警配置添加和编辑")
    @ApiOperation(value = "关联报警配置添加和编辑", notes = "关联报警配置添加和编辑")
    @PostMapping(value = "/addGlAlarmConfigTemplate")
    public Result addGlAlarmConfigTemplate(@RequestBody AlarmRuleLevelConfigTemplate alarmRuleLevelConfigTemplate) {

        Result result = new Result<>();
        //自定义报警模板类型默认使用6
        alarmRuleLevelConfigTemplate.setAlarmTemplateType("6");
        alarmRuleLevelConfigTemplate.setAlarmTemplateName(alarmRuleLevelConfigTemplate.getZexpression());
        if (StringUtils.isNotBlank(alarmRuleLevelConfigTemplate.getExpression())) {
            alarmRuleLevelConfigTemplateService.saveOrUpdate(alarmRuleLevelConfigTemplate);
        } else {
            if (StringUtils.isNotBlank(alarmRuleLevelConfigTemplate.getId())) {
                alarmRuleLevelConfigTemplateService.removeById(alarmRuleLevelConfigTemplate.getId());
            }
        }

        result.setMessage("操作成功");
        result.setSuccess(true);
        return result;

    }

    /**
     * 根据设备点查询点表是否配置运行点、故障点和停止点
     */
    @AutoLog(value = "根据设备点查询点表是否配置运行点、故障点和停止点")
    @ApiOperation(value = "根据设备点查询点表是否配置运行点、故障点和停止点", notes = "根据设备点查询点表是否配置运行点、故障点和停止点")
    @GetMapping(value = "/getEquipStatus")
    public Result<List<Map<String, Object>>> getEquipStatus(String equipId) {

        Result<List<Map<String, Object>>> result = new Result<>();
        result.setResult(alarmRuleConfigService.getEquipStatus(equipId));
        result.setMessage("操作成功");
        result.setSuccess(true);
        return result;

    }

    /**
     * type 0仪表 1设备 2质量 3关联
     * status 0停用 1启用
     * anType
     *
     * @return com.skua.core.api.vo.Result
     * @Description 一键启用停用
     * @Date 2021-08-26 15:11
     * @Param [type, status, departId, anType]
     **/
    @AutoLog(value = "一键启用停用")
    @ApiOperation(value = "一键启用停用", notes = "一键启用停用")
    @GetMapping(value = "/startAndEnd")
    public Result startAndEnd(String type, String status, String departId, String anType) {

        Result result = new Result<>();
        alarmRuleConfigService.startAndEnd(type, status, departId, anType);
        result.setMessage("操作成功");
        result.setSuccess(true);
        return result;

    }

    /**
     * @Description 启用停用
     * @Date 2021-08-26 15:11
     **/
    @AutoLog(value = "列表启用停用")
    @ApiOperation(value = "列表启用停用", notes = "列表启用停用")
    @GetMapping(value = "/updConfigStatus")
    public Result updConfigStatus(String id, String departId, String anType, String status) {

        Result result = new Result<>();
        alarmRuleConfigService.updConfigStatus(id, departId, anType, status);
        result.setMessage("操作成功");
        result.setSuccess(true);
        return result;

    }

    /**
     * 根据类型查询关联报警指标
     */
    @AutoLog(value = "根据类型查询关联报警指标")
    @ApiOperation(value = "根据类型查询关联报警指标", notes = "根据类型查询关联报警指标")
    @GetMapping(value = "/getMonitorByType")
    public Result<List<Map<String, Object>>> getMonitorByType(String type, String departId) {
        Result<List<Map<String, Object>>> result = new Result<>();
        List<Map<String, Object>> data = alarmRuleConfigService.getMonitorByType(type, departId);
        result.setSuccess(true);
        result.setResult(data);
        return result;

    }

}