From 894c720bb812bb2d2a13fe8832a32e07e19b4909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=8C=E5=85=88=E8=88=9C?= <2499071264@qq.com> Date: Tue, 3 Nov 2026 20:35:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E7=A6=8F=E5=88=A92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WelfareSelectionSituationServiceImpl.java | 104 +++++++++++------- .../platform/zhghh5/welfare/mine/list.html | 33 +++--- 2 files changed, 82 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/budwk/app/zhgh/welfare/service/impl/WelfareSelectionSituationServiceImpl.java b/src/main/java/com/budwk/app/zhgh/welfare/service/impl/WelfareSelectionSituationServiceImpl.java index 1c5e0a2..b5b5ba2 100644 --- a/src/main/java/com/budwk/app/zhgh/welfare/service/impl/WelfareSelectionSituationServiceImpl.java +++ b/src/main/java/com/budwk/app/zhgh/welfare/service/impl/WelfareSelectionSituationServiceImpl.java @@ -5,7 +5,6 @@ import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; -import cn.afterturn.easypoi.excel.export.ExcelExportService; import cn.hutool.core.util.StrUtil; import com.budwk.app.base.constant.RoleConstant; import com.budwk.app.base.page.Pagination; @@ -24,6 +23,13 @@ import com.budwk.app.zhgh.welfare.param.WelfareSelectionSituationPageForm; import com.budwk.app.zhgh.welfare.service.WelfareSelectionSituationService; import lombok.extern.slf4j.Slf4j; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.ClientAnchor; +import org.apache.poi.ss.usermodel.Drawing; +import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.nutz.dao.Cnd; import org.nutz.dao.Dao; @@ -232,55 +238,69 @@ public class WelfareSelectionSituationServiceImpl extends BaseServiceImpl optionList = dao().query(WelfareProjectSubjectOption.class, Cnd.where(WelfareProjectSubjectOption::getWelfareId, "=", pageForm.getProjectId()).asc("optionSort")); for (NutMap map : list) { - if (map.get("selectOptionIds") != null){ - String[] selectOptionIds = map.getString("selectOptionIds").split(","); - for (WelfareProjectSubjectOption option : optionList) { - if(Arrays.asList(selectOptionIds).contains(option.getId())){ - map.put(option.getOptionName(), "√"); - } - } - } - if (map.get("userSign") != null){ + if (map.get("userSign") != null) { try { Sys_file file = dao().fetch(Sys_file.class, Cnd.where(Sys_file::getDownloadPath, "=", map.getString("userSign"))); byte[] userSignBytes = SysFileMinIoUtil.getFileBytes(file.getBucket(), file.getStoragePath()); - map.put("userSign", userSignBytes); - }catch (Exception e){ - e.printStackTrace(); - log.error("下载图片失败", e); + BufferedImage image = ImageIO.read(new ByteArrayInputStream(userSignBytes)); + if (image != null) { + ByteArrayOutputStream png = new ByteArrayOutputStream(); + ImageIO.write(image, "png", png); + map.put("userSign", png.toByteArray()); + } + } catch (Exception e) { + log.error("下载签字图片失败", e); } } } - List> safeList = list.stream().map(nutMap -> { - Map map = new HashMap<>(nutMap); - return map; - }).toList(); - - // 分组 - Map>> listMap = safeList.stream() - .collect(Collectors.groupingBy(n -> (String) n.get("welfareUnionName"))); - - // 构建 Excel 列 - List entities = new ArrayList<>(); - entities.add(new ExcelExportEntity("工号", "loginName", 20)); - entities.add(new ExcelExportEntity("姓名", "userName", 20)); - optionList.forEach(option -> { - entities.add(new ExcelExportEntity(option.getOptionName(), option.getOptionName(), 20)); - }); - ExcelExportEntity userSignEntity = new ExcelExportEntity("签字", "userSign", 20); - userSignEntity.setType(2); - userSignEntity.setExportImageType(2); - entities.add(userSignEntity); - - // 导出 + Map> rowsByUnion = list.stream() + .collect(Collectors.groupingBy(n -> n.getString("welfareUnionName"))); Workbook workbook = new HSSFWorkbook(); - listMap.forEach((k, v) -> { - ExcelExportService service = new ExcelExportService(); - ExportParams exportParams = new ExportParams(); - exportParams.setSheetName(k); - exportParams.setType(ExcelType.HSSF); - service.createSheetForMap(workbook, exportParams, entities, v); + if (rowsByUnion.isEmpty()) { + rowsByUnion.put("领取表", Collections.emptyList()); + } + + CellStyle headerStyle = workbook.createCellStyle(); + Font headerFont = workbook.createFont(); + headerFont.setBold(true); + headerStyle.setFont(headerFont); + + List headers = new ArrayList<>(List.of("工号", "姓名")); + optionList.forEach(option -> headers.add(option.getOptionName())); + headers.add("签字"); + int signColumn = headers.size() - 1; + + rowsByUnion.forEach((unionName, records) -> { + Sheet sheet = workbook.createSheet(unionName); + Row header = sheet.createRow(0); + for (int column = 0; column < headers.size(); column++) { + sheet.setColumnWidth(column, 20 * 256); + Cell cell = header.createCell(column); + cell.setCellValue(headers.get(column)); + cell.setCellStyle(headerStyle); + } + + Drawing drawing = sheet.createDrawingPatriarch(); + for (NutMap record : records) { + Row row = sheet.createRow(sheet.getLastRowNum() + 1); + row.createCell(0).setCellValue(Objects.toString(record.get("loginName"), "")); + row.createCell(1).setCellValue(Objects.toString(record.get("userName"), "")); + Set selectedIds = new HashSet<>(Arrays.asList( + Objects.toString(record.get("selectOptionIds"), "").split(","))); + for (int i = 0; i < optionList.size(); i++) { + row.createCell(i + 2).setCellValue(selectedIds.contains(optionList.get(i).getId()) ? "√" : ""); + } + if (record.get("userSign") instanceof byte[] signature) { + row.setHeightInPoints(40); + ClientAnchor anchor = workbook.getCreationHelper().createClientAnchor(); + anchor.setCol1(signColumn); + anchor.setCol2(signColumn + 1); + anchor.setRow1(row.getRowNum()); + anchor.setRow2(row.getRowNum() + 1); + drawing.createPicture(anchor, workbook.addPicture(signature, Workbook.PICTURE_TYPE_PNG)); + } + } }); CommonDownloadUtil.download("领取表.xls", workbook, response); diff --git a/src/main/resources/views/platform/zhghh5/welfare/mine/list.html b/src/main/resources/views/platform/zhghh5/welfare/mine/list.html index dfa3f09..fe8238f 100644 --- a/src/main/resources/views/platform/zhghh5/welfare/mine/list.html +++ b/src/main/resources/views/platform/zhghh5/welfare/mine/list.html @@ -174,7 +174,7 @@ layout("/layouts/platform_h5.html"){ display: flex; min-width: 0; margin-top: 10px; - padding-top: 2px; + padding-top: 10px; align-items: center; border-top: 1px solid #edf1f6; } @@ -194,18 +194,22 @@ layout("/layouts/platform_h5.html"){ } .welfare-list-card__choices .welfare-inline-selection { - width: 82px; - min-width: 82px; - min-height: 112px; - padding: 8px 0; + flex: 0 0 clamp(82px, 31%, 112px); + min-width: 0; + padding: 0; flex-direction: column; align-items: stretch; - border-bottom: 0; + overflow: hidden; + border: 0; + border-radius: 8px; + background: #edf4fc; } .welfare-list-card__choices .welfare-inline-selection__image { - width: 82px; - height: 64px; + display: block; + width: 100%; + height: auto; + aspect-ratio: 4 / 3; margin-right: 0; } @@ -223,19 +227,22 @@ layout("/layouts/platform_h5.html"){ } .welfare-list-card__choices .welfare-inline-selection__image--name span { - display: -webkit-box; + min-width: 0; overflow: hidden; text-overflow: ellipsis; - -webkit-box-orient: vertical; - -webkit-line-clamp: 2; + white-space: nowrap; } .welfare-list-card__choices .welfare-inline-selection__content { - margin-top: 6px; + width: 100%; + padding: 3px 6px; + box-sizing: border-box; + text-align: center; } .welfare-list-card__choices .welfare-inline-selection__name { font-weight: 400; + line-height: 16px; } .welfare-list-card__choices .welfare-inline-selection__meta { @@ -486,7 +493,7 @@ layout("/layouts/platform_h5.html"){ .welfare-inline-selection__name { overflow: hidden; color: #263548; - font-size: 14px; + font-size: 12px; line-height: 21px; font-weight: 600; text-overflow: ellipsis;