Commit 138d81f3 138d81f33d6c02e0585df1f5d30b7c91ad73b837 by 张云鹏

内容访问统计

1 parent c42d214b
Showing 18 changed files with 641 additions and 0 deletions
package com.topdraw.business.module.content.all.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author XiangHan
* @date 2022-02-26
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="content_pv_uv")
public class ContentPVUV implements Serializable {
// ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 活动按钮id
@Column(name = "template_param_value_id", nullable = false)
private Long templateParamValueId;
@Column(name = "btn_name", nullable = false)
private String btnName;
// 显示用名称,表示哪个按钮或者内容
@Column(name = "code", nullable = false)
private String code;
// 显示用名称,表示哪个按钮或者内容
@Column(name = "name", nullable = false)
private String name;
// pv值
@Column(name = "pv", nullable = false)
private Integer pv;
// uv值
@Column(name = "uv", nullable = false)
private Integer uv;
@Column(name = "lp_id")
private Long lpId;
@Column(name = "site_id")
private Long siteId;
// 创建时间
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(ContentPVUV source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.content.all.repository;
import com.topdraw.business.module.content.all.domain.ContentPVUV;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.Optional;
public interface ContentPVUVRepository extends JpaRepository<ContentPVUV, Long>, JpaSpecificationExecutor<ContentPVUV> {
Optional<ContentPVUV> findByTemplateParamValueIdAndCode(Long templateParamValueId, String code);
}
package com.topdraw.business.module.content.all.service;
import com.topdraw.business.module.content.all.domain.ContentPVUV;
public interface ContentPVUVService {
void create(ContentPVUV resources);
void update(ContentPVUV resources);
ContentPVUV findByBtnIdAndCode(Long btnId, String code);
}
package com.topdraw.business.module.content.all.service.impl;
import com.topdraw.business.module.content.all.domain.ContentPVUV;
import com.topdraw.business.module.content.all.repository.ContentPVUVRepository;
import com.topdraw.business.module.content.all.service.ContentPVUVService;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class ContentPVUVServiceImpl implements ContentPVUVService {
@Autowired
private ContentPVUVRepository contentPVUVRepository;
@Override
@Transactional(rollbackFor = Exception.class)
public void create(ContentPVUV resources) {
contentPVUVRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(ContentPVUV resources) {
ContentPVUV PvUv = contentPVUVRepository.findById(resources.getId()).orElseGet(ContentPVUV::new);
ValidationUtil.isNull( PvUv.getId(),"PvUv","id",resources.getId());
PvUv.copy(resources);
contentPVUVRepository.save(PvUv);
}
public ContentPVUV findByBtnIdAndCode(Long btnId, String code){
return contentPVUVRepository.findByTemplateParamValueIdAndCode(btnId, code).orElseGet(ContentPVUV::new);
}
}
package com.topdraw.business.module.content.day.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author XiangHan
* @date 2022-02-26
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="content_pv_uv_day")
public class ContentPVUVDay implements Serializable {
// ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 活动按钮id
@Column(name = "template_param_value_id", nullable = false)
private Long templateParamValueId;
@Column(name = "btn_name", nullable = false)
private String btnName;
// 显示用名称,表示哪个按钮或者内容
@Column(name = "code", nullable = false)
private String code;
// 显示用名称,表示哪个按钮或者内容
@Column(name = "name", nullable = false)
private String name;
// pv值
@Column(name = "pv", nullable = false)
private Integer pv;
// uv值
@Column(name = "uv", nullable = false)
private Integer uv;
@Column(name = "lp_id")
private Long lpId;
@Column(name = "site_id")
private Long siteId;
@Column(name = "day")
private String day;
// 创建时间
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(ContentPVUVDay source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.content.day.repository;
import com.topdraw.business.module.content.day.domain.ContentPVUVDay;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.Optional;
public interface ContentPVUVDayRepository extends JpaRepository<ContentPVUVDay, Long>, JpaSpecificationExecutor<ContentPVUVDay> {
Optional<ContentPVUVDay> findByTemplateParamValueIdAndCodeAndDay(Long templateParamValueId, String code, String day);
}
package com.topdraw.business.module.content.day.service;
import com.topdraw.business.module.content.day.domain.ContentPVUVDay;
public interface ContentPVUVDayService {
void create(ContentPVUVDay resources);
void update(ContentPVUVDay resources);
ContentPVUVDay findByBtnIdAndCodeAndDay(Long btnId, String code, String day);
}
package com.topdraw.business.module.content.day.service.impl;
import com.topdraw.business.module.content.day.domain.ContentPVUVDay;
import com.topdraw.business.module.content.day.repository.ContentPVUVDayRepository;
import com.topdraw.business.module.content.day.service.ContentPVUVDayService;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class ContentPVUVDayServiceImpl implements ContentPVUVDayService {
@Autowired
private ContentPVUVDayRepository contentPVUVRepository;
@Override
@Transactional(rollbackFor = Exception.class)
public void create(ContentPVUVDay resources) {
contentPVUVRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(ContentPVUVDay resources) {
ContentPVUVDay PvUv = contentPVUVRepository.findById(resources.getId()).orElseGet(ContentPVUVDay::new);
ValidationUtil.isNull( PvUv.getId(),"PvUv","id",resources.getId());
PvUv.copy(resources);
contentPVUVRepository.save(PvUv);
}
public ContentPVUVDay findByBtnIdAndCodeAndDay(Long btnId, String code, String day){
return contentPVUVRepository.findByTemplateParamValueIdAndCodeAndDay(btnId, code, day).orElseGet(ContentPVUVDay::new);
}
}
package com.topdraw.business.module.content.hour.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author XiangHan
* @date 2022-02-26
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name="content_pv_uv_hour")
public class ContentPVUVHour implements Serializable {
// ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 活动按钮id
@Column(name = "template_param_value_id", nullable = false)
private Long templateParamValueId;
@Column(name = "btn_name", nullable = false)
private String btnName;
// 显示用名称,表示哪个按钮或者内容
@Column(name = "code", nullable = false)
private String code;
// 显示用名称,表示哪个按钮或者内容
@Column(name = "name", nullable = false)
private String name;
// pv值
@Column(name = "pv", nullable = false)
private Integer pv;
// uv值
@Column(name = "uv", nullable = false)
private Integer uv;
@Column(name = "lp_id")
private Long lpId;
@Column(name = "site_id")
private Long siteId;
@Column(name = "day")
private String day;
@Column(name = "hour")
private Integer hour;
// 创建时间
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(ContentPVUVHour source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.content.hour.repository;
import com.topdraw.business.module.content.hour.domain.ContentPVUVHour;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.Optional;
public interface ContentPVUVHourRepository extends JpaRepository<ContentPVUVHour, Long>, JpaSpecificationExecutor<ContentPVUVHour> {
Optional<ContentPVUVHour> findByTemplateParamValueIdAndCodeAndDayAndHour(Long templateParamValueId, String code, String day, Integer hour);
}
package com.topdraw.business.module.content.hour.service;
import com.topdraw.business.module.content.hour.domain.ContentPVUVHour;
public interface ContentPVUVHourService {
void create(ContentPVUVHour resources);
void update(ContentPVUVHour resources);
ContentPVUVHour findByBtnIdAndCodeAndDayAndHour(Long btnId, String code, String day, Integer hour);
}
package com.topdraw.business.module.content.hour.service.impl;
import com.topdraw.business.module.content.hour.domain.ContentPVUVHour;
import com.topdraw.business.module.content.hour.repository.ContentPVUVHourRepository;
import com.topdraw.business.module.content.hour.service.ContentPVUVHourService;
import com.topdraw.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class ContentPVUVHourServiceImpl implements ContentPVUVHourService {
@Autowired
private ContentPVUVHourRepository contentPVUVRepository;
@Override
@Transactional(rollbackFor = Exception.class)
public void create(ContentPVUVHour resources) {
contentPVUVRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(ContentPVUVHour resources) {
ContentPVUVHour PvUv = contentPVUVRepository.findById(resources.getId()).orElseGet(ContentPVUVHour::new);
ValidationUtil.isNull( PvUv.getId(),"PvUv","id",resources.getId());
PvUv.copy(resources);
contentPVUVRepository.save(PvUv);
}
public ContentPVUVHour findByBtnIdAndCodeAndDayAndHour(Long btnId, String code, String day, Integer hour){
return contentPVUVRepository.findByTemplateParamValueIdAndCodeAndDayAndHour(btnId, code, day, hour).orElseGet(ContentPVUVHour::new);
}
}
package com.topdraw.business.module.template.domain;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author zhang sheng xiang
* @date 2021-09-07
*/
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
@Table(name = "tp_template_param_value")
public class TemplateParamValue implements Serializable {
// ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 名称
@Column(name = "name")
private String name;
// 标识
@Column(name = "code")
private String code;
//模板参数id
@Column(name = "template_param_id")
private Long templateParamId;
// 模板关联实体类型 1: 活动类型;2:专题类型;3:页面类型
@Column(name = "content_type")
private Integer contentType;
// 模板关联实体id
@Column(name = "content_id")
private Long contentId;
// 参数类型 0:实体;1:常量;2:虚拟实体;3:图片
@Column(name = "type", nullable = false)
private Integer type;
// 组键
@Column(name = "`group`")
private String group;
// 组名称
@Column(name = "group_name")
private String groupName;
// 实体类型(仅当参数类型为实体时有效)
@Column(name = "entity")
private String entity;
// 值(实体类型下为实体id,常量类型下为常量值,虚拟实体和图片此属性无效)
@Column(name = "`value`")
private String value;
// 资源标志符,供模板引擎识别调度
@Column(name = "`uri`")
private String uri;
// 对象标识
@Column(name = "obj_code")
private String objCode;
// 描述
@Column(name = "description")
private String description;
// 图片
@Column(name = "image")
private String image;
// 图片
@Column(name = "images")
private String images;
// 顺序
@Column(name = "sequence", nullable = false)
private Integer sequence;
@Column(name = "component_data")
private String componentData;
// 组内顺序
@Column(name = "group_index")
private Integer groupIndex;
//事件类型 0:抽奖;1:投票;2:答题;3:闯关;4:签到(当entity是activity时生效)
@Column(name = "activity_type")
private Integer activity_type;
//当前页面标识
@Column(name = "page_code")
private String pageCode;
@Column(name = "page_title")
private String pageTitle;
//展现形式
@Column(name = "display_form")
private Integer displayForm;
@Column(name = "top")
private Integer top;
@Column(name = "`left`")
private Integer left;
@Column(name = "width")
private Integer width;
@Column(name = "height")
private Integer height;
// 创建时间
@CreatedDate
@Column(name = "create_time")
private Timestamp createTime;
// 更新时间
@LastModifiedDate
@Column(name = "update_time")
private Timestamp updateTime;
public void copy(TemplateParamValue source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}
package com.topdraw.business.module.template.repository;
import com.topdraw.business.module.template.domain.TemplateParamValue;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
public interface TemplateParamValueRepository extends JpaRepository<TemplateParamValue, Long>, JpaSpecificationExecutor<TemplateParamValue> {
List<TemplateParamValue> findByIdIn(List<Long> ids);
}
package com.topdraw.business.module.template.service;
import java.util.List;
import java.util.Map;
public interface TemplateParamValueService {
Map<Long, String> btnNames(List<Long> btnIds);
}
package com.topdraw.business.module.template.service.impl;
import com.topdraw.business.module.template.domain.TemplateParamValue;
import com.topdraw.business.module.template.repository.TemplateParamValueRepository;
import com.topdraw.business.module.template.service.TemplateParamValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class TemplateParamValueServiceImpl implements TemplateParamValueService {
@Autowired
private TemplateParamValueRepository templateParamValueRepository;
public Map<Long, String> btnNames(List<Long> btnIds){
List<TemplateParamValue> list = templateParamValueRepository.findByIdIn(btnIds);
Map<Long, String> result = list.stream().collect(Collectors.toMap(TemplateParamValue::getId, TemplateParamValue::getName));
return result;
}
}
package com.topdraw.schedule;
import com.topdraw.business.process.calculate.task.ContentCalculateTask;
import com.topdraw.business.process.calculate.task.PvUvCalculateTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
@Component
@Slf4j
@EnableScheduling
public class TransferContentScheduleTask {
@Autowired
private ContentCalculateTask contentCalculateTask;
@Value("${cronContent:0 0/5 * * * ?}")
private String cron;
public String cron(){
return cron;
}
/**
* 统计pv、uv
*/
@Scheduled(cron = "#{transferContentScheduleTask.cron()}")
public void calculatePvUv2Mysql(){
log.info("专题内容pv、uv统计 ===>>> 开始 !!!" + LocalDateTime.now());
this.contentCalculateTask.calculateRedisData2Mysql();
}
}