TriggerAlarmHelper.java
package com.mycim.webapp.utils;
import com.mycim.framework.context.spring.SpringContext;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.server.alarm.service.AlarmService;
import com.mycim.server.ems.service.EmsService;
import com.mycim.server.security.service.SecurityService;
import com.mycim.valueobject.consts.MailComponent;
import com.mycim.valueobject.consts.SessionNames;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;
/**
* @author pinyan.song
* @version 6.0.0
* @date 2019-12-16
**/
public class TriggerAlarmHelper {
AlarmService alarmService = SpringContext.getBean(AlarmService.class);
SecurityService securityService = SpringContext.getBean(SecurityService.class);
EmsService emsService = SpringContext.getBean(EmsService.class);
public Map<String, Object> triggerAlarmWithWorkFlow(Map<String, Object> alarmInfo) {
Long fromUserRrn = (Long) alarmInfo.get("fromUserRrn");
Long toUserRrn = (Long) alarmInfo.get("toUserRrn");
Long toQCUserRrn = (Long) alarmInfo.get("toQCUserRrn");
Long toPMUserRrn = (Long) alarmInfo.get("toPMUserRrn");
Long workflowRrn = (Long) alarmInfo.get("workflowRrn");
if (fromUserRrn == null) {
fromUserRrn = 0L;
}
if (toUserRrn == null) {
toUserRrn = 0L;
}
if (toQCUserRrn == null) {
toQCUserRrn = 0L;
}
if (toPMUserRrn == null) {
toPMUserRrn = 0L;
}
Map fromUserInfo = securityService.getUserInfo4Alarm(fromUserRrn);
Map toUserInfo = securityService.getUserInfo4Alarm(toUserRrn);
Map toQCUserInfo = securityService.getUserInfo4Alarm(toQCUserRrn);
Map toPMUserInfo = securityService.getUserInfo4Alarm(toPMUserRrn);
if (toUserInfo == null) {
toUserInfo = securityService.getUserInfo4AlarmByUserGroup(toUserRrn);
}
if (toQCUserInfo == null) {
toQCUserInfo = securityService.getUserInfo4AlarmByUserGroup(toQCUserRrn);
}
if (toPMUserInfo == null) {
toPMUserInfo = securityService.getUserInfo4AlarmByUserGroup(toPMUserRrn);
}
alarmInfo.put("fromUserEmail", fromUserInfo.get("emailAddress"));
alarmInfo.put("toUserEmail", toUserInfo.get("emailAddress"));
alarmInfo.put("toQCUserEmail", toQCUserInfo.get("emailAddress"));
alarmInfo.put("toPMUserEmail", toPMUserInfo.get("emailAddress"));
alarmInfo.put("curTime", new Timestamp(System.currentTimeMillis()));
String entityDesc = (String) alarmInfo.get("entityDesc");
MailComponent.clearMap();
MailComponent.paraMap.put(MailComponent.ENTITY_DESC_PARAMETER_KEY, entityDesc);
if (alarmInfo.get("subject") != null) {
alarmInfo.put("subject", alarmInfo.get("subject") + " 计数警报 PM Count Notify");
}
HashMap values = buildWorkFlowValues(alarmInfo);
Map returnValue = executeWorkflow(workflowRrn, values);
long reportRrn = alarmService.insertAlarmActionHistory((HashMap) alarmInfo);
returnValue.put("reportRrn", reportRrn);
return returnValue;
}
private Map executeWorkflow(Long workflowRrn, HashMap values) {
values.put("WFL_RRN", "" + workflowRrn);
Map returnValue = new HashMap();
String sAlarmCategory = alarmService.getAlarmCategoryByWflRrn(workflowRrn);
if (StringUtils.equalsIgnoreCase(sAlarmCategory, "ALARM_PM_CATEGORY")) {
emsService.createChecklistJob(values);
}
return new HashMap();
}
private HashMap buildWorkFlowValues(Map<String, Object> alarmInfo) {
HashMap values = new HashMap();
values.putAll(alarmInfo);
values.put("jobRrn", alarmInfo.get("jobRrn") + "");
values.put("userRrn", alarmInfo.get("userRrn") + "");
values.put("entityRrn", alarmInfo.get("entityRrn") + "");
values.put("from", alarmInfo.get("fromUserEmail"));
values.put("to", alarmInfo.get("toUserEmail"));
values.put("toQC", alarmInfo.get("toQCUserEmail"));
values.put("toPM", alarmInfo.get("toPMUserEmail"));
if (alarmInfo.get("subject") != null) {
values.put("subject", alarmInfo.get("subject"));
} else {
values.put("subject", alarmInfo.get("alarmId"));
}
values.put("content", alarmInfo.get("alarmText"));
values.put(SessionNames.RUNSTEP_FLAG, "1");
values.put(SessionNames.PARENT_WFL_EXEC_RRN, "0");
values.put(SessionNames.RUNPARENTSTEP_FLAG, "0");
values.put(SessionNames.ROOT_WFL_EXEC_RRN, "0");
return values;
}
}