Authored by 张帅

增加检查接口

Showing 30 changed files with 998 additions and 92 deletions
... ... @@ -10,4 +10,5 @@ import java.util.List;
public interface GrassArticleBlockRepository extends JpaRepository<GrassArticleBlock, Integer>{
List<GrassArticleBlock> findAllByArticleIdInAndStatusIs( List<Integer> articleId, Integer status);
int countByArticleIdInAndStatusIs( List<Integer> articleId, Integer status);
}
... ...
... ... @@ -14,10 +14,14 @@ public interface GrassArticleCommentRepository extends JpaRepository<GrassArticl
int countByCreateTimeBetween(Integer startTime, Integer endTime);
List<GrassArticleComment> findAllByCreateTimeBetween(Integer startTime, Integer endTime, Pageable pageable);
List<GrassArticleComment> findAllByCreateTimeBetween(Integer startTime, Integer endTime);
List<GrassArticleComment> findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNull(List<Integer> articleIds, List<Integer> articleTypes,Integer status);
List<GrassArticleComment> findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNullAndCreateTimeAfter(List<Integer> articleIds, List<Integer> articleTypes,Integer status,Integer beginTime);
List<GrassArticleComment> findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNotNullAndCreateTimeAfter(List<Integer> articleIds, List<Integer> articleTypes,Integer status,Integer beginTime);
int countByDestIdInAndArticleTypeInAndStatusIsNotAndCreateTimeAfter(List<Integer> articleIds, List<Integer> articleTypes,Integer status,Integer beginTime);
List<GrassArticleComment> findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNotNull(List<Integer> articleIds, List<Integer> articleTypes,Integer status);
}
... ...
... ... @@ -10,4 +10,6 @@ import java.util.List;
public interface GrassArticleLabelRepository extends JpaRepository<GrassArticleLabel, Integer>{
List<GrassArticleLabel> findAllByArticleIdInAndAuthStatusIn(List<Integer> articleId, List<Integer> status);
int countByArticleIdInAndAuthStatusIn(List<Integer> articleId, List<Integer> status);
}
... ...
... ... @@ -10,9 +10,13 @@ import java.util.List;
@Repository
public interface GrassArticlePraiseRepository extends JpaRepository<GrassArticlePraise, Integer>{
List<GrassArticlePraise> findAllByArticleIdIn(List<Integer> list);
List<GrassArticlePraise> findAllByArticleIdInAndCreateTimeAfter(List<Integer> list, Integer createTime);
int countByArticleIdInAndCreateTimeAfter(List<Integer> list, Integer createTime);
int countByCreateTimeBetween(Integer startTime, Integer endTime);
List<GrassArticlePraise> findAllByCreateTimeBetween(Integer startTime, Integer endTime, Pageable pageable);
List<GrassArticlePraise> findAllByCreateTimeBetween(Integer startTime, Integer endTime);
}
... ...
... ... @@ -10,4 +10,5 @@ import java.util.List;
public interface GrassArticleProductRepository extends JpaRepository<GrassArticleProduct, Integer>{
List<GrassArticleProduct> findAllByArticleIdInAndStatusIs(List<Integer> articleId, Integer status);
int countByArticleIdInAndStatusIs(List<Integer> articleId, Integer status);
}
... ...
... ... @@ -12,7 +12,10 @@ public interface GrassArticleRepository extends JpaRepository<GrassArticle, Inte
int countByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(long startTime, long endTime,List<Integer> list,List<Integer> statusList);
List<GrassArticle> findAllByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(long startTime, long endTime,List<Integer> list,List<Integer> statusList, Pageable pageable);
List<GrassArticle> findAllByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(long startTime, long endTime,List<Integer> list,
List<Integer> statusList, Pageable pageable);
List<GrassArticle> findAllByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(long startTime, long endTime,List<Integer> list,
List<Integer> statusList);
List<GrassArticle> findAllByIdIn(List<Integer> articleIds);
}
... ...
package com.yoho.datasync.fullsync.dal.repository.grass;
import com.yoho.datasync.fullsync.dal.repository.grass.model.GrassCommentPraise;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface GrassCommentPraiseRepository extends JpaRepository<GrassCommentPraise, Integer>{
int countByCreateTimeBetween(Integer startTime, Integer endTime);
List<GrassCommentPraise> findAllByCreateTimeBetween(Integer startTime, Integer endTime, Pageable pageable);
List<GrassCommentPraise> findAllByCreateTimeBetween(Integer startTime, Integer endTime);
}
... ...
... ... @@ -12,5 +12,7 @@ public interface GrassUserAttentionRepository extends JpaRepository<GrassUserAtt
int countByCreateTimeBetween(Integer startTime, Integer endTime);
List<GrassUserAttention> findAllByCreateTimeBetween(Integer startTime, Integer endTime, Pageable pageable);
List<GrassUserAttention> findAllByCreateTimeBetweenAndCreateTimeAfter(Integer startTime, Integer endTime,Integer beginTime, Pageable pageable);
List<GrassUserAttention> findAllByCreateTimeBetweenAndCreateTimeAfter(Integer startTime, Integer endTime,Integer beginTime);
}
... ...
... ... @@ -10,9 +10,14 @@ import java.util.List;
@Repository
public interface UserFavoriteArticleRepository extends JpaRepository<UserFavoriteArticle, Integer>{
List<UserFavoriteArticle> findAllByArticleIdIn(List<Integer> list);
List<UserFavoriteArticle> findAllByArticleIdInAndCreateTimeAfter(List<Integer> list, Integer createTime);
int countByCreateTimeBetween(Integer startTime, Integer endTime);
List<UserFavoriteArticle> findAllByCreateTimeBetween(Integer startTime, Integer endTime, Pageable pageable);
List<UserFavoriteArticle> findAllByCreateTimeBetween(Integer startTime, Integer endTime);
int countByArticleIdInAndCreateTimeAfter(List<Integer> list, Integer createTime);
}
... ...
package com.yoho.datasync.fullsync.dal.repository.grass.model;
import com.yoho.datasync.fullsync.dal.repository.BaseEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
@Entity
@Table(name = "grass_comment_praise")
public class GrassCommentPraise extends BaseEntity implements Serializable {
private static final long serialVersionUID = -2270181821264128734L;
@Column(name = "comment_id")
private Integer commentId;
private Integer uid;
@Column(name = "create_time")
private Integer createTime;
@Column(name = "update_time")
private Integer updateTime;
@Column
private Integer status;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCommentId() {
return commentId;
}
public void setCommentId(Integer commentId) {
this.commentId = commentId;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
}
... ...
... ... @@ -4,8 +4,11 @@ import com.yoho.datasync.fullsync.dal.repository.pcms.model.PublicArticleBlock;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface PublicArticleBlockRepository extends JpaRepository<PublicArticleBlock, Integer> {
int countByArticleIdIn(List<Integer> articleIds);
}
... ...
... ... @@ -9,4 +9,5 @@ import java.util.List;
@Repository
public interface PublicArticleLabelRepository extends JpaRepository<PublicArticleLabel, Integer>{
int countByArticleIdIn(List<Integer> list);
}
... ...
package com.yoho.datasync.fullsync.dal.repository.pcms;
import com.yoho.datasync.fullsync.dal.repository.pcms.model.PublicArticleBlock;
import com.yoho.datasync.fullsync.dal.repository.pcms.model.PublicArticleProduct;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface PublicArticleProductRepository extends JpaRepository<PublicArticleProduct, Integer> {
int countByArticleIdIn(List<Integer> list);
}
... ...
... ... @@ -10,4 +10,6 @@ import java.util.List;
public interface PublicArticleRepository extends JpaRepository<PublicArticle, Integer> {
List<PublicArticle> findAllByRelateIdInAndArticleTypeIn(List<Integer> relateIds, List<Integer> types);
int countByRelateIdInAndArticleTypeIn(List<Integer> relateIds, List<Integer> types);
}
... ...
... ... @@ -4,8 +4,10 @@ import com.yoho.datasync.fullsync.dal.repository.pcms.model.PublicUserAttention;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface PublicUserAttentionRepository extends JpaRepository<PublicUserAttention, Integer>{
int countByTargetIdInAndUidInAndAttentionTypeIsAndSrcChannelIsAndCreateTimeBetween(List<Integer> targetIds,List<Integer> uids,Integer attentionType,Integer srcChannel, Long startTime,Long endTIme);
}
... ...
... ... @@ -10,4 +10,8 @@ import java.util.List;
public interface PublicUserCommentRepository extends JpaRepository<PublicUserComment, Integer>{
List<PublicUserComment> findAllByRelateIdInAndSrcChannelIs(List<Integer> relateIds, Integer srcChannel);
int countByArticleIdInAndSrcChannelIs(List<Integer> articleIds, Integer src_channel);
int countByArticleIdInAndSrcChannelIsAndCreateTimeBetween(List<Integer> articleIds, Integer src_channel,Long startTime, Long endTime);
}
... ...
... ... @@ -4,8 +4,14 @@ import com.yoho.datasync.fullsync.dal.repository.pcms.model.PublicUserFavorite;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface PublicUserFavoriteRepository extends JpaRepository<PublicUserFavorite, Integer>{
int countByTargetIdInAndFavoriteTypeIsAndSrcChannelIs(List<Integer> ids, Integer favoriteType, Integer srcChannel);
int countByTargetIdInAndFavoriteTypeIsAndSrcChannelIsAndCreateTimeBetween(List<Integer> ids, Integer favoriteType, Integer srcChannel, Long satrtTime, Long endTime);
}
... ...
... ... @@ -8,4 +8,5 @@ import org.springframework.stereotype.Repository;
public interface PublicUserHomePageRepository extends JpaRepository<PublicUserHomePage, Integer>{
int countByCreateTimeBetween(Long startTime, Long endTime);
}
... ...
... ... @@ -9,5 +9,7 @@ import java.util.List;
@Repository
public interface PublicUserPraiseRepository extends JpaRepository<PublicUserPraise, Integer>{
int countByTargetIdInAndPraiseTypeIsAndSrcChannelIs(List<Integer> ids, Integer type,Integer src_channel);
int countByTargetIdInAndPraiseTypeIsAndSrcChannelIsAndCreateTimeBetween(List<Integer> ids, Integer type,Integer src_channel,Long startTime, Long endTime);
}
... ...
... ... @@ -7,5 +7,5 @@ import org.springframework.stereotype.Repository;
@Repository
public interface PublicVirtualUserRepository extends JpaRepository<PublicVirtualUser, Integer>{
int countByCreateTimeBetween(Integer startTime, Integer endTime);
}
... ...
... ... @@ -3,6 +3,7 @@ package com.yoho.datasync.fullsync.dal.repository.pcms.model;
import com.yoho.datasync.fullsync.dal.repository.BaseEntity;
import lombok.EqualsAndHashCode;
import javax.persistence.Column;
import javax.persistence.Entity;
... ... @@ -11,6 +12,7 @@ import java.io.Serializable;
@Entity
@Table(name = "public_virtual_user")
@EqualsAndHashCode(callSuper = true)
public class PublicVirtualUser extends BaseEntity implements Serializable {
private static final long serialVersionUID = -2270181821264128734L;
... ...
package com.yoho.datasync.fullsync.controller;
import com.alibaba.fastjson.JSONObject;
import com.yoho.datasync.fullsync.service.IGrassArticleDataCheckService;
import com.yoho.datasync.fullsync.service.IGrassInteractiveDataCheckService;
import com.yoho.datasync.fullsync.service.IGrassUserDataCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GrassDataCheckController {
@Autowired
private IGrassArticleDataCheckService grassArticleDataCheckService;
@Autowired
private IGrassInteractiveDataCheckService grassInteractiveDataCheckService;
@Autowired
private IGrassUserDataCheckService grassUserDataCheckService;
@RequestMapping("/checkArticleData")
public JSONObject checkArticleData(@RequestParam("startTime") Long startTime, @RequestParam("endTime") Long endTime){
return grassArticleDataCheckService.checkArticleData(startTime, endTime);
}
@RequestMapping("/checkInteractiveData")
public JSONObject checkInteractiveData(@RequestParam("startTime") Integer startTime, @RequestParam("endTime") Integer endTime,
@RequestParam("timeType") Integer timeType, @RequestParam("syncType") Integer syncType){
return grassInteractiveDataCheckService.checkInteractiveData(startTime, endTime, timeType, syncType);
}
@RequestMapping("/checkUserData")
public JSONObject checkUserData(@RequestParam("startTime") Integer startTime, @RequestParam("endTime") Integer endTime,
@RequestParam("syncType") Integer syncType){
return grassUserDataCheckService.checkGrassUserData(startTime, endTime, syncType);
}
}
... ...
package com.yoho.datasync.fullsync.service;
import com.alibaba.fastjson.JSONObject;
public interface IGrassArticleDataCheckService {
JSONObject checkArticleData(Long startTime, Long endTime);
}
... ...
package com.yoho.datasync.fullsync.service;
import com.alibaba.fastjson.JSONObject;
public interface IGrassInteractiveDataCheckService {
JSONObject checkInteractiveData(Integer startTime, Integer endTime, Integer timeType, Integer syncType);
}
... ...
package com.yoho.datasync.fullsync.service;
import com.alibaba.fastjson.JSONObject;
public interface IGrassUserDataCheckService {
JSONObject checkGrassUserData(Integer startTime, Integer endTime, Integer syncType);
}
... ...
package com.yoho.datasync.fullsync.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.yoho.datasync.fullsync.dal.repository.BaseEntity;
import com.yoho.datasync.fullsync.dal.repository.grass.*;
import com.yoho.datasync.fullsync.dal.repository.grass.model.*;
import com.yoho.datasync.fullsync.dal.repository.pcms.*;
import com.yoho.datasync.fullsync.dal.repository.pcms.model.*;
import com.yoho.datasync.fullsync.service.IGrassArticleDataCheckService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
import static com.yoho.datasync.fullsync.service.impl.GrassArticleSyncServiceImpl.needSyncArticleType;
import static com.yoho.datasync.fullsync.service.impl.GrassArticleSyncServiceImpl.needSyncArticleStatus;
@Service
public class GrassArticleDataCheckServiceImpl implements IGrassArticleDataCheckService {
private Logger logger = LoggerFactory.getLogger(GrassArticleDataCheckServiceImpl.class);
@Autowired
private GrassArticleRepository grassArticleRepository;
@Autowired
private PublicArticleRepository publicArticleRepository;
@Autowired
private GrassArticleBlockRepository grassArticleBlockRepository;
@Autowired
private PublicArticleBlockRepository publicArticleBlockRepository;
@Autowired
private GrassArticleProductRepository grassArticleProductRepository;
@Autowired
private PublicArticleProductRepository publicArticleProductRepository;
@Autowired
private GrassArticleLabelRepository grassArticleLabelRepository;
@Autowired
private PublicArticleLabelRepository publicArticleLabelRepository;
@Autowired
private GrassLabelRepository grassLabelRepository;
@Autowired
private PublicLabelRepository publicLabelRepository;
private static final String CHECK_SUCCESS = "success";
private static final String CHECK_FAIL = "fail";
@Override
public JSONObject checkArticleData(Long startTime, Long endTime) {
int grassArticleTotal = grassArticleRepository.countByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(startTime, endTime,needSyncArticleType,needSyncArticleStatus);
logger.info("checkArticleData , get grassArticleTotal is {}", grassArticleTotal);
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(
startTime, endTime,needSyncArticleType,needSyncArticleStatus);
List<Integer> grassArticleIds = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
List<Integer> publicArticleIds = publicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
int publicCount = publicArticleList.size();
logger.info("checkArticleData , get publicCount is {}", publicCount);
JSONObject result = new JSONObject();
JSONArray data = new JSONArray();
data.add(checkArticle(grassArticleTotal, publicCount));
data.add(checkArticleBlock(grassArticleIds, publicArticleIds));
data.add(checkArticleProduct(grassArticleIds, publicArticleIds));
data.add(checkArticleLabel(grassArticleIds, publicArticleIds));
result.put("data",data);
return result;
}
private JSONObject checkArticle(int grassArticleTotal, int publicCount){
JSONObject result = new JSONObject();
result.put("checkBlockResult", grassArticleTotal == publicCount? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_article_num", grassArticleTotal );
result.put("public_article_num", publicCount );
return result;
}
private JSONObject checkArticleBlock(List<Integer> grassArticleIds, List<Integer> publicArticleIds){
int grassNum = grassArticleBlockRepository.countByArticleIdInAndStatusIs(grassArticleIds, 1);
int publicNum = publicArticleBlockRepository.countByArticleIdIn(publicArticleIds);
logger.info("checkArticleBlock get grass_block_num is {}, public_block_num is {}", grassNum, publicNum);
JSONObject result = new JSONObject();
result.put("checkBlockResult", grassNum == publicNum? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_block_num", grassNum );
result.put("public_block_num", grassNum );
return result;
}
private JSONObject checkArticleProduct(List<Integer> grassArticleIds, List<Integer> publicArticleIds){
int grassNum = grassArticleProductRepository.countByArticleIdInAndStatusIs(grassArticleIds, 1);
int publicNum = publicArticleProductRepository.countByArticleIdIn(publicArticleIds);
logger.info("checkArticleProduct get grass_product_num is {}, public_product_num is {}", grassNum, publicNum);
JSONObject result = new JSONObject();
result.put("checkProductResult", grassNum == publicNum? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_product_num", grassNum );
result.put("public_product_num", grassNum );
return result;
}
private JSONObject checkArticleLabel(List<Integer> grassArticleIds, List<Integer> publicArticleIds){
List<Integer> needSyncStatus = Lists.newArrayList(0,1,2);
int grassNum = grassArticleLabelRepository.countByArticleIdInAndAuthStatusIn(grassArticleIds, needSyncStatus);
int publicNum = publicArticleLabelRepository.countByArticleIdIn(publicArticleIds);
logger.info("checkArticleLabel get grass_label_num is {}, public_label_num is {}", grassNum, publicNum);
JSONObject result = new JSONObject();
result.put("checkLabelResult", grassNum == publicNum? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_article_label_num", grassNum );
result.put("public_article_label_num", publicNum );
return result;
}
}
... ...
... ... @@ -62,7 +62,7 @@ public class GrassArticleSyncServiceImpl implements IGrassArticleSyncService {
@Autowired
private PublicArticleAuditRepository publicArticleAuditRepository;
private static List<Integer> needSyncArticleType = new ArrayList<>();
public static List<Integer> needSyncArticleType = new ArrayList<>();
public static List<Integer> needSyncArticleStatus = new ArrayList<>();
... ... @@ -203,6 +203,9 @@ public class GrassArticleSyncServiceImpl implements IGrassArticleSyncService {
}
private String getCoverImg(List<GrassArticleBlock> grassArticleBlocks){
if(CollectionUtils.isEmpty(grassArticleBlocks)){
return "";
}
grassArticleBlocks = grassArticleBlocks.stream().sorted((o1, o2) ->{
if(o1.getOrderBy()> o2.getOrderBy()){
return 1;
... ... @@ -454,10 +457,14 @@ public class GrassArticleSyncServiceImpl implements IGrassArticleSyncService {
List<PublicArticleLabel> resultList = Lists.newArrayList();
grassArticleLabels.forEach(grassArticleLabel -> {
String labelName = grassLabelIdAndlabelNameMap.get(grassArticleLabel.getLabelId());
Integer label_id = labelNameAndPublicLabelIdMap.get(labelName);
if(label_id == null){
return;
}
PublicArticleLabel publicArticleLabel = new PublicArticleLabel();
publicArticleLabel.setArticleId(publicArticleIdAndGrassIdMap.get(grassArticleLabel.getArticleId()));
publicArticleLabel.setCreateTime(grassArticleLabel.getCreateTime());
publicArticleLabel.setLabelId(labelNameAndPublicLabelIdMap.get(labelName));
publicArticleLabel.setLabelId(label_id);
publicArticleLabel.setSrcChannel(1);
resultList.add(publicArticleLabel);
});
... ...
package com.yoho.datasync.fullsync.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.yoho.datasync.fullsync.constant.UserAttentionConstant;
import com.yoho.datasync.fullsync.constant.UserCommentConstant;
import com.yoho.datasync.fullsync.constant.UserPraiseConstant;
import com.yoho.datasync.fullsync.dal.repository.BaseEntity;
import com.yoho.datasync.fullsync.dal.repository.grass.*;
import com.yoho.datasync.fullsync.dal.repository.grass.model.*;
import com.yoho.datasync.fullsync.dal.repository.pcms.*;
import com.yoho.datasync.fullsync.dal.repository.pcms.model.*;
import com.yoho.datasync.fullsync.service.IGrassInteractiveDataCheckService;
import com.yoho.datasync.fullsync.service.IGrassInteractiveDataSyncService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import static com.yoho.datasync.fullsync.service.impl.GrassInteractiveDataSyncServiceImpl.DATA_BEGIN_TIME;
import static com.yoho.datasync.fullsync.service.impl.GrassInteractiveDataSyncServiceImpl.needSyncArticleStatus;
import static com.yoho.datasync.fullsync.service.impl.GrassInteractiveDataSyncServiceImpl.needSyncArticleType;
@Service
public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDataCheckService {
private Logger logger = LoggerFactory.getLogger(GrassInteractiveDataCheckServiceImpl.class);
@Autowired
private GrassArticleRepository grassArticleRepository;
@Autowired
private GrassArticlePraiseRepository grassArticlePraiseRepository;
@Autowired
private PublicUserPraiseRepository publicUserPraiseRepository;
@Autowired
private PublicArticleRepository publicArticleRepository;
@Autowired
private UserFavoriteArticleRepository userFavoriteArticleRepository;
@Autowired
private PublicUserFavoriteRepository publicUserFavoriteRepository;
@Autowired
private GrassUserAttentionRepository grassUserAttentionRepository;
@Autowired
private PublicUserAttentionRepository publicUserAttentionRepository;
@Autowired
private GrassArticleCommentRepository grassArticleCommentRepository;
@Autowired
private PublicUserCommentRepository publicUserCommentRepository;
@Autowired
private GrassCommentPraiseRepository grassCommentPraiseRepository;
private static final int PRAISE = 1;
private static final int COMMENT = 2;
private static final int FAVORITE = 3;
private static final int ATTENTION = 4;
private static final int COMMENT_PRAISE = 5;
//根据article表的时间区间同步从表内对应 articleId的从表数据
private static final int MASTER = 1;
//根据各自从表数据的时间区间 同步时间区间内对应的从表内容
private static final int SLAVE = 2;
private static final String CHECK_SUCCESS = "success";
private static final String CHECK_FAIL = "fail";
@Override
public JSONObject checkInteractiveData(Integer startTime, Integer endTime, Integer timeType, Integer syncType) {
// syncType : 1、同步点赞 2、 同步评论 3、 同步收藏 4、 同步关注 5、同步评论的点赞
JSONObject reulst;
switch (syncType){
case PRAISE:
return checkPraise(startTime, endTime, timeType);
case FAVORITE:
return checkFavorite(startTime, endTime, timeType);
case ATTENTION:
return checkUserAttention(startTime, endTime);
case COMMENT:
return checkComments(startTime, endTime,timeType);
case COMMENT_PRAISE:
return checkCommentPraise(startTime, endTime);
default:
return null;
}
}
private JSONObject checkPraise(Integer startTime, Integer endTime, Integer timeType){
switch (timeType){
case MASTER:
return checkPraiseByArticle(startTime,endTime);
case SLAVE:
return checkPraiseBySelf(startTime,endTime);
default:
return null;
}
}
private JSONObject checkFavorite(Integer startTime, Integer endTime, Integer timeType){
switch (timeType){
case MASTER:
return checkFavoriteByArticle(startTime,endTime);
case SLAVE:
return checkFavoriteBySelf(startTime,endTime);
default:
return null;
}
}
private JSONObject checkComments(Integer startTime, Integer endTime, Integer timeType){
switch (timeType){
case MASTER:
return checkCommentsByArticle(startTime,endTime);
case SLAVE:
return checkCommentsBySelf(startTime,endTime);
default:
return null;
}
}
/**
* 同步用户点赞 (起始时间条件根据 文章表时间区间)
* @param startTime
* @param endTime
*/
private JSONObject checkPraiseByArticle(Integer startTime, Integer endTime){
logger.info("syncPraiseByArticle begin, startTime is {}, endTime is {}", startTime, endTime);
Long startTimeLong = (long)startTime * 1000;
Long endTimeLong = (long)endTime * 1000;
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(
startTimeLong, endTimeLong,needSyncArticleType,needSyncArticleStatus);
List<Integer> grassArticleIds = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
int grass_praise_count = grassArticlePraiseRepository.countByArticleIdInAndCreateTimeAfter(grassArticleIds, DATA_BEGIN_TIME);
List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList());
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, Lists.newArrayList(1,2,4));
List<Integer> publicArticleIds = publicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(nowArticleIds)){
List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
}
int public_count = publicUserPraiseRepository.countByTargetIdInAndPraiseTypeIsAndSrcChannelIs(publicArticleIds, UserPraiseConstant.ARTICLE_PRAISE , 1);
JSONObject result = new JSONObject();
result.put("checkPraiseResult", grass_praise_count == public_count? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_praise_count", grass_praise_count );
result.put("public_praise_count", public_count );
return result;
}
/**
* 同步用户点赞 (起始时间条件根据 点赞表时间区间)
* @param startTime
* @param endTime
*/
private JSONObject checkPraiseBySelf(Integer startTime, Integer endTime){
logger.info("checkPraiseBySelf begin, startTime is {}, endTime is {}", startTime, endTime);
Long startTimeLong = (long)startTime * 1000;
Long endTimeLong = (long)endTime * 1000;
List<GrassArticlePraise> grassArticlePraiseList = grassArticlePraiseRepository.findAllByCreateTimeBetween(
startTime, endTime);
List<Integer> grassArticleIds = grassArticlePraiseList.stream().map(GrassArticlePraise::getArticleId).collect(Collectors.toList());
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList());
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, Lists.newArrayList(1,2,4));
List<Integer> publicArticleIds = publicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(nowArticleIds)){
List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
}
int public_count = publicUserPraiseRepository.countByTargetIdInAndPraiseTypeIsAndSrcChannelIsAndCreateTimeBetween(publicArticleIds, UserPraiseConstant.ARTICLE_PRAISE , 1,startTimeLong, endTimeLong);
JSONObject result = new JSONObject();
result.put("checkPraiseResult", grassArticlePraiseList.size() == public_count? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_praise_count", grassArticlePraiseList.size());
result.put("public_praise_count", public_count );
return result;
}
/**
* 同步用户收藏 (起始时间条件根据 文章表时间区间)
* @param startTime
* @param endTime
*/
private JSONObject checkFavoriteByArticle(Integer startTime, Integer endTime){
logger.info("syncFavoriteByArticle begin, startTime is {}, endTime is {}", startTime, endTime);
Long startTimeLong = (long)startTime * 1000;
Long endTimeLong = (long)endTime * 1000;
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(
startTimeLong, endTimeLong,needSyncArticleType,needSyncArticleStatus);
List<Integer> grassArticleIds = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
int grass_favorite_count = userFavoriteArticleRepository.countByArticleIdInAndCreateTimeAfter(grassArticleIds, DATA_BEGIN_TIME);
List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList());
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, Lists.newArrayList(1,2,4));
List<Integer> publicArticleIds = publicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(nowArticleIds)){
List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
}
int public_count = publicUserFavoriteRepository.countByTargetIdInAndFavoriteTypeIsAndSrcChannelIs(publicArticleIds, 1 , 1);
JSONObject result = new JSONObject();
result.put("checkFavoriteResult", grass_favorite_count == public_count? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_praise_count", grass_favorite_count );
result.put("public_praise_count", public_count );
return result;
}
/**
* 同步用户收藏 (起始时间条件根据 收藏表时间区间)
* @param startTime
* @param endTime
*/
private JSONObject checkFavoriteBySelf(Integer startTime, Integer endTime){
logger.info("checkFavoriteBySelf begin, startTime is {}, endTime is {}", startTime, endTime);
Long startTimeLong = (long)startTime * 1000;
Long endTimeLong = (long)endTime * 1000;
List<UserFavoriteArticle> userFavoriteArticleList = userFavoriteArticleRepository.findAllByCreateTimeBetween(
startTime, endTime);
List<Integer> grassArticleIds = userFavoriteArticleList.stream().map(UserFavoriteArticle::getArticleId).collect(Collectors.toList());
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList());
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, Lists.newArrayList(1,2,4));
List<Integer> publicArticleIds = publicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(nowArticleIds)){
List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
}
int public_count = publicUserFavoriteRepository.countByTargetIdInAndFavoriteTypeIsAndSrcChannelIsAndCreateTimeBetween(publicArticleIds, 1, 1,startTimeLong, endTimeLong);
JSONObject result = new JSONObject();
result.put("checkFavoriteResult", userFavoriteArticleList.size() == public_count? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_favorite_count", userFavoriteArticleList.size());
result.put("public_favorite_count", public_count );
return result;
}
/**
* 同步用户关注
* @param startTime
* @param endTime
*/
private JSONObject checkUserAttention(Integer startTime, Integer endTime){
logger.info("syncUserAttention begin, startTime is {}, endTime is {}", startTime, endTime);
Long startTimeLong = (long)startTime * 1000;
Long endTimeLong = (long)endTime * 1000;
List<GrassUserAttention> grassUserAttentionList = grassUserAttentionRepository.findAllByCreateTimeBetweenAndCreateTimeAfter(
startTime, endTime, DATA_BEGIN_TIME);
List<Integer> uids = grassUserAttentionList.stream().map(GrassUserAttention::getUid).collect(Collectors.toList());
List<Integer> followIds = grassUserAttentionList.stream().map(GrassUserAttention::getFollowUid).collect(Collectors.toList());
int public_count = publicUserAttentionRepository.countByTargetIdInAndUidInAndAttentionTypeIsAndSrcChannelIsAndCreateTimeBetween(followIds, uids, 1,1,startTimeLong, endTimeLong);
JSONObject result = new JSONObject();
result.put("checkUserAttentionResult", grassUserAttentionList.size() == public_count? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_userAttention_count", grassUserAttentionList.size());
result.put("public_favoritetion_count", public_count );
return result;
}
/**
* 根据文章主表的时间区间同步 评论
* 数据构成主要是:1 文章的所有根评论
* 2 所有子评论
* @param startTime
* @param endTime
*/
private JSONObject checkCommentsByArticle(Integer startTime, Integer endTime){
logger.info("syncCommentsByArticle begin, startTime is {}, endTime is {}", startTime, endTime);
Long startTimeLong = (long)startTime * 1000;
Long endTimeLong = (long)endTime * 1000;
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(
startTimeLong, endTimeLong,needSyncArticleType,needSyncArticleStatus);
List<Integer> grassArticleIds = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
int grass_comment_count = grassArticleCommentRepository.countByDestIdInAndArticleTypeInAndStatusIsNotAndCreateTimeAfter(grassArticleIds,needSyncArticleType, 2,DATA_BEGIN_TIME );
List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList());
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, Lists.newArrayList(1,2,4));
List<Integer> publicArticleIds = publicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(nowArticleIds)){
List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
}
int public_count = publicUserCommentRepository.countByArticleIdInAndSrcChannelIs(publicArticleIds, 1);
JSONObject result = new JSONObject();
result.put("checkCommentResult", grass_comment_count == public_count? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_comment_count", public_count);
result.put("public_comment_count", public_count );
return result;
}
private JSONObject checkCommentsBySelf(Integer startTime, Integer endTime){
logger.info("syncCommentsBySelf begin, startTime is {}, endTime is {}", startTime, endTime);
Long startTimeLong = (long)startTime * 1000;
Long endTimeLong = (long)endTime * 1000;
List<GrassArticleComment> grassArticleComments = grassArticleCommentRepository.findAllByCreateTimeBetween(
startTime, endTime);
List<Integer> grassArticleIds = grassArticleComments.stream().map(GrassArticleComment::getDestId).collect(Collectors.toList());
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList());
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, Lists.newArrayList(1,2,4));
List<Integer> publicArticleIds = publicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(nowArticleIds)){
List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
}
int public_count = publicUserCommentRepository.countByArticleIdInAndSrcChannelIsAndCreateTimeBetween(publicArticleIds, 1,startTimeLong, endTimeLong);
JSONObject result = new JSONObject();
result.put("checkCommentResult", grassArticleComments.size() == public_count? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_comment_count", grassArticleComments.size());
result.put("public_comment_count", public_count );
return result;
}
/**
* 同步种草评论的点赞
* @param startTime
* @param endTime
*/
private JSONObject checkCommentPraise(Integer startTime, Integer endTime){
logger.info("syncCommentPraise begin, startTime is {}, endTime is {}", startTime, endTime);
Long startTimeLong = (long)startTime * 1000;
Long endTimeLong = (long)endTime * 1000;
List<GrassCommentPraise> grassCommentPraiseList = grassCommentPraiseRepository.findAllByCreateTimeBetween(
startTime, endTime);
int grass_count = 0;
List<Integer> commentIds = grassCommentPraiseList.stream().map(GrassCommentPraise::getCommentId).collect(Collectors.toList());
List<PublicUserComment> publicUserCommentList = publicUserCommentRepository.findAllByRelateIdInAndSrcChannelIs(commentIds, 1);
List<Integer> publicCommentIds = publicUserCommentList.stream().map(BaseEntity::getId).collect(Collectors.toList());
List<Integer> existGrassId = publicUserCommentList.stream().map(PublicUserComment::getRelateId).collect(Collectors.toList());
for (GrassCommentPraise grassCommentPraise : grassCommentPraiseList) {
if(existGrassId.contains(grassCommentPraise.getCommentId())){
grass_count ++;
}
}
int public_count = publicUserPraiseRepository.countByTargetIdInAndPraiseTypeIsAndSrcChannelIsAndCreateTimeBetween(publicCommentIds, 2, 1,startTimeLong,endTimeLong);
JSONObject result = new JSONObject();
result.put("checkCommentPraiseResult", grass_count == public_count? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_count", grass_count);
result.put("public_count", public_count );
return result;
}
}
... ...
... ... @@ -60,17 +60,25 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
@Autowired
private PublicUserCommentRepository publicUserCommentRepository;
@Autowired
private GrassCommentPraiseRepository grassCommentPraiseRepository;
public static final int DATA_BEGIN_TIME = 1551283200;
private static final int PRAISE = 1;
private static final int COMMENT = 2;
private static final int FAVORITE = 3;
private static final int ATTENTION = 4;
private static final int COMMENT_PRAISE = 5;
//根据article表的时间区间同步从表内对应 articleId的从表数据
private static final int MASTER = 1;
//根据各自从表数据的时间区间 同步时间区间内对应的从表内容
private static final int SLAVE = 2;
private static List<Integer> needSyncArticleType = new ArrayList<>();
public static List<Integer> needSyncArticleType = new ArrayList<>();
private static List<Integer> needSyncArticleStatus = new ArrayList<>();
public static List<Integer> needSyncArticleStatus = new ArrayList<>();
static {
needSyncArticleType.add(1);
... ... @@ -85,7 +93,7 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
@Override
public String syncInteractiveData(Integer startTime, Integer endTime, Integer timeType, Integer syncType) {
// syncType : 1、同步点赞 2、 同步评论 3、 同步收藏 4、 同步关注
// syncType : 1、同步点赞 2、 同步评论 3、 同步收藏 4、 同步关注 5、同步评论的点赞
switch (syncType){
case PRAISE:
syncPraise(startTime, endTime, timeType);
... ... @@ -99,6 +107,9 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
case COMMENT:
syncComments(startTime, endTime,timeType);
break;
case COMMENT_PRAISE:
syncCommentPraise(startTime, endTime);
break;
default:
break;
... ... @@ -139,6 +150,11 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
}
}
/**
* 同步用户点赞 (起始时间条件根据 文章表时间区间)
* @param startTime
* @param endTime
*/
private void syncPraiseByArticle(Integer startTime, Integer endTime){
logger.info("syncPraiseByArticle begin, startTime is {}, endTime is {}", startTime, endTime);
ExecutorService es = Executors.newSingleThreadExecutor();
... ... @@ -167,23 +183,11 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
startTime, endTime,needSyncArticleType,needSyncArticleStatus,pageReq);
List<Integer> grassArticleIds = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
List<Integer> grassRelatedIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
.map(GrassArticle::getRelateId).collect(Collectors.toList());
//社区文章 relate_id 和article_id 对应关系
Map<Integer, Integer> grassRelatedIdAndIdMap = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
.collect(Collectors.toMap(GrassArticle::getRelateId, GrassArticle::getId));
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
List<PublicArticle> publicArticleNowList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassRelatedIds, Lists.newArrayList(5));
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = new HashMap<>();
publicArticleList.forEach(publicArticle -> {
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
});
publicArticleNowList.forEach(publicArticle -> {
Integer grassArticleId = grassRelatedIdAndIdMap.get(publicArticle.getRelateId());
nowArticleIdAndpublicArticleIdMap.put(grassArticleId, publicArticle.getId());
});
List<GrassArticlePraise> grassArticlePraiseList = grassArticlePraiseRepository.findAllByArticleIdIn(grassArticleIds);
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
List<GrassArticlePraise> grassArticlePraiseList = grassArticlePraiseRepository.findAllByArticleIdInAndCreateTimeAfter(grassArticleIds, DATA_BEGIN_TIME);
logger.info("syncPraiseByArticlePage find grassArticlePraise num is {}", grassArticlePraiseList.size());
List<PublicUserPraise> needSyncData = buildPublicUserPraise(publicArticleIdAndGrassIdMap, nowArticleIdAndpublicArticleIdMap,grassArticlePraiseList);
publicUserPraiseRepository.saveAll(needSyncData);
... ... @@ -227,6 +231,11 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
}
}
/**
* 同步用户点赞 (起始时间条件根据 点赞表时间区间)
* @param startTime
* @param endTime
*/
private void syncPraiseBySelf(Integer startTime, Integer endTime){
logger.info("syncPraiseBySelf begin, startTime is {}, endTime is {}", startTime, endTime);
ExecutorService es = Executors.newSingleThreadExecutor();
... ... @@ -255,18 +264,20 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
List<Integer> grassArticleIds = grassArticlePraiseList.stream().map(GrassArticlePraise::getArticleId).collect(Collectors.toList());
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPulicIdMap(grassArticleList);
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
List<PublicArticle> publicUserPraiseList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
publicUserPraiseList.forEach(publicArticle -> {
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
});
List<PublicUserPraise> needSyncData = buildPublicUserPraise(publicArticleIdAndGrassIdMap,nowArticleIdAndpublicArticleIdMap, grassArticlePraiseList);
publicUserPraiseRepository.saveAll(needSyncData);
}
/**
* 同步用户收藏 (起始时间条件根据 文章表时间区间)
* @param startTime
* @param endTime
*/
private void syncFavoriteByArticle(Integer startTime, Integer endTime){
logger.info("syncFavoriteByArticle begin, startTime is {}, endTime is {}", startTime, endTime);
ExecutorService es = Executors.newSingleThreadExecutor();
... ... @@ -295,24 +306,12 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
startTime, endTime,needSyncArticleType,needSyncArticleStatus,pageReq);
List<Integer> grassArticleIds = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
List<Integer> grassRelatedIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
.map(GrassArticle::getRelateId).collect(Collectors.toList());
//社区文章 relate_id 和article_id 对应关系
Map<Integer, Integer> grassRelatedIdAndIdMap = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
.collect(Collectors.toMap(GrassArticle::getRelateId, GrassArticle::getId));
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
List<PublicArticle> publicArticleNowList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassRelatedIds, Lists.newArrayList(5));
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
publicArticleList.forEach(publicArticle -> {
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
});
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = new HashMap<>();
publicArticleNowList.forEach(publicArticle -> {
Integer grassArticleId = grassRelatedIdAndIdMap.get(publicArticle.getRelateId());
nowArticleIdAndpublicArticleIdMap.put(grassArticleId, publicArticle.getId());
});
List<UserFavoriteArticle> userFavoriteArticleList = userFavoriteArticleRepository.findAllByArticleIdIn(grassArticleIds);
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
List<UserFavoriteArticle> userFavoriteArticleList = userFavoriteArticleRepository.findAllByArticleIdInAndCreateTimeAfter(grassArticleIds, DATA_BEGIN_TIME);
logger.info("syncFavoriteByArticlePage find userFavoriteArticle num is {}", userFavoriteArticleList.size());
List<PublicUserFavorite> needSyncData = buildPublicUserFavorite(publicArticleIdAndGrassIdMap,nowArticleIdAndpublicArticleIdMap, userFavoriteArticleList);
publicUserFavoriteRepository.saveAll(needSyncData);
... ... @@ -347,6 +346,11 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
return resultList;
}
/**
* 同步用户收藏 (起始时间条件根据 收藏表时间区间)
* @param startTime
* @param endTime
*/
private void syncFavoriteBySelf(Integer startTime, Integer endTime){
logger.info("syncFavoriteBySelf begin, startTime is {}, endTime is {}", startTime, endTime);
ExecutorService es = Executors.newSingleThreadExecutor();
... ... @@ -375,17 +379,20 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
List<Integer> grassArticleIds = userFavoriteArticleList.stream().map(UserFavoriteArticle::getArticleId).collect(Collectors.toList());
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPulicIdMap(grassArticleList);
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
publicArticleList.forEach(publicArticle -> {
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
});
List<PublicUserFavorite> needSyncData = buildPublicUserFavorite(publicArticleIdAndGrassIdMap,nowArticleIdAndpublicArticleIdMap, userFavoriteArticleList);
publicUserFavoriteRepository.saveAll(needSyncData);
}
/**
* 同步用户关注
* @param startTime
* @param endTime
*/
private void syncUserAttention(Integer startTime, Integer endTime){
logger.info("syncUserAttention begin, startTime is {}, endTime is {}", startTime, endTime);
ExecutorService es = Executors.newSingleThreadExecutor();
... ... @@ -408,8 +415,8 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
private void syncUserAttentionPage(int startTime, int endTime, int indexPage, int pageSize){
Pageable pageReq = PageRequest.of(indexPage, pageSize);
List<GrassUserAttention> grassUserAttentionList = grassUserAttentionRepository.findAllByCreateTimeBetween(
startTime, endTime,pageReq);
List<GrassUserAttention> grassUserAttentionList = grassUserAttentionRepository.findAllByCreateTimeBetweenAndCreateTimeAfter(
startTime, endTime, DATA_BEGIN_TIME, pageReq);
List<PublicUserAttention> needSyncData = buildPublicUserAttention(grassUserAttentionList);
publicUserAttentionRepository.saveAll(needSyncData);
... ... @@ -436,6 +443,7 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
return resultList;
}
//种草用户关注status → 公共库用户关注status 转换
private int convertAttentionStatus(int grassAttentionStatus){
switch (grassAttentionStatus){
case UserAttentionConstant.GRASS_HAS_ATTENTION:
... ... @@ -521,13 +529,9 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
List<Integer> grassArticleIds = grassArticleCommentsList.stream().map(GrassArticleComment::getDestId).collect(Collectors.toList());
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPulicIdMap(grassArticleList);
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
publicArticleList.forEach(publicArticle -> {
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
});
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
//先把时间区间内所有的新产生的根评论同步
List<GrassArticleComment> grassRootArticleComments = grassArticleCommentsList.stream().filter(grassArticleComment -> grassArticleComment.getParentId() == null).collect(Collectors.toList());;
... ... @@ -565,31 +569,17 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
startTime, endTime,needSyncArticleType,needSyncArticleStatus,pageReq);
List<Integer> grassArticleIds = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
List<Integer> grassRelatedIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
.map(GrassArticle::getRelateId).collect(Collectors.toList());
//社区文章 relate_id 和article_id 对应关系
Map<Integer, Integer> grassRelatedIdAndIdMap = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
.collect(Collectors.toMap(GrassArticle::getRelateId, GrassArticle::getId));
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
List<PublicArticle> publicArticleNowList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassRelatedIds, Lists.newArrayList(5));
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
publicArticleList.forEach(publicArticle -> {
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
});
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = new HashMap<>();
publicArticleNowList.forEach(publicArticle -> {
Integer grassArticleId = grassRelatedIdAndIdMap.get(publicArticle.getRelateId());
nowArticleIdAndpublicArticleIdMap.put(grassArticleId, publicArticle.getId());
});
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
//先把所有根评论同步
List<PublicUserComment> roots = queryAndBuildRootComment(grassArticleIds, publicArticleIdAndGrassIdMap,nowArticleIdAndpublicArticleIdMap);
List<PublicUserComment> rootPublicComments = publicUserCommentRepository.saveAll(roots);
//审核未通过的不查
List<GrassArticleComment> childrenComments = grassArticleCommentRepository.findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNotNull(grassArticleIds,
needSyncArticleType, 2);
List<GrassArticleComment> childrenComments = grassArticleCommentRepository.findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNotNullAndCreateTimeAfter(grassArticleIds,
needSyncArticleType, 2, DATA_BEGIN_TIME);
Map<Integer, Integer> rootIdMap = new HashMap<>();
rootPublicComments.forEach(publicUserComment -> {
rootIdMap.put(publicUserComment.getRelateId(), publicUserComment.getId());
... ... @@ -605,13 +595,14 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
List<PublicUserComment> result;
//审核未通过的不查
List<GrassArticleComment> rootComments = grassArticleCommentRepository.findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNull(grassArticleIds,
needSyncArticleType, 2);
List<GrassArticleComment> rootComments = grassArticleCommentRepository.findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNullAndCreateTimeAfter(grassArticleIds,
needSyncArticleType, 2,DATA_BEGIN_TIME);
result = buildRootComments(publicArticleIdAndGrassIdMap, rootComments,nowArticleIdAndpublicArticleIdMap);
return result;
}
private List<PublicUserComment> buildRootComments( Map<Integer, Integer> publicArticleIdAndGrassIdMap, List<GrassArticleComment> grassRootArticleComments,
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap){
List<PublicUserComment> result = Lists.newArrayList();
... ... @@ -730,6 +721,7 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
return syncPublicUserCommentList;
}
//种草评论内容 → 公共库评论内容转换
private String convertCommentContent(String text){
JSONObject jsonObject = new JSONObject();
jsonObject.put("type","text");
... ... @@ -737,6 +729,7 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
return jsonObject.toString();
}
//种草评论status → 公共库评论status转换
private int convertCommentStatus(int grassCommentStatus){
switch (grassCommentStatus){
case UserCommentConstant.GRASS_NOT_AUDIT:
... ... @@ -750,7 +743,13 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
}
}
private Map<Integer, Integer> getNowArticleIdAndPulicIdMap(List<GrassArticle> grassArticleList){
/**
* 获取种草文章中社区同步过来的文章 在公共库的文章id
* 返回种草库中id 和公共库中id的对应关系map
* @param grassArticleList
* @return
*/
private Map<Integer, Integer> getNowArticleIdAndPublicIdMap(List<GrassArticle> grassArticleList){
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = new HashMap<>();
List<Integer> grassRelatedIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
.map(GrassArticle::getRelateId).collect(Collectors.toList());
... ... @@ -766,7 +765,83 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat
}
return nowArticleIdAndpublicArticleIdMap;
}
private Map<Integer, Integer> getGrassArticleIdAndPublicIdMap(List<Integer> grassArticleIds){
Map<Integer, Integer> grassArticleIdAndpublicArticleIdMap = new HashMap<>();
if(!CollectionUtils.isEmpty(grassArticleIds)){
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, Lists.newArrayList(1,2,4));
publicArticleList.forEach(publicArticle -> {
grassArticleIdAndpublicArticleIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
});
}
return grassArticleIdAndpublicArticleIdMap;
}
/**
* 同步种草评论的点赞
* @param startTime
* @param endTime
*/
private void syncCommentPraise(Integer startTime, Integer endTime){
logger.info("syncCommentPraise begin, startTime is {}, endTime is {}", startTime, endTime);
ExecutorService es = Executors.newSingleThreadExecutor();
int pageSize = 100;
int total = grassCommentPraiseRepository.countByCreateTimeBetween(startTime, endTime);
logger.info("syncCommentPraise get commentPraise count is {}", total);
int totalPage = total % pageSize ==0 ? total / pageSize : (total / pageSize)+1;
try{
//每次查询100条,增加detail
for (int index=0; index < totalPage; index++) {
int indexPage = index;
es.execute(() -> {
syncCommentPraisePage(startTime, endTime, indexPage, pageSize);
});
}
}finally {
es.shutdown();
}
}
private void syncCommentPraisePage(int startTime, int endTime, int indexPage, int pageSize){
Pageable pageReq = PageRequest.of(indexPage, pageSize);
List<GrassCommentPraise> grassCommentPraiseList = grassCommentPraiseRepository.findAllByCreateTimeBetween(
startTime, endTime,pageReq);
if(CollectionUtils.isEmpty(grassCommentPraiseList)){
logger.info("syncCommentPraisePage , grassCommentPraiseList is empty");
return;
}
List<Integer> grassCommentIds = grassCommentPraiseList.stream().map(GrassCommentPraise::getCommentId).collect(Collectors.toList());
List<PublicUserComment> publicUserComments = publicUserCommentRepository.findAllByRelateIdInAndSrcChannelIs(grassCommentIds, 1);
Map<Integer, Integer> relateIdMap = new HashMap<>();
publicUserComments.forEach(publicUserComment -> {
relateIdMap.put(publicUserComment.getRelateId(), publicUserComment.getId());
});
List<PublicUserPraise> needSyncData = buildPublicUserPraise(relateIdMap, grassCommentPraiseList);
publicUserPraiseRepository.saveAll(needSyncData);
}
private List<PublicUserPraise> buildPublicUserPraise(Map<Integer, Integer> relateIdMap, List<GrassCommentPraise> grassCommentPraiseList){
List<PublicUserPraise> result = Lists.newArrayList();
grassCommentPraiseList.forEach(grassCommentPraise -> {
Integer targrtId = relateIdMap.get(grassCommentPraise.getCommentId());
if(null == targrtId){
return;
}
PublicUserPraise publicUserPraise = new PublicUserPraise();
publicUserPraise.setUid(grassCommentPraise.getUid());
publicUserPraise.setPraiseType(2);
publicUserPraise.setStatus(convertPraiseStatus(grassCommentPraise.getStatus()));
publicUserPraise.setSrcChannel(1);
publicUserPraise.setTargetId(targrtId);
publicUserPraise.setCreateTime(convertIntTimeToLong(grassCommentPraise.getCreateTime()));
publicUserPraise.setUpdateTime(convertIntTimeToLong(grassCommentPraise.getUpdateTime()));
result.add(publicUserPraise);
});
return result;
}
private Long convertIntTimeToLong(Integer time){
return Long.valueOf(Optional.ofNullable(time).orElse(0)) * 1000;
... ...
package com.yoho.datasync.fullsync.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.yoho.datasync.fullsync.dal.repository.grass.GrassUserAchieveRepository;
import com.yoho.datasync.fullsync.dal.repository.grass.GrassVirtualUserRepository;
import com.yoho.datasync.fullsync.dal.repository.grass.model.GrassUserAchieve;
import com.yoho.datasync.fullsync.dal.repository.grass.model.GrassVirtualUser;
import com.yoho.datasync.fullsync.dal.repository.pcms.PublicUserHomePageRepository;
import com.yoho.datasync.fullsync.dal.repository.pcms.PublicVirtualUserRepository;
import com.yoho.datasync.fullsync.dal.repository.pcms.model.PublicUserHomePage;
import com.yoho.datasync.fullsync.dal.repository.pcms.model.PublicVirtualUser;
import com.yoho.datasync.fullsync.service.IGrassUserDataCheckService;
import com.yoho.datasync.fullsync.service.IGrassUserDataSyncService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Service
public class GrassUserDataCheckServiceImpl implements IGrassUserDataCheckService {
private Logger logger = LoggerFactory.getLogger(GrassUserDataCheckServiceImpl.class);
@Autowired
private GrassUserAchieveRepository grassUserAchieveRepository;
@Autowired
private PublicUserHomePageRepository publicUserHomePageRepository;
@Autowired
private GrassVirtualUserRepository grassVirtualUserRepository;
@Autowired
private PublicVirtualUserRepository publicVirtualUserRepository;
private static final int USER_ACHIEVE = 1;
private static final int USER_VIRTUAL = 2;
private static final String CHECK_SUCCESS = "success";
private static final String CHECK_FAIL = "fail";
@Override
public JSONObject checkGrassUserData(Integer startTime, Integer endTime, Integer syncType) {
switch (syncType){
case USER_ACHIEVE:
return checkUserAchieveData(startTime,endTime);
case USER_VIRTUAL:
return checkVirtualUserData(startTime,endTime);
default:
return null;
}
}
private JSONObject checkUserAchieveData(Integer startTime, Integer endTime){
logger.info("checkUserAchieveData begin, startTime is {}, endTime is {}", startTime, endTime);
Long startTimeLong = (long)startTime * 1000;
Long endTimeLong = (long)endTime * 1000;
int grass_count = grassUserAchieveRepository.countByCreateTimeBetween(startTime,endTime);
int public_count = publicUserHomePageRepository.countByCreateTimeBetween(startTimeLong, endTimeLong);
JSONObject result = new JSONObject();
result.put("checkUserAchieveResult", grass_count == public_count? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_userAchieve_count", grass_count);
result.put("public_userAchieve_count", public_count );
return result;
}
private JSONObject checkVirtualUserData(Integer startTime, Integer endTime){
logger.info("syncVirtualUserData begin, startTime is {}, endTime is {}", startTime, endTime);
int grass_count = grassVirtualUserRepository.countByCreateTimeBetween(startTime, endTime);
int public_count = publicVirtualUserRepository.countByCreateTimeBetween(startTime, endTime);
JSONObject result = new JSONObject();
result.put("checkVirtualUserResult", grass_count == public_count? CHECK_SUCCESS : CHECK_FAIL);
result.put("grass_virtual_count", grass_count);
result.put("public_virtual_count", public_count );
return result;
}
}
... ...