Commit 048694ba by shenjunjie

Merge branch 'feature' into 'dev'

Feature

See merge request !12
parents d6139789 57631a16
...@@ -29,6 +29,13 @@ public class GenericAttribute { ...@@ -29,6 +29,13 @@ public class GenericAttribute {
*/ */
public static final String ES_FOLLOWERS_NUM = "followers_num"; public static final String ES_FOLLOWERS_NUM = "followers_num";
/** /**
* es media_type
*/
public static final String ES_MEDIA_TYPE = "media_type";
// ss platform_id
// TODO 待修改为 platform_id
public static final String ES_PLATFORM_ID= "platformId";
/**
* es rootSource * es rootSource
**/ **/
public static final String ES_ROOT_SOURCE = "root_source"; public static final String ES_ROOT_SOURCE = "root_source";
......
...@@ -25,6 +25,7 @@ public class RedisKeyPrefix { ...@@ -25,6 +25,7 @@ public class RedisKeyPrefix {
public static final String MARK_HIGH_WORD = "BRANDKBS:MARK:HIGH_WORD:"; public static final String MARK_HIGH_WORD = "BRANDKBS:MARK:HIGH_WORD:";
public static final String REDIS_SYSTEM_COPY = "BRANDKBS:SYSTEM:COPY:"; public static final String REDIS_SYSTEM_COPY = "BRANDKBS:SYSTEM:COPY:";
public static final String AGGREE_RESULT_CACHE = "BRANDKBS:AGGREE_CACHE:";
/** /**
* 项目简报报相关缓存KEY * 项目简报报相关缓存KEY
......
...@@ -10,6 +10,8 @@ import org.apache.commons.lang3.time.FastDateFormat; ...@@ -10,6 +10,8 @@ import org.apache.commons.lang3.time.FastDateFormat;
*/ */
public class Constant { public class Constant {
public static final Long ONE_DAY = 24 * 60 * 60 * 1000L;
public static final String HOUR_PATTERN = "yyyy-MM-dd HH"; public static final String HOUR_PATTERN = "yyyy-MM-dd HH";
public static final String DAY_PATTERN = "yyyy-MM-dd"; public static final String DAY_PATTERN = "yyyy-MM-dd";
......
...@@ -47,7 +47,7 @@ import java.util.Set; ...@@ -47,7 +47,7 @@ import java.util.Set;
public class EventController extends BaseController { public class EventController extends BaseController {
@Resource(name = "eventServiceImpl") @Resource(name = "eventServiceImpl")
private EventService EventService; private EventService eventService;
@Resource(name = "behaviorServiceImpl") @Resource(name = "behaviorServiceImpl")
private BehaviorService behaviorService; private BehaviorService behaviorService;
...@@ -64,13 +64,13 @@ public class EventController extends BaseController { ...@@ -64,13 +64,13 @@ public class EventController extends BaseController {
@ApiImplicitParam(name = "linkedGroupId", value = "关联项目组id", paramType = "query", dataType = "string") @ApiImplicitParam(name = "linkedGroupId", value = "关联项目组id", paramType = "query", dataType = "string")
@GetMapping("/yq/tag") @GetMapping("/yq/tag")
public ResponseResult searchCriteria(@RequestParam(value = "linkedGroupId") String linkedGroupId) { public ResponseResult searchCriteria(@RequestParam(value = "linkedGroupId") String linkedGroupId) {
return ResponseResult.success(EventService.findEventTagListAll(linkedGroupId)); return ResponseResult.success(eventService.findEventTagListAll(linkedGroupId));
} }
@ApiOperation("分页查询舆情事件列表") @ApiOperation("分页查询舆情事件列表")
@PostMapping("/yq/list") @PostMapping("/yq/list")
public ResponseResult findYqEventList(@RequestBody YqEventSearchVO yqEventSearchVO) { public ResponseResult findYqEventList(@RequestBody YqEventSearchVO yqEventSearchVO) {
PageVO<JSONObject> yqEventList = EventService.findYqEventList(yqEventSearchVO); PageVO<JSONObject> yqEventList = eventService.findYqEventList(yqEventSearchVO);
return ResponseResult.success(yqEventList); return ResponseResult.success(yqEventList);
} }
...@@ -87,27 +87,27 @@ public class EventController extends BaseController { ...@@ -87,27 +87,27 @@ public class EventController extends BaseController {
@RequestParam(value = "linkedGroupId") String linkedGroupId, @RequestParam(value = "linkedGroupId") String linkedGroupId,
@RequestParam(value = "keyword", defaultValue = "") String keyword, @RequestParam(value = "keyword", defaultValue = "") String keyword,
@RequestParam(value = "sorter", defaultValue = "{\"startTime\":\"descend\"}") String sorter) { @RequestParam(value = "sorter", defaultValue = "{\"startTime\":\"descend\"}") String sorter) {
return ResponseResult.success(EventService.findEventList(page, size, linkedGroupId, keyword, sorter)); return ResponseResult.success(eventService.findEventList(page, size, linkedGroupId, keyword, sorter));
} }
@ApiOperation("获取单个事件信息") @ApiOperation("获取单个事件信息")
@ApiImplicitParam(name = "eventId", value = "事件ID", required = true, paramType = "path", dataType = "string") @ApiImplicitParam(name = "eventId", value = "事件ID", required = true, paramType = "path", dataType = "string")
@GetMapping("/get/{eventId}") @GetMapping("/get/{eventId}")
public ResponseResult getEvent(@PathVariable("eventId") String eventId) { public ResponseResult getEvent(@PathVariable("eventId") String eventId) {
return ResponseResult.success(EventService.getEventJSONByEventId(eventId)); return ResponseResult.success(eventService.getEventJSONByEventId(eventId));
} }
@ApiOperation("获取事件数据列表") @ApiOperation("获取事件数据列表")
@ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码", required = false, defaultValue = "1", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "size", value = "每页记录数", required = false, defaultValue = "10", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "eventId", value = "事件ID", required = true, paramType = "query", dataType = "string")}) @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码", required = false, defaultValue = "1", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "size", value = "每页记录数", required = false, defaultValue = "10", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "eventId", value = "事件ID", required = true, paramType = "query", dataType = "string")})
@GetMapping("/data/get") @GetMapping("/data/get")
public ResponseResult getEventDatas(@RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "size", defaultValue = "10") int size, @RequestParam(value = "eventId") String eventId) { public ResponseResult getEventDatas(@RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "size", defaultValue = "10") int size, @RequestParam(value = "eventId") String eventId) {
return ResponseResult.success(EventService.getEventDatas(page, size, eventId)); return ResponseResult.success(eventService.getEventDatas(page, size, eventId));
} }
@ApiOperation("修改事件信息") @ApiOperation("修改事件信息")
@PutMapping("/update") @PutMapping("/update")
public ResponseResult updateEvent(@RequestBody EventVO eventVO) { public ResponseResult updateEvent(@RequestBody EventVO eventVO) {
EventService.updateEvent(eventVO); eventService.updateEvent(eventVO);
behaviorService.pushBehavior(OPERATION, "修改事件信息:" + eventVO.getId(), request); behaviorService.pushBehavior(OPERATION, "修改事件信息:" + eventVO.getId(), request);
return ResponseResult.success(); return ResponseResult.success();
} }
...@@ -115,7 +115,7 @@ public class EventController extends BaseController { ...@@ -115,7 +115,7 @@ public class EventController extends BaseController {
@ApiOperation("修改事件首发信息") @ApiOperation("修改事件首发信息")
@PutMapping("/updateFirst") @PutMapping("/updateFirst")
public ResponseResult updateEventFirst(@RequestBody EventDataDTO eventDataDTO) { public ResponseResult updateEventFirst(@RequestBody EventDataDTO eventDataDTO) {
EventService.updateEventFirst(eventDataDTO); eventService.updateEventFirst(eventDataDTO);
behaviorService.pushBehavior(OPERATION, "修改事件首发信息:" + eventDataDTO.getEventId(), request); behaviorService.pushBehavior(OPERATION, "修改事件首发信息:" + eventDataDTO.getEventId(), request);
return ResponseResult.success(); return ResponseResult.success();
} }
...@@ -124,7 +124,7 @@ public class EventController extends BaseController { ...@@ -124,7 +124,7 @@ public class EventController extends BaseController {
@ApiImplicitParam(name = "eventIds", value = "事件ID集合", paramType = "body", dataType = "list") @ApiImplicitParam(name = "eventIds", value = "事件ID集合", paramType = "body", dataType = "list")
@PostMapping("/analyze") @PostMapping("/analyze")
public ResponseResult analysisEvents(@RequestBody JSONObject info) { public ResponseResult analysisEvents(@RequestBody JSONObject info) {
EventService.analysisEvents(info.getJSONArray("eventIds").toJavaList(String.class)); eventService.analysisEvents(info.getJSONArray("eventIds").toJavaList(String.class));
behaviorService.pushBehavior(OPERATION, "批量更新事件", request); behaviorService.pushBehavior(OPERATION, "批量更新事件", request);
return ResponseResult.success(); return ResponseResult.success();
} }
...@@ -133,7 +133,7 @@ public class EventController extends BaseController { ...@@ -133,7 +133,7 @@ public class EventController extends BaseController {
@ApiImplicitParam(name = "eventId", value = "事件ID", required = true, paramType = "path", dataType = "string") @ApiImplicitParam(name = "eventId", value = "事件ID", required = true, paramType = "path", dataType = "string")
@PutMapping("/end/{eventId}") @PutMapping("/end/{eventId}")
public ResponseResult endEvent(@PathVariable("eventId") String eventId) { public ResponseResult endEvent(@PathVariable("eventId") String eventId) {
EventService.endEvent(eventId); eventService.endEvent(eventId);
behaviorService.pushBehavior(OPERATION, "结束事件:" + eventId, request); behaviorService.pushBehavior(OPERATION, "结束事件:" + eventId, request);
return ResponseResult.success(); return ResponseResult.success();
} }
...@@ -142,7 +142,7 @@ public class EventController extends BaseController { ...@@ -142,7 +142,7 @@ public class EventController extends BaseController {
@ApiImplicitParam(name = "eventId", value = "事件ID", required = true, paramType = "path", dataType = "string") @ApiImplicitParam(name = "eventId", value = "事件ID", required = true, paramType = "path", dataType = "string")
@DeleteMapping("/delete/{eventId}") @DeleteMapping("/delete/{eventId}")
public ResponseResult deleteEvent(@PathVariable("eventId") String eventId) { public ResponseResult deleteEvent(@PathVariable("eventId") String eventId) {
String title = EventService.deleteEvent(eventId); String title = eventService.deleteEvent(eventId);
behaviorService.pushBehavior(OPERATION, "删除事件:" + title, request); behaviorService.pushBehavior(OPERATION, "删除事件:" + title, request);
return ResponseResult.success(); return ResponseResult.success();
} }
...@@ -153,7 +153,7 @@ public class EventController extends BaseController { ...@@ -153,7 +153,7 @@ public class EventController extends BaseController {
public ResponseResult deleteEventData(@RequestBody JSONObject info) { public ResponseResult deleteEventData(@RequestBody JSONObject info) {
String id = info.getString("id"); String id = info.getString("id");
String eventId = info.getString("eventId"); String eventId = info.getString("eventId");
String title = EventService.deleteEventData(id, eventId); String title = eventService.deleteEventData(id, eventId);
behaviorService.pushBehavior(OPERATION, "删除事件单条数据,eventId:" + eventId + ",数据id:" + id + ",事件标题:" + title, request); behaviorService.pushBehavior(OPERATION, "删除事件单条数据,eventId:" + eventId + ",数据id:" + id + ",事件标题:" + title, request);
return ResponseResult.success(); return ResponseResult.success();
} }
...@@ -172,14 +172,14 @@ public class EventController extends BaseController { ...@@ -172,14 +172,14 @@ public class EventController extends BaseController {
@ApiOperation("事件上传进度获取") @ApiOperation("事件上传进度获取")
@GetMapping("data/upload/progress/{ticket}") @GetMapping("data/upload/progress/{ticket}")
public ResponseResult getEventDataUploadProgress(@PathVariable String ticket) { public ResponseResult getEventDataUploadProgress(@PathVariable String ticket) {
return ResponseResult.success(EventService.getEventDataUploadProgress(ticket)); return ResponseResult.success(eventService.getEventDataUploadProgress(ticket));
} }
@ApiOperation("事件数据上传进度获取") @ApiOperation("事件数据上传进度获取")
@ApiImplicitParams(@ApiImplicitParam(name = "eventIds", value = "事件id列表", paramType = "body", dataType = "list")) @ApiImplicitParams(@ApiImplicitParam(name = "eventIds", value = "事件id列表", paramType = "body", dataType = "list"))
@PostMapping("analyze/progress") @PostMapping("analyze/progress")
public ResponseResult getEventAnalyzeProgress(@RequestBody JSONObject info) { public ResponseResult getEventAnalyzeProgress(@RequestBody JSONObject info) {
return ResponseResult.success(EventService.getEventAnalyzeProgress(info.getJSONArray("eventIds").toJavaList(String.class))); return ResponseResult.success(eventService.getEventAnalyzeProgress(info.getJSONArray("eventIds").toJavaList(String.class)));
} }
@ApiOperation("事件上传模板下载") @ApiOperation("事件上传模板下载")
...@@ -202,7 +202,7 @@ public class EventController extends BaseController { ...@@ -202,7 +202,7 @@ public class EventController extends BaseController {
@ApiImplicitParam(name = "linkedGroupId", value = "关联项目组id", required = true, paramType = "query", dataType = "string") @ApiImplicitParam(name = "linkedGroupId", value = "关联项目组id", required = true, paramType = "query", dataType = "string")
@GetMapping("/download") @GetMapping("/download")
public ResponseResult downloadEvents(@RequestParam("linkedGroupId") String linkedGroupId) { public ResponseResult downloadEvents(@RequestParam("linkedGroupId") String linkedGroupId) {
Pair<String, List<ExportEventDTO>> result = EventService.downloadEvents(linkedGroupId); Pair<String, List<ExportEventDTO>> result = eventService.downloadEvents(linkedGroupId);
String fileName = result.getLeft(); String fileName = result.getLeft();
EasyExcelUtil.download(fileName + "_事件列表数据", fileName, ExportEventDTO.class, result.getRight(), response); EasyExcelUtil.download(fileName + "_事件列表数据", fileName, ExportEventDTO.class, result.getRight(), response);
return ResponseResult.success(); return ResponseResult.success();
...@@ -212,7 +212,7 @@ public class EventController extends BaseController { ...@@ -212,7 +212,7 @@ public class EventController extends BaseController {
@ApiImplicitParam(name = "eventId", value = "事件ID", required = true, paramType = "query", dataType = "string") @ApiImplicitParam(name = "eventId", value = "事件ID", required = true, paramType = "query", dataType = "string")
@GetMapping("/data/download") @GetMapping("/data/download")
public ResponseResult downloadEventDatas(@RequestParam("eventId") String eventId) { public ResponseResult downloadEventDatas(@RequestParam("eventId") String eventId) {
Pair<String, List<ExportEventDataDTO>> result = EventService.downloadEventDatas(eventId); Pair<String, List<ExportEventDataDTO>> result = eventService.downloadEventDatas(eventId);
String title = result.getLeft(); String title = result.getLeft();
EasyExcelUtil.download(title, title, ExportEventDataDTO.class, result.getRight(), response); EasyExcelUtil.download(title, title, ExportEventDataDTO.class, result.getRight(), response);
return ResponseResult.success(); return ResponseResult.success();
...@@ -224,7 +224,7 @@ public class EventController extends BaseController { ...@@ -224,7 +224,7 @@ public class EventController extends BaseController {
public ResponseResult addEventsByYq(@RequestBody JSONObject info) { public ResponseResult addEventsByYq(@RequestBody JSONObject info) {
String linkedGroupId = info.getString("linkedGroupId"); String linkedGroupId = info.getString("linkedGroupId");
List<YqEventDTO> yqEventList = info.getJSONArray("list").toJavaList(YqEventDTO.class); List<YqEventDTO> yqEventList = info.getJSONArray("list").toJavaList(YqEventDTO.class);
EventService.addYqEvents(linkedGroupId, yqEventList); eventService.addYqEvents(linkedGroupId, yqEventList);
behaviorService.pushBehavior(OPERATION, "批量导入舆情事件数据", request); behaviorService.pushBehavior(OPERATION, "批量导入舆情事件数据", request);
return ResponseResult.success(); return ResponseResult.success();
} }
...@@ -232,7 +232,7 @@ public class EventController extends BaseController { ...@@ -232,7 +232,7 @@ public class EventController extends BaseController {
@ApiOperation("按搜索条件全部导入舆情事件数据") @ApiOperation("按搜索条件全部导入舆情事件数据")
@PutMapping("/upload/yqAll") @PutMapping("/upload/yqAll")
public ResponseResult addEventAllByYq(@RequestBody YqEventSearchVO yqEventSearchVO) { public ResponseResult addEventAllByYq(@RequestBody YqEventSearchVO yqEventSearchVO) {
EventService.addYqEventAll(yqEventSearchVO); eventService.addYqEventAll(yqEventSearchVO);
behaviorService.pushBehavior(OPERATION, "全部导入舆情事件数据", request); behaviorService.pushBehavior(OPERATION, "全部导入舆情事件数据", request);
return ResponseResult.success(); return ResponseResult.success();
} }
...@@ -242,7 +242,7 @@ public class EventController extends BaseController { ...@@ -242,7 +242,7 @@ public class EventController extends BaseController {
@PostMapping(value = "/upload/file", headers = "content-type=multipart/form-data") @PostMapping(value = "/upload/file", headers = "content-type=multipart/form-data")
@Auth(role = RoleEnum.SUPER_ADMIN) @Auth(role = RoleEnum.SUPER_ADMIN)
public ResponseResult addEventsByFile(@RequestParam(value = "linkedGroupId") String linkedGroupId, @RequestParam("fileUrl") String fileUrl) { public ResponseResult addEventsByFile(@RequestParam(value = "linkedGroupId") String linkedGroupId, @RequestParam("fileUrl") String fileUrl) {
EventService.addFileEvents(linkedGroupId, fileUrl); eventService.addFileEvents(linkedGroupId, fileUrl);
behaviorService.pushBehavior(OPERATION, "文件上传事件", request); behaviorService.pushBehavior(OPERATION, "文件上传事件", request);
return ResponseResult.success(); return ResponseResult.success();
} }
...@@ -252,7 +252,7 @@ public class EventController extends BaseController { ...@@ -252,7 +252,7 @@ public class EventController extends BaseController {
"linkedGroupId", value = "关联项目id", paramType = "form", dataType = "string")}) "linkedGroupId", value = "关联项目id", paramType = "form", dataType = "string")})
@PostMapping(value = "/data/upload", headers = "content-type=multipart/form-data") @PostMapping(value = "/data/upload", headers = "content-type=multipart/form-data")
public ResponseResult uploadEventDatas(@RequestParam("linkedGroupId") String linkedGroupId, @RequestParam("file") MultipartFile file) { public ResponseResult uploadEventDatas(@RequestParam("linkedGroupId") String linkedGroupId, @RequestParam("file") MultipartFile file) {
EventService.uploadEventDatas(linkedGroupId, file); eventService.uploadEventDatas(linkedGroupId, file);
behaviorService.pushBehavior(OPERATION, "事件数据上传", request); behaviorService.pushBehavior(OPERATION, "事件数据上传", request);
return ResponseResult.success(); return ResponseResult.success();
} }
...@@ -261,13 +261,13 @@ public class EventController extends BaseController { ...@@ -261,13 +261,13 @@ public class EventController extends BaseController {
@ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码", required = false, defaultValue = "1", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "size", value = "每页记录数", required = false, defaultValue = "10", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "linkedGroupId", value = "关联性项目组id", required = true, paramType = "query", dataType = "string"), @ApiImplicitParam(name = "tagGroupName", value = "标签组名", required = true, paramType = "query", dataType = "string")}) @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码", required = false, defaultValue = "1", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "size", value = "每页记录数", required = false, defaultValue = "10", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "linkedGroupId", value = "关联性项目组id", required = true, paramType = "query", dataType = "string"), @ApiImplicitParam(name = "tagGroupName", value = "标签组名", required = true, paramType = "query", dataType = "string")})
@GetMapping("/tag/list") @GetMapping("/tag/list")
public ResponseResult findEventTagList(@RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "size", defaultValue = "10") int size, @RequestParam(value = "linkedGroupId") String linkedGroupId, @RequestParam(value = "tagGroupName") String tagGroupName) { public ResponseResult findEventTagList(@RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "size", defaultValue = "10") int size, @RequestParam(value = "linkedGroupId") String linkedGroupId, @RequestParam(value = "tagGroupName") String tagGroupName) {
return ResponseResult.success(EventService.findEventTagList(page, size, linkedGroupId, tagGroupName)); return ResponseResult.success(eventService.findEventTagList(page, size, linkedGroupId, tagGroupName));
} }
@ApiOperation("查询所有事件标签组名") @ApiOperation("查询所有事件标签组名")
@GetMapping("/tag/groupName") @GetMapping("/tag/groupName")
public ResponseResult findEventTagGroupName(@RequestParam(value = "linkedGroupId") String linkedGroupId) { public ResponseResult findEventTagGroupName(@RequestParam(value = "linkedGroupId") String linkedGroupId) {
return ResponseResult.success(EventService.findEventTagGroupName(linkedGroupId)); return ResponseResult.success(eventService.findEventTagGroupName(linkedGroupId));
} }
} }
...@@ -2,8 +2,10 @@ package com.zhiwei.brandkbs2.controller.app; ...@@ -2,8 +2,10 @@ package com.zhiwei.brandkbs2.controller.app;
import com.zhiwei.brandkbs2.auth.Auth; import com.zhiwei.brandkbs2.auth.Auth;
import com.zhiwei.brandkbs2.controller.BaseController; import com.zhiwei.brandkbs2.controller.BaseController;
import com.zhiwei.brandkbs2.easyexcel.EasyExcelUtil;
import com.zhiwei.brandkbs2.enmus.RoleEnum; import com.zhiwei.brandkbs2.enmus.RoleEnum;
import com.zhiwei.brandkbs2.model.ResponseResult; import com.zhiwei.brandkbs2.model.ResponseResult;
import com.zhiwei.brandkbs2.pojo.dto.ExportAppYuqingDTO;
import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO; import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO;
import com.zhiwei.brandkbs2.pojo.dto.ReportDTO; import com.zhiwei.brandkbs2.pojo.dto.ReportDTO;
import com.zhiwei.brandkbs2.pojo.dto.ReportSearchDTO; import com.zhiwei.brandkbs2.pojo.dto.ReportSearchDTO;
...@@ -14,9 +16,11 @@ import io.swagger.annotations.Api; ...@@ -14,9 +16,11 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
/** /**
* @author sjj * @author sjj
...@@ -46,17 +50,37 @@ public class AppArticleController extends BaseController { ...@@ -46,17 +50,37 @@ public class AppArticleController extends BaseController {
} }
@ApiOperation("舆情列表-生成聚合") @ApiOperation("舆情列表-生成聚合")
@PostMapping("/mark/agree") @PostMapping("/mark/aggree")
public ResponseResult generateYuqingMarkAggreeList(@RequestBody MarkSearchDTO markSearchDTO) { public ResponseResult generateYuqingMarkAggreeList(@RequestBody MarkSearchDTO markSearchDTO) {
return ResponseResult.success(markDataService.generateYuqingMarkAggreeList(markSearchDTO)); return ResponseResult.success(markDataService.generateYuqingMarkAggreeList(markSearchDTO));
} }
@ApiOperation("舆情列表-聚合进度查询")
@GetMapping("/mark/aggree/progress/{aggreeId}")
public ResponseResult getYuqingMarkAggreeProgress(@PathVariable String aggreeId) {
return ResponseResult.success(markDataService.getYuqingMarkAggreeProgress(aggreeId));
}
@ApiOperation("舆情列表-获取聚合结果")
@PostMapping("/mark/aggree/list")
public ResponseResult getYuqingMarkAggreeList(@RequestBody MarkSearchDTO markSearchDTO) {
return ResponseResult.success(markDataService.getYuqingMarkAggreeList(markSearchDTO));
}
@ApiOperation("舆情列表-搜索条件") @ApiOperation("舆情列表-搜索条件")
@GetMapping("/mark/list/criteria") @GetMapping("/mark/list/criteria")
public ResponseResult getYuqingMark(@RequestParam(required = false) String linkedGroupId) { public ResponseResult getYuqingMark(@RequestParam(required = false) String linkedGroupId) {
return ResponseResult.success(markDataService.getYuqingMarkCriteria(linkedGroupId)); return ResponseResult.success(markDataService.getYuqingMarkCriteria(linkedGroupId));
} }
@ApiOperation("舆情导出")
@PostMapping(value = "mark/list/export")
public ResponseResult exportYuqingMarkList(@RequestBody MarkSearchDTO markSearchDTO) {
Pair<String, List<ExportAppYuqingDTO>> stringListPair = markDataService.downloadYuqingMarkList(markSearchDTO);
EasyExcelUtil.download(stringListPair.getLeft() + "_舆情列表数据", "sheet1", ExportAppYuqingDTO.class, stringListPair.getRight(), response);
return ResponseResult.success();
}
@ApiOperation("舆情分析-舆情概览") @ApiOperation("舆情分析-舆情概览")
@ApiImplicitParams({@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "long"), @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "long")}) @ApiImplicitParams({@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "long"), @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "long")})
@GetMapping("/analyze/summary") @GetMapping("/analyze/summary")
......
...@@ -19,7 +19,7 @@ import javax.annotation.Resource; ...@@ -19,7 +19,7 @@ import javax.annotation.Resource;
*/ */
@RestController @RestController
@RequestMapping("/app/global") @RequestMapping("/app/global")
@Api(tags = "全局通用接口") @Api(tags = "全局通用接口", description = "提供全局通用相关")
@Auth(role = RoleEnum.CUSTOMER) @Auth(role = RoleEnum.CUSTOMER)
public class GlobalController extends BaseController { public class GlobalController extends BaseController {
......
package com.zhiwei.brandkbs2.dao;
import com.zhiwei.brandkbs2.pojo.AggreeResult;
/**
* @ClassName: AggreeResultDao
* @Description AggreeResultDao
* @author: sjj
* @date: 2022-07-18 09:47
*/
public interface AggreeResultDao extends BaseMongoDao<AggreeResult>{
long deleteExpire(long expireTime);
}
package com.zhiwei.brandkbs2.dao.impl;
import com.mongodb.client.result.DeleteResult;
import com.zhiwei.brandkbs2.dao.AggreeResultDao;
import com.zhiwei.brandkbs2.pojo.AggreeResult;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
/**
* @ClassName: AggreeResultDaoImpl
* @Description AggreeResultDaoImpl
* @author: sjj
* @date: 2022-07-18 09:50
*/
@Service("aggreeResultDaoImpl")
public class AggreeResultDaoImpl extends BaseMongoDaoImpl<AggreeResult> implements AggreeResultDao {
private static final String COLLECTION_PREFIX = "brandkbs_aggree_result";
public AggreeResultDaoImpl() {
super(COLLECTION_PREFIX);
}
@Override
public long deleteExpire(long expireTime) {
Query query = Query.query(Criteria.where("cTime").lt(expireTime));
DeleteResult remove = mongoTemplate.remove(query, COLLECTION_PREFIX);
return remove.getDeletedCount();
}
}
...@@ -6,8 +6,6 @@ import lombok.Setter; ...@@ -6,8 +6,6 @@ import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Date;
/** /**
* @ClassName: UserProjectOldImpl * @ClassName: UserProjectOldImpl
* @Description 用户项目关联旧表 * @Description 用户项目关联旧表
...@@ -28,7 +26,7 @@ public class UserProjectOldDaoImpl extends BaseMongoDaoImpl<UserProjectOldDaoImp ...@@ -28,7 +26,7 @@ public class UserProjectOldDaoImpl extends BaseMongoDaoImpl<UserProjectOldDaoImp
public static class UserProjectOld extends AbstractBaseMongo{ public static class UserProjectOld extends AbstractBaseMongo{
String userId; String userId;
Integer roleId; Integer roleId;
Date expiredTime; Long expiredTime;
Integer exportAmount; Integer exportAmount;
String projectName; String projectName;
} }
......
...@@ -25,12 +25,12 @@ public class EventFileListener extends AnalysisEventListener<UploadEventDTO> { ...@@ -25,12 +25,12 @@ public class EventFileListener extends AnalysisEventListener<UploadEventDTO> {
* 储存解析数据集合 * 储存解析数据集合
*/ */
private final List<UploadEventDTO> datas = new ArrayList<>(BATCH_COUNT); private final List<UploadEventDTO> datas = new ArrayList<>(BATCH_COUNT);
private final EventService EventService; private final EventService eventService;
private final String projectId; private final String projectId;
private final String linkedGroupId; private final String linkedGroupId;
public EventFileListener(EventService EventService, String projectId, String linkedGroupId) { public EventFileListener(EventService eventService, String projectId, String linkedGroupId) {
this.EventService = EventService; this.eventService = eventService;
this.projectId = projectId; this.projectId = projectId;
this.linkedGroupId = linkedGroupId; this.linkedGroupId = linkedGroupId;
} }
...@@ -65,6 +65,6 @@ public class EventFileListener extends AnalysisEventListener<UploadEventDTO> { ...@@ -65,6 +65,6 @@ public class EventFileListener extends AnalysisEventListener<UploadEventDTO> {
* 保存更新事件信息逻辑 * 保存更新事件信息逻辑
*/ */
private void addFileEvent() { private void addFileEvent() {
datas.forEach(eventDTO -> EventService.addFileEvent(projectId, linkedGroupId, eventDTO)); datas.forEach(eventDTO -> eventService.addFileEvent(projectId, linkedGroupId, eventDTO));
} }
} }
package com.zhiwei.brandkbs2.pojo;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.util.Tools;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @ClassName: AggreeResult
* @Description 聚合实体
* @author: sjj
* @date: 2022-07-18 09:41
*/
@Setter
@Getter
public class AggreeResult extends AbstractBaseMongo {
/**
* 任务id
*/
private String taskId;
/**
* 创建时间
*/
private Long cTime;
/**
* 原数据
*/
private JSONObject data;
/**
* 聚合标题
*/
private String aggreeTitle;
/**
* 发文时间
*/
private Long time;
/**
* 平台id
*/
private String platformId;
/**
* 重要发声方
*/
private List<String> mediaTypes;
/**
* 情感倾向(舆情调性)
*/
private List<String> tags;
/**
* 聚合量
*/
private Integer aggreeSize;
/**
* 父聚合id
*/
private String fatherId;
/**
* 是否是父聚合
*/
private boolean isFather;
public static AggreeResult createFather(JSONObject json, String taskId, Integer aggreeSize) {
AggreeResult aggreeResult = getInstance(json, taskId);
aggreeResult.setFather(true);
aggreeResult.setAggreeSize(aggreeSize);
aggreeResult.setCTime(System.currentTimeMillis());
return aggreeResult;
}
public static AggreeResult createSon(JSONObject json, String taskId, String fatherId, String fatherTitle) {
AggreeResult aggreeResult = getInstance(json, taskId);
aggreeResult.setFatherId(fatherId);
// 使用父聚合标题
aggreeResult.setAggreeTitle(fatherTitle);
aggreeResult.setCTime(System.currentTimeMillis());
return aggreeResult;
}
private static AggreeResult getInstance(JSONObject json, String taskId) {
AggreeResult aggreeResult = new AggreeResult();
aggreeResult.setTaskId(taskId);
aggreeResult.setData(json);
BaseMap baseMap = Tools.getBaseFromEsMap(json);
aggreeResult.setTime(baseMap.getTime());
aggreeResult.setPlatformId(json.getString(GenericAttribute.ES_PLATFORM_ID));
String mediaType = json.getString(GenericAttribute.ES_MEDIA_TYPE);
if (StringUtils.isNotEmpty(mediaType)) {
aggreeResult.setMediaTypes(Arrays.asList(mediaType.split(",")));
}
aggreeResult.setTags(parseMatg(json.getString(GenericAttribute.ES_MTAG)));
aggreeResult.setAggreeTitle(baseMap.getTitleNullOptionalContent());
return aggreeResult;
}
private static List<String> parseMatg(String mtag) {
if (StringUtils.isEmpty(mtag)) {
return null;
}
List<String> resList = new ArrayList<>();
String[] uniques = mtag.substring(1).split(",");
for (String unique : uniques) {
resList.add("," + unique);
}
return resList;
}
}
package com.zhiwei.brandkbs2.pojo; package com.zhiwei.brandkbs2.pojo;
import com.zhiwei.base.category.ClassD;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -14,6 +15,11 @@ import lombok.Setter; ...@@ -14,6 +15,11 @@ import lombok.Setter;
public class BaseMap { public class BaseMap {
/** /**
* typeB
*/
private ClassD.TypeB typeB;
/**
* url * url
*/ */
private String url; private String url;
......
...@@ -34,11 +34,6 @@ public class Channel extends ChannelIndex { ...@@ -34,11 +34,6 @@ public class Channel extends ChannelIndex {
private String imgUrl; private String imgUrl;
/** /**
* 渠道标签
*/
private String tag;
/**
* 发布稿件id列表 * 发布稿件id列表
*/ */
private LinkedHashSet<String> articleIds; private LinkedHashSet<String> articleIds;
...@@ -99,10 +94,11 @@ public class Channel extends ChannelIndex { ...@@ -99,10 +94,11 @@ public class Channel extends ChannelIndex {
channel.setPlatform(channelIndex.getPlatform()); channel.setPlatform(channelIndex.getPlatform());
channel.setRealSource(channelIndex.getRealSource()); channel.setRealSource(channelIndex.getRealSource());
channel.setSource(channelIndex.getSource()); channel.setSource(channelIndex.getSource());
channel.setLastTime(channelRecord.getLastTime());
channel.setArticleIds(channelRecord.getArticleIds());
// fid 用来便捷搜索 // fid 用来便捷搜索
channel.setFid(channelIndex.getFid()); channel.setFid(channelIndex.getFid());
channel.setLastTime(channelRecord.getLastTime());
channel.setArticleIds(channelRecord.getArticleIds());
// TODO 调性随机分配 // TODO 调性随机分配
double random = Math.random(); double random = Math.random();
if (random < 0.3) { if (random < 0.3) {
......
...@@ -15,6 +15,7 @@ import lombok.Setter; ...@@ -15,6 +15,7 @@ import lombok.Setter;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -28,7 +29,7 @@ import java.util.Objects; ...@@ -28,7 +29,7 @@ import java.util.Objects;
@Getter @Getter
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
public class MarkFlowEntity { public class MarkFlowEntity implements Serializable {
/** /**
* 消息类型 * 消息类型
...@@ -47,16 +48,29 @@ public class MarkFlowEntity { ...@@ -47,16 +48,29 @@ public class MarkFlowEntity {
public static MarkFlowEntity getFoldInstance(List<MarkFlowEntity> entities) { public static MarkFlowEntity getFoldInstance(List<MarkFlowEntity> entities) {
// 首条数据为主 // 首条数据为主
MarkFlowEntity entity = entities.get(0); MarkFlowEntity entity = Tools.copyByJson(entities.get(0), MarkFlowEntity.class);
if (entities.size() > 1) { if (entities.size() > 1) {
entity.getType().put("fold", true); entity.getType().put("fold", true);
entity.getType().put("size", entities.size()); entity.getType().put("size", entities.size());
// info内容 // info内容
if (null == entity.getInfo()) {
entity.setInfo(new JSONObject());
}
entity.getInfo().put("foldInfo", entities); entity.getInfo().put("foldInfo", entities);
} }
return entity; return entity;
} }
public static MarkFlowEntity getAggreeInstance(List<MarkFlowEntity> entities,int size) {
// 首条数据为主
MarkFlowEntity entity = Tools.copyByJson(entities.get(0), MarkFlowEntity.class);
if (size > 1) {
entity.getType().put("fold", true);
entity.getType().put("size",size);
}
return entity;
}
/** /**
* Constructor * Constructor
* *
......
...@@ -3,6 +3,7 @@ package com.zhiwei.brandkbs2.pojo; ...@@ -3,6 +3,7 @@ package com.zhiwei.brandkbs2.pojo;
import com.zhiwei.brandkbs2.enmus.RoleEnum; import com.zhiwei.brandkbs2.enmus.RoleEnum;
import com.zhiwei.brandkbs2.pojo.dto.UserDTO; import com.zhiwei.brandkbs2.pojo.dto.UserDTO;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
...@@ -17,6 +18,7 @@ import java.util.Date; ...@@ -17,6 +18,7 @@ import java.util.Date;
*/ */
@Setter @Setter
@Getter @Getter
@NoArgsConstructor
public class UserRole { public class UserRole {
// 默认绑定阿里项目 // 默认绑定阿里项目
...@@ -51,10 +53,10 @@ public class UserRole { ...@@ -51,10 +53,10 @@ public class UserRole {
*/ */
private Integer exportAmount; private Integer exportAmount;
public UserRole(String projectId, int roleId, Date expiredTime, Integer exportAmount) { public UserRole(String projectId, int roleId, Long expiredTime, Integer exportAmount) {
this.projectId = projectId; this.projectId = projectId;
this.roleId = roleId; this.roleId = roleId;
this.expiredTime = expiredTime.getTime(); this.expiredTime = expiredTime;
this.exportAmount = exportAmount; this.exportAmount = exportAmount;
} }
...@@ -63,7 +65,7 @@ public class UserRole { ...@@ -63,7 +65,7 @@ public class UserRole {
if (null != userDTO.getExportAmount() && userDTO.getExportAmount() < MAX_EXPORT_LIMIT) { if (null != userDTO.getExportAmount() && userDTO.getExportAmount() < MAX_EXPORT_LIMIT) {
exportAmount = userDTO.getExportAmount(); exportAmount = userDTO.getExportAmount();
} }
Date expiredTime = null; Long expiredTime = null;
//当创建用户为客户时,添加过期时间 //当创建用户为客户时,添加过期时间
if (userDTO.getRoleId() == RoleEnum.CUSTOMER.getState()) { if (userDTO.getRoleId() == RoleEnum.CUSTOMER.getState()) {
Date date = new Date(userDTO.getExpiredTime()); Date date = new Date(userDTO.getExpiredTime());
...@@ -72,13 +74,13 @@ public class UserRole { ...@@ -72,13 +74,13 @@ public class UserRole {
calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.SECOND, 59);
expiredTime = calendar.getTime(); expiredTime = calendar.getTime().getTime();
} }
return new UserRole(userDTO.getProjectId(), userDTO.getRoleId(), expiredTime, exportAmount); return new UserRole(userDTO.getProjectId(), userDTO.getRoleId(), expiredTime, exportAmount);
} }
public static UserRole defaultUserRole(Date now) { public static UserRole defaultUserRole(Date now) {
return new UserRole(DEFAULT_PROJECT_ID, DEFAULT_ROLE_ID, DateUtils.addDays(now, 30), DEFAULT_EXPORT_LIMIT); return new UserRole(DEFAULT_PROJECT_ID, DEFAULT_ROLE_ID, DateUtils.addDays(now, 30).getTime(), DEFAULT_EXPORT_LIMIT);
} }
} }
package com.zhiwei.brandkbs2.pojo.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.zhiwei.brandkbs2.pojo.BaseMap;
import com.zhiwei.brandkbs2.util.Tools;
import lombok.Data;
import lombok.ToString;
import java.util.Date;
import java.util.Map;
/**
* 舆情导出
*/
@Data
@ToString
public class ExportAppYuqingDTO {
@ColumnWidth(20)
@ExcelProperty("时间")
private Date time;
@ColumnWidth(20)
@ExcelProperty("平台")
private String platform;
@ColumnWidth(20)
@ExcelProperty("渠道")
private String source;
@ColumnWidth(50)
@ExcelProperty("标题")
private String title;
@ColumnWidth(50)
@ExcelProperty("文本")
private String content;
@ColumnWidth(50)
@ExcelProperty("地址")
private String url;
@ColumnWidth(25)
@ExcelProperty("情感调性")
private String emotion;
public static ExportAppYuqingDTO createFromEsMap(Map<String, Object> map) {
ExportAppYuqingDTO dto = new ExportAppYuqingDTO();
BaseMap baseFromEsMap = Tools.getBaseFromEsMap(map);
dto.setTime(new Date(baseFromEsMap.getTime()));
dto.setPlatform(baseFromEsMap.getPlatform());
dto.setSource(baseFromEsMap.getSource());
dto.setTitle(baseFromEsMap.getTitle());
dto.setContent(baseFromEsMap.getContent());
dto.setUrl(baseFromEsMap.getUrl());
dto.setEmotion(baseFromEsMap.getEmotion());
return dto;
}
}
...@@ -12,6 +12,12 @@ import java.util.List; ...@@ -12,6 +12,12 @@ import java.util.List;
@ToString @ToString
@ApiModel("标注数据搜索传输类") @ApiModel("标注数据搜索传输类")
public class MarkSearchDTO { public class MarkSearchDTO {
/**
* 聚合id
*/
@ApiModelProperty("聚合id")
private String aggreeId;
/** /**
* 页码 * 页码
*/ */
...@@ -25,6 +31,8 @@ public class MarkSearchDTO { ...@@ -25,6 +31,8 @@ public class MarkSearchDTO {
private int pageSize; private int pageSize;
// postFilter // postFilter
@ApiModelProperty(value = "项目id")
private String projectId;
/** /**
* 关联项目组id * 关联项目组id
*/ */
...@@ -102,6 +110,6 @@ public class MarkSearchDTO { ...@@ -102,6 +110,6 @@ public class MarkSearchDTO {
* 是否去重 * 是否去重
*/ */
@ApiModelProperty(value = "是否去重") @ApiModelProperty(value = "是否去重")
private boolean duplicate; private boolean fold;
} }
...@@ -2,8 +2,10 @@ package com.zhiwei.brandkbs2.service; ...@@ -2,8 +2,10 @@ package com.zhiwei.brandkbs2.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.pojo.MarkFlowEntity; import com.zhiwei.brandkbs2.pojo.MarkFlowEntity;
import com.zhiwei.brandkbs2.pojo.dto.ExportAppYuqingDTO;
import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO; import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO; import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import org.apache.commons.lang3.tuple.Pair;
import java.util.List; import java.util.List;
...@@ -22,6 +24,12 @@ public interface MarkDataService { ...@@ -22,6 +24,12 @@ public interface MarkDataService {
PageVO<MarkFlowEntity> getYuqingMarkList(MarkSearchDTO markSearchDTO); PageVO<MarkFlowEntity> getYuqingMarkList(MarkSearchDTO markSearchDTO);
/** /**
* @param markSearchDTO 标注数据搜索传输类
* @return 返回结果
*/
Pair<String,List<ExportAppYuqingDTO>> downloadYuqingMarkList(MarkSearchDTO markSearchDTO);
/**
* 生成聚合列表并返回id * 生成聚合列表并返回id
* *
* @return 聚合id * @return 聚合id
...@@ -29,6 +37,21 @@ public interface MarkDataService { ...@@ -29,6 +37,21 @@ public interface MarkDataService {
String generateYuqingMarkAggreeList(MarkSearchDTO markSearchDTO); String generateYuqingMarkAggreeList(MarkSearchDTO markSearchDTO);
/** /**
* 获取聚合进度结果
* @param id 聚合id
* @return 进度值
*/
String getYuqingMarkAggreeProgress(String id);
/**
* 获取聚合结果列表
*
* @param markSearchDTO 搜索实体
* @return 标注消息流列表
*/
PageVO<MarkFlowEntity> getYuqingMarkAggreeList(MarkSearchDTO markSearchDTO);
/**
* 舆情标注数据搜索条件 * 舆情标注数据搜索条件
*/ */
JSONObject getYuqingMarkCriteria(String linkedGroup); JSONObject getYuqingMarkCriteria(String linkedGroup);
......
...@@ -18,4 +18,9 @@ public interface TaskService{ ...@@ -18,4 +18,9 @@ public interface TaskService{
*/ */
void generateReportAndSend(); void generateReportAndSend();
/**
* 清理过期聚合任务
*/
void cleanAggreeTask();
} }
package com.zhiwei.brandkbs2.service.impl; package com.zhiwei.brandkbs2.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.dao.ChannelDao; import com.zhiwei.brandkbs2.dao.*;
import com.zhiwei.brandkbs2.dao.ChannelLabelDao;
import com.zhiwei.brandkbs2.dao.EventDao;
import com.zhiwei.brandkbs2.dao.EventDataDao;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelArticleDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelArticleDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelEventDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelEventDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportChannelDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportChannelDTO;
...@@ -55,12 +52,14 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -55,12 +52,14 @@ public class ChannelServiceImpl implements ChannelService {
@Resource(name = "esClientDao") @Resource(name = "esClientDao")
EsClientDao esClientDao; EsClientDao esClientDao;
@Resource(name = "channelTagDao")
ChannelTagDao channelTagDao;
@Resource(name = "mongoUtil") @Resource(name = "mongoUtil")
MongoUtil mongoUtil; MongoUtil mongoUtil;
@Override @Override
public PageVO<JSONObject> findChannelList(int page, int size, String linkedGroupId, String emotion, String platform, Boolean show, public PageVO<JSONObject> findChannelList(int page, int size, String linkedGroupId, String emotion, String platform, Boolean show, String keyword, String sorter) {
String keyword, String sorter) {
Query query = channelListQuery(linkedGroupId, show, emotion, platform, keyword, sorter); Query query = channelListQuery(linkedGroupId, show, emotion, platform, keyword, sorter);
long total = channelDao.count(query); long total = channelDao.count(query);
// 开启分页 // 开启分页
...@@ -80,7 +79,7 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -80,7 +79,7 @@ public class ChannelServiceImpl implements ChannelService {
result.put("lastTime", channel.getLastTime()); result.put("lastTime", channel.getLastTime());
result.put("show", channel.isShow()); result.put("show", channel.isShow());
result.put("imgUrl", channel.getImgUrl()); result.put("imgUrl", channel.getImgUrl());
result.put("tag", channel.getTag()); result.put("tag", channelTagDao.getTagByChannelName(channel.getSource()));
return result; return result;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
MongoUtil.PageHelper<JSONObject> pageHelper = mongoUtil.pageHelper(total, resList); MongoUtil.PageHelper<JSONObject> pageHelper = mongoUtil.pageHelper(total, resList);
...@@ -100,7 +99,7 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -100,7 +99,7 @@ public class ChannelServiceImpl implements ChannelService {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
BaseMap baseMap = Tools.getBaseFromEsMap(sourceJson); BaseMap baseMap = Tools.getBaseFromEsMap(sourceJson);
json.put("id", sourceJson.get("id")); json.put("id", sourceJson.get("id"));
json.put("title",baseMap.getTitleNullOptionalContent()); json.put("title", baseMap.getTitleNullOptionalContent());
json.put("url", baseMap.getUrl()); json.put("url", baseMap.getUrl());
json.put("time", new Date(baseMap.getTime())); json.put("time", new Date(baseMap.getTime()));
json.put("emotion", baseMap.getEmotion()); json.put("emotion", baseMap.getEmotion());
...@@ -170,7 +169,7 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -170,7 +169,7 @@ public class ChannelServiceImpl implements ChannelService {
jsonObject.put("realSource", channel.getRealSource()); jsonObject.put("realSource", channel.getRealSource());
jsonObject.put("source", channel.getSource()); jsonObject.put("source", channel.getSource());
jsonObject.put("imgUrl", channel.getImgUrl()); jsonObject.put("imgUrl", channel.getImgUrl());
jsonObject.put("tag", channel.getTag()); jsonObject.put("tag", channelTagDao.getTagByChannelName(channel.getSource()));
return jsonObject; return jsonObject;
} }
......
...@@ -8,6 +8,7 @@ import com.zhiwei.brandkbs2.auth.UserThreadLocal; ...@@ -8,6 +8,7 @@ import com.zhiwei.brandkbs2.auth.UserThreadLocal;
import com.zhiwei.brandkbs2.common.GenericAttribute; import com.zhiwei.brandkbs2.common.GenericAttribute;
import com.zhiwei.brandkbs2.common.GlobalPojo; import com.zhiwei.brandkbs2.common.GlobalPojo;
import com.zhiwei.brandkbs2.common.RedisKeyPrefix; import com.zhiwei.brandkbs2.common.RedisKeyPrefix;
import com.zhiwei.brandkbs2.dao.AggreeResultDao;
import com.zhiwei.brandkbs2.enmus.EmotionEnum; import com.zhiwei.brandkbs2.enmus.EmotionEnum;
import com.zhiwei.brandkbs2.enmus.ImportantChannelEnum; import com.zhiwei.brandkbs2.enmus.ImportantChannelEnum;
import com.zhiwei.brandkbs2.es.EsClientDao; import com.zhiwei.brandkbs2.es.EsClientDao;
...@@ -15,13 +16,14 @@ import com.zhiwei.brandkbs2.es.EsQueryTools; ...@@ -15,13 +16,14 @@ import com.zhiwei.brandkbs2.es.EsQueryTools;
import com.zhiwei.brandkbs2.exception.ExceptionCast; import com.zhiwei.brandkbs2.exception.ExceptionCast;
import com.zhiwei.brandkbs2.listener.ApplicationProjectListener; import com.zhiwei.brandkbs2.listener.ApplicationProjectListener;
import com.zhiwei.brandkbs2.model.CommonCodeEnum; import com.zhiwei.brandkbs2.model.CommonCodeEnum;
import com.zhiwei.brandkbs2.pojo.BaseMap; import com.zhiwei.brandkbs2.pojo.*;
import com.zhiwei.brandkbs2.pojo.MarkFlowEntity; import com.zhiwei.brandkbs2.pojo.dto.ExportAppYuqingDTO;
import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO; import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO;
import com.zhiwei.brandkbs2.pojo.vo.CustomTagVo; import com.zhiwei.brandkbs2.pojo.vo.CustomTagVo;
import com.zhiwei.brandkbs2.pojo.vo.PageVO; import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import com.zhiwei.brandkbs2.pojo.vo.ProjectVO; import com.zhiwei.brandkbs2.pojo.vo.ProjectVO;
import com.zhiwei.brandkbs2.service.*; import com.zhiwei.brandkbs2.service.*;
import com.zhiwei.brandkbs2.util.MongoUtil;
import com.zhiwei.brandkbs2.util.RedisUtil; import com.zhiwei.brandkbs2.util.RedisUtil;
import com.zhiwei.brandkbs2.util.TextUtil; import com.zhiwei.brandkbs2.util.TextUtil;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
...@@ -52,6 +54,8 @@ import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilde ...@@ -52,6 +54,8 @@ import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilde
import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -88,19 +92,25 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -88,19 +92,25 @@ public class MarkDataServiceImpl implements MarkDataService {
@Resource(name = "markFlowServiceImpl") @Resource(name = "markFlowServiceImpl")
MarkFlowService markFlowService; MarkFlowService markFlowService;
@Resource(name = "aggreeResultDaoImpl")
AggreeResultDao aggreeResultDao;
@Resource(name = "redisUtil") @Resource(name = "redisUtil")
RedisUtil redisUtil; RedisUtil redisUtil;
@Resource(name = "mongoUtil")
MongoUtil mongoUtil;
@Override @Override
public PageVO<MarkFlowEntity> getYuqingMarkList(MarkSearchDTO markSearchDTO) { public PageVO<MarkFlowEntity> getYuqingMarkList(MarkSearchDTO markSearchDTO) {
try { try {
defaultMarkSearch(markSearchDTO); defaultMarkSearch(markSearchDTO);
// 搜索es数据 // 搜索es数据
Pair<SearchHits, Map<String, Long>> hitsAndCounts = searchMarkHitsAndCount(markSearchDTO); Pair<SearchHits[], Map<String, Long>> hitsAndCounts = searchMarkHitsAndCount(markSearchDTO, false);
// 总量 // 总量
long total = hitsAndCounts.getLeft().getTotalHits().value > 10000 ? 10000 : hitsAndCounts.getLeft().getTotalHits().value; long total = hitsAndCounts.getLeft()[0].getTotalHits().value > 10000 ? 10000 : hitsAndCounts.getLeft()[0].getTotalHits().value;
// 消息列表 // 消息列表
List<MarkFlowEntity> flowEntityList = getMarkFlowEntity(markSearchDTO, hitsAndCounts.getLeft()); List<MarkFlowEntity> flowEntityList = getMarkFlowEntity(markSearchDTO, hitsAndCounts.getLeft()[0]);
// 返回分页结果并设置平台count // 返回分页结果并设置平台count
return PageVO.createPageVo(total, markSearchDTO.getPage(), markSearchDTO.getPageSize(), flowEntityList) return PageVO.createPageVo(total, markSearchDTO.getPage(), markSearchDTO.getPageSize(), flowEntityList)
// 各平台计量 // 各平台计量
...@@ -112,25 +122,159 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -112,25 +122,159 @@ public class MarkDataServiceImpl implements MarkDataService {
} }
@Override @Override
public Pair<String, List<ExportAppYuqingDTO>> downloadYuqingMarkList(MarkSearchDTO markSearchDTO) {
try {
ProjectVO project = projectService.getProjectVOById(UserThreadLocal.getProjectId());
List<ExportAppYuqingDTO> returnList = new ArrayList<>();
Pair<SearchHits[], Map<String, Long>> hitsAndCounts = searchMarkHitsAndCount(markSearchDTO, false);
for (SearchHits searchHits : hitsAndCounts.getLeft()) {
List<ExportAppYuqingDTO> collect = Arrays.stream(searchHits.getHits()).map(SearchHit::getSourceAsMap).map(ExportAppYuqingDTO::createFromEsMap).collect(Collectors.toList());
returnList.addAll(collect);
}
return Pair.of(project.getBrandName() + "_" + markSearchDTO.getStartTime() + "_" + markSearchDTO.getEndTime(), returnList);
} catch (IOException e) {
ExceptionCast.cast(CommonCodeEnum.FAIL.message("es检索异常"));
}
return null;
}
@Override
public String generateYuqingMarkAggreeList(MarkSearchDTO markSearchDTO) { public String generateYuqingMarkAggreeList(MarkSearchDTO markSearchDTO) {
String uuid = Tools.getUUID(); String uuid = Tools.getUUID();
String projectId = UserThreadLocal.getProjectId();
defaultMarkSearch4Aggree(markSearchDTO);
ApplicationProjectListener.getThreadPool().execute(() -> { ApplicationProjectListener.getThreadPool().execute(() -> {
String redisKey = RedisUtil.getAggreeCacheKey(uuid, projectId);
try { try {
defaultMarkSearch(markSearchDTO); redisUtil.setExpire(redisKey, "0");
// 搜索es数据 // 搜索es数据
Pair<SearchHits, Map<String, Long>> hitsAndCounts = searchMarkHitsAndCount(markSearchDTO); Pair<SearchHits[], Map<String, Long>> hitsAndCounts = searchMarkHitsAndCount(markSearchDTO, true);
log.info("taskId:{},聚合前数据:{}条", uuid, hitsAndCounts.getLeft()[0].getTotalHits().value);
// 聚合分组后数据 // 聚合分组后数据
List<List<JSONObject>> groupList = aggregation(hitsAndCounts.getLeft(), "id"); List<List<JSONObject>> groupList = aggregation(hitsAndCounts.getLeft(), "id");
log.info("taskId:{},聚合完成,聚合组:{}个", uuid, groupList.size());
// 入mongo缓存
cacheAggreeResult(groupList, uuid);
redisUtil.setExpire(redisKey, "100");
} catch (Exception e) { } catch (Exception e) {
log.error("generateYuqingMarkAggreeList-", e); log.error("generateYuqingMarkAggreeList-", e);
redisUtil.remove(redisKey);
} }
}); });
return uuid; return uuid;
} }
@Override @Override
public String getYuqingMarkAggreeProgress(String id) {
String redisKey = RedisUtil.getAggreeCacheKey(id, UserThreadLocal.getProjectId());
return redisUtil.get(redisKey);
}
@Override
public PageVO<MarkFlowEntity> getYuqingMarkAggreeList(MarkSearchDTO dto) {
if (null == dto.getAggreeId()) {
ExceptionCast.cast(CommonCodeEnum.INVALID_PARAM.message("聚合id不得为空"));
}
defaultMarkSearch4Aggree(dto);
Query query = assembleAggreeQuery(dto);
// 量查询
long count = aggreeResultDao.count(query);
// 开启分页
mongoUtil.start(dto.getPage(), dto.getPageSize(), query);
// 排序
aggreeResultDao.addSort(query, "{\"aggreeSize\":\"descend\"}");
// 返回结果
List<MarkFlowEntity> resList = new ArrayList<>();
List<AggreeResult> fatherList = aggreeResultDao.findList(query);
// List<String> fatherIds = fatherList.stream().map(AggreeResult::getFatherId).collect(Collectors.toList());
// Map<String, List<AggreeResult>> fatherMap = new HashMap<>();
// for (AggreeResult aggreeResult : aggreeResultDao.findList(Query.query(Criteria.where("fatherId").in(fatherIds)))) {
// fatherMap.compute(aggreeResult.getFatherId(), (k, v) -> {
// if (null == v) {
// v = new ArrayList<>();
// }
// v.add(aggreeResult);
// return v;
// });
// }
// Map<String, List<AggreeResult>> fatherMap = aggreeResultDao.findList(Query.query(Criteria.where("fatherId").in(fatherIds))).stream().collect(Collectors.groupingBy(AggreeResult::getFatherId));
for (AggreeResult aggreeResult : fatherList) {
List<MarkFlowEntity> markFlowEntities = new ArrayList<>();
MarkFlowEntity instance = new MarkFlowEntity(aggreeResult.getData());
instance.setInfo(markFlowService.createMarkFlowInfo(aggreeResult.getData(), dto.getProjectId(), dto.getLinkedGroupId()));
markFlowEntities.add(instance);
// 添加父标题集下的子标题集
// markFlowEntities.addAll(fatherMap.get(aggreeResult.getFatherId()).stream().map(sonResult -> new MarkFlowEntity(sonResult.getData())).collect(Collectors.toList()));
resList.add(MarkFlowEntity.getAggreeInstance(markFlowEntities, aggreeResult.getAggreeSize()));
}
return PageVO.createPageVo(count, dto.getPage(), dto.getPageSize(), resList);
}
private Query assembleAggreeQuery(MarkSearchDTO dto) {
Query query = new Query();
query.addCriteria(Criteria.where("taskId").is(dto.getAggreeId()));
// 平台
if (CollectionUtils.isNotEmpty(dto.getPlatforms())) {
Criteria orCriteria = new Criteria();
List<Criteria> platformCriteria = new ArrayList<>();
for (String platformId : dto.getPlatforms()) {
platformCriteria.add(Criteria.where("platformId").is(platformId));
}
query.addCriteria(orCriteria.orOperator(platformCriteria.toArray(new Criteria[0])));
}
// 媒体类型
if (CollectionUtils.isNotEmpty(dto.getMediaTypes())) {
Criteria orCriteria = new Criteria();
List<Criteria> mediaCriteria = new ArrayList<>();
for (String mediaType : dto.getMediaTypes()) {
mediaCriteria.add(Criteria.where("mediaTypes").is(mediaType));
}
query.addCriteria(orCriteria.orOperator(mediaCriteria.toArray(new Criteria[0])));
}
// 情感调性
if (CollectionUtils.isNotEmpty(dto.getTags())) {
Criteria orCriteria = new Criteria();
List<Criteria> tagCriteria = new ArrayList<>();
for (String tag : dto.getTags()) {
tagCriteria.add(Criteria.where("tags").is(tag));
}
query.addCriteria((orCriteria.orOperator(tagCriteria.toArray(new Criteria[0]))));
}
// 关键词模糊查询
aggreeResultDao.addKeywordFuzz(query, dto.getKeyword(), "aggreeTitle");
return query;
}
private void cacheAggreeResult(List<List<JSONObject>> groupList, String taskId) {
int count = 0;
int percent;
for (List<JSONObject> list : groupList) {
String fatherId = null;
String fatherTitle = null;
for (int i = 0; i < list.size(); i++) {
JSONObject json = list.get(i);
AggreeResult aggreeResult;
// 父聚合处理
if (i == 0) {
aggreeResult = AggreeResult.createFather(json, taskId, list.size());
aggreeResultDao.insertOneWithoutId(aggreeResult);
fatherId = aggreeResult.getId();
fatherTitle = aggreeResult.getAggreeTitle();
} else {
aggreeResult = AggreeResult.createSon(json, taskId, fatherId, fatherTitle);
aggreeResultDao.insertOneWithoutId(aggreeResult);
}
}
if ((percent = (++count / list.size())) % (10 / list.size()) == 0) {
log.info("taskId:{},fatherId:{} 入库完毕,进度:{}%", taskId, fatherId, percent);
}
}
}
@Override
public JSONObject getYuqingMarkCriteria(String linkedGroupId) { public JSONObject getYuqingMarkCriteria(String linkedGroupId) {
if (null == linkedGroupId) { if (null == linkedGroupId) {
linkedGroupId = projectService.getProjectVOById(UserThreadLocal.getProjectId()).getBrandLinkedGroupId(); linkedGroupId = projectService.getProjectVOById(UserThreadLocal.getProjectId()).getBrandLinkedGroupId();
...@@ -183,8 +327,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -183,8 +327,7 @@ public class MarkDataServiceImpl implements MarkDataService {
// 获取所有平台稿件倾向稿件数量信息 // 获取所有平台稿件倾向稿件数量信息
List<JSONObject> platformsCount = getPlatformMarkEmotionCount(startTime, endTime, projectId, linkedGroupId); List<JSONObject> platformsCount = getPlatformMarkEmotionCount(startTime, endTime, projectId, linkedGroupId);
// 正面舆情峰值平台 // 正面舆情峰值平台
platformsCount.stream().max(Comparator.comparing(o -> o.getInteger(EmotionEnum.POSITIVE.getName()))).ifPresent(e -> result.put("posTopPlatform", platformsCount.stream().max(Comparator.comparing(o -> o.getInteger(EmotionEnum.POSITIVE.getName()))).ifPresent(e -> result.put("posTopPlatform", e.getString("platform_id")));
e.getString("platform_id")));
// 负面舆情峰值平台 // 负面舆情峰值平台
platformsCount.stream().max(Comparator.comparing(o -> o.getInteger(EmotionEnum.NEGATIVE.getName()))).ifPresent(e -> result.put("negTopPlatform", e.getString("platform_id"))); platformsCount.stream().max(Comparator.comparing(o -> o.getInteger(EmotionEnum.NEGATIVE.getName()))).ifPresent(e -> result.put("negTopPlatform", e.getString("platform_id")));
// 获取时间段正面情感数据最多的标题 // 获取时间段正面情感数据最多的标题
...@@ -278,11 +421,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -278,11 +421,7 @@ public class MarkDataServiceImpl implements MarkDataService {
for (JSONObject result : channelEmotions) { for (JSONObject result : channelEmotions) {
int channelEmotion = result.getIntValue("channelEmotion"); int channelEmotion = result.getIntValue("channelEmotion");
long channelEmotionCount = result.getLongValue("count"); long channelEmotionCount = result.getLongValue("count");
List<String> mediaTypeList = Arrays.asList( List<String> mediaTypeList = Arrays.asList(ImportantChannelEnum.YANGJI.getState(), ImportantChannelEnum.KEJI.getState(), ImportantChannelEnum.CAIJING.getState(), ImportantChannelEnum.QITA.getState());
ImportantChannelEnum.YANGJI.getState(),
ImportantChannelEnum.KEJI.getState(),
ImportantChannelEnum.CAIJING.getState(),
ImportantChannelEnum.QITA.getState());
List<JSONObject> mediaTypeResultList = new ArrayList<>(mediaTypeList.size()); List<JSONObject> mediaTypeResultList = new ArrayList<>(mediaTypeList.size());
for (String mediaType : mediaTypeList) { for (String mediaType : mediaTypeList) {
BoolQueryBuilder boolQueryBuilder = projectLinkedGroupQuery(projectId, linkedGroupId); BoolQueryBuilder boolQueryBuilder = projectLinkedGroupQuery(projectId, linkedGroupId);
...@@ -291,9 +430,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -291,9 +430,7 @@ public class MarkDataServiceImpl implements MarkDataService {
.must(QueryBuilders.termQuery("channel_emotion", channelEmotion)); .must(QueryBuilders.termQuery("channel_emotion", channelEmotion));
// TODO 其他类别标签 // TODO 其他类别标签
if (ImportantChannelEnum.QITA.getState().equals(mediaType)) { if (ImportantChannelEnum.QITA.getState().equals(mediaType)) {
boolQueryBuilder.mustNot(QueryBuilders.matchQuery("tag", ImportantChannelEnum.YANGJI.getState())) boolQueryBuilder.mustNot(QueryBuilders.matchQuery("tag", ImportantChannelEnum.YANGJI.getState())).mustNot(QueryBuilders.matchQuery("tag", ImportantChannelEnum.KEJI.getState())).mustNot(QueryBuilders.matchQuery("tag", ImportantChannelEnum.CAIJING.getState()));
.mustNot(QueryBuilders.matchQuery("tag", ImportantChannelEnum.KEJI.getState()))
.mustNot(QueryBuilders.matchQuery("tag", ImportantChannelEnum.CAIJING.getState()));
} else { } else {
boolQueryBuilder.must(QueryBuilders.matchQuery("tag", mediaType)); boolQueryBuilder.must(QueryBuilders.matchQuery("tag", mediaType));
} }
...@@ -349,6 +486,16 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -349,6 +486,16 @@ public class MarkDataServiceImpl implements MarkDataService {
return null; return null;
} }
private void defaultMarkSearch4Aggree(MarkSearchDTO markSearchDTO) {
// 时间范围默认一星期
if (Objects.isNull(markSearchDTO.getStartTime()) || Objects.isNull(markSearchDTO.getEndTime())) {
Date now = new Date();
markSearchDTO.setEndTime(now.getTime());
markSearchDTO.setStartTime(DateUtils.addDays(now, -7).getTime());
}
defaultMarkSearch(markSearchDTO);
}
private void defaultMarkSearch(MarkSearchDTO markSearchDTO) { private void defaultMarkSearch(MarkSearchDTO markSearchDTO) {
// 时间范围默认一个月 // 时间范围默认一个月
if (Objects.isNull(markSearchDTO.getStartTime()) || Objects.isNull(markSearchDTO.getEndTime())) { if (Objects.isNull(markSearchDTO.getStartTime()) || Objects.isNull(markSearchDTO.getEndTime())) {
...@@ -369,19 +516,22 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -369,19 +516,22 @@ public class MarkDataServiceImpl implements MarkDataService {
sorter.put("time", "descend"); sorter.put("time", "descend");
markSearchDTO.setSorter(sorter); markSearchDTO.setSorter(sorter);
} }
String projectId = UserThreadLocal.getProjectId();
markSearchDTO.setProjectId(projectId);
String linkedGroupId = markSearchDTO.getLinkedGroupId();
if (null == linkedGroupId) {
linkedGroupId = projectService.getProjectVOById(projectId).getBrandLinkedGroupId();
markSearchDTO.setLinkedGroupId(linkedGroupId);
}
} }
private Pair<SearchHits, Map<String, Long>> searchMarkHitsAndCount(MarkSearchDTO dto) throws IOException { private EsClientDao.SearchHelper createSearchHelperByMarkSearchDTO(MarkSearchDTO dto) {
// 获取索引 EsClientDao.SearchHelper helper = EsClientDao.createSearchHelper();
String[] indexes = esClientDao.getIndexes();
// PostFilter 后置过滤器
BoolQueryBuilder postFilter = QueryBuilders.boolQuery();
// linkedGroupId projectId // linkedGroupId projectId
String projectId = dto.getProjectId();
String linkedGroupId = dto.getLinkedGroupId(); String linkedGroupId = dto.getLinkedGroupId();
if (null == linkedGroupId) { // PostFilter 后置过滤器
linkedGroupId = projectService.getProjectVOById(UserThreadLocal.getProjectId()).getBrandLinkedGroupId(); BoolQueryBuilder postFilter = projectLinkedGroupQuery(projectId, linkedGroupId);
}
postFilter.must(QueryBuilders.termQuery("brandkbs_cache_maps.linkedGroupId.keyword", linkedGroupId)).must(QueryBuilders.termQuery("brandkbs_cache_maps.projectId.keyword", UserThreadLocal.getProjectId()));
// time // time
postFilter.must(QueryBuilders.rangeQuery(dto.getTimeType()).lte(dto.getStartTime()).lt(dto.getEndTime())); postFilter.must(QueryBuilders.rangeQuery(dto.getTimeType()).lte(dto.getStartTime()).lt(dto.getEndTime()));
// platform // platform
...@@ -397,6 +547,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -397,6 +547,7 @@ public class MarkDataServiceImpl implements MarkDataService {
if (CollectionUtils.isNotEmpty(dto.getCustomTags())) { if (CollectionUtils.isNotEmpty(dto.getCustomTags())) {
postFilter.must(EsQueryTools.assembleTagQuery(dto.getCustomTags())); postFilter.must(EsQueryTools.assembleTagQuery(dto.getCustomTags()));
} }
helper.setPostFilter(postFilter);
// Query 查询条件 // Query 查询条件
BoolQueryBuilder query = QueryBuilders.boolQuery(); BoolQueryBuilder query = QueryBuilders.boolQuery();
// keyword // keyword
...@@ -409,6 +560,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -409,6 +560,7 @@ public class MarkDataServiceImpl implements MarkDataService {
if (StringUtils.isNotEmpty(dto.getSourceKeyword())) { if (StringUtils.isNotEmpty(dto.getSourceKeyword())) {
query.must(QueryBuilders.matchQuery(GenericAttribute.ES_SOURCE, dto.getSourceKeyword())); query.must(QueryBuilders.matchQuery(GenericAttribute.ES_SOURCE, dto.getSourceKeyword()));
} }
helper.setQuery(query);
// sort // sort
FieldSortBuilder sort = null; FieldSortBuilder sort = null;
for (Map.Entry<String, Object> entry : dto.getSorter().entrySet()) { for (Map.Entry<String, Object> entry : dto.getSorter().entrySet()) {
...@@ -422,28 +574,46 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -422,28 +574,46 @@ public class MarkDataServiceImpl implements MarkDataService {
sort = SortBuilders.fieldSort(entry.getKey()).order(SortOrder.ASC); sort = SortBuilders.fieldSort(entry.getKey()).order(SortOrder.ASC);
} }
} }
helper.setSort(sort);
// from size // from size
int from = (dto.getPage() - 1) * dto.getPageSize(); helper.setFrom((dto.getPage() - 1) * dto.getPageSize());
helper.setSize(dto.getPageSize());
// HighlightBuilder ??? // HighlightBuilder ???
SearchHits searchHits = esClientDao.searchHits(indexes, postFilter, query, null, sort, from, dto.getPageSize(), null); return helper;
}
private Pair<SearchHits[], Map<String, Long>> searchMarkHitsAndCount(MarkSearchDTO dto, boolean aggree) throws IOException {
EsClientDao.SearchHelper helper = createSearchHelperByMarkSearchDTO(dto);
if (aggree) {
helper.setSize(0);
// TODO 本地调试不滚动查询
// List<SearchResponse> searchResponses = esClientDao.searchScrollResponse(helper);
List<SearchResponse> searchResponses = Collections.singletonList(esClientDao.searchResponse(helper));
return Pair.of(searchResponses.stream().map(SearchResponse::getHits).toArray(SearchHits[]::new), null);
}
SearchHits searchHits = esClientDao.searchHits(helper);
//平台计量统计 仅第一页且无平台限制 //平台计量统计 仅第一页且无平台限制
Map<String, Long> counts = new HashMap<>(); Map<String, Long> counts = new HashMap<>();
if (1 == dto.getPage() && CollectionUtils.isEmpty(dto.getPlatforms())) { if (1 == dto.getPage() && CollectionUtils.isEmpty(dto.getPlatforms())) {
for (MessagePlatform platform : GlobalPojo.PLATFORMS) { for (MessagePlatform platform : GlobalPojo.PLATFORMS) {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery().must(query).must(EsQueryTools.assemblePlatformQuery(Collections.singletonList(platform))); BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery().must(helper.getQuery()).must(EsQueryTools.assemblePlatformQuery(Collections.singletonList(platform)));
Long count = esClientDao.count(indexes, postFilter, queryBuilder); Long count = esClientDao.count(esClientDao.getIndexes(), helper.getPostFilter(), queryBuilder);
counts.put(platform.getName(), count); counts.put(platform.getName(), count);
} }
} }
return Pair.of(searchHits, counts); return Pair.of(new SearchHits[]{searchHits}, counts);
} }
private List<List<JSONObject>> aggregation(SearchHits searchHits, String uniqueField) { private List<List<JSONObject>> aggregation(SearchHits[] searchHitsList, String uniqueField) {
List<JSONObject> jsonList = Arrays.stream(searchHits.getHits()).map(hit -> new JSONObject(hit.getSourceAsMap())).collect(Collectors.toList()); List<SearchHit> hitList = new ArrayList<>();
Map<String, String> idTitle = jsonList.stream().collect(Collectors.toMap(json -> json.getString(uniqueField), for (SearchHits searchHits : searchHitsList) {
json -> Tools.getBaseFromEsMap(json).getTitleNullOptionalContent())); hitList.addAll(Arrays.stream(searchHits.getHits()).collect(Collectors.toList()));
}
Map<String, String> idTitle = hitList.stream().collect(Collectors.toMap(SearchHit::getId, hit -> Tools.getBaseFromEsMap(hit.getSourceAsMap()).getTitleNullOptionalContent()));
List<List<String>> kResult = TextUtil.getKResult(idTitle); List<List<String>> kResult = TextUtil.getKResult(idTitle);
return TextUtil.restoreAndSort(kResult, jsonList, uniqueField); // return TextUtil.restoreThenSort(kResult, hitList.stream().map(hit -> new JSONObject(hit.getSourceAsMap())).collect(Collectors.toList()),
// uniqueField);
return TextUtil.restoreThenSort(kResult, hitList);
} }
// private List<JSONObject> criteriaTime(Date endDate) { // private List<JSONObject> criteriaTime(Date endDate) {
...@@ -536,8 +706,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -536,8 +706,7 @@ public class MarkDataServiceImpl implements MarkDataService {
query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime)); query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime));
List<JSONObject> resultList = new ArrayList<>(emotionList.size()); List<JSONObject> resultList = new ArrayList<>(emotionList.size());
Map<String, Aggregation> aggMap = Map<String, Aggregation> aggMap = esClientDao.searchResponse(indexes, null, query, aggregationBuilder, null, null, 0, 0, null).getAggregations().asMap();
esClientDao.searchResponse(indexes, null, query, aggregationBuilder, null, null, 0, 0, null).getAggregations().asMap();
ParsedStringTerms teamAgg = (ParsedStringTerms) aggMap.get("count"); ParsedStringTerms teamAgg = (ParsedStringTerms) aggMap.get("count");
List<? extends Terms.Bucket> buckets = teamAgg.getBuckets(); List<? extends Terms.Bucket> buckets = teamAgg.getBuckets();
for (String emotion : emotionList) { for (String emotion : emotionList) {
...@@ -635,14 +804,11 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -635,14 +804,11 @@ public class MarkDataServiceImpl implements MarkDataService {
TermsAggregationBuilder emotionAggregationBuilder = AggregationBuilders.terms("count").field("mark_cache_maps.name.keyword"); TermsAggregationBuilder emotionAggregationBuilder = AggregationBuilders.terms("count").field("mark_cache_maps.name.keyword");
// query // query
BoolQueryBuilder query = QueryBuilders.boolQuery(); BoolQueryBuilder query = QueryBuilders.boolQuery();
query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime)). query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime)).must(QueryBuilders.termQuery("brandkbs_cache_maps.projectId.keyword", projectId)).must(QueryBuilders.termQuery("brandkbs_cache_maps.linkedGroupId.keyword", linkedGroupId));
must(QueryBuilders.termQuery("brandkbs_cache_maps.projectId.keyword", projectId)).
must(QueryBuilders.termQuery("brandkbs_cache_maps.linkedGroupId.keyword", linkedGroupId));
// 情感倾向限制 // 情感倾向限制
query.must(QueryBuilders.termQuery("mark_cache_maps.group_name.keyword", "情感倾向")); query.must(QueryBuilders.termQuery("mark_cache_maps.group_name.keyword", "情感倾向"));
// response // response
SearchResponse searchResponse = esClientDao.searchResponse(indexes, null, query, SearchResponse searchResponse = esClientDao.searchResponse(indexes, null, query, daysAggregationBuilder.subAggregation(emotionAggregationBuilder), null, null, 0, 0, null);
daysAggregationBuilder.subAggregation(emotionAggregationBuilder), null, null, 0, 0, null);
Map<String, Aggregation> aggMap = searchResponse.getAggregations().asMap(); Map<String, Aggregation> aggMap = searchResponse.getAggregations().asMap();
ParsedDateHistogram dayAggTeam = (ParsedDateHistogram) aggMap.get("dayAgg"); ParsedDateHistogram dayAggTeam = (ParsedDateHistogram) aggMap.get("dayAgg");
List<? extends Histogram.Bucket> buckets = dayAggTeam.getBuckets(); List<? extends Histogram.Bucket> buckets = dayAggTeam.getBuckets();
...@@ -680,8 +846,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -680,8 +846,7 @@ public class MarkDataServiceImpl implements MarkDataService {
query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime)); query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime));
// 情感倾向限制 // 情感倾向限制
query.must(QueryBuilders.termQuery("mark_cache_maps.group_name.keyword", "情感倾向")); query.must(QueryBuilders.termQuery("mark_cache_maps.group_name.keyword", "情感倾向"));
SearchResponse searchResponse = esClientDao.searchResponse(indexes, null, query, SearchResponse searchResponse = esClientDao.searchResponse(indexes, null, query, platformAggregationBuilder.subAggregation(emotionAggregationBuilder), null, null, 0, 0, null);
platformAggregationBuilder.subAggregation(emotionAggregationBuilder), null, null, 0, 0, null);
Map<String, Aggregation> aggMap = searchResponse.getAggregations().asMap(); Map<String, Aggregation> aggMap = searchResponse.getAggregations().asMap();
ParsedStringTerms teamAgg = (ParsedStringTerms) aggMap.get("platform_count"); ParsedStringTerms teamAgg = (ParsedStringTerms) aggMap.get("platform_count");
List<? extends Terms.Bucket> buckets = teamAgg.getBuckets(); List<? extends Terms.Bucket> buckets = teamAgg.getBuckets();
...@@ -723,8 +888,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -723,8 +888,7 @@ public class MarkDataServiceImpl implements MarkDataService {
List<JSONObject> platformList = commonService.getQbjcPlatform("id", "name"); List<JSONObject> platformList = commonService.getQbjcPlatform("id", "name");
List<JSONObject> platformsCount = getPlatformsCount(startTime, endTime, null, null, projectId, linkedGroupId, platformList); List<JSONObject> platformsCount = getPlatformsCount(startTime, endTime, null, null, projectId, linkedGroupId, platformList);
long articlesCount = platformsCount.stream().mapToLong(platform -> platform.getLongValue("count")).sum(); long articlesCount = platformsCount.stream().mapToLong(platform -> platform.getLongValue("count")).sum();
List<JSONObject> resultList = platformsCount.stream().peek(platform -> platform.put("proportion", List<JSONObject> resultList = platformsCount.stream().peek(platform -> platform.put("proportion", 0 == articlesCount ? 0 : platform.getLongValue("count") * 1.0 / articlesCount)).collect(Collectors.toList());
0 == articlesCount ? 0 : platform.getLongValue("count") * 1.0 / articlesCount)).collect(Collectors.toList());
redisUtil.setExpire(redisKey, JSON.toJSONString(resultList), 1, TimeUnit.HOURS); redisUtil.setExpire(redisKey, JSON.toJSONString(resultList), 1, TimeUnit.HOURS);
return resultList; return resultList;
} }
...@@ -777,8 +941,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -777,8 +941,7 @@ public class MarkDataServiceImpl implements MarkDataService {
* *
* @return 所有稿件倾向稿件数量信息 * @return 所有稿件倾向稿件数量信息
*/ */
private List<JSONObject> getChannelEmotionsCount(Long startTime, Long endTime, String keyword, String searchField, String projectId, String linkedGroupId, private List<JSONObject> getChannelEmotionsCount(Long startTime, Long endTime, String keyword, String searchField, String projectId, String linkedGroupId, List<String> emotionList) {
List<String> emotionList) {
return Collections.emptyList(); return Collections.emptyList();
} }
...@@ -814,11 +977,22 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -814,11 +977,22 @@ public class MarkDataServiceImpl implements MarkDataService {
private List<MarkFlowEntity> getMarkFlowEntity(MarkSearchDTO markSearchDTO, SearchHits searchHits) { private List<MarkFlowEntity> getMarkFlowEntity(MarkSearchDTO markSearchDTO, SearchHits searchHits) {
String projectId = UserThreadLocal.getProjectId(); String projectId = UserThreadLocal.getProjectId();
String linkedGroupId = markSearchDTO.getLinkedGroupId(); String linkedGroupId = markSearchDTO.getLinkedGroupId();
return Arrays.stream(searchHits.getHits()).map(entity -> { // 重复消息折叠
MarkFlowEntity instance = new MarkFlowEntity(entity); if (markSearchDTO.isFold()) {
instance.setInfo(markFlowService.createMarkFlowInfo(new JSONObject(entity.getSourceAsMap()), projectId, linkedGroupId)); Map<String, List<Map<String, Object>>> collect = Arrays.stream(searchHits.getHits()).map(SearchHit::getSourceAsMap).collect(Collectors.groupingBy(map -> {
return instance; BaseMap baseMap = Tools.getBaseFromEsMap(map);
}).collect(Collectors.toList()); String title = baseMap.getTitleNullOptionalContent();
return Tools.filterSpecialCharacter(title) + baseMap.getTypeB().encode();
}));
return collect.values().stream().map(list -> MarkFlowEntity.getFoldInstance(list.stream().map(map -> getMarkFlowEntity(map, projectId, linkedGroupId)).collect(Collectors.toList()))).collect(Collectors.toList());
}
return Arrays.stream(searchHits.getHits()).map(hit -> getMarkFlowEntity(hit.getSourceAsMap(), projectId, linkedGroupId)).collect(Collectors.toList());
}
private MarkFlowEntity getMarkFlowEntity(Map<String, Object> map, String projectId, String linkedGroupId) {
MarkFlowEntity instance = new MarkFlowEntity(new JSONObject(map));
instance.setInfo(markFlowService.createMarkFlowInfo(new JSONObject(map), projectId, linkedGroupId));
return instance;
} }
} }
\ No newline at end of file
...@@ -88,7 +88,7 @@ public class ReportServiceImpl implements ReportService { ...@@ -88,7 +88,7 @@ public class ReportServiceImpl implements ReportService {
@Override @Override
public List<Report> getCustomReportByStatus(String projectId, boolean status) { public List<Report> getCustomReportByStatus(String projectId, boolean status) {
Criteria criteria = Criteria.where("projectId").is(projectId).and("status").is(status).is("type").is(ReportTypeEnum.CUSTOM.getState()); Criteria criteria = Criteria.where("projectId").is(projectId).and("status").is(status).and("type").is(ReportTypeEnum.CUSTOM.getState());
return reportDao.findList(Query.query(criteria)); return reportDao.findList(Query.query(criteria));
} }
...@@ -158,7 +158,7 @@ public class ReportServiceImpl implements ReportService { ...@@ -158,7 +158,7 @@ public class ReportServiceImpl implements ReportService {
} }
JSONObject all = new JSONObject(); JSONObject all = new JSONObject();
all.put("name", "不限"); all.put("name", "不限");
all.put("count",collect.values().stream().mapToInt(v -> v).sum()); all.put("count", collect.values().stream().mapToInt(v -> v).sum());
result.add(0, all); result.add(0, all);
return result; return result;
} }
...@@ -220,7 +220,18 @@ public class ReportServiceImpl implements ReportService { ...@@ -220,7 +220,18 @@ public class ReportServiceImpl implements ReportService {
@Override @Override
public PageVO<JSONObject> findReportList(ReportSearchDTO reportSearch) { public PageVO<JSONObject> findReportList(ReportSearchDTO reportSearch) {
Query query = new Query(); Criteria criteria = new Criteria();
if (null != reportSearch.getStartTime()) {
criteria.and("startTime").gte(reportSearch.getStartTime());
}
if (null != reportSearch.getEndTime()) {
criteria.and("endTime").lt(reportSearch.getEndTime());
}
if (StringUtils.isNotEmpty(reportSearch.getType())) {
criteria.and("type").is(reportSearch.getType());
}
Query query = new Query(criteria);
// 添加关键字查询并排序
long count = reportDao.count(query, reportSearch.getKeyword(), new String[]{"title"}); long count = reportDao.count(query, reportSearch.getKeyword(), new String[]{"title"});
mongoUtil.start(reportSearch.getPage(), reportSearch.getPageSize(), query); mongoUtil.start(reportSearch.getPage(), reportSearch.getPageSize(), query);
// 添加排序 // 添加排序
......
package com.zhiwei.brandkbs2.service.impl; package com.zhiwei.brandkbs2.service.impl;
import com.zhiwei.brandkbs2.config.Constant; import com.zhiwei.brandkbs2.config.Constant;
import com.zhiwei.brandkbs2.dao.BrandkbsTaskDao; import com.zhiwei.brandkbs2.dao.*;
import com.zhiwei.brandkbs2.dao.ChannelDao;
import com.zhiwei.brandkbs2.dao.EventDataDao;
import com.zhiwei.brandkbs2.dao.ReportSettingsDao;
import com.zhiwei.brandkbs2.enmus.ReportTypeEnum; import com.zhiwei.brandkbs2.enmus.ReportTypeEnum;
import com.zhiwei.brandkbs2.es.EsClientDao; import com.zhiwei.brandkbs2.es.EsClientDao;
import com.zhiwei.brandkbs2.listener.ApplicationProjectListener; import com.zhiwei.brandkbs2.listener.ApplicationProjectListener;
...@@ -52,6 +49,9 @@ public class TaskServiceImpl implements TaskService { ...@@ -52,6 +49,9 @@ public class TaskServiceImpl implements TaskService {
@Resource(name = "reportSettingsDao") @Resource(name = "reportSettingsDao")
ReportSettingsDao reportSettingsDao; ReportSettingsDao reportSettingsDao;
@Resource(name = "aggreeResultDaoImpl")
AggreeResultDao aggreeResultDao;
@Resource(name = "brandkbsTaskServiceImpl") @Resource(name = "brandkbsTaskServiceImpl")
BrandkbsTaskService brandkbsTaskService; BrandkbsTaskService brandkbsTaskService;
...@@ -123,6 +123,12 @@ public class TaskServiceImpl implements TaskService { ...@@ -123,6 +123,12 @@ public class TaskServiceImpl implements TaskService {
} }
} }
@Override
public void cleanAggreeTask() {
long deleteCount = aggreeResultDao.deleteExpire(System.currentTimeMillis() - Constant.ONE_DAY);
log.info("本次清理过期聚合:{}条", deleteCount);
}
private boolean reportSendByProject(Project project) { private boolean reportSendByProject(Project project) {
boolean flag = false; boolean flag = false;
// 扫描setting信息 // 扫描setting信息
......
...@@ -50,4 +50,17 @@ public class ControlCenter { ...@@ -50,4 +50,17 @@ public class ControlCenter {
} }
} }
@Async("scheduledExecutor")
@Scheduled(cron = "0 0 * * * ? ")
public void cleanAggreeTask(){
log.info("每小时清理过期聚合任务-启动");
try {
taskService.cleanAggreeTask();
} catch (Exception e) {
log.info("每小时清理过期聚合任务-出错", e);
} finally {
log.info("每小时清理过期聚合任务-结束");
}
}
} }
...@@ -23,6 +23,10 @@ public class RedisUtil { ...@@ -23,6 +23,10 @@ public class RedisUtil {
return RedisKeyPrefix.REDIS_SYSTEM_COPY + "SHOT_PAGE:" + projectId + "-" + id; return RedisKeyPrefix.REDIS_SYSTEM_COPY + "SHOT_PAGE:" + projectId + "-" + id;
} }
public static String getAggreeCacheKey(String id, String projectId) {
return RedisKeyPrefix.AGGREE_RESULT_CACHE + projectId + ":" + id;
}
public void setExpire(String key, String value, long timeout, TimeUnit unit) { public void setExpire(String key, String value, long timeout, TimeUnit unit) {
stringRedisTemplate.opsForValue().set(key, value, timeout, unit); stringRedisTemplate.opsForValue().set(key, value, timeout, unit);
} }
...@@ -35,4 +39,8 @@ public class RedisUtil { ...@@ -35,4 +39,8 @@ public class RedisUtil {
return stringRedisTemplate.opsForValue().get(key); return stringRedisTemplate.opsForValue().get(key);
} }
public void remove(String key) {
setExpire(key, "-1", 1, TimeUnit.SECONDS);
}
} }
...@@ -13,6 +13,7 @@ import com.zhiwei.nlp.common.AggreeConfig; ...@@ -13,6 +13,7 @@ import com.zhiwei.nlp.common.AggreeConfig;
import com.zhiwei.nlp.vo.KResult; import com.zhiwei.nlp.vo.KResult;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.elasticsearch.search.SearchHit;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -67,7 +68,7 @@ public class TextUtil { ...@@ -67,7 +68,7 @@ public class TextUtil {
return AggreeBootStarter.getKResult(listMap, LIMIT).stream().map(KResult::getDataPoints).collect(Collectors.toList()); return AggreeBootStarter.getKResult(listMap, LIMIT).stream().map(KResult::getDataPoints).collect(Collectors.toList());
} }
public static <T> List<List<JSONObject>> restoreAndSort(List<List<T>> kResultList, List<JSONObject> sourceList, String tField) { public static <T> List<List<JSONObject>> restoreThenSort(List<List<T>> kResultList, List<JSONObject> sourceList, String tField) {
ImmutableMap<T, JSONObject> idMap = Maps.uniqueIndex(sourceList, json -> (T) json.get(tField)); ImmutableMap<T, JSONObject> idMap = Maps.uniqueIndex(sourceList, json -> (T) json.get(tField));
// 还原数据 // 还原数据
return kResultList.stream().map(gList -> return kResultList.stream().map(gList ->
...@@ -75,6 +76,14 @@ public class TextUtil { ...@@ -75,6 +76,14 @@ public class TextUtil {
).collect(Collectors.toList()); ).collect(Collectors.toList());
} }
public static List<List<JSONObject>> restoreThenSort(List<List<String>> kResultList, List<SearchHit> sourceList) {
ImmutableMap<String, SearchHit> idMap = Maps.uniqueIndex(sourceList, SearchHit::getId);
// 还原数据
return kResultList.stream().map(gList ->
gList.stream().map(title -> new JSONObject(idMap.get(title).getSourceAsMap())).sorted(Comparator.comparingLong(o -> o.getLong(DEFAULT_SORT_FIELD))).collect(Collectors.toList())
).collect(Collectors.toList());
}
public static Map<String, Integer> getHighWords(List<String> texts) { public static Map<String, Integer> getHighWords(List<String> texts) {
return getHighWords(texts, null); return getHighWords(texts, null);
} }
......
...@@ -2,7 +2,9 @@ package com.zhiwei.brandkbs2.util; ...@@ -2,7 +2,9 @@ package com.zhiwei.brandkbs2.util;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener; import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zhiwei.base.category.ClassB;
import com.zhiwei.base.category.ClassCodec; import com.zhiwei.base.category.ClassCodec;
import com.zhiwei.base.entity.subclass.CompleteText; import com.zhiwei.base.entity.subclass.CompleteText;
import com.zhiwei.base.entity.subclass.IncompleteText; import com.zhiwei.base.entity.subclass.IncompleteText;
...@@ -312,6 +314,7 @@ public class Tools { ...@@ -312,6 +314,7 @@ public class Tools {
public static BaseMap getBaseFromEsMap(Map<String, Object> map) { public static BaseMap getBaseFromEsMap(Map<String, Object> map) {
// 设置source,forward,time // 设置source,forward,time
BaseMap res = Tools.convertMap(map, BaseMap.class); BaseMap res = Tools.convertMap(map, BaseMap.class);
res.setTypeB(ClassB.TypeB.fromEncode((int) map.get(GenericAttribute.ES_C2)));
// 统一设置属性:realSource,platform,emotion // 统一设置属性:realSource,platform,emotion
res.setRealSource(String.valueOf(map.get(GenericAttribute.ES_REAL_SOURCE))); res.setRealSource(String.valueOf(map.get(GenericAttribute.ES_REAL_SOURCE)));
res.setPlatform(getPlatform(map)); res.setPlatform(getPlatform(map));
...@@ -554,4 +557,8 @@ public class Tools { ...@@ -554,4 +557,8 @@ public class Tools {
return calendar.getTime().getTime(); return calendar.getTime().getTime();
} }
public static <T> T copyByJson(T obj, Class<T> clazz) {
return JSON.parseObject(JSON.toJSONString(obj), clazz);
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment