Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
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
徐少华
midjourney-proxy
Commits
381be837
Commit
381be837
authored
Oct 21, 2021
by
吴博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: [1005780] book error
parent
f90e1cad
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
9 deletions
+49
-9
ProductConsr.java
.../java/com/pcloud/book/consumer/resource/ProductConsr.java
+40
-7
ResourcePageBizImpl.java
...a/com/pcloud/book/group/biz/impl/ResourcePageBizImpl.java
+1
-1
ThreadPoolUtils.java
...ain/java/com/pcloud/book/util/common/ThreadPoolUtils.java
+8
-1
No files found.
pcloud-service-book/src/main/java/com/pcloud/book/consumer/resource/ProductConsr.java
View file @
381be837
...
@@ -4,10 +4,14 @@
...
@@ -4,10 +4,14 @@
package
com
.
pcloud
.
book
.
consumer
.
resource
;
package
com
.
pcloud
.
book
.
consumer
.
resource
;
import
com.pcloud.book.base.exception.BookBizException
;
import
com.pcloud.book.base.exception.BookBizException
;
import
com.pcloud.book.util.common.ThreadPoolUtils
;
import
com.pcloud.channelcenter.base.exceptions.ChannelBizException
;
import
com.pcloud.channelcenter.base.exceptions.ChannelBizException
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.page.PageBeanNew
;
import
com.pcloud.common.utils.BeanUtils
;
import
com.pcloud.common.utils.ListUtils
;
import
com.pcloud.common.utils.ListUtils
;
import
com.pcloud.common.utils.ResponseHandleUtil
;
import
com.pcloud.common.utils.ResponseHandleUtil
;
import
com.pcloud.common.utils.ThreadUtil
;
import
com.pcloud.resourcecenter.product.dto.ProDto
;
import
com.pcloud.resourcecenter.product.dto.ProDto
;
import
com.pcloud.resourcecenter.product.dto.Product4BookDTO
;
import
com.pcloud.resourcecenter.product.dto.Product4BookDTO
;
import
com.pcloud.resourcecenter.product.dto.ProductDto
;
import
com.pcloud.resourcecenter.product.dto.ProductDto
;
...
@@ -25,9 +29,12 @@ import org.springframework.stereotype.Component;
...
@@ -25,9 +29,12 @@ import org.springframework.stereotype.Component;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.ExecutionException
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
/**
/**
...
@@ -94,18 +101,44 @@ public class ProductConsr {
...
@@ -94,18 +101,44 @@ public class ProductConsr {
if
(
productIds
==
null
||
productIds
.
isEmpty
())
{
if
(
productIds
==
null
||
productIds
.
isEmpty
())
{
return
null
;
return
null
;
}
}
try
{
Map
<
Long
,
ProductDto
>
productDtoMap
=
new
HashMap
<>();
return
ResponseHandleUtil
.
parseMapResponse
(
productService
.
getProBasesByIds
(
productIds
),
Long
.
class
,
productIds
=
productIds
.
stream
().
distinct
().
collect
(
Collectors
.
toList
());
Integer
size
=
productIds
.
size
();
if
(
productIds
.
size
()
>
1000
)
{
Integer
[]
queryCountArray
=
{
0
,
1
,
2
,
3
};
Integer
queryCount
=
4
;
//并发查询
List
<
Long
>
finalProductIds
=
productIds
;
Map
<
Long
,
ProductDto
>
finalProductDtoMap
=
productDtoMap
;
CompletableFuture
[]
completableFutures
=
Arrays
.
stream
(
queryCountArray
).
map
(
x
->
CompletableFuture
.
supplyAsync
(()
->
{
Integer
startIndex
=
size
/
queryCount
*
x
;
Integer
endIndex
=
size
/
queryCount
*
(
x
+
1
);
List
<
Long
>
queryList
=
finalProductIds
.
subList
(
startIndex
,
endIndex
);
Map
<
Long
,
ProductDto
>
productMap
=
ResponseHandleUtil
.
parseMapResponse
(
productService
.
getProBasesByIds
(
queryList
),
Long
.
class
,
ProductDto
.
class
);
ProductDto
.
class
);
return
productMap
;
},
ThreadPoolUtils
.
EXPORT_THREAD_POOL
).
whenComplete
(((
productMap
,
throwable
)
->
{
finalProductDtoMap
.
putAll
(
productMap
);
}))).
toArray
(
CompletableFuture
[]::
new
);
try
{
CompletableFuture
.
allOf
(
completableFutures
).
get
();
}
catch
(
InterruptedException
|
ExecutionException
e
)
{
LOGGER
.
warn
(
"[getProBasesByIds] 填充信息失败,err:{}"
,
e
.
getMessage
(),
e
);
}
return
finalProductDtoMap
;
}
else
{
try
{
productDtoMap
=
ResponseHandleUtil
.
parseMapResponse
(
productService
.
getProBasesByIds
(
productIds
),
Long
.
class
,
ProductDto
.
class
);
}
catch
(
BizException
e
)
{
}
catch
(
BizException
e
)
{
LOGGER
.
warn
(
"【资源中心(消)】获取商品基本信息失败:"
+
e
.
getMessage
(),
e
);
LOGGER
.
warn
(
"调用:productService.getProBasesByIds报错"
,
e
.
getMessage
(),
e
);
throw
new
BizException
(
e
.
getCode
(),
e
.
getMessage
());
}
}
catch
(
Exception
e
)
{
return
productDtoMap
;
LOGGER
.
error
(
"【资源中心(消)】获取商品基本信息.[getProBasesByIds]:"
+
e
.
getMessage
(),
e
);
throw
new
BookBizException
(
BookBizException
.
INVOKE_RES_ERROR
,
"服务内部错误,请稍后重试"
);
}
}
}
}
/**
/**
* 资源中心拉取商品基本信息
* 资源中心拉取商品基本信息
*/
*/
...
...
pcloud-service-book/src/main/java/com/pcloud/book/group/biz/impl/ResourcePageBizImpl.java
View file @
381be837
...
@@ -1120,7 +1120,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
...
@@ -1120,7 +1120,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
try
{
try
{
productDtoMap
=
productMapSubmit
.
get
(
ThreadPoolUtils
.
REMOTE_TIME_OUT
,
TimeUnit
.
SECONDS
);
productDtoMap
=
productMapSubmit
.
get
(
ThreadPoolUtils
.
REMOTE_TIME_OUT
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
|
ExecutionException
|
TimeoutException
e
)
{
}
catch
(
InterruptedException
|
ExecutionException
|
TimeoutException
e
)
{
log
.
error
(
"调用资源中心获取商品信息错误:"
+
e
.
getMessage
(),
e
);
log
.
warn
(
"调用资源中心获取商品信息错误:"
+
e
.
getMessage
(),
e
);
}
}
try
{
try
{
appPriceMap
=
appPriceMapSubmit
.
get
(
ThreadPoolUtils
.
REMOTE_TIME_OUT
,
TimeUnit
.
SECONDS
);
appPriceMap
=
appPriceMapSubmit
.
get
(
ThreadPoolUtils
.
REMOTE_TIME_OUT
,
TimeUnit
.
SECONDS
);
...
...
pcloud-service-book/src/main/java/com/pcloud/book/util/common/ThreadPoolUtils.java
View file @
381be837
...
@@ -12,7 +12,7 @@ public class ThreadPoolUtils {
...
@@ -12,7 +12,7 @@ public class ThreadPoolUtils {
/**
/**
* 远程调用超时时间(单位:秒)
* 远程调用超时时间(单位:秒)
*/
*/
public
static
final
int
REMOTE_TIME_OUT
=
5
;
public
static
final
int
REMOTE_TIME_OUT
=
10
;
/**
/**
* 远程调用超时时间(单位:秒)
* 远程调用超时时间(单位:秒)
...
@@ -90,5 +90,12 @@ public class ThreadPoolUtils {
...
@@ -90,5 +90,12 @@ public class ThreadPoolUtils {
public
static
final
ThreadPoolExecutor
UPDATE_SUPER_SEARCH_POOL
=
new
ThreadPoolExecutor
(
8
,
8
,
0
,
TimeUnit
.
SECONDS
,
public
static
final
ThreadPoolExecutor
UPDATE_SUPER_SEARCH_POOL
=
new
ThreadPoolExecutor
(
8
,
8
,
0
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingQueue
<>(),
new
ThreadFactoryBuilder
().
setNameFormat
(
"update_super_search-pool-%d"
).
build
(),
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
new
LinkedBlockingQueue
<>(),
new
ThreadFactoryBuilder
().
setNameFormat
(
"update_super_search-pool-%d"
).
build
(),
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
/**
* 超级搜索更新线程
*/
public
static
final
ThreadPoolExecutor
FILL_SERVICE_POOL
=
new
ThreadPoolExecutor
(
8
,
8
,
0
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingQueue
<>(),
new
ThreadFactoryBuilder
().
setNameFormat
(
"fill-service-pool-%d"
).
build
(),
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
}
}
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