diff --git a/admin/src/main/java/com/jinrui/reference/admin/controller/ApiController.java b/admin/src/main/java/com/jinrui/reference/admin/controller/ApiController.java index 7c71592..9890482 100644 --- a/admin/src/main/java/com/jinrui/reference/admin/controller/ApiController.java +++ b/admin/src/main/java/com/jinrui/reference/admin/controller/ApiController.java @@ -19,6 +19,7 @@ import com.jinrui.reference.admin.model.entity.AdminUser; import com.jinrui.reference.admin.service.AdminJwtService; import com.jinrui.reference.core.model.vo.ResultObject; import com.jinrui.reference.core.model.vo.news.NewsApi2VO; +import com.jinrui.reference.core.model.vo.news.NewsApi4VO; import com.jinrui.reference.core.model.vo.news.NewsApiVO; import com.jinrui.reference.core.service.ApiKeyService; import com.jinrui.reference.core.service.NewsService; @@ -39,7 +40,7 @@ public class ApiController { @GetMapping("/news") public ResultObject> getNews(@RequestParam(name = "num", required = true, defaultValue = "10") Integer num, @RequestParam(name = "last", required = false) Long last, HttpServletRequest request) { String accessKey = request.getHeader("X-Api-Key"); - Integer clientType = apiKeyService.getClientType(accessKey); + Integer clientType = apiKeyService.getClientType(accessKey, "v1"); if (clientType == null||clientType == 0) { return ResultObject.failed("非法操作!"); } @@ -50,7 +51,7 @@ public class ApiController { @PostMapping("/news") public ResultObject> queryNews(@RequestParam(name = "num", required = true, defaultValue = "10") Integer num, @RequestParam(name = "last", required = false) Long last, HttpServletRequest request) { String accessKey = request.getHeader("X-Api-Key"); - Integer clientType = apiKeyService.getClientType(accessKey); + Integer clientType = apiKeyService.getClientType(accessKey, "v1"); if (clientType == null||clientType == 0) { return ResultObject.failed("非法操作!"); } @@ -60,7 +61,7 @@ public class ApiController { @PostMapping("/news/published") public ResultObject> queryPublishedNews(@RequestParam(name = "num", required = true, defaultValue = "10") Integer num, @RequestParam(name = "last", required = false) Long last, HttpServletRequest request) { String accessKey = request.getHeader("X-Api-Key"); - Integer clientType = apiKeyService.getClientType(accessKey); + Integer clientType = apiKeyService.getClientType(accessKey, "v1"); if (clientType == null) { return ResultObject.failed("非法操作,用户不存在!"); } @@ -70,13 +71,39 @@ public class ApiController { @GetMapping("/news/v2") public ResultObject> getNewsV2(HttpServletRequest request) { String accessKey = request.getHeader("X-Api-Key"); - Integer clientType = apiKeyService.getClientType(accessKey); + Integer clientType = apiKeyService.getClientType(accessKey, "v2"); if (clientType == null||clientType == 0) { return ResultObject.failed("非法操作!"); } return newsService.requestNewsByApi2(); } + @GetMapping("/news/v3") + public ResultObject> getNewsV3(HttpServletRequest request) { + String accessKey = request.getHeader("X-Api-Key"); + Integer clientType = apiKeyService.getClientType(accessKey, "v3"); + if (clientType == null) { + return ResultObject.failed("非法操作,用户不存在!"); + } + ResultObject> result = newsService.requestNewsByApi(10, null, clientType); + List newsList = result.getData(); + newsList.forEach(e -> e.setSource("中国证券报")); + return result; + } + + @GetMapping("/news/v4") + public ResultObject> getNewsV4(@RequestParam(name = "num", required = false, defaultValue = "10000") Integer num, @RequestParam(name = "last", required = false) Long last, HttpServletRequest request) { + String accessKey = request.getHeader("X-Api-Key"); + Integer clientType = apiKeyService.getClientType(accessKey, "v4"); + if (clientType == null) { + return ResultObject.failed("非法操作,用户不存在!"); + } + ResultObject> result = newsService.requestNewsByApi4(num, last, clientType); + List newsList = result.getData(); + newsList.forEach(e -> e.setSource("中国证券报")); + return result; + } + @PostMapping("/key") public ResultObject> generateApiKey(@RequestHeader("auth-token") String token, @RequestParam(name = "clientName", required = true) String clientName, diff --git a/core/src/main/java/com/jinrui/reference/core/mapper/ApiUserMapper.java b/core/src/main/java/com/jinrui/reference/core/mapper/ApiUserMapper.java index a3d2d30..80508c7 100644 --- a/core/src/main/java/com/jinrui/reference/core/mapper/ApiUserMapper.java +++ b/core/src/main/java/com/jinrui/reference/core/mapper/ApiUserMapper.java @@ -10,8 +10,8 @@ public interface ApiUserMapper { @Select("select secret_key from api_user where access_key = #{ak} and disabled = 0") String getClientSecretkey(@Param("ak") String ak); - @Select("select fulled from api_user where access_key = #{ak} and disabled = 0") - Integer getClientType(@Param("ak") String ak); + @Select("select fulled from api_user where access_key = #{ak} and disabled = 0 and api_version = #{version}") + Integer getClientType(@Param("ak") String ak, @Param("version") String version); @Select("select access_key, secret_key from api_user where client_name = #{clientName} and disabled = 0") Map getClientKey(@Param("clientName") String clientName); diff --git a/core/src/main/java/com/jinrui/reference/core/mapper/NewsMapper.java b/core/src/main/java/com/jinrui/reference/core/mapper/NewsMapper.java index 5448752..2fa3775 100644 --- a/core/src/main/java/com/jinrui/reference/core/mapper/NewsMapper.java +++ b/core/src/main/java/com/jinrui/reference/core/mapper/NewsMapper.java @@ -16,6 +16,7 @@ import org.apache.ibatis.type.JdbcType; import com.jinrui.reference.core.model.entity.News; import com.jinrui.reference.core.model.entity.NewsDraft; import com.jinrui.reference.core.model.vo.news.NewsApi2VO; +import com.jinrui.reference.core.model.vo.news.NewsApi4VO; import com.jinrui.reference.core.model.vo.news.NewsApiVO; import com.jinrui.reference.core.typehandler.JsonArrayTypeHandler; @@ -464,6 +465,7 @@ public interface NewsMapper { @Result(column = "tdx_industry", property = "tdxIndustry", typeHandler = JsonArrayTypeHandler.class), @Result(column = "tdx_industry_confidence", property = "tdxIndustryConfidence", typeHandler = JsonArrayTypeHandler.class), @Result(column = "company_name", property = "companyName"), + @Result(column = "source", property = "source"), @Result(column = "news_score", property = "newsScore"), }) @Select("") List queryNewsByApi3(@Param("limit") int limit); + + @Results({ + @Result(column = "id", property = "id", id = true), + @Result(column = "llm_title", property = "title"), + @Result(column = "llm_content", property = "content"), + @Result(column = "summary", property = "summary"), + @Result(column = "publish_time", property = "publishTime"), + @Result(column = "industry_label", property = "industryLabel", typeHandler = JsonArrayTypeHandler.class), + @Result(column = "industry_confidence", property = "industryConfidence", typeHandler = JsonArrayTypeHandler.class), + @Result(column = "industry_score", property = "industryScore", typeHandler = JsonArrayTypeHandler.class), + @Result(column = "concept_label", property = "conceptLabel", typeHandler = JsonArrayTypeHandler.class), + @Result(column = "concept_confidence", property = "conceptConfidence", typeHandler = JsonArrayTypeHandler.class), + @Result(column = "concept_score", property = "conceptScore", typeHandler = JsonArrayTypeHandler.class), + @Result(column = "source", property = "source"), + @Result(column = "source_impact", property = "sourceImpact"), + @Result(column = "China_factor", property = "chinaFactor"), + @Result(column = "public_opinion_score", property = "publicOpinionScore"), + @Result(column = "news_score", property = "newsScore"), + @Result(column = "stock_codes", property = "stockCodes", typeHandler = JsonArrayTypeHandler.class), + @Result(column = "stock_names", property = "stockNames", typeHandler = JsonArrayTypeHandler.class), + @Result(column = "company_name", property = "companyName"), + }) + @Select("") + List queryNewsByApi4(@Param("last") Long last, @Param("limit") int limit, @Param("clientType") int clientType); + } diff --git a/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsApi2VO.java b/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsApi2VO.java index c30bf2f..cfb48df 100644 --- a/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsApi2VO.java +++ b/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsApi2VO.java @@ -100,7 +100,7 @@ public class NewsApi2VO { private List tdxIndustry; - private List tdxIndustryConfidence; + private List tdxIndustryConfidence; private Boolean published; @@ -197,11 +197,11 @@ public class NewsApi2VO { this.tdxIndustry = tdxIndustry; } - public List getTdxIndustryConfidence() { + public List getTdxIndustryConfidence() { return tdxIndustryConfidence; } - public void setTdxIndustryConfidence(List tdxIndustryConfidence) { + public void setTdxIndustryConfidence(List tdxIndustryConfidence) { this.tdxIndustryConfidence = tdxIndustryConfidence; } diff --git a/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsApi4VO.java b/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsApi4VO.java new file mode 100644 index 0000000..4ced2b3 --- /dev/null +++ b/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsApi4VO.java @@ -0,0 +1,303 @@ +package com.jinrui.reference.core.model.vo.news; + +import java.util.Date; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonFormat; + +public class NewsApi4VO { + /** + * 资讯ID + */ + private Long id; + + /** + * 资讯标题 + */ + private String title; + + /** + * 资讯内容 + */ + private String content; + + /** + * 报道时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") + private Date publishTime; + + /** + * 资讯摘要 + */ + private String summary; + + /** + * 资讯评分 + */ + private Double newsScore; + + /** + * 资讯来源 + */ + private String source; + +// /** +// * +// */ +// private Integer exclusive; + + /** + * 行业分类标签 + */ + private List industryLabel; + + /** + * 行业分类置信度 + */ + private List industryConfidence; + + /** + * 行业分类评分 + */ + private List industryScore; + + + /** + * 概念标签 + * @return + */ + private List conceptLabel; + + /** + * 概念标签置信度 + */ + private List conceptConfidence; + + /** + * 概念标签评分 + */ + private List conceptScore; + + /** + * 媒体影响力 + */ + private Integer sourceImpact; + + /** + * 中国股市相关性 + */ + private Double chinaFactor; + + /** + * 资讯质量 + */ + private Integer publicOpinionScore; + + private List stockCodes; + + private List stockNames; + +// private List tdxIndustry; +// +// private List tdxIndustryConfidence; + +// private Boolean published; + + private String companyName; + +// private String signalRule; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Date getPublishTime() { + return publishTime; + } + + public void setPublishTime(Date publishTime) { + this.publishTime = publishTime; + } + + public String getSummary() { + return summary; + } + + public void setSummary(String summary) { + this.summary = summary; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + + public Double getNewsScore() { + return newsScore; + } + + public void setNewsScore(Double newsScore) { + this.newsScore = newsScore; + } + +// public Integer getExclusive() { +// return exclusive; +// } +// +// public void setExclusive(Integer exclusive) { +// this.exclusive = exclusive; +// } + + public List getStockCodes() { + return stockCodes; + } + + public void setStockCodes(List stockCodes) { + this.stockCodes = stockCodes; + } + + public List getStockNames() { + return stockNames; + } + + public void setStockNames(List stockNames) { + this.stockNames = stockNames; + } + +// public List getTdxIndustry() { +// return tdxIndustry; +// } +// +// public void setTdxIndustry(List tdxIndustry) { +// this.tdxIndustry = tdxIndustry; +// } +// +// public List getTdxIndustryConfidence() { +// return tdxIndustryConfidence; +// } +// +// public void setTdxIndustryConfidence(List tdxIndustryConfidence) { +// this.tdxIndustryConfidence = tdxIndustryConfidence; +// } + +// public Boolean getPublished() { +// return published; +// } +// +// public void setPublished(Boolean published) { +// this.published = published; +// } + + public String getCompanyName() { + return companyName; + } + + public void setCompanyName(String companyName) { + this.companyName = companyName; + } + +// public String getSignalRule() { +// return signalRule; +// } +// +// public void setSignalRule(String signalRule) { +// this.signalRule = signalRule; +// } + + public List getIndustryLabel() { + return industryLabel; + } + + public void setIndustryLabel(List industryLabel) { + this.industryLabel = industryLabel; + } + + public List getIndustryConfidence() { + return industryConfidence; + } + + public void setIndustryConfidence(List industryConfidence) { + this.industryConfidence = industryConfidence; + } + + public List getIndustryScore() { + return industryScore; + } + + public void setIndustryScore(List industryScore) { + this.industryScore = industryScore; + } + + public List getConceptLabel() { + return conceptLabel; + } + + public void setConceptLabel(List conceptLabel) { + this.conceptLabel = conceptLabel; + } + + public List getConceptConfidence() { + return conceptConfidence; + } + + public void setConceptConfidence(List conceptConfidence) { + this.conceptConfidence = conceptConfidence; + } + + public List getConceptScore() { + return conceptScore; + } + + public void setConceptScore(List conceptScore) { + this.conceptScore = conceptScore; + } + + public Integer getSourceImpact() { + return sourceImpact; + } + + public void setSourceImpact(Integer sourceImpact) { + this.sourceImpact = sourceImpact; + } + + public Double getChinaFactor() { + return chinaFactor; + } + + public void setChinaFactor(Double chinaFactor) { + this.chinaFactor = chinaFactor; + } + + public Integer getPublicOpinionScore() { + return publicOpinionScore; + } + + public void setPublicOpinionScore(Integer publicOpinionScore) { + this.publicOpinionScore = publicOpinionScore; + } +} diff --git a/core/src/main/java/com/jinrui/reference/core/service/ApiKeyService.java b/core/src/main/java/com/jinrui/reference/core/service/ApiKeyService.java index 16b73d5..e2cadf2 100644 --- a/core/src/main/java/com/jinrui/reference/core/service/ApiKeyService.java +++ b/core/src/main/java/com/jinrui/reference/core/service/ApiKeyService.java @@ -46,8 +46,8 @@ public class ApiKeyService { return ResultObject.success(clientKeyMap); } - public Integer getClientType(String ak) { - return apiUserMapper.getClientType(ak); + public Integer getClientType(String ak, String apiVersion) { + return apiUserMapper.getClientType(ak, apiVersion); } } diff --git a/core/src/main/java/com/jinrui/reference/core/service/NewsService.java b/core/src/main/java/com/jinrui/reference/core/service/NewsService.java index cda08fa..95e57c2 100644 --- a/core/src/main/java/com/jinrui/reference/core/service/NewsService.java +++ b/core/src/main/java/com/jinrui/reference/core/service/NewsService.java @@ -63,6 +63,7 @@ import com.jinrui.reference.core.model.entity.UserOperationLog; import com.jinrui.reference.core.model.vo.PageObject; import com.jinrui.reference.core.model.vo.ResultObject; import com.jinrui.reference.core.model.vo.news.NewsApi2VO; +import com.jinrui.reference.core.model.vo.news.NewsApi4VO; import com.jinrui.reference.core.model.vo.news.NewsApiVO; import com.jinrui.reference.core.model.vo.news.NewsDetailColumn; import com.jinrui.reference.core.model.vo.news.NewsDetailColumnVip; @@ -1399,4 +1400,26 @@ public class NewsService { } return ResultObject.success(result); } + + /** + * 返回最近两天的数据 + * @param num + * @param last + * @return + */ + public ResultObject> requestNewsByApi4(Integer num, Long last, Integer clientType) { + List result = newsMapper.queryNewsByApi4(last, num, clientType); + + Map industryMap = industryMapper.queryAll().stream().collect(Collectors.toMap(Industry::getId, Function.identity())); + result.stream().forEach( e -> { + List newsTagRels = tagMapper.getNewsTagRelList(e.getId()).stream().map(x -> tagMapper.queryById(x.getTagId())).collect(Collectors.toList()); + + List conceptLabel = newsTagRels.stream().filter(t -> t != null).map(Tag::getDisplayName).collect(Collectors.toList()); + e.setConceptLabel(conceptLabel); + + List industryLabel = industryMapper.getNewsIndustryRelList(e.getId()).stream().map(x -> industryMap.get(x.getIndustryId())).filter(i -> i != null).map(n -> n.getDisplayName()).collect(Collectors.toList()); + e.setIndustryLabel(industryLabel); + }); + return ResultObject.success(result); + } }