Browse Source

增加定时任务发送消息通知

master
赵鹏 2 months ago
parent
commit
bff2e3da13
  1. 3
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/enterpriseinspections/vo/EnterpriseInspectionsPageReqVO.java
  2. 2
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/taskinfo/TaskInfoController.java
  3. 5
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/taskinfo/vo/TaskInfoRespVO.java
  4. 7
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/taskinfo/vo/TaskInfoSaveReqVO.java
  5. 1
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/enterpriseinspections/EnterpriseInspectionsMapper.java
  6. 62
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/TaskSendStartMessageJob.java
  7. 2
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/taskinfo/TaskInfoService.java
  8. 40
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/taskinfo/TaskInfoServiceImpl.java

3
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/enterpriseinspections/vo/EnterpriseInspectionsPageReqVO.java

@ -48,5 +48,8 @@ public class EnterpriseInspectionsPageReqVO extends PageParam {
@Schema(description = "按部门查询的用户id集合")
private List<Long> userIds;
@Schema(description = "任务ids")
private List<Long> taskIds;
}

2
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/taskinfo/TaskInfoController.java

@ -84,7 +84,7 @@ public class TaskInfoController {
return success(taskInfoService.createTaskInfo(createReqVO));
}
@PutMapping("/update")
@PostMapping("/update")
@Operation(summary = "更新任务表,用于存储所有的任务信息,任务可由不同用户创建并管理。")
@PreAuthorize("@ss.hasPermission('system:task-info:update')")
public CommonResult<Boolean> updateTaskInfo(@Valid @RequestBody TaskInfoSaveReqVO updateReqVO) {

5
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/taskinfo/vo/TaskInfoRespVO.java

@ -103,6 +103,11 @@ public class TaskInfoRespVO {
@ExcelProperty("企业集合")
private List<EnterpriseDO> enterpriseIdes;
@Schema(description = "企业任务集合")
@ExcelProperty("企业任务集合")
private List<EnterpriseInspectionsDO> enterpriseIdeTasks;
@Schema(description = "标签集合")
@ExcelProperty("标签集合")
private List<TaskTagDO> taskTagIdes;

7
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/taskinfo/vo/TaskInfoSaveReqVO.java

@ -3,14 +3,19 @@ package cn.iocoder.yudao.module.system.controller.admin.taskinfo.vo;
import cn.iocoder.yudao.module.system.dal.dataobject.enterprise.EnterpriseDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.*;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 任务表,用于存储所有的任务信息,任务可由不同用户创建并管理。新增/修改 Request VO")
@Data
@ToString(callSuper = true)
public class TaskInfoSaveReqVO {
@Schema(description = "任务ID,主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "4541")
@ -42,9 +47,11 @@ public class TaskInfoSaveReqVO {
private String status;
@Schema(description = "任务计划开始时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime startDate;
@Schema(description = "任务计划结束时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime endDate;
@Schema(description = "父任务id", example = "30399")

1
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/enterpriseinspections/EnterpriseInspectionsMapper.java

@ -45,6 +45,7 @@ public interface EnterpriseInspectionsMapper extends BaseMapperX<EnterpriseInspe
.eqIfPresent(EnterpriseInspectionsDO::getTaskId, reqVO.getTaskId())
.eqIfPresent(EnterpriseInspectionsDO::getEnterpriseId, reqVO.getEnterpriseId())
.betweenIfPresent(EnterpriseInspectionsDO::getCreateTime, reqVO.getCreateTime())
.inIfPresent(EnterpriseInspectionsDO::getTaskId,reqVO.getTaskIds())
.orderByDesc(EnterpriseInspectionsDO::getId));
}

62
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/TaskSendStartMessageJob.java

@ -0,0 +1,62 @@
package cn.iocoder.yudao.module.system.job;
import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO;
import cn.iocoder.yudao.module.system.controller.admin.taskinfo.vo.TaskInfoRespVO;
import cn.iocoder.yudao.module.system.service.taskinfo.TaskInfoService;
import lombok.extern.slf4j.Slf4j;
import org.redisson.executor.TasksService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
@Slf4j
public class TaskSendStartMessageJob implements JobHandler {
@Resource
TaskInfoService taskInfoService;
@Resource
SocialClientApi socialClientApi;
@Override
public String execute(String param) throws Exception {
//要发送的信息
List<TaskInfoRespVO> beforeTaskInfoList = taskInfoService.getBeforeTaskInfoList();
beforeTaskInfoList.forEach(beforeTaskInfo -> {
beforeTaskInfo.getEnterpriseIdeTasks().forEach(x ->{
if(x.getUserId()!= null){
try {
//发送消息);
SocialWxaSubscribeMessageSendReqDTO reqDTO = new SocialWxaSubscribeMessageSendReqDTO();
reqDTO.setUserType(1);
reqDTO.setTemplateTitle("环保任务通知");
reqDTO.setPage("pages/index");
reqDTO.setUserId(x.getUserId());
Map<String, String> message = new HashMap<>();
message.put("thing2", beforeTaskInfo.getTitle());
message.put("time3", DateUtil.format(beforeTaskInfo.getStartDate(), DateUtils.FORMAT_YEAR_MONTH_DAY));
message.put("thing4", beforeTaskInfo.getDescription());
message.put("time5", DateUtil.format(beforeTaskInfo.getEndDate(), DateUtils.FORMAT_YEAR_MONTH_DAY));
reqDTO.setMessages(message);
socialClientApi.sendWxaSubscribeMessage(reqDTO);
}
catch (Exception e){
log.error("任务发送通知错误:",e.toString());
}
}
});
});
return "发送消息任务数量:"+ beforeTaskInfoList.size();
}
}

2
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/taskinfo/TaskInfoService.java

@ -55,6 +55,8 @@ public interface TaskInfoService {
// List<TaskInfoDO> getTaskInfoList(TaskInfoPageReqVO pageReqVO);
List<TaskInfoRespVO> getBeforeTaskInfoList();
//定时执行任务
void sendTask(Long taskId);

40
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/taskinfo/TaskInfoServiceImpl.java

@ -1,10 +1,11 @@
package cn.iocoder.yudao.module.system.service.taskinfo;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.infra.api.job.JobApi;
import cn.iocoder.yudao.module.system.controller.admin.tasktag.vo.TaskTagPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.enterpriseinspections.vo.EnterpriseInspectionsPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.enterprise.EnterpriseDO;
import cn.iocoder.yudao.module.system.dal.dataobject.enterpriseinspections.EnterpriseInspectionsDO;
import cn.iocoder.yudao.module.system.dal.dataobject.taglibrary.TagLibraryDO;
@ -31,9 +32,7 @@ import java.util.stream.Collectors;
import cn.iocoder.yudao.module.system.controller.admin.taskinfo.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.taskinfo.TaskInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.common.pojo.JobSaveReqVO;
import cn.iocoder.yudao.module.system.dal.mysql.taskinfo.TaskInfoMapper;
@ -180,6 +179,39 @@ public class TaskInfoServiceImpl implements TaskInfoService {
return taskInfoMapper.selectPage(pageReqVO);
}
@Override
public List<TaskInfoRespVO> getBeforeTaskInfoList() {
//查询所有新建的任务
LambdaQueryWrapperX<TaskInfoDO> queryWrapperX=new LambdaQueryWrapperX<TaskInfoDO>();
//待进行的任务
queryWrapperX.eqIfPresent(TaskInfoDO::getStatus,1);
//当天到任务
queryWrapperX.eqIfPresent(TaskInfoDO::getStartDate,DateUtil.format(new Date(), "yyyy-MM-dd"));
List<TaskInfoDO> taskInfoDOS = taskInfoMapper.selectList(queryWrapperX);
Map<Long, TaskInfoDO> taskMap = CollectionUtils.convertMap(taskInfoDOS, TaskInfoDO::getId);
EnterpriseInspectionsPageReqVO enterpriseInspectionsPageReqVO=new EnterpriseInspectionsPageReqVO();
enterpriseInspectionsPageReqVO.setTaskIds(taskMap.keySet().parallelStream().collect(Collectors.toList()));
List<EnterpriseInspectionsDO> enterpriseInspectionsDOList = enterpriseInspectionsMapper.selectList(enterpriseInspectionsPageReqVO);
Map<Long, List<EnterpriseInspectionsDO>> enterpriseInspectionsMap = CollectionUtils.convertMultiMap(enterpriseInspectionsDOList, EnterpriseInspectionsDO::getTaskId);
List<TaskInfoRespVO> taskInfoRespVOS = new LinkedList<>();
taskMap.forEach((k,v)->{
TaskInfoRespVO taskInfoRespVO=BeanUtils.toBean(v,TaskInfoRespVO.class);
taskInfoRespVO.setEnterpriseIdeTasks(enterpriseInspectionsMap.get(k));
taskInfoRespVOS.add(taskInfoRespVO);
});
return taskInfoRespVOS;
}
@Override
public void sendTask(Long taskId) {

Loading…
Cancel
Save