package com.qianwen.smartman.modules.notify.jobHandler; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import org.assertj.core.util.Lists; import org.springframework.stereotype.Component; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.common.constant.NotifyConstant; import com.qianwen.smartman.modules.cps.entity.MaintainProject; import com.qianwen.smartman.modules.cps.service.IMaintainProjectService; import com.qianwen.smartman.modules.notify.business.BusinessSend; import com.qianwen.smartman.modules.notify.business.BusinessSendFactory; import com.qianwen.smartman.modules.notify.dto.NotifyBusinessSendDTO; import com.qianwen.smartman.modules.notify.entity.BusinessNotifyState; import com.qianwen.smartman.modules.notify.enums.ObjectTypeEnum; import com.qianwen.smartman.modules.notify.service.IBusinessNotifyStateService; import com.qianwen.smartman.modules.tpm.entity.MaintainPlan; import com.qianwen.smartman.modules.tpm.enums.MaintainGenerateEnum; import com.qianwen.smartman.modules.tpm.enums.MaintainPlanStatusEnum; import com.qianwen.smartman.modules.tpm.service.IMaintainPlanService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; @Component /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/jobHandler/BusinessNotifyJob.class */ public class BusinessNotifyJob { private final IMaintainPlanService maintainPlanService; private final BusinessSendFactory businessSendFactory; private final IBusinessNotifyStateService businessNotifyStateService; private final IMaintainProjectService maintainProjectService; public BusinessNotifyJob(final IMaintainPlanService maintainPlanService, final BusinessSendFactory businessSendFactory, final IBusinessNotifyStateService businessNotifyStateService, final IMaintainProjectService maintainProjectService) { this.maintainPlanService = maintainPlanService; this.businessSendFactory = businessSendFactory; this.businessNotifyStateService = businessNotifyStateService; this.maintainProjectService = maintainProjectService; } @XxlJob("maintain-overdueJobHandler") public ReturnT maintainOverdueJobHandler(String param) { XxlJobLogger.log("定时发送开始,:{}", new Object[]{param}); LocalDateTime now = LocalDateTime.now(); BusinessSend businessSend = this.businessSendFactory.getBusinessSend(NotifyConstant.MAINTAIN_OVERDUE); List businessNotifyStates = this.businessNotifyStateService.listByBusinessKey(NotifyConstant.MAINTAIN_OVERDUE); Map> mapByBusinessId = businessNotifyStates.stream().collect(Collectors.groupingBy((v0) -> { return v0.getBusinessId(); })); Set businessIds = mapByBusinessId.keySet(); if (Func.isEmpty(businessIds)) { return ReturnT.SUCCESS; } List expireIds = deleteExpireState(businessIds); expireIds.forEach(businessIds::remove); /* businessIds.getClass(); expireIds.forEach((v1) -> { r1.remove(v1); });*/ List list = this.maintainPlanService.list(Wrappers.lambdaQuery() .lt(true, MaintainPlan::getMaintainDate, now) .in(MaintainPlan::getPlanStatus, Lists.list(new Integer[] {MaintainPlanStatusEnum.T1.getType(), MaintainPlanStatusEnum.T2.getType() } )).in(MaintainPlan::getId, businessIds)); /* List list = this.maintainPlanService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().lt(true, (v0) -> { return v0.getMaintainDate(); }, now).in((v0) -> { return v0.getPlanStatus(); }, Lists.list(new Integer[]{Integer.valueOf(MaintainPlanStatusEnum.T1.getType()), Integer.valueOf(MaintainPlanStatusEnum.T2.getType())}))).in((v0) -> { return v0.getId(); }, businessIds));*/ if (Func.isEmpty(list)) { return ReturnT.SUCCESS; } for (MaintainPlan maintainPlan : list) { Long id = maintainPlan.getId(); List states = mapByBusinessId.get(id); List empIds = states.stream().filter(item -> { return Func.equals(item.getPersonType(), Integer.valueOf(ObjectTypeEnum.EMP.getCode())); }).map((v0) -> { return v0.getPersonId(); }).collect(Collectors.toList()); List empIds2 = empIds.stream().distinct().collect(Collectors.toList()); List orgIds = states.stream().filter(item2 -> { return Func.equals(item2.getPersonType(), Integer.valueOf(ObjectTypeEnum.ORG.getCode())); }).map((v0) -> { return v0.getPersonId(); }).collect(Collectors.toList()); businessSend.sendMessage(maintainPlan, NotifyBusinessSendDTO.builder().empIds(empIds2).orgIds(orgIds.stream().distinct().collect(Collectors.toList())).build()); } XxlJobLogger.log("定时发送成功,:{}", new Object[]{now}); return ReturnT.SUCCESS; } private List deleteExpireState(Set businessIds) { if (Func.isEmpty(businessIds)) { return new ArrayList<>(); } List deleteStatePlans = this.maintainPlanService.list(Wrappers.lambdaQuery() .select( MaintainPlan::getId).in(MaintainPlan::getPlanStatus, Lists.list(new Integer[] { Integer.valueOf(MaintainPlanStatusEnum.T3.getType()),MaintainPlanStatusEnum.T4.getType(), MaintainPlanStatusEnum.T5.getType() })) .in(MaintainPlan::getId, businessIds)); /* List deleteStatePlans = this.maintainPlanService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().select(new SFunction[]{(v0) -> { return v0.getId(); }}).in((v0) -> { return v0.getPlanStatus(); }, Lists.list(new Integer[]{Integer.valueOf(MaintainPlanStatusEnum.T3.getType()), Integer.valueOf(MaintainPlanStatusEnum.T4.getType()), Integer.valueOf(MaintainPlanStatusEnum.T5.getType())}))).in((v0) -> { return v0.getId(); }, businessIds));*/ if (Func.isEmpty(deleteStatePlans)) { return new ArrayList<>(); } List waitDeleteBusinessIds = deleteStatePlans.stream().map(MaintainPlan::getId).collect(Collectors.toList()); /* List waitDeleteBusinessIds = (List) deleteStatePlans.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList());*/ this.businessNotifyStateService.remove(Wrappers.lambdaQuery().in(BusinessNotifyState::getBusinessId, waitDeleteBusinessIds)); /* this.businessNotifyStateService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> { return v0.getBusinessId(); }, waitDeleteBusinessIds));*/ return waitDeleteBusinessIds; } @XxlJob("maintenance-warningJobHandler") public ReturnT maintenanceWarningJobHandler(String param) { XxlJobLogger.log("定时发送开始,:{}", new Object[]{param}); List waitSends = new ArrayList<>(); LocalDateTime now = LocalDateTime.now(); BusinessSend businessSend = this.businessSendFactory.getBusinessSend(NotifyConstant.MAINTENANCE_WARNING); List businessNotifyStates = this.businessNotifyStateService.listByBusinessKey(NotifyConstant.MAINTENANCE_WARNING); Map> businessStateMap = businessNotifyStates.stream().collect(Collectors.groupingBy((v0) -> { return v0.getBusinessId(); })); Set businessIds = businessStateMap.keySet(); if (Func.isEmpty(businessIds)) { return ReturnT.SUCCESS; } List expireIds = deleteExpireState(businessIds); expireIds.forEach(businessIds::remove); /* businessIds.getClass(); expireIds.forEach((v1) -> { r1.remove(v1); });*/ List list = this.maintainPlanService.list(Wrappers.lambdaQuery() .in(MaintainPlan::getPlanStatus, Lists.list(new Integer[] {MaintainPlanStatusEnum.T1.getType(), MaintainPlanStatusEnum.T2.getType() })) .in(MaintainPlan::getId, businessIds)); /* List list = this.maintainPlanService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> { return v0.getPlanStatus(); }, Lists.list(new Integer[]{Integer.valueOf(MaintainPlanStatusEnum.T1.getType()), Integer.valueOf(MaintainPlanStatusEnum.T2.getType())}))).in((v0) -> { return v0.getId(); }, businessIds));*/ if (Func.isEmpty(list)) { return ReturnT.SUCCESS; } Map> planMap =list.stream().collect(Collectors.groupingBy((v0) -> { return v0.getIsAuto(); })); if (planMap.containsKey(Integer.valueOf(MaintainGenerateEnum.T0.getType()))) { for (MaintainPlan plan : planMap.get(Integer.valueOf(MaintainGenerateEnum.T0.getType()))) { Integer preWarningDays = plan.getPreWarningDays(); LocalDateTime maintainDate = plan.getMaintainDate(); LocalDateTime start = maintainDate.plusDays(-preWarningDays.intValue()); if (now.isAfter(start) && now.isBefore(maintainDate)) { waitSends.add(plan); } } } if (planMap.containsKey(Integer.valueOf(MaintainGenerateEnum.T1.getType()))) { List maintainPlans = planMap.get(Integer.valueOf(MaintainGenerateEnum.T1.getType())); List projectIds = maintainPlans.stream().map((v0) -> { return v0.getProjectId(); }).filter((v0) -> { return Func.isNotEmpty(v0); }).collect(Collectors.toList()); List maintainProjects = this.maintainProjectService.listByIds(projectIds); Map projectMap = maintainProjects.stream().collect(Collectors.toMap((v0) -> { return v0.getId(); }, item -> { return item; })); for (MaintainPlan plan2 : maintainPlans) { Long projectId = plan2.getProjectId(); if (projectId != null && projectMap.containsKey(projectId)) { MaintainProject maintainProject = projectMap.get(plan2.getProjectId()); Integer preWarningDays2 = maintainProject.getPreWarningDays(); LocalDateTime maintainDate2 = plan2.getMaintainDate(); LocalDateTime start2 = maintainDate2.plusDays(-preWarningDays2.intValue()); if (now.isAfter(start2) && now.isBefore(maintainDate2)) { waitSends.add(plan2); } } } } for (MaintainPlan maintainPlan : waitSends) { Long id = maintainPlan.getId(); List states = businessStateMap.get(id); List empIds = states.stream().filter(item2 -> { return Func.equals(item2.getPersonType(), Integer.valueOf(ObjectTypeEnum.EMP.getCode())); }).map((v0) -> { return v0.getPersonId(); }).collect(Collectors.toList()); List orgIds = states.stream().filter(item3 -> { return Func.equals(item3.getPersonType(), Integer.valueOf(ObjectTypeEnum.ORG.getCode())); }).map((v0) -> { return v0.getPersonId(); }).collect(Collectors.toList()); businessSend.sendMessage(maintainPlan, NotifyBusinessSendDTO.builder().empIds(empIds).orgIds(orgIds).build()); } XxlJobLogger.log("定时发送成功,:{}", new Object[]{now}); return ReturnT.SUCCESS; } }