package com.product.face.entity;
|
|
import com.alibaba.fastjson.JSON;
|
import com.google.common.collect.Lists;
|
import com.google.common.collect.Maps;
|
import com.product.admin.config.CmnConst;
|
import com.product.admin.service.DictService;
|
import com.product.admin.service.SystemFaceService;
|
import com.product.common.lang.StringUtils;
|
import com.product.core.cache.DataPoolCacheImpl;
|
import com.product.core.cache.util.RedisUtil;
|
import com.product.core.config.CoreConst;
|
import com.product.core.entity.DataTableEntity;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.core.spring.context.SpringBeanUtil;
|
import com.product.core.spring.context.SpringMVCContextHolder;
|
import com.product.face.config.FaceConst;
|
import com.product.module.sys.entity.SystemUser;
|
import com.product.util.BaseUtil;
|
|
import java.io.Serializable;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @Author cheng
|
* @Description 列表字段操作类
|
* @Date 2021/9/7 14:34
|
* @Version 1.0
|
*/
|
public class FaceListEntity implements Serializable {
|
|
private static final long serialVersionUID = -6777140406080679771L;
|
/**
|
* 表uuid
|
*/
|
private String tableUuid;
|
/**
|
* face_uuid
|
*/
|
private String uuid;
|
/**
|
* 表单名
|
*/
|
private String faceName;
|
/**
|
* 功能uuid
|
*/
|
@Deprecated
|
private String functionUuid;
|
/**
|
* 字段集合
|
*/
|
private List<FaceField> faceFields;
|
/**
|
* 表名
|
*/
|
private String tableName;
|
|
/**
|
* 是否显示树
|
*/
|
private String treeShow;
|
|
/**
|
* 树数据源类型
|
*/
|
private String treeDataType;
|
|
/**
|
* 数据源
|
*/
|
private String treeDataSource;
|
|
/**
|
* 树label key
|
*/
|
private String treeLabelKey;
|
|
/**
|
* 树value key
|
*/
|
private String treeValueKey;
|
|
/**
|
* 获取表名
|
*
|
* @return
|
*/
|
public String getTableName() {
|
if (this.tableName == null && this.tableUuid != null) {
|
//从缓存中获取
|
DataTableEntity cacheData = DataPoolCacheImpl.getInstance().getCacheData("所有表信息(uuid)", new String[]{this.tableUuid});
|
if (cacheData != null && cacheData.getRows() > 0) {
|
String table_name = cacheData.getString(0, "table_name");
|
this.tableName = table_name;
|
}
|
}
|
return tableName;
|
}
|
|
/**
|
* 条件字段
|
*
|
* @param fieldName 字段名称
|
* @param faceUuid 字段uuid
|
* @param columnName 列名
|
* @param columnWidth 列宽
|
* @param sequence 排序
|
* @param fieldReference 参照
|
*/
|
public void addField(String fieldName, String faceUuid, String columnName, String columnWidth, Integer sequence, String fieldReference) {
|
FaceField faceField = new FaceField();
|
faceField.setFieldName(fieldName);
|
faceField.setFieldUuid(faceUuid);
|
faceField.setColumnName(columnName);
|
faceField.setColumnWidth(columnWidth);
|
faceField.setSequence(sequence);
|
faceField.setFieldReference(fieldReference);
|
if (this.faceFields == null) {
|
this.faceFields = Lists.newArrayList();
|
}
|
this.faceFields.add(faceField);
|
}
|
|
/**
|
* 字段排序方法
|
*/
|
public void sortField() {
|
if (this.faceFields != null && this.faceFields.size() > 0) {
|
this.faceFields.sort((a, b) -> {
|
return a.getSequence().compareTo(b.getSequence());
|
});
|
}
|
}
|
|
public String getTableUuid() {
|
return tableUuid;
|
}
|
|
public void setTableUuid(String tableUuid) {
|
this.tableUuid = tableUuid;
|
}
|
|
public String getUuid() {
|
return uuid;
|
}
|
|
public void setUuid(String uuid) {
|
this.uuid = uuid;
|
}
|
|
public String getFaceName() {
|
return faceName;
|
}
|
|
public void setFaceName(String faceName) {
|
this.faceName = faceName;
|
}
|
|
public String getFunctionUuid() {
|
return functionUuid;
|
}
|
|
public void setFunctionUuid(String functionUuid) {
|
this.functionUuid = functionUuid;
|
}
|
|
public List<FaceField> getFaceFields() {
|
return faceFields;
|
}
|
|
public void setFaceFields(List<FaceField> faceFields) {
|
this.faceFields = faceFields;
|
}
|
|
public void setTableName(String tableName) {
|
this.tableName = tableName;
|
}
|
|
public String getTreeShow() {
|
return treeShow;
|
}
|
|
public void setTreeShow(String treeShow) {
|
this.treeShow = treeShow;
|
}
|
|
public String getTreeDataType() {
|
return treeDataType;
|
}
|
|
public void setTreeDataType(String treeDataType) {
|
this.treeDataType = treeDataType;
|
}
|
|
public String getTreeDataSource() {
|
return treeDataSource;
|
}
|
|
public void setTreeDataSource(String treeDataSource) {
|
this.treeDataSource = treeDataSource;
|
}
|
|
public String getTreeLabelKey() {
|
return treeLabelKey;
|
}
|
|
public void setTreeLabelKey(String treeLabelKey) {
|
this.treeLabelKey = treeLabelKey;
|
}
|
|
public String getTreeValueKey() {
|
return treeValueKey;
|
}
|
|
public void setTreeValueKey(String treeValueKey) {
|
this.treeValueKey = treeValueKey;
|
}
|
|
/**
|
* 获取参照条件
|
*
|
* @param fieldName
|
* @param dictName
|
* @return
|
*/
|
private String getDictFilter(String fieldName, String dictName) {
|
StringBuilder filter = new StringBuilder();
|
DictService bean = SpringBeanUtil.getBean(DictService.class);
|
String manager_type = null;
|
SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
|
if (currentUser != null && currentUser.getCurrentManager() != null) {
|
manager_type = currentUser.getCurrentManager().getString(CmnConst.MANAGER_TYPE);
|
} else {
|
manager_type = null;
|
}
|
//拼装普通参照查询所需参数
|
FieldSetEntity fse = new FieldSetEntity();
|
fse.setTableName(CmnConst.PRODUCT_SYS_DICT);
|
fse.setValue(CmnConst.DICT_NAME, dictName);
|
fse.setValue(CoreConst.SYSTEM_CLIENT_TYPE_, currentUser.getClientType());
|
//获取参照集合
|
DataTableEntity dataTableEntity = bean.listDictByname(fse, manager_type);
|
if (!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
|
//组成条件
|
Object[] uuids = dataTableEntity.getUuids();
|
filter.append(fieldName);
|
filter.append(" in (SELECT dict_value FROM product_sys_dict where ");
|
filter.append(BaseUtil.buildQuestionMarkFilter("uuid", uuids, true));
|
filter.append(" and dict_label like concat('%','~val~','%') ) ");
|
}
|
return filter.toString();
|
}
|
|
/**
|
* 获取条件
|
*
|
* @param tableAlias 表别名
|
* @param aliasField 字段别名
|
* @return
|
*/
|
public Map<String, List<String>> getFilters(String tableAlias, Map<String, List<String>> aliasField) {
|
DataPoolCacheImpl poolCache = null;
|
//所有字段集合
|
List<FaceField> faceFields = this.getFaceFields();
|
//普通模糊查询字段集合
|
List<String> fieldNames = Lists.newArrayList();
|
//参照模糊查询条件集合
|
List<String> filters = Lists.newArrayList();
|
//返回的结果集
|
Map<String, List<String>> maps = Maps.newHashMap();
|
maps.put("fields", fieldNames);
|
maps.put("filter", filters);
|
for (int i = 0; i < faceFields.size(); i++) {
|
FaceField faceField = faceFields.get(i);
|
if (StringUtils.isEmpty(faceField.getFieldName()) || StringUtils.isEmpty(faceField.getFieldReference())) {
|
if (poolCache == null) {
|
poolCache = DataPoolCacheImpl.getInstance();
|
}
|
DataTableEntity dt = poolCache.getCacheData("表字段信息", new String[]{getTableUuid(), faceField.getFieldName()});
|
if (BaseUtil.dataTableIsEmpty(dt)) {
|
} else {
|
FieldSetEntity f = dt.getFieldSetEntity(0);
|
faceField.setFieldName(f.getString(CmnConst.FIELD_NAME));
|
faceField.setFieldReference(f.getString("field_reference"));
|
}
|
}
|
//字段名称
|
String fieldName = faceField.getFieldName();
|
if (!StringUtils.isEmpty(fieldName)) {
|
fieldName.trim();
|
}
|
if (aliasField != null && !StringUtils.isEmpty(fieldName)) {
|
List<String> fieldAlias = aliasField.get(getTableName() + "." + fieldName);
|
if (fieldAlias != null && fieldAlias.size() > 0) {
|
String alias = fieldAlias.get(0);
|
if (!StringUtils.isEmpty(alias)) {
|
fieldName = alias.trim();
|
}
|
}
|
}
|
//参照处理
|
String field_reference = faceField.getFieldReference();
|
if (!StringUtils.isEmpty(field_reference)) {
|
if (field_reference.indexOf("《") == 0 && field_reference.indexOf("》") > 0) {
|
//普通参照
|
filters.add(getDictFilter(getFieldName(tableAlias, fieldName), field_reference.replace("《", "").replace("》", "")));
|
continue;
|
} else {
|
if (poolCache == null) {
|
poolCache = DataPoolCacheImpl.getInstance();
|
}
|
//高级参照
|
DataTableEntity prompt = poolCache.getCacheData("高级参照配置信息", new String[]{field_reference});
|
if (BaseUtil.dataTableIsEmpty(prompt)) {
|
continue;
|
}
|
FieldSetEntity ff = prompt.getFieldSetEntity(0);
|
StringBuilder p = new StringBuilder();
|
p.append(getFieldName(tableAlias, fieldName)).append(" in ").append(" ( SELECT ").append(ff.getString("value_field")).append(" FROM ").append(ff.getString("source_table"));
|
p.append(" WHERE ").append(ff.getString("view_fields")).append(" like concat('%','~val~','%') )");
|
filters.add(p.toString());
|
continue;
|
}
|
}
|
|
if (!StringUtils.isEmpty(faceField.getFieldName())) {
|
fieldNames.add(getFieldName(tableAlias, fieldName));
|
}
|
}
|
//获取redis 起始key
|
String faceListKey = SystemFaceService.FACE_LIST_KEY;
|
//重新放入redis
|
RedisUtil.set(faceListKey + getUuid(), JSON.parseObject(JSON.toJSONString(this), com.product.admin.entity.FaceListEntity.class));
|
return maps;
|
}
|
|
private String getFieldName(String tableAlias, String fieldName) {
|
fieldName = "`" + fieldName + "`";
|
if (!StringUtils.isEmpty(tableAlias)) {
|
return "`" + tableAlias + "`." + fieldName;
|
}
|
return fieldName;
|
}
|
|
/**
|
* 字段实体类
|
*/
|
public class FaceField implements Serializable {
|
|
private static final long serialVersionUID = 3154509166818911568L;
|
/**
|
* 字段名称
|
*/
|
private String fieldName;
|
/**
|
* 字段uuid
|
*/
|
private String fieldUuid;
|
/**
|
* 列名
|
*/
|
private String columnName;
|
/**
|
* 列宽
|
*/
|
private String columnWidth;
|
/**
|
* 排序
|
*/
|
private Integer sequence;
|
/**
|
* 字段参照
|
*/
|
private String fieldReference;
|
|
public String getFieldReference() {
|
return fieldReference;
|
}
|
|
public void setFieldReference(String fieldReference) {
|
this.fieldReference = fieldReference;
|
}
|
|
public String getFieldName() {
|
return fieldName;
|
}
|
|
public void setFieldName(String fieldName) {
|
this.fieldName = fieldName;
|
}
|
|
public String getFieldUuid() {
|
return fieldUuid;
|
}
|
|
public void setFieldUuid(String fieldUuid) {
|
this.fieldUuid = fieldUuid;
|
}
|
|
public String getColumnName() {
|
return columnName;
|
}
|
|
public void setColumnName(String columnName) {
|
this.columnName = columnName;
|
}
|
|
public String getColumnWidth() {
|
return columnWidth;
|
}
|
|
public void setColumnWidth(String columnWidth) {
|
this.columnWidth = columnWidth;
|
}
|
|
public Integer getSequence() {
|
return sequence;
|
}
|
|
public void setSequence(Integer sequence) {
|
this.sequence = sequence;
|
}
|
|
}
|
|
|
}
|