Commit 58f4906d by 陈健智

首页-事件数替换为净情感度

parent b0cf4fdb
......@@ -27,6 +27,7 @@ public class RedisKeyPrefix {
public static final String INDEX_PLATFORM = "BRANDKBS:INDEX:PLATFORM:";
public static final String INDEX_SPREAD = "BRANDKBS:INDEX:SPREAD:";
public static final String INDEX_COMPARE_SUMMARY_MOBILE = "BRANDKBS:INDEX:COMPARE_SUMMARY:MOBILE:";
public static final String INDEX_EMOTION = "BRANDKBS:INDEX:EMOTION:";
/**
* 渠道榜单缓存
*/
......
......@@ -90,5 +90,15 @@ public class AppIndexController extends BaseController {
return ResponseResult.success(indexService.getSpreadingTend(startTime, endTime, true));
}
@ApiOperation("首页-净情感度")
@ApiImplicitParams({
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "long"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "long")
})
@GetMapping("/emotion-percent")
public ResponseResult getEmotionPercent(@RequestParam(value = "startTime", required = false) Long startTime,
@RequestParam(value = "endTime", required = false) Long endTime) {
return ResponseResult.success(indexService.getEmotionPercent(startTime, endTime, false));
}
}
......@@ -81,4 +81,12 @@ public interface IndexService {
*/
JSONObject getMobileWholeCriteria(Long startTime, Long endTime);
/**
* 获取主品牌净情感度
* @param startTime 开始时间
* @param endTime 结束时间
* @param cache 是否优先读取缓存
* @return
*/
JSONObject getEmotionPercent(Long startTime, Long endTime, boolean cache);
}
......@@ -334,6 +334,58 @@ public class IndexServiceImpl implements IndexService {
return result;
}
@Override
public JSONObject getEmotionPercent(Long startTime, Long endTime, boolean cache) {
if (Objects.isNull(startTime) || Objects.isNull(endTime)) {
Long[] timeRangeMonth = commonService.getTimeRangeMonth();
startTime = timeRangeMonth[0];
endTime = timeRangeMonth[1];
}
String projectId = UserThreadLocal.getProjectId();
String redisKey = RedisUtil.getIndexEmotionKey(projectId, startTime, endTime);
String resultStr;
// 返回缓存
if (cache && StringUtils.isNotEmpty(resultStr = redisUtil.get(redisKey))) {
return JSON.parseObject(resultStr);
}
JSONObject jsonObject = new JSONObject();
try {
// 关于NSR计算:NSR净情感度=(正面-负面)/(正面+负面)*100%
// 项目总正面稿件数
long totalPositiveCount = markDataService.getYuqingMarkCount(null, null, EmotionEnum.POSITIVE.getName(), projectId, Constant.PRIMARY_CONTEND_ID);
// 项目总负面稿件数
long totalNegativeCount = markDataService.getYuqingMarkCount(null, null, EmotionEnum.NEGATIVE.getName(), projectId, Constant.PRIMARY_CONTEND_ID);
// 项目均值NSR
double avg = 0 == totalPositiveCount + totalNegativeCount ? 0 :(totalPositiveCount - totalNegativeCount) / (double) (totalPositiveCount + totalNegativeCount);
jsonObject.put("avgNSR", avg);
// 正面稿件数
long positiveCount = markDataService.getYuqingMarkCount(startTime, endTime, EmotionEnum.POSITIVE.getName(), projectId, Constant.PRIMARY_CONTEND_ID);
jsonObject.put("positiveCount", positiveCount);
// 负面稿件数
long negativeCount = markDataService.getYuqingMarkCount(startTime, endTime, EmotionEnum.NEGATIVE.getName(), projectId, Constant.PRIMARY_CONTEND_ID);
jsonObject.put("negativeCount", negativeCount);
// 本次NSR
double NSR = 0 == positiveCount + negativeCount ? 0 :(positiveCount - negativeCount) / (double) (positiveCount + negativeCount);
jsonObject.put("NSR", NSR);
// 上一周期开始时间
long previousStartTime = startTime - (endTime - startTime);
// 上一周期正面稿件数
long previousPositiveCount = markDataService.getYuqingMarkCount(previousStartTime, startTime, EmotionEnum.POSITIVE.getName(), projectId, Constant.PRIMARY_CONTEND_ID);
// 上一周期负面稿件数
long previousNegativeCount = markDataService.getYuqingMarkCount(previousStartTime, startTime, EmotionEnum.NEGATIVE.getName(), projectId, Constant.PRIMARY_CONTEND_ID);
// 上一周期NSR
double previousNSR = 0 == previousPositiveCount + previousNegativeCount ? 0 :(previousPositiveCount - previousNegativeCount) / (double) (previousPositiveCount + previousNegativeCount);
// 环比
jsonObject.put("compare", NSR - previousNSR);
redisUtil.setExpire(redisKey, JSON.toJSONString(jsonObject));
} catch (Exception e) {
ExceptionCast.cast(CommonCodeEnum.FAIL, "getEmotionPercent异常", e);
}
return jsonObject;
}
public List<JSONObject> getPlatformProportionWithPlatform(Long startTime, Long endTime, String emotion, String projectId, String contendId, long normalCount) {
List<String> platformIds = GlobalPojo.PLATFORMS.stream().map(MessagePlatform::getId).collect(Collectors.toList());
List<JSONObject> resultList = new ArrayList<>(platformIds.size());
......
......@@ -2749,7 +2749,7 @@ public class MarkDataServiceImpl implements MarkDataService {
}catch (Exception e){
ExceptionCast.cast(CommonCodeEnum.FAIL, "新舆情分析getActiveChannels异常-", e);
}
return list;
return list.stream().limit(20).collect(Collectors.toList());
}
@Override
......
......@@ -188,6 +188,8 @@ public class TaskServiceImpl implements TaskService {
indexService.getPlatformInfo(null, null, false);
// 首页-传播趋势
indexService.getSpreadingTend(null, null, false);
// 首页-净情感度
indexService.getEmotionPercent(null, null, false);
log.info("项目:{}-首页缓存已完成:{}个", project.getProjectName(), total.incrementAndGet());
return null;
}, cacheServiceExecutor)).toArray(CompletableFuture[]::new)).join();
......
......@@ -59,6 +59,10 @@ public class RedisUtil {
return RedisKeyPrefix.INDEX_SPREAD + Tools.concat(projectId, startTime, endTime);
}
public static String getIndexEmotionKey(String projectId, Long startTime, Long endTime) {
return RedisKeyPrefix.INDEX_EMOTION + Tools.concat(projectId, startTime, endTime);
}
public static String getChannelRecordList(String projectId, Long startTime, Long endTime, String platform, int emotion) {
return RedisKeyPrefix.CHANNEL_RECORD_LIST + Tools.concat(projectId, startTime, endTime, platform, emotion);
}
......
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