修复:综合浏览系统中置标标签查询数据时,数据列表显示的数据不对的问题

master
Guo XIn 1 year ago
parent abd3029311
commit 9cb96f9dbf
  1. 19
      shandan-browser/src/main/java/com/keyware/shandan/browser/service/MetadataSearchService.java
  2. 78
      shandan-browser/src/main/resources/static/js/browser.js
  3. 1
      shandan-browser/src/main/resources/view/browser.html
  4. 49
      shandan-common/src/main/resources/static/js/common/layui/extend/datalabel.js
  5. 4
      shandan-system/src/main/java/com/keyware/shandan/bianmu/entity/LabelEntity.java
  6. 19
      shandan-system/src/main/java/com/keyware/shandan/bianmu/mapper/LabelEntityMapper.java

@ -18,6 +18,7 @@ import org.springframework.util.Assert;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Administrator
@ -81,17 +82,15 @@ public class MetadataSearchService {
}
break;
case "markTag":
String tagText = item.getFieldValue();
List<String> tags = Arrays.asList(tagText.split(","));
StringBuilder existsSql = new StringBuilder("select 1 from MARK_RECORD MR where MR.ENTITY_ID = V_DIRECTORY_RESOURCE.ID and ( 1 = 1 ");
tags.forEach(tagItem -> {
if (StringUtils.hasText(tagItem)) {
String[] arr = tagItem.split("-");
existsSql.append(" and MR.MARK_VALUE like '%").append(arr[1]).append("%' ");
}
});
existsSql.append(")");
String tagIds = item.getFieldValue();
List<String> ids = Arrays.asList(tagIds.split(","));
if (ids.size() > 0) {
StringBuilder existsSql = new StringBuilder("select 1 from (select ENTITY_ID, WM_CONCAT(LABEL_ID) LABEL_IDS from B_DATA_LABEL_ENTITY DLN where DLN.ENTITY_ID = V_DIRECTORY_RESOURCE.ID group by ENTITY_ID) tmp1");
List<String> andSqlList = ids.stream().map(id -> "tmp1.LABEL_IDS like '%" + id + "%'").collect(Collectors.toList());
existsSql.append(" where ").append(String.join(" and ", andSqlList));
wrapper.exists(existsSql.toString());
}
break;
default:
}

@ -8,15 +8,16 @@
*/
// 目录树数据缓存
const dirCache = new Map();
layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'dropdown', 'laydate', 'dict'], function () {
layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'dropdown', 'laydate', 'dict', 'datalabel'], function () {
const listPage = layui.listPage,
form = layui.form,
element = layui.element,
laydate = layui.laydate,
globalTree = layui.globalTree;
let metaListTable, dirFileTable, tagSelector, tags = [], unchecked_tags = [], conditions = [];
globalTree = layui.globalTree,
DataLabel = layui.datalabel;
let metaListTable, dirFileTable, tagSelector, tags = [], conditions = [];
const unchecked_tags = new Set();
// 初始化
initDirectoryTree();
@ -273,15 +274,13 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
$('#condition-div').slideToggle(100, 'linear', conditionSlideToggle)
});
if (!tagSelector) {
tagSelector = new MarkerSelector('#mark-selector-input');
}
tagSelector.bindBtnEvent()
tagSelector.onOkBtn(data => {
tags = data
setMarkTagInputValue();
});
$('#mark-selector-input').on('click', function () {
DataLabel.openChooseDialog(null, null, null, true).then((labels) => {
tags = labels || [];
setMarkTagInputValue();
})
})
// 监听标签点击事件
element.on('tab(condition-tab)', function (data) {
// 点击后移除选中样式
@ -296,6 +295,9 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
// 监听条件标签删除事件
element.on('tabDelete(condition-tab)', function (data) {
let key = $(this).parent().data('key');
if(key === 'markTag'){
tags = [];
}
let formVal = form.val('search-form');
formVal[key] = '';
form.val('search-form', formVal);
@ -310,7 +312,7 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
$('#condition-clear-btn').on('click', function () {
$('#searchKeyInput').val('');
tags = [];
unchecked_tags = [];
unchecked_tags.clear();
conditions = [];
beginSearch();
});
@ -342,9 +344,7 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
function setMarkTagInputValue() {
let temp = [];
for (let tag of tags) {
let arr = tag.split('-');
let text = tag.replace(arr[0] + '-' + arr[1] + '-', '');
temp.push(text);
temp.push(tag.title);
}
$('#mark-selector-input').val(temp.join(', '));
}
@ -370,7 +370,7 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
let htm = '';
conditions = [];
for (let key in formVal) {
if (key == 'searchKeyInput') continue;
if (key === 'searchKeyInput') continue;
let fieldName = key, fieldValue = formVal[key], logicJudgement;
// 如果fieldName是条件下拉框,则跳过
if (fieldName.startsWith('logic-') || fieldName === 'directoryId' || fieldName === 'metadataId') continue;
@ -397,11 +397,11 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
condition = '包含';
}
if (fieldName == 'secretLevel') {
if (fieldName === 'secretLevel') {
hasText = $(`select[name="secretLevel"] option[value="${fieldValue}"]`).text();
} else if (fieldName == 'dataFrom') {
} else if (fieldName === 'dataFrom') {
hasText = $(`select[name="dataFrom"] option[value="${fieldValue}"]`).text();
} else if (fieldName == 'dataType') {
} else if (fieldName === 'dataType') {
hasText = $(`select[name="dataType"] option[value="${fieldValue}"]`).text();
}
conditions.push({fieldName, fieldValue, logicJudgement})
@ -409,40 +409,29 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
}
}
let temp = [];
let tag_htm = '';
for (let tag of tags) {
let tag_arr = tag.split('-');
let tag_type = tag_arr[1], tag_text = tag_arr[2], temp_tags = temp[tag_type];
if (!temp_tags) {
temp_tags = []
}
temp_tags.push({id: tag_arr[0], text: tag_text});
temp[tag_type] = temp_tags;
}
for (let type in temp) {
let tag_type = type, tag_items = temp[type], tag_htm = '';
for (let item of tag_items) {
let val = item.id + '-' + item.text, checked = 'checked';
if (unchecked_tags.includes(val)) {
let checked = 'checked';
if (unchecked_tags.has(tag.id + '')) {
checked = '';
}
tag_htm += `<input type="checkbox" title="${item.text}" value="${val}" ${checked} lay-skin="primary">`;
tag_htm += `<input type="checkbox" title="${tag.title}" value="${tag.id}" ${checked} lay-skin="primary">`;
}
htm += `<li data-key="markTag">${tag_type}${tag_htm}</li>`;
if (tag_htm){
htm += `<li data-key="markTag">置标标签:${tag_htm}</li>`;
}
$('#condition-tab ul').html(htm);
element.render('tab');
$('#condition-tab ul li[data-key="markTag"] i').remove();
$('#condition-tab ul li[data-key="markTag"] i').css({'margin-left': '-10px'});
form.render('checkbox');
$('li[data-key="markTag"] .layui-form-checkbox').on('click', function () {
let val = $(this).prev().val(), index = unchecked_tags.indexOf(val);
if (!$(this).hasClass('layui-form-checked')) {
unchecked_tags.push(val);
} else if (index > -1) {
unchecked_tags.splice(index, 1)
let val = $(this).prev().val();
if(unchecked_tags.has(val)){
unchecked_tags.delete(val);
}else{
unchecked_tags.add(val);
}
beginSearch();
})
@ -453,7 +442,6 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
}
}
function beginSearch() {
setMarkTagsValue()
metaListTable.where.conditions = conditions;

@ -219,7 +219,6 @@
<!-- js -->
<script th:replace="common/head::static-foot"></script>
<script th:src="@{/js/business/mark/markTag.js}"></script>
<script th:src="@{/js/marker_selector.js}"></script>
<script th:src="@{/js/browser.js}"></script>
<script th:src="@{/js/view.js}"></script>
<script type="text/javascript">

@ -118,8 +118,7 @@ layui.define(['globalTree'], function (exports) {
function addEventListen() {
$elem.find('.choose-data').on('click', function () {
let labelId = $(this).data('labelId') || 0;
labelId = labelId === 'undefined' ? 0 : labelId;
chooseLabelData(labelId, fixedTitlePath, labelIdPath).then(data => {
chooseLabelData(labelId, labelIdPath).then(data => {
component.newLabel = data;
renderLabelElement(component);
});
@ -136,7 +135,18 @@ layui.define(['globalTree'], function (exports) {
}
}
function chooseLabelData(labelId, titlePath, idPath) {
/**
* 显示置标标签选择窗口
* @param labelId {String} 上级置标标签ID为空则查询所有
* @param idPath {String} 上级标签的id路径用于默认勾选和设置为不可选
* @param chooseIds {String | String[]} 默认选中的ID集合逗号拼接的数组或者字符数组
* @param multiple {Boolean} 多选
* @returns {Promise<Object>}
*/
function chooseLabelData(labelId, idPath, chooseIds, multiple) {
if (!labelId || labelId === 'undefined') {
labelId = 0;
}
return new Promise(resolve => {
layer.open({
type: 1,
@ -160,17 +170,27 @@ layui.define(['globalTree'], function (exports) {
all: true,
cache: true,
checkbar: true,
checkbarType: 'only',
checkbarType: multiple ? 'no-all' : 'only',
scroll: '#label-tree',
done: function () {
let _chooseIds = [];
if (disableIds.length > 0) {
treeObj.chooseDataInit(disableIds.join(','));
_chooseIds.concat(disableIds);
treeObj.setDisabledNodes(disableIds.join(','));
}
if (chooseIds) {
_chooseIds.concat(Array.isArray(chooseIds) ? chooseIds : chooseIds.split(','));
}
treeObj.chooseDataInit(disableIds.join(','));
$('#layerCancel').on('click', () => layer.close(index));
$('#layerOk').on('click', () => {
if (treeObj.chooseNodes && treeObj.chooseNodes.length > 0) {
resolve && resolve(treeObj.chooseNodes[0].basicData);
const nodes = treeObj.chooseNodes;
if (nodes && nodes.length > 0) {
let return_data = nodes.map(node => node.basicData);
if (!multiple) {
resolve(return_data[0]);
}
resolve(return_data);
layer.close(index);
} else {
showErrorMsg('请选择一条数据')
@ -182,7 +202,21 @@ layui.define(['globalTree'], function (exports) {
if (disableIds.length > 0) {
treeObj.chooseDataInit(disableIds.join(','));
}
const chooseNodes = treeObj.chooseNodes;
if (!multiple) {
treeObj.chooseNodes = nodes;
} else {
const nodeMap = new Map();
const choosePids = nodes.map(n => n.id);
// 如果包含选中节点中包含上下级关系,则在选中节点中去掉上级节点
for(const node of nodes){
if(nodeMap.has(node.parentId)){
nodeMap.delete(node.parentId);
}
nodeMap.set(node.id, node)
}
treeObj.chooseNodes = [...nodeMap.values()];
}
}
}
});
@ -256,6 +290,7 @@ layui.define(['globalTree'], function (exports) {
const _exports = {
getData: (entityId, entityType) => _CACHE.getData(entityId, entityType),
setData,
openChooseDialog: chooseLabelData
};
exports('datalabel', _exports)
})

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.keyware.shandan.common.util.MD5Util;
import lombok.*;
import org.apache.ibatis.annotations.One;
import org.springframework.util.StringUtils;
import java.io.Serializable;
@ -42,6 +43,9 @@ public class LabelEntity implements Serializable {
@TableField("LABEL")
private String label;
@TableField(exist = false)
private DataLabelsVo data;
public String getId() {
if (StringUtils.hasText(id)) {
return id;

@ -2,9 +2,9 @@ package com.keyware.shandan.bianmu.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.keyware.shandan.bianmu.entity.LabelEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.*;
import java.io.Serializable;
import java.util.List;
/**
@ -14,6 +14,21 @@ import java.util.List;
@Mapper
public interface LabelEntityMapper extends BaseMapper<LabelEntity> {
@Override
@Results(id="all_result_map", value = {
@Result(id = true, column = "ID", property = "id"),
@Result(column = "ENTITY_ID", property = "entityId"),
@Result(column = "ENTITY_TYPE", property = "entityType"),
@Result(column = "LABEL_ID", property = "labelId"),
@Result(column = "FIELD_TITLE", property = "fieldTitle"),
@Result(column = "LABEL", property = "label"),
@Result(column = "LABEL_ID", property = "data", one = @One(select = "com.keyware.shandan.bianmu.mapper.DataLabelsMapper.selectById"))
})
@Select("SELECT * FROM B_DATA_LABEL_ENTITY WHERE ID = #{id}")
LabelEntity selectById(Serializable id);
@ResultMap(value = {"all_result_map"})
@Select("SELECT * FROM B_DATA_LABEL_ENTITY WHERE ENTITY_ID = #{entityId}")
List<LabelEntity> selectByEntityId(String entityId);
}