package com.ld.igds.sec.view; import com.bstek.bdf2.core.model.DefaultUser; import com.bstek.dorado.annotation.DataProvider; import com.bstek.dorado.annotation.DataResolver; import com.bstek.dorado.annotation.Expose; import com.bstek.dorado.data.provider.Page; import com.ld.igds.constant.NoticeType; import com.ld.igds.constant.WarnLevel; import com.ld.igds.constant.WarnStatus; import com.ld.igds.constant.WarnType; import com.ld.igds.models.DicTrigger; import com.ld.igds.models.MWarnConf; import com.ld.igds.models.BlackListWarnInfo; import com.ld.igds.sec.service.BlackListWarnService; import com.ld.igds.sys.service.SysUserService; import com.ld.igds.util.ContextUtil; import com.ld.igds.warn.data.WarnData; import com.ld.igds.warn.service.CoreWarnService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 警报管理 * * @author: * */ @Component public class BlackListWarnPR { @Autowired private BlackListWarnService blackListWarnService; @Autowired private CoreWarnService coreWarnService; @Autowired private SysUserService sysUserService; /** * 警告类型 * blackListWarnPR * ${dorado.getDataProvider("warnPR#triggerWarnType").getResult()} * * @return */ @DataProvider public List triggerWarnType() { List list = new ArrayList(); // for (WarnType w:WarnType.values()) { // list.add(new DicTrigger(w.getCode(), w.getMsg())); // } //list.add(new DicTrigger(WarnType.TYPE_01.getCode(), "警告")); //list.add(new DicTrigger(WarnType.TYPE_02.getCode(), "预警")); //list.add(new DicTrigger(WarnType.TYPE_01.getCode(), "通知")); list.add(new DicTrigger("01", "人员")); list.add(new DicTrigger("02", "车辆")); return list; } /** * 警告等级 * * ${dorado.getDataProvider("warnPR#triggerWarnLevel").getResult()} * * @return */ @DataProvider public List triggerWarnLevel() { List list = new ArrayList(); for (WarnLevel w:WarnLevel.values()) { list.add(new DicTrigger(w.getCode(), w.getMsg())); } //list.add(new DicTrigger(WarnLevel.LEVEL_01.getCode(), "一级警告")); // list.add(new DicTrigger(WarnLevel.LEVEL_02.getCode(), "二级警告")); // list.add(new DicTrigger(WarnLevel.LEVEL_03.getCode(), "三级警告")); return list; } /** * 警告状态 * * ${dorado.getDataProvider("warnPR#triggerWarnStatus").getResult()} * * @return */ @DataProvider public List triggerWarnStatus() { List list = new ArrayList(); list.add(new DicTrigger(WarnStatus.STATUS_10.getCode(), "未处理")); list.add(new DicTrigger(WarnStatus.STATUS_20.getCode(), "延迟处理")); list.add(new DicTrigger(WarnStatus.STATUS_30.getCode(), "已处理")); list.add(new DicTrigger(WarnStatus.STATUS_40.getCode(), "忽略")); return list; } /** * warnPR#listWarn * @param param * @return */ @DataProvider public void listWarn(Page page, Map param) throws Exception { if(null == param){ param = new HashMap<>(); } blackListWarnService.listWarnInfo(page, param); } /** * warnPR#saveWarn * * @param data */ @DataResolver public void saveWarn(BlackListWarnInfo data){ blackListWarnService.saveWarnInfo(data); } /** * warnPR#updateWarnStatus * @param data */ @DataResolver public String updateWarnStatus(BlackListWarnInfo data) throws Exception { blackListWarnService.updateWarnStatus(data); return null; } /** * warnPR#delWarn * @param data * @return */ @Expose public String delWarn(BlackListWarnInfo data){ return blackListWarnService.delWarnInfo(data); } /** * warnPR#testWarn 警告测试 */ @Expose public String testWarn(WarnData data) { if(data == null || StringUtils.isEmpty(data.getPhone())){ return "手机号不能为空!"; } return coreWarnService.noticeTestWarn(data.getPhone(),data.getType(),data.getLevel(), data.getBizType()); } //----------------------------------警告配置-------------------------------------// /** * 警告通知方式 * * ${dorado.getDataProvider("warnPR#triggerNoticeType").getResult()} * * @return */ @DataProvider public List triggerNoticeType() { List list = new ArrayList(); list.add(new DicTrigger(NoticeType.NONE.getCode(), NoticeType.NONE.getName())); list.add(new DicTrigger(NoticeType.SMS.getCode(), NoticeType.SMS.getName())); list.add(new DicTrigger(NoticeType.EMAIL.getCode(), NoticeType.EMAIL.getName())); list.add(new DicTrigger(NoticeType.VOICE.getCode(), NoticeType.VOICE.getName())); list.add(new DicTrigger(NoticeType.WECHAT.getCode(), NoticeType.WECHAT.getName())); return list; } /** * warnPR#getConf * @param deptId * @return */ @DataProvider public MWarnConf getConf(String deptId){ if(StringUtils.isEmpty(deptId)){ deptId = ContextUtil.subDeptId(null); } MWarnConf result = blackListWarnService.getConf(deptId); if(null == result){ result = new MWarnConf(); result.setStart(0); result.setEnd(24); result.setDeptId(deptId); } return result; } /** * warnPR#updateConf * @param data */ @DataResolver public void updateConf(MWarnConf data){ blackListWarnService.updateConf(data); } /** * warnPR#loadUserByParam * 根据关键字查询,可能是用户账号,或者中文名 * * @param * @return */ @DataProvider public List loadUserByParam(Map param) { if(null == param){ param = new HashMap(); } return sysUserService.loadUsers(param); } }