提交 87bfd3fc 作者: 925993793@qq.com

专题创建逻辑完善以及增加用户拦截

上级 f1e0f4b5
package com.zzsn.event.config;
import com.zzsn.event.util.user.AuthUtil;
import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -103,7 +103,7 @@ public class MybatisInterceptor implements Interceptor {
private String getLoginUsername() {
String username = null;
UserVo loginUser = AuthUtil.getLoginUser();
UserVo loginUser = UserUtil.getLoginUser();
if(loginUser != null){
username = loginUser.getUsername();
}
......
package com.zzsn.event.config;
import com.zzsn.event.config.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author lkg
* @description: 拦截配置
* @date 2021/7/1 9:43
*/
@Configuration
public class WebConfigure implements WebMvcConfigurer {
@Value("${jeecg.shiro,excludeUrls:}")
private String ALLOW_URL;
@Bean
public LoginInterceptor loginInterceptor() {
return new LoginInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
//用户登录拦截
registry.addInterceptor(loginInterceptor()).addPathPatterns("/**").excludePathPatterns(ALLOW_URL.split(","));
}
}
package com.zzsn.event.config.interceptor;
import cn.hutool.core.net.URLDecoder;
import com.alibaba.fastjson2.JSON;
import com.zzsn.event.constant.Result;
import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
/**
* 授权拦截
*
* @author lkg
* @date 2023/4/12
*/
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
public final static String LOGIN_USER_HEADER = "loginUser";
@Override
public boolean preHandle(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) {
String userInfo = URLDecoder.decode(request.getHeader(LOGIN_USER_HEADER), StandardCharsets.UTF_8);
log.info("当前登录用户信息:{}", userInfo);
if (StringUtils.isBlank(userInfo)) {
returnJson(response, JSON.toJSONString(Result.FAIL(401, "用户未登录")));
return false;
}
UserVo userVo = JSON.parseObject(userInfo, UserVo.class);
UserUtil.setLoginUser(userVo);
return true;
}
@Override
public void postHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler, ModelAndView modelAndView) {
}
@Override
public void afterCompletion(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler, Exception ex) {
UserUtil.removeUser();
}
private void returnJson(HttpServletResponse response, String json) {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=utf-8");
try (PrintWriter writer = response.getWriter()) {
writer.println(json);
} catch (Exception ignored) {
}
}
}
......@@ -15,6 +15,7 @@ import com.zzsn.event.es.EsService;
import com.zzsn.event.service.*;
import com.zzsn.event.util.*;
import com.zzsn.event.util.user.AuthUtil;
import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo;
import com.zzsn.event.vo.InfoDataSearchCondition;
import com.zzsn.event.vo.LabelModelVo;
......@@ -145,7 +146,7 @@ public class FileController {
*/
@PostMapping("/importInfo")
public Result<?> importInfo(HttpServletRequest request) {
UserVo userVo = AuthUtil.getLoginUser();
UserVo userVo = UserUtil.getLoginUser();
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
if (fileMap.size() < 1) {
......@@ -220,7 +221,7 @@ public class FileController {
}
} else {
//获取当前登录用户
UserVo userVo = AuthUtil.getLoginUser();
UserVo userVo = UserUtil.getLoginUser();
String subjectName;
Integer category = searchCondition.getCategory();
if (category == 1) {
......
......@@ -86,10 +86,6 @@ public class SubjectManageController {
@Resource
private KafkaTemplate<String, String> kafkaTemplate;
@Value("${hotWords.extractUrl}")
private String extractHotWordsUrl;
/**
* 专题列表-资讯转换时使用
*
......@@ -268,12 +264,6 @@ public class SubjectManageController {
String cron = CronUtil.generateCron(subjectPage.getUnit(), subjectPage.getSpace());
xxlJobInfoService.cronUpdate(subjectPage.getSubjectCode(), cron);
}
//判断是否提取热词
extractHotWords(subjectPage);
/*Subject byId = subjectService.getById(subjectPage.getId());
if (!Objects.equals(byId.getStatus(), subjectPage.getStatus()) && subjectPage.getStatus() == 1) {
kafkaTemplate.send("subjectModel", subjectPage.getSubjectCode());
}*/
});
return Result.OK();
}
......@@ -1075,15 +1065,6 @@ public class SubjectManageController {
return Result.OK(countVOS);
}
private void extractHotWords(SubjectPage subjectPage) {
if (StringUtils.isNotEmpty(subjectPage.getYnExtractHotWords()) && "1".equals(subjectPage.getYnExtractHotWords())) {
Map<String, String> param = new HashMap<>();
param.put("status", "0,1,2,3");
param.put("timeFiled", "ALL");
param.put("subjectId", subjectPage.getId());
HttpUtil.doGet(extractHotWordsUrl, param, "utf-8");
}
}
private List<StatisticsKeyWordVo> extractWords(String words) {
List<StatisticsKeyWordVo> wordList = new ArrayList<>();
......
......@@ -8,18 +8,16 @@ import com.zzsn.event.es.EsService;
import com.zzsn.event.service.SubjectService;
import com.zzsn.event.service.SubjectSimpleService;
import com.zzsn.event.vo.InfoDataSearchCondition;
import com.zzsn.event.vo.SearchWordVO;
import com.zzsn.event.vo.SubjectDetailVO;
import com.zzsn.event.vo.SubjectSimpleVO;
import com.zzsn.event.vo.es.SpecialInformation;
import com.zzsn.event.xxljob.service.IXxlJobInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
/**
......@@ -50,6 +48,10 @@ public class SubjectSimpleController {
*/
@PostMapping("/createSubject")
public Result<?> createSubject(@RequestBody SubjectSimpleVO subjectSimpleVO) {
List<SearchWordVO> keywords = subjectSimpleVO.getKeywords();
if (CollectionUtils.isEmpty(keywords)) {
return Result.FAIL("请先添加关键词");
}
Subject subject = subjectSimpleService.createSubject(subjectSimpleVO);
//插入xxlJob
xxlJobInfoService.subjectInsert(subject);
......
......@@ -14,6 +14,7 @@ import com.zzsn.event.es.EsService;
import com.zzsn.event.service.*;
import com.zzsn.event.util.HttpUtil;
import com.zzsn.event.util.user.AuthUtil;
import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo;
import com.zzsn.event.vo.*;
import com.zzsn.event.vo.es.DisplayInfo;
......@@ -106,7 +107,7 @@ public class InformationController {
*/
@GetMapping("/search/condition/list")
public Result<?> queryInfo(@RequestParam("subjectId") String relationId) {
UserVo user = AuthUtil.getLoginUser();
UserVo user = UserUtil.getLoginUser();
String userId = user.getId();
LambdaQueryWrapper<SubjectUserCondition> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SubjectUserCondition::getUserId, userId)
......@@ -124,7 +125,7 @@ public class InformationController {
*/
@PostMapping("/search/condition/modify")
public Result<?> modify(@RequestBody SubjectUserCondition condition) {
UserVo user = AuthUtil.getLoginUser();
UserVo user = UserUtil.getLoginUser();
String userId = user.getId();
condition.setUserId(userId);
subjectUserConditionService.saveOrUpdate(condition);
......@@ -202,7 +203,7 @@ public class InformationController {
if (StringUtils.isEmpty(searchCondition.getSubjectId())) {
return Result.FAIL("专题id不能为空");
}
UserVo userVo = AuthUtil.getLoginUser();
UserVo userVo = UserUtil.getLoginUser();
IPage<DisplayInfo> pageList = informationService.subjectPageList(userVo, searchCondition);
return Result.OK(pageList);
}
......@@ -259,7 +260,7 @@ public class InformationController {
*/
@PostMapping(value = "/add")
public Result<?> add(@RequestBody JSONObject jsonObject) {
UserVo userVo = AuthUtil.getLoginUser();
UserVo userVo = UserUtil.getLoginUser();
DisplayInfo displayInfo = JSON.parseObject(JSON.toJSONString(jsonObject.get("data")), DisplayInfo.class);
Integer category = (Integer) jsonObject.get("category");
boolean modelFlag = judgeDuplicate(displayInfo);
......@@ -280,7 +281,7 @@ public class InformationController {
*/
@PostMapping(value = "/check")
public Result<?> check(@RequestBody Map<String, Object> map) {
UserVo userVo = AuthUtil.getLoginUser();
UserVo userVo = UserUtil.getLoginUser();
informationService.checkInfo(map, userVo);
return Result.OK();
}
......@@ -294,7 +295,7 @@ public class InformationController {
*/
@PostMapping(value = "/edit")
public Result<?> edit(@RequestBody JSONObject jsonObject) {
UserVo userVo = AuthUtil.getLoginUser();
UserVo userVo = UserUtil.getLoginUser();
informationService.updateInfo(jsonObject, userVo);
return Result.OK();
}
......@@ -308,7 +309,7 @@ public class InformationController {
*/
@PostMapping(value = "/deleteBatch")
public Result<?> deleteBatch(@RequestBody Map<String, Object> map) {
UserVo userVo = AuthUtil.getLoginUser();
UserVo userVo = UserUtil.getLoginUser();
informationService.deleteBatch(map, userVo);
return Result.OK();
}
......@@ -331,7 +332,7 @@ public class InformationController {
*/
@PostMapping(value = "/top")
public Result<?> top(@RequestBody SubjectInfoVo subjectInfoVo) {
UserVo userVo = AuthUtil.getLoginUser();
UserVo userVo = UserUtil.getLoginUser();
informationService.topInfo(subjectInfoVo, userVo);
return Result.OK();
}
......
......@@ -9,6 +9,7 @@ import com.zzsn.event.service.ISubjectTypeService;
import com.zzsn.event.util.tree.Node;
import com.zzsn.event.util.tree.TreeUtil;
import com.zzsn.event.util.user.AuthUtil;
import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo;
import com.zzsn.event.vo.SubjectTreeVO;
import com.zzsn.event.vo.SubjectTypeTreeVO;
......@@ -161,7 +162,7 @@ public class SubjectTypeController {
*/
@GetMapping("/typeList")
public Result<?> typeTreeList() {
UserVo loginUser = AuthUtil.getLoginUser();
UserVo loginUser = UserUtil.getLoginUser();
List<Node> nodes = subjectTypeService.researchCenterEnableList(loginUser.getUsername());
List<Node> tree = TreeUtil.tree(nodes, "0");
return Result.OK(tree);
......
......@@ -18,6 +18,7 @@ import com.zzsn.event.es.EsService;
import com.zzsn.event.service.*;
import com.zzsn.event.util.*;
import com.zzsn.event.util.user.AuthUtil;
import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo;
import com.zzsn.event.vo.*;
import com.zzsn.event.vo.es.*;
......@@ -545,7 +546,7 @@ public class InformationServiceImpl implements InformationService {
@Override
public void collect(CollectionInfo collectionInfo) {
UserVo userVo = AuthUtil.getLoginUser();
UserVo userVo = UserUtil.getLoginUser();
String userId = userVo.getId();
CollectionMap collectionMap = new CollectionMap();
BeanUtils.copyProperties(collectionInfo, collectionMap);
......
......@@ -6,7 +6,6 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
......@@ -26,6 +25,7 @@ import com.zzsn.event.util.CronUtil;
import com.zzsn.event.util.HttpUtil;
import com.zzsn.event.util.RedisUtil;
import com.zzsn.event.util.user.AuthUtil;
import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo;
import com.zzsn.event.vo.*;
import lombok.extern.slf4j.Slf4j;
......@@ -141,7 +141,7 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
typeIds = subjectTypeService.researchCenterBelowIdList(subjectTypeId, 1);
}
subjectCondition.setTypeIds(typeIds);
UserVo loginUser = AuthUtil.getLoginUser();
UserVo loginUser = UserUtil.getLoginUser();
subjectCondition.setUsername(loginUser.getUsername());
page = baseMapper.researchCenterPageList(subjectCondition, page);
}
......@@ -176,41 +176,13 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
BeanUtils.copyProperties(subjectPage, subject);
String cron = CronUtil.generateCron(subject.getUnit(), subject.getSpace());
subject.setCron(cron);
//先记录老的信息状态
Subject oldSubject = baseMapper.selectById(subject.getId());
baseMapper.updateById(subject);
//删除专题-类别绑定关系
subjectTypeMapService.deleteBySubjectId(subject.getId());
//删除专题-项目的绑定关系
projectSubjectMapService.deleteBySubjectId(subject.getId());
//插入新的
saveMapMain(subject, subjectPage);
//判断专题状态是否启用(启用时控制xxljob调度启动,关闭时控制xxljob关闭),随着状态的改变发消息给python
/* if (!subject.getStatus().equals(oldSubject.getStatus())) {
if (subject.getStatus() == 1) {
send(subject.getId(), "1");
} else if (subject.getStatus() == 0) {
//向python发起停止处理请求
send(subject.getId(), "0");
}
}*/
//判断开始时间和结束时间是否发生变动 todo 还需要吗
/*Date newTimeEnable = subjectPage.getTimeEnable();
Date oldTimeEnable = oldSubject.getTimeEnable();
if (!((newTimeEnable == null && oldTimeEnable == null) ||
(newTimeEnable != null && oldTimeEnable != null && oldTimeEnable.compareTo(newTimeEnable) == 0))) {
//查询出该专题绑定的关键词组
List<KeyWordsPage> keyWordsPages = commonService.selectKeyWordsListById(subject.getId());
List<String> keyWordIds = new ArrayList<>();
for (KeyWordsPage keyWordsPage : keyWordsPages) {
keyWordIds.add(keyWordsPage.getId());
}
//更新redis中关键词时间
updateRedisKeyWordsDate(subjectPage.getId(), keyWordIds);
}*/
}
@Override
......@@ -343,8 +315,6 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
mapList.add(subjectKeywordsMap);
}
subjectKeywordsMapService.saveBatch(mapList);
//更新redis缓存(查询每个词组绑定专题的最小时间,作为爬取依据)
updateRedisKeyWordsDate(subjectPage.getId(), idList);
}
}
......@@ -389,8 +359,6 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
for (KeyWordsPage keyWordsPage : keyWordsPages) {
keyWordIds.add(keyWordsPage.getId());
}
//更新redis中关键词时间
updateRedisKeyWordsDate(subjectPage.getId(), keyWordIds);
}
@Override
......@@ -591,34 +559,6 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
}
}
//更新专题绑定的关键词组的缓存信息
private void updateRedisKeyWordsDate(String subjectId, List<String> keyWordsIds) {
for (String keyWordsId : keyWordsIds) {
KeyWordsDTO keyWordsDTO = subjectKeywordsMapService.selectMinByKeyWordsId(keyWordsId);
KeyWordsDTO redisKeyWordsDTO = (KeyWordsDTO) redisUtil.get(Constants.KEY_WORDS_TO_REDIS_PREFIX + keyWordsDTO.getWordsCode());
int count = subjectKeywordsMapService.selectCountByKeyWordsId(keyWordsId);
KeyWordsDTO keyWordsDTO1;
if (count <= 0) {
keyWordsDTO1 = subjectKeywordsMapService.selectMaxByKeyWordsId(keyWordsId);
redisKeyWordsDTO.setStartTime(keyWordsDTO.getStartTime());
redisKeyWordsDTO.setEndTime(keyWordsDTO1.getEndTime());
} else {
if (redisKeyWordsDTO == null) {
redisKeyWordsDTO = keyWordsDTO;
} else {
redisKeyWordsDTO.setEndTime(null);
redisKeyWordsDTO.setStartTime(keyWordsDTO.getStartTime());
}
}
//查询出该专题绑定了哪些搜索引擎
List<String> stringList = subjectSearchEnginesMapService.querySearchList(subjectId);
redisKeyWordsDTO.setSearchEngines(stringList);
redisUtil.set(Constants.KEY_WORDS_TO_REDIS_PREFIX + redisKeyWordsDTO.getWordsCode(), redisKeyWordsDTO);
//立即执行一次
kafkaTemplate.send("keyWordsCrawl", JSON.toJSONString(redisKeyWordsDTO));
}
}
private void saveMapMain(Subject subject, SubjectPage subjectPage) {
if (StringUtils.isNotEmpty(subjectPage.getSubjectTypeId())) {
SubjectTypeMap subjectTypeMap = new SubjectTypeMap();
......
......@@ -21,7 +21,6 @@ import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* 简化专题创建流程
......@@ -54,6 +53,8 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
private ISubjectInfoSourceMapService subjectInfoSourceMapService;
@Autowired
private ISubjectModelMapService subjectModelMapService;
@Autowired
private ScoreModelService scoreModelService;
@Autowired
private EsService esService;
......@@ -62,7 +63,9 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
@Autowired
private CodeGenerateUtil codeGenerateUtil;
//关键词默认分类
private final static String KEYWORDS_TYPE_ID = "1476498704680194050";
//默认项目
private final static String PROJECT_ID = "1476527644425682945";
@Override
......@@ -71,15 +74,27 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
BeanUtils.copyProperties(subjectSimpleVO, subjectPage);
subjectPage.setProjectId(PROJECT_ID);
Subject subject = subjectService.saveMain(subjectPage);
//关键词绑定 todo 关键词创建时是否还需要 创建定时任务、redis缓存以及发送kafka消息
String subjectId = subject.getId();
//关键词绑定
List<SearchWordVO> keywords = subjectSimpleVO.getKeywords();
modifyKeyword(subject.getId(), subject.getSubjectName(), keywords);
modifyKeyword(subjectId, subject.getSubjectName(), keywords);
//默认绑定tpu流程
ClbModelArrangeSubjectMap tpu = new ClbModelArrangeSubjectMap();
tpu.setSubjectId(subject.getId());
tpu.setArrangeId("1877652205629173761");
tpu.setType("baseDateToSubject");
clbModelArrangeSubjectMapService.save(tpu);
//默认通用打分配置
String defaultConfig = "[{\"id\": \"1-1\", \"name\": \"信息源组\", \"children\": [], \"indexWeight\": 10}, {\"id\": \"1-2\", \"name\": \"文章长度\", \"indexWeight\": 15, \"keyWordsTopLimit\": 2500, \"keyWordsLowerLimit\": 500}, {\"id\": \"1-3\", \"name\": \"内容\", \"children\": [{\"id\": \"1-3-1\", \"name\": \"内容-关键词\", \"keyWords\": \"KEY_WORD\", \"indexWeight\": 75, \"titleWeight\": 10, \"keyWordsTopLimit\": 15, \"keyWordsLowerLimit\": 3}]}]";
List<SearchWordVO> collect = keywords.stream().filter(searchWordVO -> !"NOT".equalsIgnoreCase(searchWordVO.getSearchLogicRelationship())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect)) {
defaultConfig = defaultConfig.replace("KEY_WORD", String.join("|", collect.stream().map(SearchWordVO::getSearchInfo).collect(Collectors.toList())));
}
ScoreModel scoreModel = new ScoreModel();
scoreModel.setSubjectId(subjectId);
scoreModel.setType("1");
scoreModel.setData(defaultConfig);
scoreModelService.save(scoreModel);
return subject;
}
......@@ -278,7 +293,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
//专题-关键词绑定关系
List<SearchWordVO> addMapIdList = new ArrayList<>();
for (SearchWordVO searchWordVO : retainList) {
if (!updateIdList.contains(searchWordVO.getId())) {//过滤已存在绑定关系的数据
if (!updateIdList.contains(searchWordVO.getId())) {//过滤已存在绑定关系的数据
addMapIdList.add(searchWordVO);
}
}
......@@ -299,8 +314,12 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
List<SearchWordVO> relationList = retainList.stream().filter(searchWordVO -> !"NOT".equalsIgnoreCase(searchWordVO.getSearchLogicRelationship())).collect(Collectors.toList());
List<SearchWordVO> excludedList = retainList.stream().filter(searchWordVO -> "NOT".equalsIgnoreCase(searchWordVO.getSearchLogicRelationship())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(relationList)) {
SubjectKeywordsGroupRelation subjectKeywordsGroupRelation = handlerGroupRelationMap(subjectId, relationList, "2");
subjectKeywordsGroupRelationList.add(subjectKeywordsGroupRelation);
//采集词
SubjectKeywordsGroupRelation subjectKeywordsGroupRelationCaiJi = handlerGroupRelationMap(subjectId, relationList, "1");
subjectKeywordsGroupRelationList.add(subjectKeywordsGroupRelationCaiJi);
//过滤词
SubjectKeywordsGroupRelation subjectKeywordsGroupRelationGuoLv = handlerGroupRelationMap(subjectId, relationList, "2");
subjectKeywordsGroupRelationList.add(subjectKeywordsGroupRelationGuoLv);
}
if (CollectionUtils.isNotEmpty(excludedList)) {
SubjectKeywordsGroupRelation subjectKeywordsGroupRelation = handlerGroupRelationMap(subjectId, excludedList, "3");
......@@ -311,32 +330,13 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
//格式化 词组关系数据
private SubjectKeywordsGroupRelation handlerGroupRelationMap(String subjectId, List<SearchWordVO> relationList, String relationType) {
//relationList.sort(Comparator.comparing(SearchWordVO::getSearchLogicRelationship, Comparator.nullsFirst(Comparator.naturalOrder())));
SubjectKeywordsGroupRelation subjectKeywordsGroupRelation = new SubjectKeywordsGroupRelation();
subjectKeywordsGroupRelation.setSubjectId(subjectId);
subjectKeywordsGroupRelation.setRelationType(relationType);
List<String> keywordsGroupIds = new ArrayList<>();
List<JSONObject> paramsStr = new ArrayList<>();
String expression = null;
if ("2".equals(relationType)) {
StringBuilder expressionStr = new StringBuilder();
for (SearchWordVO searchWordVO : relationList) {
String id = searchWordVO.getId();
String wordName = searchWordVO.getWordName();
keywordsGroupIds.add(id);
expressionStr.append("&").append(id);
JSONObject relationParam = new JSONObject();
relationParam.put("title", "and");
relationParam.put("value", "&");
paramsStr.add(relationParam);
JSONObject params = new JSONObject();
params.put("title", wordName);
params.put("value", id);
paramsStr.add(params);
}
expression = expressionStr.substring(1);
paramsStr = paramsStr.subList(1, paramsStr.size());
} else if ("3".equals(relationType)) {
String expression;
if ("3".equals(relationType)) {
StringBuilder expressionStr = new StringBuilder();
for (int i = 0; i < relationList.size(); i++) {
SearchWordVO searchWordVO = relationList.get(i);
......@@ -369,6 +369,24 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
}
}
expression = expressionStr.toString();
} else {
StringBuilder expressionStr = new StringBuilder();
for (SearchWordVO searchWordVO : relationList) {
String id = searchWordVO.getId();
String wordName = searchWordVO.getWordName();
keywordsGroupIds.add(id);
expressionStr.append("&").append(id);
JSONObject relationParam = new JSONObject();
relationParam.put("title", "and");
relationParam.put("value", "&");
paramsStr.add(relationParam);
JSONObject params = new JSONObject();
params.put("title", wordName);
params.put("value", id);
paramsStr.add(params);
}
expression = expressionStr.substring(1);
paramsStr = paramsStr.subList(1, paramsStr.size());
}
subjectKeywordsGroupRelation.setKeywordsGroupIds(String.join(",", keywordsGroupIds));
subjectKeywordsGroupRelation.setExpressionStr(expression);
......@@ -395,6 +413,12 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
subjectKeywordsMapList.add(subjectKeywordsMap);
}
subjectKeywordsMapService.saveBatch(subjectKeywordsMapList);
//绑定为过滤词的同时,绑定为采集词
List<SubjectKeywordsMap> collect = subjectKeywordsMapList.stream().filter(e -> "2".equals(e.getBindingType())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect)) {
collect.forEach(e -> e.setBindingType("1"));
subjectKeywordsMapService.saveBatch(subjectKeywordsMapList);
}
}
if (CollectionUtils.isNotEmpty(removeIdList)) {
LambdaQueryWrapper<SubjectKeywordsMap> queryWrapper = Wrappers.lambdaQuery();
......
......@@ -9,7 +9,7 @@ import com.zzsn.event.mapper.SubjectTypeMapper;
import com.zzsn.event.service.ISubjectTypeService;
import com.zzsn.event.util.tree.Node;
import com.zzsn.event.util.tree.TreeUtil;
import com.zzsn.event.util.user.AuthUtil;
import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.vo.SubjectPage;
import com.zzsn.event.vo.SubjectTreeVO;
import com.zzsn.event.vo.SubjectTypeTreeVO;
......@@ -104,7 +104,7 @@ public class SubjectTypeServiceImpl extends ServiceImpl<SubjectTypeMapper, Subje
@Override
public List<SubjectTreeVO> subjectAndTypeTree() {
String username = AuthUtil.getLoginUser().getUsername();
String username = UserUtil.getLoginUser().getUsername();
List<SubjectTreeVO> tree = new ArrayList<>();
List<SubjectTreeVO> subjectTreeVOS = baseMapper.subjectAndTypeTree(username);
if (CollectionUtils.isNotEmpty(subjectTreeVOS)) {
......@@ -115,7 +115,7 @@ public class SubjectTypeServiceImpl extends ServiceImpl<SubjectTypeMapper, Subje
@Override
public List<String> researchCenterBelowIdList(String typeId, Integer category) {
String username = AuthUtil.getLoginUser().getUsername();
String username = UserUtil.getLoginUser().getUsername();
List<Node> nodes = baseMapper.enableList(category,username);
return TreeUtil.belowList(nodes, typeId, true);
}
......
......@@ -8,9 +8,11 @@ package com.zzsn.event.util.user;
*/
public abstract class UserUtil {
UserUtil() {}
private static final ThreadLocal<UserVo> USER_THREAD_LOCAL = new ThreadLocal<>();
public static UserVo getLoginUser(){
public static UserVo getLoginUser() {
return USER_THREAD_LOCAL.get();
}
......@@ -18,5 +20,7 @@ public abstract class UserUtil {
USER_THREAD_LOCAL.set(userVo);
}
public static void removeUser(){USER_THREAD_LOCAL.remove();}
public static void removeUser() {
USER_THREAD_LOCAL.remove();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论