licailing 4 лет назад
Родитель
Сommit
53dea3e867

+ 9 - 3
src/main/java/com/izouma/wenlvju/web/TrainingInstitutionController.java

@@ -1,16 +1,17 @@
 package com.izouma.wenlvju.web;
 
 import com.izouma.wenlvju.domain.TrainingInstitution;
-import com.izouma.wenlvju.dto.TrainingInstitutionDTO;
-import com.izouma.wenlvju.service.TrainingInstitutionService;
 import com.izouma.wenlvju.dto.PageQuery;
+import com.izouma.wenlvju.dto.TrainingInstitutionDTO;
 import com.izouma.wenlvju.exception.BusinessException;
 import com.izouma.wenlvju.repo.TrainingInstitutionRepo;
+import com.izouma.wenlvju.service.TrainingInstitutionService;
 import com.izouma.wenlvju.utils.ObjUtils;
 import com.izouma.wenlvju.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Page;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
@@ -63,7 +64,7 @@ public class TrainingInstitutionController extends BaseController {
 
     @GetMapping("/excel1")
     @ResponseBody
-    public void excel1(HttpServletResponse response, PageQuery pageQuery) throws IOException {
+    public void excel1(HttpServletResponse response) throws IOException {
         List<TrainingInstitution> data = trainingInstitutionRepo.findAllByPhoneIsNull();
         List<TrainingInstitutionDTO> dtos = data.stream()
                 .map(TrainingInstitutionDTO::new)
@@ -76,5 +77,10 @@ public class TrainingInstitutionController extends BaseController {
         List<String> phones = trainingInstitutionRepo.findAllBySubmitFalseAndPhoneIsNotNull();
         trainingInstitutionService.batchSend(phones);
     }
+
+    @PostMapping("/upload")
+    public void uploadFile(@RequestParam("file") MultipartFile file) throws Exception {
+        trainingInstitutionService.upload(file);
+    }
 }
 

+ 59 - 16
src/main/vue/src/views/TrainingInstitutionList.vue

@@ -4,23 +4,29 @@
             <el-input placeholder="输入关键字" v-model="search" clearable class="filter-item"></el-input>
             <el-button @click="getData" type="primary" icon="el-icon-search" class="filter-item">搜索 </el-button>
             <!-- <el-button @click="addRow" type="primary" icon="el-icon-plus" class="filter-item">添加 </el-button> -->
-            <el-button
-                @click="download"
-                type="primary"
-                icon="el-icon-download"
-                :loading="downloading"
-                class="filter-item"
-                >导出EXCEL
+            <el-button @click="download" type="primary" icon="el-icon-download" :loading="downloading"
+                >导出所有
             </el-button>
-            <el-button
-                @click="downloadTel"
-                type="primary"
-                icon="el-icon-download"
-                :loading="downloading"
-                class="filter-item"
+            <el-button @click="downloadTel" type="primary" icon="el-icon-download" :loading="downloading"
                 >导出固定电话
             </el-button>
-            <el-button @click="sendSms" type="primary" class="filter-item">短信通知 </el-button>
+            <el-upload
+                :action="uploadUrl"
+                :before-upload="beforeUpload"
+                :headers="headers"
+                :show-file-list="false"
+                ref="upload"
+                :on-success="onSuccess"
+                class="uploader"
+                :on-error="onfail"
+                :loading="loading"
+                :disabled="loading"
+            >
+                <el-button slot="trigger" type="primary" icon="el-icon-upload2" :loading="loading" :disabled="loading"
+                    >批量上传</el-button
+                >
+            </el-upload>
+            <el-button @click="sendSms" type="primary">短信通知 </el-button>
         </div>
         <el-table
             :data="tableData"
@@ -96,6 +102,7 @@
 <script>
 import { mapState } from 'vuex';
 import pageableTable from '@/mixins/pageableTable';
+import resolveUrl from 'resolve-url';
 
 export default {
     name: 'TrainingInstitutionList',
@@ -105,14 +112,24 @@ export default {
             multipleMode: false,
             search: '',
             url: '/trainingInstitution/all',
-            downloading: false
+            downloading: false,
+            loading: false,
+            uploadUrl: ''
         };
     },
     computed: {
         selection() {
             return this.$refs.table.selection.map(i => i.id);
+        },
+        headers() {
+            return {
+                Authorization: 'Bearer ' + sessionStorage.getItem('token')
+            };
         }
     },
+    created() {
+        this.uploadUrl = resolveUrl(this.$baseUrl, 'trainingInstitution/upload');
+    },
     methods: {
         beforeGetData() {
             return { search: this.search };
@@ -225,8 +242,34 @@ export default {
                         this.$message.error(e.error);
                     }
                 });
+        },
+        upload() {},
+        onfail(e) {
+            console.log(e);
+            this.$message.error('失败:' + e);
+            this.loading = false;
+            this.getData();
+        },
+        onSuccess() {
+            this.$message.success('上传成功');
+            this.loading = false;
+            this.getData();
+        },
+        beforeUpload() {
+            return this.$confirm('确认要上传文件吗?', '提示', {
+                confirmButtonText: '确定',
+                cancelButtonText: '取消',
+                type: 'warning'
+            }).then(() => {
+                this.loading = true;
+            });
         }
     }
 };
 </script>
-<style lang="less" scoped></style>
+<style lang="less" scoped>
+.uploader {
+    display: inline-block;
+    margin: 0 10px;
+}
+</style>