|
@@ -1,68 +1,48 @@
|
|
-package com.jiayue.ipfcst.util;
|
|
|
|
|
|
+package com.jiayue.ipfcst.service;
|
|
|
|
|
|
import cn.hutool.db.Db;
|
|
import cn.hutool.db.Db;
|
|
import cn.hutool.db.Entity;
|
|
import cn.hutool.db.Entity;
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
+import cn.hutool.poi.exceptions.POIException;
|
|
import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
|
|
import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
|
|
import com.jiayue.ipfcst.common.data.entity.CutOutSpeedSpecifyInfo;
|
|
import com.jiayue.ipfcst.common.data.entity.CutOutSpeedSpecifyInfo;
|
|
import com.jiayue.ipfcst.common.data.entity.FanUnitInfo;
|
|
import com.jiayue.ipfcst.common.data.entity.FanUnitInfo;
|
|
import com.jiayue.ipfcst.common.data.entity.WindSpeedPointInfo;
|
|
import com.jiayue.ipfcst.common.data.entity.WindSpeedPointInfo;
|
|
import com.jiayue.ipfcst.common.data.entity.WindTurbinePowerCurve;
|
|
import com.jiayue.ipfcst.common.data.entity.WindTurbinePowerCurve;
|
|
|
|
+import com.jiayue.ipfcst.common.data.repository.FanUnitInfoRepository;
|
|
import com.jiayue.ipfcst.common.data.repository.WindSpeedPointInfoRepository;
|
|
import com.jiayue.ipfcst.common.data.repository.WindSpeedPointInfoRepository;
|
|
import com.jiayue.ipfcst.common.data.repository.WindTurbinePowerCurveRepository;
|
|
import com.jiayue.ipfcst.common.data.repository.WindTurbinePowerCurveRepository;
|
|
|
|
+import com.jiayue.ipfcst.common.data.service.BaseService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import javax.swing.plaf.multi.MultiInternalFrameUI;
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.io.InputStream;
|
|
|
|
import java.sql.SQLException;
|
|
import java.sql.SQLException;
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author shd
|
|
* @author shd
|
|
- * @since 2022-06-01
|
|
|
|
|
|
+ * @since 2022-07-25
|
|
*/
|
|
*/
|
|
-@Component
|
|
|
|
-public class ReadtoMysql {
|
|
|
|
- //模板配置文件路径
|
|
|
|
- public static String modleParamFilePath = "C:\\Users\\song\\Desktop\\单风机法模板-all.xlsx";
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+@Service
|
|
|
|
+public class ReadToMysqlService extends BaseService {
|
|
private static WindSpeedPointInfoRepository windSpeedPointInfoRepository;
|
|
private static WindSpeedPointInfoRepository windSpeedPointInfoRepository;
|
|
private static WindTurbinePowerCurveRepository windTurbinePowerCurveRepository;
|
|
private static WindTurbinePowerCurveRepository windTurbinePowerCurveRepository;
|
|
|
|
+ private static FanUnitInfoRepository fanUnitInfoRepository;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- public void setWindSpeedPointInfoRepository(WindSpeedPointInfoRepository windSpeedPointInfoRepository) {
|
|
|
|
- ReadtoMysql.windSpeedPointInfoRepository = windSpeedPointInfoRepository;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- public void setWindTurbinePowerCurveRepository(WindTurbinePowerCurveRepository windTurbinePowerCurveRepository) {
|
|
|
|
- ReadtoMysql.windTurbinePowerCurveRepository = windTurbinePowerCurveRepository;
|
|
|
|
|
|
+ public ReadToMysqlService(WindSpeedPointInfoRepository windSpeedPointInfoRepository,
|
|
|
|
+ FanUnitInfoRepository fanUnitInfoRepository,
|
|
|
|
+ WindTurbinePowerCurveRepository windTurbinePowerCurveRepository) {
|
|
|
|
+ this.windSpeedPointInfoRepository = windSpeedPointInfoRepository;
|
|
|
|
+ this.fanUnitInfoRepository = fanUnitInfoRepository;
|
|
|
|
+ this.windTurbinePowerCurveRepository = windTurbinePowerCurveRepository;
|
|
}
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) throws Exception {
|
|
|
|
-// 读取机组信息到数据库
|
|
|
|
-// readFanUnitInfo();
|
|
|
|
- /**
|
|
|
|
- * 读取风速点表到数据库
|
|
|
|
- */
|
|
|
|
-// readSpeedSheet();
|
|
|
|
- /**
|
|
|
|
- * 机组功率曲线
|
|
|
|
- */
|
|
|
|
-// readWindTurbinePowerCurveMap();
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 切出
|
|
|
|
- */
|
|
|
|
-// readFanCutOutSpeedInfo();
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 读取机组信息
|
|
* 读取机组信息
|
|
@@ -70,89 +50,34 @@ public class ReadtoMysql {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static ResponseVO readFanUnitInfo(MultipartFile multipartFile) throws Exception {
|
|
public static ResponseVO readFanUnitInfo(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);
|
|
|
|
-
|
|
|
|
- //机组信息读取 sheet 0
|
|
|
|
- List<FanUnitInfo> fanUnitInfoList;
|
|
|
|
|
|
+ // 机组信息读取 sheet 0
|
|
try (
|
|
try (
|
|
- ExcelReader reader = ExcelUtil.getReader(file.getPath(), 0)) {
|
|
|
|
- reader.addHeaderAlias("序号", "id");
|
|
|
|
|
|
+ ExcelReader reader = ExcelUtil.getReader(multipartFile.getInputStream(), 0)) {
|
|
|
|
+ reader.addHeaderAlias("序号", "fanId");
|
|
reader.addHeaderAlias("机组名称", "fanName");
|
|
reader.addHeaderAlias("机组名称", "fanName");
|
|
reader.addHeaderAlias("风机容量KW", "fanUnitCapacity");
|
|
reader.addHeaderAlias("风机容量KW", "fanUnitCapacity");
|
|
reader.addHeaderAlias("满发风速(m/s)", "fullWindSpeed");
|
|
reader.addHeaderAlias("满发风速(m/s)", "fullWindSpeed");
|
|
reader.addHeaderAlias("切出停机风速(m/s)", "cutOutSpeed");
|
|
reader.addHeaderAlias("切出停机风速(m/s)", "cutOutSpeed");
|
|
reader.addHeaderAlias("标杆风机编号", "benchmarkFan");
|
|
reader.addHeaderAlias("标杆风机编号", "benchmarkFan");
|
|
reader.addHeaderAlias("风机编号(多个风机使用竖线分割)", "fanNumArrs");
|
|
reader.addHeaderAlias("风机编号(多个风机使用竖线分割)", "fanNumArrs");
|
|
- fanUnitInfoList = reader.readAll(FanUnitInfo.class);
|
|
|
|
- for (FanUnitInfo fanUnitInfo :
|
|
|
|
- fanUnitInfoList) {
|
|
|
|
- Db.use().insertForGeneratedKey(
|
|
|
|
- Entity.create("t_fan_unit_info")
|
|
|
|
-// .set("C_ID",fanUnitInfo.getId())
|
|
|
|
- .set("C_FAN_NAME", fanUnitInfo.getFanName())
|
|
|
|
- .set("C_FAN_UNIT_CAPACITY", fanUnitInfo.getFanUnitCapacity())
|
|
|
|
- .set("C_FULL_WIND_SPEED", fanUnitInfo.getFullWindSpeed())
|
|
|
|
- .set("C_CUT_OUT_SPEED", fanUnitInfo.getCutOutSpeed())
|
|
|
|
- .set("C_BENCHMARK_FAN", fanUnitInfo.getBenchmarkFan())
|
|
|
|
- .set("C_FAN_NUM_ARRS", fanUnitInfo.getFanNumArrs())
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
|
|
+ List<FanUnitInfo> fanUnitInfoList = reader.readAll(FanUnitInfo.class);
|
|
|
|
+ fanUnitInfoRepository.saveAll(fanUnitInfoList);
|
|
} catch (cn.hutool.poi.exceptions.POIException e) {
|
|
} catch (cn.hutool.poi.exceptions.POIException e) {
|
|
return ResponseVO.error(e);
|
|
return ResponseVO.error(e);
|
|
}
|
|
}
|
|
- //删除文件
|
|
|
|
- file.delete();
|
|
|
|
return ResponseVO.success(1);
|
|
return ResponseVO.success(1);
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 读取 东北风向风速 东南风向风速 西南风向风速 西北风向风速 4个sheet表风速点表
|
|
|
|
|
|
+ * 读取 8个风向 sheet表风速点表
|
|
*/
|
|
*/
|
|
- 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);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ public static ResponseVO readSpeedSheet(MultipartFile multipartFile){
|
|
Map<Integer, List<String>> fanidInfo = new HashMap<>();
|
|
Map<Integer, List<String>> fanidInfo = new HashMap<>();
|
|
List<WindSpeedPointInfo> windSpeedPointInfoList = new ArrayList<>();
|
|
List<WindSpeedPointInfo> windSpeedPointInfoList = new ArrayList<>();
|
|
DecimalFormat decimalFormat = new DecimalFormat(".00");
|
|
DecimalFormat decimalFormat = new DecimalFormat(".00");
|
|
|
|
|
|
- try (ExcelReader reader = ExcelUtil.getReader(file.getPath(), 0)) {
|
|
|
|
|
|
+ try (ExcelReader reader = ExcelUtil.getReader(multipartFile.getInputStream(), 0)) {
|
|
reader.addHeaderAlias("序号", "id");
|
|
reader.addHeaderAlias("序号", "id");
|
|
reader.addHeaderAlias("机组名称", "fanName");
|
|
reader.addHeaderAlias("机组名称", "fanName");
|
|
reader.addHeaderAlias("风机容量KW", "fanUnitCapacity");
|
|
reader.addHeaderAlias("风机容量KW", "fanUnitCapacity");
|
|
@@ -170,7 +95,7 @@ public class ReadtoMysql {
|
|
|
|
|
|
for (int sheelIndex = 1; sheelIndex <= 8; sheelIndex++) {
|
|
for (int sheelIndex = 1; sheelIndex <= 8; sheelIndex++) {
|
|
// 读取风速数据 sheet
|
|
// 读取风速数据 sheet
|
|
- ExcelReader readerWind = ExcelUtil.getReader(modleParamFilePath, sheelIndex);
|
|
|
|
|
|
+ ExcelReader readerWind = ExcelUtil.getReader(multipartFile.getInputStream(), sheelIndex);
|
|
List<Map<String, Object>> readMap = readerWind.readAll();
|
|
List<Map<String, Object>> readMap = readerWind.readAll();
|
|
int belong = 0;
|
|
int belong = 0;
|
|
for (Map<String, Object> map : readMap) {
|
|
for (Map<String, Object> map : readMap) {
|
|
@@ -203,46 +128,22 @@ public class ReadtoMysql {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
windSpeedPointInfoRepository.saveAll(windSpeedPointInfoList);
|
|
windSpeedPointInfoRepository.saveAll(windSpeedPointInfoList);
|
|
- } catch (cn.hutool.poi.exceptions.POIException e) {
|
|
|
|
|
|
+ } catch (POIException | IOException e) {
|
|
return ResponseVO.error(e);
|
|
return ResponseVO.error(e);
|
|
}
|
|
}
|
|
- //删除文件
|
|
|
|
- file.delete();
|
|
|
|
return ResponseVO.success(1);
|
|
return ResponseVO.success(1);
|
|
}
|
|
}
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 读取风速曲线
|
|
* 读取风速曲线
|
|
*/
|
|
*/
|
|
public static ResponseVO readWindTurbinePowerCurveMap(MultipartFile multipartFile) throws Exception {
|
|
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++) {
|
|
for (int sheelIndex = 10; sheelIndex <= 14; sheelIndex++) {
|
|
//读取风速曲线 sheet
|
|
//读取风速曲线 sheet
|
|
String sheetName;
|
|
String sheetName;
|
|
List<List<Object>> readRows;
|
|
List<List<Object>> readRows;
|
|
List<WindTurbinePowerCurve> windTurbinePowerCurves = new ArrayList<>();
|
|
List<WindTurbinePowerCurve> windTurbinePowerCurves = new ArrayList<>();
|
|
try (
|
|
try (
|
|
- ExcelReader readerWind = ExcelUtil.getReader(file.getPath(), sheelIndex)) {
|
|
|
|
|
|
+ ExcelReader readerWind = ExcelUtil.getReader(multipartFile.getInputStream(), sheelIndex)) {
|
|
sheetName = readerWind.getSheet().getSheetName();
|
|
sheetName = readerWind.getSheet().getSheetName();
|
|
//按行读取所有数据
|
|
//按行读取所有数据
|
|
readRows = readerWind.read();
|
|
readRows = readerWind.read();
|
|
@@ -262,39 +163,17 @@ public class ReadtoMysql {
|
|
return ResponseVO.error(e);
|
|
return ResponseVO.error(e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //删除文件
|
|
|
|
- file.delete();
|
|
|
|
return ResponseVO.success(1);
|
|
return ResponseVO.success(1);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 满发风速之后各风速发电曲线
|
|
|
|
|
|
+ * 切出风速
|
|
*
|
|
*
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static ResponseVO readFanCutOutSpeedInfo(MultipartFile multipartFile) throws SQLException, IOException {
|
|
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;
|
|
List<CutOutSpeedSpecifyInfo> cutOutSpeedSpecifyInfoList;
|
|
- try (ExcelReader reader = ExcelUtil.getReader(file.getPath(), 9)) {
|
|
|
|
|
|
+ try (ExcelReader reader = ExcelUtil.getReader(multipartFile.getInputStream(), 9)) {
|
|
reader.addHeaderAlias("序号", "id");
|
|
reader.addHeaderAlias("序号", "id");
|
|
reader.addHeaderAlias("风速下限(包含)m/s", "lowerWindSpeedLimit");
|
|
reader.addHeaderAlias("风速下限(包含)m/s", "lowerWindSpeedLimit");
|
|
reader.addHeaderAlias("风速上限(不包含)m/s", "highWindSpeedLimit");
|
|
reader.addHeaderAlias("风速上限(不包含)m/s", "highWindSpeedLimit");
|
|
@@ -304,7 +183,6 @@ public class ReadtoMysql {
|
|
for (CutOutSpeedSpecifyInfo cs : cutOutSpeedSpecifyInfoList) {
|
|
for (CutOutSpeedSpecifyInfo cs : cutOutSpeedSpecifyInfoList) {
|
|
Db.use().insertForGeneratedKey(
|
|
Db.use().insertForGeneratedKey(
|
|
Entity.create("t_cut_out_speed_specify_info")
|
|
Entity.create("t_cut_out_speed_specify_info")
|
|
-// .set("C_ID",cs.getId())
|
|
|
|
.set("C_LOWER_WIND_SPEED_LIMIT", cs.getLowerWindSpeedLimit())
|
|
.set("C_LOWER_WIND_SPEED_LIMIT", cs.getLowerWindSpeedLimit())
|
|
.set("C_HIGH_WIND_SPEED_LIMIT", cs.getHighWindSpeedLimit())
|
|
.set("C_HIGH_WIND_SPEED_LIMIT", cs.getHighWindSpeedLimit())
|
|
.set("C_POWER_GENERATION", cs.getPowerGeneration())
|
|
.set("C_POWER_GENERATION", cs.getPowerGeneration())
|
|
@@ -314,10 +192,6 @@ public class ReadtoMysql {
|
|
} catch (cn.hutool.poi.exceptions.POIException e) {
|
|
} catch (cn.hutool.poi.exceptions.POIException e) {
|
|
return ResponseVO.error(e);
|
|
return ResponseVO.error(e);
|
|
}
|
|
}
|
|
- //删除文件
|
|
|
|
- file.delete();
|
|
|
|
return ResponseVO.success(1);
|
|
return ResponseVO.success(1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|