浏览代码

点表导出

songhaodong 2 年之前
父节点
当前提交
405acc87d3

+ 9 - 3
ipfcst/ipfcst-reportquery/src/main/frontend/views/parameterConfiguration/WindSpeedPointInfo/index.vue

@@ -76,10 +76,9 @@
               action=""
               :show-file-list = false
             >
-              <el-button size="small" type="primary" >读取excel</el-button>
-
+              <el-button size="small" type="primary" >导入</el-button>
             </el-upload>
-
+            <el-button size="small" type="primary" @click="exportToExcel">导出</el-button>
           </el-col>
         </el-row>
       </div>
@@ -287,6 +286,13 @@ export default {
       this.form = {};
       this.dialogVisible = true;
     },
+    exportToExcel(){
+      this.dialogVisible = true;
+      this.$axios.get('/exportToExcel/fanUnitInfoToExcel').then(res => {
+        console.log("eee");
+      })
+      this.dialogVisible = false;
+    },
     saveRowEvent() {
       this.$axios.post('/windSpeedPointInfo', this.form).then(res => {
         this.$message.success(res.message)

+ 29 - 0
ipfcst/ipfcst-reportquery/src/main/java/com/jiayue/ipfcst/controller/ExportToExcelController.java

@@ -0,0 +1,29 @@
+package com.jiayue.ipfcst.controller;
+
+import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
+import com.jiayue.ipfcst.service.ExportToExcelService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.IOException;
+
+/**
+ * @author shd
+ * @since 2022-07-25
+ */
+@Slf4j
+@RestController
+@RequestMapping("/exportToExcel")
+public class ExportToExcelController {
+  @Autowired
+  private ExportToExcelService exportToExcelService;
+
+  @GetMapping("/fanUnitInfoToExcel")
+  public ResponseVO fanUnitInfoToExcel() throws IOException {
+    exportToExcelService.fanUnitInfoToExcel();
+    return ResponseVO.success(1);
+  }
+}

+ 50 - 0
ipfcst/ipfcst-reportquery/src/main/java/com/jiayue/ipfcst/service/ExportToExcelService.java

@@ -0,0 +1,50 @@
+package com.jiayue.ipfcst.service;
+
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.ExcelWriter;
+import com.jiayue.ipfcst.common.data.entity.WindSpeedPointInfo;
+import com.jiayue.ipfcst.common.data.repository.WindSpeedPointInfoRepository;
+import com.jiayue.ipfcst.common.data.service.BaseService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author shd
+ * @since 2022-07-25
+ */
+@Service
+public class ExportToExcelService extends BaseService {
+  @Autowired
+  private WindSpeedPointInfoRepository windSpeedPointInfoRepository;
+  @Autowired
+  HttpServletResponse response;
+
+  public void fanUnitInfoToExcel() throws IOException {
+    List<Float> list = new ArrayList<>();
+    List<List<Float>> lists = new ArrayList<>();
+    List<WindSpeedPointInfo> windSpeedPointInfoList = windSpeedPointInfoRepository.findAll();
+    List<WindSpeedPointInfo> windSpeedPointInfos = windSpeedPointInfoList.stream().filter(w -> w.getWind() == 1).collect(Collectors.toList());
+    List<WindSpeedPointInfo> belongList = windSpeedPointInfos.stream().filter(n -> n.getBelong() == 1).collect(Collectors.toList());
+    for(WindSpeedPointInfo w: belongList){
+      list.add(Float.parseFloat(w.getBelong().toString()));
+      list.add(w.getSpeed());
+    }
+    lists.add(list);
+//通过工具类创建writer
+    ExcelWriter writer = ExcelUtil.getWriter("d:/writeTest.xlsx");
+
+
+//一次性写出内容,强制输出标题
+    writer.write(lists, true);
+//关闭writer,释放内存
+    writer.close();
+  }
+}