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
027caaea
Commit
027caaea
authored
Jul 08, 2022
by
hongguangwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
人员档案导入-更新,换代码逻辑
parent
b080e1b9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
143 additions
and
25 deletions
+143
-25
EmployeeVO.java
...a/com/yifu/cloud/plus/v1/yifu/archives/vo/EmployeeVO.java
+1
-2
TEmployeeInfoController.java
.../v1/yifu/archives/controller/TEmployeeInfoController.java
+8
-8
TEmployeeInfoService.java
...d/plus/v1/yifu/archives/service/TEmployeeInfoService.java
+3
-4
TEmployeeInfoServiceImpl.java
.../yifu/archives/service/impl/TEmployeeInfoServiceImpl.java
+131
-11
No files found.
yifu-archives/yifu-archives-api/src/main/java/com/yifu/cloud/plus/v1/yifu/archives/vo/EmployeeVO.java
View file @
027caaea
...
...
@@ -21,7 +21,6 @@ import com.alibaba.excel.annotation.write.style.ColumnWidth;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Size
;
import
java.io.Serializable
;
import
java.time.LocalDate
;
...
...
@@ -34,7 +33,7 @@ import java.time.LocalDate;
*/
@Data
@ColumnWidth
(
30
)
public
class
EmployeeVO
implements
Serializable
{
public
class
EmployeeVO
extends
RowIndex
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
yifu-archives/yifu-archives-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/archives/controller/TEmployeeInfoController.java
View file @
027caaea
...
...
@@ -40,6 +40,7 @@ import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
lombok.RequiredArgsConstructor
;
import
lombok.SneakyThrows
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cache.Cache
;
import
org.springframework.cache.CacheManager
;
...
...
@@ -47,6 +48,7 @@ import org.springframework.cache.support.SimpleValueWrapper;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.Valid
;
...
...
@@ -364,35 +366,33 @@ public class TEmployeeInfoController {
}
/**
* @param excelList
* @param bindingResult
* @Description: 批量导入人员档案
* @Author: hgw
* @Date: 2022/6/22 11:57
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.pig4cloud.plugin.excel.vo.ErrorMessage>>
**/
@SneakyThrows
@Operation
(
summary
=
"批量导入人员档案"
,
description
=
"批量导入人员档案 hasPermission('employee_batch_import') 额外属性:isCanAdd:0不可以复档复项;1允许复档复项"
)
@SysLog
(
"批量导入人员档案"
)
@PostMapping
(
"/batchImportEmployee"
)
@PreAuthorize
(
"@pms.hasPermission('employee_batch_import')"
)
public
R
<
List
<
ErrorMessage
>>
batchImportEmployee
(
@Request
Excel
List
<
EmployeeVO
>
excelList
,
BindingResult
bindingResult
,
@RequestParam
Integer
isCanAdd
)
{
return
tEmployeeInfoService
.
batchImportEmployee
(
excelList
,
bindingResult
,
isCanAdd
);
public
R
<
List
<
ErrorMessage
>>
batchImportEmployee
(
@Request
Body
MultipartFile
file
,
@RequestParam
Integer
isCanAdd
)
{
return
tEmployeeInfoService
.
batchImportEmployee
(
file
.
getInputStream
()
,
isCanAdd
);
}
/**
* @param excelList
* @param bindingResult
* @Description: 批量更新人员档案
* @Author: hgw
* @Date: 2022/6/22 20:29
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.pig4cloud.plugin.excel.vo.ErrorMessage>>
**/
@SneakyThrows
@Operation
(
summary
=
"批量更新人员档案"
,
description
=
"批量更新人员档案 hasPermission('employee_batch_update')"
)
@SysLog
(
"批量更新人员档案"
)
@PostMapping
(
"/batchUpdateEmployee"
)
@PreAuthorize
(
"@pms.hasPermission('employee_batch_update')"
)
public
R
<
List
<
ErrorMessage
>>
batchUpdateEmployee
(
@Request
Excel
List
<
EmployeeVO
>
excelList
,
BindingResult
bindingResult
)
{
return
tEmployeeInfoService
.
batchUpdateEmployee
(
excelList
,
bindingResult
);
public
R
<
List
<
ErrorMessage
>>
batchUpdateEmployee
(
@Request
Body
MultipartFile
file
)
{
return
tEmployeeInfoService
.
batchUpdateEmployee
(
file
.
getInputStream
()
);
}
/**
...
...
yifu-archives/yifu-archives-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/archives/service/TEmployeeInfoService.java
View file @
027caaea
...
...
@@ -30,6 +30,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import
org.springframework.validation.BindingResult
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.InputStream
;
import
java.util.List
;
/**
...
...
@@ -154,17 +155,15 @@ public interface TEmployeeInfoService extends IService<TEmployeeInfo> {
* @Date: 2022/6/22 11:58
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.pig4cloud.plugin.excel.vo.ErrorMessage>>
**/
R
<
List
<
ErrorMessage
>>
batchImportEmployee
(
List
<
EmployeeVO
>
excelVOList
,
BindingResult
bindingResult
,
int
isCanAdd
);
R
<
List
<
ErrorMessage
>>
batchImportEmployee
(
InputStream
inputStream
,
int
isCanAdd
);
/**
* @param excelVOList
* @param bindingResult
* @Description: 批量更新人员档案
* @Author: hgw
* @Date: 2022/6/22 20:30
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.pig4cloud.plugin.excel.vo.ErrorMessage>>
**/
R
<
List
<
ErrorMessage
>>
batchUpdateEmployee
(
List
<
EmployeeVO
>
excelVOList
,
BindingResult
bindingResult
);
R
<
List
<
ErrorMessage
>>
batchUpdateEmployee
(
InputStream
inputStream
);
void
updateEducationOfEmp
(
EmpEducationUpdateVO
education
);
...
...
yifu-archives/yifu-archives-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/archives/service/impl/TEmployeeInfoServiceImpl.java
View file @
027caaea
...
...
@@ -19,6 +19,10 @@ package com.yifu.cloud.plus.v1.yifu.archives.service.impl;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.read.listener.ReadListener
;
import
com.alibaba.excel.read.metadata.holder.ReadRowHolder
;
import
com.alibaba.excel.util.ListUtils
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
...
...
@@ -46,6 +50,7 @@ import com.yifu.cloud.plus.v1.yifu.common.dapr.config.DaprUpmsProperties;
import
com.yifu.cloud.plus.v1.yifu.common.dapr.util.HttpDaprUtil
;
import
com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cache.Cache
;
import
org.springframework.cache.CacheManager
;
...
...
@@ -57,6 +62,7 @@ import org.springframework.validation.BindingResult;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URLEncoder
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
...
...
@@ -69,6 +75,7 @@ import java.util.*;
* @author hgw
* @date 2022-06-20 09:55:06
*/
@Log4j2
@Service
@RequiredArgsConstructor
@EnableConfigurationProperties
({
DaprUpmsProperties
.
class
,
DaprCheckProperties
.
class
})
...
...
@@ -718,23 +725,78 @@ public class TEmployeeInfoServiceImpl extends ServiceImpl<TEmployeeInfoMapper, T
}
@Override
public
R
<
List
<
ErrorMessage
>>
batchImportEmployee
(
List
<
EmployeeVO
>
excelVOList
,
BindingResult
bindingResult
,
int
isCanAdd
)
{
YifuUser
user
=
SecurityUtils
.
getUser
();
if
(
user
==
null
||
Common
.
isEmpty
(
user
.
getId
()))
{
return
R
.
failed
(
"请登录!"
);
public
R
<
List
<
ErrorMessage
>>
batchImportEmployee
(
InputStream
inputStream
,
int
isCanAdd
)
{
List
<
ErrorMessage
>
errorMessageList
=
new
ArrayList
<>();
ExcelUtil
<
EmployeeVO
>
util1
=
new
ExcelUtil
<>(
EmployeeVO
.
class
);
// 写法2:
// 匿名内部类 不用额外写一个DemoDataListener
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
try
{
EasyExcel
.
read
(
inputStream
,
EmployeeVO
.
class
,
new
ReadListener
<
EmployeeVO
>()
{
/**
* 单次缓存的数据量
*/
public
static
final
int
BATCH_COUNT
=
CommonConstants
.
BATCH_COUNT
;
/**
*临时存储
*/
private
List
<
EmployeeVO
>
cachedDataList
=
ListUtils
.
newArrayListWithExpectedSize
(
BATCH_COUNT
);
@Override
public
void
invoke
(
EmployeeVO
data
,
AnalysisContext
context
)
{
ReadRowHolder
readRowHolder
=
context
.
readRowHolder
();
Integer
rowIndex
=
readRowHolder
.
getRowIndex
();
data
.
setRowIndex
(
rowIndex
+
1
);
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
core
.
util
.
ErrorMessage
errorMessage
=
util1
.
checkEntity
(
data
,
data
.
getRowIndex
());
if
(
Common
.
isNotNull
(
errorMessage
))
{
Set
<
String
>
errors
=
new
HashSet
<>();
errors
.
add
(
errorMessage
.
getMessage
());
errorMessageList
.
add
(
new
ErrorMessage
(
errorMessage
.
getLineNum
()
+
0L
,
errors
));
}
else
{
cachedDataList
.
add
(
data
);
}
if
(
cachedDataList
.
size
()
>=
BATCH_COUNT
)
{
saveData
();
// 存储完成清理 list
cachedDataList
=
ListUtils
.
newArrayListWithExpectedSize
(
BATCH_COUNT
);
}
}
@Override
public
void
doAfterAllAnalysed
(
AnalysisContext
context
)
{
saveData
();
}
/**
* 加上存储数据库
*/
private
void
saveData
()
{
log
.
info
(
"{}条数据,开始存储数据库!"
,
cachedDataList
.
size
());
batchImportCore
(
cachedDataList
,
isCanAdd
,
errorMessageList
);
log
.
info
(
"存储数据库成功!"
);
}
}).
sheet
().
doRead
();
}
catch
(
Exception
e
)
{
log
.
error
(
CommonConstants
.
IMPORT_DATA_ANALYSIS_ERROR
,
e
);
return
R
.
failed
(
CommonConstants
.
IMPORT_DATA_ANALYSIS_ERROR
);
}
return
R
.
ok
(
errorMessageList
);
}
private
R
<
List
<
ErrorMessage
>>
batchImportCore
(
List
<
EmployeeVO
>
excelVOList
,
int
isCanAdd
,
List
<
ErrorMessage
>
errorMessageList
)
{
if
(
excelVOList
==
null
||
excelVOList
.
isEmpty
())
{
return
R
.
failed
(
CommonConstants
.
DATA_CAN_NOT_EMPTY
);
}
// 通用校验获取失败的数据
List
<
ErrorMessage
>
errorMessageList
=
(
List
<
ErrorMessage
>)
bindingResult
.
getTarget
();
YifuUser
user
=
SecurityUtils
.
getUser
();
if
(
user
==
null
||
Common
.
isEmpty
(
user
.
getId
()))
{
return
R
.
failed
(
"请登录!"
);
}
Map
<
Long
,
ErrorMessage
>
errorMsgMap
=
new
HashMap
<>();
if
(
Common
.
isNotNull
(
errorMessageList
))
{
errorMessageList
.
stream
().
forEach
(
errorMessage
->
errorMsgMap
.
put
(
errorMessage
.
getLineNum
(),
errorMessage
));
}
else
{
errorMessageList
=
new
ArrayList
<>();
}
// 获取身份证、手机号列表,批量查询档案
List
<
String
>
idCardList
=
new
ArrayList
<>();
List
<
String
>
phoneList
=
new
ArrayList
<>();
...
...
@@ -1202,7 +1264,66 @@ public class TEmployeeInfoServiceImpl extends ServiceImpl<TEmployeeInfoMapper, T
}
@Override
public
R
<
List
<
ErrorMessage
>>
batchUpdateEmployee
(
List
<
EmployeeVO
>
excelVOList
,
BindingResult
bindingResult
)
{
public
R
<
List
<
ErrorMessage
>>
batchUpdateEmployee
(
InputStream
inputStream
)
{
List
<
ErrorMessage
>
errorMessageList
=
new
ArrayList
<>();
ExcelUtil
<
EmployeeVO
>
util1
=
new
ExcelUtil
<>(
EmployeeVO
.
class
);
// 写法2:
// 匿名内部类 不用额外写一个DemoDataListener
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
try
{
EasyExcel
.
read
(
inputStream
,
EmployeeVO
.
class
,
new
ReadListener
<
EmployeeVO
>()
{
/**
* 单次缓存的数据量
*/
public
static
final
int
BATCH_COUNT
=
CommonConstants
.
BATCH_COUNT
;
/**
*临时存储
*/
private
List
<
EmployeeVO
>
cachedDataList
=
ListUtils
.
newArrayListWithExpectedSize
(
BATCH_COUNT
);
@Override
public
void
invoke
(
EmployeeVO
data
,
AnalysisContext
context
)
{
ReadRowHolder
readRowHolder
=
context
.
readRowHolder
();
Integer
rowIndex
=
readRowHolder
.
getRowIndex
();
data
.
setRowIndex
(
rowIndex
+
1
);
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
core
.
util
.
ErrorMessage
errorMessage
=
util1
.
checkEntity
(
data
,
data
.
getRowIndex
());
if
(
Common
.
isNotNull
(
errorMessage
))
{
Set
<
String
>
errors
=
new
HashSet
<>();
errors
.
add
(
errorMessage
.
getMessage
());
errorMessageList
.
add
(
new
ErrorMessage
(
errorMessage
.
getLineNum
()
+
0L
,
errors
));
}
else
{
cachedDataList
.
add
(
data
);
}
if
(
cachedDataList
.
size
()
>=
BATCH_COUNT
)
{
saveData
();
// 存储完成清理 list
cachedDataList
=
ListUtils
.
newArrayListWithExpectedSize
(
BATCH_COUNT
);
}
}
@Override
public
void
doAfterAllAnalysed
(
AnalysisContext
context
)
{
saveData
();
}
/**
* 加上存储数据库
*/
private
void
saveData
()
{
log
.
info
(
"{}条数据,开始存储数据库!"
,
cachedDataList
.
size
());
batchUpdateCore
(
cachedDataList
,
errorMessageList
);
log
.
info
(
"存储数据库成功!"
);
}
}).
sheet
().
doRead
();
}
catch
(
Exception
e
)
{
log
.
error
(
CommonConstants
.
IMPORT_DATA_ANALYSIS_ERROR
,
e
);
return
R
.
failed
(
CommonConstants
.
IMPORT_DATA_ANALYSIS_ERROR
);
}
return
R
.
ok
(
errorMessageList
);
}
private
R
<
List
<
ErrorMessage
>>
batchUpdateCore
(
List
<
EmployeeVO
>
excelVOList
,
List
<
ErrorMessage
>
errorMessageList
)
{
YifuUser
user
=
SecurityUtils
.
getUser
();
if
(
user
==
null
||
Common
.
isEmpty
(
user
.
getId
()))
{
return
R
.
failed
(
"请登录!"
);
...
...
@@ -1211,7 +1332,6 @@ public class TEmployeeInfoServiceImpl extends ServiceImpl<TEmployeeInfoMapper, T
return
R
.
failed
(
CommonConstants
.
DATA_CAN_NOT_EMPTY
);
}
// 通用校验获取失败的数据
List
<
ErrorMessage
>
errorMessageList
=
(
List
<
ErrorMessage
>)
bindingResult
.
getTarget
();
Map
<
Long
,
ErrorMessage
>
errorMsgMap
=
new
HashMap
<>();
if
(
Common
.
isNotNull
(
errorMessageList
))
{
errorMessageList
.
stream
().
forEach
(
errorMessage
->
errorMsgMap
.
put
(
errorMessage
.
getLineNum
(),
errorMessage
));
...
...
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