提交 fb64d8ca 作者: 925993793@qq.com

1.报告数据接口;2.增加组合标签的查询条件逻辑

上级 31fb8907
...@@ -14,12 +14,17 @@ import com.zzsn.event.service.*; ...@@ -14,12 +14,17 @@ import com.zzsn.event.service.*;
import com.zzsn.event.util.tree.Node; import com.zzsn.event.util.tree.Node;
import com.zzsn.event.vo.*; import com.zzsn.event.vo.*;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* 专题/事件关系绑定 * 专题/事件关系绑定
...@@ -49,6 +54,8 @@ public class RelationBindController { ...@@ -49,6 +54,8 @@ public class RelationBindController {
private SubjectService subjectService; private SubjectService subjectService;
@Autowired @Autowired
private SubjectDictMapService subjectDictMapService; private SubjectDictMapService subjectDictMapService;
@Autowired
private SysDictItemService dictItemService;
/** /**
* 项目列表 * 项目列表
...@@ -295,4 +302,33 @@ public class RelationBindController { ...@@ -295,4 +302,33 @@ public class RelationBindController {
List<DictVO> boundList = subjectDictMapService.boundList(subjectId); List<DictVO> boundList = subjectDictMapService.boundList(subjectId);
return Result.OK(boundList); return Result.OK(boundList);
} }
/**
* 专题已经绑定的标签(包含标签值)-树型结构----创建专题报告任务时使用
*
* @param subjectId 专题id
* @author lkg
* @date 2025/3/28
*/
@GetMapping("/boundLabelTreeList")
public Result<?> boundLabelTreeList(@RequestParam String subjectId){
List<DictTreeVO> list = new ArrayList<>();
List<DictVO> boundList = subjectDictMapService.boundList(subjectId);
boundList.forEach(dictVO -> {
DictTreeVO dictTreeVO = new DictTreeVO();
BeanUtils.copyProperties(dictVO, dictTreeVO);
dictTreeVO.setYnItem(false);
list.add(dictTreeVO);
});
List<String> dictIds = boundList.stream().map(DictVO::getId).collect(Collectors.toList());
List<DictTreeVO> itemTreeList = dictItemService.dictItemTreeList(dictIds);
Map<String, List<DictTreeVO>> dictMap = itemTreeList.stream().collect(Collectors.groupingBy(DictTreeVO::getDictId));
for (DictTreeVO dictTreeVO : list) {
if (dictMap.containsKey(dictTreeVO.getId())) {
List<DictTreeVO> dictTreeVOS = dictMap.get(dictTreeVO.getId());
dictTreeVO.setChildren(dictTreeVOS);
}
}
return Result.OK(list);
}
} }
package com.zzsn.event.controller.reportData;
import java.lang.annotation.*;
/**
* 字段描述注解
*
* @author lkg
* @date 2025/4/9
*/
@Documented
@Target(ElementType.FIELD) //说明该注解只能放在字段上面
@Retention(RetentionPolicy.RUNTIME)
public @interface FieldDescription {
/**
* 字段描述
*/
String value() default "";
/**
* 是否有效
*/
boolean valid() default true;
}
package com.zzsn.event.controller.reportData;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.zzsn.event.constant.Constants;
import com.zzsn.event.constant.Result;
import com.zzsn.event.service.CommonService;
import com.zzsn.event.service.SubjectService;
import com.zzsn.event.util.DateUtil;
import com.zzsn.event.util.EsDateUtil;
import com.zzsn.event.util.EsIndexUtil;
import com.zzsn.event.util.FieldUtil;
import com.zzsn.event.vo.es.Label;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.index.query.TermsQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
/**
* 专题报告数据接口
*
* @author lkg
* @date 2025/4/9
*/
@RestController
@RequestMapping("/report/data/api")
public class ReportDataController {
@Resource
private RestHighLevelClient client;
@Autowired
private SubjectService subjectService;
@Autowired
private CommonService commonService;
/**
* 检索字段集合
*
* @author lkg
* @date 2025/4/9
*/
@GetMapping("/searchFieldList")
public Result<?> fieldList(){
List<Map<String, Object>> fieldDetails = FieldUtil.fieldDetails(SearchCondition.class);
return Result.OK(fieldDetails);
}
/**
* 专题资讯列表
*
* @author lkg
* @date 2025/4/9
*/
@PostMapping("/dataList")
public Result<?> dataList(@RequestBody SearchCondition searchCondition){
try {
List<ReportDataVO> pageList = pageList(searchCondition);
return Result.OK(pageList);
} catch (IOException e) {
e.printStackTrace();
}
return Result.OK();
}
/**
* 事件对应专题库的资讯分页列表
*
* @param searchCondition 检索条件
* @author lkg
* @date 2024/5/6
*/
public List<ReportDataVO> pageList(SearchCondition searchCondition) throws IOException {
List<String> subjectIdList = new ArrayList<>();
subjectIdList.add(searchCondition.getSubjectId());
String minDate = subjectService.getMinCreateTime(subjectIdList);
String[] indexArr = EsIndexUtil.getIndexIntervalYearStr(Constants.SUBJECT_INDEX, minDate);
SearchRequest searchRequest = new SearchRequest(indexArr);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
//默认最大数量是10000,设置为true后,显示准确数量
searchSourceBuilder.trackTotalHits(true);
String[] fetchFields = searchCondition.getFetchFields();
String[] excludeFields = searchCondition.getExcludeFields();
if (fetchFields != null && fetchFields.length > 0) {
searchSourceBuilder.fetchSource(fetchFields, null);
} else if (excludeFields != null && excludeFields.length > 0) {
searchSourceBuilder.fetchSource(null, excludeFields);
}
//设置分页参数
Integer pageNo = searchCondition.getPageNo();
Integer pageSize = searchCondition.getPageSize();
searchSourceBuilder.from((pageNo - 1) * pageSize);
searchSourceBuilder.size(pageSize);
//排序规则
String column = searchCondition.getColumn();
String order = searchCondition.getOrder();
if (searchCondition.getTopSortValid() == 1) {
searchSourceBuilder.sort("topNum", SortOrder.DESC);
}
switch (column) {
case "score":
if (order.equals("asc")) {
searchSourceBuilder.sort("score", SortOrder.ASC);
searchSourceBuilder.sort("publishDate", SortOrder.ASC);
} else if (order.equals("desc")) {
searchSourceBuilder.sort("score", SortOrder.DESC);
searchSourceBuilder.sort("publishDate", SortOrder.DESC);
}
break;
case "publishDate":
if (order.equals("desc")) {
searchSourceBuilder.sort("publishDate", SortOrder.DESC);
searchSourceBuilder.sort("score", SortOrder.DESC);
} else if (order.equals("asc")) {
searchSourceBuilder.sort("publishDate", SortOrder.ASC);
searchSourceBuilder.sort("score", SortOrder.ASC);
}
break;
default:
searchSourceBuilder.sort("publishDate", SortOrder.DESC);
break;
}
//构建es查询条件
BoolQueryBuilder boolQuery = buildQuery(searchCondition);
searchSourceBuilder.query(boolQuery);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
SearchHit[] searchHits = searchResponse.getHits().getHits();
List<ReportDataVO> list = new ArrayList<>();
for (SearchHit hit : searchHits) {
String queryInfo = hit.getSourceAsString();
ReportDataVO info = JSONUtil.toBean(queryInfo, ReportDataVO.class);
info.setPublishDate(EsDateUtil.esFieldDateMapping(info.getPublishDate()));
info.setCreateDate(EsDateUtil.esFieldDateMapping(info.getCreateDate()));
list.add(info);
}
return list;
}
/**
* 构建通用的es查询语句
*
* @param searchCondition 检索条件
* @author lkg
* @date 2024/12/25
*/
private BoolQueryBuilder buildQuery(SearchCondition searchCondition) {
//创建查询对象
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
String subjectId = searchCondition.getSubjectId();
boolQuery.must(QueryBuilders.termsQuery("subjectId.keyword", subjectId));
String searchScope = searchCondition.getSearchScope();
String searchWord = searchCondition.getSearchWord();
if (StringUtils.isNotEmpty(searchWord)) {
if ("all".equalsIgnoreCase(searchScope)) {
boolQuery.must(QueryBuilders.multiMatchQuery(searchWord, "title", "content","origin"));
} else {
boolQuery.must(QueryBuilders.matchPhraseQuery(searchScope, searchWord));
}
}
Integer checkStatus = searchCondition.getCheckStatus();
Integer deleteFlag = searchCondition.getDeleteFlag();
if (checkStatus != null) {
if (checkStatus == 0) {
BoolQueryBuilder checkStatusBoolQuery = QueryBuilders.boolQuery();
checkStatusBoolQuery.should(QueryBuilders.termQuery("checkStatus", checkStatus));
checkStatusBoolQuery.should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("checkStatus")));
boolQuery.must(checkStatusBoolQuery);
} else {
boolQuery.must(QueryBuilders.termQuery("checkStatus", checkStatus));
}
} else {
if (deleteFlag == null) {
deleteFlag = 0;
}
}
//删除状态查询
if (deleteFlag != null) {
if (deleteFlag != 0) {
boolQuery.must(QueryBuilders.termQuery("deleteFlag", "1"));
} else {
boolQuery.mustNot(QueryBuilders.termQuery("deleteFlag", "1"));
}
}
//免审核状态
if (searchCondition.getIsFreeCheck() != null) {
boolQuery.must(QueryBuilders.termQuery("isFreeCheck", searchCondition.getClassificationType()));
}
boolQuery.mustNot(QueryBuilders.matchQuery("type", "video"));
//专题库类别筛选
if (CollectionUtils.isNotEmpty(searchCondition.getClassificationType())) {
boolQuery.must(QueryBuilders.termsQuery("classificationType", searchCondition.getClassificationType()));
}
//是否原创
if (StringUtils.isNotEmpty(searchCondition.getOriginality())) {
boolQuery.must(QueryBuilders.matchQuery("originality", searchCondition.getOriginality()));
}
//得分范围筛选
Integer minScore = searchCondition.getMinScore();
if (minScore != null) {
boolQuery.filter(QueryBuilders.rangeQuery("score").gte(minScore));
}
Integer maxScore = searchCondition.getMaxScore();
if (maxScore != null) {
boolQuery.filter(QueryBuilders.rangeQuery("score").lte(maxScore));
}
//时间过滤筛选-前端传参
if (searchCondition.getStartTime() != null) {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").gte(EsDateUtil.esFieldDateFormat(DateUtil.dateToString(searchCondition.getStartTime()))));
}
if (searchCondition.getEndTime() != null) {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").lte(EsDateUtil.esFieldDateFormat(DateUtil.dateToString(searchCondition.getEndTime()))));
} else {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").lte(EsDateUtil.esFieldDateFormat(DateUtil.dateToString(new Date()))));
}
//关联标签id集合
List<String> labelIds = searchCondition.getLabelIds();
if (CollectionUtils.isNotEmpty(labelIds)) {
Set<String> relationIdSet = new HashSet<>(labelIds);
TermsQueryBuilder relationIdQuery = QueryBuilders.termsQuery("labels.relationId", relationIdSet);
boolQuery.must(QueryBuilders.nestedQuery("labels", relationIdQuery, ScoreMode.None));
}
//正面标签
String tendencyLabelId = searchCondition.getTendencyLabelId();
if (StringUtils.isNotBlank(tendencyLabelId)) {
TermQueryBuilder relationIdQuery = QueryBuilders.termQuery("labels.relationId", tendencyLabelId);
boolQuery.must(QueryBuilders.nestedQuery("labels", relationIdQuery, ScoreMode.None));
}
//地域标签
List<String> areaLabelIds = searchCondition.getAreaLabelIds();
if (CollectionUtils.isNotEmpty(areaLabelIds)) {
Set<String> relationIdSet = new HashSet<>(areaLabelIds);
TermsQueryBuilder relationIdQuery = QueryBuilders.termsQuery("labels.relationId", relationIdSet);
boolQuery.must(QueryBuilders.nestedQuery("labels", relationIdQuery, ScoreMode.None));
}
//企业标签
List<String> enterpriseLabelTypeIds = searchCondition.getEnterpriseLabelTypeIds();
List<String> socialCreditCodeList = searchCondition.getSocialCreditCodeList();
if (CollectionUtils.isNotEmpty(socialCreditCodeList) || CollectionUtils.isNotEmpty(enterpriseLabelTypeIds)) {
if (CollectionUtils.isEmpty(socialCreditCodeList)) {
socialCreditCodeList = commonService.codesByLabels(enterpriseLabelTypeIds);
}
Set<String> codeSet = new HashSet<>(socialCreditCodeList);
TermsQueryBuilder relationIdQuery = QueryBuilders.termsQuery("labels.relationId", codeSet);
boolQuery.must(QueryBuilders.nestedQuery("labels", relationIdQuery, ScoreMode.None));
}
//信息源标签
List<Label> labelList = searchCondition.getInfoSourceLabelList();
if (CollectionUtils.isNotEmpty(labelList)) {
List<String> collect = labelList.stream().map(label -> label.getLabelMark() + "-" + label.getRelationId()).collect(Collectors.toList());
TermsQueryBuilder relationIdQuery = QueryBuilders.termsQuery("labels.relationId", collect);
boolQuery.must(QueryBuilders.nestedQuery("labels", relationIdQuery, ScoreMode.None));
}
return boolQuery;
}
}
package com.zzsn.event.controller.reportData;
import lombok.Data;
/**
* 报告资讯返回对象
*
* @author lkg
* @date 2025/4/9
*/
@Data
public class ReportDataVO {
//信息id
private String id;
//标题
private String title;
//摘要
private String summary;
//正文
private String content;
//带标签正文
private String contentWithTag;
//语言
private String lang;
//来源(信息来源)
private String origin;
//发布时间
private String publishDate;
//发布地址
private String sourceAddress;
//得分
private Double score;
//专题库类型(0: 其它 1:政策;2:领导讲话;3:专家观点;4:企业案例)
private Integer classificationType;
//删除标记(1:删除;0:保留)
private Integer deleteFlag;
//专题id
private String subjectId;
//专题名称
private String subjectName;
//审核操作(0:未审核 1:审核通过 2:审核未通过 3:暂定 默认值为0)
private Integer checkStatus;
/**原创性*/
private String originality;
//入库时间
private String createDate;
}
package com.zzsn.event.controller.reportData;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zzsn.event.vo.es.Label;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
@Data
public class SearchCondition {
//专题id
@FieldDescription(value = "专题id")
private String subjectId;
//搜索范围(all、title、content、origin)
@FieldDescription(value = "搜索范围")
private String searchScope;
//搜索词
@FieldDescription(value = "搜索词")
private String searchWord;
//开始时间
@FieldDescription(value = "开始时间")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date startTime;
//结束时间
@FieldDescription(value = "结束时间")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date endTime;
//专题库类型(对应字典编码为【Thematic_Library】的数据字典值)
@FieldDescription(value = "专题库类型")
private List<Integer> classificationType;
/**原创性(0-非原创;1-原创;2-疑似)*/
@FieldDescription(value = "原创性")
private String originality;
//审核操作(0:未审核 1:审核通过 2:审核未通过 3:暂定 默认值为0)
@FieldDescription(value = "审核状态")
private Integer checkStatus;
//删除标记(1:删除;0:未删除)
@FieldDescription(value = "删除标记")
private Integer deleteFlag = 0;
//爬虫类型
@FieldDescription(value = "爬虫类型")
private String crawler;
/**----企业类标签筛选----**/
//企业类标签id集合
@FieldDescription(value = "企业类标签id集合")
private List<String> enterpriseLabelTypeIds;
//企业信用代码集合
@FieldDescription(value = "企业信用代码集合")
private List<String> socialCreditCodeList;
/**----企业类标签id集合----**/
//专题关联标签值id集合
@FieldDescription(value = "专题关联标签值id集合")
private List<String> labelIds;
//正负面标签
@FieldDescription(value = "正负面标签")
private String tendencyLabelId;
//地域标签id集合
@FieldDescription(value = "地域标签id集合")
private List<String> areaLabelIds;
//专题关联信息源标签集合
@FieldDescription(value = "专题关联信息源标签集合",valid = false)
private List<Label> infoSourceLabelList;
//是否免审核(1-是;0-否)
@FieldDescription(value = "免审核状态")
private Integer isFreeCheck;
//得分范围-研究中心
//最小得分
@FieldDescription(value = "最小得分")
private Integer minScore;
//最大得分
@FieldDescription(value = "最大得分")
private Integer maxScore;
//es查询字段数组
@FieldDescription(value = "查询字段数组")
private String[] fetchFields;
//排除字段数组
@FieldDescription(value = "排除字段数组")
private String[] excludeFields = new String[]{"content", "contentWithTag"};
//排序参数
//排序字段
@FieldDescription(value = "排序字段")
private String column = "publishDate";
//排序方式 asc/desc
@FieldDescription(value = "排序方式")
private String order = "desc";
//置顶排序是否起效(1-是;0-否)
@FieldDescription(value = "置顶排序是否起效")
private Integer topSortValid = 0;
//分页参数
//当前页
@FieldDescription(value = "当前页")
private Integer pageNo = 1;
//每页返回条数
@FieldDescription(value = "每页返回条数")
private Integer pageSize = 10;
}
...@@ -2121,6 +2121,18 @@ public class EsService { ...@@ -2121,6 +2121,18 @@ public class EsService {
if (StringUtils.isNotBlank(crawler)) { if (StringUtils.isNotBlank(crawler)) {
boolQuery.must(QueryBuilders.termQuery("source.keyword", crawler)); boolQuery.must(QueryBuilders.termQuery("source.keyword", crawler));
} }
//组合标签查询(不同类标签之间是与的关系,同一类标签之间是或的关系),示例: "a1,a2;c1,c2;e1,e2"
String composeSearchLabelIds = searchCondition.getComposeSearchLabelIds();
if (StringUtils.isNotEmpty(composeSearchLabelIds)) {
//分号隔开的标签查询用且的关系
String[] split = composeSearchLabelIds.split(";");
for (String items : split) {
List<String> ids = Arrays.asList(items.split(","));
NestedQueryBuilder nestedQueryBuilder = QueryBuilders
.nestedQuery("labels", QueryBuilders.termsQuery("labels.relationId",ids), ScoreMode.None);
boolQuery.must(nestedQueryBuilder);
}
}
//关联标签id集合 //关联标签id集合
List<String> labelIds = searchCondition.getLabelIds(); List<String> labelIds = searchCondition.getLabelIds();
if (CollectionUtils.isNotEmpty(labelIds)) { if (CollectionUtils.isNotEmpty(labelIds)) {
......
...@@ -2,6 +2,7 @@ package com.zzsn.event.mapper; ...@@ -2,6 +2,7 @@ package com.zzsn.event.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.event.entity.SysDictItem; import com.zzsn.event.entity.SysDictItem;
import com.zzsn.event.vo.DictTreeVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -21,4 +22,14 @@ public interface SysDictItemMapper extends BaseMapper<SysDictItem> { ...@@ -21,4 +22,14 @@ public interface SysDictItemMapper extends BaseMapper<SysDictItem> {
List<SysDictItem> listByDictCode(@Param("dictCode") String dictCode); List<SysDictItem> listByDictCode(@Param("dictCode") String dictCode);
SysDictItem dictItemInfoByName(@Param("dictCode") String dictCode,@Param("itemName") String itemName); SysDictItem dictItemInfoByName(@Param("dictCode") String dictCode,@Param("itemName") String itemName);
/**
* 获取字典值信息
*
* @param dictIds 字典id集合
* @return
* @author lkg
* @date 2024/12/30
*/
List<DictTreeVO> dictItemList(List<String> dictIds);
} }
...@@ -57,4 +57,5 @@ ...@@ -57,4 +57,5 @@
#{id} #{id}
</foreach> </foreach>
</select> </select>
</mapper> </mapper>
...@@ -10,4 +10,15 @@ ...@@ -10,4 +10,15 @@
select * from sys_dict_item item inner join sys_dict dict on item.dict_id = dict.id select * from sys_dict_item item inner join sys_dict dict on item.dict_id = dict.id
where dict.dict_code = #{dictCode} and item.item_text = #{itemName} where dict.dict_code = #{dictCode} and item.item_text = #{itemName}
</select> </select>
</mapper>
\ No newline at end of file <select id="dictItemList" resultType="com.zzsn.event.vo.DictTreeVO">
select item.id,item.item_text as name,item.pid,dict.id as dictId from sys_dict_item item inner join sys_dict dict on item.dict_id = dict.id
where item.status = 1
<if test="dictIds != null and dictIds.size() > 0">
and dict.id in
<foreach collection="dictIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
</mapper>
...@@ -3,6 +3,7 @@ package com.zzsn.event.service; ...@@ -3,6 +3,7 @@ package com.zzsn.event.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.event.entity.SysDictItem; import com.zzsn.event.entity.SysDictItem;
import com.zzsn.event.vo.CountVO; import com.zzsn.event.vo.CountVO;
import com.zzsn.event.vo.DictTreeVO;
import java.util.List; import java.util.List;
...@@ -29,4 +30,14 @@ public interface SysDictItemService extends IService<SysDictItem> { ...@@ -29,4 +30,14 @@ public interface SysDictItemService extends IService<SysDictItem> {
* @date 2024/12/30 * @date 2024/12/30
*/ */
void changeKey(List<CountVO> dataList, List<SysDictItem> dictItemList); void changeKey(List<CountVO> dataList, List<SysDictItem> dictItemList);
/**
* 获取字典值信息-树型结构
*
* @param dictIds 字典id集合
* @return
* @author lkg
* @date 2024/12/30
*/
List<DictTreeVO> dictItemTreeList(List<String> dictIds);
} }
...@@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.event.entity.SysDictItem; import com.zzsn.event.entity.SysDictItem;
import com.zzsn.event.mapper.SysDictItemMapper; import com.zzsn.event.mapper.SysDictItemMapper;
import com.zzsn.event.service.SysDictItemService; import com.zzsn.event.service.SysDictItemService;
import com.zzsn.event.util.tree.TreeUtil;
import com.zzsn.event.vo.CountVO; import com.zzsn.event.vo.CountVO;
import com.zzsn.event.vo.DictTreeVO;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -66,4 +68,12 @@ public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDi ...@@ -66,4 +68,12 @@ public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDi
} }
} }
} }
@Override
public List<DictTreeVO> dictItemTreeList(List<String> dictIds) {
List<DictTreeVO> itemList = baseMapper.dictItemList(dictIds);
List<DictTreeVO> tree = TreeUtil.tree(itemList, "0");
tree.forEach(e -> e.setPid(e.getDictId()));
return tree;
}
} }
package com.zzsn.event.util;
import com.zzsn.event.controller.reportData.FieldDescription;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
/**
* 实体字段工具类
*
* @author lkg
* @date 2025/4/9
*/
public class FieldUtil {
public static List<Map<String, Object>> fieldDetails(Class<?> clazz) {
List<Map<String, Object>> list = new ArrayList<>();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
Map<String, Object> fieldMap = new TreeMap<>();
FieldDescription fieldAnnotation = field.getAnnotation(FieldDescription.class);
if (fieldAnnotation != null && fieldAnnotation.valid()) {
fieldMap.put("fieldName", field.getName());
fieldMap.put("fieldType", field.getType().getSimpleName());
fieldMap.put("fieldDescription", fieldAnnotation.value());
if (List.class.isAssignableFrom(field.getType())) {
Class<?> elementType = getCollectionElementType(field.getGenericType());
if (elementType.isAssignableFrom(Integer.class)) {
fieldMap.put("fieldType", field.getType().getSimpleName() + "<Integer>");
} else if (elementType.isAssignableFrom(String.class )) {
fieldMap.put("fieldType", field.getType().getSimpleName() + "<String>");
} else {
List<Map<String, Object>> children = fieldDetails(elementType);
fieldMap.put("children", children);
}
}
list.add(fieldMap);
}
}
return list;
}
private static Class<?> getCollectionElementType(java.lang.reflect.Type collectionType) {
if (collectionType instanceof java.lang.reflect.ParameterizedType) {
java.lang.reflect.ParameterizedType aType = (java.lang.reflect.ParameterizedType) collectionType;
java.lang.reflect.Type[] fieldArgTypes = aType.getActualTypeArguments();
for (java.lang.reflect.Type fieldArgType : fieldArgTypes) {
return (Class<?>) fieldArgType; // 返回第一个元素的类型,通常集合只有一个泛型参数
}
}
return Object.class; // 如果没有找到泛型类型,返回Object类
}
}
package com.zzsn.event.vo;
import com.zzsn.event.util.tree.Node;
import lombok.Data;
/**
*
*
* @author lkg
* @date 2025/4/1
*/
@Data
public class DictTreeVO extends Node {
private Boolean ynItem = true;
private String dictId;
}
...@@ -69,6 +69,10 @@ public class InfoDataSearchCondition { ...@@ -69,6 +69,10 @@ public class InfoDataSearchCondition {
//爬虫类型 //爬虫类型
private String crawler; private String crawler;
//组合标签查询(不同类标签之间是与的关系,同一类标签之间是或的关系),示例: "a,b;c,d;e,f"
private String composeSearchLabelIds;
/**----企业类标签筛选----**/ /**----企业类标签筛选----**/
//企业类标签id集合 //企业类标签id集合
private List<String> enterpriseLabelTypeIds; private List<String> enterpriseLabelTypeIds;
......
package com.zzsn.event.vo.es; package com.zzsn.event.vo.es;
import com.zzsn.event.controller.reportData.FieldDescription;
import lombok.Data; import lombok.Data;
/** /**
...@@ -11,6 +12,7 @@ public class Label { ...@@ -11,6 +12,7 @@ public class Label {
private String hitRemarks; private String hitRemarks;
//标签标识 //标签标识
@FieldDescription(value = "标签标识")
private String labelMark; private String labelMark;
//标签备注 //标签备注
...@@ -20,9 +22,11 @@ public class Label { ...@@ -20,9 +22,11 @@ public class Label {
private String sourceId; private String sourceId;
//关联标签id //关联标签id
@FieldDescription(value = "标签id")
private String relationId; private String relationId;
//关联标签名称 //关联标签名称
@FieldDescription(value = "标签名称")
private String relationName; private String relationName;
//得分 //得分
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论