luofl
2025-03-18 bb1487efec7f9b55db0af2535dfa5649d95089b7
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java
@@ -1,14 +1,17 @@
package com.panzhihua.sangeshenbian.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.idev.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.deepoove.poi.XWPFTemplate;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo;
import com.panzhihua.common.redis.RedisUtils;
import com.panzhihua.sangeshenbian.enums.RateEnum;
import com.panzhihua.sangeshenbian.model.dto.ComplaintCompletionDTO;
import com.panzhihua.sangeshenbian.model.dto.ComplaintProcessDTO;
import com.panzhihua.sangeshenbian.model.entity.Complaint;
@@ -35,17 +38,17 @@
import com.panzhihua.sangeshenbian.model.vo.ComplaintVO;
import com.panzhihua.sangeshenbian.service.ISystemUserService;
import com.panzhihua.sangeshenbian.utils.FileUtil;
import com.panzhihua.sangeshenbian.warpper.IdentityInformationVO;
import com.panzhihua.sangeshenbian.warpper.MgtComplaintQuery;
import com.panzhihua.sangeshenbian.warpper.PermissionsVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -82,6 +85,8 @@
    private final IComplaintCommentService complaintCommentService;
    private final HttpServletResponse response;
    private final IPartyMemberService partyMemberService;
    private final IdentityInformationService identityInformationService;
    private final RedisUtils redisUtils;
    @Override
    public void saveComplaint(Complaint complaint, LoginUserInfoVO loginUserInfoVO) {
@@ -109,24 +114,34 @@
        complaint.setSerialNumber(serialNumber);
        Optional<SystemUser> systemUserOpt = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone());
        Integer accountLevel = 5;
        if (systemUserOpt.isPresent()) {
        //获取当前身份
        IdentityInformationVO identityInformationVO = identityInformationService.getIdentityInformationVO(loginUserInfoVO);
        //1=党员,2=管理员
        Integer identity = identityInformationVO.getIdentity();
        if (systemUserOpt.isPresent() && null != identity && identity == 2) {
            SystemUser systemUser = systemUserOpt.get();
            accountLevel = systemUser.getAccountLevel();
            switch (accountLevel) {
                case 1:
                    //市级
                    complaint.setCityCode(510400);
                    complaint.setReportUserName(systemUser.getName());
                    complaint.setReportUserPhone(systemUser.getPhone());
                    break;
                case 2:
                    //区县级
                    complaint.setCityCode(510400);
                    complaint.setDistrictsCode(Integer.valueOf(systemUser.getDistrictsCode()));
                    complaint.setReportUserName(systemUser.getName());
                    complaint.setReportUserPhone(systemUser.getPhone());
                    break;
                case 3:
                    //街道
                    complaint.setCityCode(510400);
                    complaint.setDistrictsCode(Integer.valueOf(systemUser.getDistrictsCode()));
                    complaint.setStreetId(Long.valueOf(systemUser.getStreetId()));
                    complaint.setReportUserName(systemUser.getName());
                    complaint.setReportUserPhone(systemUser.getPhone());
                    break;
                case 4:
                    //社区
@@ -134,20 +149,31 @@
                    complaint.setDistrictsCode(Integer.valueOf(systemUser.getDistrictsCode()));
                    complaint.setStreetId(Long.valueOf(systemUser.getStreetId()));
                    complaint.setCommunityId(systemUser.getCommunityId());
                    complaint.setReportUserName(systemUser.getName());
                    complaint.setReportUserPhone(systemUser.getPhone());
                    break;
                case 5:
                    //社区
                    //党员
                    complaint.setCityCode(510400);
                    complaint.setDistrictsCode(Integer.valueOf(systemUser.getDistrictsCode()));
                    complaint.setStreetId(Long.valueOf(systemUser.getStreetId()));
                    complaint.setCommunityId(systemUser.getCommunityId());
                    PartyMember partyMember = partyMemberService.getPartyMemberByPhone(loginUserInfoVO.getPhone());
                    complaint.setPartyMemberId(partyMember.getId());
                    complaint.setReportUserName(partyMember.getName());
                    complaint.setReportUserPhone(partyMember.getPhone());
                    break;
            }
        } else{
            PartyMember partyMember = partyMemberService.getPartyMemberByPhone(loginUserInfoVO.getPhone());
            //党员
            complaint.setCityCode(510400);
            complaint.setDistrictsCode(Integer.valueOf(partyMember.getDistrictsCode()));
            complaint.setStreetId(Long.valueOf(partyMember.getStreetId()));
            complaint.setCommunityId(partyMember.getCommunityId());
            complaint.setPartyMemberId(partyMember.getId());
            complaint.setReportUserName(partyMember.getName());
            complaint.setReportUserPhone(partyMember.getPhone());
        }
        complaint.setReportType(accountLevel);
        // 设置其他字段
@@ -178,8 +204,10 @@
        Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone());
        Long targetId = null;
        Integer accountLevel = 5;
        //获取当前身份,1=党员,2=管理员
        Integer identity = (Integer) redisUtils.get("identity:" + loginUserInfoVO.getPhone());
        //上级
        if (systemUserByPhone.isPresent()) {
        if (systemUserByPhone.isPresent() && null != identity && identity == 2) {
            SystemUser systemUser = systemUserByPhone.get();
            accountLevel = systemUser.getAccountLevel();
            switch (accountLevel) {
@@ -227,6 +255,8 @@
    public void buttonPermission(ComplaintVO vo, Optional<SystemUser> systemUserByPhone){
        vo.setListControlsButtonStatus(1);
        vo.setEvaluateButtonStatus(1);
        vo.setAuditButtonStatus(1);
        ComplaintAuditRecord one = complaintAuditRecordService.getOne(new LambdaQueryWrapper<ComplaintAuditRecord>().eq(ComplaintAuditRecord::getComplaintId, vo.getId())
                .ne(ComplaintAuditRecord::getAuditType, 1).orderByDesc(ComplaintAuditRecord::getSort).last(" limit 0, 1"));
        //没有审核数据,且正在办理,则按钮权限是添加人员的
@@ -246,7 +276,7 @@
            }
        }
        //有审核数据,且正在办理
        if(null != one && (vo.getStatus() == 0 || vo.getStatus() == 1 || vo.getStatus() == 2)){
        if(null != one && (vo.getStatus() == 0 || vo.getStatus() == 1 || vo.getStatus() == 2 || vo.getStatus() == 6)){
            //区分是上报数据还是下派数据
            if(one.getAuditType() == 2){
                //判断当前审核状态
@@ -349,6 +379,50 @@
                }
            }
        }
        //有审核数据,且为审核中
        //审核状态为待审核,需要授权审核按钮
        if(null != one && (vo.getStatus() == 5 || vo.getStatus() == 7) && systemUserByPhone.isPresent()){
            SystemUser systemUser = systemUserByPhone.get();
            String targetId = "";
            Integer accountLevel = 5;
            //获取当前身份,1=党员,2=管理员
            Integer identity = (Integer) redisUtils.get("identity:" + systemUser.getPhone());
            if(2 == identity){
                accountLevel = systemUser.getAccountLevel();
                switch (accountLevel) {
                    case 1:
                        //市级
                        targetId = "510400";
                        break;
                    case 2:
                        //区县级
                        targetId = systemUser.getDistrictsCode();
                        break;
                    case 3:
                        //街道
                        targetId = systemUser.getStreetId().toString();
                        break;
                    case 4:
                        //社区
                        targetId = systemUser.getCommunityId().toString();
                        break;
                    case 5:
                        //党员
                        PartyMember partyMember = partyMemberService.getPartyMemberByPhone(systemUser.getPhone());
                        targetId = partyMember.getId().toString();
                        break;
                }
                ComplaintAuditRecord one2 = complaintAuditRecordService.getOne(new LambdaQueryWrapper<ComplaintAuditRecord>().eq(ComplaintAuditRecord::getComplaintId, vo.getId())
                        .eq(ComplaintAuditRecord::getLatestFlag, 1));
                Integer isAdmin = systemUserByPhone.get().getIsAdmin();
                if(one2.getReportType().equals(accountLevel) && one2.getSuperiorId().toString().equals(targetId) && 1 == isAdmin){
                    vo.setAuditButtonStatus(0);
                }
            }
        }
        
        //状态为已办结,判断评价按钮
        int count = complaintCommentService.count(new LambdaQueryWrapper<ComplaintComment>().eq(ComplaintComment::getComplaintId, vo.getId()).eq(ComplaintComment::getDelFlag, 0));
@@ -380,8 +454,10 @@
        Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone());
        String targetId = "";
        Integer accountLevel = 5;
        //获取当前身份,1=党员,2=管理员
        Integer identity = (Integer) redisUtils.get("identity:" + loginUserInfoVO.getPhone());
        //上级
        if (systemUserByPhone.isPresent()) {
        if (systemUserByPhone.isPresent() && identity == 2) {
            SystemUser systemUser = systemUserByPhone.get();
            accountLevel = systemUser.getAccountLevel();
            switch (accountLevel) {
@@ -421,31 +497,36 @@
        List<ComplaintProgress> list = complaintProgressService.lambdaQuery().eq(ComplaintProgress::getComplaintId, id)
                .orderByAsc(ComplaintProgress::getCreateTime).list();
        detail.setComplaintProgresses(list);
        detail.setAuditButtonStatus(1);
        detail.setEvaluateButtonStatus(1);
        if((detail.getStatus() == 5 || detail.getStatus() == 7) && systemUserByPhone.isPresent()){
            ComplaintAuditRecord one = complaintAuditRecordService.getOne(new LambdaQueryWrapper<ComplaintAuditRecord>().eq(ComplaintAuditRecord::getComplaintId, detail.getId())
                    .eq(ComplaintAuditRecord::getLatestFlag, 1));
            Integer isAdmin = systemUserByPhone.get().getIsAdmin();
            if(one.getReportType().equals(accountLevel) && one.getSuperiorId().toString().equals(targetId) && 1 == isAdmin){
                detail.setAuditButtonStatus(0);
            }
        }
        //已办结,显示评价按钮
        int count = complaintCommentService.count(new LambdaQueryWrapper<ComplaintComment>().eq(ComplaintComment::getComplaintId, detail.getId()).eq(ComplaintComment::getDelFlag, 0));
        if(detail.getStatus() == 3 && 0 == count){
            if(systemUserByPhone.isPresent()){
                SystemUser systemUser = systemUserByPhone.get();
                Integer isAdmin = systemUser.getIsAdmin();
                if(accountLevel.compareTo(detail.getReportType()) == 0 && ((accountLevel != 5 && 1 == isAdmin) || accountLevel == 5)){
                    detail.setEvaluateButtonStatus(0);
                }
            }else{
                if(detail.getReportType() == 5){
                    detail.setEvaluateButtonStatus(0);
                }
            }
        }
//        detail.setAuditButtonStatus(1);
//        detail.setEvaluateButtonStatus(1);
//        if((detail.getStatus() == 5 || detail.getStatus() == 7) && systemUserByPhone.isPresent()){
//            ComplaintAuditRecord one = complaintAuditRecordService.getOne(new LambdaQueryWrapper<ComplaintAuditRecord>().eq(ComplaintAuditRecord::getComplaintId, detail.getId())
//                    .eq(ComplaintAuditRecord::getLatestFlag, 1));
//            Integer isAdmin = systemUserByPhone.get().getIsAdmin();
//            if(one.getReportType().equals(accountLevel) && one.getSuperiorId().toString().equals(targetId) && 1 == isAdmin){
//                detail.setAuditButtonStatus(0);
//            }
//        }
        buttonPermission(detail, systemUserByPhone);
//        //已办结,显示评价按钮
//        int count = complaintCommentService.count(new LambdaQueryWrapper<ComplaintComment>().eq(ComplaintComment::getComplaintId, detail.getId()).eq(ComplaintComment::getDelFlag, 0));
//        if(detail.getStatus() == 3 && 0 == count){
//            if(systemUserByPhone.isPresent()){
//                SystemUser systemUser = systemUserByPhone.get();
//                Integer isAdmin = systemUser.getIsAdmin();
//                if(accountLevel.compareTo(detail.getReportType()) == 0 && ((accountLevel != 5 && 1 == isAdmin) || accountLevel == 5)){
//                    detail.setEvaluateButtonStatus(0);
//                }
//            }else{
//                if(detail.getReportType() == 5){
//                    detail.setEvaluateButtonStatus(0);
//                }
//            }
//        }
        return detail;
    }
@@ -504,14 +585,17 @@
                .ne(SystemUser::getStatus, 3)
                .last("LIMIT 1"));
        IdentityInformationVO identityInformationVO = identityInformationService.getIdentityInformationVO(loginUserInfoVO);
        if (CollectionUtil.isEmpty(identityInformationVO.getPermissions())) {
            throw new ServiceException("请先完成认证");
        }
        Long superiorId;
        int reportType;
        if (adminUser == null) {
            superiorId = loginUserInfoVO.getCommunityId();
            if (Objects.isNull(superiorId)) {
                throw new ServiceException("上报失败,请绑定社区");
            }
            reportType = ReportTypeEnum.COMMUNITY.getCode();
            PartyMember partyMember = partyMemberService.getPartyMemberByPhone(phone);
            superiorId = partyMember.getCommunityId();
            reportType = 4;
        } else {
            int accountLevel = adminUser.getAccountLevel(); // 改为基本类型
            if (accountLevel == 1) {
@@ -672,16 +756,24 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveDelay(ComplaintDelayDTO dto, LoginUserInfoVO loginUserInfoVO) {
        IdentityInformationVO identityInformationVO = identityInformationService.getIdentityInformationVO(loginUserInfoVO);
        List<PermissionsVO> permissions = identityInformationVO.getPermissions();
        if (CollectionUtil.isEmpty(permissions)){
            throw new ServiceException("请先完成认证");
        }
        SystemUser systemUser = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone()).orElse(null);
        Long superiorId;
        int reportType;
        if (systemUser == null) {
            superiorId = loginUserInfoVO.getCommunityId();
        if (identityInformationVO.getIdentity() == 1) {
            PartyMember partyMember = partyMemberService.getPartyMemberByPhone(loginUserInfoVO.getPhone());
            superiorId = partyMember.getCommunityId();
            if (Objects.isNull(superiorId)) {
                throw new ServiceException("延期申请失败,请绑定社区");
            }
            reportType = ReportTypeEnum.COMMUNITY.getCode();
        } else {
        } else if (identityInformationVO.getIdentity() == 2){
            int accountLevel = systemUser.getAccountLevel(); // 改为基本类型
            if (accountLevel == 1) {
                throw new ServiceException("市级账号,无法延期申请!");
@@ -701,6 +793,8 @@
                // 处理未预期的账号等级
                throw new ServiceException("未知的账号等级");
            }
        }else {
            throw new ServiceException("无权申请");
        }
        // 清除最新记录
@@ -897,7 +991,7 @@
     * @return
     */
    @Override
    public Page<ComplaintVO> pageList(ComplaintQuery query, SystemUserVo loginUserInfo) {
    public Page<ComplaintVO> pageList(MgtComplaintQuery query, SystemUserVo loginUserInfo) {
        return baseMapper.pageList(new Page<>(query.getPageNum(), query.getPageSize()), query,loginUserInfo);
    }
@@ -923,58 +1017,84 @@
     * @param loginUserInfo
     */
    @Override
    public void export(ComplaintQuery query, SystemUserVo loginUserInfo) throws IOException {
    public void export(MgtComplaintQuery query, SystemUserVo loginUserInfo) throws IOException {
        List<ComplaintVO> list =  baseMapper.getList(query, loginUserInfo);
        List<ComplaintExcel> complaintExcels = BeanUtil.copyToList(list, ComplaintExcel.class);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        String fileName = URLEncoder.encode("诉求数据", "UTF-8").replaceAll("\\+", "%20");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
        EasyExcel.write(response.getOutputStream(), PartyMemberExcel.class)
        EasyExcel.write(response.getOutputStream(), ComplaintExcel.class)
                .sheet("诉求数据")
                .doWrite(complaintExcels);
    }
    @Override
    public void communityProblem(Long id) throws IOException {
        //Complaint complaint = getById(id);
        //TODO 查询真实数据
    public void downloadFile(Long id,Integer type) throws IOException {
        Complaint complaint = baseMapper.getDetailBg(id);
        if (Objects.isNull(complaint)) {
            throw new ServiceException("该诉求不存在");
        }
         //查询社区信息
        BcRegion region = bcRegionService.getDistrictByCode(complaint.getDistrictsCode().toString());
        ComStreet street = comStreetService.getById(complaint.getStreetId().toString());
        ComAct act = comActService.getById(complaint.getCommunityId());
        String community = region.getRegionName() +"-"+ street.getName() + "-"+ act.getName();
        PartyMember partyMember = null;
        if (Objects.nonNull(complaint.getPartyMemberId())){
             partyMember = partyMemberService.getById(complaint.getPartyMemberId());
        }
        String fileName = "";
        switch (type){
            case 1:
                fileName = "社区问题单";
                break;
            case 2:
                fileName = "问题处理单";
                if (Objects.nonNull(partyMember)) {
                    community = community + "-" + partyMember.getServiceTarget();
                }
                break;
            case 3:
                fileName = "协调通知单";
                break;
        }
        Map<String, Object> map = new HashMap<>();
        map.put("community", "社区社区");
        map.put("problemType", "就业");
        map.put("descriptionContent", "描述内容");
        map.put("reportType", "党员");
        map.put("partyOrganization", "石羊党群");
        map.put("name", "张三");
        map.put("contactNumber", "1888888888");
        map.put("nickname", "李四");
        map.put("phone", "17777777777");
        map.put("community", community);
        map.put("problemType", complaint.getProblemType());
        map.put("descriptionContent", complaint.getDescriptionContent());
        map.put("reportType", ReportTypeEnum.fromCode(complaint.getReportType()).getDescription());
        map.put("partyOrganization",Objects.nonNull(partyMember)? partyMember.getPartyOrganization() : "");
        map.put("name", complaint.getName());
        map.put("contactNumber", complaint.getContactNumber());
        map.put("nickname", complaint.getReportUserName());
        map.put("phone", complaint.getReportUserPhone());
        List<ComplaintProgress> list = complaintProgressService.lambdaQuery().eq(ComplaintProgress::getComplaintId, id).orderByAsc(ComplaintProgress::getCreateTime).list();
        StringBuilder sb = new StringBuilder();
        if (CollUtil.isNotEmpty(list)) {
            int rowNum = 1;
            list.forEach(item->{
                sb.append(rowNum).append("、 ");
                sb.append(item.getDescribe()).append("\n");
            });
        }
        // 在文本中直接使用换行符
        String content = "第一行内容\n第二行内容\n第三行内容";
        map.put("complaintProgress", content);
        map.put("status", "处理中");
        map.put("complaintProgress", sb.toString());
        map.put("status", ProcessStatusEnum.getDescriptionByCode(complaint.getStatus()));
        if (2 == type) {
            //查询诉求评价
            ComplaintComment complaintComment = complaintCommentService.lambdaQuery().eq(ComplaintComment::getComplaintId, id).last("LIMIT 1").one();
            if (Objects.nonNull(complaintComment)) {
                map.put("rateStr", RateEnum.getEnumByCode(complaintComment.getRate()));
            }
        }
        response.setContentType("application/octet-stream");
        String fileName = URLEncoder.encode("社区问题单", "UTF-8").replaceAll("\\+", "%20");
        response.setHeader("Content-disposition","attachment;filename=\""+fileName+".docx"+"\"");
        String fileTemplateName = FileUtil.getPath() + "template/社区问题单.docx";
        String fileNameEncode = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
        response.setHeader("Content-disposition","attachment;filename=\""+fileNameEncode+".docx"+"\"");
        String fileTemplateName = FileUtil.getPath() + "template/"+fileName+".docx";
        XWPFTemplate.compile(fileTemplateName).render(map).writeAndClose(response.getOutputStream());
    }
    /**
     * 问题处理单
     * @param id
     */
    @Override
    public void problemHandle(Long id) {
    }
    /**
     * 协调通知
     * @param id
     */
    @Override
    public void coordinationNotice(Long id) {
    }
    public static void main(String[] args) {
        try {