Commit 00b852a3 by shenjunjie

报告配置bug修复

parent 00cc4f36
......@@ -14,6 +14,7 @@ public class Constant {
public static final Long EIGHT_HOUR = 8 * 60 * 60 * 1000L;
public static final Long ONE_DAY = 24 * 60 * 60 * 1000L;
public static final Long ONE_WEEK = 7 * 24 * 60 * 60 * 1000L;
public static final Long ONE_MONTH = 30 * 24 * 60 * 60 * 1000L;
public static final String SPEC_MINUTE_PATTERN = "yyyy.MM.dd HH:mm";
......
......@@ -69,18 +69,25 @@ public class CommonController extends BaseController {
return ResponseResult.success(projectService.getUserAllProjects());
}
// @ApiOperation("获取默认间隔时间节点")
// @GetMapping("/time/month")
// @ApiOperation("获取默认间隔时间节点")
// @GetMapping("/time/format/day")
// @Auth(role = RoleEnum.CUSTOMER)
// public ResponseResult getTimeRangeMonth() {
// return ResponseResult.success(commonService.getTimeRangeMonth());
// public ResponseResult getTimeRangeDay() {
// return ResponseResult.success(commonService.getTimeRangeDay());
// }
//
// @ApiOperation("获取默认周间隔时间节点")
// @GetMapping("/time/week")
// @GetMapping("/time/format/week")
// @Auth(role = RoleEnum.CUSTOMER)
// public ResponseResult getTimeRangeWeek() {
// return ResponseResult.success(commonService.getTimeRangeWeek());
// return ResponseResult.success(commonService.getTimeRangeFormatWeek());
// }
//
// @ApiOperation("获取默认月间隔时间节点")
// @GetMapping("/time/format/month")
// @Auth(role = RoleEnum.CUSTOMER)
// public ResponseResult getTimeRangeMonth() {
// return ResponseResult.success(commonService.getTimeRangeFormatMonth());
// }
}
......@@ -24,6 +24,11 @@ public interface TaskService{
void messageFlowCache();
/**
* 自定义事件标题聚合分析缓存
*/
void customEventCache();
/**
* 生成简报任务并推送
*/
void generateReportAndSend();
......
......@@ -11,8 +11,6 @@ import com.zhiwei.brandkbs2.pojo.UserRole;
import com.zhiwei.brandkbs2.pojo.vo.BehaviorVO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import com.zhiwei.brandkbs2.service.BehaviorService;
import com.zhiwei.brandkbs2.util.MongoUtil;
import com.zhiwei.brandkbs2.util.Tools;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
......@@ -123,6 +121,8 @@ public class BehaviorServiceImpl implements BehaviorService {
Date end = new Date(endTime);
Query query = new Query();
query.addCriteria(Criteria.where("cTime").gte(startTime).lt(endTime).and("backstage").is(backstage));
query.addCriteria(Criteria.where("projectId").is(UserThreadLocal.getProjectId()));
behaviorDao.addSort(query, "{\"cTime\":\"descend\"}");
List<Behavior> behaviorList = behaviorDao.findList(query, behaviorDao.generateCollectionNames(start, end));
List<ExportBehaviorDTO> resList = new ArrayList<>(behaviorList.size());
behaviorList.forEach(behavior -> {
......
......@@ -113,7 +113,7 @@ public class CommonServiceImpl implements CommonService {
@Override
public Long[] getTimeRangeMonth() {
long endTime = DateUtils.addDays(Tools.truncDate(new Date(), Constant.DAY_PATTERN), 1).getTime();
long endTime = Tools.truncDate(new Date(), Constant.DAY_PATTERN).getTime();
long startTime = DateUtils.addMonths(new Date(endTime), -1).getTime();
return new Long[]{startTime, endTime};
}
......
......@@ -100,7 +100,17 @@ public class ReportServiceImpl implements ReportService {
}
ReportSettingsDTO reportSettingsDTO = ReportSettingsDTO.createFromReportSettings(settings);
if (!CollectionUtils.isEmpty(reportSettingsDTO.getContendIds())) {
reportSettingsDTO.setContendBrandNames(reportSettingsDTO.getContendIds().stream().map(contendId -> projectService.getProjectByContendId(UserThreadLocal.getProjectId(), contendId).getBrandName()).collect(Collectors.toList()));
List<String> collect = reportSettingsDTO.getContendIds().stream().map(contendId -> {
AbstractProject project = projectService.getProjectByContendId(UserThreadLocal.getProjectId(), contendId);
if (null != project) {
return project.getBrandName();
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
// 历史竞品信息已失效
if (!collect.isEmpty()) {
reportSettingsDTO.setContendBrandNames(collect);
}
}
res.put(key, reportSettingsDTO);
}
......@@ -236,8 +246,9 @@ public class ReportServiceImpl implements ReportService {
JSONObject result = null;
try {
result = getPcReportResult(report);
} catch (IOException e) {
ExceptionCast.cast(CommonCodeEnum.FAIL, "es查询异常");
} catch (Exception e) {
log.error("生成报告数据异常", e);
ExceptionCast.cast(CommonCodeEnum.FAIL, "生成报告数据异常");
}
redisUtil.set(redisKey, JSON.toJSONString(result));
return result;
......@@ -329,7 +340,7 @@ public class ReportServiceImpl implements ReportService {
* @param report 报告对象
* @return 月报结果
*/
private JSONObject getPcReportResult(Report report) throws IOException {
private JSONObject getPcReportResult(Report report) throws Exception {
switchReportStatus(report.getId(), false);
log.info("getPcReportResult-生成报告开始,id:{}", report.getId());
Long startTime = report.getStartTime();
......@@ -352,15 +363,19 @@ public class ReportServiceImpl implements ReportService {
List<JSONObject> contendCompare = report.getContends().stream().map(brandContendId -> {
JSONObject json = new JSONObject();
AbstractProject abstractProject = projectService.getProjectByContendId(projectId, brandContendId);
json.put("id", brandContendId);
json.put("brand", abstractProject.getBrandName());
try {
json.put("brandCompare", markDataService.getContendSpreadAnalyze(startTime, endTime, projectId, brandContendId, 5, true));
} catch (IOException e) {
log.error("getPcReportResult-brandCompare-", e);
// 历史竞品信息已失效
if (null != abstractProject) {
json.put("id", brandContendId);
json.put("brand", abstractProject.getBrandName());
try {
json.put("brandCompare", markDataService.getContendSpreadAnalyze(startTime, endTime, projectId, brandContendId, 5, false));
} catch (Exception e) {
log.error("getPcReportResult-brandCompare-", e);
}
return json;
}
return json;
}).collect(Collectors.toList());
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
result.put("contendCompare", contendCompare);
log.info("getPcReportResult-生成报告结束,id:{}", report.getId());
switchReportStatus(report.getId(), true);
......
......@@ -78,6 +78,9 @@ public class TaskServiceImpl implements TaskService {
@Resource(name = "eventServiceImpl")
EventService eventService;
@Resource(name = "customEventServiceImpl")
CustomEventService customEventService;
@Resource(name = "taskServiceExecutor")
ThreadPoolTaskExecutor taskServiceExecutor;
......@@ -113,14 +116,14 @@ public class TaskServiceImpl implements TaskService {
}
// 替换成新的记录map
channelIndexRecordMap = newRecordMap;
ListUtils.partition(insertList, 1000).forEach(list -> {
channelDao.insertMany(list);
});
// ListUtils.partition(insertList, 1000).forEach(list -> {
// channelDao.insertMany(list);
// });
log.info("渠道统计-渠道总计-录入完毕,新增渠道{}条,更新渠道{}条", insertList.size(), channelIndexRecordMap.size() - insertList.size());
// 获得单位时间内最小最大时间戳
Long[] timeMinMax = Tools.timeMinMax(rangeTimeRecords.stream().map(Pair::getLeft).collect(Collectors.toList()));
List<ChannelRecord> channelRecords = ChannelRecord.createChannelRecords(timeMinMax[0], timeMinMax[1], channelIndexRecordMap);
channelEsDao.upsertChannelRecord(channelRecords);
// channelEsDao.upsertChannelRecord(channelRecords);
// 同步channelCopy
ListUtils.partition(insertList, 1000).forEach(list -> {
channelEsDao.batchInsert(list.stream().map(Channel::createChannelCopyMap).collect(Collectors.toList()));
......@@ -145,7 +148,6 @@ public class TaskServiceImpl implements TaskService {
channelService.getPositiveList(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);
});
log.info("项目:{}-渠道榜单缓存已完成:{}个", project.getProjectName(), total.incrementAndGet());
return null;
......@@ -172,6 +174,23 @@ public class TaskServiceImpl implements TaskService {
}, cacheServiceExecutor)).toArray(CompletableFuture[]::new)).join();
}
@Override
public void customEventCache() {
AtomicInteger total = new AtomicInteger();
Long[] timeRangeFormatWeek = commonService.getTimeRangeFormatWeek();
Long[] timeRangeLastWeek = new Long[]{timeRangeFormatWeek[0] - Constant.ONE_WEEK, timeRangeFormatWeek[1] - Constant.ONE_WEEK};
List<Long[]> timeList = Arrays.asList(commonService.getTimeRangeDay(), timeRangeLastWeek);
CompletableFuture.allOf(GlobalPojo.PROJECT_MAP.values().stream().map(project -> CompletableFuture.supplyAsync(() -> {
UserThreadLocal.set(new UserInfo().setProjectId(project.getId()));
timeList.forEach(times -> {
// 自定义事件标题缓存
customEventService.getCustomEventRankList(times[0], times[1]);
});
log.info("项目:{}-自定义事件标题缓存已完成:{}个", project.getProjectName(), total.incrementAndGet());
return null;
}, cacheServiceExecutor)).toArray(CompletableFuture[]::new)).join();
}
private Pair<List<Channel>, List<Channel>> batchHandle(List<Map.Entry<ChannelIndex, ChannelIndex.Record>> batchList, Map<ChannelIndex,
ChannelIndex.Record> newRecordMap) {
List<Channel> insertList = Collections.synchronizedList(new ArrayList<>());
......@@ -188,7 +207,7 @@ public class TaskServiceImpl implements TaskService {
channel.setRecord(entry.getValue());
Channel updateChannel = channelService.calculateChannelEmotionIndex(channel);
updateChannel.updateInfo(entry.getKey(), entry.getValue());
channelDao.updateOne(updateChannel);
// channelDao.updateOne(updateChannel);
updateList.add(channel);
}
// 设置查询数值
......@@ -306,6 +325,7 @@ public class TaskServiceImpl implements TaskService {
Report report = booleanReportPair.getRight();
// 用作生成缓存
reportService.getPcReportAnalyze(report.getId(), false);
reportService.switchReportStatus(report.getId(), true);
}
flag = true;
}
......@@ -314,6 +334,7 @@ public class TaskServiceImpl implements TaskService {
for (Report report : reportService.getCustomReportByStatus(project.getId(), false)) {
// 用作生成缓存
reportService.getPcReportAnalyze(report.getId(), false);
reportService.switchReportStatus(report.getId(), true);
}
return flag;
}
......
......@@ -41,13 +41,14 @@ public class ControlCenter {
@Async("scheduledExecutor")
@Scheduled(cron = "0 0 1 * * ?")
public void messageFlowCache() {
log.info("定时按天缓存消息流信息-启动");
log.info("定时按天缓存数据-启动");
try {
taskService.messageFlowCache();
taskService.customEventCache();
} catch (Exception e) {
log.error("定时按天缓存消息流信息-出错", e);
log.error("定时按天缓存数据-出错", e);
} finally {
log.info("定时按天缓存消息流信息-结束");
log.info("定时按天缓存数据-结束");
}
}
......
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