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<String> maintainOverdueJobHandler(String param) {
|
XxlJobLogger.log("定时发送开始,:{}", new Object[]{param});
|
LocalDateTime now = LocalDateTime.now();
|
BusinessSend businessSend = this.businessSendFactory.getBusinessSend(NotifyConstant.MAINTAIN_OVERDUE);
|
List<BusinessNotifyState> businessNotifyStates = this.businessNotifyStateService.listByBusinessKey(NotifyConstant.MAINTAIN_OVERDUE);
|
Map<Long, List<BusinessNotifyState>> mapByBusinessId = businessNotifyStates.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getBusinessId();
|
}));
|
Set<Long> businessIds = mapByBusinessId.keySet();
|
if (Func.isEmpty(businessIds)) {
|
return ReturnT.SUCCESS;
|
}
|
List<Long> expireIds = deleteExpireState(businessIds);
|
expireIds.forEach(businessIds::remove);
|
/*
|
businessIds.getClass();
|
expireIds.forEach((v1) -> {
|
r1.remove(v1);
|
});*/
|
List<MaintainPlan> list = this.maintainPlanService.list(Wrappers.<MaintainPlan>lambdaQuery()
|
.lt(true, MaintainPlan::getMaintainDate, now)
|
.in(MaintainPlan::getPlanStatus, Lists.list(new Integer[] {MaintainPlanStatusEnum.T1.getType(), MaintainPlanStatusEnum.T2.getType() } )).in(MaintainPlan::getId, businessIds));
|
/*
|
List<MaintainPlan> 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<BusinessNotifyState> states = mapByBusinessId.get(id);
|
List<Long> empIds = states.stream().filter(item -> {
|
return Func.equals(item.getPersonType(), Integer.valueOf(ObjectTypeEnum.EMP.getCode()));
|
}).map((v0) -> {
|
return v0.getPersonId();
|
}).collect(Collectors.toList());
|
List<Long> empIds2 = empIds.stream().distinct().collect(Collectors.toList());
|
List<Long> 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<Long> deleteExpireState(Set<Long> businessIds) {
|
if (Func.isEmpty(businessIds)) {
|
return new ArrayList<>();
|
}
|
List<MaintainPlan> deleteStatePlans = this.maintainPlanService.list(Wrappers.<MaintainPlan>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<MaintainPlan> 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<Long> waitDeleteBusinessIds = deleteStatePlans.stream().map(MaintainPlan::getId).collect(Collectors.toList());
|
/*
|
List<Long> waitDeleteBusinessIds = (List) deleteStatePlans.stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList());*/
|
|
this.businessNotifyStateService.remove(Wrappers.<BusinessNotifyState>lambdaQuery().in(BusinessNotifyState::getBusinessId, waitDeleteBusinessIds));
|
/*
|
this.businessNotifyStateService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getBusinessId();
|
}, waitDeleteBusinessIds));*/
|
return waitDeleteBusinessIds;
|
}
|
|
@XxlJob("maintenance-warningJobHandler")
|
public ReturnT<String> maintenanceWarningJobHandler(String param) {
|
XxlJobLogger.log("定时发送开始,:{}", new Object[]{param});
|
List<MaintainPlan> waitSends = new ArrayList<>();
|
LocalDateTime now = LocalDateTime.now();
|
BusinessSend businessSend = this.businessSendFactory.getBusinessSend(NotifyConstant.MAINTENANCE_WARNING);
|
List<BusinessNotifyState> businessNotifyStates = this.businessNotifyStateService.listByBusinessKey(NotifyConstant.MAINTENANCE_WARNING);
|
Map<Long, List<BusinessNotifyState>> businessStateMap = businessNotifyStates.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getBusinessId();
|
}));
|
Set<Long> businessIds = businessStateMap.keySet();
|
if (Func.isEmpty(businessIds)) {
|
return ReturnT.SUCCESS;
|
}
|
List<Long> expireIds = deleteExpireState(businessIds);
|
expireIds.forEach(businessIds::remove);
|
/*
|
businessIds.getClass();
|
expireIds.forEach((v1) -> {
|
r1.remove(v1);
|
});*/
|
List<MaintainPlan> list = this.maintainPlanService.list(Wrappers.<MaintainPlan>lambdaQuery()
|
.in(MaintainPlan::getPlanStatus, Lists.list(new Integer[] {MaintainPlanStatusEnum.T1.getType(), MaintainPlanStatusEnum.T2.getType() }))
|
.in(MaintainPlan::getId, businessIds));
|
/*
|
List<MaintainPlan> 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<Integer, List<MaintainPlan>> 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<MaintainPlan> maintainPlans = planMap.get(Integer.valueOf(MaintainGenerateEnum.T1.getType()));
|
List<Long> projectIds = maintainPlans.stream().map((v0) -> {
|
return v0.getProjectId();
|
}).filter((v0) -> {
|
return Func.isNotEmpty(v0);
|
}).collect(Collectors.toList());
|
List<MaintainProject> maintainProjects = this.maintainProjectService.listByIds(projectIds);
|
Map<Long, MaintainProject> 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<BusinessNotifyState> states = businessStateMap.get(id);
|
List<Long> empIds = states.stream().filter(item2 -> {
|
return Func.equals(item2.getPersonType(), Integer.valueOf(ObjectTypeEnum.EMP.getCode()));
|
}).map((v0) -> {
|
return v0.getPersonId();
|
}).collect(Collectors.toList());
|
List<Long> 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;
|
}
|
}
|