jiangping
2024-01-27 c6c95a49be6194989c124b8fd316fb5d434bd153
server/service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
@@ -1,5 +1,6 @@
package com.doumee.service.business.impl;
import com.alibaba.fastjson.JSONObject;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
@@ -31,9 +32,12 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.net.URI;
import java.net.URLEncoder;
import java.util.*;
/**
@@ -112,6 +116,46 @@
        //处理关联方案
        dealSolutionsData(company);
    }
    @Transactional
    public void exportFiles(Integer id, HttpServletResponse response){
        try {
            Company model = companyMapper.selectById(id);
            if(model == null){
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            List<File> fileList = new ArrayList<>();
            List<Multifile> multifileList = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda()
                    .eq(Multifile::getObjId,id)
                    .isNotNull(Multifile::getFileurl)
                    .in(Multifile::getObjType, Arrays.asList(new Integer[]{
                            Constants.MultiFile.COM_BUSINESS_LICENSE.getKey(),
                            Constants.MultiFile.COM_IDCARD_IMG.getKey(),
                    }))
            );
            if(multifileList== null || multifileList.size() == 0){
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+systemDictDataBiz.queryByCode(Constants.OSS,Constants.COMPANY_FILE).getCode();
            for(Multifile l : multifileList){
                File f = Constants.getFileByNetFile(path + l.getFileurl(),StringUtils.defaultString(l.getName(),"未命名"));
                if(f !=null && f.isFile()){
                    fileList.add(f);
                }
            }
            if(fileList == null || fileList.size() == 0){
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            String fileName =  model.getName() +"_企业证件_"+System.currentTimeMillis()+".zip" ;
            String encodeFileName = URLEncoder.encode(fileName);
            response.setHeader("Content-Disposition","attachment;filename=" + encodeFileName);
            response.setContentType("application/octet-stream");
            response.setHeader("eva-opera-type", "download");
            response.setHeader("eva-download-filename", encodeFileName);
            Constants. packFilesToZip(fileList,response.getOutputStream());
        } catch (IOException e) {
            throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
        }
    }
    private void dealSystemUserData(Company company) {
        if(systemUserMapper.selectCount(new QueryWrapper<SystemUser>().lambda()