Commit 93d8e9bf by 桂前礼

feat: [1004526] 业务(bm\trade\book)\接口\数据库层面推动优化

parent 9a388a5f
......@@ -58,6 +58,7 @@ import com.pcloud.book.group.vo.GroupIncomeStaticParamVO;
import com.pcloud.book.group.vo.GroupScanTrendParamVO;
import com.pcloud.book.group.vo.GroupScanTrendVO;
import com.pcloud.book.group.vo.GroupStatisticVO;
import com.pcloud.book.group.vo.ListBook4ChannelVO;
import com.pcloud.book.group.vo.ListBookGroup4ChannelParamVO;
import com.pcloud.book.group.vo.ResourcesStatisticVO;
import com.pcloud.book.group.vo.StatisticVO;
......@@ -206,7 +207,7 @@ public interface BookGroupBiz {
* @author 戴兴
* @date 2019/7/23 15:39
*/
PageBean listBookGroup4Channel(Long channelId, ListBookGroup4ChannelParamVO listBookGroup4ChannelParamVO);
PageBeanNew<ListBook4ChannelVO> listBookGroup4Channel(Long channelId, ListBookGroup4ChannelParamVO listBookGroup4ChannelParamVO);
/**
* 获取社群书列表(编辑)
......
......@@ -195,6 +195,7 @@ import com.pcloud.book.keywords.dao.BookKeywordDao;
import com.pcloud.book.keywords.dto.KeywordDTO;
import com.pcloud.book.keywords.enums.ReplyTypeEnum;
import com.pcloud.book.keywords.vo.ListKeywordVO;
import com.pcloud.book.mapper.clickhouse.BookMapper;
import com.pcloud.book.pcloudkeyword.biz.PcloudRobotBiz;
import com.pcloud.book.pcloudkeyword.entity.PcloudRobot;
import com.pcloud.book.push.enums.AltTypeEnum;
......@@ -499,6 +500,8 @@ public class BookGroupBizImpl implements BookGroupBiz {
private WordappConsr wordappConsr;
@Autowired
private ExerciseBookConsr exerciseBookConsr;
@Autowired
private BookMapper bookMapper;
private static final ThreadPoolExecutor PLATFORM_STATISTICS_EXPORT_THREAD = new ThreadPoolExecutor(2, 2,
0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
......@@ -1300,7 +1303,7 @@ public class BookGroupBizImpl implements BookGroupBiz {
}
@Override
public PageBean listBookGroup4Channel( Long channelId, ListBookGroup4ChannelParamVO listBookGroup4ChannelParamVO ) {
public PageBeanNew<ListBook4ChannelVO> listBookGroup4Channel(Long channelId, ListBookGroup4ChannelParamVO listBookGroup4ChannelParamVO) {
Integer currentPage = listBookGroup4ChannelParamVO.getCurrentPage();
Integer numPerPage = listBookGroup4ChannelParamVO.getNumPerPage();
if (currentPage == null || numPerPage == null || currentPage < 0 || numPerPage < 0) {
......@@ -1319,29 +1322,32 @@ public class BookGroupBizImpl implements BookGroupBiz {
if (endTime != null) {
paramMap.put("endTime", endTime + " 23:59:59");
}
PageBean listBookGroup4Channel = bookDao.listPage(pageParam, paramMap, "listBookGroup4Channel");
List<Long> bookGroupIds = new ArrayList<>();
listBookGroup4Channel.getRecordList().forEach(e -> {
ListBook4ChannelVO listBook4ChannelVO = (ListBook4ChannelVO) e;
bookGroupIds.add(listBook4ChannelVO.getBookGroupId());
});
paramMap.put("offset", currentPage * numPerPage);
paramMap.put("limit", numPerPage);
Integer totalCount = bookMapper.countBookGroup4Channel(paramMap);
if (totalCount < 1) {
return new PageBeanNew(currentPage, numPerPage, new ArrayList<>());
}
List<ListBook4ChannelVO> recordList = bookMapper.listBookGroup4Channel(paramMap);
List<Long> bookGroupIds = recordList.stream().filter(x -> ObjectUtil.isAllNotEmpty(x, x.getBookGroupId())).map(ListBook4ChannelVO::getBookGroupId).distinct().collect(Collectors.toList());
if (ListUtils.isEmpty(bookGroupIds)) {
return new PageBean(0, 0, new ArrayList<>());
return new PageBeanNew(currentPage, numPerPage, new ArrayList<>());
}
Map<Long, BookGroupStatisticDTO> statisMap = bookGroupClassifyDao.getClassifyCountAbout(bookGroupIds);
listBookGroup4Channel.getRecordList().forEach(e -> {
ListBook4ChannelVO listBook4ChannelVO = (ListBook4ChannelVO) e;
if (!MapUtils.isEmpty(statisMap) && statisMap.containsKey(listBook4ChannelVO.getBookGroupId())) {
BookGroupStatisticDTO dto = statisMap.get(listBook4ChannelVO.getBookGroupId());
listBook4ChannelVO.setClassifyNum(null != dto.getClassifyCount() ? dto.getClassifyCount().longValue() : 0L);
listBook4ChannelVO.setTotalNum(null != dto.getUserNumber() ? dto.getUserNumber().longValue() : 0L);
recordList.forEach(e -> {
if (!MapUtils.isEmpty(statisMap) && statisMap.containsKey(e.getBookGroupId())) {
BookGroupStatisticDTO dto = statisMap.get(e.getBookGroupId());
e.setClassifyNum(null != dto.getClassifyCount() ? dto.getClassifyCount().longValue() : 0L);
e.setTotalNum(null != dto.getUserNumber() ? dto.getUserNumber().longValue() : 0L);
} else {
listBook4ChannelVO.setClassifyNum(0L);
listBook4ChannelVO.setTotalNum(0L);
e.setClassifyNum(0L);
e.setTotalNum(0L);
}
});
return listBookGroup4Channel;
return new PageBeanNew<>(currentPage, numPerPage, totalCount, recordList);
}
/**
......@@ -2261,21 +2267,22 @@ public class BookGroupBizImpl implements BookGroupBiz {
@Override
public Map<Long, StoreFlowInfoDto> getBookGroupInfoByChannelId( Long channelId, Integer itemNum ) {
Map<Long, StoreFlowInfoDto> result = new HashMap<>();
PageParam pageParam = new PageParam(0, itemNum);
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("channelId", channelId);
PageBean listBookGroup4Channel = bookDao.listPage(pageParam, paramMap, "listBookGroup4Channel");
List<Long> bookGroupIds = new ArrayList<>();
listBookGroup4Channel.getRecordList().forEach(e -> {
ListBook4ChannelVO listBook4ChannelVO = (ListBook4ChannelVO) e;
bookGroupIds.add(listBook4ChannelVO.getBookGroupId());
});
paramMap.put("offset", 0);
paramMap.put("limit", itemNum);
Integer totalCount = bookMapper.countBookGroup4Channel(paramMap);
if (totalCount < 1) {
return new HashMap<>();
}
List<ListBook4ChannelVO> recordList = bookMapper.listBookGroup4Channel(paramMap);
List<Long> bookGroupIds = recordList.stream().filter(x -> ObjectUtil.isAllNotEmpty(x, x.getBookGroupId())).map(ListBook4ChannelVO::getBookGroupId).distinct().collect(Collectors.toList());
if (ListUtils.isEmpty(bookGroupIds)) {
return new HashMap<>();
}
Map<Long, BookGroupStatisticDTO> statisMap = bookGroupClassifyBiz.getBookGroupStatistic(bookGroupIds);
listBookGroup4Channel.getRecordList().forEach(e -> {
ListBook4ChannelVO listBook4ChannelVO = (ListBook4ChannelVO) e;
recordList.forEach(listBook4ChannelVO -> {
StoreFlowInfoDto storeFlowInfoDto = new StoreFlowInfoDto();
storeFlowInfoDto.setOriginId(listBook4ChannelVO.getBookGroupId());
storeFlowInfoDto.setOriginType(StoreCons.OriginTypeEnum.BOOK_GROUP.getCode());
......@@ -2302,13 +2309,20 @@ public class BookGroupBizImpl implements BookGroupBiz {
PageParam pageParam = new PageParam(currentPage, numPerPage);
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("channelId", channelId);
PageBeanNew<ListBook4ChannelVO> resultInfos = bookDao.listPageNew(pageParam, paramMap, "listBookGroup4Channel");
List<Long> bookGroupIds = resultInfos.getRecordList().stream().map(ListBook4ChannelVO::getBookGroupId).collect(Collectors.toList());
paramMap.put("offset", currentPage * numPerPage);
paramMap.put("limit", numPerPage);
Integer totalCount = bookMapper.countBookGroup4Channel(paramMap);
if (totalCount < 1) {
return new PageBeanNew(currentPage, numPerPage, new ArrayList<>());
}
List<ListBook4ChannelVO> recordList = bookMapper.listBookGroup4Channel(paramMap);
List<Long> bookGroupIds = recordList.stream().map(ListBook4ChannelVO::getBookGroupId).collect(Collectors.toList());
if (ListUtils.isEmpty(bookGroupIds)) {
return new PageBeanNew(currentPage, numPerPage, 0, new ArrayList<>());
}
Map<Long, BookGroupStatisticDTO> statisMap = bookGroupClassifyBiz.getBookGroupStatistic(bookGroupIds);
for (ListBook4ChannelVO listBook4ChannelVO : resultInfos.getRecordList()) {
for (ListBook4ChannelVO listBook4ChannelVO : recordList) {
StoreFlowInfoDto storeFlowInfoDto = new StoreFlowInfoDto();
storeFlowInfoDto.setOriginId(listBook4ChannelVO.getBookGroupId());
storeFlowInfoDto.setOriginType(StoreCons.OriginTypeEnum.BOOK_GROUP.getCode());
......@@ -2324,7 +2338,7 @@ public class BookGroupBizImpl implements BookGroupBiz {
}
results.add(storeFlowInfoDto);
}
return new PageBeanNew<>(currentPage, numPerPage, resultInfos.getTotalCount(), results);
return new PageBeanNew<>(currentPage, numPerPage, totalCount, results);
}
@ParamLog("获取用户购买或者参与过的社群书信息")
......
......@@ -18,6 +18,7 @@ import com.pcloud.book.group.vo.FriendsVO;
import com.pcloud.book.group.vo.GroupIncomeStaticParamVO;
import com.pcloud.book.group.vo.GroupScanTrendParamVO;
import com.pcloud.book.group.vo.GroupScanTrendVO;
import com.pcloud.book.group.vo.ListBook4ChannelVO;
import com.pcloud.book.group.vo.ListBookGroup4ChannelParamVO;
import com.pcloud.book.group.vo.ResourcesStatisticVO;
import com.pcloud.book.group.vo.UpdateRankTypeVO;
......@@ -181,8 +182,8 @@ public interface BookGroupFacade {
@ApiImplicitParam(name = "listBookGroup4ChannelParamVO", value = "ListBookGroup4ChannelParamVO", dataType = "ListBookGroup4ChannelParamVO", paramType = "body")
})
@RequestMapping(value = "listBookGroup4Channel", method = RequestMethod.POST)
ResponseDto<PageBean> listBookGroup4Channel(@RequestHeader("token") String token,
@RequestBody ListBookGroup4ChannelParamVO listBookGroup4ChannelParamVO)
ResponseDto<PageBeanNew<ListBook4ChannelVO>> listBookGroup4Channel(@RequestHeader("token") String token,
@RequestBody ListBookGroup4ChannelParamVO listBookGroup4ChannelParamVO)
throws BizException, PermissionException;
@ApiOperation(value = "获取用户购买或者参与过的社群书信息", httpMethod = "GET")
......
......@@ -33,6 +33,7 @@ import com.pcloud.book.group.vo.GroupIncomeStaticParamVO;
import com.pcloud.book.group.vo.GroupScanTrendParamVO;
import com.pcloud.book.group.vo.GroupScanTrendVO;
import com.pcloud.book.group.vo.GroupStatisticVO;
import com.pcloud.book.group.vo.ListBook4ChannelVO;
import com.pcloud.book.group.vo.ListBookGroup4ChannelParamVO;
import com.pcloud.book.group.vo.ResourcesStatisticVO;
import com.pcloud.book.group.vo.TotalRescourceDataVO;
......@@ -297,10 +298,10 @@ public class BookGroupFacadeImpl implements BookGroupFacade {
@Override
@RequestMapping(value = "listBookGroup4Channel", method = RequestMethod.POST)
public ResponseDto<PageBean> listBookGroup4Channel( @RequestHeader("token") String token,
public ResponseDto<PageBeanNew<ListBook4ChannelVO>> listBookGroup4Channel( @RequestHeader("token") String token,
@RequestBody ListBookGroup4ChannelParamVO listBookGroup4ChannelParamVO ) throws BizException, PermissionException {
Long channelId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
PageBean pageBean = bookGroupBiz.listBookGroup4Channel(channelId, listBookGroup4ChannelParamVO);
PageBeanNew<ListBook4ChannelVO> pageBean = bookGroupBiz.listBookGroup4Channel(channelId, listBookGroup4ChannelParamVO);
return new ResponseDto<>(pageBean);
}
......
package com.pcloud.book.mapper.clickhouse;
import com.pcloud.book.group.vo.ListBook4ChannelVO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
@Mapper
@Component
public interface BookMapper {
List<ListBook4ChannelVO> listBookGroup4Channel(Map<String,Object> params);
Integer countBookGroup4Channel(Map<String,Object> params);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pcloud.book.mapper.clickhouse.BookMapper">
<select id="listBookGroup4Channel" resultType="com.pcloud.book.group.vo.ListBook4ChannelVO" parameterType="map">
SELECT b.BOOK_ID bookId,
any(b.COVER_IMG) coverImg,
any(bg.id) bookGroupId,
any(b.ISBN) isbn,
any(b.BOOK_NAME) bookName,
any(concat('BK', toString(b.BOOK_ID))) bookNumber
FROM (SELECT BOOK_ID, COVER_IMG, ISBN, BOOK_NAME
FROM book
WHERE IS_DELETE = 0
AND BOOK_NAME NOT LIKE concat('%', '红榜', '%')
AND BOOK_ID IN (SELECT toInt64(BOOK_ID) FROM book_adviser WHERE IS_PRINT = 1)
AND CHAR_LENGTH(BOOK_NAME) >= 8
) b
JOIN ( SELECT id, book_id, create_time, group_qrcode_name
FROM book_group
WHERE id IN (SELECT toInt64(book_group_id) FROM book_group_classify WHERE is_delete = 0)
AND is_delete = 0
<if test="channelId != null"> AND channel_id = ${channelId} </if>
<if test="startTime != null "> AND create_time &gt;= #{startTime} </if>
<if test="endTime != null "> AND create_time &lt;= #{endTime} </if>
<if test="isFundBook != null and isFundBook == 1">
AND book_id IN (SELECT BOOK_ID FROM book_fund WHERE END_TIME &lt; now() AND START_TIME > now())
</if>
) bg ON b.BOOK_ID = bg.book_id
<if test="keywords != null">
WHERE b.ISBN like concat('%',#{keywords},'%') OR b.BOOK_NAME like concat('%',#{keywords},'%') OR bg.group_qrcode_name like concat('%',#{keywords},'%')
</if>
GROUP BY b.BOOK_ID
ORDER BY b.BOOK_ID DESC
LIMIT ${offset}, ${limit}
</select>
<select id="countBookGroup4Channel" resultType="java.lang.Integer">
SELECT uniqExact(b.BOOK_ID)
FROM (SELECT BOOK_ID, COVER_IMG, ISBN, BOOK_NAME
FROM book
WHERE IS_DELETE = 0
AND BOOK_NAME NOT LIKE concat('%', '红榜', '%')
AND BOOK_ID IN (SELECT toInt64(BOOK_ID) FROM book_adviser WHERE IS_PRINT = 1)
AND CHAR_LENGTH(BOOK_NAME) >= 8
) b
JOIN ( SELECT id, book_id, create_time, group_qrcode_name
FROM book_group
WHERE id IN (SELECT toInt64(book_group_id) FROM book_group_classify WHERE is_delete = 0)
AND is_delete = 0
<if test="channelId != null"> AND channel_id = ${channelId} </if>
<if test="startTime != null "> AND create_time &gt;= #{startTime} </if>
<if test="endTime != null "> AND create_time &lt;= #{endTime} </if>
<if test="isFundBook != null and isFundBook == 1">
AND book_id IN (SELECT BOOK_ID FROM book_fund WHERE END_TIME &lt; now() AND START_TIME > now())
</if>
) bg ON b.BOOK_ID = bg.book_id
<if test="keywords != null">
WHERE b.ISBN like concat('%',#{keywords},'%') OR b.BOOK_NAME like concat('%',#{keywords},'%') OR bg.group_qrcode_name like concat('%',#{keywords},'%')
</if>
</select>
</mapper>
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