@@ -9,6 +9,7 @@ | |||||
<factory-entry name="1068-yexiu-read-model-mybatis" /> | <factory-entry name="1068-yexiu-read-model-mybatis" /> | ||||
<factory-entry name="Entities" /> | <factory-entry name="Entities" /> | ||||
</datasource-mapping> | </datasource-mapping> | ||||
<naming-strategy-map /> | |||||
</configuration> | </configuration> | ||||
</facet> | </facet> | ||||
<facet type="Spring" name="Spring"> | <facet type="Spring" name="Spring"> | ||||
@@ -0,0 +1,39 @@ | |||||
package com.yuexiu.secp.read.infra.util; | |||||
import com.google.common.base.Joiner; | |||||
import com.google.common.collect.Lists; | |||||
import org.apache.commons.lang.StringUtils; | |||||
import java.util.ArrayList; | |||||
/** | |||||
* 生成key的工具类 | |||||
*/ | |||||
public class RedisUtils { | |||||
//分隔符 | |||||
public final static String split = ":"; | |||||
public static String getRedisKey(String... name) { | |||||
StringBuffer sb = new StringBuffer(); | |||||
for (String str : name) { | |||||
if (StringUtils.isNotBlank(str)) { | |||||
sb.append(str); | |||||
sb.append(split); | |||||
} | |||||
} | |||||
sb = sb.deleteCharAt(sb.lastIndexOf(split)); | |||||
return sb.toString(); | |||||
} | |||||
public static String getRedisKeyJoin(String... name){ | |||||
ArrayList<String> strlist = Lists.newArrayList(); | |||||
for (String str : name) { | |||||
if (StringUtils.isNotBlank(str)) { | |||||
strlist.add(str); | |||||
} | |||||
} | |||||
return Joiner.on("_").join(strlist); | |||||
} | |||||
} |
@@ -1,13 +1,13 @@ | |||||
package com.yuexiu.secp.read.model.dao; | package com.yuexiu.secp.read.model.dao; | ||||
import com.yuexiu.secp.read.model.entities.readonly.ArticlePreview; | |||||
import com.sie.iot.common.model.dao.BaseCommonDAO_HI; | import com.sie.iot.common.model.dao.BaseCommonDAO_HI; | ||||
import com.yuexiu.secp.read.model.entities.ArticlePreviewEntity; | |||||
import org.apache.ibatis.annotations.Select; | import org.apache.ibatis.annotations.Select; | ||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
@Component("ArticlePreviewDao") | @Component("ArticlePreviewDao") | ||||
public interface ArticlePreviewDao extends BaseCommonDAO_HI<ArticlePreviewEntity> { | |||||
public interface ArticlePreviewDao extends BaseCommonDAO_HI<ArticlePreview> { | |||||
@Select("select * from sie_article_preview where promotion_status = 1 and task_status = 1") | |||||
@Select("select count(1) from yxh_article where promotion_status = 1 and task_status = 1") | |||||
int findRecommend(); | int findRecommend(); | ||||
} | } |
@@ -0,0 +1,392 @@ | |||||
package com.yuexiu.secp.read.model.entities; | |||||
import java.util.Date; | |||||
import com.alibaba.fastjson.annotation.JSONField; | |||||
/** | |||||
* YxhArticleEntity_MY Entity Object | |||||
* Tue May 10 15:09:48 CST 2022 Auto Generate | |||||
*/ | |||||
public class ArticleEntity { | |||||
private Long articleId; | |||||
private String publishUnit; | |||||
private String articleTitle; | |||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss") | |||||
private Date spreadBeginTime; | |||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss") | |||||
private Date spreadEndTime; | |||||
private Integer shareType; | |||||
private String copywrite1; | |||||
private String copywrite2; | |||||
private String copywrite3; | |||||
private String copywrite4; | |||||
private String copywrite5; | |||||
private String shareTitle; | |||||
private String shareImg; | |||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss") | |||||
private Date releaseTime; | |||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss") | |||||
private Date releaseTaskTime; | |||||
private Integer releaseTaskUser; | |||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss") | |||||
private Date endTaskTime; | |||||
private Integer endTaskUser; | |||||
private Integer taskStatus; | |||||
private Integer promotionStatus; | |||||
private Integer approvalStatus; | |||||
private Integer approvalUser; | |||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss") | |||||
private Date approvalTime; | |||||
private Integer articleType; | |||||
private String articleTypeAlias; | |||||
private String authorName; | |||||
private String authorLogo; | |||||
private String articleUrl; | |||||
private String codeImg; | |||||
private Long tenantId; | |||||
private Long createdBy; | |||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss") | |||||
private Date creationDate; | |||||
private Long lastUpdatedBy; | |||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss") | |||||
private Date lastUpdateDate; | |||||
private Long lastUpdateLogin; | |||||
private Integer deleteFlag; | |||||
private Integer versionNum; | |||||
public void setArticleId(Long articleId) { | |||||
this.articleId = articleId; | |||||
} | |||||
public Long getArticleId() { | |||||
return articleId; | |||||
} | |||||
public void setPublishUnit(String publishUnit) { | |||||
this.publishUnit = publishUnit; | |||||
} | |||||
public String getPublishUnit() { | |||||
return publishUnit; | |||||
} | |||||
public void setArticleTitle(String articleTitle) { | |||||
this.articleTitle = articleTitle; | |||||
} | |||||
public String getArticleTitle() { | |||||
return articleTitle; | |||||
} | |||||
public void setSpreadBeginTime(Date spreadBeginTime) { | |||||
this.spreadBeginTime = spreadBeginTime; | |||||
} | |||||
public Date getSpreadBeginTime() { | |||||
return spreadBeginTime; | |||||
} | |||||
public void setSpreadEndTime(Date spreadEndTime) { | |||||
this.spreadEndTime = spreadEndTime; | |||||
} | |||||
public Date getSpreadEndTime() { | |||||
return spreadEndTime; | |||||
} | |||||
public void setShareType(Integer shareType) { | |||||
this.shareType = shareType; | |||||
} | |||||
public Integer getShareType() { | |||||
return shareType; | |||||
} | |||||
public void setCopywrite1(String copywrite1) { | |||||
this.copywrite1 = copywrite1; | |||||
} | |||||
public String getCopywrite1() { | |||||
return copywrite1; | |||||
} | |||||
public void setCopywrite2(String copywrite2) { | |||||
this.copywrite2 = copywrite2; | |||||
} | |||||
public String getCopywrite2() { | |||||
return copywrite2; | |||||
} | |||||
public void setCopywrite3(String copywrite3) { | |||||
this.copywrite3 = copywrite3; | |||||
} | |||||
public String getCopywrite3() { | |||||
return copywrite3; | |||||
} | |||||
public void setCopywrite4(String copywrite4) { | |||||
this.copywrite4 = copywrite4; | |||||
} | |||||
public String getCopywrite4() { | |||||
return copywrite4; | |||||
} | |||||
public void setCopywrite5(String copywrite5) { | |||||
this.copywrite5 = copywrite5; | |||||
} | |||||
public String getCopywrite5() { | |||||
return copywrite5; | |||||
} | |||||
public void setShareTitle(String shareTitle) { | |||||
this.shareTitle = shareTitle; | |||||
} | |||||
public String getShareTitle() { | |||||
return shareTitle; | |||||
} | |||||
public void setShareImg(String shareImg) { | |||||
this.shareImg = shareImg; | |||||
} | |||||
public String getShareImg() { | |||||
return shareImg; | |||||
} | |||||
public void setReleaseTime(Date releaseTime) { | |||||
this.releaseTime = releaseTime; | |||||
} | |||||
public Date getReleaseTime() { | |||||
return releaseTime; | |||||
} | |||||
public void setReleaseTaskTime(Date releaseTaskTime) { | |||||
this.releaseTaskTime = releaseTaskTime; | |||||
} | |||||
public Date getReleaseTaskTime() { | |||||
return releaseTaskTime; | |||||
} | |||||
public void setReleaseTaskUser(Integer releaseTaskUser) { | |||||
this.releaseTaskUser = releaseTaskUser; | |||||
} | |||||
public Integer getReleaseTaskUser() { | |||||
return releaseTaskUser; | |||||
} | |||||
public void setEndTaskTime(Date endTaskTime) { | |||||
this.endTaskTime = endTaskTime; | |||||
} | |||||
public Date getEndTaskTime() { | |||||
return endTaskTime; | |||||
} | |||||
public void setEndTaskUser(Integer endTaskUser) { | |||||
this.endTaskUser = endTaskUser; | |||||
} | |||||
public Integer getEndTaskUser() { | |||||
return endTaskUser; | |||||
} | |||||
public void setTaskStatus(Integer taskStatus) { | |||||
this.taskStatus = taskStatus; | |||||
} | |||||
public Integer getTaskStatus() { | |||||
return taskStatus; | |||||
} | |||||
public void setPromotionStatus(Integer promotionStatus) { | |||||
this.promotionStatus = promotionStatus; | |||||
} | |||||
public Integer getPromotionStatus() { | |||||
return promotionStatus; | |||||
} | |||||
public void setApprovalStatus(Integer approvalStatus) { | |||||
this.approvalStatus = approvalStatus; | |||||
} | |||||
public Integer getApprovalStatus() { | |||||
return approvalStatus; | |||||
} | |||||
public void setApprovalUser(Integer approvalUser) { | |||||
this.approvalUser = approvalUser; | |||||
} | |||||
public Integer getApprovalUser() { | |||||
return approvalUser; | |||||
} | |||||
public void setApprovalTime(Date approvalTime) { | |||||
this.approvalTime = approvalTime; | |||||
} | |||||
public Date getApprovalTime() { | |||||
return approvalTime; | |||||
} | |||||
public void setArticleType(Integer articleType) { | |||||
this.articleType = articleType; | |||||
} | |||||
public Integer getArticleType() { | |||||
return articleType; | |||||
} | |||||
public void setArticleTypeAlias(String articleTypeAlias) { | |||||
this.articleTypeAlias = articleTypeAlias; | |||||
} | |||||
public String getArticleTypeAlias() { | |||||
return articleTypeAlias; | |||||
} | |||||
public void setAuthorName(String authorName) { | |||||
this.authorName = authorName; | |||||
} | |||||
public String getAuthorName() { | |||||
return authorName; | |||||
} | |||||
public void setAuthorLogo(String authorLogo) { | |||||
this.authorLogo = authorLogo; | |||||
} | |||||
public String getAuthorLogo() { | |||||
return authorLogo; | |||||
} | |||||
public void setArticleUrl(String articleUrl) { | |||||
this.articleUrl = articleUrl; | |||||
} | |||||
public String getArticleUrl() { | |||||
return articleUrl; | |||||
} | |||||
public void setCodeImg(String codeImg) { | |||||
this.codeImg = codeImg; | |||||
} | |||||
public String getCodeImg() { | |||||
return codeImg; | |||||
} | |||||
public void setTenantId(Long tenantId) { | |||||
this.tenantId = tenantId; | |||||
} | |||||
public Long getTenantId() { | |||||
return tenantId; | |||||
} | |||||
public void setCreatedBy(Long createdBy) { | |||||
this.createdBy = createdBy; | |||||
} | |||||
public Long getCreatedBy() { | |||||
return createdBy; | |||||
} | |||||
public void setCreationDate(Date creationDate) { | |||||
this.creationDate = creationDate; | |||||
} | |||||
public Date getCreationDate() { | |||||
return creationDate; | |||||
} | |||||
public void setLastUpdatedBy(Long lastUpdatedBy) { | |||||
this.lastUpdatedBy = lastUpdatedBy; | |||||
} | |||||
public Long getLastUpdatedBy() { | |||||
return lastUpdatedBy; | |||||
} | |||||
public void setLastUpdateDate(Date lastUpdateDate) { | |||||
this.lastUpdateDate = lastUpdateDate; | |||||
} | |||||
public Date getLastUpdateDate() { | |||||
return lastUpdateDate; | |||||
} | |||||
public void setLastUpdateLogin(Long lastUpdateLogin) { | |||||
this.lastUpdateLogin = lastUpdateLogin; | |||||
} | |||||
public Long getLastUpdateLogin() { | |||||
return lastUpdateLogin; | |||||
} | |||||
public void setDeleteFlag(Integer deleteFlag) { | |||||
this.deleteFlag = deleteFlag; | |||||
} | |||||
public Integer getDeleteFlag() { | |||||
return deleteFlag; | |||||
} | |||||
public void setVersionNum(Integer versionNum) { | |||||
this.versionNum = versionNum; | |||||
} | |||||
public Integer getVersionNum() { | |||||
return versionNum; | |||||
} | |||||
} | |||||
@@ -0,0 +1,32 @@ | |||||
package com.yuexiu.secp.read.dto; | |||||
/** | |||||
* 查询最新推荐和我已推荐的Dto | |||||
*/ | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.NoArgsConstructor; | |||||
@Data | |||||
@NoArgsConstructor | |||||
@ApiModel(value = "查询最新推荐和我已推荐的Dto") | |||||
public class ArticleQueryDto { | |||||
@ApiModelProperty(value = "推广状态") | |||||
private int promotionStatus; | |||||
@ApiModelProperty(value = "任务状态") | |||||
private int taskStatus; | |||||
@ApiModelProperty(value = "项目id") | |||||
private int projectId; | |||||
@ApiModelProperty(value = "城市id") | |||||
private int cityId; | |||||
@ApiModelProperty(value = "用户id") | |||||
private int userId; | |||||
} |
@@ -0,0 +1,54 @@ | |||||
package com.yuexiu.secp.read.controller; | |||||
import com.sie.iot.common.bean.ResponseData; | |||||
import com.sie.iot.common.secure.annotation.CheckToken; | |||||
import com.yuexiu.secp.read.dto.ArticleQueryDto; | |||||
import com.yuexiu.secp.read.model.entities.ArticleEntity; | |||||
import com.yuexiu.secp.read.model.service.IArticleServer; | |||||
import io.swagger.annotations.Api; | |||||
import io.swagger.annotations.ApiOperation; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.validation.annotation.Validated; | |||||
import org.springframework.web.bind.annotation.*; | |||||
import java.util.List; | |||||
@Validated | |||||
@Api(value = "阅读有礼-文章", tags = "阅读有礼-文章") | |||||
@RestController | |||||
@RequestMapping("/read/article") | |||||
public class ArticleController { | |||||
@Autowired | |||||
private IArticleServer iArticleServer; | |||||
/** | |||||
* 最新推查询 | |||||
* @param articleQueryDto | |||||
* @return | |||||
*/ | |||||
@ApiOperation(value = "查询最新推荐", notes = "根据城市与项目查询最新推荐数据") | |||||
@PostMapping(value = "/findNewest") | |||||
@CheckToken | |||||
public ResponseData<List<ArticleEntity>> findNewest(@RequestBody ArticleQueryDto articleQueryDto) { | |||||
List<ArticleEntity> recommendedAndPast = iArticleServer.findNewest(articleQueryDto); | |||||
return ResponseData.data(recommendedAndPast); | |||||
} | |||||
/** | |||||
* 查询往期推荐 | |||||
*/ | |||||
@ApiOperation(value = "查询往期推荐", notes = "根据城市与项目查询往期推荐数据") | |||||
@PostMapping(value = "/findPrevious") | |||||
@CheckToken | |||||
public ResponseData<List<ArticleEntity>> findPrevious(@RequestBody ArticleQueryDto articleQueryDto) { | |||||
List<ArticleEntity> recommendedAndPast = iArticleServer.findPrevious(articleQueryDto); | |||||
return ResponseData.data(recommendedAndPast); | |||||
} | |||||
} |
@@ -1,16 +1,12 @@ | |||||
package com.yuexiu.secp.read.controller; | package com.yuexiu.secp.read.controller; | ||||
import com.alibaba.fastjson.JSONObject; | |||||
import com.sie.iot.common.bean.RequestData; | import com.sie.iot.common.bean.RequestData; | ||||
import com.sie.iot.common.bean.ResponseData; | import com.sie.iot.common.bean.ResponseData; | ||||
import com.sie.iot.common.model.inter.IBaseCommon; | import com.sie.iot.common.model.inter.IBaseCommon; | ||||
import com.sie.iot.common.secure.annotation.CheckToken; | import com.sie.iot.common.secure.annotation.CheckToken; | ||||
import com.sie.iot.common.services.CommonAbstractService; | import com.sie.iot.common.services.CommonAbstractService; | ||||
import com.yuexiu.secp.read.dto.ArticlePreviewDto; | import com.yuexiu.secp.read.dto.ArticlePreviewDto; | ||||
import com.yuexiu.secp.read.dto.CostUnitDto; | |||||
import com.yuexiu.secp.read.dto.RecommendDto; | |||||
import com.yuexiu.secp.read.model.entities.ArticlePreviewEntity; | import com.yuexiu.secp.read.model.entities.ArticlePreviewEntity; | ||||
import com.yuexiu.secp.read.model.entities.CostUnitEntity; | |||||
import com.yuexiu.secp.read.model.service.IArticlePreview; | import com.yuexiu.secp.read.model.service.IArticlePreview; | ||||
import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
@@ -26,14 +22,9 @@ public class ArticlePreviewController extends CommonAbstractService { | |||||
@Override | @Override | ||||
public IBaseCommon<?> getBaseCommonServer() { | public IBaseCommon<?> getBaseCommonServer() { | ||||
return this.iReadService;; | |||||
return this.iReadService; | |||||
} | } | ||||
@GetMapping(value = "/findRecommendedAndPast") | |||||
public String findRecommendedAndPast(RecommendDto articlePreviewDto) { | |||||
return iReadService.findRecommendedAndPast(articlePreviewDto); | |||||
} | |||||
@ApiOperation(value = "保存成本单位", notes = "保存成本单位") | @ApiOperation(value = "保存成本单位", notes = "保存成本单位") | ||||
@PostMapping(value = "/save") | @PostMapping(value = "/save") | ||||
@@ -0,0 +1,33 @@ | |||||
package com.yuexiu.secp.read.controller; | |||||
import com.sie.iot.common.bean.ResponseData; | |||||
import com.sie.iot.common.secure.annotation.CheckToken; | |||||
import com.yuexiu.secp.read.model.service.IArticleServer; | |||||
import io.swagger.annotations.Api; | |||||
import io.swagger.annotations.ApiOperation; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.validation.annotation.Validated; | |||||
import org.springframework.web.bind.annotation.GetMapping; | |||||
import org.springframework.web.bind.annotation.PathVariable; | |||||
import org.springframework.web.bind.annotation.RequestMapping; | |||||
import org.springframework.web.bind.annotation.RestController; | |||||
@Validated | |||||
@Api(value = "阅读有礼文章统计数", tags = "阅读有礼文章统计数") | |||||
@RestController | |||||
@RequestMapping("/read/") | |||||
public class ArticleStatisticsController { | |||||
@Autowired | |||||
private IArticleServer iArticleServer; | |||||
@ApiOperation(value = "根据文章id获取统计数", notes = "根据文章id获取统计数") | |||||
@GetMapping(value = "/find/{articleId}/count") | |||||
@CheckToken | |||||
public ResponseData findByArticleIdCount(@PathVariable Long articleId) { | |||||
iArticleServer.findByArticleIdCount(articleId); | |||||
return null; | |||||
} | |||||
} |
@@ -10,7 +10,6 @@ import com.yuexiu.secp.read.model.entities.CostUnitEntity; | |||||
public interface IArticlePreview extends IBaseCommon<CostUnitEntity> { | public interface IArticlePreview extends IBaseCommon<CostUnitEntity> { | ||||
String findRecommendedAndPast(RecommendDto articlePreviewDto); | |||||
ArticlePreviewEntity saveArticlePreview(ArticlePreviewDto dto); | ArticlePreviewEntity saveArticlePreview(ArticlePreviewDto dto); | ||||
@@ -0,0 +1,21 @@ | |||||
package com.yuexiu.secp.read.model.service; | |||||
import com.yuexiu.secp.read.dto.ArticleQueryDto; | |||||
import com.yuexiu.secp.read.dto.RecommendDto; | |||||
import com.yuexiu.secp.read.model.entities.ArticleEntity; | |||||
import java.util.List; | |||||
public interface IArticleServer { | |||||
List<ArticleEntity> findNewest(ArticleQueryDto articleQueryDto); | |||||
List<ArticleEntity> findPrevious(ArticleQueryDto articleQueryDto); | |||||
void findByArticleIdCount(Long articleId); | |||||
} |
@@ -36,70 +36,6 @@ public class ArticlePreviewServer extends BaseCommonServer<CostUnitEntity> imple | |||||
private ArticlePreviewDao articlePreviewDao; | private ArticlePreviewDao articlePreviewDao; | ||||
@Override | |||||
public String findRecommendedAndPast(RecommendDto articlePreviewDto) { | |||||
//项目的集合信息 | |||||
List<ArticlePreviewEntity> projectList = new ArrayList<>(); | |||||
//城市的集合信息 | |||||
List<ArticlePreviewEntity> articlePreviewList = new ArrayList<>(); | |||||
List<ArticlePreviewEntity> dataList = new ArrayList<>(); | |||||
//查询是否有最新推荐 | |||||
int count = articlePreviewDao.findRecommend(); | |||||
if (count < 1) { | |||||
return "为空"; | |||||
} | |||||
//获取当前登录用户 | |||||
//获取我已推荐的文章 | |||||
Set<String> recommendIdList = redisTemplate.opsForSet().members("sie:recommend:1"); | |||||
//获取所有文章的信息 | |||||
Map<Object, Object> entries = redisTemplate.opsForHash().entries("sie:read:article"); | |||||
ObjectMapper objectMapper = new ObjectMapper(); | |||||
//剔除我已推荐文章 | |||||
for (String recommendId : recommendIdList) { | |||||
entries.remove(recommendId); | |||||
} | |||||
Collection<Object> values = entries.values(); | |||||
//判断是否有房产 | |||||
if (true) { | |||||
for (Object value : values) { | |||||
//匹配项目,任务状态为已发布 , 推广状态为有效 | |||||
ArticlePreviewEntity articlePreview = objectMapper.convertValue(value,ArticlePreviewEntity.class); | |||||
if(articlePreview.getPromotionStatus() == articlePreviewDto.getPromotionStatus() && | |||||
articlePreview.getTaskStatus() == articlePreviewDto.getTaskStatus()){ | |||||
//往城市里的集合塞数据 | |||||
projectList.add(articlePreview); | |||||
} | |||||
System.out.println(value); | |||||
} | |||||
} | |||||
for (Object value : values) { | |||||
//匹配城市,任务状态为已发布 , 推广状态为有效 | |||||
ArticlePreviewEntity articlePreview = objectMapper.convertValue(value,ArticlePreviewEntity.class); | |||||
if(articlePreview.getPromotionStatus() == articlePreviewDto.getPromotionStatus() && | |||||
articlePreview.getTaskStatus() == articlePreviewDto.getTaskStatus()){ | |||||
//往城市里的集合塞数据 | |||||
articlePreviewList.add(articlePreview); | |||||
} | |||||
System.out.println(value); | |||||
} | |||||
//如果项目类型不为空,合并项目和城市 | |||||
if(!CollectionUtils.isEmpty(projectList)){ | |||||
Iterables.addAll(dataList, projectList); | |||||
Iterables.addAll(dataList, articlePreviewList); | |||||
} | |||||
return "不为空"; | |||||
} | |||||
@Override | @Override | ||||
public ArticlePreviewEntity saveArticlePreview(ArticlePreviewDto dto) { | public ArticlePreviewEntity saveArticlePreview(ArticlePreviewDto dto) { | ||||
@@ -0,0 +1,127 @@ | |||||
package com.yuexiu.secp.read.model.service.impl; | |||||
import com.fasterxml.jackson.databind.ObjectMapper; | |||||
import com.google.common.collect.Iterables; | |||||
import com.yuexiu.secp.read.dto.ArticleQueryDto; | |||||
import com.yuexiu.secp.read.infra.util.RedisUtils; | |||||
import com.yuexiu.secp.read.model.dao.ArticlePreviewDao; | |||||
import com.yuexiu.secp.read.model.entities.ArticleEntity; | |||||
import com.yuexiu.secp.read.model.service.IArticleServer; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.data.redis.core.StringRedisTemplate; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.util.CollectionUtils; | |||||
import java.util.*; | |||||
/** | |||||
* @author YuChengLong | |||||
* @date 2022/5/10 | |||||
*/ | |||||
@Service | |||||
public class ArticleServer implements IArticleServer{ | |||||
/** | |||||
* redis | |||||
*/ | |||||
@Autowired | |||||
private StringRedisTemplate redisTemplate; | |||||
/** | |||||
* 文章DAO | |||||
*/ | |||||
@Autowired | |||||
private ArticlePreviewDao articlePreviewDao; | |||||
/** | |||||
* 最新推荐 | |||||
* @param articleQueryDto | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public List<ArticleEntity> findNewest(ArticleQueryDto articleQueryDto) { | |||||
//项目的集合信息 | |||||
List<ArticleEntity> projectList = new ArrayList<>(); | |||||
//城市的集合信息 | |||||
List<ArticleEntity> articlePreviewList = new ArrayList<>(); | |||||
List<ArticleEntity> dataList = new ArrayList<>(); | |||||
//查询是否有最新推荐 | |||||
int count = articlePreviewDao.findRecommend(); | |||||
if (count < 1) { | |||||
return null; | |||||
} | |||||
//获取当前登录用户 | |||||
//获取我已推荐的文章 | |||||
Set<String> recommendIdList = redisTemplate.opsForSet().members(RedisUtils.getRedisKey("SIE" , "RECOMMEND" ,String.valueOf(articleQueryDto.getUserId()))); | |||||
//获取所有文章的信息 | |||||
Map<Object, Object> entries = redisTemplate.opsForHash().entries(RedisUtils.getRedisKey("SIE" , "READ" ,"ARTICLE")); | |||||
ObjectMapper objectMapper = new ObjectMapper(); | |||||
//剔除我已推荐文章 | |||||
for (String recommendId : recommendIdList) { | |||||
entries.remove(recommendId); | |||||
} | |||||
Collection<Object> values = entries.values(); | |||||
//判断是否有房产 | |||||
//todo 调用第三方接口cdp,查询是否有房产 | |||||
if (true) { | |||||
for (Object value : values) { | |||||
//匹配项目,任务状态为已发布 , 推广状态为有效 | |||||
ArticleEntity articlePreview = objectMapper.convertValue(value,ArticleEntity.class); | |||||
if(articlePreview.getPromotionStatus() == articleQueryDto.getPromotionStatus() && | |||||
articlePreview.getTaskStatus() == articleQueryDto.getTaskStatus()){ | |||||
//往城市里的集合塞数据 | |||||
projectList.add(articlePreview); | |||||
} | |||||
System.out.println(value); | |||||
} | |||||
} | |||||
for (Object value : values) { | |||||
//匹配城市,任务状态为已发布 , 推广状态为有效 | |||||
ArticleEntity articlePreview = objectMapper.convertValue(value,ArticleEntity.class); | |||||
if(articlePreview.getPromotionStatus() == articleQueryDto.getPromotionStatus() && | |||||
articlePreview.getTaskStatus() == articleQueryDto.getTaskStatus()){ | |||||
//往城市里的集合塞数据 | |||||
articlePreviewList.add(articlePreview); | |||||
} | |||||
System.out.println(value); | |||||
} | |||||
//如果项目类型不为空,合并项目和城市 | |||||
if(!CollectionUtils.isEmpty(projectList)){ | |||||
Iterables.addAll(dataList, projectList); | |||||
Iterables.addAll(dataList, articlePreviewList); | |||||
} | |||||
return dataList; | |||||
} | |||||
/** | |||||
* 往期推荐 | |||||
* @param articleQueryDto | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public List<ArticleEntity> findPrevious(ArticleQueryDto articleQueryDto) { | |||||
return null; | |||||
} | |||||
@Override | |||||
public void findByArticleIdCount(Long articleId) { | |||||
} | |||||
} |