Commit 66c00f8a authored by hongguangwu's avatar hongguangwu

MVP1.6.3 特殊导入-优化

parent 82d6ad4f
......@@ -124,9 +124,9 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
InputStream inputStream = file.getInputStream();
//根据文件格式 对应不同的api解析
if (filename.endsWith(".xlsx")) {
voR = readXlsx(inputStream, specialIdCardList, true, sheetName, -1);
voR = readXlsx(inputStream, specialIdCardList, true, sheetName, -1, null);
} else {
voR = readXls(inputStream, specialIdCardList, true, sheetName, -1);
voR = readXls(inputStream, specialIdCardList, true, sheetName, -1, null);
}
if (voR != null && voR.getCode() == CommonConstants.SUCCESS) {
vo = voR.getData();
......@@ -146,6 +146,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
}
/**
* @param maxColumn 表格表头长度 + 10 (有可能含有未配置的新员工之类的系统表头,放宽10列)
* @param inputStream
* @param specialIdCardList
* @param titleFlag true:返回title;false:返回content
......@@ -155,7 +156,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
* @return: com.yifu.cloud.plus.v1.yifu.salary.vo.ExcelVo
**/
private R<ExcelSheetVo> readXls(InputStream inputStream, List<String> specialIdCardList, boolean titleFlag
, String sheetName, int idCardNum) throws IOException {
, String sheetName, int idCardNum, Integer maxColumn) throws IOException {
HSSFWorkbook sheets = null;
ExcelSheetVo sheetVo = new ExcelSheetVo();
try {
......@@ -188,6 +189,11 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
int nullColumnNum = 0;
// 极限空白列,超过阈值,将不继续循环列
int maxNullColumNum = 30;
int rowLastCellNum = -1;
if (Common.isNotNull(maxColumn)) {
maxNullColumNum = maxColumn;
rowLastCellNum = maxColumn;
}
String idCardValue = null;
// 数据行是否被确认,true否
boolean dataRowFlag;
......@@ -213,7 +219,12 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
dataRowFlag = true;
idCardNullNum = 0;
// 循环当前sheet的每行内容
for (int rowNum = 0; rowNum <= sheetAt.getLastRowNum(); rowNum++) {
if (Common.isNotNull(maxColumn)) {
rowLastCellNum = maxColumn;
} else {
rowLastCellNum = sheetAt.getLastRowNum();
}
for (int rowNum = 0; rowNum <= rowLastCellNum; rowNum++) {
nullColumn = -1;
preNullColumn = -1;
......@@ -360,7 +371,9 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
if (Common.isEmpty(idCardValue)) {
idCardNullNum++;
}
if (Common.isNotNull(idCardValue)) {
if (Common.isNotNull(idCardValue) && (regIdCard(idCardValue))
// 特殊身份证允许识别
|| regSpecialIdCard(idCardValue, specialIdCardList)) {
contentList.add(contentMap);
}
}
......@@ -401,6 +414,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
}
/**
* @param maxColumn 表格表头长度 + 10 (有可能含有未配置的新员工之类的系统表头,放宽10列)
* @param inputStream
* @param specialIdCardList
* @param titleFlag true:返回title;false:返回content
......@@ -410,7 +424,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
* @return: com.yifu.cloud.plus.v1.yifu.salary.vo.ExcelVo
**/
private R<ExcelSheetVo> readXlsx(InputStream inputStream, List<String> specialIdCardList, boolean titleFlag
, String sheetName, int idCardNum) throws IOException {
, String sheetName, int idCardNum, Integer maxColumn) throws IOException {
ExcelSheetVo sheetVo = new ExcelSheetVo();
Workbook sheets = null;
try {
......@@ -447,7 +461,11 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
// 空白列数(一旦数量达到 maxNullColumNum,将停止循环列,并删除title list与content)
int nullColumnNum = 0;
// 极限空白列,超过阈值,将不继续循环列
int maxNullColumNum = 10;
int maxNullColumNum = 30;
int rowLastCellNum = -1;
if (Common.isNotNull(maxColumn)) {
maxNullColumNum = maxColumn;
}
String idCardValue = null;
// 数据行是否被确认,true否
boolean dataRowFlag;
......@@ -490,7 +508,12 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
contentMap = new HashMap<>();
columnList = new ArrayList<>();
if (row != null) {
for (int cellNum = 0; cellNum < row.getLastCellNum(); cellNum++) {
if (Common.isNotNull(maxColumn)) {
rowLastCellNum = maxColumn;
} else {
rowLastCellNum = row.getLastCellNum();
}
for (int cellNum = 0; cellNum < rowLastCellNum; cellNum++) {
columnVo = new ExcelColumnVo();
try {
cell = row.getCell(cellNum);
......@@ -624,7 +647,9 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
if (Common.isEmpty(idCardValue)) {
idCardNullNum++;
}
if (Common.isNotNull(idCardValue)) {
if (Common.isNotNull(idCardValue) && (regIdCard(idCardValue))
// 特殊身份证允许识别
|| regSpecialIdCard(idCardValue, specialIdCardList)) {
contentList.add(contentMap);
}
}
......@@ -736,6 +761,10 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
List<TSalaryStandardOriginalDetail> detailList = tSalaryStandardOriginalDetailService.getTSalaryStandardOriginalDetailByOrgId(originalId);
Map<String, TSalaryStandardOriginalDetail> detailMap = new HashMap<>();
int idCardNum = -1;
if (detailList == null || detailList.isEmpty() || detailList.size() < 4) {
return R.failed("请检查表头配置!");
}
int maxColumn = detailList.size() + 10;
for (TSalaryStandardOriginalDetail detail : detailList) {
if (Common.isEmpty(detail.getModelName())
&& ("是否新员工(默认否)".equals(detail.getExcelName())
......@@ -774,9 +803,9 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
ExcelSheetVo vo;
//根据文件格式 对应不同的api解析
if (filename.endsWith(".xlsx")) {
voR = readXlsx(inputStream, specialIdCardList, false, sheetName, idCardNum);
voR = readXlsx(inputStream, specialIdCardList, false, sheetName, idCardNum, maxColumn);
} else {
voR = readXls(inputStream, specialIdCardList, false, sheetName, idCardNum);
voR = readXls(inputStream, specialIdCardList, false, sheetName, idCardNum, maxColumn);
}
if (voR != null && voR.getCode() == CommonConstants.SUCCESS) {
vo = voR.getData();
......@@ -797,7 +826,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
&& !"开户行支行".equals(title.getContent())
&& !"银行卡号".equals(title.getContent())
&& !"手机号码".equals(title.getContent())
&& !"计税月份".equals(title.getContent())) {
&& !"计税月份".equals(title.getContent()) && title.getLineNum() <detailList.size()) {
return R.failed("未找到对应配置的表头,请核实导入的原表信息后,重新尝试!");
//return R.failed("表头与导入的不一致,第" + title.getLineNum() + "列表头【" + title.getContent() + "】未找到配置,请先配置表头!");
......
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