...
|
...
|
@@ -4,6 +4,7 @@ import com.yoho.datasync.consumer.common.BeanCopyUtils; |
|
|
import com.yoho.datasync.consumer.common.ServiceConstant;
|
|
|
import com.yoho.datasync.consumer.dal.repository.pcms.PublicArticleAuditRepository;
|
|
|
import com.yoho.datasync.consumer.dal.repository.pcms.PublicArticleRepository;
|
|
|
import com.yoho.datasync.core.base.model.yh_grass.GrassArticle;
|
|
|
import com.yoho.datasync.core.base.model.yh_pcms.PublicArticle;
|
|
|
import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleAudit;
|
|
|
import org.slf4j.Logger;
|
...
|
...
|
@@ -20,6 +21,9 @@ public class PublicArticleService { |
|
|
private static final Logger log = LoggerFactory.getLogger(PublicArticleService.class);
|
|
|
|
|
|
@Resource
|
|
|
private GrassArticleService grassArticleService;
|
|
|
|
|
|
@Resource
|
|
|
private PublicArticleRepository publicArticleRepository;
|
|
|
|
|
|
@Resource
|
...
|
...
|
@@ -43,7 +47,6 @@ public class PublicArticleService { |
|
|
* 2019.4.4 将文章表改为逻辑删除
|
|
|
*/
|
|
|
publicArticleRepository.save(existObject);
|
|
|
// publicArticleRepository.deleteById(existObject.getId());
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -56,19 +59,28 @@ public class PublicArticleService { |
|
|
*/
|
|
|
public void updateData(PublicArticle targetObject, PublicArticleAudit publicArticleAudit, Object checkResult) {
|
|
|
// public_article_audit表中的article_id字段为种草文章同步到公共库public_article表中的自增id字段
|
|
|
// select id from public_article where relate_id=#{grass_article.article_id} and article_type in (1,2,4)
|
|
|
PublicArticle existObject = validateInfoAndGetRecord(targetObject);
|
|
|
boolean mark = true;
|
|
|
PublicArticle saveObject;
|
|
|
if (existObject != null) {
|
|
|
// update
|
|
|
mark = false;
|
|
|
targetObject.setCoverImg((String) checkResult);
|
|
|
if (targetObject.getId() != null) {
|
|
|
log.error("something goes wrong ...");
|
|
|
return;
|
|
|
if (targetObject.getArticleType() == ServiceConstant.ARTICLE_TYPE_NOW) {
|
|
|
// relate_id 不能被覆盖
|
|
|
existObject.setAuthorUid(targetObject.getAuthorUid());
|
|
|
existObject.setPraiseNum(targetObject.getPraiseNum());
|
|
|
existObject.setFavoriteNum(targetObject.getFavoriteNum());
|
|
|
existObject.setStatus(targetObject.getStatus());
|
|
|
existObject.setAuditStatus(targetObject.getAuditStatus());
|
|
|
existObject.setAuthorType(targetObject.getAuthorType());
|
|
|
existObject.setUpdateTime(targetObject.getUpdateTime());
|
|
|
existObject.setCreateTime(targetObject.getCreateTime());
|
|
|
existObject.setPublishTime(targetObject.getPublishTime());
|
|
|
existObject.setCoverImg((String) checkResult);
|
|
|
} else {
|
|
|
targetObject.setCoverImg((String) checkResult);
|
|
|
existObject = BeanCopyUtils.copyNonNullProperties(targetObject, existObject, PublicArticle.class);
|
|
|
}
|
|
|
existObject = BeanCopyUtils.copyNonNullProperties(targetObject, existObject, PublicArticle.class);
|
|
|
|
|
|
/**
|
|
|
* public_article_audit 表的操作
|
...
|
...
|
@@ -119,25 +131,42 @@ public class PublicArticleService { |
|
|
* @throws ValidationException
|
|
|
*/
|
|
|
private PublicArticle validateInfoAndGetRecord(PublicArticle targetObject) {
|
|
|
// 根据 relateId[原id] 和 articleType 可唯一确定一条记录
|
|
|
final Integer relateId = targetObject.getRelateId();
|
|
|
if (relateId == null) {
|
|
|
log.info("targetObject {} variable relateId is null", targetObject.toString());
|
|
|
return null;
|
|
|
if (targetObject.getArticleType() == ServiceConstant.ARTICLE_TYPE_NOW) {
|
|
|
// now 来源的数据需要特别处理 min_relate_id 即时原grass表的 relate_id
|
|
|
final Integer minRelateId = targetObject.getMinRelateId();
|
|
|
if (minRelateId == null) {
|
|
|
log.warn("targetObject {} variable minRelateId is null", targetObject.toString());
|
|
|
return null;
|
|
|
}
|
|
|
return publicArticleRepository.findByRelateIdAndArticleType(minRelateId, ServiceConstant.ARTICLE_TYPE_NOW);
|
|
|
} else {
|
|
|
final Integer relateId = targetObject.getRelateId();
|
|
|
if (relateId == null) {
|
|
|
log.info("targetObject {} variable relateId is null", targetObject.toString());
|
|
|
return null;
|
|
|
}
|
|
|
return publicArticleRepository.findByRelateIdInArticleTypes(relateId, ServiceConstant.articleTypes);
|
|
|
}
|
|
|
return publicArticleRepository.findByRelateIdInArticleTypes(relateId, ServiceConstant.articleTypes);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据articleId获得记录
|
|
|
* 根据原 grass_article_id 获取 public_article_id
|
|
|
*
|
|
|
* @param articleId
|
|
|
* @param grassArticleId
|
|
|
* @return
|
|
|
*/
|
|
|
public Integer getByArticleIdAndType(Integer articleId) {
|
|
|
if (articleId == null)
|
|
|
return null;
|
|
|
return publicArticleRepository.findByArticleId(articleId, ServiceConstant.articleTypes);
|
|
|
public Integer getPublicArticleIdStage1(final Integer grassArticleId) {
|
|
|
final GrassArticle grassArticle = grassArticleService.getGrassArticleById(grassArticleId);
|
|
|
return getPublicArticleIdStage2(grassArticle);
|
|
|
}
|
|
|
|
|
|
public Integer getPublicArticleIdStage2(final GrassArticle grassArticle) {
|
|
|
if (grassArticle != null && grassArticle.getArticleType() == ServiceConstant.ARTICLE_TYPE_NOW) {
|
|
|
final PublicArticle result = publicArticleRepository.findByRelateIdAndArticleType(grassArticle.getRelateId(), ServiceConstant.ARTICLE_TYPE_NOW);
|
|
|
return result == null ? null : result.getId();
|
|
|
} else {
|
|
|
return publicArticleRepository.findByArticleId(grassArticle.getId(), ServiceConstant.articleTypes);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Integer findArticleIdByRelateIdInArticleTypes(Integer relateId, int[] articleTypes) {
|
...
|
...
|
|