Commit 720151cb authored by xinglei's avatar xinglei

*)防火监督改为规则发送消息

parent 5db5e659
package com.yeejoin.amos.supervision.common.enums;
public enum ExecuteStateNameEnum {
通过("通过", 0),
不通过("不通过", 1);
/**
* 名称,描述
*/
private String name;
/**
* 编码
*/
private Integer code;
ExecuteStateNameEnum(String name, Integer code) {
this.name = name;
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public static String getNameByCode(Integer code) {
for (ExecuteStateNameEnum e : ExecuteStateNameEnum.values()) {
if (code.equals(e.getCode())) {
return e.getName();
}
}
return null;
}
}
......@@ -8,8 +8,12 @@ package com.yeejoin.amos.supervision.common.enums;
public enum RuleTypeEnum {
GETCONTENT("维保项获取","getContent"),
CHECKRESULT("结果校验","checkResult" );
CHECKRESULT("结果校验","checkResult" ),
// 防火监督
计划提交("计划提交", "addPlan"),
计划审核("计划审核", "planAudit"),
计划生成("计划生成", "addPlanTask");
/**
* 名称,描述
......
package com.yeejoin.amos.supervision.business.dto;
import com.yeejoin.amos.component.rule.Label;
import com.yeejoin.amos.component.rule.RuleFact;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @Author: xl
* @Description: 计划规则触发对象
* @Date: 2021/11/10 10:01
*/
@Data
@RuleFact(value = "巡检计划",project = "消息规则")
public class PlanRo implements Serializable {
private static final long serialVersionUID = 3847767788621939352L;
@Label("计划名称")
private String name;
@Label(value = "检查类型名称")
private String checkTypeName;
@Label(value = "执行方法")
private String ruleType;
@Label(value = "执行状态")
private String excuteStateName;
@Label(value = "推送时间")
private String sendTime;
@Label(value = "接收人")
private List<String> recivers;
@Label(value = "发送到web标识")
private Boolean isSendWeb;
@Label(value = "发送到app标识")
private Boolean isSendApp;
@Label("关联id")
private String relationId;
@Label("消息类型")
private String msgType;
@Label(value = "终端标识")
private String terminal;
}
......@@ -73,7 +73,7 @@ public class PlanAuditServiceImpl implements IPlanAuditService {
planAuditLog.setFlowJson(condition);
planAuditLog.setRoleName(roleName);
planAuditLogDao.save(planAuditLog);
planService.getUserIdsByWorkflow(plan, instanceId);
planService.getUserIdsByWorkflow(plan, instanceId, status, planAuditLog.getExcuteState());
return Boolean.TRUE;
}
}
......
......@@ -15,10 +15,7 @@ import com.yeejoin.amos.supervision.business.dao.mapper.PointMapper;
import com.yeejoin.amos.supervision.business.dao.repository.*;
import com.yeejoin.amos.supervision.business.param.PlanInfoPageParam;
import com.yeejoin.amos.supervision.business.service.intfc.IPlanService;
import com.yeejoin.amos.supervision.common.enums.CheckTypeSuEnum;
import com.yeejoin.amos.supervision.common.enums.DangerCheckTypeLevelEnum;
import com.yeejoin.amos.supervision.common.enums.PlanStatusEnum;
import com.yeejoin.amos.supervision.common.enums.WorkFlowBranchEnum;
import com.yeejoin.amos.supervision.common.enums.*;
import com.yeejoin.amos.supervision.core.async.AsyncTask;
import com.yeejoin.amos.supervision.core.common.request.AddPlanRequest;
import com.yeejoin.amos.supervision.core.common.response.PlanPointRespone;
......@@ -36,6 +33,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
......@@ -83,6 +81,9 @@ public class PlanServiceImpl implements IPlanService {
private AsyncTask asyncTask;
@Autowired
private RulePlanService rulePlanService;
@Autowired
WorkflowFeignService workflowFeignService;
@Autowired
......@@ -183,7 +184,7 @@ public class PlanServiceImpl implements IPlanService {
//更新时间
audit.setUpdateDate(new Date());
planAuditDao.save(audit);
this.getUserIdsByWorkflow(plan, processInstanceId);
this.getUserIdsByWorkflow(plan, processInstanceId, null, null);
//记录执行流水-启动节点
insertAuditLog(reginParams, plan, personIdentity, audit);
} else {
......@@ -198,7 +199,7 @@ public class PlanServiceImpl implements IPlanService {
planAuditDao.save(audit);
//记录执行流水-启动节点
insertAuditLog(reginParams, plan, personIdentity, audit);
this.getUserIdsByWorkflow(plan, processInstanceId);
this.getUserIdsByWorkflow(plan, processInstanceId,null, null);
}
} catch (Exception e) {
log.error("=============防火监督,计划提交,工作流启动失败!!!=============");
......@@ -208,10 +209,10 @@ public class PlanServiceImpl implements IPlanService {
}
/**
* 根据工作流获取下一审核人角色下的所有用户ID
* 根据工作流获取下一审核人角色下的所有用户ID =》规则推送消息
* @return
*/
protected List<String> getUserIdsByWorkflow (Plan plan, String processInstanceId){
protected List<String> getUserIdsByWorkflow (Plan plan, String processInstanceId, Integer status, Integer excuteState){
List<String> userIds = new ArrayList<>();
JSONObject teskObject = workflowFeignService.getTaskList(processInstanceId);
JSONArray taskDetailArray = teskObject.getJSONArray(WorkFlowEnum.DATA.getCode());
......@@ -223,9 +224,15 @@ public class PlanServiceImpl implements IPlanService {
JSONObject jsonItem = (JSONObject) item;
return jsonItem.getString("userId");
}).collect(Collectors.toList());
asyncTask.sendAddPlanMsg(RequestContext.cloneRequestContext(), plan, userIds, true, false);
} else {
asyncTask.sendPlanMsgToLeadPeople(RequestContext.cloneRequestContext(), plan);
}
try {
if (ValidationUtil.isEmpty(status)){
rulePlanService.addPlanRule(plan, userIds, RuleTypeEnum.计划提交.getCode()); // 计划提交
} else {
rulePlanService.addPlanAuditRule(plan, userIds, RuleTypeEnum.计划审核.getCode(), ExecuteStateNameEnum.getNameByCode(excuteState)); // 计划审核
}
} catch (Exception e) {
log.info("规则调用失败");
}
}
return userIds;
......
......@@ -12,11 +12,6 @@ import com.yeejoin.amos.supervision.business.dao.mapper.PlanTaskDetailMapper;
import com.yeejoin.amos.supervision.business.dao.mapper.PlanTaskMapper;
import com.yeejoin.amos.supervision.business.dao.mapper.RoutePointItemMapper;
import com.yeejoin.amos.supervision.business.dao.repository.*;
import com.yeejoin.amos.supervision.business.dao.repository.ICheckDao;
import com.yeejoin.amos.supervision.business.dao.repository.IPlanDao;
import com.yeejoin.amos.supervision.business.dao.repository.IPlanTaskDao;
import com.yeejoin.amos.supervision.business.dao.repository.IPlanTaskDetailDao;
import com.yeejoin.amos.supervision.business.dao.repository.IRoutePointDao;
import com.yeejoin.amos.supervision.business.entity.mybatis.CheckChkExListBo;
import com.yeejoin.amos.supervision.business.entity.mybatis.PointCheckDetailBo;
import com.yeejoin.amos.supervision.business.feign.Business;
......@@ -34,19 +29,21 @@ import com.yeejoin.amos.supervision.business.vo.PlanTaskVo;
import com.yeejoin.amos.supervision.common.enums.PlanStatusEnum;
import com.yeejoin.amos.supervision.common.enums.PlanTaskDetailIsFinishEnum;
import com.yeejoin.amos.supervision.common.enums.PlanTaskFinishStatusEnum;
import com.yeejoin.amos.supervision.core.async.AsyncTask;
import com.yeejoin.amos.supervision.common.enums.RuleTypeEnum;
import com.yeejoin.amos.supervision.core.common.request.CommonPageable;
import com.yeejoin.amos.supervision.core.common.response.AppCheckInputRespone;
import com.yeejoin.amos.supervision.core.common.response.AppPointCheckRespone;
import com.yeejoin.amos.supervision.core.util.DateUtil;
import com.yeejoin.amos.supervision.core.util.StringUtil;
import com.yeejoin.amos.supervision.dao.entity.*;
import com.yeejoin.amos.supervision.dao.entity.Check;
import com.yeejoin.amos.supervision.dao.entity.Plan;
import com.yeejoin.amos.supervision.dao.entity.PlanTask;
import com.yeejoin.amos.supervision.dao.entity.PlanTaskDetail;
import com.yeejoin.amos.supervision.exception.YeeException;
import com.yeejoin.amos.supervision.feign.RemoteSecurityService;
import com.yeejoin.amos.supervision.quartz.IJobService;
import org.apache.commons.collections.CollectionUtils;
import org.assertj.core.util.Lists;
import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -56,7 +53,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.text.ParseException;
......@@ -106,7 +102,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
private RoutePointItemMapper routePointItemMapper;
@Autowired
private AsyncTask asyncTask;
private RulePlanService rulePlanService;
@Override
public Page<HashMap<String, Object>> getPlanTaskInfo(PlanTaskPageParam params) {
......@@ -531,8 +527,8 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
// 2.保存执行数据明细表
planTaskDetail.saveAndFlush(planTaskDetailInstance);
// 推送消息
asyncTask.sendPlanMsg(RequestContext.cloneRequestContext(), plan);
// 规则推送消息
rulePlanService.addPlanRule(plan, null, RuleTypeEnum.计划生成.getCode());
}
// 定时任务监控
jobService.planTaskAddJob(planTask);
......
package com.yeejoin.amos.supervision.business.service.impl;
import com.yeejoin.amos.component.rule.RuleTrigger;
import com.yeejoin.amos.supervision.business.dto.PlanRo;
import com.yeejoin.amos.supervision.business.feign.JCSFeignClient;
import com.yeejoin.amos.supervision.business.util.DateUtil;
import com.yeejoin.amos.supervision.dao.entity.Plan;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.util.Date;
import java.util.List;
/**
* @Author: xl
* @Description: 巡检计划触发规则
* @Date: 2021/11/10 9:50
*/
@Service
public class RulePlanService {
private final String packageId = "消息/addPlanRule";
private final String msgType = "supervision";
private final String APP = "APP";
private final String WEB = "WEB";
private final String APP_WEB = "APP/WEB";
@Autowired
private RuleTrigger ruleTrigger;
@Autowired
private JCSFeignClient jcsFeignClient;
public Boolean addPlanRule(Plan plan, List<String> userIds, String ruleType) throws Exception {
PlanRo planRo = buildPlanRo(plan, userIds, ruleType);
//触发规则
ruleTrigger.publish(planRo, packageId, new String[0]);
return true;
}
public Boolean addPlanAuditRule(Plan plan, List<String> userIds, String ruleType, String excuteStateName) throws Exception {
PlanRo planRo = buildPlanRo(plan, userIds, ruleType);
planRo.setExcuteStateName(excuteStateName);
//触发规则
ruleTrigger.publish(planRo, packageId, new String[0]);
return true;
}
private PlanRo buildPlanRo (Plan plan, List<String> userIds, String ruleType){
PlanRo planRo = new PlanRo();
BeanUtils.copyProperties(plan, planRo);
planRo.setMsgType(msgType);
planRo.setRuleType(ruleType);
planRo.setRelationId(String.valueOf(plan.getId()));
if (ValidationUtil.isEmpty(userIds)){
String leadPeopleIds = plan.getLeadPeopleIds();
if (!ValidationUtil.isEmpty(plan.getUserId()) && !leadPeopleIds.contains(plan.getUserId())){
leadPeopleIds += "," + plan.getUserId();
}
userIds = (List<String>)jcsFeignClient.getAmosIdListByUserIds(leadPeopleIds).getResult();
planRo.setIsSendApp(true);
planRo.setTerminal(WEB);
} else {
planRo.setIsSendWeb(true);
planRo.setIsSendApp(false);
planRo.setTerminal(APP_WEB);
}
planRo.setSendTime(DateUtil.date2LongStr(new Date()));
planRo.setRecivers(userIds);
return planRo;
}
}
package com.yeejoin.amos.supervision.business.util;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.supervision.business.param.MsgInfoPageParam;
import com.yeejoin.amos.supervision.core.common.request.CommonPageable;
import com.yeejoin.amos.supervision.core.common.request.CommonRequest;
......@@ -40,4 +44,11 @@ public class MsgParamUtils {
return value.toString();
}
}
public static String instedParams(String content, Object msgObj) {
Map<String, Object> strengthMap = JSON.parseObject(JSON.toJSONString(msgObj), Map.class);
for (String key : strengthMap.keySet())
content = content.replaceAll("\\$\\{" + key + "}", String.valueOf(strengthMap.get(key)));
return content;
}
}
package com.yeejoin.amos.supervision.rule.action;
import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.component.rule.RuleActionBean;
import com.yeejoin.amos.component.rule.RuleMethod;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.MessageModel;
import com.yeejoin.amos.supervision.business.util.MsgParamUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
/**
* @Author: xl
* @Description: 消息规则动作
* @Date: 2021/11/10 11:49
*/
@Component
@RuleActionBean(beanLabel = "消息发送")
public class MessageAction {
public static final Logger log = LoggerFactory.getLogger(MessageAction.class);
@RuleMethod(methodLabel = "消息发送", project = "消息")
public void sendMessage(Object msgObj, String title, String content) {
MessageModel messageModel = JSON.parseObject(JSON.toJSONString(msgObj), MessageModel.class);
messageModel.setTitle(title);
messageModel.setBody(MsgParamUtils.instedParams(content, msgObj));
if (!ValidationUtil.isEmpty(messageModel)) {
try {
Systemctl.messageClient.create(messageModel);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment