目录
主要是执行线程进行同步,简单的一个线程,后来废弃掉了,所以代码备份到这里
- @Data
- private class SendCorpusRunnable implements Runnable {
-
- private Long newsId;
-
- private List
eventInfoList; -
- private Map
> eventTagsMap; -
- public SendCorpusRunnable(Long newsId, List
eventInfoList, - Map
> eventTagsMap) { - this.newsId = newsId;
- this.eventInfoList = eventInfoList;
- this.eventTagsMap = eventTagsMap;
- }
-
- @Override
- public void run() {
- try {
- NewsEventVo newsEventVo = TbmEventConvert.convertToCorpus(newsId, eventInfoList, eventTagsMap);
- newsEventFacade.save(newsEventVo);
- } catch (CorpusException e) {
- e.printStackTrace();
- }
- }
-
- }
- /**
- * 转换推送语料数据
- *
- * @param eventInfoList
- * @return
- */
- public static NewsEventVo convertToCorpus(Long newsId, List
eventInfoList, Map> eventTagsMap) { - NewsEventVo newsEventVo = new NewsEventVo();
- newsEventVo.setNewsId(newsId);
- if (CollectionUtils.isEmpty(eventInfoList)) {
- return newsEventVo;
- }
- List
eventCalloutVoList = new ArrayList<>(); - eventInfoList.forEach(eventInfo -> {
- NewsEventVo.EventCalloutVo eventCalloutVo = new NewsEventVo.EventCalloutVo();
- if (StringUtils.isNotBlank(eventInfo.getEventFourthLevelCode())) {
- eventCalloutVo.setEventCode(eventInfo.getEventFourthLevelCode());
- }
- if (StringUtils.isNotBlank(eventInfo.getEventFourthLevel())) {
- eventCalloutVo.setEventName(eventInfo.getEventFourthLevel());
- }
- if (StringUtils.isNotBlank(eventInfo.getEventBasis())) {
- eventCalloutVo.setEventBasis(eventInfo.getEventBasis());
- }
- //提取标签主体
- List
eventTagList = eventTagsMap.get(eventInfo.getId()); - List
subjectList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(eventTagList)) {
- eventTagList.forEach(eventTag -> {
- NewsEventVo.EventSubjectVo eventSubjectVo = new NewsEventVo.EventSubjectVo();
- eventSubjectVo.setSubjectName(eventTag.getTagName());
- if (StringUtils.isNotBlank(eventTag.getMainBasis())) {
- eventSubjectVo.setSubjectBasis(eventTag.getMainBasis());
- }
- subjectList.add(eventSubjectVo);
- });
- }
- eventCalloutVo.setSubjectList(subjectList);
- eventCalloutVoList.add(eventCalloutVo);
- });
- newsEventVo.setEventList(eventCalloutVoList);
- return newsEventVo;
- }
- // 发送语料平台,异步
- ThreadPoolExecutor threadPoolExecutor = ThreadPoolExecutorFactory.getThreadPoolExecutor();
- threadPoolExecutor.submit(new SendCorpusRunnable(newsId, tbmPopularFeelingsList, eventTagsMap));
- // 发送语料平台,异步
- ThreadPoolExecutor threadPoolExecutor = ThreadPoolExecutorFactory.getThreadPoolExecutor();
- threadPoolExecutor.submit(new SendCorpusRunnable(newsId, tbmPopularFeelingsList, eventTagsMap));