From ceec388f5f5142863425a30875dfc42991a62cd9 Mon Sep 17 00:00:00 2001 From: lcj <2331845269@qq.com> Date: Mon, 10 Nov 2025 10:58:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=BD=E5=B7=A5=E4=BA=A7=E5=80=BC=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dromara/common/excel/utils/ExcelUtil.java | 13 ++-- .../OutConstructionValueRangeController.java | 60 ++++++++++++++++++- .../service/IOutConstructionValueService.java | 7 +++ .../impl/OutConstructionValueServiceImpl.java | 4 ++ 4 files changed, 74 insertions(+), 10 deletions(-) diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java b/xinnengyuan/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java index 0e73e4d3..70db2b06 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java +++ b/xinnengyuan/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java @@ -19,7 +19,6 @@ import org.dromara.common.core.utils.file.FileUtils; import org.dromara.common.excel.convert.ExcelBigNumberConvert; import org.dromara.common.excel.core.*; import org.dromara.common.excel.handler.DataWriteHandler; -import org.springframework.http.HttpHeaders; import java.io.IOException; import java.io.InputStream; @@ -208,12 +207,12 @@ public class ExcelUtil { /** * 导出多sheet excel(增强版,解决XML安全问题) * - * @param sheetData 多个sheet的数据 - * @param sheetNames 多个sheet的名称 - * @param clazz 实体类 - * @param optionsList 级联下拉选内容列表 + * @param sheetData 多个sheet的数据 + * @param sheetNames 多个sheet的名称 + * @param clazz 实体类 + * @param optionsList 级联下拉选内容列表 */ - public static void exportMultiSheetExcelEnhanced(List> sheetData, List sheetNames, Class clazz, List> optionsList,HttpServletResponse response) throws IOException { + public static void exportMultiSheetExcelEnhanced(List> sheetData, List sheetNames, Class clazz, List> optionsList, HttpServletResponse response) throws IOException { resetResponse("file", response); ExcelWriter excelWriter = null; ServletOutputStream os = response.getOutputStream(); @@ -493,6 +492,4 @@ public class ExcelUtil { } - - } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/controller/OutConstructionValueRangeController.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/controller/OutConstructionValueRangeController.java index d4c6b327..bf246ab6 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/controller/OutConstructionValueRangeController.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/controller/OutConstructionValueRangeController.java @@ -1,11 +1,15 @@ package org.dromara.out.controller; import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.domain.R; +import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.validate.AddGroup; import org.dromara.common.core.validate.EditGroup; import org.dromara.common.excel.utils.ExcelUtil; @@ -15,14 +19,24 @@ import org.dromara.common.log.enums.BusinessType; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.web.core.BaseController; +import org.dromara.out.domain.OutConstructionValue; +import org.dromara.out.domain.OutConstructionValueRange; import org.dromara.out.domain.bo.OutConstructionValueRangeBo; import org.dromara.out.domain.vo.OutConstructionAllValueRangeVo; import org.dromara.out.domain.vo.OutConstructionValueRangeVo; +import org.dromara.out.domain.vo.OutConstructionValueVo; import org.dromara.out.service.IOutConstructionValueRangeService; +import org.dromara.out.service.IOutConstructionValueService; +import org.springframework.beans.BeanUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.io.IOException; +import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; /** * 施工产值范围 @@ -30,6 +44,7 @@ import java.util.List; * @author lilemy * @date 2025-09-25 */ +@Slf4j @Validated @RequiredArgsConstructor @RestController @@ -38,6 +53,8 @@ public class OutConstructionValueRangeController extends BaseController { private final IOutConstructionValueRangeService outConstructionValueRangeService; + private final IOutConstructionValueService outConstructionValueService; + /** * 查询施工产值范围列表 */ @@ -54,8 +71,47 @@ public class OutConstructionValueRangeController extends BaseController { @Log(title = "施工产值范围", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(OutConstructionValueRangeBo bo, HttpServletResponse response) { - List list = outConstructionValueRangeService.queryList(bo); - ExcelUtil.exportExcel(list, "施工产值范围", OutConstructionValueRangeVo.class, response); + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(bo.getProjectId() != null, OutConstructionValue::getProjectId, bo.getProjectId()); + if (bo.getStartDate() != null && bo.getEndDate() != null) { + lqw.between(OutConstructionValue::getReportDate, bo.getStartDate(), bo.getEndDate()); + } else if (bo.getStartDate() != null) { + lqw.ge(OutConstructionValue::getReportDate, bo.getStartDate()); + } else if (bo.getEndDate() != null) { + lqw.le(OutConstructionValue::getReportDate, bo.getEndDate()); + } + List list = outConstructionValueService.list(lqw); + if (CollUtil.isEmpty(list)) { + return; + } + List valueVoList = new ArrayList<>(list.stream().map(value -> { + OutConstructionValueVo vo = new OutConstructionValueVo(); + BeanUtils.copyProperties(value, vo); + return vo; + }).toList()); + outConstructionValueService.supplementaryData(valueVoList); + Set weekIds = valueVoList.stream().map(OutConstructionValueVo::getRangeId).collect(Collectors.toSet()); + List ranges = outConstructionValueRangeService.listByIds(weekIds); + Map> rangeMap = ranges.stream() + .collect(Collectors.groupingBy(OutConstructionValueRange::getId)); + Map> map = valueVoList.stream() + .collect(Collectors.groupingBy(OutConstructionValueVo::getRangeId)); + List> valueList = new ArrayList<>(); + List nameList = new ArrayList<>(); + for (Map.Entry> entry : map.entrySet()) { + List valueVos = entry.getValue(); + valueList.add(valueVos); + if (rangeMap.containsKey(entry.getKey())) { + OutConstructionValueRange range = rangeMap.get(entry.getKey()).getFirst(); + nameList.add(range.getStartDate() + " - " + range.getEndDate()); + } + } + try { + ExcelUtil.exportMultiSheetExcelEnhanced(valueList, nameList, OutConstructionValueVo.class, null, response); + } catch (IOException e) { + log.error("导出失败", e); + throw new ServiceException("导出失败"); + } } /** diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/service/IOutConstructionValueService.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/service/IOutConstructionValueService.java index dbe452fe..9e3494ba 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/service/IOutConstructionValueService.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/service/IOutConstructionValueService.java @@ -103,4 +103,11 @@ public interface IOutConstructionValueService extends IService list); } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/service/impl/OutConstructionValueServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/service/impl/OutConstructionValueServiceImpl.java index c21d2432..81f29acc 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/service/impl/OutConstructionValueServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/out/service/impl/OutConstructionValueServiceImpl.java @@ -346,7 +346,11 @@ public class OutConstructionValueServiceImpl extends ServiceImpl list) { + if (CollUtil.isEmpty(list)) { + return; + } for (OutConstructionValueVo vo : list) { getName(vo); }