From 82415a93384a02277b580b470cc429148319f782 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Fri, 14 Apr 2023 14:10:22 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E6=97=A5=E5=B8=B8=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/OperMaintenanceLibraryEntity.java | 4 ++ .../entity/OperMaintenancePlanEntity.java | 4 ++ .../entity/OperMaintenanceTaskEntity.java | 4 ++ .../hnac/hzims/message/fegin/IMessageClient.java | 7 ++++ .../hzims/message/fegin/MessageClientFallback.java | 10 ++++- .../scheduled/MaintenanceTaskCreateTask.java | 44 ++++++++++++++++++++-- .../operational/src/main/resources/db/1.0.1.sql | 6 +++ 7 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 hzims-service/operational/src/main/resources/db/1.0.1.sql diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceLibraryEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceLibraryEntity.java index 3e95a8a..a096afa 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceLibraryEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceLibraryEntity.java @@ -117,4 +117,8 @@ public class OperMaintenanceLibraryEntity extends TenantEntity { @JsonSerialize(nullsUsing = NullSerializer.class) private Long createPlanStartDisposer; + @ApiModelProperty(value = "消息推送模板ID") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long messageTemplateId; + } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenancePlanEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenancePlanEntity.java index aca4fc8..968d033 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenancePlanEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenancePlanEntity.java @@ -104,4 +104,8 @@ public class OperMaintenancePlanEntity extends TenantEntity { @ApiModelProperty(value = "任务类型") private String taskType; + @ApiModelProperty(value = "消息推送模板ID") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long messageTemplateId; + } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceTaskEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceTaskEntity.java index 98bf4a3..a2a083f 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceTaskEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceTaskEntity.java @@ -145,4 +145,8 @@ public class OperMaintenanceTaskEntity extends TenantEntity { @ApiModelProperty("计划ID") @JsonSerialize(nullsUsing = NullSerializer.class) private Long planId; + + @ApiModelProperty(value = "消息推送模板ID") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long messageTemplateId; } diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java index a140ed3..b5d902d 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java @@ -5,10 +5,13 @@ import com.hnac.hzims.message.dto.MessagePushRecordDto; import com.hnac.hzims.message.dto.PushDto; import com.hnac.hzims.message.dto.SmsPushDto; import com.hnac.hzims.message.entity.MessagePushRecordEntity; +import com.hnac.hzims.message.entity.config.MessageTemplateEntity; import org.springblade.core.tool.api.R; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; /** * @author hx @@ -21,6 +24,7 @@ public interface IMessageClient { String API_PREFIX = "/feign/message"; String SEND_SMS_MESSAGE = API_PREFIX + "/send-sms-message"; String SEND_MESSAGE = API_PREFIX + "/sendMessage"; + String GET_TEMPLATE_BY_ID = API_PREFIX + "/getMsgTemplateById"; /** * 推送消息(短信) * @param pushDto @@ -31,4 +35,7 @@ public interface IMessageClient { @PostMapping(SEND_MESSAGE) R sendMessage(@RequestBody MessagePushRecordDto request); + + @GetMapping(GET_TEMPLATE_BY_ID) + R getMsgTemplateById(@RequestParam Long id); } diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java index 1aef9cb..90c79f0 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java @@ -4,6 +4,7 @@ import com.hnac.hzims.message.dto.MessagePushRecordDto; import com.hnac.hzims.message.dto.PushDto; import com.hnac.hzims.message.dto.SmsPushDto; import com.hnac.hzims.message.entity.MessagePushRecordEntity; +import com.hnac.hzims.message.entity.config.MessageTemplateEntity; import org.springblade.core.tool.api.R; import org.springframework.stereotype.Component; @@ -15,11 +16,16 @@ public class MessageClientFallback implements IMessageClient { @Override public R sendSmsMessage(SmsPushDto pushDto) { - return R.fail("推送失败"); + return R.fail("推送失败!"); } @Override public R sendMessage(MessagePushRecordDto request) { - return R.fail("推送失败"); + return R.fail("推送失败!"); + } + + @Override + public R getMsgTemplateById(Long id) { + return R.fail("获取消息模板失败!"); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java index ce3a70b..9e1e1cb 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java @@ -1,9 +1,14 @@ package com.hnac.hzims.operational.maintenance.scheduled; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.google.common.collect.Lists; import com.hnac.hzims.equipment.feign.IEmInfoClient; +import com.hnac.hzims.message.MessageConstants; +import com.hnac.hzims.message.dto.MessagePushRecordDto; +import com.hnac.hzims.message.entity.config.MessageTemplateEntity; +import com.hnac.hzims.message.fegin.IMessageClient; import com.hnac.hzims.message.req.PushExtrasReq; import com.hnac.hzims.operational.access.constants.AccessConstants; import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; @@ -20,10 +25,13 @@ import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.*; import org.springblade.flow.core.feign.IFlowClient; import org.springblade.flow.core.utils.FlowUtil; import org.springblade.flow.core.utils.TaskUtil; +import org.springblade.system.user.cache.UserCache; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; @@ -53,7 +61,8 @@ public class MaintenanceTaskCreateTask { private final IOperMaintenanceTaskService taskService; private final IImsDutyMainService mainService; private final RedisTemplate redisTemplate; - private final IEmInfoClient emInfoClient; + private final IMessageClient messageClient; + private final BladeLogger logger; @Value("${hzims.operation.task.templateCode.maintenance.taskDispose}") private String maintenanceTaskKey; @@ -149,15 +158,13 @@ public class MaintenanceTaskCreateTask { } } taskService.save(taskEntity); - //计算任务计划结束时间 存入redis - redisTemplate.opsForZSet().add(maintenanceTaskKey,taskEntity,disposeTime.toEpochSecond(ZoneOffset.of("+8"))); - redisTemplate.opsForZSet().add(REMIND_TASK_END_LIST,taskEntity,taskEntity.getPlanEndTime().toEpochSecond(ZoneOffset.of("+8"))); //生成工作流实例 String processInstanceId = this.startProcessInstance(planEntity.getProcDefId(), taskEntity); taskEntity.setProcessInstanceId(processInstanceId); taskService.updateById(taskEntity); planEntity.setCreateTaskTime(DateUtil.now()); planMapper.updateById(planEntity); + this.pushTaskMessage(taskEntity); } /** @@ -180,4 +187,33 @@ public class MaintenanceTaskCreateTask { .getData() .getProcessInstanceId(); } + + /** @Author hx + * @Description 推送日常维护任务消息 + * @Date 2023/4/12 18:39 + * @Param [taskEntity] 日常维护任务 + * @return void + **/ + private void pushTaskMessage(OperMaintenanceTaskEntity taskEntity) { + XxlJobLogger.log("开始保存{}的日常维护消息推送记录",taskEntity.getDisposer()); + R templateR = messageClient.getMsgTemplateById(taskEntity.getMessageTemplateId()); + if(templateR.isSuccess() && ObjectUtil.isNotEmpty(templateR.getData())) { + Func.toLongList("",taskEntity.getDisposer()).forEach(userId -> { + MessagePushRecordDto recordDto = BeanUtil.copy(templateR.getData(),MessagePushRecordDto.class); + recordDto.setTypes(Arrays.asList(Func.split(recordDto.getType(),","))); + recordDto.setDeptId(taskEntity.getCreateDept()); + recordDto.setCreateUser(taskEntity.getCreateUser()); + recordDto.setCreateDept(taskEntity.getCreateDept()); + ZoneId zoneId = ZoneId.systemDefault(); + recordDto.setPlanTime(LocalDateTime.ofInstant(taskEntity.getDisposeTime().toInstant(),zoneId)); + recordDto.setPushType(MessageConstants.PLAN); + recordDto.setPusher(userId.toString()); + recordDto.setPusherName(UserCache.getUser(userId).getName()); + recordDto.setAccount(recordDto.getPusher()); + recordDto.setContent("距离任务执行时间已不满一小时,请及时处理"); + XxlJobLogger.log("推送内容体为:{}", JSON.toJSONString(taskEntity.getDisposer())); + messageClient.sendMessage(recordDto); + }); + } + } } diff --git a/hzims-service/operational/src/main/resources/db/1.0.1.sql b/hzims-service/operational/src/main/resources/db/1.0.1.sql new file mode 100644 index 0000000..0ab54ec --- /dev/null +++ b/hzims-service/operational/src/main/resources/db/1.0.1.sql @@ -0,0 +1,6 @@ +-- 日常维护库添加消息模板ID +alter table hzims_oper_maintenance_library add COLUMN `MESSAGE_TEMPLATE_ID` bigint(20) comment '消息推送模板ID'; +-- 日常维护计划添加消息模板ID +alter table hzims_oper_maintenance_plan add COLUMN `MESSAGE_TEMPLATE_ID` bigint(20) comment '消息推送模板ID'; +-- 日常维护任务添加消息模板ID +alter table hzims_oper_maintenance_task add COLUMN `MESSAGE_TEMPLATE_ID` bigint(20) comment '消息推送模板ID'; \ No newline at end of file