Commit a802d072 by 田超

Merge branch 'bug/slowSQL' into 'master'

Bug/slow sql

See merge request rays/pcloud-book!1102
parents 254f69a0 a3d6b3c0
......@@ -83,4 +83,6 @@ public interface ServeCollectBiz {
* @return
*/
List<ServeCollectDTO> getList4Collect(List<ServeCollectDTO> serveCollects);
List<ServeCollect> getList4RightsSettingByWechatUserId(Long wechatUserId);
}
\ No newline at end of file
......@@ -333,6 +333,11 @@ public class ServeCollectBizImpl implements ServeCollectBiz {
}
@Override
public List<ServeCollect> getList4RightsSettingByWechatUserId(Long wechatUserId) {
return serveCollectDao.getList4RightsSettingByWechatUserId(wechatUserId);
}
@Override
public List<Long> getAllCollect(Long wechatUserId) {
return serveCollectDao.getAllCollect(wechatUserId);
}
......
......@@ -23,4 +23,6 @@ public interface ServeCollectDao extends BaseDao<ServeCollect> {
List<Long> getAllCollect(Long wechatUserId);
List<ServeCollectDTO> getList4Collect(List<ServeCollectDTO> serveCollects);
List<ServeCollect> getList4RightsSettingByWechatUserId(Long wechatUserId);
}
\ No newline at end of file
......@@ -32,6 +32,12 @@ public class ServeCollectDaoImpl extends BaseDaoImpl<ServeCollect> implements Se
return getSessionTemplate().selectList(getStatement("getList4RightsSetting"), serveCollects);
}
@Override
public List<ServeCollect> getList4RightsSettingByWechatUserId(Long wechatUserId) {
return getSessionTemplate().selectList(getStatement("getList4RightsSettingByWechatUserId"), wechatUserId);
}
@Override
public List<Long> getAllCollect(Long wechatUserId) {
return getSessionTemplate().selectList(getStatement("getAllCollect"), wechatUserId);
......
......@@ -172,7 +172,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -826,11 +825,12 @@ public class BookBizImpl implements BookBiz {
public Map<String, BookDto> listBookGroupByBookIds(MapResourceTotalCountDTO bookDetailDTO) throws BizException {
Map<String, BookDto> bookMap = Maps.newHashMap();
if (null != bookDetailDTO && !ListUtils.isEmpty(bookDetailDTO.getBookIds()) && !ListUtils.isEmpty(bookDetailDTO.getChannelIds()) && !ListUtils.isEmpty(bookDetailDTO.getAdviserIds())) {
Map<String, Object> paramMap = Maps.newHashMap();
paramMap.put("bookIds", bookDetailDTO.getBookIds());
paramMap.put("channelIds", bookDetailDTO.getChannelIds());
paramMap.put("adviserIds", bookDetailDTO.getAdviserIds());
List<BookDto> bookDtos = bookDao.listBookGroupByBookIds(paramMap);
List<BookDto> bookDtos = bookDao.listBookGroupByBookIds(bookDetailDTO.getBookIds(), bookDetailDTO.getChannelIds(),bookDetailDTO.getAdviserIds());
if (!ListUtils.isEmpty(bookDtos)) {
for (BookDto bookDto : bookDtos) {
bookMap.put(bookDto.getBookId() + "_" + bookDto.getChannelId() + "_" + bookDto.getAdviserId(), bookDto);
......
......@@ -91,10 +91,13 @@ public interface BookDao extends BaseDao<Book> {
/**
* 批量获取书籍信息
* @param paramMap
*
* @param bookIds
* @param channelIds
* @param adviserIds
* @return
*/
List<BookDto> listBookGroupByBookIds(Map<String,Object> paramMap);
List<BookDto> listBookGroupByBookIds(List<Long>bookIds,List<Long>channelIds,List<Long>adviserIds);
/**
* 获取详细信息
......
......@@ -15,7 +15,10 @@ import com.pcloud.book.book.vo.BookSaleVO;
import com.pcloud.book.book.vo.SearchBookVO;
import com.pcloud.book.book.dto.BookUniqueNumberDTO;
import com.pcloud.book.es.entity.ESBookAndAdviser;
import com.pcloud.book.group.vo.BookGroupServeCountVO;
import com.pcloud.common.core.dao.BaseDaoImpl;
import com.pcloud.common.utils.ListForInSQL;
import com.pcloud.common.utils.ListUtils;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
......@@ -94,8 +97,17 @@ public class BookDaoImpl extends BaseDaoImpl<Book> implements BookDao {
}
@Override
public List<BookDto> listBookGroupByBookIds(Map<String, Object> paramMap) {
return super.getSqlSession().selectList(super.getStatement("listBookGroupByBookIds"), paramMap);
public List<BookDto> listBookGroupByBookIds(List<Long> bookIds, List<Long> channelIds, List<Long> adviserIds) {
return ListUtils.groupList4SQL(new ListForInSQL<BookDto>() {
@Override
public <T> List<T> processSQL(List<Long> list) {
Map<String,Object> map = new HashMap<>();
map.put("bookIds", list);
map.put("channelIds", channelIds);
map.put("adviserIds", adviserIds);
return getSqlSession().selectList(getStatement("listBookGroupByBookIds"), map);
}
}, bookIds);
}
@Override
......
......@@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/**
......@@ -219,4 +220,5 @@ public class BookProductFacadeImpl implements BookProductFacade {
List<BookProductDto> bookProductDtos = bookProductBiz.list4Adviser(bookId, channelId, adviserId);
return new ResponseDto<List<BookProductDto>>(bookProductDtos == null ? new ArrayList<>() : bookProductDtos);
}
}
......@@ -308,9 +308,6 @@ public class QrcodeSceneConsr {
} catch (BizException e) {
LOGGER.error("【渠道(消)】 获取公众号基本信息,<ERROR>.[getById]:" + e.getMessage(), e);
}
if (null == accountSettingDto){
LOGGER.error("运营平台未配置公众号,channelId=" + channelId);
}
return accountSettingDto;
}
......
......@@ -766,23 +766,11 @@ public class CultivateBizImpl implements CultivateBiz {
@Override
public Integer getRanking(Long wechatUserId) {
Integer ranking=0;
List<Cultivate> list= cultivateDao.getAllOrderByStar();
if(list==null||list.size()==0){
return ranking;
}
for (int i=0;i<=list.size()-1;i++){
Cultivate cultivate = list.get(i);
if(cultivate.getWechatUserId().equals(wechatUserId)){
ranking=i+1;
return ranking;
}
Cultivate cultivate = cultivateDao.getByWechatUserId(wechatUserId);
if(cultivate==null || cultivate.getStar()==0){
return cultivateDao.getAllCounts();
}
return ranking;
return cultivateDao.getRank(cultivate.getStar());
}
@Override
......
......@@ -15,4 +15,8 @@ public interface CultivateDao extends BaseDao<Cultivate> {
List<Cultivate> getRandomUserId(Long cultivateId,Long friendCultivateId);
List<Cultivate> getByCultivateIds(List<Long> cultivateIds);
int getRank(Integer star);
int getAllCounts();
}
......@@ -43,4 +43,14 @@ public class CultivateDaoImpl extends BaseDaoImpl<Cultivate> implements Cultivat
map.put("cultivateIds",cultivateIds);
return super.getSessionTemplate().selectList(getStatement("getByCultivateIds"),map);
}
@Override
public int getRank(Integer star) {
return super.getSessionTemplate().selectOne(getStatement("getRank"),star);
}
@Override
public int getAllCounts() {
return super.getSessionTemplate().selectOne(getStatement("getAllCounts"));
}
}
......@@ -1006,4 +1006,6 @@ public interface BookGroupBiz {
*社群码下载选择样式
*/
BackgroundGroupQrcodeDTO getBackgroundGroupQr(BackgroundGroupQrcodeDTO backgroundGroupQrcodeDTO);
List<BookServeDTO> getBookAndBookGroupServeIdsFive(Long adviserId, Long bookId, Long channelId);
}
......@@ -5204,7 +5204,93 @@ public class BookGroupBizImpl implements BookGroupBiz {
}
@Override
public List<BookServeDTO> getBookAndBookGroupServeIdsFive(Long adviserId, Long bookId, Long channelId) {
List<BookServeDTO> serveDTOList = new ArrayList<>();
BookGroupDTO bookGroupDTO = bookGroupDao.getDTOByBookId(bookId, channelId, adviserId);
List<Long> appIds = new ArrayList<>();
List<Long> productIds = new ArrayList<>();
AccountSettingDto accountSettingDto = qrcodeSceneConsr.getWechatInfo(channelId);
if (null == accountSettingDto){
return new ArrayList<>();
}
//先排纸书二维码资源,后排社群书资源,张文庆
//现代纸书二维码配置资源
BookServeParamVO serveParamVO = new BookServeParamVO();
serveParamVO.setAdviserId(adviserId);
serveParamVO.setBookId(bookId);
serveParamVO.setChannelId(channelId);
List<BookServeVO> bookServeVOS = qrcodeSceneConsr.listBookServeIds(serveParamVO);
if (!ListUtils.isEmpty(bookServeVOS)) {
for (BookServeVO bookServeVO : bookServeVOS) {
if(serveDTOList.size()>=5){
break;
}
Long serveId = bookServeVO.getServeId();
BookServeDTO bookServeDTO = new BookServeDTO();
bookServeDTO.setTypeCode(bookServeVO.getTypeCode());
bookServeDTO.setFromType(bookServeVO.getFromType());
bookServeDTO.setFromTypeName(bookServeVO.getFromTypeName());
String url = SendWeixinRequestTools.splitUrl(accountSettingDto, bookServeVO.getUrl());
if (AppAndProductTypeEnum.APP.value.equals(bookServeVO.getTypeCode()) && !appIds.contains(serveId)) {
bookServeDTO.setServeId(serveId);
bookServeDTO.setServeType(bookServeVO.getTypeCode());
bookServeDTO.setUrl(url);
serveDTOList.add(bookServeDTO);
appIds.add(serveId);
} else if (AppAndProductTypeEnum.PRODUCT.value.equals(bookServeVO.getTypeCode()) && !productIds.contains(serveId)) {
bookServeDTO.setServeId(serveId);
bookServeDTO.setServeType(bookServeVO.getTypeCode());
bookServeDTO.setUrl(url);
serveDTOList.add(bookServeDTO);
productIds.add(serveId);
}
}
}
if (null != bookGroupDTO && serveDTOList.size()<5) {//有社群书
//社群书配置资源
List<BookGroupServe> bookGroupServes = bookGroupServeDao.getListByBookGroupId(bookGroupDTO.getId());
if (!ListUtils.isEmpty(bookGroupServes)) {
for (BookGroupServe bookGroupServe : bookGroupServes) {
if(serveDTOList.size()>=5){
break;
}
BookServeDTO bookServeDTO = new BookServeDTO();
BeanUtils.copyProperties(bookGroupServe, bookServeDTO);
String url = SendWeixinRequestTools.splitUrl(accountSettingDto, bookGroupServe.getServeUrl());
bookServeDTO.setUrl(url);
bookServeDTO.setTypeCode(bookServeDTO.getServeType());
bookServeDTO.setFromType(bookGroupServe.getTypeCode());
bookServeDTO.setFromTypeName(bookGroupServe.getFromType());
Long serveId = bookGroupServe.getServeId();
if (AppAndProductTypeEnum.APP.value.equals(bookServeDTO.getServeType()) && !appIds.contains(serveId)) {
serveDTOList.add(bookServeDTO);
appIds.add(serveId);
} else if (AppAndProductTypeEnum.PRODUCT.value.equals(bookServeDTO.getServeType()) && !productIds.contains(serveId)){
serveDTOList.add(bookServeDTO);
productIds.add(serveId);
}
}
}
}
return serveDTOList;
}
@Override
public List<BookServeDTO> getBookAndBookGroupServeIds( Long adviserId, Long bookId, Long channelId ) {
List<BookServeDTO> result = new ArrayList();
String key = "getBookAndBookGroupServeIds"+adviserId+"_"+bookId+"_"+channelId;
if(JedisClusterUtils.exists(key)){
result = JedisClusterUtils.getJsonList(key, BookServeDTO.class);
}else {
result = getBookServes(adviserId, bookId, channelId);
JedisClusterUtils.setJsonList(key,result,300);
}
return result;
}
private List<BookServeDTO> getBookServes( Long adviserId, Long bookId, Long channelId ) {
List<BookServeDTO> serveDTOList = new ArrayList<>();
BookGroupDTO bookGroupDTO = bookGroupDao.getDTOByBookId(bookId, channelId, adviserId);
List<Long> appIds = new ArrayList<>();
......
......@@ -10,8 +10,11 @@ import com.pcloud.book.group.dto.TopAgentBookGroupDTO;
import com.pcloud.book.group.entity.BookGroup;
import com.pcloud.book.group.entity.QrChangeRecord;
import com.pcloud.book.group.vo.BookGroupAnalysisVO;
import com.pcloud.book.group.vo.BookGroupServeCountVO;
import com.pcloud.common.core.dao.BaseDaoImpl;
import com.pcloud.common.utils.ListForInSQL;
import com.pcloud.common.utils.ListUtils;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
......@@ -47,7 +50,12 @@ public class BookGroupDaoImpl extends BaseDaoImpl<BookGroup> implements BookGrou
*/
@Override
public List<BookGroupDTO> getDTOByIds(List<Long> bookGroupIds) {
return super.getSqlSession().selectList(getStatement("getDTOByIds"), bookGroupIds);
return ListUtils.groupList4SQL(new ListForInSQL<BookGroupDTO>() {
@Override
public <T> List<T> processSQL(List<Long> list) {
return getSessionTemplate().selectList(getStatement("getDTOByIds"), list);
}
}, bookGroupIds);
}
/**
......
......@@ -8,11 +8,12 @@ import com.pcloud.book.group.entity.BookGroupServe;
import com.pcloud.book.group.vo.BookGroupServeCountVO;
import com.pcloud.common.core.dao.BaseDaoImpl;
import com.pcloud.common.utils.ListForInSQL;
import com.pcloud.common.utils.ListUtils;
import org.apache.commons.collections.ArrayStack;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @Description
......@@ -101,9 +102,18 @@ public class BookGroupServeDaoImpl extends BaseDaoImpl<BookGroupServe> implement
@Override
public List<BookGroupServeCountVO> getServeList4Applet(List<Long> bookIds) {
Map<String,Object> map = new HashMap<>();
map.put("bookIds", bookIds);
return getSessionTemplate().selectList(getStatement("getServeList4Applet"), map);
return ListUtils.groupList4SQL(new ListForInSQL<BookGroupServeCountVO>() {
@Override
public <T> List<T> processSQL(List<Long> list) {
Map<String,Object> map = new HashMap<>();
map.put("bookIds", list);
return getSessionTemplate().selectList(getStatement("getServeList4Applet"), map);
}
}, bookIds);
}
@Override
......@@ -117,11 +127,28 @@ public class BookGroupServeDaoImpl extends BaseDaoImpl<BookGroupServe> implement
@Override
public Map<String, BookGroupServeCountDTO> mapBookGroupQrcodeServeCount(List<Long> adviserIds, List<Long> bookIds, List<Long> channelIds, Integer joinGroupType) {
Map<String,Object> map = new HashMap<>();
map.put("adviserIds", adviserIds);
map.put("bookIds", bookIds);
map.put("channelIds", channelIds);
map.put("joinGroupType", joinGroupType);
return getSessionTemplate().selectMap(getStatement("mapBookGroupQrcodeServeCount"), map, "bookChannelAdviserId");
if (bookIds != null && bookIds.size() > 500) {
Map<String, BookGroupServeCountDTO>resultMap = new HashMap<>();
List<List<Long>> lists = ListUtils.groupList(bookIds);
for (List<Long> list : lists) {
Map<String, Object> map = new HashMap<>();
map.put("adviserIds", adviserIds);
map.put("bookIds", list);
map.put("channelIds", channelIds);
map.put("joinGroupType", joinGroupType);
Map<String, BookGroupServeCountDTO> objectObjectMap = getSessionTemplate().selectMap(getStatement("mapBookGroupQrcodeServeCount"), map, "bookChannelAdviserId");
if(objectObjectMap!=null){
resultMap.putAll(objectObjectMap);
}
}
return resultMap;
} else {
Map<String, Object> map = new HashMap<>();
map.put("adviserIds", adviserIds);
map.put("bookIds", bookIds);
map.put("channelIds", channelIds);
map.put("joinGroupType", joinGroupType);
return getSessionTemplate().selectMap(getStatement("mapBookGroupQrcodeServeCount"), map, "bookChannelAdviserId");
}
}
}
......@@ -120,7 +120,7 @@ public interface RightsSettingBiz {
FillRightsSettingAppletsDTO getFillRightsSettingApplets(Long rightsSettingId, Long wechatUserId, Long rightsClassifyId,
Integer top, Long bookId, Long officialAccountsId);
List<RightsItemGroup> getRightsItemGroups(Long rightsSettingId, Long adviserId, Long bookId, Long channelId, Boolean removeCanNotBuy, Integer readType, Long wechatUserId);
List<RightsItemGroup> getRightsItemGroups(Long rightsSettingId, Long adviserId, Long bookId, Long channelId, Boolean removeCanNotBuy, Integer readType, Long wechatUserId,boolean homePage);
RightsSettingDto getRightSettingByBookId(Long bookId, Long adviserId, Long channelId);
......
......@@ -233,7 +233,7 @@ public class RightsSettingFacede {
if (null==rightsSettingId){
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "参数缺失!");
}
return new ResponseDto<>(rightsSettingBiz.getRightsItemGroups(rightsSettingId, adviserId, bookId, channelId, true,readType, wechatUserId));
return new ResponseDto<>(rightsSettingBiz.getRightsItemGroups(rightsSettingId, adviserId, bookId, channelId, true,readType, wechatUserId,false));
}
@ApiOperation("根据书刊的分类获取对应的分类权益信息")
......
......@@ -342,7 +342,7 @@
n.pic1,
n.pic2,
n.pic3,
n.content,
-- n.content,
n.show_state showState,
n.create_time createTime,
n.first_classify firstClassify,
......
......@@ -183,6 +183,19 @@
and serve_type = 1
</update>
<select id="getList4RightsSettingByWechatUserId" parameterType="list" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from
serve_collect
where
is_delete = 0
and
wechat_user_id = #{wechatUserId}
</select>
<select id="getList4RightsSetting" parameterType="list" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
......
......@@ -17,6 +17,15 @@
id, wechat_user_id, energy, fish_ball, star, lighten, create_time,update_time,is_home
</sql>
<select id="getRank" resultType="int">
select count(1)+1 from cultivate where star>#{star}
</select>
<select id="getAllCounts" resultType="int">
select count(1) from cultivate
</select>
<insert id="insert" parameterType="com.pcloud.book.cultivate.entity.Cultivate" useGeneratedKeys="true" keyProperty="id">
insert into cultivate
(
......
......@@ -5,6 +5,8 @@ import com.pcloud.book.BookApplication;
import com.pcloud.book.es.biz.ESBookAndAdviserBiz;
import com.pcloud.book.es.biz.impl.IKAnalyzerUtil;
import com.pcloud.book.es.entity.ESBookAndAdviser;
import com.pcloud.book.group.dao.BookGroupServeDao;
import com.pcloud.book.group.vo.BookGroupServeCountVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
......@@ -15,6 +17,10 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {BookApplication.class, ESBookAndAdviserBizTest.class})
......@@ -23,6 +29,8 @@ public class ESBookAndAdviserBizTest {
@Autowired
private ESBookAndAdviserBiz esBookAndAdviserBiz;
@Test
public void testes() {
StopWatch sw = new StopWatch();
......
package com.pcloud.book.test;
import com.pcloud.book.BookApplication;
import com.pcloud.book.group.dao.BookGroupDao;
import com.pcloud.book.group.dao.BookGroupServeDao;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.vo.BookGroupServeCountVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {BookApplication.class})
public class SlowSQLTest {
@Autowired
private BookGroupServeDao bookGroupServeDao;
@Autowired
private BookGroupDao bookGroupDao;
@Test
public void testBookGroupServeDao(){
List<Long> bookIds = new ArrayList<>();
bookIds.add(4L);
bookIds.add(5L);
List<BookGroupServeCountVO> serveList4Applet = bookGroupServeDao.getServeList4Applet(bookIds);
List<BookGroupServeCountVO> serveList4Applet1 = bookGroupServeDao.getServeList4Applet(getTestBookIdList());
System.out.println(1);
}
@Test
public void testGetDTOByIds(){
List<BookGroupDTO> dtoByIds = bookGroupDao.getDTOByIds(getTestBookIdList());
}
public static List<Long>getTestBookIdList(){
return TestBookList.getBookIdList();
}
}
......@@ -39,12 +39,20 @@ public class BookKeywordWarehouseBizTest {
@Resource
private AdNewsBiz adNewsBiz;
@Resource
private BookGroupServeDao bookGroupServeDao;
@Test
public void testQuartzAdNewsBiz(){
adNewsBiz.sendAdNews((2L));
}
@Test
public void testBookGroupServeDao(){
bookGroupServeDao.
}
@Test
public void addBookKeyword() {
AddBookKeywordRequestVO vo = new AddBookKeywordRequestVO();
vo.setUserId(1L);
......
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