Browse Source
# Conflicts: # hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.javazhongwei
yang_shj
2 years ago
34 changed files with 1363 additions and 944 deletions
@ -0,0 +1,126 @@ |
|||||||
|
package com.hnac.hzinfo.inspect.task.aspect; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON; |
||||||
|
import com.alibaba.fastjson.JSONArray; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||||
|
import com.google.common.collect.Lists; |
||||||
|
import com.hnac.hzims.message.dto.PlanMsgRecordDto; |
||||||
|
import com.hnac.hzims.message.fegin.IMessageClient; |
||||||
|
import com.hnac.hzinfo.inspect.plan.entity.PlanEntity; |
||||||
|
import com.hnac.hzinfo.inspect.task.entity.TaskEntity; |
||||||
|
import com.hnac.hzinfo.inspect.task.entity.TaskUserEntity; |
||||||
|
import com.hnac.hzinfo.inspect.task.job.service.TaskRemindManager; |
||||||
|
import com.hnac.hzinfo.inspect.task.service.ITaskService; |
||||||
|
import com.hnac.hzinfo.inspect.task.service.ITaskUserService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.aspectj.lang.JoinPoint; |
||||||
|
import org.aspectj.lang.ProceedingJoinPoint; |
||||||
|
import org.aspectj.lang.annotation.After; |
||||||
|
import org.aspectj.lang.annotation.AfterReturning; |
||||||
|
import org.aspectj.lang.annotation.Aspect; |
||||||
|
import org.aspectj.lang.annotation.Pointcut; |
||||||
|
import org.springblade.core.secure.utils.AuthUtil; |
||||||
|
import org.springblade.core.tool.utils.CollectionUtil; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springblade.core.tool.utils.ObjectUtil; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.time.format.DateTimeFormatter; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName TaskGenerateAspect |
||||||
|
* @description: 消息生成后业务操作 |
||||||
|
* @author: hx |
||||||
|
* @create: 2023-04-17 11:21 |
||||||
|
* @Version 4.0 |
||||||
|
**/ |
||||||
|
@Aspect |
||||||
|
@Component |
||||||
|
@RequiredArgsConstructor |
||||||
|
@Slf4j |
||||||
|
public class TaskGenerateAspect { |
||||||
|
|
||||||
|
private final IMessageClient messageClient; |
||||||
|
private final ITaskService taskService; |
||||||
|
private final ITaskUserService taskUserService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 巡检任务开始前发送短信信息阿里云模板 |
||||||
|
**/ |
||||||
|
@Value("${hzims.inspect.task.templateCode.taskBegin}") |
||||||
|
private String taskBeginTemplateCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* 巡检任务结束前发送短信信息阿里云模板 |
||||||
|
**/ |
||||||
|
@Value("${hzims.inspect.task.templateCode.taskEnd}") |
||||||
|
private String taskEndTemplateCode; |
||||||
|
|
||||||
|
@Pointcut("execution(* com.hnac.hzinfo.inspect.task.job.service.ITaskJobService.sendTask(..))") |
||||||
|
public void taskSaveCut() { |
||||||
|
} |
||||||
|
|
||||||
|
@AfterReturning(value = "taskSaveCut()") |
||||||
|
private void saveTask(JoinPoint joinPoint) { |
||||||
|
Object[] args = joinPoint.getArgs(); |
||||||
|
new Thread(() -> { |
||||||
|
if(ObjectUtil.isNotEmpty(args[0]) && args[0] instanceof PlanEntity) { |
||||||
|
PlanEntity plan = (PlanEntity) args[0]; |
||||||
|
List<TaskEntity> list = taskService.list( |
||||||
|
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getPlanId,plan.getId()) |
||||||
|
); |
||||||
|
if(CollectionUtil.isNotEmpty(list)) { |
||||||
|
list.forEach(this::pushMessageByTask); |
||||||
|
} |
||||||
|
TaskEntity task = JSONObject.parseObject(JSON.toJSONString(args[0]),TaskEntity.class); |
||||||
|
this.pushMessageByTask(task); |
||||||
|
} |
||||||
|
},"巡检任务消息推送").start(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据巡检任务生成消息推送记录 |
||||||
|
* @param taskEntity 巡检任务 |
||||||
|
*/ |
||||||
|
private void pushMessageByTask(TaskEntity taskEntity) { |
||||||
|
PlanMsgRecordDto recordDto = new PlanMsgRecordDto(); |
||||||
|
recordDto.setDeptId(taskEntity.getCreateDept()); |
||||||
|
recordDto.setTemplateId(taskEntity.getMessageTemplateId()); |
||||||
|
recordDto.setTaskId(taskEntity.getId()); |
||||||
|
if(Func.isEmpty(AuthUtil.getUserId())) { |
||||||
|
recordDto.setTenantId(taskEntity.getTenantId()); |
||||||
|
} |
||||||
|
// 获取巡检任务的消息推送人
|
||||||
|
LambdaQueryWrapper<TaskUserEntity> eq = Wrappers.<TaskUserEntity>lambdaQuery().eq(TaskUserEntity::getTaskId, taskEntity.getId()); |
||||||
|
List<TaskUserEntity> taskUserList = taskUserService.list(eq); |
||||||
|
if(CollectionUtil.isNotEmpty(taskUserList)) { |
||||||
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
||||||
|
taskUserList.stream().map(TaskUserEntity::getUserId).filter(Func::isNotEmpty).forEach(userId -> { |
||||||
|
recordDto.setReceiver(userId); |
||||||
|
recordDto.setCreateUser(userId); |
||||||
|
Map<String,String> smsMap = new HashMap<>(2); |
||||||
|
// 消息开始前提醒
|
||||||
|
recordDto.setResourceCode(taskBeginTemplateCode); |
||||||
|
smsMap.put("one",taskEntity.getPlanName()); |
||||||
|
smsMap.put("two",df.format(taskEntity.getPlanStartTime())); |
||||||
|
recordDto.setPlanTime(taskEntity.getPlanStartTime()); |
||||||
|
recordDto.setSmsParam(JSON.toJSONString(smsMap)); |
||||||
|
recordDto.setContent("任务“"+ taskEntity.getPlanName() + "”的计划执行时间是:" + df.format(taskEntity.getPlanStartTime())+ " —— " + df.format(taskEntity.getPlanEndTime())); |
||||||
|
messageClient.planSendMessage(recordDto); |
||||||
|
// 消息结束前提醒
|
||||||
|
/* smsMap.put("two",df.format(taskEntity.getPlanEndTime())); |
||||||
|
recordDto.setPlanTime(taskEntity.getPlanEndTime()); |
||||||
|
recordDto.setSmsParam(JSON.toJSONString(smsMap)); |
||||||
|
messageClient.planSendMessage(recordDto);*/ |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,4 @@ |
|||||||
|
-- 巡检计划添加消息模板字段 |
||||||
|
alter table `hz_st_re_plan` add column `message_template_id` bigint(20) comment '消息模板ID'; |
||||||
|
-- 巡检任务添加消息模板字段 |
||||||
|
alter table `hz_st_ex_task` add column `message_template_id` bigint(20) comment '消息模板ID'; |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue