Browse Source

# 日常维护消息推送接口修改

zhongwei
haungxing 2 years ago
parent
commit
82415a9338
  1. 4
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceLibraryEntity.java
  2. 4
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenancePlanEntity.java
  3. 4
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/entity/OperMaintenanceTaskEntity.java
  4. 7
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java
  5. 10
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java
  6. 44
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java
  7. 6
      hzims-service/operational/src/main/resources/db/1.0.1.sql

4
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;
}

4
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;
}

4
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;
}

7
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<Boolean> sendMessage(@RequestBody MessagePushRecordDto request);
@GetMapping(GET_TEMPLATE_BY_ID)
R<MessageTemplateEntity> getMsgTemplateById(@RequestParam Long id);
}

10
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<Boolean> sendMessage(MessagePushRecordDto request) {
return R.fail("推送失败");
return R.fail("推送失败!");
}
@Override
public R<MessageTemplateEntity> getMsgTemplateById(Long id) {
return R.fail("获取消息模板失败!");
}
}

44
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<MessageTemplateEntity> 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);
});
}
}
}

6
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';
Loading…
Cancel
Save