From 8055c39fdbc304d1bb2fcf3aaec999d4e2ae05a4 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Fri, 11 Aug 2023 16:36:00 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E5=B7=A1=E6=A3=80=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E5=86=85=E5=AE=B9=E4=BF=AE=E6=94=B9=20#=20AP?= =?UTF-8?q?P=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81=E8=A7=84=E5=88=99?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20#=20=E5=B7=A1=E6=A3=80=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=90=8D=E7=A7=B0=E6=90=9C=E7=B4=A2=E6=A8=A1?= =?UTF-8?q?=E7=B3=8A=E6=9F=A5=E8=AF=A2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/message/dto/PlanMsgRecordDto.java | 6 +- .../hzims/message/dto/SmsImmediatelyPushDTO.java | 2 + .../equipment/controller/EmInfoController.java | 1 + .../equipment/src/main/resources/db/1.0.1.sql | 1 + hzims-service/inspect/pom.xml | 7 +- .../hnac/hzinfo/inspect/config/RedisKeyConfig.java | 22 ++++ .../hzinfo/inspect/config/ThreadPoolConfig.java | 30 +++++ .../obj/services/IContentDefinitionService.java | 11 +- .../obj/web/ContentDefinitionController.java | 15 ++- .../inspect/task/aspect/TaskGenerateAspect.java | 45 ++++---- .../hzinfo/inspect/task/schedule/TaskSchedule.java | 123 +++++++++++++++++++++ .../inspect/task/schedule/XxlJobConstants.java | 11 ++ .../impl/TaskObjectProjectContentServiceImpl.java | 60 +++++++--- .../task/service/impl/TaskObjectServiceImpl.java | 14 ++- .../inspect/task/service/impl/TaskServiceImpl.java | 2 +- .../task/vo/TaskObjectProjectContentVO.java | 10 +- .../inspect/src/main/resources/application-dev.yml | 3 + .../src/main/resources/application-prod.yml | 3 + .../hnac/hzims/message/fegin/MessageClient.java | 17 +++ .../message/schedule/MessagePushSchedule.java | 2 +- .../message/service/IMessagePushRecordService.java | 5 + .../service/impl/MessagePushRecordServiceImpl.java | 4 +- 22 files changed, 327 insertions(+), 67 deletions(-) create mode 100644 hzims-service/equipment/src/main/resources/db/1.0.1.sql create mode 100644 hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/config/RedisKeyConfig.java create mode 100644 hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/config/ThreadPoolConfig.java create mode 100644 hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/TaskSchedule.java create mode 100644 hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/XxlJobConstants.java diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java index d2e233d..43ff3af 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java @@ -5,8 +5,8 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.NullSerializer; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; +import lombok.*; +import lombok.experimental.Accessors; import org.springblade.core.tool.utils.DateUtil; import org.springframework.format.annotation.DateTimeFormat; @@ -24,6 +24,7 @@ import java.time.LocalDateTime; @Data @ApiModel("计划推送消息请求对象") @EqualsAndHashCode +@Accessors(chain = true) public class PlanMsgRecordDto implements Serializable { @ApiModelProperty("机构ID") @@ -33,7 +34,6 @@ public class PlanMsgRecordDto implements Serializable { @ApiModelProperty("消息模板Id") @JsonSerialize(nullsUsing = NullSerializer.class) - @NotNull private Long templateId; @ApiModelProperty("业务任务Id") diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/SmsImmediatelyPushDTO.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/SmsImmediatelyPushDTO.java index 49e9c6d..d37aad0 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/SmsImmediatelyPushDTO.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/SmsImmediatelyPushDTO.java @@ -2,6 +2,7 @@ package com.hnac.hzims.message.dto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; import org.springblade.core.mp.support.QueryField; @@ -21,6 +22,7 @@ import java.util.Map; @Data @EqualsAndHashCode @ApiModel("短信即时推送请求内容") +@Builder public class SmsImmediatelyPushDTO implements Serializable { @ApiModelProperty(value = "机构ID",required = true) diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java index 082039e..f0c1a71 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java @@ -93,6 +93,7 @@ public class EmInfoController extends BladeController { public R> list(@ApiIgnore @RequestParam Map em_info, Query query) { QueryWrapper queryWrapper = Condition.getQueryWrapper(em_info, EmInfoEntity.class); queryWrapper.lambda().eq(EmInfoEntity::getGpid, 0); + queryWrapper.orderByDesc("create_time"); IPage pages = em_infoService.page(Condition.getPage(query), queryWrapper); // 获取站点列表 - 填充站点编码、站点类型、站点名称 R> stationListR = stationClient.list(new StationEntity()); diff --git a/hzims-service/equipment/src/main/resources/db/1.0.1.sql b/hzims-service/equipment/src/main/resources/db/1.0.1.sql new file mode 100644 index 0000000..5c7b661 --- /dev/null +++ b/hzims-service/equipment/src/main/resources/db/1.0.1.sql @@ -0,0 +1 @@ +alter table hzims_em_param add COLUMN NAME VARCHAR(100) comment '参数名称'; \ No newline at end of file diff --git a/hzims-service/inspect/pom.xml b/hzims-service/inspect/pom.xml index f3610b8..d3f2e45 100644 --- a/hzims-service/inspect/pom.xml +++ b/hzims-service/inspect/pom.xml @@ -70,7 +70,7 @@ org.springblade blade-user-api - ${bladex.project.version} + 5.0.1.RELEASE org.springblade @@ -235,10 +235,7 @@ ${docker.username} ${docker.password} - ${docker.registry.url}/${docker.namespace}/${project.build.finalName} - ${project.version} - true - +dd target/${project.build.finalName}.jar false diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/config/RedisKeyConfig.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/config/RedisKeyConfig.java new file mode 100644 index 0000000..a6f0a4d --- /dev/null +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/config/RedisKeyConfig.java @@ -0,0 +1,22 @@ +package com.hnac.hzinfo.inspect.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * @ClassName RedisKeyConfig + * @description: 巡检模块redis-key配置 + * @author: hx + * @create: 2023-08-02 09:23 + * @Version 4.0 + **/ +@Component +@ConfigurationProperties("hzims.redis.key") +@Data +public class RedisKeyConfig { + + /**巡检任务结束提醒**/ + private String taskEndRemind; + +} diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/config/ThreadPoolConfig.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/config/ThreadPoolConfig.java new file mode 100644 index 0000000..690775d --- /dev/null +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/config/ThreadPoolConfig.java @@ -0,0 +1,30 @@ +package com.hnac.hzinfo.inspect.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @ClassName ThreadPoolConfig + * @description: + * @author: hx + * @create: 2023-08-02 09:42 + * @Version 4.0 + **/ +@Configuration +public class ThreadPoolConfig { + + /** + * 巡检任务推送消息管理线程池 + * @return + */ + @Bean + public ExecutorService taskPushMsgExecutor() { + return new ThreadPoolExecutor(1, 6, 5L, TimeUnit.SECONDS,new LinkedBlockingQueue()); + } + +} diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java index 5d6a014..0d6eaf0 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java @@ -2,11 +2,11 @@ package com.hnac.hzinfo.inspect.obj.services; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.hnac.hzims.common.utils.Condition; import com.hnac.hzinfo.inspect.obj.dto.ContentDefinitionDTO; import com.hnac.hzinfo.inspect.obj.entity.ContentDefinitionEntity; import com.hnac.hzinfo.inspect.obj.vo.ContentDefinitionVO; import org.springblade.core.mp.base.BaseService; -import org.springblade.core.mp.support.Condition; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; @@ -22,12 +22,11 @@ public interface IContentDefinitionService extends BaseService list(ContentDefinitionDTO request); default LambdaQueryWrapper getQueryWrapper(ContentDefinitionEntity entity) { - QueryWrapper queryWrapper = Condition.getQueryWrapper(entity); - LambdaQueryWrapper lambda = queryWrapper.lambda() - .eq(Func.isNotEmpty(entity.getCreateDept()), ContentDefinitionEntity::getCreateDept, entity.getCreateDept()) + LambdaQueryWrapper queryWrapper = Condition.getQueryWrapper(entity,ContentDefinitionEntity.class); + queryWrapper.eq(Func.isNotEmpty(entity.getCreateDept()), ContentDefinitionEntity::getCreateDept, entity.getCreateDept()) .eq(Func.isNotEmpty(entity.getCreateUser()), ContentDefinitionEntity::getCreateUser, entity.getCreateUser()) - .eq(Func.isNotEmpty(entity.getStatus()), ContentDefinitionEntity::getStatus, entity.getStatus()); - return lambda; + .eq(Func.isNotEmpty(entity.getStatus()), ContentDefinitionEntity::getStatus, entity.getStatus()).orderByDesc(ContentDefinitionEntity::getCreateTime); + return queryWrapper; } } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ContentDefinitionController.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ContentDefinitionController.java index 0aa954b..589ddc0 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ContentDefinitionController.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ContentDefinitionController.java @@ -7,6 +7,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzinfo.inspect.obj.dto.ContentDefinitionDTO; import com.hnac.hzinfo.inspect.obj.entity.ContentDefinitionEntity; import com.hnac.hzinfo.inspect.obj.services.IContentDefinitionService; +import com.hnac.hzinfo.inspect.obj.utils.CodeUtils; import com.hnac.hzinfo.inspect.obj.vo.ContentDefinitionVO; import com.hnac.hzinfo.inspect.obj.wrapper.ContentDefinitionWrapper; import io.swagger.annotations.Api; @@ -56,10 +57,13 @@ public class ContentDefinitionController extends BladeController { return R.data(ContentDefinitionWrapper.build().listVO(contentDefinitionService.list(lambda))); } - @GetMapping("/save") + @PostMapping("/save") @ApiOperation("保存巡检内容定义") @ApiOperationSupport(order = 3) public R save(@RequestBody @Valid ContentDefinitionDTO content) { + if(content.getId()==null && Func.isBlank(content.getCode())){ + content.setCode(CodeUtils.randomCode()); + } return R.status(contentDefinitionService.save(BeanUtil.copy(content,ContentDefinitionEntity.class))); } @@ -76,4 +80,13 @@ public class ContentDefinitionController extends BladeController { public R removeByIds(@RequestParam String ids) { return R.status(contentDefinitionService.removeByIds(Func.toLongList(",",ids))); } + + @GetMapping("/detail") + @ApiOperation("查看详情") + @ApiOperationSupport(order = 6) + public R detail(@RequestParam Long id) { + ContentDefinitionEntity definition = contentDefinitionService.getById(id); + return R.data(ContentDefinitionWrapper.build().entityVO(definition)); + } + } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/aspect/TaskGenerateAspect.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/aspect/TaskGenerateAspect.java index 82685fd..29e00ea 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/aspect/TaskGenerateAspect.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/aspect/TaskGenerateAspect.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.message.dto.PlanMsgRecordDto; import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzinfo.inspect.config.RedisKeyConfig; import com.hnac.hzinfo.inspect.plan.entity.PlanEntity; import com.hnac.hzinfo.inspect.task.entity.TaskEntity; import com.hnac.hzinfo.inspect.task.entity.TaskUserEntity; @@ -19,15 +20,20 @@ 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.DateUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; /** * @ClassName TaskGenerateAspect @@ -45,6 +51,8 @@ public class TaskGenerateAspect { private final IMessageClient messageClient; private final ITaskService taskService; private final ITaskUserService taskUserService; + private final RedisTemplate redisTemplate; + private final RedisKeyConfig redisKeyConfig; /** * 巡检任务开始前发送短信信息阿里云模板 @@ -95,36 +103,25 @@ public class TaskGenerateAspect { */ private void pushMessageByTask(TaskEntity taskEntity) { log.info("======================进入消息推送======================"); - 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 eq = Wrappers.lambdaQuery().eq(TaskUserEntity::getTaskId, taskEntity.getId()); List 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 smsMap = new HashMap<>(2); - // 消息开始前提醒 - recordDto.setResourceCode(taskBeginTemplateCodeV2); - 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())); - log.info("巡检任务开始,推送对象:{}",JSON.toJSONString(recordDto)); - messageClient.planSendMessage(recordDto); - // 消息结束前提醒 - smsMap.put("two",df.format(taskEntity.getPlanEndTime())); - recordDto.setPlanTime(taskEntity.getPlanEndTime()); - recordDto.setSmsParam(JSON.toJSONString(smsMap)); + PlanMsgRecordDto recordDto = new PlanMsgRecordDto() + .setDeptId(taskEntity.getCreateDept()) + .setTemplateId(taskEntity.getMessageTemplateId()) + .setTaskId(taskEntity.getId()) + .setTenantId(Optional.ofNullable(AuthUtil.getTenantId()).orElse(taskEntity.getTenantId())) + .setReceiver(userId) + .setCreateUser(userId) + .setResourceCode(taskBeginTemplateCodeV2) + .setPlanTime(taskEntity.getPlanStartTime()) + .setContent("您在"+ DateUtil.format(taskEntity.getPlanStartTime(),DateUtil.PATTERN_DATETIME) +"时间有一条巡检任务——【"+taskEntity.getPlanName()+"】待执行,请及时处理!"); + // 任务开始提醒 - 集中提送 messageClient.planSendMessage(recordDto); + // 任务结束提醒 - 提醒存入redis 定时任务调用即时推送完成消息推送 + redisTemplate.opsForZSet().add(redisKeyConfig.getTaskEndRemind(),taskEntity,taskEntity.getEndRemindTime().toEpochSecond(ZoneOffset.of("+8"))); }); } } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/TaskSchedule.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/TaskSchedule.java new file mode 100644 index 0000000..f9dcd76 --- /dev/null +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/TaskSchedule.java @@ -0,0 +1,123 @@ +package com.hnac.hzinfo.inspect.task.schedule; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.collect.Lists; +import com.hnac.hzims.message.MessageConstants; +import com.hnac.hzims.message.dto.BusinessMessageDTO; +import com.hnac.hzims.message.dto.SmsImmediatelyPushDTO; +import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzinfo.inspect.config.RedisKeyConfig; +import com.hnac.hzinfo.inspect.task.TaskContants; +import com.hnac.hzinfo.inspect.task.entity.TaskEntity; +import com.hnac.hzinfo.inspect.task.entity.TaskUserEntity; +import com.hnac.hzinfo.inspect.task.service.ITaskService; +import com.hnac.hzinfo.inspect.task.service.ITaskUserService; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.MapUtils; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.Func; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cglib.core.Local; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneOffset; +import java.util.*; +import java.util.stream.Collectors; + +import static com.hnac.hzinfo.inspect.task.schedule.XxlJobConstants.*; + +/** + * @ClassName TaskSchedule + * @description: 巡检任务定时任务 + * @author: hx + * @create: 2023-08-10 14:21 + * @Version 4.0 + **/ +@Component +@RequiredArgsConstructor +@Slf4j +public class TaskSchedule { + + private final RedisTemplate redisTemplate; + private final ITaskService taskService; + private final ITaskUserService taskUserService; + private final RedisKeyConfig redisKeyConfig; + private final IMessageClient messageClient; + + @Value("${hzims.inspect.task.templateCode.taskEnd}") + private String taskEndTemplateCode; + + @XxlJob(TASK_END_REMIND) + public ReturnT sendTaskEndMessage(String params) { + Set remindTasks = redisTemplate.opsForZSet().rangeByScore(redisKeyConfig.getTaskEndRemind(), + LocalDateTime.of(LocalDate.now(), LocalTime.MIN).toEpochSecond(ZoneOffset.of("+8")), + LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"))); + if(CollectionUtil.isEmpty(remindTasks)) { + return new ReturnT(ReturnT.SUCCESS_CODE,"当前无待发送消息的任务"); + } + // 获取redis待推送巡检任务中状态为进行中的任务 + List idList = remindTasks.stream().map(TaskEntity::getId).collect(Collectors.toList()); + List taskList = taskService.list( + Wrappers.lambdaQuery() + .in(TaskEntity::getId, idList) + .in(TaskEntity::getStatus, Lists.newArrayList(TaskContants.TaskStatusEnum.UNDERWAY_STATUS.getStatus(),TaskContants.TaskStatusEnum.INIT_STATUS.getStatus())) + ); + Map> taskUserMap = taskUserService.list(Wrappers.lambdaQuery().in(TaskUserEntity::getTaskId,idList)).stream().collect(Collectors.groupingBy(TaskUserEntity::getTaskId)); + taskList.stream().filter(task -> taskUserMap.containsKey(task.getId())).flatMap(task -> + taskUserMap.get(task.getId()).stream().filter(taskUser -> Func.isNotEmpty(taskUser.getUserId())).map(taskUser -> { + task.setUserId(taskUser.getUserId()); + return task; + }) + ).forEach(this::sendTaskEndMessage); + + redisTemplate.opsForZSet().remove(redisKeyConfig.getTaskEndRemind(),remindTasks.toArray(new TaskEntity[remindTasks.size()])); + return ReturnT.SUCCESS; + } + + /** + * 推送消息 + * @param taskEntity 巡检任务 + */ + private void sendTaskEndMessage(TaskEntity taskEntity) { + // 短信推送 + SmsImmediatelyPushDTO smsPush = SmsImmediatelyPushDTO.builder() + .deptId(taskEntity.getCreateDept()) + .taskId(taskEntity.getId()) + .businessKey("巡检任务结束提醒") + .businessClassify(MessageConstants.BusinessClassifyEnum.INSPECT.getKey()) + .content("您有一条未执行的任务【"+taskEntity.getPlanName()+"】将于"+ DateUtil.format(taskEntity.getPlanEndTime(),DateUtil.PATTERN_DATETIME)+"截止,请及时处理!") + .subject("巡检任务结束提醒") + .pusher(taskEntity.getUserId().toString()) + .createUser(taskEntity.getCreateUser()) + .tenantId(taskEntity.getTenantId()) + .resourceCode(taskEndTemplateCode) + .params(new HashMap(){{ + put("one",taskEntity.getPlanName()); + put("two",DateUtil.format(taskEntity.getPlanEndTime(),DateUtil.PATTERN_DATETIME)); + }}) + .build(); + messageClient.sendSmsImmediatelyMsg(smsPush); + // app推送 + BusinessMessageDTO appMessage = new BusinessMessageDTO(); + appMessage.setDeptId(taskEntity.getCreateDept()); + appMessage.setBusinessKey("巡检任务结束提醒"); + appMessage.setBusinessClassify(MessageConstants.BusinessClassifyEnum.INSPECT.getKey()); + appMessage.setContent("您有一条未执行的任务【"+taskEntity.getPlanName()+"】将于"+ DateUtil.format(taskEntity.getPlanEndTime(),DateUtil.PATTERN_DATETIME)+"截止,请及时处理!"); + appMessage.setTaskId(taskEntity.getId()); + appMessage.setSubject("巡检任务结束提醒"); + appMessage.setUserIds(taskEntity.getUserId().toString()); + appMessage.setCreateUser(taskEntity.getCreateUser()); + appMessage.setTenantId(taskEntity.getTenantId()); + messageClient.sendAppAndWsMsgByUsers(appMessage); + taskService.update(Wrappers.lambdaUpdate().set(TaskEntity::getEndRemindFlag,true).eq(TaskEntity::getId,taskEntity.getId())); + } +} diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/XxlJobConstants.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/XxlJobConstants.java new file mode 100644 index 0000000..1a2d194 --- /dev/null +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/XxlJobConstants.java @@ -0,0 +1,11 @@ +package com.hnac.hzinfo.inspect.task.schedule; + +/** + * XxlJob常量池 + */ +public interface XxlJobConstants { + + /**巡检任务结束提醒**/ + String TASK_END_REMIND = "taskEndRemind"; + +} diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskObjectProjectContentServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskObjectProjectContentServiceImpl.java index 3588451..0beb398 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskObjectProjectContentServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskObjectProjectContentServiceImpl.java @@ -5,6 +5,9 @@ import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Lists; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.feign.IStationClient; +import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; +import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; +import com.hnac.hzinfo.datasearch.real.po.RealDataSearchPO; import com.hnac.hzinfo.inspect.obj.entity.ContentEntity; import com.hnac.hzinfo.inspect.obj.services.ContentService; import com.hnac.hzinfo.inspect.task.vo.TaskObjectProjectContentVO; @@ -16,6 +19,7 @@ import com.hnac.hzinfo.inspect.task.entity.TaskObjectProjectContentEntity; import com.hnac.hzinfo.inspect.task.mapper.TaskObjectProjectContentMapper; import com.hnac.hzinfo.inspect.task.service.ITaskObjectProjectContentService; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; @@ -38,6 +42,7 @@ import java.util.Optional; public class TaskObjectProjectContentServiceImpl extends BaseServiceImpl implements ITaskObjectProjectContentService { private final ContentService contentService; + private final IAnalyseDataSearchClient analyseDataSearchClient; private final IStationClient stationClient; private final RedisClient redisClient; @@ -50,25 +55,46 @@ public class TaskObjectProjectContentServiceImpl extends BaseServiceImpl stationR = stationClient.getOne(station); - if(stationR.isSuccess() && ObjectUtil.isNotEmpty(stationR.getData())) { - // 获取任务巡检内容实时数据 - List realDate = redisClient.getBatchRealDataByRealId(stationR.getData().getCode(), Lists.newArrayList(content.getFacDeviceId())); - log.info("station:{},facDeviceId:{},实时数据:{}",stationR.getData().getCode(),content.getFacDeviceId(), JSON.toJSONString(realDate)); - JSONObject realDataObject = Optional.ofNullable(realDate).map(list -> list.get(0)).filter(StringUtil::isNotBlank).map(JSONObject::parseObject).orElse(null); - // q值为0时为有效值 - if(ObjectUtil.isNotEmpty(realDataObject) && realDataObject.getIntValue("q") == 0) { - contentVO.setRealData(realDataObject.getDoubleValue("v")); - contentVO.setGatherTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(realDataObject.getLongValue("ts")), ZoneId.systemDefault())); - contentVO.setAttrSignage(content.getAttrSignage()); - contentVO.setAttrName(content.getAttrName()); - } + // 若内容中不存在模型的属性标识 则不获取实时数据 + if(Func.isNotEmpty(content.getAttrSignage()) && Func.isNotEmpty(contentVO.getEmCode())) { + RealDataSearchPO po = new RealDataSearchPO(); + po.setAnalyzeCode(contentVO.getEmCode()); + po.setSignages(Lists.newArrayList(content.getAttrSignage())); + R> realDataByAnalyzeCode = analyseDataSearchClient.getRealDataByAnalyzeCode(po); + if(realDataByAnalyzeCode.isSuccess() && CollectionUtil.isNotEmpty(realDataByAnalyzeCode.getData()) && realDataByAnalyzeCode.getData().get(0).getQ() == 0) { + FieldsData realData = realDataByAnalyzeCode.getData().get(0); + contentVO.setRealData(realData.getValue()); + contentVO.setAttrName(content.getAttrName()); + contentVO.setAttrSignage(content.getAttrSignage()); + contentVO.setGatherTime(realData.getTime()); } } } } + +// @Override +// public void fillRealData(TaskObjectProjectContentVO contentVO) { +// if(Func.isNotEmpty(contentVO.getContentId())) { +// ContentEntity content = contentService.getById(contentVO.getContentId()); +// if(ObjectUtil.isNotEmpty(content) && Func.isNotEmpty(content.getFacDeviceId())) { +// // 获取该项内容站点信息 +// StationEntity station = new StationEntity(); +// station.setRefDept(content.getCreateDept()); +// R stationR = stationClient.getOne(station); +// if(stationR.isSuccess() && ObjectUtil.isNotEmpty(stationR.getData())) { +// // 获取任务巡检内容实时数据 +// List realDate = redisClient.getBatchRealDataByRealId(stationR.getData().getCode(), Lists.newArrayList(content.getFacDeviceId())); +// log.info("station:{},facDeviceId:{},实时数据:{}",stationR.getData().getCode(),content.getFacDeviceId(), JSON.toJSONString(realDate)); +// JSONObject realDataObject = Optional.ofNullable(realDate).map(list -> list.get(0)).filter(StringUtil::isNotBlank).map(JSONObject::parseObject).orElse(null); +// // q值为0时为有效值 +// if(ObjectUtil.isNotEmpty(realDataObject) && realDataObject.getIntValue("q") == 0) { +// contentVO.setRealData(realDataObject.getDoubleValue("v")); +// contentVO.setGatherTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(realDataObject.getLongValue("ts")), ZoneId.systemDefault())); +// contentVO.setAttrSignage(content.getAttrSignage()); +// contentVO.setAttrName(content.getAttrName()); +// } +// } +// } +// } +// } } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskObjectServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskObjectServiceImpl.java index 4f988b5..d421097 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskObjectServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskObjectServiceImpl.java @@ -1,5 +1,7 @@ package com.hnac.hzinfo.inspect.task.service.impl; +import com.hnac.hzinfo.inspect.obj.entity.ProjectEntity; +import com.hnac.hzinfo.inspect.obj.services.ProjectService; import com.hnac.hzinfo.inspect.task.entity.TaskObjectEntity; import com.hnac.hzinfo.inspect.task.mapper.TaskObjectMapper; import com.hnac.hzinfo.inspect.task.service.ITaskObjectProjectContentService; @@ -25,6 +27,7 @@ import java.util.List; public class TaskObjectServiceImpl extends BaseServiceImpl implements ITaskObjectService { private final ITaskObjectProjectContentService taskContentService; + private final ProjectService projectService; @Override public List getTaskObjectList(TaskObjectEntity taskObjectEntity) { @@ -38,9 +41,14 @@ public class TaskObjectServiceImpl extends BaseServiceImpl CollectionUtil.isNotEmpty(taskObjectVO.getProjects())) .flatMap(taskObjectVO -> taskObjectVO.getProjects().stream()) - .filter(project -> CollectionUtil.isNotEmpty(project.getContents())) - .flatMap(project -> project.getContents().stream()) - .forEach(contentVO -> taskContentService.fillRealData(contentVO)); + .filter(taskObjectVO -> Func.isNotEmpty(taskObjectVO.getProjectId()) && CollectionUtil.isNotEmpty(taskObjectVO.getContents())) + .flatMap(project -> { + ProjectEntity projectEntity = projectService.getById(project.getProjectId()); + if(Func.isEmpty(projectEntity) && Func.isNotEmpty(projectEntity.getEmCode())) { + return null; + } + return project.getContents().stream().peek(contentVO -> contentVO.setEmCode(projectEntity.getEmCode())); + }).filter(Func::isNotEmpty).forEach(contentVO -> taskContentService.fillRealData(contentVO)); } return taskObjectVOList; } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java index 2171751..3f7e0df 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskServiceImpl.java @@ -571,7 +571,7 @@ public class TaskServiceImpl extends BaseServiceImpl imp @Override public List getListPageAuth(IPage page, TaskListQuery task) { List re = this.baseMapper.getListPageAuth(page, task); - setVoInfo(re); + setVoInfo(re); return re; } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/vo/TaskObjectProjectContentVO.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/vo/TaskObjectProjectContentVO.java index 76c4f40..3f129b5 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/vo/TaskObjectProjectContentVO.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/vo/TaskObjectProjectContentVO.java @@ -121,16 +121,18 @@ public class TaskObjectProjectContentVO implements Serializable { private String dictType; @ApiModelProperty(value = "实时数据") - private Double realData; + private String realData; @ApiModelProperty(value = "实时数据采集时间") - @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) - @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) - private LocalDateTime gatherTime; + private String gatherTime; @ApiModelProperty(value = "绑定物模型属性标识") private String attrSignage; @ApiModelProperty(value = "绑定物模型属性名称") private String attrName; + + @ApiModelProperty(value = "设备编号") + private String emCode; + } diff --git a/hzims-service/inspect/src/main/resources/application-dev.yml b/hzims-service/inspect/src/main/resources/application-dev.yml index 5c286b2..80c761c 100644 --- a/hzims-service/inspect/src/main/resources/application-dev.yml +++ b/hzims-service/inspect/src/main/resources/application-dev.yml @@ -50,6 +50,9 @@ hzinfo: hzims: + redis: + key: + taskEndRemind: 200000:hzims:inspect:task:end:remind tasks: flag: 1 inspect: diff --git a/hzims-service/inspect/src/main/resources/application-prod.yml b/hzims-service/inspect/src/main/resources/application-prod.yml index 5fa2201..dc9c50c 100644 --- a/hzims-service/inspect/src/main/resources/application-prod.yml +++ b/hzims-service/inspect/src/main/resources/application-prod.yml @@ -25,6 +25,9 @@ oss: secret-key: fjcR2RoQxZ4eTmOaB54rkITZjn/YVJhJZlckHxy/ hzims: + redis: + key: + taskEndRemind: hzims:inspect:task:end:remind tasks: flag: 1 inspect: diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java index 45bd14b..cec9f41 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java @@ -22,6 +22,8 @@ import org.springblade.core.log.exception.ServiceException; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.*; +import org.springblade.system.entity.Dept; +import org.springblade.system.feign.ISysClient; import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; import org.springframework.util.Assert; @@ -46,6 +48,7 @@ public class MessageClient extends BladeController implements IMessageClient{ private final IMessagePushRecordService recordService; private final IMessageTemplateService messageTemplateService; + private final ISysClient sysClient; @Override @PostMapping(SEND_SMS_MESSAGE) @@ -61,6 +64,7 @@ public class MessageClient extends BladeController implements IMessageClient{ // 可能存在多种推送类型 request.getTypes().forEach(type -> { MessagePushRecordEntity entity = BeanUtil.copy(request,MessagePushRecordEntity.class); + entity.setDeptName(Func.isNotEmpty(entity.getDeptName()) ? entity.getDeptName() : this.getDeptNameById(entity.getDeptId())); entity.setType(type); if(Func.isEmpty(AuthUtil.getUserId())) { entity.setCreateUser(request.getCreateUser()); @@ -83,6 +87,7 @@ public class MessageClient extends BladeController implements IMessageClient{ // 微信消息推送记录保存 List messages = Func.toLongList(request.getUserIds()).stream().map(userId -> { MessagePushRecordEntity entity = BeanUtil.copy(request, MessagePushRecordEntity.class); + entity.setDeptName(Func.isNotEmpty(entity.getDeptName()) ? entity.getDeptName() : this.getDeptNameById(entity.getDeptId())); entity.setMessageId(IdWorker.getId()); entity.setPusher(userId.toString()); entity.setPusherName(Optional.ofNullable(UserCache.getUser(userId)).map(User::getName).orElse(null)); @@ -111,6 +116,7 @@ public class MessageClient extends BladeController implements IMessageClient{ if(Func.isNotEmpty(template.getType())) { Func.toStrList(",",template.getType()).forEach(type -> { MessagePushRecordEntity entity = BeanUtil.copy(template,MessagePushRecordEntity.class); + entity.setDeptName(Func.isNotEmpty(entity.getDeptName()) ? entity.getDeptName() : this.getDeptNameById(entity.getDeptId())); entity.setId(null); entity.setType(type); entity.setTaskId(request.getTaskId()); @@ -146,6 +152,7 @@ public class MessageClient extends BladeController implements IMessageClient{ long messageId = IdWorker.getId(); return Lists.newArrayList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH).stream().map(messageType -> { MessagePushRecordEntity record = BeanUtil.copy(request, MessagePushRecordEntity.class); + record.setDeptName(Func.isNotEmpty(record.getDeptName()) ? record.getDeptName() : this.getDeptNameById(record.getDeptId())); record.setMessageId(messageId); record.setPusher(userId.toString()); record.setPusherName(Optional.ofNullable(UserCache.getUser(userId)).map(User::getName).orElse(null)); @@ -180,6 +187,7 @@ public class MessageClient extends BladeController implements IMessageClient{ String pusherName = Optional.ofNullable(smsImmediatelyPushDTO.getPusher()).map(Func::toLong).map(UserCache::getUser).map(User::getName).orElse(null); record.setPusherName(pusherName); record.setPushType(MessageConstants.IMMEDIATELY); + record.setDeptName(Func.isNotEmpty(record.getDeptName()) ? record.getDeptName() : this.getDeptNameById(record.getDeptId())); record.setPlanTime(LocalDateTime.now()); record.setType(MessageConstants.SMS_PUSH); record.setCreateDept(record.getDeptId()); @@ -189,4 +197,13 @@ public class MessageClient extends BladeController implements IMessageClient{ return R.data(recordService.sendSmsImmediatelyMsg(record)); } + /** + * 根据机构ID获取机构名称 + * @param deptId 机构ID + * @return 机构名称 + */ + private String getDeptNameById(Long deptId) { + return Optional.ofNullable(sysClient.getDeptName(deptId)).filter(r -> r.isSuccess()).map(R::getData).orElse(null); + } + } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java index a73c13b..f1024a3 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java @@ -111,7 +111,7 @@ public class MessagePushSchedule { } }); } - // redisTemplate.opsForList().remove(appPushKey,0,records); + records.forEach(record -> redisTemplate.opsForList().remove(appPushKey,0,record)); } }); return ReturnT.SUCCESS; diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java index 845a8fc..b6b82a3 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java @@ -128,5 +128,10 @@ public interface IMessagePushRecordService extends BaseService getPersonalUnreadMessage() { QueryWrapper query = Wrappers.query(); query.select("business_classify businessClassify,count(0) todoNum"); - query.eq("account", AuthUtil.getUserId()); + query.eq("pusher", AuthUtil.getUserId()); query.in("status", Lists.newArrayList(MessageConstants.PUSH_SUCCESS)); query.groupBy("business_classify"); List> list = noAurhScopeMapper.selectMaps(query); @@ -380,7 +380,7 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl getPersonalAppUnreadMessage() { QueryWrapper query = Wrappers.query(); query.select("business_classify businessClassify,count(0) todoNum"); - query.eq("account", AuthUtil.getUserId()); + query.eq("pusher", AuthUtil.getUserId()); query.eq("type", MessageConstants.APP_PUSH); query.in("status", Lists.newArrayList(MessageConstants.PUSH_SUCCESS)); query.groupBy("business_classify");