From 23e3da03b9ec1896ab32272e0c64c101ac625af0 Mon Sep 17 00:00:00 2001 From: tyty Date: Tue, 10 Oct 2023 14:48:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=92=E7=89=88=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E5=88=B0=E6=9C=9F=E6=B6=88=E6=81=AF=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operational/main/constant/MainConstants.java | 4 + .../scheduled/DutyNoticeScheduledTask.java | 123 +++++++++++++++++++++ .../operation/business/impl/DutyServiceImpl.java | 14 +++ .../duty/service/impl/ImsDutyRecServiceImpl.java | 2 + 4 files changed, 143 insertions(+) create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/DutyNoticeScheduledTask.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java index 67e0fd5..e8b21ab 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java @@ -78,4 +78,8 @@ public interface MainConstants { // 光伏站-机组指标数据 String LOAD_PHOTOVOLTAIC_REAL = "loadPhotovoltaicReal"; + + String DUTY_NOTICE = "dutyNotice"; + + String PROJECT_MANAGER = "projectManager"; } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/DutyNoticeScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/DutyNoticeScheduledTask.java new file mode 100644 index 0000000..1fc6b8e --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/DutyNoticeScheduledTask.java @@ -0,0 +1,123 @@ +package com.hnac.hzims.scheduled.scheduled; + +import com.hnac.hzims.common.logs.utils.StringUtils; +import com.hnac.hzims.message.MessageConstants; +import com.hnac.hzims.message.dto.BusinessMessageDTO; +import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzims.scheduled.service.operation.business.impl.DutyServiceImpl; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.system.feign.ISysClient; +import org.springblade.system.user.entity.User; +import org.springblade.system.user.feign.IUserClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +import static com.hnac.hzims.operational.main.constant.MainConstants.DUTY_NOTICE; +import static com.hnac.hzims.operational.main.constant.MainConstants.PROJECT_MANAGER; + + +/** + * 排班到期定时任务通知 + * + * @author ty + */ +@Slf4j +@Component +public class DutyNoticeScheduledTask { + + @Autowired + private DutyServiceImpl service; + @Autowired + private ISysClient sysClient; + @Autowired + private IUserClient userClient; + @Autowired + private IMessageClient messageClient; + + /** + * realId刷新 + */ + @XxlJob(DUTY_NOTICE) +// @Scheduled(cron = "0 */1 * * * ? ") + public ReturnT dutyNotice(String param) throws ParseException { + if (Func.isBlank(param)) { + param = DateUtil.format(new Date(), "yyyy-MM-dd"); + } + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date datyTime = dateFormat.parse(param); + String dateAddOne = DateUtil.format(DateUtil.plusDays(datyTime, 1), "yyyy-MM-dd"); + String dateAddTwo = DateUtil.format(DateUtil.plusDays(datyTime, 2), "yyyy-MM-dd"); + String dateAddThree = DateUtil.format(DateUtil.plusDays(datyTime, 3), "yyyy-MM-dd"); + List deptByDate = service.getDeptByMainDate(param); + List deptAndSendNotice1 = service.getDeptByMainDate(dateAddOne); + List deptAndSendNotice2 = service.getDeptByMainDate(dateAddTwo); + List deptAndSendNotice3 = service.getDeptByMainDate(dateAddThree); + //去除一天后有排版计划部门 + for (Long deptIdByDayOne : deptAndSendNotice1) { + if (deptByDate.contains(deptIdByDayOne)) { + deptByDate.remove(deptIdByDayOne); + } + } + sendMessage(deptByDate, 1); + //去除二天有排版计划的部门 + for (Long deptIdByDayTwo : deptAndSendNotice2) { + if (deptAndSendNotice3.contains(deptIdByDayTwo)) { + deptByDate.remove(deptIdByDayTwo); + } + } + sendMessage(deptByDate, 2); + //去除三天有排版计划的部门 + for (Long deptIdByDayTwo : deptAndSendNotice3) { + if (deptAndSendNotice3.contains(deptIdByDayTwo)) { + deptByDate.remove(deptIdByDayTwo); + } + } + sendMessage(deptByDate, 3); + return new ReturnT<>("SUCCESS"); + + } + + private void sendMessage(List deptIds, Integer date) { + for (Long deptId : deptIds) { + BusinessMessageDTO message = new BusinessMessageDTO(); + message.setBusinessClassify("business"); + message.setBusinessKey(MessageConstants.BusinessClassifyEnum.OPERATIONDEFECTMESSAGE.getKey()); + message.setSubject(MessageConstants.BusinessClassifyEnum.OPERATIONDEFECTMESSAGE.getDescription()); + message.setTaskId(System.currentTimeMillis()); + message.setTenantId("200000"); + String countent = + date + "天后,排班计划到期,请及时更新排班计划,以免影响正常工作"; + message.setContent(countent); + message.setDeptId(deptId); + R deptName = sysClient.getDeptName(deptId); + if (deptName.isSuccess()) { + message.setDeptName(deptName.getData()); + } + //通知项目经理这个角色 + List userListByRoleAlias = userClient.relationUserListByRoleAlias("200000", deptId, PROJECT_MANAGER).getData(); + List userList = userListByRoleAlias.stream().map(s -> s.getId().toString()).collect(Collectors.toList()); + String userIds = String.join(",", userList); + if (StringUtils.isBlank(userIds)) { + log.error("推送的消息不能为空哦,{}", userIds); + throw new ServiceException("推送的消息不能为空"); + } + message.setCreateUser(Long.valueOf(userList.get(0))); + messageClient.sendAppAndWsMsgByUsers(message); + } + } + + +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyServiceImpl.java index 0a2983c..5566c77 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyServiceImpl.java @@ -20,6 +20,7 @@ import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -187,4 +188,17 @@ public class DutyServiceImpl extends BaseServiceImpl getDeptByMainDate(String date) { + List entity = this.baseMapper.selectList(new LambdaQueryWrapper() {{ + like(ImsDutyMainEntity::getDutyDate, date); + groupBy(ImsDutyMainEntity::getCreateDept); + }}); + if(ObjectUtil.isEmpty(entity)){ + return new ArrayList<>(); + } + List deptId = entity.stream().map(ImsDutyMainEntity::getCreateDept).collect(Collectors.toList()); + return deptId; + } } \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java index d7ed996..ff1631a 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java @@ -517,6 +517,8 @@ public class ImsDutyRecServiceImpl extends BaseServiceImpl