1.
luofl
2025-02-28 ac8935ad12f67f78a74a3bd2bfaf810546a7461f
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
package com.panzhihua.sangeshenbian.scheduled;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.service.sangeshenbian.SystemUserService;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.utlis.DateUtils;
import com.panzhihua.sangeshenbian.dao.ComplaintAuditRecordMapper;
import com.panzhihua.sangeshenbian.model.dto.ComplaintTimeout;
import com.panzhihua.sangeshenbian.model.entity.Complaint;
import com.panzhihua.sangeshenbian.model.entity.MessageNotification;
import com.panzhihua.sangeshenbian.model.entity.SystemUser;
import com.panzhihua.sangeshenbian.model.entity.WorkOrderItemConfig;
import com.panzhihua.sangeshenbian.service.*;
import com.panzhihua.sangeshenbian.utils.AliSmsUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
import java.util.stream.Collectors;
 
@Component
@RequiredArgsConstructor
@Slf4j
public class ComplaintTasks {
    private final IComplaintService complaintService;
    private final ComplaintAuditRecordMapper complaintAuditRecordMapper;
    private final IWorkOrderItemConfigService workOrderItemConfigService;
    private final ISystemUserService systemUserService;;
    private final UserService userService;
    private final IMessageNotificationService messageNotificationService;
 
    /**
     * 诉求超时处理(每天凌晨两点执行)
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void complaintTimeout() {
 
        WorkOrderItemConfig config = workOrderItemConfigService.getById(1);
        Integer demandProcessingTime = config.getDemandProcessingTime();
 
        // 超时未处理短信发送及告会上一级督办
        timeOutHandle(config,demandProcessingTime);
 
        // 临期提醒
        reminderHandle(config, demandProcessingTime);
 
        // 诉求超时提醒
        List<Complaint> complaintList = complaintService.list(new LambdaQueryWrapper<Complaint>()
                .le(Complaint::getClosingTime, new Date())
                .eq(Complaint::getStatus, 0));
        List<MessageNotification> messageNotificationList = new ArrayList<>();
        complaintList.forEach(complaint -> {
            complaint.setStatus(2);
            complaint.setCompletionTime(new Date());
 
 
            // 代办信息
            R<LoginUserInfoVO> uR = userService.getUserInfoByUserId(String.valueOf(complaint.getCreateBy()));
            if (!R.isOk(uR)){
                log.error("未查询到用户信息");
            }
            LoginUserInfoVO data = uR.getData();
            MessageNotification messageNotification = new MessageNotification();
            messageNotification.setTitle(complaint.getDescriptionTitle());
            messageNotification.setUndertakerUserId(String.valueOf(complaint.getSuperiorId()));
            messageNotification.setUndertakerType(1);
            messageNotification.setPhone(data.getPhone());
            messageNotification.setResponseTime(complaint.getClosingTime());
            messageNotification.setPromptType(1);
            messageNotification.setReadStatus(0);
            messageNotification.setCreateTime(new Date());
            messageNotificationList.add(messageNotification);
        });
        complaintService.updateBatchById(complaintList);
        messageNotificationService.saveBatch(messageNotificationList);
    }
 
    // 诉求超时处理
    private void timeOutHandle(WorkOrderItemConfig config,Integer demandProcessingTime) {
 
        List<ComplaintTimeout> complaintTimeoutList = complaintAuditRecordMapper.getComplaintTimeout(
                config.getCityHandlingTime() + demandProcessingTime,
                config.getDistrictHandlingTime() + demandProcessingTime,
                config.getStreetHandlingTime() + demandProcessingTime,
                config.getCommunityHandlingTime() + demandProcessingTime,
                config.getPartyMemberHandlingTime() + demandProcessingTime);
 
 
 
        Map<Integer, List<ComplaintTimeout>> timeOutMap = complaintTimeoutList.stream()
                .collect(Collectors.groupingBy(ComplaintTimeout::getReportType));
 
        // 市超时
        List<ComplaintTimeout> cityTimeOutList = timeOutMap.get(1);
        if (!CollectionUtils.isEmpty(cityTimeOutList)){
 
            List<SystemUser> cityUserList = systemUserService.list(new LambdaQueryWrapper<SystemUser>()
                    .eq(SystemUser::getAccountLevel, 1)
                    .eq(SystemUser::getStatus, 1));
            List<String> cityPhoneList = cityUserList.stream().map(SystemUser::getPhone).collect(Collectors.toList());
 
            cityTimeOutList.forEach(complaintTimeout -> {
                // 发送短信
                AliSmsUtil.sendTimeoutMessage(cityPhoneList,complaintTimeout.getTitle());
            });
        }
 
        // 区县超时
        List<ComplaintTimeout> districtTimeOutList = timeOutMap.get(2);
        if (!CollectionUtils.isEmpty(districtTimeOutList)){
            districtTimeOutList.forEach(complaintTimeout -> {
 
                List<SystemUser> districtUserList = systemUserService.list(new LambdaQueryWrapper<SystemUser>()
                        .eq(SystemUser::getAccountLevel, 2)
                        .eq(SystemUser::getDistrictsCode, complaintTimeout.getSuperiorId())
                        .eq(SystemUser::getStatus, 1));
                List<String> districtPhoneList = districtUserList.stream().map(SystemUser::getPhone).collect(Collectors.toList());
 
                // 发送短信
                AliSmsUtil.sendTimeoutMessage(districtPhoneList,complaintTimeout.getTitle());
            });
        }
 
        // 街道超时
        List<ComplaintTimeout> streetTimeOutList = timeOutMap.get(3);
        if (!CollectionUtils.isEmpty(streetTimeOutList)){
            streetTimeOutList.forEach(complaintTimeout -> {
                List<SystemUser> streetUserList = systemUserService.list(new LambdaQueryWrapper<SystemUser>()
                        .eq(SystemUser::getAccountLevel, 3)
                        .eq(SystemUser::getStreetId, complaintTimeout.getSuperiorId())
                        .eq(SystemUser::getStatus, 1));
                List<String> streetPhoneList = streetUserList.stream().map(SystemUser::getPhone).collect(Collectors.toList());
 
 
                // 发送短信
                AliSmsUtil.sendTimeoutMessage(streetPhoneList,complaintTimeout.getTitle());
            });
        }
 
        // 社区超时
        List<ComplaintTimeout> communityTimeOutList = timeOutMap.get(4);
        if (!CollectionUtils.isEmpty(communityTimeOutList)){
            communityTimeOutList.forEach(complaintTimeout -> {
                List<SystemUser> communityUserList = systemUserService.list(new LambdaQueryWrapper<SystemUser>()
                        .eq(SystemUser::getAccountLevel, 4)
                        .eq(SystemUser::getCommunityId, complaintTimeout.getSuperiorId())
                        .eq(SystemUser::getStatus, 1));
                List<String> communityPhoneList = communityUserList.stream().map(SystemUser::getPhone).collect(Collectors.toList());
 
                // 发送短信
                AliSmsUtil.sendTimeoutMessage(communityPhoneList,complaintTimeout.getTitle());
            });
        }
 
        // 党员超时
        List<ComplaintTimeout> partyMemberTimeOutList = timeOutMap.get(5);
        if (!CollectionUtils.isEmpty(partyMemberTimeOutList)){
            partyMemberTimeOutList.forEach(complaintTimeout -> {
                R<LoginUserInfoVO> uR = userService.getUserInfoByUserId(String.valueOf(complaintTimeout.getCreateBy()));
                if (!R.isOk(uR)){
                    throw new ServiceException("获取用户信息失败");
                }
                LoginUserInfoVO data = uR.getData();
                AliSmsUtil.sendTimeoutMessage(Collections.singletonList(data.getPhone()),complaintTimeout.getTitle());
            });
        }
    }
 
    // 临期提醒
    private void reminderHandle(WorkOrderItemConfig config,Integer demandProcessingTime) {
 
        List<ComplaintTimeout> complaintTimeoutList = complaintAuditRecordMapper.getComplaintTimeout(
                demandProcessingTime - config.getCityDeadlineReminder(),
                demandProcessingTime - config.getDistrictDeadlineReminder(),
                demandProcessingTime - config.getStreetDeadlineReminder(),
                demandProcessingTime - config.getCommunityDeadlineReminder(),
                demandProcessingTime - config.getPartyMemberDeadlineReminder());
 
 
        Map<Integer, List<ComplaintTimeout>> timeOutMap = complaintTimeoutList.stream()
                .collect(Collectors.groupingBy(ComplaintTimeout::getReportType));
 
        // 市超时
        List<ComplaintTimeout> cityTimeOutList = timeOutMap.get(1);
        if (!CollectionUtils.isEmpty(cityTimeOutList)){
 
            List<SystemUser> cityUserList = systemUserService.list(new LambdaQueryWrapper<SystemUser>()
                    .eq(SystemUser::getAccountLevel, 1)
                    .eq(SystemUser::getStatus, 1));
            List<String> cityPhoneList = cityUserList.stream().map(SystemUser::getPhone).collect(Collectors.toList());
 
            cityTimeOutList.forEach(complaintTimeout -> {
                // 发送短信
                Date closingTime = complaintTimeout.getClosingTime();
                int daysRemaining = DateUtils.retrieveRemainingDays(closingTime);
                AliSmsUtil.sendExpireMessage(cityPhoneList,complaintTimeout.getTitle(),closingTime, daysRemaining);
                // 代办信息
                List<MessageNotification> messageNotificationList = new ArrayList<>();
                for (String phone : cityPhoneList) {
                    MessageNotification messageNotification = new MessageNotification();
                    messageNotification.setTitle(complaintTimeout.getTitle());
                    messageNotification.setUndertakerUserId(String.valueOf(complaintTimeout.getSuperiorId()));
                    messageNotification.setUndertakerType(1);
                    messageNotification.setPhone(phone);
                    messageNotification.setResponseTime(complaintTimeout.getClosingTime());
                    messageNotification.setPromptType(1);
                    messageNotification.setReadStatus(0);
                    messageNotification.setCreateTime(new Date());
                }
                messageNotificationService.saveBatch(messageNotificationList);
 
            });
        }
 
        // 区县超时
        List<ComplaintTimeout> districtTimeOutList = timeOutMap.get(2);
        if (!CollectionUtils.isEmpty(districtTimeOutList)){
            districtTimeOutList.forEach(complaintTimeout -> {
 
                List<SystemUser> districtUserList = systemUserService.list(new LambdaQueryWrapper<SystemUser>()
                        .eq(SystemUser::getAccountLevel, 2)
                        .eq(SystemUser::getDistrictsCode, complaintTimeout.getSuperiorId())
                        .eq(SystemUser::getStatus, 1));
                List<String> districtPhoneList = districtUserList.stream().map(SystemUser::getPhone).collect(Collectors.toList());
 
                // 发送短信
                Date closingTime = complaintTimeout.getClosingTime();
                int daysRemaining = DateUtils.retrieveRemainingDays(closingTime);
                AliSmsUtil.sendExpireMessage(districtPhoneList,complaintTimeout.getTitle(),closingTime, daysRemaining);
 
 
                // 代办信息
                List<MessageNotification> messageNotificationList = new ArrayList<>();
                for (String phone : districtPhoneList) {
                    MessageNotification messageNotification = new MessageNotification();
                    messageNotification.setTitle(complaintTimeout.getTitle());
                    messageNotification.setUndertakerUserId(String.valueOf(complaintTimeout.getSuperiorId()));
                    messageNotification.setUndertakerType(1);
                    messageNotification.setPhone(phone);
                    messageNotification.setResponseTime(complaintTimeout.getClosingTime());
                    messageNotification.setPromptType(1);
                    messageNotification.setReadStatus(0);
                    messageNotification.setCreateTime(new Date());
                }
                messageNotificationService.saveBatch(messageNotificationList);
            });
        }
 
        // 街道超时
        List<ComplaintTimeout> streetTimeOutList = timeOutMap.get(3);
        if (!CollectionUtils.isEmpty(streetTimeOutList)){
            streetTimeOutList.forEach(complaintTimeout -> {
                List<SystemUser> streetUserList = systemUserService.list(new LambdaQueryWrapper<SystemUser>()
                        .eq(SystemUser::getAccountLevel, 3)
                        .eq(SystemUser::getStreetId, complaintTimeout.getSuperiorId())
                        .eq(SystemUser::getStatus, 1));
                List<String> streetPhoneList = streetUserList.stream().map(SystemUser::getPhone).collect(Collectors.toList());
 
                // 发送短信
                Date closingTime = complaintTimeout.getClosingTime();
                int daysRemaining = DateUtils.retrieveRemainingDays(closingTime);
                AliSmsUtil.sendExpireMessage(streetPhoneList,complaintTimeout.getTitle(),closingTime, daysRemaining);
 
                // 代办信息
                List<MessageNotification> messageNotificationList = new ArrayList<>();
                for (String phone : streetPhoneList) {
                    MessageNotification messageNotification = new MessageNotification();
                    messageNotification.setTitle(complaintTimeout.getTitle());
                    messageNotification.setUndertakerUserId(String.valueOf(complaintTimeout.getSuperiorId()));
                    messageNotification.setUndertakerType(1);
                    messageNotification.setPhone(phone);
                    messageNotification.setResponseTime(complaintTimeout.getClosingTime());
                    messageNotification.setPromptType(1);
                    messageNotification.setReadStatus(0);
                    messageNotification.setCreateTime(new Date());
                }
                messageNotificationService.saveBatch(messageNotificationList);
            });
        }
 
        // 社区超时
        List<ComplaintTimeout> communityTimeOutList = timeOutMap.get(4);
        if (!CollectionUtils.isEmpty(communityTimeOutList)){
            communityTimeOutList.forEach(complaintTimeout -> {
                List<SystemUser> communityUserList = systemUserService.list(new LambdaQueryWrapper<SystemUser>()
                        .eq(SystemUser::getAccountLevel, 4)
                        .eq(SystemUser::getCommunityId, complaintTimeout.getSuperiorId())
                        .eq(SystemUser::getStatus, 1));
                List<String> communityPhoneList = communityUserList.stream().map(SystemUser::getPhone).collect(Collectors.toList());
 
                // 发送短信
                Date closingTime = complaintTimeout.getClosingTime();
                int daysRemaining = DateUtils.retrieveRemainingDays(closingTime);
                AliSmsUtil.sendExpireMessage(communityPhoneList,complaintTimeout.getTitle(),closingTime, daysRemaining);
 
                // 代办信息
                List<MessageNotification> messageNotificationList = new ArrayList<>();
                for (String phone : communityPhoneList) {
                    MessageNotification messageNotification = new MessageNotification();
                    messageNotification.setTitle(complaintTimeout.getTitle());
                    messageNotification.setUndertakerUserId(String.valueOf(complaintTimeout.getSuperiorId()));
                    messageNotification.setUndertakerType(1);
                    messageNotification.setPhone(phone);
                    messageNotification.setResponseTime(complaintTimeout.getClosingTime());
                    messageNotification.setPromptType(1);
                    messageNotification.setReadStatus(0);
                    messageNotification.setCreateTime(new Date());
                }
                messageNotificationService.saveBatch(messageNotificationList);
            });
        }
 
        // 党员超时
        List<ComplaintTimeout> partyMemberTimeOutList = timeOutMap.get(5);
        if (!CollectionUtils.isEmpty(partyMemberTimeOutList)){
            partyMemberTimeOutList.forEach(complaintTimeout -> {
                R<LoginUserInfoVO> uR = userService.getUserInfoByUserId(String.valueOf(complaintTimeout.getCreateBy()));
                if (!R.isOk(uR)){
                    throw new ServiceException("获取用户信息失败");
                }
                LoginUserInfoVO data = uR.getData();
                // 发送短信
                Date closingTime = complaintTimeout.getClosingTime();
                int daysRemaining = DateUtils.retrieveRemainingDays(closingTime);
                AliSmsUtil.sendExpireMessage(Collections.singletonList(data.getPhone()),complaintTimeout.getTitle(),closingTime, daysRemaining);
 
                // 代办信息
                MessageNotification messageNotification = new MessageNotification();
                messageNotification.setTitle(complaintTimeout.getTitle());
                messageNotification.setUndertakerUserId(String.valueOf(complaintTimeout.getSuperiorId()));
                messageNotification.setUndertakerType(1);
                messageNotification.setPhone(data.getPhone());
                messageNotification.setResponseTime(complaintTimeout.getClosingTime());
                messageNotification.setPromptType(1);
                messageNotification.setReadStatus(0);
                messageNotification.setCreateTime(new Date());
                messageNotificationService.save(messageNotification);
            });
        }
    }
}