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());
|
});
|
}
|
|
}
|
|
}
|