Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bailuntec-cost
Overview
Overview
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
huluobin
bailuntec-cost
Commits
057e22f9
Commit
057e22f9
authored
Sep 10, 2021
by
liyanlin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
同步OA用户JOB
parent
b03769eb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
145 additions
and
0 deletions
+145
-0
OaUserSyncJob.java
...src/main/java/com/blt/other/common/job/OaUserSyncJob.java
+110
-0
OaUserSyncJobConfiguration.java
.../com/blt/other/common/job/OaUserSyncJobConfiguration.java
+35
-0
No files found.
cost-service/src/main/java/com/blt/other/common/job/OaUserSyncJob.java
0 → 100644
View file @
057e22f9
package
com
.
blt
.
other
.
common
.
job
;
import
com.bailuntec.api.bailuntec.oa.OaApi
;
import
com.bailuntec.api.bailuntec.oa.response.OaDepartmentResp
;
import
com.bailuntec.api.bailuntec.oa.response.OaUserResp
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.blt.other.module.auth.dao.OaDepartmentMapper
;
import
com.blt.other.module.auth.model.OaDepartment
;
import
com.blt.other.module.auth.model.OaUser
;
import
com.blt.other.module.auth.service.IOaDepartmentService
;
import
com.blt.other.module.auth.service.IOaUserService
;
import
org.quartz.JobExecutionContext
;
import
org.quartz.JobExecutionException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
public
class
OaUserSyncJob
extends
QuartzJobBean
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
OaUserSyncJob
.
class
);
@Autowired
private
OaApi
oaApi
;
@Autowired
private
IOaUserService
oaUserService
;
@Autowired
private
IOaDepartmentService
oaDepartmentService
;
@Resource
OaDepartmentMapper
oaDepartmentMapper
;
@Override
protected
void
executeInternal
(
JobExecutionContext
jobExecutionContext
)
throws
JobExecutionException
{
}
private
void
syncOa
()
{
List
<
OaUserResp
>
oaUserRespList
=
oaApi
.
getAllUser
();
List
<
OaDepartmentResp
>
oaDepartmentRespList
=
oaApi
.
getDeparmentList
();
List
<
OaUser
>
oaUserList
=
oaUserRespList
.
stream
().
map
(
oaUserResp
->
{
OaUser
oaUser
=
new
OaUser
();
oaUser
.
setCompanyId
(
oaUserResp
.
getCompanyId
());
oaUser
.
setDepartmentId
(
oaUserResp
.
getDepartmentId
());
oaUser
.
setOaUserId
(
oaUserResp
.
getId
());
oaUser
.
setUserAccount
(
oaUserResp
.
getUserAccount
());
oaUser
.
setUserCode
(
oaUserResp
.
getUserCode
());
oaUser
.
setUserName
(
oaUserResp
.
getUserName
());
return
oaUser
;
})
.
collect
(
Collectors
.
toList
());
List
<
OaDepartment
>
oaDepartmentList
=
oaDepartmentRespList
.
stream
().
map
(
oaDepartmentResp
->
{
OaDepartment
oaDepartment
=
new
OaDepartment
();
oaDepartment
.
setCode
(
oaDepartmentResp
.
getCode
());
oaDepartment
.
setCompanyId
(
oaDepartmentResp
.
getCompanyId
());
oaDepartment
.
setManageUser1
(
oaDepartmentResp
.
getManageUser1
());
oaDepartment
.
setManageUser2
(
oaDepartmentResp
.
getManageUser2
());
oaDepartment
.
setName
(
oaDepartmentResp
.
getName
());
oaDepartment
.
setSort
(
oaDepartmentResp
.
getSort
());
oaDepartment
.
setParentId
(
oaDepartmentResp
.
getParentId
());
oaDepartment
.
setDepartmentId
(
oaDepartmentResp
.
getDepartmentId
());
oaDepartment
.
setFullName
(
oaDepartmentResp
.
getFullName
());
return
oaDepartment
;
})
.
collect
(
Collectors
.
toList
());
Map
<
Integer
,
OaDepartment
>
oaDepartmentMap
=
oaDepartmentList
.
stream
().
collect
(
Collectors
.
toMap
(
OaDepartment:
:
getDepartmentId
,
oaDepartment
->
oaDepartment
,
(
k1
,
k2
)
->
k1
));
oaUserList
.
forEach
(
oaUser
->
{
oaUser
.
setPrimaryDepartmentId
(
this
.
getPrimaryDepartment
(
oaDepartmentMap
,
oaDepartmentMap
.
get
(
oaUser
.
getDepartmentId
())).
getDepartmentId
());
if
(
oaUserService
.
getOne
(
new
LambdaQueryWrapper
<
OaUser
>().
eq
(
OaUser:
:
getOaUserId
,
oaUser
.
getOaUserId
()))
==
null
)
{
oaUserService
.
save
(
oaUser
);
}
});
oaDepartmentList
.
forEach
(
oaDepartment
->
{
if
(
oaDepartmentMapper
.
selectByDepartmentId
(
oaDepartment
.
getDepartmentId
())
==
null
)
{
oaDepartment
.
setUpdateUserId
(
0
);
oaDepartmentService
.
save
(
oaDepartment
);
}
else
{
oaDepartmentService
.
update
(
oaDepartment
,
new
LambdaQueryWrapper
<
OaDepartment
>()
.
eq
(
OaDepartment:
:
getDepartmentId
,
oaDepartment
.
getDepartmentId
()));
}
});
}
private
OaDepartment
getPrimaryDepartment
(
Map
<
Integer
,
OaDepartment
>
departmentMap
,
OaDepartment
oaDepartment
)
{
if
(
oaDepartment
==
null
)
{
return
new
OaDepartment
();
}
if
(
oaDepartment
.
getParentId
().
equals
(
0
)
||
oaDepartment
.
getParentId
()
==
null
)
{
return
oaDepartment
;
}
return
getPrimaryDepartment
(
departmentMap
,
departmentMap
.
get
(
oaDepartment
.
getParentId
()));
}
}
cost-service/src/main/java/com/blt/other/common/job/OaUserSyncJobConfiguration.java
0 → 100644
View file @
057e22f9
package
com
.
blt
.
other
.
common
.
job
;
import
org.quartz.*
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @Author: li.yanlin
* @Description: 同步OA用户,免得每次有新同事使用OA都要同步一次
* @Date: Created in 17:12 2021-04-24
* @Modified by:
*/
@Configuration
public
class
OaUserSyncJobConfiguration
{
// 扫描主体列表时间间隔:(秒)
private
static
final
int
TIME
=
60
*
60
*
2
;
// JobDetail 定义要执行的 job
@Bean
public
JobDetail
oaUserSyncJobDetail
()
{
return
JobBuilder
.
newJob
(
OaUserSyncJob
.
class
)
.
withIdentity
(
"oaUserSyncJob"
)
.
storeDurably
().
build
();
}
// 触发 Bean 的 Trigger
@Bean
public
Trigger
oaUserSyncJobTrigger
()
{
SimpleScheduleBuilder
simpleScheduleBuilder
=
SimpleScheduleBuilder
.
simpleSchedule
()
.
withIntervalInSeconds
(
TIME
).
repeatForever
();
return
TriggerBuilder
.
newTrigger
().
forJob
(
oaUserSyncJobDetail
())
.
withIdentity
(
"oaUserSyncTrigger"
)
.
withSchedule
(
simpleScheduleBuilder
).
build
();
}
}
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