From 5b3ac095b558e48385c27bf618225dee62927c4f Mon Sep 17 00:00:00 2001
From: zer0Black <694429613@qq.com>
Date: Sat, 19 Mar 2022 15:52:07 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=90=84=E7=B1=BBbug?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../common/util/jsonschema/BaseColumn.java | 28 +++
.../util/jsonschema/CommonProperty.java | 195 ++++++++++++++++++
.../util/jsonschema/JsonSchemaDescrip.java | 87 ++++++++
.../util/jsonschema/JsonschemaUtil.java | 70 +++++++
.../jsonschema/validate/DictProperty.java | 82 ++++++++
.../jsonschema/validate/HiddenProperty.java | 38 ++++
.../jsonschema/validate/LinkDownProperty.java | 66 ++++++
.../jsonschema/validate/NumberProperty.java | 153 ++++++++++++++
.../jsonschema/validate/PopupProperty.java | 76 +++++++
.../jsonschema/validate/StringProperty.java | 119 +++++++++++
.../jsonschema/validate/SwitchProperty.java | 46 +++++
.../validate/TreeSelectProperty.java | 146 +++++++++++++
.../controller/SysCategoryController.java | 11 +-
.../controller/SysDepartController.java | 27 +++
.../system/controller/SysDictController.java | 125 ++++++-----
.../system/controller/SysUserController.java | 43 +++-
.../modules/system/mapper/SysDictMapper.java | 25 ++-
.../system/mapper/SysUserDepartMapper.java | 22 ++
.../system/mapper/xml/SysDictMapper.xml | 16 ++
.../system/mapper/xml/SysUserDepartMapper.xml | 27 +++
.../system/service/ISysCategoryService.java | 19 +-
.../system/service/ISysDepartService.java | 17 ++
.../system/service/ISysDictService.java | 38 +++-
.../system/service/ISysUserDepartService.java | 17 +-
.../system/service/ISysUserService.java | 21 ++
.../system/service/impl/SysBaseApiImpl.java | 4 +-
.../service/impl/SysCategoryServiceImpl.java | 30 +++
.../service/impl/SysDepartServiceImpl.java | 59 +++++-
.../service/impl/SysDictServiceImpl.java | 138 +++++++++++--
.../impl/SysUserDepartServiceImpl.java | 84 +++++---
.../service/impl/SysUserServiceImpl.java | 85 ++++++++
.../modules/system/util/TenantContext.java | 25 ---
32 files changed, 1790 insertions(+), 149 deletions(-)
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/BaseColumn.java
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/CommonProperty.java
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/JsonSchemaDescrip.java
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/JsonschemaUtil.java
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/DictProperty.java
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/HiddenProperty.java
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/LinkDownProperty.java
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/NumberProperty.java
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/PopupProperty.java
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/StringProperty.java
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/SwitchProperty.java
create mode 100644 jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/TreeSelectProperty.java
delete mode 100644 jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/util/TenantContext.java
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/BaseColumn.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/BaseColumn.java
new file mode 100644
index 00000000..5a77ac23
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/BaseColumn.java
@@ -0,0 +1,28 @@
+package com.jero.common.util.jsonschema;
+
+import lombok.Data;
+
+/**
+ * 列 配置基本信息
+ */
+@Data
+public class BaseColumn {
+
+ /**
+ * 列配置 描述 -对应数据库字段描述
+ */
+ private String title;
+
+ /**
+ * 列配置 名称 -对应数据库字段名
+ */
+ private String field;
+
+ public BaseColumn(){}
+
+ public BaseColumn(String title,String field){
+ this.title = title;
+ this.field = field;
+ }
+
+}
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/CommonProperty.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/CommonProperty.java
new file mode 100644
index 00000000..891575df
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/CommonProperty.java
@@ -0,0 +1,195 @@
+package com.jero.common.util.jsonschema;
+
+import com.alibaba.fastjson.JSONObject;
+import com.jero.common.system.vo.DictModel;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 验证通用属性
+ */
+public abstract class CommonProperty implements Serializable{
+
+ private static final long serialVersionUID = -426159949502493187L;
+
+
+ protected String key;
+
+
+ /**
+ *
此关键字的值必须是字符串或数组。如果它是一个数组,那么数组的元素必须是字符串,并且必须是唯一的。
+ *
字符串值必须是六种基本类型之一(“null”,“boolean”,“object”,“array”,“number”或“string”),或“integer”,它匹配任何数字,零分数部分。
+ *
当且仅当实例位于为此关键字列出的任何集合中时,实例才会验证。
+ *
+ */
+ protected String type;
+
+ /**
+ * 对应JsonSchema的enum
+ *
该关键字的值必须是一个数组。这个数组应该至少有一个元素。数组中的元素应该是唯一的。如果实例的值等于此关键字的数组值中的某个元素,则实例将对此关键字成功验证。
+ * 数组中的元素可以是任何值,包括null
+ *
+ * {
+ * "type": "string",
+ * "enum": ["1", "2", "3"] 需要的话可以通过这个include转一下
+ * }
+ */
+ protected List include;
+
+ /**
+ * 对应JsonSchema的const
+ * 此关键字的值可以是任何类型,包括null。
+ * 如果实例的值等于关键字的值,则实例将针对此关键字成功验证。
+ */
+ protected Object constant;
+
+ //三个自定义 属性
+ protected String view;// 展示类型
+ protected String title;//数据库字段备注
+ protected Integer order;//字段显示排序
+
+ protected boolean disabled;//是否禁用
+
+ protected String defVal; // 字段默认值
+
+ protected String fieldExtendJson;//扩展参数
+
+ protected Integer dbPointLength;//小数点
+
+ public String getDefVal() {
+ return defVal;
+ }
+
+ public void setDefVal(String defVal) {
+ this.defVal = defVal;
+ }
+
+ public boolean isDisabled() {
+ return disabled;
+ }
+
+ public void setDisabled(boolean disabled) {
+ this.disabled = disabled;
+ }
+
+ public String getView() {
+ return view;
+ }
+
+ public void setView(String view) {
+ this.view = view;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public List getInclude() {
+ return include;
+ }
+
+ public void setInclude(List include) {
+ this.include = include;
+ }
+
+ public Object getConstant() {
+ return constant;
+ }
+
+ public void setConstant(Object constant) {
+ this.constant = constant;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public Integer getOrder() {
+ return order;
+ }
+
+ public void setOrder(Integer order) {
+ this.order = order;
+ }
+
+ public String getFieldExtendJson() {
+ return fieldExtendJson;
+ }
+
+ public void setFieldExtendJson(String fieldExtendJson) {
+ this.fieldExtendJson = fieldExtendJson;
+ }
+
+ public Integer getDbPointLength() {
+ return dbPointLength;
+ }
+
+ public void setDbPointLength(Integer dbPointLength) {
+ this.dbPointLength = dbPointLength;
+ }
+
+ /**
+ * 返回一个map有两个key
+ * key ---> Property JSON的key
+ *
prop --> JSON object
+ * @return
+ */
+ public abstract Map getPropertyJson();
+
+ public JSONObject getCommonJson() {
+ JSONObject json = new JSONObject();
+ json.put("type", type);
+ if(include!=null && include.size()>0) {
+ json.put("enum", include);
+ }
+ if(constant!=null) {
+ json.put("const", constant);
+ }
+ if(title!=null) {
+ json.put("title", title);
+ }
+ if(order!=null) {
+ json.put("order", order);
+ }
+ if(view==null) {
+ json.put("view", "input");
+ }else {
+ json.put("view", view);
+ }
+ if(disabled) {
+ String str = "{\"widgetattrs\":{\"disabled\":true}}";
+ JSONObject ui = JSONObject.parseObject(str);
+ json.put("ui", ui);
+ }
+ if (defVal!=null && defVal.length()>0) {
+ json.put("defVal", defVal);
+ }
+ if(fieldExtendJson != null){
+ json.put("fieldExtendJson", fieldExtendJson);
+ }
+ if(dbPointLength !=null ) {
+ json.put("dbPointLength", dbPointLength);
+ }
+ return json;
+ }
+
+
+}
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/JsonSchemaDescrip.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/JsonSchemaDescrip.java
new file mode 100644
index 00000000..e75797fb
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/JsonSchemaDescrip.java
@@ -0,0 +1,87 @@
+package com.jero.common.util.jsonschema;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * JsonSchema 模式类
+ * < http://json-schema.org/draft-07/schema# >
+ */
+public class JsonSchemaDescrip implements Serializable{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7682073117441544718L;
+
+
+ private String $schema = "http://json-schema.org/draft-07/schema#";
+
+ /**
+ * 用它给我们的模式提供了标题。
+ */
+ private String title;
+
+ /**
+ * 关于模式的描述。
+ */
+ private String description;
+
+ /**
+ *type 关键字在我们的 JSON 数据上定义了第一个约束:必须是一个 JSON 对象。 可以直接设置成object
+ */
+ private String type;
+
+ private List required;
+
+
+ public List getRequired() {
+ return required;
+ }
+
+ public void setRequired(List required) {
+ this.required = required;
+ }
+
+ public String get$schema() {
+ return $schema;
+ }
+
+ public void set$schema(String $schema) {
+ this.$schema = $schema;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public JsonSchemaDescrip() {}
+
+ public JsonSchemaDescrip(List required) {
+ this.description="我是一个jsonschema description";
+ this.title="我是一个jsonschema title";
+ this.type="object";
+ this.required = required;
+ }
+
+}
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/JsonschemaUtil.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/JsonschemaUtil.java
new file mode 100644
index 00000000..91fab531
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/JsonschemaUtil.java
@@ -0,0 +1,70 @@
+package com.jero.common.util.jsonschema;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class JsonschemaUtil {
+
+ /**
+ * 生成JsonSchema
+ *
+ * @param descrip
+ * @param propertyList
+ * @return
+ */
+ public static JSONObject getJsonSchema(JsonSchemaDescrip descrip, List propertyList) {
+ JSONObject obj = new JSONObject();
+ obj.put("$schema", descrip.get$schema());
+ obj.put("type", descrip.getType());
+ obj.put("title", descrip.getTitle());
+
+ List requiredArr = descrip.getRequired();
+ obj.put("required", requiredArr);
+
+ JSONObject properties = new JSONObject();
+ for (CommonProperty commonProperty : propertyList) {
+ Map map = commonProperty.getPropertyJson();
+ properties.put(map.get("key").toString(), map.get("prop"));
+ }
+ obj.put("properties", properties);
+ //鬼知道这里为什么报错 com.jero.modules.system.model.DictModel cannot be cast to com.jero.modules.system.model.DictModel
+ //log.info("---JSONSchema--->"+obj.toJSONString());
+ return obj;
+ }
+
+ /**
+ * 生成JsonSchema 用于子对象
+ * @param title 子对象描述
+ * @param requiredArr 子对象必填属性名集合
+ * @param propertyList 子对象属性集合
+ * @return
+ */
+ public static JSONObject getSubJsonSchema(String title,List requiredArr,List propertyList) {
+ JSONObject obj = new JSONObject();
+ obj.put("type", "object");
+ obj.put("view", "tab");
+ obj.put("title", title);
+
+ if(requiredArr==null) {
+ requiredArr = new ArrayList();
+ }
+ obj.put("required", requiredArr);
+
+ JSONObject properties = new JSONObject();
+ for (CommonProperty commonProperty : propertyList) {
+ Map map = commonProperty.getPropertyJson();
+ properties.put(map.get("key").toString(), map.get("prop"));
+ }
+ obj.put("properties", properties);
+ //log.info("---JSONSchema--->"+obj.toString());
+ return obj;
+ }
+
+}
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/DictProperty.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/DictProperty.java
new file mode 100644
index 00000000..7a235d9a
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/DictProperty.java
@@ -0,0 +1,82 @@
+package com.jero.common.util.jsonschema.validate;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.jero.common.util.jsonschema.CommonProperty;
+
+import com.alibaba.fastjson.JSONObject;
+
+/**
+ * 字典属性
+ * @author 86729
+ *
+ */
+public class DictProperty extends CommonProperty {
+
+ private static final long serialVersionUID = 3786503639885610767L;
+
+ //字典三属性
+ private String dictCode;
+ private String dictTable;
+ private String dictText;
+
+ public String getDictCode() {
+ return dictCode;
+ }
+
+ public void setDictCode(String dictCode) {
+ this.dictCode = dictCode;
+ }
+
+ public String getDictTable() {
+ return dictTable;
+ }
+
+ public void setDictTable(String dictTable) {
+ this.dictTable = dictTable;
+ }
+
+ public String getDictText() {
+ return dictText;
+ }
+
+ public void setDictText(String dictText) {
+ this.dictText = dictText;
+ }
+
+ public DictProperty() {}
+
+ /**
+ * 构造器
+ */
+ public DictProperty(String key,String title,String dictTable,String dictCode,String dictText) {
+ this.type = "string";
+ this.view = "sel_search";
+ this.key = key;
+ this.title = title;
+ this.dictCode = dictCode;
+ this.dictTable= dictTable;
+ this.dictText= dictText;
+ }
+
+ @Override
+ public Map getPropertyJson() {
+ Map map = new HashMap<>();
+ map.put("key",getKey());
+ JSONObject prop = getCommonJson();
+ if(dictCode!=null) {
+ prop.put("dictCode",dictCode);
+ }
+ if(dictTable!=null) {
+ prop.put("dictTable",dictTable);
+ }
+ if(dictText!=null) {
+ prop.put("dictText",dictText);
+ }
+ map.put("prop",prop);
+ return map;
+ }
+
+ //TODO 重构问题:数据字典 只是字符串类的还是有存储的数值类型?只有字符串请跳过这个 只改前端
+}
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/HiddenProperty.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/HiddenProperty.java
new file mode 100644
index 00000000..2cb95058
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/HiddenProperty.java
@@ -0,0 +1,38 @@
+package com.jero.common.util.jsonschema.validate;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.jero.common.util.jsonschema.CommonProperty;
+
+import com.alibaba.fastjson.JSONObject;
+
+/**
+ * 字典属性
+ * @author 86729
+ *
+ */
+public class HiddenProperty extends CommonProperty {
+
+ private static final long serialVersionUID = -8939298551502162479L;
+
+ public HiddenProperty() {}
+
+ public HiddenProperty(String key,String title) {
+ this.type = "string";
+ this.view = "hidden";
+ this.key = key;
+ this.title = title;
+ }
+
+ @Override
+ public Map getPropertyJson() {
+ Map map = new HashMap<>();
+ map.put("key",getKey());
+ JSONObject prop = getCommonJson();
+ prop.put("hidden",true);
+ map.put("prop",prop);
+ return map;
+ }
+
+}
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/LinkDownProperty.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/LinkDownProperty.java
new file mode 100644
index 00000000..3815d477
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/LinkDownProperty.java
@@ -0,0 +1,66 @@
+package com.jero.common.util.jsonschema.validate;
+
+import com.alibaba.fastjson.JSONObject;
+import com.jero.common.util.jsonschema.BaseColumn;
+import com.jero.common.util.jsonschema.CommonProperty;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 级联下拉
+ */
+public class LinkDownProperty extends CommonProperty {
+
+ /**
+ * 配置信息
+ */
+ String dictTable;
+
+ /**
+ * 级联下拉组件 的其他级联列
+ */
+ List otherColumns;
+
+ public String getDictTable(){
+ return this.dictTable;
+ }
+
+ public void setDictTable(String dictTable){
+ this.dictTable = dictTable;
+ }
+
+ public List getOtherColumns(){
+ return this.otherColumns;
+ }
+
+ public void setOtherColumns(List otherColumns){
+ this.otherColumns = otherColumns;
+ }
+
+ public LinkDownProperty() {}
+
+ /**
+ * 构造器
+ */
+ public LinkDownProperty(String key,String title,String dictTable) {
+ this.type = "string";
+ this.view = "link_down";
+ this.key = key;
+ this.title = title;
+ this.dictTable= dictTable;
+ }
+
+ @Override
+ public Map getPropertyJson() {
+ Map map = new HashMap<>();
+ map.put("key", getKey());
+ JSONObject prop = getCommonJson();
+ JSONObject temp = JSONObject.parseObject(this.dictTable);
+ prop.put("config", temp);
+ prop.put("others", otherColumns);
+ map.put("prop", prop);
+ return map;
+ }
+}
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/NumberProperty.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/NumberProperty.java
new file mode 100644
index 00000000..174f595d
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/NumberProperty.java
@@ -0,0 +1,153 @@
+package com.jero.common.util.jsonschema.validate;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.jero.common.system.vo.DictModel;
+import com.jero.common.util.jsonschema.CommonProperty;
+
+import com.alibaba.fastjson.JSONObject;
+
+public class NumberProperty extends CommonProperty {
+
+ private static final long serialVersionUID = -558615331436437200L;
+
+ /**
+ * 倍数
+ * 验证实例是否为此数值的倍数
+ * “multipleOf”的值必须是一个数字,严格大于0。
+ */
+ private Integer multipleOf;
+
+ /**
+ * 小于等于
+ * “maximum”的值必须是一个数字,表示数字实例的包含上限。
+ * 如果实例是数字,则仅当实例小于或等于“最大”时,此关键字才会生效。
+ */
+ private Integer maxinum;
+
+ /**
+ * 小于
+ * “exclusiveMaximum”的值必须是数字,表示数字实例的独占上限。
+ * 如果实例是数字,则实例仅在其值严格小于(不等于)“exclusiveMaximum”时才有效。
+ */
+ private Integer exclusiveMaximum;
+
+ /**
+ * 大于等于
+ */
+ private Integer minimum;
+
+ /**
+ * 大于等于
+ */
+ private Integer exclusiveMinimum;
+
+ private String pattern;
+
+ public Integer getMultipleOf() {
+ return multipleOf;
+ }
+
+ public void setMultipleOf(Integer multipleOf) {
+ this.multipleOf = multipleOf;
+ }
+
+ public Integer getMaxinum() {
+ return maxinum;
+ }
+
+ public void setMaxinum(Integer maxinum) {
+ this.maxinum = maxinum;
+ }
+
+ public Integer getExclusiveMaximum() {
+ return exclusiveMaximum;
+ }
+
+ public void setExclusiveMaximum(Integer exclusiveMaximum) {
+ this.exclusiveMaximum = exclusiveMaximum;
+ }
+
+ public Integer getMinimum() {
+ return minimum;
+ }
+
+ public void setMinimum(Integer minimum) {
+ this.minimum = minimum;
+ }
+
+ public Integer getExclusiveMinimum() {
+ return exclusiveMinimum;
+ }
+
+ public void setExclusiveMinimum(Integer exclusiveMinimum) {
+ this.exclusiveMinimum = exclusiveMinimum;
+ }
+
+ public String getPattern() {
+ return pattern;
+ }
+
+ public void setPattern(String pattern) {
+ this.pattern = pattern;
+ }
+
+ public NumberProperty() {}
+
+ /**
+ * 构造器
+ * @param key 字段名
+ * @param title 字段备注
+ * @param type number和integer
+ */
+ public NumberProperty(String key,String title,String type) {
+ this.key = key;
+ this.type = type;
+ this.title = title;
+ this.view = "number";
+ }
+
+ /**
+ * 列表类型的走这个构造器 字典里存储的都是字符串 没法走这个构造器
+ * @param key
+ * @param type
+ * @param view list-checkbox-radio
+ * @param include
+ */
+ public NumberProperty(String key,String title,String view,List include) {
+ this.type = "integer";
+ this.key = key;
+ this.view = view;
+ this.title = title;
+ this.include = include;
+ }
+
+ @Override
+ public Map getPropertyJson() {
+ Map map = new HashMap<>();
+ map.put("key",getKey());
+ JSONObject prop = getCommonJson();
+ if(multipleOf!=null) {
+ prop.put("multipleOf",multipleOf);
+ }
+ if(maxinum!=null) {
+ prop.put("maxinum",maxinum);
+ }
+ if(exclusiveMaximum!=null) {
+ prop.put("exclusiveMaximum",exclusiveMaximum);
+ }
+ if(minimum!=null) {
+ prop.put("minimum",minimum);
+ }
+ if(exclusiveMinimum!=null) {
+ prop.put("exclusiveMinimum",exclusiveMinimum);
+ }
+ if(pattern!=null) {
+ prop.put("pattern",pattern);
+ }
+ map.put("prop",prop);
+ return map;
+ }
+}
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/PopupProperty.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/PopupProperty.java
new file mode 100644
index 00000000..b025d49b
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/PopupProperty.java
@@ -0,0 +1,76 @@
+package com.jero.common.util.jsonschema.validate;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.jero.common.util.jsonschema.CommonProperty;
+
+import com.alibaba.fastjson.JSONObject;
+
+public class PopupProperty extends CommonProperty {
+
+ private static final long serialVersionUID = -3200493311633999539L;
+
+ private String code;
+
+ private String destFields;
+
+ private String orgFields;
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getDestFields() {
+ return destFields;
+ }
+
+ public void setDestFields(String destFields) {
+ this.destFields = destFields;
+ }
+
+ public String getOrgFields() {
+ return orgFields;
+ }
+
+ public void setOrgFields(String orgFields) {
+ this.orgFields = orgFields;
+ }
+
+ public PopupProperty() {}
+
+ public PopupProperty(String key,String title,String code,String destFields,String orgFields) {
+ this.view = "popup";
+ this.type = "string";
+ this.key = key;
+ this.title = title;
+ this.code = code;
+ this.destFields=destFields;
+ this.orgFields=orgFields;
+ }
+
+
+ @Override
+ public Map getPropertyJson() {
+ Map map = new HashMap<>();
+ map.put("key",getKey());
+ JSONObject prop = getCommonJson();
+ if(code!=null) {
+ prop.put("code",code);
+ }
+ if(destFields!=null) {
+ prop.put("destFields",destFields);
+ }
+ if(orgFields!=null) {
+ prop.put("orgFields",orgFields);
+ }
+ map.put("prop",prop);
+ return map;
+ }
+
+}
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/StringProperty.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/StringProperty.java
new file mode 100644
index 00000000..124740f7
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/StringProperty.java
@@ -0,0 +1,119 @@
+package com.jero.common.util.jsonschema.validate;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.jero.common.system.vo.DictModel;
+import com.jero.common.util.jsonschema.CommonProperty;
+
+import com.alibaba.fastjson.JSONObject;
+
+public class StringProperty extends CommonProperty {
+
+ private static final long serialVersionUID = -3200493311633999539L;
+
+ private Integer maxLength;
+
+ private Integer minLength;
+
+ /**
+ * 根据ECMA 262正则表达式方言,该字符串应该是有效的正则表达式。
+ */
+ private String pattern;
+
+ /**
+ * 错误提示信息
+ */
+ private String errorInfo;
+
+ public Integer getMaxLength() {
+ return maxLength;
+ }
+
+
+ public void setMaxLength(Integer maxLength) {
+ this.maxLength = maxLength;
+ }
+
+ public Integer getMinLength() {
+ return minLength;
+ }
+
+ public void setMinLength(Integer minLength) {
+ this.minLength = minLength;
+ }
+
+ public String getPattern() {
+ return pattern;
+ }
+
+ public void setPattern(String pattern) {
+ this.pattern = pattern;
+ }
+
+ public String getErrorInfo() {
+ return errorInfo;
+ }
+
+
+ public void setErrorInfo(String errorInfo) {
+ this.errorInfo = errorInfo;
+ }
+
+
+ public StringProperty() {}
+
+ /**
+ * 一般字符串类型走这个构造器
+ * @param key 字段名
+ * @param title 字段备注
+ * @param view 展示控件
+ * @param maxLength 数据库字段最大长度
+ */
+ public StringProperty(String key,String title,String view,Integer maxLength) {
+ this.maxLength = maxLength;
+ this.key = key;
+ this.view = view;
+ this.title = title;
+ this.type = "string";
+ }
+
+ /**
+ * 列表类型的走这个构造器
+ * @param key 字段名
+ * @param title 字段备注
+ * @param view 展示控件 list-checkbox-radio
+ * @param maxLength 数据库字段最大长度
+ * @param include 数据字典
+ */
+ public StringProperty(String key,String title,String view,Integer maxLength,List include) {
+ this.maxLength = maxLength;
+ this.key = key;
+ this.view = view;
+ this.title = title;
+ this.type = "string";
+ this.include = include;
+ }
+ @Override
+ public Map getPropertyJson() {
+ Map map = new HashMap<>();
+ map.put("key",getKey());
+ JSONObject prop = getCommonJson();
+ if(maxLength!=null) {
+ prop.put("maxLength",maxLength);
+ }
+ if(minLength!=null) {
+ prop.put("minLength",minLength);
+ }
+ if(pattern!=null) {
+ prop.put("pattern",pattern);
+ }
+ if(errorInfo!=null) {
+ prop.put("errorInfo",errorInfo);
+ }
+ map.put("prop",prop);
+ return map;
+ }
+
+}
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/SwitchProperty.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/SwitchProperty.java
new file mode 100644
index 00000000..46ff15b2
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/SwitchProperty.java
@@ -0,0 +1,46 @@
+package com.jero.common.util.jsonschema.validate;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jero.common.util.jsonschema.CommonProperty;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 开关 属性
+ */
+public class SwitchProperty extends CommonProperty {
+
+ //扩展参数配置信息
+ private String extendStr;
+
+ public SwitchProperty() {}
+
+ /**
+ * 构造器
+ */
+ public SwitchProperty(String key, String title, String extendStr) {
+ this.type = "string";
+ this.view = "switch";
+ this.key = key;
+ this.title = title;
+ this.extendStr = extendStr;
+ }
+
+ @Override
+ public Map getPropertyJson() {
+ Map map = new HashMap<>();
+ map.put("key",getKey());
+ JSONObject prop = getCommonJson();
+ JSONArray array = new JSONArray();
+ if(extendStr!=null) {
+ array = JSONArray.parseArray(extendStr);
+ prop.put("extendOption",array);
+ }
+ map.put("prop",prop);
+ return map;
+ }
+
+ //TODO 重构问题:数据字典 只是字符串类的还是有存储的数值类型?只有字符串请跳过这个 只改前端
+}
diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/TreeSelectProperty.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/TreeSelectProperty.java
new file mode 100644
index 00000000..96160879
--- /dev/null
+++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/jsonschema/validate/TreeSelectProperty.java
@@ -0,0 +1,146 @@
+package com.jero.common.util.jsonschema.validate;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.jero.common.util.jsonschema.CommonProperty;
+
+import com.alibaba.fastjson.JSONObject;
+
+/**
+ * 字典属性
+ * @author 86729
+ *
+ */
+public class TreeSelectProperty extends CommonProperty {
+
+ private static final long serialVersionUID = 3786503639885610767L;
+
+ private String dict;//表名,文本,id
+ private String pidField;//父级字段 默认pid
+ private String pidValue;//父级节点的值 暂时没用到 默认为0
+ private String hasChildField;
+ private String textField;//树形下拉保存text值的字段名
+
+ /**
+ * 是不是pid 组件 1是 0否
+ */
+ private Integer pidComponent = 0;
+
+ public String getDict() {
+ return dict;
+ }
+
+ public void setDict(String dict) {
+ this.dict = dict;
+ }
+
+ public String getPidField() {
+ return pidField;
+ }
+
+ public void setPidField(String pidField) {
+ this.pidField = pidField;
+ }
+
+ public String getPidValue() {
+ return pidValue;
+ }
+
+ public void setPidValue(String pidValue) {
+ this.pidValue = pidValue;
+ }
+
+ public String getHasChildField() {
+ return hasChildField;
+ }
+
+ public void setHasChildField(String hasChildField) {
+ this.hasChildField = hasChildField;
+ }
+
+ public TreeSelectProperty() {}
+
+ public String getTextField() {
+ return textField;
+ }
+
+ public void setTextField(String textField) {
+ this.textField = textField;
+ }
+
+ public Integer getPidComponent() {
+ return pidComponent;
+ }
+
+ public void setPidComponent(Integer pidComponent) {
+ this.pidComponent = pidComponent;
+ }
+
+ /**
+ * 构造器 构造普通树形下拉
+ */
+ public TreeSelectProperty(String key,String title,String dict,String pidField,String pidValue) {
+ this.type = "string";
+ this.view = "sel_tree";
+ this.key = key;
+ this.title = title;
+ this.dict = dict;
+ this.pidField= pidField;
+ this.pidValue= pidValue;
+ }
+
+ /**
+ * 分类字典下拉专用
+ * @param key
+ * @param title
+ * @param pidValue
+ */
+ public TreeSelectProperty(String key,String title,String pidValue) {
+ this.type = "string";
+ this.view = "cat_tree";
+ this.key = key;
+ this.title = title;
+ this.pidValue = pidValue;
+ }
+
+ /**
+ * 分类字典 支持存储text 下拉专用
+ * @param key
+ * @param title
+ * @param pidValue
+ * @param textField
+ */
+ public TreeSelectProperty(String key,String title,String pidValue,String textField) {
+ this(key,title,pidValue);
+ this.textField = textField;
+ }
+
+ @Override
+ public Map getPropertyJson() {
+ Map map = new HashMap<>();
+ map.put("key",getKey());
+ JSONObject prop = getCommonJson();
+ if(dict!=null) {
+ prop.put("dict",dict);
+ }
+ if(pidField!=null) {
+ prop.put("pidField",pidField);
+ }
+ if(pidValue!=null) {
+ prop.put("pidValue",pidValue);
+ }
+ if(textField!=null) {
+ prop.put("textField",textField);
+ }
+ if(hasChildField!=null) {
+ prop.put("hasChildField",hasChildField);
+ }
+ if(pidComponent!=null) {
+ prop.put("pidComponent",pidComponent);
+ }
+ map.put("prop",prop);
+ return map;
+ }
+
+}
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysCategoryController.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysCategoryController.java
index 3385a854..58486b02 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysCategoryController.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysCategoryController.java
@@ -425,11 +425,11 @@ public class SysCategoryController {
* 分类字典控件数据回显[表单页面]
*
* @param ids
+ * @param delNotExist 是否移除不存在的项,默认为true,设为false如果某个key不存在数据库中,则直接返回key本身
* @return
*/
- @RequiresPermissions("sys:category:list")
@RequestMapping(value = "/loadDictItem", method = RequestMethod.GET)
- public Result> loadDictItem(@RequestParam(name = "ids") String ids) {
+ public Result> loadDictItem(@RequestParam(name = "ids") String ids, @RequestParam(name = "delNotExist", required = false, defaultValue = "true") boolean delNotExist) {
Result> result = new Result<>();
// 非空判断
if (StringUtils.isBlank(ids)) {
@@ -437,13 +437,8 @@ public class SysCategoryController {
result.setMessage("ids 不能为空");
return result;
}
- String[] idArray = ids.split(",");
- LambdaQueryWrapper query = new LambdaQueryWrapper<>();
- query.in(SysCategory::getId, Arrays.asList(idArray));
// 查询数据
- List list = this.sysCategoryService.list(query);
- // 取出name并返回
- List textList = list.stream().map(SysCategory::getName).collect(Collectors.toList());
+ List textList = sysCategoryService.loadDictItem(ids, delNotExist);
result.setSuccess(true);
result.setResult(textList);
return result;
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysDepartController.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysDepartController.java
index 423559c6..e527a213 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysDepartController.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysDepartController.java
@@ -6,6 +6,7 @@ import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jero.common.system.vo.SysDepartTreeModel;
import org.apache.shiro.SecurityUtils;
@@ -130,6 +131,32 @@ public class SysDepartController {
return result;
}
+ /**
+ * 获取某个部门的所有父级部门的ID
+ *
+ * @param departId 根据departId查
+ * @param orgCode 根据orgCode查,departId和orgCode必须有一个不为空
+ */
+ @GetMapping("/queryAllParentId")
+ public Result queryParentIds(
+ @RequestParam(name = "departId", required = false) String departId,
+ @RequestParam(name = "orgCode", required = false) String orgCode
+ ) {
+ try {
+ JSONObject data;
+ if (oConvertUtils.isNotEmpty(departId)) {
+ data = sysDepartService.queryAllParentIdByDepartId(departId);
+ } else if (oConvertUtils.isNotEmpty(orgCode)) {
+ data = sysDepartService.queryAllParentIdByOrgCode(orgCode);
+ } else {
+ return Result.error("departId 和 orgCode 不能都为空!");
+ }
+ return Result.OK(data);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ return Result.error(e.getMessage());
+ }
+ }
/**
* 添加新数据 添加用户新建的部门对象数据,并保存到数据库
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysDictController.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysDictController.java
index 2930b1d5..6f831abd 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysDictController.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysDictController.java
@@ -124,47 +124,23 @@ public class SysDictController {
*/
@ApiOperation(value = "字典控制器-根据字典编码获取字典数据", notes = "字典控制器-根据字典编码获取字典数据")
@RequestMapping(value = "/getDictItems/{dictCode}", method = RequestMethod.GET)
- public Result> getDictItems(@PathVariable String dictCode, @RequestParam(value = "sign",required = false) String sign, HttpServletRequest request) {
+ public Result> getDictItems(@PathVariable String dictCode, @RequestParam(value = "sign",required = false) String sign,HttpServletRequest request) {
log.info(" dictCode : "+ dictCode);
Result> result = new Result>();
- List ls = null;
try {
- if(dictCode.indexOf(",")!=-1) {
- //关联表字典(举例:sys_user,realname,id)
- String[] params = dictCode.split(",");
-
- if(params.length<3) {
- result.error500("字典Code格式不正确!");
- return result;
- }
- //SQL注入校验(只限制非法串改数据库)
- final String[] sqlInjCheck = {params[0],params[1],params[2]};
- SqlInjectionUtil.filterContent(sqlInjCheck);
-
- if(params.length==4) {
- //SQL注入校验(查询条件SQL 特殊check,此方法仅供此处使用)
- SqlInjectionUtil.specialFilterContent(params[3]);
- ls = sysDictService.queryTableDictItemsByCodeAndFilter(params[0],params[1],params[2],params[3]);
- }else if (params.length==3) {
- ls = sysDictService.queryTableDictItemsByCode(params[0],params[1],params[2]);
- }else{
- result.error500("字典Code格式不正确!");
- return result;
- }
- }else {
- //字典表
- ls = sysDictService.queryDictItemsByCode(dictCode);
+ List ls = sysDictService.getDictItems(dictCode);
+ if (ls == null) {
+ result.error500("字典Code格式不正确!");
+ return result;
}
-
- result.setSuccess(true);
- result.setResult(ls);
- log.debug(result.toString());
+ result.setSuccess(true);
+ result.setResult(ls);
+ log.debug(result.toString());
} catch (Exception e) {
- log.error(e.getMessage(),e);
+ log.error(e.getMessage(), e);
result.error500("操作失败");
return result;
}
-
return result;
}
@@ -205,52 +181,87 @@ public class SysDictController {
}
/**
+ * 【JSearchSelectTag下拉搜索组件专用接口】
* 大数据量的字典表 走异步加载 即前端输入内容过滤数据
- * @param dictCode
+ * @param dictCode 字典code格式:table,text,code
* @return
*/
- @ApiOperation(value = "字典控制器-通过字典code获取字典数据", notes = "字典控制器-通过字典code获取字典数据")
@RequestMapping(value = "/loadDict/{dictCode}", method = RequestMethod.GET)
public Result> loadDict(@PathVariable String dictCode,
- @RequestParam(name="keyword") String keyword,
- @RequestParam(value = "sign",required = false) String sign,
- @RequestParam(value = "pageSize", required = false) Integer pageSize) {
+ @RequestParam(name="keyword") String keyword,
+ @RequestParam(value = "sign",required = false) String sign,
+ @RequestParam(value = "pageSize", required = false) Integer pageSize) {
log.info(" 加载字典表数据,加载关键字: "+ keyword);
Result> result = new Result>();
- List ls = null;
try {
- if(dictCode.indexOf(",")!=-1) {
- String[] params = dictCode.split(",");
- if(params.length!=3) {
- result.error500("字典Code格式不正确!");
- return result;
- }
- if(pageSize!=null){
- ls = sysDictService.queryLittleTableDictItems(params[0],params[1],params[2],keyword, pageSize);
- }else{
- ls = sysDictService.queryTableDictItems(params[0],params[1],params[2],keyword);
- }
- result.setSuccess(true);
- result.setResult(ls);
- log.info(result.toString());
- }else {
+ List ls = sysDictService.loadDict(dictCode, keyword, pageSize);
+ if (ls == null) {
result.error500("字典Code格式不正确!");
+ return result;
}
+ result.setSuccess(true);
+ result.setResult(ls);
+ log.info(result.toString());
+ return result;
} catch (Exception e) {
log.error(e.getMessage(),e);
result.error500("操作失败");
return result;
}
+ }
+ /**
+ * 【给表单设计器的表字典使用】下拉搜索模式,有值时动态拼接数据
+ * @param dictCode
+ * @param keyword 当前控件的值,可以逗号分割
+ * @param sign
+ * @param pageSize
+ * @return
+ */
+ @RequestMapping(value = "/loadDictOrderByValue/{dictCode}", method = RequestMethod.GET)
+ public Result> loadDictOrderByValue(
+ @PathVariable String dictCode,
+ @RequestParam(name = "keyword") String keyword,
+ @RequestParam(value = "sign", required = false) String sign,
+ @RequestParam(value = "pageSize", required = false) Integer pageSize) {
+ // 首次查询查出来用户选中的值,并且不分页
+ Result> firstRes = this.loadDict(dictCode, keyword, sign, null);
+ if (!firstRes.isSuccess()) {
+ return firstRes;
+ }
+ // 然后再查询出第一页的数据
+ Result> result = this.loadDict(dictCode, "", sign, pageSize);
+ if (!result.isSuccess()) {
+ return result;
+ }
+ // 合并两次查询的数据
+ List firstList = firstRes.getResult();
+ List list = result.getResult();
+ for (DictModel firstItem : firstList) {
+ // anyMatch 表示:判断的条件里,任意一个元素匹配成功,返回true
+ // allMatch 表示:判断条件里的元素,所有的都匹配成功,返回true
+ // noneMatch 跟 allMatch 相反,表示:判断条件里的元素,所有的都匹配失败,返回true
+ boolean none = list.stream().noneMatch(item -> item.getValue().equals(firstItem.getValue()));
+ // 当元素不存在时,再添加到集合里
+ if (none) {
+ list.add(0, firstItem);
+ }
+ }
return result;
}
/**
+ *
* 根据字典code加载字典text 返回
+ * @param dictCode 顺序:tableName,text,code
+ * @param keys 要查询的key
+ * @param sign
+ * @param delNotExist 是否移除不存在的项,默认为true,设为false如果某个key不存在数据库中,则直接返回key本身
+ * @param request
+ * @return
*/
- @ApiOperation(value = "字典控制器-根据字典code加载字典text", notes = "字典控制器-根据字典code加载字典text")
@RequestMapping(value = "/loadDictItem/{dictCode}", method = RequestMethod.GET)
- public Result> loadDictItem(@PathVariable String dictCode, @RequestParam(name="key") String keys, @RequestParam(value = "sign",required = false) String sign, HttpServletRequest request) {
+ public Result> loadDictItem(@PathVariable String dictCode,@RequestParam(name="key") String keys, @RequestParam(value = "sign",required = false) String sign,@RequestParam(value = "delNotExist",required = false,defaultValue = "true") boolean delNotExist,HttpServletRequest request) {
Result> result = new Result<>();
try {
if(dictCode.indexOf(",")!=-1) {
@@ -259,7 +270,7 @@ public class SysDictController {
result.error500("字典Code格式不正确!");
return result;
}
- List texts = sysDictService.queryTableDictByKeys(params[0], params[1], params[2], keys);
+ List texts = sysDictService.queryTableDictByKeys(params[0], params[1], params[2], keys, delNotExist);
result.setSuccess(true);
result.setResult(texts);
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysUserController.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysUserController.java
index 024be30c..8d14cd63 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysUserController.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysUserController.java
@@ -170,8 +170,8 @@ public class SysUserController {
throw new JeroBootException("邮箱和手机号解密失败!", e);
}
- sysUserService.addUserWithRole(user, selectedRoles);
- sysUserService.addUserWithDepart(user, selectedDeparts);
+ // 保存用户走一个service 保证事务
+ sysUserService.saveUser(user, selectedRoles, selectedDeparts);
result.success("添加成功!");
} catch (Exception e) {
log.error(e.getMessage(), e);
@@ -217,9 +217,8 @@ public class SysUserController {
user.setUpdateTime(new Date());
//String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
user.setPassword(sysUser.getPassword());
- sysUserService.editUserWithRole(user, roles);
- sysUserService.editUserWithDepart(user, departs);
- sysUserService.updateNullPhoneEmail();
+ // 修改用户走一个service 保证事务
+ sysUserService.editUser(user, roles, departs);
result.success("修改成功!");
}
} catch (Exception e) {
@@ -313,6 +312,7 @@ public class SysUserController {
result.setResult(true);
try {
//通过传入信息查询新的用户信息
+ sysUser.setPassword(null);
SysUser user = sysUserService.getOne(new QueryWrapper(sysUser));
if (user != null) {
result.setSuccess(false);
@@ -329,8 +329,9 @@ public class SysUserController {
return result;
}
-
- @RequiresPermissions("user:edit")
+ /**
+ * 修改密码
+ */
@RequestMapping(value = "/changePassword", method = RequestMethod.PUT)
public Result> changePassword(@RequestBody SysUser sysUser) {
SysUser u = this.sysUserService.getOne(new LambdaQueryWrapper().eq(SysUser::getUsername, sysUser.getUsername()));
@@ -424,6 +425,23 @@ public class SysUserController {
}
}
+ /**
+ * 用户选择组件 专用 根据用户账号或部门分页查询
+ * @param departId
+ * @param username
+ * @return
+ */
+ @RequestMapping(value = "/queryUserComponentData", method = RequestMethod.GET)
+ public Result> queryUserComponentData(
+ @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
+ @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
+ @RequestParam(name = "departId", required = false) String departId,
+ @RequestParam(name="realname",required=false) String realname,
+ @RequestParam(name="username",required=false) String username) {
+ IPage pageList = sysUserDepartService.queryDepartUserPageList(departId, username, realname, pageSize, pageNo);
+ return Result.OK(pageList);
+ }
+
/**
* 导出excel
*
@@ -559,13 +577,20 @@ public class SysUserController {
* 首页用户重置密码
*/
@RequestMapping(value = "/updatePassword", method = RequestMethod.PUT)
- public Result> changPassword(@RequestBody JSONObject json) {
+ public Result> updatePassword(@RequestBody JSONObject json) {
String username = json.getString("username");
String oldpassword = json.getString("oldpassword");
String password = json.getString("password");
String confirmpassword = json.getString("confirmpassword");
String RSAPublicKey = json.getString("rsaPublicKey");
+
+ LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
+ if(!sysUser.getUsername().equals(username)){
+ return Result.error("只允许修改自己的密码!");
+ }
+
String RSAPrivateKey = String.valueOf(redisUtil.get(RSAPublicKey));
+
try {
oldpassword = CommonUtils.decryptBtRsaPriKey(oldpassword, RSAPrivateKey);
password = CommonUtils.decryptBtRsaPriKey(password, RSAPrivateKey);
@@ -573,6 +598,7 @@ public class SysUserController {
}catch (Exception e){
log.error(e.getMessage(),e);
}
+
SysUser user = this.sysUserService.getOne(new LambdaQueryWrapper().eq(SysUser::getUsername, username));
if(user==null) {
return Result.error("用户不存在!");
@@ -1342,4 +1368,5 @@ public class SysUserController {
sysUserService.updateById(user);
return Result.OK("手机号设置成功!");
}
+
}
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/SysDictMapper.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/SysDictMapper.java
index 5ad60700..74790f66 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/SysDictMapper.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/SysDictMapper.java
@@ -99,7 +99,8 @@ public interface SysDictMapper extends BaseMapper {
* @param hasChildField
* @return
*/
- List queryTreeList(@Param("query") String query,@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("pidField") String pidField,@Param("pid") String pid,@Param("hasChildField") String hasChildField);
+ @Deprecated
+ List queryTreeList(@Param("query") Map query,@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("pidField") String pidField,@Param("pid") String pid,@Param("hasChildField") String hasChildField);
/**
* 根据表名、显示字段名、存储字段名拼接树结构
@@ -151,4 +152,26 @@ public interface SysDictMapper extends BaseMapper {
*/
@Deprecated
public Page queryDictTablePageList(Page page, @Param("query") DictQuery query);
+
+
+ /**
+ * 查询 字典表数据 支持查询条件 分页
+ * @param page
+ * @param table
+ * @param text
+ * @param code
+ * @param filterSql
+ * @return
+ */
+ IPage queryTableDictWithFilter(Page page, @Param("table") String table, @Param("text") String text, @Param("code") String code, @Param("filterSql") String filterSql);
+
+ /**
+ * 查询 字典表数据 支持查询条件 查询所有
+ * @param table
+ * @param text
+ * @param code
+ * @param filterSql
+ * @return
+ */
+ List queryAllTableDictItems(@Param("table") String table, @Param("text") String text, @Param("code") String code, @Param("filterSql") String filterSql);
}
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/SysUserDepartMapper.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/SysUserDepartMapper.java
index c38501d3..66c47793 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/SysUserDepartMapper.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/SysUserDepartMapper.java
@@ -1,6 +1,10 @@
package com.jero.modules.system.mapper;
import java.util.List;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jero.modules.system.entity.SysUser;
import org.apache.ibatis.annotations.Param;
import com.jero.modules.system.entity.SysUserDepart;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@@ -8,4 +12,22 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface SysUserDepartMapper extends BaseMapper{
List getUserDepartByUid(@Param("userId") String userId);
+
+ /**
+ * 查询指定部门下的用户 并且支持用户真实姓名模糊查询
+ * @param orgCode
+ * @param realname
+ * @return
+ */
+ List queryDepartUserList(@Param("orgCode") String orgCode, @Param("realname") String realname);
+
+ /**
+ * 根据部门查询部门用户
+ * @param page
+ * @param orgCode
+ * @param username
+ * @param realname
+ * @return
+ */
+ IPage queryDepartUserPageList(Page page, @Param("orgCode") String orgCode, @Param("username") String username, @Param("realname") String realname);
}
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/xml/SysDictMapper.xml b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/xml/SysDictMapper.xml
index a95bedd2..d7a0d029 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/xml/SysDictMapper.xml
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/xml/SysDictMapper.xml
@@ -121,4 +121,20 @@
+
+
+
+
+
+
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/xml/SysUserDepartMapper.xml b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/xml/SysUserDepartMapper.xml
index 65af5072..6df1c52e 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/xml/SysUserDepartMapper.xml
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/mapper/xml/SysUserDepartMapper.xml
@@ -6,4 +6,31 @@
FROM sys_user_depart
WHERE user_id = #{userId, jdbcType=VARCHAR}
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysCategoryService.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysCategoryService.java
index f5833247..bf3c129b 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysCategoryService.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysCategoryService.java
@@ -58,5 +58,22 @@ public interface ISysCategoryService extends IService {
* @param ids
*/
void deleteSysCategory(String ids);
-
+
+ /**
+ * 分类字典控件数据回显[表单页面]
+ *
+ * @param ids
+ * @return
+ */
+ List loadDictItem(String ids);
+
+ /**
+ * 分类字典控件数据回显[表单页面]
+ *
+ * @param ids
+ * @param delNotExist 是否移除不存在的项,设为false如果某个key不存在数据库中,则直接返回key本身
+ * @return
+ */
+ List loadDictItem(String ids, boolean delNotExist);
+
}
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysDepartService.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysDepartService.java
index 9997d319..f27d5aec 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysDepartService.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysDepartService.java
@@ -1,5 +1,6 @@
package com.jero.modules.system.service;
+import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.common.system.vo.SysDepartTreeModel;
import com.jero.modules.system.entity.SysDepart;
@@ -129,11 +130,27 @@ public interface ISysDepartService extends IService{
* @return
*/
List queryTreeListByPid(String parentId);
+
+ /**
+ * 获取某个部门的所有父级部门的ID
+ *
+ * @param departId 根据departId查
+ */
+ JSONObject queryAllParentIdByDepartId(String departId);
+
+ /**
+ * 获取某个部门的所有父级部门的ID
+ *
+ * @param orgCode 根据orgCode查
+ */
+ JSONObject queryAllParentIdByOrgCode(String orgCode);
+
/**
* 获取公司信息
* @return
*/
SysDepart queryCompByOrgCode(String orgCode);
+
/**
* 获取下级部门
* @return
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysDictService.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysDictService.java
index 575a217a..441978b0 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysDictService.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysDictService.java
@@ -38,6 +38,9 @@ public interface ISysDictService extends IService {
@Deprecated
List queryTableDictByKeys(String table, String text, String code, String keys);
+ @Deprecated
+ List queryTableDictByKeys(String table, String text, String code, String keys,boolean delNotExist);
+
/**
* 根据字典类型删除关联表中其对应的数据
*
@@ -82,10 +85,21 @@ public interface ISysDictService extends IService {
* @param keyword
* @return
*/
- public List queryLittleTableDictItems(String table, String text, String code,String keyword, int pageSize);
+ public List queryLittleTableDictItems(String table, String text, String code, String condition, String keyword, int pageSize);
/**
- * 根据表名、显示字段名、存储字段名 查询树
+ * 查询字典表所有数据
+ * @param table
+ * @param text
+ * @param code
+ * @param condition
+ * @param keyword
+ * @return
+ */
+ public List queryAllTableDictItems(String table, String text, String code, String condition, String keyword);
+
+ /**
+ * 根据表名、显示字段名、存储字段名 查询树
* @param table
* @param text
* @param code
@@ -94,7 +108,8 @@ public interface ISysDictService extends IService {
* @param hasChildField
* @return
*/
- List queryTreeList(String query,String table, String text, String code, String pidField,String pid,String hasChildField);
+ @Deprecated
+ List queryTreeList(Map query,String table, String text, String code, String pidField,String pid,String hasChildField);
/**
* 根据表名、显示字段名、存储字段名 和查询条件拼接树结构
@@ -135,6 +150,23 @@ public interface ISysDictService extends IService {
@Deprecated
public List queryDictTablePageList(DictQuery query,int pageSize, int pageNo);
+ /**
+ * 获取字典数据
+ * @param dictCode 字典code
+ * @param dictCode 表名,文本字段,code字段 | 举例:sys_user,realname,id
+ * @return
+ */
+ List getDictItems(String dictCode);
+
+ /**
+ * 【JSearchSelectTag下拉搜索组件专用接口】
+ * 大数据量的字典表 走异步加载 即前端输入内容过滤数据
+ *
+ * @param dictCode 字典code格式:table,text,code
+ * @return
+ */
+ List loadDict(String dictCode, String keyword, Integer pageSize);
+
/**
* 刷新dict缓存
* @date 2021/4/8 9:06
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysUserDepartService.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysUserDepartService.java
index 69036006..3c97dd18 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysUserDepartService.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysUserDepartService.java
@@ -3,6 +3,7 @@ package com.jero.modules.system.service;
import java.util.List;
+import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.entity.SysUserDepart;
import com.jero.modules.system.model.DepartIdModel;
@@ -34,8 +35,20 @@ public interface ISysUserDepartService extends IService {
* @return
*/
List queryUserByDepId(String depId);
- /**
+
+ /**
* 根据部门code,查询当前部门和下级部门的用户信息
*/
- public List queryUserByDepCode(String depCode,String realname);
+ List queryUserByDepCode(String depCode,String realname);
+
+ /**
+ * 用户组件数据查询
+ * @param departId
+ * @param username
+ * @param pageSize
+ * @param pageNo
+ * @return
+ */
+ IPage queryDepartUserPageList(String departId, String username, String realname, int pageSize, int pageNo);
+
}
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysUserService.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysUserService.java
index ed237bf8..e6ab24e8 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysUserService.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/ISysUserService.java
@@ -1,5 +1,6 @@
package com.jero.modules.system.service;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -233,4 +234,24 @@ public interface ISysUserService extends IService {
* @return
*/
List queryByDepIds(List departIds, String username);
+
+ /**
+ * 保存用户
+ * @param user 用户
+ * @param selectedRoles 选择的角色id,多个以逗号隔开
+ * @param selectedDeparts 选择的部门id,多个以逗号隔开
+ */
+ void saveUser(SysUser user, String selectedRoles, String selectedDeparts);
+
+ /**
+ * 编辑用户
+ * @param user 用户
+ * @param roles 选择的角色id,多个以逗号隔开
+ * @param departs 选择的部门id,多个以逗号隔开
+ */
+ void editUser(SysUser user, String roles, String departs);
+
+ /** userId转为username */
+ List userIdToUsername(Collection userIdList);
+
}
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysBaseApiImpl.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysBaseApiImpl.java
index 77fb8222..5133f4a8 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysBaseApiImpl.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysBaseApiImpl.java
@@ -199,6 +199,8 @@ public class SysBaseApiImpl implements ISysBaseAPI {
info.setSysUserCode(user.getUsername());
info.setSysUserName(user.getRealname());
info.setSysOrgCode(user.getOrgCode());
+ }else{
+ return null;
}
//多部门支持in查询
List list = departMapper.queryUserDeparts(user.getId());
@@ -265,7 +267,7 @@ public class SysBaseApiImpl implements ISysBaseAPI {
}
@Override
- @Cacheable(value = CacheConstant.SYS_DICT_CACHE,key = "#code")
+ @Cacheable(value = CacheConstant.SYS_DICT_CACHE,key = "#code", unless = "#result == null ")
public List queryDictItemsByCode(String code) {
return sysDictService.queryDictItemsByCode(code);
}
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysCategoryServiceImpl.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysCategoryServiceImpl.java
index f216f32a..3d99de98 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysCategoryServiceImpl.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysCategoryServiceImpl.java
@@ -1,8 +1,10 @@
package com.jero.modules.system.service.impl;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -204,4 +206,32 @@ public class SysCategoryServiceImpl extends ServiceImpl loadDictItem(String ids) {
+ return this.loadDictItem(ids, true);
+ }
+
+ @Override
+ public List loadDictItem(String ids, boolean delNotExist) {
+ String[] idArray = ids.split(",");
+ LambdaQueryWrapper query = new LambdaQueryWrapper<>();
+ query.in(SysCategory::getId, Arrays.asList(idArray));
+ // 查询数据
+ List list = super.list(query);
+ // 取出name并返回
+ List textList;
+ // update-begin--author:sunjianlei--date:20210514--for:新增delNotExist参数,设为false不删除数据库里不存在的key ----
+ if (delNotExist) {
+ textList = list.stream().map(SysCategory::getName).collect(Collectors.toList());
+ } else {
+ textList = new ArrayList<>();
+ for (String id : idArray) {
+ List res = list.stream().filter(i -> id.equals(i.getId())).collect(Collectors.toList());
+ textList.add(res.size() > 0 ? res.get(0).getName() : id);
+ }
+ }
+ // update-end--author:sunjianlei--date:20210514--for:新增delNotExist参数,设为false不删除数据库里不存在的key ----
+ return textList;
+ }
+
}
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysDepartServiceImpl.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysDepartServiceImpl.java
index dfc88286..a121a048 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysDepartServiceImpl.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysDepartServiceImpl.java
@@ -2,8 +2,11 @@ package com.jero.modules.system.service.impl;
import java.util.*;
+import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jero.common.system.vo.SysDepartTreeModel;
+import com.jero.common.util.oConvertUtils;
import org.apache.commons.lang.StringUtils;
import com.jero.common.constant.CacheConstant;
import com.jero.common.constant.CommonConstant;
@@ -473,7 +476,7 @@ public class SysDepartServiceImpl extends ServiceImpl0){
treeModel.setIsLeaf(false);
@@ -484,6 +487,60 @@ public class SysDepartServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq(fieldName, value);
+ SysDepart depart = super.getOne(queryWrapper);
+ if (depart != null) {
+ data.getJSONArray("parentIds").add(0, depart.getId());
+ data.getJSONObject("parentMap").put(depart.getId(), depart);
+ if (oConvertUtils.isNotEmpty(depart.getParentId())) {
+ this.queryAllParentIdRecursion("id", depart.getParentId(), data);
+ }
+ }
+ }
+
@Override
public SysDepart queryCompByOrgCode(String orgCode) {
int length = YouBianCodeUtil.zhanweiLength;
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysDictServiceImpl.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysDictServiceImpl.java
index 1a96d51a..9679ed19 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysDictServiceImpl.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysDictServiceImpl.java
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.jero.common.util.SqlInjectionUtil;
import lombok.extern.slf4j.Slf4j;
import com.jero.common.constant.CacheConstant;
import com.jero.common.constant.CommonConstant;
@@ -53,7 +54,7 @@ public class SysDictServiceImpl extends ServiceImpl impl
* @return
*/
@Override
- @Cacheable(value = CacheConstant.SYS_DICT_CACHE,key = "#code")
+ @Cacheable(value = CacheConstant.SYS_DICT_CACHE,key = "#code", unless = "#result == null ")
public List queryDictItemsByCode(String code) {
log.debug("无缓存dictCache的时候调用这里!");
return sysDictMapper.queryDictItemsByCode(code);
@@ -89,7 +90,7 @@ public class SysDictServiceImpl extends ServiceImpl impl
*/
@Override
- @Cacheable(value = CacheConstant.SYS_DICT_CACHE,key = "#code+':'+#key")
+ @Cacheable(value = CacheConstant.SYS_DICT_CACHE,key = "#code+':'+#key", unless = "#result == null ")
public String queryDictTextByKey(String code, String key) {
log.debug("无缓存dictText的时候调用这里!");
return sysDictMapper.queryDictTextByKey(code, key);
@@ -126,12 +127,17 @@ public class SysDictServiceImpl extends ServiceImpl impl
* @return
*/
@Override
- @Cacheable(value = CacheConstant.SYS_DICT_TABLE_CACHE)
+ @Cacheable(value = CacheConstant.SYS_DICT_TABLE_CACHE, unless = "#result == null ")
public String queryTableDictTextByKey(String table,String text,String code, String key) {
log.debug("无缓存dictTable的时候调用这里!");
return sysDictMapper.queryTableDictTextByKey(table,text,code,key);
}
+ @Override
+ public List queryTableDictByKeys(String table, String text, String code, String keys) {
+ return this.queryTableDictByKeys(table, text, code, keys, true);
+ }
+
/**
* 通过查询指定table的 text code 获取字典,包含text和value
* dictTableCache采用redis缓存有效期10分钟
@@ -139,28 +145,33 @@ public class SysDictServiceImpl extends ServiceImpl impl
* @param text
* @param code
* @param keys (逗号分隔)
+ * @param delNotExist 是否移除不存在的项,默认为true,设为false如果某个key不存在数据库中,则直接返回key本身
* @return
*/
@Override
//update-begin--Author:lvdandan Date:20201204 for:JT-36【online】树形列表bug修改后,还是显示原来值 暂时去掉缓存
//@Cacheable(value = CacheConstant.SYS_DICT_TABLE_BY_KEYS_CACHE)
//update-end--Author:lvdandan Date:20201204 for:JT-36【online】树形列表bug修改后,还是显示原来值 暂时去掉缓存
- public List queryTableDictByKeys(String table, String text, String code, String keys) {
+ public List queryTableDictByKeys(String table, String text, String code, String keys, boolean delNotExist) {
if(oConvertUtils.isEmpty(keys)){
return null;
}
String[] keyArray = keys.split(",");
List dicts = sysDictMapper.queryTableDictByKeys(table, text, code, keyArray);
List texts = new ArrayList<>(dicts.size());
+
+ // update-begin--author:sunjianlei--date:20210514--for:新增delNotExist参数,设为false不删除数据库里不存在的key ----
// 查询出来的顺序可能是乱的,需要排个序
for (String key : keyArray) {
- for (DictModel dict : dicts) {
- if (key.equals(dict.getValue())) {
- texts.add(dict.getText());
- break;
- }
+ List res = dicts.stream().filter(i -> key.equals(i.getValue())).collect(Collectors.toList());
+ if (res.size() > 0) {
+ texts.add(res.get(0).getText());
+ } else if (!delNotExist) {
+ texts.add(key);
}
}
+ // update-end--author:sunjianlei--date:20210514--for:新增delNotExist参数,设为false不删除数据库里不存在的key ----
+
return texts;
}
@@ -208,15 +219,53 @@ public class SysDictServiceImpl extends ServiceImpl impl
}
@Override
- public List queryLittleTableDictItems(String table, String text, String code, String keyword, int pageSize) {
- Page page = new Page(1, pageSize);
- IPage pageList = baseMapper.queryTableDictItems(page, table, text, code, "%"+keyword+"%");
+ public List queryLittleTableDictItems(String table, String text, String code, String condition, String keyword, int pageSize) {
+ Page page = new Page(1, pageSize);
+ page.setSearchCount(false);
+ String filterSql = getFilterSql(text, code, condition, keyword);
+ IPage pageList = baseMapper.queryTableDictWithFilter(page, table, text, code, filterSql);
return pageList.getRecords();
}
+ /**
+ * 获取条件语句
+ * @param text
+ * @param code
+ * @param condition
+ * @param keyword
+ * @return
+ */
+ private String getFilterSql(String text, String code, String condition, String keyword){
+ String keywordSql = null, filterSql = "", sql_where = " where ";
+ if(oConvertUtils.isNotEmpty(keyword)){
+ // 判断是否是多选
+ if (keyword.contains(",")) {
+ String inKeywords = "\"" + keyword.replaceAll(",", "\",\"") + "\"";
+ keywordSql = "(" + text + " in (" + inKeywords + ") or " + code + " in (" + inKeywords + "))";
+ } else {
+ keywordSql = "("+text + " like '%"+keyword+"%' or "+ code + " like '%"+keyword+"%')";
+ }
+ }
+ if(oConvertUtils.isNotEmpty(condition) && oConvertUtils.isNotEmpty(keywordSql)){
+ filterSql+= sql_where + condition + " and " + keywordSql;
+ }else if(oConvertUtils.isNotEmpty(condition)){
+ filterSql+= sql_where + condition;
+ }else if(oConvertUtils.isNotEmpty(keywordSql)){
+ filterSql+= sql_where + keywordSql;
+ }
+ return filterSql;
+ }
+
@Override
- public List queryTreeList(String query,String table, String text, String code, String pidField, String pid, String hasChildField) {
- return baseMapper.queryTreeList(query, table, text, code, pidField, pid,hasChildField);
+ public List queryAllTableDictItems(String table, String text, String code, String condition, String keyword) {
+ String filterSql = getFilterSql(text, code, condition, keyword);
+ List ls = baseMapper.queryAllTableDictItems(table, text, code, filterSql);
+ return ls;
+ }
+
+ @Override
+ public List queryTreeList(Map query,String table, String text, String code, String pidField,String pid,String hasChildField) {
+ return baseMapper.queryTreeList(query,table, text, code, pidField, pid,hasChildField);
}
@Override
@@ -288,6 +337,65 @@ public class SysDictServiceImpl extends ServiceImpl impl
Page pageList = baseMapper.queryDictTablePageList(page, query);
return pageList.getRecords();
}
+
+
+ @Override
+ public List getDictItems(String dictCode) {
+ List ls;
+ if (dictCode.contains(",")) {
+ //关联表字典(举例:sys_user,realname,id)
+ String[] params = dictCode.split(",");
+ if (params.length < 3) {
+ // 字典Code格式不正确
+ return null;
+ }
+ //SQL注入校验(只限制非法串改数据库)
+ final String[] sqlInjCheck = {params[0], params[1], params[2]};
+ SqlInjectionUtil.filterContent(sqlInjCheck);
+ if (params.length == 4) {
+ // SQL注入校验(查询条件SQL 特殊check,此方法仅供此处使用)
+ SqlInjectionUtil.specialFilterContent(params[3]);
+ ls = this.queryTableDictItemsByCodeAndFilter(params[0], params[1], params[2], params[3]);
+ } else if (params.length == 3) {
+ ls = this.queryTableDictItemsByCode(params[0], params[1], params[2]);
+ } else {
+ // 字典Code格式不正确
+ return null;
+ }
+ } else {
+ //字典表
+ ls = this.queryDictItemsByCode(dictCode);
+ }
+ return ls;
+ }
+
+ @Override
+ public List loadDict(String dictCode, String keyword, Integer pageSize) {
+ if (dictCode.contains(",")) {
+ //update-begin-author:taoyan date:20210329 for: 下拉搜索不支持表名后加查询条件
+ String[] params = dictCode.split(",");
+ String condition = null;
+ if (params.length != 3 && params.length != 4) {
+ // 字典Code格式不正确
+ return null;
+ } else if (params.length == 4) {
+ condition = params[3];
+ }
+ List ls;
+ if (pageSize != null) {
+ ls = this.queryLittleTableDictItems(params[0], params[1], params[2], condition, keyword, pageSize);
+ } else {
+ ls = this.queryAllTableDictItems(params[0], params[1], params[2], condition, keyword);
+ }
+ //update-end-author:taoyan date:20210329 for: 下拉搜索不支持表名后加查询条件
+ return ls;
+ } else {
+ // 字典Code格式不正确
+ return null;
+ }
+ }
+
+
/**
* 刷新dict缓存
* @date 2021/4/8 9:07
@@ -299,12 +407,14 @@ public class SysDictServiceImpl extends ServiceImpl impl
//清空字典缓存
Set keys = redisTemplate.keys(CacheConstant.SYS_DICT_CACHE + "*");
Set keys2 = redisTemplate.keys(CacheConstant.SYS_DICT_TABLE_CACHE + "*");
+ Set keys21 = redisTemplate.keys(CacheConstant.SYS_DICT_TABLE_BY_KEYS_CACHE + "*");
Set keys3 = redisTemplate.keys(CacheConstant.SYS_DEPARTS_CACHE + "*");
Set keys4 = redisTemplate.keys(CacheConstant.SYS_DEPART_IDS_CACHE + "*");
Set keys5 = redisTemplate.keys( "jmreport:cache:dict*");
Set keys6 = redisTemplate.keys( "jmreport:cache:dictTable*");
redisTemplate.delete(keys);
redisTemplate.delete(keys2);
+ redisTemplate.delete(keys21);
redisTemplate.delete(keys3);
redisTemplate.delete(keys4);
redisTemplate.delete(keys5);
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysUserDepartServiceImpl.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysUserDepartServiceImpl.java
index 0f5b77ab..c3eed402 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysUserDepartServiceImpl.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysUserDepartServiceImpl.java
@@ -1,11 +1,15 @@
package com.jero.modules.system.service.impl;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.util.oConvertUtils;
import com.jero.modules.system.entity.SysDepart;
import com.jero.modules.system.entity.SysUser;
@@ -100,34 +104,58 @@ public class SysUserDepartServiceImpl extends ServiceImpl queryUserByDepCode(String depCode,String realname) {
- LambdaQueryWrapper queryByDepCode = new LambdaQueryWrapper();
- queryByDepCode.likeRight(SysDepart::getOrgCode,depCode);
- List sysDepartList = sysDepartService.list(queryByDepCode);
- List depIds = sysDepartList.stream().map(SysDepart::getId).collect(Collectors.toList());
-
- LambdaQueryWrapper queryUDep = new LambdaQueryWrapper();
- queryUDep.in(SysUserDepart::getDepId, depIds);
- List userIdList = new ArrayList<>();
- List uDepList = this.list(queryUDep);
- if(uDepList != null && uDepList.size() > 0) {
- for(SysUserDepart uDep : uDepList) {
- userIdList.add(uDep.getUserId());
- }
- LambdaQueryWrapper queryUser = new LambdaQueryWrapper();
- queryUser.in(SysUser::getId,userIdList);
- if(oConvertUtils.isNotEmpty(realname)){
- queryUser.like(SysUser::getRealname,realname.trim());
- }
- List userList = (List) sysUserService.list(queryUser);
- //update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
- for (SysUser sysUser : userList) {
- sysUser.setSalt("");
- sysUser.setPassword("");
- }
- //update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
- return userList;
+ //update-begin-author:taoyan date:20210422 for: 根据部门选择用户接口代码优化
+ if(oConvertUtils.isNotEmpty(realname)){
+ realname = realname.trim();
}
- return new ArrayList();
+ List userList = this.baseMapper.queryDepartUserList(depCode, realname);
+ Map map = new HashMap();
+ for (SysUser sysUser : userList) {
+ // 返回的用户数据去掉密码信息
+ sysUser.setSalt("");
+ sysUser.setPassword("");
+ map.put(sysUser.getId(), sysUser);
+ }
+ return new ArrayList(map.values());
+ //update-end-author:taoyan date:20210422 for: 根据部门选择用户接口代码优化
+
}
-
+
+ @Override
+ public IPage queryDepartUserPageList(String departId, String username, String realname, int pageSize, int pageNo) {
+ IPage pageList = null;
+ // 部门ID不存在 直接查询用户表即可
+ Page page = new Page(pageNo, pageSize);
+ if(oConvertUtils.isEmpty(departId)){
+ LambdaQueryWrapper query = new LambdaQueryWrapper<>();
+ if(oConvertUtils.isNotEmpty(username)){
+ query.like(SysUser::getUsername, username);
+ }
+ pageList = sysUserService.page(page, query);
+ }else{
+ // 有部门ID 需要走自定义sql
+ SysDepart sysDepart = sysDepartService.getById(departId);
+ pageList = this.baseMapper.queryDepartUserPageList(page, sysDepart.getOrgCode(), username, realname);
+ }
+ List userList = pageList.getRecords();
+ if(userList!=null && userList.size()>0){
+ List userIds = userList.stream().map(SysUser::getId).collect(Collectors.toList());
+ Map map = new HashMap();
+ if(userIds!=null && userIds.size()>0){
+ // 查部门名称
+ Map useDepNames = sysUserService.getDepNamesByUserIds(userIds);
+ userList.forEach(item->{
+ //TODO 临时借用这个字段用于页面展示
+ item.setOrgCodeTxt(useDepNames.get(item.getId()));
+ item.setSalt("");
+ item.setPassword("");
+ // 去重
+ map.put(item.getId(), item);
+ });
+ }
+ pageList.setRecords(new ArrayList(map.values()));
+ }
+ return pageList;
+ }
+
}
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysUserServiceImpl.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysUserServiceImpl.java
index 18c1da9b..3af7dc15 100644
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysUserServiceImpl.java
+++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysUserServiceImpl.java
@@ -439,4 +439,89 @@ public class SysUserServiceImpl extends ServiceImpl impl
return userMapper.queryByDepIds(departIds,username);
}
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void saveUser(SysUser user, String selectedRoles, String selectedDeparts) {
+ //step.1 保存用户
+ this.save(user);
+ //step.2 保存角色
+ if(oConvertUtils.isNotEmpty(selectedRoles)) {
+ String[] arr = selectedRoles.split(",");
+ for (String roleId : arr) {
+ SysUserRole userRole = new SysUserRole(user.getId(), roleId);
+ sysUserRoleMapper.insert(userRole);
+ }
+ }
+ //step.3 保存所属部门
+ if(oConvertUtils.isNotEmpty(selectedDeparts)) {
+ String[] arr = selectedDeparts.split(",");
+ for (String deaprtId : arr) {
+ SysUserDepart userDeaprt = new SysUserDepart(user.getId(), deaprtId);
+ sysUserDepartMapper.insert(userDeaprt);
+ }
+ }
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ @CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true)
+ public void editUser(SysUser user, String roles, String departs) {
+ //step.1 修改用户基础信息
+ this.updateById(user);
+ //step.2 修改角色
+ //处理用户角色 先删后加
+ sysUserRoleMapper.delete(new QueryWrapper().lambda().eq(SysUserRole::getUserId, user.getId()));
+ if(oConvertUtils.isNotEmpty(roles)) {
+ String[] arr = roles.split(",");
+ for (String roleId : arr) {
+ SysUserRole userRole = new SysUserRole(user.getId(), roleId);
+ sysUserRoleMapper.insert(userRole);
+ }
+ }
+
+ //step.3 修改部门
+ String[] arr = {};
+ if(oConvertUtils.isNotEmpty(departs)){
+ arr = departs.split(",");
+ }
+ //查询已关联部门
+ List userDepartList = sysUserDepartMapper.selectList(new QueryWrapper().lambda().eq(SysUserDepart::getUserId, user.getId()));
+ if(userDepartList != null && userDepartList.size()>0){
+ for(SysUserDepart depart : userDepartList ){
+ //修改已关联部门删除部门用户角色关系
+ if(!Arrays.asList(arr).contains(depart.getDepId())){
+ List sysDepartRoleList = sysDepartRoleMapper.selectList(
+ new QueryWrapper().lambda().eq(SysDepartRole::getDepartId,depart.getDepId()));
+ List roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
+ if(roleIds != null && roleIds.size()>0){
+ departRoleUserMapper.delete(new QueryWrapper().lambda().eq(SysDepartRoleUser::getUserId, user.getId())
+ .in(SysDepartRoleUser::getDroleId,roleIds));
+ }
+ }
+ }
+ }
+ //先删后加
+ sysUserDepartMapper.delete(new QueryWrapper().lambda().eq(SysUserDepart::getUserId, user.getId()));
+ if(oConvertUtils.isNotEmpty(departs)) {
+ for (String departId : arr) {
+ SysUserDepart userDepart = new SysUserDepart(user.getId(), departId);
+ sysUserDepartMapper.insert(userDepart);
+ }
+ }
+ //step.4 修改手机号和邮箱
+ // 更新手机号、邮箱空字符串为 null
+ userMapper.updateNullByEmptyString("email");
+ userMapper.updateNullByEmptyString("phone");
+
+ }
+
+ @Override
+ public List userIdToUsername(Collection userIdList) {
+ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.in(SysUser::getId, userIdList);
+ List userList = super.list(queryWrapper);
+ return userList.stream().map(SysUser::getUsername).collect(Collectors.toList());
+ }
+
+
}
diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/util/TenantContext.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/util/TenantContext.java
deleted file mode 100644
index 7b9abaae..00000000
--- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/util/TenantContext.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.jero.modules.system.util;
-
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * 多租户 tenant_id存储器
- */
-@Slf4j
-public class TenantContext {
-
- private static ThreadLocal currentTenant = new ThreadLocal<>();
-
- public static void setTenant(String tenant) {
- log.debug(" setting tenant to " + tenant);
- currentTenant.set(tenant);
- }
-
- public static String getTenant() {
- return currentTenant.get();
- }
-
- public static void clear(){
- currentTenant.remove();
- }
-}