forked from rongchao/epmet-cloud-rizhao
				
			
				 7 changed files with 166 additions and 26 deletions
			
			
		| @ -0,0 +1,18 @@ | |||
| package com.epmet.service.evaluationindex.extract; | |||
| 
 | |||
| import com.epmet.dto.extract.form.ExtractFormDTO; | |||
| 
 | |||
| /** | |||
|  * @author zhaoqifeng | |||
|  * @dscription | |||
|  * @date 2020/9/15 14:00 | |||
|  */ | |||
| public interface FactOriginExtractService { | |||
| 
 | |||
|     /** | |||
|      * desc:抽取所有业务数据到统计库 | |||
|      * | |||
|      * @param extractFormDTO | |||
|      */ | |||
|     void extractAll(ExtractFormDTO extractFormDTO); | |||
| } | |||
| @ -0,0 +1,100 @@ | |||
| package com.epmet.service.evaluationindex.extract.impl; | |||
| 
 | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.epmet.commons.tools.constant.NumConstant; | |||
| import com.epmet.commons.tools.utils.DateUtils; | |||
| import com.epmet.dto.extract.form.ExtractFormDTO; | |||
| import com.epmet.service.evaluationindex.extract.FactOriginExtractService; | |||
| import com.epmet.service.evaluationindex.extract.FactOriginTopicMainDailyService; | |||
| import com.epmet.service.evaluationindex.extract.IssueExtractService; | |||
| import com.epmet.service.evaluationindex.extract.ProjectExtractService; | |||
| import com.epmet.service.stats.DimCustomerService; | |||
| import com.epmet.util.DimIdGenerator; | |||
| import com.google.common.util.concurrent.ThreadFactoryBuilder; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.util.CollectionUtils; | |||
| 
 | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.concurrent.*; | |||
| 
 | |||
| /** | |||
|  * desc:抽取业务数据 到 统计库  汇聚类 | |||
|  */ | |||
| @Slf4j | |||
| @Service | |||
| public class FactOriginExtractServiceImpl implements FactOriginExtractService { | |||
|     ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() | |||
|             .setNameFormat("factOriginExtract-pool-%d").build(); | |||
|     ExecutorService threadPool = new ThreadPoolExecutor(4, 8, | |||
|             10L, TimeUnit.MINUTES, | |||
|             new LinkedBlockingQueue<>(100), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); | |||
| 
 | |||
|     @Autowired | |||
|     private IssueExtractService issueExtractService; | |||
|     @Autowired | |||
|     private FactOriginTopicMainDailyService factOriginTopicMainDailyService; | |||
|     @Autowired | |||
|     private ProjectExtractService projectExtractService; | |||
|     @Autowired | |||
|     private DimCustomerService dimCustomerService; | |||
| 
 | |||
| 
 | |||
|     @Override | |||
|     public void extractAll(ExtractFormDTO extractFormDTO) { | |||
|         String dateId = extractFormDTO.getDateId(); | |||
|         String customerId = extractFormDTO.getCustomerId(); | |||
|         if (StringUtils.isBlank(dateId)) { | |||
|             dateId = DimIdGenerator.getDateDimId(DateUtils.addDateDays(new Date(), -1)); | |||
|         } | |||
|         List<String> customerIds = new ArrayList<>(); | |||
|         if (StringUtils.isNotBlank(customerId)) { | |||
|             customerIds.add(customerId); | |||
|         } | |||
|         int pageNo = NumConstant.ONE; | |||
|         int pageSize = NumConstant.ONE_HUNDRED; | |||
|         customerIds = dimCustomerService.selectCustomerIdPage(pageNo, pageSize); | |||
|         if (CollectionUtils.isEmpty(customerIds)) { | |||
|             log.error("extractAll 获取客户Id为空"); | |||
|             return; | |||
|         } | |||
| 
 | |||
|         String finalDateId = dateId; | |||
|         customerIds.forEach(cId -> { | |||
|             ExtractFormDTO param = new ExtractFormDTO(); | |||
|             param.setCustomerId(cId); | |||
|             param.setDateId(finalDateId); | |||
|             submitJob(param); | |||
|         }); | |||
| 
 | |||
|     } | |||
| 
 | |||
|     private void submitJob(ExtractFormDTO param) { | |||
|         threadPool.submit(() -> { | |||
|             try { | |||
|                 factOriginTopicMainDailyService.topicCleaning(param); | |||
|             } catch (Exception e) { | |||
|                 log.error("抽取【话题数据】发生异常,参数:" + JSON.toJSONString(param), e); | |||
|             } | |||
|         }); | |||
|         threadPool.submit(() -> { | |||
|             try { | |||
|                 issueExtractService.issueExtractMain(param); | |||
|                 issueExtractService.issueExtractLog(param); | |||
|             } catch (Exception e) { | |||
|                 log.error("抽取【议题数据】发生异常,参数:" + JSON.toJSONString(param), e); | |||
|             } | |||
|         }); | |||
|         threadPool.submit(() -> { | |||
|             try { | |||
|                 projectExtractService.saveOriginProjectDaily(param); | |||
|             } catch (Exception e) { | |||
|                 log.error("抽取【项目数据】发生异常,参数:" + JSON.toJSONString(param), e); | |||
|             } | |||
|         }); | |||
|     } | |||
| } | |||
					Loading…
					
					
				
		Reference in new issue