Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangxinjiang
yifu-mvp
Commits
93e3b20b
Commit
93e3b20b
authored
Apr 23, 2024
by
hongguangwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MVP1.6.3 特殊导入
parent
5b7852f2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
60 deletions
+110
-60
pom.xml
yifu-salary/yifu-salary-biz/pom.xml
+6
-6
TSalaryStandardOriginalServiceImpl.java
...lary/service/impl/TSalaryStandardOriginalServiceImpl.java
+104
-54
No files found.
yifu-salary/yifu-salary-biz/pom.xml
View file @
93e3b20b
...
...
@@ -51,11 +51,6 @@
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<artifactId>
yifu-common-log
</artifactId>
</dependency>
<dependency>
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<artifactId>
yifu-archives-api
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<artifactId>
yifu-insurances-api
</artifactId>
...
...
@@ -88,7 +83,12 @@
<version>
1.0.0
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
<dependency>
<groupId>
com.monitorjbl
</groupId>
<artifactId>
xlsx-streamer
</artifactId>
<version>
2.2.0
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
yifu-salary/yifu-salary-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/salary/service/impl/TSalaryStandardOriginalServiceImpl.java
View file @
93e3b20b
...
...
@@ -20,6 +20,7 @@ import com.alibaba.fastjson.JSON;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.monitorjbl.xlsx.StreamingReader
;
import
com.yifu.cloud.plus.v1.check.entity.TCheckIdCard
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.Common
;
...
...
@@ -38,11 +39,7 @@ import com.yifu.cloud.plus.v1.yifu.salary.vo.SalaryUploadParamVo;
import
lombok.AllArgsConstructor
;
import
lombok.extern.log4j.Log4j2
;
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
;
import
org.apache.poi.ss.usermodel.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -127,9 +124,9 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
InputStream
inputStream
=
file
.
getInputStream
();
//根据文件格式 对应不同的api解析
if
(
filename
.
endsWith
(
".xlsx"
))
{
voR
=
readXlsx
(
inputStream
,
specialIdCardList
,
true
,
sheetName
);
voR
=
readXlsx
(
inputStream
,
specialIdCardList
,
true
,
sheetName
,
-
1
);
}
else
{
voR
=
readXls
(
inputStream
,
specialIdCardList
,
true
,
sheetName
);
voR
=
readXls
(
inputStream
,
specialIdCardList
,
true
,
sheetName
,
-
1
);
}
if
(
voR
!=
null
&&
voR
.
getCode
()
==
CommonConstants
.
SUCCESS
)
{
vo
=
voR
.
getData
();
...
...
@@ -158,7 +155,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
)
throws
IOException
{
,
String
sheetName
,
int
idCardNum
)
throws
IOException
{
HSSFWorkbook
sheets
=
null
;
ExcelSheetVo
sheetVo
=
new
ExcelSheetVo
();
try
{
...
...
@@ -182,7 +179,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
// 内容行
int
dataRow
;
// 身份证所在列
int
idCardColumn
=
-
1
;
int
idCardColumn
=
idCardNum
;
// 空白列起始号
int
nullColumn
=
-
1
;
// 上一个空白行
...
...
@@ -199,6 +196,9 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
// 极限空白表头列,超过阈值,将不继续循环列
int
maxTitleNullColumNum
=
50
;
HSSFCell
cell
;
// 极限空白身份证,超过将不循环行
int
maxIdCardNullRow
=
50
;
int
idCardNullNum
=
0
;
// 循环每个sheet
for
(
int
i
=
0
;
i
<
sheetNum
;
i
++)
{
sheetAt
=
sheets
.
getSheetAt
(
i
);
...
...
@@ -211,6 +211,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
// 初始化每个sheet的数据行
dataRow
=
0
;
dataRowFlag
=
true
;
idCardNullNum
=
0
;
// 循环当前sheet的每行内容
for
(
int
rowNum
=
0
;
rowNum
<=
sheetAt
.
getLastRowNum
();
rowNum
++)
{
...
...
@@ -259,19 +260,32 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
//sheetVo.setErrorInfo("请注意单元格格式,第" + (i + 1) + "个sheet,第" + (rowNum + 1) + "行第" + (cellNum + 1) + "列。" + e.getMessage())
//return sheetVo
}
if
(
Common
.
isNotNull
(
cellValue
)
&&
dataRowFlag
&&
(((
cellValue
.
length
()
==
15
||
cellValue
.
length
()
==
18
)
&&
regIdCard
(
cellValue
))
// 特殊身份证允许识别
||
regSpecialIdCard
(
cellValue
,
specialIdCardList
)))
{
dataRow
=
rowNum
;
idCardColumn
=
cellNum
;
dataRowFlag
=
false
;
if
(
dataRowFlag
)
{
if
(
idCardColumn
!=
-
1
)
{
if
(
idCardColumn
==
cellNum
&&
Common
.
isNotNull
(
cellValue
)
&&
(((
cellValue
.
length
()
==
15
||
cellValue
.
length
()
==
18
)
&&
regIdCard
(
cellValue
))
// 特殊身份证允许识别
||
regSpecialIdCard
(
cellValue
,
specialIdCardList
)))
{
dataRow
=
rowNum
;
dataRowFlag
=
false
;
}
}
else
{
if
(
Common
.
isNotNull
(
cellValue
)
&&
(((
cellValue
.
length
()
==
15
||
cellValue
.
length
()
==
18
)
&&
regIdCard
(
cellValue
))
// 特殊身份证允许识别
||
regSpecialIdCard
(
cellValue
,
specialIdCardList
)))
{
dataRow
=
rowNum
;
idCardColumn
=
cellNum
;
dataRowFlag
=
false
;
}
}
}
columnVo
.
setLineNum
(
cellNum
);
columnVo
.
setContent
(
cellValue
);
if
(
Common
.
isNotNull
(
cellValue
))
{
cellValue
=
cellValue
.
trim
().
replaceAll
(
"\\s+"
,
""
);
titleMap
.
put
(
String
.
valueOf
(
cellNum
),
cellValue
);
}
columnVo
.
setContent
(
cellValue
);
if
(
nullFlag
)
{
contentMap
.
put
(
String
.
valueOf
(
cellNum
),
cellValue
);
if
(
dataRowFlag
)
{
...
...
@@ -342,22 +356,25 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
}
}
if
(!
dataRowFlag
)
{
contentList
.
add
(
contentMap
);
if
(
idCardColumn
!=
-
1
)
{
if
(
Common
.
isEmpty
(
idCardValue
))
{
idCardNullNum
++;
}
if
(
Common
.
isNotNull
(
idCardValue
))
{
contentList
.
add
(
contentMap
);
}
}
}
else
{
titleList
=
new
ArrayList
<>(
columnList
);
}
}
if
(
rowNum
>=
50
&&
dataRowFlag
)
{
return
R
.
failed
(
"未找到身份证所在的数据行,请检查表数据!"
);
return
R
.
failed
(
"
请检查模板与配置是否一致!
未找到身份证所在的数据行,请检查表数据!"
);
}
if
(
titleFlag
&&
!
dataRowFlag
)
{
break
;
}
// 阻断空白行
if
(
idCardColumn
!=
-
1
&&
Common
.
isEmpty
(
idCardValue
))
{
if
(!
contentList
.
isEmpty
()
&&
contentList
.
size
()
>
1
)
{
contentList
.
remove
(
contentList
.
size
()
-
1
);
}
if
(
idCardNullNum
>=
maxIdCardNullRow
)
{
break
;
}
}
...
...
@@ -393,9 +410,9 @@ 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
)
throws
IOException
{
XSSFWorkbook
sheets
=
null
;
,
String
sheetName
,
int
idCardNum
)
throws
IOException
{
ExcelSheetVo
sheetVo
=
new
ExcelSheetVo
();
Workbook
sheets
=
null
;
try
{
List
<
ExcelColumnVo
>
titleList
;
List
<
ExcelColumnVo
>
columnList
;
...
...
@@ -406,10 +423,15 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
Map
<
String
,
String
>
contentMap
;
// 存储每一列有值的表头
Map
<
String
,
String
>
titleMap
=
new
HashMap
<>();
sheets
=
new
XSSFWorkbook
(
inputStream
);
//sheets = new SXSSFWorkbook(inputStream);
sheets
=
StreamingReader
.
builder
()
.
rowCacheSize
(
1000
)
// 缓存到内存中的行数(默认是10)
.
bufferSize
(
10240
)
// 读取资源时,缓存到内存的字节大小(默认是1024)
.
open
(
inputStream
);
// sheet
XSSFSheet
sheetAt
;
XSSFRow
row
;
//
XSSFSheet sheetAt;
//
XSSFRow row;
// 获取sheet数量
int
sheetNum
=
sheets
.
getNumberOfSheets
();
// 每个单元格内容
...
...
@@ -417,7 +439,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
// 内容行
int
dataRow
;
// 身份证所在列
int
idCardColumn
=
-
1
;
int
idCardColumn
=
idCardNum
;
// 空白列起始号
int
nullColumn
=
-
1
;
// 上一个空白行
...
...
@@ -433,9 +455,14 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
boolean
nullFlag
=
true
;
// 极限空白表头列,超过阈值,将不继续循环列
int
maxTitleNullColumNum
=
50
;
XSSFCell
cell
;
// 极限空白身份证,超过将不循环行
int
maxIdCardNullRow
=
50
;
int
idCardNullNum
=
0
;
Cell
cell
;
// 循环每个sheet
Sheet
sheetAt
;
for
(
int
i
=
0
;
i
<
sheetNum
;
i
++)
{
//sheetAt = sheets.getSheetAt(i);
sheetAt
=
sheets
.
getSheetAt
(
i
);
if
(
Common
.
isNotNull
(
sheetAt
.
getSheetName
())
&&
Common
.
isNotNull
(
sheetName
)
&&
sheetName
.
equals
(
sheetAt
.
getSheetName
()))
{
...
...
@@ -447,7 +474,12 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
dataRow
=
0
;
dataRowFlag
=
true
;
// 循环当前sheet的每行内容
for
(
int
rowNum
=
0
;
rowNum
<=
sheetAt
.
getLastRowNum
();
rowNum
++)
{
//for (int rowNum = 0; rowNum <= sheetAt.getLastRowNum(); rowNum++) {
idCardNullNum
=
0
;
int
rowNum
=
0
;
for
(
Row
row
:
sheetAt
)
{
nullColumn
=
-
1
;
preNullColumn
=
-
1
;
...
...
@@ -457,7 +489,6 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
idCardValue
=
null
;
contentMap
=
new
HashMap
<>();
columnList
=
new
ArrayList
<>();
row
=
sheetAt
.
getRow
(
rowNum
);
if
(
row
!=
null
)
{
for
(
int
cellNum
=
0
;
cellNum
<
row
.
getLastCellNum
();
cellNum
++)
{
columnVo
=
new
ExcelColumnVo
();
...
...
@@ -467,8 +498,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
cellValue
=
""
;
}
else
{
if
(
cell
.
getCellType
()
==
CellType
.
FORMULA
)
{
cell
.
setCellType
(
CellType
.
STRING
);
cellValue
=
cell
.
getStringCellValue
();
cellValue
=
String
.
valueOf
(
cell
.
getStringCellValue
());
}
else
if
(
CellType
.
STRING
==
cell
.
getCellType
())
{
cellValue
=
row
.
getCell
(
cellNum
).
getStringCellValue
();
}
else
if
(
CellType
.
NUMERIC
==
cell
.
getCellType
())
{
...
...
@@ -494,19 +524,32 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
//sheetVo.setErrorInfo("请注意单元格格式,第" + (i + 1) + "个sheet,第" + (rowNum + 1) + "行第" + (cellNum + 1) + "列。" + e.getMessage())
//return sheetVo
}
if
(
Common
.
isNotNull
(
cellValue
)
&&
dataRowFlag
&&
(((
cellValue
.
length
()
==
15
||
cellValue
.
length
()
==
18
)
&&
regIdCard
(
cellValue
))
// 特殊身份证允许识别
||
regSpecialIdCard
(
cellValue
,
specialIdCardList
)))
{
dataRow
=
rowNum
;
idCardColumn
=
cellNum
;
dataRowFlag
=
false
;
if
(
dataRowFlag
)
{
if
(
idCardColumn
!=
-
1
)
{
if
(
idCardColumn
==
cellNum
&&
Common
.
isNotNull
(
cellValue
)
&&
(((
cellValue
.
length
()
==
15
||
cellValue
.
length
()
==
18
)
&&
regIdCard
(
cellValue
))
// 特殊身份证允许识别
||
regSpecialIdCard
(
cellValue
,
specialIdCardList
)))
{
dataRow
=
rowNum
;
dataRowFlag
=
false
;
}
}
else
{
if
(
Common
.
isNotNull
(
cellValue
)
&&
(((
cellValue
.
length
()
==
15
||
cellValue
.
length
()
==
18
)
&&
regIdCard
(
cellValue
))
// 特殊身份证允许识别
||
regSpecialIdCard
(
cellValue
,
specialIdCardList
)))
{
dataRow
=
rowNum
;
idCardColumn
=
cellNum
;
dataRowFlag
=
false
;
}
}
}
columnVo
.
setLineNum
(
cellNum
);
columnVo
.
setContent
(
cellValue
);
if
(
Common
.
isNotNull
(
cellValue
))
{
cellValue
=
cellValue
.
trim
().
replaceAll
(
"\\s+"
,
""
);
titleMap
.
put
(
String
.
valueOf
(
cellNum
),
cellValue
);
}
columnVo
.
setContent
(
cellValue
);
if
(
nullFlag
)
{
contentMap
.
put
(
String
.
valueOf
(
cellNum
),
cellValue
);
if
(
dataRowFlag
)
{
...
...
@@ -577,7 +620,14 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
}
}
if
(!
dataRowFlag
)
{
contentList
.
add
(
contentMap
);
if
(
idCardColumn
!=
-
1
)
{
if
(
Common
.
isEmpty
(
idCardValue
))
{
idCardNullNum
++;
}
if
(
Common
.
isNotNull
(
idCardValue
))
{
contentList
.
add
(
contentMap
);
}
}
}
else
{
titleList
=
new
ArrayList
<>(
columnList
);
}
...
...
@@ -585,14 +635,11 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
if
(
rowNum
>=
50
&&
dataRowFlag
)
{
return
R
.
failed
(
"未找到身份证所在的数据行,请检查表数据!"
);
}
rowNum
++;
if
(
titleFlag
&&
!
dataRowFlag
)
{
break
;
}
// 阻断空白行
if
(
idCardColumn
!=
-
1
&&
Common
.
isEmpty
(
idCardValue
))
{
if
(!
contentList
.
isEmpty
()
&&
contentList
.
size
()
>
1
)
{
contentList
.
remove
(
contentList
.
size
()
-
1
);
}
if
(
idCardNullNum
>=
maxIdCardNullRow
)
{
break
;
}
}
...
...
@@ -605,7 +652,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
return
R
.
ok
(
sheetVo
);
}
}
}
catch
(
IO
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
if
(
sheets
!=
null
)
{
sheets
.
close
();
...
...
@@ -688,6 +735,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
}
List
<
TSalaryStandardOriginalDetail
>
detailList
=
tSalaryStandardOriginalDetailService
.
getTSalaryStandardOriginalDetailByOrgId
(
originalId
);
Map
<
String
,
TSalaryStandardOriginalDetail
>
detailMap
=
new
HashMap
<>();
int
idCardNum
=
-
1
;
for
(
TSalaryStandardOriginalDetail
detail
:
detailList
)
{
if
(
Common
.
isEmpty
(
detail
.
getModelName
())
&&
(
"是否新员工(默认否)"
.
equals
(
detail
.
getExcelName
())
...
...
@@ -699,6 +747,8 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
||
"手机号码"
.
equals
(
detail
.
getExcelName
())
||
"计税月份"
.
equals
(
detail
.
getExcelName
())))
{
detail
.
setModelName
(
detail
.
getExcelName
());
}
else
if
(
SalaryConstants
.
ID_NUMBER
.
equals
(
detail
.
getModelName
()))
{
idCardNum
=
detail
.
getColumnNo
();
}
detailMap
.
put
(
String
.
valueOf
(
detail
.
getColumnNo
()),
detail
);
}
...
...
@@ -724,9 +774,9 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
ExcelSheetVo
vo
;
//根据文件格式 对应不同的api解析
if
(
filename
.
endsWith
(
".xlsx"
))
{
voR
=
readXlsx
(
inputStream
,
specialIdCardList
,
false
,
sheetName
);
voR
=
readXlsx
(
inputStream
,
specialIdCardList
,
false
,
sheetName
,
idCardNum
);
}
else
{
voR
=
readXls
(
inputStream
,
specialIdCardList
,
false
,
sheetName
);
voR
=
readXls
(
inputStream
,
specialIdCardList
,
false
,
sheetName
,
idCardNum
);
}
if
(
voR
!=
null
&&
voR
.
getCode
()
==
CommonConstants
.
SUCCESS
)
{
vo
=
voR
.
getData
();
...
...
@@ -774,11 +824,11 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
||
!
"计税月份"
.
equals
(
title
.
getContent
()))
)
{
return
R
.
failed
(
"未找到对应配置的表头,请核实导入的原表信息后,重新尝试!!"
);
//return R.failed("表头与导入的不一致,第" + (i + 1) + "列应为【" + detailMap.get(String.valueOf(title.getLineNum())).getExcelName() + "】,实际为【" + title.getContent() + "】")
;
//return R.failed("表头与导入的不一致,第" + (i + 1) + "列应为【" + detailMap.get(String.valueOf(title.getLineNum())).getExcelName() + "】,实际为【" + title.getContent() + "】")
}
}
else
if
(
detailMap
.
get
(
String
.
valueOf
(
title
.
getLineNum
()))
!=
null
&&
Common
.
isNotNull
(
detailMap
.
get
(
String
.
valueOf
(
title
.
getLineNum
())).
getExcelName
()))
{
return
R
.
failed
(
"未找到对应配置的表头,请核实导入的原表信息后,重新尝试!!!"
);
//return R.failed("表头与导入的不一致,第" + (i + 1) + "列应为【" + detailMap.get(String.valueOf(title.getLineNum())).getExcelName() + "】,实际为空!")
;
//return R.failed("表头与导入的不一致,第" + (i + 1) + "列应为【" + detailMap.get(String.valueOf(title.getLineNum())).getExcelName() + "】,实际为空!")
}
}
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment