From 459c3ba8da5f507c075276e96a6a92fe5f787748 Mon Sep 17 00:00:00 2001 From: caihaohan Date: Tue, 25 Jun 2024 18:02:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B3=95=E8=A7=84=E7=AC=A6=E5=90=88?= =?UTF-8?q?=E6=80=A7=E8=AF=84=E4=BC=B0-=E4=B8=8D=E7=AC=A6=E5=90=88?= =?UTF-8?q?=E9=A1=B9-=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LawsEvaluationNotMetController.java | 31 +++++------ .../entity/LawsEvaluationNotMetLibrary.java | 17 +++++- .../ILawsEvaluationNotMetLibraryService.java | 9 ++- ...awsEvaluationNotMetLibraryServiceImpl.java | 55 +++++++++++++++++-- 4 files changed, 87 insertions(+), 25 deletions(-) diff --git a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsEvaluationNotMetController.java b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsEvaluationNotMetController.java index f19074c3..eb77b06b 100644 --- a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsEvaluationNotMetController.java +++ b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/controller/LawsEvaluationNotMetController.java @@ -9,8 +9,6 @@ import com.jero.common.system.base.controller.JeroController; import com.jero.modules.assessmentLibrary.entity.LawsEvaluationNotMetLibrary; import com.jero.modules.assessmentLibrary.service.ILawsEvaluationNotMetLibraryService; import com.jero.modules.projectLibrary.common.AssessCommon; -import com.jero.modules.projectLibrary.entity.LawsEvaluationNotMet; -import com.jero.modules.projectLibrary.service.ILawsEvaluationNotMetService; import com.jero.modules.system.vo.IdsMapBody; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -23,6 +21,7 @@ import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.Arrays; import java.util.List; @@ -37,10 +36,7 @@ import java.util.List; @RestController @RequestMapping("/assessment/lawsEvaluationNotMet") @Slf4j -public class LawsEvaluationNotMetController extends JeroController { - - @Resource - private ILawsEvaluationNotMetService lawsEvaluationNotMetService; +public class LawsEvaluationNotMetController extends JeroController { @Resource private ILawsEvaluationNotMetLibraryService lawsEvaluationNotMetLibraryService; @@ -54,16 +50,15 @@ public class LawsEvaluationNotMetController extends JeroController> queryPageList(LawsEvaluationNotMetLibrary lawsEvaluationNotMet, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, - @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, - HttpServletRequest req) { - IPage pageList = lawsEvaluationNotMetLibraryService.queryPage(lawsEvaluationNotMet, pageNo, pageSize, req); + @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) { + IPage pageList = lawsEvaluationNotMetLibraryService.queryPage(lawsEvaluationNotMet, pageNo, pageSize); return Result.OK(pageList); } /** * 批量关闭 */ - @RequiresPermissions("inconformityItem:batchClose") + @RequiresPermissions("lawsEvaluationNotMet:batchClose") @AutoLog(value = "不符合项-批量关闭") @ApiOperation(value="不符合项-批量关闭", notes="项目库-批量关闭") @PostMapping(value = "/batchClose") @@ -77,14 +72,14 @@ public class LawsEvaluationNotMetController extends JeroController ids) { - List notMets = lawsEvaluationNotMetService.listByIds(ids); - for (LawsEvaluationNotMet notMet : notMets) { - String state = notMet.getState(); + List notMets = lawsEvaluationNotMetLibraryService.listByIds(ids); + for (LawsEvaluationNotMetLibrary notMet : notMets) { + String state = notMet.getRectifyStatus(); //判断是否是待整改,超期,警示 if (!state.equals(AssessCommon.TO_BE_RECTIFIED) && !state.equals(AssessCommon.WARNING) @@ -98,10 +93,12 @@ public class LawsEvaluationNotMetController extends JeroController queryPage(LawsEvaluationNotMetLibrary lawsEvaluationNotMet, Integer pageNo, Integer pageSize, HttpServletRequest req); + IPage queryPage(LawsEvaluationNotMetLibrary lawsEvaluationNotMet, Integer pageNo, Integer pageSize); + void batchClose(List ids); + + void export(HttpServletResponse response, LawsEvaluationNotMetLibrary lawsEvaluationNotMet, String fileName, String sheetName); } diff --git a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/impl/LawsEvaluationNotMetLibraryServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/impl/LawsEvaluationNotMetLibraryServiceImpl.java index fecdcd43..d769ff9e 100644 --- a/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/impl/LawsEvaluationNotMetLibraryServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/assessmentLibrary/service/impl/LawsEvaluationNotMetLibraryServiceImpl.java @@ -1,21 +1,29 @@ package com.jero.modules.assessmentLibrary.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.jero.common.system.query.QueryGenerator; -import com.jero.modules.assessmentLibrary.entity.LawsConformityAssessmentLibrary; +import com.jero.common.exception.JeroBootException; import com.jero.modules.assessmentLibrary.entity.LawsEvaluationNotMetLibrary; import com.jero.modules.assessmentLibrary.mapper.LawsEvaluationNotMetLibraryMapper; import com.jero.modules.assessmentLibrary.service.ILawsEvaluationNotMetLibraryService; +import com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardPlanVo; +import com.jero.modules.projectLibrary.common.AssessCommon; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.ss.usermodel.Workbook; +import org.jeecgframework.poi.excel.ExcelExportUtil; +import org.jeecgframework.poi.excel.entity.ExportParams; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.List; /** * @author ThinkBook @@ -31,7 +39,7 @@ public class LawsEvaluationNotMetLibraryServiceImpl extends ServiceImpl queryPage(LawsEvaluationNotMetLibrary lawsEvaluationNotMet, Integer pageNo, Integer pageSize, HttpServletRequest req) { + public IPage queryPage(LawsEvaluationNotMetLibrary lawsEvaluationNotMet, Integer pageNo, Integer pageSize) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.like(StringUtils.isNotBlank(lawsEvaluationNotMet.getStandardNumber()), "d.standard_number", lawsEvaluationNotMet.getStandardNumber()); @@ -50,6 +58,45 @@ public class LawsEvaluationNotMetLibraryServiceImpl extends ServiceImpl page = new Page<>(pageNo, pageSize); return notMetMapper.pageList(page, queryWrapper, lawsEvaluationNotMet); } + + @Override + public void batchClose(List ids) { + if (ids == null || ids.isEmpty()) { + return; + } + LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); + wrapper.set(LawsEvaluationNotMetLibrary::getRectifyStatus, AssessCommon.CLOSED); + wrapper.in(LawsEvaluationNotMetLibrary::getId, ids); + update(wrapper); + } + + @Override + public void export(HttpServletResponse response, LawsEvaluationNotMetLibrary lawsEvaluationNotMet, String fileName, String sheetName) { + try { + // 获取数据 + IPage lawsEvaluationNotMets = this.queryPage(lawsEvaluationNotMet, 1, Integer.MAX_VALUE); + List records = lawsEvaluationNotMets.getRecords(); + + // 设置导出参数 + ExportParams exportParams = new ExportParams(null, sheetName); // 可以为标题添加更多的配置 + Workbook workbook = ExcelExportUtil.exportExcel(exportParams, EnterpriseStandardPlanVo.class, records); + + // 设置响应头和内容类型 + response.setContentType("application/vnd.ms-excel;charset=UTF-8"); // 显式设置字符编码 + response.setCharacterEncoding("UTF-8"); // 这行确保响应流使用UTF-8编码 + + // 处理文件名乱码问题 + String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()).replace("+", "%20"); + response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName + ".xls"); + + // 写出到响应流 + workbook.write(response.getOutputStream()); + workbook.close(); + } catch (Exception e) { + log.error("导出excel异常", e); + throw new JeroBootException("导出excel异常", e); + } + } }