Commit 79c28b42 authored by xinglei's avatar xinglei

*)公共包增加通用消息规则触发动作方法

parent da364e6d
package com.yeejoin.amos.boot.module.common.api.rule.action;//package com.yeejoin.amos.latentdanger.business.rule.action;
import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.boot.module.common.api.util.RuleUtils;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.foundation.context.RequestContext;
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(RuleUtils.instedParams(content, msgObj));
if (!ValidationUtil.isEmpty(messageModel)) {
try {
Systemctl.messageClient.create(messageModel);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
package com.yeejoin.amos.boot.module.common.api.util;
import com.alibaba.fastjson.JSON;
import java.util.Map;
/**
* @Author: xl
* @Description:
* @Date: 2021/11/12 18:37
*/
public class RuleUtils {
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.latentdanger.common.enums;
/**
* 规则请求枚举
* @author xl
*
*/
public enum RuleTypeEnum {
// 隐患
隐患第一次提交("隐患提交", "addLatentDanger"),
隐患审核("隐患审核", "dangerAudit");
/**
* 名称,描述
*/
private String name;
/**
* 编码
*/
private String code;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
private RuleTypeEnum(String name, String code){
this.name = name;
this.code = code;
}
}
package com.yeejoin.amos.latentdanger.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;
import java.util.Map;
/**
* @Author: xl
* @Description: 隐患规则实体
* @Date: 2021/11/12 14:44
*/
@Data
@RuleFact(value = "隐患",project = "消息规则")
public class LatentDangerRo implements Serializable {
private static final long serialVersionUID = -2985122485796921797L;
@Label("隐患名称")
private String dangerName;
@Label(value = "隐患等级名称")
private String dangerLevelName;
@Label(value = "执行方法")
private String ruleType;
@Label(value = "整改类型名称")
private String reformTypeName;
@Label(value = "隐患状态名称")
private String dangerStateName;
@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;
@Label(value = "扩展参数")
private Map<String, String> extras;
}
......@@ -49,20 +49,7 @@ import com.yeejoin.amos.latentdanger.business.vo.DangerTimeAxisVo;
import com.yeejoin.amos.latentdanger.business.vo.LatentDangerDetailRiskVo;
import com.yeejoin.amos.latentdanger.business.vo.LatentDangerDetailVo;
import com.yeejoin.amos.latentdanger.business.vo.LatentDangerListVo;
import com.yeejoin.amos.latentdanger.common.enums.DangerHandleStateEnum;
import com.yeejoin.amos.latentdanger.common.enums.DictTypeEnum;
import com.yeejoin.amos.latentdanger.common.enums.ExecuteStateEnum;
import com.yeejoin.amos.latentdanger.common.enums.ExecuteTypeEnum;
import com.yeejoin.amos.latentdanger.common.enums.LatentDangerBizTypeEnum;
import com.yeejoin.amos.latentdanger.common.enums.LatentDangerExecuteTypeEnum;
import com.yeejoin.amos.latentdanger.common.enums.LatentDangerLevelEnum;
import com.yeejoin.amos.latentdanger.common.enums.LatentDangerOvertimeStateEnum;
import com.yeejoin.amos.latentdanger.common.enums.LatentDangerProcessStateEnum;
import com.yeejoin.amos.latentdanger.common.enums.LatentDangerReformTypeEnum;
import com.yeejoin.amos.latentdanger.common.enums.LatentDangerState;
import com.yeejoin.amos.latentdanger.common.enums.LatentDangerStateEnum;
import com.yeejoin.amos.latentdanger.common.enums.LatentDangerTypeEnum;
import com.yeejoin.amos.latentdanger.common.enums.OwerEnum;
import com.yeejoin.amos.latentdanger.common.enums.*;
import com.yeejoin.amos.latentdanger.common.remote.RemoteSpcService;
import com.yeejoin.amos.latentdanger.common.remote.RemoteWebSocketServer;
import com.yeejoin.amos.latentdanger.common.remote.RemoteWorkFlowService;
......@@ -144,6 +131,8 @@ public class LatentDangerServiceImpl extends BaseService<LatentDangerBo, LatentD
private RemoteSpcService remoteSpcService;
@Autowired
private AsyncTask asyncTask;
@Autowired
private RuleDangerService ruleDangerService;
// @Autowired
// private Business business;
@Autowired
......@@ -288,7 +277,7 @@ public class LatentDangerServiceImpl extends BaseService<LatentDangerBo, LatentD
latentDanger.setCurrentFlowRecordId(inputRecord.getId());
latentDanger.setInstanceId(instance.getString("id"));
latentDangerMapper.updateById(latentDanger);
asyncTask.sendDangerMsg(RequestContext.cloneRequestContext(), latentDanger, onSiteConfirmRole);
ruleDangerService.addLatentDangerRule(latentDanger, RuleTypeEnum.隐患第一次提交.getCode(), onSiteConfirmRole);
}
// TODO 使用远程调用替换
......@@ -2110,7 +2099,7 @@ public class LatentDangerServiceImpl extends BaseService<LatentDangerBo, LatentD
throw new Exception(executeSubmitDto.getMsg());
}
List<String> userIds = workflowExecuteService.getUserIdsByWorkflow(latentDanger.getInstanceId(), executeSubmitDto.getCheckLeaderId());
asyncTask.sendDangerSubmitMsg(RequestContext.cloneRequestContext(), latentDanger, userIds, ExecuteTypeEnum.getNameByCode(executeType));
ruleDangerService.addDangerSubmitRule(latentDanger, userIds, RuleTypeEnum.隐患审核.getCode(), ExecuteTypeEnum.getNameByCode(executeType));
return executeSubmitDto;
}
......
package com.yeejoin.amos.latentdanger.business.service.impl;
import com.yeejoin.amos.component.rule.RuleTrigger;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.RoleModel;
import com.yeejoin.amos.latentdanger.business.dto.LatentDangerRo;
import com.yeejoin.amos.latentdanger.business.util.DateUtil;
import com.yeejoin.amos.latentdanger.common.enums.LatentDangerState;
import com.yeejoin.amos.latentdanger.dao.entity.LatentDanger;
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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Author: xl
* @Description: 隐患触发规则
* @Date: 2021/11/12 14:55
*/
@Service
public class RuleDangerService {
private final String packageId = "消息/addDangerRule";
private final String msgType = "danger";
private final String APP = "APP";
private final String WEB = "WEB";
private final String APP_WEB = "APP/WEB";
@Autowired
private RuleTrigger ruleTrigger;
public Boolean addLatentDangerRule(LatentDanger latentDanger, String ruleType, String roleName) throws Exception {
LatentDangerRo latentDangerRo = buildLatentDangerRo(latentDanger, ruleType);
List<RoleModel> result = Privilege.roleClient.queryRoleList(roleName, null).getResult();
if (result.size() > 0) {
List<AgencyUserModel> userModels = Privilege.agencyUserClient.queryByRoleId(String.valueOf(result.get(0).getSequenceNbr()), null).getResult();
List<String> userIds = userModels.stream().map(AgencyUserModel::getUserId).collect(Collectors.toList());
latentDangerRo.setRecivers(userIds);
}
//触发规则
ruleTrigger.publish(latentDangerRo, packageId, new String[0]);
return true;
}
public Boolean addDangerSubmitRule(LatentDanger latentDanger, List<String> userIds, String ruleType, String excuteStateName) throws Exception {
LatentDangerRo latentDangerRo = buildLatentDangerRo(latentDanger, ruleType);
latentDangerRo.setExcuteStateName(excuteStateName);
latentDangerRo.setIsSendWeb(true);
latentDangerRo.setRecivers(userIds);
//触发规则
ruleTrigger.publish(latentDangerRo, packageId, new String[0]);
return true;
}
private LatentDangerRo buildLatentDangerRo (LatentDanger latentDanger, String ruleType){
LatentDangerRo latentDangerRo = new LatentDangerRo();
BeanUtils.copyProperties(latentDanger, latentDangerRo);
latentDangerRo.setMsgType(msgType);
latentDangerRo.setIsSendApp(true);
latentDangerRo.setRuleType(ruleType);
latentDangerRo.setRelationId(String.valueOf(latentDanger.getId()));
latentDangerRo.setSendTime(DateUtil.date2LongStr(new Date()));
String type = null;
latentDanger.getDangerState();
LatentDangerState.SupervisionDangerStateEnum stateEnum =
LatentDangerState.SupervisionDangerStateEnum.getEnumByCode(latentDanger.getDangerState());
if (!ValidationUtil.isEmpty(stateEnum)) {
if (stateEnum.getProcessState().equals("1")) {
type = "1";
} else if (stateEnum.getProcessState().equals("4")) {
type = "2";
}
}
if (!ValidationUtil.isEmpty(type)){
Map<String, String> map = new HashMap<>();
map.put("type", type);
latentDangerRo.setExtras(map);
}
return latentDangerRo;
}
}
......@@ -15,7 +15,7 @@ import java.util.List;
/**
* @Author: xl
* @Description: 巡检计划触发规则
* @Description: 防火监督触发规则
* @Date: 2021/11/10 9:50
*/
@Service
......@@ -50,19 +50,19 @@ public class RulePlanService {
return true;
}
private PlanRo buildPlanRo (Plan plan, List<String> userIds, String ruleType){
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)){
if (ValidationUtil.isEmpty(userIds)) {
String leadPeopleIds = plan.getLeadPeopleIds();
if (!ValidationUtil.isEmpty(plan.getUserId()) && !leadPeopleIds.contains(plan.getUserId())){
if (!ValidationUtil.isEmpty(plan.getUserId()) && !leadPeopleIds.contains(plan.getUserId())) {
leadPeopleIds += "," + plan.getUserId();
}
userIds = (List<String>)jcsFeignClient.getAmosIdListByUserIds(leadPeopleIds).getResult();
userIds = (List<String>) jcsFeignClient.getAmosIdListByUserIds(leadPeopleIds).getResult();
planRo.setIsSendApp(true);
planRo.setTerminal(WEB);
} else {
......
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