Commit a196b04a by shenjunjie

Merge branch 'release' into 'master'

Release

See merge request !330
parents 5fe98ca2 89f68172
......@@ -62,6 +62,7 @@ public class RedisKeyPrefix {
*/
public static final String HOT_RANK_LIST = "BRANDKBS:HOT:RANK_LIST:";
public static final String HOT_LIST = "BRANDKBS:HOT:LIST:";
public static final String HOT_KEYWORD = "BRANDKBS:HOT:KEYWORD:";
/**
* 项目简报报相关缓存KEY
......@@ -120,6 +121,10 @@ public class RedisKeyPrefix {
return RedisKeyPrefix.generateRedisKey(RedisKeyPrefix.EVENT_DATA_UPLOAD_PROGRESS, UserThreadLocal.getProjectId(), ticket);
}
public static String hotKeywordKey(String projectId) {
return RedisKeyPrefix.generateRedisKey(RedisKeyPrefix.HOT_KEYWORD, projectId);
}
private static String generateRedisKey(String... keys) {
Objects.requireNonNull(keys);
boolean contains = keys[0].endsWith(":");
......
package com.zhiwei.brandkbs2.controller.app;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.aop.LogRecord;
import com.zhiwei.brandkbs2.auth.Auth;
......@@ -16,15 +17,13 @@ import com.zhiwei.brandkbs2.service.ProjectService;
import com.zhiwei.brandkbs2.util.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
......@@ -60,14 +59,89 @@ public class AppHotController extends BaseController {
private RedisUtil redisUtil;
@Autowired
private ProjectService projectService;
@Autowired
private MarkDataService markDataService;
@Resource(name = "projectServiceImpl")
ProjectService projectService;
@Resource(name = "esSearchExecutor")
ThreadPoolTaskExecutor executor;
@Value("${trends.getHotSearchFromEsInTimeAndTypeOrWord.url}")
private String hotSearchUrl;
/**
* weibo 热搜
* weibo-topic 话题
* weibo-rise 预热
* zhihu 知乎
* toutiao 头条
* douyin 抖音
* bilibili-ranking B站
*/
@ApiOperation("热点库-品牌热点-搜索")
@GetMapping("/keyword/search")
public ResponseResult search(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "type", defaultValue = "weibo") String type,
@RequestParam(value = "sort", defaultValue = "endTime") String sort,
@RequestParam(value = "startTime", required = false) Long startTime,
@RequestParam(value = "endTime", required = false) Long endTime) {
String keywordStr = redisUtil.get(RedisKeyPrefix.hotKeywordKey(UserThreadLocal.getProjectId()));
if (null == keywordStr) {
return ResponseResult.success();
}
String keyword = StringUtils.join(JSONArray.parseArray(keywordStr, String.class), "|");
ResponseEntity<JSONObject> jsonObjectResponseEntity;
if (null != startTime && null != endTime) {
jsonObjectResponseEntity = restTemplate.getForEntity(hotSearchUrl + "&startTime={6}&endTime={7}", JSONObject.class, pageSize, page, type, keyword, sort, startTime, endTime);
} else {
jsonObjectResponseEntity = restTemplate.getForEntity(hotSearchUrl, JSONObject.class, pageSize, page, type, keyword, sort);
}
JSONObject result = jsonObjectResponseEntity.getBody();
if (Objects.isNull(result)) {
return ResponseResult.failure("响应超时");
}
// 查询在榜数据
ResponseEntity<JSONObject> responseEntity = restTemplate.getForEntity(trendsListUrl, JSONObject.class, null, type, null);
if (Objects.isNull(responseEntity.getBody())) {
return ResponseResult.success(result);
}
List<String> rankingIds = responseEntity.getBody().getJSONArray("data").stream().map(obj -> ((JSONObject) obj).getString("_id")).collect(Collectors.toList());
List<JSONObject> list = result.getJSONArray("data").stream().map(obj -> {
JSONObject json = (JSONObject) obj;
if (rankingIds.contains(json.getString("id"))) {
json.put("inTheList", true);
}
return json;
}).collect(Collectors.toList());
result.put("data", list);
return ResponseResult.success(result);
}
@ApiOperation("热点库-品牌热点-关键词获取")
@GetMapping("/keyword")
public ResponseResult getKeyword() {
String projectId = UserThreadLocal.getProjectId();
String key = RedisKeyPrefix.hotKeywordKey(projectId);
String keywordStr = redisUtil.get(key);
if (null == keywordStr) {
// 默认返回并设置品牌名
List<String> defaultKeyword = Collections.singletonList(projectService.getProjectById(projectId).getBrandName());
redisUtil.set(key, JSON.toJSONString(defaultKeyword));
return ResponseResult.success(defaultKeyword);
}
return ResponseResult.success(JSONArray.parseArray(keywordStr));
}
@ApiOperation("热点库-品牌热点-关键词调整")
@PutMapping("/keyword/update")
public ResponseResult updateKeyword(@RequestBody JSONObject json) {
JSONArray list = json.getJSONArray("list");
redisUtil.set(RedisKeyPrefix.hotKeywordKey(UserThreadLocal.getProjectId()), list.toJSONString());
return ResponseResult.success();
}
/**
* weibo 热搜
* weibo-topic 话题
......@@ -81,23 +155,14 @@ public class AppHotController extends BaseController {
@LogRecord(description = "热点库")
@GetMapping("/getHotList")
public ResponseResult getHotList(@RequestParam(value = "sortType", defaultValue = "realTime") String sortType,
@RequestParam(value = "type", defaultValue = "weibo") String type) {
ResponseEntity<JSONObject> jsonObjectResponseEntity = restTemplate.getForEntity(trendsListUrl, JSONObject.class, sortType, type);
Object data = jsonObjectResponseEntity.getBody().get("data");
String redisKey = RedisKeyPrefix.HOT_LIST + type;
String result = redisUtil.get(redisKey);
// 当舆论场崩溃时从缓存里获取
@RequestParam(value = "type", defaultValue = "weibo") String type,
@RequestParam(value = "day", required = false) String day) {
ResponseEntity<JSONObject> jsonObjectResponseEntity = restTemplate.getForEntity(trendsListUrl, JSONObject.class, sortType, type, day);
Object data = Objects.requireNonNull(jsonObjectResponseEntity.getBody()).get("data");
if (Objects.nonNull(data)) {
if (Objects.isNull(result)) {
redisUtil.setExpire(redisKey, JSON.toJSONString(data), ONE_HOUR, TimeUnit.HOURS);
}
return ResponseResult.success(data);
} else {
if (Objects.nonNull(result)) {
return ResponseResult.success(result);
}
return ResponseResult.failure("响应超时");
}
return ResponseResult.failure("响应超时");
}
@ApiOperation("热点库-热点榜单")
......
......@@ -81,9 +81,10 @@ crisis.list.url=https://crisis.zhiweidata.com/app/brandkbs/crisisList?page={1}&s
crisis.share.url=https://crisis.zhiweidata.com/app/brandkbs/share/{1}
crisis.event.url =https://crisis.zhiweidata.com/event/{1}/general?share={2}
#\u70ED\u70B9\u5E93\u5916\u90E8\u63A5\u53E3
trends.longTimeInListSearchByInner.url=https://trends.zhiweidata.com/hotSearchTrend/inner/longTimeInListSearchByInner?sortType={1}&type={2}
trends.longTimeInListSearchByInner.url=https://trends.zhiweidata.com/hotSearchTrend/inner/longTimeInListSearchByInner?sortType={1}&type={2}&day={3}
trends.findHotSearchESDataInTimeByInner.url=https://hotsearch-manage.zhiweidata.com/hotsearch/hotSearch/findHotSearchESDataInTimeByInner?limit={1}&page={2}&type={3}&word={4}
trends.longTimeInListSearch.url=https://trends.zhiweidata.com/hotSearchTrend/search/longTimeInListSearch?type={1}&sortType=realTime
trends.getHotSearchFromEsInTimeAndTypeOrWord.url=https://hotsearch-manage.zhiweidata.com/hotsearch/hotSearch/getHotSearchFromEsInTimeAndTypeOrWord?limit={1}&page={2}&type={3}&word={4}&sort={5}
#\u4E8B\u4EF6\u5E93\u5916\u90E8\u63A5\u53E3
ef.search.url=https://ef.zhiweidata.com/external/search.do?name={1}&page={2}
ef.searchCriteria.url=https://ef.zhiweidata.com/index/getSearchKey.do
......
......@@ -84,9 +84,10 @@ crisis.list.url=https://crisis.zhiweidata.com/app/brandkbs/crisisList?page={1}&s
crisis.share.url=https://crisis.zhiweidata.com/app/brandkbs/share/{1}
crisis.event.url =https://crisis.zhiweidata.com/event/{1}/general?share={2}
#\u70ED\u70B9\u5E93\u5916\u90E8\u63A5\u53E3
trends.longTimeInListSearchByInner.url=https://trends.zhiweidata.com/hotSearchTrend/inner/longTimeInListSearchByInner?sortType={1}&type={2}
trends.longTimeInListSearchByInner.url=https://trends.zhiweidata.com/hotSearchTrend/inner/longTimeInListSearchByInner?sortType={1}&type={2}&day={3}
trends.findHotSearchESDataInTimeByInner.url=https://hotsearch-manage.zhiweidata.com/hotsearch/hotSearch/findHotSearchESDataInTimeByInner?limit={1}&page={2}&type={3}&word={4}
trends.longTimeInListSearch.url=https://trends.zhiweidata.com/hotSearchTrend/search/longTimeInListSearch?type={1}&sortType=realTime
trends.getHotSearchFromEsInTimeAndTypeOrWord.url=https://hotsearch-manage.zhiweidata.com/hotsearch/hotSearch/getHotSearchFromEsInTimeAndTypeOrWord?limit={1}&page={2}&type={3}&word={4}&sort={5}
#\u4E8B\u4EF6\u5E93\u5916\u90E8\u63A5\u53E3
ef.search.url=https://ef.zhiweidata.com/external/search.do?name={1}&page={2}&size={3}
ef.searchCriteria.url=https://ef.zhiweidata.com/index/getSearchKey.do
......
......@@ -81,9 +81,10 @@ crisis.list.url=https://crisis.zhiweidata.com/app/brandkbs/crisisList?page={1}&s
crisis.share.url=https://crisis.zhiweidata.com/app/brandkbs/share/{1}
crisis.event.url =https://crisis.zhiweidata.com/event/{1}/general?share={2}
#\u70ED\u70B9\u5E93\u5916\u90E8\u63A5\u53E3
trends.longTimeInListSearchByInner.url=https://trends.zhiweidata.com/hotSearchTrend/inner/longTimeInListSearchByInner?sortType={1}&type={2}
trends.longTimeInListSearchByInner.url=https://trends.zhiweidata.com/hotSearchTrend/inner/longTimeInListSearchByInner?sortType={1}&type={2}&day={3}
trends.findHotSearchESDataInTimeByInner.url=https://hotsearch-manage.zhiweidata.com/hotsearch/hotSearch/findHotSearchESDataInTimeByInner?limit={1}&page={2}&type={3}&word={4}
trends.longTimeInListSearch.url=https://trends.zhiweidata.com/hotSearchTrend/search/longTimeInListSearch?type={1}&sortType=realTime
trends.getHotSearchFromEsInTimeAndTypeOrWord.url=https://hotsearch-manage.zhiweidata.com/hotsearch/hotSearch/getHotSearchFromEsInTimeAndTypeOrWord?limit={1}&page={2}&type={3}&word={4}&sort={5}
#\u4E8B\u4EF6\u5E93\u5916\u90E8\u63A5\u53E3
ef.search.url=https://ef.zhiweidata.com/external/search.do?name={1}&page={2}
ef.searchCriteria.url=https://ef.zhiweidata.com/index/getSearchKey.do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment