Commit 214207bf authored by 王明生's avatar 王明生

feats: 优化代码,增加成员ID和数据更新时间

parent 9125e610
...@@ -16,23 +16,21 @@ import java.time.LocalDate; ...@@ -16,23 +16,21 @@ import java.time.LocalDate;
public interface XiaoHongShuMemberDayMapper extends BaseMapper<XiaoHongShuMemberDay> { public interface XiaoHongShuMemberDayMapper extends BaseMapper<XiaoHongShuMemberDay> {
@Select("select a.matrix_member_id,b.matrix_member_name as member_name,b.matrix_member_code as member_code,\n" + @Select("select * \n" +
" b.area_name,b.village_name,b.principal_name,b.province_name,b.city_name,\n" +
" a.statistics_day as stats_date,a.fans_count_total as fans_cnt_total,\n" +
" a.fans_count_total_di as fans_cnt_di,a.note_count_di as note_cnt_di,\n" +
" a.note_digg_count_di as note_like_cnt_di,a.note_collect_count_di as note_collect_count_di,\n" +
" a.note_share_count_di as note_share_cnt_di \n" +
"from dws_xiaohongshu_member_action_day a \n" + "from dws_xiaohongshu_member_action_day a \n" +
"inner join dim_matrix_member_info b on a.matrix_member_id =b.matrix_member_id\n" +
"where 1=1 \n" + "where 1=1 \n" +
"and statistics_day >= #{startDate}\n" + "and statistics_day >= #{startDate}\n" +
"and statistics_day <= #{endDate}\n" + "and statistics_day <= #{endDate}\n" +
"and principal_id=#{principalId} \n" + "and matrix_member_id in (\n" +
"and end_time='2099-01-01' \n" + " select matrix_member_id \n" +
"and is_valid=1 \n" + " from dim_matrix_member_info \n" +
" where principal_id=#{principalId} \n" +
" and is_valid=1 \n" +
" and end_time ='2099-01-01'" +
") \n" +
"order by statistics_day,a.matrix_member_id" "order by statistics_day,a.matrix_member_id"
) )
Page<BydXiaoHongShuMemberDayVO> queryMemberDayByPrincipalId( Page<XiaoHongShuMemberDay> queryMemberDayByPrincipalId(
Page page, Page page,
@Param("principalId") String principalId, @Param("principalId") String principalId,
@Param("startDate") LocalDate startDate, @Param("startDate") LocalDate startDate,
......
...@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; ...@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Data; import lombok.Data;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -92,12 +93,12 @@ public class XiaoHongShuAuthorDay extends BaseADB{ ...@@ -92,12 +93,12 @@ public class XiaoHongShuAuthorDay extends BaseADB{
/** /**
* 数据更新时间 * 数据更新时间
*/ */
private Date mtime; private LocalDateTime mtime;
/** /**
* 数据创建时间 * 数据创建时间
*/ */
private Date ctime; private LocalDateTime ctime;
/** /**
* 成员ID数组 * 成员ID数组
......
...@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableName; ...@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Data; import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
@Data @Data
...@@ -50,17 +52,17 @@ public class XiaoHongShuMemberDay { ...@@ -50,17 +52,17 @@ public class XiaoHongShuMemberDay {
/** /**
* 统计日期,YYYY-MM-DD 00:00:00 * 统计日期,YYYY-MM-DD 00:00:00
*/ */
private Date statisticsDay; private LocalDate statisticsDay;
/** /**
* 数据更新时间 * 数据更新时间
*/ */
private Date mtime; private LocalDateTime mtime;
/** /**
* 数据创建时间 * 数据创建时间
*/ */
private Date ctime; private LocalDateTime ctime;
/** /**
* 本日笔记发布数 * 本日笔记发布数
......
...@@ -48,6 +48,8 @@ public class BydXiaoHongShuAuthorDayVO { ...@@ -48,6 +48,8 @@ public class BydXiaoHongShuAuthorDayVO {
private Integer noteFavoriteCntDi; private Integer noteFavoriteCntDi;
@ApiModelProperty(value = "笔记分享新增数", example = "200") @ApiModelProperty(value = "笔记分享新增数", example = "200")
private Integer noteShareCntDi; private Integer noteShareCntDi;
@ApiModelProperty(value = "数据更新时间", example = "....")
private LocalDateTime dataUpdateTime;
@Data @Data
public static class MemberInfo { public static class MemberInfo {
......
...@@ -6,7 +6,7 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -6,7 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.time.LocalDateTime;
@Data @Data
@JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class) @JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class)
...@@ -22,12 +22,14 @@ public class BydXiaoHongShuMemberDayVO { ...@@ -22,12 +22,14 @@ public class BydXiaoHongShuMemberDayVO {
* " a.statistics_day,a.fans_count_total,a.fans_count_total_di,a.note_count_di,\n" + * " a.statistics_day,a.fans_count_total,a.fans_count_total_di,a.note_count_di,\n" +
* " a.note_digg_count_di,a.note_collect_count_di,a.note_share_count_di \n" + * " a.note_digg_count_di,a.note_collect_count_di,a.note_share_count_di \n" +
*/ */
@ApiModelProperty(value = "品牌名称", example = "比亚迪-海洋") @ApiModelProperty(value = "门店ID", example = "A12345")
private String principalName; private String memberId;
@ApiModelProperty(value = "门店名称", example = "南京宁星") @ApiModelProperty(value = "门店名称", example = "南京宁星")
private String memberName; private String memberName;
@ApiModelProperty(value = "门店编码", example = "ABC123") @ApiModelProperty(value = "门店编码", example = "ABC123")
private String memberCode; private String memberCode;
@ApiModelProperty(value = "品牌名称", example = "比亚迪-海洋")
private String principalName;
@ApiModelProperty(value = "大区名称", example = "大区名称1") @ApiModelProperty(value = "大区名称", example = "大区名称1")
private String areaName; private String areaName;
@ApiModelProperty(value = "小区名称", example = "200") @ApiModelProperty(value = "小区名称", example = "200")
...@@ -50,7 +52,9 @@ public class BydXiaoHongShuMemberDayVO { ...@@ -50,7 +52,9 @@ public class BydXiaoHongShuMemberDayVO {
@ApiModelProperty(value = "笔记评论新增数", example = "200") @ApiModelProperty(value = "笔记评论新增数", example = "200")
private Integer noteCommentCntDi; private Integer noteCommentCntDi;
@ApiModelProperty(value = "笔记收藏新增数", example = "200") @ApiModelProperty(value = "笔记收藏新增数", example = "200")
private Integer noteFavoriteCntDi; private Integer noteCollectCntDi;
@ApiModelProperty(value = "笔记分享新增数", example = "200") @ApiModelProperty(value = "笔记分享新增数", example = "200")
private Integer noteShareCntDi; private Integer noteShareCntDi;
@ApiModelProperty(value = "数据更新时间", example = "....")
private LocalDateTime dataUpdateTime;
} }
...@@ -12,7 +12,6 @@ import com.afanticar.core.entity.EsBaseQuery; ...@@ -12,7 +12,6 @@ import com.afanticar.core.entity.EsBaseQuery;
import com.afanticar.core.entity.InnerHits; import com.afanticar.core.entity.InnerHits;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -43,11 +42,40 @@ public class BydOpenService { ...@@ -43,11 +42,40 @@ public class BydOpenService {
public BasePageVO<BydXiaoHongShuMemberDayVO> fetchMemberDaySnap(PrincipalEnum principal, public BasePageVO<BydXiaoHongShuMemberDayVO> fetchMemberDaySnap(PrincipalEnum principal,
LocalDate startDate, LocalDate endDate, Integer currentPage, Integer pageSize){ LocalDate startDate, LocalDate endDate, Integer currentPage, Integer pageSize){
Page<BydXiaoHongShuMemberDayVO> page = new Page<>(currentPage, pageSize); Page<BydXiaoHongShuMemberDayVO> page = new Page<>(currentPage, pageSize);
Page<BydXiaoHongShuMemberDayVO> data = memberDayMapper.queryMemberDayByPrincipalId(page, principal.id, startDate, endDate); Page<XiaoHongShuMemberDay> data = memberDayMapper.queryMemberDayByPrincipalId(page, principal.id, startDate, endDate);
List<String> memberIds = data.getRecords().stream().map(XiaoHongShuMemberDay::getMatrixMemberId).distinct().collect(Collectors.toList());
Map<String, MemberInfo> memberInfos = memberInfoMapper
.queryMemberInfoListByMemberIds(memberIds.isEmpty()? Collections.singletonList("XXX") : memberIds)
.stream().distinct()
.collect(Collectors.toMap(MemberInfo::getMatrixMemberId, Function.identity()));
List<BydXiaoHongShuMemberDayVO> voList = data.getRecords().stream().map(x->{
BydXiaoHongShuMemberDayVO vo = new BydXiaoHongShuMemberDayVO();
vo.setMemberId(x.getMatrixMemberId());
MemberInfo info = memberInfos.get(x.getMatrixMemberId());
if (Objects.nonNull(info)) {
vo.setMemberName(info.getMatrixMemberName());
vo.setMemberCode(info.getMatrixMemberCode());
vo.setPrincipalName(info.getPrincipalName());
vo.setAreaName(info.getAreaName());
vo.setVillageName(info.getVillageName());
vo.setCityName(info.getCityName());
vo.setProvinceName(info.getProvinceName());
}
vo.setStatsDate(x.getStatisticsDay());
vo.setFansCntTotal(x.getFansCountTotal());
vo.setFansCntDi(x.getFansCountTotalDi());
vo.setNoteCntDi(x.getNoteCountDi());
vo.setNoteLikeCntDi(x.getNoteDiggCountDi());
vo.setNoteCommentCntDi(x.getNoteCommentCountDi());
vo.setNoteCollectCntDi(x.getNoteCollectCountDi());
vo.setNoteShareCntDi(x.getNoteShareCountDi());
return vo;
}).collect(Collectors.toList());
// List<String> memberIds = data.stream().map(XiaoHongShuMemberDay::getMatrixMemberId).collect(Collectors.toList()); // List<String> memberIds = data.stream().map(XiaoHongShuMemberDay::getMatrixMemberId).collect(Collectors.toList());
// List<MemberInfo> memberInfos = memberInfoMapper.queryMemberInfoListByMemberIds(memberIds); // List<MemberInfo> memberInfos = memberInfoMapper.queryMemberInfoListByMemberIds(memberIds);
return BasePageVO.restPage((int) data.getCurrent(), (int) data.getSize(), (int) data.getTotal(), (int) data.getPages(), data.getRecords()); return BasePageVO.restPage((int) data.getCurrent(), (int) data.getSize(), (int) data.getTotal(), (int) data.getPages(), voList);
} }
...@@ -108,6 +136,7 @@ public class BydOpenService { ...@@ -108,6 +136,7 @@ public class BydOpenService {
vo.setNoteCommentCntDi(x.getNoteCommentCountDi()); vo.setNoteCommentCntDi(x.getNoteCommentCountDi());
vo.setNoteFavoriteCntDi(x.getCollectCountDi()); vo.setNoteFavoriteCntDi(x.getCollectCountDi());
vo.setNoteShareCntDi(x.getNoteShareCountDi()); vo.setNoteShareCntDi(x.getNoteShareCountDi());
vo.setDataUpdateTime(x.getMtime());
return vo; return vo;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
......
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