From 6aa4a5eae7e33d61f10616643ad0a18486cc4bc2 Mon Sep 17 00:00:00 2001 From: hongchao <3228015117@qq.com> Date: Thu, 18 Dec 2025 14:43:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sgzb/material/config/PoiOutPage.java | 77 +++++++++++++++---- .../sgzb/material/domain/SecondLotConfig.java | 2 + .../material/domain/SecondaryWarehouse.java | 2 + .../mapper/SecondaryWarehouseMapper.java | 3 + .../impl/SecondaryWarehouseServiceImpl.java | 18 +++++ .../material/SecondaryWarehouseMapper.xml | 3 + 6 files changed, 90 insertions(+), 15 deletions(-) diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/PoiOutPage.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/PoiOutPage.java index df7174d..472737f 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/PoiOutPage.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/PoiOutPage.java @@ -9,6 +9,7 @@ import org.apache.poi.ss.util.RegionUtil; import java.math.BigDecimal; import java.math.RoundingMode; +import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -314,11 +315,11 @@ public class PoiOutPage { row.setHeightInPoints(30); HSSFCell cell1 = row.createCell(0); cell1.setCellStyle(headerStyleNoSide); - cell1.setCellValue("主管:"); + cell1.setCellValue("专责:"); HSSFCell cell2 = row.createCell(4); cell2.setCellStyle(headerStyleNoSide); - cell2.setCellValue("审核:"); + cell2.setCellValue("班长审核:"); HSSFCell cell3 = row.createCell(8); cell3.setCellStyle(headerStyleNoSide); @@ -801,7 +802,8 @@ public class PoiOutPage { int totalCostColumnIndex = list.size() - 3; HSSFCell cell1 = row.createCell(totalCostColumnIndex); cell1.setCellStyle(headerStyle); - cell1.setCellValue(String.format("%.2f", totalCost)); + DecimalFormat decimalFormat = new DecimalFormat("#,##0.00"); + cell1.setCellValue(decimalFormat.format(totalCost.doubleValue())); // 设置边框样式,覆盖整个合并区域 CellRangeAddress cellRange2 = new CellRangeAddress(rowNum - 1, rowNum - 1, list.size() - 3, list.size() - 2); // 修改为包含至少两个单元格 RegionUtil.setBorderTop(BorderStyle.THIN, cellRange2, sheet); @@ -813,7 +815,7 @@ public class PoiOutPage { int totalCostColumnIndexTwo = list.size() - 2; HSSFCell cell2 = row.createCell(totalCostColumnIndexTwo); cell2.setCellStyle(headerStyle); - cell2.setCellValue(String.format("%.2f", totalCostReal)); + cell2.setCellValue(decimalFormat.format(totalCostReal.doubleValue())); int totalCostColumnIndexThree = list.size() - 1; @@ -1025,25 +1027,35 @@ public class PoiOutPage { // 第一行:结算单位 HSSFRow row1 = sheet.createRow(rowNum++); row1.setHeightInPoints(30); + + // 创建对齐样式 - 保留原有标题样式的其他属性 + HSSFCellStyle rightAlignedStyle = sheet.getWorkbook().createCellStyle(); + rightAlignedStyle.cloneStyleFrom(titleStyle); + rightAlignedStyle.setAlignment(HorizontalAlignment.RIGHT); + + HSSFCellStyle leftAlignedStyle = sheet.getWorkbook().createCellStyle(); + leftAlignedStyle.cloneStyleFrom(titleStyle); + leftAlignedStyle.setAlignment(HorizontalAlignment.LEFT); + // bug修复:修改合并单元格区域,确保包含两个或以上单元格 sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, 1)); // 结算单位: 占8 HSSFCell cell1 = row1.createCell(0); - cell1.setCellStyle(titleStyle); + cell1.setCellStyle(rightAlignedStyle); cell1.setCellValue("领用单位:"); sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 2, (short) (nColumn - 7))); // unitName 占剩余的22 HSSFCell cell2 = row1.createCell(2); - cell2.setCellStyle(titleStyle); + cell2.setCellStyle(leftAlignedStyle); cell2.setCellValue(unitName); sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, (short) (nColumn - 6), (short) (nColumn - 5))); // 月结月份: 占8 HSSFCell cellMonth = row1.createCell(6); - cellMonth.setCellStyle(titleStyle); + cellMonth.setCellStyle(rightAlignedStyle); cellMonth.setCellValue("月结月份:"); sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, (short) (nColumn - 4), (short) (nColumn - 1))); // 月份值 占剩余的22 HSSFCell cellMonthTwo = row1.createCell(8); - cellMonthTwo.setCellStyle(titleStyle); + cellMonthTwo.setCellStyle(leftAlignedStyle); try { SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM"); SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy年M月"); @@ -1059,24 +1071,24 @@ public class PoiOutPage { row2.setHeightInPoints(30); sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, 1)); // 工程名称: 占8 HSSFCell cell3 = row2.createCell(0); - cell3.setCellStyle(titleStyle); + cell3.setCellStyle(rightAlignedStyle); cell3.setCellValue("工程名称:"); sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 2, (short) (nColumn - 7))); // projectName 占剩余的22 HSSFCell cell4 = row2.createCell(2); - cell4.setCellStyle(titleStyle); + cell4.setCellStyle(leftAlignedStyle); cell4.setCellValue(projectName); sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, (short) (nColumn - 6), (short) (nColumn - 5))); // 费用承担方: 占8 HSSFCell cell5 = row2.createCell(6); - cell5.setCellStyle(titleStyle); + cell5.setCellStyle(rightAlignedStyle); cell5.setCellValue("费用承担方:"); sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, (short) (nColumn - 4), (short) (nColumn - 1))); // 费用承担方值 占剩余的22 HSSFCell cell6 = row2.createCell(8); // 创建红色字体样式 HSSFCellStyle redStyle = sheet.getWorkbook().createCellStyle(); - redStyle.cloneStyleFrom(titleStyle); // 复制原有样式 + redStyle.cloneStyleFrom(leftAlignedStyle); // 复制原有样式 HSSFFont font = sheet.getWorkbook().createFont(); font.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex()); // 设置字体颜色为红色 font.setFontHeightInPoints((short) 12); @@ -1084,9 +1096,9 @@ public class PoiOutPage { cell6.setCellStyle(redStyle); // 应用红色字体样式 if(type==1){ - cell6.setCellValue("01(项目)"); + cell6.setCellValue("01"); }else{ - cell6.setCellValue("03(分包)"); + cell6.setCellValue("03"); } @@ -1362,7 +1374,42 @@ public class PoiOutPage { integerStyle.cloneStyleFrom(contentStyle); integerStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0")); cell.setCellStyle(integerStyle); - } else { + } + // 如果是天数栏,设置整数格式(假设天数列为第5列,索引4,根据实际情况调整) + else if (j == 4 || j == 8) { + HSSFCellStyle integerStyle = sheet.getWorkbook().createCellStyle(); + integerStyle.cloneStyleFrom(contentStyle); + integerStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0")); + cell.setCellStyle(integerStyle); + + // 处理天数数据,四舍五入取整 + if (data != null && isNumeric(data)) { + double value = Double.parseDouble(data.toString()); + cell.setCellValue((int)Math.round(value)); // 四舍五入为整数 + } else { + cell.setCellValue(""); + } + continue; // 已手动设置值,跳过后续setCellData调用 + } + // 如果是金额列(j == 10),设置千位符格式 + else if (j == 10) { + HSSFCellStyle numberStyle = sheet.getWorkbook().createCellStyle(); + numberStyle.cloneStyleFrom(contentStyle); + // 设置千位符格式,保留两位小数 + DataFormat format = sheet.getWorkbook().createDataFormat(); + numberStyle.setDataFormat(format.getFormat("#,##0.00")); + cell.setCellStyle(numberStyle); + + // 处理金额数据 + if (data != null && isNumeric(data)) { + double value = Double.parseDouble(data.toString()); + cell.setCellValue(value); + } else { + cell.setCellValue(""); + } + continue; // 已手动设置值,跳过后续setCellData调用 + } + else { cell.setCellStyle(contentStyle); } diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/SecondLotConfig.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/SecondLotConfig.java index ade5f98..bf5e4fb 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/SecondLotConfig.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/SecondLotConfig.java @@ -25,4 +25,6 @@ public class SecondLotConfig { private String updateTime; // 部门id private Long deptId; + + private Long parentId; } diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/SecondaryWarehouse.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/SecondaryWarehouse.java index 6f5f115..07cdebf 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/SecondaryWarehouse.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/SecondaryWarehouse.java @@ -148,4 +148,6 @@ public class SecondaryWarehouse { */ private Integer teamGroupId; + private Long parentId; + } diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/SecondaryWarehouseMapper.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/SecondaryWarehouseMapper.java index 303d4a2..44be301 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/SecondaryWarehouseMapper.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/SecondaryWarehouseMapper.java @@ -3,6 +3,7 @@ package com.bonus.sgzb.material.mapper; import com.bonus.sgzb.base.api.domain.MaMachine; import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.material.domain.*; +import com.bonus.sgzb.system.api.domain.SysDept; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -102,4 +103,6 @@ public interface SecondaryWarehouseMapper { * @return */ TeamLeaseInfo getParentIdByMaIdAndTypeId(TeamLeaseInfo teamLeaseInfo); + + SysDept selectDeptById(Long deptId); } diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/SecondaryWarehouseServiceImpl.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/SecondaryWarehouseServiceImpl.java index d2afed3..f0858e8 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/SecondaryWarehouseServiceImpl.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/SecondaryWarehouseServiceImpl.java @@ -6,6 +6,7 @@ import com.bonus.sgzb.common.security.utils.SecurityUtils; import com.bonus.sgzb.material.domain.*; import com.bonus.sgzb.material.mapper.SecondaryWarehouseMapper; import com.bonus.sgzb.material.service.SecondaryWarehouseService; +import com.bonus.sgzb.system.api.domain.SysDept; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -96,6 +97,12 @@ public class SecondaryWarehouseServiceImpl implements SecondaryWarehouseService public List listConfig(SecondLotConfig bean) { if (!SecurityUtils.getLoginUser().getRoles().contains("admin") && !SecurityUtils.getLoginUser().getRoles().contains("sysadmin")) { bean.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId()); + + //查询祖级以便获取上级部门id + SysDept dept = mapper.selectDeptById(SecurityUtils.getLoginUser().getSysUser().getDeptId()); + if (dept != null && StringUtils.isNotBlank(dept.getAncestors()) && StringUtils.countMatches(dept.getAncestors(), ",") == 2) { + bean.setDeptId(dept.getParentId()); + } } return mapper.listConfig(bean); } @@ -104,6 +111,12 @@ public class SecondaryWarehouseServiceImpl implements SecondaryWarehouseService public List listTeamGroup(TeamGroup bean) { if (!SecurityUtils.getLoginUser().getRoles().contains("admin") && !SecurityUtils.getLoginUser().getRoles().contains("sysadmin")) { bean.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId()); + + //查询祖级以便获取上级部门id + SysDept dept = mapper.selectDeptById(SecurityUtils.getLoginUser().getSysUser().getDeptId()); + if (dept != null && StringUtils.isNotBlank(dept.getAncestors()) && StringUtils.countMatches(dept.getAncestors(), ",") == 2) { + bean.setDeptId(dept.getParentId()); + } } return mapper.listTeamGroup(bean); } @@ -266,6 +279,11 @@ public class SecondaryWarehouseServiceImpl implements SecondaryWarehouseService bean.setLeaseType(1); if (!SecurityUtils.getLoginUser().getRoles().contains("admin") && !SecurityUtils.getLoginUser().getRoles().contains("sysadmin")) { bean.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId()); + //查询祖级以便获取上级部门id + SysDept dept = mapper.selectDeptById(SecurityUtils.getLoginUser().getSysUser().getDeptId()); + if (dept != null && StringUtils.isNotBlank(dept.getAncestors()) && StringUtils.countMatches(dept.getAncestors(), ",") == 2) { + bean.setDeptId(dept.getParentId()); + } } List list = mapper.getList(bean); for (SecondaryWarehouse secondaryWarehouse : list) { diff --git a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SecondaryWarehouseMapper.xml b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SecondaryWarehouseMapper.xml index 1a141ef..8cab888 100644 --- a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SecondaryWarehouseMapper.xml +++ b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SecondaryWarehouseMapper.xml @@ -682,6 +682,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and type_id = #{typeId} order by create_time desc limit 1 + insert into second_lot_config (name,unit_id,creater,create_time)