Commit dedaef33 by 郑永强

修改自有公众号结构

parent 983c494b
...@@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import sun.plugin.com.Utils;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
...@@ -108,11 +109,24 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -108,11 +109,24 @@ public class AdNewsBizImpl implements AdNewsBiz {
adNewsSetDao.insert(adNewsSet); adNewsSetDao.insert(adNewsSet);
buildAdNewsGroups(adNewsSet, adNewsSet.getCreateUser()); buildAdNewsGroups(adNewsSet, adNewsSet.getCreateUser());
adNewsGroupDao.batchInsert(adNewsSet.getAdNewsGroups()); adNewsGroupDao.batchInsert(adNewsSet.getAdNewsGroups());
buildAdNewsWechats(adNewsSet);
adNewsWechatDao.batchInsert(adNewsSet.getAdNewsWechats());
//创建定时任务 //创建定时任务
buildAdNewsSh(adNewsSet); buildAdNewsSh(adNewsSet);
return adNewsSet.getId(); return adNewsSet.getId();
} }
/**
* 构建自有公众号对象
*
* @param adNewsSet
*/
private void buildAdNewsWechats(AdNewsSet adNewsSet) {
for (AdNewsWechat adNewsWechat : adNewsSet.getAdNewsWechats()) {
adNewsWechat.setAdviserId(adNewsSet.getUpdateUser());
}
}
@ParamLog("创建编辑端早晚报定时任务") @ParamLog("创建编辑端早晚报定时任务")
private void buildAdNewsSh(AdNewsSet adNewsSet) { private void buildAdNewsSh(AdNewsSet adNewsSet) {
if (adNewsSet.getHasMorningOpen()) { if (adNewsSet.getHasMorningOpen()) {
...@@ -175,6 +189,12 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -175,6 +189,12 @@ public class AdNewsBizImpl implements AdNewsBiz {
//重新设置关联 //重新设置关联
buildAdNewsGroups(adNewsSet, adNewsSet.getUpdateUser()); buildAdNewsGroups(adNewsSet, adNewsSet.getUpdateUser());
adNewsGroupDao.batchInsert(adNewsSet.getAdNewsGroups()); adNewsGroupDao.batchInsert(adNewsSet.getAdNewsGroups());
// 判断是否增加自有过公众号,如果没有则将当前数据入库
if (!ListUtils.isEmpty(adNewsSet.getAdNewsWechats())
&& !adNewsWechatDao.existsAdNewsWechat(adNewsSet.getUpdateUser())) {
buildAdNewsWechats(adNewsSet);
adNewsWechatDao.batchInsert(adNewsSet.getAdNewsWechats());
}
//删除旧的定时任务 //删除旧的定时任务
deleteAdNewsSch(AD_MORNING_NEWS_SCHEDULE_PRE + adNewsSet.getId()); deleteAdNewsSch(AD_MORNING_NEWS_SCHEDULE_PRE + adNewsSet.getId());
deleteAdNewsSch(AD_EVENING_NEWS_SCHEDULE_PRE + adNewsSet.getId()); deleteAdNewsSch(AD_EVENING_NEWS_SCHEDULE_PRE + adNewsSet.getId());
...@@ -200,6 +220,7 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -200,6 +220,7 @@ public class AdNewsBizImpl implements AdNewsBiz {
//查询关联的群 //查询关联的群
List<GroupQrcodeFoAdDTO> groupQrcodeFoAdDTOS = groupQrcodeDao.GroupQrcodeFoAdDTOSByClassifyIds(classifyIds); List<GroupQrcodeFoAdDTO> groupQrcodeFoAdDTOS = groupQrcodeDao.GroupQrcodeFoAdDTOSByClassifyIds(classifyIds);
if (ListUtils.isEmpty(groupQrcodeFoAdDTOS)) { if (ListUtils.isEmpty(groupQrcodeFoAdDTOS)) {
LOGGER.info("没有关联任何群,无法发送早晚报!");
return; return;
} }
...@@ -217,10 +238,18 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -217,10 +238,18 @@ public class AdNewsBizImpl implements AdNewsBiz {
if (adNewsSet.getContentFrom() == AdContentFromEnum.WECHAT.key) { if (adNewsSet.getContentFrom() == AdContentFromEnum.WECHAT.key) {
//查询要发的记录 // 查询要发的记录
List<AdNews> adNewsList = adNewsDao.getNewsToSendBySetIdAndAdviser(adNewsSetId, adNewsSet.getCreateUser(), adNewsSet.getSendCount()); List<AdNews> adNewsList = null;
AdContentFromEnum adContentFromEnum = AdContentFromEnum.WECHAT_ADVISER;
adNewsList = adNewsDao.getNewsToSendBySetIdAndAdviser4Own(adNewsSetId, adNewsSet.getCreateUser(), adNewsSet.getSendCount());
if (ListUtils.isEmpty(adNewsList)) { if (ListUtils.isEmpty(adNewsList)) {
return; adContentFromEnum = AdContentFromEnum.WECHAT;
adNewsList = adNewsDao.getNewsToSendBySetIdAndAdviser(adNewsSetId, adNewsSet.getCreateUser(), adNewsSet.getSendCount());
if (ListUtils.isEmpty(adNewsList)) {
LOGGER.info("记录为空,没有可供发送的早晚报!");
return;
}
} }
// 构建记录对象 // 构建记录对象
...@@ -244,12 +273,13 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -244,12 +273,13 @@ 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.setContentFrom(adNewsSet.getContentFrom()); adNewsMessageStatistic.setContentFrom(adContentFromEnum.key);
adNewsMessageStatistic.setMessageCount(adNewsList.size()); adNewsMessageStatistic.setMessageCount(adNewsList.size());
adNewsMessageStatistic.setInsertMark(groupQrcodeFoAdDTOS.indexOf(groupQrcodeFoAdDTO)); adNewsMessageStatistic.setInsertMark(groupQrcodeFoAdDTOS.indexOf(groupQrcodeFoAdDTO));
adNewsMessageStatistics.add(adNewsMessageStatistic); adNewsMessageStatistics.add(adNewsMessageStatistic);
} }
// 因为拼短链接需要主键,所以需要先入库拿到主键后然后拼接Url,最后再发送微信消息;
// 记录入库 // 记录入库
this.insertRecord(adNewsGroupRecords, adNewsMessageStatistics); this.insertRecord(adNewsGroupRecords, adNewsMessageStatistics);
...@@ -331,7 +361,7 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -331,7 +361,7 @@ public class AdNewsBizImpl implements AdNewsBiz {
*/ */
private void insertRecord(List<AdNewsGroupRecord> adNewsGroupRecords, List<AdNewsMessageStatistic> adNewsMessageStatistics) { private void insertRecord(List<AdNewsGroupRecord> adNewsGroupRecords, List<AdNewsMessageStatistic> adNewsMessageStatistics) {
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()));
} }
...@@ -438,6 +468,10 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -438,6 +468,10 @@ public class AdNewsBizImpl implements AdNewsBiz {
List<Long> classifyIds = adNewsGroups.stream().filter(s -> s.getClassifyId() != null).map(AdNewsGroup::getClassifyId).collect(Collectors.toList()); List<Long> classifyIds = adNewsGroups.stream().filter(s -> s.getClassifyId() != null).map(AdNewsGroup::getClassifyId).collect(Collectors.toList());
adNewsSet.setClassifyIds(classifyIds); adNewsSet.setClassifyIds(classifyIds);
} }
// 自有公众号
List<AdNewsWechat> adNewsWechats = adNewsWechatDao.getListByAdviserId(adNewsSet.getUpdateUser());
adNewsSet.setAdNewsWechats(ListUtils.isEmpty(adNewsWechats) ? new ArrayList<>() : adNewsWechats);
} }
return adNewsSet; return adNewsSet;
} }
...@@ -563,8 +597,7 @@ public class AdNewsBizImpl implements AdNewsBiz { ...@@ -563,8 +597,7 @@ public class AdNewsBizImpl implements AdNewsBiz {
if (StringUtil.isEmpty(adNewsWechat.getWechatName())) { if (StringUtil.isEmpty(adNewsWechat.getWechatName())) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "公众号不能为空!"); throw new BookBizException(BookBizException.PARAM_IS_ERROR, "公众号不能为空!");
} }
if(adNewsWechatDao.checkRepeat(adNewsWechat.getWechatName(),adNewsWechat.getAdviserId())) if (adNewsWechatDao.checkRepeat(adNewsWechat.getWechatName(), adNewsWechat.getAdviserId())) {
{
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "该公众号已经存在!"); throw new BookBizException(BookBizException.PARAM_IS_ERROR, "该公众号已经存在!");
} }
} }
......
...@@ -9,4 +9,12 @@ public interface AdNewsDao extends BaseDao<AdNews> { ...@@ -9,4 +9,12 @@ public interface AdNewsDao extends BaseDao<AdNews> {
List<AdNews> getNewsToSendBySetIdAndAdviser(Long adNewsSetId, Long adviserId, Integer top); List<AdNews> getNewsToSendBySetIdAndAdviser(Long adNewsSetId, Long adviserId, Integer top);
/**
* 获取自有公众号的需要发送的新闻
* @param adNewsSetId
* @param adviserId
* @param top
* @return
*/
List<AdNews> getNewsToSendBySetIdAndAdviser4Own(Long adNewsSetId, Long adviserId, Integer top);
} }
...@@ -3,6 +3,8 @@ package com.pcloud.book.adnews.dao; ...@@ -3,6 +3,8 @@ package com.pcloud.book.adnews.dao;
import com.pcloud.book.adnews.entity.AdNewsWechat; import com.pcloud.book.adnews.entity.AdNewsWechat;
import com.pcloud.common.core.dao.BaseDao; import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
/** /**
* @author zhengyongqiang * @author zhengyongqiang
* @date 2019/8/7 11:46 * @date 2019/8/7 11:46
...@@ -10,4 +12,25 @@ import com.pcloud.common.core.dao.BaseDao; ...@@ -10,4 +12,25 @@ import com.pcloud.common.core.dao.BaseDao;
public interface AdNewsWechatDao extends BaseDao<AdNewsWechat> { public interface AdNewsWechatDao extends BaseDao<AdNewsWechat> {
boolean checkRepeat(String wechatName, Long adviserId); boolean checkRepeat(String wechatName, Long adviserId);
/**
* 批量新增自有公众号
* @param list
* @return
*/
Integer batchInsert(List<AdNewsWechat> list);
/**
* 检测是否存在自有公众号
* @param adviserId
* @return
*/
boolean existsAdNewsWechat(Long adviserId);
/**
* 获取自有公众号
* @param adviserId
* @return
*/
List<AdNewsWechat> getListByAdviserId(Long adviserId);
} }
...@@ -24,4 +24,13 @@ public class AdNewsDaoImpl extends BaseDaoImpl<AdNews> implements AdNewsDao { ...@@ -24,4 +24,13 @@ public class AdNewsDaoImpl extends BaseDaoImpl<AdNews> implements AdNewsDao {
map.put("top", top); map.put("top", top);
return super.getSqlSession().selectList(getStatement("getNewsToSendBySetIdAndAdviser"), map); return super.getSqlSession().selectList(getStatement("getNewsToSendBySetIdAndAdviser"), map);
} }
@Override
public List<AdNews> getNewsToSendBySetIdAndAdviser4Own(Long adNewsSetId, Long adviserId, Integer top) {
Map<String, Object> map = new HashMap<>();
map.put("adNewsSetId", adNewsSetId);
map.put("adviserId", adviserId);
map.put("top", top);
return super.getSqlSession().selectList(getStatement("getNewsToSendBySetIdAndAdviser4Own"), map);
}
} }
...@@ -6,6 +6,7 @@ import com.pcloud.common.core.dao.BaseDaoImpl; ...@@ -6,6 +6,7 @@ import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -21,4 +22,21 @@ public class AdNewsWechatDaoImpl extends BaseDaoImpl<AdNewsWechat> implements Ad ...@@ -21,4 +22,21 @@ public class AdNewsWechatDaoImpl extends BaseDaoImpl<AdNewsWechat> implements Ad
map.put("adviserId",adviserId); map.put("adviserId",adviserId);
return super.getSqlSession().selectOne(getStatement("checkRepeat"),map); return super.getSqlSession().selectOne(getStatement("checkRepeat"),map);
} }
@Override
public Integer batchInsert(List<AdNewsWechat> list) {
return super.getSqlSession().insert(getStatement("batchInsert"),list);
}
@Override
public boolean existsAdNewsWechat(Long adviserId) {
Map<String,Object> map = new HashMap<>();
map.put("adviserId",adviserId);
return super.getSqlSession().selectOne(getStatement("existsAdNewsWechat"),map);
}
@Override
public List<AdNewsWechat> getListByAdviserId(Long adviserId) {
return super.getSqlSession().selectList(getStatement("getListByAdviserId"),adviserId);
}
} }
...@@ -68,4 +68,8 @@ public class AdNewsSet extends BaseEntity { ...@@ -68,4 +68,8 @@ public class AdNewsSet extends BaseEntity {
@ApiModelProperty("分类id集合") @ApiModelProperty("分类id集合")
private List<Long> classifyIds; private List<Long> classifyIds;
@ApiModelProperty("自有公众号")
private List<AdNewsWechat> adNewsWechats;
} }
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
</foreach> </foreach>
</insert> </insert>
<!--查找要发送的新闻--> <!--查找要发送的新闻(推荐公众号)-->
<!-- <!--
1、ad_news_ban 排除掉禁止发送的 1、ad_news_ban 排除掉禁止发送的
2、ad_news_group_record 排除掉已发送的 2、ad_news_group_record 排除掉已发送的
...@@ -123,6 +123,25 @@ ...@@ -123,6 +123,25 @@
LIMIT #{top} LIMIT #{top}
</select> </select>
<!--查找要发送的新闻(自有公众号)-->
<!--
1、ad_news_ban 排除掉禁止发送的
2、ad_news_group_record 排除掉已发送的
-->
<select id="getNewsToSendBySetIdAndAdviser4Own" 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
FROM
ad_news a
INNER JOIN ad_news_wechat b ON a.news_from = b.news_from AND b.is_delete = 0
WHERE
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
LIMIT #{top}
</select>
<!--获取素材库列表--> <!--获取素材库列表-->
<select id="getAdNewsList" parameterType="map" resultType="com.pcloud.book.adnews.entity.AdNews"> <select id="getAdNewsList" parameterType="map" resultType="com.pcloud.book.adnews.entity.AdNews">
SELECT SELECT
......
...@@ -22,8 +22,16 @@ ...@@ -22,8 +22,16 @@
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</select> </select>
<select id="getListByAdviserId" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from ad_news_wechat
where adviser_id = #{adviserId,jdbcType=BIGINT}
AND is_delete=0
</select>
<!--获取公众号列表--> <!--获取公众号列表-->
<select id=" getAdNewsWechatList" parameterType="map" resultMap="BaseResultMap"> <select id="getAdNewsWechatList" parameterType="map" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from ad_news_wechat from ad_news_wechat
...@@ -70,9 +78,12 @@ ...@@ -70,9 +78,12 @@
SELECT count(1) FROM ad_news_wechat SELECT count(1) FROM ad_news_wechat
WHERE (wechat_name=#{wechatName} AND adviser_id IS NULL) WHERE (wechat_name=#{wechatName} AND adviser_id IS NULL)
OR (wechat_name=#{wechatName} AND adviser_id=#{adviserId}) OR (wechat_name=#{wechatName} AND adviser_id=#{adviserId})
LIMIT 1
</select> </select>
<select id="existsAdNewsWechat" parameterType="map" resultType="boolean">
SELECT count(1) FROM ad_news_wechat
WHERE adviser_id=#{adviserId}
</select>
<insert id="insert" parameterType="com.pcloud.book.adnews.entity.AdNewsWechat" useGeneratedKeys="true" <insert id="insert" parameterType="com.pcloud.book.adnews.entity.AdNewsWechat" useGeneratedKeys="true"
keyProperty="id"> keyProperty="id">
...@@ -87,4 +98,24 @@ ...@@ -87,4 +98,24 @@
NOW() NOW()
</trim> </trim>
</insert> </insert>
<insert id="batchInsert" parameterType="list" useGeneratedKeys="true" keyProperty="id">
insert into ad_news_wechat(
wechat_name,
adviser_id,
is_delete,
create_time
)
values
<foreach collection="list" item="item" index="index" separator="," >
(
#{item.wechatName,jdbcType=VARCHAR},
#{item.adviserId,jdbcType=BIGINT},
0,
NOW()
)
</foreach>
</insert>
</mapper> </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