提交 69b2d991 作者: yanxin

支持按照标签检索数据

上级 cd2a0e57
...@@ -2,7 +2,9 @@ package com.zzsn.leaderbase.service.impl; ...@@ -2,7 +2,9 @@ package com.zzsn.leaderbase.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
...@@ -22,10 +24,7 @@ import com.zzsn.leaderbase.service.CharacterTagService; ...@@ -22,10 +24,7 @@ import com.zzsn.leaderbase.service.CharacterTagService;
import com.zzsn.leaderbase.service.IGeneratorIdService; import com.zzsn.leaderbase.service.IGeneratorIdService;
import com.zzsn.leaderbase.service.LeaderCategoryService; import com.zzsn.leaderbase.service.LeaderCategoryService;
import com.zzsn.leaderbase.util.ExcelUtil; import com.zzsn.leaderbase.util.ExcelUtil;
import com.zzsn.leaderbase.vo.BasicInfoListVo; import com.zzsn.leaderbase.vo.*;
import com.zzsn.leaderbase.vo.CharacterVo;
import com.zzsn.leaderbase.vo.CheckVo;
import com.zzsn.leaderbase.vo.Result;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -69,7 +68,7 @@ public class CharacterBasicInfoServiceImpl extends ServiceImpl<CharacterBasicInf ...@@ -69,7 +68,7 @@ public class CharacterBasicInfoServiceImpl extends ServiceImpl<CharacterBasicInf
@Autowired @Autowired
LeaderCategoryService leaderCategoryService; LeaderCategoryService leaderCategoryService;
@Autowired @Autowired(required = false)
private RemoteSystemService remoteSystemService; private RemoteSystemService remoteSystemService;
@Override @Override
...@@ -85,6 +84,12 @@ public class CharacterBasicInfoServiceImpl extends ServiceImpl<CharacterBasicInf ...@@ -85,6 +84,12 @@ public class CharacterBasicInfoServiceImpl extends ServiceImpl<CharacterBasicInf
@Override @Override
public IPage<CharacterBasicInfo> getList(BasicInfoListVo basicInfoListVo) { public IPage<CharacterBasicInfo> getList(BasicInfoListVo basicInfoListVo) {
//多级数据字典标签,获取当前选择标签层级之后的相差3级以内的标签
List<LabelVO> labelCodeList = basicInfoListVo.getLabelList();
if (CollUtil.isNotEmpty(labelCodeList)) {
List<LabelVO> realList = getRealList(labelCodeList);
basicInfoListVo.setLabelList(realList);
}
List<CharacterBasicInfo> list = baseMapper.getList(basicInfoListVo); List<CharacterBasicInfo> list = baseMapper.getList(basicInfoListVo);
Integer total = baseMapper.getListCount(basicInfoListVo); Integer total = baseMapper.getListCount(basicInfoListVo);
List<CharacterBasicInfo> listNew =setListValues(list,basicInfoListVo); List<CharacterBasicInfo> listNew =setListValues(list,basicInfoListVo);
...@@ -98,6 +103,53 @@ public class CharacterBasicInfoServiceImpl extends ServiceImpl<CharacterBasicInf ...@@ -98,6 +103,53 @@ public class CharacterBasicInfoServiceImpl extends ServiceImpl<CharacterBasicInf
return page; return page;
} }
/**
* 多级数据字典标签,获取当前选择标签层级之后的相差3级以内的标签
*
* @param labelCodeList 标签参数
* @author lkg
* @date 2024/12/10
*/
private List<LabelVO> getRealList(List<LabelVO> labelCodeList) {
Set<LabelVO> set = new HashSet<>();
Map<String, List<SysDictItem>> dictMap = new HashMap<>();
//若有数据字典类数据进行检索,提前准备好字典数据
Map<String, List<LabelVO>> collect = labelCodeList.stream()
.filter(e -> e.getDictCode() != null)
.collect(Collectors.groupingBy(LabelVO::getDictCode));
if (MapUtil.isNotEmpty(collect)) {
for (Map.Entry<String, List<LabelVO>> entry : collect.entrySet()) {
String dictCode = entry.getKey();
//关联数据字典,展示字典树
List<SysDictItem> sysDictItems = JSON.parseArray(remoteSystemService.sysDictItemList(dictCode),SysDictItem.class);
dictMap.put(dictCode, sysDictItems);
}
}
for (LabelVO LabelVO : labelCodeList) {
Integer level = LabelVO.getLevel();
if (level != null) {
String labelCode = LabelVO.getLabelCode();
String labelItemId = LabelVO.getLabelItemId();
String dictCode = LabelVO.getDictCode();
List<SysDictItem> sysDictItems = dictMap.get(dictCode);
List<SysDictItem> children = sysDictItems.stream().filter(e -> e.getPathIds().contains(labelItemId) && e.getLevel() <= (level + 2)).collect(Collectors.toList());
Set<LabelVO> followSet = new HashSet<>();
if (CollUtil.isNotEmpty(children)) {
for (SysDictItem child : children) {
LabelVO map = new LabelVO();
map.setLabelCode(labelCode);
map.setLabelItemCode(child.getItemValue());
followSet.add(map);
}
set.addAll(followSet);
}
} else {
set.add(LabelVO);
}
}
return new ArrayList<>(set);
}
private List<CharacterBasicInfo> setListValues(List<CharacterBasicInfo> list, BasicInfoListVo basicInfoListVo) { private List<CharacterBasicInfo> setListValues(List<CharacterBasicInfo> list, BasicInfoListVo basicInfoListVo) {
if(CollectionUtil.isNotEmpty(list)){ if(CollectionUtil.isNotEmpty(list)){
List<String> ids=list.stream().map(CharacterBasicInfo::getId).collect(Collectors.toList()); List<String> ids=list.stream().map(CharacterBasicInfo::getId).collect(Collectors.toList());
......
...@@ -2,6 +2,8 @@ package com.zzsn.leaderbase.vo; ...@@ -2,6 +2,8 @@ package com.zzsn.leaderbase.vo;
import lombok.Data; import lombok.Data;
import java.util.List;
/** /**
* @Version 1.0 * @Version 1.0
* @Author: ZhangJingKun * @Author: ZhangJingKun
...@@ -45,4 +47,9 @@ public class BasicInfoListVo { ...@@ -45,4 +47,9 @@ public class BasicInfoListVo {
//标签 //标签
private String tagId; private String tagId;
/**
* 标签信息集合
*/
private List<LabelVO> labelList;
} }
package com.zzsn.leaderbase.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
/**
*
*
* @author lkg
* @date 2024/12/11
*/
@Data
public class LabelVO {
/**
* 标签 唯一编码
*/
private String labelCode;
/**
* 数据字典编码
*/
private String dictCode;
/**
* 标签值/字典值/数仓值 唯一编码
*/
private String labelItemCode;
/**
* 标签值id(用于检索)
*/
@TableField(exist = false)
private String labelItemId;
/**
* 层级(用于检索)
*/
@TableField(exist = false)
private Integer level;
}
...@@ -9,10 +9,9 @@ ...@@ -9,10 +9,9 @@
FROM character_basic_info cbi FROM character_basic_info cbi
JOIN ( JOIN (
SELECT uid,max(create_time) create_time SELECT uid,max(create_time) create_time
FROM character_basic_info FROM character_basic_info a
where 1 = 1
<include refid="getListWhere"/> <include refid="getListWhere"/>
group by uid group by a.uid
ORDER BY ${column} ${order} ORDER BY ${column} ${order}
limit #{offset}, #{pageSize} limit #{offset}, #{pageSize}
) sub on cbi.uid = sub.uid and cbi.create_time = sub.create_time ) sub on cbi.uid = sub.uid and cbi.create_time = sub.create_time
...@@ -34,46 +33,55 @@ ...@@ -34,46 +33,55 @@
<select id="getAllList" resultType="com.zzsn.leaderbase.entity.CharacterBasicInfo"> <select id="getAllList" resultType="com.zzsn.leaderbase.entity.CharacterBasicInfo">
select select
* *
from character_basic_info from character_basic_info a
where 1 = 1
<include refid="getListWhere"/> <include refid="getListWhere"/>
group by uid group by a.uid
ORDER BY CONVERT (${column} USING gbk) ${order} ORDER BY CONVERT (${column} USING gbk) ${order}
</select> </select>
<select id="getListCount" resultType="int"> <select id="getListCount" resultType="int">
select count(1) from ( select count(1) from (
SELECT count(1) as c SELECT count(1) as c
from character_basic_info from character_basic_info a
where 1 = 1
<include refid="getListWhere"/> <include refid="getListWhere"/>
group by uid group by a.uid
)t1 )t1
</select> </select>
<sql id="getListWhere"> <sql id="getListWhere">
<if test="labelList != null and labelList.size()>0">
INNER JOIN clb_label_expert_map lem ON a.id = lem.entity_code
</if>
where 1 = 1
<if test="labelList != null and labelList.size()>0">
and
<foreach collection="labelList" item="item" index="index" open="(" separator="or"
close=")">
lem.label_code = #{item.labelCode} and lem.label_item_code = #{item.labelItemCode}
</foreach>
</if>
<if test="keyword != null and keyword != ''"> <if test="keyword != null and keyword != ''">
AND CONCAT_WS(',',name,biographical_notes,department,duty,update_desc,article_title,article_origin,tag_name) AND CONCAT_WS(',',a.name,a.biographical_notes,a.department,a.duty,update_desc,a.article_title,a.article_origin,a.tag_name)
like '%${keyword}%' like '%${keyword}%'
</if> </if>
<if test="name != null and name != ''"> <if test="name != null and name != ''">
AND name like '%${name}%' AND a.name like '%${name}%'
</if> </if>
<if test="department != null and department != ''"> <if test="department != null and department != ''">
AND department like '%${department}%' AND a.department like '%${department}%'
</if> </if>
<if test="duty != null and duty != ''"> <if test="duty != null and duty != ''">
AND duty like '%${duty}%' AND a.duty like '%${duty}%'
</if> </if>
<if test="category != null and category != ''"> <if test="category != null and category != ''">
AND category = #{category} AND a.category = #{category}
</if> </if>
<if test="typeId != null and typeId != ''"> <if test="typeId != null and typeId != ''">
AND type_id = #{typeId} AND a.type_id = #{typeId}
</if> </if>
<if test="tagId != null and tagId != ''"> <if test="tagId != null and tagId != ''">
<foreach item="item" index="index" collection="tagId.split(',')"> <foreach item="item" index="index" collection="tagId.split(',')">
AND tag_id like '%${item}%' AND a.tag_id like '%${item}%'
</foreach> </foreach>
</if> </if>
</sql> </sql>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论