Commit 26d81c35 by shenjunjie

Merge branch 'release' into 'master'

Release

See merge request !385
parents 8308c137 e9ddade4
......@@ -266,6 +266,7 @@ public class AppChannelController extends BaseController {
@ApiImplicitParams({@ApiImplicitParam(name = "contendId", value = "品牌id", defaultValue = "0", paramType = "query", dataType = "string"),
@ApiImplicitParam(name = "startTime", value = "起始时间", paramType = "query", dataType = "long"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "long"),
@ApiImplicitParam(name = "sorter", defaultValue = "{\"index\":\"descend\"}", value = "排序字段", paramType = "query", dataType = "string"),
@ApiImplicitParam(name = "pageSize", value = "选取前几", defaultValue = "50", paramType = "query", dataType = "int"),
})
@ApiOperation("渠道库-友好渠道榜")
......@@ -274,13 +275,15 @@ public class AppChannelController extends BaseController {
public ResponseResult getPositiveChannelList(@RequestParam(value = "contendId", defaultValue = "0") String contendId,
@RequestParam(value = "startTime", required = false) Long startTime,
@RequestParam(value = "endTime", required = false) Long endTime,
@RequestParam(value = "sorter", defaultValue = "{\"index\":\"descend\"}") String sorter,
@RequestParam(value = "pageSize", defaultValue = "50") int size) {
return ResponseResult.success(channelService.getPositiveChannelList(contendId, startTime, endTime, size, true));
return ResponseResult.success(channelService.getPositiveChannelList(contendId, startTime, endTime, size, sorter, true));
}
@ApiImplicitParams({@ApiImplicitParam(name = "contendId", value = "品牌id", defaultValue = "0", paramType = "query", dataType = "string"),
@ApiImplicitParam(name = "startTime", value = "起始时间", paramType = "query", dataType = "long"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "long"),
@ApiImplicitParam(name = "sorter", defaultValue = "{\"index\":\"descend\"}", value = "排序字段", paramType = "query", dataType = "string"),
@ApiImplicitParam(name = "pageSize", value = "选取前几", defaultValue = "50", paramType = "query", dataType = "int"),
})
@ApiOperation("渠道库-敏感渠道榜")
......@@ -289,8 +292,9 @@ public class AppChannelController extends BaseController {
public ResponseResult getNegativeChannelList(@RequestParam(value = "contendId", defaultValue = "0") String contendId,
@RequestParam(value = "startTime", required = false) Long startTime,
@RequestParam(value = "endTime", required = false) Long endTime,
@RequestParam(value = "sorter", defaultValue = "{\"index\":\"descend\"}") String sorter,
@RequestParam(value = "pageSize", defaultValue = "50") int size) {
return ResponseResult.success(channelService.getNegativeChannelList(contendId, startTime, endTime, size, true));
return ResponseResult.success(channelService.getNegativeChannelList(contendId, startTime, endTime, size, sorter, true));
}
@ApiOperation("渠道库-渠道申请")
......
......@@ -169,7 +169,7 @@ public interface ChannelService {
* @param size 数据量
* @return
*/
JSONObject getPositiveChannelList(String contendId, Long startTime, Long endTime, int size, boolean cache);
JSONObject getPositiveChannelList(String contendId, Long startTime, Long endTime, int size, String sorter, boolean cache);
/**
* 新-敏感渠道榜
......@@ -179,7 +179,7 @@ public interface ChannelService {
* @param size 数据量
* @return
*/
JSONObject getNegativeChannelList(String contendId, Long startTime, Long endTime, int size, boolean cache);
JSONObject getNegativeChannelList(String contendId, Long startTime, Long endTime, int size, String sorter, boolean cache);
/**
* 收藏渠道
......
......@@ -451,20 +451,20 @@ public class ChannelServiceImpl implements ChannelService {
@Override
public JSONObject getActiveChannelList(String contendId, Long startTime, Long endTime, int size, boolean cache) {
return getChannelListCache(contendId, startTime, endTime, EmotionEnum.ALL.getState(), size, cache);
return getChannelListCache(contendId, startTime, endTime, EmotionEnum.ALL.getState(), size, null, cache);
}
@Override
public JSONObject getPositiveChannelList(String contendId, Long startTime, Long endTime, int size, boolean cache) {
return getChannelListCache(contendId, startTime, endTime, EmotionEnum.POSITIVE.getState(), size, cache);
public JSONObject getPositiveChannelList(String contendId, Long startTime, Long endTime, int size, String sorter, boolean cache) {
return getChannelListCache(contendId, startTime, endTime, EmotionEnum.POSITIVE.getState(), size, sorter, cache);
}
@Override
public JSONObject getNegativeChannelList(String contendId, Long startTime, Long endTime, int size, boolean cache) {
return getChannelListCache(contendId, startTime, endTime, EmotionEnum.NEGATIVE.getState(), size, cache);
public JSONObject getNegativeChannelList(String contendId, Long startTime, Long endTime, int size, String sorter, boolean cache) {
return getChannelListCache(contendId, startTime, endTime, EmotionEnum.NEGATIVE.getState(), size, sorter, cache);
}
private JSONObject getChannelListCache(String contendId, Long startTime, Long endTime, int emotion, int size, boolean cache) {
private JSONObject getChannelListCache(String contendId, Long startTime, Long endTime, int emotion, int size, String sorter, boolean cache) {
JSONObject res = new JSONObject();
try {
String projectId = UserThreadLocal.getProjectId();
......@@ -474,7 +474,7 @@ public class ChannelServiceImpl implements ChannelService {
if (cache && StringUtils.isNotEmpty(resultStr = redisUtil.get(redisKey))) {
return JSONObject.parseObject(resultStr);
}
res = getChannelList(projectId, contendId, startTime, endTime, emotion, size);
res = getChannelList(projectId, contendId, startTime, endTime, emotion, sorter, size);
// 配合天级缓存开启
redisUtil.setExpire(redisKey, JSON.toJSONString(res));
} catch (IOException e) {
......@@ -483,8 +483,8 @@ public class ChannelServiceImpl implements ChannelService {
return res;
}
private JSONObject getChannelList(String projectId, String contendId, Long startTime, Long endTime, int emotion, int size) throws IOException {
JSONObject res = new JSONObject(new LinkedHashMap<>());
private JSONObject getChannelList(String projectId, String contendId, Long startTime, Long endTime, int emotion, String sorter, int size) throws IOException {
JSONObject res = new JSONObject(true);
Map<String, Pair<Long, ChannelRecord>> keyMap = new HashMap<>();
EsClientDao.SearchHelper searchHelper = createSearchHelperByChannelCriteria(projectId, Collections.singleton(contendId), startTime, endTime, true);
// 分页查询所有结果
......@@ -519,15 +519,7 @@ public class ChannelServiceImpl implements ChannelService {
return channelRecord;
}
return null;
}).filter(Objects::nonNull).sorted((x, y) -> {
// 稿件数排序
if (x.getRecord().getArticles().size() > y.getRecord().getArticles().size()) {
return -1;
} else if (Objects.equals(x.getRecord().getArticles().size(), y.getRecord().getArticles().size())) {
return 0;
}
return 1;
}).collect(Collectors.groupingBy(ChannelRecord::getPlatform));
}).filter(Objects::nonNull).collect(Collectors.groupingBy(ChannelRecord::getPlatform));
for (String platformName : PLATFORMS) {
List<ChannelRecord> channelRecordList = channelRecords.getOrDefault(platformName, Collections.emptyList()).stream().limit(size).collect(Collectors.toList());
List<ChannelListVO> list = new ArrayList<>(size);
......@@ -541,7 +533,14 @@ public class ChannelServiceImpl implements ChannelService {
list.add(ChannelListVO.createFromChannel(record, record.getRecord().getArticles().size()));
}
});
res.put(platformName, list);
List<ChannelListVO> resList;
// 排序
if (Objects.nonNull(sorter) && sorter.contains("index")){
resList = list.stream().sorted(Comparator.comparingDouble(ChannelListVO::getEmotionIndex).reversed()).collect(Collectors.toList());
}else {
resList = list.stream().sorted(Comparator.comparingDouble(ChannelListVO::getArticleCount).reversed()).collect(Collectors.toList());
}
res.put(platformName, resList);
}
return res;
}
......
......@@ -155,10 +155,10 @@ public class TaskServiceImpl implements TaskService {
channelService.getActiveChannelList(Constant.PRIMARY_CONTEND_ID, times[0], times[1], 50, false);
// 友好渠道榜
channelService.getPositiveList(Constant.PRIMARY_CONTEND_ID, null, null, sorter, times[0], times[1], 50, false);
channelService.getPositiveChannelList(Constant.PRIMARY_CONTEND_ID, times[0], times[1], 50, false);
channelService.getPositiveChannelList(Constant.PRIMARY_CONTEND_ID, times[0], times[1], 50, sorter, false);
// 敏感渠道榜
channelService.getNegativeList(Constant.PRIMARY_CONTEND_ID, null, null, sorter, times[0], times[1], 50, false);
channelService.getNegativeChannelList(Constant.PRIMARY_CONTEND_ID, times[0], times[1], 50, false);
channelService.getNegativeChannelList(Constant.PRIMARY_CONTEND_ID, times[0], times[1], 50, sorter, false);
});
log.info("项目:{}-渠道榜单缓存已完成:{}个", project.getProjectName(), total.incrementAndGet());
return null;
......
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