From 5ec41335471a9f1ad9a851cd70e27936325bae7f Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期四, 22 五月 2025 20:04:24 +0800
Subject: [PATCH] 修改bug
---
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/scheduled/ComplaintTasks.java | 385 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 365 insertions(+), 20 deletions(-)
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/scheduled/ComplaintTasks.java b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/scheduled/ComplaintTasks.java
index f89948b..3f6abaa 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/scheduled/ComplaintTasks.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/scheduled/ComplaintTasks.java
@@ -1,20 +1,365 @@
-//package com.panzhihua.sangeshenbian.scheduled;
-//
-//import com.panzhihua.sangeshenbian.service.IComplaintService;
-//import lombok.RequiredArgsConstructor;
-//import org.springframework.scheduling.annotation.Scheduled;
-//import org.springframework.stereotype.Component;
-//
-//@Component
-//@RequiredArgsConstructor
-//public class ComplaintTasks {
-// private final IComplaintService complaintService;
-//
-// /**
-// * 诉求超时处理
-// */
-// @Scheduled(fixedRate = 60000)
-// public void complaintTimeout() {
-// complaintService.list();
-// }
-//}
+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.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.*;
+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;
+ private final IComplaintCommentService complaintCommentService;
+
+ /**
+ * 诉求超时处理(每天凌晨两点执行)
+ */
+ @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);
+ }
+
+
+ /**
+ * 自动完成诉求评价
+ */
+ @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,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);
+ });
+ }
+ }
+}
--
Gitblit v1.7.1