yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
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;
    }
}