薪酬系统-薪资核算,薪资核算和薪资档案导出excel通用格式改造
This commit is contained in:
parent
3059829619
commit
dc2cb5f448
|
|
@ -105,6 +105,9 @@ public interface SalaryAcctExcelService {
|
|||
|
||||
Map<String, Object> preview(SalaryAcctImportParam param);
|
||||
|
||||
Map<String, Object> previewImportSalaryAcctResult(SalaryAcctImportParam param);
|
||||
|
||||
|
||||
//
|
||||
// /**
|
||||
// * 薪资核算结果校验异常导出
|
||||
|
|
|
|||
|
|
@ -166,8 +166,8 @@ public class SalaryAcctExcelServiceImpl extends Service implements SalaryAcctExc
|
|||
// 3.表数据
|
||||
List<List<Object>> lists = convert2ExcelRow(salaryAcctEmployees);
|
||||
rows.addAll(lists);
|
||||
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
|
||||
// return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
return ExcelUtilPlus.genWorkbookV2(rows, sheetName);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -199,8 +199,8 @@ public class SalaryAcctExcelServiceImpl extends Service implements SalaryAcctExc
|
|||
// 3.表数据
|
||||
List<List<Object>> lists = convert2ExcelRow(salaryAcctEmployees);
|
||||
rows.addAll(lists);
|
||||
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
|
||||
// return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
return ExcelUtilPlus.genWorkbookV2(rows, sheetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -231,7 +231,8 @@ public class SalaryAcctExcelServiceImpl extends Service implements SalaryAcctExc
|
|||
// 3.表数据
|
||||
List<List<Object>> lists = convert2ExcelRow(salaryAcctEmployees);
|
||||
rows.addAll(lists);
|
||||
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
// return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
return ExcelUtilPlus.genWorkbookV2(rows, sheetName);
|
||||
}
|
||||
|
||||
private List<List<Object>> convert2ExcelRow(List<SalaryAcctEmployeePO> salaryAcctEmployees) {
|
||||
|
|
@ -549,7 +550,8 @@ public class SalaryAcctExcelServiceImpl extends Service implements SalaryAcctExc
|
|||
|
||||
String sheetName = "线下对比结果";
|
||||
|
||||
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
// return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
return ExcelUtilPlus.genWorkbookV2(rows, sheetName);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -597,7 +599,8 @@ public class SalaryAcctExcelServiceImpl extends Service implements SalaryAcctExc
|
|||
rows.add(headerList);
|
||||
String sheetName = "线下对比结果导入模板";
|
||||
|
||||
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
// return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
return ExcelUtilPlus.genWorkbookV2(rows, sheetName);
|
||||
}
|
||||
|
||||
public Map<String, Object> importSalaryAcctResult(SalaryAcctImportParam param) {
|
||||
|
|
@ -630,6 +633,27 @@ public class SalaryAcctExcelServiceImpl extends Service implements SalaryAcctExc
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> previewImportSalaryAcctResult(SalaryAcctImportParam param) {
|
||||
|
||||
//1、参数校验
|
||||
ValidUtil.doValidator(param);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
InputStream fileInputStream = null;
|
||||
try {
|
||||
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(param.getImageId()));
|
||||
Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLSX);
|
||||
map.put("headers", ExcelSupport.getSheetHeader(sheet, 1));
|
||||
map.put("list", ExcelParseHelper.parse2List(sheet, 2, 1));
|
||||
return map;
|
||||
|
||||
} finally {
|
||||
IOUtils.closeQuietly(fileInputStream);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> batchImport(SalaryAcctImportParam param, String importType) {
|
||||
Map<String, Object> apidatas = new HashMap<String, Object>();
|
||||
ValidUtil.doValidator(param);
|
||||
|
|
@ -703,10 +727,23 @@ public class SalaryAcctExcelServiceImpl extends Service implements SalaryAcctExc
|
|||
// 存在错误的那行数据
|
||||
List<Map<String, Object>> errorDatas = Lists.newArrayList();
|
||||
// 表头
|
||||
List<String> headers = ExcelSupport.getSheetHeader(sheet, 0);
|
||||
// List<String> headers = ExcelSupport.getSheetHeader(sheet, 0);
|
||||
List<String> headers;
|
||||
if (StringUtils.equals("importSalaryAcctResult", importType)) {
|
||||
headers = ExcelSupport.getSheetHeader(sheet, 1);
|
||||
} else {
|
||||
headers = ExcelSupport.getSheetHeader(sheet, 0);
|
||||
}
|
||||
|
||||
// 处理数值
|
||||
// List<Map<String, Object>> data = ExcelParseHelper.parse2Map(sheet, 1);
|
||||
List<Map<String, Object>> data;
|
||||
if (StringUtils.equals("importSalaryAcctResult", importType)) {
|
||||
data = ExcelParseHelper.parse2Map(sheet, 2, 1);
|
||||
} else {
|
||||
data = ExcelParseHelper.parse2Map(sheet, 1);
|
||||
}
|
||||
|
||||
// 处理数值
|
||||
List<Map<String, Object>> data = ExcelParseHelper.parse2Map(sheet, 1);
|
||||
if (CollectionUtils.isEmpty(headers)) {
|
||||
throw new RuntimeException("表头为空");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,7 @@ import com.engine.salary.service.*;
|
|||
import com.engine.salary.util.SalaryEntityUtil;
|
||||
import com.engine.salary.util.SalaryI18nUtil;
|
||||
import com.engine.salary.util.db.MapperProxyFactory;
|
||||
import com.engine.salary.util.excel.ExcelComment;
|
||||
import com.engine.salary.util.excel.ExcelParseHelper;
|
||||
import com.engine.salary.util.excel.ExcelSupport;
|
||||
import com.engine.salary.util.excel.ExcelUtil;
|
||||
import com.engine.salary.util.excel.*;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -406,7 +403,8 @@ public class SalaryArchiveExcelServiceImpl extends Service implements SalaryArch
|
|||
// SalaryArchiveExcelBO.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(109736, "格式样例为'2022-01-01'、'2022/1/1'"), 0, 0, i + 1, i + 1);
|
||||
}
|
||||
|
||||
return ExcelUtil.genWorkbookV2(rows, finalNameI18n, excelComments);
|
||||
// return ExcelUtil.genWorkbookV2(rows, finalNameI18n, excelComments);
|
||||
return ExcelUtilPlus.genWorkbookV2(rows, finalNameI18n, excelComments);
|
||||
}
|
||||
|
||||
// /**
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import com.engine.salary.util.db.MapperProxyFactory;
|
|||
import com.engine.salary.util.excel.ExcelParseHelper;
|
||||
import com.engine.salary.util.excel.ExcelSupport;
|
||||
import com.engine.salary.util.excel.ExcelUtil;
|
||||
import com.engine.salary.util.excel.ExcelUtilPlus;
|
||||
import com.engine.salary.util.page.PageInfo;
|
||||
import com.engine.salary.util.page.SalaryPageUtil;
|
||||
import com.engine.salary.util.valid.ValidUtil;
|
||||
|
|
@ -520,7 +521,8 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
});
|
||||
// 3.表数据
|
||||
|
||||
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
// return ExcelUtil.genWorkbookV2(rows, sheetName);
|
||||
return ExcelUtilPlus.genWorkbookV2(rows, sheetName);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -174,6 +174,31 @@ public class ExcelParseHelper {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将sheet数据转为map
|
||||
*
|
||||
* @param rowIndex 从哪行开始解析
|
||||
* @param headerRowIndex 抽取列数的参考行
|
||||
* @return
|
||||
*/
|
||||
public static List<Map<String, Object>> parse2Map(Sheet sheet, int rowIndex, int headerRowIndex) {
|
||||
int rowCount = sheet.getPhysicalNumberOfRows(); // 总行数
|
||||
int cellCount = sheet.getRow(headerRowIndex).getPhysicalNumberOfCells(); // 总列数
|
||||
|
||||
List<String> sheetHeader = ExcelSupport.getSheetHeader(sheet, headerRowIndex);
|
||||
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
for (; rowIndex < rowCount; rowIndex++) {
|
||||
Map<String, Object> cellResult = new HashMap<>();
|
||||
for (int j = 0; j < cellCount; j++) {
|
||||
String key = sheetHeader.get(j);
|
||||
cellResult.put(key, ExcelSupport.getCellValue(sheet, rowIndex, j));
|
||||
}
|
||||
result.add(cellResult);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将sheet数据转为List
|
||||
*
|
||||
|
|
@ -195,6 +220,27 @@ public class ExcelParseHelper {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将sheet数据转为List
|
||||
* @param rowIndex 从哪行开始解析
|
||||
* @param headerRowIndex 抽取列数的参考行
|
||||
* @return
|
||||
*/
|
||||
public static List<List<String>> parse2List(Sheet sheet, int rowIndex, int headerRowIndex) {
|
||||
int rowCount = sheet.getPhysicalNumberOfRows(); // 总行数
|
||||
int cellCount = sheet.getRow(headerRowIndex).getPhysicalNumberOfCells(); // 总列数
|
||||
|
||||
List<List<String>> result = new ArrayList<List<String>>();
|
||||
for (; rowIndex < rowCount; rowIndex++) {
|
||||
List<String> cellResult = new ArrayList<String>();
|
||||
for (int j = 0; j < cellCount; j++) {
|
||||
cellResult.add(ExcelSupport.getCellValue(sheet, rowIndex, j));
|
||||
}
|
||||
result.add(cellResult);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 为对象的每一个属性赋值
|
||||
|
|
|
|||
|
|
@ -74,12 +74,18 @@ public class ExcelUtilPlus {
|
|||
// 设置title样式
|
||||
XSSFCellStyle titleCellStyle = workbook.createCellStyle();
|
||||
XSSFFont titleFont = workbook.createFont();
|
||||
titleFont.setBold(true);
|
||||
titleFont.setFontName("仿宋");
|
||||
titleFont.setFontHeightInPoints((short) 15);
|
||||
titleCellStyle.setFont(titleFont);
|
||||
titleCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
titleCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());//背景色
|
||||
titleCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());//背景色
|
||||
titleCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
titleCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
titleCellStyle.setBorderLeft(BorderStyle.THIN);
|
||||
titleCellStyle.setBorderRight(BorderStyle.THIN);
|
||||
titleCellStyle.setBorderTop(BorderStyle.THIN);
|
||||
titleCellStyle.setBorderBottom(BorderStyle.THIN);
|
||||
|
||||
|
||||
// 设置主体样式
|
||||
|
|
@ -89,6 +95,10 @@ public class ExcelUtilPlus {
|
|||
font.setFontHeightInPoints((short) 10);// 设置字体大小
|
||||
cellStyle.setFont(font);// 选择需要用到的字体格式
|
||||
cellStyle.setWrapText(true);
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN);
|
||||
|
||||
XSSFSheet sheet = workbook.createSheet(sheetName);
|
||||
//自适应宽度
|
||||
|
|
@ -97,6 +107,11 @@ public class ExcelUtilPlus {
|
|||
sheet.setDefaultColumnWidth(20);
|
||||
//默认行高
|
||||
sheet.setDefaultRowHeightInPoints(18);
|
||||
//遍历设置列宽
|
||||
List<Object> header = rowList.get(0);
|
||||
for (int i = 0; i < header.size(); i++) {
|
||||
sheet.setColumnWidth(i,Math.max(12, header.get(i).toString().length()*4)*256);
|
||||
}
|
||||
|
||||
for (int rowIndex = 0; rowIndex < rowList.size(); rowIndex++) {
|
||||
List<Object> infoList = rowList.get(rowIndex);
|
||||
|
|
@ -134,12 +149,18 @@ public class ExcelUtilPlus {
|
|||
// 设置title样式
|
||||
XSSFCellStyle titleCellStyle = workbook.createCellStyle();
|
||||
XSSFFont titleFont = workbook.createFont();
|
||||
titleFont.setBold(true);
|
||||
titleFont.setFontName("仿宋");
|
||||
titleFont.setFontHeightInPoints((short) 15);
|
||||
titleCellStyle.setFont(titleFont);
|
||||
titleCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
titleCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());//背景色
|
||||
titleCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());//背景色
|
||||
titleCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
titleCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
titleCellStyle.setBorderLeft(BorderStyle.THIN);
|
||||
titleCellStyle.setBorderRight(BorderStyle.THIN);
|
||||
titleCellStyle.setBorderTop(BorderStyle.THIN);
|
||||
titleCellStyle.setBorderBottom(BorderStyle.THIN);
|
||||
|
||||
|
||||
// 设置主体样式
|
||||
|
|
@ -149,6 +170,10 @@ public class ExcelUtilPlus {
|
|||
font.setFontHeightInPoints((short) 10);// 设置字体大小
|
||||
cellStyle.setFont(font);// 选择需要用到的字体格式
|
||||
cellStyle.setWrapText(true);
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN);
|
||||
|
||||
XSSFSheet sheet = workbook.createSheet(sheetName);
|
||||
//自适应宽度
|
||||
|
|
@ -158,6 +183,12 @@ public class ExcelUtilPlus {
|
|||
//默认行高
|
||||
sheet.setDefaultRowHeightInPoints(18);
|
||||
|
||||
//遍历设置列宽
|
||||
List<Object> header = rowList.get(0);
|
||||
for (int i = 0; i < header.size(); i++) {
|
||||
sheet.setColumnWidth(i,Math.max(12, header.get(i).toString().length()*4)*256);
|
||||
}
|
||||
|
||||
for (int rowIndex = 0; rowIndex < rowList.size(); rowIndex++) {
|
||||
List<Object> infoList = rowList.get(rowIndex);
|
||||
XSSFRow row = sheet.createRow(rowIndex);
|
||||
|
|
@ -202,10 +233,11 @@ public class ExcelUtilPlus {
|
|||
// 设置title样式
|
||||
XSSFCellStyle titleCellStyle = workbook.createCellStyle();
|
||||
XSSFFont titleFont = workbook.createFont();
|
||||
titleFont.setBold(true);
|
||||
titleFont.setFontName("仿宋");
|
||||
titleFont.setFontHeightInPoints((short) 15);
|
||||
titleCellStyle.setFont(titleFont);
|
||||
titleCellStyle.setAlignment(HorizontalAlignment.LEFT);
|
||||
titleCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
titleCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());//背景色
|
||||
titleCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
titleCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
|
|
@ -214,6 +246,17 @@ public class ExcelUtilPlus {
|
|||
titleCellStyle.setBorderTop(BorderStyle.THIN);
|
||||
titleCellStyle.setBorderBottom(BorderStyle.THIN);
|
||||
|
||||
XSSFCellStyle childTitleCellStyle = workbook.createCellStyle();
|
||||
childTitleCellStyle.setFont(titleFont);
|
||||
childTitleCellStyle.setAlignment(HorizontalAlignment.LEFT);
|
||||
childTitleCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());//背景色
|
||||
childTitleCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
childTitleCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
childTitleCellStyle.setBorderLeft(BorderStyle.THIN);
|
||||
childTitleCellStyle.setBorderRight(BorderStyle.THIN);
|
||||
childTitleCellStyle.setBorderTop(BorderStyle.THIN);
|
||||
childTitleCellStyle.setBorderBottom(BorderStyle.THIN);
|
||||
|
||||
|
||||
|
||||
// 设置主体样式
|
||||
|
|
@ -234,6 +277,7 @@ public class ExcelUtilPlus {
|
|||
redFont.setFontName("宋体");
|
||||
redFont.setFontHeightInPoints((short) 10);// 设置字体大小
|
||||
redFont.setColor(new XSSFColor(new Color(0xFF3333), null));
|
||||
redFont.setBold(true);
|
||||
redCellStyle.setWrapText(true);
|
||||
redCellStyle.setFont(redFont);// 选择需要用到的字体格式
|
||||
|
||||
|
|
@ -265,9 +309,10 @@ public class ExcelUtilPlus {
|
|||
rowZeroCell.setCellValue(columnGroupItem.getText().toString());
|
||||
rowZeroCell.setCellStyle(titleCellStyle);
|
||||
XSSFCell rowOneCell = row1.createCell(startIndex, CellType.STRING);
|
||||
rowOneCell.setCellValue(columnGroupItem.getText().toString());
|
||||
rowOneCell.setCellStyle(titleCellStyle);
|
||||
//设置列宽
|
||||
sheet.setColumnWidth(startIndex,columnGroupItem.getText().length()*4*256);
|
||||
sheet.setColumnWidth(startIndex,Math.max(12, columnGroupItem.getText().length()*4)*256);
|
||||
startIndex++;
|
||||
} else {
|
||||
List<WeaTableColumnGroup> childrenList = columnGroupItem.getChildren();
|
||||
|
|
@ -279,7 +324,7 @@ public class ExcelUtilPlus {
|
|||
|
||||
XSSFCell cell = row0.createCell(startIndex, CellType.STRING);
|
||||
cell.setCellValue(columnGroupItem.getText().toString());
|
||||
cell.setCellStyle(titleCellStyle);
|
||||
cell.setCellStyle(childTitleCellStyle);
|
||||
|
||||
for (int j = 0; j < childrenList.size(); j++) {
|
||||
WeaTableColumnGroup childrenItem = (WeaTableColumnGroup) childrenList.get(j);
|
||||
|
|
@ -288,7 +333,7 @@ public class ExcelUtilPlus {
|
|||
subHeader.setCellValue(childrenItem.getText().toString());
|
||||
subHeader.setCellStyle(titleCellStyle);
|
||||
//设置列宽
|
||||
sheet.setColumnWidth(startIndex + j,childrenItem.getText().length()*4*256);
|
||||
sheet.setColumnWidth(startIndex + j,Math.max(12, childrenItem.getText().length()*4)*256);
|
||||
}
|
||||
|
||||
startIndex += childrenList.size();
|
||||
|
|
|
|||
|
|
@ -537,7 +537,7 @@ public class SalaryAcctController {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String importSalaryAcctResultPreview(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryAcctImportParam param) {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
return new ResponseResult<SalaryAcctImportParam, Map<String, Object>>(user).run(getSalaryAcctExcelService(user)::preview, param);
|
||||
return new ResponseResult<SalaryAcctImportParam, Map<String, Object>>(user).run(getSalaryAcctExcelService(user)::previewImportSalaryAcctResult, param);
|
||||
}
|
||||
|
||||
// **********************************薪资核算结果 end*********************************/
|
||||
|
|
|
|||
Loading…
Reference in New Issue