Commit b3fbf47a by 李传峰

Merge branch 'feature/1007236' into 'release'

book慢sql优化转es(段宏超提供)

See merge request rays/pcloud-book!1581
parents bc9aa8a2 aad6386d
......@@ -509,4 +509,16 @@ public interface BookAdviserBiz {
Integer getBookIsOpenCatalog(Long bookId, Long channelId, Long adviserId);
void updateOpenRaysCode(BookAdviser bookAdviser);
/**
* 从es中查询rays书刊信息
* @param isbn
* @param uniqueNumber
* @param adviserName
* @param agentId
* @param currentPage
* @param numPerPage
* @return
*/
PageBeanNew<ErpAdviserBookVO> listAdviserBook4Erp4ES(String isbn, String uniqueNumber, String adviserName, Long agentId, Integer currentPage, Integer numPerPage);
}
......@@ -29,6 +29,7 @@ import com.pcloud.book.book.vo.request.RelateRaysBookApprovalVO;
import com.pcloud.book.book.vo.request.UpdateBookRobotProcessDto;
import com.pcloud.book.consumer.analysisengine.BrowseRecordConsr;
import com.pcloud.book.consumer.app.AppConsr;
import com.pcloud.book.consumer.book.elasticsearch.BookElasticSearchConsr;
import com.pcloud.book.consumer.channel.QrcodeSceneConsr;
import com.pcloud.book.consumer.common.ExportConsr;
import com.pcloud.book.consumer.data.DataConsr;
......@@ -47,6 +48,9 @@ import com.pcloud.book.consumer.user.BookcaseConsr;
import com.pcloud.book.consumer.user.ChannelConsr;
import com.pcloud.book.consumer.user.OperationConsr;
import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
import com.pcloud.book.elasticsearch7.domain.dto.param.BookSearchDto;
import com.pcloud.book.elasticsearch7.domain.dto.param.PlatformSearchDto;
import com.pcloud.book.elasticsearch7.domain.entity.Es7Book;
import com.pcloud.book.es.biz.ESBookAndAdviserBiz;
import com.pcloud.book.es.entity.ESBookAndAdviser;
import com.pcloud.book.group.biz.BookGroupBiz;
......@@ -70,6 +74,7 @@ import com.pcloud.book.rightsSetting.dto.RightsSettingQueryDTO;
import com.pcloud.book.rightsSetting.entity.RightsSetting;
import com.pcloud.book.rightsSetting.entity.RightsSettingNow;
import com.pcloud.book.rightsSetting.entity.RightsSettingTitle;
import com.pcloud.book.util.common.Converter;
import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.book.util.common.YesOrNoEnums;
import com.pcloud.channelcenter.base.constants.MessageFromTypeEnum;
......@@ -106,10 +111,12 @@ import com.pcloud.readercenter.userlabel.dto.UserGradeLabelIdDTO;
import com.pcloud.resourcecenter.product.dto.ProductDto;
import com.pcloud.resourcecenter.product.dto.ProductLabelDto;
import com.pcloud.resourcecenter.product.dto.ProductTypeDto;
import com.pcloud.universe.commons.paging.Pagination;
import com.pcloud.usercenter.party.adviser.dto.AdviserBaseInfoDto;
import com.pcloud.usercenter.user.entity.UserLogin;
import com.pcloud.wechatgroup.group.dto.GroupScanUserStatsDTO;
import com.pcloud.wechatgroup.group.dto.GroupUserCountDTO;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -232,6 +239,8 @@ public class BookAdviserBizImpl implements BookAdviserBiz {
private DataConsr dataConsr;
@Autowired
private OperationConsr operationConsr;
@Autowired
private BookElasticSearchConsr bookElasticSearchConsr;
@Override
public List<BookDto> listByAdviserId(Long adviserId) {
......@@ -2585,29 +2594,11 @@ public class BookAdviserBizImpl implements BookAdviserBiz {
if(StringUtils.isBlank(isbn) && StringUtils.isBlank(uniqueNumber) && StringUtils.isBlank(adviserName) && !NumberUtil.isNumber(agentId)){
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "请筛选后再下载!");
}
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("isbn", isbn);
paramMap.put("uniqueNumber", uniqueNumber);
if(!StringUtil.isEmpty(adviserName)) {
List<Long> adviserIds = adviserConsr.getAdviserIdsByName(adviserName);
if(CollectionUtils.isEmpty(adviserIds)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "当前列表为空,请重新筛选再下载!");
}
paramMap.put("adviserIds", adviserIds);
}
if(agentId != null && agentId > 0){
List<Long> allAdvisers4Agent = adviserConsr.getByAgentId(agentId);
if(CollectionUtils.isEmpty(allAdvisers4Agent)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "当前列表为空,请重新筛选再下载!");
}
if(paramMap.containsKey("adviserIds")){
List<Long> adviserIds = (List<Long>)paramMap.get("adviserIds");
adviserIds.retainAll(allAdvisers4Agent);
} else {
paramMap.put("adviserIds", allAdvisers4Agent);
}
PageBeanNew<ErpAdviserBookVO> pageBeanNew = this.listAdviserBook4Erp4ES(isbn, uniqueNumber, adviserName, agentId, 0, 10000);
if (null == pageBeanNew || CollUtil.isEmpty(pageBeanNew.getRecordList())) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "当前列表为空,请重新筛选再下载!");
}
List<ErpAdviserBookVO> bookVOS = bookAdviserDao.listAdviserBook4Erp(paramMap);
List<ErpAdviserBookVO> bookVOS = pageBeanNew.getRecordList();
if(ListUtils.isEmpty(bookVOS)){
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "当前列表为空,请重新筛选再下载!");
}
......@@ -3576,4 +3567,193 @@ public class BookAdviserBizImpl implements BookAdviserBiz {
model.setOpenRaysCode(bookAdviser.getOpenRaysCode());
bookAdviserDao.update(model);
}
@Override
public PageBeanNew<ErpAdviserBookVO> listAdviserBook4Erp4ES(String isbn, String uniqueNumber, String adviserName, Long agentId,
Integer currentPage, Integer numPerPage) {
BookSearchDto bookSearchDto = new BookSearchDto();
if (!StringUtil.isEmpty(isbn)) {
String[] nameList = isbn.trim().split("[\u00A0|\u3000|\u0020]");
if (nameList.length > 1) {
bookSearchDto.setBookNames(Lists.newArrayList(nameList));
}
}
bookSearchDto.setKeyword(isbn);
if (StrUtil.isNotBlank(uniqueNumber) && uniqueNumber.contains("BK")) {
String bk = uniqueNumber.replace("BK", "");
if (NumberUtil.isNumber(bk)) {
bookSearchDto.setBookIdList(Lists.newArrayList(Long.valueOf(bk)));
}
}
bookSearchDto.setIsAdviserBook(Boolean.TRUE);
List<Long> adviserIds4ES = new ArrayList<>();
if (!StringUtil.isEmpty(adviserName)) {
adviserIds4ES = adviserConsr.getAdviserIdsByName(adviserName);
if (CollectionUtils.isEmpty(adviserIds4ES)) {
return new PageBeanNew<>(currentPage, numPerPage, new ArrayList<>());
}
}
if (agentId != null && agentId > 0) {
List<Long> allAdvisers4Agent = adviserConsr.getByAgentId(agentId);
if (CollectionUtils.isEmpty(allAdvisers4Agent)) {
return new PageBeanNew<>(currentPage, numPerPage, new ArrayList<>());
}
if (CollUtil.isNotEmpty(adviserIds4ES)) {
adviserIds4ES.retainAll(allAdvisers4Agent);
} else {
adviserIds4ES = allAdvisers4Agent;
}
}
if (CollUtil.isNotEmpty(adviserIds4ES)) {
bookSearchDto.setAdviserIds(adviserIds4ES);
}
bookSearchDto.setCurrentPage(Optional.ofNullable(currentPage).orElse(0) + 1);
bookSearchDto.setPageSize(numPerPage);
Pagination<Es7Book> data = bookElasticSearchConsr.getAdviserBooks4Erp(bookSearchDto);
LOGGER.info(data.toString());
PageBeanNew<ErpAdviserBookVO> pageBeanNew = convertData(data);
if (null == pageBeanNew || CollUtil.isEmpty(pageBeanNew.getRecordList())) {
return new PageBeanNew<>(currentPage, numPerPage, null == pageBeanNew ? 0 : pageBeanNew.getTotalCount(), new ArrayList<>());
}
List<ErpAdviserBookVO> bookVOS = pageBeanNew.getRecordList();
List<BookScanCountParamDTO> param = new ArrayList<>();
BookScanCountParamDTO bookScanCountParamDTO = null;
if (!CollectionUtils.isEmpty(bookVOS)) {
Set<Long> setAdviserIds = new HashSet<>();
Set<Long> setChannelIds = new HashSet<>();
Set<Long> setBookIds = new HashSet<>();
for (ErpAdviserBookVO bookVO : bookVOS) {
bookScanCountParamDTO = new BookScanCountParamDTO();
addIfNonNull(setAdviserIds, bookVO.getAdviserId());
addIfNonNull(setChannelIds, bookVO.getChannelId());
addIfNonNull(setBookIds, bookVO.getBookId());
bookScanCountParamDTO.setBookId(bookVO.getBookId());
bookScanCountParamDTO.setAdviserId(bookVO.getAdviserId());
bookScanCountParamDTO.setChannelId(bookVO.getChannelId());
param.add(bookScanCountParamDTO);
}
List<Long> adviserIds = Lists.newArrayList(setAdviserIds);
List<Long> channelIds = Lists.newArrayList(setChannelIds);
List<Long> bookIds = Lists.newArrayList(setBookIds);
// Map<String, BookDataStatisticsDTO> stringBookDataStatisticsDTOMap = mapBookDataStatistics(adviserIds, bookIds, channelIds);
List<Long> xiaoRuiEducation = channelConsr.isXiaoRuiEducation(bookIds);
// List<BookScanCountDto> bookScanCounts = bookMapper.getBookScanCounts(bookIds);
//小睿书的扫码量
Map<Long, Long> xiaoRuiScanMap = erpConsr.mapScan4Erp(xiaoRuiEducation);
//从data服务拿书刊扫码量(bookId,adviserId,channelId)
Map<String, BookScanCountVO> bookScanCountVOMap = dataConsr.multiGetBookScanCount(param);
/* Map<Long,Integer> chMap = new HashMap<>();
for (BookScanCountDto bookScanCount : bookScanCounts) {
chMap.put(bookScanCount.getBookId(),bookScanCount.getScanCount().intValue());
}*/
Map<Long, UserLogin> userLoginInfoMap = new HashMap<>();
Map<Long, AdviserBaseInfoDto> adviserAgentMap = new HashMap<>();
Map<Long, String> channelNameMap = new HashMap<>();
CompletableFuture<Map<Long, UserLogin>> userLoginInfoMapFuture = CompletableFuture.supplyAsync(() -> {
return adviserConsr.getUserLoginInfoList(adviserIds);
}, ThreadPoolUtils.OTHER_THREAD_POOL);
CompletableFuture<Map<Long, AdviserBaseInfoDto>> adviserAgentMapFuture = CompletableFuture.supplyAsync(() -> {
return adviserConsr.getAdviserId2AdviserInfoDtoMap(adviserIds);
}, ThreadPoolUtils.OTHER_THREAD_POOL);
CompletableFuture<Map<Long, String>> channelNameMapFuture = CompletableFuture.supplyAsync(() -> {
return channelConsr.getNamesByIdList(channelIds);
}, ThreadPoolUtils.OTHER_THREAD_POOL);
CompletableFuture.allOf(userLoginInfoMapFuture, adviserAgentMapFuture, channelNameMapFuture);
try {
userLoginInfoMap = userLoginInfoMapFuture.get(10, TimeUnit.SECONDS);
adviserAgentMap = adviserAgentMapFuture.get(10, TimeUnit.SECONDS);
channelNameMap = channelNameMapFuture.get(10, TimeUnit.SECONDS);
} catch (InterruptedException | TimeoutException | ExecutionException e) {
LOGGER.error("[exportMonthReport] 并行导出word失败! err:{}", e.getMessage(), e);
}
List<Long> list = bookFundBiz.listHaveFundBooks(bookIds);
for (ErpAdviserBookVO bookVO : bookVOS) {
if (bookVO.getAdviserId() != null && bookVO.getChannelId() != null && bookVO.getBookId() != null) {
String key = bookVO.getBookId() + "_" + bookVO.getChannelId() + "_" + bookVO.getAdviserId();
String scanKey = bookVO.getBookId() + "_" + bookVO.getAdviserId() + "_" + bookVO.getChannelId();
/*if(stringBookDataStatisticsDTOMap.containsKey(key)){
BookDataStatisticsDTO bookDataStatisticsDTO = stringBookDataStatisticsDTOMap.get(key);
bookVO.setScanCount(bookDataStatisticsDTO.getScanCount().intValue());
bookVO.setUserCount(bookDataStatisticsDTO.getUserCount().intValue());
}*/
if (CollUtil.isNotEmpty(bookScanCountVOMap) && bookScanCountVOMap.containsKey(scanKey)) {
BookScanCountVO bookScanCountVO = bookScanCountVOMap.get(scanKey);
if (null != bookScanCountVO) {
bookVO.setScanCount(Optional.ofNullable(bookScanCountVO.getScanCnt()).map(Long::intValue).orElse(0));
bookVO.setUserCount(Optional.ofNullable(bookScanCountVO.getScanUserCnt()).map(Long::intValue).orElse(0));
bookVO.setChScanCount(Optional.ofNullable(bookScanCountVO.getScanCnt()).map(Long::intValue).orElse(0));
}
}
}
if (bookVO.getBookId() != null) {
if (xiaoRuiEducation.contains(bookVO.getBookId())) {
bookVO.setXiaoRuiEducation(1);
if (CollUtil.isNotEmpty(xiaoRuiScanMap) && xiaoRuiScanMap.containsKey(bookVO.getBookId())) {
Long scanCount = xiaoRuiScanMap.get(bookVO.getBookId());
bookVO.setChScanCount(Optional.ofNullable(scanCount).map(Long::intValue).orElse(0));
}
}
/*Integer chScan = chMap.get(bookVO.getBookId());
if(chScan!=null) {
bookVO.setChScanCount(chScan);
}*/
}
Long adviserId = bookVO.getAdviserId();
if (adviserId != null && MapUtils.isNotEmpty(userLoginInfoMap) && userLoginInfoMap.containsKey(adviserId)) {
UserLogin userLogin = userLoginInfoMap.get(adviserId);
bookVO.setAdviserAccount(userLogin != null ? userLogin.getUserName() : null);
bookVO.setEncryptInfo(userLogin != null ? userLogin.getEncryptInfo() : null);
}
if (adviserId != null && MapUtils.isNotEmpty(adviserAgentMap) && adviserAgentMap.containsKey(adviserId)) {
AdviserBaseInfoDto adviserBaseInfoDto = adviserAgentMap.get(adviserId);
bookVO.setAgentName(null != adviserBaseInfoDto ? adviserBaseInfoDto.getAgentName() : "--");
bookVO.setAdviserName(null != adviserBaseInfoDto ? adviserBaseInfoDto.getPartyName() : "--");
bookVO.setPhoneNum(null != adviserBaseInfoDto ? adviserBaseInfoDto.getPhoneNum() : "--");
}
if (bookVO.getChannelId() != null && MapUtils.isNotEmpty(channelNameMap) && channelNameMap.containsKey(bookVO.getChannelId())) {
bookVO.setChannelName(channelNameMap.get(bookVO.getChannelId()));
}
bookVO.setIsFundSupport(false);
if (!ListUtils.isEmpty(list) && list.contains(bookVO.getBookId())) {
bookVO.setIsFundSupport(true);
}
}
}
return new PageBeanNew<>(currentPage, numPerPage, pageBeanNew.getTotalCount(), bookVOS);
}
private PageBeanNew<ErpAdviserBookVO> convertData(Pagination<Es7Book> esResult) {
PageBeanNew<ErpAdviserBookVO> pageBeanNew = new PageBeanNew<>();
pageBeanNew.setCurrentPage(esResult.getCurrentPage() - 1);
pageBeanNew.setNumPerPage(esResult.getPageSize());
pageBeanNew.setTotalCount((int) esResult.getTotalCount());
if (CollUtil.isEmpty(esResult.getList())) {
pageBeanNew.setRecordList(new ArrayList<>());
} else {
List<ErpAdviserBookVO> erpAdviserBookVOS = new ArrayList<>();
esResult.getList().stream().forEach(es7Book -> {
ErpAdviserBookVO erpAdviserBookVO = new ErpAdviserBookVO();
erpAdviserBookVO.setBookId(es7Book.getBookId());
erpAdviserBookVO.setAdviserId(es7Book.getAdviserId());
erpAdviserBookVO.setChannelId(es7Book.getAdviserChannelId());
erpAdviserBookVO.setBookName(es7Book.getBookName());
erpAdviserBookVO.setCoverImg(es7Book.getCoverImg());
erpAdviserBookVO.setIsbn(es7Book.getIsbn());
erpAdviserBookVO.setUniqueNumber("BK" + es7Book.getBookId());
erpAdviserBookVO.setBookAdviserId(es7Book.getBookAdviserId());
erpAdviserBookVO.setSerialNumber(es7Book.getSerialNumber());
erpAdviserBookVOS.add(erpAdviserBookVO);
});
pageBeanNew.setRecordList(erpAdviserBookVOS);
}
return pageBeanNew;
}
}
......@@ -218,7 +218,7 @@ public class BookAdviserFacadeImpl implements BookAdviserFacade {
@RequestParam(value = "currentPage") Integer currentPage,
@RequestParam(value = "numPerPage") Integer numPerPage)
throws PermissionException, JsonParseException, BizException {
return new ResponseDto<>(bookAdviserBiz.listAdviserBook4Erp(isbn, uniqueNumber, adviserName, agentId, currentPage, numPerPage));
return new ResponseDto<>(bookAdviserBiz.listAdviserBook4Erp4ES(isbn, uniqueNumber, adviserName, agentId, currentPage, numPerPage));
}
/**
......
package com.pcloud.book.consumer.book.elasticsearch;
import com.pcloud.book.elasticsearch7.domain.dto.param.BookExtendImgSearchDto;
import com.pcloud.book.elasticsearch7.domain.dto.param.BookSearchDto;
import com.pcloud.book.elasticsearch7.domain.dto.param.PlatformSearchDto;
import com.pcloud.book.elasticsearch7.domain.entity.Es7Book;
import com.pcloud.book.elasticsearch7.service.Es7BookExtendImgService;
import com.pcloud.book.elasticsearch7.service.Es7BookSearchService;
import com.pcloud.book.elasticsearch7.service.PlatformBookSearchService;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.universe.commons.paging.Pagination;
......@@ -30,6 +32,8 @@ public class BookElasticSearchConsr {
private PlatformBookSearchService platformBookSearchService;
@Autowired
private Es7BookExtendImgService es7BookExtendImgService;
@Autowired
private Es7BookSearchService es7BookSearchService;
public Pagination<Es7Book> search(PlatformSearchDto dto) {
try {
......@@ -50,4 +54,14 @@ public class BookElasticSearchConsr {
}
return new ArrayList<>();
}
public Pagination<Es7Book> getAdviserBooks4Erp(BookSearchDto param) {
try {
Pagination<Es7Book> r = es7BookSearchService.getAdviserBooks4Erp(param);
return r;
} catch (Exception e) {
logger.error("platform book es search exception.", e);
}
return new Pagination<>();
}
}
......@@ -2110,6 +2110,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
} catch (BizException e) {
LOGGER.warn("修改一码一资源直接跳转失败"+e.getMsg());
}
}
@Override
......
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