mitao
2025-05-23 c7f69f55e98c9f0777d46ef04f5cb58924e8d869
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
package com.panzhihua.sangeshenbian.service.impl;
 
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.sangeshenbian.dao.ComplaintMapper;
import com.panzhihua.sangeshenbian.dao.ComplaintRejectMapper;
import com.panzhihua.sangeshenbian.model.entity.ComplaintAuditRecord;
import com.panzhihua.sangeshenbian.model.entity.ComplaintProgress;
import com.panzhihua.sangeshenbian.model.entity.SystemUserLevel;
import com.panzhihua.sangeshenbian.model.query.SuperviseQuery;
import com.panzhihua.sangeshenbian.model.vo.AppComplaintRejectVO;
import com.panzhihua.sangeshenbian.model.vo.ComplaintVO;
import com.panzhihua.sangeshenbian.service.IComplaintAuditRecordService;
import com.panzhihua.sangeshenbian.service.IComplaintProgressService;
import com.panzhihua.sangeshenbian.service.IdentityInformationService;
import com.panzhihua.sangeshenbian.warpper.IdentityInformation;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * @author mitao
 * @date 2025/5/7
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class SuperviseService {
    private final IdentityInformationService identityInformationService;
    private final ComplaintMapper complaintMapper;
    private final IComplaintAuditRecordService complaintAuditRecordService;
    private final IComplaintProgressService complaintProgressService;
 
    public Page<ComplaintVO> queryProcessingRecordPage(SuperviseQuery query, LoginUserInfoVO loginUserInfo) {
        IdentityInformation currentIdentityInformation = identityInformationService.getCurrentIdentityInformation(loginUserInfo);
        Integer identity = currentIdentityInformation.getIdentity();
        if (!identity.equals(2)) {
            throw new ServiceException("当前账号无权限");
        }
        Long targetId = null;
        SystemUserLevel systemUserLevel = currentIdentityInformation.getSystemUserLevel();
        Integer accountLevel = systemUserLevel.getLevel();
        switch (accountLevel) {
            case 1:
                //市级
                targetId = 510400L;
                break;
            case 2:
                //区县级
                targetId = Long.valueOf(systemUserLevel.getDistrictsCode());
                break;
            case 3:
                //街道
                targetId = Long.valueOf(systemUserLevel.getStreetId());
                break;
            case 4:
                //社区
                targetId = systemUserLevel.getCommunityId();
                break;
        }
        Page<ComplaintVO> page = complaintMapper.queryProcessingRecordPage(new Page<>(query.getPageNum(), query.getPageSize()), query.getKeyword(), accountLevel, targetId);
        //查询上报下派记录
        List<Long> complaintIds = page.getRecords().stream().map(ComplaintVO::getId).collect(Collectors.toList());
        if (CollUtil.isEmpty(complaintIds)){
            return page;
        }
        List<ComplaintAuditRecord> list = complaintAuditRecordService.lambdaQuery()
                .in(ComplaintAuditRecord::getComplaintId, complaintIds)
                .in(ComplaintAuditRecord::getAuditType, 2, 3).list();
        Map<Long, List<ComplaintAuditRecord>> auditRecordListMap = new HashMap<>();
        if (CollUtil.isNotEmpty(list)) {
            auditRecordListMap = list.stream().collect(Collectors.groupingBy(ComplaintAuditRecord::getComplaintId));
        }
        //查询办理进度
        List<ComplaintProgress> complaintProgressList = complaintProgressService.lambdaQuery().in(ComplaintProgress::getComplaintId, complaintIds).list();
        Map<Long, List<ComplaintProgress>> complaintProgressListMap = complaintProgressList.stream().collect(Collectors.groupingBy(ComplaintProgress::getComplaintId));
        Map<Long, List<ComplaintAuditRecord>> finalAuditRecordListMap = auditRecordListMap;
        page.getRecords().forEach(item->{
            List<ComplaintAuditRecord> auditList = finalAuditRecordListMap.getOrDefault(item.getId(), CollUtil.newArrayList());
            item.setReportCount((int) auditList.stream().filter(auditRecord -> auditRecord.getAuditType().equals(2)).count());
            item.setAssignmentCount((int) auditList.stream().filter(auditRecord -> auditRecord.getAuditType().equals(3)).count());
            List<ComplaintProgress> progressList = complaintProgressListMap.getOrDefault(item.getId(), CollUtil.newArrayList());
            item.setProgressCount(progressList.size());
        });
        return page;
    }
 
    public Page<AppComplaintRejectVO> queryRejectRecordPage(SuperviseQuery query, LoginUserInfoVO loginUserInfo) {
        IdentityInformation currentIdentityInformation = identityInformationService.getCurrentIdentityInformation(loginUserInfo);
        Integer identity = currentIdentityInformation.getIdentity();
        if (!identity.equals(2) || currentIdentityInformation.getSuperviseFlag().equals(0)) {
            throw new ServiceException("当前账号无权限");
        }
        Long targetId = null;
        SystemUserLevel systemUserLevel = currentIdentityInformation.getSystemUserLevel();
        Integer accountLevel = systemUserLevel.getLevel();
        switch (accountLevel) {
            case 1:
                //市级
                targetId = 510400L;
                break;
            case 2:
                //区县级
                targetId = Long.valueOf(systemUserLevel.getDistrictsCode());
                break;
            case 3:
                //街道
                targetId = Long.valueOf(systemUserLevel.getStreetId());
                break;
            case 4:
                //社区
                targetId = systemUserLevel.getCommunityId();
                break;
        }
        return complaintMapper.queryRejectRecordPage(new Page<>(query.getPageNum(), query.getPageSize()), query.getKeyword(), accountLevel, targetId);
    }
}