Browse Source

# 巡检消息推送内容修改

# APP消息推送规则修改
# 巡检内容定义名称搜索模糊查询修改
zhongwei
haungxing 1 year ago
parent
commit
8055c39fdb
  1. 6
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/PlanMsgRecordDto.java
  2. 2
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/SmsImmediatelyPushDTO.java
  3. 1
      hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java
  4. 1
      hzims-service/equipment/src/main/resources/db/1.0.1.sql
  5. 7
      hzims-service/inspect/pom.xml
  6. 22
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/config/RedisKeyConfig.java
  7. 30
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/config/ThreadPoolConfig.java
  8. 11
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/IContentDefinitionService.java
  9. 15
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/web/ContentDefinitionController.java
  10. 45
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/aspect/TaskGenerateAspect.java
  11. 123
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/TaskSchedule.java
  12. 11
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/XxlJobConstants.java
  13. 58
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskObjectProjectContentServiceImpl.java
  14. 14
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/service/impl/TaskObjectServiceImpl.java
  15. 10
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/vo/TaskObjectProjectContentVO.java
  16. 3
      hzims-service/inspect/src/main/resources/application-dev.yml
  17. 3
      hzims-service/inspect/src/main/resources/application-prod.yml
  18. 17
      hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java
  19. 2
      hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java
  20. 5
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java
  21. 4
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java

6
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")

2
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)

1
hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/controller/EmInfoController.java

@ -93,6 +93,7 @@ public class EmInfoController extends BladeController {
public R<IPage<EmInfoEntity>> list(@ApiIgnore @RequestParam Map<String, Object> em_info, Query query) {
QueryWrapper<EmInfoEntity> queryWrapper = Condition.getQueryWrapper(em_info, EmInfoEntity.class);
queryWrapper.lambda().eq(EmInfoEntity::getGpid, 0);
queryWrapper.orderByDesc("create_time");
IPage<EmInfoEntity> pages = em_infoService.page(Condition.getPage(query), queryWrapper);
// 获取站点列表 - 填充站点编码、站点类型、站点名称
R<List<StationEntity>> stationListR = stationClient.list(new StationEntity());

1
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 '参数名称';

7
hzims-service/inspect/pom.xml

@ -70,7 +70,7 @@
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-user-api</artifactId>
<version>${bladex.project.version}</version>
<version>5.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
@ -235,10 +235,7 @@
<configuration>
<username>${docker.username}</username>
<password>${docker.password}</password>
<repository>${docker.registry.url}/${docker.namespace}/${project.build.finalName}</repository>
<tag>${project.version}</tag>
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
<buildArgs>
dd <buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
<skip>false</skip>

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

30
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<Runnable>());
}
}

11
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<ContentDefinition
List<ContentDefinitionVO> list(ContentDefinitionDTO request);
default LambdaQueryWrapper<ContentDefinitionEntity> getQueryWrapper(ContentDefinitionEntity entity) {
QueryWrapper<ContentDefinitionEntity> queryWrapper = Condition.getQueryWrapper(entity);
LambdaQueryWrapper<ContentDefinitionEntity> lambda = queryWrapper.lambda()
.eq(Func.isNotEmpty(entity.getCreateDept()), ContentDefinitionEntity::getCreateDept, entity.getCreateDept())
LambdaQueryWrapper<ContentDefinitionEntity> 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;
}
}

15
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<ContentDefinitionVO> detail(@RequestParam Long id) {
ContentDefinitionEntity definition = contentDefinitionService.getById(id);
return R.data(ContentDefinitionWrapper.build().entityVO(definition));
}
}

45
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<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(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")));
});
}
}

123
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<String> sendTaskEndMessage(String params) {
Set<TaskEntity> 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<Long> idList = remindTasks.stream().map(TaskEntity::getId).collect(Collectors.toList());
List<TaskEntity> taskList = taskService.list(
Wrappers.<TaskEntity>lambdaQuery()
.in(TaskEntity::getId, idList)
.in(TaskEntity::getStatus, Lists.newArrayList(TaskContants.TaskStatusEnum.UNDERWAY_STATUS.getStatus(),TaskContants.TaskStatusEnum.INIT_STATUS.getStatus()))
);
Map<Long, List<TaskUserEntity>> taskUserMap = taskUserService.list(Wrappers.<TaskUserEntity>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<String,String>(){{
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.<TaskEntity>lambdaUpdate().set(TaskEntity::getEndRemindFlag,true).eq(TaskEntity::getId,taskEntity.getId()));
}
}

11
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";
}

58
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<TaskObjectProjectContentMapper, TaskObjectProjectContentEntity> 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<TaskObj
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<StationEntity> stationR = stationClient.getOne(station);
if(stationR.isSuccess() && ObjectUtil.isNotEmpty(stationR.getData())) {
// 获取任务巡检内容实时数据
List<String> 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());
// 若内容中不存在模型的属性标识 则不获取实时数据
if(Func.isNotEmpty(content.getAttrSignage()) && Func.isNotEmpty(contentVO.getEmCode())) {
RealDataSearchPO po = new RealDataSearchPO();
po.setAnalyzeCode(contentVO.getEmCode());
po.setSignages(Lists.newArrayList(content.getAttrSignage()));
R<List<FieldsData>> 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<StationEntity> stationR = stationClient.getOne(station);
// if(stationR.isSuccess() && ObjectUtil.isNotEmpty(stationR.getData())) {
// // 获取任务巡检内容实时数据
// List<String> 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());
// }
// }
// }
// }
// }
}

14
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<TaskObjectMapper, TaskObjectEntity> implements ITaskObjectService {
private final ITaskObjectProjectContentService taskContentService;
private final ProjectService projectService;
@Override
public List<TaskObjectEntity> getTaskObjectList(TaskObjectEntity taskObjectEntity) {
@ -38,9 +41,14 @@ public class TaskObjectServiceImpl extends BaseServiceImpl<TaskObjectMapper, Tas
taskObjectVOList.stream()
.filter(taskObjectVO -> 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;
}

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

3
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:

3
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:

17
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<MessagePushRecordEntity> 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);
}
}

2
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;

5
hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java

@ -128,5 +128,10 @@ public interface IMessagePushRecordService extends BaseService<MessagePushRecord
*/
UserPushStatTypeResponseVo newUserPushStat(MessagePushRecordEntityVo vo);
/**
* 推送即时短信
* @param record 短信内容
* @return 推送结果
*/
Boolean sendSmsImmediatelyMsg(MessagePushRecordEntity record);
}

4
hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java

@ -365,7 +365,7 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
public List<UnreadMessageVO> getPersonalUnreadMessage() {
QueryWrapper<MessagePushRecordEntity> 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<Map<String, Object>> list = noAurhScopeMapper.selectMaps(query);
@ -380,7 +380,7 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
public List<UnreadMessageVO> getPersonalAppUnreadMessage() {
QueryWrapper<MessagePushRecordEntity> 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");

Loading…
Cancel
Save