提交 cd49ba7e 作者: 925993793@qq.com

代码优化

上级 87bfd3fc
...@@ -30,7 +30,7 @@ public class LoginInterceptor implements HandlerInterceptor { ...@@ -30,7 +30,7 @@ public class LoginInterceptor implements HandlerInterceptor {
@Override @Override
public boolean preHandle(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) { public boolean preHandle(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) {
String userInfo = URLDecoder.decode(request.getHeader(LOGIN_USER_HEADER), StandardCharsets.UTF_8); String userInfo = URLDecoder.decode(request.getHeader(LOGIN_USER_HEADER), StandardCharsets.UTF_8);
log.info("当前登录用户信息:{}", userInfo); log.debug("当前登录用户信息:{}", userInfo);
if (StringUtils.isBlank(userInfo)) { if (StringUtils.isBlank(userInfo)) {
returnJson(response, JSON.toJSONString(Result.FAIL(401, "用户未登录"))); returnJson(response, JSON.toJSONString(Result.FAIL(401, "用户未登录")));
return false; return false;
......
...@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzsn.event.constant.Result; import com.zzsn.event.constant.Result;
import com.zzsn.event.entity.Subject; import com.zzsn.event.entity.Subject;
import com.zzsn.event.es.EsService;
import com.zzsn.event.service.SubjectService; import com.zzsn.event.service.SubjectService;
import com.zzsn.event.service.SubjectSimpleService; import com.zzsn.event.service.SubjectSimpleService;
import com.zzsn.event.vo.InfoDataSearchCondition; import com.zzsn.event.vo.InfoDataSearchCondition;
...@@ -36,8 +35,6 @@ public class SubjectSimpleController { ...@@ -36,8 +35,6 @@ public class SubjectSimpleController {
private SubjectService subjectService; private SubjectService subjectService;
@Autowired @Autowired
private IXxlJobInfoService xxlJobInfoService; private IXxlJobInfoService xxlJobInfoService;
@Autowired
private EsService esService;
/** /**
* 创建专题 * 创建专题
...@@ -67,6 +64,10 @@ public class SubjectSimpleController { ...@@ -67,6 +64,10 @@ public class SubjectSimpleController {
*/ */
@PostMapping("/editSubject") @PostMapping("/editSubject")
public Result<?> editSubject(@RequestBody SubjectSimpleVO subjectSimpleVO) { public Result<?> editSubject(@RequestBody SubjectSimpleVO subjectSimpleVO) {
List<SearchWordVO> keywords = subjectSimpleVO.getKeywords();
if (CollectionUtils.isEmpty(keywords)) {
return Result.FAIL("请先添加关键词");
}
subjectSimpleService.editSubject(subjectSimpleVO); subjectSimpleService.editSubject(subjectSimpleVO);
return Result.OK(); return Result.OK();
} }
......
package com.zzsn.event.service.impl; package com.zzsn.event.service.impl;
import cn.hutool.core.lang.tree.Tree;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
...@@ -36,7 +35,6 @@ import org.springframework.stereotype.Service; ...@@ -36,7 +35,6 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
......
...@@ -17,6 +17,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -17,6 +17,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
...@@ -69,6 +70,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -69,6 +70,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
private final static String PROJECT_ID = "1476527644425682945"; private final static String PROJECT_ID = "1476527644425682945";
@Override @Override
@Transactional
public Subject createSubject(SubjectSimpleVO subjectSimpleVO) { public Subject createSubject(SubjectSimpleVO subjectSimpleVO) {
SubjectPage subjectPage = new SubjectPage(); SubjectPage subjectPage = new SubjectPage();
BeanUtils.copyProperties(subjectSimpleVO, subjectPage); BeanUtils.copyProperties(subjectSimpleVO, subjectPage);
...@@ -99,6 +101,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -99,6 +101,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
} }
@Override @Override
@Transactional
public void editSubject(SubjectSimpleVO subjectSimpleVO) { public void editSubject(SubjectSimpleVO subjectSimpleVO) {
SubjectPage subjectPage = new SubjectPage(); SubjectPage subjectPage = new SubjectPage();
BeanUtils.copyProperties(subjectSimpleVO, subjectPage); BeanUtils.copyProperties(subjectSimpleVO, subjectPage);
...@@ -150,7 +153,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -150,7 +153,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
} }
} }
List<SearchWordVO> wordList = new ArrayList<>(map.values()); List<SearchWordVO> wordList = new ArrayList<>(map.values());
sortByAnotherList(wordList,sortList); sortByAnotherList(wordList, sortList);
return wordList; return wordList;
} }
...@@ -167,7 +170,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -167,7 +170,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
@Override @Override
public void removeSubject(String subjectId) { public void removeSubject(String subjectId) {
subjectService.removeById(subjectId); subjectService.removeById(subjectId);
CompletableFuture.runAsync(()->{ CompletableFuture.runAsync(() -> {
//删除与类别的映射 //删除与类别的映射
subjectTypeMapService.deleteBySubjectId(subjectId); subjectTypeMapService.deleteBySubjectId(subjectId);
//删除与信息源的关联关系 //删除与信息源的关联关系
...@@ -177,7 +180,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -177,7 +180,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
queryWrapper.eq(SubjectKeywordsMap::getSubjectId, subjectId); queryWrapper.eq(SubjectKeywordsMap::getSubjectId, subjectId);
List<SubjectKeywordsMap> list = subjectKeywordsMapService.list(queryWrapper); List<SubjectKeywordsMap> list = subjectKeywordsMapService.list(queryWrapper);
if (CollectionUtils.isNotEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
List<String> keywordIds = list.stream().map(SubjectKeywordsMap::getKeywordsId).collect(Collectors.toList()); List<String> keywordIds = list.stream().map(SubjectKeywordsMap::getKeywordsId).collect(Collectors.toList());
//删除关键词 //删除关键词
keywordWordsService.removeByIds(keywordIds); keywordWordsService.removeByIds(keywordIds);
//删除与关键词组的关联关系 //删除与关键词组的关联关系
...@@ -202,7 +205,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -202,7 +205,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
public void selected(InfoDataSearchCondition searchCondition) { public void selected(InfoDataSearchCondition searchCondition) {
String[] fetchFields = new String[]{"id", "checkStatus"}; String[] fetchFields = new String[]{"id", "checkStatus"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
Map<String,List<SpecialInformation>> updateMap = new HashMap<>(); Map<String, List<SpecialInformation>> updateMap = new HashMap<>();
List<SpecialInformation> informationList = esService.informationList(searchCondition); List<SpecialInformation> informationList = esService.informationList(searchCondition);
for (SpecialInformation information : informationList) { for (SpecialInformation information : informationList) {
String index = information.getDbIndex(); String index = information.getDbIndex();
...@@ -215,14 +218,14 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -215,14 +218,14 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
updateMap.put(index, list); updateMap.put(index, list);
} }
} }
updateMap.forEach((k,v)->esOpUtil.docUpdateBulk(k,v)); updateMap.forEach((k, v) -> esOpUtil.docUpdateBulk(k, v));
} }
@Override @Override
public void removeSelected(InfoDataSearchCondition searchCondition) { public void removeSelected(InfoDataSearchCondition searchCondition) {
String[] fetchFields = new String[]{"id", "checkStatus"}; String[] fetchFields = new String[]{"id", "checkStatus"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
Map<String,List<SpecialInformation>> updateMap = new HashMap<>(); Map<String, List<SpecialInformation>> updateMap = new HashMap<>();
List<SpecialInformation> informationList = esService.informationList(searchCondition); List<SpecialInformation> informationList = esService.informationList(searchCondition);
for (SpecialInformation information : informationList) { for (SpecialInformation information : informationList) {
String index = information.getDbIndex(); String index = information.getDbIndex();
...@@ -235,14 +238,14 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -235,14 +238,14 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
updateMap.put(index, list); updateMap.put(index, list);
} }
} }
updateMap.forEach((k,v)->esOpUtil.docUpdateBulk(k,v)); updateMap.forEach((k, v) -> esOpUtil.docUpdateBulk(k, v));
} }
@Override @Override
public void batchRemove(InfoDataSearchCondition searchCondition) { public void batchRemove(InfoDataSearchCondition searchCondition) {
String[] fetchFields = new String[]{"id", "deleteFlag"}; String[] fetchFields = new String[]{"id", "deleteFlag"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
Map<String,List<SpecialInformation>> updateMap = new HashMap<>(); Map<String, List<SpecialInformation>> updateMap = new HashMap<>();
List<SpecialInformation> informationList = esService.informationList(searchCondition); List<SpecialInformation> informationList = esService.informationList(searchCondition);
for (SpecialInformation information : informationList) { for (SpecialInformation information : informationList) {
String index = information.getDbIndex(); String index = information.getDbIndex();
...@@ -255,7 +258,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -255,7 +258,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
updateMap.put(index, list); updateMap.put(index, list);
} }
} }
updateMap.forEach((k,v)->esOpUtil.docUpdateBulk(k,v)); updateMap.forEach((k, v) -> esOpUtil.docUpdateBulk(k, v));
} }
//目标集合按照另一个集合的顺序排序 //目标集合按照另一个集合的顺序排序
...@@ -416,7 +419,10 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -416,7 +419,10 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
//绑定为过滤词的同时,绑定为采集词 //绑定为过滤词的同时,绑定为采集词
List<SubjectKeywordsMap> collect = subjectKeywordsMapList.stream().filter(e -> "2".equals(e.getBindingType())).collect(Collectors.toList()); List<SubjectKeywordsMap> collect = subjectKeywordsMapList.stream().filter(e -> "2".equals(e.getBindingType())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect)) { if (CollectionUtils.isNotEmpty(collect)) {
collect.forEach(e -> e.setBindingType("1")); collect.forEach(e -> {
e.setBindingType("1");
e.setId(null);
});
subjectKeywordsMapService.saveBatch(subjectKeywordsMapList); subjectKeywordsMapService.saveBatch(subjectKeywordsMapList);
} }
} }
......
...@@ -101,6 +101,9 @@ public class InfoDataSearchCondition { ...@@ -101,6 +101,9 @@ public class InfoDataSearchCondition {
//每页返回条数 //每页返回条数
private Integer pageSize = 10; private Integer pageSize = 10;
//选择前num条数据
private Integer num;
//资讯id集合,导出/专题分析时使用-研究中心 //资讯id集合,导出/专题分析时使用-研究中心
private List<String> ids; private List<String> ids;
...@@ -113,8 +116,6 @@ public class InfoDataSearchCondition { ...@@ -113,8 +116,6 @@ public class InfoDataSearchCondition {
/*------专题分析类参数---start-------------------*/ /*------专题分析类参数---start-------------------*/
//聚合分组类型-按日期集合分析时使用 //聚合分组类型-按日期集合分析时使用
private String groupType; private String groupType;
//选择的前num条数据-专题分析时使用
private Integer num;
//信息源id集合-统计分析资讯量最多的信息源时使用 //信息源id集合-统计分析资讯量最多的信息源时使用
private List<String> sourceIdList; private List<String> sourceIdList;
//聚合包含的字段值的集合 //聚合包含的字段值的集合
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论