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
98748ba1
Commit
98748ba1
authored
Apr 09, 2024
by
hongguangwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MVP1.6.2-工资原表识别-主逻辑提交
parent
815ce707
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
537 additions
and
39 deletions
+537
-39
TSalaryStandardOriginal.java
...d/plus/v1/yifu/salary/entity/TSalaryStandardOriginal.java
+9
-2
ExcelColumnVo.java
.../com/yifu/cloud/plus/v1/yifu/salary/vo/ExcelColumnVo.java
+1
-1
ExcelSheetVo.java
...a/com/yifu/cloud/plus/v1/yifu/salary/vo/ExcelSheetVo.java
+6
-3
ExcelVo.java
...n/java/com/yifu/cloud/plus/v1/yifu/salary/vo/ExcelVo.java
+0
-19
SalaryUploadOriginalParamVo.java
...d/plus/v1/yifu/salary/vo/SalaryUploadOriginalParamVo.java
+46
-0
TSalaryStandardOriginalController.java
.../salary/controller/TSalaryStandardOriginalController.java
+17
-4
TSalaryStandardOriginalMapper.java
.../v1/yifu/salary/mapper/TSalaryStandardOriginalMapper.java
+12
-4
TSalaryStandardOriginalService.java
...1/yifu/salary/service/TSalaryStandardOriginalService.java
+15
-2
TSalaryStandardOriginalServiceImpl.java
...lary/service/impl/TSalaryStandardOriginalServiceImpl.java
+424
-3
TSalaryStandardOriginalMapper.xml
...c/main/resources/mapper/TSalaryStandardOriginalMapper.xml
+7
-1
No files found.
yifu-salary/yifu-salary-api/src/main/java/com/yifu/cloud/plus/v1/yifu/salary/entity/TSalaryStandardOriginal.java
View file @
98748ba1
...
...
@@ -123,11 +123,18 @@ public class TSalaryStandardOriginal extends BaseEntity {
/**
* 是否删除0:未删除;1:已删除
*/
@ExcelAttribute
(
name
=
"是否删除0:未删除;1:已删除"
,
isNotEmpty
=
true
,
errorInfo
=
"是否删除0:未删除;1:已删除不能为空"
)
@NotBlank
(
message
=
"是否删除0:未删除;1:已删除不能为空"
)
@ExcelAttribute
(
name
=
"是否删除0:未删除;1:已删除"
)
@HeadFontStyle
(
fontHeightInPoints
=
11
)
@ExcelProperty
(
"是否删除0:未删除;1:已删除"
)
private
Integer
deleteFlag
;
/**
* 数据所在行
*/
@ExcelAttribute
(
name
=
"数据所在行"
)
@HeadFontStyle
(
fontHeightInPoints
=
11
)
@ExcelProperty
(
"数据所在行"
)
private
Integer
dateNum
;
/**
* 明细
*/
...
...
yifu-salary/yifu-salary-api/src/main/java/com/yifu/cloud/plus/v1/yifu/salary/vo/ExcelColumnVo.java
View file @
98748ba1
...
...
@@ -13,7 +13,7 @@ import lombok.Setter;
public
class
ExcelColumnVo
{
// 列号
private
String
lineNum
;
private
int
lineNum
;
// 列内容
private
String
content
;
}
yifu-salary/yifu-salary-api/src/main/java/com/yifu/cloud/plus/v1/yifu/salary/vo/ExcelSheetVo.java
View file @
98748ba1
...
...
@@ -4,6 +4,7 @@ import lombok.Getter;
import
lombok.Setter
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author hgw
...
...
@@ -13,10 +14,12 @@ import java.util.List;
@Getter
@Setter
public
class
ExcelSheetVo
{
// 数据行
private
int
dataNum
;
// sheet名
private
String
sheetName
;
// 标题行
private
List
<
ExcelColumnVo
>
titleList
;
// 内容行+列
private
List
<
List
<
ExcelColumnVo
>>
data
List
;
private
List
<
Map
<
String
,
String
>>
content
List
;
}
yifu-salary/yifu-salary-api/src/main/java/com/yifu/cloud/plus/v1/yifu/salary/vo/ExcelVo.java
deleted
100644 → 0
View file @
815ce707
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
salary
.
vo
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.List
;
/**
* @author hgw
* @description 薪资原表识别的 EXCEL vo
* @date 2024-4-3 17:37:35
*/
@Getter
@Setter
public
class
ExcelVo
{
// sheet内容
private
List
<
ExcelSheetVo
>
sheetList
;
}
yifu-salary/yifu-salary-api/src/main/java/com/yifu/cloud/plus/v1/yifu/salary/vo/SalaryUploadOriginalParamVo.java
0 → 100644
View file @
98748ba1
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
salary
.
vo
;
import
com.yifu.cloud.plus.v1.yifu.salary.entity.TSalaryStandardIssueRes
;
import
com.yifu.cloud.plus.v1.yifu.salary.entity.TSalaryStandardOriginal
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
/**
* @author hgw2
* @description 薪资上传vo
* @date 2023/1/10
*/
@Getter
@Setter
public
class
SalaryUploadOriginalParamVo
{
// 表格file
MultipartFile
file
;
// 配置
TSalaryStandardOriginal
original
;
// sheetName;必填
String
sheetName
;
// 结算主体id;必填
String
settleDepart
;
// 工资配置结算月等信息的id
String
configId
;
// 工资类型。必填
String
salaryType
;
// 订单id
String
orderId
;
// 是否代发户,默认为空或0:非代发户,1是代发户
Integer
isIssue
;
// 代发户的配置list
List
<
TSalaryStandardIssueRes
>
resList
;
}
yifu-salary/yifu-salary-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/salary/controller/TSalaryStandardOriginalController.java
View file @
98748ba1
...
...
@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.Common
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser
;
...
...
@@ -31,8 +32,7 @@ import com.yifu.cloud.plus.v1.yifu.salary.entity.TSalaryStandardOriginal;
import
com.yifu.cloud.plus.v1.yifu.salary.entity.TSalaryStandardOriginalDetail
;
import
com.yifu.cloud.plus.v1.yifu.salary.service.TSalaryStandardOriginalDetailService
;
import
com.yifu.cloud.plus.v1.yifu.salary.service.TSalaryStandardOriginalService
;
import
com.yifu.cloud.plus.v1.yifu.salary.vo.ExcelVo
;
import
com.yifu.cloud.plus.v1.yifu.salary.vo.SalaryOriginalVo
;
import
com.yifu.cloud.plus.v1.yifu.salary.vo.*
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
lombok.RequiredArgsConstructor
;
...
...
@@ -210,8 +210,21 @@ public class TSalaryStandardOriginalController {
@SysLog
(
"获取表头等信息"
)
@Operation
(
description
=
"获取表头等信息"
)
@PostMapping
(
"/getExcelHeader"
)
public
R
<
ExcelVo
>
getExcelHeader
(
@RequestBody
MultipartFile
file
)
throws
IOException
{
return
tSalaryStandardOriginalService
.
getExcelHeader
(
file
);
public
R
<
ExcelSheetVo
>
getExcelHeader
(
@RequestBody
MultipartFile
file
,
@RequestParam
String
sheetName
)
{
return
tSalaryStandardOriginalService
.
getExcelHeader
(
file
,
sheetName
);
}
/**
* @Description: 新版原表识别导入
* @Author: hgw
* @Date: 2024-4-8 18:04:56
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.String>
**/
@SysLog
(
"新版原表识别导入"
)
@Operation
(
description
=
"新版原表识别导入"
)
@PostMapping
(
"/salaryUploadByOriginal"
)
public
R
<
List
<
ErrorMessage
>>
salaryUploadByOriginal
(
@RequestBody
SalaryUploadOriginalParamVo
vo
)
{
return
tSalaryStandardOriginalService
.
salaryUploadByOriginal
(
vo
);
}
}
yifu-salary/yifu-salary-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/salary/mapper/TSalaryStandardOriginalMapper.java
View file @
98748ba1
...
...
@@ -24,6 +24,8 @@ import com.yifu.cloud.plus.v1.yifu.salary.entity.TSalaryStandardOriginal;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
* 薪资原表识别导入
*
...
...
@@ -32,9 +34,15 @@ import org.apache.ibatis.annotations.Param;
*/
@Mapper
public
interface
TSalaryStandardOriginalMapper
extends
BaseMapper
<
TSalaryStandardOriginal
>
{
/**
* 薪资原表识别导入-分页
*/
IPage
<
TSalaryStandardOriginal
>
getTSalaryStandardOriginalPage
(
Page
<
TSalaryStandardOriginal
>
page
/**
* 薪资原表识别导入-分页
*/
IPage
<
TSalaryStandardOriginal
>
getTSalaryStandardOriginalPage
(
Page
<
TSalaryStandardOriginal
>
page
,
@Param
(
"tSalaryStandardOriginal"
)
TSalaryStandardOriginal
tSalaryStandardOriginal
);
/**
* 特殊身份证允许识别为数据行
*/
List
<
String
>
getSpecialIdCardList
();
}
yifu-salary/yifu-salary-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/salary/service/TSalaryStandardOriginalService.java
View file @
98748ba1
...
...
@@ -20,11 +20,15 @@ package com.yifu.cloud.plus.v1.yifu.salary.service;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.salary.entity.TSalaryStandardOriginal
;
import
com.yifu.cloud.plus.v1.yifu.salary.vo.ExcelVo
;
import
com.yifu.cloud.plus.v1.yifu.salary.vo.ExcelSheetVo
;
import
com.yifu.cloud.plus.v1.yifu.salary.vo.SalaryUploadOriginalParamVo
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
/**
* 薪资原表识别
*
...
...
@@ -47,6 +51,15 @@ public interface TSalaryStandardOriginalService extends IService<TSalaryStandard
* @Date: 2024/4/3 17:40
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<com.yifu.cloud.plus.v1.yifu.salary.vo.ExcelVo>
**/
R
<
ExcelVo
>
getExcelHeader
(
MultipartFile
file
);
R
<
ExcelSheetVo
>
getExcelHeader
(
MultipartFile
file
,
String
sheetName
);
/**
* @param excelVo
* @Description: 新版原表识别导入
* @Author: hgw
* @Date: 2024/4/8 18:05
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage>>
**/
R
<
List
<
ErrorMessage
>>
salaryUploadByOriginal
(
SalaryUploadOriginalParamVo
excelVo
);
}
yifu-salary/yifu-salary-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/salary/service/impl/TSalaryStandardOriginalServiceImpl.java
View file @
98748ba1
...
...
@@ -16,22 +16,47 @@
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
salary
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
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.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.Common
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.salary.entity.TSalaryStandardOriginal
;
import
com.yifu.cloud.plus.v1.yifu.salary.entity.TSalaryStandardOriginalDetail
;
import
com.yifu.cloud.plus.v1.yifu.salary.mapper.TSalaryStandardOriginalMapper
;
import
com.yifu.cloud.plus.v1.yifu.salary.service.SalaryUploadService
;
import
com.yifu.cloud.plus.v1.yifu.salary.service.TSalaryStandardOriginalDetailService
;
import
com.yifu.cloud.plus.v1.yifu.salary.service.TSalaryStandardOriginalService
;
import
com.yifu.cloud.plus.v1.yifu.salary.vo.ExcelVo
;
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.xssf.usermodel.XSSFRow
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* 薪资原表识别
*
* @author hgw
* @date 2024-4-2 17:20:46
*/
...
...
@@ -42,6 +67,7 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
implements
TSalaryStandardOriginalService
{
private
final
SalaryUploadService
salaryUploadService
;
private
final
TSalaryStandardOriginalDetailService
tSalaryStandardOriginalDetailService
;
/**
* @Description: 分页查询
...
...
@@ -54,10 +80,405 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
return
baseMapper
.
getTSalaryStandardOriginalPage
(
page
,
tSalaryStandardOriginal
);
}
/**
* @param file
* @Description: 核心解析
* @Author: hgw
* @Date: 2024/4/8 17:05
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<com.yifu.cloud.plus.v1.yifu.salary.vo.ExcelVo>
**/
@Override
public
R
<
ExcelVo
>
getExcelHeader
(
MultipartFile
file
)
{
// TODO-识别核心代码
public
R
<
ExcelSheetVo
>
getExcelHeader
(
MultipartFile
file
,
String
sheetName
)
{
// 特殊身份证允许识别为数据行
List
<
String
>
specialIdCardList
=
baseMapper
.
getSpecialIdCardList
();
try
{
//对前端传递的文件进行校验
if
(
file
==
null
||
file
.
isEmpty
())
{
return
R
.
failed
(
"文件为空,重新上传"
);
}
//对前端传递的文件进行校验
if
(
Common
.
isEmpty
(
sheetName
))
{
return
R
.
failed
(
"sheet名为空,请选择!"
);
}
//获取文件名称 判断文件是否为 Execl
String
filename
=
file
.
getOriginalFilename
();
if
(
filename
==
null
||
Common
.
isEmpty
(
filename
))
{
return
R
.
failed
(
"文件名称为空,请重新上传!"
);
}
if
(!(
filename
.
endsWith
(
".xls"
)
||
filename
.
endsWith
(
".xlsx"
)))
{
return
R
.
failed
(
"文件名称格式有误,请重新上传!"
+
filename
);
}
ExcelSheetVo
vo
;
InputStream
inputStream
=
file
.
getInputStream
();
//根据文件格式 对应不同的api解析
if
(
filename
.
endsWith
(
".xlsx"
))
{
vo
=
readXlsx
(
inputStream
,
specialIdCardList
,
true
,
sheetName
);
}
else
{
vo
=
readXls
(
inputStream
,
specialIdCardList
,
true
,
sheetName
);
}
//数据保存
return
R
.
ok
(
vo
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
* @param inputStream
* @param specialIdCardList
* @param titleFlag true:返回title;false:返回content
* @Description: 解析xls
* @Author: hgw
* @Date: 2024/4/8 17:02
* @return: com.yifu.cloud.plus.v1.yifu.salary.vo.ExcelVo
**/
private
ExcelSheetVo
readXls
(
InputStream
inputStream
,
List
<
String
>
specialIdCardList
,
boolean
titleFlag
,
String
sheetName
)
throws
IOException
{
HSSFWorkbook
sheets
=
null
;
ExcelSheetVo
sheetVo
=
new
ExcelSheetVo
();
try
{
List
<
ExcelColumnVo
>
titleList
;
List
<
ExcelColumnVo
>
columnList
;
ExcelColumnVo
columnVo
;
// 内容list
List
<
Map
<
String
,
String
>>
contentList
;
// 每一行的内容map
Map
<
String
,
String
>
contentMap
;
sheets
=
new
HSSFWorkbook
(
inputStream
);
// sheet
HSSFSheet
sheetAt
;
HSSFRow
row
;
// 获取sheet数量
int
sheetNum
=
sheets
.
getNumberOfSheets
();
// 每个单元格内容
String
cellValue
;
// 内容行
int
dataRow
;
// 数据行是否被确认,true否
boolean
dataRowFlag
;
// 循环每个sheet
for
(
int
i
=
0
;
i
<
sheetNum
;
i
++)
{
sheetAt
=
sheets
.
getSheetAt
(
i
);
if
(
Common
.
isNotNull
(
sheetAt
.
getSheetName
())
&&
Common
.
isNotNull
(
sheetName
)
&&
sheetName
.
equals
(
sheetAt
.
getSheetName
()))
{
contentList
=
new
ArrayList
<>();
// 塞sheet名称
sheetVo
.
setSheetName
(
sheetAt
.
getSheetName
());
titleList
=
new
ArrayList
<>();
// 初始化每个sheet的数据行
dataRow
=
0
;
dataRowFlag
=
true
;
// 循环当前sheet的每行内容
for
(
int
rowNum
=
0
;
rowNum
<
sheetAt
.
getLastRowNum
();
rowNum
++)
{
contentMap
=
new
HashMap
<>();
columnList
=
new
ArrayList
<>();
row
=
sheetAt
.
getRow
(
rowNum
);
if
(
row
!=
null
)
{
for
(
int
cellNum
=
0
;
cellNum
<
row
.
getLastCellNum
();
cellNum
++)
{
columnVo
=
new
ExcelColumnVo
();
cellValue
=
row
.
getCell
(
cellNum
).
getStringCellValue
();
if
(
Common
.
isNotNull
(
cellValue
))
{
if
(
dataRowFlag
&&
(((
cellValue
.
length
()
==
15
||
cellValue
.
length
()
==
18
)
&&
regIdCard
(
cellValue
))
// 特殊身份证允许识别
||
regSpecialIdCard
(
cellValue
,
specialIdCardList
)))
{
dataRow
=
rowNum
;
dataRowFlag
=
false
;
}
columnVo
.
setLineNum
(
cellNum
);
columnVo
.
setContent
(
cellValue
);
contentMap
.
put
(
String
.
valueOf
(
cellNum
),
cellValue
);
if
(
dataRowFlag
)
{
columnList
.
add
(
columnVo
);
}
}
}
if
(!
dataRowFlag
)
{
contentList
.
add
(
contentMap
);
}
else
{
titleList
=
new
ArrayList
<>(
columnList
);
}
}
if
(
titleFlag
&&
!
dataRowFlag
)
{
break
;
}
}
sheetVo
.
setDataNum
(
dataRow
);
sheetVo
.
setTitleList
(
titleList
);
sheetVo
.
setContentList
(
contentList
);
return
sheetVo
;
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
if
(
sheets
!=
null
)
{
sheets
.
close
();
}
}
finally
{
if
(
sheets
!=
null
)
{
sheets
.
close
();
}
}
return
sheetVo
;
}
/**
* @param inputStream
* @param specialIdCardList
* @param titleFlag true:返回title;false:返回content
* @Description: 解析xlsx
* @Author: hgw
* @Date: 2024/4/8 17:02
* @return: com.yifu.cloud.plus.v1.yifu.salary.vo.ExcelVo
**/
private
ExcelSheetVo
readXlsx
(
InputStream
inputStream
,
List
<
String
>
specialIdCardList
,
boolean
titleFlag
,
String
sheetName
)
throws
IOException
{
XSSFWorkbook
sheets
=
null
;
ExcelSheetVo
sheetVo
=
new
ExcelSheetVo
();
try
{
List
<
ExcelColumnVo
>
titleList
;
List
<
ExcelColumnVo
>
columnList
;
ExcelColumnVo
columnVo
;
// 内容list
List
<
Map
<
String
,
String
>>
contentList
;
// 每一行的内容map
Map
<
String
,
String
>
contentMap
;
sheets
=
new
XSSFWorkbook
(
inputStream
);
// sheet
XSSFSheet
sheetAt
;
XSSFRow
row
;
// 获取sheet数量
int
sheetNum
=
sheets
.
getNumberOfSheets
();
// 每个单元格内容
String
cellValue
;
// 内容行
int
dataRow
;
// 数据行是否被确认,true否
boolean
dataRowFlag
;
// 循环每个sheet
for
(
int
i
=
0
;
i
<
sheetNum
;
i
++)
{
sheetAt
=
sheets
.
getSheetAt
(
i
);
if
(
Common
.
isNotNull
(
sheetAt
.
getSheetName
())
&&
Common
.
isNotNull
(
sheetName
)
&&
sheetName
.
equals
(
sheetAt
.
getSheetName
()))
{
contentList
=
new
ArrayList
<>();
// 塞sheet名称
sheetVo
.
setSheetName
(
sheetAt
.
getSheetName
());
titleList
=
new
ArrayList
<>();
// 初始化每个sheet的数据行
dataRow
=
0
;
dataRowFlag
=
true
;
// 循环当前sheet的每行内容
for
(
int
rowNum
=
0
;
rowNum
<
sheetAt
.
getLastRowNum
();
rowNum
++)
{
contentMap
=
new
HashMap
<>();
columnList
=
new
ArrayList
<>();
row
=
sheetAt
.
getRow
(
rowNum
);
if
(
row
!=
null
)
{
for
(
int
cellNum
=
0
;
cellNum
<
row
.
getLastCellNum
();
cellNum
++)
{
columnVo
=
new
ExcelColumnVo
();
cellValue
=
row
.
getCell
(
cellNum
).
getStringCellValue
();
if
(
Common
.
isNotNull
(
cellValue
))
{
if
(
dataRowFlag
&&
(((
cellValue
.
length
()
==
15
||
cellValue
.
length
()
==
18
)
&&
regIdCard
(
cellValue
))
// 特殊身份证允许识别
||
regSpecialIdCard
(
cellValue
,
specialIdCardList
)))
{
dataRow
=
rowNum
;
dataRowFlag
=
false
;
}
columnVo
.
setLineNum
(
cellNum
);
columnVo
.
setContent
(
cellValue
);
contentMap
.
put
(
String
.
valueOf
(
cellNum
),
cellValue
);
if
(
dataRowFlag
)
{
columnList
.
add
(
columnVo
);
}
}
}
if
(!
dataRowFlag
)
{
contentList
.
add
(
contentMap
);
}
else
{
titleList
=
new
ArrayList
<>(
columnList
);
}
}
if
(
titleFlag
&&
!
dataRowFlag
)
{
break
;
}
}
sheetVo
.
setDataNum
(
dataRow
);
sheetVo
.
setTitleList
(
titleList
);
sheetVo
.
setContentList
(
contentList
);
return
sheetVo
;
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
if
(
sheets
!=
null
)
{
sheets
.
close
();
}
}
finally
{
if
(
sheets
!=
null
)
{
sheets
.
close
();
}
}
return
sheetVo
;
}
/**
* @param content
* @Description: 判断特殊身份证
* 格式正确返回true
* @Author: hgw
* @Date: 2024-4-8 15:33:04
* @return: boolean
**/
private
static
boolean
regSpecialIdCard
(
String
content
,
List
<
String
>
specialIdCardList
)
{
if
(
specialIdCardList
!=
null
&&
!
specialIdCardList
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
specialIdCardList
.
size
();
i
++)
{
if
(
specialIdCardList
.
get
(
i
).
equals
(
content
))
{
return
true
;
}
}
}
return
false
;
}
/**
* @param content
* @Description: 判断身份证格式:18位数字,17位数字+X,15位数字,14位数字+X
* 格式正确返回true
* @Author: hgw
* @Date: 2022/5/13 11:53
* @return: boolean
**/
private
static
boolean
regIdCard
(
String
content
)
{
boolean
flag
=
false
;
Pattern
p
=
Pattern
.
compile
(
"\\d{18}|\\d{17}X|\\d{15}|\\d{14}X"
);
Matcher
m
=
p
.
matcher
(
content
);
if
(
m
.
matches
())
{
flag
=
true
;
}
return
flag
;
}
/**
* @param excelVo
* @Description: 新版原表识别导入
* @Author: hgw
* @Date: 2024/4/8 18:22
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage>>
**/
@Override
public
R
<
List
<
ErrorMessage
>>
salaryUploadByOriginal
(
SalaryUploadOriginalParamVo
excelVo
)
{
R
<
String
>
contR
=
this
.
getExcelContent
(
excelVo
);
if
(
contR
!=
null
)
{
if
(
CommonConstants
.
SUCCESS
.
equals
(
contR
.
getCode
()))
{
SalaryUploadParamVo
vo
=
new
SalaryUploadParamVo
();
vo
.
setJsonString
(
contR
.
getData
());
vo
.
setSalaryType
(
excelVo
.
getSalaryType
());
vo
.
setConfigId
(
excelVo
.
getConfigId
());
vo
.
setIsIssue
(
excelVo
.
getIsIssue
());
vo
.
setOrderId
(
excelVo
.
getOrderId
());
vo
.
setResList
(
excelVo
.
getResList
());
vo
.
setSettleDepart
(
excelVo
.
getSettleDepart
());
return
salaryUploadService
.
salaryUpload
(
vo
);
}
else
{
return
R
.
failed
(
contR
.
getMsg
());
}
}
else
{
return
R
.
failed
(
"原表识别无数据!请准备原表,联系管理员"
);
}
}
/**
* @param excelVo
* @Description: 核心解析-内容
* @Author: hgw
* @Date: 2024-4-8 18:20:22
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<com.yifu.cloud.plus.v1.yifu.salary.vo.ExcelVo>
**/
private
R
<
String
>
getExcelContent
(
SalaryUploadOriginalParamVo
excelVo
)
{
MultipartFile
file
=
excelVo
.
getFile
();
String
sheetName
=
excelVo
.
getSheetName
();
// 配置
TSalaryStandardOriginal
original
=
excelVo
.
getOriginal
();
// 特殊身份证允许识别为数据行
List
<
String
>
specialIdCardList
=
baseMapper
.
getSpecialIdCardList
();
try
{
//对前端传递的文件进行校验
if
(
original
==
null
||
Common
.
isEmpty
(
original
.
getId
()))
{
return
R
.
failed
(
"识别配置为空,请选择识别配置!"
);
}
List
<
TSalaryStandardOriginalDetail
>
detailList
=
tSalaryStandardOriginalDetailService
.
getTSalaryStandardOriginalDetailByOrgId
(
original
.
getId
());
Map
<
String
,
TSalaryStandardOriginalDetail
>
detailMap
=
new
HashMap
<>();
for
(
TSalaryStandardOriginalDetail
detail
:
detailList
)
{
detailMap
.
put
(
String
.
valueOf
(
detail
.
getColumnNo
()),
detail
);
}
//对前端传递的文件进行校验
if
(
Common
.
isEmpty
(
sheetName
))
{
return
R
.
failed
(
"sheet名为空,请选择!"
);
}
//对前端传递的文件进行校验
if
(
file
==
null
||
file
.
isEmpty
())
{
return
R
.
failed
(
"文件为空,重新上传"
);
}
//获取文件名称 判断文件是否为 Execl
String
filename
=
file
.
getOriginalFilename
();
if
(
filename
==
null
||
Common
.
isEmpty
(
filename
))
{
return
R
.
failed
(
"文件名称为空,请重新上传!"
);
}
if
(!(
filename
.
endsWith
(
".xls"
)
||
filename
.
endsWith
(
".xlsx"
)))
{
return
R
.
failed
(
"文件名称格式有误,请重新上传!"
+
filename
);
}
String
jsonString
=
null
;
InputStream
inputStream
=
file
.
getInputStream
();
ExcelSheetVo
vo
;
//根据文件格式 对应不同的api解析
if
(
filename
.
endsWith
(
".xlsx"
))
{
vo
=
readXlsx
(
inputStream
,
specialIdCardList
,
false
,
sheetName
);
}
else
{
vo
=
readXls
(
inputStream
,
specialIdCardList
,
false
,
sheetName
);
}
if
(
vo
.
getContentList
()
!=
null
&&
!
vo
.
getContentList
().
isEmpty
())
{
// 智能识别表头
TSalaryStandardOriginalDetail
detail
;
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
())
{
i
++;
newRowMap
=
new
HashMap
<>();
for
(
Map
.
Entry
<
String
,
String
>
column
:
rowMap
.
entrySet
())
{
detail
=
detailMap
.
get
(
column
.
getKey
());
if
(
detail
!=
null
)
{
value
=
column
.
getValue
();
try
{
if
(
"REDUCE"
.
equals
(
detail
.
getFlag
()))
{
value
=
String
.
valueOf
(
new
BigDecimal
(
value
).
negate
());
}
oldValue
=
newRowMap
.
get
(
detail
.
getModelName
());
if
(
oldValue
!=
null
)
{
value
=
String
.
valueOf
(
new
BigDecimal
(
oldValue
).
add
(
new
BigDecimal
(
value
))
.
setScale
(
SalaryConstants
.
PLACES
,
BigDecimal
.
ROUND_HALF_UP
));
}
}
catch
(
NumberFormatException
e
)
{
return
R
.
failed
(
"第 "
+
i
+
" 行,第 "
+
(
Integer
.
parseInt
(
column
.
getKey
())+
1
)
+
" 列 不是金额,不可以进行加减计算!"
);
}
newRowMap
.
put
(
detail
.
getModelName
(),
value
);
}
}
contentList
.
add
(
newRowMap
);
}
// 最后转化为jsonString
jsonString
=
JSON
.
toJSON
(
contentList
).
toString
();
}
//数据保存
return
R
.
ok
(
jsonString
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
yifu-salary/yifu-salary-biz/src/main/resources/mapper/TSalaryStandardOriginalMapper.xml
View file @
98748ba1
...
...
@@ -40,6 +40,7 @@
<result
property=
"attaUrl"
column=
"ATTA_URL"
/>
<result
property=
"attaSize"
column=
"ATTA_SIZE"
/>
<result
property=
"attaType"
column=
"ATTA_TYPE"
/>
<result
property=
"dateNum"
column=
"DATE_NUM"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
a.ID,
...
...
@@ -57,7 +58,8 @@
a.ATTA_SRC,
a.ATTA_URL,
a.ATTA_SIZE,
a.ATTA_TYPE
a.ATTA_TYPE,
a.DATE_NUM
</sql>
<sql
id=
"TSalaryStandardOriginal_where"
>
<if
test=
"tSalaryStandardOriginal != null"
>
...
...
@@ -108,5 +110,9 @@
ORDER BY a.CREATE_TIME desc
</select>
<!-- 特殊身份证允许识别为数据行 -->
<select
id=
"getSpecialIdCardList"
resultType=
"java.lang.String"
>
SELECT a.ID_CARD FROM t_salary_standard_original_special_idcard a
</select>
</mapper>
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