gaocr 3 жил өмнө
parent
commit
fcb0d2f396

+ 11 - 0
src/main/java/com/goer/project/model/modelEntity/controller/ModelEntityController.java

@@ -11,6 +11,7 @@ import com.goer.project.model.modelDbs.domain.ModelDbs;
 import com.goer.project.model.modelDbs.service.IModelDbsService;
 import com.goer.project.model.modelProject.domain.ModelProject;
 import com.goer.project.model.modelProject.service.IModelProjectService;
+import com.goer.project.system.user.domain.User;
 import lombok.SneakyThrows;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -270,4 +271,14 @@ public class ModelEntityController extends BaseController
 
         return toAjax(modelEntityService.importTable(modelEntity));
     }
+
+    /**
+     * 校验表逻辑名唯一性
+     */
+    @PostMapping("/checkEntityCodeUnique")
+    @ResponseBody
+    public String checkEntityCodeUnique(ModelEntity modelEntity)
+    {
+        return modelEntityService.checkEntityCodeUnique(modelEntity);
+    }
 }

+ 2 - 0
src/main/java/com/goer/project/model/modelEntity/mapper/ModelEntityMapper.java

@@ -102,4 +102,6 @@ public interface ModelEntityMapper
     public List<ModelEntity> selectModelEntityWithFieldList(ModelEntity modelEntity);
 
     public int saveModelFieldVersion(ModelEntity modelEntity);
+
+    public ModelEntity checkEntityCodeUnique(ModelEntity modelEntity);
 }

+ 3 - 0
src/main/java/com/goer/project/model/modelEntity/service/IModelEntityService.java

@@ -70,4 +70,7 @@ public interface IModelEntityService
     public int sort(ModelEntity modelEntity);
 
     public int importTable(ModelEntity modelEntity);
+
+    public String checkEntityCodeUnique(ModelEntity modelEntity);
+
 }

+ 16 - 0
src/main/java/com/goer/project/model/modelEntity/service/impl/ModelEntityServiceImpl.java

@@ -12,6 +12,7 @@ import com.goer.common.command.AbstractDBCommand;
 import com.goer.common.command.ExecResult;
 import com.goer.common.command.impl.DBReverseGetTableDDLImpl;
 import com.goer.common.utils.DateUtils;
+import com.goer.common.utils.StringUtils;
 import com.goer.common.utils.fisok.raw.kit.JSONKit;
 import com.goer.project.model.dataType.domain.DataType;
 import com.goer.project.model.dataType.mapper.DataTypeMapper;
@@ -269,4 +270,19 @@ public class ModelEntityServiceImpl implements IModelEntityService
 
         return ret;
     }
+
+    public String checkEntityCodeUnique(ModelEntity modelEntity) {
+        Long entityId = StringUtils.isNull(modelEntity.getId()) ? -1L : modelEntity.getId();
+        ModelEntity info = null;
+        if(StringUtils.isNotEmpty(modelEntity.getEntityCode())) {
+            info = modelEntityMapper.checkEntityCodeUnique(modelEntity);
+        }
+        if (StringUtils.isNull(info)) {
+            return "0";
+        }
+        if(info.getId().longValue() != entityId.longValue()) {
+            return "1";
+        }
+        return "0";
+    }
 }

+ 10 - 0
src/main/java/com/goer/project/model/modelField/controller/ModelFieldController.java

@@ -219,4 +219,14 @@ public class ModelFieldController extends BaseController
         modelField.setUpdateTime(new Date());
         return toAjax(modelFieldService.sort(modelField));
     }
+
+    /**
+     * 校验表字段名唯一性
+     */
+    @PostMapping("/checkFieldCodeUnique")
+    @ResponseBody
+    public String checkFieldCodeUnique(ModelField modelField)
+    {
+        return modelFieldService.checkFieldCodeUnique(modelField);
+    }
 }

+ 3 - 0
src/main/java/com/goer/project/model/modelField/mapper/ModelFieldMapper.java

@@ -1,6 +1,7 @@
 package com.goer.project.model.modelField.mapper;
 
 import java.util.List;
+
 import com.goer.project.model.modelField.domain.ModelField;
 import org.springframework.stereotype.Repository;
 
@@ -91,4 +92,6 @@ public interface ModelFieldMapper
      * @return
      */
     int updateList(List<ModelField> list);
+
+    public ModelField checkFieldCodeUnique(ModelField modelField);
 }

+ 2 - 0
src/main/java/com/goer/project/model/modelField/service/IModelFieldService.java

@@ -66,4 +66,6 @@ public interface IModelFieldService
      * @return
      */
     public int sort(ModelField modelField);
+
+    public String checkFieldCodeUnique(ModelField modelField);
 }

+ 18 - 0
src/main/java/com/goer/project/model/modelField/service/impl/ModelFieldServiceImpl.java

@@ -3,7 +3,9 @@ package com.goer.project.model.modelField.service.impl;
 import java.util.Date;
 import java.util.List;
 import com.goer.common.utils.DateUtils;
+import com.goer.common.utils.StringUtils;
 import com.goer.common.utils.security.ShiroUtils;
+import com.goer.project.model.modelEntity.domain.ModelEntity;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.goer.project.model.modelField.mapper.ModelFieldMapper;
@@ -132,4 +134,20 @@ public class ModelFieldServiceImpl implements IModelFieldService
         }
         return result;
     }
+
+    @Override
+    public String checkFieldCodeUnique(ModelField modelField) {
+        Long fieldId = StringUtils.isNull(modelField.getId()) ? -1L : modelField.getId();
+        ModelField info = null;
+        if(StringUtils.isNotEmpty(modelField.getFieldCode())) {
+            info = modelFieldMapper.checkFieldCodeUnique(modelField);
+        }
+        if (StringUtils.isNull(info)) {
+            return "0";
+        }
+        if(info.getId().longValue() != fieldId.longValue()) {
+            return "1";
+        }
+        return "0";
+    }
 }

+ 5 - 0
src/main/resources/mybatis/model/ModelEntityMapper.xml

@@ -221,4 +221,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         order by me.entity_sort,mf.field_sort
     </select>
 
+    <select id="checkEntityCodeUnique" parameterType="ModelEntity" resultMap="ModelEntityResult">
+        <include refid="selectModelEntityVo"/>
+        where project_id = #{projectId} and entity_code = #{entityCode} and version_id = 0
+        limit 1
+    </select>
 </mapper>

+ 6 - 0
src/main/resources/mybatis/model/ModelFieldMapper.xml

@@ -163,4 +163,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             where id = #{item.id}
         </foreach>
     </update>
+
+    <select id="checkFieldCodeUnique" parameterType="ModelField" resultMap="ModelFieldResult">
+        <include refid="selectModelFieldVo"/>
+        where project_id = #{projectId} and entity_id = #{entityId} and field_code = #{fieldCode} and version_id = 0
+        limit 1
+    </select>
 </mapper>

+ 34 - 3
src/main/resources/templates/model/modelEntity/add.html

@@ -10,19 +10,19 @@
         <div class="form-group">
             <label class="col-sm-3 control-label is-required">表名称:</label>
             <div class="col-sm-8">
-                <input name="entityName" class="form-control" type="text" required>
+                <input id="entityName" name="entityName" placeholder="商品表" class="form-control" type="text" required>
             </div>
         </div>
         <div class="form-group">
             <label class="col-sm-3 control-label is-required">表逻辑名:</label>
             <div class="col-sm-8">
-                <input name="entityCode" class="form-control" type="text" required>
+                <input id="entityCode" name="entityCode" placeholder="m_product" class="form-control" type="text" required>
             </div>
         </div>
         <div class="form-group">
             <label class="col-sm-3 control-label">描述:</label>
             <div class="col-sm-8">
-                <textarea name="remark" class="form-control"></textarea>
+                <textarea id="remark" name="remark" class="form-control"></textarea>
             </div>
         </div>
     </form>
@@ -31,6 +31,37 @@
 <script th:inline="javascript">
     var prefix = ctx + "model/modelEntity"
     $("#form-modelEntity-add").validate({
+        onkeyup: false,
+        rules:{
+            entityCode:{
+                maxlength: 50,
+                remote: {
+                    url: prefix + "/checkEntityCodeUnique",
+                    type: "post",
+                    dataType: "json",
+                    data: {
+                        "projectId":$("#projectId").val(),
+                        "entityCode": function() {
+                            return $.common.trim($("#entityCode").val());
+                        }
+                    },
+                    dataFilter: function(data, type) {
+                        return $.validate.unique(data);
+                    }
+                }
+            },
+            entityName:{
+                maxlength: 25
+            },
+            remark:{
+                maxlength: 100
+            },
+        },
+        messages: {
+            "entityCode": {
+                remote: "数据表已经存在"
+            },
+        },
         focusCleanup: true
     });
 

+ 33 - 0
src/main/resources/templates/model/modelEntity/edit.html

@@ -7,6 +7,7 @@
     <div class="wrapper wrapper-content animated fadeInRight ibox-content">
         <form class="form-horizontal m" id="form-modelEntity-edit" th:object="${modelEntity}">
             <input name="id" th:field="*{id}" type="hidden">
+            <input type="hidden" id="projectId" name="projectId" th:value="${modelEntity.projectId}">
             <div class="form-group">
                 <label class="col-sm-3 control-label is-required">表名称:</label>
                 <div class="col-sm-8">
@@ -31,6 +32,38 @@
     <script th:inline="javascript">
         var prefix = ctx + "model/modelEntity";
         $("#form-modelEntity-edit").validate({
+            onkeyup: false,
+            rules:{
+                entityCode:{
+                    maxlength: 50,
+                    remote: {
+                        url: prefix + "/checkEntityCodeUnique",
+                        type: "post",
+                        dataType: "json",
+                        data: {
+                            "id":$("#id").val(),
+                            "projectId":$("#projectId").val(),
+                            "entityCode": function() {
+                                return $.common.trim($("#entityCode").val());
+                            }
+                        },
+                        dataFilter: function(data, type) {
+                            return $.validate.unique(data);
+                        }
+                    }
+                },
+                entityName:{
+                    maxlength: 25
+                },
+                remark:{
+                    maxlength: 100
+                },
+            },
+            messages: {
+                "entityCode": {
+                    remote: "数据表已经存在"
+                },
+            },
             focusCleanup: true
         });
 

+ 40 - 5
src/main/resources/templates/model/modelField/add.html

@@ -12,19 +12,19 @@
             <div class="form-group">
                 <label class="col-sm-3 control-label is-required">字段名:</label>
                 <div class="col-sm-8">
-                    <input name="fieldName" class="form-control" type="text" required>
+                    <input id="fieldName" name="fieldName" placeholder="商品名称" class="form-control" type="text" required>
                 </div>
             </div>
             <div class="form-group">    
                 <label class="col-sm-3 control-label is-required">逻辑名:</label>
                 <div class="col-sm-8">
-                    <input name="fieldCode" class="form-control" type="text" required>
+                    <input id="fieldCode" name="fieldCode" placeholder="productName" class="form-control" type="text" required>
                 </div>
             </div>
             <div class="form-group">
                 <label class="col-sm-3 control-label is-required">类型:</label>
                 <div class="col-sm-8">
-                    <select name="fieldType" class="form-control m-b">
+                    <select id="fieldType" name="fieldType" class="form-control m-b">
                         <option th:each="dt : ${dataTypeList}" th:text="${dt.dataTypeName}" th:value="${dt.dataTypeCode}"></option>
                     </select>
                 </div>
@@ -59,13 +59,13 @@
             <div class="form-group">    
                 <label class="col-sm-3 control-label">默认值:</label>
                 <div class="col-sm-8">
-                    <input name="defaultValue" class="form-control" type="text" >
+                    <input id="defaultValue" name="defaultValue" class="form-control" type="text" >
                 </div>
             </div>
             <div class="form-group">
                 <label class="col-sm-3 control-label">备注:</label>
                 <div class="col-sm-8">
-                    <textarea name="remark" class="form-control" ></textarea>
+                    <textarea id="remark" name="remark" class="form-control" ></textarea>
                 </div>
             </div>
         </form>
@@ -74,6 +74,41 @@
     <script th:inline="javascript">
         var prefix = ctx + "model/modelField"
         $("#form-modelField-add").validate({
+            onkeyup: false,
+            rules:{
+                fieldCode:{
+                    maxlength: 50,
+                    remote: {
+                        url: prefix + "/checkFieldCodeUnique",
+                        type: "post",
+                        dataType: "json",
+                        data: {
+                            "projectId":$("#projectId").val(),
+                            "entityId":$("#entityId").val(),
+                            "fieldCode": function() {
+                                return $.common.trim($("#fieldCode").val());
+                            }
+                        },
+                        dataFilter: function(data, type) {
+                            return $.validate.unique(data);
+                        }
+                    }
+                },
+                fieldName:{
+                    maxlength: 25
+                },
+                defaultValue:{
+                    maxlength: 8
+                },
+                remark:{
+                    maxlength: 100
+                },
+            },
+            messages: {
+                "fieldCode": {
+                    remote: "字段已经存在"
+                },
+            },
             focusCleanup: true
         });
 

+ 44 - 5
src/main/resources/templates/model/modelField/edit.html

@@ -6,17 +6,20 @@
 <body class="white-bg">
     <div class="wrapper wrapper-content animated fadeInRight ibox-content">
         <form class="form-horizontal m" id="form-modelField-edit" th:object="${modelField}">
-            <input name="id" th:field="*{id}" type="hidden">
+            <input id="id" name="id" th:field="*{id}" type="hidden">
+            <input type="hidden" id="projectId" name="projectId" th:value="*{projectId}">
+            <input type="hidden" id="entityId" name="entityId" th:value="*{entityId}">
+
             <div class="form-group">
                 <label class="col-sm-3 control-label is-required">字段名:</label>
                 <div class="col-sm-8">
-                    <input name="fieldName" th:field="*{fieldName}" class="form-control" type="text" required>
+                    <input id="fieldName" name="fieldName" th:field="*{fieldName}" class="form-control" type="text" required>
                 </div>
             </div>
             <div class="form-group">    
                 <label class="col-sm-3 control-label is-required">逻辑名:</label>
                 <div class="col-sm-8">
-                    <input name="fieldCode" th:field="*{fieldCode}" class="form-control" type="text" required>
+                    <input id="fieldCode" name="fieldCode" th:field="*{fieldCode}" class="form-control" type="text" required>
                 </div>
             </div>
             <div class="form-group">
@@ -57,13 +60,13 @@
             <div class="form-group">    
                 <label class="col-sm-3 control-label">默认值:</label>
                 <div class="col-sm-8">
-                    <input name="defaultValue" th:field="*{defaultValue}" class="form-control" type="text">
+                    <input id="defaultValue" name="defaultValue" th:field="*{defaultValue}" class="form-control" type="text">
                 </div>
             </div>
             <div class="form-group">    
                 <label class="col-sm-3 control-label">备注:</label>
                 <div class="col-sm-8">
-                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
+                    <textarea id="remark" name="remark" class="form-control">[[*{remark}]]</textarea>
                 </div>
             </div>
         </form>
@@ -72,6 +75,42 @@
     <script th:inline="javascript">
         var prefix = ctx + "model/modelField";
         $("#form-modelField-edit").validate({
+            onkeyup: false,
+            rules:{
+                fieldCode:{
+                    maxlength: 50,
+                    remote: {
+                        url: prefix + "/checkFieldCodeUnique",
+                        type: "post",
+                        dataType: "json",
+                        data: {
+                            "id":$("#id").val(),
+                            "projectId":$("#projectId").val(),
+                            "entityId":$("#entityId").val(),
+                            "fieldCode": function() {
+                                return $.common.trim($("#fieldCode").val());
+                            }
+                        },
+                        dataFilter: function(data, type) {
+                            return $.validate.unique(data);
+                        }
+                    }
+                },
+                fieldName:{
+                    maxlength: 25
+                },
+                defaultValue:{
+                    maxlength: 8
+                },
+                remark:{
+                    maxlength: 100
+                },
+            },
+            messages: {
+                "fieldCode": {
+                    remote: "字段已经存在"
+                },
+            },
             focusCleanup: true
         });