Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-api-boot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-api-boot
Commits
5b8c6aac
提交
5b8c6aac
authored
4月 18, 2022
作者:
17607474349
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:
1、线程池 2、封装zyHttpService
上级
a792a2b3
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
234 行增加
和
116 行删除
+234
-116
ZyLocationTagAddParam.java
...m/yiring/app/param/location/zy/ZyLocationTagAddParam.java
+3
-3
LocationTagServiceImpl.java
...ing/app/service/location/impl/LocationTagServiceImpl.java
+15
-7
ZyHttpService.java
...c/main/java/com/yiring/auth/service/zy/ZyHttpService.java
+49
-0
ZyHttpServiceImpl.java
...va/com/yiring/auth/service/zy/impl/ZyHttpServiceImpl.java
+118
-0
ZyUtil.java
basic-auth/src/main/java/com/yiring/auth/util/ZyUtil.java
+2
-106
ExecutorConfig.java
...rc/main/java/com/yiring/common/config/ExecutorConfig.java
+47
-0
没有找到文件。
app/src/main/java/com/yiring/app/param/location/zy/ZyLocationTagAddParam.java
浏览文件 @
5b8c6aac
...
@@ -26,7 +26,7 @@ public class ZyLocationTagAddParam implements Serializable {
...
@@ -26,7 +26,7 @@ public class ZyLocationTagAddParam implements Serializable {
private
static
final
long
serialVersionUID
=
-
8828137320896062620L
;
private
static
final
long
serialVersionUID
=
-
8828137320896062620L
;
@ApiModelProperty
(
value
=
"工厂"
,
example
=
"100"
)
@ApiModelProperty
(
value
=
"工厂"
,
example
=
"100"
)
String
orgId
;
Integer
orgId
;
@ApiModelProperty
(
value
=
"标签类型"
,
example
=
"蓝牙人员定位卡"
,
required
=
true
)
@ApiModelProperty
(
value
=
"标签类型"
,
example
=
"蓝牙人员定位卡"
,
required
=
true
)
LocationTag
.
Type
types
;
LocationTag
.
Type
types
;
...
@@ -37,11 +37,11 @@ public class ZyLocationTagAddParam implements Serializable {
...
@@ -37,11 +37,11 @@ public class ZyLocationTagAddParam implements Serializable {
@ApiModelProperty
(
value
=
"实体类型"
,
example
=
"car"
,
required
=
true
)
@ApiModelProperty
(
value
=
"实体类型"
,
example
=
"car"
,
required
=
true
)
String
entityType
;
String
entityType
;
public
static
ZyLocationTagAddParam
transform
(
LocationTag
locationTag
)
{
public
static
ZyLocationTagAddParam
transform
(
LocationTag
locationTag
,
Integer
orgId
)
{
String
entityType
=
StrUtil
.
equals
(
locationTag
.
getType
().
name
(),
"BTT02"
)
?
"car"
:
"staff"
;
String
entityType
=
StrUtil
.
equals
(
locationTag
.
getType
().
name
(),
"BTT02"
)
?
"car"
:
"staff"
;
return
ZyLocationTagAddParam
return
ZyLocationTagAddParam
.
builder
()
.
builder
()
.
orgId
(
"100"
)
.
orgId
(
orgId
)
.
tagId
(
locationTag
.
getCode
())
.
tagId
(
locationTag
.
getCode
())
.
types
(
locationTag
.
getType
())
.
types
(
locationTag
.
getType
())
.
entityType
(
entityType
)
.
entityType
(
entityType
)
...
...
app/src/main/java/com/yiring/app/service/location/impl/LocationTagServiceImpl.java
浏览文件 @
5b8c6aac
...
@@ -17,7 +17,7 @@ import com.yiring.app.param.location.LocationTagModifyParam;
...
@@ -17,7 +17,7 @@ import com.yiring.app.param.location.LocationTagModifyParam;
import
com.yiring.app.param.location.zy.ZyLocationTagAddParam
;
import
com.yiring.app.param.location.zy.ZyLocationTagAddParam
;
import
com.yiring.app.service.location.LocationTagService
;
import
com.yiring.app.service.location.LocationTagService
;
import
com.yiring.app.vo.location.LocationTagVo
;
import
com.yiring.app.vo.location.LocationTagVo
;
import
com.yiring.auth.
util.ZyUtil
;
import
com.yiring.auth.
service.zy.ZyHttpService
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.core.Status
;
import
com.yiring.common.core.Status
;
import
com.yiring.common.param.IdParam
;
import
com.yiring.common.param.IdParam
;
...
@@ -61,6 +61,9 @@ public class LocationTagServiceImpl implements LocationTagService {
...
@@ -61,6 +61,9 @@ public class LocationTagServiceImpl implements LocationTagService {
final
Integer
FACTORY_ID
=
100
;
final
Integer
FACTORY_ID
=
100
;
@Resource
@Resource
ZyHttpService
zyHttpService
;
@Resource
LocationTagRepository
locationTagRepository
;
LocationTagRepository
locationTagRepository
;
@Override
@Override
...
@@ -68,13 +71,18 @@ public class LocationTagServiceImpl implements LocationTagService {
...
@@ -68,13 +71,18 @@ public class LocationTagServiceImpl implements LocationTagService {
if
(
hasLocationTagInfoByCode
(
param
.
getCode
()))
return
Result
.
no
(
Status
.
BAD_REQUEST
,
"编号已存在"
);
if
(
hasLocationTagInfoByCode
(
param
.
getCode
()))
return
Result
.
no
(
Status
.
BAD_REQUEST
,
"编号已存在"
);
LocationTag
locationTag
=
param
.
transform
();
LocationTag
locationTag
=
param
.
transform
();
locationTagRepository
.
save
(
locationTag
);
locationTagRepository
.
save
(
locationTag
);
ZyLocationTagAddParam
zyLocationTagAddParam
=
ZyLocationTagAddParam
.
transform
(
locationTag
);
ZyLocationTagAddParam
zyLocationTagAddParam
=
ZyLocationTagAddParam
.
transform
(
locationTag
,
FACTORY_ID
);
List
<
ZyLocationTagAddParam
>
of
=
ListUtil
.
of
(
zyLocationTagAddParam
);
List
<
ZyLocationTagAddParam
>
of
=
ListUtil
.
of
(
zyLocationTagAddParam
);
new
Thread
(()
->
{
try
{
Result
<
Serializable
>
result
=
ZyUtil
.
post
(
"/positionApi/api/tag/saveTag"
,
of
,
3000
);
Result
<
Serializable
>
result
=
zyHttpService
.
post
(
"/positionApi/api/tag/saveTag"
,
of
,
3000
).
get
();
if
(
result
.
getCode
()
!=
200
)
throw
new
RuntimeException
(
result
.
getMessage
());
if
(
result
.
getStatus
()
!=
200
)
throw
new
InterruptedException
(
})
result
.
getStatus
()
+
" : "
+
result
.
getMessage
()
.
start
();
);
}
catch
(
Exception
e
)
{
log
.
error
(
"线程执行异常: "
+
e
.
getMessage
());
throw
new
RuntimeException
(
e
.
getMessage
());
// return Result.no(Status.INTERNAL_SERVER_ERROR, "新增定位标签失败");
}
return
Result
.
ok
();
return
Result
.
ok
();
}
}
...
...
basic-auth/src/main/java/com/yiring/auth/service/zy/ZyHttpService.java
0 → 100644
浏览文件 @
5b8c6aac
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
auth
.
service
.
zy
;
import
com.yiring.common.core.Result
;
import
java.io.Serializable
;
import
java.util.concurrent.CompletableFuture
;
/**
* ZyHttp请求
* @author LJ-2204
* @date 2022/4/18
*/
public
interface
ZyHttpService
{
/**
* get请求
* @param urlString 路径
* @param obj 参数
* @param timeout 请求时长
* @return json
*/
CompletableFuture
<
Result
<
Serializable
>>
get
(
String
urlString
,
Object
obj
,
int
timeout
);
/**
* post请求
* @param urlString 路径
* @param obj 参数
* @param timeout 请求时长
* @return json
*/
CompletableFuture
<
Result
<
Serializable
>>
post
(
String
urlString
,
Object
obj
,
int
timeout
);
/**
* put请求
* @param urlString 路径
* @param obj 参数
* @param timeout 请求时长
* @return json
*/
CompletableFuture
<
Result
<
Serializable
>>
put
(
String
urlString
,
Object
obj
,
int
timeout
);
/**
* delete请求
* @param urlString 路径
* @param obj 参数
* @param timeout 请求时长
* @return json
*/
CompletableFuture
<
Result
<
Serializable
>>
delete
(
String
urlString
,
Object
obj
,
int
timeout
);
}
basic-auth/src/main/java/com/yiring/auth/service/zy/impl/ZyHttpServiceImpl.java
0 → 100644
浏览文件 @
5b8c6aac
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
auth
.
service
.
zy
.
impl
;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.http.Header
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.json.JSONUtil
;
import
com.yiring.auth.service.zy.ZyHttpService
;
import
com.yiring.auth.util.ZyUtil
;
import
com.yiring.common.core.Result
;
import
java.io.Serializable
;
import
java.util.Map
;
import
java.util.concurrent.CompletableFuture
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* ZyHttp请求
* @author LJ-2204
* @date 2022/4/18
*/
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
@Service
@Slf4j
public
class
ZyHttpServiceImpl
implements
ZyHttpService
{
public
final
String
TOKEN_TYPE
=
"bearer "
;
public
final
String
URL_PREFIX
=
"http://project.yz-online.com:789"
;
@Override
@Async
(
"httpThreadPool"
)
public
CompletableFuture
<
Result
<
Serializable
>>
get
(
String
urlString
,
Object
obj
,
int
timeout
)
{
String
json
=
JSONUtil
.
toJsonStr
(
obj
);
String
token
=
ZyUtil
.
login
();
String
body
=
HttpRequest
.
get
(
URL_PREFIX
+
urlString
)
.
header
(
Header
.
AUTHORIZATION
,
TOKEN_TYPE
+
token
)
.
header
(
Header
.
CONTENT_TYPE
,
"application/json"
)
.
body
(
json
)
.
timeout
(
timeout
)
.
execute
()
.
body
();
return
CompletableFuture
.
completedFuture
(
getResult
(
body
));
}
@Override
@Async
(
"httpThreadPool"
)
public
CompletableFuture
<
Result
<
Serializable
>>
post
(
String
urlString
,
Object
obj
,
int
timeout
)
{
String
json
=
JSONUtil
.
toJsonStr
(
obj
);
String
token
=
ZyUtil
.
login
();
String
body
=
HttpRequest
.
post
(
URL_PREFIX
+
urlString
)
.
header
(
Header
.
AUTHORIZATION
,
TOKEN_TYPE
+
token
)
.
header
(
Header
.
CONTENT_TYPE
,
"application/json"
)
.
body
(
json
)
.
timeout
(
timeout
)
.
execute
()
.
body
();
return
CompletableFuture
.
completedFuture
(
getResult
(
body
));
}
@Override
@Async
(
"httpThreadPool"
)
public
CompletableFuture
<
Result
<
Serializable
>>
put
(
String
urlString
,
Object
obj
,
int
timeout
)
{
String
json
=
JSONUtil
.
toJsonStr
(
obj
);
String
token
=
ZyUtil
.
login
();
String
body
=
HttpRequest
.
put
(
URL_PREFIX
+
urlString
)
.
header
(
Header
.
AUTHORIZATION
,
TOKEN_TYPE
+
token
)
.
header
(
Header
.
CONTENT_TYPE
,
"application/json"
)
.
body
(
json
)
.
timeout
(
timeout
)
.
execute
()
.
body
();
return
CompletableFuture
.
completedFuture
(
getResult
(
body
));
}
@Override
@Async
(
"httpThreadPool"
)
public
CompletableFuture
<
Result
<
Serializable
>>
delete
(
String
urlString
,
Object
obj
,
int
timeout
)
{
String
json
=
JSONUtil
.
toJsonStr
(
obj
);
String
token
=
ZyUtil
.
login
();
String
body
=
HttpRequest
.
delete
(
URL_PREFIX
+
urlString
)
.
header
(
Header
.
AUTHORIZATION
,
TOKEN_TYPE
+
token
)
.
header
(
Header
.
CONTENT_TYPE
,
"application/json"
)
.
body
(
json
)
.
timeout
(
timeout
)
.
execute
()
.
body
();
return
CompletableFuture
.
completedFuture
(
getResult
(
body
));
}
/**
* 返回类型转换
* @param body json
* @return Result
*/
private
static
Result
<
Serializable
>
getResult
(
String
body
)
{
String
data
=
null
;
Map
map
=
JSONUtil
.
toBean
(
body
,
Map
.
class
);
Integer
code
=
Convert
.
toInt
(
map
.
get
(
"code"
));
String
msg
=
Convert
.
toStr
(
map
.
get
(
"msg"
));
if
(
ObjectUtil
.
isNotEmpty
(
map
.
get
(
"data"
)))
{
data
=
Convert
.
toStr
(
map
.
get
(
"data"
));
}
return
Result
.
builder
().
status
(
code
).
message
(
msg
).
body
(
data
).
build
();
}
}
basic-auth/src/main/java/com/yiring/auth/util/ZyUtil.java
浏览文件 @
5b8c6aac
...
@@ -4,14 +4,9 @@ package com.yiring.auth.util;
...
@@ -4,14 +4,9 @@ package com.yiring.auth.util;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.http.Header
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.util.BeanUtils
;
import
com.yiring.common.util.BeanUtils
;
import
java.io.Serializable
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -41,10 +36,6 @@ public class ZyUtil {
...
@@ -41,10 +36,6 @@ public class ZyUtil {
public
final
String
KEY
=
"zy_token"
;
public
final
String
KEY
=
"zy_token"
;
public
final
String
TOKEN_TYPE
=
"bearer "
;
public
final
String
URL_PREFIX
=
"http://project.yz-online.com:789"
;
/**
/**
* 获取token
* 获取token
* @return token
* @return token
...
@@ -61,7 +52,8 @@ public class ZyUtil {
...
@@ -61,7 +52,8 @@ public class ZyUtil {
String
json
=
HttpUtil
.
get
(
"http://project.yz-online.com:789/positionApi/oauth/token"
,
map
);
String
json
=
HttpUtil
.
get
(
"http://project.yz-online.com:789/positionApi/oauth/token"
,
map
);
Map
result
=
JSON
.
parseObject
(
json
,
Map
.
class
);
Map
result
=
JSON
.
parseObject
(
json
,
Map
.
class
);
String
access_token
=
result
.
get
(
"access_token"
).
toString
();
String
access_token
=
result
.
get
(
"access_token"
).
toString
();
redisTemplate
.
opsForValue
().
set
(
KEY
,
access_token
,
1200
,
TimeUnit
.
SECONDS
);
String
expires_in
=
result
.
get
(
"expires_in"
).
toString
();
redisTemplate
.
opsForValue
().
set
(
KEY
,
access_token
,
Convert
.
toInt
(
expires_in
),
TimeUnit
.
SECONDS
);
return
access_token
;
return
access_token
;
}
}
...
@@ -72,100 +64,4 @@ public class ZyUtil {
...
@@ -72,100 +64,4 @@ public class ZyUtil {
public
static
boolean
getToken
()
{
public
static
boolean
getToken
()
{
return
ObjectUtil
.
isNotEmpty
(
redisTemplate
.
opsForValue
().
get
(
KEY
));
return
ObjectUtil
.
isNotEmpty
(
redisTemplate
.
opsForValue
().
get
(
KEY
));
}
}
/**
* get请求
* @param urlString 路径
* @param obj 参数
* @param timeout 请求时长
* @return json
*/
public
static
Result
get
(
String
urlString
,
Object
obj
,
int
timeout
)
{
String
json
=
JSONUtil
.
toJsonStr
(
obj
);
String
token
=
login
();
String
body
=
HttpRequest
.
get
(
URL_PREFIX
+
urlString
)
.
header
(
Header
.
AUTHORIZATION
,
TOKEN_TYPE
+
token
)
.
header
(
Header
.
CONTENT_TYPE
,
"application/json"
)
.
body
(
json
)
.
timeout
(
timeout
)
.
execute
()
.
body
();
return
getResult
(
body
);
}
/**
* post请求
* @param urlString 路径
* @param obj 参数
* @param timeout 请求时长
* @return json
*/
public
static
Result
<
Serializable
>
post
(
String
urlString
,
Object
obj
,
int
timeout
)
{
String
json
=
JSONUtil
.
toJsonStr
(
obj
);
String
token
=
login
();
String
body
=
HttpRequest
.
post
(
URL_PREFIX
+
urlString
)
.
header
(
Header
.
AUTHORIZATION
,
TOKEN_TYPE
+
token
)
.
header
(
Header
.
CONTENT_TYPE
,
"application/json"
)
.
body
(
json
)
.
timeout
(
timeout
)
.
execute
()
.
body
();
return
getResult
(
body
);
}
/**
* put请求
* @param urlString 路径
* @param obj 参数
* @param timeout 请求时长
* @return json
*/
public
static
Result
<
Serializable
>
put
(
String
urlString
,
Object
obj
,
int
timeout
)
{
String
json
=
JSONUtil
.
toJsonStr
(
obj
);
String
token
=
login
();
String
body
=
HttpRequest
.
put
(
URL_PREFIX
+
urlString
)
.
header
(
Header
.
AUTHORIZATION
,
TOKEN_TYPE
+
token
)
.
header
(
Header
.
CONTENT_TYPE
,
"application/json"
)
.
body
(
json
)
.
timeout
(
timeout
)
.
execute
()
.
body
();
return
getResult
(
body
);
}
/**
* delete请求
* @param urlString 路径
* @param obj 参数
* @param timeout 请求时长
* @return json
*/
public
static
Result
<
Serializable
>
delete
(
String
urlString
,
Object
obj
,
int
timeout
)
{
String
json
=
JSONUtil
.
toJsonStr
(
obj
);
String
token
=
login
();
String
body
=
HttpRequest
.
delete
(
URL_PREFIX
+
urlString
)
.
header
(
Header
.
AUTHORIZATION
,
TOKEN_TYPE
+
token
)
.
header
(
Header
.
CONTENT_TYPE
,
"application/json"
)
.
body
(
json
)
.
timeout
(
timeout
)
.
execute
()
.
body
();
return
getResult
(
body
);
}
/**
* 返回类型转换
* @param body json
* @return Result
*/
private
static
Result
<
Serializable
>
getResult
(
String
body
)
{
Map
map
=
JSONUtil
.
toBean
(
body
,
Map
.
class
);
Integer
code
=
Convert
.
toInt
(
map
.
get
(
"code"
));
String
msg
=
Convert
.
toStr
(
map
.
get
(
"msg"
));
return
Result
.
builder
().
code
(
code
).
message
(
msg
).
build
();
}
}
}
basic-common/core/src/main/java/com/yiring/common/config/ExecutorConfig.java
0 → 100644
浏览文件 @
5b8c6aac
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
common
.
config
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
/**
* 线程池
* @author LJ-2204
* @date 2022/4/18
*/
@Configuration
@EnableAsync
@Slf4j
public
class
ExecutorConfig
{
@Bean
(
"httpThreadPool"
)
public
Executor
asyncServiceExecutor
()
{
log
.
info
(
"start asyncServiceExecutor"
);
ThreadPoolTaskExecutor
executor
=
new
ThreadPoolTaskExecutor
();
//配置核心线程数
executor
.
setCorePoolSize
(
10
);
//配置最大线程数
executor
.
setMaxPoolSize
(
100
);
//配置队列大小
executor
.
setQueueCapacity
(
10000
);
//配置线程池中的线程的名称前缀
//线程池维护线程所允许的空闲时间
executor
.
setKeepAliveSeconds
(
60
);
executor
.
setThreadNamePrefix
(
"async--"
);
// rejection-policy:当pool已经达到maxsize的时候,如何处理新任务
// CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
executor
.
setRejectedExecutionHandler
(
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
//执行初始化
executor
.
initialize
();
return
executor
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论