Commit aab61f65 by 田超

Merge branch 'feature/1002978' into 'master'

feat: [1002978] 小程序书刊分类选择推荐及社群书优化方案

See merge request rays/pcloud-book!768
parents 68cc3b84 4fb0dac1
package com.pcloud.book.applet.biz;
import com.pcloud.appcenter.assist.dto.AssistTempletDTO;
import com.pcloud.book.applet.dto.AppletBookClassifyDTO;
import com.pcloud.book.applet.dto.AppletBookClassifyRelationDTO;
import com.pcloud.book.applet.dto.AppletUserLabelDTO;
......@@ -101,4 +102,12 @@ public interface AppletBookClassifyBiz {
* * @param null
*/
List<AppletUserLabelRelation> getByAppletUserLabelId(Long appletUserLabelId);
/**
* 平台端获取二级分类
* @author:zhuyajie
* @date:2020/6/15 16:07
* * @param null
*/
List<AssistTempletDTO> getChildTempletList(Long appletBookClassifyId);
}
......@@ -85,4 +85,12 @@ public interface AppletUserBookcaseBiz {
* * @param null
*/
List<Long> getBookcaseIdListByUser(Long wechatUserId);
/**
* 书刊访问量
* @author:zhuyajie
* @date:2020/6/15 11:45
* * @param null
*/
Map<String,Integer> mapBookUserCountList(List<Long> bookIds);
}
......@@ -10,6 +10,7 @@ import com.pcloud.book.applet.dto.AppletUserLabelDTO;
import com.pcloud.book.applet.entity.AppletBookClassify;
import com.pcloud.book.applet.entity.AppletUserLabel;
import com.pcloud.book.applet.entity.AppletUserLabelRelation;
import com.pcloud.book.applet.enums.LabelTypeEnum;
import com.pcloud.book.applet.mapper.AppletUserLabelMapper;
import com.pcloud.book.applet.mapper.AppletUserLabelRelationMapper;
import com.pcloud.book.base.exception.BookBizException;
......@@ -161,7 +162,7 @@ public class AppletBookClassifyBizImpl implements AppletBookClassifyBiz {
return new ArrayList<>();
}
List<AppletUserLabelRelation> appletUserLabelRelations = new ArrayList<>();
Set<Long> LabelIds = new HashSet<>();
Set<Long> labelIds = new HashSet<>();
appletUserLabelDTOS.forEach(e -> {
if (!ListUtils.isEmpty(e.getAppletUserLabelRelations())) {
appletUserLabelRelations.addAll(e.getAppletUserLabelRelations());
......@@ -170,14 +171,26 @@ public class AppletBookClassifyBizImpl implements AppletBookClassifyBiz {
if (ListUtils.isEmpty(appletUserLabelRelations)) {
return appletUserLabelDTOS;
}
LabelIds = appletUserLabelRelations.stream().map(e -> e.getBookLabelId()).collect(Collectors.toSet());
List<Long> templetIds = new ArrayList<>();
for (AppletUserLabelRelation labelRelation : appletUserLabelRelations) {
Integer labelType = labelRelation.getLabelType();
if (labelType.equals(LabelTypeEnum.grade_label.code) || labelType.equals(LabelTypeEnum.subject_label.code)) {
labelIds.add(labelRelation.getBookLabelId());
} else if (labelType.equals(LabelTypeEnum.sceond_templet.code) && !templetIds.contains(labelRelation.getBookLabelId())) {
templetIds.add(labelRelation.getBookLabelId());
}
}
//填充标签名称
fillLabelName(appletUserLabelDTOS, LabelIds);
fillLabelName(appletUserLabelDTOS, labelIds);
fillTempletName(appletUserLabelDTOS, templetIds);
return appletUserLabelDTOS;
}
private void fillLabelName(List<AppletUserLabelDTO> appletUserLabelDTOS, Set<Long> labelIds) {
log.info("填充标签名称");
if (null==labelIds ||labelIds.size()<=0){
return;
}
Map<Long, BookLabel> bookLabelMap = bookLabelDao.getMapByIds(new ArrayList<>(labelIds));
appletUserLabelDTOS.forEach(e -> {
if (ListUtils.isEmpty(e.getAppletUserLabelRelations())) {
......@@ -187,7 +200,26 @@ public class AppletBookClassifyBizImpl implements AppletBookClassifyBiz {
if (!bookLabelMap.containsKey(m.getBookLabelId())) {
return;
}
m.setBookLabelName(bookLabelMap.get(m.getBookLabelId()).getName());
if (m.getLabelType().equals(LabelTypeEnum.grade_label.code) || m.getLabelType().equals(LabelTypeEnum.subject_label.code)) {
m.setBookLabelName(bookLabelMap.get(m.getBookLabelId()).getName());
}
});
});
}
private void fillTempletName(List<AppletUserLabelDTO> appletUserLabelDTOS, List<Long> templetIds){
if (ListUtils.isEmpty(templetIds)){
return;
}
Map<Long, AssistTempletDTO> classifyMap = assistTempletConsr.mapByIds4Classify(templetIds);
appletUserLabelDTOS.forEach(e -> {
if (ListUtils.isEmpty(e.getAppletUserLabelRelations())) {
return;
}
e.getAppletUserLabelRelations().forEach(m -> {
if (classifyMap.containsKey(m.getBookLabelId()) && m.getLabelType().equals(LabelTypeEnum.sceond_templet.code)) {
m.setBookLabelName(classifyMap.get(m.getBookLabelId()).getTempletName());
}
});
});
}
......@@ -232,4 +264,13 @@ public class AppletBookClassifyBizImpl implements AppletBookClassifyBiz {
return relationMapper.getByAppletUserLabelId(appletUserLabelId);
}
@Override
public List<AssistTempletDTO> getChildTempletList(Long appletBookClassifyId) {
List<Long> templetIds = getRelationBookTempletByBookClassify(appletBookClassifyId);
if (ListUtils.isEmpty(templetIds)){
return new ArrayList<>();
}
return assistTempletConsr.getChildTempletList(templetIds);
}
}
......@@ -12,7 +12,7 @@ import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.book.dao.BookRaysClassifyDao;
import com.pcloud.book.book.entity.BookRaysClassify;
import com.pcloud.book.consumer.app.AssistTempletConsr;
import com.pcloud.book.consumer.user.AdviserConsr;
import com.pcloud.book.es.biz.ESBookAndAdviserBiz;
import com.pcloud.book.group.biz.BookGroupBiz;
import com.pcloud.book.group.dto.BookServeDTO;
import com.pcloud.book.group.enums.JoinGroupTypeEnum;
......@@ -33,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -52,8 +53,6 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
@Autowired
private AppletUserBookcaseDao appletUserBookcaseDao;
@Autowired
private AdviserConsr adviserConsr;
@Autowired
private AssistTempletConsr assistTempletConsr;
@Autowired
private BookGroupBiz bookGroupBiz;
......@@ -61,17 +60,22 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
private BookRaysClassifyDao bookRaysClassifyDao;
@Autowired
private RightsSettingBiz rightsSettingBiz;
@Autowired
private ESBookAndAdviserBiz esBookAndAdviserBiz;
@Override
public void addUserBook(AppletUserBookcase appletUserBookcase) {
Long wechatUserId = appletUserBookcase.getWechatUserId();
if (null == appletUserBookcase.getReadType()) {//取书刊第一种阅读方式
if (null == appletUserBookcase.getRightsSettingId()) {//书刊对应的权益
RightsSettingDto rightsSettingDto = rightsSettingBiz.getReadType4Book(wechatUserId, appletUserBookcase.getBookId(), appletUserBookcase.getChannelId(), appletUserBookcase.getAdviserId());
if (null != rightsSettingDto && !ListUtils.isEmpty(rightsSettingDto.getRightsReadTypes())) {
for (RightsReadType rightsReadType : rightsSettingDto.getRightsReadTypes()) {
if (rightsReadType.getRightsCount() > 0) {
appletUserBookcase.setReadType(rightsReadType.getReadType());
break;
appletUserBookcase.setRightsSettingId(rightsSettingDto == null ? null : rightsSettingDto.getId());
if (null == appletUserBookcase.getReadType()) {//取书刊第一种阅读方式
if (null != rightsSettingDto && !ListUtils.isEmpty(rightsSettingDto.getRightsReadTypes())) {
for (RightsReadType rightsReadType : rightsSettingDto.getRightsReadTypes()) {
if (null != rightsReadType && null != rightsReadType.getRightsCount() && rightsReadType.getRightsCount() > 0) {
appletUserBookcase.setReadType(rightsReadType.getReadType());
break;
}
}
}
}
......@@ -80,6 +84,7 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
appletUserBookcaseDao.insert(appletUserBookcase);
JedisClusterUtils.del(AppletConstants.USER_BOOK_CASE + wechatUserId);
JedisClusterUtils.del(AppletConstants.USER_BOOK_CASE_COUNT + wechatUserId);
esBookAndAdviserBiz.updateBookAndAdviserToES(Collections.singletonList(appletUserBookcase.getBookId()));
}
@Override
......@@ -104,6 +109,7 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
return new PageBeanNew<>(currentPage,numPerPage,0,new ArrayList<>());
}
fillTempletName(pageBeanNew.getRecordList());
fillRightsSettingAndResourceCount(pageBeanNew.getRecordList());
JedisClusterUtils.hset2Json(key,field,pageBeanNew.getRecordList());
JedisClusterUtils.set(countKey,String.valueOf(pageBeanNew.getTotalCount()));
JedisClusterUtils.expire(key,60);
......@@ -111,6 +117,30 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
return pageBeanNew;
}
private void fillRightsSettingAndResourceCount(List<AppletUserBookcaseDTO> recordList) {
if (ListUtils.isEmpty(recordList)) {
return;
}
for (AppletUserBookcaseDTO bookcaseDTO : recordList) {
//权益
if (JoinGroupTypeEnum.XIAORUI.getCode().equals(bookcaseDTO.getJoinGroupType()) && null == bookcaseDTO.getRightsSettingId()) {
RightsSettingDto rightsSettingDto = rightsSettingBiz.getRightsSettingByBookId4AppletHome(bookcaseDTO.getBookId(), bookcaseDTO.getAdviserId(), bookcaseDTO.getChannelId());
if (null == rightsSettingDto) {
continue;
}
bookcaseDTO.setRightsSettingId(rightsSettingDto.getId());
bookcaseDTO.setRightsSettingCount(rightsSettingDto.getCount());
ThreadPoolUtils.OTHER_THREAD_POOL.execute(() -> {
appletUserBookcaseDao.updateRightsSettingId(rightsSettingDto.getId(), bookcaseDTO.getBookId(), bookcaseDTO.getAdviserId(), bookcaseDTO.getChannelId());
});
}
//资源数量
List<BookServeDTO> serveDTOList = bookGroupBiz.getBookAndBookGroupServeIds(bookcaseDTO.getAdviserId(), bookcaseDTO.getBookId(), bookcaseDTO.getChannelId());
bookGroupBiz.removeCanNotBuy(serveDTOList);
bookcaseDTO.setResourceCount(serveDTOList.size());
}
}
@Override
public void addUserClickRecord(AppletUserClickRecord appletUserClickRecord) {
appletUserBookcaseDao.insertClickRecord(appletUserClickRecord);
......@@ -229,6 +259,7 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
if (ListUtils.isEmpty(ids)){
return;
}
esBookAndAdviserBiz.updateBookAndAdviserToES(appletUserBookcaseDao.getBookIdsByIds(ids));
appletUserBookcaseDao.deleteByIds(ids);
JedisClusterUtils.del(AppletConstants.USER_BOOK_CASE + wechatUserId);
JedisClusterUtils.del(AppletConstants.USER_BOOK_CASE_COUNT + wechatUserId);
......@@ -269,4 +300,18 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
return appletUserBookcaseDao.getBookcaseIdListByUser(wechatUserId);
}
@Override
public Map<String, Integer> mapBookUserCountList(List<Long> bookIds) {
List<AppletUserBookcaseDTO> list = appletUserBookcaseDao.getBookUserCountList(bookIds);
if (ListUtils.isEmpty(list)) {
return new HashMap<>();
}
Map<String, Integer> map = new HashMap<>();
for (AppletUserBookcaseDTO bookcaseDTO : list) {
String key = bookcaseDTO.getBookId() + "-" + bookcaseDTO.getAdviserId() + "-" + bookcaseDTO.getChannelId();
map.put(key, bookcaseDTO.getBookUserCount());
}
return map;
}
}
......@@ -40,4 +40,8 @@ public class AppletConstants {
* 首页推荐书单列表
*/
public static final String HOME_BOOKLIST = CacheConstant.BOOK+"APPLET:listBooklist4Wechat";
/**
* 书刊资源数量
*/
public static final String BOOK_RESOURCE_COUNT = CacheConstant.BOOK+"APPLET:book_resource_count";
}
......@@ -75,4 +75,25 @@ public interface AppletUserBookcaseDao extends BaseDao<AppletUserBookcase> {
* * @param null
*/
List<Long> getBookcaseIdListByUser(Long wechatUserId);
/**
* 更新书刊对应的权益
* @author:zhuyajie
* @date:2020/6/12 17:25
* * @param null
*/
void updateRightsSettingId(Long rightsSettingId, Long bookId, Long adviserId, Long channelId);
/**
* 书刊访问用户数量
* @author:zhuyajie
* @date:2020/6/15 11:40
* * @param null
*/
List<AppletUserBookcaseDTO> getBookUserCountList(List<Long> bookIds);
/**
* 根据id获取书刊id
* @author:zhuyajie
* @date:2020/6/15 12:40
* * @param null
*/
List<Long> getBookIdsByIds(List<Long> ids);
}
package com.pcloud.book.applet.dao.impl;
import com.pcloud.book.applet.dao.AppletUserBookcaseDao;
import com.pcloud.book.applet.dto.AppletUserBookcaseDTO;
import com.pcloud.book.applet.dto.UserLastBookReDTO;
import com.pcloud.book.applet.entity.AppletUserBookcase;
import com.pcloud.book.applet.entity.AppletUserClickRecord;
......@@ -92,4 +93,26 @@ public class AppletUserBookcaseDaoImpl extends BaseDaoImpl<AppletUserBookcase> i
public List<Long> getBookcaseIdListByUser(Long wechatUserId) {
return getSessionTemplate().selectList(getStatement("getBookcaseIdListByUser"), wechatUserId);
}
@Override
public void updateRightsSettingId(Long rightsSettingId, Long bookId, Long adviserId, Long channelId) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("rightsSettingId",rightsSettingId);
paramMap.put("bookId",bookId);
paramMap.put("adviserId",adviserId);
paramMap.put("channelId",channelId);
getSessionTemplate().update(getStatement("updateRightsSettingId"), paramMap);
}
@Override
public List<AppletUserBookcaseDTO> getBookUserCountList(List<Long> bookIds) {
Map<String, Object> map = new HashMap<>();
map.put("bookIds", bookIds);
return getSessionTemplate().selectList(getStatement("getBookUserCountList"), map);
}
@Override
public List<Long> getBookIdsByIds(List<Long> ids) {
return getSessionTemplate().selectList(getStatement("getBookIdsByIds"), ids);
}
}
......@@ -53,9 +53,9 @@ public class AppletUserBookcaseDTO extends BaseDto {
@ApiModelProperty("二级分类名")
private String secondTempletName;
@ApiModelProperty("社群码类型")
private Integer joinGroupType;
@ApiModelProperty("小睿分类id")
private Integer classifyId;
@ApiModelProperty("isbn")
......@@ -69,4 +69,17 @@ public class AppletUserBookcaseDTO extends BaseDto {
@ApiModelProperty("上下册标签id")
private Long volLabelId;
@ApiModelProperty("社群书id")
private Long bookGroupId;
@ApiModelProperty("有关联社群")
private Boolean hasGroup;
@ApiModelProperty("权益id")
private Long rightsSettingId;
@ApiModelProperty("权益数量")
private Integer rightsSettingCount;
@ApiModelProperty("资源数量")
private Integer resourceCount;
@ApiModelProperty("书刊访问数量")
private Integer bookUserCount;
}
......@@ -23,4 +23,7 @@ public class AppletUserBookcase extends BaseEntity {
@ApiModelProperty("阅读类型")
private Integer readType;
@ApiModelProperty("权益id")
private Long rightsSettingId;
}
package com.pcloud.book.applet.enums;
public enum LabelTypeEnum {
/**
* 1年级标签
*/
grade_label(1),
/**
* 2科目标签
*/
subject_label(2),
/**
* 3二级科目
*/
sceond_templet(3);
public final Integer code;
LabelTypeEnum(Integer code) {
this.code = code;
}
}
package com.pcloud.book.applet.facade;
import com.pcloud.appcenter.assist.dto.AssistTempletDTO;
import com.pcloud.book.applet.biz.AppletBookClassifyBiz;
import com.pcloud.book.applet.dto.AppletBookClassifyDTO;
import com.pcloud.book.applet.dto.AppletBookClassifyRelationDTO;
......@@ -118,4 +119,12 @@ public class AppletBookClassifyFacade {
public ResponseDto<List<AppletBookClassifyDTO>> getAllBookClassifyAndLabel4Wechat(@RequestParam(value = "grayStatus",required = false) String grayStatus){
return new ResponseDto<>(appletBookClassifyBiz.getAllBookClassifyAndLabel(grayStatus));
}
@ApiOperation("平台端获取二级分类")
@GetMapping("getChildTempletList")
public ResponseDto<?> getChildTempletList(@RequestHeader("token") String token, @RequestParam("appletBookClassifyId") Long appletBookClassifyId){
SessionUtil.getToken4Redis(token);
List<AssistTempletDTO> list = appletBookClassifyBiz.getChildTempletList(appletBookClassifyId);
return new ResponseDto<>(list);
}
}
......@@ -12,6 +12,7 @@ import com.pcloud.appcenter.assist.dto.AssistTempletDTO;
import com.pcloud.appcenter.base.exception.AppBizException;
import com.pcloud.book.applet.biz.AppletBookClassifyBiz;
import com.pcloud.book.applet.entity.AppletUserLabelRelation;
import com.pcloud.book.applet.enums.LabelTypeEnum;
import com.pcloud.book.base.enums.BookFreezeEnum;
import com.pcloud.book.base.enums.BookStatusEnum;
import com.pcloud.book.base.enums.BookTypeEnum;
......@@ -2060,6 +2061,7 @@ public class BookBizImpl implements BookBiz {
List<BookDto> bookDtos=new ArrayList<>();
for (ESBookAndAdviser esBookAndAdviser:esBookAndAdvisers){
BookDto bookDto=new BookDto();
BeanUtils.copyProperties(esBookAndAdviser, bookDto);
bookDto.setBookId(esBookAndAdviser.getBookId()==null?null:new Long(esBookAndAdviser.getBookId()));
bookDto.setBookAdviserId(esBookAndAdviser.getBookAdviserId()==null?null:new Long(esBookAndAdviser.getBookAdviserId()));
bookDto.setAdviserId(esBookAndAdviser.getAdviserId()==null?null:new Long(esBookAndAdviser.getAdviserId()));
......@@ -2378,15 +2380,18 @@ public class BookBizImpl implements BookBiz {
}
List<Long> graLabelIds = new ArrayList<>();
List<Long> subLabelIds = new ArrayList<>();
List<Long> scecondTempletIds = new ArrayList<>();
if (!ListUtils.isEmpty(bookSearchParamVO.getAppletUserLabelIdList())) {
Long appletUserLabelId = bookSearchParamVO.getAppletUserLabelIdList().get(0);//先支持一个标签
List<AppletUserLabelRelation> relations = appletBookClassifyBiz.getByAppletUserLabelId(appletUserLabelId);
if (!ListUtils.isEmpty(relations)) {
for (AppletUserLabelRelation relation : relations) {
if (relation.getLabelType() == 1) {
if (relation.getLabelType().equals(LabelTypeEnum.grade_label.code)) {
graLabelIds.add(relation.getBookLabelId());
} else if (relation.getLabelType() == 2) {
} else if (relation.getLabelType().equals(LabelTypeEnum.subject_label.code)) {
subLabelIds.add(relation.getBookLabelId());
} else if (relation.getLabelType().equals(LabelTypeEnum.sceond_templet.code)){
scecondTempletIds.add(relation.getBookLabelId());
}
}
}
......@@ -2395,7 +2400,7 @@ public class BookBizImpl implements BookBiz {
String keyword = bookSearchParamVO.getKeyword();
Integer currentPage = bookSearchParamVO.getCurrentPage();
Integer numPerPage = bookSearchParamVO.getNumPerPage();
Page<ESBookAndAdviser> esPage = esBookAndAdviserBiz.getESAdviserBooks4Applet(grayStatus, keyword, templetIds, graLabelIds, subLabelIds, currentPage, numPerPage);
Page<ESBookAndAdviser> esPage = esBookAndAdviserBiz.getESAdviserBooks4Applet(grayStatus, keyword, templetIds, graLabelIds, subLabelIds, currentPage, numPerPage,scecondTempletIds);
List<ESBookAndAdviser> esBookAndAdvisers = esPage.getContent();
if (ListUtils.isEmpty(esBookAndAdvisers)) {
return new PageBeanNew<>(currentPage,numPerPage,0,new ArrayList<>());
......
package com.pcloud.book.consumer.app;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -97,4 +98,15 @@ public class AssistTempletConsr {
}
return assistTempletDTOs;
}
@ParamLog("查二级分类列表")
public List<AssistTempletDTO> getChildTempletList(List<Long> parentIds){
List<AssistTempletDTO> list = new ArrayList<>();
try {
list = ResponseHandleUtil.parseList(assistTempletService.getChildTempletList(parentIds),AssistTempletDTO.class);
}catch (Exception e){
LOGGER.error("查二级分类列表失败"+e.getMessage(),e);
}
return list;
}
}
......@@ -384,4 +384,16 @@ public class QrcodeSceneConsr {
}
return list;
}
@ParamLog("小程序书刊资源数量")
public Map<String, Integer> mapServeCount4Applet(List<Long> bookIds) {
Map<String, Integer> map = new HashMap<>();
try {
map = ResponseHandleUtil.parseMapResponse(messageService.mapServeCount4Applet(bookIds), String.class, Integer.class);
} catch (Exception e) {
LOGGER.error("调用messageService.mapServeCount4Applet失败" + e.getMessage(), e);
}
return map;
}
}
......@@ -17,7 +17,7 @@ public interface ESBookAndAdviserBiz {
Page<ESBookAndAdviser> getAdviserBooks4ES(String grayStatus, String keyword, Long templetId, Long secondTempletId, Integer currentPage, Integer numPerPage);
Page<ESBookAndAdviser> getESAdviserBooks4Applet(String grayStatus, String keyword, List<Long> templetIds, List<Long> graLabelIds, List<Long> subLabelIds, Integer currentPage, Integer numPerPage);
Page<ESBookAndAdviser> getESAdviserBooks4Applet(String grayStatus, String keyword, List<Long> templetIds, List<Long> graLabelIds, List<Long> subLabelIds, Integer currentPage, Integer numPerPage, List<Long> scecondTempletIds);
void deleteAdviserBooks4ES();
......
package com.pcloud.book.es.biz.impl;
import com.pcloud.book.applet.biz.AppletUserBookcaseBiz;
import com.pcloud.book.book.constant.BookConstant;
import com.pcloud.book.book.dao.BookDao;
import com.pcloud.book.consumer.user.BookcaseConsr;
import com.pcloud.book.consumer.channel.QrcodeSceneConsr;
import com.pcloud.book.es.biz.ESBookAndAdviserBiz;
import com.pcloud.book.es.entity.ESBookAndAdviser;
import com.pcloud.book.es.repository.BookAndAdviserRepository;
import com.pcloud.book.group.biz.BookGroupBiz;
import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.book.util.common.YesOrNoEnums;
import com.pcloud.book.util.properties.BookProps;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.string.StringUtil;
import java.util.Iterator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.index.query.WildcardQueryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -27,9 +27,13 @@ import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
/**
* @Description
* @Author ruansiyuan
......@@ -45,6 +49,12 @@ public class ESBookAndAdviserBizImpl implements ESBookAndAdviserBiz {
private BookDao bookDao;
@Autowired
private BookAndAdviserRepository bookAndAdviserRepository;
@Autowired
private AppletUserBookcaseBiz appletUserBookcaseBiz;
@Autowired
private QrcodeSceneConsr qrcodeSceneConsr;
@Autowired
private BookGroupBiz bookGroupBiz;
@ParamLog("导入全部book和bookAdviser")
@Transactional(rollbackFor = Exception.class)
......@@ -65,6 +75,7 @@ public class ESBookAndAdviserBizImpl implements ESBookAndAdviserBiz {
if (ListUtils.isEmpty(list)) {
break;
}
fillInfo(list,null);
bookAndAdviserRepository.save(list);
maxId = Long.valueOf(list.get(list.size() - 1).getBookId());
index += 1;
......@@ -73,6 +84,29 @@ public class ESBookAndAdviserBizImpl implements ESBookAndAdviserBiz {
});
}
private void fillInfo(List<ESBookAndAdviser> list, List<Long> bookIds){
//书刊访问量
Map<String, Integer> userCountMap = appletUserBookcaseBiz.mapBookUserCountList(bookIds);
//书刊资源数量(二维码)
Map<String, Integer> resourceCountMap = qrcodeSceneConsr.mapServeCount4Applet(bookIds);
//书刊资源数量(社群书)
Map<String, Integer> bookGroupResourceCountMap = bookGroupBiz.mapServeCount4Applet(bookIds);
for (ESBookAndAdviser bookAndAdviser : list){
String key = bookAndAdviser.getBookId() + "-" + bookAndAdviser.getAdviserId() + "-" + bookAndAdviser.getChannelId();
Integer resourceCount=0;
if (!MapUtils.isEmpty(userCountMap) && userCountMap.containsKey(key)){
bookAndAdviser.setBookUserCount(userCountMap.get(key));
}
if (!MapUtils.isEmpty(resourceCountMap) && resourceCountMap.containsKey(key)){
resourceCount = resourceCountMap.get(key);
}
if (!MapUtils.isEmpty(bookGroupResourceCountMap) && bookGroupResourceCountMap.containsKey(key)) {
resourceCount = resourceCount + bookGroupResourceCountMap.get(key);
}
bookAndAdviser.setResourceCount(resourceCount);
}
}
@ParamLog("更新书和编辑书")
@Override
public void updateBookAndAdviserToES(List<Long> bookIds) {
......@@ -82,6 +116,7 @@ public class ESBookAndAdviserBizImpl implements ESBookAndAdviserBiz {
try {
List<ESBookAndAdviser> list = bookDao.findBookAndAdviserByBookIds(bookIds);
filterBooks(list);
fillInfo(list,bookIds);
if (ListUtils.isEmpty(list)){
return;
}
......@@ -147,12 +182,13 @@ public class ESBookAndAdviserBizImpl implements ESBookAndAdviserBiz {
}
@Override
public Page<ESBookAndAdviser> getESAdviserBooks4Applet(String grayStatus, String keyword, List<Long> templetIds, List<Long> graLabelIds, List<Long> subLabelIds, Integer currentPage, Integer numPerPage) {
public Page<ESBookAndAdviser> getESAdviserBooks4Applet(String grayStatus, String keyword, List<Long> templetIds, List<Long> graLabelIds, List<Long> subLabelIds, Integer currentPage, Integer numPerPage, List<Long> scecondTempletIds) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
.filter(QueryBuilders.termQuery("isBookDelete", 0))
.filter(ListUtils.isEmpty(templetIds) ? QueryBuilders.boolQuery() : QueryBuilders.termsQuery("templetId", templetIds))
.filter(ListUtils.isEmpty(graLabelIds) ? QueryBuilders.boolQuery() : QueryBuilders.termsQuery("graLabelId", graLabelIds))
.filter(ListUtils.isEmpty(subLabelIds) ? QueryBuilders.boolQuery() : QueryBuilders.termsQuery("subLabelId", subLabelIds));
.filter(ListUtils.isEmpty(subLabelIds) ? QueryBuilders.boolQuery() : QueryBuilders.termsQuery("subLabelId", subLabelIds))
.filter(ListUtils.isEmpty(scecondTempletIds) ? QueryBuilders.boolQuery() : QueryBuilders.termsQuery("secondTempletId", scecondTempletIds));
BoolQueryBuilder should = QueryBuilders.boolQuery()
.should(StringUtil.isEmpty(keyword) ? QueryBuilders.boolQuery() : QueryBuilders.wildcardQuery("bookName", keyword))
.should(StringUtil.isEmpty(keyword) ? QueryBuilders.boolQuery() : QueryBuilders.wildcardQuery("isbn", "*" + keyword + "*"));
......@@ -183,7 +219,7 @@ public class ESBookAndAdviserBizImpl implements ESBookAndAdviserBiz {
}
boolQueryBuilder.must(should);
boolQueryBuilder.must(should1);
Sort sort = new Sort(Sort.Direction.DESC, "isAdviserBook", "lastModifiedDate", "bookId");
Sort sort = new Sort(Sort.Direction.DESC, "bookUserCount", "resourceCount", "isAdviserBook", "lastModifiedDate", "bookId");
PageRequest pageRequest = new PageRequest(currentPage, numPerPage, sort);
Page<ESBookAndAdviser> search = bookAndAdviserRepository.search(boolQueryBuilder, pageRequest);
return search;
......
package com.pcloud.book.es.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
......@@ -114,5 +116,24 @@ public class ESBookAndAdviser {
* 地域标签id
*/
private Long areaLabelId;
/**
* 上下册标签id
*/
private Long volLabelId;
/**
* 社群书id
*/
private Long bookGroupId;
/**
* 社群书类型
*/
private Integer joinGroupType;
/**
* 书刊访问数量
*/
private Integer bookUserCount;
/**
* 书刊资源数量
*/
private Integer resourceCount;
}
......@@ -827,6 +827,8 @@ public interface BookGroupBiz {
*/
PageBeanNew<BookServeDTO> getBookAndBookGroupServeList(Long adviserId, Long bookId, Long channelId);
void removeCanNotBuy( List<BookServeDTO> list );
/**
* 获取小睿社群书和现代纸书所配资源id
* @param adviserId
......@@ -880,4 +882,19 @@ public interface BookGroupBiz {
* * @param null
*/
PageBeanNew<BookGroupDTO> listSingleBookGroup4Adviser(String name, Integer currentPage, Integer numPerPage, Long adviserId);
/**
* 资源服务类型旧数据处理
* @author:zhuyajie
* @date:2020/6/16 11:09
* * @param null
*/
void updateBookServeTypeCode();
/**
* 小程序书刊资源数量
* @author:zhuyajie
* @date:2020/6/15 18:12
* * @param null
*/
Map<String,Integer> mapServeCount4Applet(List<Long> bookIds);
}
......@@ -3,6 +3,7 @@ package com.pcloud.book.group.dao;
import com.pcloud.book.group.dto.BookGroupCountDTO;
import com.pcloud.book.group.entity.BookGroupApp;
import com.pcloud.book.group.entity.BookGroupServe;
import com.pcloud.book.group.vo.BookGroupServeCountVO;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
......@@ -36,4 +37,27 @@ public interface BookGroupServeDao extends BaseDao<BookGroupServe> {
* @return
*/
List<BookGroupCountDTO> getCountByServeIds(List<Long> serveIds, String serveType, Long adviserId);
/**
* typecode为空的记录-旧数据处理
* @author:zhuyajie
* @date:2020/6/16 11:13
* * @param null
*/
List<BookGroupServe> getTypeCodeNull(String serveType);
/**
* 批量更新
* @author:zhuyajie
* @date:2020/6/16 13:42
* * @param null
*/
void batchUpdate(List<BookGroupServe> bookGroupServeList);
/**
* 书刊资源数量-小程序
* @author:zhuyajie
* @date:2020/6/16 15:23
* * @param null
*/
List<BookGroupServeCountVO> getServeList4Applet(List<Long> bookIds);
}
......@@ -4,7 +4,9 @@ import com.pcloud.book.group.dao.BookGroupServeDao;
import com.pcloud.book.group.dto.BookGroupCountDTO;
import com.pcloud.book.group.entity.BookGroupApp;
import com.pcloud.book.group.entity.BookGroupServe;
import com.pcloud.book.group.vo.BookGroupServeCountVO;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.HashMap;
......@@ -85,4 +87,21 @@ public class BookGroupServeDaoImpl extends BaseDaoImpl<BookGroupServe> implement
map.put("adviserId", adviserId);
return super.getSqlSession().selectList(getStatement("getCountByServeIds"), map);
}
@Override
public List<BookGroupServe> getTypeCodeNull(String serveType) {
return super.getSqlSession().selectList(getStatement("getTypeCodeNull"), serveType);
}
@Override
public void batchUpdate(List<BookGroupServe> bookGroupServeList) {
getSessionTemplate().update(getStatement("batchUpdate"), bookGroupServeList);
}
@Override
public List<BookGroupServeCountVO> getServeList4Applet(List<Long> bookIds) {
Map<String,Object> map = new HashMap<>();
map.put("bookIds", bookIds);
return getSessionTemplate().selectList(getStatement("getServeList4Applet"), map);
}
}
......@@ -64,4 +64,6 @@ public class BookGroupServe extends BaseEntity {
@ApiModelProperty("描述信息")
private String description;
@ApiModelProperty("类型")
private String typeCode;
}
......@@ -749,4 +749,8 @@ public interface BookGroupFacade {
@RequestParam(value = "currentPage", required = true) Integer currentPage,
@RequestParam(value = "numPerPage", required = true) Integer numPerPage)
throws BizException, PermissionException;
@ApiOperation("资源服务类型旧数据处理")
@GetMapping("updateBookServeTypeCode")
ResponseDto<?>updateBookServeTypeCode();
}
......@@ -1215,4 +1215,11 @@ public class BookGroupFacadeImpl implements BookGroupFacade {
return new ResponseDto<>(pageBeanNew);
}
@Override
@GetMapping("updateBookServeTypeCode")
public ResponseDto<?>updateBookServeTypeCode(){
bookGroupBiz.updateBookServeTypeCode();
return new ResponseDto<>();
}
}
package com.pcloud.book.group.vo;
import com.pcloud.common.dto.BaseDto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @ClassName com.pcloud.channelcenter.wechat.vo.BookGroupServeCountVO
* @Author zhuyajie
* @Description 书刊资源数量
* @Date 2020/6/15 17:55
* @Version 1.0
**/
@Data
public class BookGroupServeCountVO extends BaseDto {
@ApiModelProperty("图书标识")
private Long bookId;
@ApiModelProperty("运营标识")
private Long channelId;
@ApiModelProperty("编辑id")
private Long adviserId;
@ApiModelProperty("服务数量")
private Integer serveCount;
}
......@@ -9,18 +9,19 @@
<result column="adviser_id" property="adviserId" jdbcType="BIGINT" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="read_type" property="readType" jdbcType="TINYINT" />
<result column="rights_setting_id" property="rightsSettingId" jdbcType="BIGINT" />
</resultMap>
<sql id="Base_Column_List" >
id, wechat_user_id, book_id, channel_id, adviser_id, create_time,read_type
id, wechat_user_id, book_id, channel_id, adviser_id, create_time,read_type, rights_setting_id
</sql>
<insert id="insert" parameterType="com.pcloud.book.applet.entity.AppletUserBookcase" useGeneratedKeys="true" keyProperty="id">
insert into applet_user_bookcase (
wechat_user_id, book_id, channel_id, adviser_id, create_time, read_type
wechat_user_id, book_id, channel_id, adviser_id, create_time, read_type, rights_setting_id
)
values (
#{wechatUserId}, #{bookId}, #{channelId}, #{adviserId}, NOW(), #{readType}
#{wechatUserId}, #{bookId}, #{channelId}, #{adviserId}, NOW(), #{readType}, #{rightsSettingId}
)
on duplicate key
update
......@@ -41,15 +42,20 @@
a.SECOND_TEMPLET_ID secondTempletId,
a.TEMPLET_ID templetId,
d.join_group_type joinGroupType,
d.id bookGroupId,
b.ISBN isbn,
a.GRA_LABEL_ID gradeLabelId,
a.SUB_LABEL_ID subjectLabelId,
a.vol_label_id volLabelId
a.vol_label_id volLabelId,
IF(d.join_group_type=1 OR d.related_book_group_id>0,1,0) hasGroup,
c.rights_setting_id rightsSettingId,
r.count rightsSettingCount
FROM applet_user_bookcase c
LEFT JOIN BOOK_ADVISER a ON c.book_id=a.BOOK_ID AND c.adviser_id=a.ADVISER_ID
AND c.channel_id=a.CHANNEL_ID AND a.IS_DELETE = 0
INNER JOIN BOOK b ON c.BOOK_ID = b.BOOK_ID AND b.IS_DELETE = 0
LEFT JOIN book_group d ON d.BOOK_ID = a.BOOK_ID and d.create_user=c.adviser_id and d.channel_id=c.channel_id AND d.IS_DELETE = 0
LEFT JOIN rights_setting r ON c.rights_setting_id = r.id AND d.join_group_type=4
WHERE c.wechat_user_id=#{wechatUserId}
ORDER BY c.create_time DESC
</select>
......@@ -187,4 +193,37 @@
WHERE wechat_user_id = #{wechatUserId}
</select>
<update id="updateRightsSettingId" parameterType="com.pcloud.book.applet.entity.AppletUserBookcase">
update
applet_user_bookcase
set
rights_setting_id = #{rightsSettingId}
WHERE
book_id=#{bookId}
AND channel_id=#{channelId}
AND adviser_id=#{adviserId}
</update>
<select id="getBookUserCountList" resultType="com.pcloud.book.applet.dto.AppletUserBookcaseDTO" parameterType="map">
SELECT book_id bookId, adviser_id adviserId, channel_id channelId, COUNT(1) bookUserCount
FROM applet_user_bookcase
WHERE 1=1
<if test="bookIds != null and bookIds.size>0">
AND book_id in
<foreach collection="bookIds" open="(" close=")" separator="," index="index" item="item">
#{item}
</foreach>
</if>
GROUP BY book_id, adviser_id, channel_id
</select>
<select id="getBookIdsByIds" resultType="long" parameterType="list">
SELECT DISTINCT book_id
FROM applet_user_bookcase
WHERE id in
<foreach collection="ids" open="(" close=")" separator="," index="index" item="item">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
......@@ -2281,10 +2281,14 @@
IF(A.GRA_LABEL_ID is NULL, 0, A.GRA_LABEL_ID) graLabelId,
IF(A.SUB_LABEL_ID is NULL, 0, A.SUB_LABEL_ID) subLabelId,
IF(A.AREA_LABEL_ID is NULL, 0, A.AREA_LABEL_ID) areaLabelId,
IF(A.VER_LABEL_ID is NULL, 0, A.VER_LABEL_ID) verLabelId
IF(A.VER_LABEL_ID is NULL, 0, A.VER_LABEL_ID) verLabelId,
IF(A.vol_label_id is NULL, 0, A.vol_label_id) volLabelId,
G.id bookGroupId,
G.join_group_type joinGroupType
FROM
BOOK B
LEFT JOIN BOOK_ADVISER A ON A.BOOK_ID = B.BOOK_ID and A.IS_MAIN_EDITOR=1
LEFT JOIN book_group G on G.BOOK_ID = A.BOOK_ID AND G.CHANNEL_ID = A.CHANNEL_ID AND G.CREATE_USER = A.ADVISER_ID AND G.IS_DELETE = 0
WHERE B.BOOK_ID>#{maxId}
GROUP BY B.BOOK_ID
limit #{offset}
......@@ -2310,10 +2314,14 @@
IF(A.GRA_LABEL_ID is NULL, 0, A.GRA_LABEL_ID) graLabelId,
IF(A.SUB_LABEL_ID is NULL, 0, A.SUB_LABEL_ID) subLabelId,
IF(A.AREA_LABEL_ID is NULL, 0, A.AREA_LABEL_ID) areaLabelId,
IF(A.VER_LABEL_ID is NULL, 0, A.VER_LABEL_ID) verLabelId
IF(A.VER_LABEL_ID is NULL, 0, A.VER_LABEL_ID) verLabelId,
IF(A.vol_label_id is NULL, 0, A.vol_label_id) volLabelId,
G.id bookGroupId,
G.join_group_type joinGroupType
FROM
BOOK B
LEFT JOIN BOOK_ADVISER A ON A.BOOK_ID = B.BOOK_ID and A.IS_MAIN_EDITOR=1
LEFT JOIN book_group G on G.BOOK_ID = A.BOOK_ID AND G.CHANNEL_ID = A.CHANNEL_ID AND G.CREATE_USER = A.ADVISER_ID AND G.IS_DELETE = 0
WHERE B.BOOK_ID in
<foreach collection="bookIds" index="i" item="item" open="(" separator="," close=")">
${item}
......
......@@ -10,11 +10,12 @@
<result column="book_group_id" property="bookGroupId" jdbcType="BIGINT"/>
<result column="create_user" property="createUser" jdbcType="BIGINT"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="type_code" property="typeCode" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id, serve_id, serve_type, serve_url, short_url, book_group_id, create_user, create_time
id, serve_id, serve_type, serve_url, short_url, book_group_id, create_user, create_time, type_code
</sql>
<insert id="insert" parameterType="com.pcloud.book.group.entity.BookGroupServe" useGeneratedKeys="true"
......@@ -27,7 +28,8 @@
short_url,
book_group_id,
create_user,
create_time
create_time,
type_code
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{serveId,jdbcType=BIGINT},
......@@ -36,7 +38,8 @@
#{shortUrl,jdbcType=VARCHAR},
#{bookGroupId,jdbcType=BIGINT},
#{createUser,jdbcType=INTEGER},
NOW()
NOW(),
#{typeCode}
</trim>
</insert>
......@@ -49,7 +52,8 @@
short_url,
book_group_id,
create_user,
create_time
create_time,
type_code
) values
<foreach collection="list" item="item" index="index" separator=",">
(
......@@ -59,7 +63,8 @@
#{item.shortUrl,jdbcType=VARCHAR},
#{item.bookGroupId,jdbcType=BIGINT},
#{item.createUser,jdbcType=INTEGER},
NOW()
NOW(),
#{item.typeCode}
)
</foreach>
</insert>
......@@ -161,4 +166,48 @@
and create_user = #{adviserId}
group by serve_id
</select>
<select id="getTypeCodeNull" parameterType="string" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM book_group_serve
WHERE (type_code IS NULL OR type_code ="")
AND serve_type = #{serveType}
</select>
<update id="batchUpdate" parameterType="list">
update book_group_serve
<trim prefix="set" suffixOverrides=",">
<trim prefix="type_code =case" suffix="end,">
<foreach collection="list" item="item">
<if test="item.typeCode!=null">
when id=#{item.id} then #{item.typeCode}
</if>
</foreach>
</trim>
</trim>
<where>
<foreach collection="list" separator="or" item="item">
id = #{item.id}
</foreach>
</where>
</update>
<select id="getServeList4Applet" parameterType="map" resultType="com.pcloud.book.group.vo.BookGroupServeCountVO">
SELECT
g.book_id bookId,
g.create_user adviserId,
g.channel_id channelId,
COUNT(1) serveCount
FROM book_group_serve s LEFT JOIN book_group g ON s.book_group_id =g.id AND g.is_delete=0
WHERE 1=1
<if test="bookIds != null and bookIds.size>0">
and g.book_id IN
<foreach collection="bookIds" item="bookId" separator="," open="(" close=")">
${bookId}
</foreach>
</if>
AND s.type_code NOT in('INTERACT','MEMBER','ENROLL','QA','TOOL','TUTORIAL','ATTENDANCE_TASK','THIRDPARTY','LINK')
GROUP BY g.book_id,g.create_user,g.channel_id
</select>
</mapper>
\ No newline at end of file
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