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