Browse Source

逻辑关键字校验

suochencheng 7 years ago
parent
commit
a0be42946c

+ 10 - 0
src/main/java/com/izouma/awesomeadmin/model/TableField.java

@@ -146,6 +146,8 @@ public class TableField {
 
 
     private String optionsValue;
     private String optionsValue;
 
 
+    private Boolean logicalKey;
+
 
 
     public void setId(Integer id) {
     public void setId(Integer id) {
         this.id = id;
         this.id = id;
@@ -370,5 +372,13 @@ public class TableField {
     public void setOptionsValue(String optionsValue) {
     public void setOptionsValue(String optionsValue) {
         this.optionsValue = optionsValue;
         this.optionsValue = optionsValue;
     }
     }
+
+    public Boolean getLogicalKey() {
+        return logicalKey;
+    }
+
+    public void setLogicalKey(Boolean logicalKey) {
+        this.logicalKey = logicalKey;
+    }
 }
 }
 
 

+ 2 - 3
src/main/java/com/izouma/awesomeadmin/util/DatabaseUtil.java

@@ -10,9 +10,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.List;
-import java.util.Map;
 
 
 /**
 /**
  * 数据源方法
  * 数据源方法
@@ -51,7 +49,7 @@ public class DatabaseUtil {
                 url = "jdbc:sqlserver://" + dataSourceInfo.getUrl() + ";DatabaseName=" + dataSourceInfo.getDatabaseName();
                 url = "jdbc:sqlserver://" + dataSourceInfo.getUrl() + ";DatabaseName=" + dataSourceInfo.getDatabaseName();
                 user = dataSourceInfo.getUsername();
                 user = dataSourceInfo.getUsername();
                 password = dataSourceInfo.getPassword();
                 password = dataSourceInfo.getPassword();
-                sql = "select * from sys.tables order by name";
+                sql = "select * from sysobjects where xtype='U' OR  xtype='V'  order by  xtype , name";
             }
             }
 
 
         }
         }
@@ -72,6 +70,7 @@ public class DatabaseUtil {
                     tables.add(rs.getString(1));
                     tables.add(rs.getString(1));
                 }
                 }
             }
             }
+
         } catch (SQLException e) {
         } catch (SQLException e) {
             e.printStackTrace();
             e.printStackTrace();
         } finally {
         } finally {

+ 47 - 1
src/main/resources/templates/FormTemplate.vm

@@ -272,12 +272,58 @@
             onSave() {
             onSave() {
                 this.${esc.d}refs.form.validate((valid) => {
                 this.${esc.d}refs.form.validate((valid) => {
                     if (valid) {
                     if (valid) {
-                        this.submit();
+                        this.logicalValidate();
                     } else {
                     } else {
                         return false;
                         return false;
                     }
                     }
                 });
                 });
             },
             },
+            logicalValidate() {
+                var data = JSON.parse(JSON.stringify(this.formData));
+
+                var logicalData = {
+                    #foreach($field in $model.fields)
+                    #if(${field.logicalKey})
+                            ${field.modelName}:data.${field.modelName},
+                    #end
+                    #end
+                }
+
+                if (JSON.stringify(logicalData) == '{}') {
+                    this.submit();
+                } else {
+                    this.${esc.d}http.get({
+                    url: '/${display.uncapitalize($model.className)}/getOne',
+                    data: logicalData
+                    }).then(res => {
+                    if (res.success) {
+
+                    var logicalFlag = true;
+
+                    if (res.data) {
+                    if (this.formData.id) {
+                    if (res.data.id != this.formData.id) {
+                    logicalFlag = false;
+                    }
+                    } else {
+                    logicalFlag = false;
+                    }
+
+                    }
+
+                    if (logicalFlag) {
+                    this.submit();
+                    } else {
+                    this.${esc.d}message.warning('逻辑关键字:'+'#foreach($field in $model.fields)#if(${field.logicalKey})${field.remark},#end#end'+'验证失败')
+                    }
+
+
+                    } else {
+                    this.${esc.d}message.warning('逻辑关键字:'+'#foreach($field in $model.fields)#if(${field.logicalKey})${field.remark},#end#end'+'验证失败')
+                    }
+                    });
+                }
+            },
             submit() {
             submit() {
                 var data = JSON.parse(JSON.stringify(this.formData));
                 var data = JSON.parse(JSON.stringify(this.formData));
                 this.${esc.d}http.post({
                 this.${esc.d}http.post({

+ 6 - 1
src/main/vue/src/pages/GenCode.vue

@@ -59,7 +59,7 @@
                 <el-tabs value="1" type="border-card">
                 <el-tabs value="1" type="border-card">
                     <el-tab-pane label="字段" name="1">
                     <el-tab-pane label="字段" name="1">
                         <el-table :data="fields">
                         <el-table :data="fields">
-                            <el-table-column prop="name" label="字段名" align="center">
+                            <el-table-column prop="name" label="字段名" min-width="100"  align="center">
                                 <template slot-scope="{row}">
                                 <template slot-scope="{row}">
                                     <el-input v-model="row.name"></el-input>
                                     <el-input v-model="row.name"></el-input>
                                 </template>
                                 </template>
@@ -170,6 +170,11 @@
                         <el-table :data="fields">
                         <el-table :data="fields">
                             <el-table-column prop="name" label="字段" align="center">
                             <el-table-column prop="name" label="字段" align="center">
                             </el-table-column>
                             </el-table-column>
+                            <el-table-column prop="logicalKey" label="逻辑关键字"  align="center">
+                                <template slot-scope="{row}">
+                                    <el-checkbox v-model="row.logicalKey"></el-checkbox>
+                                </template>
+                            </el-table-column>
                             <el-table-column prop="required" label="必填" width="50" align="center">
                             <el-table-column prop="required" label="必填" width="50" align="center">
                                 <template slot-scope="{row}">
                                 <template slot-scope="{row}">
                                     <el-checkbox v-model="row.required"></el-checkbox>
                                     <el-checkbox v-model="row.required"></el-checkbox>

+ 163 - 138
src/main/vue/src/pages/TestAaa.vue

@@ -1,60 +1,42 @@
 <template>
 <template>
     <div>
     <div>
-        <el-form :model="formData" :rules="rules" ref="form" label-width="120px" label-position="right" size="small"
-                 style="max-width: 500px;">
-                                                                                                                                                                                                                                                                 <el-form-item prop="imageUrl" label="图片">
-                 <single-upload v-model="formData.imageUrl" :disabled="'imageUrl'==subColumn"></single-upload>
-             </el-form-item>
-                                                                                                                                                                                                                                                                                                        <el-form-item prop="testName" label="名称">
+        <el-form :model="formData" :rules="rules" ref="form" label-width="120px" label-position="right" size="small" style="max-width: 500px;">
+            <el-form-item prop="imageUrl" label="图片">
+                <single-upload v-model="formData.imageUrl" :disabled="'imageUrl'==subColumn"></single-upload>
+            </el-form-item>
+            <el-form-item prop="testName" label="名称">
                 <template>
                 <template>
-                    <el-select v-model="formData.testName" clearable  placeholder="请选择" :disabled="'testName'==subColumn">
-                        <el-option
-                                v-for="item in testNameOptions"
-                                :key="item.value"
-                                :label="item.label"
-                                :value="item.value">
+                    <el-select v-model="formData.testName" clearable placeholder="请选择" :disabled="'testName'==subColumn">
+                        <el-option v-for="item in testNameOptions" :key="item.value" :label="item.label" :value="item.value">
                         </el-option>
                         </el-option>
                     </el-select>
                     </el-select>
                 </template>
                 </template>
             </el-form-item>
             </el-form-item>
-                                                                                                                                                                                                                                                                                                                                                <el-form-item prop="remark" label="嗯嗯">
+            <el-form-item prop="remark" label="嗯嗯">
                 <template>
                 <template>
-                    <el-select v-model="formData.remark" clearable  placeholder="请选择" :disabled="'remark'==subColumn">
-                        <el-option
-                                v-for="item in remarkOptions"
-                                :key="item.value"
-                                :label="item.label"
-                                :value="item.value">
+                    <el-select v-model="formData.remark" clearable placeholder="请选择" :disabled="'remark'==subColumn">
+                        <el-option v-for="item in remarkOptions" :key="item.value" :label="item.label" :value="item.value">
                         </el-option>
                         </el-option>
                     </el-select>
                     </el-select>
                 </template>
                 </template>
             </el-form-item>
             </el-form-item>
-                                                                                                                                                                                                                                                                                                                                                                    <el-form-item prop="multiSelect" label="多选">
+            <el-form-item prop="multiSelect" label="多选">
                 <template>
                 <template>
                     <el-select v-model="formData.multiSelect" multiple clearable placeholder="请选择" :disabled="'multiSelect'==subColumn">
                     <el-select v-model="formData.multiSelect" multiple clearable placeholder="请选择" :disabled="'multiSelect'==subColumn">
-                        <el-option
-                                v-for="item in multiSelectOptions"
-                                :key="item.value"
-                                :label="item.label"
-                                :value="item.value">
+                        <el-option v-for="item in multiSelectOptions" :key="item.value" :label="item.label" :value="item.value">
                         </el-option>
                         </el-option>
                     </el-select>
                     </el-select>
                 </template>
                 </template>
             </el-form-item>
             </el-form-item>
-                                                                                                                                                                                                                                                                                    <el-form-item prop="testTime" label="时间">
+            <el-form-item prop="testTime" label="时间">
                 <template>
                 <template>
                     <div class="block">
                     <div class="block">
-                        <el-date-picker
-                                v-model="formData.testTime"
-                                type="date"
-                                value-format="timestamp"
-                                placeholder="选择日期"
-                                :disabled="'testTime'==subColumn">
+                        <el-date-picker v-model="formData.testTime" type="date" value-format="timestamp" placeholder="选择日期" :disabled="'testTime'==subColumn">
                         </el-date-picker>
                         </el-date-picker>
                     </div>
                     </div>
                 </template>
                 </template>
             </el-form-item>
             </el-form-item>
-                                                                                                                                                                                                                                                <el-form-item>
+            <el-form-item>
                 <el-button @click="onSave" :loading="$store.state.fetchingData" type="primary">保存</el-button>
                 <el-button @click="onSave" :loading="$store.state.fetchingData" type="primary">保存</el-button>
                 <el-button @click="onDelete" v-if="formData.id" type="danger">删除</el-button>
                 <el-button @click="onDelete" v-if="formData.id" type="danger">删除</el-button>
                 <el-button @click="$router.go(-1)">取消</el-button>
                 <el-button @click="$router.go(-1)">取消</el-button>
@@ -63,144 +45,187 @@
     </div>
     </div>
 </template>
 </template>
 <script>
 <script>
-    import formValidator from '../formValidator'
+import formValidator from '../formValidator'
 
 
-    export default {
-        created() {
-            if (this.$route.query.column) {
-                this.subColumn = this.$route.query.column.split(',')[1];
-                this.subValue = this.$route.query.column.split(',')[0];
-            }
+export default {
+    created() {
+        if (this.$route.query.column) {
+            this.subColumn = this.$route.query.column.split(',')[1];
+            this.subValue = this.$route.query.column.split(',')[0];
+        }
 
 
-            if (this.$route.query.id) {
-                this.$http.get({
-                    url: '/testAaa/getOne',
-                    data: {
-                        id: this.$route.query.id
+        if (this.$route.query.id) {
+            this.$http.get({
+                url: '/testAaa/getOne',
+                data: {
+                    id: this.$route.query.id
+                }
+            }).then(res => {
+                if (res.success) {
+
+
+                    if (res.data.multiSelect) {
+                        res.data.multiSelect = res.data.multiSelect.split(',');
+                    } else {
+                        res.data.multiSelect = [];
                     }
                     }
-                }).then(res => {
-                    if (res.success) {
 
 
-                                                                                                                                                                                                                                                                                                                        
-                                if(res.data.multiSelect){
-                                    res.data.multiSelect = res.data.multiSelect.split(',');
-                                }else{
-                                    res.data.multiSelect = [];
-                                }
 
 
-                                                                                                        
-                        this.formData = res.data;
+                    this.formData = res.data;
 
 
                     if (this.$route.query.column) {
                     if (this.$route.query.column) {
                         this.formData[this.subColumn] = this.subValue;
                         this.formData[this.subColumn] = this.subValue;
                     }
                     }
-                    }
-                })
-            }else {
-                if (this.$route.query.column) {
-                    this.formData[this.subColumn] = this.subValue;
                 }
                 }
+            })
+        } else {
+            if (this.$route.query.column) {
+                this.formData[this.subColumn] = this.subValue;
             }
             }
+        }
 
 
-                                                                                                                                                                                                    
 
 
 
 
-                        this.$http.get({
-                        url:'/testBbb/all'
-                        }).then(res => {
-                        if (res.success) {
 
 
-                        if (res.data.length > 0) {
-                        res.data.forEach(item => {
-                        this.remarkOptions.push({label: item.nameAaa, value:item.nameAaa});
-                        })
-                        }
-                        }
-                        });
-                                                                                    
+        this.$http.get({
+            url: '/testBbb/all'
+        }).then(res => {
+            if (res.success) {
 
 
+                if (res.data.length > 0) {
+                    res.data.forEach(item => {
+                        this.remarkOptions.push({ label: item.nameAaa, value: item.nameAaa });
+                    })
+                }
+            }
+        });
 
 
-                        this.$http.get({
-                        url:'/testBbb/all'
-                        }).then(res => {
-                        if (res.success) {
 
 
-                        if (res.data.length > 0) {
-                        res.data.forEach(item => {
-                        this.multiSelectOptions.push({label: item.nameCcc, value:item.nameCcc});
-                        })
-                        }
-                        }
-                        });
-                                                                                    },
-        data() {
-            return {
-                saving: false,
-                formData: {},
-                rules: {
-                                                                                                                                    testName:
+
+        this.$http.get({
+            url: '/testBbb/all'
+        }).then(res => {
+            if (res.success) {
+
+                if (res.data.length > 0) {
+                    res.data.forEach(item => {
+                        this.multiSelectOptions.push({ label: item.nameCcc, value: item.nameCcc });
+                    })
+                }
+            }
+        });
+    },
+    data() {
+        return {
+            saving: false,
+            formData: {},
+            rules: {
+                testName:
                     [
                     [
-                                                {required: true, message: '请输入 名称', trigger: 'blur'},
-                                                                    ],
-                                                                remark:
+                        { required: true, message: '请输入 名称', trigger: 'blur' },
+                    ],
+                remark:
                     [
                     [
-                                                {required: true, message: '请输入 嗯嗯', trigger: 'blur'},
-                                                                    ],
-                                                                multiSelect:
+                        { required: true, message: '请输入 嗯嗯', trigger: 'blur' },
+                    ],
+                multiSelect:
                     [
                     [
-                                                {required: true, message: '请输入 多选', trigger: 'blur'},
-                                                                    ],
-                                                                },
-                                                testNameOptions:[{ label: '??', value: '??' }, { label: '??', value: '??' },{ label: '??', value: '??' }],
-                                            remarkOptions:[],
-                                            multiSelectOptions:[],
-                                        subColumn: '',
+                        { required: true, message: '请输入 多选', trigger: 'blur' },
+                    ],
+            },
+            testNameOptions: [{ label: 'A', value: 'A' }, { label: 'B', value: 'B' }, { label: 'C', value: 'C' }],
+            remarkOptions: [],
+            multiSelectOptions: [],
+            subColumn: '',
             subValue: '',
             subValue: '',
         }
         }
+    },
+    methods: {
+        onSave() {
+            this.$refs.form.validate((valid) => {
+                if (valid) {
+                    this.logicalValidate();
+                } else {
+                    return false;
+                }
+            });
         },
         },
-        methods: {
-            onSave() {
-                this.$refs.form.validate((valid) => {
-                    if (valid) {
-                        this.submit();
-                    } else {
-                        return false;
-                    }
-                });
-            },
-            submit() {
-                var data = JSON.parse(JSON.stringify(this.formData));
-                this.$http.post({
-                    url: this.formData.id ? '/testAaa/update' : '/testAaa/save',
-                    data: data
+        logicalValidate() {
+            var data = JSON.parse(JSON.stringify(this.formData));
+
+            var logicalData = {
+                testName: data.testName,
+                remark: data.remark,
+            }
+
+            if (JSON.stringify(logicalData) == '{}') {
+                this.submit();
+            } else {
+                this.$http.get({
+                    url: '/testAaa/getOne',
+                    data: logicalData
                 }).then(res => {
                 }).then(res => {
                     if (res.success) {
                     if (res.success) {
-                        this.$message.success('成功');
-                        this.$router.go(-1);
+
+                        var logicalFlag = true;
+
+                        if (res.data) {
+                            if (this.formData.id) {
+                                if (res.data.id != this.formData.id) {
+                                    logicalFlag = false;
+                                }
+                            } else {
+                                logicalFlag = false;
+                            }
+
+                        }
+
+                        if (logicalFlag) {
+                            this.submit();
+                        } else {
+                            this.$message.warning('逻辑关键字:' + '名称,嗯嗯,' + '验证失败')
+                        }
+
+
                     } else {
                     } else {
-                        this.$message.warning('失败')
+                        this.$message.warning('逻辑关键字:' + '名称嗯嗯' + '验证失败')
                     }
                     }
                 });
                 });
-            },
-            onDelete() {
-                this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' }).then(() => {
-                    return this.$http.post({
+            }
+        },
+        submit() {
+            var data = JSON.parse(JSON.stringify(this.formData));
+            this.$http.post({
+                url: this.formData.id ? '/testAaa/update' : '/testAaa/save',
+                data: data
+            }).then(res => {
+                if (res.success) {
+                    this.$message.success('成功');
+                    this.$router.go(-1);
+                } else {
+                    this.$message.warning('失败')
+                }
+            });
+        },
+        onDelete() {
+            this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' }).then(() => {
+                return this.$http.post({
                     url: '/testAaa/del',
                     url: '/testAaa/del',
                     data: { id: this.formData.id }
                     data: { id: this.formData.id }
-                    })
-                }).then(() => {
-                    this.$message.success('删除成功');
-                    this.$router.go(-1);
-                }).catch(action => {
-                    if (action === 'cancel') {
-                        this.$message.info('删除取消');
-                    } else {
-                        this.$message.error('删除失败');
-                    }
                 })
                 })
-            },
-        }
+            }).then(() => {
+                this.$message.success('删除成功');
+                this.$router.go(-1);
+            }).catch(action => {
+                if (action === 'cancel') {
+                    this.$message.info('删除取消');
+                } else {
+                    this.$message.error('删除失败');
+                }
+            })
+        },
     }
     }
+}
 </script>
 </script>
 <style lang="less" scoped>
 <style lang="less" scoped>
 </style>
 </style>