From 930932971fbaa8dae0233373ddde3d88c94f7781 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 26 Aug 2024 18:49:33 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E6=89=A9=E5=B1=95?= =?UTF-8?q?=E7=9F=AD=E4=BF=A1esb=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1227688277147648]扩展短信esb插件 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1227688277147648 --- .../api/notify/test/TestNotifyPolicyApi.java | 147 ++++++++++++++++++ .../param/DeployJobEndTimeParamHandler.java | 23 +++ .../param/DeployJobStartTimeParamHandler.java | 23 +++ 3 files changed, 193 insertions(+) create mode 100644 src/main/java/neatlogic/module/deploy/api/notify/test/TestNotifyPolicyApi.java create mode 100644 src/main/java/neatlogic/module/deploy/notify/handler/param/DeployJobEndTimeParamHandler.java create mode 100644 src/main/java/neatlogic/module/deploy/notify/handler/param/DeployJobStartTimeParamHandler.java diff --git a/src/main/java/neatlogic/module/deploy/api/notify/test/TestNotifyPolicyApi.java b/src/main/java/neatlogic/module/deploy/api/notify/test/TestNotifyPolicyApi.java new file mode 100644 index 00000000..de99e6e2 --- /dev/null +++ b/src/main/java/neatlogic/module/deploy/api/notify/test/TestNotifyPolicyApi.java @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.deploy.api.notify.test; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.NOTIFY_POLICY_MODIFY; +import neatlogic.framework.autoexec.constvalue.JobUserType; +import neatlogic.framework.cmdb.crossover.IAppSystemMapper; +import neatlogic.framework.cmdb.dto.resourcecenter.entity.AppModuleVo; +import neatlogic.framework.cmdb.dto.resourcecenter.entity.AppSystemVo; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.common.constvalue.GroupSearch; +import neatlogic.framework.common.constvalue.SystemUser; +import neatlogic.framework.crossover.CrossoverServiceFactory; +import neatlogic.framework.deploy.constvalue.DeployJobNotifyTriggerType; +import neatlogic.framework.deploy.dto.job.DeployJobVo; +import neatlogic.framework.notify.dao.mapper.NotifyMapper; +import neatlogic.framework.notify.dto.NotifyPolicyVo; +import neatlogic.framework.notify.dto.NotifyReceiverVo; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.NotifyPolicyUtil; +import neatlogic.module.deploy.dao.mapper.DeployJobMapper; +import neatlogic.module.deploy.handler.DeployJobMessageHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +@Service +@AuthAction(action = NOTIFY_POLICY_MODIFY.class) +@OperationType(type = OperationTypeEnum.SEARCH) +public class TestNotifyPolicyApi extends PrivateApiComponentBase { + + @Resource + private DeployJobMapper deployJobMapper; + + @Resource + private NotifyMapper notifyMapper; + + private final Logger logger = LoggerFactory.getLogger(TestNotifyPolicyApi.class); + + @Override + public String getName() { + return "测试通知策略"; + } + + @Input({ + @Param(name = "jobId", type = ApiParamType.LONG, isRequired = true, desc = "作业ID"), + @Param(name = "jobStatus", type = ApiParamType.STRING, isRequired = true, desc = "作业状态"), + @Param(name = "notifyPolicyId", type = ApiParamType.STRING, isRequired = true, desc = "通知策略ID") + }) + @Output({ + }) + @Description(desc = "测试通知策略") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + Long jobId = paramObj.getLong("jobId"); + String jobStatus = paramObj.getString("jobStatus"); + DeployJobNotifyTriggerType trigger = DeployJobNotifyTriggerType.getTriggerByStatus(jobStatus); + if (trigger == null) { + return null; + } + DeployJobVo jobInfo = deployJobMapper.getDeployJobInfoByJobId(jobId); + if (jobInfo == null) { + return null; + } + Long appSystemId = jobInfo.getAppSystemId(); + if (appSystemId == null) { + return null; + } + IAppSystemMapper iAppSystemMapper = CrossoverServiceFactory.getApi(IAppSystemMapper.class); + AppSystemVo appSystemVo = iAppSystemMapper.getAppSystemById(appSystemId); + if (appSystemVo != null) { + jobInfo.setAppSystemName(appSystemVo.getName()); + jobInfo.setAppSystemAbbrName(appSystemVo.getAbbrName()); + } + Long appModuleId = jobInfo.getAppModuleId(); + if (appModuleId != null) { + AppModuleVo appModuleVo = iAppSystemMapper.getAppModuleById(appModuleId); + if (appModuleVo != null) { + jobInfo.setAppModuleName(appModuleVo.getName()); + jobInfo.setAppModuleAbbrName(appModuleVo.getAbbrName()); + } + } +// String configStr = deployAppConfigMapper.getAppSystemNotifyPolicyConfigByAppSystemId(appSystemId); +// InvokeNotifyPolicyConfigVo invokeNotifyPolicyConfigVo = JSONObject.parseObject(configStr, InvokeNotifyPolicyConfigVo.class); +// INotifyServiceCrossoverService notifyServiceCrossoverService = CrossoverServiceFactory.getApi(INotifyServiceCrossoverService.class); +// invokeNotifyPolicyConfigVo = notifyServiceCrossoverService.regulateNotifyPolicyConfig(invokeNotifyPolicyConfigVo); +// if (invokeNotifyPolicyConfigVo == null) { +// return null; +// } + // 触发点被排除,不用发送邮件 +// List excludeTriggerList = invokeNotifyPolicyConfigVo.getExcludeTriggerList(); +// if (CollectionUtils.isNotEmpty(excludeTriggerList) && excludeTriggerList.contains(trigger.getTrigger())) { +// return null; +// } +// Long notifyPolicyId = invokeNotifyPolicyConfigVo.getPolicyId(); +// if (notifyPolicyId == null) { +// return null; +// } + Long notifyPolicyId = paramObj.getLong("notifyPolicyId"); + NotifyPolicyVo notifyPolicyVo = notifyMapper.getNotifyPolicyById(notifyPolicyId); + if (notifyPolicyVo == null || notifyPolicyVo.getConfig() == null) { + return null; + } + try { + Map> receiverMap = new HashMap<>(); + if (!Objects.equals(jobInfo.getExecUser(), SystemUser.SYSTEM.getUserUuid())) { + receiverMap.computeIfAbsent(JobUserType.EXEC_USER.getValue(), k -> new ArrayList<>()) + .add(new NotifyReceiverVo(GroupSearch.USER.getValue(), jobInfo.getExecUser())); + } + String notifyAuditMessage = jobInfo.getId() + "-" + jobInfo.getName(); + NotifyPolicyUtil.execute(notifyPolicyVo.getHandler(), trigger, DeployJobMessageHandler.class + , notifyPolicyVo, null, null, receiverMap + , jobInfo, null, notifyAuditMessage); + } catch (Exception ex) { + logger.error("发布作业:" + jobInfo.getId() + "-" + jobInfo.getName() + "通知失败"); + logger.error(ex.getMessage(), ex); + } + return null; + } + + @Override + public String getToken() { + return "deploy/notify/policy/test"; + } +} diff --git a/src/main/java/neatlogic/module/deploy/notify/handler/param/DeployJobEndTimeParamHandler.java b/src/main/java/neatlogic/module/deploy/notify/handler/param/DeployJobEndTimeParamHandler.java new file mode 100644 index 00000000..8f22c19f --- /dev/null +++ b/src/main/java/neatlogic/module/deploy/notify/handler/param/DeployJobEndTimeParamHandler.java @@ -0,0 +1,23 @@ +package neatlogic.module.deploy.notify.handler.param; + +import neatlogic.framework.deploy.constvalue.DeployJobNotifyParam; +import neatlogic.framework.deploy.dto.job.DeployJobVo; +import neatlogic.framework.deploy.notify.DeployJobNotifyParamHandlerBase; +import neatlogic.framework.util.TimeUtil; +import org.springframework.stereotype.Component; + +@Component +public class DeployJobEndTimeParamHandler extends DeployJobNotifyParamHandlerBase { + @Override + public Object getMyText(DeployJobVo deployJobVo) { + if (deployJobVo != null && deployJobVo.getEndTime() != null) { + return TimeUtil.convertDateToString(deployJobVo.getEndTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS); + } + return null; + } + + @Override + public String getValue() { + return DeployJobNotifyParam.DEPLOYJOBENDTIME.getValue(); + } +} diff --git a/src/main/java/neatlogic/module/deploy/notify/handler/param/DeployJobStartTimeParamHandler.java b/src/main/java/neatlogic/module/deploy/notify/handler/param/DeployJobStartTimeParamHandler.java new file mode 100644 index 00000000..0b93e786 --- /dev/null +++ b/src/main/java/neatlogic/module/deploy/notify/handler/param/DeployJobStartTimeParamHandler.java @@ -0,0 +1,23 @@ +package neatlogic.module.deploy.notify.handler.param; + +import neatlogic.framework.deploy.constvalue.DeployJobNotifyParam; +import neatlogic.framework.deploy.dto.job.DeployJobVo; +import neatlogic.framework.deploy.notify.DeployJobNotifyParamHandlerBase; +import neatlogic.framework.util.TimeUtil; +import org.springframework.stereotype.Component; + +@Component +public class DeployJobStartTimeParamHandler extends DeployJobNotifyParamHandlerBase { + @Override + public Object getMyText(DeployJobVo deployJobVo) { + if (deployJobVo != null && deployJobVo.getStartTime() != null) { + return TimeUtil.convertDateToString(deployJobVo.getStartTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS); + } + return null; + } + + @Override + public String getValue() { + return DeployJobNotifyParam.DEPLOYJOBSTARTTIME.getValue(); + } +} -- Gitee