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; ...@@ -2,12 +2,31 @@ package com.pcloud.book.adnews.biz.impl;
import com.pcloud.book.adnews.biz.AdNewsBiz; import com.pcloud.book.adnews.biz.AdNewsBiz;
import com.pcloud.book.adnews.check.AdNewsCheck; import com.pcloud.book.adnews.check.AdNewsCheck;
import com.pcloud.book.adnews.dao.*; import com.pcloud.book.adnews.dao.AdNewsBanDao;
import com.pcloud.book.adnews.entity.*; 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.AdContentFromEnum;
import com.pcloud.book.adnews.enums.AdNewsBanEnum; import com.pcloud.book.adnews.enums.AdNewsBanEnum;
import com.pcloud.book.adnews.dto.AdNewsListParam; import com.pcloud.book.adnews.dto.AdNewsListParam;
import com.pcloud.book.adnews.enums.AdNewsContentTypeEnum; 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.AdNewsGroupRecordVO;
import com.pcloud.book.adnews.vo.AdNewsMessageStatisticVO; import com.pcloud.book.adnews.vo.AdNewsMessageStatisticVO;
import com.pcloud.book.base.exception.BookBizException; import com.pcloud.book.base.exception.BookBizException;
...@@ -89,6 +108,9 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -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 String AD_EVENING_NEWS_SCHEDULE_PRE = "AD_EVENING_NEWS_SCHEDULE_";
// 发送消息的长度限制
private static final Integer SEND_MESSAGE_LENGTH=1000;
@Value("${wechat.group.link.prefix}") @Value("${wechat.group.link.prefix}")
private String wechatGroupLinkPrefix; private String wechatGroupLinkPrefix;
...@@ -237,30 +259,19 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -237,30 +259,19 @@ public class AdNewsBizImpl implements AdNewsBiz {
AdNewsMessageStatistic adNewsMessageStatistic; AdNewsMessageStatistic adNewsMessageStatistic;
if (adNewsSet.getContentFrom() == AdContentFromEnum.WECHAT.key) { if (adNewsSet.getContentFrom() == AdContentFromEnum.WECHAT.key) {
// 填充要发送的早晚报
setPushAdNewsList(adNewsSet,groupQrcodeFoAdDTOS);
// 查询要发的记录 // 构建早晚报发送记录对象
List<AdNews> adNewsList = null; for (GroupQrcodeFoAdDTO groupQrcodeFoAdDTO : groupQrcodeFoAdDTOS) {
if (ListUtils.isEmpty(groupQrcodeFoAdDTO.getAdNewsList())) {
adNewsList = adNewsDao.getNewsToSendBySetIdAndAdviser4Own(adNewsSetId, adNewsSet.getCreateUser(), adNewsSet.getSendCount()); LOGGER.info("BookGroupId:"+ groupQrcodeFoAdDTO.getBookGroupId() + " 没有可供发送的早晚报!");
// 如果自有公众号的数据为空,则查询系统推荐公众号数据 continue;
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);
}
} }
if (ListUtils.isEmpty(adNewsList)) { this.replaceUnescaped(groupQrcodeFoAdDTO.getAdNewsList());
LOGGER.info("记录为空,没有可供发送的早晚报!");
return;
}
// 构建记录对象 for (AdNews adNews : groupQrcodeFoAdDTO.getAdNewsList()) {
for (GroupQrcodeFoAdDTO groupQrcodeFoAdDTO : groupQrcodeFoAdDTOS) {
for (AdNews adNews : adNewsList) {
adNewsGroupRecord = new AdNewsGroupRecord(); adNewsGroupRecord = new AdNewsGroupRecord();
adNewsGroupRecord.setAdNewsId(adNews.getId()); adNewsGroupRecord.setAdNewsId(adNews.getId());
adNewsGroupRecord.setAdNewsSetId(adNewsSetId); adNewsGroupRecord.setAdNewsSetId(adNewsSetId);
...@@ -280,14 +291,15 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -280,14 +291,15 @@ public class AdNewsBizImpl implements AdNewsBiz {
adNewsMessageStatistic.setClassifyId(groupQrcodeFoAdDTO.getClassifyId()); adNewsMessageStatistic.setClassifyId(groupQrcodeFoAdDTO.getClassifyId());
adNewsMessageStatistic.setQrcodeId(groupQrcodeFoAdDTO.getQrcodeId()); adNewsMessageStatistic.setQrcodeId(groupQrcodeFoAdDTO.getQrcodeId());
adNewsMessageStatistic.setCreateUser(adNewsSet.getCreateUser()); adNewsMessageStatistic.setCreateUser(adNewsSet.getCreateUser());
adNewsMessageStatistic.setMessageCount(adNewsList.size()); adNewsMessageStatistic.setMessageCount(groupQrcodeFoAdDTO.getAdNewsList().size());
adNewsMessageStatistic.setInsertMark(groupQrcodeFoAdDTOS.indexOf(groupQrcodeFoAdDTO)); adNewsMessageStatistic.setInsertMark(groupQrcodeFoAdDTOS.indexOf(groupQrcodeFoAdDTO));
adNewsMessageStatistics.add(adNewsMessageStatistic); adNewsMessageStatistics.add(adNewsMessageStatistic);
} }
// 因为拼短链接需要主键,所以需要先入库拿到主键后然后拼接Url,最后再发送微信消息; // 因为拼短链接需要主键,所以需要先入库拿到主键后然后拼接Url,最后再发送微信消息;
// 记录入库 // 记录入库
this.insertRecord(adNewsGroupRecords, adNewsMessageStatistics); int flag = this.insertRecord(adNewsGroupRecords, adNewsMessageStatistics);
if(flag == 0){ return; }
// 拼接中转链接 // 拼接中转链接
String transferUrl; String transferUrl;
...@@ -299,7 +311,7 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -299,7 +311,7 @@ public class AdNewsBizImpl implements AdNewsBiz {
// 获取对应当前群的记录详情 // 获取对应当前群的记录详情
if (groupQrcodeFoAdDTO.getQrcodeId() == item.getQrcodeId()) { 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 transferUrl = wechatGroupLinkPrefix
.concat("/link") .concat("/link")
.concat("?message_statistic_id=").concat(item.getMessageStatisticId().toString()) .concat("?message_statistic_id=").concat(item.getMessageStatisticId().toString())
...@@ -308,8 +320,8 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -308,8 +320,8 @@ public class AdNewsBizImpl implements AdNewsBiz {
adNews.setShortUrl(UrlUtils.getShortUrl4Own(transferUrl)); adNews.setShortUrl(UrlUtils.getShortUrl4Own(transferUrl));
} }
} }
// 将多条需要发送的早晚报拼接成300字符一组的消息 // 将多条需要发送的早晚报拼接成小于字数限制一组的消息
contents = this.concatContent(adNewsList); contents = this.concatContent(groupQrcodeFoAdDTO.getAdNewsList());
// 将对应群的消息发送出去 // 将对应群的消息发送出去
this.sendAdNewsToWechatGroup(adNewsSet, new ArrayList<GroupQrcodeFoAdDTO>() {{ this.sendAdNewsToWechatGroup(adNewsSet, new ArrayList<GroupQrcodeFoAdDTO>() {{
add(groupQrcodeFoAdDTO); add(groupQrcodeFoAdDTO);
...@@ -359,19 +371,157 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -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 adNewsGroupRecords
* @param adNewsMessageStatistics * @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); adNewsMessageStatisticDao.batchInsert(adNewsMessageStatistics);
// 将主键赋值给从表外键;(不会mybatis的主从表批量插入,所以只能这么做) // 将主键赋值给从表外键;(不会mybatis的主从表批量插入,所以只能这么做)
for (AdNewsMessageStatistic item : adNewsMessageStatistics) { for (AdNewsMessageStatistic item : adNewsMessageStatistics) {
adNewsGroupRecords.stream().filter(x -> x.getInsertMark() == item.getInsertMark()).forEach(x -> x.setMessageStatisticId(item.getId())); adNewsGroupRecords.stream().filter(x -> x.getInsertMark() == item.getInsertMark()).forEach(x -> x.setMessageStatisticId(item.getId()));
} }
adNewsGroupRecordDao.batchInsert(adNewsGroupRecords); adNewsGroupRecordDao.batchInsert(adNewsGroupRecords);
return 1;
} }
/** /**
...@@ -396,7 +546,23 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -396,7 +546,23 @@ public class AdNewsBizImpl implements AdNewsBiz {
String robotId = wechatGroupConsr.getRobotIdByGroupId(weixinGroupId); String robotId = wechatGroupConsr.getRobotIdByGroupId(weixinGroupId);
if (StringUtil.isEmpty(robotId)) { if (StringUtil.isEmpty(robotId)) {
LOGGER.info("发送编辑端早晚报未找到小号" + weixinGroupId); 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)) { if (!StringUtil.isEmpty(startContent)) {
//发送开场语 //发送开场语
sendAdNewsText(startContent, robotId, weixinGroupId); sendAdNewsText(startContent, robotId, weixinGroupId);
...@@ -432,10 +598,10 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -432,10 +598,10 @@ public class AdNewsBizImpl implements AdNewsBiz {
} }
/** /**
* 将内容拼接为300字符一条数据项的数组【微信目前单次消息发送字符长度为300 * 将内容拼接为 SEND_MESSAGE_LENGTH 字符一条数据项的数组【微信目前单次消息发送字符长度存在字数限制
* 拼接内容大致为 * 拼接内容大致为
* 1.xxxxxxxxxxx 2.xxxxxxxxxx 3.xxxxxxxx 【假设此条数据加下一条数据【4.xxx】 就大于300字符,那就先将之前的存一条到数组】 * 1.xxxxxxxxxxx 2.xxxxxxxxxx 3.xxxxxxxx 【假设此条数据加下一条数据【4.xxx】 就大于限制数,那就先将之前的存一条到数组】
* 4.xxxxx 5.xxxxxxx 【多余300字符再重新拼接,以此循环下去】 * 4.xxxxx 5.xxxxxxx 【多余限制数的字符再重新拼接,以此循环下去】
* *
* @param adNewsList * @param adNewsList
* @return * @return
...@@ -446,8 +612,8 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -446,8 +612,8 @@ public class AdNewsBizImpl implements AdNewsBiz {
int i = 1; int i = 1;
for (AdNews adNews : adNewsList) { for (AdNews adNews : adNewsList) {
String temp = content + i + "." + adNews.getTitle() + adNews.getShortUrl() + "\n"; String temp = content + i + "." + adNews.getTitle() + adNews.getShortUrl() + "\n";
if (temp.length() >= 1000) { if (temp.length() >= SEND_MESSAGE_LENGTH) {
// 如果本次拼接后的长度大于 300,那么将之前拼接的内容存入数组 // 如果本次拼接后的长度大于限制数,那么将之前拼接的内容存入数组
contents.add(content); contents.add(content);
// 重置 content 的内容 // 重置 content 的内容
content = i + "." + adNews.getTitle() + adNews.getShortUrl() + "\n"; content = i + "." + adNews.getTitle() + adNews.getShortUrl() + "\n";
...@@ -524,6 +690,7 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -524,6 +690,7 @@ public class AdNewsBizImpl implements AdNewsBiz {
map.put("adNewsWechatIds", adNewsListParam.getAdNewsWechatIds()); map.put("adNewsWechatIds", adNewsListParam.getAdNewsWechatIds());
map.put("contentFrom", adNewsListParam.getContentFrom()); map.put("contentFrom", adNewsListParam.getContentFrom());
PageBeanNew<AdNews> pageBeanNew = adNewsDao.listPageNew(pageParam, map, "getAdNewsList"); PageBeanNew<AdNews> pageBeanNew = adNewsDao.listPageNew(pageParam, map, "getAdNewsList");
this.replaceUnescaped(pageBeanNew.getRecordList());
return pageBeanNew; return pageBeanNew;
} }
...@@ -725,7 +892,9 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -725,7 +892,9 @@ public class AdNewsBizImpl implements AdNewsBiz {
@Override @Override
@ParamLog("查询早晚报发送详情") @ParamLog("查询早晚报发送详情")
public List<AdNewsGroupRecordVO> getAdNewsGroupRecord(Long partyId, Long messageStatisticId) { 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 @Override
......
...@@ -17,4 +17,30 @@ public interface AdNewsDao extends BaseDao<AdNews> { ...@@ -17,4 +17,30 @@ public interface AdNewsDao extends BaseDao<AdNews> {
* @return * @return
*/ */
List<AdNews> getNewsToSendBySetIdAndAdviser4Own(Long adNewsSetId, Long adviserId, Integer top); 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 { ...@@ -33,4 +33,30 @@ public class AdNewsDaoImpl extends BaseDaoImpl<AdNews> implements AdNewsDao {
map.put("top", top); map.put("top", top);
return super.getSqlSession().selectList(getStatement("getNewsToSendBySetIdAndAdviser4Own"), map); 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 { ...@@ -33,6 +33,9 @@ public class AdNewsSet extends BaseEntity {
@ApiModelProperty("发送次数") @ApiModelProperty("发送次数")
private Integer sendCount; private Integer sendCount;
@ApiModelProperty("发送规则")
private Integer sendRule;
@ApiModelProperty("开场语") @ApiModelProperty("开场语")
private String startContent; 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; package com.pcloud.book.group.dto;
import com.pcloud.book.adnews.entity.AdNews;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* @Description * @Description
* @Author ruansiyuan * @Author ruansiyuan
* @Date 2019/7/18 15:09 * @Date 2019/7/18 15:09
**/ **/
@Data
public class GroupQrcodeFoAdDTO implements Serializable { public class GroupQrcodeFoAdDTO implements Serializable {
private static final long serialVersionUID = 7018070035247234809L; private static final long serialVersionUID = 7018070035247234809L;
...@@ -18,45 +23,25 @@ public class GroupQrcodeFoAdDTO implements Serializable { ...@@ -18,45 +23,25 @@ public class GroupQrcodeFoAdDTO implements Serializable {
private String weixinGroupId; private String weixinGroupId;
public Long getQrcodeId() { // 专业id
return qrcodeId; private Long proLabelId;
}
// 深度id
public void setQrcodeId(Long qrcodeId) { private Long depLabelId;
this.qrcodeId = qrcodeId;
} // 目的id
private Long purLabelId;
public Long getClassifyId() {
return classifyId; // 专业
} private String proLabelName;
public void setClassifyId(Long classifyId) { // 深度
this.classifyId = classifyId; private String depLabelName;
}
// 目的
public Long getBookGroupId() { private String purLabelName;
return bookGroupId;
} // 需要发送的早晚报
private List<AdNews> adNewsList;
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 + '\'' +
'}';
}
} }
...@@ -120,7 +120,7 @@ ...@@ -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 ) 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 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 ORDER BY
a.id DESC a.create_time DESC
LIMIT #{top} LIMIT #{top}
</select> </select>
...@@ -139,7 +139,55 @@ ...@@ -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} ) 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}) 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 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} LIMIT #{top}
</select> </select>
...@@ -180,10 +228,10 @@ ...@@ -180,10 +228,10 @@
AND a.title like concat('%', #{title},'%') AND a.title like concat('%', #{title},'%')
</if> </if>
<if test="beginTime!=null"> <if test="beginTime!=null">
AND a.news_date <![CDATA[>=]]> #{beginTime} AND a.create_time <![CDATA[>=]]> #{beginTime}
</if> </if>
<if test="endTime!=null"> <if test="endTime!=null">
AND a.news_date<![CDATA[<=]]> #{endTime} AND a.create_time<![CDATA[<=]]> #{endTime}
</if> </if>
<if test="hasBan==0"> <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) 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 @@ ...@@ -197,6 +245,7 @@
<if test="hasUsed==1"> <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) AND EXISTS (SELECT 1 FROM ad_news_group_record WHERE ad_news_id=a.id and create_user=#{partyId} LIMIT 1)
</if> </if>
ORDER BY a.create_time DESC,a.id DESC
</select> </select>
<!--获取编辑选择的素材--> <!--获取编辑选择的素材-->
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<result column="has_morning_open" property="hasMorningOpen" jdbcType="BOOLEAN"/> <result column="has_morning_open" property="hasMorningOpen" jdbcType="BOOLEAN"/>
<result column="has_evening_open" property="hasEveningOpen" jdbcType="BOOLEAN"/> <result column="has_evening_open" property="hasEveningOpen" jdbcType="BOOLEAN"/>
<result column="send_count" property="sendCount" jdbcType="INTEGER"/> <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="start_content" property="startContent" jdbcType="VARCHAR"/>
<result column="end_content" property="endContent" jdbcType="VARCHAR"/> <result column="end_content" property="endContent" jdbcType="VARCHAR"/>
<result column="has_start_content" property="hasStartContent" jdbcType="BOOLEAN"/> <result column="has_start_content" property="hasStartContent" jdbcType="BOOLEAN"/>
...@@ -22,7 +23,7 @@ ...@@ -22,7 +23,7 @@
</resultMap> </resultMap>
<sql id="Base_Column_List"> <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 end_content, has_start_content, has_end_content, create_user, create_time, update_user, update_time
,content_from,morning_content,evening_content ,content_from,morning_content,evening_content
</sql> </sql>
...@@ -42,6 +43,7 @@ ...@@ -42,6 +43,7 @@
has_morning_open, has_morning_open,
has_evening_open, has_evening_open,
send_count, send_count,
send_rule,
start_content, start_content,
end_content, end_content,
has_start_content, has_start_content,
...@@ -60,6 +62,7 @@ ...@@ -60,6 +62,7 @@
#{hasMorningOpen,jdbcType=BOOLEAN}, #{hasMorningOpen,jdbcType=BOOLEAN},
#{hasEveningOpen,jdbcType=BOOLEAN}, #{hasEveningOpen,jdbcType=BOOLEAN},
#{sendCount,jdbcType=INTEGER}, #{sendCount,jdbcType=INTEGER},
#{sendRule,jdbcType=INTEGER},
#{startContent,jdbcType=VARCHAR}, #{startContent,jdbcType=VARCHAR},
#{endContent,jdbcType=VARCHAR}, #{endContent,jdbcType=VARCHAR},
#{hasStartContent,jdbcType=BOOLEAN}, #{hasStartContent,jdbcType=BOOLEAN},
...@@ -92,6 +95,9 @@ ...@@ -92,6 +95,9 @@
<if test="sendCount != null"> <if test="sendCount != null">
send_count = #{sendCount,jdbcType=INTEGER}, send_count = #{sendCount,jdbcType=INTEGER},
</if> </if>
<if test="sendRule != null">
send_rule = #{sendRule,jdbcType=INTEGER},
</if>
<if test="startContent != null"> <if test="startContent != null">
start_content = #{startContent,jdbcType=VARCHAR}, start_content = #{startContent,jdbcType=VARCHAR},
</if> </if>
......
...@@ -537,13 +537,18 @@ ...@@ -537,13 +537,18 @@
t.id qrcodeId, t.id qrcodeId,
t.weixin_group_id weixinGroupId, t.weixin_group_id weixinGroupId,
t1.id classifyId, 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 FROM
book_group_qrcode t book_group_qrcode t
INNER JOIN book_group_classify t1 ON t.classify_id = t1.id 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 WHERE
t.is_delete = 0 t.is_delete = 0
AND t1.is_delete = 0 AND t1.is_delete = 0
AND t2.is_delete = 0
AND t1.id IN AND t1.id IN
<foreach collection = "list" index="index" item = "item" open = "(" separator= "," close = ")"> <foreach collection = "list" index="index" item = "item" open = "(" separator= "," close = ")">
#{item} #{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