Commit 3eb6f88c by 田超

Merge branch 'fixbug/performance' into 'master'

bug: [none] 接口性能优化bookAuthCode/checkServe

See merge request rays/pcloud-book!1504
parents 00910cca 41f1d3a3
package com.pcloud.book.copyright.biz.impl; package com.pcloud.book.copyright.biz.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.pcloud.book.base.enums.BookStatusEnum; import com.pcloud.book.base.enums.BookStatusEnum;
...@@ -52,8 +54,8 @@ import com.pcloud.common.utils.string.StringUtil; ...@@ -52,8 +54,8 @@ import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.readercenter.wechat.entity.WechatUser; import com.pcloud.readercenter.wechat.entity.WechatUser;
import com.pcloud.resourcecenter.base.exceptions.ResBizException; import com.pcloud.resourcecenter.base.exceptions.ResBizException;
import com.pcloud.settlementcenter.record.exceptions.RecordException; import com.pcloud.settlementcenter.record.exceptions.RecordException;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.HorizontalAlignment;
...@@ -75,20 +77,21 @@ import java.io.IOException; ...@@ -75,20 +77,21 @@ import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Date; import java.util.Date;
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.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import static com.pcloud.book.util.common.ExcelUtils.getColumnTopStyle; import static com.pcloud.book.util.common.ExcelUtils.getColumnTopStyle;
import static com.pcloud.book.util.common.ExcelUtils.getDataStyle; import static com.pcloud.book.util.common.ExcelUtils.getDataStyle;
import static com.pcloud.book.util.common.ThreadPoolUtils.REMOTE_CALL_POOL;
/** /**
* @author lily * @author lily
...@@ -190,20 +193,16 @@ public class BookAuthCodeBizImpl implements BookAuthCodeBiz { ...@@ -190,20 +193,16 @@ public class BookAuthCodeBizImpl implements BookAuthCodeBiz {
} }
Long bookId = authBookInfo.getBookId(); Long bookId = authBookInfo.getBookId();
Long adviserId = authBookInfo.getAdviserId(); Long adviserId = authBookInfo.getAdviserId();
List<Long> serveIds = new ArrayList<>(); CompletableFuture<Boolean> haveServeFuture = CompletableFuture.supplyAsync(() -> MapUtils.isNotEmpty(qrcodeSceneConsr.listIsInBook(bookId, channelId, adviserId, Collections.singletonList(serveId))), REMOTE_CALL_POOL);
serveIds.add(serveId); CompletableFuture<Boolean> needAuthFuture = CompletableFuture.supplyAsync(() -> bookAuthServeBiz.checkIsNeedAuth(bookId, channelId, adviserId, serveId, serveType), REMOTE_CALL_POOL);
Map<String, Boolean> isHaveServe = qrcodeSceneConsr.listIsInBook(bookId, channelId, adviserId, serveIds); CompletableFuture<Boolean> haveAuthFuture = CompletableFuture.supplyAsync(() -> !bookAuthUserBiz.checkIsHaveAuth(bookId, channelId, adviserId, wechatUserId, null, null, null), REMOTE_CALL_POOL);
if (isHaveServe == null) { try {
return false; CompletableFuture.allOf(haveServeFuture, needAuthFuture, haveAuthFuture).get();
} return haveServeFuture.get() && needAuthFuture.get() && haveAuthFuture.get();
//校验服务是否需要授权 } catch (InterruptedException | ExecutionException e) {
Boolean isNeedAuth = bookAuthServeBiz.checkIsNeedAuth(bookId, channelId, adviserId, serveId, serveType); LOGGER.warn("校验服务是否需要验证失败! [BookAuthCodeBizImpl.checkServe] ERR:{}", e.getMessage(), e);
if (!isNeedAuth) {
return false; return false;
} }
//校验用户是否已经授权过
Boolean isHaveAuth = bookAuthUserBiz.checkIsHaveAuth(bookId, channelId, adviserId, wechatUserId,null,null,null);
return !isHaveAuth;
} }
@Override @Override
......
...@@ -596,7 +596,7 @@ public class BookAuthInfoBizImpl implements BookAuthInfoBiz { ...@@ -596,7 +596,7 @@ public class BookAuthInfoBizImpl implements BookAuthInfoBiz {
} }
if(null != sceneId){ if(null != sceneId){
//通过二维码获取图书信息 //通过二维码获取图书信息
QrcodeSceneDto qrcodeSceneDto = qrcodeSceneConsr.getById(sceneId); QrcodeSceneDto qrcodeSceneDto = qrcodeSceneConsr.getOnlySceneInfoById(sceneId);
if(qrcodeSceneDto == null){ if(qrcodeSceneDto == null){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "图书不存在"); throw new BookBizException(BookBizException.PARAM_IS_NULL, "图书不存在");
} }
......
...@@ -102,6 +102,13 @@ public class ThreadPoolUtils { ...@@ -102,6 +102,13 @@ public class ThreadPoolUtils {
*/ */
public static final ThreadPoolExecutor UPDATE_PRODUCT_CHANNEL = new ThreadPoolExecutor(8, 8, 0, TimeUnit.SECONDS, public static final ThreadPoolExecutor UPDATE_PRODUCT_CHANNEL = new ThreadPoolExecutor(8, 8, 0, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("update-product-channel-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy()); new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("update-product-channel-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy());
/**
* 远程调用线程池
*/
public static final ThreadPoolExecutor REMOTE_CALL_POOL = new ThreadPoolExecutor(8, 8, 0, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("remote-call-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy());
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment