Selaa lähdekoodia

读取excel入库

admin 2 vuotta sitten
vanhempi
commit
2bc3462bfe

+ 20 - 3
ipfcst/ipfcst-reportquery/src/main/frontend/views/parameterConfiguration/CutOutSpeedSpecifyInfo/index.vue

@@ -4,8 +4,20 @@
       <div slot="header" class="clearfix">
         <span>切出停机</span>
       </div>
+      <el-row>
       <el-button type="primary" size="small" @click="insertEvent" style="round-clip: 10px">新增</el-button>
-      <el-button type="primary" size="small" :loading="loading" @click="cutOutSpeedSpecifyInfo" style="round-clip: 10px">读取excel</el-button>
+      <el-upload
+        ref="upload"
+        name="file"
+        :http-request="this.cutOutSpeedSpecifyInfo"
+        class="link-block"
+        action=""
+        :show-file-list = false
+      >
+        <el-button size="small" type="primary" >读取excel</el-button>
+
+      </el-upload>
+      </el-row>
       <div>
         <el-table
           :data="tableData"
@@ -182,9 +194,11 @@ export default {
       this.currentPage = pageNum
       this.initPage()
     },
-    cutOutSpeedSpecifyInfo() {
+    cutOutSpeedSpecifyInfo(obj) {
+      const formData = new FormData()
+      formData.append("multipartFile",obj.file)
       this.loading = true
-      this.$axios.get("/readToMysql/cutOutSpeedSpecifyInfo").then((res=>{
+      this.$axios.post("/readToMysql/cutOutSpeedSpecifyInfo",formData).then((res=>{
         this.$message.success(res.message)
         this.loading = false
         this.initPage()
@@ -202,6 +216,9 @@ export default {
   background: transparent;
   color: #ffffff;
 }
+.link-block{
+  display: inline-block;
+}
 .el-button {
   round-clip: 10px;
   color: #ffffff;

+ 2 - 7
ipfcst/ipfcst-reportquery/src/main/frontend/views/parameterConfiguration/FanUnitInfo/index.vue

@@ -13,6 +13,7 @@
           :http-request="this.readFanUnitInfo"
           class="link-block"
           action=""
+          :show-file-list = false
         >
           <el-button size="small" type="primary" >读取excel</el-button>
 
@@ -20,10 +21,6 @@
 
       </el-row>
 
-
-
-
-
       <div>
         <el-table
           :data="tableData"
@@ -247,9 +244,7 @@ export default {
       this.loading = true
       this.$axios.post("/readToMysql/getFanUnitInfo", formData
       ).then(res=>{
-        this.$message.success(
-          res.message
-        )
+        this.$message.success(res.message)
         this.loading = false
         this.initPage()
       })

+ 19 - 4
ipfcst/ipfcst-reportquery/src/main/frontend/views/parameterConfiguration/WindSpeedPointInfo/index.vue

@@ -68,7 +68,18 @@
           <el-col :span="4">
             <el-button type="primary" size="small" :loading="loading" @click="findBySomeConditions">查询</el-button>
             <el-button type="primary" size="small" @click="insertEvent">新增</el-button>
-            <el-button type="primary" size="small" :loading="loading" @click="readSpeedSheet">读取excel</el-button>
+            <el-upload
+              ref="upload"
+              name="file"
+              :http-request="this.readSpeedSheet"
+              class="link-block"
+              action=""
+              :show-file-list = false
+            >
+              <el-button size="small" type="primary" >读取excel</el-button>
+
+            </el-upload>
+
           </el-col>
         </el-row>
       </div>
@@ -308,11 +319,13 @@ export default {
       })
     },
 
-    readSpeedSheet() {
+    readSpeedSheet(obj) {
       this.$XModal.confirm('是否从Excel读取数据?').then(type => {
         if (type === 'confirm') {
+          const formData = new FormData()
+          formData.append("multipartFile",obj.file)
           this.loading = true
-          this.$axios.get("/readToMysql/readSpeedSheet").then(res => {
+          this.$axios.post("/readToMysql/readSpeedSheet",formData).then(res => {
             this.$message.success(res.message)
             this.loading = false
             this.findBySomeConditions()
@@ -363,7 +376,9 @@ export default {
   border: 1px solid #fff;
 
 }
-
+.link-block{
+  display: inline-block;
+}
 ::v-deep .el-table, .el-table__expanded-cell {
   margin-top: 20px;
   background-color: transparent;

+ 20 - 6
ipfcst/ipfcst-reportquery/src/main/frontend/views/parameterConfiguration/WindTurbinePowerCurve/index.vue

@@ -2,9 +2,19 @@
   <div class="chart-container">
     <div class="filter" >
       <div style="margin-left:-10px;">
-        <el-button type="primary" size="small" :loading="loading" @click="readWindTurbinePowerCurve"
-                   style="round-clip: 10px">读取excel
-        </el-button>
+
+        <el-upload
+          ref="upload"
+          name="file"
+          :http-request="this.readWindTurbinePowerCurve"
+          class="link-block"
+          action=""
+          :show-file-list = false
+        >
+          <el-button size="small" type="primary" >读取excel</el-button>
+
+        </el-upload>
+
       </div>
       <div class="toolbar" v-show="this.showToolBar"> <vxe-toolbar ref="fstToolBar" custom >
         <template v-slot:buttons>
@@ -179,11 +189,13 @@
         this.loading = true
         this.getTable();
       },
-      readWindTurbinePowerCurve() {
+      readWindTurbinePowerCurve(obj) {
         this.$XModal.confirm('是否从Excel读取数据?').then(type => {
           if (type === 'confirm') {
+            const formData = new FormData()
+            formData.append("multipartFile",obj.file)
             this.loading = true
-            this.$axios.get("/readToMysql/readWindTurbinePowerCurveMap").then(res=>{
+            this.$axios.post("/readToMysql/readWindTurbinePowerCurveMap",formData).then(res=>{
               this.$message.success(
                 res.message
               )
@@ -243,6 +255,8 @@
 </script>
 
 <style scoped>
-
+.link-block{
+  display: inline-block;
+}
 </style>
 

+ 13 - 12
ipfcst/ipfcst-reportquery/src/main/java/com/jiayue/ipfcst/controller/ReadToMysqlController.java

@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.sql.SQLException;
 
 /**
@@ -40,12 +41,12 @@ public class ReadToMysqlController {
    * 读取切除
    * @return
    */
-  @GetMapping("/cutOutSpeedSpecifyInfo")
-  public ResponseVO getCutOutSpeedSpecifyInfo(){
+  @PostMapping("/cutOutSpeedSpecifyInfo")
+  public ResponseVO getCutOutSpeedSpecifyInfo(@RequestParam("multipartFile") MultipartFile multipartFile){
     try {
 
-      return ReadtoMysql.readFanCutOutSpeedInfo();
-    } catch (SQLException e) {
+      return ReadtoMysql.readFanCutOutSpeedInfo(multipartFile);
+    } catch (Exception e) {
       e.printStackTrace();
       return ResponseVO.error(e);
     }
@@ -55,14 +56,14 @@ public class ReadToMysqlController {
    * 读取风速点表
    * @return
    */
-  @GetMapping("/readSpeedSheet")
-  public ResponseVO getSpeedSheet(){
+  @PostMapping("/readSpeedSheet")
+  public ResponseVO getSpeedSheet(@RequestParam("multipartFile") MultipartFile multipartFile){
     try {
       if(windSpeedPointInfoRepository.findAll().size() > 0){
         windSpeedPointInfoRepository.deleteAll();
       }
-      return ReadtoMysql.readSpeedSheet();
-    } catch (SQLException e) {
+      return ReadtoMysql.readSpeedSheet(multipartFile);
+    } catch (Exception e) {
       e.printStackTrace();
       return ResponseVO.error(e);
     }
@@ -72,14 +73,14 @@ public class ReadToMysqlController {
    * 读取功率曲线
    * @return
    */
-  @GetMapping("/readWindTurbinePowerCurveMap")
-  public ResponseVO getReadWindTurbinePowerCurveMap(){
+  @PostMapping("/readWindTurbinePowerCurveMap")
+  public ResponseVO getReadWindTurbinePowerCurveMap(@RequestParam("multipartFile") MultipartFile multipartFile){
     try {
       if(windTurbinePowerCurveRepository.findAll().size() > 0){
         windTurbinePowerCurveRepository.deleteAll();
       }
-      return ReadtoMysql.readWindTurbinePowerCurveMap();
-    } catch (SQLException e) {
+      return ReadtoMysql.readWindTurbinePowerCurveMap(multipartFile);
+    } catch (Exception e) {
       e.printStackTrace();
       return ResponseVO.error(e);
     }

+ 74 - 6
ipfcst/ipfcst-reportquery/src/main/java/com/jiayue/ipfcst/util/ReadtoMysql.java

@@ -17,6 +17,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.swing.plaf.multi.MultiInternalFrameUI;
 import java.io.File;
+import java.io.IOException;
 import java.io.InputStream;
 import java.sql.SQLException;
 import java.text.DecimalFormat;
@@ -125,12 +126,33 @@ public class ReadtoMysql {
   /**
    * 读取 东北风向风速 东南风向风速  西南风向风速  西北风向风速 4个sheet表风速点表
    */
-  public static ResponseVO readSpeedSheet() throws SQLException {
+  public static ResponseVO readSpeedSheet(MultipartFile multipartFile) throws Exception {
+
+    //获取到文件名
+    String originalFilename = multipartFile.getOriginalFilename();
+    File fileP = new File("");
+    //获取项目路径
+    String filePath = fileP.getCanonicalPath();
+
+    String route = filePath + "/" + "Temporary/";
+    File file1 = new File(route);
+
+    if (!file1.exists()) {
+      file1.mkdirs();
+    }
+    File[] files = file1.listFiles();
+    //判断文件夹中是否有文件
+    if(files.length < 1){
+      multipartFile.transferTo(new File(route + originalFilename));
+    }
+    File file = new File(route + originalFilename);
+
+
     Map<Integer, List<String>> fanidInfo = new HashMap<>();
     List<WindSpeedPointInfo> windSpeedPointInfoList = new ArrayList<>();
     DecimalFormat decimalFormat = new DecimalFormat(".00");
 
-    try (ExcelReader reader = ExcelUtil.getReader(modleParamFilePath, 0)) {
+    try (ExcelReader reader = ExcelUtil.getReader(file.getPath(), 0)) {
       reader.addHeaderAlias("序号", "id");
       reader.addHeaderAlias("机组名称", "fanName");
       reader.addHeaderAlias("风机容量KW", "fanUnitCapacity");
@@ -184,20 +206,43 @@ public class ReadtoMysql {
     } catch (cn.hutool.poi.exceptions.POIException e) {
       return ResponseVO.error(e);
     }
+    //删除文件
+    file.delete();
     return ResponseVO.success(1);
   }
 
   /**
    * 读取风速曲线
    */
-  public static ResponseVO readWindTurbinePowerCurveMap() throws SQLException {
+  public static ResponseVO readWindTurbinePowerCurveMap(MultipartFile multipartFile) throws Exception {
+
+    //获取到文件名
+    String originalFilename = multipartFile.getOriginalFilename();
+    File fileP = new File("");
+    //获取项目路径
+    String filePath = fileP.getCanonicalPath();
+
+    String route = filePath + "/" + "Temporary/";
+    File file1 = new File(route);
+
+    if (!file1.exists()) {
+      file1.mkdirs();
+    }
+    File[] files = file1.listFiles();
+    //判断文件夹中是否有文件
+    if(files.length < 1){
+      multipartFile.transferTo(new File(route + originalFilename));
+    }
+    File file = new File(route + originalFilename);
+
+
     for (int sheelIndex = 10; sheelIndex <= 14; sheelIndex++) {
       //读取风速曲线 sheet
       String sheetName;
       List<List<Object>> readRows;
       List<WindTurbinePowerCurve> windTurbinePowerCurves = new ArrayList<>();
       try (
-        ExcelReader readerWind = ExcelUtil.getReader(modleParamFilePath, sheelIndex)) {
+        ExcelReader readerWind = ExcelUtil.getReader(file.getPath(), sheelIndex)) {
         sheetName = readerWind.getSheet().getSheetName();
         //按行读取所有数据
         readRows = readerWind.read();
@@ -217,6 +262,8 @@ public class ReadtoMysql {
         return ResponseVO.error(e);
       }
     }
+    //删除文件
+    file.delete();
     return ResponseVO.success(1);
   }
 
@@ -225,10 +272,29 @@ public class ReadtoMysql {
    *
    * @return
    */
-  public static ResponseVO readFanCutOutSpeedInfo() throws SQLException {
+  public static ResponseVO readFanCutOutSpeedInfo(MultipartFile multipartFile) throws SQLException, IOException {
+    //获取到文件名
+    String originalFilename = multipartFile.getOriginalFilename();
+    File fileP = new File("");
+    //获取项目路径
+    String filePath = fileP.getCanonicalPath();
+
+    String route = filePath + "/" + "Temporary/";
+    File file1 = new File(route);
+
+    if (!file1.exists()) {
+      file1.mkdirs();
+    }
+    File[] files = file1.listFiles();
+    //判断文件夹中是否有文件
+    if(files.length < 1){
+      multipartFile.transferTo(new File(route + originalFilename));
+    }
+    File file = new File(route + originalFilename);
+
     //机组信息读取 sheet 0
     List<CutOutSpeedSpecifyInfo> cutOutSpeedSpecifyInfoList;
-    try (ExcelReader reader = ExcelUtil.getReader(modleParamFilePath, 9)) {
+    try (ExcelReader reader = ExcelUtil.getReader(file.getPath(), 9)) {
       reader.addHeaderAlias("序号", "id");
       reader.addHeaderAlias("风速下限(包含)m/s", "lowerWindSpeedLimit");
       reader.addHeaderAlias("风速上限(不包含)m/s", "highWindSpeedLimit");
@@ -248,6 +314,8 @@ public class ReadtoMysql {
     } catch (cn.hutool.poi.exceptions.POIException e) {
       return ResponseVO.error(e);
     }
+    //删除文件
+    file.delete();
     return ResponseVO.success(1);
   }
 }