Commit 7f780f22 authored by hongguangwu's avatar hongguangwu

MVP1.6.2-工资原表识别-主逻辑优化

parent 93c04356
......@@ -18,6 +18,8 @@ public class ExcelSheetVo {
private int dataNum;
// sheet名
private String sheetName;
// 解析过程发现的错误信息
private String errorInfo;
// 标题行
private List<ExcelColumnVo> titleList;
// 内容行+列
......
......@@ -35,9 +35,9 @@ import com.yifu.cloud.plus.v1.yifu.salary.util.SalaryConstants;
import com.yifu.cloud.plus.v1.yifu.salary.vo.*;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
......@@ -47,6 +47,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -157,6 +158,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
int dataRow;
// 数据行是否被确认,true否
boolean dataRowFlag;
HSSFCell cell;
// 循环每个sheet
for (int i = 0; i < sheetNum; i++) {
sheetAt = sheets.getSheetAt(i);
......@@ -177,7 +179,30 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
if (row != null) {
for (int cellNum = 0; cellNum < row.getLastCellNum(); cellNum++) {
columnVo = new ExcelColumnVo();
cellValue = row.getCell(cellNum).getStringCellValue();
try {
cell = row.getCell(cellNum);
if (CellType.STRING == cell.getCellType()) {
cellValue = row.getCell(cellNum).getStringCellValue();
} else if (CellType.NUMERIC == cell.getCellType()) {
try {
cellValue = String.valueOf(row.getCell(cellNum).getNumericCellValue());
if (cellValue.contains("E")) {
cellValue = String.valueOf(new DecimalFormat("#").format(row.getCell(cellNum).getNumericCellValue()));
}
} catch (NumberFormatException e) {
cellValue = String.valueOf(row.getCell(cellNum).getNumericCellValue());
}
} else if (HSSFDateUtil.isCellDateFormatted(cell)) {
cellValue = String.valueOf(row.getCell(cellNum).getDateCellValue());
} else if (CellType.BOOLEAN == cell.getCellType()) {
cellValue = String.valueOf(row.getCell(cellNum).getBooleanCellValue());
} else {
cellValue = row.getCell(cellNum).getStringCellValue();
}
} catch (Exception e) {
sheetVo.setErrorInfo("请注意单元格格式,第"+(i+1) +"个sheet,第"+(rowNum+1)+"行第"+(cellNum+1)+"列。"+e.getMessage());
return sheetVo;
}
if (Common.isNotNull(cellValue)) {
if (dataRowFlag
&& (((cellValue.length() == 15 || cellValue.length() == 18) && regIdCard(cellValue))
......@@ -256,6 +281,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
int dataRow;
// 数据行是否被确认,true否
boolean dataRowFlag;
XSSFCell cell;
// 循环每个sheet
for (int i = 0; i < sheetNum; i++) {
sheetAt = sheets.getSheetAt(i);
......@@ -276,7 +302,30 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
if (row != null) {
for (int cellNum = 0; cellNum < row.getLastCellNum(); cellNum++) {
columnVo = new ExcelColumnVo();
cellValue = row.getCell(cellNum).getStringCellValue();
try {
cell = row.getCell(cellNum);
if (CellType.STRING == cell.getCellType()) {
cellValue = row.getCell(cellNum).getStringCellValue();
} else if (CellType.NUMERIC == cell.getCellType()) {
try {
cellValue = String.valueOf(row.getCell(cellNum).getNumericCellValue());
if (cellValue.contains("E")) {
cellValue = String.valueOf(new DecimalFormat("#").format(row.getCell(cellNum).getNumericCellValue()));
}
} catch (NumberFormatException e) {
cellValue = String.valueOf(row.getCell(cellNum).getNumericCellValue());
}
} else if (HSSFDateUtil.isCellDateFormatted(cell)) {
cellValue = String.valueOf(row.getCell(cellNum).getDateCellValue());
} else if (CellType.BOOLEAN == cell.getCellType()) {
cellValue = String.valueOf(row.getCell(cellNum).getBooleanCellValue());
} else {
cellValue = row.getCell(cellNum).getStringCellValue();
}
} catch (Exception e) {
sheetVo.setErrorInfo("请注意单元格格式,第"+(i+1) +"个sheet,第"+(rowNum+1)+"行第"+(cellNum+1)+"列。"+e.getMessage());
return sheetVo;
}
if (Common.isNotNull(cellValue)) {
if (dataRowFlag
&& (((cellValue.length() == 15 || cellValue.length() == 18) && regIdCard(cellValue))
......@@ -443,7 +492,6 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
List<Map<String, String>> contentList = new ArrayList<>();
Map<String, String> newRowMap;
String value;
BigDecimal valueBig;
String oldValue;
int i=0;
for (Map<String, String> rowMap : vo.getContentList()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment