Commit 4c915644 by 高鹏

Merge branch 'feat-zyq-1001743' into 'master'

1001743-增加早晚报推送规则

See merge request rays/pcloud-book!201
parents 3419f6da c71de252
......@@ -2,12 +2,31 @@ package com.pcloud.book.adnews.biz.impl;
import com.pcloud.book.adnews.biz.AdNewsBiz;
import com.pcloud.book.adnews.check.AdNewsCheck;
import com.pcloud.book.adnews.dao.*;
import com.pcloud.book.adnews.entity.*;
import com.pcloud.book.adnews.dao.AdNewsBanDao;
import com.pcloud.book.adnews.dao.AdNewsChooseDao;
import com.pcloud.book.adnews.dao.AdNewsClickRecordDao;
import com.pcloud.book.adnews.dao.AdNewsDao;
import com.pcloud.book.adnews.dao.AdNewsGroupDao;
import com.pcloud.book.adnews.dao.AdNewsGroupRecordDao;
import com.pcloud.book.adnews.dao.AdNewsMessageStatisticDao;
import com.pcloud.book.adnews.dao.AdNewsSetDao;
import com.pcloud.book.adnews.dao.AdNewsWechatChooseDao;
import com.pcloud.book.adnews.dao.AdNewsWechatDao;
import com.pcloud.book.adnews.entity.AdNews;
import com.pcloud.book.adnews.entity.AdNewsBan;
import com.pcloud.book.adnews.entity.AdNewsChoose;
import com.pcloud.book.adnews.entity.AdNewsClickRecord;
import com.pcloud.book.adnews.entity.AdNewsGroup;
import com.pcloud.book.adnews.entity.AdNewsGroupRecord;
import com.pcloud.book.adnews.entity.AdNewsMessageStatistic;
import com.pcloud.book.adnews.entity.AdNewsSet;
import com.pcloud.book.adnews.entity.AdNewsWechat;
import com.pcloud.book.adnews.entity.AdNewsWechatChoose;
import com.pcloud.book.adnews.enums.AdContentFromEnum;
import com.pcloud.book.adnews.enums.AdNewsBanEnum;
import com.pcloud.book.adnews.dto.AdNewsListParam;
import com.pcloud.book.adnews.enums.AdNewsContentTypeEnum;
import com.pcloud.book.adnews.enums.AdNewsSendRuleEnum;
import com.pcloud.book.adnews.vo.AdNewsGroupRecordVO;
import com.pcloud.book.adnews.vo.AdNewsMessageStatisticVO;
import com.pcloud.book.base.exception.BookBizException;
......@@ -89,6 +108,9 @@ public class AdNewsBizImpl implements AdNewsBiz {
private static final String AD_EVENING_NEWS_SCHEDULE_PRE = "AD_EVENING_NEWS_SCHEDULE_";
// 发送消息的长度限制
private static final Integer SEND_MESSAGE_LENGTH=1000;
@Value("${wechat.group.link.prefix}")
private String wechatGroupLinkPrefix;
......@@ -237,30 +259,19 @@ public class AdNewsBizImpl implements AdNewsBiz {
AdNewsMessageStatistic adNewsMessageStatistic;
if (adNewsSet.getContentFrom() == AdContentFromEnum.WECHAT.key) {
// 填充要发送的早晚报
setPushAdNewsList(adNewsSet,groupQrcodeFoAdDTOS);
// 查询要发的记录
List<AdNews> adNewsList = null;
adNewsList = adNewsDao.getNewsToSendBySetIdAndAdviser4Own(adNewsSetId, adNewsSet.getCreateUser(), adNewsSet.getSendCount());
// 如果自有公众号的数据为空,则查询系统推荐公众号数据
if (ListUtils.isEmpty(adNewsList)) {
adNewsList = adNewsDao.getNewsToSendBySetIdAndAdviser(adNewsSetId, adNewsSet.getCreateUser(), adNewsSet.getSendCount());
}else if (adNewsList.size() < adNewsSet.getSendCount()) {
// 如果自有公众号的数据条数少于要发送的条数,则用系统推荐公众号的补齐剩余的条数
List<AdNews> _adNewsList = adNewsDao.getNewsToSendBySetIdAndAdviser(adNewsSetId, adNewsSet.getCreateUser(), adNewsSet.getSendCount()-adNewsList.size());
if(!ListUtils.isEmpty(_adNewsList)){
adNewsList.addAll(_adNewsList);
}
// 构建早晚报发送记录对象
for (GroupQrcodeFoAdDTO groupQrcodeFoAdDTO : groupQrcodeFoAdDTOS) {
if (ListUtils.isEmpty(groupQrcodeFoAdDTO.getAdNewsList())) {
LOGGER.info("BookGroupId:"+ groupQrcodeFoAdDTO.getBookGroupId() + " 没有可供发送的早晚报!");
continue;
}
if (ListUtils.isEmpty(adNewsList)) {
LOGGER.info("记录为空,没有可供发送的早晚报!");
return;
}
this.replaceUnescaped(groupQrcodeFoAdDTO.getAdNewsList());
// 构建记录对象
for (GroupQrcodeFoAdDTO groupQrcodeFoAdDTO : groupQrcodeFoAdDTOS) {
for (AdNews adNews : adNewsList) {
for (AdNews adNews : groupQrcodeFoAdDTO.getAdNewsList()) {
adNewsGroupRecord = new AdNewsGroupRecord();
adNewsGroupRecord.setAdNewsId(adNews.getId());
adNewsGroupRecord.setAdNewsSetId(adNewsSetId);
......@@ -280,14 +291,15 @@ public class AdNewsBizImpl implements AdNewsBiz {
adNewsMessageStatistic.setClassifyId(groupQrcodeFoAdDTO.getClassifyId());
adNewsMessageStatistic.setQrcodeId(groupQrcodeFoAdDTO.getQrcodeId());
adNewsMessageStatistic.setCreateUser(adNewsSet.getCreateUser());
adNewsMessageStatistic.setMessageCount(adNewsList.size());
adNewsMessageStatistic.setMessageCount(groupQrcodeFoAdDTO.getAdNewsList().size());
adNewsMessageStatistic.setInsertMark(groupQrcodeFoAdDTOS.indexOf(groupQrcodeFoAdDTO));
adNewsMessageStatistics.add(adNewsMessageStatistic);
}
// 因为拼短链接需要主键,所以需要先入库拿到主键后然后拼接Url,最后再发送微信消息;
// 记录入库
this.insertRecord(adNewsGroupRecords, adNewsMessageStatistics);
int flag = this.insertRecord(adNewsGroupRecords, adNewsMessageStatistics);
if(flag == 0){ return; }
// 拼接中转链接
String transferUrl;
......@@ -299,7 +311,7 @@ public class AdNewsBizImpl implements AdNewsBiz {
// 获取对应当前群的记录详情
if (groupQrcodeFoAdDTO.getQrcodeId() == item.getQrcodeId()) {
// 将对应当前群里的需要发送的新闻链接拼接完成
adNews = adNewsList.stream().filter(x -> x.getId() == item.getAdNewsId()).findFirst().get();
adNews = groupQrcodeFoAdDTO.getAdNewsList().stream().filter(x -> x.getId() == item.getAdNewsId()).findFirst().get();
transferUrl = wechatGroupLinkPrefix
.concat("/link")
.concat("?message_statistic_id=").concat(item.getMessageStatisticId().toString())
......@@ -308,8 +320,8 @@ public class AdNewsBizImpl implements AdNewsBiz {
adNews.setShortUrl(UrlUtils.getShortUrl4Own(transferUrl));
}
}
// 将多条需要发送的早晚报拼接成300字符一组的消息
contents = this.concatContent(adNewsList);
// 将多条需要发送的早晚报拼接成小于字数限制一组的消息
contents = this.concatContent(groupQrcodeFoAdDTO.getAdNewsList());
// 将对应群的消息发送出去
this.sendAdNewsToWechatGroup(adNewsSet, new ArrayList<GroupQrcodeFoAdDTO>() {{
add(groupQrcodeFoAdDTO);
......@@ -359,19 +371,157 @@ public class AdNewsBizImpl implements AdNewsBiz {
}
}
// 设置群标签名称
private void setGroupLabelName(List<GroupQrcodeFoAdDTO> groupQrcodeFoAdDTOS) {
List<Long> labelIds = new ArrayList<>();
for (GroupQrcodeFoAdDTO item : groupQrcodeFoAdDTOS) {
if (item.getProLabelId() != null) {
labelIds.add(item.getProLabelId());
}
if (item.getDepLabelId() != null) {
labelIds.add(item.getDepLabelId());
}
if (item.getPurLabelId() != null) {
labelIds.add(item.getPurLabelId());
}
}
Map<Long, String> labelMap = new HashMap<>();
if (!ListUtils.isEmpty(labelIds)) {
labelMap = ResponseHandleUtil.parseMap(labelService.getLabelName(labelIds), Long.class, String.class);
}
if (!MapUtils.isEmpty(labelMap)) {
for (GroupQrcodeFoAdDTO item : groupQrcodeFoAdDTOS) {
if (item.getProLabelId() != null) {
item.setProLabelName(labelMap.get(item.getProLabelId()));
}
if (item.getDepLabelId() != null) {
item.setDepLabelName(labelMap.get(item.getDepLabelId()));
}
if (item.getPurLabelId() != null) {
item.setPurLabelName(labelMap.get(item.getPurLabelId()));
}
}
}
}
/**
* 根据规则获取推送的新闻
*
* 规则:优先推送自有公众号的内容,如果自有公众号的内容不够,再从公共库里进行挑选;
* 公共库需要用群的标签匹配新闻的标题,如果匹配不到再进行公众号的名称匹配,如果还是没有,最后则直接推送最新入库的数据
*
* @param adNewsSet
* @param groupQrcodeFoAdDTOS
* @return
*/
private void setPushAdNewsList(AdNewsSet adNewsSet,List<GroupQrcodeFoAdDTO> groupQrcodeFoAdDTOS) {
// 获取自有公众号的新闻
List<AdNews> adNewsList = adNewsDao.getNewsToSendBySetIdAndAdviser4Own(adNewsSet.getId(), adNewsSet.getCreateUser(), adNewsSet.getSendCount());
if(ListUtils.isEmpty(adNewsList)){
adNewsList = new ArrayList<>();
}
// 初始化 groupQrcodeFoAdDTOS.adNewsList
for (GroupQrcodeFoAdDTO groupQrcodeFoAdDTO : groupQrcodeFoAdDTOS)
{
groupQrcodeFoAdDTO.setAdNewsList(adNewsList.stream().collect(Collectors.toList()));
}
// 如果自有公众号的数据条数少于要发送的条数,则用系统推荐公众号的补齐剩余的条数
if(adNewsList.size() < adNewsSet.getSendCount()){
List<AdNews> _adNewsList = new ArrayList<>();
if(AdNewsSendRuleEnum.MATCH_LABEL.key == adNewsSet.getSendRule()){
// 根据群批量查找社群码的标签
setGroupLabelName(groupQrcodeFoAdDTOS);
// 标签去重进行匹配新闻
List<Long> bookGroupIds = groupQrcodeFoAdDTOS.stream().map(x -> x.getBookGroupId()).distinct().collect(Collectors.toList());
// 三天前
String beginTime = DateUtils.formatDate(DateUtils.subDays(3), DateUtils.DATE_FORMAT_DATEONLY);
for (GroupQrcodeFoAdDTO groupQrcodeFoAdDTO : groupQrcodeFoAdDTOS){
_adNewsList = adNewsDao.getNewsByLabelName(adNewsSet.getId(), adNewsSet.getCreateUser(), beginTime, groupQrcodeFoAdDTO.getProLabelName(),groupQrcodeFoAdDTO.getDepLabelName(),groupQrcodeFoAdDTO.getPurLabelName(),adNewsSet.getSendCount() - groupQrcodeFoAdDTO.getAdNewsList().size());
if(!ListUtils.isEmpty(_adNewsList)){
groupQrcodeFoAdDTO.getAdNewsList().addAll(_adNewsList);
}
// 如果筛选新闻条数还不够,继续再公众号匹配
if(groupQrcodeFoAdDTO.getAdNewsList().size() < adNewsSet.getSendCount()) {
_adNewsList = adNewsDao.getNews4WechatByLabelName(adNewsSet.getId(), adNewsSet.getCreateUser(), beginTime, groupQrcodeFoAdDTO.getProLabelName(),groupQrcodeFoAdDTO.getDepLabelName(),groupQrcodeFoAdDTO.getPurLabelName(),adNewsSet.getSendCount() - groupQrcodeFoAdDTO.getAdNewsList().size());
if(!ListUtils.isEmpty(_adNewsList)){
groupQrcodeFoAdDTO.getAdNewsList().addAll(_adNewsList);
}
}
// 继续筛选新闻条数不够的群,根据时间排序补齐剩余
if(groupQrcodeFoAdDTO.getAdNewsList().size() < adNewsSet.getSendCount()) {
_adNewsList = adNewsDao.getNewsToSendBySetIdAndAdviser(adNewsSet.getId(), adNewsSet.getCreateUser(), adNewsSet.getSendCount() - groupQrcodeFoAdDTO.getAdNewsList().size());
if (!ListUtils.isEmpty(_adNewsList)) {
groupQrcodeFoAdDTO.getAdNewsList().addAll(_adNewsList);
}
}
}
}else {
// 直接用最新数据补齐剩余条数
_adNewsList = adNewsDao.getNewsToSendBySetIdAndAdviser(adNewsSet.getId(), adNewsSet.getCreateUser(), adNewsSet.getSendCount() - adNewsList.size());
if (!ListUtils.isEmpty(_adNewsList)) {
for (GroupQrcodeFoAdDTO groupQrcodeFoAdDTO : groupQrcodeFoAdDTOS)
{
groupQrcodeFoAdDTO.getAdNewsList().addAll(_adNewsList);
}
}
}
}
}
/**
* 替换转义符
* @param adNewsList
*/
private void replaceUnescaped(List<AdNews> adNewsList) {
for (AdNews adNews : adNewsList) {
if (!StringUtil.isEmpty(adNews.getTitle())) {
adNews.setTitle(adNews.getTitle()
.replaceAll("&amp;quot;", "\"")
.replaceAll("&nbsp;", " "));
}
}
}
/**
* 替换转义符
* @param adNewsGroupRecordVOS
*/
private void replaceUnescaped4Record(List<AdNewsGroupRecordVO> adNewsGroupRecordVOS) {
for (AdNewsGroupRecordVO adNewsGroupRecordVO : adNewsGroupRecordVOS) {
if (!StringUtil.isEmpty(adNewsGroupRecordVO.getTitle())) {
adNewsGroupRecordVO.setTitle(adNewsGroupRecordVO.getTitle()
.replaceAll("&amp;quot;", "\"")
.replaceAll("&nbsp;", " "));
}
}
}
/**
* 将发送记录入库
*
* @param adNewsGroupRecords
* @param adNewsMessageStatistics
*/
private void insertRecord(List<AdNewsGroupRecord> adNewsGroupRecords, List<AdNewsMessageStatistic> adNewsMessageStatistics) {
private int insertRecord(List<AdNewsGroupRecord> adNewsGroupRecords, List<AdNewsMessageStatistic> adNewsMessageStatistics) {
if(ListUtils.isEmpty(adNewsGroupRecords) || ListUtils.isEmpty(adNewsMessageStatistics)){
LOGGER.info("没有可入库的数据,没有可供发送的早晚报内容");
return 0;
}
adNewsMessageStatisticDao.batchInsert(adNewsMessageStatistics);
// 将主键赋值给从表外键;(不会mybatis的主从表批量插入,所以只能这么做)
for (AdNewsMessageStatistic item : adNewsMessageStatistics) {
adNewsGroupRecords.stream().filter(x -> x.getInsertMark() == item.getInsertMark()).forEach(x -> x.setMessageStatisticId(item.getId()));
}
adNewsGroupRecordDao.batchInsert(adNewsGroupRecords);
return 1;
}
/**
......@@ -396,7 +546,23 @@ public class AdNewsBizImpl implements AdNewsBiz {
String robotId = wechatGroupConsr.getRobotIdByGroupId(weixinGroupId);
if (StringUtil.isEmpty(robotId)) {
LOGGER.info("发送编辑端早晚报未找到小号" + weixinGroupId);
continue;
}
// 如果正文内容的长度小于1,说明文字少于限制数,那么就可以合并发送
if(contents.size()==1){
String temp = contents.get(0);
if (!StringUtil.isEmpty(startContent)) { temp = startContent.concat("\n\n").concat(temp); }
if (!StringUtil.isEmpty(endContent)) { temp = temp.concat("\n").concat(endContent); }
// 合并后的字数长度小于限制则发送
if(temp.length() <= SEND_MESSAGE_LENGTH){
// 直接发送合并后的消息
sendAdNewsText(temp, robotId, weixinGroupId);
continue;
}
}
if (!StringUtil.isEmpty(startContent)) {
//发送开场语
sendAdNewsText(startContent, robotId, weixinGroupId);
......@@ -432,10 +598,10 @@ public class AdNewsBizImpl implements AdNewsBiz {
}
/**
* 将内容拼接为300字符一条数据项的数组【微信目前单次消息发送字符长度为300
* 将内容拼接为 SEND_MESSAGE_LENGTH 字符一条数据项的数组【微信目前单次消息发送字符长度存在字数限制
* 拼接内容大致为
* 1.xxxxxxxxxxx 2.xxxxxxxxxx 3.xxxxxxxx 【假设此条数据加下一条数据【4.xxx】 就大于300字符,那就先将之前的存一条到数组】
* 4.xxxxx 5.xxxxxxx 【多余300字符再重新拼接,以此循环下去】
* 1.xxxxxxxxxxx 2.xxxxxxxxxx 3.xxxxxxxx 【假设此条数据加下一条数据【4.xxx】 就大于限制数,那就先将之前的存一条到数组】
* 4.xxxxx 5.xxxxxxx 【多余限制数的字符再重新拼接,以此循环下去】
*
* @param adNewsList
* @return
......@@ -446,8 +612,8 @@ public class AdNewsBizImpl implements AdNewsBiz {
int i = 1;
for (AdNews adNews : adNewsList) {
String temp = content + i + "." + adNews.getTitle() + adNews.getShortUrl() + "\n";
if (temp.length() >= 1000) {
// 如果本次拼接后的长度大于 300,那么将之前拼接的内容存入数组
if (temp.length() >= SEND_MESSAGE_LENGTH) {
// 如果本次拼接后的长度大于限制数,那么将之前拼接的内容存入数组
contents.add(content);
// 重置 content 的内容
content = i + "." + adNews.getTitle() + adNews.getShortUrl() + "\n";
......@@ -524,6 +690,7 @@ public class AdNewsBizImpl implements AdNewsBiz {
map.put("adNewsWechatIds", adNewsListParam.getAdNewsWechatIds());
map.put("contentFrom", adNewsListParam.getContentFrom());
PageBeanNew<AdNews> pageBeanNew = adNewsDao.listPageNew(pageParam, map, "getAdNewsList");
this.replaceUnescaped(pageBeanNew.getRecordList());
return pageBeanNew;
}
......@@ -725,7 +892,9 @@ public class AdNewsBizImpl implements AdNewsBiz {
@Override
@ParamLog("查询早晚报发送详情")
public List<AdNewsGroupRecordVO> getAdNewsGroupRecord(Long partyId, Long messageStatisticId) {
return adNewsGroupRecordDao.getAdNewsGroupRecord(partyId, messageStatisticId);
List<AdNewsGroupRecordVO> adNewsGroupRecordVOS= adNewsGroupRecordDao.getAdNewsGroupRecord(partyId, messageStatisticId);
this.replaceUnescaped4Record(adNewsGroupRecordVOS);
return adNewsGroupRecordVOS;
}
@Override
......
......@@ -17,4 +17,30 @@ public interface AdNewsDao extends BaseDao<AdNews> {
* @return
*/
List<AdNews> getNewsToSendBySetIdAndAdviser4Own(Long adNewsSetId, Long adviserId, Integer top);
/**
* 根据标签匹配新闻————新闻标题
* @param adNewsSetId
* @param adviserId
* @param beginTime
* @param proLabelName
* @param depLabelName
* @param purLabelName
* @param top
* @return
*/
List<AdNews> getNewsByLabelName(Long adNewsSetId, Long adviserId, String beginTime, String proLabelName, String depLabelName, String purLabelName, Integer top);
/**
* 根据标签匹配新闻————公众号名称
* @param adNewsSetId
* @param adviserId
* @param beginTime
* @param proLabelName
* @param depLabelName
* @param purLabelName
* @param top
* @return
*/
List<AdNews> getNews4WechatByLabelName(Long adNewsSetId, Long adviserId, String beginTime, String proLabelName, String depLabelName, String purLabelName, Integer top);
}
......@@ -33,4 +33,30 @@ public class AdNewsDaoImpl extends BaseDaoImpl<AdNews> implements AdNewsDao {
map.put("top", top);
return super.getSqlSession().selectList(getStatement("getNewsToSendBySetIdAndAdviser4Own"), map);
}
@Override
public List<AdNews> getNewsByLabelName(Long adNewsSetId, Long adviserId, String beginTime, String proLabelName, String depLabelName, String purLabelName, Integer top) {
Map<String, Object> map = new HashMap<>();
map.put("adNewsSetId", adNewsSetId);
map.put("adviserId", adviserId);
map.put("beginTime", beginTime);
map.put("proLabelName", proLabelName);
map.put("depLabelName", depLabelName);
map.put("purLabelName", purLabelName);
map.put("top", top);
return super.getSqlSession().selectList(getStatement("getNewsByLabelName"), map);
}
@Override
public List<AdNews> getNews4WechatByLabelName(Long adNewsSetId, Long adviserId,String beginTime, String proLabelName, String depLabelName, String purLabelName, Integer top) {
Map<String, Object> map = new HashMap<>();
map.put("adNewsSetId", adNewsSetId);
map.put("adviserId", adviserId);
map.put("beginTime", beginTime);
map.put("proLabelName", proLabelName);
map.put("depLabelName", depLabelName);
map.put("purLabelName", purLabelName);
map.put("top", top);
return super.getSqlSession().selectList(getStatement("getNews4WechatByLabelName"), map);
}
}
......@@ -33,6 +33,9 @@ public class AdNewsSet extends BaseEntity {
@ApiModelProperty("发送次数")
private Integer sendCount;
@ApiModelProperty("发送规则")
private Integer sendRule;
@ApiModelProperty("开场语")
private String startContent;
......
package com.pcloud.book.adnews.enums;
/**
* @author zhengyongqiang
* @date 2019/10/9 9:39
*/
public enum AdNewsSendRuleEnum {
LAST_UPDATE(0, "最近更新"),
MATCH_LABEL(1, "匹配标签");
public final Integer key;
public final String description;
AdNewsSendRuleEnum(Integer key, String description) {
this.key = key;
this.description = description;
}
public static String getDescriptionByKey(Integer key) {
AdNewsSendRuleEnum[] var1 = values();
int var2 = var1.length;
for (int var3 = 0; var3 < var2; ++var3) {
AdNewsSendRuleEnum methodEnum = var1[var3];
if (methodEnum.key.equals(key)) {
return methodEnum.description;
}
}
return null;
}
}
package com.pcloud.book.group.dto;
import com.pcloud.book.adnews.entity.AdNews;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/7/18 15:09
**/
@Data
public class GroupQrcodeFoAdDTO implements Serializable {
private static final long serialVersionUID = 7018070035247234809L;
......@@ -18,45 +23,25 @@ public class GroupQrcodeFoAdDTO implements Serializable {
private String weixinGroupId;
public Long getQrcodeId() {
return qrcodeId;
}
public void setQrcodeId(Long qrcodeId) {
this.qrcodeId = qrcodeId;
}
public Long getClassifyId() {
return classifyId;
}
public void setClassifyId(Long classifyId) {
this.classifyId = classifyId;
}
public Long getBookGroupId() {
return bookGroupId;
}
public void setBookGroupId(Long bookGroupId) {
this.bookGroupId = bookGroupId;
}
public String getWeixinGroupId() {
return weixinGroupId;
}
public void setWeixinGroupId(String weixinGroupId) {
this.weixinGroupId = weixinGroupId;
}
@Override
public String toString() {
return "GroupQrcodeFoAdDTO{" +
"qrcodeId=" + qrcodeId +
", classifyId=" + classifyId +
", bookGroupId=" + bookGroupId +
", weixinGroupId='" + weixinGroupId + '\'' +
'}';
}
// 专业id
private Long proLabelId;
// 深度id
private Long depLabelId;
// 目的id
private Long purLabelId;
// 专业
private String proLabelName;
// 深度
private String depLabelName;
// 目的
private String purLabelName;
// 需要发送的早晚报
private List<AdNews> adNewsList;
}
......@@ -120,7 +120,7 @@
NOT EXISTS ( SELECT 1 FROM ad_news_ban e WHERE a.id = e.ad_news_id AND e.adviser_id = c.adviser_id )
AND NOT EXISTS (SELECT 1 from ad_news_group_record f WHERE f.ad_news_id=a.id and f.ad_news_set_id=#{adNewsSetId})
ORDER BY
a.id DESC
a.create_time DESC
LIMIT #{top}
</select>
......@@ -139,7 +139,55 @@
NOT EXISTS ( SELECT 1 FROM ad_news_ban e WHERE a.id = e.ad_news_id AND e.adviser_id = #{adviserId} )
AND NOT EXISTS (SELECT 1 from ad_news_group_record f WHERE f.ad_news_id=a.id and f.ad_news_set_id=#{adNewsSetId})
ORDER BY
a.id DESC
a.create_time DESC
LIMIT #{top}
</select>
<!--查找要发送的新闻(新闻标题匹配标签)-->
<!--
1、ad_news_ban 排除掉禁止发送的
2、ad_news_group_record 排除掉已发送的
-->
<select id="getNewsByLabelName" parameterType="map" resultMap="BaseResultMap">
SELECT
a.id, a.type, a.news_from, a.title, a.publisher, a.url, a.short_url, a.news_date, a.create_time,0 content_from
FROM
ad_news a
INNER JOIN ad_news_wechat b ON a.news_from = b.news_from AND b.is_delete = 0
INNER JOIN ad_news_wechat_choose c ON c.ad_news_wechat_id = b.id AND c.is_delete = 0 AND c.adviser_id = #{adviserId}
WHERE
NOT EXISTS ( SELECT 1 FROM ad_news_ban e WHERE a.id = e.ad_news_id AND e.adviser_id = c.adviser_id )
AND NOT EXISTS (SELECT 1 from ad_news_group_record f WHERE f.ad_news_id=a.id and f.ad_news_set_id=#{adNewsSetId})
AND a.create_time >= #{beginTime}
AND (a.title LIKE CONCAT('%', #{proLabelName},'%')
OR a.title LIKE CONCAT('%', #{depLabelName},'%')
OR a.title LIKE CONCAT('%', #{purLabelName},'%'))
ORDER BY
a.create_time DESC
LIMIT #{top}
</select>
<!--查找要发送的新闻(公众号名称匹配标签)-->
<!--
1、ad_news_ban 排除掉禁止发送的
2、ad_news_group_record 排除掉已发送的
-->
<select id="getNews4WechatByLabelName" parameterType="map" resultMap="BaseResultMap">
SELECT
a.id, a.type, a.news_from, a.title, a.publisher, a.url, a.short_url, a.news_date, a.create_time,0 content_from
FROM
ad_news a
INNER JOIN ad_news_wechat b ON a.news_from = b.news_from AND b.is_delete = 0
INNER JOIN ad_news_wechat_choose c ON c.ad_news_wechat_id = b.id AND c.is_delete = 0 AND c.adviser_id = #{adviserId}
WHERE
NOT EXISTS ( SELECT 1 FROM ad_news_ban e WHERE a.id = e.ad_news_id AND e.adviser_id = c.adviser_id )
AND NOT EXISTS (SELECT 1 from ad_news_group_record f WHERE f.ad_news_id=a.id and f.ad_news_set_id=#{adNewsSetId})
AND a.create_time >= #{beginTime}
AND (b.wechat_name LIKE CONCAT('%', #{proLabelName},'%')
OR b.wechat_name LIKE CONCAT('%', #{depLabelName},'%')
OR b.wechat_name LIKE CONCAT('%', #{purLabelName},'%'))
ORDER BY
a.create_time DESC
LIMIT #{top}
</select>
......@@ -180,10 +228,10 @@
AND a.title like concat('%', #{title},'%')
</if>
<if test="beginTime!=null">
AND a.news_date <![CDATA[>=]]> #{beginTime}
AND a.create_time <![CDATA[>=]]> #{beginTime}
</if>
<if test="endTime!=null">
AND a.news_date<![CDATA[<=]]> #{endTime}
AND a.create_time<![CDATA[<=]]> #{endTime}
</if>
<if test="hasBan==0">
AND NOT EXISTS (SELECT 1 FROM ad_news_ban WHERE ad_news_id=a.id and adviser_id=#{partyId} LIMIT 1)
......@@ -197,6 +245,7 @@
<if test="hasUsed==1">
AND EXISTS (SELECT 1 FROM ad_news_group_record WHERE ad_news_id=a.id and create_user=#{partyId} LIMIT 1)
</if>
ORDER BY a.create_time DESC,a.id DESC
</select>
<!--获取编辑选择的素材-->
......
......@@ -8,6 +8,7 @@
<result column="has_morning_open" property="hasMorningOpen" jdbcType="BOOLEAN"/>
<result column="has_evening_open" property="hasEveningOpen" jdbcType="BOOLEAN"/>
<result column="send_count" property="sendCount" jdbcType="INTEGER"/>
<result column="send_rule" property="sendRule" jdbcType="INTEGER"/>
<result column="start_content" property="startContent" jdbcType="VARCHAR"/>
<result column="end_content" property="endContent" jdbcType="VARCHAR"/>
<result column="has_start_content" property="hasStartContent" jdbcType="BOOLEAN"/>
......@@ -22,7 +23,7 @@
</resultMap>
<sql id="Base_Column_List">
id, morning_time, evening_time, has_morning_open, has_evening_open, send_count, start_content,
id, morning_time, evening_time, has_morning_open, has_evening_open, send_count,send_rule, start_content,
end_content, has_start_content, has_end_content, create_user, create_time, update_user, update_time
,content_from,morning_content,evening_content
</sql>
......@@ -42,6 +43,7 @@
has_morning_open,
has_evening_open,
send_count,
send_rule,
start_content,
end_content,
has_start_content,
......@@ -60,6 +62,7 @@
#{hasMorningOpen,jdbcType=BOOLEAN},
#{hasEveningOpen,jdbcType=BOOLEAN},
#{sendCount,jdbcType=INTEGER},
#{sendRule,jdbcType=INTEGER},
#{startContent,jdbcType=VARCHAR},
#{endContent,jdbcType=VARCHAR},
#{hasStartContent,jdbcType=BOOLEAN},
......@@ -92,6 +95,9 @@
<if test="sendCount != null">
send_count = #{sendCount,jdbcType=INTEGER},
</if>
<if test="sendRule != null">
send_rule = #{sendRule,jdbcType=INTEGER},
</if>
<if test="startContent != null">
start_content = #{startContent,jdbcType=VARCHAR},
</if>
......
......@@ -537,13 +537,18 @@
t.id qrcodeId,
t.weixin_group_id weixinGroupId,
t1.id classifyId,
t1.book_group_id bookGroupId
t1.book_group_id bookGroupId,
t2.pro_label_id proLabelId,
t2.dep_label_id depLabelId,
t2.pur_label_id purLabelId
FROM
book_group_qrcode t
INNER JOIN book_group_classify t1 ON t.classify_id = t1.id
INNER JOIN book_group t2 ON t2.id = t1.book_group_id
WHERE
t.is_delete = 0
AND t1.is_delete = 0
AND t2.is_delete = 0
AND t1.id IN
<foreach collection = "list" index="index" item = "item" open = "(" separator= "," close = ")">
#{item}
......
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