Commit fc95fd23 by shenjunjie

2022/8/30 17:39

parent c4f8d36e
......@@ -7,7 +7,9 @@ import com.zhiwei.brandkbs2.auth.Auth;
import com.zhiwei.brandkbs2.config.Constant;
import com.zhiwei.brandkbs2.enmus.RoleEnum;
import com.zhiwei.brandkbs2.model.ResponseResult;
import com.zhiwei.brandkbs2.pojo.dto.MarkSearchDTO;
import com.zhiwei.brandkbs2.pojo.dto.SearchFilterDTO;
import com.zhiwei.brandkbs2.service.ChannelService;
import com.zhiwei.brandkbs2.service.MarkDataService;
import com.zhiwei.brandkbs2.util.Tools;
import io.swagger.annotations.Api;
......@@ -23,17 +25,18 @@ import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* @author cjz
* @ClassName AppSearchController
* @Description 提供前台搜索相关功能
* @author cjz
* @date 2022-08-15 16:17
*/
@RestController
@RequestMapping("/app/search")
@Api(tags = "前台搜索相关接口",description = "提供搜索相关功能")
@Api(tags = "前台搜索相关接口", description = "提供搜索相关功能")
@Auth(role = RoleEnum.CUSTOMER)
public class AppSearchController {
@Autowired
......@@ -51,26 +54,29 @@ public class AppSearchController {
@Resource(name = "markDataServiceImpl")
MarkDataService markDataService;
@Resource(name = "channelServiceImpl")
ChannelService channelService;
@ApiOperation("搜索-查热点")
@GetMapping("/hot/list")
public ResponseResult searchHotList(@RequestParam(value = "pageSize",defaultValue ="10") Integer limit,
@RequestParam(value = "page",defaultValue ="1") Integer page,
@RequestParam(value = "type",defaultValue = "weibo") String type,
@RequestParam(value = "word") String word){
public ResponseResult searchHotList(@RequestParam(value = "pageSize", defaultValue = "10") Integer limit,
@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "type", defaultValue = "weibo") String type,
@RequestParam(value = "word") String word) {
ResponseEntity<JSONObject> jsonObjectResponseEntity = restTemplate.getForEntity(trendsSearchUrl, JSONObject.class, limit, page, type, word);
JSONObject result = jsonObjectResponseEntity.getBody();
if(Objects.nonNull(result)){
if (Objects.nonNull(result)) {
return ResponseResult.success(result);
}else{
} else {
return ResponseResult.failure("响应超时");
}
}
@ApiOperation("搜索-查危机")
@GetMapping("/crisisSearch")
public ResponseResult crisisSearch(@RequestParam(value = "page",defaultValue = "1") Integer page,
@RequestParam(value = "pageSize",defaultValue = "3") Integer pageSize,
@RequestParam("keyword") String keyword){
public ResponseResult crisisSearch(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize,
@RequestParam("keyword") String keyword) {
ResponseEntity<String> responseEntity = restTemplate.getForEntity(crisisSearchUrl, String.class, page, pageSize, keyword);
Object result = JSON.parseObject(responseEntity.getBody()).get("data");
return ResponseResult.success(result);
......@@ -79,7 +85,7 @@ public class AppSearchController {
@ApiOperation("搜索-全网事件库-查事件")
@GetMapping("/getWholeNetworkEvents")
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();
ResponseEntity<String> responseEntity = restTemplate.getForEntity(getEfSearchUrl, String.class, name, page);
JSONObject result = JSON.parseObject(responseEntity.getBody());
......@@ -88,9 +94,9 @@ public class AppSearchController {
@ApiOperation("搜索-全网搜")
@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();
if (time > dto.getStartTime()){
if (time > dto.getStartTime()) {
return ResponseResult.failure("仅能搜索近3个月内信息");
}
Period periodDay = new Period(dto.getStartTime(), dto.getEndTime(), PeriodType.days());
......@@ -99,4 +105,49 @@ public class AppSearchController {
}
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;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
......@@ -40,9 +41,14 @@ public enum ImportantChannelEnum {
*/
QITA("其他");
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) {
this.state = state;
}
......
......@@ -71,10 +71,6 @@ public class EventData extends AbstractBaseMongo {
*/
private String projectId;
/**
* 关联项目组
*/
private String linkedGroupId;
/**
* 品牌ID
*/
private String contendId;
......
......@@ -251,4 +251,13 @@ public interface ChannelService {
* @param 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 {
/**
* 竞品库-舆情导出
*
* @param markSearchDTO 标注数据搜索传输类
* @return
*/
......@@ -209,6 +210,7 @@ public interface MarkDataService {
/**
* 搜索-全网搜
*
* @param searchFilterDTO
* @return
*/
......@@ -262,4 +264,6 @@ public interface MarkDataService {
*/
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;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelEventDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportAppChannelArticleDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportChannelDTO;
import com.zhiwei.brandkbs2.enmus.ChannelEmotion;
import com.zhiwei.brandkbs2.enmus.EmotionEnum;
import com.zhiwei.brandkbs2.enmus.EventTagEnum;
import com.zhiwei.brandkbs2.enmus.ExperienceEnum;
import com.zhiwei.brandkbs2.enmus.*;
import com.zhiwei.brandkbs2.es.ChannelEsDao;
import com.zhiwei.brandkbs2.es.EsClientDao;
import com.zhiwei.brandkbs2.es.EsQueryTools;
......@@ -28,6 +25,7 @@ import com.zhiwei.brandkbs2.pojo.vo.ChannelListVO;
import com.zhiwei.brandkbs2.pojo.vo.PageVO;
import com.zhiwei.brandkbs2.service.ChannelService;
import com.zhiwei.brandkbs2.service.CommonService;
import com.zhiwei.brandkbs2.service.MarkDataService;
import com.zhiwei.brandkbs2.service.ProjectService;
import com.zhiwei.brandkbs2.util.MongoUtil;
import com.zhiwei.brandkbs2.util.Tools;
......@@ -101,6 +99,9 @@ public class ChannelServiceImpl implements ChannelService {
@Resource(name = "commonServiceImpl")
CommonService commonService;
@Resource(name = "markDataServiceImpl")
MarkDataService markDataService;
@Resource(name = "mongoUtil")
MongoUtil mongoUtil;
......@@ -774,6 +775,77 @@ public class ChannelServiceImpl implements ChannelService {
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;
import com.zhiwei.brandkbs2.easyexcel.listener.EventFileListener;
import com.zhiwei.brandkbs2.enmus.EmotionEnum;
import com.zhiwei.brandkbs2.enmus.EventTagEnum;
import com.zhiwei.brandkbs2.enmus.ImportantChannelEnum;
import com.zhiwei.brandkbs2.exception.ExceptionCast;
import com.zhiwei.brandkbs2.listener.ApplicationProjectListener;
import com.zhiwei.brandkbs2.model.CommonCodeEnum;
......@@ -111,11 +112,6 @@ public class EventServiceImpl implements EventService {
@Resource
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]");
@Override
......@@ -595,7 +591,7 @@ public class EventServiceImpl implements EventService {
Event event = getEventById(eventId);
Query query = Query.query(Criteria.where("eventId").is(eventId));
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());
......
......@@ -319,6 +319,9 @@ public class Tools {
}
public static BaseMap getBaseFromEsMap(Map<String, Object> map, boolean cacheSource) {
if (null == map) {
return new BaseMap();
}
// 设置source,forward,time
BaseMap res = Tools.convertMap(map, BaseMap.class);
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