|
|
@ -1,7 +1,12 @@ |
|
|
|
package com.epmet.controller; |
|
|
|
|
|
|
|
import cn.hutool.core.thread.ThreadUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.enums.BizTypeEnum; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dto.StatsFormDTO; |
|
|
@ -15,8 +20,10 @@ import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author liujianjun |
|
|
@ -50,42 +57,101 @@ public class FactAggregationExtractController { |
|
|
|
* @date 2020/11/10 3:14 下午 |
|
|
|
*/ |
|
|
|
@RequestMapping("extractDailyOrMonthly") |
|
|
|
public Result extractDaily(@RequestBody AggregationExtractFormDTO formDTO) { |
|
|
|
public Result extractDailyOrMonthly(@RequestBody AggregationExtractFormDTO formDTO) { |
|
|
|
if (StringUtils.isBlank(formDTO.getStartDate()) && StringUtils.isBlank(formDTO.getEndDate())) { |
|
|
|
log.error("抽取日期范围不能为空"); |
|
|
|
return new Result().error(); |
|
|
|
} |
|
|
|
if (formDTO.getStartDate().indexOf(StrConstant.HYPHEN) < 0 || formDTO.getEndDate().indexOf(StrConstant.HYPHEN) < 0) { |
|
|
|
if (!formDTO.getStartDate().contains(StrConstant.HYPHEN) || !formDTO.getEndDate().contains(StrConstant.HYPHEN)) { |
|
|
|
log.error("抽取日期范围格式不正确,yyyy-MM-dd"); |
|
|
|
return new Result().error(); |
|
|
|
} |
|
|
|
|
|
|
|
BizTypeEnum bizTypeEnum = null; |
|
|
|
|
|
|
|
Set<String> bizType = formDTO.getBizType(); |
|
|
|
for (String item : bizType) { |
|
|
|
bizTypeEnum = BizTypeEnum.getEnum(item); |
|
|
|
if (bizTypeEnum == null) { |
|
|
|
log.error("抽取业务类型不正确,BizTypeEnum"); |
|
|
|
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<String> daysBetween = DateUtils.getDaysBetween(formDTO.getStartDate(), formDTO.getEndDate(), DateUtils.DATE_PATTERN, DateUtils.DATE_PATTERN); |
|
|
|
daysBetween.forEach(dateId -> { |
|
|
|
Date date = DateUtils.parse(dateId, DateUtils.DATE_PATTERN); |
|
|
|
for (String dateId : daysBetween) { |
|
|
|
StatsFormDTO param = new StatsFormDTO(); |
|
|
|
param.setCustomerId(formDTO.getCustomerId()); |
|
|
|
param.setDate(dateId); |
|
|
|
|
|
|
|
switch (formDTO.getType()) { |
|
|
|
case "monthly": |
|
|
|
if ("monthly".equals(formDTO.getType())) { |
|
|
|
if (bizType.isEmpty() || bizType.contains(BizTypeEnum.GROUP.getType())) { |
|
|
|
extractGroupDataMonthly(param); |
|
|
|
} |
|
|
|
if (bizType.isEmpty() || bizType.contains(BizTypeEnum.ARTICLE.getType())) { |
|
|
|
extractArticleDataMonthlyAndQuarterly(param); |
|
|
|
} |
|
|
|
} else { |
|
|
|
//todo 如果要加方法 记得这个枚举里要加
|
|
|
|
int threadCount = bizType.isEmpty() ? BizTypeEnum.values().length : bizType.size(); |
|
|
|
System.out.println(threadCount); |
|
|
|
CountDownLatch countDownLatch = ThreadUtil.newCountDownLatch(threadCount); |
|
|
|
if (bizType.isEmpty() || bizType.contains(BizTypeEnum.USER.getType())) { |
|
|
|
ThreadUtil.execute(() -> { |
|
|
|
extractUserDataDaily(param); |
|
|
|
countDownLatch.countDown(); |
|
|
|
}); |
|
|
|
} |
|
|
|
if (bizType.isEmpty() || bizType.contains(BizTypeEnum.GROUP.getType())) { |
|
|
|
ThreadUtil.execute(() -> { |
|
|
|
extractGroupDataDaily(param); |
|
|
|
countDownLatch.countDown(); |
|
|
|
}); |
|
|
|
} |
|
|
|
if (bizType.isEmpty() || bizType.contains(BizTypeEnum.TOPIC.getType())) { |
|
|
|
ThreadUtil.execute(() -> { |
|
|
|
extractTopicDataDaily(param); |
|
|
|
countDownLatch.countDown(); |
|
|
|
}); |
|
|
|
} |
|
|
|
if (bizType.isEmpty() || bizType.contains(BizTypeEnum.ISSUE.getType())) { |
|
|
|
ThreadUtil.execute(() -> { |
|
|
|
extractIssueDataDaily(param); |
|
|
|
countDownLatch.countDown(); |
|
|
|
}); |
|
|
|
} |
|
|
|
if (bizType.isEmpty() || bizType.contains(BizTypeEnum.PROJECT.getType())) { |
|
|
|
ThreadUtil.execute(() -> { |
|
|
|
extractProjectDataDaily(param); |
|
|
|
countDownLatch.countDown(); |
|
|
|
}); |
|
|
|
} |
|
|
|
if (bizType.isEmpty() || bizType.contains(BizTypeEnum.ARTICLE.getType())) { |
|
|
|
ThreadUtil.execute(() -> { |
|
|
|
extractAtricleDataDaily(param); |
|
|
|
countDownLatch.countDown(); |
|
|
|
}); |
|
|
|
} |
|
|
|
try { |
|
|
|
//如果半小时还没执行完 则中断 说明执行方法有问题 要优化
|
|
|
|
countDownLatch.await(NumConstant.THIRTY, TimeUnit.MINUTES); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
log.error("extractDailyOrMonthly dateId:{} 始终没有结束 中断操作 InterruptedException", dateId); |
|
|
|
break; |
|
|
|
default: |
|
|
|
extractUserDataDaily(param); |
|
|
|
extractGroupDataDaily(param); |
|
|
|
extractTopicDataDaily(param); |
|
|
|
extractIssueDataDaily(param); |
|
|
|
extractProjectDataDaily(param); |
|
|
|
extractAtricleDataDaily(param); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
log.info("extractDailyOrMonthly dateId:{} run end", dateId); |
|
|
|
} |
|
|
|
|
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
private void extractUserDataDaily(StatsFormDTO formDTO) { |
|
|
|
try { |
|
|
|
statsUserService.partition(formDTO); |
|
|
|
log.info("extractUserDataDaily end param:{}", JSON.toJSONString(formDTO)); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("抽取【用户】数据失败", e); |
|
|
|
} |
|
|
@ -103,6 +169,7 @@ public class FactAggregationExtractController { |
|
|
|
private void extractIssueDataDaily(StatsFormDTO formDTO) { |
|
|
|
try { |
|
|
|
statsIssueService.agencyGridIssueStats(formDTO); |
|
|
|
log.info("extractIssueDataDaily end param:{}", JSON.toJSONString(formDTO)); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("抽取【议题】数据失败", e); |
|
|
|
} |
|
|
@ -112,6 +179,7 @@ public class FactAggregationExtractController { |
|
|
|
try { |
|
|
|
statsProjectService.gridProjectStats(formDTO); |
|
|
|
statsProjectService.agencyProjectStats(formDTO); |
|
|
|
log.info("extractProjectDataDaily end param:{}", JSON.toJSONString(formDTO)); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("抽取【项目】数据失败", e); |
|
|
|
} |
|
|
@ -122,6 +190,7 @@ public class FactAggregationExtractController { |
|
|
|
statsPublicityService.articleSummaryDailyStatsjob(formDTO); |
|
|
|
statsPublicityService.tagUsedDailyStatsjob(formDTO); |
|
|
|
statsPublicityService.tagViewedDailyStatsjob(formDTO); |
|
|
|
log.info("extractAtricleDataDaily end param:{}", JSON.toJSONString(formDTO)); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("抽取【文章】数据失败", e); |
|
|
|
} |
|
|
@ -135,6 +204,7 @@ public class FactAggregationExtractController { |
|
|
|
|
|
|
|
statsGroupService.groupGridDaily(groupStatsFormDTO); |
|
|
|
statsGroupService.groupAgencyDaily(groupStatsFormDTO); |
|
|
|
log.info("extractGroupDataDaily end param:{}", JSON.toJSONString(formDTO)); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("抽取【小组】数据失败", e); |
|
|
|
} |
|
|
@ -147,6 +217,7 @@ public class FactAggregationExtractController { |
|
|
|
groupStatsFormDTO.setCustomerId(formDTO.getCustomerId()); |
|
|
|
|
|
|
|
statsGroupService.groupAgencyMonthly(groupStatsFormDTO); |
|
|
|
log.info("extractGroupDataMonthly end param:{}", JSON.toJSONString(formDTO)); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("抽取【小组】数据失败", e); |
|
|
|
} |
|
|
@ -158,6 +229,7 @@ public class FactAggregationExtractController { |
|
|
|
statsPublicityService.tagUsedQuarterlyStatsjob(formDTO); |
|
|
|
statsPublicityService.tagViewedMonthlyStatsjob(formDTO); |
|
|
|
statsPublicityService.tagViewedQuarterlyStatsjob(formDTO); |
|
|
|
log.info("extractArticleDataMonthlyAndQuarterly end param:{}", JSON.toJSONString(formDTO)); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("抽取【文章】数据失败", e); |
|
|
|
} |
|
|
|