|
@@ -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();
|
|
|
+ }
|
|
|
+}
|