1.
luofl
2025-02-28 ac8935ad12f67f78a74a3bd2bfaf810546a7461f
1.
4个文件已修改
1个文件已添加
420 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/dao/ComplaintAuditRecordMapper.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/model/dto/ComplaintTimeout.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/model/entity/MessageNotification.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/scheduled/ComplaintTasks.java 367 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/resources/mapper/ComplaintAuditRecordMapper.xml 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/dao/ComplaintAuditRecordMapper.java
@@ -1,7 +1,11 @@
package com.panzhihua.sangeshenbian.dao;
import com.panzhihua.sangeshenbian.model.dto.ComplaintTimeout;
import com.panzhihua.sangeshenbian.model.entity.ComplaintAuditRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
 * <p>
@@ -13,4 +17,10 @@
 */
public interface ComplaintAuditRecordMapper extends BaseMapper<ComplaintAuditRecord> {
    public List<ComplaintTimeout> getComplaintTimeout(@Param("cityDay") Integer cityDay,
                                                      @Param("districtDay") Integer districtDay,
                                                      @Param("streetDay") Integer streetDay,
                                                      @Param("communityDay") Integer communityDay,
                                                      @Param("partyMemberDay") Integer partyMemberDay);
}
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/model/dto/ComplaintTimeout.java
New file
@@ -0,0 +1,15 @@
package com.panzhihua.sangeshenbian.model.dto;
import lombok.Data;
import java.util.Date;
@Data
public class ComplaintTimeout {
    private Long complaintId;
    private String title;
    private Long createBy;
    private Integer reportType;
    private Integer superiorId;
    private Date closingTime;
}
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/model/entity/MessageNotification.java
@@ -9,6 +9,7 @@
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Date;
/**
 * @author zhibing.pu
@@ -71,7 +72,7 @@
     */
    @TableField("response_time")
    @ApiModelProperty("需求应处理时间")
    private LocalDateTime responseTime;
    private Date responseTime;
    /**
     * 提示类型(1=临期提醒,2=超时提醒)
     */
@@ -89,5 +90,5 @@
     */
    @TableField("create_time")
    @ApiModelProperty("创建时间")
    private LocalDateTime createTime;
    private Date createTime;
}
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/scheduled/ComplaintTasks.java
@@ -1,20 +1,347 @@
//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.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);
            });
        }
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/resources/mapper/ComplaintAuditRecordMapper.xml
@@ -2,4 +2,27 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.panzhihua.sangeshenbian.dao.ComplaintAuditRecordMapper">
    <select id="getComplaintTimeout" resultType="com.panzhihua.sangeshenbian.model.dto.ComplaintTimeout">
        SELECT
        sc.id complaintId,
        sc.description_title title,
        sc.create_by,
        scar.report_type,
        scar.superior_id,
        sc.create_time,
        sc.closingTime
        FROM
        sgsb_complaint_audit_record scar
        LEFT JOIN sgsb_complaint sc ON scar.complaint_id = sc.id
        WHERE
        scar.latest_flag = 1
        AND sc.create_time <![CDATA[ < ]]> NOW() - INTERVAL
        CASE scar.report_type
        WHEN 1 THEN ${cityDay}
        WHEN 2 THEN ${districtDay}
        WHEN 3 THEN ${streetDay}
        WHEN 4 THEN ${communityDay}
        WHEN 5 THEN ${partyMemberDay}
        END DAY
    </select>
</mapper>