Commit e4ebf027 by 朱亚洁

faet:[none]listAppletNews

parent f4b2cf30
package com.pcloud.book.applet.biz.impl;
import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Lists;
import com.pcloud.appcenter.assist.dto.AssistTempletDTO;
import com.pcloud.book.applet.biz.AppletNewsBiz;
import com.pcloud.book.applet.biz.AppletUserBookcaseBiz;
......@@ -43,7 +43,6 @@ import com.pcloud.book.book.entity.BookLabel;
import com.pcloud.book.consumer.app.AssistTempletConsr;
import com.pcloud.book.consumer.label.LabelConsr;
import com.pcloud.book.consumer.reader.ReaderConsr;
import com.pcloud.book.es.entity.ESBookAndAdviser;
import com.pcloud.book.push.dao.PersonalAppletsDao;
import com.pcloud.book.push.entity.PersonalApplets;
import com.pcloud.book.rightsSetting.biz.RightsSettingBiz;
......@@ -52,10 +51,10 @@ import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.NumberUtil;
import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.readercenter.wechat.entity.WechatUser;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -64,7 +63,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
......@@ -73,6 +71,8 @@ import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
/**
* 小程序资讯
*/
......@@ -289,8 +289,11 @@ public class AppletNewsBizImpl implements AppletNewsBiz {
paramMap.put("showState", showState);
paramMap.put("newsClassifyId", newsClassifyId);
paramMap.put("customTagId", customTagId);
//是否有分类筛选
Boolean classifySelect = false;
//处理分类
if (null!=firstClassify){
classifySelect = true;
BaseTempletClassify classify = new BaseTempletClassify();
classify.setFirstClassify(firstClassify);
classify.setSecondClassify(secondClassify);
......@@ -304,17 +307,18 @@ public class AppletNewsBizImpl implements AppletNewsBiz {
}else {
paramMap.put("gradeLabelId", gradeLabelId);
paramMap.put("subjectLabelId", subjectLabelId);
if (null != gradeLabelId || null != subjectLabelId) {
classifySelect = true;
}
}
paramMap.put("classifySelect", classifySelect);
PageBeanNew<AppletNewsDTO> pageBeanNew = appletNewsDao.listPageNew(
new PageParam(currentPage, numPerPage), paramMap, "listAppletNews", "listAppletNewsCount");
if (null == pageBeanNew || ListUtils.isEmpty(pageBeanNew.getRecordList())) {
return new PageBeanNew<>(currentPage, numPerPage, 0, new ArrayList<>());
}
fillLabel(pageBeanNew.getRecordList());
setLabelContent(pageBeanNew.getRecordList());
//填充咨询分类
fillCategory(pageBeanNew.getRecordList());
return pageBeanNew;
}
......@@ -548,41 +552,46 @@ public class AppletNewsBizImpl implements AppletNewsBiz {
}
private void fillCategory(List<AppletNewsDTO> appletNewsDTOList) {
if(ListUtils.isEmpty(appletNewsDTOList)){
if (ListUtils.isEmpty(appletNewsDTOList)) {
return;
}
List<Long> classifyIds = new ArrayList<>();
for (AppletNewsDTO newsDTO : appletNewsDTOList) {
Long newsId = newsDTO.getId();
List<AppletNewsCategoryDTO> newsCategoryDTOList = appletNewsCategoryDao.getByNewsId(newsId);
if (ListUtils.isEmpty(newsCategoryDTOList)) {
continue;
}
List<Long> firstClassifyIds = newsCategoryDTOList.stream().map(AppletNewsCategoryDTO::getFirstClassify)
.collect(
Collectors.toList());
List<Long> secondClassifyIds = newsCategoryDTOList.stream().map(AppletNewsCategoryDTO::getSecondClassify)
.collect(
Collectors.toList());
List<Long> classifyIds = firstClassifyIds;
classifyIds.addAll(secondClassifyIds);
classifyIds.removeAll(Collections.singleton(null));
Map<Long, AssistTempletDTO> classifyMap = assistTempletConsr.mapByIds4Classify(classifyIds);
for (AppletNewsCategoryDTO categoryDTO : newsCategoryDTOList) {
AssistTempletDTO templetDTO = classifyMap.get(categoryDTO.getFirstClassify());
if (templetDTO != null) {
categoryDTO.setFirstClassifyName(templetDTO.getTempletName());
for (AppletNewsCategoryDTO appletNewsCategoryDTO : newsCategoryDTOList) {
if (null != appletNewsCategoryDTO.getFirstClassify() && !classifyIds.contains(appletNewsCategoryDTO.getFirstClassify())) {
classifyIds.add(appletNewsCategoryDTO.getFirstClassify());
}
templetDTO = classifyMap.get(categoryDTO.getSecondClassify());
if (templetDTO != null) {
categoryDTO.setSecondClassifyName(templetDTO.getTempletName());
if (null != appletNewsCategoryDTO.getSecondClassify() && !classifyIds.contains(appletNewsCategoryDTO.getSecondClassify())) {
classifyIds.add(appletNewsCategoryDTO.getSecondClassify());
}
}
newsDTO.setCategoryList(newsCategoryDTOList);
}
Map<Long, AssistTempletDTO> classifyMap = assistTempletConsr.mapByIds4Classify(classifyIds);
if (MapUtils.isEmpty(classifyMap)) {
return;
}
for (AppletNewsDTO newsDTO : appletNewsDTOList) {
if (ListUtils.isEmpty(newsDTO.getCategoryList())){
continue;
}
for (AppletNewsCategoryDTO categoryDTO : newsDTO.getCategoryList()) {
if (null == categoryDTO){
continue;
}
if (classifyMap.containsKey(categoryDTO.getFirstClassify())) {
categoryDTO.setFirstClassifyName(classifyMap.get(categoryDTO.getFirstClassify()).getTempletName());
}
if (classifyMap.containsKey(categoryDTO.getSecondClassify())) {
categoryDTO.setSecondClassifyName(classifyMap.get(categoryDTO.getSecondClassify()).getTempletName());
}
}
}
}
private void fillBusinessCard(AppletNewsDTO appletNewsDTO) {
......
......@@ -159,10 +159,9 @@
<select id="listAppletNewsCount" parameterType="map" resultType="integer">
SELECT count(DISTINCT n.id)
FROM applet_news n
LEFT JOIN applet_news_classify c ON n.news_classify_id=c.id
LEFT JOIN rights_setting_classify d ON n.rights_classify_id = d.id
LEFT JOIN applet_news_custom_tag t ON n.custom_tag_id = t.id
LEFT JOIN applet_news_category category on n.id = category.applet_news_id
<if test="classifySelect == 1">
LEFT JOIN applet_news_category category on n.id = category.applet_news_id
</if>
WHERE 1=1
<if test="name != null">
AND (n.news_name LIKE CONCAT("%",#{name},"%") OR n.url_number LIKE CONCAT("%",#{name},"%"))
......@@ -173,18 +172,6 @@
<if test="showState != null">
AND n.show_state = #{showState}
</if>
<if test="firstClassify!=null">
AND category.first_classify =#{firstClassify}
</if>
<if test="secondClassify!=null">
AND category.second_classify =#{secondClassify}
</if>
<if test="gradeLabelId != null">
AND category.grade_label_id = #{gradeLabelId}
</if>
<if test="subjectLabelId != null">
AND category.subject_label_id = #{subjectLabelId}
</if>
<if test="rightsClassifyId!=null">
AND n.rights_classify_id =#{rightsClassifyId}
</if>
......@@ -194,32 +181,32 @@
<if test="customTagId != null">
AND n.custom_tag_id = #{customTagId}
</if>
ORDER BY n.update_time DESC
<if test="classifySelect == 1">
<if test="firstClassify!=null">
AND category.first_classify =#{firstClassify}
</if>
<if test="secondClassify!=null">
AND category.second_classify =#{secondClassify}
</if>
<if test="gradeLabelId != null">
AND category.grade_label_id = #{gradeLabelId}
</if>
<if test="subjectLabelId != null">
AND category.subject_label_id = #{subjectLabelId}
</if>
</if>
</select>
<select id="listAppletNews" parameterType="map" resultType="com.pcloud.book.applet.dto.AppletNewsDTO">
SELECT DISTINCT
SELECT
n.id,
n.news_name newsName,
n.source,
n.news_classify_id newsClassifyId,
n.pro_label_id proLabelId,
n.dep_label_id depLabelId,
n.pur_label_id purLabelId,
n.type,
n.digest,
n.pic1,
n.pic2,
n.pic3,
n.content,
n.show_state showState,
c.news_classify newsClassify,
n.create_time createTime,
n.update_time updateTime,
n.first_classify firstClassify,
n.second_classify secondClassify,
n.grade_label_id gradeLabelId,
n.subject_label_id subjectLabelId,
n.rights_classify_id rightsClassifyId,
d.classify rightsClassifyContent,
n.jump_type jumpType,
......@@ -227,14 +214,14 @@
n.url_number urlNumber,
n.custom_tag_id customTagId,
t.custom_tag customTag,
n.show_source showSource,
n.show_link showLink,
IF(n.business_card_id is null,2,n.business_card_isOpen) businessCardIsOpen
FROM applet_news n
LEFT JOIN applet_news_classify c ON n.news_classify_id=c.id
LEFT JOIN rights_setting_classify d ON n.rights_classify_id = d.id
LEFT JOIN applet_news_custom_tag t ON n.custom_tag_id = t.id
<if test="classifySelect == 1">
LEFT JOIN applet_news_category category on n.id = category.applet_news_id
</if>
WHERE 1=1
<if test="name != null">
AND (n.news_name LIKE CONCAT("%",#{name},"%") OR n.url_number LIKE CONCAT("%",#{name},"%"))
......@@ -245,18 +232,6 @@
<if test="showState != null">
AND n.show_state = #{showState}
</if>
<if test="firstClassify!=null">
AND category.first_classify =#{firstClassify}
</if>
<if test="secondClassify!=null">
AND category.second_classify =#{secondClassify}
</if>
<if test="gradeLabelId != null">
AND category.grade_label_id = #{gradeLabelId}
</if>
<if test="subjectLabelId != null">
AND category.subject_label_id = #{subjectLabelId}
</if>
<if test="rightsClassifyId!=null">
AND n.rights_classify_id =#{rightsClassifyId}
</if>
......@@ -266,6 +241,21 @@
<if test="customTagId != null">
AND n.custom_tag_id = #{customTagId}
</if>
<if test="classifySelect == 1">
<if test="firstClassify!=null">
AND category.first_classify =#{firstClassify}
</if>
<if test="secondClassify!=null">
AND category.second_classify =#{secondClassify}
</if>
<if test="gradeLabelId != null">
AND category.grade_label_id = #{gradeLabelId}
</if>
<if test="subjectLabelId != null">
AND category.subject_label_id = #{subjectLabelId}
</if>
GROUP BY n.id
</if>
ORDER BY n.update_time DESC
</select>
......
......@@ -66,8 +66,8 @@
label.name gradeLabelName,
label2.name subjectLabelName
from applet_news_category category
LEFT JOIN book_label label ON category.grade_label_id = label.id
LEFT JOIN book_label label2 ON category.subject_label_id = label2.id
LEFT JOIN book_label label ON category.grade_label_id = label.id AND label.type=1
LEFT JOIN book_label label2 ON category.subject_label_id = label2.id AND label2.type=2
where applet_news_id=#{appletNewId}
</select>
......
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