Commit d396fa92 by shenjunjie

Merge branch 'feature' into 'dev'

Feature

See merge request !49
parents 6b198283 9ee50458
......@@ -42,7 +42,7 @@ public class BehaviorController extends BaseController {
@ApiOperation("分页查询用户行为列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int"),
@ApiImplicitParam(name = "size", value = "每页记录数", defaultValue = "10", paramType = "query", dataType = "int"),
@ApiImplicitParam(name = "pageSize", value = "每页记录数", defaultValue = "10", paramType = "query", dataType = "int"),
@ApiImplicitParam(name = "startTime", value = "开始时间", required = true, paramType = "query", dataType = "long"),
@ApiImplicitParam(name = "endTime", value = "结束时间", required = true, paramType = "query", dataType = "long"),
@ApiImplicitParam(name = "behavior", value = "行为所属(前台=false,后台=true)", defaultValue = "true", paramType = "query", dataType =
......@@ -51,12 +51,12 @@ public class BehaviorController extends BaseController {
})
@GetMapping("/list")
public ResponseResult findList(@RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "size", defaultValue = "10") int size,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
@RequestParam("startTime") long startTime,
@RequestParam("endTime") long endTime,
@RequestParam(value = "behavior", defaultValue = "true") boolean behavior,
@RequestParam(value = "keyword", defaultValue = "") String keyword) {
return ResponseResult.success(behaviorService.findBehaviorList(page, size, startTime, endTime, behavior, keyword));
return ResponseResult.success(behaviorService.findBehaviorList(page, pageSize, startTime, endTime, behavior, keyword));
}
@ApiOperation("导出用户行为列表")
......
......@@ -19,29 +19,29 @@ import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* @author cjz
* @ClassName AppCrisisController
* @Description 提供前台危机相关信息展示
* @author cjz
* @date 2022-07-19 16:17
*/
@RestController
@RequestMapping("/app/hot")
@Api(tags = "前台热点库",description = "提供前台热点相关信息展示")
@Api(tags = "前台热点库", description = "提供前台热点相关信息展示")
@Auth(role = RoleEnum.CUSTOMER)
public class AppHotController extends BaseController {
private static final long ONE_HOUR = 1L;
......@@ -63,6 +63,10 @@ public class AppHotController extends BaseController {
@Autowired
private MarkDataService markDataService;
@Resource(name = "esSearchExecutor")
ThreadPoolTaskExecutor executor;
/**
* weibo 热搜
* weibo-topic 话题
......@@ -74,19 +78,19 @@ public class AppHotController extends BaseController {
*/
@ApiOperation("热点库-列表")
@GetMapping("/getHotList")
public ResponseResult getHotList(@RequestParam(value = "sortType",defaultValue = "realTime") String sortType,
@RequestParam(value = "type",defaultValue = "weibo") String type){
public ResponseResult getHotList(@RequestParam(value = "sortType", defaultValue = "realTime") String sortType,
@RequestParam(value = "type", defaultValue = "weibo") String type) {
ResponseEntity<JSONObject> jsonObjectResponseEntity = restTemplate.getForEntity(trendsListUrl, JSONObject.class, sortType, type);
Object data = jsonObjectResponseEntity.getBody().get("data");
String redisKey = RedisKeyPrefix.HOT_LIST+type;
String redisKey = RedisKeyPrefix.HOT_LIST + type;
String result = redisUtil.get(redisKey);
//当舆论场崩溃时从缓存里获取
if(Objects.nonNull(data)){
if (Objects.nonNull(data)) {
if (Objects.isNull(result)) {
redisUtil.setExpire(redisKey, JSON.toJSONString(data), ONE_HOUR, TimeUnit.HOURS);
}
return ResponseResult.success(data);
}else{
} else {
if (Objects.nonNull(result)) {
return ResponseResult.success(result);
}
......@@ -96,19 +100,19 @@ public class AppHotController extends BaseController {
@ApiOperation("热点库-热点榜单")
@GetMapping("/hot")
public ResponseResult hot(){
ResponseEntity<String> responseEntity = restTemplate.getForEntity(longTimeInListSearchUrl, String.class,"weibo");
public ResponseResult hot() {
ResponseEntity<String> responseEntity = restTemplate.getForEntity(longTimeInListSearchUrl, String.class, "weibo");
JSONObject jsonObject = JSON.parseObject(responseEntity.getBody());
String redisKey = RedisKeyPrefix.HOT_RANK_LIST;
String result = redisUtil.get(redisKey);
//当舆论场崩溃时从缓存里获取
if(jsonObject.getBoolean("state")){
if (jsonObject.getBoolean("state")) {
Object data = jsonObject.get("data");
if (Objects.isNull(result)) {
redisUtil.setExpire(redisKey, JSON.toJSONString(data), ONE_HOUR, TimeUnit.HOURS);
}
return ResponseResult.success(data);
}else{
} else {
if (Objects.nonNull(result)) {
return ResponseResult.success(result);
}
......@@ -129,19 +133,22 @@ public class AppHotController extends BaseController {
markDataService.getMarkTopTitle(startDate.getTime(), endDate.getTime(), null, projectId, linkedGroupId, Constant.PRIMARY_CONTEND_ID, size, include);
List<JSONObject> resultList = markTopTitleList.stream().map(map -> {
JSONObject resultJsonObject = new JSONObject();
resultJsonObject.put("title", map.getKey());
resultJsonObject.put("num", map.getValue());
JSONObject json = new JSONObject();
json.put("title", map.getKey());
json.put("num", map.getValue());
return json;
}).collect(Collectors.toList());
CompletableFuture.allOf(resultList.stream().map(json -> CompletableFuture.supplyAsync(() -> {
try {
BaseMap firstArticle = markDataService.getFirstArticle(startDate.getTime(), endDate.getTime(), map.getKey(), projectId, linkedGroupId, Constant.PRIMARY_CONTEND_ID, include);
resultJsonObject.put("content", firstArticle.getContent());
resultJsonObject.put("url", firstArticle.getUrl());
resultJsonObject.put("realSource", firstArticle.getRealSource());
resultJsonObject.put("emotion", firstArticle.getEmotion());
BaseMap firstArticle = markDataService.getFirstArticle(startDate.getTime(), endDate.getTime(), json.getString("title"), projectId, linkedGroupId, Constant.PRIMARY_CONTEND_ID, include);
json.put("content", firstArticle.getContent());
json.put("url", firstArticle.getUrl());
json.put("realSource", firstArticle.getRealSource());
json.put("emotion", firstArticle.getEmotion());
} catch (IOException ignored) {
}
return resultJsonObject;
}).collect(Collectors.toList());
return null;
}, executor)).toArray(CompletableFuture[]::new)).join();
return ResponseResult.success(resultList);
}
}
......@@ -26,9 +26,9 @@ public class Behavior extends AbstractBaseMongo {
*/
private String projectId;
/**
* nickName
* nickname
*/
private String nickName;
private String nickname;
/**
* IP地址
*/
......
......@@ -23,7 +23,7 @@ public class BehaviorVO {
/**
* 用户ID
*/
private String nickname;
private String nickName;
/**
* IP地址
*/
......@@ -46,10 +46,9 @@ public class BehaviorVO {
*/
private Integer roleId;
public static BehaviorVO createFromBehavior(Behavior behavior, String nickname, Integer roleId) {
public static BehaviorVO createFromBehavior(Behavior behavior, Integer roleId) {
BehaviorVO behaviorVO = Tools.convertMap(behavior, BehaviorVO.class);
// 补充nickname和role
behaviorVO.setNickname(nickname);
// 补充role
behaviorVO.setRoleId(roleId);
return behaviorVO;
}
......
......@@ -13,7 +13,6 @@ import com.zhiwei.brandkbs2.service.BehaviorService;
import com.zhiwei.brandkbs2.util.MongoUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.data.mongodb.core.query.Criteria;
......@@ -26,7 +25,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
......@@ -78,7 +76,8 @@ public class BehaviorServiceImpl implements BehaviorService {
Query query = new Query();
query.addCriteria(Criteria.where("cTime").gte(startTime).lt(endTime).and("backstage").is(backstage));
if (StringUtils.isNotEmpty(nickname)) {
List<User> userList = userDao.findList(Query.query(Criteria.where("nickname").regex(Pattern.compile("^.*" + nickname + ".*$", Pattern.CASE_INSENSITIVE))));
userDao.addKeywordFuzz(query,nickname,"nickname");
List<User> userList = userDao.findList(query);
// 根据nickname未查询
if (CollectionUtils.isEmpty(userList)) {
return PageVO.createPageVo(0, page, 0, size, Collections.emptyList());
......@@ -90,8 +89,8 @@ public class BehaviorServiceImpl implements BehaviorService {
mongoUtil.start(page, size, query);
List<Behavior> behaviorList = behaviorDao.findList(query, collectionNames);
List<BehaviorVO> resList = behaviorList.stream().map(behavior -> {
Pair<String, Integer> nicknameAndRoleId = getNicknameAndRoleId(behavior.getUserId(), behavior.getProjectId());
return BehaviorVO.createFromBehavior(behavior, nicknameAndRoleId.getLeft(), nicknameAndRoleId.getRight());
Integer roleId = getRoleId(behavior.getUserId(), behavior.getProjectId());
return BehaviorVO.createFromBehavior(behavior, roleId);
}).collect(Collectors.toList());
MongoUtil.PageHelper<BehaviorVO> pageHelper = mongoUtil.pageHelperT(count, resList);
return PageVO.createPageVo(pageHelper, resList);
......@@ -107,19 +106,19 @@ public class BehaviorServiceImpl implements BehaviorService {
List<ExportBehaviorDTO> resList = new ArrayList<>(behaviorList.size());
behaviorList.forEach(behavior -> {
ExportBehaviorDTO exportBehaviorDTO = new ExportBehaviorDTO();
Pair<String, Integer> nicknameAndRoleId = getNicknameAndRoleId(behavior.getUserId(), behavior.getProjectId());
exportBehaviorDTO.setNickname(nicknameAndRoleId.getLeft());
Integer roleId = getRoleId(behavior.getUserId(), behavior.getProjectId());
exportBehaviorDTO.setNickname(behavior.getNickname());
exportBehaviorDTO.setIp(behavior.getIp());
exportBehaviorDTO.setTime(new Date(behavior.getCTime()));
exportBehaviorDTO.setController(behavior.getController());
exportBehaviorDTO.setMethod(behavior.getMethod());
exportBehaviorDTO.setRole(RoleEnum.getNameByState(nicknameAndRoleId.getRight()));
exportBehaviorDTO.setRole(RoleEnum.getNameByState(roleId));
resList.add(exportBehaviorDTO);
});
return resList;
}
private Pair<String, Integer> getNicknameAndRoleId(String userId, String projectId) {
private Integer getRoleId(String userId, String projectId) {
User user = userDao.findOneById(userId);
Integer roleId = -1;
if (user.isSuperAdmin()) {
......@@ -130,6 +129,6 @@ public class BehaviorServiceImpl implements BehaviorService {
roleId = collect.get(0).getRoleId();
}
}
return Pair.of(user.getNickname(), roleId);
return roleId;
}
}
......@@ -593,8 +593,7 @@ public class MarkDataServiceImpl implements MarkDataService {
// keyword
if (StringUtils.isNotEmpty(dto.getKeyword())) {
// Query
String[] fieldSearch = "仅标题".equals(dto.getSearchField()) ? new String[]{GenericAttribute.ES_IND_TITLE} :
new String[]{GenericAttribute.ES_IND_FULL_TEXT};
String[] fieldSearch = "仅标题".equals(dto.getSearchField()) ? new String[]{GenericAttribute.ES_IND_TITLE} : new String[]{GenericAttribute.ES_IND_FULL_TEXT};
postFilter.must(EsQueryTools.assembleNormalKeywordQuery(dto.getKeyword(), fieldSearch));
}
// sourceKeyword
......@@ -812,7 +811,7 @@ public class MarkDataServiceImpl implements MarkDataService {
// TODO script使用
// Script script = new Script("params._source.ind_title");
// TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("titles").script(script).order(BucketOrder.count(false)).size(60000);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("titles").field("agg_title.keyword").size(size * 10);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("titles").field("agg_title.keyword").size(size + 1);
// query
BoolQueryBuilder query;
if (include) {
......@@ -1001,8 +1000,7 @@ public class MarkDataServiceImpl implements MarkDataService {
// keyword
if (StringUtils.isNotEmpty(dto.getKeyword())) {
// Query
String[] fieldSearch = "仅标题".equals(dto.getSearchField()) ? new String[]{GenericAttribute.ES_IND_TITLE} :
new String[]{GenericAttribute.ES_IND_FULL_TEXT};
String[] fieldSearch = "仅标题".equals(dto.getSearchField()) ? new String[]{GenericAttribute.ES_IND_TITLE} : new String[]{GenericAttribute.ES_IND_FULL_TEXT};
postFilter.must(EsQueryTools.assembleNormalKeywordQuery(dto.getKeyword(), fieldSearch));
}
// sourceKeyword
......@@ -1785,7 +1783,7 @@ public class MarkDataServiceImpl implements MarkDataService {
EsClientDao.SearchHelper searchHelper = EsClientDao.createSearchHelper();
BoolQueryBuilder postFilter = projectLinkedGroupContendIdQuery(projectId, linkedGroupId, "0");
postFilter.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime));
postFilter.must(EsQueryTools.cacheMapsNestedQuery(QueryBuilders.existsQuery("brandkbs_cache_maps.channel_emotion")));
postFilter.mustNot(EsQueryTools.cacheMapsNestedQuery(QueryBuilders.termQuery("brandkbs_cache_maps.channel_emotion", 0)));
searchHelper.setPostFilter(postFilter);
searchHelper.setFetchSource(new String[]{GenericAttribute.ES_BRANDKBS_CACHE_MAPS});
List<SearchResponse> searchResponses = esClientDao.searchScrollResponse(searchHelper);
......@@ -1803,9 +1801,9 @@ public class MarkDataServiceImpl implements MarkDataService {
}
}
long total = emotionMap.values().stream().mapToInt(AtomicInteger::getAndIncrement).sum();
channelEmotionResult.put("positivePercent", (double) emotionMap.get(ChannelEmotion.POSITIVE.getState()).get() / total);
channelEmotionResult.put("negativePercent", (double) emotionMap.get(ChannelEmotion.NEGATIVE.getState()).get() / total);
channelEmotionResult.put("neutralPercent", (double) emotionMap.get(ChannelEmotion.NEUTRAL.getState()).get() / total);
channelEmotionResult.put("positivePercent", total == 0 ? 0 : (double) emotionMap.get(ChannelEmotion.POSITIVE.getState()).get() / total);
channelEmotionResult.put("negativePercent", total == 0 ? 0 : (double) emotionMap.get(ChannelEmotion.NEGATIVE.getState()).get() / total);
channelEmotionResult.put("neutralPercent", total == 0 ? 0 : (double) emotionMap.get(ChannelEmotion.NEUTRAL.getState()).get() / total);
return channelEmotionResult;
}
......@@ -1822,9 +1820,7 @@ public class MarkDataServiceImpl implements MarkDataService {
mediaTypeMap.put(channelEnum.name().toLowerCase() + "Percent", count);
}
long total = mediaTypeMap.values().stream().mapToLong(v -> v).sum();
mediaTypeMap.forEach((percentName, size) -> {
mediaTypePercent.put(percentName, (double) size / total == 0 ? 1 : total);
});
mediaTypePercent.putAll(mediaTypeMap);
return mediaTypePercent;
}
......
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