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

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

@ -8,15 +8,16 @@
*/ */
// 目录树数据缓存 // 目录树数据缓存
const dirCache = new Map(); 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, const listPage = layui.listPage,
form = layui.form, form = layui.form,
element = layui.element, element = layui.element,
laydate = layui.laydate, laydate = layui.laydate,
globalTree = layui.globalTree; globalTree = layui.globalTree,
DataLabel = layui.datalabel;
let metaListTable, dirFileTable, tagSelector, tags = [], unchecked_tags = [], conditions = [];
let metaListTable, dirFileTable, tagSelector, tags = [], conditions = [];
const unchecked_tags = new Set();
// 初始化 // 初始化
initDirectoryTree(); initDirectoryTree();
@ -273,15 +274,13 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
$('#condition-div').slideToggle(100, 'linear', conditionSlideToggle) $('#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) { 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) { element.on('tabDelete(condition-tab)', function (data) {
let key = $(this).parent().data('key'); let key = $(this).parent().data('key');
if(key === 'markTag'){
tags = [];
}
let formVal = form.val('search-form'); let formVal = form.val('search-form');
formVal[key] = ''; formVal[key] = '';
form.val('search-form', formVal); form.val('search-form', formVal);
@ -310,7 +312,7 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
$('#condition-clear-btn').on('click', function () { $('#condition-clear-btn').on('click', function () {
$('#searchKeyInput').val(''); $('#searchKeyInput').val('');
tags = []; tags = [];
unchecked_tags = []; unchecked_tags.clear();
conditions = []; conditions = [];
beginSearch(); beginSearch();
}); });
@ -342,9 +344,7 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
function setMarkTagInputValue() { function setMarkTagInputValue() {
let temp = []; let temp = [];
for (let tag of tags) { for (let tag of tags) {
let arr = tag.split('-'); temp.push(tag.title);
let text = tag.replace(arr[0] + '-' + arr[1] + '-', '');
temp.push(text);
} }
$('#mark-selector-input').val(temp.join(', ')); $('#mark-selector-input').val(temp.join(', '));
} }
@ -370,7 +370,7 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
let htm = ''; let htm = '';
conditions = []; conditions = [];
for (let key in formVal) { for (let key in formVal) {
if (key == 'searchKeyInput') continue; if (key === 'searchKeyInput') continue;
let fieldName = key, fieldValue = formVal[key], logicJudgement; let fieldName = key, fieldValue = formVal[key], logicJudgement;
// 如果fieldName是条件下拉框,则跳过 // 如果fieldName是条件下拉框,则跳过
if (fieldName.startsWith('logic-') || fieldName === 'directoryId' || fieldName === 'metadataId') continue; if (fieldName.startsWith('logic-') || fieldName === 'directoryId' || fieldName === 'metadataId') continue;
@ -397,11 +397,11 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
condition = '包含'; condition = '包含';
} }
if (fieldName == 'secretLevel') { if (fieldName === 'secretLevel') {
hasText = $(`select[name="secretLevel"] option[value="${fieldValue}"]`).text(); hasText = $(`select[name="secretLevel"] option[value="${fieldValue}"]`).text();
} else if (fieldName == 'dataFrom') { } else if (fieldName === 'dataFrom') {
hasText = $(`select[name="dataFrom"] option[value="${fieldValue}"]`).text(); hasText = $(`select[name="dataFrom"] option[value="${fieldValue}"]`).text();
} else if (fieldName == 'dataType') { } else if (fieldName === 'dataType') {
hasText = $(`select[name="dataType"] option[value="${fieldValue}"]`).text(); hasText = $(`select[name="dataType"] option[value="${fieldValue}"]`).text();
} }
conditions.push({fieldName, fieldValue, logicJudgement}) 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) { for (let tag of tags) {
let tag_arr = tag.split('-'); let checked = 'checked';
let tag_type = tag_arr[1], tag_text = tag_arr[2], temp_tags = temp[tag_type]; if (unchecked_tags.has(tag.id + '')) {
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)) {
checked = ''; 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">`;
} }
if (tag_htm){
htm += `<li data-key="markTag">${tag_type}${tag_htm}</li>`; htm += `<li data-key="markTag">置标标签:${tag_htm}</li>`;
} }
$('#condition-tab ul').html(htm); $('#condition-tab ul').html(htm);
element.render('tab'); 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'); form.render('checkbox');
$('li[data-key="markTag"] .layui-form-checkbox').on('click', function () { $('li[data-key="markTag"] .layui-form-checkbox').on('click', function () {
let val = $(this).prev().val(), index = unchecked_tags.indexOf(val); let val = $(this).prev().val();
if (!$(this).hasClass('layui-form-checked')) { if(unchecked_tags.has(val)){
unchecked_tags.push(val); unchecked_tags.delete(val);
} else if (index > -1) { }else{
unchecked_tags.splice(index, 1) unchecked_tags.add(val);
} }
beginSearch(); beginSearch();
}) })
@ -453,7 +442,6 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
} }
} }
function beginSearch() { function beginSearch() {
setMarkTagsValue() setMarkTagsValue()
metaListTable.where.conditions = conditions; metaListTable.where.conditions = conditions;

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

@ -118,8 +118,7 @@ layui.define(['globalTree'], function (exports) {
function addEventListen() { function addEventListen() {
$elem.find('.choose-data').on('click', function () { $elem.find('.choose-data').on('click', function () {
let labelId = $(this).data('labelId') || 0; let labelId = $(this).data('labelId') || 0;
labelId = labelId === 'undefined' ? 0 : labelId; chooseLabelData(labelId, labelIdPath).then(data => {
chooseLabelData(labelId, fixedTitlePath, labelIdPath).then(data => {
component.newLabel = data; component.newLabel = data;
renderLabelElement(component); 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 => { return new Promise(resolve => {
layer.open({ layer.open({
type: 1, type: 1,
@ -160,17 +170,27 @@ layui.define(['globalTree'], function (exports) {
all: true, all: true,
cache: true, cache: true,
checkbar: true, checkbar: true,
checkbarType: 'only', checkbarType: multiple ? 'no-all' : 'only',
scroll: '#label-tree', scroll: '#label-tree',
done: function () { done: function () {
let _chooseIds = [];
if (disableIds.length > 0) { if (disableIds.length > 0) {
treeObj.chooseDataInit(disableIds.join(',')); _chooseIds.concat(disableIds);
treeObj.setDisabledNodes(disableIds.join(',')); treeObj.setDisabledNodes(disableIds.join(','));
} }
if (chooseIds) {
_chooseIds.concat(Array.isArray(chooseIds) ? chooseIds : chooseIds.split(','));
}
treeObj.chooseDataInit(disableIds.join(','));
$('#layerCancel').on('click', () => layer.close(index)); $('#layerCancel').on('click', () => layer.close(index));
$('#layerOk').on('click', () => { $('#layerOk').on('click', () => {
if (treeObj.chooseNodes && treeObj.chooseNodes.length > 0) { const nodes = treeObj.chooseNodes;
resolve && resolve(treeObj.chooseNodes[0].basicData); 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); layer.close(index);
} else { } else {
showErrorMsg('请选择一条数据') showErrorMsg('请选择一条数据')
@ -182,7 +202,21 @@ layui.define(['globalTree'], function (exports) {
if (disableIds.length > 0) { if (disableIds.length > 0) {
treeObj.chooseDataInit(disableIds.join(',')); treeObj.chooseDataInit(disableIds.join(','));
} }
const chooseNodes = treeObj.chooseNodes;
if (!multiple) {
treeObj.chooseNodes = nodes; 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 = { const _exports = {
getData: (entityId, entityType) => _CACHE.getData(entityId, entityType), getData: (entityId, entityType) => _CACHE.getData(entityId, entityType),
setData, setData,
openChooseDialog: chooseLabelData
}; };
exports('datalabel', _exports) exports('datalabel', _exports)
}) })

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

@ -2,9 +2,9 @@ package com.keyware.shandan.bianmu.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.keyware.shandan.bianmu.entity.LabelEntity; import com.keyware.shandan.bianmu.entity.LabelEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Select;
import java.io.Serializable;
import java.util.List; import java.util.List;
/** /**
@ -14,6 +14,21 @@ import java.util.List;
@Mapper @Mapper
public interface LabelEntityMapper extends BaseMapper<LabelEntity> { 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}") @Select("SELECT * FROM B_DATA_LABEL_ENTITY WHERE ENTITY_ID = #{entityId}")
List<LabelEntity> selectByEntityId(String entityId); List<LabelEntity> selectByEntityId(String entityId);
} }