From 5ed3405a0156f76decc081c9f1d65d2f44f1ad8c Mon Sep 17 00:00:00 2001 From: 龚焕茏 <2842157468@qq.com> Date: 星期二, 30 七月 2024 13:58:19 +0800 Subject: [PATCH] feat:核算报告导出 --- ycl-pojo/src/main/java/com/ycl/platform/domain/excel/CalculateExport.java | 63 +++++++++++++++++++++ ycl-server/src/main/java/com/ycl/platform/controller/CalculateReportController.java | 26 ++++---- ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateReportServiceImpl.java | 51 ++++++++++------- ycl-server/src/main/resources/mapper/zgyw/CalculateReportMapper.xml | 12 ++++ ycl-server/src/main/java/com/ycl/platform/mapper/CalculateReportMapper.java | 14 +++- ycl-server/src/main/java/com/ycl/platform/service/CalculateReportService.java | 8 ++ 6 files changed, 136 insertions(+), 38 deletions(-) diff --git a/ycl-pojo/src/main/java/com/ycl/platform/domain/excel/CalculateExport.java b/ycl-pojo/src/main/java/com/ycl/platform/domain/excel/CalculateExport.java new file mode 100644 index 0000000..bd6aca7 --- /dev/null +++ b/ycl-pojo/src/main/java/com/ycl/platform/domain/excel/CalculateExport.java @@ -0,0 +1,63 @@ +package com.ycl.platform.domain.excel; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.*; +import com.alibaba.excel.enums.BooleanEnum; +import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum; +import com.alibaba.excel.enums.poi.VerticalAlignmentEnum; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author gonghl + * @since 2024/7/30 涓婂崍 10:01 + */ +@Data +@ColumnWidth(20) +@HeadRowHeight(30) +@ContentRowHeight(30) +@HeadStyle(fillForegroundColor = 64) +@ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER) +@ContentFontStyle(fontHeightInPoints = 18, bold = BooleanEnum.TRUE, fontName = "瀹嬩綋") +@HeadFontStyle(fontHeightInPoints = 18, bold = BooleanEnum.TRUE, fontName = "瀹嬩綋") +public class CalculateExport { + + /** + * 瑙勫垯鍚嶇О + */ + @ExcelProperty({"鑷础甯傚叕鍏辫棰戠洃鎺х郴缁熺画缁村悎鍚�", "瑙勫垯鍚嶇О"}) + @ColumnWidth(40) + private String ruleName; + + /** + * 鏁伴噺 + */ + @ExcelProperty({"鑷础甯傚叕鍏辫棰戠洃鎺х郴缁熺画缁村悎鍚�", "鏁伴噺"}) + private Integer num; + + /** + * 閲戦 + */ + @ExcelProperty({"鑷础甯傚叕鍏辫棰戠洃鎺х郴缁熺画缁村悎鍚�", "閲戦"}) + private BigDecimal money; + + /** + * 鍒嗘暟 + */ + @ExcelProperty({"鑷础甯傚叕鍏辫棰戠洃鎺х郴缁熺画缁村悎鍚�", "鍒嗘暟"}) + private Integer score; + + /** + * 鍓╀綑鍒嗘暟 + */ + @ExcelProperty({"鑷础甯傚叕鍏辫棰戠洃鎺х郴缁熺画缁村悎鍚�", "鍓╀綑鍒嗘暟"}) + private Integer surplusScore; + + /** + * 鍚堣 + */ + @ExcelProperty({"鑷础甯傚叕鍏辫棰戠洃鎺х郴缁熺画缁村悎鍚�", "鍚堣"}) + private BigDecimal total; + +} diff --git a/ycl-server/src/main/java/com/ycl/platform/controller/CalculateReportController.java b/ycl-server/src/main/java/com/ycl/platform/controller/CalculateReportController.java index f6049ca..7c23eea 100644 --- a/ycl-server/src/main/java/com/ycl/platform/controller/CalculateReportController.java +++ b/ycl-server/src/main/java/com/ycl/platform/controller/CalculateReportController.java @@ -1,22 +1,15 @@ package com.ycl.platform.controller; import com.ycl.platform.domain.form.CalculateReportBackfillForm; -import com.ycl.platform.domain.param.HK.CoordinateByAreaParam; -import com.ycl.system.domain.group.Update; -import com.ycl.system.domain.group.Add; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import lombok.RequiredArgsConstructor; -import java.util.List; -import org.springframework.validation.annotation.Validated; -import jakarta.validation.constraints.NotEmpty; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; +import com.ycl.platform.domain.query.CalculateReportQuery; import com.ycl.platform.service.CalculateReportService; import com.ycl.system.Result; -import com.ycl.platform.domain.form.CalculateReportForm; -import com.ycl.platform.domain.query.CalculateReportQuery; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; /** @@ -62,4 +55,11 @@ return calculateReportService.updatePublishStatus(reportId); } + @PostMapping("/export") + @ApiOperation(value = "瀵煎嚭", notes = "瀵煎嚭") + @PreAuthorize("@ss.hasPermi('system:calculate:report:export')") + public void export(Integer contractId, HttpServletResponse response) { + calculateReportService.export(contractId, response); + } + } diff --git a/ycl-server/src/main/java/com/ycl/platform/mapper/CalculateReportMapper.java b/ycl-server/src/main/java/com/ycl/platform/mapper/CalculateReportMapper.java index b8d17a4..8b5e223 100644 --- a/ycl-server/src/main/java/com/ycl/platform/mapper/CalculateReportMapper.java +++ b/ycl-server/src/main/java/com/ycl/platform/mapper/CalculateReportMapper.java @@ -1,16 +1,16 @@ package com.ycl.platform.mapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.ycl.platform.domain.entity.CalculateReport; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ycl.platform.domain.excel.CalculateExport; import com.ycl.platform.domain.query.CalculateReportQuery; -import com.ycl.platform.domain.vo.CalculateRecordVO; import com.ycl.platform.domain.vo.CalculateReportDetailVO; import com.ycl.platform.domain.vo.CalculateReportVO; -import com.ycl.platform.domain.form.CalculateReportForm; -import java.util.List; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 鏍哥畻鎶ュ憡 Mapper 鎺ュ彛 @@ -37,4 +37,10 @@ * @return */ CalculateReportDetailVO getById(@Param("id") Long id); + + /** + * 瀵煎嚭鏁版嵁 + * @return 鏁版嵁 + */ + List<CalculateExport> exportData(Integer contractId); } diff --git a/ycl-server/src/main/java/com/ycl/platform/service/CalculateReportService.java b/ycl-server/src/main/java/com/ycl/platform/service/CalculateReportService.java index 2281a39..96d9dd8 100644 --- a/ycl-server/src/main/java/com/ycl/platform/service/CalculateReportService.java +++ b/ycl-server/src/main/java/com/ycl/platform/service/CalculateReportService.java @@ -6,6 +6,8 @@ import com.ycl.system.Result; import com.ycl.platform.domain.form.CalculateReportForm; import com.ycl.platform.domain.query.CalculateReportQuery; +import jakarta.servlet.http.HttpServletResponse; + import java.util.List; /** @@ -79,4 +81,10 @@ * @return */ Result updatePublishStatus(Long reportId); + + /** + * 瀵煎嚭 + * @param response 鍝嶅簲 + */ + void export(Integer contractId, HttpServletResponse response); } diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateReportServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateReportServiceImpl.java index 8943806..cd1fed3 100644 --- a/ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateReportServiceImpl.java +++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateReportServiceImpl.java @@ -1,40 +1,37 @@ package com.ycl.platform.service.impl; -import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; +import com.alibaba.excel.EasyExcel; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ycl.platform.domain.entity.CalculateRecord; import com.ycl.platform.domain.entity.CalculateReport; +import com.ycl.platform.domain.excel.CalculateExport; import com.ycl.platform.domain.form.CalculateReportBackfillForm; -import com.ycl.platform.domain.vo.CalculateRecordVO; +import com.ycl.platform.domain.form.CalculateReportForm; +import com.ycl.platform.domain.query.CalculateReportQuery; import com.ycl.platform.domain.vo.CalculateReportDetailVO; +import com.ycl.platform.domain.vo.CalculateReportVO; import com.ycl.platform.mapper.CalculateRecordMapper; import com.ycl.platform.mapper.CalculateReportMapper; import com.ycl.platform.service.CalculateReportService; import com.ycl.system.Result; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ycl.platform.domain.form.CalculateReportForm; -import com.ycl.platform.domain.vo.CalculateReportVO; -import com.ycl.platform.domain.query.CalculateReportQuery; - -import java.math.BigDecimal; -import java.util.List; - -import com.ycl.utils.SecurityUtils; -import enumeration.general.CalculateReportStatusEnum; -import org.apache.commons.lang3.StringUtils; -import com.baomidou.mybatisplus.core.metadata.IPage; import com.ycl.system.page.PageUtil; -import org.springframework.stereotype.Service; -import org.springframework.security.core.context.SecurityContextHolder; +import enumeration.general.CalculateReportStatusEnum; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; -import java.util.ArrayList; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; -import lombok.RequiredArgsConstructor; -import org.springframework.util.CollectionUtils; /** * 鏍哥畻鎶ュ憡 鏈嶅姟瀹炵幇绫� @@ -198,4 +195,16 @@ baseMapper.updateById(report); return Result.ok("鎿嶄綔鎴愬姛"); } + + @Override + @SneakyThrows + public void export(Integer contractId, HttpServletResponse response) { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String fileName = URLEncoder.encode("鏍哥畻鎶ュ憡", StandardCharsets.UTF_8).replace("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + EasyExcel.write(response.getOutputStream(), CalculateExport.class) + .sheet("鏍哥畻鎶ュ憡") + .doWrite(baseMapper.exportData(contractId)); + } } diff --git a/ycl-server/src/main/resources/mapper/zgyw/CalculateReportMapper.xml b/ycl-server/src/main/resources/mapper/zgyw/CalculateReportMapper.xml index 21c56ba..a5e761d 100644 --- a/ycl-server/src/main/resources/mapper/zgyw/CalculateReportMapper.xml +++ b/ycl-server/src/main/resources/mapper/zgyw/CalculateReportMapper.xml @@ -20,6 +20,7 @@ <select id="page" resultMap="BaseResultMap"> SELECT + tcr.contract_id, tyu.unit_name, tc.name, tcr.id, @@ -99,4 +100,15 @@ WHERE tcr.id = #{id} </select> + <select id="exportData" resultType="com.ycl.platform.domain.excel.CalculateExport"> + SELECT + SUBSTRING_INDEX(rule_name, '/', 1) AS rule_name, + COUNT(*) AS num, + SUM(score) AS score, + (100 - SUM(score)) AS surplusScore + FROM t_contract_score + WHERE contract_id = #{contractId} AND auditing_status = 'PASS' AND deleted = 0 + GROUP BY SUBSTRING_INDEX(rule_name, '/', 1) + </select> + </mapper> -- Gitblit v1.8.0