Commit fc95fd23 by shenjunjie

2022/8/30 17:39

parent c4f8d36e
...@@ -7,7 +7,9 @@ import com.zhiwei.brandkbs2.auth.Auth; ...@@ -7,7 +7,9 @@ import com.zhiwei.brandkbs2.auth.Auth;
import com.zhiwei.brandkbs2.config.Constant; import com.zhiwei.brandkbs2.config.Constant;
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.MarkSearchDTO;
import com.zhiwei.brandkbs2.pojo.dto.SearchFilterDTO; import com.zhiwei.brandkbs2.pojo.dto.SearchFilterDTO;
import com.zhiwei.brandkbs2.service.ChannelService;
import com.zhiwei.brandkbs2.service.MarkDataService; import com.zhiwei.brandkbs2.service.MarkDataService;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -23,17 +25,18 @@ import org.springframework.web.client.RestTemplate; ...@@ -23,17 +25,18 @@ import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Objects; import java.util.Objects;
/** /**
* @author cjz
* @ClassName AppSearchController * @ClassName AppSearchController
* @Description 提供前台搜索相关功能 * @Description 提供前台搜索相关功能
* @author cjz
* @date 2022-08-15 16:17 * @date 2022-08-15 16:17
*/ */
@RestController @RestController
@RequestMapping("/app/search") @RequestMapping("/app/search")
@Api(tags = "前台搜索相关接口",description = "提供搜索相关功能") @Api(tags = "前台搜索相关接口", description = "提供搜索相关功能")
@Auth(role = RoleEnum.CUSTOMER) @Auth(role = RoleEnum.CUSTOMER)
public class AppSearchController { public class AppSearchController {
@Autowired @Autowired
...@@ -51,26 +54,29 @@ public class AppSearchController { ...@@ -51,26 +54,29 @@ public class AppSearchController {
@Resource(name = "markDataServiceImpl") @Resource(name = "markDataServiceImpl")
MarkDataService markDataService; MarkDataService markDataService;
@Resource(name = "channelServiceImpl")
ChannelService channelService;
@ApiOperation("搜索-查热点") @ApiOperation("搜索-查热点")
@GetMapping("/hot/list") @GetMapping("/hot/list")
public ResponseResult searchHotList(@RequestParam(value = "pageSize",defaultValue ="10") Integer limit, public ResponseResult searchHotList(@RequestParam(value = "pageSize", defaultValue = "10") Integer limit,
@RequestParam(value = "page",defaultValue ="1") Integer page, @RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "type",defaultValue = "weibo") String type, @RequestParam(value = "type", defaultValue = "weibo") String type,
@RequestParam(value = "word") String word){ @RequestParam(value = "word") String word) {
ResponseEntity<JSONObject> jsonObjectResponseEntity = restTemplate.getForEntity(trendsSearchUrl, JSONObject.class, limit, page, type, word); ResponseEntity<JSONObject> jsonObjectResponseEntity = restTemplate.getForEntity(trendsSearchUrl, JSONObject.class, limit, page, type, word);
JSONObject result = jsonObjectResponseEntity.getBody(); JSONObject result = jsonObjectResponseEntity.getBody();
if(Objects.nonNull(result)){ if (Objects.nonNull(result)) {
return ResponseResult.success(result); return ResponseResult.success(result);
}else{ } else {
return ResponseResult.failure("响应超时"); return ResponseResult.failure("响应超时");
} }
} }
@ApiOperation("搜索-查危机") @ApiOperation("搜索-查危机")
@GetMapping("/crisisSearch") @GetMapping("/crisisSearch")
public ResponseResult crisisSearch(@RequestParam(value = "page",defaultValue = "1") Integer page, public ResponseResult crisisSearch(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "pageSize",defaultValue = "3") Integer pageSize, @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize,
@RequestParam("keyword") String keyword){ @RequestParam("keyword") String keyword) {
ResponseEntity<String> responseEntity = restTemplate.getForEntity(crisisSearchUrl, String.class, page, pageSize, keyword); ResponseEntity<String> responseEntity = restTemplate.getForEntity(crisisSearchUrl, String.class, page, pageSize, keyword);
Object result = JSON.parseObject(responseEntity.getBody()).get("data"); Object result = JSON.parseObject(responseEntity.getBody()).get("data");
return ResponseResult.success(result); return ResponseResult.success(result);
...@@ -79,7 +85,7 @@ public class AppSearchController { ...@@ -79,7 +85,7 @@ public class AppSearchController {
@ApiOperation("搜索-全网事件库-查事件") @ApiOperation("搜索-全网事件库-查事件")
@GetMapping("/getWholeNetworkEvents") @GetMapping("/getWholeNetworkEvents")
public ResponseResult getWholeNetworkEvents(@RequestParam("keyword") String keyword, public ResponseResult getWholeNetworkEvents(@RequestParam("keyword") String keyword,
@RequestParam(value = "page",defaultValue = "1") Integer page){ @RequestParam(value = "page", defaultValue = "1") Integer page) {
String name = keyword.trim(); String name = keyword.trim();
ResponseEntity<String> responseEntity = restTemplate.getForEntity(getEfSearchUrl, String.class, name, page); ResponseEntity<String> responseEntity = restTemplate.getForEntity(getEfSearchUrl, String.class, name, page);
JSONObject result = JSON.parseObject(responseEntity.getBody()); JSONObject result = JSON.parseObject(responseEntity.getBody());
...@@ -88,9 +94,9 @@ public class AppSearchController { ...@@ -88,9 +94,9 @@ public class AppSearchController {
@ApiOperation("搜索-全网搜") @ApiOperation("搜索-全网搜")
@GetMapping("/searchWhole") @GetMapping("/searchWhole")
public ResponseResult searchWholeNetwork(@RequestBody SearchFilterDTO dto){ public ResponseResult searchWholeNetwork(@RequestBody SearchFilterDTO dto) {
long time = DateUtils.addDays(Tools.truncDate(new Date(), Constant.DAY_PATTERN), -89).getTime(); long time = DateUtils.addDays(Tools.truncDate(new Date(), Constant.DAY_PATTERN), -89).getTime();
if (time > dto.getStartTime()){ if (time > dto.getStartTime()) {
return ResponseResult.failure("仅能搜索近3个月内信息"); return ResponseResult.failure("仅能搜索近3个月内信息");
} }
Period periodDay = new Period(dto.getStartTime(), dto.getEndTime(), PeriodType.days()); Period periodDay = new Period(dto.getStartTime(), dto.getEndTime(), PeriodType.days());
...@@ -99,4 +105,49 @@ public class AppSearchController { ...@@ -99,4 +105,49 @@ public class AppSearchController {
} }
return ResponseResult.success(markDataService.searchWholeNetwork(dto)); return ResponseResult.success(markDataService.searchWholeNetwork(dto));
} }
@ApiOperation("舆情列表")
@PostMapping("/mark/list")
public ResponseResult getYuqingMarkList(@RequestBody MarkSearchDTO markSearchDTO) {
return ResponseResult.success(markDataService.getYuqingMarkList(markSearchDTO));
}
@ApiOperation("舆情列表-搜索条件")
@GetMapping("/mark/list/criteria")
public ResponseResult getYuqingMarkCriteria(@RequestParam(required = false) String linkedGroupId) {
return ResponseResult.success(markDataService.getYuqingMarkCriteria(linkedGroupId));
}
@ApiOperation("渠道搜索条件")
@GetMapping("/channel/getChannelSearchCriteria")
public ResponseResult getChannelSearchCriteria() {
return ResponseResult.success(channelService.getChannelSearchCriteria());
}
@ApiOperation("查渠道 渠道库")
@GetMapping(value = "/channel/channelList")
public ResponseResult getChannelList(@RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
@RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "platforms", defaultValue = "全部") List<String> platforms,
@RequestParam(value = "emotions", defaultValue = "") List<Integer> emotions,
@RequestParam(value = "mediaTypes", defaultValue = "全部") List<String> mediaTypes,
@RequestParam(value = "articlesCount", required = false) String[] articlesCount,
@RequestParam(value = "sorter", defaultValue = "{\"influence\":\"descend\"}") String sorter) {
return ResponseResult.success(channelService.getChannelList(page, pageSize, keyword, platforms, emotions, mediaTypes, articlesCount, sorter));
}
@ApiOperation("查竞品")
@PostMapping("/contend/list")
public ResponseResult getContendSearchList(@RequestBody MarkSearchDTO markSearchDTO) {
return ResponseResult.success(markDataService.getContendSearchList(markSearchDTO));
}
@ApiOperation("查竞品-搜索条件")
@GetMapping("/contend/list/criteria")
public ResponseResult getContendSearchCriteria(@RequestParam(required = false) String contendId) {
return ResponseResult.success(markDataService.getContendSearchCriteria(contendId));
}
} }
package com.zhiwei.brandkbs2.enmus; package com.zhiwei.brandkbs2.enmus;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -40,9 +41,14 @@ public enum ImportantChannelEnum { ...@@ -40,9 +41,14 @@ public enum ImportantChannelEnum {
*/ */
QITA("其他"); QITA("其他");
private final String state; private final String state;
/**
* 重要渠道集合
*/
public static final List<String> IMPORTANT_CHANNEL_LIST = new ArrayList<>(Arrays.asList(YANGJI.getState(), KEJI.getState(), CAIJING.getState(), QITA.getState()));
ImportantChannelEnum(String state) { ImportantChannelEnum(String state) {
this.state = state; this.state = state;
} }
......
...@@ -71,10 +71,6 @@ public class EventData extends AbstractBaseMongo { ...@@ -71,10 +71,6 @@ public class EventData extends AbstractBaseMongo {
*/ */
private String projectId; private String projectId;
/** /**
* 关联项目组
*/
private String linkedGroupId;
/**
* 品牌ID * 品牌ID
*/ */
private String contendId; private String contendId;
......
...@@ -251,4 +251,13 @@ public interface ChannelService { ...@@ -251,4 +251,13 @@ public interface ChannelService {
* @param channel 渠道 * @param channel 渠道
*/ */
Channel calculateChannelEmotionIndex(Channel channel); Channel calculateChannelEmotionIndex(Channel channel);
/**
* 获取渠道的删选条件
* @return
*/
JSONObject getChannelSearchCriteria();
PageVO<JSONObject> getChannelList(int page, int pageSize, String keyword, List<String> platforms, List<Integer> emotions, List<String> mediaTypes, String[] articlesCount, String sorter);
} }
...@@ -202,6 +202,7 @@ public interface MarkDataService { ...@@ -202,6 +202,7 @@ public interface MarkDataService {
/** /**
* 竞品库-舆情导出 * 竞品库-舆情导出
*
* @param markSearchDTO 标注数据搜索传输类 * @param markSearchDTO 标注数据搜索传输类
* @return * @return
*/ */
...@@ -209,6 +210,7 @@ public interface MarkDataService { ...@@ -209,6 +210,7 @@ public interface MarkDataService {
/** /**
* 搜索-全网搜 * 搜索-全网搜
*
* @param searchFilterDTO * @param searchFilterDTO
* @return * @return
*/ */
...@@ -255,11 +257,13 @@ public interface MarkDataService { ...@@ -255,11 +257,13 @@ public interface MarkDataService {
* @param startTime 开始时间 * @param startTime 开始时间
* @param endTime 结束时间 * @param endTime 结束时间
* @param emotion 情感倾向 * @param emotion 情感倾向
* @param projectId 项目ID * @param projectId 项目ID
* @param contendId 竞品ID * @param contendId 竞品ID
* @param size 大小 * @param size 大小
* @return 发布最多稿件的渠道 * @return 发布最多稿件的渠道
*/ */
List<Map<String, Object>> getEsTopSource(Long startTime, Long endTime, String projectId, String linkedGroupId, String contendId, String emotion, int size) throws IOException; List<Map<String, Object>> getEsTopSource(Long startTime, Long endTime, String projectId, String linkedGroupId, String contendId, String emotion, int size) throws IOException;
String getLastMarkUrl(String projectId, String linkedGroupId, String contendId, String platform, String realSource, String source);
} }
...@@ -12,10 +12,7 @@ import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelArticleDTO; ...@@ -12,10 +12,7 @@ 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.ExportAppChannelArticleDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportAppChannelArticleDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportChannelDTO; import com.zhiwei.brandkbs2.easyexcel.dto.ExportChannelDTO;
import com.zhiwei.brandkbs2.enmus.ChannelEmotion; import com.zhiwei.brandkbs2.enmus.*;
import com.zhiwei.brandkbs2.enmus.EmotionEnum;
import com.zhiwei.brandkbs2.enmus.EventTagEnum;
import com.zhiwei.brandkbs2.enmus.ExperienceEnum;
import com.zhiwei.brandkbs2.es.ChannelEsDao; import com.zhiwei.brandkbs2.es.ChannelEsDao;
import com.zhiwei.brandkbs2.es.EsClientDao; import com.zhiwei.brandkbs2.es.EsClientDao;
import com.zhiwei.brandkbs2.es.EsQueryTools; import com.zhiwei.brandkbs2.es.EsQueryTools;
...@@ -28,6 +25,7 @@ import com.zhiwei.brandkbs2.pojo.vo.ChannelListVO; ...@@ -28,6 +25,7 @@ import com.zhiwei.brandkbs2.pojo.vo.ChannelListVO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO; import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import com.zhiwei.brandkbs2.service.ChannelService; import com.zhiwei.brandkbs2.service.ChannelService;
import com.zhiwei.brandkbs2.service.CommonService; import com.zhiwei.brandkbs2.service.CommonService;
import com.zhiwei.brandkbs2.service.MarkDataService;
import com.zhiwei.brandkbs2.service.ProjectService; import com.zhiwei.brandkbs2.service.ProjectService;
import com.zhiwei.brandkbs2.util.MongoUtil; import com.zhiwei.brandkbs2.util.MongoUtil;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
...@@ -101,6 +99,9 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -101,6 +99,9 @@ public class ChannelServiceImpl implements ChannelService {
@Resource(name = "commonServiceImpl") @Resource(name = "commonServiceImpl")
CommonService commonService; CommonService commonService;
@Resource(name = "markDataServiceImpl")
MarkDataService markDataService;
@Resource(name = "mongoUtil") @Resource(name = "mongoUtil")
MongoUtil mongoUtil; MongoUtil mongoUtil;
...@@ -774,6 +775,77 @@ public class ChannelServiceImpl implements ChannelService { ...@@ -774,6 +775,77 @@ public class ChannelServiceImpl implements ChannelService {
return channel; return channel;
} }
@Override
public JSONObject getChannelSearchCriteria() {
JSONObject result = new JSONObject();
// 平台
result.put("platformList", commonService.getQbjcPlatform("id", "name"));
//渠道倾向
List<EmotionEnum> emotionList = Arrays.asList(EmotionEnum.ALL, EmotionEnum.POSITIVE, EmotionEnum.NEUTRAL, EmotionEnum.NEGATIVE);
result.put("emotionList", emotionList.stream().map(emotion -> {
JSONObject json = new JSONObject();
json.put("id", emotion.getState());
json.put("name", emotion.getName());
return json;
}).collect(Collectors.toList()));
//渠道级别
List<String> mediaTypeList = ImportantChannelEnum.getAllTagExceptSpec();
mediaTypeList.add(0, "全部");
result.put("mediaTypeList", mediaTypeList);
//发文数量
result.put("articleList", getArticleList());
return result;
}
@Override
public PageVO<JSONObject> getChannelList(int page, int pageSize, String keyword, List<String> platforms, List<Integer> emotions, List<String> mediaTypes,
String[] articlesCount, String sorter) {
String projectId = UserThreadLocal.getProjectId();
String contendId = "0";
String linkedGroupId = projectService.getProjectByContendId(projectId, contendId).getBrandLinkedGroupId();
Query query = new Query(Criteria.where("projectId").is(projectId).and("contendId").is(contendId));
channelDao.addKeywordFuzz(query, keyword, "source");
if (!platforms.contains("全部")) {
query.addCriteria(Criteria.where("platform").in(platforms));
}
if (!emotions.contains(-1)) {
query.addCriteria(Criteria.where("emotion").in(emotions));
}
if (!mediaTypes.contains("全部")) {
// TODO
}
if (null != articlesCount) {
query.addCriteria(Criteria.where("articleCount").gte(articlesCount[0]).lt(articlesCount[1]));
}
long total = channelDao.count(query);
channelDao.addSort(query, sorter);
List<Channel> channelList = channelDao.findList(query);
List<JSONObject> resultList = channelList.stream().map(channel -> {
JSONObject result = new JSONObject();
result.put("channelInfo", channel);
result.put("lastArticle", markDataService.getLastMarkUrl(projectId, linkedGroupId, contendId, channel.getPlatform(), channel.getRealSource(),
channel.getSource()));
return result;
}).collect(Collectors.toList());
return PageVO.createPageVo(total, page, pageSize, resultList);
}
private List<JSONObject> getArticleList() {
List<JSONObject> res = new ArrayList<>();
for (String name : Arrays.asList("全部", "1-10篇", "11-15篇", "51-100篇")) {
JSONObject json = new JSONObject();
json.put("name", name);
if ("全部".equals(name)) {
json.put("value", null);
} else {
String[] split = name.substring(name.length() - 1).split("-");
json.put("value", new Long[]{Long.parseLong(split[0]), Long.parseLong(split[1])});
}
res.add(json);
}
return res;
}
/** /**
* 更新渠道指数,渠道等级,情感倾向并记录变化 * 更新渠道指数,渠道等级,情感倾向并记录变化
* *
......
...@@ -20,6 +20,7 @@ import com.zhiwei.brandkbs2.easyexcel.listener.EventDataListener; ...@@ -20,6 +20,7 @@ import com.zhiwei.brandkbs2.easyexcel.listener.EventDataListener;
import com.zhiwei.brandkbs2.easyexcel.listener.EventFileListener; import com.zhiwei.brandkbs2.easyexcel.listener.EventFileListener;
import com.zhiwei.brandkbs2.enmus.EmotionEnum; import com.zhiwei.brandkbs2.enmus.EmotionEnum;
import com.zhiwei.brandkbs2.enmus.EventTagEnum; import com.zhiwei.brandkbs2.enmus.EventTagEnum;
import com.zhiwei.brandkbs2.enmus.ImportantChannelEnum;
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;
...@@ -111,11 +112,6 @@ public class EventServiceImpl implements EventService { ...@@ -111,11 +112,6 @@ public class EventServiceImpl implements EventService {
@Resource @Resource
private RedisUtil redisUtil; private RedisUtil redisUtil;
/**
* 重要渠道集合
*/
private static final List<String> IMPORTANT_CHANNEL_LIST = new ArrayList<>(Arrays.asList("央级", "科技", "财经", "其他"));
// private static final Pattern PATTERN = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]"); // private static final Pattern PATTERN = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]");
@Override @Override
...@@ -595,7 +591,7 @@ public class EventServiceImpl implements EventService { ...@@ -595,7 +591,7 @@ public class EventServiceImpl implements EventService {
Event event = getEventById(eventId); Event event = getEventById(eventId);
Query query = Query.query(Criteria.where("eventId").is(eventId)); Query query = Query.query(Criteria.where("eventId").is(eventId));
if (Objects.equals("重要渠道", type)) { if (Objects.equals("重要渠道", type)) {
query.addCriteria(Criteria.where("mediaType").in(IMPORTANT_CHANNEL_LIST)); query.addCriteria(Criteria.where("mediaType").in(ImportantChannelEnum.IMPORTANT_CHANNEL_LIST));
} }
// 总量 // 总量
long total = eventDataDao.count(query, event.getCollectionName()); long total = eventDataDao.count(query, event.getCollectionName());
......
...@@ -938,8 +938,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -938,8 +938,7 @@ public class MarkDataServiceImpl implements MarkDataService {
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(helper.getPostFilter()) BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery().must(helper.getPostFilter()).must(EsQueryTools.assemblePlatformQuery(Collections.singletonList(platform)));
.must(EsQueryTools.assemblePlatformQuery(Collections.singletonList(platform)));
Long count = esClientDao.count(esClientDao.getIndexes(), queryBuilder, null); Long count = esClientDao.count(esClientDao.getIndexes(), queryBuilder, null);
counts.put(platform.getName(), count); counts.put(platform.getName(), count);
} }
...@@ -1032,8 +1031,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1032,8 +1031,7 @@ public class MarkDataServiceImpl implements MarkDataService {
result.put("days", new Period(dto.getStartTime(), dto.getEndTime(), PeriodType.days()).getDays()); result.put("days", new Period(dto.getStartTime(), dto.getEndTime(), PeriodType.days()).getDays());
result.put("priName", project.getBrandName()); result.put("priName", project.getBrandName());
// 获取时间段主品牌在每个平台传播量占比 // 获取时间段主品牌在每个平台传播量占比
List<JSONObject> primaryPlatformsProportion = List<JSONObject> primaryPlatformsProportion = getMarkPlatformProportion(dto.getStartTime(), dto.getEndTime(), dto.getProjectId(), dto.getLinkedGroupId(), Constant.PRIMARY_CONTEND_ID, true);
getMarkPlatformProportion(dto.getStartTime(), dto.getEndTime(), dto.getProjectId(), dto.getLinkedGroupId(), Constant.PRIMARY_CONTEND_ID, true);
// 获取时间段主品牌总传播量 // 获取时间段主品牌总传播量
long primaryTotalCount = primaryPlatformsProportion.stream().mapToLong(platform -> platform.getLongValue("count")).sum(); long primaryTotalCount = primaryPlatformsProportion.stream().mapToLong(platform -> platform.getLongValue("count")).sum();
result.put("priNorTotal", primaryTotalCount); result.put("priNorTotal", primaryTotalCount);
...@@ -1046,8 +1044,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1046,8 +1044,7 @@ public class MarkDataServiceImpl implements MarkDataService {
result.put("conName", brandName); result.put("conName", brandName);
// 获取时间段竞品在每个平台传播量 // 获取时间段竞品在每个平台传播量
String contendLinkedGroupId = projectService.getProjectByContendId(dto.getProjectId(), dto.getContendId()).getBrandLinkedGroupId(); String contendLinkedGroupId = projectService.getProjectByContendId(dto.getProjectId(), dto.getContendId()).getBrandLinkedGroupId();
List<JSONObject> contendPlatformsProportion = List<JSONObject> contendPlatformsProportion = getMarkPlatformProportion(dto.getStartTime(), dto.getEndTime(), dto.getProjectId(), contendLinkedGroupId, dto.getContendId(), true);
getMarkPlatformProportion(dto.getStartTime(), dto.getEndTime(), dto.getProjectId(), contendLinkedGroupId, dto.getContendId(), true);
// 获取时间段竞品总传播量 // 获取时间段竞品总传播量
long contendTotalCount = contendPlatformsProportion.stream().mapToLong(platform -> platform.getLongValue("count")).sum(); long contendTotalCount = contendPlatformsProportion.stream().mapToLong(platform -> platform.getLongValue("count")).sum();
result.put("conNorTotal", contendTotalCount); result.put("conNorTotal", contendTotalCount);
...@@ -1127,24 +1124,20 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1127,24 +1124,20 @@ public class MarkDataServiceImpl implements MarkDataService {
long priMaxDayStartTime = primaryMax.getDate(); long priMaxDayStartTime = primaryMax.getDate();
long priMaxDayEndTime = DateUtils.addDays(new Date(primaryMax.getDate()), 1).getTime(); long priMaxDayEndTime = DateUtils.addDays(new Date(primaryMax.getDate()), 1).getTime();
// 获取时间段某情感数据最多的标题 // 获取时间段某情感数据最多的标题
List<Map.Entry<String, Integer>> priTopTitle = List<Map.Entry<String, Integer>> priTopTitle = getMarkTopTitle(priMaxDayStartTime, priMaxDayEndTime, EmotionEnum.ALL.getName(), dto.getProjectId(), dto.getLinkedGroupId(), Constant.PRIMARY_CONTEND_ID, 1);
getMarkTopTitle(priMaxDayStartTime, priMaxDayEndTime, EmotionEnum.ALL.getName(), dto.getProjectId(), dto.getLinkedGroupId(), Constant.PRIMARY_CONTEND_ID, 1);
if (CollectionUtils.isNotEmpty(priTopTitle)) { if (CollectionUtils.isNotEmpty(priTopTitle)) {
// 首发稿件 // 首发稿件
BaseMap priFirstArticle = BaseMap priFirstArticle = getFirstArticle(priMaxDayStartTime, priMaxDayEndTime, priTopTitle.get(0).getKey(), dto.getProjectId(), dto.getLinkedGroupId(), Constant.PRIMARY_CONTEND_ID);
getFirstArticle(priMaxDayStartTime, priMaxDayEndTime, priTopTitle.get(0).getKey(), dto.getProjectId(), dto.getLinkedGroupId(), Constant.PRIMARY_CONTEND_ID);
result.put("priTopTitle", priFirstArticle.getTitle()); result.put("priTopTitle", priFirstArticle.getTitle());
result.put("priTopTitleUrl", priFirstArticle.getUrl()); result.put("priTopTitleUrl", priFirstArticle.getUrl());
} }
// 获取主品牌热门媒体方向 // 获取主品牌热门媒体方向
List<Map.Entry<String, Integer>> priHotTitles = List<Map.Entry<String, Integer>> priHotTitles = getMarkTopTitle(priMaxDayStartTime, priMaxDayEndTime, EmotionEnum.ALL.getName(), dto.getProjectId(), dto.getLinkedGroupId(), Constant.PRIMARY_CONTEND_ID, hotArticleSize);
getMarkTopTitle(priMaxDayStartTime, priMaxDayEndTime, EmotionEnum.ALL.getName(), dto.getProjectId(), dto.getLinkedGroupId(), Constant.PRIMARY_CONTEND_ID, hotArticleSize);
if (CollectionUtils.isNotEmpty(priHotTitles)) { if (CollectionUtils.isNotEmpty(priHotTitles)) {
List<JSONObject> priHotArticle = priHotTitles.stream().map(map -> { List<JSONObject> priHotArticle = priHotTitles.stream().map(map -> {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
try { try {
BaseMap priFirstArticle = BaseMap priFirstArticle = getFirstArticle(dto.getStartTime(), dto.getEndTime(), map.getKey(), dto.getProjectId(), dto.getLinkedGroupId(), Constant.PRIMARY_CONTEND_ID);
getFirstArticle(dto.getStartTime(), dto.getEndTime(), map.getKey(), dto.getProjectId(), dto.getLinkedGroupId(), Constant.PRIMARY_CONTEND_ID);
if (null != priFirstArticle) { if (null != priFirstArticle) {
jsonObject.put("title", priFirstArticle.getTitle()); jsonObject.put("title", priFirstArticle.getTitle());
jsonObject.put("url", priFirstArticle.getUrl()); jsonObject.put("url", priFirstArticle.getUrl());
...@@ -1173,24 +1166,20 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1173,24 +1166,20 @@ public class MarkDataServiceImpl implements MarkDataService {
result.put("conMaxCount", contendMax.getCount()); result.put("conMaxCount", contendMax.getCount());
long conMaxDayStartTime = contendMax.getDate(); long conMaxDayStartTime = contendMax.getDate();
long conMaxDayEndTime = DateUtils.addDays(new Date(contendMax.getDate()), 1).getTime(); long conMaxDayEndTime = DateUtils.addDays(new Date(contendMax.getDate()), 1).getTime();
List<Map.Entry<String, Integer>> conTopTitle = List<Map.Entry<String, Integer>> conTopTitle = getMarkTopTitle(conMaxDayStartTime, conMaxDayEndTime, EmotionEnum.ALL.getName(), dto.getProjectId(), contendLinkedGroupId, dto.getContendId(), 1);
getMarkTopTitle(conMaxDayStartTime, conMaxDayEndTime, EmotionEnum.ALL.getName(), dto.getProjectId(), contendLinkedGroupId, dto.getContendId(), 1);
if (CollectionUtils.isNotEmpty(conTopTitle)) { if (CollectionUtils.isNotEmpty(conTopTitle)) {
// 首发稿件 // 首发稿件
BaseMap conFirstArticle = BaseMap conFirstArticle = getFirstArticle(conMaxDayStartTime, conMaxDayEndTime, conTopTitle.get(0).getKey(), dto.getProjectId(), contendLinkedGroupId, dto.getContendId());
getFirstArticle(conMaxDayStartTime, conMaxDayEndTime, conTopTitle.get(0).getKey(), dto.getProjectId(), contendLinkedGroupId, dto.getContendId());
result.put("conTopTitle", conFirstArticle.getTitle()); result.put("conTopTitle", conFirstArticle.getTitle());
result.put("conTopTitleUrl", conFirstArticle.getUrl()); result.put("conTopTitleUrl", conFirstArticle.getUrl());
} }
// 获取竞品热门媒体方向 // 获取竞品热门媒体方向
List<Map.Entry<String, Integer>> conHotTitles = List<Map.Entry<String, Integer>> conHotTitles = getMarkTopTitle(conMaxDayStartTime, conMaxDayEndTime, EmotionEnum.ALL.getName(), dto.getProjectId(), contendLinkedGroupId, dto.getContendId(), hotArticleSize);
getMarkTopTitle(conMaxDayStartTime, conMaxDayEndTime, EmotionEnum.ALL.getName(), dto.getProjectId(), contendLinkedGroupId, dto.getContendId(), hotArticleSize);
if (CollectionUtils.isNotEmpty(conHotTitles)) { if (CollectionUtils.isNotEmpty(conHotTitles)) {
List<JSONObject> conHotArticle = conHotTitles.stream().map(map -> { List<JSONObject> conHotArticle = conHotTitles.stream().map(map -> {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
try { try {
BaseMap conFirstArticle = BaseMap conFirstArticle = getFirstArticle(dto.getStartTime(), dto.getEndTime(), map.getKey(), dto.getProjectId(), contendLinkedGroupId, dto.getContendId());
getFirstArticle(dto.getStartTime(), dto.getEndTime(), map.getKey(), dto.getProjectId(), contendLinkedGroupId, dto.getContendId());
if (null != conFirstArticle) { if (null != conFirstArticle) {
jsonObject.put("title", conFirstArticle.getTitle()); jsonObject.put("title", conFirstArticle.getTitle());
jsonObject.put("url", conFirstArticle.getUrl()); jsonObject.put("url", conFirstArticle.getUrl());
...@@ -1230,11 +1219,10 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1230,11 +1219,10 @@ public class MarkDataServiceImpl implements MarkDataService {
public JSONObject searchWholeNetwork(SearchFilterDTO dto) { public JSONObject searchWholeNetwork(SearchFilterDTO dto) {
Project project = projectService.getProjectById(dto.getProjectId()); Project project = projectService.getProjectById(dto.getProjectId());
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
if (2 == project.getWholeSearchDataSource()){ // 查商业数据库 if (2 == project.getWholeSearchDataSource()) { // 查商业数据库
defaultSearchFilter(dto); defaultSearchFilter(dto);
try { try {
JSONObject params = IstarShineUtil.getKSSearchParam(dto.getSearch(), null, dto.getStartTime(), dto.getEndTime(), dto.getPlatformsStr(), JSONObject params = IstarShineUtil.getKSSearchParam(dto.getSearch(), null, dto.getStartTime(), dto.getEndTime(), dto.getPlatformsStr(), dto.getFilterForward(), dto.getSortOf(), dto.getPage(), dto.getPageSize(), dto.getMatchFields(), null, null);
dto.getFilterForward(), dto.getSortOf(), dto.getPage(), dto.getPageSize(), dto.getMatchFields(), null, null);
JSONObject taskEntity = new JSONObject(); JSONObject taskEntity = new JSONObject();
taskEntity.put("appId", "6183571e0d710000f6003a12"); // 应用id, 由张志伟提供给使用者 taskEntity.put("appId", "6183571e0d710000f6003a12"); // 应用id, 由张志伟提供给使用者
...@@ -1246,17 +1234,17 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1246,17 +1234,17 @@ public class MarkDataServiceImpl implements MarkDataService {
ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(addIStarShineKSDataUrl, taskEntity, JSONObject.class); ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(addIStarShineKSDataUrl, taskEntity, JSONObject.class);
JSONObject result = Objects.requireNonNull(responseEntity.getBody()).getJSONObject("data"); JSONObject result = Objects.requireNonNull(responseEntity.getBody()).getJSONObject("data");
return searchWholeBackUp(result.get("id").toString()); return searchWholeBackUp(result.get("id").toString());
}catch (Exception e){ } catch (Exception e) {
log.error("error searchWholeNetwork - ", e); log.error("error searchWholeNetwork - ", e);
} }
}else { // 查舆情库 } else { // 查舆情库
ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(wholeSearchUrl, dto.toMap(), JSONObject.class); ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(wholeSearchUrl, dto.toMap(), JSONObject.class);
return searchWholeOpinion(responseEntity, jsonObject); return searchWholeOpinion(responseEntity, jsonObject);
} }
return jsonObject; return jsonObject;
} }
private JSONObject searchWholeOpinion(ResponseEntity<JSONObject> responseEntity, JSONObject jsonObject){ private JSONObject searchWholeOpinion(ResponseEntity<JSONObject> responseEntity, JSONObject jsonObject) {
JSONObject bodyData = Objects.requireNonNull(responseEntity.getBody()).getJSONObject("data"); JSONObject bodyData = Objects.requireNonNull(responseEntity.getBody()).getJSONObject("data");
JSONObject data = bodyData.getJSONObject("data"); JSONObject data = bodyData.getJSONObject("data");
JSONArray listArray = data.getJSONArray("list"); JSONArray listArray = data.getJSONArray("list");
...@@ -1300,7 +1288,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1300,7 +1288,7 @@ public class MarkDataServiceImpl implements MarkDataService {
ResponseEntity<JSONObject> responseEntity = restTemplate.getForEntity(getIStarShineKSInfoDataUrl, JSONObject.class, taskId); ResponseEntity<JSONObject> responseEntity = restTemplate.getForEntity(getIStarShineKSInfoDataUrl, JSONObject.class, taskId);
JSONObject data = Objects.requireNonNull(responseEntity.getBody()).getJSONObject("data"); JSONObject data = Objects.requireNonNull(responseEntity.getBody()).getJSONObject("data");
JSONObject task = data.getJSONObject("task"); JSONObject task = data.getJSONObject("task");
if(1 == task.getInteger("crawlerFinish")){ if (1 == task.getInteger("crawlerFinish")) {
//pageSize //pageSize
Integer receiveCount = task.getInteger("receiveCount"); Integer receiveCount = task.getInteger("receiveCount");
Integer searchCount = task.getInteger("searchCount"); Integer searchCount = task.getInteger("searchCount");
...@@ -1318,12 +1306,12 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1318,12 +1306,12 @@ public class MarkDataServiceImpl implements MarkDataService {
result.put("time", list.get("ctime")); result.put("time", list.get("ctime"));
resultList.add(result); resultList.add(result);
} }
jsonObject.put("list",resultList); jsonObject.put("list", resultList);
//jsonObject.put("page",data1.get("page")); //jsonObject.put("page",data1.get("page"));
jsonObject.put("pageLimit",receiveCount); jsonObject.put("pageLimit", receiveCount);
jsonObject.put("total",searchCount); jsonObject.put("total", searchCount);
jsonObject.put("totalPage",totalPage); jsonObject.put("totalPage", totalPage);
jsonObject.put("isBackUp",true); jsonObject.put("isBackUp", true);
return jsonObject; return jsonObject;
} }
Tools.sleep(500L); Tools.sleep(500L);
...@@ -1442,15 +1430,51 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1442,15 +1430,51 @@ public class MarkDataServiceImpl implements MarkDataService {
return channelResultList; return channelResultList;
} }
@Override
public String getLastMarkUrl(String projectId, String linkedGroupId, String contendId, String platform, String realSource, String source) {
try {
EsClientDao.SearchHelper searchHelper = EsClientDao.createSearchHelper();
BoolQueryBuilder query = projectLinkedGroupContendIdQuery(projectId, linkedGroupId, contendId);
query.must(QueryBuilders.termQuery("platform", platform));
query.must(QueryBuilders.termQuery("real_source", realSource));
query.must(QueryBuilders.termQuery("source", source));
searchHelper.setQuery(query);
searchHelper.setSort(SortBuilders.fieldSort("time").order(SortOrder.DESC));
searchHelper.setSize(1);
searchHelper.setFetchSource(new String[]{"url", "question_url", "answer_url"});
SearchHits searchHits = esClientDao.searchHits(searchHelper);
if (0 == searchHits.getTotalHits().value) {
return null;
}
return getUrl(searchHits.getAt(0).getSourceAsMap());
} catch (IOException e) {
return null;
}
}
private static String getUrl(Map<String, Object> map) {
JSONObject json = new JSONObject(map);
String url = json.getString("url");
// 如果url为空,则查询QA类型url字段
if (null == url) {
url = json.getString("answer_url");
}
if (null == url) {
url = json.getString("question_url");
}
return url;
}
/** /**
* 获取传播图谱 * 获取传播图谱
*
* @param projectId 项目ID * @param projectId 项目ID
* @param linkedGroupId 关联组Id * @param linkedGroupId 关联组Id
* @param contendId 竞品ID * @param contendId 竞品ID
* @param dayList 以天为最小单位分割的时间 * @param dayList 以天为最小单位分割的时间
* @return * @return
*/ */
private List<LineVO> getArticleSpread(String projectId, String linkedGroupId, String contendId, List<Map<String, Long>> dayList){ private List<LineVO> getArticleSpread(String projectId, String linkedGroupId, String contendId, List<Map<String, Long>> dayList) {
List<LineVO> lineList = new ArrayList<>(dayList.size()); List<LineVO> lineList = new ArrayList<>(dayList.size());
dayList.forEach(day -> { dayList.forEach(day -> {
LineVO lineVO = new LineVO(); LineVO lineVO = new LineVO();
...@@ -1500,7 +1524,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1500,7 +1524,7 @@ public class MarkDataServiceImpl implements MarkDataService {
Long[] timeRangeMonth = commonService.getTimeRangeMonth(); Long[] timeRangeMonth = commonService.getTimeRangeMonth();
dto.setEndTime(timeRangeMonth[1]); dto.setEndTime(timeRangeMonth[1]);
dto.setStartTime(timeRangeMonth[0]); dto.setStartTime(timeRangeMonth[0]);
}else{ } else {
dto.setStartTime(Tools.truncDate(dto.getStartTime(), Constant.DAY_PATTERN)); dto.setStartTime(Tools.truncDate(dto.getStartTime(), Constant.DAY_PATTERN));
dto.setEndTime(Tools.truncDate(dto.getEndTime(), Constant.DAY_PATTERN)); dto.setEndTime(Tools.truncDate(dto.getEndTime(), Constant.DAY_PATTERN));
} }
...@@ -1743,9 +1767,7 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1743,9 +1767,7 @@ public class MarkDataServiceImpl implements MarkDataService {
} }
protected static BoolQueryBuilder projectLinkedGroupContendIdQuery(String projectId, String linkedGroupId, String contendId) { protected static BoolQueryBuilder projectLinkedGroupContendIdQuery(String projectId, String linkedGroupId, String contendId) {
return QueryBuilders.boolQuery().must(QueryBuilders.termQuery("brandkbs_cache_maps.key.keyword", Tools.concat(projectId, linkedGroupId, contendId))) ; return EsQueryTools.assembleCacheMapsQuery(projectId, linkedGroupId, contendId);
// TODO 上线后开启
// return EsQueryTools.assembleCacheMapsQuery(projectId, linkedGroupId, contendId);
} }
private List<MarkFlowEntity> getMarkFlowEntity(MarkSearchDTO markSearchDTO, SearchHits searchHits) { private List<MarkFlowEntity> getMarkFlowEntity(MarkSearchDTO markSearchDTO, SearchHits searchHits) {
......
...@@ -319,6 +319,9 @@ public class Tools { ...@@ -319,6 +319,9 @@ public class Tools {
} }
public static BaseMap getBaseFromEsMap(Map<String, Object> map, boolean cacheSource) { public static BaseMap getBaseFromEsMap(Map<String, Object> map, boolean cacheSource) {
if (null == map) {
return new BaseMap();
}
// 设置source,forward,time // 设置source,forward,time
BaseMap res = Tools.convertMap(map, BaseMap.class); BaseMap res = Tools.convertMap(map, BaseMap.class);
if (cacheSource) { if (cacheSource) {
......
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