Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
李苗
/
Vion-DevOps
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ef75b2f3
authored
Aug 08, 2024
by
HlQ
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[add] 使用 RestClient 替换 Hutool 的 http 请求工具类
[fix] 修复项目合并时,集团 id 错误的问题
1 parent
f18e25ef
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
199 additions
and
104 deletions
src/main/java/vion/config/RestClientConfig.java
src/main/java/vion/cron/ContractRunner.java
src/main/java/vion/service/impl/ContractServiceImpl.java
src/main/java/vion/service/impl/StoreServiceImpl.java
src/main/java/vion/third/DingMod.java
src/main/java/vion/config/RestClientConfig.java
0 → 100644
View file @
ef75b2f
package
vion
.
config
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.client.RestClient
;
/**
* @author HlQ
* @date 2024/7/19
*/
@Configuration
@Slf4j
public
class
RestClientConfig
{
@Bean
(
name
=
"bongRestClient"
)
public
RestClient
getBongRestClient
()
{
return
RestClient
.
builder
()
.
baseUrl
(
"https://proapi.xbongbong.com"
)
.
build
();
}
@Bean
(
name
=
"oDingRestClient"
)
public
RestClient
getODingRestClient
()
{
return
RestClient
.
builder
()
.
baseUrl
(
"https://oapi.dingtalk.com"
)
.
build
();
}
@Bean
(
name
=
"dingRestClient"
)
public
RestClient
getdingRestClient
()
{
return
RestClient
.
builder
()
.
baseUrl
(
"https://api.dingtalk.com"
)
.
build
();
}
}
src/main/java/vion/cron/ContractRunner.java
View file @
ef75b2f
...
@@ -10,15 +10,15 @@ import org.dromara.hutool.core.math.NumberUtil;
...
@@ -10,15 +10,15 @@ import org.dromara.hutool.core.math.NumberUtil;
import
org.dromara.hutool.core.text.StrUtil
;
import
org.dromara.hutool.core.text.StrUtil
;
import
org.dromara.hutool.core.util.ObjUtil
;
import
org.dromara.hutool.core.util.ObjUtil
;
import
org.dromara.hutool.crypto.SecureUtil
;
import
org.dromara.hutool.crypto.SecureUtil
;
import
org.dromara.hutool.http.client.Request
;
import
org.dromara.hutool.http.meta.Method
;
import
org.dromara.hutool.json.JSONObject
;
import
org.dromara.hutool.json.JSONObject
;
import
org.dromara.hutool.json.JSONUtil
;
import
org.dromara.hutool.json.JSONUtil
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.MediaType
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.client.RestClient
;
import
vion.constant.RedisKeyEnum
;
import
vion.constant.RedisKeyEnum
;
import
vion.model.Dictionary
;
import
vion.model.Dictionary
;
import
vion.model.*
;
import
vion.model.*
;
...
@@ -46,6 +46,7 @@ public class ContractRunner {
...
@@ -46,6 +46,7 @@ public class ContractRunner {
private
final
IPaymentService
paymentService
;
private
final
IPaymentService
paymentService
;
private
final
IRContractProductService
contractProductService
;
private
final
IRContractProductService
contractProductService
;
private
final
RedissonClient
redissonClient
;
private
final
RedissonClient
redissonClient
;
private
final
RestClient
bongRestClient
;
@Value
(
"${xbongbong.token}"
)
@Value
(
"${xbongbong.token}"
)
private
String
token
;
private
String
token
;
...
@@ -75,12 +76,13 @@ public class ContractRunner {
...
@@ -75,12 +76,13 @@ public class ContractRunner {
.
set
(
"corpid"
,
corpId
)
.
set
(
"corpid"
,
corpId
)
.
set
(
"formId"
,
8429903
)
.
set
(
"formId"
,
8429903
)
.
set
(
"pageSize"
,
100
);
.
set
(
"pageSize"
,
100
);
var
res
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/contract/list"
)
var
jobO
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/contract/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
body
(
json
.
toString
())
.
body
(
json
.
toString
())
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
jobO
=
JSONUtil
.
parseObj
(
res
.
bodyStr
());
if
(
jobO
.
getInt
(
"code"
)
!=
1
)
{
if
(
jobO
.
getInt
(
"code"
)
!=
1
)
{
log
.
error
(
"获取合同列表失败,错误原因:{}"
,
jobO
);
log
.
error
(
"获取合同列表失败,错误原因:{}"
,
jobO
);
return
;
return
;
...
@@ -115,12 +117,13 @@ public class ContractRunner {
...
@@ -115,12 +117,13 @@ public class ContractRunner {
.
set
(
"formId"
,
8429903
)
.
set
(
"formId"
,
8429903
)
.
set
(
"page"
,
i
)
.
set
(
"page"
,
i
)
.
set
(
"pageSize"
,
100
);
.
set
(
"pageSize"
,
100
);
var
resR
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/contract/list"
)
var
jobR
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/contract/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
jsonR
.
toString
()
+
token
))
.
header
(
"sign"
,
SecureUtil
.
sha256
(
jsonR
.
toString
()
+
token
))
.
body
(
jsonR
.
toString
())
.
body
(
json
.
toString
())
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
jobR
=
JSONUtil
.
parseObj
(
resR
.
bodyStr
());
var
jsonArrR
=
jobR
.
getJSONObject
(
"result"
).
getJSONArray
(
"list"
);
var
jsonArrR
=
jobR
.
getJSONObject
(
"result"
).
getJSONArray
(
"list"
);
var
dataIdSetR
=
jsonArrR
.
stream
().
map
(
v
->
JSONUtil
.
parseObj
(
v
).
getInt
(
"dataId"
)).
collect
(
Collectors
.
toSet
());
var
dataIdSetR
=
jsonArrR
.
stream
().
map
(
v
->
JSONUtil
.
parseObj
(
v
).
getInt
(
"dataId"
)).
collect
(
Collectors
.
toSet
());
dataIdSet
.
addAll
(
dataIdSetR
);
dataIdSet
.
addAll
(
dataIdSetR
);
...
@@ -139,12 +142,13 @@ public class ContractRunner {
...
@@ -139,12 +142,13 @@ public class ContractRunner {
var
json1
=
JSONUtil
.
ofObj
()
var
json1
=
JSONUtil
.
ofObj
()
.
set
(
"corpid"
,
corpId
)
.
set
(
"corpid"
,
corpId
)
.
set
(
"dataId"
,
dataId
);
.
set
(
"dataId"
,
dataId
);
var
res1
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/contract/detail"
)
var
jobj1
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/contract/detail"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json1
.
toString
()
+
token
))
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json1
.
toString
()
+
token
))
.
body
(
json1
.
toString
())
.
body
(
json1
.
toString
())
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
jobj1
=
JSONUtil
.
parseObj
(
res1
.
bodyStr
());
if
(
jobj1
.
getInt
(
"code"
)
!=
1
)
{
if
(
jobj1
.
getInt
(
"code"
)
!=
1
)
{
log
.
error
(
"获取合同详情失败,错误原因:{}"
,
jobj1
);
log
.
error
(
"获取合同详情失败,错误原因:{}"
,
jobj1
);
return
;
return
;
...
@@ -159,6 +163,7 @@ public class ContractRunner {
...
@@ -159,6 +163,7 @@ public class ContractRunner {
contract
.
setMaintainSdate
(
Opt
.
ofNullable
(
jsonObj1
.
getLong
(
"date_4"
)).
map
(
sec
->
DateUtil
.
date
(
sec
*
1000
)).
orElse
(
null
));
contract
.
setMaintainSdate
(
Opt
.
ofNullable
(
jsonObj1
.
getLong
(
"date_4"
)).
map
(
sec
->
DateUtil
.
date
(
sec
*
1000
)).
orElse
(
null
));
contract
.
setMaintainEdate
(
Opt
.
ofNullable
(
jsonObj1
.
getLong
(
"date_5"
)).
map
(
sec
->
DateUtil
.
date
(
sec
*
1000
)).
orElse
(
null
));
contract
.
setMaintainEdate
(
Opt
.
ofNullable
(
jsonObj1
.
getLong
(
"date_5"
)).
map
(
sec
->
DateUtil
.
date
(
sec
*
1000
)).
orElse
(
null
));
String
warrantyPeriod
=
Opt
.
ofNullable
(
jsonObj1
.
getJSONObject
(
"text_23"
)).
map
(
wp
->
wp
.
getStr
(
"text"
)).
orElse
(
""
);
String
warrantyPeriod
=
Opt
.
ofNullable
(
jsonObj1
.
getJSONObject
(
"text_23"
)).
map
(
wp
->
wp
.
getStr
(
"text"
)).
orElse
(
""
);
// 23 质保 没有维保开始时间和结束时间 25 维保
if
(
StrUtil
.
isNotBlank
(
warrantyPeriod
)
&&
warrantyPeriod
.
contains
(
"个月"
))
{
if
(
StrUtil
.
isNotBlank
(
warrantyPeriod
)
&&
warrantyPeriod
.
contains
(
"个月"
))
{
String
substring
=
warrantyPeriod
.
substring
(
0
,
(
warrantyPeriod
.
length
()
-
2
));
String
substring
=
warrantyPeriod
.
substring
(
0
,
(
warrantyPeriod
.
length
()
-
2
));
contract
.
setWarrantyPeriod
(
Integer
.
parseInt
(
substring
));
contract
.
setWarrantyPeriod
(
Integer
.
parseInt
(
substring
));
...
@@ -400,13 +405,13 @@ public class ContractRunner {
...
@@ -400,13 +405,13 @@ public class ContractRunner {
.
set
(
"page"
,
1
)
.
set
(
"page"
,
1
)
.
set
(
"pageSize"
,
100
);
.
set
(
"pageSize"
,
100
);
var
res
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/product/list"
)
var
jobj
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/product/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
body
(
json
.
toString
())
.
body
(
json
.
toString
())
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
body
=
res
.
bodyStr
();
var
jobj
=
JSONUtil
.
parseObj
(
body
);
if
(
jobj
.
getInt
(
"code"
)
!=
1
)
{
if
(
jobj
.
getInt
(
"code"
)
!=
1
)
{
log
.
error
(
"获取CRM产品列表失败:{}"
,
jobj
);
log
.
error
(
"获取CRM产品列表失败:{}"
,
jobj
);
return
List
.
of
();
return
List
.
of
();
...
@@ -420,13 +425,13 @@ public class ContractRunner {
...
@@ -420,13 +425,13 @@ public class ContractRunner {
.
set
(
"corpid"
,
corpId
)
.
set
(
"corpid"
,
corpId
)
.
set
(
"page"
,
i
)
.
set
(
"page"
,
i
)
.
set
(
"pageSize"
,
100
);
.
set
(
"pageSize"
,
100
);
var
res1
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/product/list"
)
var
jobj1
=
bongRestClient
.
post
(
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json1
+
token
)
)
.
uri
(
"/pro/v2/api/product/list"
)
.
body
(
json1
.
toString
()
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
method
(
Method
.
POST
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json1
.
toString
()
+
token
)
)
.
send
();
.
body
(
json
.
toString
())
var
body1
=
res1
.
bodyStr
();
.
retrieve
()
var
jobj1
=
JSONUtil
.
parseObj
(
body1
);
.
body
(
JSONObject
.
class
);
if
(
jobj1
.
getInt
(
"code"
)
!=
1
)
{
if
(
jobj1
.
getInt
(
"code"
)
!=
1
)
{
log
.
error
(
"获取CRM产品列表失败:{}"
,
jobj1
);
log
.
error
(
"获取CRM产品列表失败:{}"
,
jobj1
);
return
List
.
of
();
return
List
.
of
();
...
...
src/main/java/vion/service/impl/ContractServiceImpl.java
View file @
ef75b2f
...
@@ -29,14 +29,14 @@ import org.dromara.hutool.core.text.StrUtil;
...
@@ -29,14 +29,14 @@ import org.dromara.hutool.core.text.StrUtil;
import
org.dromara.hutool.core.util.ObjUtil
;
import
org.dromara.hutool.core.util.ObjUtil
;
import
org.dromara.hutool.crypto.SecureUtil
;
import
org.dromara.hutool.crypto.SecureUtil
;
import
org.dromara.hutool.http.client.HttpDownloader
;
import
org.dromara.hutool.http.client.HttpDownloader
;
import
org.dromara.hutool.http.client.Request
;
import
org.dromara.hutool.http.meta.Method
;
import
org.dromara.hutool.json.JSONObject
;
import
org.dromara.hutool.json.JSONObject
;
import
org.dromara.hutool.json.JSONUtil
;
import
org.dromara.hutool.json.JSONUtil
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.MediaType
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.client.RestClient
;
import
vion.dto.ContractDTO
;
import
vion.dto.ContractDTO
;
import
vion.dto.RContractTeamDTO
;
import
vion.dto.RContractTeamDTO
;
import
vion.mapper.ContractMapper
;
import
vion.mapper.ContractMapper
;
...
@@ -75,6 +75,7 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -75,6 +75,7 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
private
final
SettlementDiffMapper
settlementDiffMapper
;
private
final
SettlementDiffMapper
settlementDiffMapper
;
private
final
DingMod
dingMod
;
private
final
DingMod
dingMod
;
private
final
Converter
converter
;
private
final
Converter
converter
;
private
final
RestClient
bongRestClient
;
@Value
(
"${fileUrl:}"
)
@Value
(
"${fileUrl:}"
)
private
String
fileUrl
;
private
String
fileUrl
;
...
@@ -527,15 +528,15 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -527,15 +528,15 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
@Override
@Override
public
String
createContract
(
String
contractJson
)
{
public
String
createContract
(
String
contractJson
)
{
var
sha256
=
SecureUtil
.
sha256
(
contractJson
+
token
);
var
sha256
=
SecureUtil
.
sha256
(
contractJson
+
token
);
var
res
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/contract/list"
)
var
jobj
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/contract/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
sha256
)
.
header
(
"sign"
,
sha256
)
.
body
(
contractJson
)
.
body
(
contractJson
)
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
body
=
res
.
bodyStr
();
var
jobj
=
JSONUtil
.
parseObj
(
body
);
if
(
jobj
.
getInt
(
"code"
)
!=
1
)
{
if
(
jobj
.
getInt
(
"code"
)
!=
1
)
{
log
.
error
(
"调用CRM接口创建合同失败,错误原因:{}"
,
body
);
log
.
error
(
"调用CRM接口创建合同失败,错误原因:{}"
,
jobj
);
return
"创建合同失败"
;
return
"创建合同失败"
;
}
}
return
"合同创建成功"
;
return
"合同创建成功"
;
...
@@ -559,15 +560,15 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -559,15 +560,15 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.
set
(
"pageSize"
,
pageSize
)
.
set
(
"pageSize"
,
pageSize
)
.
set
(
"conditions"
,
conditions
);
.
set
(
"conditions"
,
conditions
);
var
res
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/product/list"
)
var
jobj
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/product/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
body
(
json
.
toString
())
.
body
(
json
.
toString
())
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
body
=
res
.
bodyStr
();
var
jobj
=
JSONUtil
.
parseObj
(
body
);
if
(
jobj
.
getInt
(
"code"
)
!=
1
)
{
if
(
jobj
.
getInt
(
"code"
)
!=
1
)
{
log
.
error
(
"调用CRM接口获取产品列表失败,错误原因:{}"
,
body
);
log
.
error
(
"调用CRM接口获取产品列表失败,错误原因:{}"
,
jobj
);
return
JSONUtil
.
ofObj
();
return
JSONUtil
.
ofObj
();
}
}
return
JSONUtil
.
ofObj
().
set
(
"records"
,
jobj
.
getJSONObject
(
"result"
).
getJSONArray
(
"list"
))
return
JSONUtil
.
ofObj
().
set
(
"records"
,
jobj
.
getJSONObject
(
"result"
).
getJSONArray
(
"list"
))
...
@@ -597,12 +598,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -597,12 +598,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.
set
(
"corpid"
,
corpId
)
.
set
(
"corpid"
,
corpId
)
.
set
(
"formId"
,
8429903
)
.
set
(
"formId"
,
8429903
)
.
set
(
"pageSize"
,
100
);
.
set
(
"pageSize"
,
100
);
var
res
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/contract/list"
)
var
jobO
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/contract/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
body
(
json
.
toString
())
.
body
(
json
.
toString
())
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
jobO
=
JSONUtil
.
parseObj
(
res
.
bodyStr
());
if
(
jobO
.
getInt
(
"code"
)
!=
1
)
{
if
(
jobO
.
getInt
(
"code"
)
!=
1
)
{
var
errorInfo
=
StrUtil
.
format
(
"获取合同列表失败,错误原因:{}"
,
jobO
);
var
errorInfo
=
StrUtil
.
format
(
"获取合同列表失败,错误原因:{}"
,
jobO
);
log
.
error
(
errorInfo
);
log
.
error
(
errorInfo
);
...
@@ -627,12 +629,14 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -627,12 +629,14 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.
set
(
"formId"
,
8429903
)
.
set
(
"formId"
,
8429903
)
.
set
(
"page"
,
i
)
.
set
(
"page"
,
i
)
.
set
(
"pageSize"
,
100
);
.
set
(
"pageSize"
,
100
);
var
resR
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/contract/list"
)
var
jobR
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/contract/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
jsonR
.
toString
()
+
token
))
.
header
(
"sign"
,
SecureUtil
.
sha256
(
jsonR
.
toString
()
+
token
))
.
body
(
jsonR
.
toString
())
.
body
(
jsonR
.
toString
())
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
jobR
=
JSONUtil
.
parseObj
(
resR
.
bodyStr
());
var
jsonArrR
=
jobR
.
getJSONObject
(
"result"
).
getJSONArray
(
"list"
);
var
jsonArrR
=
jobR
.
getJSONObject
(
"result"
).
getJSONArray
(
"list"
);
var
fileListR
=
jsonArrR
.
stream
().
map
(
v
->
{
var
fileListR
=
jsonArrR
.
stream
().
map
(
v
->
{
var
fileArr
=
JSONUtil
.
parseObj
(
v
).
getJSONObject
(
"data"
).
getJSONArray
(
"file_1"
);
var
fileArr
=
JSONUtil
.
parseObj
(
v
).
getJSONObject
(
"data"
).
getJSONArray
(
"file_1"
);
...
@@ -649,7 +653,6 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -649,7 +653,6 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
var
contractId2Sha256Map
=
fileInfoList
.
stream
().
collect
(
Collectors
.
groupingBy
(
FileInfo:
:
getContractId
,
var
contractId2Sha256Map
=
fileInfoList
.
stream
().
collect
(
Collectors
.
groupingBy
(
FileInfo:
:
getContractId
,
Collectors
.
mapping
(
FileInfo:
:
getSha256
,
Collectors
.
toList
())));
Collectors
.
mapping
(
FileInfo:
:
getSha256
,
Collectors
.
toList
())));
List
<
FileInfo
>
saveFileInfoList
=
new
ArrayList
<>();
for
(
JSONObject
entries
:
fileList
)
{
for
(
JSONObject
entries
:
fileList
)
{
var
contractNo
=
entries
.
getStr
(
"contractNo"
);
var
contractNo
=
entries
.
getStr
(
"contractNo"
);
var
fileArr
=
entries
.
getJSONArray
(
"fileArr"
);
var
fileArr
=
entries
.
getJSONArray
(
"fileArr"
);
...
@@ -663,6 +666,7 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -663,6 +666,7 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
continue
;
continue
;
}
}
List
<
FileInfo
>
saveFileInfoList
=
new
ArrayList
<>();
for
(
Object
o
:
fileArr
)
{
for
(
Object
o
:
fileArr
)
{
var
fileObj
=
JSONUtil
.
parseObj
(
o
);
var
fileObj
=
JSONUtil
.
parseObj
(
o
);
var
filename
=
fileObj
.
getStr
(
"filename"
);
var
filename
=
fileObj
.
getStr
(
"filename"
);
...
@@ -688,8 +692,8 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -688,8 +692,8 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
fileInfo
.
setUploader
(
"销帮帮同步"
);
fileInfo
.
setUploader
(
"销帮帮同步"
);
saveFileInfoList
.
add
(
fileInfo
);
saveFileInfoList
.
add
(
fileInfo
);
}
}
fileService
.
saveBatch
(
saveFileInfoList
);
}
}
fileService
.
saveBatch
(
saveFileInfoList
);
log
.
info
(
"同步销帮帮合同文件[完成]"
);
log
.
info
(
"同步销帮帮合同文件[完成]"
);
return
"销帮帮合同文件同步完成,请核对已同步文件!"
;
return
"销帮帮合同文件同步完成,请核对已同步文件!"
;
}
}
...
@@ -869,12 +873,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -869,12 +873,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.
set
(
"corpid"
,
corpId
)
.
set
(
"corpid"
,
corpId
)
.
set
(
"formId"
,
8429903
)
.
set
(
"formId"
,
8429903
)
.
set
(
"pageSize"
,
100
);
.
set
(
"pageSize"
,
100
);
var
res
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/contract/list"
)
var
jobO
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/contract/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
body
(
json
.
toString
())
.
body
(
json
.
toString
())
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
jobO
=
JSONUtil
.
parseObj
(
res
.
bodyStr
());
if
(
jobO
.
getInt
(
"code"
)
!=
1
)
{
if
(
jobO
.
getInt
(
"code"
)
!=
1
)
{
log
.
error
(
"获取合同列表失败,错误原因:{}"
,
jobO
);
log
.
error
(
"获取合同列表失败,错误原因:{}"
,
jobO
);
}
}
...
@@ -897,12 +902,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -897,12 +902,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.
set
(
"formId"
,
8429903
)
.
set
(
"formId"
,
8429903
)
.
set
(
"page"
,
i
)
.
set
(
"page"
,
i
)
.
set
(
"pageSize"
,
100
);
.
set
(
"pageSize"
,
100
);
var
resR
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/contract/list"
)
var
jobR
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/contract/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
jsonR
.
toString
()
+
token
))
.
header
(
"sign"
,
SecureUtil
.
sha256
(
jsonR
.
toString
()
+
token
))
.
body
(
jsonR
.
toString
())
.
body
(
jsonR
.
toString
())
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
jobR
=
JSONUtil
.
parseObj
(
resR
.
bodyStr
());
var
jsonArrR
=
jobR
.
getJSONObject
(
"result"
).
getJSONArray
(
"list"
);
var
jsonArrR
=
jobR
.
getJSONObject
(
"result"
).
getJSONArray
(
"list"
);
var
dataIdSetR
=
jsonArrR
.
stream
().
map
(
v
->
JSONUtil
.
parseObj
(
v
).
getJSONObject
(
"data"
).
getStr
(
"serialNo"
)).
collect
(
Collectors
.
toSet
());
var
dataIdSetR
=
jsonArrR
.
stream
().
map
(
v
->
JSONUtil
.
parseObj
(
v
).
getJSONObject
(
"data"
).
getStr
(
"serialNo"
)).
collect
(
Collectors
.
toSet
());
dataIdSet
.
addAll
(
dataIdSetR
);
dataIdSet
.
addAll
(
dataIdSetR
);
...
@@ -988,12 +994,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -988,12 +994,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.
set
(
"corpid"
,
corpId
)
.
set
(
"corpid"
,
corpId
)
.
set
(
"formId"
,
8429903
)
.
set
(
"formId"
,
8429903
)
.
set
(
"pageSize"
,
100
);
.
set
(
"pageSize"
,
100
);
var
res
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/contract/list"
)
var
jobO
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/contract/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json
.
toString
()
+
token
))
.
body
(
json
.
toString
())
.
body
(
json
.
toString
())
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
jobO
=
JSONUtil
.
parseObj
(
res
.
bodyStr
());
if
(
jobO
.
getInt
(
"code"
)
!=
1
)
{
if
(
jobO
.
getInt
(
"code"
)
!=
1
)
{
log
.
error
(
"获取合同列表失败,错误原因:{}"
,
jobO
);
log
.
error
(
"获取合同列表失败,错误原因:{}"
,
jobO
);
}
}
...
@@ -1004,12 +1011,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -1004,12 +1011,13 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
var
json1
=
JSONUtil
.
ofObj
()
var
json1
=
JSONUtil
.
ofObj
()
.
set
(
"corpid"
,
corpId
)
.
set
(
"corpid"
,
corpId
)
.
set
(
"dataId"
,
CollUtil
.
getFirst
(
dataIdSet
));
.
set
(
"dataId"
,
CollUtil
.
getFirst
(
dataIdSet
));
var
res1
=
Request
.
of
(
"https://proapi.xbongbong.com/pro/v2/api/contract/detail"
)
var
jobj1
=
bongRestClient
.
post
()
.
uri
(
"/pro/v2/api/contract/detail"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json1
.
toString
()
+
token
))
.
header
(
"sign"
,
SecureUtil
.
sha256
(
json1
.
toString
()
+
token
))
.
body
(
json1
.
toString
())
.
body
(
json1
.
toString
())
.
method
(
Method
.
POST
)
.
retrieve
()
.
send
();
.
body
(
JSONObject
.
class
);
var
jobj1
=
JSONUtil
.
parseObj
(
res1
.
bodyStr
());
if
(
jobj1
.
getInt
(
"code"
)
!=
1
)
{
if
(
jobj1
.
getInt
(
"code"
)
!=
1
)
{
log
.
error
(
"获取合同详情失败,错误原因:{}"
,
jobj1
);
log
.
error
(
"获取合同详情失败,错误原因:{}"
,
jobj1
);
}
}
...
@@ -1089,7 +1097,6 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
...
@@ -1089,7 +1097,6 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
var
bongMap
=
BeanUtil
.
beanToMap
(
xbongContract
,
new
HashMap
<>(),
copyOptions
);
var
bongMap
=
BeanUtil
.
beanToMap
(
xbongContract
,
new
HashMap
<>(),
copyOptions
);
if
(!
mapEqual
(
platMap
,
bongMap
))
{
if
(!
mapEqual
(
platMap
,
bongMap
))
{
log
.
info
(
"不一致的合同:{}"
,
contractNo
);
log
.
info
(
"不一致的合同:{}"
,
contractNo
);
// SC 合同全部对比, CS 合同只对比金额
}
}
}
}
}
}
...
...
src/main/java/vion/service/impl/StoreServiceImpl.java
View file @
ef75b2f
...
@@ -367,8 +367,8 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
...
@@ -367,8 +367,8 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
public
String
mergeStore
(
StoreDTO
dto
)
{
public
String
mergeStore
(
StoreDTO
dto
)
{
// targetId 合并到 sourceId
// targetId 合并到 sourceId
Long
sourceId
=
dto
.
getSourceId
();
Long
sourceId
=
dto
.
getSourceId
();
Store
store
=
this
.
getById
(
sourceId
);
Long
targetId
=
dto
.
getTargetId
();
Long
targetId
=
dto
.
getTargetId
();
var
targetStore
=
this
.
getById
(
targetId
);
// 项目关联合同合并
// 项目关联合同合并
Opt
.
ofEmptyAble
(
contractStoreService
.
lambdaQuery
().
select
(
RContractStore:
:
getContractId
).
eq
(
RContractStore:
:
getStoreId
,
targetId
).
list
())
Opt
.
ofEmptyAble
(
contractStoreService
.
lambdaQuery
().
select
(
RContractStore:
:
getContractId
).
eq
(
RContractStore:
:
getStoreId
,
targetId
).
list
())
.
ifPresent
(
l
->
{
.
ifPresent
(
l
->
{
...
@@ -385,13 +385,13 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
...
@@ -385,13 +385,13 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
});
});
// 工单相关合并
// 工单相关合并
taskMapper
.
update
(
new
Task
(),
Wrappers
.
lambdaUpdate
(
Task
.
class
).
set
(
Task:
:
getStoreId
,
sourceId
).
set
(
Task:
:
getAccountId
,
s
tore
.
getAccountId
()).
eq
(
Task:
:
getStoreId
,
targetId
));
taskMapper
.
update
(
new
Task
(),
Wrappers
.
lambdaUpdate
(
Task
.
class
).
set
(
Task:
:
getStoreId
,
sourceId
).
set
(
Task:
:
getAccountId
,
targetS
tore
.
getAccountId
()).
eq
(
Task:
:
getStoreId
,
targetId
));
taskTempService
.
lambdaUpdate
().
set
(
TaskTemp:
:
getStoreId
,
sourceId
).
eq
(
TaskTemp:
:
getStoreId
,
targetId
).
update
();
taskTempService
.
lambdaUpdate
().
set
(
TaskTemp:
:
getStoreId
,
sourceId
).
eq
(
TaskTemp:
:
getStoreId
,
targetId
).
update
();
// 所有 targetId 的文件 转移到 sourceId
// 所有 targetId 的文件 转移到 sourceId
fileService
.
lambdaUpdate
().
set
(
FileInfo:
:
getStoreId
,
sourceId
).
eq
(
FileInfo:
:
getStoreId
,
targetId
).
update
();
fileService
.
lambdaUpdate
().
set
(
FileInfo:
:
getStoreId
,
sourceId
).
eq
(
FileInfo:
:
getStoreId
,
targetId
).
update
();
faultLogService
.
lambdaUpdate
().
set
(
FaultLog:
:
getStoreId
,
sourceId
).
eq
(
FaultLog:
:
getStoreId
,
targetId
).
update
();
faultLogService
.
lambdaUpdate
().
set
(
FaultLog:
:
getStoreId
,
sourceId
).
eq
(
FaultLog:
:
getStoreId
,
targetId
).
update
();
formService
.
lambdaUpdate
().
set
(
Form:
:
getStoreId
,
sourceId
).
set
(
Form:
:
getAccountId
,
s
tore
.
getAccountId
()).
eq
(
Form:
:
getStoreId
,
targetId
).
update
(
new
Form
());
formService
.
lambdaUpdate
().
set
(
Form:
:
getStoreId
,
sourceId
).
set
(
Form:
:
getAccountId
,
targetS
tore
.
getAccountId
()).
eq
(
Form:
:
getStoreId
,
targetId
).
update
(
new
Form
());
inspectService
.
lambdaUpdate
().
set
(
Inspect:
:
getStoreId
,
sourceId
).
set
(
Inspect:
:
getAccountId
,
s
tore
.
getAccountId
()).
eq
(
Inspect:
:
getStoreId
,
targetId
).
update
(
new
Inspect
());
inspectService
.
lambdaUpdate
().
set
(
Inspect:
:
getStoreId
,
sourceId
).
set
(
Inspect:
:
getAccountId
,
targetS
tore
.
getAccountId
()).
eq
(
Inspect:
:
getStoreId
,
targetId
).
update
(
new
Inspect
());
// 删除 targetId 对应的项目
// 删除 targetId 对应的项目
this
.
removeById
(
targetId
);
this
.
removeById
(
targetId
);
return
"合并成功"
;
return
"合并成功"
;
...
...
src/main/java/vion/third/DingMod.java
View file @
ef75b2f
...
@@ -14,15 +14,14 @@ import org.dromara.hutool.core.text.StrUtil;
...
@@ -14,15 +14,14 @@ import org.dromara.hutool.core.text.StrUtil;
import
org.dromara.hutool.core.util.ObjUtil
;
import
org.dromara.hutool.core.util.ObjUtil
;
import
org.dromara.hutool.crypto.SecureUtil
;
import
org.dromara.hutool.crypto.SecureUtil
;
import
org.dromara.hutool.crypto.digest.mac.HMac
;
import
org.dromara.hutool.crypto.digest.mac.HMac
;
import
org.dromara.hutool.http.HttpUtil
;
import
org.dromara.hutool.http.client.Request
;
import
org.dromara.hutool.http.client.Response
;
import
org.dromara.hutool.json.JSONArray
;
import
org.dromara.hutool.json.JSONArray
;
import
org.dromara.hutool.json.JSONObject
;
import
org.dromara.hutool.json.JSONObject
;
import
org.dromara.hutool.json.JSONUtil
;
import
org.dromara.hutool.json.JSONUtil
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestClient
;
import
vion.constant.RedisKeyEnum
;
import
vion.constant.RedisKeyEnum
;
import
vion.dto.DingDTO
;
import
vion.dto.DingDTO
;
import
vion.model.*
;
import
vion.model.*
;
...
@@ -60,6 +59,8 @@ public class DingMod {
...
@@ -60,6 +59,8 @@ public class DingMod {
private
final
IDeptService
deptService
;
private
final
IDeptService
deptService
;
private
final
Converter
converter
;
private
final
Converter
converter
;
private
final
RedissonClient
redissonClient
;
private
final
RedissonClient
redissonClient
;
private
final
RestClient
oDingRestClient
;
private
final
RestClient
dingRestClient
;
/**
/**
* 获取钉钉token
* 获取钉钉token
...
@@ -69,7 +70,10 @@ public class DingMod {
...
@@ -69,7 +70,10 @@ public class DingMod {
public
String
getToken
()
{
public
String
getToken
()
{
return
(
String
)
Opt
.
ofNullable
(
redissonClient
.
getBucket
(
RedisKeyEnum
.
DING_PREFIX
.
getVal
()
+
RedisKeyEnum
.
ACCESS_TOKEN
.
getVal
()).
get
())
return
(
String
)
Opt
.
ofNullable
(
redissonClient
.
getBucket
(
RedisKeyEnum
.
DING_PREFIX
.
getVal
()
+
RedisKeyEnum
.
ACCESS_TOKEN
.
getVal
()).
get
())
.
orElseGet
(()
->
{
.
orElseGet
(()
->
{
String
res
=
HttpUtil
.
get
(
"https://oapi.dingtalk.com/gettoken?appkey="
+
appKey
+
"&appsecret="
+
appSecret
);
String
res
=
oDingRestClient
.
get
()
.
uri
(
"/gettoken?appkey="
+
appKey
+
"&appsecret="
+
appSecret
)
.
retrieve
()
.
body
(
String
.
class
);
JSONObject
jsonObj
=
JSONUtil
.
parseObj
(
res
);
JSONObject
jsonObj
=
JSONUtil
.
parseObj
(
res
);
if
(
jsonObj
.
containsKey
(
"access_token"
))
{
if
(
jsonObj
.
containsKey
(
"access_token"
))
{
String
accessToken
=
jsonObj
.
getStr
(
"access_token"
);
String
accessToken
=
jsonObj
.
getStr
(
"access_token"
);
...
@@ -95,8 +99,12 @@ public class DingMod {
...
@@ -95,8 +99,12 @@ public class DingMod {
.
set
(
"status_list"
,
"2,3,5,-1"
)
.
set
(
"status_list"
,
"2,3,5,-1"
)
.
set
(
"size"
,
50
)
.
set
(
"size"
,
50
)
.
set
(
"offset"
,
offset
);
.
set
(
"offset"
,
offset
);
String
res
=
HttpUtil
.
post
(
"https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/queryonjob?access_token="
+
accessToken
,
paramJson
.
toString
());
var
jsonObject
=
oDingRestClient
.
post
()
JSONObject
jsonObject
=
JSONUtil
.
parseObj
(
res
);
.
uri
(
"/topapi/smartwork/hrm/employee/queryonjob?access_token="
+
accessToken
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
body
(
paramJson
.
toString
())
.
retrieve
()
.
body
(
JSONObject
.
class
);
if
(
jsonObject
.
getBool
(
"success"
,
false
))
{
if
(
jsonObject
.
getBool
(
"success"
,
false
))
{
JSONArray
jsonArray
=
jsonObject
.
getJSONObject
(
"result"
).
getJSONArray
(
"data_list"
);
JSONArray
jsonArray
=
jsonObject
.
getJSONObject
(
"result"
).
getJSONArray
(
"data_list"
);
List
<
String
>
list
=
jsonArray
.
toList
(
String
.
class
);
List
<
String
>
list
=
jsonArray
.
toList
(
String
.
class
);
...
@@ -123,8 +131,12 @@ public class DingMod {
...
@@ -123,8 +131,12 @@ public class DingMod {
.
set
(
"userid_list"
,
String
.
join
(
","
,
tmpList
))
.
set
(
"userid_list"
,
String
.
join
(
","
,
tmpList
))
.
set
(
"field_filter_list"
,
"sys00-name,sys00-mobile,sys00-mainDeptId,sys00-mainDept,sys01-employeeStatus"
);
.
set
(
"field_filter_list"
,
"sys00-name,sys00-mobile,sys00-mainDeptId,sys00-mainDept,sys01-employeeStatus"
);
String
res
=
HttpUtil
.
post
(
"https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/v2/list?access_token="
+
accessToken
,
paramJson
.
toString
());
var
jsonObject
=
oDingRestClient
.
post
()
JSONObject
jsonObject
=
JSONUtil
.
parseObj
(
res
);
.
uri
(
"/topapi/smartwork/hrm/employee/v2/list?access_token="
+
accessToken
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
body
(
paramJson
.
toString
())
.
retrieve
()
.
body
(
JSONObject
.
class
);
if
(
jsonObject
.
getBool
(
"success"
,
false
))
{
if
(
jsonObject
.
getBool
(
"success"
,
false
))
{
JSONArray
resArr
=
jsonObject
.
getJSONArray
(
"result"
);
JSONArray
resArr
=
jsonObject
.
getJSONArray
(
"result"
);
for
(
Object
o
:
resArr
)
{
for
(
Object
o
:
resArr
)
{
...
@@ -172,8 +184,12 @@ public class DingMod {
...
@@ -172,8 +184,12 @@ public class DingMod {
while
(
idx
<
deptIdList
.
size
())
{
while
(
idx
<
deptIdList
.
size
())
{
// 2:试用期 3:正式 5:待离职 -1:无状态
// 2:试用期 3:正式 5:待离职 -1:无状态
Long
value
=
deptIdList
.
get
(
idx
++);
Long
value
=
deptIdList
.
get
(
idx
++);
String
res
=
HttpUtil
.
post
(
"https://oapi.dingtalk.com/topapi/v2/department/listsub?access_token="
+
accessToken
,
JSONUtil
.
ofObj
().
set
(
"dept_id"
,
value
).
toString
());
var
jsonObject
=
oDingRestClient
.
post
()
JSONObject
jsonObject
=
JSONUtil
.
parseObj
(
res
);
.
uri
(
"/topapi/v2/department/listsub?access_token="
+
accessToken
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
body
(
JSONUtil
.
ofObj
().
set
(
"dept_id"
,
value
).
toString
())
.
retrieve
()
.
body
(
JSONObject
.
class
);
if
(
StrUtil
.
equals
(
"ok"
,
jsonObject
.
getStr
(
"errmsg"
)))
{
if
(
StrUtil
.
equals
(
"ok"
,
jsonObject
.
getStr
(
"errmsg"
)))
{
JSONArray
resArr
=
jsonObject
.
getJSONArray
(
"result"
);
JSONArray
resArr
=
jsonObject
.
getJSONArray
(
"result"
);
if
(
CollUtil
.
isNotEmpty
(
resArr
))
{
if
(
CollUtil
.
isNotEmpty
(
resArr
))
{
...
@@ -203,7 +219,12 @@ public class DingMod {
...
@@ -203,7 +219,12 @@ public class DingMod {
*/
*/
public
String
workMsg
(
JSONObject
msg
)
{
public
String
workMsg
(
JSONObject
msg
)
{
String
token
=
getToken
();
String
token
=
getToken
();
String
res
=
HttpUtil
.
post
(
"https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token="
+
token
,
msg
.
toString
());
var
res
=
oDingRestClient
.
post
()
.
uri
(
"/topapi/message/corpconversation/asyncsend_v2?access_token="
+
token
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
body
(
msg
.
toString
())
.
retrieve
()
.
body
(
String
.
class
);
log
.
info
(
"钉钉工作通知消息推送:{}"
,
res
);
log
.
info
(
"钉钉工作通知消息推送:{}"
,
res
);
return
res
;
return
res
;
}
}
...
@@ -223,24 +244,31 @@ public class DingMod {
...
@@ -223,24 +244,31 @@ public class DingMod {
.
set
(
"clientSecret"
,
appSecret
)
.
set
(
"clientSecret"
,
appSecret
)
.
set
(
"code"
,
dto
.
getAuthCode
())
.
set
(
"code"
,
dto
.
getAuthCode
())
.
set
(
"grantType"
,
"authorization_code"
);
.
set
(
"grantType"
,
"authorization_code"
);
String
tokenRes
=
HttpUtil
.
post
(
"https://api.dingtalk.com/v1.0/oauth2/userAccessToken"
,
jsonObject
.
toString
());
var
tokenObj
=
dingRestClient
.
post
()
JSONObject
tokenObj
=
JSONUtil
.
parseObj
(
tokenRes
);
.
uri
(
"/v1.0/oauth2/userAccessToken"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
body
(
jsonObject
.
toString
())
.
retrieve
()
.
body
(
JSONObject
.
class
);
if
(!
tokenObj
.
containsKey
(
"accessToken"
))
{
if
(!
tokenObj
.
containsKey
(
"accessToken"
))
{
log
.
error
(
"钉钉回调接口获取accessToken失败:{}"
,
tokenObj
);
log
.
error
(
"钉钉回调接口获取accessToken失败:{}"
,
tokenObj
);
return
tokenObj
;
return
tokenObj
;
}
}
String
accessToken
=
tokenObj
.
getStr
(
"accessToken"
);
String
accessToken
=
tokenObj
.
getStr
(
"accessToken"
);
Response
response
=
Request
.
of
(
"https://api.dingtalk.com/v1.0/contact/users/me"
)
var
userInfoObj
=
dingRestClient
.
get
()
.
uri
(
"/v1.0/contact/users/me"
)
.
header
(
"x-acs-dingtalk-access-token"
,
accessToken
)
.
header
(
"x-acs-dingtalk-access-token"
,
accessToken
)
.
send
();
.
retrieve
()
if
(!
response
.
isOk
())
{
.
onStatus
(
httpStatusCode
->
!
httpStatusCode
.
is2xxSuccessful
(),
(
request
,
response
)
->
{
log
.
error
(
"钉钉回调接口获取unionid失败:{}"
,
response
.
bodyStr
());
throw
new
RuntimeException
(
"钉钉回调接口获取unionid失败:"
+
response
.
getBody
());
return
response
.
bodyStr
();
})
}
.
body
(
JSONObject
.
class
);
JSONObject
userInfoObj
=
JSONUtil
.
parseObj
(
response
.
bodyStr
());
String
unionId
=
userInfoObj
.
getStr
(
"unionId"
);
String
unionId
=
userInfoObj
.
getStr
(
"unionId"
);
String
response1
=
HttpUtil
.
post
(
"https://oapi.dingtalk.com/topapi/user/getbyunionid?access_token="
+
getToken
(),
"{\"unionid\":\""
+
unionId
+
"\"}"
);
var
useridObj
=
oDingRestClient
.
post
()
JSONObject
useridObj
=
JSONUtil
.
parseObj
(
response1
);
.
uri
(
"/topapi/user/getbyunionid?access_token="
+
getToken
())
.
body
(
JSONUtil
.
ofObj
().
set
(
"unionid"
,
unionId
).
toString
())
.
retrieve
()
.
body
(
JSONObject
.
class
);
if
(!
useridObj
.
containsKey
(
"result"
))
{
if
(!
useridObj
.
containsKey
(
"result"
))
{
log
.
error
(
"钉钉回调接口获取userid失败:{}"
,
useridObj
);
log
.
error
(
"钉钉回调接口获取userid失败:{}"
,
useridObj
);
return
useridObj
;
return
useridObj
;
...
@@ -267,16 +295,24 @@ public class DingMod {
...
@@ -267,16 +295,24 @@ public class DingMod {
StpUtil
.
getTokenSession
().
set
(
"curLoginUser"
,
userVO
);
StpUtil
.
getTokenSession
().
set
(
"curLoginUser"
,
userVO
);
return
userVO
;
return
userVO
;
}
else
if
(
StrUtil
.
equals
(
target
,
"inside"
))
{
}
else
if
(
StrUtil
.
equals
(
target
,
"inside"
))
{
String
response
=
HttpUtil
.
post
(
buildSignUrl
(),
"{\"tmp_auth_code\":\""
+
dto
.
getCode
()
+
"\"}"
);
var
userInfoObj
=
oDingRestClient
.
post
()
JSONObject
userInfoObj
=
JSONUtil
.
parseObj
(
response
);
.
uri
(
buildSignUrl
())
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
body
(
JSONUtil
.
ofObj
().
set
(
"tmp_auth_code"
,
dto
.
getCode
()).
toString
())
.
retrieve
()
.
body
(
JSONObject
.
class
);
if
(!
userInfoObj
.
containsKey
(
"user_info"
))
{
if
(!
userInfoObj
.
containsKey
(
"user_info"
))
{
log
.
error
(
"钉钉回调接口获取unionid失败:{}"
,
userInfoObj
);
log
.
error
(
"钉钉回调接口获取unionid失败:{}"
,
userInfoObj
);
return
userInfoObj
;
return
userInfoObj
;
}
}
String
unionId
=
userInfoObj
.
getJSONObject
(
"user_info"
).
getStr
(
"unionid"
);
String
unionId
=
userInfoObj
.
getJSONObject
(
"user_info"
).
getStr
(
"unionid"
);
String
response1
=
HttpUtil
.
post
(
"https://oapi.dingtalk.com/topapi/user/getbyunionid?access_token="
+
getToken
(),
"{\"unionid\":\""
+
unionId
+
"\"}"
);
JSONObject
useridObj
=
oDingRestClient
.
post
()
JSONObject
useridObj
=
JSONUtil
.
parseObj
(
response1
);
.
uri
(
"/topapi/user/getbyunionid?access_token="
+
getToken
())
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
body
(
JSONUtil
.
ofObj
().
set
(
"unionid"
,
unionId
).
toString
())
.
retrieve
()
.
body
(
JSONObject
.
class
);
if
(!
useridObj
.
containsKey
(
"result"
))
{
if
(!
useridObj
.
containsKey
(
"result"
))
{
log
.
error
(
"钉钉回调接口获取userid失败:{}"
,
useridObj
);
log
.
error
(
"钉钉回调接口获取userid失败:{}"
,
useridObj
);
return
useridObj
;
return
useridObj
;
...
@@ -325,16 +361,22 @@ public class DingMod {
...
@@ -325,16 +361,22 @@ public class DingMod {
* @return java.lang.Object
* @return java.lang.Object
*/
*/
public
Object
getPlatformToken
(
String
authCode
)
{
public
Object
getPlatformToken
(
String
authCode
)
{
var
accessTokenStr
=
HttpUtil
.
get
(
StrUtil
.
format
(
"https://oapi.dingtalk.com/gettoken?appkey={}&appsecret={}"
,
var
accessTokenStr
=
oDingRestClient
.
get
()
appKey
,
appSecret
));
.
uri
(
StrUtil
.
format
(
"/gettoken?appkey={}&appsecret={}"
,
appKey
,
appSecret
))
.
retrieve
()
.
body
(
String
.
class
);
if
(!
StrUtil
.
contains
(
accessTokenStr
,
"access_token"
))
{
if
(!
StrUtil
.
contains
(
accessTokenStr
,
"access_token"
))
{
log
.
error
(
"获取钉钉access_token失败:{}"
,
accessTokenStr
);
log
.
error
(
"获取钉钉access_token失败:{}"
,
accessTokenStr
);
return
"获取钉钉access_token失败"
;
return
"获取钉钉access_token失败"
;
}
}
var
accessToken
=
JSONUtil
.
parseObj
(
accessTokenStr
).
getStr
(
"access_token"
);
var
accessToken
=
JSONUtil
.
parseObj
(
accessTokenStr
).
getStr
(
"access_token"
);
var
userInfoStr
=
HttpUtil
.
post
(
"https://oapi.dingtalk.com/topapi/v2/user/getuserinfo?access_token="
+
accessToken
,
var
userInfoStr
=
oDingRestClient
.
post
()
JSONUtil
.
ofObj
().
set
(
"code"
,
authCode
));
.
uri
(
"/topapi/v2/user/getuserinfo?access_token="
+
accessToken
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
body
(
JSONUtil
.
ofObj
().
set
(
"code"
,
authCode
).
toString
())
.
retrieve
()
.
body
(
String
.
class
);
if
(!
StrUtil
.
contains
(
userInfoStr
,
"\"errmsg\":\"ok\""
))
{
if
(!
StrUtil
.
contains
(
userInfoStr
,
"\"errmsg\":\"ok\""
))
{
log
.
error
(
"获取钉钉用户信息失败:{}"
,
userInfoStr
);
log
.
error
(
"获取钉钉用户信息失败:{}"
,
userInfoStr
);
return
"获取钉钉用户信息失败"
;
return
"获取钉钉用户信息失败"
;
...
@@ -397,11 +439,16 @@ public class DingMod {
...
@@ -397,11 +439,16 @@ public class DingMod {
String
sign
=
Base64
.
encode
(
signBytes
);
String
sign
=
Base64
.
encode
(
signBytes
);
String
encode
=
URLEncoder
.
encode
(
sign
,
StandardCharsets
.
UTF_8
);
String
encode
=
URLEncoder
.
encode
(
sign
,
StandardCharsets
.
UTF_8
);
String
encodeSign
=
encode
.
replace
(
"+"
,
"%20"
).
replace
(
"*"
,
"%2A"
).
replace
(
"~"
,
"%7E"
).
replace
(
"/"
,
"%2F"
).
replace
(
"="
,
"%3D"
);
String
encodeSign
=
encode
.
replace
(
"+"
,
"%20"
).
replace
(
"*"
,
"%2A"
).
replace
(
"~"
,
"%7E"
).
replace
(
"/"
,
"%2F"
).
replace
(
"="
,
"%3D"
);
return
StrUtil
.
format
(
"
https://oapi.dingtalk.com
/sns/getuserinfo_bycode?accessKey=dingkrzwks0jpi2di3uo×tamp={}&signature={}"
,
timestamp
,
encodeSign
);
return
StrUtil
.
format
(
"/sns/getuserinfo_bycode?accessKey=dingkrzwks0jpi2di3uo×tamp={}&signature={}"
,
timestamp
,
encodeSign
);
}
}
public
String
robotPush
(
String
accessToken
,
String
body
)
{
public
String
robotPush
(
String
accessToken
,
String
body
)
{
String
res
=
HttpUtil
.
post
(
"https://oapi.dingtalk.com/robot/send?access_token="
+
accessToken
,
body
);
var
res
=
oDingRestClient
.
post
()
.
uri
(
"/robot/send?access_token="
+
accessToken
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
body
(
body
)
.
retrieve
()
.
body
(
String
.
class
);
log
.
info
(
"钉钉机器人消息推送:{}"
,
res
);
log
.
info
(
"钉钉机器人消息推送:{}"
,
res
);
return
res
;
return
res
;
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment