Commit 048694ba by shenjunjie

Merge branch 'feature' into 'dev'

Feature

See merge request !12
parents d6139789 57631a16
......@@ -29,6 +29,13 @@ public class GenericAttribute {
*/
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
**/
public static final String ES_ROOT_SOURCE = "root_source";
......
......@@ -25,6 +25,7 @@ public class RedisKeyPrefix {
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 AGGREE_RESULT_CACHE = "BRANDKBS:AGGREE_CACHE:";
/**
* 项目简报报相关缓存KEY
......
......@@ -10,6 +10,8 @@ import org.apache.commons.lang3.time.FastDateFormat;
*/
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 DAY_PATTERN = "yyyy-MM-dd";
......
......@@ -2,8 +2,10 @@ package com.zhiwei.brandkbs2.controller.app;
import com.zhiwei.brandkbs2.auth.Auth;
import com.zhiwei.brandkbs2.controller.BaseController;
import com.zhiwei.brandkbs2.easyexcel.EasyExcelUtil;
import com.zhiwei.brandkbs2.enmus.RoleEnum;
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.ReportDTO;
import com.zhiwei.brandkbs2.pojo.dto.ReportSearchDTO;
......@@ -14,9 +16,11 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @author sjj
......@@ -46,17 +50,37 @@ public class AppArticleController extends BaseController {
}
@ApiOperation("舆情列表-生成聚合")
@PostMapping("/mark/agree")
@PostMapping("/mark/aggree")
public ResponseResult generateYuqingMarkAggreeList(@RequestBody MarkSearchDTO 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("舆情列表-搜索条件")
@GetMapping("/mark/list/criteria")
public ResponseResult getYuqingMark(@RequestParam(required = false) String 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("舆情分析-舆情概览")
@ApiImplicitParams({@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "long"), @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "long")})
@GetMapping("/analyze/summary")
......
......@@ -19,7 +19,7 @@ import javax.annotation.Resource;
*/
@RestController
@RequestMapping("/app/global")
@Api(tags = "全局通用接口")
@Api(tags = "全局通用接口", description = "提供全局通用相关")
@Auth(role = RoleEnum.CUSTOMER)
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;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* @ClassName: UserProjectOldImpl
* @Description 用户项目关联旧表
......@@ -28,7 +26,7 @@ public class UserProjectOldDaoImpl extends BaseMongoDaoImpl<UserProjectOldDaoImp
public static class UserProjectOld extends AbstractBaseMongo{
String userId;
Integer roleId;
Date expiredTime;
Long expiredTime;
Integer exportAmount;
String projectName;
}
......
......@@ -25,12 +25,12 @@ public class EventFileListener extends AnalysisEventListener<UploadEventDTO> {
* 储存解析数据集合
*/
private final List<UploadEventDTO> datas = new ArrayList<>(BATCH_COUNT);
private final EventService EventService;
private final EventService eventService;
private final String projectId;
private final String linkedGroupId;
public EventFileListener(EventService EventService, String projectId, String linkedGroupId) {
this.EventService = EventService;
public EventFileListener(EventService eventService, String projectId, String linkedGroupId) {
this.eventService = eventService;
this.projectId = projectId;
this.linkedGroupId = linkedGroupId;
}
......@@ -65,6 +65,6 @@ public class EventFileListener extends AnalysisEventListener<UploadEventDTO> {
* 保存更新事件信息逻辑
*/
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;
import com.zhiwei.base.category.ClassD;
import lombok.Getter;
import lombok.Setter;
......@@ -14,6 +15,11 @@ import lombok.Setter;
public class BaseMap {
/**
* typeB
*/
private ClassD.TypeB typeB;
/**
* url
*/
private String url;
......
......@@ -34,11 +34,6 @@ public class Channel extends ChannelIndex {
private String imgUrl;
/**
* 渠道标签
*/
private String tag;
/**
* 发布稿件id列表
*/
private LinkedHashSet<String> articleIds;
......@@ -99,10 +94,11 @@ public class Channel extends ChannelIndex {
channel.setPlatform(channelIndex.getPlatform());
channel.setRealSource(channelIndex.getRealSource());
channel.setSource(channelIndex.getSource());
channel.setLastTime(channelRecord.getLastTime());
channel.setArticleIds(channelRecord.getArticleIds());
// fid 用来便捷搜索
channel.setFid(channelIndex.getFid());
channel.setLastTime(channelRecord.getLastTime());
channel.setArticleIds(channelRecord.getArticleIds());
// TODO 调性随机分配
double random = Math.random();
if (random < 0.3) {
......
......@@ -15,6 +15,7 @@ import lombok.Setter;
import org.apache.commons.lang3.ObjectUtils;
import org.elasticsearch.search.SearchHit;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
......@@ -28,7 +29,7 @@ import java.util.Objects;
@Getter
@Setter
@NoArgsConstructor
public class MarkFlowEntity {
public class MarkFlowEntity implements Serializable {
/**
* 消息类型
......@@ -47,16 +48,29 @@ public class MarkFlowEntity {
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) {
entity.getType().put("fold", true);
entity.getType().put("size", entities.size());
// info内容
if (null == entity.getInfo()) {
entity.setInfo(new JSONObject());
}
entity.getInfo().put("foldInfo", entities);
}
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
*
......
......@@ -3,6 +3,7 @@ package com.zhiwei.brandkbs2.pojo;
import com.zhiwei.brandkbs2.enmus.RoleEnum;
import com.zhiwei.brandkbs2.pojo.dto.UserDTO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.time.DateUtils;
......@@ -17,6 +18,7 @@ import java.util.Date;
*/
@Setter
@Getter
@NoArgsConstructor
public class UserRole {
// 默认绑定阿里项目
......@@ -51,10 +53,10 @@ public class UserRole {
*/
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.roleId = roleId;
this.expiredTime = expiredTime.getTime();
this.expiredTime = expiredTime;
this.exportAmount = exportAmount;
}
......@@ -63,7 +65,7 @@ public class UserRole {
if (null != userDTO.getExportAmount() && userDTO.getExportAmount() < MAX_EXPORT_LIMIT) {
exportAmount = userDTO.getExportAmount();
}
Date expiredTime = null;
Long expiredTime = null;
//当创建用户为客户时,添加过期时间
if (userDTO.getRoleId() == RoleEnum.CUSTOMER.getState()) {
Date date = new Date(userDTO.getExpiredTime());
......@@ -72,13 +74,13 @@ public class UserRole {
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
expiredTime = calendar.getTime();
expiredTime = calendar.getTime().getTime();
}
return new UserRole(userDTO.getProjectId(), userDTO.getRoleId(), expiredTime, exportAmount);
}
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;
@ToString
@ApiModel("标注数据搜索传输类")
public class MarkSearchDTO {
/**
* 聚合id
*/
@ApiModelProperty("聚合id")
private String aggreeId;
/**
* 页码
*/
......@@ -25,6 +31,8 @@ public class MarkSearchDTO {
private int pageSize;
// postFilter
@ApiModelProperty(value = "项目id")
private String projectId;
/**
* 关联项目组id
*/
......@@ -102,6 +110,6 @@ public class MarkSearchDTO {
* 是否去重
*/
@ApiModelProperty(value = "是否去重")
private boolean duplicate;
private boolean fold;
}
......@@ -2,8 +2,10 @@ package com.zhiwei.brandkbs2.service;
import com.alibaba.fastjson.JSONObject;
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.vo.PageVO;
import org.apache.commons.lang3.tuple.Pair;
import java.util.List;
......@@ -22,6 +24,12 @@ public interface MarkDataService {
PageVO<MarkFlowEntity> getYuqingMarkList(MarkSearchDTO markSearchDTO);
/**
* @param markSearchDTO 标注数据搜索传输类
* @return 返回结果
*/
Pair<String,List<ExportAppYuqingDTO>> downloadYuqingMarkList(MarkSearchDTO markSearchDTO);
/**
* 生成聚合列表并返回id
*
* @return 聚合id
......@@ -29,6 +37,21 @@ public interface MarkDataService {
String generateYuqingMarkAggreeList(MarkSearchDTO markSearchDTO);
/**
* 获取聚合进度结果
* @param id 聚合id
* @return 进度值
*/
String getYuqingMarkAggreeProgress(String id);
/**
* 获取聚合结果列表
*
* @param markSearchDTO 搜索实体
* @return 标注消息流列表
*/
PageVO<MarkFlowEntity> getYuqingMarkAggreeList(MarkSearchDTO markSearchDTO);
/**
* 舆情标注数据搜索条件
*/
JSONObject getYuqingMarkCriteria(String linkedGroup);
......
......@@ -18,4 +18,9 @@ public interface TaskService{
*/
void generateReportAndSend();
/**
* 清理过期聚合任务
*/
void cleanAggreeTask();
}
package com.zhiwei.brandkbs2.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.brandkbs2.dao.ChannelDao;
import com.zhiwei.brandkbs2.dao.ChannelLabelDao;
import com.zhiwei.brandkbs2.dao.EventDao;
import com.zhiwei.brandkbs2.dao.EventDataDao;
import com.zhiwei.brandkbs2.dao.*;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelArticleDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportAdminChannelEventDTO;
import com.zhiwei.brandkbs2.easyexcel.dto.ExportChannelDTO;
......@@ -55,12 +52,14 @@ public class ChannelServiceImpl implements ChannelService {
@Resource(name = "esClientDao")
EsClientDao esClientDao;
@Resource(name = "channelTagDao")
ChannelTagDao channelTagDao;
@Resource(name = "mongoUtil")
MongoUtil mongoUtil;
@Override
public PageVO<JSONObject> findChannelList(int page, int size, String linkedGroupId, String emotion, String platform, Boolean show,
String keyword, String sorter) {
public PageVO<JSONObject> findChannelList(int page, int size, String linkedGroupId, String emotion, String platform, Boolean show, String keyword, String sorter) {
Query query = channelListQuery(linkedGroupId, show, emotion, platform, keyword, sorter);
long total = channelDao.count(query);
// 开启分页
......@@ -80,7 +79,7 @@ public class ChannelServiceImpl implements ChannelService {
result.put("lastTime", channel.getLastTime());
result.put("show", channel.isShow());
result.put("imgUrl", channel.getImgUrl());
result.put("tag", channel.getTag());
result.put("tag", channelTagDao.getTagByChannelName(channel.getSource()));
return result;
}).collect(Collectors.toList());
MongoUtil.PageHelper<JSONObject> pageHelper = mongoUtil.pageHelper(total, resList);
......@@ -100,7 +99,7 @@ public class ChannelServiceImpl implements ChannelService {
JSONObject json = new JSONObject();
BaseMap baseMap = Tools.getBaseFromEsMap(sourceJson);
json.put("id", sourceJson.get("id"));
json.put("title",baseMap.getTitleNullOptionalContent());
json.put("title", baseMap.getTitleNullOptionalContent());
json.put("url", baseMap.getUrl());
json.put("time", new Date(baseMap.getTime()));
json.put("emotion", baseMap.getEmotion());
......@@ -170,7 +169,7 @@ public class ChannelServiceImpl implements ChannelService {
jsonObject.put("realSource", channel.getRealSource());
jsonObject.put("source", channel.getSource());
jsonObject.put("imgUrl", channel.getImgUrl());
jsonObject.put("tag", channel.getTag());
jsonObject.put("tag", channelTagDao.getTagByChannelName(channel.getSource()));
return jsonObject;
}
......
......@@ -88,7 +88,7 @@ public class ReportServiceImpl implements ReportService {
@Override
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));
}
......@@ -158,7 +158,7 @@ public class ReportServiceImpl implements ReportService {
}
JSONObject all = new JSONObject();
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);
return result;
}
......@@ -220,7 +220,18 @@ public class ReportServiceImpl implements ReportService {
@Override
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"});
mongoUtil.start(reportSearch.getPage(), reportSearch.getPageSize(), query);
// 添加排序
......
package com.zhiwei.brandkbs2.service.impl;
import com.zhiwei.brandkbs2.config.Constant;
import com.zhiwei.brandkbs2.dao.BrandkbsTaskDao;
import com.zhiwei.brandkbs2.dao.ChannelDao;
import com.zhiwei.brandkbs2.dao.EventDataDao;
import com.zhiwei.brandkbs2.dao.ReportSettingsDao;
import com.zhiwei.brandkbs2.dao.*;
import com.zhiwei.brandkbs2.enmus.ReportTypeEnum;
import com.zhiwei.brandkbs2.es.EsClientDao;
import com.zhiwei.brandkbs2.listener.ApplicationProjectListener;
......@@ -52,6 +49,9 @@ public class TaskServiceImpl implements TaskService {
@Resource(name = "reportSettingsDao")
ReportSettingsDao reportSettingsDao;
@Resource(name = "aggreeResultDaoImpl")
AggreeResultDao aggreeResultDao;
@Resource(name = "brandkbsTaskServiceImpl")
BrandkbsTaskService brandkbsTaskService;
......@@ -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) {
boolean flag = false;
// 扫描setting信息
......
......@@ -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 {
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) {
stringRedisTemplate.opsForValue().set(key, value, timeout, unit);
}
......@@ -35,4 +39,8 @@ public class RedisUtil {
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;
import com.zhiwei.nlp.vo.KResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.search.SearchHit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
......@@ -67,7 +68,7 @@ public class TextUtil {
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));
// 还原数据
return kResultList.stream().map(gList ->
......@@ -75,6 +76,14 @@ public class TextUtil {
).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) {
return getHighWords(texts, null);
}
......
......@@ -2,7 +2,9 @@ package com.zhiwei.brandkbs2.util;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.base.category.ClassB;
import com.zhiwei.base.category.ClassCodec;
import com.zhiwei.base.entity.subclass.CompleteText;
import com.zhiwei.base.entity.subclass.IncompleteText;
......@@ -312,6 +314,7 @@ public class Tools {
public static BaseMap getBaseFromEsMap(Map<String, Object> map) {
// 设置source,forward,time
BaseMap res = Tools.convertMap(map, BaseMap.class);
res.setTypeB(ClassB.TypeB.fromEncode((int) map.get(GenericAttribute.ES_C2)));
// 统一设置属性:realSource,platform,emotion
res.setRealSource(String.valueOf(map.get(GenericAttribute.ES_REAL_SOURCE)));
res.setPlatform(getPlatform(map));
......@@ -554,4 +557,8 @@ public class Tools {
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