Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
yang_shj 2 years ago
parent
commit
b899d3016e
  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. 58
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java
  5. 18
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java
  6. 16
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java
  7. 40
      hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java
  8. 26
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessageService.java
  9. 2
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/SmsMessageServiceImpl.java
  10. 44
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java
  11. 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;
}

58
hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java

@ -0,0 +1,58 @@
package com.hnac.hzims.message.dto;
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 javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @ClassName PlanMsgRecordDto
* @description:
* @author: hx
* @create: 2023-04-14 14:15
* @Version 4.0
**/
@Data
@ApiModel("计划推送消息请求对象")
@EqualsAndHashCode
public class PlanMsgRecordDto implements Serializable {
@ApiModelProperty("机构ID")
@JsonSerialize(nullsUsing = NullSerializer.class)
@NotNull
private Long deptId;
@ApiModelProperty("消息模板Id")
@JsonSerialize(nullsUsing = NullSerializer.class)
@NotNull
private Long templateId;
@ApiModelProperty("业务任务Id")
@JsonSerialize(nullsUsing = NullSerializer.class)
@NotNull
private Long taskId;
@ApiModelProperty("消息接收人")
@JsonSerialize(nullsUsing = NullSerializer.class)
@NotNull
private Long receiver;
@ApiModelProperty("消息推送计划时间")
@NotNull
private LocalDateTime planTime;
@ApiModelProperty("消息创建人")
@JsonSerialize(nullsUsing = NullSerializer.class)
private Long createUser;
@ApiModelProperty("消息推送耳机")
@NotNull
private String content;
}

18
hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java

@ -2,13 +2,17 @@ package com.hnac.hzims.message.fegin;
import com.hnac.hzims.message.MessageConstants;
import com.hnac.hzims.message.dto.MessagePushRecordDto;
import com.hnac.hzims.message.dto.PlanMsgRecordDto;
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 +25,8 @@ 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";
String PLAN_SEND_MESSAGE = API_PREFIX + "/planSendMessage";
/**
* 推送消息短信
* @param pushDto
@ -31,4 +37,16 @@ public interface IMessageClient {
@PostMapping(SEND_MESSAGE)
R<Boolean> sendMessage(@RequestBody MessagePushRecordDto request);
@GetMapping(GET_TEMPLATE_BY_ID)
R<MessageTemplateEntity> getMsgTemplateById(@RequestParam Long id);
/** @Author hx
* @Description 计划推送类型消息推送
* @Date 2023/4/14 15:04
* @Param
* @return
**/
@PostMapping(PLAN_SEND_MESSAGE)
R<PlanMsgRecordDto> planSendMessage(@RequestBody PlanMsgRecordDto request);
}

16
hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java

@ -1,9 +1,11 @@
package com.hnac.hzims.message.fegin;
import com.hnac.hzims.message.dto.MessagePushRecordDto;
import com.hnac.hzims.message.dto.PlanMsgRecordDto;
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 +17,21 @@ 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("获取消息模板失败!");
}
@Override
public R<PlanMsgRecordDto> planSendMessage(PlanMsgRecordDto request) {
return R.fail("调用失败!");
}
}

40
hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.hnac.hzims.message.MessageConstants;
import com.hnac.hzims.message.dto.MessagePushRecordDto;
import com.hnac.hzims.message.dto.PlanMsgRecordDto;
import com.hnac.hzims.message.dto.PushDto;
import com.hnac.hzims.message.dto.SmsPushDto;
import com.hnac.hzims.message.entity.MessagePushRecordEntity;
@ -12,15 +13,24 @@ import com.hnac.hzims.message.service.IMessagePushRecordService;
import com.hnac.hzims.message.service.IMessageService;
import com.hnac.hzims.message.service.IMessageTemplateService;
import com.hnac.hzims.message.service.impl.SmsMessageServiceImpl;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.system.user.cache.UserCache;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
/**
* @author hx
@ -60,4 +70,34 @@ public class MessageClient extends BladeController implements IMessageClient{
return R.data(messageTemplateService.getById(id));
}
@PostMapping(PLAN_SEND_MESSAGE)
@Override
public R<PlanMsgRecordDto> planSendMessage(@RequestBody @Valid PlanMsgRecordDto request) {
MessageTemplateEntity template = messageTemplateService.getById(request.getTemplateId());
Assert.isTrue(ObjectUtil.isNotEmpty(template),() -> {
throw new ServiceException("获取消息模板失败,请检查消息模板是否删除!");
});
long messageId = IdWorker.getId();
if(Func.isNotEmpty(template.getType())) {
Func.toStrList(",",template.getType()).forEach(type -> {
MessagePushRecordEntity entity = BeanUtil.copy(template,MessagePushRecordEntity.class);
entity.setType(type);
entity.setTemplateId(messageId);
entity.setDeptId(request.getDeptId());
entity.setCreateUser(request.getCreateUser());
entity.setCreateDept(request.getDeptId());
entity.setPlanTime(request.getPlanTime());
entity.setPushType(MessageConstants.PLAN);
entity.setPusher(request.getReceiver().toString());
entity.setPusherName(UserCache.getUser(request.getReceiver()).getName());
entity.setAccount(request.getReceiver().toString());
entity.setContent(request.getContent());
Assert.isTrue(recordService.saveAndSend(entity),()-> {
throw new ServiceException("消息保存失败!");
});
});
}
return R.success("推送成功!");
}
}

26
hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessageService.java

@ -4,6 +4,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.hnac.hzims.message.dto.PushDto;
import com.hnac.hzims.message.entity.MessagePushRecordEntity;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;
import static com.hnac.hzims.message.MessageConstants.*;
/**
* @author hx
@ -19,4 +24,25 @@ public interface IMessageService {
boolean send(MessagePushRecordEntity request);
/** @Author hx
* @Description 根据消息接受人获取推送账号
* @Date 2023/4/14 15:09
* @Param pusher 消息接收人
* @return
**/
default String getAccountByPusher(Long pusher,String type) {
User user = UserCache.getUser(pusher);
if(ObjectUtil.isNotEmpty(user)) {
switch(type) {
case MAIL_PUSH:
return Func.isNotEmpty(user.getEmail()) ? user.getEmail() : Long.toString(pusher);
case SMS_PUSH:
return Func.isNotEmpty(user.getPhone()) ? user.getPhone() : Long.toString(pusher);
default:
break;
}
}
return Long.toString(pusher);
}
}

2
hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/SmsMessageServiceImpl.java

@ -52,7 +52,7 @@ public class SmsMessageServiceImpl implements IMessageService {
Func.isNotEmpty(AuthUtil.getTenantId()) ? AuthUtil.getTenantId() : request.getTenantId(),
request.getResourceCode(),
request.getContent(),
request.getAccount()
this.getAccountByPusher(Long.parseLong(request.getPusher()),request.getType())
);
Assert.isTrue(response.isSuccess(),() -> {
throw new ServiceException(response.getMsg());

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