liujie
2025-06-10 f6222774733db5783c8a06fe933174779c7c58b9
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
package com.panzhihua.westcommittee.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.user.UserService;
import com.panzhihua.common.utlis.DateUtils;
import com.panzhihua.westcommittee.dao.ComplaintAuditRecordMapper;
import com.panzhihua.westcommittee.model.dto.ComplaintTimeout;
import com.panzhihua.westcommittee.model.entity.*;
import com.panzhihua.westcommittee.service.*;
import com.panzhihua.westcommittee.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;
    private final IComplaintCommentService complaintCommentService;
 
    /**
     * 诉求超时处理(每天凌晨两点执行)
     */
//    @Scheduled(cron = "0 0 2 * * ?")
    public void complaintTimeout() {
 
        WorkOrderItemConfig config = workOrderItemConfigService.getById(1);
 
        // 超时未处理短信发送及告会上一级督办
        timeOutHandle(config);
 
//        // 诉求超时提醒
//        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);
    }
    
    
    /**
     * 自动完成诉求评价
     */
//    @Scheduled(cron = "0 1 0 * * ?")
    public void automaticEvaluation() {
        // 诉求超时提醒
        List<Complaint> complaintList = complaintService.getTimeoutAndNotComment();
        for (Complaint complaint : complaintList) {
            ComplaintComment complaintComment = new ComplaintComment();
            complaintComment.setComplaintId(complaint.getId());
            complaintComment.setRate(2);
            complaintComment.setContent("满意");
            complaintComment.setDelFlag(0);
            complaintCommentService.save(complaintComment);
            complaint.setCommentRate(2);
            complaintService.updateById(complaint);
        }
    }
    
 
    // 诉求超时处理
    private void timeOutHandle(WorkOrderItemConfig config) {
 
        List<ComplaintTimeout> complaintTimeoutList = complaintAuditRecordMapper.getComplaintTimeout(
                config.getDistrictHandlingTime() ,
                config.getStreetHandlingTime(),
                config.getCommunityHandlingTime()
              );
 
 
        Map<Integer, List<ComplaintTimeout>> timeOutMap = complaintTimeoutList.stream()
                .collect(Collectors.groupingBy(ComplaintTimeout::getNowLevel));
 
        // 区县超时
        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)
                        .in(SystemUser::getSystemRoleId,1,2)
                        .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)
                        .in(SystemUser::getSystemRoleId,1,2)
                        .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)
                        .in(SystemUser::getSystemRoleId,1,2)
                        .eq(SystemUser::getStatus, 1));
                List<String> communityPhoneList = communityUserList.stream().map(SystemUser::getPhone).collect(Collectors.toList());
 
                // 发送短信
                AliSmsUtil.sendTimeoutMessage(communityPhoneList,complaintTimeout.getTitle());
            });
        }
 
    }
 
}