问题修复

This commit is contained in:
hongchao 2025-12-18 14:43:18 +08:00
parent db5b90b0b4
commit 6aa4a5eae7
6 changed files with 90 additions and 15 deletions

View File

@ -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);
}
// 如果是天数栏设置整数格式假设天数列为第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);
}

View File

@ -25,4 +25,6 @@ public class SecondLotConfig {
private String updateTime;
// 部门id
private Long deptId;
private Long parentId;
}

View File

@ -148,4 +148,6 @@ public class SecondaryWarehouse {
*/
private Integer teamGroupId;
private Long parentId;
}

View File

@ -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);
}

View File

@ -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<SecondLotConfig> 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<TeamGroup> 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<SecondaryWarehouse> list = mapper.getList(bean);
for (SecondaryWarehouse secondaryWarehouse : list) {

View File

@ -682,6 +682,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and type_id = #{typeId}
order by create_time desc limit 1
</select>
<select id="selectDeptById" resultType="com.bonus.sgzb.system.api.domain.SysDept">
select parent_id as parentId,ancestors from sys_dept where dept_id = #{deptId}
</select>
<insert id="addConfig">
insert into second_lot_config (name,unit_id,creater,create_time)