From 1462476c93011079d6cec65be2877729571bba16 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期一, 02 十二月 2024 15:04:36 +0800 Subject: [PATCH] 项目库导出 --- business/src/main/resources/mapper/ProjectInfoMapper.xml | 22 +++++ business/src/main/java/com/ycl/domain/vo/ProjectVO.java | 2 business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java | 120 ++++++++++++++++++++++++++++- business/src/main/resources/mapper/ProjectInvestmentFundingMapper.xml | 12 +- business/src/main/resources/mapper/ProjectUnitRegistrationInfoMapper.xml | 12 +- business/src/main/resources/mapper/ProjectInvestmentInfoMapper.xml | 12 +- common/src/main/java/com/ycl/common/utils/excel/OutputExcelUtils.java | 2 business/src/main/java/com/ycl/service/ProjectInfoService.java | 3 8 files changed, 157 insertions(+), 28 deletions(-) diff --git a/business/src/main/java/com/ycl/domain/vo/ProjectVO.java b/business/src/main/java/com/ycl/domain/vo/ProjectVO.java index 119abd9..4e6d223 100644 --- a/business/src/main/java/com/ycl/domain/vo/ProjectVO.java +++ b/business/src/main/java/com/ycl/domain/vo/ProjectVO.java @@ -8,6 +8,8 @@ @Data public class ProjectVO extends ProjectExcelTemplate { private Long id; + //鏀跨瓥琛╥d + private Long policyId; /** 鐘舵�佺爜 */ private String projectColorCode; private List<Long> competentDepartmentList; diff --git a/business/src/main/java/com/ycl/service/ProjectInfoService.java b/business/src/main/java/com/ycl/service/ProjectInfoService.java index cea7951..e92b8b3 100644 --- a/business/src/main/java/com/ycl/service/ProjectInfoService.java +++ b/business/src/main/java/com/ycl/service/ProjectInfoService.java @@ -11,6 +11,7 @@ import com.ycl.domain.vo.IndexDTO; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.List; import java.util.Map; @@ -80,5 +81,5 @@ Result getManagerFlag(Integer recordId); - void export(HttpServletResponse response, ProjectExportQuery query); + void export(HttpServletResponse response, ProjectExportQuery query) throws IOException; } diff --git a/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java b/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java index b865b20..308304b 100644 --- a/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java +++ b/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java @@ -1,11 +1,15 @@ package com.ycl.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ZipUtil; import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ycl.common.base.Result; +import com.ycl.common.config.SysConfig; +import com.ycl.common.constant.Constants; import com.ycl.common.enums.business.FileTypeEnum; import com.ycl.common.enums.business.ImportanceTypeEnum; import com.ycl.common.enums.business.ProjectCategoryEnum; @@ -28,17 +32,25 @@ import com.ycl.service.FileService; import com.ycl.service.ProjectInfoService; import lombok.RequiredArgsConstructor; +import org.apache.commons.codec.Charsets; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; +import java.io.FileOutputStream; +import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; +import java.util.zip.ZipOutputStream; /** * 椤圭洰绠$悊鍩虹淇℃伅琛� 鏈嶅姟瀹炵幇绫� @@ -388,28 +400,122 @@ } @Override - public void export(HttpServletResponse response, ProjectExportQuery query) { + public void export(HttpServletResponse response, ProjectExportQuery query) throws IOException { List<ProjectVO> data = baseMapper.selectProjectDetailByIds(query.getDataIdList()); List<ProjectExcelTemplate> excelList = new ArrayList<>(); //瀛楀吀浣滅炕璇� - data.forEach(item->{ + data.forEach(item -> { ProjectExcelTemplate excel = new ProjectExcelTemplate(); - BeanUtils.copyProperties(item,excel); + BeanUtils.copyProperties(item, excel); //椤圭洰闃舵 - excel.setProjectPhase(ProjectCategoryEnum.getPhaseByProjectStatus(item.getProjectStatus(),item.getProcessId()!=null)); + excel.setProjectPhase(ProjectCategoryEnum.getPhaseByProjectStatus(item.getProjectStatus(), item.getProcessId() != null)); excelList.add(excel); }); - //琛ュ厖鏂囦欢鐨勫瓧娈� Set<Integer> indexes = OutputExcelUtils.getSelectFields(query.getFieldList(), ProjectExcelTemplate.class); //涓嶉渶瑕侀檮浠� - if(!query.getRequireFile()) { + if (!query.getRequireFile()) { try (ServletOutputStream outputStream = response.getOutputStream()) { EasyExcel.write(outputStream, ProjectExcelTemplate.class).includeColumnIndexes(indexes).sheet("椤圭洰鍒楄〃").doWrite(excelList); } catch (Exception e) { log.error(e.getMessage(), e); throw new BaseException("瀵煎嚭澶辫触锛�" + e.getMessage()); } + } else { + //闇�瑕侀檮浠�,瀵煎嚭涓簔ip + response.setContentType("application/zip"); + response.setCharacterEncoding(Charsets.UTF_8.name()); + String fileName = URLEncoder.encode("椤圭洰鍒楄〃", Charsets.UTF_8); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".zip"); + + java.io.File tempDir = null; + try { + //鏌ュ嚭闄勪欢 + List<File> projectInfoFiles = fileMapper.selectList(new QueryWrapper<File>() + .in("bus_id", data.stream().map(ProjectVO::getId).collect(Collectors.toList())) + .and(q -> q.eq("type", FileTypeEnum.PROJECT_INFO.getType()).or().eq("type", FileTypeEnum.DOCUMENT_INFO.getType())) + ); + List<File> policyFiles = fileMapper.selectList(new QueryWrapper<File>() + .in("bus_id", data.stream().map(ProjectVO::getPolicyId).collect(Collectors.toList())) + .eq("type", FileTypeEnum.INVEST_POLICY.getType()) + ); + projectInfoFiles.addAll(policyFiles); + projectInfoFiles.forEach(file -> { + data.forEach(item -> { + if (FileTypeEnum.PROJECT_INFO.equals(file.getType())) { + if (file.getBusId().equals(item.getId())) { + //瀹℃壒璁″垝涔� + item.setApprovalPlan(file.getOriginalName()); + } + }else if(FileTypeEnum.DOCUMENT_INFO.equals(file.getType())){ + if (file.getBusId().equals(item.getId())) { + //鐩稿叧鏂囦功 + item.setDocuments(file.getOriginalName()); + } + }else if(FileTypeEnum.INVEST_POLICY.equals(file.getType())){ + if (file.getBusId().equals(item.getPolicyId())) { + //绗﹀悎浜т笟鏀跨瓥闄勪欢 + item.setPolicyComplianceAttachment(file.getOriginalName()); + } + } + }); + + }); + // 鍒涘缓涓存椂鐩綍 + tempDir = Files.createTempDirectory("temp").toFile(); + + java.io.File templateDir = new java.io.File(tempDir, "template"); + if (!templateDir.exists()) { + templateDir.mkdirs(); + } + + // 鍒涘缓 Excel 鏂囦欢 + java.io.File excelFile = new java.io.File(templateDir, "excel.xlsx"); + if (!excelFile.exists()) { + excelFile.createNewFile(); + } + + // 鍐欏叆 Excel 妯℃澘鏁版嵁 + try (FileOutputStream fileOutputStream = new FileOutputStream(excelFile, false)) { + EasyExcel.write(fileOutputStream, ProjectExcelTemplate.class).sheet("椤圭洰鍒楄〃").doWrite(excelList); + } + + // 鍒涘缓闄勪欢鐩綍 + java.io.File attachmentDir = new java.io.File(templateDir, "attachment"); + if (!attachmentDir.exists()) { + attachmentDir.mkdirs(); + } + + //灏嗛檮浠跺鍒跺鐩綍涓� + for (File item : projectInfoFiles) { + String url = item.getUrl(); + if (StringUtils.isBlank(url)) continue; + url = url.replaceFirst(Constants.RESOURCE_PREFIX, SysConfig.getProfile()); + // 鐩存帴浣跨敤File绫诲鐞嗙郴缁熻矾寰� + java.io.File sourceFile = new java.io.File(url); + if (!sourceFile.exists() || !sourceFile.isFile()) { + // 澶勭悊鏂囦欢涓嶅瓨鍦ㄦ垨涓嶆槸鏂囦欢鐨勬儏鍐� + continue; // 鎴栬�呰褰曟棩蹇椼�佹姏鍑哄紓甯哥瓑 + } + // 鐩爣鏂囦欢璺緞锛屼娇鐢╝ttachmentDir浣滀负鐖剁洰褰曪紝骞朵繚鎸佸師鏂囦欢鍚� + java.io.File targetFile = new java.io.File(attachmentDir, sourceFile.getName()); + // 澶嶅埗鏂囦欢 + try { + Files.copy(sourceFile.toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + log.error(e.getMessage()); + } + } + // 鎵撳寘 ZIP 鏂囦欢 + java.io.File zipFile = ZipUtil.zip(templateDir); + byte[] zipBytes = Files.readAllBytes(zipFile.toPath()); + + // 灏� ZIP 鏂囦欢鍐欏叆鍝嶅簲 + try (ServletOutputStream outputStream = response.getOutputStream()) { + outputStream.write(zipBytes); + } + } finally { + OutputExcelUtils.deleteDirectoryOrFile(tempDir); + } } - //TODO锛氶渶瑕侀檮浠� } } diff --git a/business/src/main/resources/mapper/ProjectInfoMapper.xml b/business/src/main/resources/mapper/ProjectInfoMapper.xml index 021bfeb..258dde8 100644 --- a/business/src/main/resources/mapper/ProjectInfoMapper.xml +++ b/business/src/main/resources/mapper/ProjectInfoMapper.xml @@ -165,7 +165,27 @@ </select> <select id="selectProjectDetailByIds" resultType="com.ycl.domain.vo.ProjectVO"> - select * + select + TPI.id as id,TPI.project_name,TPI.project_code,TPI.content,TPI.project_type,TPI.project_status,TPI.fund_type,TPI.invest_type,TPI.project_phase, + TPI.tag,TPI.competent_department,TPI.area,TPI.management_centralization,TPI.project_approval_type,TPI.importance_type,TPI.year,TPI.year_invest_amount,TPI.create_project_time,TPI.plan_start_time, + TPI.plan_complete_time,TPI.win_unit,TPI.win_amount,TPI.win_time,TPI.project_address,TPI.longitude,TPI.latitude, + TPI.project_owner_unit,TPI.project_contact_person,TPI.contact,TPI.gmt_create,TPI.gmt_update,TPI.update_by,TPI.create_by, + TPIF.id,TPIF.project_id,TPIF.total_investment,TPIF.principal,TPIF.government_investment_total,TPIF.central_investment_total,TPIF.central_budget_investment,TPIF.central_fiscal_investment,TPIF.central_special_bond_investment, + TPIF.central_special_fund_investment,TPIF.provincial_investment_total, + TPIF.provincial_budget_investment,TPIF.provincial_fiscal_investment,TPIF.provincial_special_fund_investment,TPIF.city_investment_total,TPIF.city_budget_investment,TPIF.city_fiscal_investment,TPIF.city_special_fund_investment, + TPIF.county_investment_total,TPIF.county_budget_investment,TPIF.county_fiscal_investment, + TPIF.county_special_fund_investment,TPIF.domestic_loan_total,TPIF.bank_loan,TPIF.foreign_investment_total,TPIF.enterprise_self_raised_total,TPIF.other_investment_total,TPIF.gmt_create, + TPIF.create_by,TPIF.gmt_update,TPIF.update_by, + TPII.id,TPII.project_id,TPII.be_cross_region,TPII.construction_location,TPII.detailed_address,TPII.be_compensation_project,TPII.compensation_reason,TPII.planned_start_date, + TPII.expected_completion_date,TPII.national_industry_classification,TPII.industry_classification,TPII.project_nature,TPII.project_attribute, + TPII.use_earth,TPII.content_scale,TPII.code,TPII.gmt_create,TPII.create_by,TPII.gmt_update, TPII.update_by, + TPIPC.id as policyId,TPIPC.project_id,TPIPC.belongs_to_industry_adjustment_directory,TPIPC.belongs_to_western_encouraged_directory,TPIPC.not_banned_or_controlled_project,TPIPC.information_is_true,TPIPC.special_planning_compliance, + TPIPC.annual_energy_consumption,TPIPC.annual_electricity_consumption,TPIPC.energy_check,TPIPC.no_only_check_type,TPIPC.remarks,TPIPC.gmt_create, + TPIPC.gmt_update,TPIPC.create_by,TPIPC.update_by, + TPURI.id,TPURI.project_id,TPURI.total_investment,TPURI.project_unit,TPURI.project_unit_type, + TPURI.registration_type,TPURI.holding_situation,TPURI.certificate_type,TPURI.certificate_number,TPURI.registered_address,TPURI.registered_capital, + TPURI.legal_representative,TPURI.fixed_phone,TPURI.legal_person_idcard,TPURI.project_contact_person,TPURI.phone,TPURI.contact_idcard, + TPURI.wechat,TPURI.contact_address,TPURI.post_code,TPURI.email,TPURI.create_by,TPURI.update_by,TPURI.gmt_create,TPURI.gmt_update from t_project_info TPI left join t_project_investment_funding TPIF on TPI.id = TPIF.project_id and TPIF.deleted = 0 left join t_project_investment_info TPII on TPI.id = TPII.project_id and TPII.deleted = 0 diff --git a/business/src/main/resources/mapper/ProjectInvestmentFundingMapper.xml b/business/src/main/resources/mapper/ProjectInvestmentFundingMapper.xml index fbe5946..c894c7c 100644 --- a/business/src/main/resources/mapper/ProjectInvestmentFundingMapper.xml +++ b/business/src/main/resources/mapper/ProjectInvestmentFundingMapper.xml @@ -30,9 +30,9 @@ <result column="foreign_investment_total" property="foreignInvestmentTotal" /> <result column="enterprise_self_raised_total" property="enterpriseSelfRaisedTotal" /> <result column="other_investment_total" property="otherInvestmentTotal" /> - <result column="gmt_create_time" property="gmtCreateTime" /> + <result column="gmt_create" property="gmtCreate" /> <result column="create_by" property="createBy" /> - <result column="gmt_update_time" property="gmtUpdateTime" /> + <result column="gmt_update" property="gmtUpdate" /> <result column="update_by" property="updateBy" /> </resultMap> @@ -70,9 +70,9 @@ TPIF.foreign_investment_total, TPIF.enterprise_self_raised_total, TPIF.other_investment_total, - TPIF.gmt_create_time, + TPIF.gmt_create, TPIF.create_by, - TPIF.gmt_update_time, + TPIF.gmt_update, TPIF.update_by, TPIF.id FROM @@ -110,9 +110,9 @@ TPIF.foreign_investment_total, TPIF.enterprise_self_raised_total, TPIF.other_investment_total, - TPIF.gmt_create_time, + TPIF.gmt_create, TPIF.create_by, - TPIF.gmt_update_time, + TPIF.gmt_update, TPIF.update_by, TPIF.id FROM diff --git a/business/src/main/resources/mapper/ProjectInvestmentInfoMapper.xml b/business/src/main/resources/mapper/ProjectInvestmentInfoMapper.xml index e9270c7..3ed4a4d 100644 --- a/business/src/main/resources/mapper/ProjectInvestmentInfoMapper.xml +++ b/business/src/main/resources/mapper/ProjectInvestmentInfoMapper.xml @@ -19,9 +19,9 @@ <result column="use_earth" property="useEarth" /> <result column="content_scale" property="contentScale" /> <result column="code" property="code" /> - <result column="gmt_create_time" property="gmtCreateTime" /> + <result column="gmt_create" property="gmtCreate" /> <result column="create_by" property="createBy" /> - <result column="gmt_update_time" property="gmtUpdateTime" /> + <result column="gmt_update" property="gmtUpdate" /> <result column="update_by" property="updateBy" /> </resultMap> @@ -43,9 +43,9 @@ TPII.use_earth, TPII.content_scale, TPII.code, - TPII.gmt_create_time, + TPII.gmt_create, TPII.create_by, - TPII.gmt_update_time, + TPII.gmt_update, TPII.update_by, TPII.id FROM @@ -72,9 +72,9 @@ TPII.use_earth, TPII.content_scale, TPII.code, - TPII.gmt_create_time, + TPII.gmt_create, TPII.create_by, - TPII.gmt_update_time, + TPII.gmt_update, TPII.update_by, TPII.id FROM diff --git a/business/src/main/resources/mapper/ProjectUnitRegistrationInfoMapper.xml b/business/src/main/resources/mapper/ProjectUnitRegistrationInfoMapper.xml index e72c4c9..768154d 100644 --- a/business/src/main/resources/mapper/ProjectUnitRegistrationInfoMapper.xml +++ b/business/src/main/resources/mapper/ProjectUnitRegistrationInfoMapper.xml @@ -26,8 +26,8 @@ <result column="email" property="email" /> <result column="create_by" property="createBy" /> <result column="update_by" property="updateBy" /> - <result column="gmt_create_time" property="gmtCreateTime" /> - <result column="gmt_update_time" property="gmtUpdateTime" /> + <result column="gmt_create" property="gmtCreateTime" /> + <result column="gmt_update" property="gmtUpdateTime" /> </resultMap> @@ -60,8 +60,8 @@ TPURI.email, TPURI.create_by, TPURI.update_by, - TPURI.gmt_create_time, - TPURI.gmt_update_time, + TPURI.gmt_create, + TPURI.gmt_update, TPURI.id FROM t_project_unit_registration_info TPURI @@ -94,8 +94,8 @@ TPURI.email, TPURI.create_by, TPURI.update_by, - TPURI.gmt_create_time, - TPURI.gmt_update_time, + TPURI.gmt_create, + TPURI.gmt_update, TPURI.id FROM t_project_unit_registration_info TPURI diff --git a/common/src/main/java/com/ycl/common/utils/excel/OutputExcelUtils.java b/common/src/main/java/com/ycl/common/utils/excel/OutputExcelUtils.java index b1d2fb8..cc41e66 100644 --- a/common/src/main/java/com/ycl/common/utils/excel/OutputExcelUtils.java +++ b/common/src/main/java/com/ycl/common/utils/excel/OutputExcelUtils.java @@ -120,7 +120,7 @@ } } - private static void deleteDirectoryOrFile(File file) { + public static void deleteDirectoryOrFile(File file) { if (ObjectUtil.isNull(file)) { return; } -- Gitblit v1.8.0