From 39ba55149edd778eb6c514ba1d18610e4b6b86b7 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Mon, 27 Jan 2020 23:55:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=A8=E6=80=81=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E5=88=97=E8=A1=A8=E7=9A=84=E8=81=94=E8=A1=A8=EF=BC=88?= =?UTF-8?q?left,inner,right)=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/dao/dynamic/IDynamicFormDao.java | 4 +- .../plugin/enums/dynamic/FieldTypeEnum.java | 14 +- .../pojo/dtos/dynamic/DynamicFormDTO.java | 95 ++++++++-- .../config/form/DynamicConfigFormDTO.java | 60 +++++++ .../config/form/DynamicConfigFormVO.java | 66 ++++++- .../service/dynamic/IDynamicFormService.java | 17 ++ .../dynamic/impl/DynamicDataServiceImpl.java | 13 +- .../dynamic/impl/DynamicFormServiceImpl.java | 167 ++++++++++++++++-- .../config/form/dynamicconfigform-mapper.xml | 30 ++++ .../mapper/dynamic/dynamicdata-mapper.xml | 44 ++++- .../mapper/dynamic/dynamicform-mapper.xml | 16 +- .../templates/dynamic/config/form/list.html | 24 +++ .../templates/dynamic/config/form/save.html | 143 ++++++++++----- .../templates/dynamic/config/form/update.html | 158 ++++++++++++----- .../annotation/CheckEmptyAnnotation.java | 1 + .../java/com/cm/common/utils/HashMapUtil.java | 57 +++++- 16 files changed, 764 insertions(+), 145 deletions(-) diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/dynamic/IDynamicFormDao.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/dynamic/IDynamicFormDao.java index af397c0..b36f22e 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/dynamic/IDynamicFormDao.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/dao/dynamic/IDynamicFormDao.java @@ -41,9 +41,9 @@ public interface IDynamicFormDao { /** * 动态表单详情 * - * @param tableName + * @param params * @return * @throws SearchException */ - List listDynamicForm(String tableName) throws SearchException; + List listDynamicForm(Map params) throws SearchException; } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/enums/dynamic/FieldTypeEnum.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/enums/dynamic/FieldTypeEnum.java index 168f22d..2fdeb9f 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/enums/dynamic/FieldTypeEnum.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/enums/dynamic/FieldTypeEnum.java @@ -67,7 +67,19 @@ public enum FieldTypeEnum { /** * 外联 */ - JOIN("join"); + JOIN("join"), + /** + * 内联 + */ + INNER_JOIN("innerJoin"), + /** + * 左联 + */ + LEFT_JOIN("leftJoin"), + /** + * 右联 + */ + RIGHT_JOIN("rightJoin"); private String value; diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/DynamicFormDTO.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/DynamicFormDTO.java index 42d4331..967a918 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/DynamicFormDTO.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/DynamicFormDTO.java @@ -40,6 +40,16 @@ public class DynamicFormDTO { private Integer listShow; @ApiModelProperty(name = "formShow", value = "表单显示") private Integer formShow; + @ApiModelProperty(name = "joinTable", value = "联表") + private String joinTable; + @ApiModelProperty(name = "joinTableField", value = "联表字段") + private String joinTableField; + @ApiModelProperty(name = "joinTableSort", value = "联表顺序") + private Integer joinTableSort; + @ApiModelProperty(name = "joinTableListShow", value = "联表列表显示") + private String joinTableListShow; + @ApiModelProperty(name = "joinTableFormShow", value = "联表表单显示") + private String joinTableFormShow; public String getId() { return id == null ? "" : id; @@ -137,34 +147,83 @@ public class DynamicFormDTO { this.formShow = formShow; } + public String getJoinTable() { + return joinTable == null ? "" : joinTable.trim(); + } + + public void setJoinTable(String joinTable) { + this.joinTable = joinTable; + } + + public String getJoinTableField() { + return joinTableField == null ? "" : joinTableField.trim(); + } + + public void setJoinTableField(String joinTableField) { + this.joinTableField = joinTableField; + } + + public Integer getJoinTableSort() { + return joinTableSort; + } + + public void setJoinTableSort(Integer joinTableSort) { + this.joinTableSort = joinTableSort; + } + + public String getJoinTableListShow() { + return joinTableListShow == null ? "" : joinTableListShow.trim(); + } + + public void setJoinTableListShow(String joinTableListShow) { + this.joinTableListShow = joinTableListShow; + } + + public String getJoinTableFormShow() { + return joinTableFormShow == null ? "" : joinTableFormShow.trim(); + } + + public void setJoinTableFormShow(String joinTableFormShow) { + this.joinTableFormShow = joinTableFormShow; + } @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); - sb.append("\"id\":\"") - .append(id).append('\"'); - sb.append(",\"tableName\":\"") - .append(tableName).append('\"'); - sb.append(",\"fieldName\":\"") - .append(fieldName).append('\"'); - sb.append(",\"fieldExplain\":\"") - .append(fieldExplain).append('\"'); - sb.append(",\"fieldType\":\"") - .append(fieldType).append('\"'); - sb.append(",\"fieldDefault\":\"") - .append(fieldDefault).append('\"'); - sb.append(",\"dictionaryId\":\"") - .append(dictionaryId).append('\"'); - sb.append(",\"verifyType\":\"") - .append(verifyType).append('\"'); - sb.append(",\"verifyRegular\":\"") - .append(verifyRegular).append('\"'); + sb.append("\"id\":") + .append("\"").append(id).append("\""); + sb.append(",\"tableName\":") + .append("\"").append(tableName).append("\""); + sb.append(",\"fieldName\":") + .append("\"").append(fieldName).append("\""); + sb.append(",\"fieldExplain\":") + .append("\"").append(fieldExplain).append("\""); + sb.append(",\"fieldType\":") + .append("\"").append(fieldType).append("\""); + sb.append(",\"fieldDefault\":") + .append("\"").append(fieldDefault).append("\""); + sb.append(",\"dictionaryId\":") + .append("\"").append(dictionaryId).append("\""); + sb.append(",\"verifyType\":") + .append("\"").append(verifyType).append("\""); + sb.append(",\"verifyRegular\":") + .append("\"").append(verifyRegular).append("\""); sb.append(",\"fieldSort\":") .append(fieldSort); sb.append(",\"listShow\":") .append(listShow); sb.append(",\"formShow\":") .append(formShow); + sb.append(",\"joinTable\":") + .append("\"").append(joinTable).append("\""); + sb.append(",\"joinTableField\":") + .append("\"").append(joinTableField).append("\""); + sb.append(",\"joinTableSort\":") + .append(joinTableSort); + sb.append(",\"joinTableListShow\":") + .append("\"").append(joinTableListShow).append("\""); + sb.append(",\"joinTableFormShow\":") + .append("\"").append(joinTableFormShow).append("\""); sb.append('}'); return sb.toString(); } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/config/form/DynamicConfigFormDTO.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/config/form/DynamicConfigFormDTO.java index faa060b..94f6c15 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/config/form/DynamicConfigFormDTO.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/config/form/DynamicConfigFormDTO.java @@ -44,6 +44,16 @@ public class DynamicConfigFormDTO { private Integer listShow; @ApiModelProperty(name = "formShow", value = "表单显示") private Integer formShow; + @ApiModelProperty(name = "joinTable", value = "连接表") + private String joinTable; + @ApiModelProperty(name = "joinTableField", value = "连表字段") + private String joinTableField; + @ApiModelProperty(name = "joinTableSort", value = "连表顺序") + private Integer joinTableSort; + @ApiModelProperty(name = "joinTableListShow", value = "连表列表显示") + private String joinTableListShow; + @ApiModelProperty(name = "joinTableFormShow", value = "连表表单显示") + private String joinTableFormShow; public String getId() { return id == null ? "" : id.trim(); @@ -149,6 +159,46 @@ public class DynamicConfigFormDTO { this.formShow = formShow; } + public String getJoinTable() { + return joinTable == null ? "" : joinTable.trim(); + } + + public void setJoinTable(String joinTable) { + this.joinTable = joinTable; + } + + public String getJoinTableField() { + return joinTableField == null ? "" : joinTableField.trim(); + } + + public void setJoinTableField(String joinTableField) { + this.joinTableField = joinTableField; + } + + public Integer getJoinTableSort() { + return joinTableSort; + } + + public void setJoinTableSort(Integer joinTableSort) { + this.joinTableSort = joinTableSort; + } + + public String getJoinTableListShow() { + return joinTableListShow == null ? "" : joinTableListShow.trim(); + } + + public void setJoinTableListShow(String joinTableListShow) { + this.joinTableListShow = joinTableListShow; + } + + public String getJoinTableFormShow() { + return joinTableFormShow == null ? "" : joinTableFormShow.trim(); + } + + public void setJoinTableFormShow(String joinTableFormShow) { + this.joinTableFormShow = joinTableFormShow; + } + @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); @@ -178,6 +228,16 @@ public class DynamicConfigFormDTO { .append(listShow); sb.append(",\"formShow\":") .append(formShow); + sb.append(",\"joinTable\":") + .append("\"").append(joinTable).append("\""); + sb.append(",\"joinTableField\":") + .append("\"").append(joinTableField).append("\""); + sb.append(",\"joinTableSort\":") + .append(joinTableSort); + sb.append(",\"joinTableListShow\":") + .append("\"").append(joinTableListShow).append("\""); + sb.append(",\"joinTableFormShow\":") + .append("\"").append(joinTableFormShow).append("\""); sb.append('}'); return sb.toString(); } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/vos/dynamic/config/form/DynamicConfigFormVO.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/vos/dynamic/config/form/DynamicConfigFormVO.java index dd16791..4335653 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/vos/dynamic/config/form/DynamicConfigFormVO.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/vos/dynamic/config/form/DynamicConfigFormVO.java @@ -28,7 +28,11 @@ public class DynamicConfigFormVO { @CheckEmptyAnnotation(name = "字段说明") private String fieldExplain; @ApiModelProperty(name = "fieldType", value = "字段类型") - @CheckEmptyAnnotation(name = "字段类型", types = {"string", "datetime", "date", "number", "double", "textarea", "richText", "select", "checkbox", "radio", "selectUser", "selectDepartment", "file", "join"}) + @CheckEmptyAnnotation(name = "字段类型", types = { + "string", "datetime", "date", "number", "double", "textarea", "richText", + "select", "checkbox", "radio", "selectUser", "selectDepartment", "file", + "join", "currentUser", "currentDepartment", "currentRole", "currentGroup", "currentPosition", + "leftJoin", "innerJoin", "rightJoin"}) private String fieldType; @ApiModelProperty(name = "fieldDefault", value = "字段默认值") private String fieldDefault; @@ -47,6 +51,16 @@ public class DynamicConfigFormVO { @ApiModelProperty(name = "formShow", value = "表单显示") @CheckNumberAnnotation(name = "表单显示", types = {"0", "1"}) private Integer formShow; + @ApiModelProperty(name = "joinTable", value = "连接表") + private String joinTable; + @ApiModelProperty(name = "joinTableField", value = "连表字段") + private String joinTableField; + @ApiModelProperty(name = "joinTableSort", value = "连表顺序") + private Integer joinTableSort; + @ApiModelProperty(name = "joinTableListShow", value = "连表列表显示") + private String joinTableListShow; + @ApiModelProperty(name = "joinTableFormShow", value = "连表表单显示") + private String joinTableFormShow; public String getTableName() { return tableName == null ? "" : tableName.trim(); @@ -136,6 +150,46 @@ public class DynamicConfigFormVO { this.formShow = formShow; } + public String getJoinTable() { + return joinTable == null ? "" : joinTable.trim(); + } + + public void setJoinTable(String joinTable) { + this.joinTable = joinTable; + } + + public String getJoinTableField() { + return joinTableField == null ? "" : joinTableField.trim(); + } + + public void setJoinTableField(String joinTableField) { + this.joinTableField = joinTableField; + } + + public Integer getJoinTableSort() { + return joinTableSort; + } + + public void setJoinTableSort(Integer joinTableSort) { + this.joinTableSort = joinTableSort; + } + + public String getJoinTableListShow() { + return joinTableListShow == null ? "" : joinTableListShow.trim(); + } + + public void setJoinTableListShow(String joinTableListShow) { + this.joinTableListShow = joinTableListShow; + } + + public String getJoinTableFormShow() { + return joinTableFormShow == null ? "" : joinTableFormShow.trim(); + } + + public void setJoinTableFormShow(String joinTableFormShow) { + this.joinTableFormShow = joinTableFormShow; + } + @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); @@ -161,6 +215,16 @@ public class DynamicConfigFormVO { .append(listShow); sb.append(",\"formShow\":") .append(formShow); + sb.append(",\"joinTable\":") + .append("\"").append(joinTable).append("\""); + sb.append(",\"joinTableField\":") + .append("\"").append(joinTableField).append("\""); + sb.append(",\"joinTableSort\":") + .append(joinTableSort); + sb.append(",\"joinTableListShow\":") + .append("\"").append(joinTableListShow).append("\""); + sb.append(",\"joinTableFormShow\":") + .append("\"").append(joinTableFormShow).append("\""); sb.append('}'); return sb.toString(); } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicFormService.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicFormService.java index 3aa5262..a6d82d9 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicFormService.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/IDynamicFormService.java @@ -57,6 +57,15 @@ public interface IDynamicFormService { */ List> listListShowField(String tableName) throws SearchException; + /** + * 获取列表显示的字段 + * + * @param dynamicFormDTOs + * @return + * @throws SearchException + */ + List> listListShowField(List dynamicFormDTOs) throws SearchException; + /** * 获取表单显示的字段 * @@ -86,4 +95,12 @@ public interface IDynamicFormService { */ List listFormShowFieldOfPage(String tableName) throws SearchException; + /** + * 连表字段列表 + * + * @param dynamicFormDTOs + * @return + * @throws SearchException + */ + List> listJoinTableField(List dynamicFormDTOs) throws SearchException; } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicDataServiceImpl.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicDataServiceImpl.java index 894b78e..1319f17 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicDataServiceImpl.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicDataServiceImpl.java @@ -11,6 +11,7 @@ import com.cm.common.plugin.service.dynamic.IDynamicTableService; import com.cm.common.pojo.ListPage; import com.cm.common.result.SuccessResult; import com.cm.common.result.SuccessResultList; +import com.cm.common.utils.HashMapUtil; import com.cm.common.utils.RegexUtil; import com.cm.common.utils.UUIDUtil; import com.cm.common.utils.WStringUtil; @@ -156,7 +157,7 @@ public class DynamicDataServiceImpl extends AbstractService implements IDynamicD params.put("joinId", joinId); Map dynamicData = dynamicDataDao.getDynamicJoinData(params); if (Objects.isNull(dynamicData)) { - dynamicData = new HashMap<>(); + dynamicData = getHashMap(0); } resetDynamicDataKey2LowerUpper(dynamicData); return dynamicData; @@ -169,8 +170,16 @@ public class DynamicDataServiceImpl extends AbstractService implements IDynamicD * @param params */ private void setSearchBaseListInfo(String tableName, Map params) { - List> listShowFieldList = dynamicFormService.listListShowField(tableName); + List dynamicFormDTOs = dynamicFormService.listDynamicForm(tableName); + // 列表显示字段 + List> listShowFieldList = dynamicFormService.listListShowField(dynamicFormDTOs); params.put("listShowFieldList", listShowFieldList); + // 联表字段列表 + List> listJoinTableField = dynamicFormService.listJoinTableField(dynamicFormDTOs); + if (!listJoinTableField.isEmpty()) { + HashMapUtil.bubbleSort(listJoinTableField, "joinTableSort", true, true); + params.put("listJoinTableField", listJoinTableField); + } setSearchBaseInfo(tableName, params); } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java index 0b5d426..3cb9be9 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java @@ -20,11 +20,9 @@ import com.cm.common.utils.WStringUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import sun.tools.jconsole.JConsole; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * When you feel like quitting. Think about why you started @@ -56,12 +54,19 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF @Override public List listDynamicForm(String tableName) throws SearchException { - return dynamicFormDao.listDynamicForm(tableName); + Map params = getHashMap(1); + params.put("tableName", tableName); + return dynamicFormDao.listDynamicForm(params); } @Override public List> listListShowField(String tableName) throws SearchException { List dynamicFormDTOs = listDynamicForm(tableName); + return listListShowField(dynamicFormDTOs); + } + + @Override + public List> listListShowField(List dynamicFormDTOs) throws SearchException { List> listShowField = new ArrayList<>(); for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) { if (dynamicFormDTO.getListShow() == 1) { @@ -90,13 +95,15 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF public List listListShowFieldOfPage(String tableName) throws SearchException { List dynamicFormDTOs = listDynamicForm(tableName); List dynamicFormListShowFieldDTOList = new ArrayList<>(); + Integer joinIndex = 0; for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) { + // 显示字段 if (dynamicFormDTO.getListShow() == 1) { - DynamicFormListShowFieldDTO dynamicFormListShowFieldDTO = new DynamicFormListShowFieldDTO(); - dynamicFormListShowFieldDTO.setFieldName(dynamicFormDTO.getFieldName()); - dynamicFormListShowFieldDTO.setFieldExplain(dynamicFormDTO.getFieldExplain()); - dynamicFormListShowFieldDTO.setFieldType(dynamicFormDTO.getFieldType()); - dynamicFormListShowFieldDTOList.add(dynamicFormListShowFieldDTO); + dynamicFormListShowFieldDTOList.add(getDynamicFormListShowFieldDTOByDynamicFormDTO(dynamicFormDTO)); + } + // 联表字段 + if (isJoinDynamicField(dynamicFormDTO)) { + dynamicFormListShowFieldDTOList.addAll(listJoinDynamicFormListShowField(dynamicFormDTO, ++joinIndex)); } } return dynamicFormListShowFieldDTOList; @@ -106,22 +113,135 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF public List listFormShowFieldOfPage(String tableName) throws SearchException { List dynamicFormDTOs = listDynamicForm(tableName); List dynamicFormFormShowFieldDTOList = new ArrayList<>(); + int joinIndex = 0; for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) { + // 显示字段 if (dynamicFormDTO.getFormShow() == 1) { - DynamicFormFormShowFieldDTO dynamicFormFormShowFieldDTO = new DynamicFormFormShowFieldDTO(); - dynamicFormFormShowFieldDTO.setFieldName(dynamicFormDTO.getFieldName()); - dynamicFormFormShowFieldDTO.setFieldExplain(dynamicFormDTO.getFieldExplain()); - dynamicFormFormShowFieldDTO.setFieldDefault(dynamicFormDTO.getFieldDefault()); - dynamicFormFormShowFieldDTO.setDictionaryId(dynamicFormDTO.getDictionaryId()); - dynamicFormFormShowFieldDTO.setFieldType(dynamicFormDTO.getFieldType()); - dynamicFormFormShowFieldDTO.setVerifyType(dynamicFormDTO.getVerifyType()); - dynamicFormFormShowFieldDTO.setVerifyRegular(dynamicFormDTO.getVerifyRegular()); - dynamicFormFormShowFieldDTOList.add(dynamicFormFormShowFieldDTO); + dynamicFormFormShowFieldDTOList.add(getDynamicFormFormShowFieldDTOByDynamicFormDTO(dynamicFormDTO)); + } + // 联表字段 + if (isJoinDynamicField(dynamicFormDTO)) { + dynamicFormFormShowFieldDTOList.addAll(listJoinDynamicFormFormShowField(dynamicFormDTO, ++joinIndex)); } } return dynamicFormFormShowFieldDTOList; } + /** + * 设置动态表单列表 联表 列表显示字段 + * + * @param dynamicFormDTO + * @param index 下标 + * @return + */ + private List listJoinDynamicFormListShowField(DynamicFormDTO dynamicFormDTO, int index) { + List dynamicFormListShowFieldDTOList = new ArrayList<>(); + Map params = getHashMap(2); + params.put("tableName", WStringUtil.firstToLower(dynamicFormDTO.getJoinTable().replaceFirst("dynamic", ""))); + params.put("fieldNameList", Arrays.asList(dynamicFormDTO.getJoinTableListShow().split(","))); + List joinDynamicFormDTOs = dynamicFormDao.listDynamicForm(params); + for (DynamicFormDTO joinDynamicFormDTO : joinDynamicFormDTOs) { + DynamicFormListShowFieldDTO dynamicFormListShowFieldDTO = getDynamicFormListShowFieldDTOByDynamicFormDTO(joinDynamicFormDTO); + dynamicFormListShowFieldDTO.setFieldName(String.format("%sJt%d", dynamicFormListShowFieldDTO.getFieldName(), index)); + dynamicFormListShowFieldDTOList.add(dynamicFormListShowFieldDTO); + } + return dynamicFormListShowFieldDTOList; + } + + /** + * 设置动态表单列表 联表 表单显示字段 + * + * @param dynamicFormDTO + * @param index 下标 + * @return + */ + private List listJoinDynamicFormFormShowField(DynamicFormDTO dynamicFormDTO, int index) { + List dynamicFormFormShowFieldDTOList = new ArrayList<>(); + Map params = getHashMap(2); + params.put("tableName", WStringUtil.firstToLower(dynamicFormDTO.getJoinTable().replaceFirst("dynamic", ""))); + params.put("fieldNameList", Arrays.asList(dynamicFormDTO.getJoinTableListShow().split(","))); + List joinDynamicFormDTOs = dynamicFormDao.listDynamicForm(params); + for (DynamicFormDTO joinDynamicFormDTO : joinDynamicFormDTOs) { + DynamicFormFormShowFieldDTO dynamicFormFormShowFieldDTO = getDynamicFormFormShowFieldDTOByDynamicFormDTO(joinDynamicFormDTO); + dynamicFormFormShowFieldDTO.setFieldName(String.format("%sJt%d", dynamicFormFormShowFieldDTO.getFieldName(), index)); + dynamicFormFormShowFieldDTOList.add(dynamicFormFormShowFieldDTO); + } + return dynamicFormFormShowFieldDTOList; + } + + /** + * 设置动态表单的列表字段 + * + * @param dynamicFormDTO + * @return + */ + private DynamicFormListShowFieldDTO getDynamicFormListShowFieldDTOByDynamicFormDTO(DynamicFormDTO dynamicFormDTO) { + DynamicFormListShowFieldDTO dynamicFormListShowFieldDTO = new DynamicFormListShowFieldDTO(); + dynamicFormListShowFieldDTO.setFieldName(dynamicFormDTO.getFieldName()); + dynamicFormListShowFieldDTO.setFieldExplain(dynamicFormDTO.getFieldExplain()); + dynamicFormListShowFieldDTO.setFieldType(dynamicFormDTO.getFieldType()); + return dynamicFormListShowFieldDTO; + } + + /** + * 设置动态表单的表单字段 + * + * @param dynamicFormDTO + * @return + */ + private DynamicFormFormShowFieldDTO getDynamicFormFormShowFieldDTOByDynamicFormDTO(DynamicFormDTO dynamicFormDTO) { + DynamicFormFormShowFieldDTO dynamicFormFormShowFieldDTO = new DynamicFormFormShowFieldDTO(); + dynamicFormFormShowFieldDTO.setFieldName(dynamicFormDTO.getFieldName()); + dynamicFormFormShowFieldDTO.setFieldExplain(dynamicFormDTO.getFieldExplain()); + dynamicFormFormShowFieldDTO.setFieldDefault(dynamicFormDTO.getFieldDefault()); + dynamicFormFormShowFieldDTO.setDictionaryId(dynamicFormDTO.getDictionaryId()); + dynamicFormFormShowFieldDTO.setFieldType(dynamicFormDTO.getFieldType()); + dynamicFormFormShowFieldDTO.setVerifyType(dynamicFormDTO.getVerifyType()); + dynamicFormFormShowFieldDTO.setVerifyRegular(dynamicFormDTO.getVerifyRegular()); + return dynamicFormFormShowFieldDTO; + } + + @Override + public List> listJoinTableField(List dynamicFormDTOs) throws SearchException { + List> listShowField = new ArrayList<>(); + for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) { + boolean isJoin = isJoinDynamicField(dynamicFormDTO); + if (isJoin) { + Map listShow = new HashMap<>(2); + listShow.put("fieldType", dynamicFormDTO.getFieldType()); + listShow.put("fieldName", WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getFieldName())); + listShow.put("joinTable", WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getJoinTable())); + listShow.put("joinTableField", WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getJoinTableField())); + listShow.put("joinTableSort", dynamicFormDTO.getJoinTableSort()); + // 构建连表显示字段 + List listJoinTableListShow = new ArrayList<>(); + if (!StringUtils.isBlank(dynamicFormDTO.getJoinTableListShow())) { + String[] joinTableListShowArray = dynamicFormDTO.getJoinTableListShow().split(","); + for (String joinTableListShow : joinTableListShowArray) { + listJoinTableListShow.add(WStringUtil.lowerUpper2UnderLine(joinTableListShow)); + } + } else { + listJoinTableListShow.add(WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getJoinTableListShow())); + } + listShow.put("joinTableListShow", listJoinTableListShow); + listShowField.add(listShow); + } + } + return listShowField; + } + + /** + * 判断是否是动态字段 + * + * @param dynamicFormDTO + * @return + */ + private boolean isJoinDynamicField(DynamicFormDTO dynamicFormDTO) { + return (StringUtils.equals(FieldTypeEnum.INNER_JOIN.getValue(), dynamicFormDTO.getFieldType()) + || StringUtils.equals(FieldTypeEnum.LEFT_JOIN.getValue(), dynamicFormDTO.getFieldType()) + || StringUtils.equals(FieldTypeEnum.RIGHT_JOIN.getValue(), dynamicFormDTO.getFieldType())); + } + /** * 保存动态表单信息 * @@ -314,6 +434,15 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF } else if (StringUtils.equals(FieldTypeEnum.JOIN.getValue(), dynamicFormFieldVO.getFieldType())) { tableColumnVO.setDataType(ColumnDataTypeEnum.CHAR.getDataType()); tableColumnVO.setColumnLength(36); + } else if (StringUtils.equals(FieldTypeEnum.LEFT_JOIN.getValue(), dynamicFormFieldVO.getFieldType())) { + tableColumnVO.setDataType(ColumnDataTypeEnum.VARCHAR.getDataType()); + tableColumnVO.setColumnLength(255); + } else if (StringUtils.equals(FieldTypeEnum.INNER_JOIN.getValue(), dynamicFormFieldVO.getFieldType())) { + tableColumnVO.setDataType(ColumnDataTypeEnum.VARCHAR.getDataType()); + tableColumnVO.setColumnLength(255); + } else if (StringUtils.equals(FieldTypeEnum.RIGHT_JOIN.getValue(), dynamicFormFieldVO.getFieldType())) { + tableColumnVO.setDataType(ColumnDataTypeEnum.VARCHAR.getDataType()); + tableColumnVO.setColumnLength(255); } return tableColumnVO; } diff --git a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/form/dynamicconfigform-mapper.xml b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/form/dynamicconfigform-mapper.xml index 7f31ad1..ff179a1 100644 --- a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/form/dynamicconfigform-mapper.xml +++ b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/config/form/dynamicconfigform-mapper.xml @@ -16,6 +16,11 @@ + + + + + @@ -33,6 +38,11 @@ field_sort, list_show, form_show, + join_table, + join_table_field, + join_table_sort, + join_table_list_show, + join_table_form_show, gmt_create, creator, gmt_modified, @@ -51,6 +61,11 @@ #{fieldSort}, #{listShow}, #{formShow}, + #{joinTable}, + #{joinTableField}, + #{joinTableSort}, + #{joinTableListShow}, + #{joinTableFormShow}, #{gmtCreate}, #{creator}, #{gmtModified}, @@ -111,6 +126,21 @@ form_show = #{formShow}, + + + join_table = #{joinTable}, + + + join_table_field = #{joinTableField}, + + + join_table_sort = #{joinTableSort}, + + + join_table_list_show = #{joinTableListShow}, + + + join_table_form_show = #{joinTableFormShow}, modifier = #{modifier}, gmt_modified = #{gmtModified} diff --git a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicdata-mapper.xml b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicdata-mapper.xml index 39bde7a..61f5f03 100644 --- a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicdata-mapper.xml +++ b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicdata-mapper.xml @@ -82,22 +82,49 @@ - GROUP_CONCAT(t${index + 1}.dictionary_name) ${item.fieldName}_dictionary_name, + GROUP_CONCAT(dt${index + 1}.dictionary_name) ${item.fieldName}_dictionary_name, + + + + + jt${index + 1}.${item} ${item}_jt${index + 1}, + + + + t1.${uuidField} FROM ${tableName} t1 LEFT JOIN - data_dictionary t${index + 1} + data_dictionary dt${index + 1} ON - FIND_IN_SET(t${index + 1}.dictionary_id, t1.${item.fieldName}) + FIND_IN_SET(dt${index + 1}.dictionary_id, t1.${item.fieldName}) AND - t${index + 1}.is_delete = 0 + dt${index + 1}.is_delete = 0 + + + + LEFT JOIN + + + INNER JOIN + + + RIGHT JOIN + + ${item.joinTable} jt${index + 1} + ON + t1.${item.fieldName} = jt${index + 1}.${item.joinTableField} + AND + jt${index + 1}.is_delete = 0 + + WHERE t1.is_delete = 0 GROUP BY @@ -105,6 +132,15 @@ t1.${item.fieldName} + + + + + jt${index + 1}.${item} + + + + diff --git a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicform-mapper.xml b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicform-mapper.xml index c8b69dc..6a1144f 100644 --- a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicform-mapper.xml +++ b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicform-mapper.xml @@ -15,6 +15,11 @@ + + + + + @@ -70,7 +75,7 @@ - SELECT * FROM @@ -78,7 +83,14 @@ WHERE is_delete = 0 AND - table_name = #{_parameter} + table_name = #{tableName} + + AND + field_name IN + + #{item} + + ORDER BY field_sort diff --git a/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/list.html b/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/list.html index 23c6c52..008b8dd 100644 --- a/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/list.html +++ b/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/list.html @@ -134,6 +134,30 @@ case 'join': value = '主联字段'; break; + case 'currentUser': + value = '当前用户'; + break; + case 'currentDepartment': + value = '当前组织'; + break; + case 'currentRole': + value = '当前角色'; + break; + case 'currentGroup': + value = '当前组'; + break; + case 'currentPosition': + value = '当前职位'; + break; + case 'leftJoin': + value = '左联表'; + break; + case 'innerJoin': + value = '内联表'; + break; + case 'rightJoin': + value = '右联表'; + break; default: value = '文本'; } diff --git a/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/save.html b/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/save.html index d470825..97881dc 100644 --- a/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/save.html +++ b/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/save.html @@ -9,6 +9,11 @@ +
@@ -42,7 +47,7 @@
- @@ -62,64 +67,99 @@ - - + + +
-
- -
- + -
- -
- - +
+
+ +
+ +
-
-
- -
- +
+ +
+ + +
-
-
- -
- +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
- -
-
-
- -
- - -
-
-
- -
- - +
@@ -185,6 +225,15 @@ } } }); + form.on('select(fieldType)', function(data) { + if(data.value === 'leftJoin' || data.value === 'innerJoin' || data.value === 'rightJoin') { + $('#normalFieldBox').hide(); + $('#joinFieldBox').show(); + } else { + $('#joinFieldBox').hide(); + $('#normalFieldBox').show(); + } + }); $(document.body).on('click', '#dictionaryName', function() { top.dialog.tree({ title: '绑定数据字典', diff --git a/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/update.html b/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/update.html index c4d16d4..c5b81c6 100644 --- a/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/update.html +++ b/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/update.html @@ -9,6 +9,11 @@ +
@@ -42,7 +47,7 @@
- @@ -57,42 +62,98 @@ + + + + + + + +
-
- -
- + -
- -
- - +
+
+ +
+ +
-
-
- -
- +
+ +
+ + +
-
-
- -
- +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
@@ -101,20 +162,6 @@
-
- -
- - -
-
-
- -
- - -
-