Commit 906532b4 by 郑永强

早晚报点击量统计

parent 3ff48c9e
......@@ -108,7 +108,7 @@ public interface AdNewsBiz {
* @param numPerPage
* @return
*/
PageBeanNew<AdNewsMessageStatisticVO> getAdNewsMessageStatistic(Long partyId, String title, String beginTime, String endTime, String proLabelId, String depLabelId, String purLabelId, Integer currentPage, Integer numPerPage);
PageBeanNew<AdNewsMessageStatisticVO> getAdNewsMessageStatistic(Long partyId, String title, String beginTime, String endTime, Long proLabelId, Long depLabelId, Long purLabelId, Integer currentPage, Integer numPerPage);
/**
* 查询早晚报发送详情
......@@ -117,4 +117,11 @@ public interface AdNewsBiz {
* @return
*/
List<AdNewsGroupRecordVO> getAdNewsGroupRecord(Long partyId, Long messageStatisticId);
/**
* 记录用户点击量
* @param adNewsClickRecord
* @return
*/
Long addAdNewsClickRecord(AdNewsClickRecord adNewsClickRecord);
}
......@@ -22,6 +22,7 @@ import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.DateUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.ResponseHandleUtil;
import com.pcloud.common.utils.httpclient.UrlUtils;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.facade.quartz.entity.CallBackParam;
import com.pcloud.facade.quartz.entity.ScheduleJob;
......@@ -33,9 +34,12 @@ import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.net.URLEncoder;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.stream.Collectors;
......@@ -64,6 +68,8 @@ public class AdNewsBizImpl implements AdNewsBiz {
@Autowired
private AdNewsMessageStatisticDao adNewsMessageStatisticDao;
@Autowired
private AdNewsClickRecordDao adNewsClickRecordDao;
@Autowired
private AdNewsBanDao adNewsBanDao;
@Autowired
private ScheduleService scheduleService;
......@@ -84,6 +90,9 @@ public class AdNewsBizImpl implements AdNewsBiz {
private static final String AD_EVENING_NEWS_SCHEDULE_PRE = "AD_EVENING_NEWS_SCHEDULE_";
@Value("${wechat.group.link.prefix}")
private String wechatGroupLinkPrefix;
@Transactional(rollbackFor = Exception.class)
@ParamLog("新增早晚报设置")
@Override
......@@ -242,16 +251,34 @@ public class AdNewsBizImpl implements AdNewsBiz {
// 记录入库
this.insertRecord(adNewsGroupRecords, adNewsMessageStatistics);
// 拼短链接
// 将多条需要发送的早晚报拼接成300字符一组的消息
contents = this.concatContent(adNewsList);
// 通过机器人小号发送消息到微信群
this.sendAdNewsToWechatGroup(adNewsSet, groupQrcodeFoAdDTOS, contents);
// 拼接中转链接
String transferUrl;
AdNews adNews;
// 遍历微信群
for (GroupQrcodeFoAdDTO groupQrcodeFoAdDTO : groupQrcodeFoAdDTOS) {
// 遍历记录详情
for (AdNewsGroupRecord item : adNewsGroupRecords) {
// 获取对应当前群的记录详情
if(groupQrcodeFoAdDTO.getQrcodeId() == item.getQrcodeId()) {
// 将对应当前群里的需要发送的新闻链接拼接完成
adNews = adNewsList.stream().filter(x -> x.getId() == item.getAdNewsId()).findFirst().get();
transferUrl = wechatGroupLinkPrefix
.concat("/link")
.concat("?message_statistic_id=").concat(item.getMessageStatisticId().toString())
.concat("&group_record_id=").concat(item.getId().toString())
.concat("&url=").concat(URLEncoder.encode(adNews.getUrl()));
adNews.setShortUrl(UrlUtils.getShortUrl4Own(transferUrl));
}
}
// 将多条需要发送的早晚报拼接成300字符一组的消息
contents = this.concatContent(adNewsList);
// 将对应群的消息发送出去
this.sendAdNewsToWechatGroup(adNewsSet,new ArrayList<GroupQrcodeFoAdDTO>(){{ add(groupQrcodeFoAdDTO); }} ,contents);
}
} else if (adNewsSet.getContentFrom() == AdContentFromEnum.CUSTOM.key) {
if (StringUtil.isEmpty(adNewsSet.getMorningContent())) {
LOGGER.info("早报内容为空,无法发送");
return;
......@@ -262,9 +289,6 @@ public class AdNewsBizImpl implements AdNewsBiz {
}
// 获取发送早报还是晚报
String customContent = this.getMorningOrEveningContent(adNewsSet);
contents.add(customContent);
// 通过机器人小号发送消息到微信群
this.sendAdNewsToWechatGroup(adNewsSet, groupQrcodeFoAdDTOS, contents);
for (GroupQrcodeFoAdDTO groupQrcodeFoAdDTO : groupQrcodeFoAdDTOS) {
adNewsGroupRecord = new AdNewsGroupRecord();
adNewsGroupRecord.setAdNewsSetId(adNewsSetId);
......@@ -291,6 +315,10 @@ public class AdNewsBizImpl implements AdNewsBiz {
}
// 发送记录入库
this.insertRecord(adNewsGroupRecords, adNewsMessageStatistics);
contents.add(customContent);
// 通过机器人小号发送消息到微信群,自定义的消息无法记录点击,所以可以一起发(其实里面也是遍历微信群然后发送消息)
this.sendAdNewsToWechatGroup(adNewsSet, groupQrcodeFoAdDTOS, contents);
}
}
......@@ -348,7 +376,6 @@ public class AdNewsBizImpl implements AdNewsBiz {
}
}
/**
* 发送早报还是晚报
*
......@@ -576,7 +603,7 @@ public class AdNewsBizImpl implements AdNewsBiz {
@Override
@ParamLog("获取早晚报发送记录")
public PageBeanNew<AdNewsMessageStatisticVO> getAdNewsMessageStatistic(Long partyId, String title, String beginTime, String endTime, String proLabelId, String depLabelId, String purLabelId, Integer currentPage, Integer numPerPage) {
public PageBeanNew<AdNewsMessageStatisticVO> getAdNewsMessageStatistic(Long partyId, String title, String beginTime, String endTime, Long proLabelId, Long depLabelId, Long purLabelId, Integer currentPage, Integer numPerPage) {
PageParam pageParam = new PageParam(currentPage, numPerPage);
Map<String, Object> map = new HashMap<>();
......@@ -637,6 +664,12 @@ public class AdNewsBizImpl implements AdNewsBiz {
public List<AdNewsGroupRecordVO> getAdNewsGroupRecord(Long partyId, Long messageStatisticId) {
return adNewsGroupRecordDao.getAdNewsGroupRecord(partyId, messageStatisticId);
}
@Override
@ParamLog("记录用户点击量")
public Long addAdNewsClickRecord(AdNewsClickRecord adNewsClickRecord) {
return adNewsClickRecordDao.insert(adNewsClickRecord);
}
}
......
package com.pcloud.book.adnews.dao;
import com.pcloud.book.adnews.entity.AdNewsClickRecord;
import com.pcloud.common.core.dao.BaseDao;
/**
* @author zhengyongqiang
* @date 2019/8/15 11:10
*/
public interface AdNewsClickRecordDao extends BaseDao<AdNewsClickRecord> {
}
package com.pcloud.book.adnews.dao.impl;
import com.pcloud.book.adnews.dao.AdNewsClickRecordDao;
import com.pcloud.book.adnews.entity.AdNewsClickRecord;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Repository;
/**
* @author zhengyongqiang
* @date 2019/8/15 11:10
*/
@Repository("adNewsClickRecordDao")
public class AdNewsClickRecordDaoImpl extends BaseDaoImpl<AdNewsClickRecord> implements AdNewsClickRecordDao {
}
package com.pcloud.book.adnews.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author zhengyongqiang
* @date 2019/8/15 11:02
*/
@Data
@ApiModel("记录点击量")
public class AdNewsClickRecord extends BaseEntity {
private static final long serialVersionUID = -3879628889314992714L;
@ApiModelProperty("微信统计记录id")
private Long messageStatisticId;
@ApiModelProperty("微信记录详情id")
private Long groupRecordId;
@ApiModelProperty("微信用户id")
private Long wechatUserId;
}
......@@ -3,12 +3,14 @@ package com.pcloud.book.adnews.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/7/17 15:20
**/
@Data
@ApiModel("编辑新闻群关联")
public class AdNewsGroup extends BaseEntity {
......@@ -32,63 +34,7 @@ public class AdNewsGroup extends BaseEntity {
@ApiModelProperty("修改人")
private Long updateUser;
public Long getClassifyId() {
return classifyId;
}
@ApiModelProperty("分类")
private String classify;
public void setClassifyId(Long classifyId) {
this.classifyId = classifyId;
}
public Long getBookGroupId() {
return bookGroupId;
}
public void setBookGroupId(Long bookGroupId) {
this.bookGroupId = bookGroupId;
}
public Long getAdNewsSetId() {
return adNewsSetId;
}
public void setAdNewsSetId(Long adNewsSetId) {
this.adNewsSetId = adNewsSetId;
}
public Boolean getIsDelete() {
return isDelete;
}
public void setIsDelete(Boolean isDelete) {
this.isDelete = isDelete;
}
public Long getCreateUser() {
return createUser;
}
public void setCreateUser(Long createUser) {
this.createUser = createUser;
}
public Long getUpdateUser() {
return updateUser;
}
public void setUpdateUser(Long updateUser) {
this.updateUser = updateUser;
}
@Override
public String toString() {
return "AdNewsGroup{" +
"classifyId=" + classifyId +
", bookGroupId=" + bookGroupId +
", adNewsSetId=" + adNewsSetId +
", isDelete=" + isDelete +
", createUser=" + createUser +
", updateUser=" + updateUser +
"} " + super.toString();
}
}
package com.pcloud.book.adnews.facade;
import com.pcloud.book.adnews.entity.AdNewsClickRecord;
import com.pcloud.book.adnews.entity.AdNewsSet;
import com.pcloud.book.adnews.dto.AdNewsListParam;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.permission.PermissionException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.*;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
......@@ -116,9 +115,9 @@ public interface AdNewsFacade {
@RequestParam(value = "title", required = false) @ApiParam("群名称、群分类、社群码、社群书") String title,
@RequestParam(value = "beginTime", required = false) @ApiParam("开始日期") String beginTime,
@RequestParam(value = "endTime", required = false) @ApiParam("结束日期") String endTime,
@RequestParam(value = "proLabelId", required = false) @ApiParam("专业") String proLabelId,
@RequestParam(value = "depLabelId", required = false) @ApiParam("深度") String depLabelId,
@RequestParam(value = "purLabelId", required = false) @ApiParam("目的") String purLabelId,
@RequestParam(value = "proLabelId", required = false) @ApiParam("专业") Long proLabelId,
@RequestParam(value = "depLabelId", required = false) @ApiParam("深度") Long depLabelId,
@RequestParam(value = "purLabelId", required = false) @ApiParam("目的") Long purLabelId,
@RequestParam(value = "currentPage", required = false, defaultValue = "0") @ApiParam("当前页") Integer currentPage,
@RequestParam(value = "numPerPage", required = false, defaultValue = "10") @ApiParam("每页条数") Integer numPerPage
) throws BizException, PermissionException;
......@@ -130,4 +129,14 @@ public interface AdNewsFacade {
@RequestHeader("token") @ApiParam("token信息") String token,
@RequestParam("messageStatisticId") @ApiParam("统计表id") Long messageStatisticId
) throws BizException, PermissionException;
@ApiOperation("记录用户点击量")
@PostMapping("/addAdNewsClickRecord")
@ApiImplicitParams({
@ApiImplicitParam(name = "userInfo", value = "Cookie", dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "adNewsClickRecord", value = "用户点击量对象", dataType = "AdNewsClickRecord", paramType = "body")})
ResponseDto<?> addAdNewsClickRecord(
@CookieValue("userInfo") @ApiParam("用户信息") String userInfo,
@RequestBody @ApiParam("用户点击量对象") AdNewsClickRecord adNewsClickRecord
) throws BizException, PermissionException;
}
package com.pcloud.book.adnews.facade.impl;
import com.pcloud.book.adnews.biz.AdNewsBiz;
import com.pcloud.book.adnews.entity.AdNewsClickRecord;
import com.pcloud.book.adnews.entity.AdNewsSet;
import com.pcloud.book.adnews.entity.AdNewsWechat;
import com.pcloud.book.adnews.facade.AdNewsFacade;
......@@ -12,12 +13,16 @@ import com.pcloud.common.permission.PermissionException;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.NumberUtil;
import com.pcloud.common.utils.SessionUtil;
import com.pcloud.common.utils.cookie.Cookie;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @Description
......@@ -28,6 +33,7 @@ import java.util.List;
@RequestMapping("adNews")
public class AdNewsFacadeImpl implements AdNewsFacade {
private static final Logger LOGGER = LoggerFactory.getLogger(AdNewsFacadeImpl.class);
@Autowired
private AdNewsBiz adNewsBiz;
......@@ -164,7 +170,7 @@ public class AdNewsFacadeImpl implements AdNewsFacade {
if (!NumberUtil.isNumber(hasBan)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "hasBan 必须大于0!");
}
adNewsBiz.saveAdNewsBan(partyId,adNewsId,hasBan);
adNewsBiz.saveAdNewsBan(partyId, adNewsId, hasBan);
return new ResponseDto<>();
}
......@@ -236,12 +242,12 @@ public class AdNewsFacadeImpl implements AdNewsFacade {
@RequestParam(value = "title", required = false) @ApiParam("群名称、群分类、社群码、社群书") String title,
@RequestParam(value = "beginTime", required = false) @ApiParam("开始日期") String beginTime,
@RequestParam(value = "endTime", required = false) @ApiParam("结束日期") String endTime,
@RequestParam(value = "proLabelId", required = false) @ApiParam("专业") String proLabelId,
@RequestParam(value = "depLabelId", required = false) @ApiParam("深度") String depLabelId,
@RequestParam(value = "purLabelId", required = false) @ApiParam("目的") String purLabelId,
@RequestParam(value = "proLabelId", required = false) @ApiParam("专业") Long proLabelId,
@RequestParam(value = "depLabelId", required = false) @ApiParam("深度") Long depLabelId,
@RequestParam(value = "purLabelId", required = false) @ApiParam("目的") Long purLabelId,
@RequestParam(value = "currentPage", required = false, defaultValue = "0") @ApiParam("当前页") Integer currentPage,
@RequestParam(value = "numPerPage", required = false, defaultValue = "10") @ApiParam("每页条数") Integer numPerPage
) throws BizException, PermissionException{
) throws BizException, PermissionException {
Long partyId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
if (currentPage == null || currentPage < 0) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "当前页不能为空且不能小于0!");
......@@ -249,7 +255,7 @@ public class AdNewsFacadeImpl implements AdNewsFacade {
if (numPerPage == null || numPerPage <= 0) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "每页条数不能为空且必须大于0!");
}
return new ResponseDto<>(adNewsBiz.getAdNewsMessageStatistic(partyId,title,beginTime,endTime,proLabelId,depLabelId,purLabelId,currentPage,numPerPage));
return new ResponseDto<>(adNewsBiz.getAdNewsMessageStatistic(partyId, title, beginTime, endTime, proLabelId, depLabelId, purLabelId, currentPage, numPerPage));
}
@Override
......@@ -258,8 +264,25 @@ public class AdNewsFacadeImpl implements AdNewsFacade {
public ResponseDto<?> getAdNewsGroupRecord(
@RequestHeader("token") @ApiParam("token信息") String token,
@RequestParam("messageStatisticId") @ApiParam("统计表id") Long messageStatisticId
) throws BizException, PermissionException{
) throws BizException, PermissionException {
Long partyId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
return new ResponseDto<>(adNewsBiz.getAdNewsGroupRecord(partyId,messageStatisticId));
return new ResponseDto<>(adNewsBiz.getAdNewsGroupRecord(partyId, messageStatisticId));
}
@Override
@ApiOperation("记录用户点击量")
@PostMapping("/addAdNewsClickRecord")
public ResponseDto<?> addAdNewsClickRecord(
@CookieValue("userInfo") @ApiParam("用户信息") String userInfo,
@RequestBody @ApiParam("用户点击量对象") AdNewsClickRecord adNewsClickRecord
) throws BizException, PermissionException {
Map<String, Object> map = Cookie.getUserInfo(userInfo);
Long channelId = (Long) map.get(Cookie._CHANNEL_ID);
Long wechatUserId = (Long) map.get(Cookie._WECHAT_USER_ID);
LOGGER.info("addAdNewsClickRecord Map => "+map.toString());
adNewsClickRecord.setWechatUserId(wechatUserId);
return new ResponseDto<>(adNewsBiz.addAdNewsClickRecord(adNewsClickRecord));
}
}
......@@ -56,4 +56,10 @@ public class AdNewsMessageStatisticVO {
@ApiModelProperty("发送时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
@ApiModelProperty("点击次数")
private Long clickCount;
@ApiModelProperty("点击人数")
private Long userCount;
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.adnews.dao.impl.AdNewsClickRecordDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.adnews.entity.AdNewsClickRecord">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="message_statistic_id" property="messageStatisticId" jdbcType="BIGINT"/>
<result column="group_record_id" property="groupRecordId" jdbcType="BIGINT"/>
<result column="wechat_user_id" property="wechatUserId" jdbcType="BIGINT"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, message_statistic_id, group_record_id, wechat_user_id, create_time
</sql>
<select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from ad_news_click_record
where id = #{id,jdbcType=BIGINT}
</select>
<insert id="insert" parameterType="com.pcloud.book.adnews.entity.AdNewsClickRecord" useGeneratedKeys="true" keyProperty="id">
insert into ad_news_click_record
(message_statistic_id,
group_record_id,
wechat_user_id,
create_time)
values(
#{messageStatisticId,jdbcType=BIGINT},
#{groupRecordId,jdbcType=BIGINT},
#{wechatUserId,jdbcType=BIGINT},
NOW())
</insert>
</mapper>
......@@ -107,8 +107,19 @@
</update>
<!--根据早晚报设置id查询-->
<select id="getListByAdNewsSetId" parameterType="Long" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/> from ad_news_group
where is_delete=0 and ad_news_set_id=#{adNewsSetId}
<select id="getListByAdNewsSetId" parameterType="Long" resultType="com.pcloud.book.adnews.entity.AdNewsGroup">
select
a.id,
a.classify_id classifyId,
a.book_group_id bookGroupId,
a.ad_news_set_id adNewsSetId,
a.is_delete isDelete,
a.create_user createUser,
a.create_time createTime,
a.update_user updateUser,
a.update_time updateTime,
(select classify from book_group_classify b where b.id=a.classify_id) classify
from ad_news_group a
where a.is_delete=0 and a.ad_news_set_id=#{adNewsSetId}
</select>
</mapper>
\ No newline at end of file
......@@ -35,7 +35,7 @@
c.wechat_name wechatName,
b.title,
b.short_url shortUrl,
a.custom_content customContent
a.custom_content customContent,
a.content_type contentType
FROM
ad_news_group_record a
......@@ -113,7 +113,7 @@
</update>
<!--批量新增-->
<insert id="batchInsert" useGeneratedKeys="true" parameterType="java.util.List">
<insert id="batchInsert" useGeneratedKeys="true" keyProperty="id" parameterType="java.util.List">
insert into ad_news_group_record (
message_statistic_id,
qrcode_id,
......
......@@ -36,7 +36,9 @@
b.pur_label_id purLabelId,
a.message_count messageCount,
a.create_time createTime,
a.content_from contentFrom
a.content_from contentFrom,
(SELECT COUNT(1) FROM ad_news_click_record x WHERE x.message_statistic_id=a.id) click_count,
(SELECT COUNT(DISTINCT wechat_user_id) FROM ad_news_click_record x WHERE x.message_statistic_id=a.id) user_count
FROM
ad_news_message_statistic a
INNER JOIN book_group b ON a.book_group_id = b.id
......
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