package com.panzhihua.westcommittee.scheduled;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
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 IDepartmentService departmentService;
|
private final IComplaintCommentService complaintCommentService;
|
|
/**
|
* 诉求超时处理(每天凌晨两点执行)
|
*/
|
@Scheduled(fixedRate = 600000)
|
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()
|
);
|
|
if(!complaintTimeoutList.isEmpty()) {
|
// 当前不在发送
|
complaintService.update(new LambdaUpdateWrapper<Complaint>().in(Complaint::getId, complaintTimeoutList.stream().map(ComplaintTimeout::getComplaintId).collect(Collectors.toList())).set(Complaint::getNowLevelSms, 1));
|
|
}
|
|
Map<Integer, List<ComplaintTimeout>> timeOutMap = complaintTimeoutList.stream()
|
.collect(Collectors.groupingBy(ComplaintTimeout::getNowLevel));
|
|
// 区县超时
|
List<ComplaintTimeout> districtTimeOutList = timeOutMap.get(2);
|
if (!CollectionUtils.isEmpty(districtTimeOutList)){
|
// 没有分配的 需要发给层级管理员和纪委
|
List<ComplaintTimeout> collect = districtTimeOutList.stream().filter(e -> e.getAssignStatus() == 0).collect(Collectors.toList());
|
// 查询状态正常 是区纪委和管理员
|
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().filter(e->e.getSystemRoleId()==1).map(SystemUser::getPhone).collect(Collectors.toList());
|
List<String> districtPhoneList1 = districtUserList.stream().filter(e->e.getSystemRoleId()==2).map(SystemUser::getPhone).collect(Collectors.toList());
|
collect.forEach(complaintTimeout -> {
|
// 发送短信
|
if(!districtPhoneList.isEmpty() && !complaintTimeout.getProblemType().equals("纪委")){
|
AliSmsUtil.sendTimeoutMessageAdmin(districtPhoneList,complaintTimeout.getSerialNumber());
|
}
|
if(!districtPhoneList1.isEmpty()){
|
AliSmsUtil.sendTimeoutMessage(districtPhoneList1,complaintTimeout.getSerialNumber());
|
}
|
});
|
|
|
// 分配了 查询是否有管理员 没有找层级管理员
|
List<ComplaintTimeout> collect1 = districtTimeOutList.stream().filter(e -> e.getAssignStatus() == 1).collect(Collectors.toList());
|
if(!collect1.isEmpty()){
|
// 分配的单位id
|
List<Integer> deptIds = collect1.stream().map(ComplaintTimeout::getAssignPersonId).collect(Collectors.toList());
|
// 这些单位的管理员
|
List<SystemUser> list = systemUserService.list(new LambdaQueryWrapper<SystemUser>().in(SystemUser::getOneDepartmentId, deptIds).in(SystemUser::getSystemRoleId,1,2).eq(SystemUser::getStatus,1));
|
collect1.forEach(complaintTimeout -> {
|
// 当前单位的管理员
|
List<SystemUser> systemUsers = list.stream().filter(e -> e.getOneDepartmentId().equals(complaintTimeout.getAssignPersonId())).collect(Collectors.toList());
|
if(!systemUsers.isEmpty()){
|
// 找出当前单位的管理员 纪委
|
List<String> districtPhoneList2 = systemUsers.stream().filter(e->e.getSystemRoleId()==1).map(SystemUser::getPhone).collect(Collectors.toList());
|
List<String> districtPhoneList3 = systemUsers.stream().filter(e->e.getSystemRoleId()==2).map(SystemUser::getPhone).collect(Collectors.toList());
|
// 发送短信
|
if(!districtPhoneList2.isEmpty() && !complaintTimeout.getProblemType().equals("纪委")){
|
AliSmsUtil.sendTimeoutMessageAdmin(districtPhoneList2,complaintTimeout.getSerialNumber());
|
}
|
if(!districtPhoneList3.isEmpty()){
|
AliSmsUtil.sendTimeoutMessage(districtPhoneList3,complaintTimeout.getSerialNumber());
|
}
|
}else {
|
// 发送短信
|
if(!districtPhoneList.isEmpty() && !complaintTimeout.getProblemType().equals("纪委")){
|
AliSmsUtil.sendTimeoutMessageAdmin(districtPhoneList,complaintTimeout.getSerialNumber());
|
}
|
if(!districtPhoneList1.isEmpty()){
|
AliSmsUtil.sendTimeoutMessage(districtPhoneList1,complaintTimeout.getSerialNumber());
|
}
|
}
|
});
|
}
|
|
}
|
|
// 街道超时
|
List<ComplaintTimeout> streetTimeOutList = timeOutMap.get(3);
|
if (!CollectionUtils.isEmpty(streetTimeOutList)){
|
|
// 没有分配的 需要发给层级管理员和纪委
|
List<ComplaintTimeout> collect = streetTimeOutList.stream().filter(e -> e.getAssignStatus() == 0).collect(Collectors.toList());
|
|
List<SystemUser> streetUserList = systemUserService.list(new LambdaQueryWrapper<SystemUser>()
|
.eq(SystemUser::getAccountLevel, 3)
|
.in(SystemUser::getSystemRoleId,1,2)
|
.eq(SystemUser::getStatus, 1));
|
collect.forEach(complaintTimeout -> {
|
List<String> streetPhoneList = streetUserList.stream().filter(e->e.getSystemRoleId()==1 && e.getStreetId().equals(complaintTimeout.getSuperiorId().toString())).map(SystemUser::getPhone).collect(Collectors.toList());
|
List<String> streetPhoneList1 = streetUserList.stream().filter(e->e.getSystemRoleId()==2 && e.getStreetId().equals(complaintTimeout.getSuperiorId().toString())).map(SystemUser::getPhone).collect(Collectors.toList());
|
// 发送短信
|
if(!streetPhoneList.isEmpty() && !complaintTimeout.getProblemType().equals("纪委")){
|
AliSmsUtil.sendTimeoutMessageAdmin(streetPhoneList,complaintTimeout.getSerialNumber());
|
}
|
if(!streetPhoneList1.isEmpty()){
|
AliSmsUtil.sendTimeoutMessage(streetPhoneList1,complaintTimeout.getSerialNumber());
|
}
|
});
|
|
|
// 分配了
|
List<ComplaintTimeout> collect1 = streetTimeOutList.stream().filter(e -> e.getAssignStatus() == 1).collect(Collectors.toList());
|
if(!collect1.isEmpty()){
|
List<Integer> deptIds = collect1.stream().map(ComplaintTimeout::getAssignPersonId).collect(Collectors.toList());
|
List<SystemUser> list = systemUserService.list(new LambdaQueryWrapper<SystemUser>().in(SystemUser::getOneDepartmentId, deptIds).in(SystemUser::getSystemRoleId,1,2).eq(SystemUser::getStatus,1));
|
collect1.forEach(complaintTimeout -> {
|
List<SystemUser> systemUsers = list.stream().filter(e -> e.getOneDepartmentId().equals(complaintTimeout.getAssignPersonId())).collect(Collectors.toList());
|
if(!systemUsers.isEmpty()){
|
List<String> streetPhoneList2 = systemUsers.stream().filter(e->e.getSystemRoleId()==1).map(SystemUser::getPhone).collect(Collectors.toList());
|
List<String> streetPhoneList3 = systemUsers.stream().filter(e->e.getSystemRoleId()==2).map(SystemUser::getPhone).collect(Collectors.toList());
|
// 发送短信
|
if(!streetPhoneList2.isEmpty() && !complaintTimeout.getProblemType().equals("纪委")){
|
AliSmsUtil.sendTimeoutMessageAdmin(streetPhoneList2,complaintTimeout.getSerialNumber());
|
}
|
if(!streetPhoneList3.isEmpty()){
|
AliSmsUtil.sendTimeoutMessage(streetPhoneList3,complaintTimeout.getSerialNumber());
|
}
|
}else {
|
List<String> streetPhoneList = streetUserList.stream().filter(e->e.getSystemRoleId()==1 && e.getStreetId().equals(complaintTimeout.getSuperiorId().toString())).map(SystemUser::getPhone).collect(Collectors.toList());
|
List<String> streetPhoneList1 = streetUserList.stream().filter(e->e.getSystemRoleId()==2 && e.getStreetId().equals(complaintTimeout.getSuperiorId().toString())).map(SystemUser::getPhone).collect(Collectors.toList());
|
// 发送短信
|
if(!streetPhoneList.isEmpty() && !complaintTimeout.getProblemType().equals("纪委")){
|
AliSmsUtil.sendTimeoutMessageAdmin(streetPhoneList,complaintTimeout.getSerialNumber());
|
}
|
if(!streetPhoneList1.isEmpty()){
|
AliSmsUtil.sendTimeoutMessage(streetPhoneList1,complaintTimeout.getSerialNumber());
|
}
|
}
|
});
|
}
|
|
|
|
}
|
|
// 社区超时
|
List<ComplaintTimeout> communityTimeOutList = timeOutMap.get(4);
|
if (!CollectionUtils.isEmpty(communityTimeOutList)){
|
List<ComplaintTimeout> collect = communityTimeOutList.stream().filter(e -> e.getAssignStatus() == 0).collect(Collectors.toList());
|
|
|
|
List<SystemUser> communityUserList = systemUserService.list(new LambdaQueryWrapper<SystemUser>()
|
.eq(SystemUser::getAccountLevel, 4)
|
.in(SystemUser::getSystemRoleId,1,2)
|
.eq(SystemUser::getStatus, 1));
|
collect.forEach(complaintTimeout -> {
|
List<String> communityPhoneList = communityUserList.stream().filter(e->e.getSystemRoleId()==1 && e.getCommunityId().equals(complaintTimeout.getSuperiorId())).map(SystemUser::getPhone).collect(Collectors.toList());
|
List<String> communityPhoneList1 = communityUserList.stream().filter(e->e.getSystemRoleId()==2 && e.getCommunityId().equals(complaintTimeout.getSuperiorId())).map(SystemUser::getPhone).collect(Collectors.toList());
|
|
// 发送短信
|
if(!communityPhoneList.isEmpty() && !complaintTimeout.getProblemType().equals("纪委")){
|
AliSmsUtil.sendTimeoutMessageAdmin(communityPhoneList, complaintTimeout.getSerialNumber());
|
}
|
if(!communityPhoneList1.isEmpty()){
|
AliSmsUtil.sendTimeoutMessage(communityPhoneList1,complaintTimeout.getSerialNumber());
|
}
|
});
|
|
|
// 分配了
|
List<ComplaintTimeout> collect1 = communityTimeOutList.stream().filter(e -> e.getAssignStatus() == 1).collect(Collectors.toList());
|
if(!collect1.isEmpty()){
|
List<Integer> deptIds = collect1.stream().map(ComplaintTimeout::getAssignPersonId).collect(Collectors.toList());
|
List<SystemUser> list = systemUserService.list(new LambdaQueryWrapper<SystemUser>().in(SystemUser::getOneDepartmentId, deptIds).in(SystemUser::getSystemRoleId,1,2).eq(SystemUser::getStatus,1));
|
collect1.forEach(complaintTimeout -> {
|
List<SystemUser> systemUsers = list.stream().filter(e -> e.getOneDepartmentId().equals(complaintTimeout.getAssignPersonId())).collect(Collectors.toList());
|
if(!systemUsers.isEmpty()){
|
List<String> communityPhoneList2 = systemUsers.stream().filter(e->e.getSystemRoleId()==1).map(SystemUser::getPhone).collect(Collectors.toList());
|
List<String> communityPhoneList3 = systemUsers.stream().filter(e->e.getSystemRoleId()==2).map(SystemUser::getPhone).collect(Collectors.toList());
|
// 发送短信
|
if(!communityPhoneList2.isEmpty() && !complaintTimeout.getProblemType().equals("纪委")){
|
AliSmsUtil.sendTimeoutMessageAdmin(communityPhoneList2, complaintTimeout.getSerialNumber());
|
}
|
if(!communityPhoneList3.isEmpty()){
|
AliSmsUtil.sendTimeoutMessage(communityPhoneList3,complaintTimeout.getSerialNumber());
|
}
|
}else {
|
List<String> communityPhoneList = communityUserList.stream().filter(e->e.getSystemRoleId()==1 && e.getCommunityId().equals(complaintTimeout.getSuperiorId())).map(SystemUser::getPhone).collect(Collectors.toList());
|
List<String> communityPhoneList1 = communityUserList.stream().filter(e->e.getSystemRoleId()==2 && e.getCommunityId().equals(complaintTimeout.getSuperiorId())).map(SystemUser::getPhone).collect(Collectors.toList());
|
// 发送短信
|
if(!communityPhoneList.isEmpty() && !complaintTimeout.getProblemType().equals("纪委")){
|
AliSmsUtil.sendTimeoutMessageAdmin(communityPhoneList, complaintTimeout.getSerialNumber());
|
}
|
if(!communityPhoneList1.isEmpty()){
|
AliSmsUtil.sendTimeoutMessage(communityPhoneList1,complaintTimeout.getSerialNumber());
|
}
|
}
|
});
|
}
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|