Commit e9ddade4 by shenjunjie

Merge branch 'feature' into 'release'

渠道库榜单增加情感指数排序

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