提交 7ef7f858 作者: chenshiqiang

commit 3.30

上级 0bbacb7c
package com.zzsn.event.controller; package com.zzsn.event.controller;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzsn.event.constant.Constants; import com.zzsn.event.constant.Constants;
import com.zzsn.event.entity.Event; import com.zzsn.event.entity.*;
import com.zzsn.event.entity.SubjectAnalysis;
import com.zzsn.event.producer.ProduceInfo; import com.zzsn.event.producer.ProduceInfo;
import com.zzsn.event.service.AnalysisService; import com.zzsn.event.service.*;
import com.zzsn.event.service.IEventService; import com.zzsn.event.util.*;
import com.zzsn.event.util.ObjectUtil;
import com.zzsn.event.util.RedisUtil;
import com.zzsn.event.util.RestUtil;
import com.zzsn.event.vo.*; import com.zzsn.event.vo.*;
import com.zzsn.event.xxljob.entity.KeyWords;
import com.zzsn.event.xxljob.service.IXxlJobInfoService; import com.zzsn.event.xxljob.service.IXxlJobInfoService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -27,271 +31,685 @@ import org.springframework.web.util.WebUtils; ...@@ -27,271 +31,685 @@ import org.springframework.web.util.WebUtils;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
/** /**
* 事件 * 事件
*
* @Author: jeecg-boot * @Author: jeecg-boot
* @Date: 2024-03-14 * @Date: 2024-03-14
* @Version: V1.0 * @Version: V1.0
*/ */
@Slf4j @Slf4j
@Api(tags="事件") @Api(tags = "事件")
@RestController @RestController
@RequestMapping("/event/event") @RequestMapping("/event/event")
public class EventController { public class EventController {
@Autowired @Autowired
private IEventService eventService; private IEventService eventService;
@Value(("${serviceProject.url:}")) @Autowired
private String SERVICE_PROJECT_URL; private IEventTagService eventTagService;
@Value(("${serviceProject.url:}"))
@Autowired private String SERVICE_PROJECT_URL;
private RedisUtil redisUtil;
@Autowired @Autowired
private AnalysisService analysisService; private RedisUtil redisUtil;
@Autowired @Autowired
private IXxlJobInfoService iXxlJobInfoService; private AnalysisService analysisService;
@Autowired @Autowired
private ProduceInfo produceInfo; private IXxlJobInfoService iXxlJobInfoService;
@Autowired
/** private ProduceInfo produceInfo;
* 分页列表查询 @Autowired
* private ISubjectInfoSourceMapService subjectInfoSourceMapService;
* @param event @Autowired
* @param pageNo private EsStatisticsService esStatisticsService;
* @param pageSize @Autowired
* @param req private LabelEntityService labelEntityService;
* @return @Autowired
*/ private SubjectDisplayServive subjectDisplayServive;
@ApiOperation(value="事件-分页列表查询", notes="事件-分页列表查询")
@GetMapping(value = "/list") /**
public Result<?> queryPageList(Event event, * 1.1 分页列表查询
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo, *
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, * @param event
HttpServletRequest req) { * @param pageNo
* @param pageSize
IPage<Event> pageList = eventService.pageList(event, pageNo,pageSize); * @param req
return Result.OK(pageList); * @return
} */
@ApiOperation(value = "事件-分页列表查询", notes = "事件-分页列表查询")
/** @GetMapping(value = "/list")
* 添加 public Result<?> queryPageList(Event event,
* @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
* @param eventParam @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
* @return HttpServletRequest req) {
*/
@ApiOperation(value="事件-添加", notes="事件-添加") IPage<Event> pageList = eventService.pageList(event, pageNo, pageSize);
@PostMapping(value = "/add") return Result.OK(pageList);
public Result<?> add(@RequestBody AddEventParam eventParam) { }
eventParam.setCreateTime(new Date());
eventParam.setUpdateTime(new Date()); /**
Event event = eventService.saveMain(eventParam); * 1.2 添加
//插入xxlJob *
iXxlJobInfoService.subjectInsert(event); * @param eventParam
return Result.OK("添加成功!"); * @return
} */
@ApiOperation(value = "事件-添加", notes = "事件-添加")
/** @PostMapping(value = "/add")
* 编辑 public Result<?> add(@RequestBody AddEventParam eventParam) {
* eventParam.setCreateTime(new Date());
* @param addEventParam eventParam.setUpdateTime(new Date());
* @return Event event = eventService.saveMain(eventParam);
*/ //插入xxlJob
@ApiOperation(value="事件-编辑", notes="事件-编辑") iXxlJobInfoService.subjectInsert(event);
@PutMapping(value = "/edit") return Result.OK("添加成功!");
public Result<?> edit(@RequestBody AddEventParam addEventParam) { }
Event byId = eventService.getById(addEventParam.getId());
addEventParam.setUpdateTime(new Date()); /**
eventService.updateMain(addEventParam); * 1.3 编辑
//更新xxljob *
List<String> subjectCodes = new ArrayList<>(); * @param addEventParam
if(null!=addEventParam.getEventCode()){ * @return
subjectCodes.add(addEventParam.getEventCode()); */
iXxlJobInfoService.keyWordsUpdate(subjectCodes, String.valueOf(addEventParam.getStatus())); @ApiOperation(value = "事件-编辑", notes = "事件-编辑")
}else { @PutMapping(value = "/edit")
return Result.error("eventCode 必传!"); public Result<?> edit(@RequestBody AddEventParam addEventParam) {
} Event byId = eventService.getById(addEventParam.getId());
addEventParam.setUpdateTime(new Date());
eventService.updateMain(addEventParam);
//判断是否提取热词 //更新xxljob
eventService.extractHotWords(addEventParam); List<String> subjectCodes = new ArrayList<>();
if (!Objects.equals(byId.getStatus(), addEventParam.getStatus()) && addEventParam.getStatus() == 1){ subjectCodes.add(addEventParam.getEventCode());
produceInfo.sendSubjectMsg(addEventParam.getEventCode()); iXxlJobInfoService.keyWordsUpdate(subjectCodes, String.valueOf(addEventParam.getStatus()));
}
return Result.OK("编辑成功!"); //判断是否提取热词
} eventService.extractHotWords(addEventParam);
if (!Objects.equals(byId.getStatus(), addEventParam.getStatus()) && addEventParam.getStatus() == 1) {
/** produceInfo.sendSubjectMsg(addEventParam.getEventCode());
* 通过id删除 }
* return Result.OK("编辑成功!");
* @param id }
* @return
*/ /**
@ApiOperation(value="事件-通过id删除", notes="事件-通过id删除") * 1.4 通过id删除
@DeleteMapping(value = "/delete") *
public Result<?> delete(@RequestParam(name="id",required=true) String id) { * @param id
Event event = eventService.getById(id); * @return
iXxlJobInfoService.deleteByInfosourceCode(event.getEventCode()); */
eventService.deleteMain(id); @ApiOperation(value = "事件-通过id删除", notes = "事件-通过id删除")
return Result.OK("删除成功!"); @DeleteMapping(value = "/delete")
} public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
Event event = eventService.getById(id);
/** iXxlJobInfoService.deleteByInfosourceCode(event.getEventCode());
* 批量删除 eventService.deleteMain(id);
* return Result.OK("删除成功!");
* @param ids }
* @return
*/ /**
@ApiOperation(value="事件-批量删除", notes="事件-批量删除") * 1.5 批量删除
@DeleteMapping(value = "/deleteBatch") *
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) { * @param ids
this.eventService.removeByIds(Arrays.asList(ids.split(","))); * @return
return Result.OK("批量删除成功!"); */
} @ApiOperation(value = "事件-批量删除", notes = "事件-批量删除")
@DeleteMapping(value = "/deleteBatch")
/** public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
* 通过id查询 this.eventService.removeByIds(Arrays.asList(ids.split(",")));
* return Result.OK("批量删除成功!");
* @param id }
* @return
*/ /**
@ApiOperation(value="事件-通过id查询", notes="事件-通过id查询") * 1.6 通过id查询
@GetMapping(value = "/queryById") *
public Result<?> queryById(@RequestParam(name="id",required=true) String id) { * @param id
Event event = eventService.getById(id); * @return
return Result.OK(event); */
} @ApiOperation(value = "事件-通过id查询", notes = "事件-通过id查询")
@GetMapping(value = "/queryById")
public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
/** Event event = eventService.getById(id);
* 专题信息源绑定 String relationEvents = event.getRelationEvents();
*/ if (null != relationEvents) {
@PostMapping("/infoSourceBind") List<String> split = Arrays.asList(relationEvents.split(","));
public Object infoSourceBind(@RequestBody SubjectPage subjectPage) { List<Event> list = eventService.list(new LambdaQueryWrapper<Event>().in(Event::getId, split));
try { event.setRelatedEventList(list);
JSONObject params = ObjectUtil.objectToJSONObject(subjectPage);; }
String url = SERVICE_PROJECT_URL + "event/infoSource/infoSourceBind"; EventTag one = eventTagService.getOne(new LambdaQueryWrapper<EventTag>()
return RestUtil.post(url, null, params); .eq(EventTag::getEventId, event.getId())
} catch (Exception e) { .last(" limit 1"));
return null; event.setEventTag(one);
} return Result.OK(event);
} }
/**
* 查询信息源组的绑定列表
* /**
*/ * 2.1 专题信息源绑定
@GetMapping("/bindList") */
public Object bindList(InfoSourceVo infoSourceVo, @PostMapping("/infoSourceBind")
@RequestParam(name="ynBind") Integer ynBind, public Object infoSourceBind(@RequestBody SubjectPage subjectPage) {
@RequestParam(name="groupId") String groupId, try {
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo, JSONObject params = ObjectUtil.objectToJSONObject(subjectPage);
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize) { ;
String url = SERVICE_PROJECT_URL + "event/infoSource/bindList"; String url = SERVICE_PROJECT_URL + "event/infoSource/infoSourceBind";
JSONObject params = ObjectUtil.objectToJSONObject(infoSourceVo); return HttpUtil.doPost(url, params, 10000);
params.put("ynBind",ynBind); } catch (Exception e) {
params.put("groupId",groupId); return null;
params.put("pageNo",pageNo); }
params.put("pageSize",pageSize); }
return RestUtil.get(url, params);
} /**
/** * 2.2 查询信息源组的绑定列表
* 关键词类别 */
* @GetMapping("/bindList")
*/ public Object bindList(InfoSourceVo infoSourceVo,
@GetMapping("/keywordsType/rootListNoPage") @RequestParam(name = "ynBind") Integer ynBind,
public Object keywordsList(@RequestParam(name = "contain", defaultValue = "false") Boolean contain, @RequestParam(name = "groupId") String groupId,
@RequestParam(name = "subjectId", defaultValue = "0") String subjectId) { @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
String url = SERVICE_PROJECT_URL + "event/keywordsType/rootListNoPage"; @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
JSONObject params = new JSONObject(); String url = SERVICE_PROJECT_URL + "event/infoSource/bindList";
params.put("contain",contain); Map<String, String> params = ObjectUtil.objectToMap(infoSourceVo);
params.put("subjectId",subjectId); params.put("ynBind", ynBind.toString());
return RestUtil.get(url, params); params.put("groupId", groupId);
} params.put("pageNo", pageNo.toString());
/** params.put("pageSize", pageSize.toString());
* 专题关键词绑定 return HttpUtil.doGet(url, params, "utf-8");
*/ }
@PostMapping("/keyWordsBind")
public Object keyWordsBind(@RequestBody SubjectPage subjectPage) { /**
try { * 2.3 关键词类别
JSONObject params = ObjectUtil.objectToJSONObject(subjectPage);; */
String url = SERVICE_PROJECT_URL + "event/keyWordsBind"; @GetMapping("/keywordsType/rootListNoPage")
return RestUtil.post(url, null, params); public Object keywordsList(@RequestParam(name = "contain", defaultValue = "false") Boolean contain,
} catch (Exception e) { @RequestParam(name = "subjectId", defaultValue = "0") String subjectId) {
return null; String url = SERVICE_PROJECT_URL + "event/keywordsType/rootListNoPage";
} Map<String, String> params = new HashMap<>();
} params.put("contain", contain.toString());
/** params.put("subjectId", subjectId);
* 专题关键词绑定 return HttpUtil.doGet(url, params, "utf-8");
*/ }
@PostMapping("/keyWordsEdit")
public Object keyWordsEdit(@RequestBody SubjectKeywordsMap subjectKeywordsMap) { /**
try { * 2.4 专题关键词绑定
JSONObject params = ObjectUtil.objectToJSONObject(subjectKeywordsMap);; */
String url = SERVICE_PROJECT_URL + "event/keyWords/edit"; @PostMapping("/keyWordsBind")
return RestUtil.post(url, null, params); public Object keyWordsBind(@RequestBody SubjectPage subjectPage) {
} catch (Exception e) { try {
return null; JSONObject params = ObjectUtil.objectToJSONObject(subjectPage);
} ;
} String url = SERVICE_PROJECT_URL + "event/keyWordsBind";
return HttpUtil.doPost(url, params, 10000);
/** } catch (Exception e) {
* 标签查询 return null;
*/ }
@PostMapping("/label/treeList") }
public Object labelTreeList(@RequestBody SubjectKeywordsMap subjectKeywordsMap) {
try { /**
JSONObject params = ObjectUtil.objectToJSONObject(subjectKeywordsMap);; * 2.5 专题关键词绑定
String url = SERVICE_PROJECT_URL + "event/label/treeList"; */
return RestUtil.post(url, null, params); @PostMapping("/keyWordsEdit")
} catch (Exception e) { public Object keyWordsEdit(@RequestBody SubjectKeywordsMap subjectKeywordsMap) {
return null; try {
} JSONObject params = ObjectUtil.objectToJSONObject(subjectKeywordsMap);
} ;
String url = SERVICE_PROJECT_URL + "event/keyWords/edit";
return HttpUtil.doPost(url, params, 10000);
} catch (Exception e) {
/** return null;
* 传播路径 }
* }
* @param eventId 事件id
*/ /**
@GetMapping("/propagationPath") * 2.6 标签查询
public Result propagationPath(@RequestParam String eventId) { */
String key = Constants.SUBJECT_ANALYSIS_PRE + Constants.PROPAGATION_KEY + eventId; @PostMapping("/label/treeList")
PropagationPathVo pathVo = (PropagationPathVo) redisUtil.get(key); public Object labelTreeList(@RequestBody SubjectKeywordsMap subjectKeywordsMap) {
if (ObjectUtils.isEmpty(pathVo)) { try {
pathVo = analysisService.propagationPath(eventId); JSONObject params = ObjectUtil.objectToJSONObject(subjectKeywordsMap);
} ;
return Result.OK(pathVo); String url = SERVICE_PROJECT_URL + "event/label/treeList";
} return HttpUtil.doPost(url, params, 10000);
/** } catch (Exception e) {
* 事件脉络 return null;
* }
* @param subjectId 专题id }
* @param fakeNum 专题事件脉络展示 伪事件脉络 的资讯数量阈值
* @return com.zzsn.subjectAnalysis.common.Result /**
*/ * 2.7 专题绑定的搜索引擎列表
@GetMapping("/eventContext") *
public Result eventContext(@RequestParam String subjectId, * @return
@RequestParam(value = "fakeNum", required = false) Integer fakeNum) { */
if (fakeNum == null) { @ApiOperation(value = "专题绑定的搜索引擎列表", notes = "专题绑定的搜索引擎列表")
fakeNum = Constants.FAKE_NUM; @GetMapping(value = "/bindSearchEngineList")
} public Object bindSearchEngineList(SearchEnginesVo searchEnginesVo) {
List<SubjectAnalysis> cacheList = analysisService.eventContext(subjectId, fakeNum); String url = SERVICE_PROJECT_URL + "event/bindSearchEngineList";
return Result.OK(cacheList); Map<String, String> params = new HashMap<>();
} params.put("searchEnginesVo", searchEnginesVo.toString());
params.put("subjectId", searchEnginesVo.getSubjectId());
/** params.put("type", searchEnginesVo.getType().toString());
* 添上传 return HttpUtil.doGet(url, params, "utf-8");
* }
* @return
*/ /**
@PostMapping(value = "/upload") * 2.8 专题搜索引擎绑定
@ResponseBody *
public Result<?> uploadKnowledge(HttpServletRequest request) { * @param subjectPage
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; * @return
MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象 */
String orgName = file.getOriginalFilename();// 获取文件名 @ApiOperation(value = "专题搜索引擎绑定", notes = "专题搜索引擎绑定")
String url=eventService.upload(file); @PostMapping(value = "/searchEngineBind")
return Result.OK(url); public Object searchEngineBind(@RequestBody SubjectPage subjectPage) {
} try {
JSONObject params = ObjectUtil.objectToJSONObject(subjectPage);
;
String url = SERVICE_PROJECT_URL + "event/searchEngineBind";
return HttpUtil.doPost(url, params, 10000);
} catch (Exception e) {
return null;
}
}
/**
* 2.9 专题绑定的信息源组列表
*
* @param id
* @return
*/
@ApiOperation(value = "专题绑定/排除的信息源组列表", notes = "专题绑定/排除的信息源组列表")
@GetMapping(value = "/bindInfoSourceList")
public Object bindInfoSourceList(@RequestParam(name = "id") String id) {
String url = SERVICE_PROJECT_URL + "event/bindInfoSourceList";
Map<String, String> params = new HashMap<>();
params.put("id", id);
return HttpUtil.doGet(url, params, "utf-8");
}
/**
* 2.10 专题信息源绑定删除
*
* @param subjectPage
* @return
*/
@ApiOperation(value = "专题信息源绑定删除", notes = "专题信息源绑定删除")
@PostMapping(value = "/deleteBindInfoSource")
public Object deleteBindInfoSource(@RequestBody SubjectPage subjectPage) {
try {
JSONObject params = ObjectUtil.objectToJSONObject(subjectPage);
;
String url = SERVICE_PROJECT_URL + "event/deleteBindInfoSource";
return HttpUtil.doPost(url, params, 10000);
} catch (Exception e) {
return null;
}
}
/**
* 2.11 专题与信息源关联编辑
*
* @param subjectInfoSourceMap
* @return
*/
@ApiOperation(value = "专题与信息源关联表-编辑", notes = "专题与信息源关联表-编辑")
@PutMapping(value = "/SubjectInfoSourceMap/edit")
public Result<?> edit(@RequestBody SubjectInfoSourceMap subjectInfoSourceMap) {
subjectInfoSourceMapService.updateMain(subjectInfoSourceMap);
return Result.OK("编辑成功!");
}
/**
* 2.12 信息源组类别列表查询
*
* @param contain
* @param subjectId
* @return
*/
@ApiOperation(value = "信息源组类别-列表查询", notes = "信息源组类别-列表查询")
@GetMapping(value = "/groupType/rootListNoPage")
public Object queryPageListNoPage(@RequestParam(name = "contain", defaultValue = "false") Boolean contain,
@RequestParam(name = "keywords", required = false) String keywords,
@RequestParam(name = "subjectId", defaultValue = "0") String subjectId) {
String url = SERVICE_PROJECT_URL + "event/groupType/rootListNoPage";
Map<String, String> params = new HashMap<>();
params.put("contain", contain.toString());
params.put("keywords", keywords);
params.put("subjectId", subjectId);
return HttpUtil.doGet(url, params, "utf-8");
}
/**
* 2.13 专题绑定的关键词组列表
*
* @param id
* @return
*/
@ApiOperation(value = "专题绑定的关键词组列表", notes = "专题绑定的关键词组列表")
@GetMapping(value = "/bindKeyWordsList")
public Object bindKeyWordsList(@RequestParam(name = "id") String id) {
String url = SERVICE_PROJECT_URL + "event/bindKeyWordsList";
Map<String, String> params = new HashMap<>();
params.put("id", id);
return HttpUtil.doGet(url, params, "utf-8");
}
/**
* 2.14 删除专题关键词绑定
*
* @param subjectPage
* @return
*/
@ApiOperation(value = "删除专题关键词绑定", notes = "删除专题关键词绑定")
@PostMapping(value = "/deleteKeyWordsBind")
public Object deleteKeyWordsBind(@RequestBody SubjectPage subjectPage) {
try {
JSONObject params = ObjectUtil.objectToJSONObject(subjectPage);
;
String url = SERVICE_PROJECT_URL + "event/deleteKeyWordsBind";
return HttpUtil.doPost(url, params, 10000);
} catch (Exception e) {
return null;
}
}
/**
* 2.15 关键词管理-分页列表查询
*
* @param keyWords
* @param pageNo
* @param pageSize
* @return
*/
@ApiOperation(value = "关键词管理-分页列表查询", notes = "关键词管理-分页列表查询")
@GetMapping(value = "/keyWords/listByTypeId")
public Object queryPageListByTypeId(KeyWords keyWords,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "wordsName", required = false) String wordsName,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "keyWordsTypeId", defaultValue = "0") String keyWordsTypeId,
@RequestParam(name = "search", defaultValue = "false") Boolean search,
@RequestParam(name = "subjectId", defaultValue = "0") String subjectId) {
String url = SERVICE_PROJECT_URL + "event/keyWords/listByTypeId";
Map<String, String> params = new HashMap<>();
keyWords.setWordsName(wordsName);
params.put("wordsName", wordsName);
params.put("pageNo", pageNo.toString());
params.put("pageSize", pageSize.toString());
params.put("keyWordsTypeId", keyWordsTypeId);
params.put("subjectId", subjectId);
params.put("search", search.toString());
return HttpUtil.doGet(url, params, "utf-8");
}
/**
* 2.16 具体标签信息列表-树状结构
*
* @return org.jeecg.common.api.vo.Result
* @author lkg
* @date 2023/1/6
*/
@PostMapping("/labelEntityTreeList")
public Object labelEntityTreeList(@RequestBody SysLabelVo sysLabelVo) {
try {
JSONObject params = ObjectUtil.objectToJSONObject(sysLabelVo);
;
String url = SERVICE_PROJECT_URL + "event/labelEntityTreeList";
return HttpUtil.doPost(url, params, 10000);
} catch (Exception e) {
return null;
}
}
/**
* 2.17 上传icon
*
* @return
*/
@PostMapping(value = "/upload")
@ResponseBody
public Result<?> uploadKnowledge(HttpServletRequest request) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象
String orgName = file.getOriginalFilename();// 获取文件名
String url = eventService.upload(file);
return Result.OK(url);
}
/**
* 3.1 传播路径
*
* @param eventId 事件id
*/
@GetMapping("/propagationPath")
public Result propagationPath(@RequestParam String eventId) {
String key = Constants.SUBJECT_ANALYSIS_PRE + Constants.PROPAGATION_KEY + eventId;
PropagationPathVo pathVo = (PropagationPathVo) redisUtil.get(key);
if (ObjectUtils.isEmpty(pathVo)) {
pathVo = analysisService.propagationPath(eventId);
}
return Result.OK(pathVo);
}
/**
* 3.2 事件脉络
*
* @param subjectId 专题id
* @param fakeNum 专题事件脉络展示 伪事件脉络 的资讯数量阈值
* @return com.zzsn.subjectAnalysis.common.Result
*/
@GetMapping("/eventContext")
public Result eventContext(@RequestParam String subjectId,
@RequestParam(value = "fakeNum", required = false) Integer fakeNum) {
if (fakeNum == null) {
fakeNum = Constants.FAKE_NUM;
}
List<SubjectAnalysis> cacheList = analysisService.eventContext(subjectId, fakeNum);
return Result.OK(cacheList);
}
/**
* 3.3 热词查询
*
* @return
*/
@ApiOperation(value = "热词查询", notes = "热词查询")
@PostMapping(value = "/keywordsCount")
public Object keywordsCount(@RequestBody SpecialInformationParam param) {
try {
JSONObject params = ObjectUtil.objectToJSONObject(param);
;
String url = SERVICE_PROJECT_URL + "event/keywordsCount";
return HttpUtil.doPost(url, params, 10000);
} catch (Exception e) {
return null;
}
}
/**
* 3.4 总体分析
*
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/1/24
*/
@GetMapping("/total")
public Result<?> totalAndMax(@RequestParam String subjectId, @RequestParam String startTime, @RequestParam String endTime) {
Map<String, Object> map = esStatisticsService.totalAndMax(subjectId, null, null);
long hours = DateUtil.between(DateUtil.parseDateTime(startTime), DateUtil.parseDateTime(endTime), DateUnit.HOUR);
map.put("duration", hours);
Object count = map.get("totalCount");
String divide = CalculateUtil.divide(String.valueOf(count), String.valueOf(hours), 2);
map.put("spread", divide);
// String mainReport = esStatisticsService.mainReport(subjectId);
map.put("mainReport", "mainReport");
return Result.OK(map);
}
/**
* 3.5 情感判断分析
*
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @param type 1-按小时;2-按天
* @author lkg
* @date 2024/1/25
*/
@GetMapping("/orientation")
public Result<?> orientation(@RequestParam String subjectId, @RequestParam String startTime,
@RequestParam String endTime, @RequestParam Integer type) {
List<CountVO> list = new ArrayList<>();
String labelTypeId = "1631119596744265729";
List<LabelEntity> labelEntities = labelEntityService.listByType(labelTypeId);
AtomicLong total = new AtomicLong();
labelEntities.forEach(e -> {
CompletableFuture<CountVO> async = CompletableFuture.supplyAsync(() -> {
CountVO countVO = esStatisticsService.orientation(subjectId, e.getId(), startTime, endTime, type);
total.addAndGet(countVO.getValue());
supply(countVO, startTime, endTime, type);
return countVO;
});
try {
CountVO countVO = async.get();
list.add(countVO);
} catch (Exception ex) {
ex.printStackTrace();
}
});
for (CountVO countVO : list) {
long value = countVO.getValue();
long totalCount = total.get();
String divide = CalculateUtil.divide(String.valueOf(value), String.valueOf(totalCount));
String percentage = "0%";
if (StringUtils.isNotEmpty(divide)) {
percentage = CalculateUtil.percentage(Double.parseDouble(divide), false);
}
countVO.setPercentage(percentage);
}
return Result.OK(list);
}
/**
* 3.6 趋势
*
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @param type 1-按小时;2-按天
* @author lkg
* @date 2024/1/25
*/
@GetMapping("/flowData")
public Result<?> flowData(@RequestParam String subjectId, @RequestParam String startTime,
@RequestParam String endTime, @RequestParam Integer type) {
AtomicLong total = new AtomicLong();
CountVO countVO = esStatisticsService.flowData(subjectId, startTime, endTime, type);
total.addAndGet(countVO.getValue());
supply(countVO, startTime, endTime, type);
long value = countVO.getValue();
long totalCount = total.get();
String divide = CalculateUtil.divide(String.valueOf(value), String.valueOf(totalCount));
String percentage = "0%";
if (StringUtils.isNotEmpty(divide)) {
percentage = CalculateUtil.percentage(Double.parseDouble(divide), false);
}
countVO.setPercentage(percentage);
return Result.OK(countVO);
}
/**
* 3.6 平台活跃度占比
*
* @param subjectId 专题id
* @author lkg
* @date 2024/1/25
*/
@GetMapping("/origin")
public Result<?> origin(@RequestParam String subjectId) {
List<CountVO> list = esStatisticsService.origin(subjectId, null, null);
return Result.OK(list);
}
/**
* 3.7 事件资讯列表展示
*
* @param subjectInfoVo 部分筛选条件封装
* @param userId 用户id
* @param video
* @param pageNo 当前页
* @param pageSize 返回条数
* @param column 排序字段
* @param isCustomer 是否为客户 1是 0 否
* @param order 排序方式
* @param crawler
* @param objectType
* @param objectId
* @param isSubject
* @param subjectType
* @param labelIds
* @param sourceId
* @author lkg
* @date 2024/1/12
*/
@ApiOperation(value = "专题信息列表-分页列表查询", notes = "专题信息列表-分页列表查询")
@PostMapping(value = "/listArticle")
public Result<?> queryPageList(@RequestBody SubjectInfoVo subjectInfoVo,
@RequestParam(name = "userId", defaultValue = "") String userId,
@RequestParam(name = "video", defaultValue = "") String video,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "isCustomer", defaultValue = "0") Integer isCustomer,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "column", defaultValue = "common") String column,
@RequestParam(name = "order", defaultValue = "desc") String order,
@RequestParam(name = "crawler", defaultValue = "") String crawler,
@RequestParam(name = "objectType", defaultValue = "", required = false) String objectType,
@RequestParam(name = "objectId", defaultValue = "", required = false) String objectId,
@RequestParam(name = "isSubject", defaultValue = "1") String isSubject,
@RequestParam(name = "subjectType", defaultValue = "1") String subjectType,
@RequestParam(name = "labelIds", required = false) String labelIds,
@RequestParam(name = "sourceId", required = false) String sourceId) throws Exception {
List<String> socialCreditCodeList = new ArrayList<>();
//获取数据
IPage<DisplayInfo> pageList = subjectDisplayServive.frontListByPage(objectType, objectId, userId, subjectInfoVo, video, pageNo, pageSize, column, order, crawler, isSubject, subjectType, labelIds, socialCreditCodeList, sourceId, isCustomer);
return Result.OK(pageList);
}
/**
* 补充缺失的时间
*/
private void supply(CountVO countVO, String startTime, String endTime, Integer type) {
List<CountVO> list = new ArrayList<>();
List<CountVO> children = countVO.getChildren();
Map<String, CountVO> map = children.stream().collect(Collectors.toMap(CountVO::getName, item -> item, (k1, k2) -> k2));
DateTime startDate = DateUtil.parseDateTime(startTime);
DateTime endDate = DateUtil.parseDateTime(endTime);
List<DateTime> rangeToList = new ArrayList<>();
String format = null;
if (type == 1) {
rangeToList = DateUtil.rangeToList(startDate, endDate, DateField.HOUR_OF_DAY);
format = "yyyy-MM-dd HH";
} else if (type == 2) {
rangeToList = DateUtil.rangeToList(startDate, endDate, DateField.DAY_OF_YEAR);
format = "yyyy-MM-dd";
}
for (DateTime dateTime : rangeToList) {
String date = DateUtil.format(dateTime, format);
if (map.containsKey(date)) {
list.add(map.get(date));
} else {
CountVO vo = new CountVO();
vo.setName(date);
vo.setValue(0L);
list.add(vo);
}
}
countVO.setChildren(list);
}
} }
package com.zzsn.event.controller;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzsn.event.constant.Constants;
import com.zzsn.event.entity.LabelEntity;
import com.zzsn.event.entity.Subject;
import com.zzsn.event.service.ColumnService;
import com.zzsn.event.service.EsStatisticsService;
import com.zzsn.event.service.IEventService;
import com.zzsn.event.service.SubjectDisplayServive;
import com.zzsn.event.util.CalculateUtil;
import com.zzsn.event.util.EsDateUtil;
import com.zzsn.event.util.RestUtil;
import com.zzsn.event.vo.*;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.index.query.WildcardQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
import org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
/**
* 报告数据接口
*
* @author lkg
* @date 2023/3/29
*/
@RestController
@RequestMapping("/datapull/report/api")
public class ReportApiController {
@Autowired
private RestHighLevelClient client;
@Autowired
private ColumnService columnService;
@Autowired
private IEventService eventService;
@Autowired
private EsStatisticsService esStatisticsService;
@Autowired
private SubjectDisplayServive subjectDisplayServive;
@Value("${subject.analysis-url:}")
private String analysisUrl;
/**
* 所有资讯类数据的分页列表
*
* @param startTime 开始时间
* @param endTime 结束时间
* @param pageNo 当前页
* @param pageSize 返回条数
* @author lkg
* @date 2024/2/28
*/
@GetMapping("/informationList")
public Result<?> informationList(@RequestParam String startTime, @RequestParam String endTime,
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "10") Integer pageSize) {
List<ReportDataVo> informationList = columnService.informationList(startTime, endTime, pageNo, pageSize);
return Result.OK(informationList);
}
/**
* 专题数据分页列表
*
* @param subjectId 专题id
* @param pageNo 当前页
* @param pageSize 返回条数
* @author lkg
* @date 2024/2/28
*/
@GetMapping("/subjectDataList")
public Result<?> subjectDataList(@RequestParam String subjectId,
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "10") Integer pageSize) {
List<ReportDataVo> dataList = columnService.subjectDataList(subjectId, pageNo, pageSize);
return Result.OK(dataList);
}
/**
* 信息总量走势图(来源)
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/2/2
*/
@GetMapping("/source")
public Result<?> source(@RequestParam(required = false) String column,
@RequestParam(required = false) boolean ynGroup,
@RequestParam(required = false) String subjectId,
@RequestParam String startTime, @RequestParam String endTime) {
List<CountVO> source = columnService.source(column, ynGroup, subjectId, startTime, endTime);
for (CountVO countVO : source) {
supply(countVO, startTime, endTime);
}
return Result.OK(source);
}
/**
* 信息属性占比
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/2/2
*/
@GetMapping("/orientation")
public Result<?> orientation(@RequestParam(required = false) String column,
@RequestParam(required = false) boolean ynGroup,
@RequestParam(required = false) String subjectId,
@RequestParam String startTime, @RequestParam String endTime) {
List<CountVO> list = new ArrayList<>();
String labelTypeId = "1631119596744265729";
List<LabelEntity> labelEntities = eventService.listByType(labelTypeId);
AtomicLong total = new AtomicLong();
labelEntities.forEach(e -> {
CompletableFuture<CountVO> async = CompletableFuture.supplyAsync(() -> {
CountVO countVO = columnService.orientation(column, true, subjectId, startTime, endTime, e.getId());
countVO.setKey(e.getName());
total.addAndGet(Long.parseLong(countVO.getCount()));
supply(countVO, startTime, endTime);
return countVO;
});
try {
CountVO countVO = async.get();
list.add(countVO);
} catch (Exception ex) {
ex.printStackTrace();
}
});
for (CountVO countVO : list) {
long value = Long.parseLong(countVO.getCount());
long totalCount = total.get();
String divide = CalculateUtil.divide(String.valueOf(value), String.valueOf(totalCount));
String percentage = "0%";
if (org.apache.commons.lang3.StringUtils.isNotEmpty(divide)) {
percentage = CalculateUtil.percentage(Double.parseDouble(divide), false);
}
countVO.setPercentage(percentage);
}
return Result.OK(list);
}
/**
* 媒体分布
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/2/2
*/
@GetMapping("/media")
public Result<?> media(@RequestParam(required = false) String column,
@RequestParam(required = false) boolean ynGroup,
@RequestParam(required = false) String subjectId,
@RequestParam String startTime, @RequestParam String endTime) {
List<MediaVO> media = columnService.media(column, ynGroup, subjectId, startTime, endTime);
return Result.OK(media);
}
/**
* 平台活跃度
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/2/2
*/
@GetMapping("/origin")
public Result<?> origin(@RequestParam(required = false) String column,
@RequestParam(required = false) boolean ynGroup,
@RequestParam(required = false) String subjectId,
@RequestParam String startTime, @RequestParam String endTime) {
List<CountVO> origin = columnService.origin(column, ynGroup, subjectId, startTime, endTime);
return Result.OK(origin);
}
/**
* 影响力
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/2/2
*/
@GetMapping("/influence")
public Result<?> influence(@RequestParam(required = false) String column,
@RequestParam(required = false) boolean ynGroup,
@RequestParam(required = false) String subjectId,
@RequestParam String startTime, @RequestParam String endTime) {
List<CountVO> influence = columnService.influence(column, ynGroup, subjectId, startTime, endTime);
return Result.OK(influence);
}
/**
* 关键词云
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @param size 热词个数
* @author lkg
* @date 2024/2/2
*/
@GetMapping("/hotWords")
public Result<?> hotWords(@RequestParam(required = false) String column,
@RequestParam(required = false) boolean ynGroup,
@RequestParam(required = false) String subjectId,
@RequestParam String startTime, @RequestParam String endTime,
@RequestParam(defaultValue = "20") Integer size) {
List<CountVO> horWords = columnService.horWords(column, ynGroup, subjectId, startTime, endTime, size);
return Result.OK(horWords);
}
/**
* 信息传播路径
*
* @param subjectId 专题id
* @author lkg
* @date 2024/1/29
*/
@GetMapping("/propagationPath")
public String propagationPath(@RequestParam String subjectId) {
JSONObject variables = new JSONObject();
variables.put("subjectId", subjectId);
String url = analysisUrl + "/analysis/propagationPath";
return RestUtil.get(url, variables).toJSONString();
}
/**
* 传播力
*
* @param subjectId 专题id
* @author lkg
* @date 2024/2/27
*/
@GetMapping("/spread")
public Result<?> spread(@RequestParam String subjectId) {
Map<String, Object> map = new HashMap<>();
Subject subject = new Subject();
Date timeEnable = subject.getTimeEnable();
Date timeDisable = subject.getTimeDisable();
DateTime beforeOneHour = DateUtil.offset(timeDisable, DateField.HOUR, -1);
Long count = columnService.count(null, null, subjectId, DateUtil.formatDateTime(beforeOneHour), DateUtil.formatDateTime(timeDisable));
map.put("increaseBefore", count);
Map<String, Object> maxValueMap = columnService.maxValue(subjectId);
map.put("hourTime", maxValueMap.get("hourTime"));
map.put("maxValue", maxValueMap.get("maxValue"));
long hours = DateUtil.between(timeEnable, timeDisable, DateUnit.HOUR);
map.put("hours", hours);
String spreadSpeed = CalculateUtil.divide(count.toString(), String.valueOf(hours), 2);
//传播速度
map.put("spreadSpeed", spreadSpeed);
List<MediaVO> media = columnService.media(null, null, subjectId, null, null);
StringBuilder mediaStr = new StringBuilder("其中");
StringBuilder stringBuilder = new StringBuilder();
int total = 0;
for (MediaVO mediaVO : media) {
String name = mediaVO.getKey();
Long mediaNum = mediaVO.getMediaNum();
total += mediaNum;
stringBuilder.append(",").append(name).append(mediaNum).append("家");
}
mediaStr.append(total).append("家媒体参与报道,");
if (stringBuilder.length() > 0) {
mediaStr.append(stringBuilder.substring(1));
}
map.put("media", mediaStr.toString());
return Result.OK(map);
}
//补充缺失的时间
private void supply(CountVO countVO, String startTime, String endTime) {
List<CountVO> list = new ArrayList<>();
List<CountVO> children = countVO.getChildren();
Map<String, CountVO> map = children.stream().collect(Collectors.toMap(CountVO::getKey, item -> item, (k1, k2) -> k2));
DateTime startDate = DateUtil.parseDateTime(startTime);
DateTime endDate = DateUtil.parseDateTime(endTime);
List<DateTime> rangeToList = DateUtil.rangeToList(startDate, endDate, DateField.DAY_OF_YEAR);
for (DateTime dateTime : rangeToList) {
String date = DateUtil.format(dateTime, "yyyy-MM-dd");
if (map.containsKey(date)) {
list.add(map.get(date));
} else {
CountVO vo = new CountVO();
vo.setKey(date);
vo.setCount("0");
list.add(vo);
}
}
countVO.setChildren(list);
}
/*------------------------------------------------------------------以下为---真实测试模板对应的数据接口---------------------------------------------------------------------------*/
/**
* 获取专题信息列表(最近10条)
*
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2023/3/29
*/
@GetMapping("/dataOfSubject")
public Result<?> dataOfSubject(@RequestParam("subjectId") String subjectId,
@RequestParam(value = "startTime", required = false) String startTime,
@RequestParam(value = "endTime", required = false) String endTime) {
List<ReportDataVo> list = new ArrayList<>();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(subjectId, startTime, endTime, 10);
//按时间倒序
searchSourceBuilder.sort("publishDate", SortOrder.DESC);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = null;
try {
searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
} catch (Exception e) {
e.printStackTrace();
}
if (searchResponse != null) {
SearchHit[] searchHits = searchResponse.getHits().getHits();
for (SearchHit hit : searchHits) {
String queryInfo = hit.getSourceAsString();
ReportDataVo info = JSON.parseObject(queryInfo, ReportDataVo.class);
info.setPublishDate(EsDateUtil.esFieldDateMapping(info.getPublishDate()));
list.add(info);
}
}
return Result.OK(list);
}
/**
* 获取前几来源(饼图+表格)
*
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @param size 前几
* @author lkg
* @date 2023/3/29
*/
@GetMapping("/topOrigin")
public Result<?> groupByOrigin(@RequestParam("subjectId") String subjectId,
@RequestParam(value = "startTime", required = false) String startTime,
@RequestParam(value = "endTime", required = false) String endTime,
@RequestParam(value = "size", defaultValue = "10") Integer size) {
List<Map<String, Object>> data = new ArrayList<>();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(subjectId, startTime, endTime, 0);
//按来源分组
TermsAggregationBuilder originAggregationBuilder = AggregationBuilders.terms("group_origin")
.field("origin.keyword")
.order(BucketOrder.count(false))
.size(size); //返回的最大数据
searchSourceBuilder.aggregation(originAggregationBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = null;
try {
searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
} catch (Exception e) {
e.printStackTrace();
}
if (searchResponse != null) {
//获取分组桶
Aggregations aggregations = searchResponse.getAggregations();
//获取按来源分组集合
Terms groupOrigin = aggregations.get("group_origin");
List<? extends Terms.Bucket> originBuckets = groupOrigin.getBuckets();
for (Terms.Bucket originBucket : originBuckets) {
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("name", originBucket.getKeyAsString());
dataMap.put("value", originBucket.getDocCount());
data.add(dataMap);
}
}
return Result.OK(data);
}
/**
* 柱状图
*
* @param subjectId 专题id
* @param size 前几
* @author lkg
* @date 2023/3/29
*/
@GetMapping("/histogram")
public Result<?> histogram(@RequestParam("subjectId") String subjectId, @RequestParam(value = "size", defaultValue = "10") Integer size) {
List<Map<String, Object>> result = new ArrayList<>();
List<Map<String, Object>> list = groupByOriginDate(subjectId, size);
Map<String, List<Map<String, Object>>> originMap = list.stream().collect(Collectors.groupingBy(e -> e.get("name").toString()));
for (Map.Entry<String, List<Map<String, Object>>> nameEntry : originMap.entrySet()) {
Map<String, Object> data = new HashMap<>();
String name = nameEntry.getKey();
List<Map<String, Object>> value = nameEntry.getValue();
data.put("name", name);
for (Map<String, Object> map : value) {
data.put(map.get("date").toString(), map.get("value"));
}
result.add(data);
}
return Result.OK(result);
}
/**
* 折线图和双轴图
*
* @param subjectId 专题id
* @param size 前几
* @author lkg
* @date 2023/3/29
*/
@GetMapping("/discount")
public Result<?> discount(@RequestParam("subjectId") String subjectId, @RequestParam(value = "size", defaultValue = "10") Integer size) {
List<Map<String, Object>> ratioList = new ArrayList<>();
List<Map<String, Object>> list = groupByOriginDate(subjectId, size);
Map<String, List<Map<String, Object>>> dateMap = list.stream().collect(Collectors.groupingBy(e -> e.get("date").toString()));
for (Map.Entry<String, List<Map<String, Object>>> dateEntry : dateMap.entrySet()) {
Map<String, Object> ratio = new HashMap<>();
String date = dateEntry.getKey();
ratio.put("date", date);
List<Map<String, Object>> value = dateEntry.getValue();
for (Map<String, Object> map : value) {
String name = map.get("name").toString();
if ("网易新闻".equals(name)) {
ratio.put(name, map.get("value"));
}
if ("新浪财经".equals(name)) {
ratio.put(name, map.get("value"));
}
}
Object sina = ratio.get("新浪财经");
Object netEase = ratio.get("网易新闻");
String divide = CalculateUtil.divide(sina == null ? null : sina.toString(), netEase == null ? null : netEase.toString(), 2);
ratio.put("占比", CalculateUtil.multiply(divide, "100"));
ratioList.add(ratio);
}
return Result.OK(ratioList);
}
/**
* 现根据来源分组,再根据月份分组
*
* @param subjectId 专题id
* @param size 前几
* @author lkg
* @date 2023/3/29
*/
public List<Map<String, Object>> groupByOriginDate(String subjectId, Integer size) {
List<Map<String, Object>> data = new ArrayList<>();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(subjectId, null, null, 0);
//按来源分组
TermsAggregationBuilder originAggregationBuilder = AggregationBuilders.terms("group_origin")
.field("origin.keyword")
.order(BucketOrder.count(false))
.subAggregation(AggregationBuilders.dateHistogram("group_month")
.field("publishDate")
.calendarInterval(DateHistogramInterval.MONTH)
.format("yyyy-MM")).size(size); //返回的最大数据
searchSourceBuilder.aggregation(originAggregationBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = null;
try {
searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
} catch (Exception e) {
e.printStackTrace();
}
if (searchResponse != null) {
//获取分组桶
Aggregations aggregations = searchResponse.getAggregations();
//获取按来源分组集合
Terms groupOrigin = aggregations.get("group_origin");
List<? extends Terms.Bucket> originBuckets = groupOrigin.getBuckets();
for (Terms.Bucket originBucket : originBuckets) {
String originName = originBucket.getKeyAsString();
long originCount = originBucket.getDocCount();
Aggregations monthAggregations = originBucket.getAggregations();
ParsedDateHistogram groupMonth = monthAggregations.get("group_month");
for (Histogram.Bucket monthBucket : groupMonth.getBuckets()) {
Map<String, Object> map = new HashMap<>();
String month = monthBucket.getKeyAsString();
long count = monthBucket.getDocCount();
map.put("name", originName);
map.put("totalCount", originCount);
map.put("date", month);
map.put("value", count);
data.add(map);
}
}
}
return data;
}
private SearchSourceBuilder getSearchSourceBuilder(String subjectId, String startTime, String endTime, Integer originSize) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.trackTotalHits(true);
searchSourceBuilder.size(originSize);//不输出原始数据
//创建查询对象
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
//专题筛选
TermQueryBuilder termQuery = QueryBuilders.termQuery("subjectId", subjectId);
boolQuery.must(termQuery);
//时间范围筛选
if (StringUtils.isNotBlank(startTime)) {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").gte(EsDateUtil.esFieldDateFormat(startTime)));
}
if (StringUtils.isNotBlank(endTime)) {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").lte(EsDateUtil.esFieldDateFormat(endTime)));
} else {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").lte(EsDateUtil.esFieldDateFormat(DateUtil.formatDateTime(new Date()))));
}
//过滤掉origin为空的数据
WildcardQueryBuilder wildcardQueryBuilder = QueryBuilders.wildcardQuery("origin", "*");
//主条目且未删除
boolQuery.mustNot(QueryBuilders.matchQuery("flag", 0));
boolQuery.mustNot(QueryBuilders.matchQuery("deleteFlag", "1"));
boolQuery.must(wildcardQueryBuilder);
searchSourceBuilder.query(boolQuery);
return searchSourceBuilder;
}
/**
* 3.4 总体分析
*
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/1/24
*/
@GetMapping("/total")
public Result<?> totalAndMax(@RequestParam String subjectId, @RequestParam String startTime, @RequestParam String endTime) {
Map<String, Object> map = esStatisticsService.totalAndMax(subjectId, null, null);
long hours = DateUtil.between(DateUtil.parseDateTime(startTime), DateUtil.parseDateTime(endTime), DateUnit.HOUR);
map.put("duration", hours);
Object count = map.get("totalCount");
String divide = CalculateUtil.divide(String.valueOf(count), String.valueOf(hours), 2);
map.put("spread", divide);
// String mainReport = esStatisticsService.mainReport(subjectId);
map.put("mainReport", "mainReport");
return Result.OK(map);
}
/**
* 3.7 事件资讯列表展示
*
* @param video
* @param pageNo 当前页
* @param pageSize 返回条数
* @param column 排序字段
* @param isCustomer 是否为客户 1是 0 否
* @param order 排序方式
* @param crawler
* @param objectType
* @param objectId
* @param isSubject
* @param subjectType
* @param labelIds
* @param sourceId
* @author lkg
* @date 2024/1/12
*/
@ApiOperation(value = "专题信息列表-分页列表查询", notes = "专题信息列表-分页列表查询")
@GetMapping(value = "/listArticle")
public Result<?> queryPageList(
@RequestParam(name = "subjectId", defaultValue = "") String subjectId,
@RequestParam(name = "video", defaultValue = "") String video,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "isCustomer", defaultValue = "0") Integer isCustomer,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "column", defaultValue = "common") String column,
@RequestParam(name = "order", defaultValue = "desc") String order,
@RequestParam(name = "crawler", defaultValue = "") String crawler,
@RequestParam(name = "objectType", defaultValue = "", required = false) String objectType,
@RequestParam(name = "objectId", defaultValue = "", required = false) String objectId,
@RequestParam(name = "isSubject", defaultValue = "1") String isSubject,
@RequestParam(name = "subjectType", defaultValue = "1") String subjectType,
@RequestParam(name = "labelIds", required = false) String labelIds,
@RequestParam(name = "sourceId", required = false) String sourceId) throws Exception {
SubjectInfoVo subjectInfoVo=new SubjectInfoVo();
subjectInfoVo.setSubjectId(subjectId);
List<String> socialCreditCodeList = new ArrayList<>();
//获取数据
IPage<DisplayInfo> pageList = subjectDisplayServive.frontListByPage(objectType, objectId, null, subjectInfoVo, video, pageNo, pageSize, column, order, crawler, isSubject, subjectType, labelIds, socialCreditCodeList, sourceId, isCustomer);
return Result.OK(pageList);
}
}
...@@ -2,6 +2,8 @@ package com.zzsn.event.entity; ...@@ -2,6 +2,8 @@ package com.zzsn.event.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
...@@ -123,4 +125,16 @@ public class Event { ...@@ -123,4 +125,16 @@ public class Event {
private Integer mediaHot; private Integer mediaHot;
private Integer wechatHot; private Integer wechatHot;
private Integer otherHot; private Integer otherHot;
private Integer publishStatus;
private String relationEvents;
@TableField(exist = false)
private String startDate;
@TableField(exist = false)
private String endDate;
@TableField(exist = false)
private List<Event> relatedEventList;
@TableField(exist = false)
private EventTag eventTag;
} }
package com.zzsn.event.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
/**
* @Description: EventTag
* @Author: jeecg-boot
* @Date: 2024-03-14
* @Version: V1.0
*/
@Data
@TableName("event_tag")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value="EventTag对象", description="事件")
public class EventTag {
/**ID*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "ID")
private String id;
private String eventId;
private String extractIndustryTag;
private String extractCompanyTag;
private String extractPersonTag;
private String extractSentimentTag;
private String extractKeywordsTag;
private String extractLocationTag;
private String extractTimeTag;
}
...@@ -2,6 +2,7 @@ package com.zzsn.event.mapper; ...@@ -2,6 +2,7 @@ package com.zzsn.event.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.event.entity.Event; import com.zzsn.event.entity.Event;
import com.zzsn.event.entity.LabelEntity;
import com.zzsn.event.vo.SubjectKafkaVo; import com.zzsn.event.vo.SubjectKafkaVo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -25,4 +26,6 @@ public interface EventMapper extends BaseMapper<Event> { ...@@ -25,4 +26,6 @@ public interface EventMapper extends BaseMapper<Event> {
Integer totalCount(@Param("event") Event event); Integer totalCount(@Param("event") Event event);
List<SubjectKafkaVo> prosessList(Date disableDate); List<SubjectKafkaVo> prosessList(Date disableDate);
List<LabelEntity> listByType(String labelTypeId);
} }
package com.zzsn.event.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.event.entity.EventTag;
import org.apache.ibatis.annotations.Mapper;
/**
* @Author: jeecg-boot
* @Date: 2024-03-14
* @Version: V1.0
*/
@Mapper
public interface EventTagMapper extends BaseMapper<EventTag> {
}
package com.zzsn.event.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.event.xxljob.entity.InfoSource;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @Description: 信息源表
* @Author: jeecg-boot
* @Date: 2022-01-18
* @Version: V1.0
*/
@Mapper
public interface InfoSourceMapper extends BaseMapper<InfoSource> {
String getNatureName(@Param("id") String id);
}
...@@ -19,6 +19,13 @@ ...@@ -19,6 +19,13 @@
<if test="event.eventType!=null and event.eventType != ''"> <if test="event.eventType!=null and event.eventType != ''">
and t1.event_type = #{event.eventType} and t1.event_type = #{event.eventType}
</if> </if>
<if test="event.startDate!=null and event.startDate != ''">
and t1.create_time >= #{event.startDate}
</if>
<if test="event.endDate!=null and event.endDate != ''">
and t1.create_time <![CDATA[ <= ]]> #{event.endDate}
</if>
order by t1.create_time desc
limit #{offset}, #{pageSize} limit #{offset}, #{pageSize}
</select> </select>
<select id="totalCount" resultType="java.lang.Integer"> <select id="totalCount" resultType="java.lang.Integer">
...@@ -31,15 +38,27 @@ ...@@ -31,15 +38,27 @@
<if test="event.eventType!=null and event.eventType != ''"> <if test="event.eventType!=null and event.eventType != ''">
and t1.event_type = #{event.eventType} and t1.event_type = #{event.eventType}
</if> </if>
<if test="event.startDate!=null and event.startDate != ''">
and t1.create_time >= #{event.startDate}
</if>
<if test="event.endDate!=null and event.endDate != ''">
and t1.create_time <![CDATA[ <= ]]> #{event.endDate}
</if>
</select> </select>
<select id="prosessList" resultType="com.zzsn.event.vo.SubjectKafkaVo"> <select id="prosessList" resultType="com.zzsn.event.vo.SubjectKafkaVo">
select s.id,s.event_name as subject_name,s.start_time as time_enable,s.end_time as time_disable,s.incre_ana_rule, select s.id,s.event_name as subject_name,s.start_time as time_enable,s.end_time as time_disable,s.incre_ana_rule,
s.total_ana_rule,s.time_ana_rule,s.analysis_time,s.event_time s.total_ana_rule,s.time_ana_rule,s.analysis_time,s.event_time
from event s from event s
where 1=1 where 1=1 and id='1702575766171996162'
<if test="endDate != null"> <if test="endDate != null">
and (s.end_time is null or s.end_time <![CDATA[ >= ]]> #{endDate}) and (s.end_time is null or s.end_time <![CDATA[ >= ]]> #{endDate})
</if> </if>
</select> </select>
<select id="listByType" resultType="com.zzsn.event.entity.LabelEntity">
SELECT e.id, e.name
FROM label_entity e
inner join sys_base_label_type_map m on e.id = m.relation_id
where m.label_id = #{labelTypeId}
</select>
</mapper> </mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zzsn.event.mapper.InfoSourceMapper">
<select id="getNatureName" resultType="String">
select nature_name from info_source_nature where id = #{id}
</select>
</mapper>
package com.zzsn.event.service;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzsn.event.constant.Constants;
import com.zzsn.event.enums.InfluenceEnum;
import com.zzsn.event.enums.SourceEnum;
import com.zzsn.event.util.CalculateUtil;
import com.zzsn.event.util.EsDateUtil;
import com.zzsn.event.vo.CountVO;
import com.zzsn.event.vo.MediaVO;
import com.zzsn.event.vo.ReportDataVo;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
import org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram;
import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.nested.ParsedNested;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.Cardinality;
import org.elasticsearch.search.aggregations.metrics.Sum;
import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.collapse.CollapseBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.*;
/**
* todo
*
* @author lkg
* @date 2024/1/30
*/
@Service
public class ColumnService {
@Autowired
private RestHighLevelClient client;
@Autowired
private IInfoSourceService infoSourceService;
/**
* 获取栏目或栏目组下的信息数量
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/1/30
*/
public Long count(String column, Boolean ynGroup, String subjectId, String startTime, String endTime) {
long count = 0;
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(column, ynGroup, subjectId, startTime, endTime, null);
searchSourceBuilder.size(0);
searchSourceBuilder.trackTotalHits(true);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse;
try {
searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
count = searchResponse.getHits().getTotalHits().value;
} catch (Exception e) {
e.printStackTrace();
}
return count;
}
/**
* 按信息源性质分组数量统计
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/1/30
*/
public List<CountVO> source(String column, Boolean ynGroup, String subjectId, String startTime, String endTime) {
List<CountVO> list = new ArrayList<>();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(column, ynGroup, subjectId, startTime, endTime, null);
searchSourceBuilder.size(0);
searchSourceBuilder.trackTotalHits(true);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("group_source")
.field("infoSourceTypeId.keyword")
.order(BucketOrder.count(false))
.size(SourceEnum.values().length)
.subAggregation(AggregationBuilders.dateHistogram("group_day")
.field("publishDate")
.calendarInterval(DateHistogramInterval.DAY)
.format("yyyy-MM-dd")
);
searchSourceBuilder.aggregation(aggregationBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse;
try {
searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
long value = searchResponse.getHits().getTotalHits().value;
Aggregations aggregations = searchResponse.getAggregations();
Terms groupSource = aggregations.get("group_source");
List<? extends Terms.Bucket> sourceBuckets = groupSource.getBuckets();
for (int i = 0; i < sourceBuckets.size(); i++) {
Terms.Bucket source = sourceBuckets.get(i);
CountVO countVO = new CountVO();
countVO.setOrder(i + 1);
String keyAsString = source.getKeyAsString();
countVO.setKey(SourceEnum.getDescription(keyAsString));
long count = source.getDocCount();
countVO.setCount(String.valueOf(count));
String percentage = getPercentage(count, value);
countVO.setPercentage(percentage);
List<CountVO> children = new ArrayList<>();
Aggregations sourceAggregations = source.getAggregations();
ParsedDateHistogram groupDay = sourceAggregations.get("group_day");
List<? extends Histogram.Bucket> dayBuckets = groupDay.getBuckets();
for (Histogram.Bucket day : dayBuckets) {
CountVO vo = new CountVO();
vo.setKey(day.getKeyAsString());
vo.setCount(String.valueOf(day.getDocCount()));
children.add(vo);
}
countVO.setChildren(children);
list.add(countVO);
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
/**
* 影响力数量统计-点赞数、评论数、收藏数、分享数
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/1/30
*/
public List<CountVO> influence(String column, Boolean ynGroup, String subjectId, String startTime, String endTime) {
List<CountVO> list = new ArrayList<>();
InfluenceEnum[] influenceEnums = InfluenceEnum.values();
for (InfluenceEnum influenceEnum : influenceEnums) {
String field = influenceEnum.getField();
String description = influenceEnum.getDescription();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(column, ynGroup, subjectId, startTime, endTime, null);
searchSourceBuilder.size(0);
searchSourceBuilder.trackTotalHits(true);
SumAggregationBuilder sumAggregationBuilder = AggregationBuilders.sum("sum_count").field(field);
searchSourceBuilder.aggregation(sumAggregationBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse;
try {
searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
Aggregations aggregations = searchResponse.getAggregations();
Sum sumCount = aggregations.get("sum_count");
double value = sumCount.getValue();
CountVO countVO = new CountVO();
countVO.setKey(description);
countVO.setCount(String.valueOf(value));
list.add(countVO);
} catch (Exception e) {
e.printStackTrace();
}
}
return list;
}
/**
* 情感数量统计
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @param labelId 情感标签id
* @author lkg
* @date 2024/2/2
*/
public CountVO orientation(String column, Boolean ynGroup, String subjectId, String startTime, String endTime, String labelId) {
CountVO countVO = new CountVO();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(column, ynGroup, subjectId, startTime, endTime, labelId);
searchSourceBuilder.size(0);
searchSourceBuilder.trackTotalHits(true);
DateHistogramAggregationBuilder aggregation = AggregationBuilders.dateHistogram("group_day")
.field("publishDate")
.calendarInterval(DateHistogramInterval.DAY)
.format("yyyy-MM-dd");
searchSourceBuilder.aggregation(aggregation);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
long value = response.getHits().getTotalHits().value;
countVO.setCount(String.valueOf(value));
List<CountVO> list = new ArrayList<>();
Aggregations aggregations = response.getAggregations();
ParsedDateHistogram groupHour = aggregations.get("group_day");
List<? extends Histogram.Bucket> buckets = groupHour.getBuckets();
if (CollectionUtils.isNotEmpty(buckets)) {
for (Histogram.Bucket bucket : buckets) {
CountVO vo = new CountVO();
vo.setKey(bucket.getKeyAsString());
vo.setCount(String.valueOf(bucket.getDocCount()));
list.add(vo);
}
}
countVO.setChildren(list);
} catch (Exception e) {
e.printStackTrace();
}
return countVO;
}
/**
* 媒体分布
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/2/2
*/
public List<MediaVO> media(String column, Boolean ynGroup, String subjectId, String startTime, String endTime) {
List<MediaVO> list = new ArrayList<>();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(column, ynGroup, subjectId, startTime, endTime, null);
searchSourceBuilder.size(0);
searchSourceBuilder.trackTotalHits(true);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("group_nature")
.field("infoSourceNatureId.keyword")
.subAggregation(AggregationBuilders.cardinality("sid_count").field("sid.keyword"));
searchSourceBuilder.aggregation(aggregationBuilder);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
long totalCount = response.getHits().getTotalHits().value;
Aggregations aggregations = response.getAggregations();
Terms groupNature = aggregations.get("group_nature");
List<? extends Terms.Bucket> natureBuckets = groupNature.getBuckets();
for (int i = 0; i < natureBuckets.size(); i++) {
Terms.Bucket nature = natureBuckets.get(i);
MediaVO vo = new MediaVO();
vo.setOrder(i + 1);
String natureName = infoSourceService.getNatureName(nature.getKeyAsString());
vo.setKey(natureName);
long count = nature.getDocCount();
vo.setCount(count);
String percentage = getPercentage(count, totalCount);
vo.setPercentage(percentage);
Aggregations natureAggregations = nature.getAggregations();
Cardinality sidCount = natureAggregations.get("sid_count");
long value = sidCount.getValue();
vo.setMediaNum(value);
list.add(vo);
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
/**
* 平台活跃度排名
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @author lkg
* @date 2024/2/2
*/
public List<CountVO> origin(String column, Boolean ynGroup, String subjectId, String startTime, String endTime) {
List<CountVO> list = new ArrayList<>();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(column, ynGroup, subjectId, startTime, endTime, null);
searchSourceBuilder.size(0);
searchSourceBuilder.trackTotalHits(true);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("group_origin")
.field("origin.keyword")
.order(BucketOrder.count(false))
.size(10);
searchSourceBuilder.aggregation(aggregationBuilder);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
long value = response.getHits().getTotalHits().value;
Aggregations aggregations = response.getAggregations();
Terms groupSource = aggregations.get("group_origin");
List<? extends Terms.Bucket> buckets = groupSource.getBuckets();
if (CollectionUtils.isNotEmpty(buckets)) {
for (int i = 0; i < buckets.size(); i++) {
Terms.Bucket bucket = buckets.get(i);
CountVO vo = new CountVO();
vo.setOrder(i + 1);
vo.setKey(bucket.getKeyAsString());
long count = bucket.getDocCount();
vo.setCount(String.valueOf(count));
String percentage = getPercentage(count, value);
vo.setPercentage(percentage);
list.add(vo);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
/**
* 热词词云
*
* @param column 栏目id或栏目组id,多个逗号隔开
* @param ynGroup 是否栏目组
* @param subjectId 专题id
* @param startTime 开始时间
* @param endTime 结束时间
* @param size 热词个数
* @author lkg
* @date 2024/2/2
*/
public List<CountVO> horWords(String column, Boolean ynGroup, String subjectId, String startTime, String endTime, Integer size) {
List<CountVO> list = new ArrayList<>();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(column, ynGroup, subjectId, startTime, endTime, null);
searchRequest.source(searchSourceBuilder);
searchSourceBuilder.size(0);
searchSourceBuilder.trackTotalHits(true);
TermsAggregationBuilder aggTerms = AggregationBuilders.terms("keyWordsList")
.field("keyWordsList.keyword")
.size(size);
searchSourceBuilder.aggregation(aggTerms);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
//获取分组桶
Aggregations aggregations = searchResponse.getAggregations();
Terms keyWordsList = aggregations.get("keyWordsList");
List<? extends Terms.Bucket> buckets = keyWordsList.getBuckets();
for (int i = 0; i < buckets.size(); i++) {
Terms.Bucket bucket = buckets.get(i);
CountVO countVO = new CountVO();
countVO.setKey(bucket.getKeyAsString());
countVO.setCount(String.valueOf(bucket.getDocCount()));
countVO.setOrder(i + 1);
list.add(countVO);
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
/**
* 事件专题信息峰值以及峰值所在点
*
* @param subjectId 专题id
* @author lkg
* @date 2024/2/28
*/
public Map<String, Object> maxValue(String subjectId) {
Map<String, Object> map = new HashMap<>();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(null, null, subjectId, null, null, null);
searchSourceBuilder.size(0);
searchSourceBuilder.trackTotalHits(true);
DateHistogramAggregationBuilder aggregation = AggregationBuilders.dateHistogram("group_hour")
.field("publishDate")
.calendarInterval(DateHistogramInterval.HOUR)
.format("yyyy-MM-dd HH")
.order(BucketOrder.count(false));
searchSourceBuilder.aggregation(aggregation);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
Aggregations aggregations = response.getAggregations();
ParsedDateHistogram groupHour = aggregations.get("group_hour");
List<? extends Histogram.Bucket> buckets = groupHour.getBuckets();
if (CollectionUtils.isNotEmpty(buckets)) {
Histogram.Bucket bucket = buckets.get(0);
long count = bucket.getDocCount();
String key = bucket.getKeyAsString();
map.put("hourTime", key);
map.put("maxValue", count);
}
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
/**
* @param subjectId 专题
* @param pageNo 当前页
* @param pageSize 返回条数
* @author lkg
* @date 2024/2/28
*/
public List<ReportDataVo> subjectDataList(String subjectId, Integer pageNo, Integer pageSize) {
List<ReportDataVo> dataList = new ArrayList<>();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(null, null, subjectId, null, null, null);
int offset = (pageNo - 1) * pageSize;
searchSourceBuilder.from(offset);
searchSourceBuilder.size(pageSize);
searchSourceBuilder.trackTotalHits(true);
searchSourceBuilder.sort("publishDate", SortOrder.DESC);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
SearchHit[] hits = response.getHits().getHits();
for (SearchHit hit : hits) {
String sourceAsString = hit.getSourceAsString();
ReportDataVo reportDataVo = JSON.parseObject(sourceAsString, ReportDataVo.class);
dataList.add(reportDataVo);
}
} catch (Exception e) {
e.printStackTrace();
}
return dataList;
}
/**
* 所有资讯类数据的分页列表
*
* @param startTime 开始时间
* @param endTime 结束时间
* @param pageNo 当前页
* @param pageSize 返回条数
* @author lkg
* @date 2024/2/28
*/
public List<ReportDataVo> informationList(String startTime, String endTime, Integer pageNo, Integer pageSize) {
List<ReportDataVo> dataList = new ArrayList<>();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = getSearchSourceBuilder(null, null, null, startTime, endTime, null);
int offset = (pageNo - 1) * pageSize;
searchSourceBuilder.from(offset);
searchSourceBuilder.size(pageSize);
searchSourceBuilder.trackTotalHits(true);
searchSourceBuilder.sort("publishDate", SortOrder.DESC);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
SearchHit[] hits = response.getHits().getHits();
for (SearchHit hit : hits) {
String sourceAsString = hit.getSourceAsString();
ReportDataVo reportDataVo = JSON.parseObject(sourceAsString, ReportDataVo.class);
dataList.add(reportDataVo);
}
} catch (Exception e) {
e.printStackTrace();
}
return dataList;
}
private SearchSourceBuilder getSearchSourceBuilder(String column, Boolean ynGroup, String subjectId, String startTime, String endTime, String labelId) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
//去重 collapse只允许keywords或者numbers类型
searchSourceBuilder.collapse(new CollapseBuilder("sourceAddress.keyword"));
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
BoolQueryBuilder dataTypeBoolQuery = QueryBuilders.boolQuery();
dataTypeBoolQuery.should(QueryBuilders.termQuery("dataType.keyword", "yqjc"));
dataTypeBoolQuery.should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("dataType")));
boolQuery.must(dataTypeBoolQuery);
if (StringUtils.isNotEmpty(subjectId)) {
boolQuery.must(QueryBuilders.termQuery("subjectId.keyword", subjectId));
}
if (StringUtils.isNotEmpty(startTime)) {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").gte(EsDateUtil.esFieldDateFormat(startTime)));
}
if (StringUtils.isNotEmpty(endTime)) {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").lte(EsDateUtil.esFieldDateFormat(endTime)));
}
if (StringUtils.isNotEmpty(labelId)) {
boolQuery.must(QueryBuilders.nestedQuery("labels", QueryBuilders.termQuery("labels.relationId", labelId), ScoreMode.None));
}
//未删除状态查询
boolQuery.mustNot(QueryBuilders.matchQuery("deleteFlag", "1"));
searchSourceBuilder.query(boolQuery);
return searchSourceBuilder;
}
/**
* 获取占比
*
* @param count 数量
* @param totalCount 总数量
* @author lkg
* @date 2024/1/25
*/
private String getPercentage(long count, long totalCount) {
String divide = CalculateUtil.divide(String.valueOf(count), String.valueOf(totalCount));
String percentage = "0%";
if (StringUtils.isNotEmpty(divide)) {
percentage = CalculateUtil.percentage(Double.parseDouble(divide), false);
}
return percentage;
}
}
...@@ -144,4 +144,6 @@ public interface EsStatisticsService { ...@@ -144,4 +144,6 @@ public interface EsStatisticsService {
* @date 2024/2/29 * @date 2024/2/29
*/ */
Page<NegativeDataVO> labelPageList(String labelId, String startTime, String endTime, Integer pageNo, Integer pageSize); Page<NegativeDataVO> labelPageList(String labelId, String startTime, String endTime, Integer pageNo, Integer pageSize);
CountVO flowData(String subjectId, String startTime, String endTime, Integer type);
} }
...@@ -3,6 +3,7 @@ package com.zzsn.event.service; ...@@ -3,6 +3,7 @@ package com.zzsn.event.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzsn.event.entity.Event; import com.zzsn.event.entity.Event;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.event.entity.LabelEntity;
import com.zzsn.event.vo.AddEventParam; import com.zzsn.event.vo.AddEventParam;
import com.zzsn.event.vo.KeyWordsPage; import com.zzsn.event.vo.KeyWordsPage;
import com.zzsn.event.vo.SubjectKafkaVo; import com.zzsn.event.vo.SubjectKafkaVo;
...@@ -43,4 +44,6 @@ public interface IEventService extends IService<Event> { ...@@ -43,4 +44,6 @@ public interface IEventService extends IService<Event> {
void deleteMain(String id); void deleteMain(String id);
String upload(MultipartFile file); String upload(MultipartFile file);
List<LabelEntity> listByType(String labelTypeId);
} }
package com.zzsn.event.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.event.entity.EventTag;
/**
* @Description: 事件
* @Author: jeecg-boot
* @Date: 2024-03-14
* @Version: V1.0
*/
public interface IEventTagService extends IService<EventTag> {
}
package com.zzsn.event.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.event.xxljob.entity.InfoSource;
/**
* @Description: 信息源表
* @Author: jeecg-boot
* @Date: 2022-01-18
* @Version: V1.0
*/
public interface IInfoSourceService extends IService<InfoSource> {
String getNatureName(String id);
}
package com.zzsn.event.service;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzsn.event.constant.Constants;
import com.zzsn.event.util.DateUtil;
import com.zzsn.event.util.EsDateUtil;
import com.zzsn.event.util.EsIndexUtil;
import com.zzsn.event.vo.DisplayInfo;
import com.zzsn.event.vo.SubjectInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@Slf4j
@Service
public class SubjectDisplayServive {
@Autowired
private RestHighLevelClient client;
/**
* 分页获取数据
*
* @param subjectInfo 查询条件封装
* @param offset 页数
* @param pageSize 每页条数
* @param labelIds
* @param socialCreditCodeList 企业信用代码集合
* @param sourceId
* @throws Exception 异常
*/
public IPage<DisplayInfo> frontListByPage(String objectType, String objectId, String userId, SubjectInfoVo subjectInfo, String video, int offset, int pageSize,
String column, String order, String crawler, String isSubject, String subjectType, String labelIds, List<String> socialCreditCodeList, String sourceId, Integer isCustomer) throws Exception {
String[] indexs = EsIndexUtil.getIndexIntervalYear(Constants.ES_DATA_FOR_SUBJECT, subjectInfo.getStartTime(), subjectInfo.getEndTime());
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
//设置分页参数
searchSourceBuilder.size(pageSize);
searchSourceBuilder.from((offset - 1) * pageSize);
//默认按照置顶以及时间倒序排列
//根据topNum正序查找,查询置顶数据
searchSourceBuilder.sort("topNum", SortOrder.DESC);
if (column.equals("score")) {
if (order.equals("asc")) {
searchSourceBuilder.sort("score", SortOrder.ASC);
searchSourceBuilder.sort("publishDate", SortOrder.ASC);
} else if (order.equals("desc")) {
searchSourceBuilder.sort("score", SortOrder.DESC);
searchSourceBuilder.sort("publishDate", SortOrder.DESC);
}
} else if (column.equals("publishDate")) {
if (order.equals("desc")) {
searchSourceBuilder.sort("publishDate", SortOrder.DESC);
searchSourceBuilder.sort("score", SortOrder.DESC);
} else if (order.equals("asc")) {
searchSourceBuilder.sort("publishDate", SortOrder.ASC);
searchSourceBuilder.sort("score", SortOrder.ASC);
}
}
//默认最大数量是10000,设置为true后,显示准确数量
searchSourceBuilder.trackTotalHits(true);
//创建查询对象
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must(QueryBuilders.matchQuery("subjectId", subjectInfo.getSubjectId()));
if (StringUtils.isNotEmpty(subjectInfo.getSearch())) {
boolQuery.must(QueryBuilders.multiMatchQuery(subjectInfo.getSearch(), "title", "content"));
}
if (StringUtils.isNotEmpty(subjectInfo.getContent())) {
boolQuery.must(QueryBuilders.matchPhraseQuery("content", subjectInfo.getContent()));
}
if (StringUtils.isNotEmpty(subjectInfo.getTitle())) {
boolQuery.must(QueryBuilders.matchPhraseQuery("title", subjectInfo.getTitle()));
}
if (StringUtils.isNotEmpty(subjectInfo.getOrigin())) {
boolQuery.must(QueryBuilders.matchPhraseQuery("origin", subjectInfo.getOrigin()));
}
if (StringUtils.isNotEmpty(subjectInfo.getSourceAddress())) {
boolQuery.must(QueryBuilders.termQuery("sourceAddress", subjectInfo.getSourceAddress()));
}
if (StringUtils.isNotEmpty(subjectInfo.getId())) {
boolQuery.must(QueryBuilders.termQuery("id", subjectInfo.getId()));
}
if (subjectInfo.getCheckStatusList() != null && subjectInfo.getCheckStatusList().size() > 0) {
List<Integer> list = new ArrayList<>();
list = subjectInfo.getCheckStatusList();
if (list.size() == 1 && list.contains(4)) {
//
} else {
boolQuery.must(QueryBuilders.termsQuery("checkStatus", subjectInfo.getCheckStatusList()));
}
}
if (StringUtils.isNotBlank(video)) {
boolQuery.must(QueryBuilders.matchQuery("type", "video"));
} else {
boolQuery.mustNot(QueryBuilders.matchQuery("type", "video"));
}
//只查询主条目
boolQuery.mustNot(QueryBuilders.matchQuery("flag", "0"));
//删除状态查询
if (subjectInfo.getDeleteFlag() != 0) {
boolQuery.must(QueryBuilders.matchQuery("deleteFlag", "1"));
} else {
boolQuery.mustNot(QueryBuilders.matchQuery("deleteFlag", "1"));
}
//专题库类别筛选
if (subjectInfo.getClassificationType() != null) {
boolQuery.must(QueryBuilders.termQuery("classificationType", subjectInfo.getClassificationType()));
}
//正负面
if (subjectInfo.getOrientation() != null) {
boolQuery.must(QueryBuilders.termQuery("orientation", subjectInfo.getOrientation()));
}
//时间过滤筛选
if (StringUtils.isNotBlank(subjectInfo.getStartTime())) {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").gte(EsDateUtil.esFieldDateFormat(subjectInfo.getStartTime())));
}
if (StringUtils.isNotBlank(subjectInfo.getEndTime())) {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").lte(EsDateUtil.esFieldDateFormat(subjectInfo.getEndTime())));
} else {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").lte(EsDateUtil.esFieldDateFormat(DateUtil.dateToString(new Date()))));
}
if (StringUtils.isNotBlank(crawler)) {
boolQuery.must(QueryBuilders.matchQuery("source", crawler));
}
Set<String> relationIds = new HashSet<>();
if (StringUtils.isNotEmpty(labelIds)) {
relationIds.add(labelIds);
}
if (CollectionUtils.isNotEmpty(socialCreditCodeList)) {
relationIds.addAll(socialCreditCodeList);
}
if (CollectionUtils.isNotEmpty(relationIds)) {
BoolQueryBuilder nestedBoolQueryBuilder = QueryBuilders.boolQuery();
for (String relationId : relationIds) {
TermQueryBuilder relationIdQuery = QueryBuilders.termQuery("labels.relationId", relationId);
nestedBoolQueryBuilder.should(QueryBuilders.nestedQuery("labels", relationIdQuery, ScoreMode.None));
}
boolQuery.must(nestedBoolQueryBuilder);
}
if (subjectInfo.getLabelName() != null) {
BoolQueryBuilder nestedBoolQueryBuilder = QueryBuilders.boolQuery();
TermQueryBuilder relationIdQuery = QueryBuilders.termQuery("labels.relationName", subjectInfo.getLabelName());
nestedBoolQueryBuilder.should(QueryBuilders.nestedQuery("labels", relationIdQuery, ScoreMode.None));
boolQuery.must(nestedBoolQueryBuilder);
}
if (StringUtils.isNotBlank(sourceId)) {
boolQuery.must(QueryBuilders.termQuery("sid", sourceId));
}
searchSourceBuilder.query(boolQuery);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
SearchHit[] searchHits = searchResponse.getHits().getHits();
List<DisplayInfo> list = new ArrayList<>();
int i = 0;
for (SearchHit hit : searchHits) {
i++;
String queryInfo = hit.getSourceAsString();
DisplayInfo info = JSONUtil.toBean(queryInfo, DisplayInfo.class);
info.setPublishDate(EsDateUtil.esFieldDateMapping(info.getPublishDate()));
String index = hit.getIndex();
info.setIndex(index);
list.add(info);
}
IPage<DisplayInfo> pageData = new Page<>(offset, pageSize, searchResponse.getHits().getTotalHits().value);
pageData.setRecords(list);
return pageData;
}
}
...@@ -530,11 +530,6 @@ public class EsStatisticsServiceImpl implements EsStatisticsService { ...@@ -530,11 +530,6 @@ public class EsStatisticsServiceImpl implements EsStatisticsService {
*/ */
private SearchSourceBuilder formatSourceBuilder(String subjectId, String relationId, String startTime, String endTime, Integer type) { private SearchSourceBuilder formatSourceBuilder(String subjectId, String relationId, String startTime, String endTime, Integer type) {
SpecialInformationParam param = new SpecialInformationParam(); SpecialInformationParam param = new SpecialInformationParam();
if (StringUtils.isNotEmpty(subjectId)) {
param.setSubjectId(subjectId);
} else {
param.setDataType("yqjc");
}
if (StringUtils.isNotEmpty(relationId)) { if (StringUtils.isNotEmpty(relationId)) {
param.setSearchLabelIds(relationId); param.setSearchLabelIds(relationId);
} }
...@@ -587,4 +582,43 @@ public class EsStatisticsServiceImpl implements EsStatisticsService { ...@@ -587,4 +582,43 @@ public class EsStatisticsServiceImpl implements EsStatisticsService {
return percentage; return percentage;
} }
@Override
public CountVO flowData(String subjectId,String startTime, String endTime, Integer type) {
CountVO countVO = new CountVO();
SearchRequest searchRequest = new SearchRequest(Constants.ES_DATA_FOR_SUBJECT);
SearchSourceBuilder searchSourceBuilder = formatSourceBuilder(subjectId, null, startTime, endTime, null);
searchSourceBuilder.size(0);
searchSourceBuilder.trackTotalHits(true);
DateHistogramAggregationBuilder aggregation = AggregationBuilders.dateHistogram("group_day")
.field("publishDate");
if (type == 1) {
aggregation.calendarInterval(DateHistogramInterval.HOUR).format("yyyy-MM-dd HH");
} else if (type == 2) {
aggregation.calendarInterval(DateHistogramInterval.DAY).format("yyyy-MM-dd");
}
searchSourceBuilder.aggregation(aggregation);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
long value = response.getHits().getTotalHits().value;
countVO.setValue(value);
List<CountVO> list = new ArrayList<>();
Aggregations aggregations = response.getAggregations();
ParsedDateHistogram groupHour = aggregations.get("group_day");
List<? extends Histogram.Bucket> buckets = groupHour.getBuckets();
if (CollectionUtils.isNotEmpty(buckets)) {
for (Histogram.Bucket bucket : buckets) {
CountVO vo = new CountVO();
vo.setName(bucket.getKeyAsString());
vo.setValue(bucket.getDocCount());
list.add(vo);
}
}
countVO.setChildren(list);
} catch (Exception e) {
e.printStackTrace();
}
return countVO;
}
} }
...@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; ...@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzsn.event.constant.Constants; import com.zzsn.event.constant.Constants;
import com.zzsn.event.entity.Event; import com.zzsn.event.entity.Event;
import com.zzsn.event.entity.EventTag;
import com.zzsn.event.entity.LabelEntity;
import com.zzsn.event.enums.CodePrefixEnum; import com.zzsn.event.enums.CodePrefixEnum;
import com.zzsn.event.mapper.EventMapper; import com.zzsn.event.mapper.EventMapper;
import com.zzsn.event.producer.ProduceInfo; import com.zzsn.event.producer.ProduceInfo;
...@@ -59,6 +61,8 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements ...@@ -59,6 +61,8 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements
@Autowired @Autowired
private ProduceInfo produceInfo; private ProduceInfo produceInfo;
@Autowired @Autowired
private IEventTagService eventTagService;
@Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Value("${files.storage}") @Value("${files.storage}")
String filesStorage; String filesStorage;
...@@ -181,6 +185,7 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements ...@@ -181,6 +185,7 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements
cron = CronUtil.getRandomCron(); cron = CronUtil.getRandomCron();
event.setCron(cron); event.setCron(cron);
baseMapper.insert(event); baseMapper.insert(event);
eventTagService.save(EventTag.builder().eventId(event.getId()).build());
return event; return event;
} }
...@@ -246,6 +251,11 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements ...@@ -246,6 +251,11 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements
return null; return null;
} }
@Override
public List<LabelEntity> listByType(String labelTypeId) {
return baseMapper.listByType(labelTypeId);
}
//生成文件夹路径 //生成文件夹路径
private String getFilePath() { private String getFilePath() {
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = LocalDate.now();
......
package com.zzsn.event.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.event.entity.EventTag;
import com.zzsn.event.mapper.EventTagMapper;
import com.zzsn.event.service.IEventTagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @Description: 事件
* @Author: jeecg-boot
* @Date: 2024-03-14
* @Version: V1.0
*/
@Service
@Slf4j
public class EventTagServiceImpl extends ServiceImpl<EventTagMapper, EventTag> implements IEventTagService {
}
package com.zzsn.event.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.event.mapper.InfoSourceMapper;
import com.zzsn.event.service.IInfoSourceService;
import com.zzsn.event.xxljob.entity.InfoSource;
import org.springframework.stereotype.Service;
/**
* @Description: 信息源表
* @Author: jeecg-boot
* @Date: 2022-01-18
* @Version: V1.0
*/
@Service
public class InfoSourceServiceImpl extends ServiceImpl<InfoSourceMapper, InfoSource> implements IInfoSourceService {
@Override
public String getNatureName(String id) {
return baseMapper.getNatureName(id);
}
}
...@@ -60,8 +60,8 @@ public class AnalysisTask { ...@@ -60,8 +60,8 @@ public class AnalysisTask {
* 每天凌晨0点执行一次 * 每天凌晨0点执行一次
* 按天发送kafka 获取进行中(未结束)的事件专题列表 * 按天发送kafka 获取进行中(未结束)的事件专题列表
*/ */
@Scheduled(cron = "0 0 0 * * ?") // @Scheduled(cron = "0 0 0 * * ?")
// @Scheduled(cron = "0 * * * * ?") @Scheduled(cron = "0 * * * * ?")
public void subjectList() { public void subjectList() {
List<SubjectKafkaVo> data = new ArrayList<>(); List<SubjectKafkaVo> data = new ArrayList<>();
Date today = new Date(); Date today = new Date();
......
...@@ -25,6 +25,11 @@ public class DateUtil { ...@@ -25,6 +25,11 @@ public class DateUtil {
return format.format(date); return format.format(date);
} }
public static String dateToString(Date date) {
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.format(date);
}
/** /**
* String转Date * String转Date
* *
......
package com.zzsn.event.util;
import org.apache.commons.lang3.StringUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2023/11/28 16:20
* @Content: 获取索引名称的工具类
*/
public class EsIndexUtil {
/**
* 根据索引名称获取带有当前年的索引名称 subjectdatabase --> subjectdatabase_2023
* @param index
* @return
*/
public static String getIndexYear(String index){
return index + "_" + LocalDateTime.now().getYear();
}
/**
* 获取最近两年的索引名称 subjectdatabase --> subjectdatabase_2023
* 并返回数组
* @param index
* @return
*/
public static String[] getIndexLatelyTwoYear(String index){
String[] indexs;
Integer year = LocalDateTime.now().getYear();
if(year <= 2023){//索引年份是从2023年开始的
indexs = new String[]{index + "_2023"};
} else {
String index_1 = index + "_" + year;
String index_2 = index + "_" + (year-1);
indexs = new String[]{index_1, index_2};
}
return indexs;
}
/**
* 获取两个时间之间的所有年份
* 并返回数组
* @param startYear 搜索范围开始年份
* @param endYear 搜索范围结束年份
* @return
*/
public static String[] getIndexIntervalYear(String index, Integer startYear, Integer endYear){
if(startYear < 2023){
startYear = 2023; //索引年份是从2023年开始的
}
int nowYear = LocalDateTime.now().getYear();
if(endYear > nowYear) {
endYear = nowYear;
}
String[] indexs;
if(endYear <= 2023){//索引年份是从2023年开始的
indexs = new String[]{index + "_2023"};
} else {
List<String> result = new ArrayList<>();
while (startYear <= endYear) {
result.add(index + "_" + startYear);
startYear++;
}
indexs = result.toArray(new String[0]);
}
if(indexs.length == 0) {
indexs = new String[]{index};
}
return indexs;
}
/**
* 获取两个时间之间的所有年份
* 并返回数组
* @param startDate 搜索范围开始年份
* @param endDate 搜索范围结束年份
* @return
*/
public static String[] getIndexIntervalYear(String index, String startDate, String endDate){
Integer startYear;
Integer endYear;
if (StringUtils.isNotBlank(startDate)) {
try {
String s = startDate.substring(0, 4);
startYear = Integer.parseInt(s);
} catch (Exception e1) {
startYear = LocalDateTime.now().getYear()-1;
}
} else {
startYear = LocalDateTime.now().getYear()-1;
}
if (StringUtils.isNotBlank(endDate)) {
try {
String s = endDate.substring(0, 4);
endYear = Integer.parseInt(s);
} catch (Exception e1) {
endYear = LocalDateTime.now().getYear();
}
} else {
endYear = LocalDateTime.now().getYear();
}
String[] indexs = getIndexIntervalYear(index,startYear,endYear);
return indexs;
}
}
...@@ -13,6 +13,10 @@ import java.util.List; ...@@ -13,6 +13,10 @@ import java.util.List;
@Data @Data
public class CountVO { public class CountVO {
//key值
private String key;
//数量/价格
private String count;
/**排序*/ /**排序*/
private Integer order; private Integer order;
/**名称*/ /**名称*/
......
package com.zzsn.event.vo;
import lombok.Data;
import java.util.List;
@Data
public class DisplayInfo {
//说明:...Raw 表示原文,即原语言
//作者
private String author;
private String authorRaw;
//正文
private String content;
private String contentRaw;
//带标签正文
private String contentWithTag;
private String contentWithTagRaw;
//入库时间
private String createDate;
//信息id
private String id;
//信息来源id(信息源或者关键词)
private String sid;
//语言
private String lang;
private String langRaw;
//来源(信息来源)
private String origin;
private String originRaw;
//发布时间
private String publishDate;
//原始时间(网页上,没有解析之前的时间)
private String originalTime;
//发布地址
private String sourceAddress;
//摘要
private String summary;
private String summaryRaw;
//关键词
private String keyWords;
//标题
private String title;
private String titleRaw;
//采集来源(如通用、定制、微信公众号等)
private String source;
//附加字段
private String type;
//标签信息
private List<Label> labels;
//视频下载链接
private String downLoadUrl;
//视频链接(原链接 网页版)
private String videoUrl;
//视频链接(原链接 手机版)
private String videoPhoneUrl;
//视频时长
private Long videoTime;
//视频第一帧图片
private String videoImg;
//自定义标签
private List<String> customLabel;
private Double score;
//专题库类型(0: 其它 1:政策;2:领导讲话;3:专家观点;4:企业案例)
private Integer classificationType;
//置顶排位(默认为0)
private Integer topNum;
//删除标记(1:删除;0:保留)
private Integer deleteFlag;
private String subjectId;
//审核操作(0:未审核 1:审核通过 2:审核未通过 3:暂定 默认值为0)
private Integer checkStatus;
//阅读数
private Long readNum = 0L;
//是否收藏
private boolean ynCollect = false;
//重复id
private String repeatId;
//(1:主条目 0:非主条目)
private String flag;
//关联的主条目id
private String masterEntryId;
//原始id(去重服务生成的id,因为一条信息可以属于多个专题,原始id会发生改变,所以存储一个原始id,找寻对应关系)
private String originalId;
//快照地址
private String screenShotImg;
//资讯更新时间
private String updateDate;
//信息类别(1:报刊 2:博客 3:客户端 4:论坛 5:视频 6:外媒 7:网站 8:微博 9:微信 10:新闻 11:政务 12:其它)
private String infoSourceType;
//数据类型 qbyw:情报要闻 qbnc:情报内参
private String dataType;
//abi报表地址
private String abiUrl;
//abi报表id
private String abiId;
//栏目code列表
private List<String> programaIds;
//数据库code列表
private List<String> databaseIds;
//是否风险
private Integer isRisk;
//风险类型
private List<String> riskTypes;
//资讯关联的附件id
private List<String> attachmentIds;
//是否为资讯(true:资讯 false:附件类)
private Boolean ynArticle = true;
//法规号
private String contentNo;
//来源 (政策发文机关)
private String organ;
//政策文件分类
private String topicClassification;
//发文字号
private String issuedNumber;
//成文时间
private String writtenDate;
//数据所在的索引名称
private String index;
/**
* 是否是主条目,0为非主条目,1为主条目
*/
private Integer ismain;
}
package com.zzsn.event.vo;
import lombok.Data;
/**
* 基础信息打上标签的实体对象
*/
@Data
public class Label {
//命中标识
private String hitRemarks;
//标签标识
private String labelMark;
//标签备注
private String labelRemarks;
//项目标签id
private String projectLabelId;
//关联标签id
private String relationId;
//关联标签名称
private String relationName;
//审核状态
private Integer status;
}
...@@ -23,4 +23,10 @@ public class MediaVO { ...@@ -23,4 +23,10 @@ public class MediaVO {
private Long mediaNum; private Long mediaNum;
//热门媒体 //热门媒体
private List<String> hotList; private List<String> hotList;
//媒体性质
private String key;
//数据量
private Long count;
//序号
private Integer order;
} }
package com.zzsn.event.vo;
import lombok.Data;
/**
* 报告资讯列表数据封装
*
* @author lkg
* @date 2023/3/29
*/
@Data
public class ReportDataVo {
private String title;
private String summary;
private String origin;
private String publishDate;
private String sourceAddress;
}
package com.zzsn.event.vo;
import lombok.Data;
import java.util.List;
@Data
public class SubjectInfoVo {
private String id;
//专题id
private String subjectId;
//文章链接
private String url;
//搜索时,全部情况下,,搜索传值
private String search;
//专题标题
private String title;
//专题摘要
private String summary;
//内容
private String content;
//作者
private String author;
//发布时间
private String publishDate;
//来源
private String origin;
//得分
private String score;
//企业名称
private String enterpriseName;
//倾向性
private String orientation;
//风险类型
private String riskType;
//企业性质
private String enterpriseNature;
//区域
private String area;
//行业
private String trade;
//信息类型
private String InfoType;
//专题库类型
private String libraryType;
//ids
private List<String> ids;
//置顶标识(0取消置顶 1置顶)
private Integer type;
private String sourceAddress;
//开始时间
private String startTime;
//结束时间
private String endTime;
//倾向性(前端交互参数约定 0:中性 1:负面 2:正面)
private Integer tendency;
//专题库类型(1:政策;2:领导讲话;3:专家观点;4:企业案例)
private Integer classificationType;
//审核操作(0:未审核 1:审核通过 2:审核未通过 3:暂定 默认值为0)
private List<Integer> checkStatusList;
private Integer checkStatus;
//删除标记(1:删除;0:保留)
private Integer deleteFlag = 0;
//国家
private String countryIds;
//城市
private String cityIds;
//企业
private String enterpriseIds;
//人物
private String characterIds;
//字段
private String fields;
//操作类型 add .update
private String action;
//日期最大值
private String maxValue;
//关键词检索范围 1标题 2正文 3 全部
private Integer searchScope;
//精确度("精确"| --)
private String searchAccuracy;
//数据所在的索引名称
private String index;
private String operateStartTime;
private String operateEndTime;
private String labelName;
}
package com.zzsn.event.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class SysLabelVo {
/**
* 主键
*/
private String id;
/**
* 名称
*/
private String name;
/**
* 近义词
*/
private String synonym;
/**
* 说明
*/
private String explanation;
/**
* 层级
*/
private Integer level;
/**
* 一级主键id
*/
private String topId;
/**
* 所有id
*/
private String pathIds;
/**
* 状态
*/
private Integer status;
/**
* 排序
*/
private Integer sort;
/**
* 创建人
*/
private String createBy;
/**
* 创建日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private java.util.Date createTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private java.util.Date updateTime;
/**
* 所属部门
*/
private String sysOrgCode;
/**
* 父级节点
*/
private String pid;
/**
* 是否有子节点
*/
private String hasChild;
/**
* 属于哪个标签(表sys_base_label_type的主键id)
*/
private String labelTypeId;
/**
* 标签类别(如企业、自定义等)
*/
private String labelType;
/**
* 标签标识
*/
private String labelMark;
/**
* 下级节点
*/
private List<SysLabelVo> children;
private Boolean isLeaf;
/**
* 具体标签的id集合
*/
private List<String> labelIdList;
private String queryParam;
private String dataType = "";
/**
* 专题字段
*/
private Integer category;
/**
* 词条名称
*/
private String itemText;
/**
* 词条代码
*/
private String itemValue;
/**
* 描述
*/
private String description;
/**
* 排序值
*/
private String sortOrder;
/**
* 字典id
*/
private String dictId;
/**唯一编码(前端回显)*/
private String code;
private Integer pageNo=1;
private Integer pageSize=10;
}
...@@ -55,9 +55,12 @@ spring: ...@@ -55,9 +55,12 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
elasticsearch: elasticsearch:
rest: rest:
uris: ["114.116.90.53:9200"] uris: ["114.115.215.250:9700","114.116.19.92:9700","114.116.54.108:9200"]
#uris: ["192.168.0.149:9700","192.168.0.35:9700","192.168.200.108:9200"]
username: elastic username: elastic
password: elastic password: zzsn9988
connection-timeout: 300000
socket-timeout: 300000
cloud: cloud:
stream: stream:
kafka: kafka:
...@@ -112,9 +115,15 @@ mybatis-plus: ...@@ -112,9 +115,15 @@ mybatis-plus:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true map-underscore-to-camel-case: true
serviceProject: serviceProject:
url: https://clb.ciglobal.cn/clb-api/ # url: https://clb.ciglobal.cn/clb-api/datapull/
url: http://127.0.0.1:9988/datapull/
#热词抽取地址 #热词抽取地址
hotWords: hotWords:
extractUrl: http://114.116.99.6:8055/task/dispose/extractKeyword extractUrl: http://114.116.99.6:8055/task/dispose/extractKeyword
files: files:
storage: D:/event/ storage: D:/event/
\ No newline at end of file scoreRule:
weekScore: 1
monthScore: 2
yearScore: 3
beforeYearScore: 3
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论