suochencheng пре 7 година
родитељ
комит
d7dba0ba85

+ 74 - 2
src/main/java/com/izouma/awesomeadmin/dao/TestAaaMapper.xml

@@ -96,10 +96,47 @@
             </if>
                   <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
              <trim prefix="and (" suffix=")" prefixOverrides="OR" >
-                                                                                                                                                                OR  test_name LIKE concat('%',#{record.searchKey},'%')
+                                                                                               OR  del_flag LIKE concat('%',#{record.searchKey},'%')
+                                                                                                    OR  test_name LIKE concat('%',#{record.searchKey},'%')
                                                                                                     OR  remark LIKE concat('%',#{record.searchKey},'%')
                                                              </trim>
          </if>
+
+            <if test="record.advancedQuery != null and !&quot;&quot;.equals(record.advancedQuery)">
+                <foreach item="item" index="index" collection="record.advancedQuery.split('_;')">
+                    <choose>
+                        <when test="item.indexOf('like') != -1">
+                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                                <if test="detailIndex == 3">
+                                    concat('%',#{itemDetail},'%')
+                                </if>
+
+                                <if test="detailIndex &lt; 3">
+                                    ${itemDetail}
+                                </if>
+
+                            </foreach>
+                        </when>
+                        <otherwise>
+                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                                <if test="detailIndex == 3">
+                                    #{itemDetail}
+                                </if>
+
+                                <if test="detailIndex &lt; 3">
+                                    ${itemDetail}
+                                </if>
+
+                            </foreach>
+                        </otherwise>
+                    </choose>
+
+
+                </foreach>
+
+
+            </if>
+
         </where>
         order by id desc
     </select>
@@ -121,10 +158,45 @@
             </if>
                     <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                 <trim prefix="and (" suffix=")" prefixOverrides="OR" >
-                                                                                                                                                                                                                                                OR  test_name LIKE concat('%',#{searchKey},'%')
+                                                                                                                                                OR  del_flag LIKE concat('%',#{searchKey},'%')
+                                                                                                                                                        OR  test_name LIKE concat('%',#{searchKey},'%')
                                                                                                                                                         OR  remark LIKE concat('%',#{searchKey},'%')
                                                                                         </trim>
             </if>
+<if test="advancedQuery != null and !&quot;&quot;.equals(advancedQuery)">
+    <foreach item="item" index="index" collection="advancedQuery.split('_;')">
+        <choose>
+            <when test="item.indexOf('like') != -1">
+                <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                    <if test="detailIndex == 3">
+                        concat('%',#{itemDetail},'%')
+                    </if>
+
+                    <if test="detailIndex &lt; 3">
+                        ${itemDetail}
+                    </if>
+
+                </foreach>
+            </when>
+            <otherwise>
+                <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                    <if test="detailIndex == 3">
+                        #{itemDetail}
+                    </if>
+
+                    <if test="detailIndex &lt; 3">
+                        ${itemDetail}
+                    </if>
+
+                </foreach>
+            </otherwise>
+        </choose>
+
+
+    </foreach>
+
+
+</if>
         </where>
         order by id desc
     </select>

+ 16 - 3
src/main/java/com/izouma/awesomeadmin/model/TestAaa.java

@@ -8,18 +8,23 @@ import com.fasterxml.jackson.annotation.JsonInclude;
 @JsonAutoDetect
 @JsonInclude(JsonInclude.Include.NON_NULL)
 public class TestAaa{
-    private Integer id;
+    private String id;
     private String delFlag;
     private String testName;
     private String remark;
 
 private String searchKey;
 
-    public Integer getId(){
+/**
+* and,test_name,like,value;or,remark,=,123
+*/
+private String advancedQuery;
+
+    public String getId(){
         return this.id;
     }
 
-    public void setId(Integer id){
+    public void setId(String id){
         this.id = id;
     }
     public String getDelFlag(){
@@ -52,5 +57,13 @@ public void setSearchKey(String searchKey) {
     this.searchKey = searchKey;
 }
 
+public String getAdvancedQuery() {
+    return advancedQuery;
+}
+
+public void setAdvancedQuery(String advancedQuery) {
+    this.advancedQuery = advancedQuery;
+}
+
 }
 

+ 48 - 0
src/main/java/test/com/izouma/admintemplate/datasource/SQLServiceTest.java

@@ -0,0 +1,48 @@
+package test.com.izouma.admintemplate.datasource;
+
+
+import com.izouma.awesomeadmin.datasource.DataService;
+import com.izouma.awesomeadmin.dto.Page;
+import com.izouma.awesomeadmin.model.SqlServerTest;
+import com.izouma.awesomeadmin.model.SuperUser;
+import com.izouma.awesomeadmin.model.TestAaa;
+import com.izouma.awesomeadmin.model.Zouma;
+import com.izouma.awesomeadmin.service.SuperUserService;
+import com.izouma.awesomeadmin.service.TestAaaService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.List;
+
+/**
+ * 配置spring和junit整合,junit启动时加载springIOC容器
+ * spring-test,junit
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration({"classpath:spring/applicationContext.xml"})
+public class SQLServiceTest {
+
+    @Autowired
+    TestAaaService testAaaService;
+
+
+    @Test
+    public void test() {
+
+        TestAaa testAaa = new TestAaa();
+        testAaa.setAdvancedQuery("and,test_name,like,张;or,remark,>,23是");
+        Page page = new Page();
+
+        List<TestAaa> testAaaList = testAaaService.getTestAaaByPage(page, testAaa);
+
+        System.out.println(testAaaList);
+    }
+
+
+}
+
+
+

+ 103 - 2
src/main/resources/templates/ListTemplate.vm

@@ -17,7 +17,8 @@
                         value="item2">
                 </el-option>
             </el-select>
-
+            <el-button @click="showAdvancedQueryDialog = !showAdvancedQueryDialog" type="primary" size="small" icon="el-icon-search" class="filter-item">高级查询
+            </el-button>
             <el-button @click="getData" type="primary" size="small" icon="el-icon-search" class="filter-item">搜索
             </el-button>
             <el-button @click="${esc.d}router.push('/${display.uncapitalize($model.className)}')" type="primary" size="small" icon="el-icon-edit"
@@ -88,6 +89,53 @@
                     :total="totalNumber">
             </el-pagination>
         </div>
+        <el-dialog title="高级查询" :visible.sync="showAdvancedQueryDialog">
+            <el-button @click="addField" type="text" icon="el-icon-plus">添加</el-button>
+            <el-table :data="advancedQueryFields">
+
+                <el-table-column prop="link" label="链接符" align="center">
+                    <template slot-scope="{row}">
+                        <el-select placeholder="链接" size="small" v-model="row.link" class="filter-item">
+                            <el-option label="AND" value="AND">
+                            </el-option>
+                            <el-option label="OR" value="OR">
+                            </el-option>
+                        </el-select>
+                    </template>
+                </el-table-column>
+                <el-table-column prop="name" label="字段" align="center">
+                    <template slot-scope="{row}">
+                        <el-select v-model="row.name">
+
+                            <el-option v-for="item in advancedQueryColumns" :label="item.label" :value="item.value" :key="item.value"></el-option>
+                        </el-select>
+                    </template>
+                </el-table-column>
+                <el-table-column prop="searchMethod" label="搜索方式" width="150" align="center">
+                    <template slot-scope="{row}">
+                        <el-select v-model="row.searchMethod">
+                            <el-option v-for="item in searchMethods" :label="item" :value="item" :key="item"></el-option>
+                        </el-select>
+                    </template>
+                </el-table-column>
+                <el-table-column prop="value" label="参数" align="center">
+                    <template slot-scope="{row}">
+                        <el-input v-model="row.value"></el-input>
+                    </template>
+                </el-table-column>
+                <el-table-column width="60" align="center">
+                    <template slot-scope="{ row, column, $index }">
+                        <el-button @click="removeField($index)" size="small" type="text">删除</el-button>
+                    </template>
+                </el-table-column>
+            </el-table>
+
+            <span slot="footer" class="dialog-footer">
+
+                <el-button @click="advancedQuery" :loading="$store.state.fetchingData">确定</el-button>
+            </span>
+        </el-dialog>
+
     </div>
 </template>
 <script>
@@ -117,7 +165,21 @@
             #end
         #end
                 ],
-                multipleMode: false
+                multipleMode: false,
+                showAdvancedQueryDialog: false,
+                advancedQueryFields: [],
+                searchMethods: ['=', '!=', '>', '>=', '<', '<=', 'like'],
+                advancedQueryColumns: [
+                    #foreach($field in $model.fields)
+                        #if(${field.showInList})
+                            {
+                                label: '$display.alt(${field.remark},${field.modelName})',
+                                value: '${field.name}'
+                            },
+                        #end
+                    #end
+                ],
+                advancedQuerySearchKey: '',
             }
         },
         computed: {
@@ -143,6 +205,7 @@
                     currentPage: this.currentPage,
                     pageNumber: this.pageSize,
                     searchKey: this.filter1,
+                    advancedQuery: this.advancedQuerySearchKey,
                 }
                 }).then(res => {
                     if (res.success) {
@@ -177,7 +240,45 @@
             },
             operation2() {
                 this.${esc.d}message('操作2');
+            },
+            addField() {
+                this.advancedQueryFields.push({
+                    link: 'AND',
+                    name: '',
+                    searchMethod: '=',
+                    value: '',
+                });
+            },
+            removeField(i) {
+                if (this.advancedQueryFields.length > 0) {
+                    this.advancedQueryFields.splice(i, 1);
+                }
+            },
+            advancedQuery() {
+
+                this.advancedQuerySearchKey = '';
+
+                if (this.advancedQueryFields.length > 0) {
+
+                    var templist = [];
+
+                    this.advancedQueryFields.forEach(item => {
+                        if (item.link && item.name && item.searchMethod && item.value) {
+                            var tempItem = item.link + '_,' + item.name + '_,' + item.searchMethod + '_,' + item.value;
+                            templist.push(tempItem);
+                        }
+                    })
+
+                    if (templist.length > 0) {
+
+                        this.advancedQuerySearchKey = templist.join('_;');
+                    }
+                }
+
+                this.getData();
+                this.showAdvancedQueryDialog = false;
             }
+
         }
     }
 </script>

+ 66 - 0
src/main/resources/templates/MapperXmlSqlServerTemplate.vm

@@ -83,7 +83,40 @@
                     #end
                 </trim>
             </if>
+            <if test="record.advancedQuery != null and !&quot;&quot;.equals(record.advancedQuery)">
+                <foreach item="item" index="index" collection="record.advancedQuery.split('_;')">
+                    <choose>
+                        <when test="item.indexOf('like') != -1">
+                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                                <if test="detailIndex == 3">
+                                    concat('%',#{itemDetail},'%')
+                                </if>
 
+                                <if test="detailIndex &lt; 3">
+                                    ${esc.d}{itemDetail}
+                                </if>
+
+                            </foreach>
+                        </when>
+                        <otherwise>
+                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                                <if test="detailIndex == 3">
+                                    #{itemDetail}
+                                </if>
+
+                                <if test="detailIndex &lt; 3">
+                                    ${esc.d}{itemDetail}
+                                </if>
+
+                            </foreach>
+                        </otherwise>
+                    </choose>
+
+
+                </foreach>
+
+
+            </if>
         </where>
         order by id desc
     </select>
@@ -109,7 +142,40 @@
                     #end
                 </trim>
             </if>
+            <if test="advancedQuery != null and !&quot;&quot;.equals(advancedQuery)">
+                <foreach item="item" index="index" collection="advancedQuery.split('_;')">
+                    <choose>
+                        <when test="item.indexOf('like') != -1">
+                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                                <if test="detailIndex == 3">
+                                    concat('%',#{itemDetail},'%')
+                                </if>
 
+                                <if test="detailIndex &lt; 3">
+                                    ${esc.d}{itemDetail}
+                                </if>
+
+                            </foreach>
+                        </when>
+                        <otherwise>
+                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                                <if test="detailIndex == 3">
+                                    #{itemDetail}
+                                </if>
+
+                                <if test="detailIndex &lt; 3">
+                                    ${esc.d}{itemDetail}
+                                </if>
+
+                            </foreach>
+                        </otherwise>
+                    </choose>
+
+
+                </foreach>
+
+
+            </if>
         </where>
         order by id desc
     </select>

+ 70 - 0
src/main/resources/templates/MapperXmlTemplate.vm

@@ -77,6 +77,42 @@
              #end
              </trim>
          </if>
+
+            <if test="record.advancedQuery != null and !&quot;&quot;.equals(record.advancedQuery)">
+                <foreach item="item" index="index" collection="record.advancedQuery.split('_;')">
+                    <choose>
+                        <when test="item.indexOf('like') != -1">
+                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                                <if test="detailIndex == 3">
+                                    concat('%',#{itemDetail},'%')
+                                </if>
+
+                                <if test="detailIndex &lt; 3">
+                                    ${esc.d}{itemDetail}
+                                </if>
+
+                            </foreach>
+                        </when>
+                        <otherwise>
+                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                                <if test="detailIndex == 3">
+                                    #{itemDetail}
+                                </if>
+
+                                <if test="detailIndex &lt; 3">
+                                    ${esc.d}{itemDetail}
+                                </if>
+
+                            </foreach>
+                        </otherwise>
+                    </choose>
+
+
+                </foreach>
+
+
+            </if>
+
         </where>
         order by id desc
     </select>
@@ -100,6 +136,40 @@
                     #end
                 </trim>
             </if>
+<if test="advancedQuery != null and !&quot;&quot;.equals(advancedQuery)">
+    <foreach item="item" index="index" collection="advancedQuery.split('_;')">
+        <choose>
+            <when test="item.indexOf('like') != -1">
+                <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                    <if test="detailIndex == 3">
+                        concat('%',#{itemDetail},'%')
+                    </if>
+
+                    <if test="detailIndex &lt; 3">
+                        ${esc.d}{itemDetail}
+                    </if>
+
+                </foreach>
+            </when>
+            <otherwise>
+                <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
+                    <if test="detailIndex == 3">
+                        #{itemDetail}
+                    </if>
+
+                    <if test="detailIndex &lt; 3">
+                        ${esc.d}{itemDetail}
+                    </if>
+
+                </foreach>
+            </otherwise>
+        </choose>
+
+
+    </foreach>
+
+
+</if>
         </where>
         order by id desc
     </select>

+ 13 - 0
src/main/resources/templates/ModelTemplate.vm

@@ -17,6 +17,11 @@ public class $model.className{
 
 private String searchKey;
 
+/**
+* and,test_name,like,value;or,remark,=,123
+*/
+private String advancedQuery;
+
 #foreach($field in $model.fields)
     public $field.javaType get${display.capitalize($field.modelName)}(){
         return this.$field.modelName;
@@ -35,5 +40,13 @@ public void setSearchKey(String searchKey) {
     this.searchKey = searchKey;
 }
 
+public String getAdvancedQuery() {
+    return advancedQuery;
+}
+
+public void setAdvancedQuery(String advancedQuery) {
+    this.advancedQuery = advancedQuery;
+}
+
 }
 

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

@@ -295,12 +295,25 @@ export default {
             });
         },
         submit() {
+
             this.formData.fields = this.fields;
             this.formData.javaPath = this.formData.rootPath + this.formData.javaPathRelative;
             this.formData.viewPath = this.formData.rootPath + this.formData.viewPathRelative;
-            axios.post('/genCode/save', this.formData).then(res => {
+            var alertMsg = "生成代码可能会删除已有同名表、数据或文件,确认要生成么?";
+
+            this.$alert(alertMsg, '警告', { type: 'error' }).then(() => {
+                return axios.post('/genCode/save', this.formData)
+            }).then(() => {
                 this.$msgbox({ title: '提示', type: 'success', message: '代码生成成功' });
+            }).catch(() => {
+                if (res === 'cancel') {
+                    this.$msgbox({ title: '提示', type: 'error', message: '生成取消' });
+                } else {
+                    this.$msgbox({ title: '提示', type: 'error', message: '生成失败' });
+                }
             })
+
+
         },
         addField() {
             this.fields.push({

+ 4 - 1
src/main/vue/src/pages/TestAaa.vue

@@ -2,7 +2,10 @@
     <div>
         <el-form :model="formData" :rules="rules" ref="form" label-width="80px" label-position="right" size="small"
                  style="max-width: 500px;">
-                                                                                                                    <el-form-item prop="testName" label="姓名">
+                                                                                        <el-form-item prop="delFlag" label="删除标识">
+                <el-input v-model="formData.delFlag"></el-input>
+            </el-form-item>
+                                                                                                                                                                                                                                                                                                        <el-form-item prop="testName" label="名字">
                 <el-input v-model="formData.testName"></el-input>
             </el-form-item>
                                                                                                                                                                                                                                                                                                         <el-form-item prop="remark" label="备注">

+ 137 - 6
src/main/vue/src/pages/TestAaas.vue

@@ -13,7 +13,8 @@
                         value="item2">
                 </el-option>
             </el-select>
-
+            <el-button @click="showAdvancedQueryDialog = !showAdvancedQueryDialog" type="primary" size="small" icon="el-icon-search" class="filter-item">高级查询
+            </el-button>
             <el-button @click="getData" type="primary" size="small" icon="el-icon-search" class="filter-item">搜索
             </el-button>
             <el-button @click="$router.push('/testAaa')" type="primary" size="small" icon="el-icon-edit"
@@ -45,10 +46,22 @@
                     min-width="50"
                     align="center">
             </el-table-column>
-                                                                                                <el-table-column
+                                        <el-table-column
+                    v-if="isColumnShow('id')"
+                    prop="id"
+                    label="id"
+                    min-width="100">
+            </el-table-column>
+                                                        <el-table-column
+                    v-if="isColumnShow('delFlag')"
+                    prop="delFlag"
+                    label="删除标识"
+                    min-width="100">
+            </el-table-column>
+                                                        <el-table-column
                     v-if="isColumnShow('testName')"
                     prop="testName"
-                    label="姓名"
+                    label="名"
                     min-width="100">
             </el-table-column>
                                                         <el-table-column
@@ -86,6 +99,53 @@
                     :total="totalNumber">
             </el-pagination>
         </div>
+        <el-dialog title="高级查询" :visible.sync="showAdvancedQueryDialog">
+            <el-button @click="addField" type="text" icon="el-icon-plus">添加</el-button>
+            <el-table :data="advancedQueryFields">
+
+                <el-table-column prop="link" label="链接符" align="center">
+                    <template slot-scope="{row}">
+                        <el-select placeholder="链接" size="small" v-model="row.link" class="filter-item">
+                            <el-option label="AND" value="AND">
+                            </el-option>
+                            <el-option label="OR" value="OR">
+                            </el-option>
+                        </el-select>
+                    </template>
+                </el-table-column>
+                <el-table-column prop="name" label="字段" align="center">
+                    <template slot-scope="{row}">
+                        <el-select v-model="row.name">
+
+                            <el-option v-for="item in advancedQueryColumns" :label="item.label" :value="item.value" :key="item.value"></el-option>
+                        </el-select>
+                    </template>
+                </el-table-column>
+                <el-table-column prop="searchMethod" label="搜索方式" width="150" align="center">
+                    <template slot-scope="{row}">
+                        <el-select v-model="row.searchMethod">
+                            <el-option v-for="item in searchMethods" :label="item" :value="item" :key="item"></el-option>
+                        </el-select>
+                    </template>
+                </el-table-column>
+                <el-table-column prop="value" label="参数" align="center">
+                    <template slot-scope="{row}">
+                        <el-input v-model="row.value"></el-input>
+                    </template>
+                </el-table-column>
+                <el-table-column width="60" align="center">
+                    <template slot-scope="{ row, column, $index }">
+                        <el-button @click="removeField($index)" size="small" type="text">删除</el-button>
+                    </template>
+                </el-table-column>
+            </el-table>
+
+            <span slot="footer" class="dialog-footer">
+
+                <el-button @click="advancedQuery" :loading="$store.state.fetchingData">确定</el-button>
+            </span>
+        </el-dialog>
+
     </div>
 </template>
 <script>
@@ -105,8 +165,18 @@
                 filter1: '',
                 filter2: '',
                 tableColumns: [
-                                                                                {
-                        label: '姓名',
+                                        {
+                        label: 'id',
+                        value: 'id',
+                        show: true
+                    },
+                                                    {
+                        label: '删除标识',
+                        value: 'delFlag',
+                        show: true
+                    },
+                                                    {
+                        label: '名字',
                         value: 'testName',
                         show: true
                     },
@@ -116,7 +186,29 @@
                         show: true
                     },
                                     ],
-                multipleMode: false
+                multipleMode: false,
+                showAdvancedQueryDialog: false,
+                advancedQueryFields: [],
+                searchMethods: ['=', '!=', '>', '>=', '<', '<=', 'like'],
+                advancedQueryColumns: [
+                                                                        {
+                                label: 'id',
+                                value: 'id'
+                            },
+                                                                                                {
+                                label: '删除标识',
+                                value: 'del_flag'
+                            },
+                                                                                                {
+                                label: '名字',
+                                value: 'test_name'
+                            },
+                                                                                                {
+                                label: '备注',
+                                value: 'remark'
+                            },
+                                                            ],
+                advancedQuerySearchKey: '',
             }
         },
         computed: {
@@ -142,6 +234,7 @@
                     currentPage: this.currentPage,
                     pageNumber: this.pageSize,
                     searchKey: this.filter1,
+                    advancedQuery: this.advancedQuerySearchKey,
                 }
                 }).then(res => {
                     if (res.success) {
@@ -176,7 +269,45 @@
             },
             operation2() {
                 this.$message('操作2');
+            },
+            addField() {
+                this.advancedQueryFields.push({
+                    link: 'AND',
+                    name: '',
+                    searchMethod: '=',
+                    value: '',
+                });
+            },
+            removeField(i) {
+                if (this.advancedQueryFields.length > 0) {
+                    this.advancedQueryFields.splice(i, 1);
+                }
+            },
+            advancedQuery() {
+
+                this.advancedQuerySearchKey = '';
+
+                if (this.advancedQueryFields.length > 0) {
+
+                    var templist = [];
+
+                    this.advancedQueryFields.forEach(item => {
+                        if (item.link && item.name && item.searchMethod && item.value) {
+                            var tempItem = item.link + '_,' + item.name + '_,' + item.searchMethod + '_,' + item.value;
+                            templist.push(tempItem);
+                        }
+                    })
+
+                    if (templist.length > 0) {
+
+                        this.advancedQuerySearchKey = templist.join('_;');
+                    }
+                }
+
+                this.getData();
+                this.showAdvancedQueryDialog = false;
             }
+
         }
     }
 </script>