Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lyf-beidou-cdp-api
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
zhoupeng
lyf-beidou-cdp-api
Commits
0f5c0643
Commit
0f5c0643
authored
Aug 31, 2023
by
zhoupeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交导入组织架构openapi接口
parent
e1bb8058
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
371 additions
and
173 deletions
+371
-173
QiDianController.java
.../java/com/rome/order/api/controller/QiDianController.java
+2
-2
SyncEmployeCdpController.java
...m/rome/order/api/controller/SyncEmployeCdpController.java
+1
-1
OrganizationRedisServiceImpl.java
...der/domain/service/impl/OrganizationRedisServiceImpl.java
+3
-1
QiDianServiceImpl.java
...com/rome/order/domain/service/impl/QiDianServiceImpl.java
+27
-31
SyncEmployeCdpServiceImpl.java
.../order/domain/service/impl/SyncEmployeCdpServiceImpl.java
+125
-87
DateUtils.java
src/main/java/com/rome/order/domain/util/DateUtils.java
+8
-0
HmacSHA256Util.java
src/main/java/com/rome/order/domain/util/HmacSHA256Util.java
+2
-3
HttpUtil.java
src/main/java/com/rome/order/domain/util/HttpUtil.java
+15
-0
SignUtil.java
src/main/java/com/rome/order/domain/util/SignUtil.java
+92
-0
SyncEmployeeCdpDO.java
...me/order/infrastructure/dataobject/SyncEmployeeCdpDO.java
+0
-15
SyncEmployeeCdpMapper.java
...me/order/infrastructure/mapper/SyncEmployeeCdpMapper.java
+14
-0
SyncCdpEmpOrgReqDTO.java
...er/infrastructure/remote/dto/req/SyncCdpEmpOrgReqDTO.java
+20
-0
EmpMainDataResDTO.java
...rder/infrastructure/remote/dto/res/EmpMainDataResDTO.java
+2
-1
application.yml
src/main/resources/application.yml
+32
-22
SyncEmployeeCdpMapper.xml
src/main/resources/mapper/SyncEmployeeCdpMapper.xml
+28
-10
No files found.
src/main/java/com/rome/order/api/controller/QiDianController.java
View file @
0f5c0643
...
...
@@ -35,12 +35,12 @@ public class QiDianController {
@GetMapping
(
"/toSSOCallback"
)
@ApiOperation
(
value
=
"跳转至企点鉴权地址"
)
public
void
toSSOCallback
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
public
String
toSSOCallback
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
String
token
=
request
.
getParameter
(
"token"
);
log
.
info
(
"-------跳转至企点鉴权地址token入参信息-------:{}"
,
token
);
// 参数非空校验
ParameterCheckUtils
.
noNull
(
ResponseMsg
.
PARAM_ERROR_TOKEN
,
token
);
re
sponse
.
sendRedirect
(
qiDianService
.
getSSOCallback
(
token
)
);
re
turn
qiDianService
.
getSSOCallback
(
token
);
}
...
...
src/main/java/com/rome/order/api/controller/SyncEmployeCdpController.java
View file @
0f5c0643
...
...
@@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@Api
(
value
=
"新Cdp同步员工(基础信息)"
,
tags
=
"新Cdp同步员工(基础信息)"
)
@RequestMapping
(
value
=
"/api/synEmp"
)
@RequestMapping
(
value
=
"/api/synEmp
Cdp
"
)
public
class
SyncEmployeCdpController
{
@Autowired
...
...
src/main/java/com/rome/order/domain/service/impl/OrganizationRedisServiceImpl.java
View file @
0f5c0643
...
...
@@ -6,9 +6,11 @@ import com.rome.order.domain.constant.RedisConstant;
import
com.rome.order.domain.service.OrganizationRedisService
;
import
com.rome.order.domain.util.PageInfo
;
import
com.rome.order.domain.util.RedisService
;
import
com.rome.order.infrastructure.remote.constant.RemoteConstant
;
import
com.rome.order.infrastructure.remote.dto.res.OrgDTO
;
import
com.rome.order.infrastructure.remote.facade.OrganizationFacade
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
...
...
@@ -57,7 +59,7 @@ public class OrganizationRedisServiceImpl implements OrganizationRedisService {
public
List
<
OrgDTO
>
getAllOrgRedis
()
{
List
<
OrgDTO
>
organizationRedisDTOS
=
new
ArrayList
<>();
Object
cacheObject
=
redisService
.
getValue
(
RedisConstant
.
DEPARTMENT_ORGANIZATION
);
if
(
Objects
.
nonNull
(
cacheObject
))
{
if
(
Objects
.
nonNull
(
cacheObject
)
&&!
RemoteConstant
.
EMP
.
equals
(
cacheObject
)
)
{
organizationRedisDTOS
=
JSON
.
parseArray
(
cacheObject
.
toString
(),
OrgDTO
.
class
);
}
else
{
organizationRedisDTOS
=
this
.
getRemoteOrgCdpList
();
...
...
src/main/java/com/rome/order/domain/service/impl/QiDianServiceImpl.java
View file @
0f5c0643
...
...
@@ -14,7 +14,9 @@ import com.rome.order.domain.constant.BaseConstant;
import
com.rome.order.domain.constant.QiDianConstant
;
import
com.rome.order.domain.constant.RedisConstant
;
import
com.rome.order.domain.service.QiDianService
;
import
com.rome.order.domain.util.*
;
import
com.rome.order.domain.util.HttpUtil
;
import
com.rome.order.domain.util.Md5Utils
;
import
com.rome.order.domain.util.RedisService
;
import
com.rome.order.infrastructure.dataobject.SyncOrgDO
;
import
com.rome.order.infrastructure.remote.constant.QiDianRemoteConstant
;
import
com.rome.order.infrastructure.remote.constant.RemoteConstant
;
...
...
@@ -34,7 +36,10 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
@Service
@Slf4j
...
...
@@ -55,6 +60,17 @@ public class QiDianServiceImpl implements QiDianService {
@Value
(
"${qidian.password:}"
)
private
String
password
;
private
String
corporationId
=
"0"
;
private
String
secret
=
"ajdjhfwjk123"
;
@Value
(
"${beidou.openapiUrl:}"
)
private
String
beidouOpenapiUrl
;
private
String
consoleUrl
=
"https://beidou.test.laiyifen.com/console"
;
@Override
public
String
getCacheToken
()
{
String
key
=
RedisConstant
.
QIDIAN_TENCENT_ACCESS_TOKEN
;
...
...
@@ -73,12 +89,9 @@ public class QiDianServiceImpl implements QiDianService {
@Override
public
String
getSSOCallback
(
String
code
)
{
//使用urlencode转义
String
redirectUrlEncode
=
ServletUtils
.
urlEncode
(
redirectUrl
);
//跳转至企点鉴权地址
String
url
=
QiDianConstant
.
SKIP_CALLBACK_URL
+
RemoteConstant
.
SKIP_SSOCALLBACK_URL
+
"?code="
+
code
+
"&appid="
+
QiDianConstant
.
APP_ID
+
"&redirect_url="
+
redirectUrlEncode
;
log
.
info
(
"---getSSOCallbackUrl获取的地址为-----:{}"
,
url
);
return
url
;
//三方sso登录
String
result
=
this
.
login
(
code
);
return
result
;
}
@Override
...
...
@@ -442,16 +455,12 @@ public class QiDianServiceImpl implements QiDianService {
@Override
public
String
login
(
String
code
)
{
try
{
String
url
=
String
.
format
(
RemoteConstant
.
SSO_LOGIN_API_URL
,
code
);
Map
<
String
,
String
>
headers
=
getSSOHeaderMap
()
;
String
url
=
String
.
format
(
beidouOpenapiUrl
+
RemoteConstant
.
SSO_LOGIN_API_URL
,
code
,
consoleUrl
);
Map
<
String
,
String
>
headers
=
HttpUtil
.
getOpenApiHeaderMap
(
corporationId
,
secret
);
;
log
.
info
(
"-----第三方sso登录------url:{},headers={}"
,
url
,
JSONObject
.
toJSONString
(
headers
));
String
result
=
HttpUtil
.
httpGet
(
url
,
headers
);
log
.
info
(
"-----第三方sso登录,result------:{}"
,
result
);
Map
map
=
JSONObject
.
parseObject
(
result
,
Map
.
class
);
if
(
RemoteConstant
.
SSO_SUCCESS
.
equals
(
Integer
.
parseInt
(
map
.
get
(
"code"
).
toString
())))
{
//todo 成功
}
return
map
.
get
(
"msg"
).
toString
();
return
result
;
}
catch
(
Exception
e
)
{
String
errorMsg
=
e
.
getMessage
();
log
.
error
(
"-----第三方sso登录报错了-------:{}"
,
errorMsg
);
...
...
@@ -462,16 +471,12 @@ public class QiDianServiceImpl implements QiDianService {
@Override
public
String
logout
(
String
account
)
{
try
{
String
url
=
String
.
format
(
RemoteConstant
.
SSO_LOGOUT_API_URL
,
account
);
Map
<
String
,
String
>
headers
=
getSSOHeaderMap
(
);
String
url
=
String
.
format
(
beidouOpenapiUrl
+
RemoteConstant
.
SSO_LOGOUT_API_URL
,
account
);
Map
<
String
,
String
>
headers
=
HttpUtil
.
getOpenApiHeaderMap
(
corporationId
,
secret
);
log
.
info
(
"-----第三方sso用户退出登录------url:{},headers={}"
,
url
,
JSONObject
.
toJSONString
(
headers
));
String
result
=
HttpUtil
.
httpGet
(
url
,
headers
);
log
.
info
(
"-----第三方sso用户退出登录,result------:{}"
,
result
);
Map
map
=
JSONObject
.
parseObject
(
result
,
Map
.
class
);
if
(
RemoteConstant
.
SSO_SUCCESS
.
equals
(
Integer
.
parseInt
(
map
.
get
(
"code"
).
toString
())))
{
//todo 成功
}
return
map
.
get
(
"msg"
).
toString
();
return
result
;
}
catch
(
Exception
e
)
{
String
errorMsg
=
e
.
getMessage
();
log
.
error
(
"-----第三方sso登录报错了-------:{}"
,
errorMsg
);
...
...
@@ -479,14 +484,5 @@ public class QiDianServiceImpl implements QiDianService {
}
}
private
Map
<
String
,
String
>
getSSOHeaderMap
()
{
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
String
timestamp
=
DateUtils
.
convert
(
new
Date
(),
DateUtils
.
YYYYMMDDHHMMSS
);
headers
.
put
(
"corporationId"
,
"0"
);
headers
.
put
(
"timestamp"
,
timestamp
);
headers
.
put
(
"sign"
,
HmacSHA256Util
.
getSign
(
timestamp
));
return
headers
;
}
}
src/main/java/com/rome/order/domain/service/impl/SyncEmployeCdpServiceImpl.java
View file @
0f5c0643
...
...
@@ -6,8 +6,6 @@ import com.github.pagehelper.PageInfo;
import
com.rome.order.domain.enums.ResponseMsg
;
import
com.rome.order.domain.service.OrganizationRedisService
;
import
com.rome.order.domain.service.SyncEmployeCdpService
;
import
com.rome.order.domain.util.DateUtils
;
import
com.rome.order.domain.util.HmacSHA256Util
;
import
com.rome.order.domain.util.HttpUtil
;
import
com.rome.order.domain.util.ParameterCheckUtils
;
import
com.rome.order.infrastructure.dataobject.SyncEmployeeCdpDO
;
...
...
@@ -15,18 +13,20 @@ import com.rome.order.infrastructure.mapper.SyncEmployeeCdpMapper;
import
com.rome.order.infrastructure.remote.constant.QiDianOpenApiRemoteConstant
;
import
com.rome.order.infrastructure.remote.constant.RemoteConstant
;
import
com.rome.order.infrastructure.remote.dto.req.EmpMainStaffsReqDTO
;
import
com.rome.order.infrastructure.remote.dto.req.SyncCdpEmpOrgReqDTO
;
import
com.rome.order.infrastructure.remote.dto.res.EmpMainDataResDTO
;
import
com.rome.order.infrastructure.remote.dto.res.OrgDTO
;
import
com.rome.order.infrastructure.remote.facade.UserEmployeeFacade
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.hadoop.yarn.webapp.hamlet.Hamlet
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -50,6 +50,16 @@ public class SyncEmployeCdpServiceImpl implements SyncEmployeCdpService {
private
OrganizationRedisService
organizationRedisService
;
@Value
(
"${beidou.openapiUrl:}"
)
private
String
beidouOpenapiUrl
;
@Value
(
"${beidou.email:}"
)
private
Boolean
beidouEmail
;
private
String
corporationId
=
"0"
;
private
String
secret
=
"ajdjhfwjk123"
;
@Override
public
Boolean
synAllEmpCdpBase
(
Integer
pageNum
)
{
List
<
OrgDTO
>
allOrg
=
organizationRedisService
.
getAllOrgRedis
();
...
...
@@ -89,14 +99,9 @@ public class SyncEmployeCdpServiceImpl implements SyncEmployeCdpService {
@Override
public
String
synProgress
()
{
try
{
String
timestamp
=
DateUtils
.
convert
(
new
Date
(),
DateUtils
.
YYYYMMDDHHMMSS
);
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"corporationId"
,
"0"
);
headers
.
put
(
"timestamp"
,
timestamp
);
String
sign
=
HmacSHA256Util
.
getSign
(
timestamp
);
headers
.
put
(
"sign"
,
sign
);
Map
<
String
,
String
>
headers
=
HttpUtil
.
getOpenApiHeaderMap
(
corporationId
,
secret
);
log
.
info
(
"------指定某员工为企业管理员查询组织架构导入进度头部信息------:{}"
,
JSON
.
toJSONString
(
headers
));
String
result
=
HttpUtil
.
httpGet
(
QiDianOpenApiRemoteConstant
.
SYNC_PROGRESS_URL
,
headers
);
String
result
=
HttpUtil
.
httpGet
(
beidouOpenapiUrl
+
QiDianOpenApiRemoteConstant
.
SYNC_PROGRESS_URL
,
headers
);
log
.
info
(
"----synProgress返回信息----:{}"
,
result
);
return
result
;
}
catch
(
Exception
e
)
{
...
...
@@ -105,6 +110,14 @@ public class SyncEmployeCdpServiceImpl implements SyncEmployeCdpService {
}
}
private
Map
<
String
,
String
>
getEmailMap
(){
List
<
String
>
employeeByEmail
=
syncEmployeeCdpMapper
.
findEmployeeByEmail
();
if
(
CollectionUtils
.
isEmpty
(
employeeByEmail
)){
return
null
;
}
Map
<
String
,
String
>
emailMap
=
employeeByEmail
.
stream
().
collect
(
Collectors
.
toMap
(
Function
.
identity
(),
Function
.
identity
()));
return
emailMap
;
}
/**
* 同步员工数据
...
...
@@ -180,93 +193,121 @@ public class SyncEmployeCdpServiceImpl implements SyncEmployeCdpService {
List
<
SyncEmployeeCdpDO
>
employeeCdpListByUserIds
=
syncEmployeeCdpMapper
.
findEmployeeCdpListByUserIds
(
userIds
);
if
(
CollectionUtils
.
isEmpty
(
employeeCdpListByUserIds
)){
//需要用户id 根据进行去重
empResList
=
empResList
.
stream
().
collect
(
Collectors
.
collectingAndThen
(
Collectors
.
toCollection
(()
->
new
TreeSet
<>(
Comparator
.
comparing
(
o
->
o
.
getUserId
()))),
ArrayList:
:
new
));
//
empResList = empResList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getUserId()))), ArrayList::new));
syncEmployeeCdpMapper
.
batchSaveEmpCdp
(
empResList
);
//同步腾讯
List
<
EmpMainStaffsReqDTO
>
staffs
=
new
ArrayList
<>();
for
(
EmpMainDataResDTO
empMainDataResDTO:
empResList
)
{
EmpMainStaffsReqDTO
empMainStaffsReqDTO
=
new
EmpMainStaffsReqDTO
();
//获取部门编码 ,根据部门编码去获取部门详细信息
String
departmentCode
=
empMainDataResDTO
.
getDepartmentCode
();
if
(!
CollectionUtils
.
isEmpty
(
orgDTOMap
)&&
orgDTOMap
.
containsKey
(
departmentCode
)){
List
<
OrgDTO
>
orgDTOList
=
orgDTOMap
.
get
(
departmentCode
);
OrgDTO
orgDTO
=
orgDTOList
.
get
(
0
);
List
<
String
>
fullDeptNames
=
new
ArrayList
<>();
String
name
=
orgDTO
.
getName
();
fullDeptNames
.
add
(
name
);
//不断的查询上级部门,并获取部门名称,直到为空,
String
parentDepartmentCode
=
orgDTO
.
getParentDepartmentCode
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
//不断的去查询父级
if
(
orgDTOMap
.
containsKey
(
parentDepartmentCode
)){
List
<
OrgDTO
>
orgDTOtTempList
=
orgDTOMap
.
get
(
parentDepartmentCode
);
OrgDTO
orgDTOTemp
=
orgDTOtTempList
.
get
(
0
);
String
parentDeptName
=
orgDTOTemp
.
getName
();
//替换原来
parentDepartmentCode
=
orgDTOTemp
.
getParentDepartmentCode
();
if
(
StringUtils
.
isEmpty
(
parentDepartmentCode
)){
break
;
}
this
.
orgSyncTecent
(
empResList
,
orgDTOMap
);
}
else
{
//批量添加
List
<
EmpMainDataResDTO
>
batchAdd
=
new
ArrayList
<>();
Map
<
Long
,
SyncEmployeeCdpDO
>
empMainMap
=
employeeCdpListByUserIds
.
stream
().
collect
(
Collectors
.
toMap
(
SyncEmployeeCdpDO:
:
getUserId
,
Function
.
identity
()));
for
(
EmpMainDataResDTO
empResDTO:
empResList
)
{
Long
userId
=
empResDTO
.
getUserId
();
if
(!
empMainMap
.
containsKey
(
userId
)){
batchAdd
.
add
(
empResDTO
);
}
}
if
(!
CollectionUtils
.
isEmpty
(
batchAdd
)){
syncEmployeeCdpMapper
.
batchSaveEmpCdp
(
batchAdd
);
//同步腾讯
this
.
orgSyncTecent
(
empResList
,
orgDTOMap
);
}
}
}
/**
* 同步组织架构到腾讯
* @param empResList
*/
private
void
orgSyncTecent
(
List
<
EmpMainDataResDTO
>
empResList
,
Map
<
String
,
List
<
OrgDTO
>>
orgDTOMap
){
//同步腾讯
List
<
EmpMainStaffsReqDTO
>
staffs
=
new
ArrayList
<>();
for
(
EmpMainDataResDTO
empMainDataResDTO:
empResList
)
{
EmpMainStaffsReqDTO
empMainStaffsReqDTO
=
new
EmpMainStaffsReqDTO
();
//获取部门编码 ,根据部门编码去获取部门详细信息
String
departmentCode
=
empMainDataResDTO
.
getDepartmentCode
();
if
(!
CollectionUtils
.
isEmpty
(
orgDTOMap
)&&
orgDTOMap
.
containsKey
(
departmentCode
)){
List
<
OrgDTO
>
orgDTOList
=
orgDTOMap
.
get
(
departmentCode
);
OrgDTO
orgDTO
=
orgDTOList
.
get
(
0
);
List
<
String
>
fullDeptNames
=
new
ArrayList
<>();
String
name
=
orgDTO
.
getName
();
fullDeptNames
.
add
(
name
);
//不断的查询上级部门,并获取部门名称,直到为空,
String
parentDepartmentCode
=
orgDTO
.
getParentDepartmentCode
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
//不断的去查询父级
if
(
orgDTOMap
.
containsKey
(
parentDepartmentCode
)){
List
<
OrgDTO
>
orgDTOtTempList
=
orgDTOMap
.
get
(
parentDepartmentCode
);
OrgDTO
orgDTOTemp
=
orgDTOtTempList
.
get
(
0
);
String
parentDeptName
=
orgDTOTemp
.
getName
();
//替换原来
parentDepartmentCode
=
orgDTOTemp
.
getParentDepartmentCode
();
if
(
StringUtils
.
isEmpty
(
parentDepartmentCode
)){
fullDeptNames
.
add
(
parentDeptName
);
break
;
}
}
if
(!
CollectionUtils
.
isEmpty
(
fullDeptNames
)){
Collections
.
reverse
(
fullDeptNames
);
String
fullDeptName
=
fullDeptNames
.
stream
().
map
(
String:
:
valueOf
).
collect
(
Collectors
.
joining
(
"/"
));
empMainStaffsReqDTO
.
setFullDeptName
(
fullDeptName
);
fullDeptNames
.
add
(
parentDeptName
);
}
}
empMainStaffsReqDTO
.
setAccountId
(
empMainDataResDTO
.
getUserId
()+
""
);
empMainStaffsReqDTO
.
setAccountName
(
empMainDataResDTO
.
getName
());
empMainStaffsReqDTO
.
setEmail
(
empMainDataResDTO
.
getCompanyEmail
());
staffs
.
add
(
empMainStaffsReqDTO
);
}
String
result
=
this
.
syncCdpEmpOrg
(
staffs
);
//成功标识
Boolean
successFlag
=
false
;
String
errMsg
=
""
;
if
(
StringUtils
.
isNotBlank
(
result
)){
Map
map
=
JSONObject
.
parseObject
(
result
,
Map
.
class
);
if
(
Objects
.
nonNull
(
map
.
get
(
"status"
)))
{
Object
statusObj
=
map
.
get
(
"status"
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
statusObj
));
String
code
=
jsonObject
.
getString
(
"code"
);
String
message
=
jsonObject
.
getString
(
"message"
);
//返回为1 表示成功
if
(
RemoteConstant
.
CODE
.
equals
(
code
)){
successFlag
=
true
;
}
else
{
//其他的表示失败
errMsg
=
message
;
}
if
(!
CollectionUtils
.
isEmpty
(
fullDeptNames
)){
Collections
.
reverse
(
fullDeptNames
);
//员工对应所有部门信息
String
fullDeptName
=
fullDeptNames
.
stream
().
map
(
String:
:
valueOf
).
collect
(
Collectors
.
joining
(
"/"
));
empMainStaffsReqDTO
.
setFullDeptName
(
fullDeptName
);
empMainDataResDTO
.
setDepartmentAll
(
fullDeptName
);
}
}
//整个批次成功
if
(
successFlag
){
empResList
.
forEach
(
s
->{
s
.
setIsSyncEmployee
(
RemoteConstant
.
IS_SYNC_EMPLOYEE_SUCCESS
);
});
empMainStaffsReqDTO
.
setAccountId
(
empMainDataResDTO
.
getUserId
()+
""
);
empMainStaffsReqDTO
.
setAccountName
(
empMainDataResDTO
.
getName
());
//判断数据库中对应的邮箱是否存在
String
companyEmail
=
empMainDataResDTO
.
getCompanyEmail
();
if
(
beidouEmail
){
empMainStaffsReqDTO
.
setEmail
(
companyEmail
);
}
else
{
for
(
EmpMainDataResDTO
s:
empResList
)
{
s
.
setIsSyncEmployee
(
RemoteConstant
.
IS_SYNC_EMPLOYEE_FAIL
);
s
.
setErrorMsg
(
errMsg
);
empMainStaffsReqDTO
.
setEmail
(
null
);
}
staffs
.
add
(
empMainStaffsReqDTO
);
}
String
result
=
this
.
syncCdpEmpOrg
(
staffs
);
//成功标识
Boolean
successFlag
=
false
;
String
errMsg
=
""
;
if
(
StringUtils
.
isNotBlank
(
result
)){
Map
map
=
JSONObject
.
parseObject
(
result
,
Map
.
class
);
if
(
Objects
.
nonNull
(
map
.
get
(
"status"
)))
{
Object
statusObj
=
map
.
get
(
"status"
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
statusObj
));
String
code
=
jsonObject
.
getString
(
"code"
);
String
message
=
jsonObject
.
getString
(
"message"
);
//返回为1 表示成功
if
(
RemoteConstant
.
CODE
.
equals
(
code
)){
successFlag
=
true
;
}
else
{
//其他的表示失败
errMsg
=
message
;
}
}
}
//整个批次成功
if
(
successFlag
){
empResList
.
forEach
(
s
->{
s
.
setIsSyncEmployee
(
RemoteConstant
.
IS_SYNC_EMPLOYEE_SUCCESS
);
});
}
else
{
for
(
EmpMainDataResDTO
s:
empResList
)
{
s
.
setIsSyncEmployee
(
RemoteConstant
.
IS_SYNC_EMPLOYEE_FAIL
);
s
.
setErrorMsg
(
errMsg
);
}
}
syncEmployeeCdpMapper
.
batchUpdateEmpCdp
(
empResList
);
}
private
String
orgSetAdminAccountId
(
String
accountId
){
try
{
log
.
info
(
"-----指定某员工为企业管理员/api/dataauth/authserver/openapi/org/set/admin入参信息----:{}"
,
accountId
);
String
timestamp
=
DateUtils
.
convert
(
new
Date
(),
DateUtils
.
YYYYMMDDHHMMSS
);
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"corporationId"
,
"0"
);
headers
.
put
(
"timestamp"
,
timestamp
);
String
sign
=
HmacSHA256Util
.
getSign
(
timestamp
);
headers
.
put
(
"sign"
,
sign
);
Map
<
String
,
String
>
headers
=
HttpUtil
.
getOpenApiHeaderMap
(
corporationId
,
secret
);
log
.
info
(
"------指定某员工为企业管理员/api/dataauth/authserver/openapi/org/set/admin头部信息------:{}"
,
JSON
.
toJSONString
(
headers
));
String
result
=
HttpUtil
.
httpGet
(
QiDianOpenApiRemoteConstant
.
SET_ADMIN_ACCOUNT_URL
+
accountId
,
headers
);
String
result
=
HttpUtil
.
httpGet
(
beidouOpenapiUrl
+
QiDianOpenApiRemoteConstant
.
SET_ADMIN_ACCOUNT_URL
+
accountId
,
headers
);
log
.
info
(
"----orgSetAdminAccountId返回信息----:{}"
,
result
);
return
result
;
}
catch
(
Exception
e
)
{
...
...
@@ -281,16 +322,13 @@ public class SyncEmployeCdpServiceImpl implements SyncEmployeCdpService {
*/
private
String
syncCdpEmpOrg
(
List
<
EmpMainStaffsReqDTO
>
staffs
){
try
{
String
bodyStr
=
JSON
.
toJSONString
(
staffs
);
SyncCdpEmpOrgReqDTO
syncCdpEmpOrgReqDTO
=
new
SyncCdpEmpOrgReqDTO
();
syncCdpEmpOrgReqDTO
.
setStaffs
(
staffs
);
String
bodyStr
=
JSON
.
toJSONString
(
syncCdpEmpOrgReqDTO
);
log
.
info
(
"-----同步导入组织架构和人员信息到企点/api/dataauth/authserver/openapi/org/sync入参信息----:{}"
,
bodyStr
);
String
timestamp
=
DateUtils
.
convert
(
new
Date
(),
DateUtils
.
YYYYMMDDHHMMSS
);
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"corporationId"
,
"0"
);
headers
.
put
(
"timestamp"
,
timestamp
);
String
sign
=
HmacSHA256Util
.
getSign
(
timestamp
);
headers
.
put
(
"sign"
,
sign
);
Map
<
String
,
String
>
headers
=
HttpUtil
.
getOpenApiHeaderMap
(
corporationId
,
secret
);
log
.
info
(
"------同步导入组织架构和人员信息到企点/api/dataauth/authserver/openapi/org/sync头部信息------:{}"
,
JSON
.
toJSONString
(
headers
));
String
result
=
HttpUtil
.
httpPost
(
QiDianOpenApiRemoteConstant
.
ORG_SYNC_URL
,
bodyStr
,
headers
);
String
result
=
HttpUtil
.
httpPost
(
beidouOpenapiUrl
+
QiDianOpenApiRemoteConstant
.
ORG_SYNC_URL
,
bodyStr
,
headers
);
log
.
info
(
"----syncCdpEmpOrg返回信息----:{}"
,
result
);
return
result
;
}
catch
(
Exception
e
)
{
...
...
src/main/java/com/rome/order/domain/util/DateUtils.java
View file @
0f5c0643
...
...
@@ -359,6 +359,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
return
new
SimpleDateFormat
(
dateFormat
).
format
(
date
);
}
/**
* 获取时间搓
* @return
*/
public
static
String
getUnixTimestamp
()
{
return
String
.
valueOf
(
System
.
currentTimeMillis
()/
1000
);
}
/**
* 推荐使用 getFormatDateTime(Object date)
*
...
...
src/main/java/com/rome/order/domain/util/HmacSHA256Util.java
View file @
0f5c0643
...
...
@@ -71,10 +71,9 @@ public class HmacSHA256Util {
* 获取请求头sign
* @return
*/
public
static
String
getSign
(
String
timestamp
){
public
static
String
getSign
(
String
secret
,
String
message
){
try
{
String
enterpriseId
=
"0"
;
String
str
=
HmacSHA256Util
.
hmacSHA256
(
enterpriseId
,
timestamp
);
String
str
=
HmacSHA256Util
.
hmacSHA256
(
secret
,
message
);
String
encodeStr
=
Base64
.
encodeBase64String
(
str
.
getBytes
());
return
encodeStr
;
}
catch
(
Exception
e
)
{
...
...
src/main/java/com/rome/order/domain/util/HttpUtil.java
View file @
0f5c0643
...
...
@@ -16,6 +16,7 @@ import org.apache.http.protocol.HTTP;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
...
...
@@ -178,4 +179,18 @@ public class HttpUtil {
}
}
public
static
Map
<
String
,
String
>
getOpenApiHeaderMap
(
String
corporationId
,
String
secret
)
{
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
String
timestamp
=
DateUtils
.
getUnixTimestamp
();
headers
.
put
(
"corporationId"
,
corporationId
);
headers
.
put
(
"timestamp"
,
timestamp
);
String
sign
=
SignUtil
.
getSign
(
corporationId
,
secret
,
timestamp
);
headers
.
put
(
"sign"
,
sign
);
return
headers
;
}
}
src/main/java/com/rome/order/domain/util/SignUtil.java
0 → 100644
View file @
0f5c0643
package
com
.
rome
.
order
.
domain
.
util
;
import
javax.crypto.Mac
;
import
javax.crypto.spec.SecretKeySpec
;
import
sun.misc.BASE64Encoder
;
/**
* @Author: zhoupeng
* @createTime: 2023年08月31日 11:49:01
* @version: 1.0
* @Description:
* @copyright:
*/
public
class
SignUtil
{
private
static
final
String
SHA265
=
"HmacSHA256"
;
private
static
final
String
SHA1
=
"HmacSHA1"
;
/**
* 将加密后的字节数组转换成字符串
*
* @param b 字节数组
* @return 字符串
*/
private
static
String
byteArrayToHexString
(
byte
[]
b
)
{
StringBuilder
hs
=
new
StringBuilder
();
String
stmp
;
for
(
int
n
=
0
;
b
!=
null
&&
n
<
b
.
length
;
n
++)
{
stmp
=
Integer
.
toHexString
(
b
[
n
]
&
0XFF
);
if
(
stmp
.
length
()
==
1
)
{
hs
.
append
(
'0'
);
}
hs
.
append
(
stmp
);
}
return
hs
.
toString
().
toLowerCase
();
}
/**
* sha256_HMAC加密
*
* @param source 消息
* @param secret 秘钥
* @param signatureMethod 加密类型
* @return 加密后字符串-base64
*/
private
static
byte
[]
sign
(
String
source
,
String
secret
,
String
signatureMethod
)
{
byte
[]
bytes
=
{};
try
{
Mac
sha256HMAC
=
Mac
.
getInstance
(
signatureMethod
);
SecretKeySpec
secretKey
=
new
SecretKeySpec
(
secret
.
getBytes
(),
signatureMethod
);
sha256HMAC
.
init
(
secretKey
);
bytes
=
sha256HMAC
.
doFinal
(
source
.
getBytes
());
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"sign error ==========="
+
e
.
getMessage
());
}
return
bytes
;
}
// HmacSHA256加密,base64编码
public
static
String
signToBase64BySHA256
(
String
source
,
String
secret
)
{
byte
[]
hmacSHA256Bytes
=
sign
(
source
,
secret
,
SHA265
);
return
new
BASE64Encoder
().
encode
(
hmacSHA256Bytes
);
}
// HmacSHA256加密,hex编码
public
static
String
signToBaseHexBySHA256
(
String
source
,
String
secret
)
{
byte
[]
hmacSHA256Bytes
=
sign
(
source
,
secret
,
SHA265
);
return
byteArrayToHexString
(
hmacSHA256Bytes
);
}
public
static
String
getSign
(
String
tenantId
,
String
secret
,
String
timestamp
){
String
sign
=
signToBase64BySHA256
(
tenantId
+
timestamp
,
secret
);
return
sign
;
}
public
static
void
main
(
String
[]
args
)
{
String
tenantId
=
"0"
;
long
timestamp
=
System
.
currentTimeMillis
()
/
1000
;
System
.
out
.
println
(
timestamp
);
String
s
=
signToBase64BySHA256
(
tenantId
+
timestamp
,
"cdpentity123"
);
System
.
out
.
println
(
s
);
}
}
src/main/java/com/rome/order/infrastructure/dataobject/SyncEmployeeCdpDO.java
View file @
0f5c0643
...
...
@@ -52,10 +52,6 @@ public class SyncEmployeeCdpDO {
private
String
name
;
/**
* 性别:1-男,2-女
*/
private
Integer
gender
;
/**
...
...
@@ -70,17 +66,6 @@ public class SyncEmployeeCdpDO {
private
String
departmentName
;
/**
* 手机号
*/
private
String
mobile
;
/**
* 电话号
*/
private
String
phone
;
/**
...
...
src/main/java/com/rome/order/infrastructure/mapper/SyncEmployeeCdpMapper.java
View file @
0f5c0643
...
...
@@ -26,6 +26,12 @@ public interface SyncEmployeeCdpMapper {
*/
int
batchSaveEmpCdp
(
@Param
(
"empList"
)
List
<
EmpMainDataResDTO
>
empList
);
/**
* 批量修改同步员工状态信息
* @param empList
* @return
*/
int
batchUpdateEmpCdp
(
@Param
(
"empList"
)
List
<
EmpMainDataResDTO
>
empList
);
/**
* 根据同步的员工号获取员工信息
...
...
@@ -35,4 +41,12 @@ public interface SyncEmployeeCdpMapper {
*/
List
<
SyncEmployeeCdpDO
>
findEmployeeCdpListByUserIds
(
@Param
(
"userIds"
)
List
<
Long
>
userIds
);
/**
* 查询所有的邮箱
* @param
* @return
*/
List
<
String
>
findEmployeeByEmail
();
}
src/main/java/com/rome/order/infrastructure/remote/dto/req/SyncCdpEmpOrgReqDTO.java
0 → 100644
View file @
0f5c0643
package
com
.
rome
.
order
.
infrastructure
.
remote
.
dto
.
req
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.List
;
/**
* @Author: zhoupeng
* @createTime: 2023年08月31日 13:41:06
* @version: 1.0
* @Description:
* @copyright:
*/
@Data
public
class
SyncCdpEmpOrgReqDTO
{
@ApiModelProperty
(
value
=
"导入企业组织架构信息"
)
List
<
EmpMainStaffsReqDTO
>
staffs
;
}
src/main/java/com/rome/order/infrastructure/remote/dto/res/EmpMainDataResDTO.java
View file @
0f5c0643
...
...
@@ -153,6 +153,7 @@ public class EmpMainDataResDTO {
@ApiModelProperty
(
value
=
"是否停用员工 0-企点正常激活 1-企点停用"
)
private
Integer
isDisable
;
@ApiModelProperty
(
value
=
"对应的所有部门"
)
private
String
departmentAll
;
}
src/main/resources/application.yml
View file @
0f5c0643
...
...
@@ -61,36 +61,36 @@ elasticjob:
elasticJobClass
:
com.rome.order.domain.task.SynByStartDateEmpBaseJob
cron
:
0 0 0/1 * * ?
shardingTotalCount
:
1
SynFailEmployeeJob
:
shardingItemParameters
:
0=0
elasticJobClass
:
com.rome.order.domain.task.SynFailEmployeeJob
cron
:
0 0/30 * * * ?
shardingTotalCount
:
1
SyncAllOrgJob
:
shardingItemParameters
:
0=0
elasticJobClass
:
com.rome.order.domain.task.SyncAllOrgJob
cron
:
0 0 23 * * ?
shardingTotalCount
:
1
SynFailOrgJob
:
shardingItemParameters
:
0=0
elasticJobClass
:
com.rome.order.domain.task.SynFailOrgJob
cron
:
0 0/30 * * * ?
shardingTotalCount
:
1
SyncProductJob
:
shardingItemParameters
:
0=0
elasticJobClass
:
com.rome.order.domain.task.SyncProductJob
cron
:
0 0 23 * * ?
shardingTotalCount
:
1
#
SynFailEmployeeJob:
#
shardingItemParameters: 0=0
#
elasticJobClass: com.rome.order.domain.task.SynFailEmployeeJob
#
cron: 0 0/30 * * * ?
#
shardingTotalCount: 1
#
SyncAllOrgJob:
#
shardingItemParameters: 0=0
#
elasticJobClass: com.rome.order.domain.task.SyncAllOrgJob
#
cron: 0 0 23 * * ?
#
shardingTotalCount: 1
#
SynFailOrgJob:
#
shardingItemParameters: 0=0
#
elasticJobClass: com.rome.order.domain.task.SynFailOrgJob
#
cron: 0 0/30 * * * ?
#
shardingTotalCount: 1
#
SyncProductJob:
#
shardingItemParameters: 0=0
#
elasticJobClass: com.rome.order.domain.task.SyncProductJob
#
cron: 0 0 23 * * ?
#
shardingTotalCount: 1
reg-center
:
max-sleep-time-milliseconds
:
8000
server-lists
:
'
10.6.5.66:2181,10.6.5.67:2181,10.6.5.68:2181'
base-sleep-time-milliseconds
:
8000
namespace
:
lyf-
qidian
-api
namespace
:
lyf-
beidou-cdp
-api
rocketmq
:
nameServer
:
'
10.6.5.12:9876'
defaultBigRetryNum
:
30
producer
:
group
:
lyf-
qidian
-api
group
:
lyf-
beidou-cdp
-api
defaultSmallRetryNum
:
20
eureka
:
client
:
...
...
@@ -158,6 +158,16 @@ tsa:
# 腾讯广告服务地址
remote_address
:
https://api.e.qq.com/v1.1/
#openapi接口地址
beidou
:
openapiUrl
:
https://beidou.test.laiyifen.com
#企业ID
corporationId
:
0
#密钥
secret
:
ajdjhfwjk123
#是否同步邮件
email
:
false
src/main/resources/mapper/SyncEmployeeCdpMapper.xml
View file @
0f5c0643
...
...
@@ -10,17 +10,15 @@
`employee_number`,
`employee_type`,
`name`,
`gender`,
`department_code`,
`department_name`,
`mobile`,
`phone`,
`company_code`,
`company_name`,
`company_email`,
`is_sync_employee`,
`is_disable`,
`error_msg`,
`department_all`,
`creator`,
`creator_name`,
`updator`,
...
...
@@ -33,17 +31,15 @@
#{item.employeeNumber},
#{item.employeeType},
#{item.name},
#{item.gender},
#{item.departmentCode},
#{item.departmentName},
#{item.mobile},
#{item.phone},
#{item.companyCode},
#{item.companyName},
#{item.companyEmail},
#{item.isSyncEmployee},
#{item.isDisable},
#{item.errorMsg},
#{item.departmentAll},
#{item.creator},
#{item.creatorName},
#{item.updator},
...
...
@@ -52,7 +48,25 @@
</foreach>
</insert>
<!-- 批量修改同步员工信息 -->
<update
id=
"batchUpdateEmpCdp"
parameterType=
"java.util.List"
>
<foreach
close=
""
collection=
"empList"
index=
"index"
item=
"item"
open=
""
separator=
";"
>
update sync_employee_cdp
<trim
prefix=
"set"
suffixOverrides=
","
suffix=
"where user_id=#{item.userId}"
>
<if
test=
"item.isSyncEmployee != null"
>
`is_sync_employee`=#{item.isSyncEmployee},
</if>
<if
test=
"item.departmentAll != null and item.departmentAll!='' "
>
`department_all`=#{item.departmentAll},
</if>
<if
test=
"item.errorMsg != null and item.errorMsg!='' "
>
`error_msg`=#{item.errorMsg},
</if>
resent_number = resent_number + 1
</trim>
</foreach>
</update>
<!-- 根据同步的员工号获取员工信息 -->
<select
id=
"findEmployeeCdpListByUserIds"
parameterType=
"java.util.List"
resultType=
"com.rome.order.infrastructure.dataobject.SyncEmployeeCdpDO"
>
...
...
@@ -63,11 +77,8 @@
se.employee_number,
se.employee_type,
se.name,
se.gender,
se.department_code,
se.department_name,
se.mobile,
se.phone,
se.company_code,
se.company_name,
se.company_email,
...
...
@@ -91,5 +102,12 @@
</if>
</select>
<!-- 根据邮箱号进行查询 -->
<select
id=
"findEmployeeByEmail"
resultType=
"java.lang.String"
>
SELECT
se.company_email
FROM sync_employee_cdp se
where se.is_delete = 0 and se.company_email is not null group by se.company_email
</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