mitao
2025-03-16 0b966344989a8c193b20d493bc68875d365f643b
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java
@@ -1,14 +1,15 @@
package com.panzhihua.sangeshenbian.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
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.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 +36,15 @@
import com.panzhihua.sangeshenbian.model.vo.ComplaintVO;
import com.panzhihua.sangeshenbian.service.ISystemUserService;
import com.panzhihua.sangeshenbian.utils.FileUtil;
import com.panzhihua.sangeshenbian.warpper.MgtComplaintQuery;
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;
@@ -147,6 +146,11 @@
            }
        } 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.setReportType(accountLevel);
@@ -897,7 +901,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,7 +927,7 @@
     * @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");
@@ -936,45 +940,71 @@
    }
    @Override
    public void communityProblem(Long id) throws IOException {
        //Complaint complaint = getById(id);
        //TODO 查询真实数据
    public void downloadFile(Long id,Integer type) throws IOException {
        Complaint complaint = getById(id);
        if (Objects.isNull(complaint)) {
            throw new ServiceException("该诉求不存在");
        }
         //查询社区信息
        BcRegion region = bcRegionService.lambdaQuery().eq(BcRegion::getRegionCode, complaint.getDistrictsCode()).last("LIMIT 1").one();
        ComStreet street = comStreetService.lambdaQuery().eq(ComStreet::getStreetId, complaint.getStreetId()).one();
        ComAct act = comActService.lambdaQuery().eq(ComAct::getCommunityId, complaint.getCommunityId()).one();
        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", Objects.nonNull(complaint.getPartyMemberId())?"党员": "上级"); //TODO待修改
        map.put("partyOrganization",Objects.nonNull(partyMember)? partyMember.getPartyOrganization() : "");
        map.put("name", complaint.getName());
        map.put("contactNumber", complaint.getContactNumber());
        map.put("nickname", Objects.nonNull(partyMember)? partyMember.getName() : "");
        map.put("phone", Objects.nonNull(partyMember)? partyMember.getPhone() : "");
        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 {