|
@@ -0,0 +1,224 @@
|
|
|
+package com.jiayue.ipfcst.util;
|
|
|
+
|
|
|
+import cn.hutool.db.Db;
|
|
|
+import cn.hutool.db.Entity;
|
|
|
+import cn.hutool.poi.excel.ExcelReader;
|
|
|
+import cn.hutool.poi.excel.ExcelUtil;
|
|
|
+import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.CutOutSpeedSpecifyInfo;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.FanUnitInfo;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.WindSpeedPointInfo;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.WindTurbinePowerCurve;
|
|
|
+import com.jiayue.ipfcst.common.data.repository.WindSpeedPointInfoRepository;
|
|
|
+import com.jiayue.ipfcst.common.data.repository.WindTurbinePowerCurveRepository;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author shd
|
|
|
+ * @since 2022-06-01
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class ReadtoMysql {
|
|
|
+ //模板配置文件路径
|
|
|
+ public static String modleParamFilePath = "C:\\Users\\song\\Desktop\\单风机法模板-all.xlsx";
|
|
|
+
|
|
|
+
|
|
|
+ private static WindSpeedPointInfoRepository windSpeedPointInfoRepository;
|
|
|
+ private static WindTurbinePowerCurveRepository windTurbinePowerCurveRepository;
|
|
|
+ @Autowired
|
|
|
+ public void setWindSpeedPointInfoRepository(WindSpeedPointInfoRepository windSpeedPointInfoRepository){
|
|
|
+ ReadtoMysql.windSpeedPointInfoRepository = windSpeedPointInfoRepository;
|
|
|
+ }
|
|
|
+ @Autowired
|
|
|
+ public void setWindTurbinePowerCurveRepository(WindTurbinePowerCurveRepository windTurbinePowerCurveRepository){
|
|
|
+ ReadtoMysql.windTurbinePowerCurveRepository = windTurbinePowerCurveRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) throws Exception{
|
|
|
+// 读取机组信息到数据库
|
|
|
+// readFanUnitInfo();
|
|
|
+ /**
|
|
|
+ * 读取风速点表到数据库
|
|
|
+ */
|
|
|
+// readSpeedSheet();
|
|
|
+ /**
|
|
|
+ * 机组功率曲线
|
|
|
+ */
|
|
|
+// readWindTurbinePowerCurveMap();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 切出
|
|
|
+ */
|
|
|
+// readFanCutOutSpeedInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取机组信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static ResponseVO readFanUnitInfo() throws Exception{
|
|
|
+ //机组信息读取 sheet 0
|
|
|
+ List<FanUnitInfo> fanUnitInfoList;
|
|
|
+ try (ExcelReader reader = ExcelUtil.getReader(modleParamFilePath, 0)) {
|
|
|
+ reader.addHeaderAlias("序号", "id");
|
|
|
+ reader.addHeaderAlias("机组名称", "fanName");
|
|
|
+ reader.addHeaderAlias("风机容量KW", "fanUnitCapacity");
|
|
|
+ reader.addHeaderAlias("满发风速(m/s)", "fullWindSpeed");
|
|
|
+ reader.addHeaderAlias("切出停机风速(m/s)", "cutOutSpeed");
|
|
|
+ reader.addHeaderAlias("标杆风机编号", "benchmarkFan");
|
|
|
+ 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())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }catch (cn.hutool.poi.exceptions.POIException e){
|
|
|
+ return ResponseVO.error(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseVO.success(1);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取 东北风向风速 东南风向风速 西南风向风速 西北风向风速 4个sheet表风速点表
|
|
|
+ */
|
|
|
+ public static ResponseVO readSpeedSheet() throws SQLException {
|
|
|
+ Map<Integer,List<String>> fanidInfo = new HashMap<>();
|
|
|
+ List<WindSpeedPointInfo> windSpeedPointInfoList = new ArrayList<>();
|
|
|
+ DecimalFormat decimalFormat=new DecimalFormat(".00");
|
|
|
+
|
|
|
+ try (ExcelReader reader = ExcelUtil.getReader(modleParamFilePath, 0)) {
|
|
|
+ reader.addHeaderAlias("序号", "id");
|
|
|
+ reader.addHeaderAlias("机组名称", "fanName");
|
|
|
+ reader.addHeaderAlias("风机容量KW", "fanUnitCapacity");
|
|
|
+ reader.addHeaderAlias("满发风速(m/s)", "fullWindSpeed");
|
|
|
+ reader.addHeaderAlias("切出停机风速(m/s)", "cutOutSpeed");
|
|
|
+ reader.addHeaderAlias("标杆风机编号", "benchmarkFan");
|
|
|
+ reader.addHeaderAlias("风机编号(多个风机使用竖线分割)", "fanNumArrs");
|
|
|
+
|
|
|
+ List<FanUnitInfo> fanUnitInfoList = reader.readAll(FanUnitInfo.class);
|
|
|
+
|
|
|
+ for (FanUnitInfo fanUnitInfo :
|
|
|
+ fanUnitInfoList) {
|
|
|
+ fanidInfo.put(fanUnitInfo.getId(), Arrays.asList(fanUnitInfo.getFanNumArrs().split("\\|")));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int sheelIndex = 1; sheelIndex <= 8; sheelIndex++) {
|
|
|
+ // 读取风速数据 sheet
|
|
|
+ ExcelReader readerWind = ExcelUtil.getReader(modleParamFilePath, sheelIndex);
|
|
|
+ List<Map<String, Object>> readMap = readerWind.readAll();
|
|
|
+ int belong = 0;
|
|
|
+ for (Map<String, Object> map : readMap) {
|
|
|
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
+ // 风机id
|
|
|
+ String fengid = entry.getKey();
|
|
|
+ // 风速
|
|
|
+ String speed = decimalFormat.format(entry.getValue());
|
|
|
+ if (fengid.equals("#14#")) {
|
|
|
+ belong += 1;
|
|
|
+ }
|
|
|
+ if ("序号".equals(fengid)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 所属机组
|
|
|
+ int jizuid = 0;
|
|
|
+ for (Integer key : fanidInfo.keySet()) {
|
|
|
+ if (fanidInfo.get(key).contains(fengid)) {
|
|
|
+ jizuid = key;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WindSpeedPointInfo windSpeedPointInfo = new WindSpeedPointInfo();
|
|
|
+ windSpeedPointInfo.setFanNumber(fengid);
|
|
|
+ windSpeedPointInfo.setWind(sheelIndex);
|
|
|
+ windSpeedPointInfo.setSpeed(Float.parseFloat(speed));
|
|
|
+ windSpeedPointInfo.setUnitBelongs(jizuid);
|
|
|
+ windSpeedPointInfo.setBelong(belong);
|
|
|
+ windSpeedPointInfoList.add(windSpeedPointInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ windSpeedPointInfoRepository.saveAll(windSpeedPointInfoList);
|
|
|
+ }catch (cn.hutool.poi.exceptions.POIException e){
|
|
|
+ return ResponseVO.error(e);
|
|
|
+ }
|
|
|
+ return ResponseVO.success(1);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 读取风速曲线
|
|
|
+ */
|
|
|
+ public static ResponseVO readWindTurbinePowerCurveMap() throws SQLException {
|
|
|
+ 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)) {
|
|
|
+ sheetName = readerWind.getSheet().getSheetName();
|
|
|
+ //按行读取所有数据
|
|
|
+ readRows = readerWind.read();
|
|
|
+ for(List<Object> r: readRows){
|
|
|
+ if(String.valueOf(r.get(0)).contains("风")){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ WindTurbinePowerCurve windTurbinePowerCurve = new WindTurbinePowerCurve();
|
|
|
+ windTurbinePowerCurve.setSpeed(Float.parseFloat(String.valueOf(r.get(0))));
|
|
|
+ windTurbinePowerCurve.setPower(Float.parseFloat(String.valueOf(r.get(1))));
|
|
|
+ windTurbinePowerCurve.setFanId(Integer.parseInt(sheetName.split("-")[0]));
|
|
|
+ windTurbinePowerCurves.add(windTurbinePowerCurve);
|
|
|
+ }
|
|
|
+
|
|
|
+ windTurbinePowerCurveRepository.saveAll(windTurbinePowerCurves);
|
|
|
+ }catch (cn.hutool.poi.exceptions.POIException e){
|
|
|
+ return ResponseVO.error(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseVO.success(1);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 满发风速之后各风速发电曲线
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static ResponseVO readFanCutOutSpeedInfo() throws SQLException {
|
|
|
+ //机组信息读取 sheet 0
|
|
|
+ List<CutOutSpeedSpecifyInfo> cutOutSpeedSpecifyInfoList;
|
|
|
+ try (ExcelReader reader = ExcelUtil.getReader(modleParamFilePath, 9)) {
|
|
|
+ reader.addHeaderAlias("序号", "id");
|
|
|
+ reader.addHeaderAlias("风速下限(包含)m/s", "lowerWindSpeedLimit");
|
|
|
+ reader.addHeaderAlias("风速上限(不包含)m/s", "highWindSpeedLimit");
|
|
|
+ reader.addHeaderAlias("发电功率kW", "powerGeneration");
|
|
|
+ reader.addHeaderAlias("所属机组", "UnitBelongs");
|
|
|
+ cutOutSpeedSpecifyInfoList = reader.readAll(CutOutSpeedSpecifyInfo.class);
|
|
|
+ for(CutOutSpeedSpecifyInfo cs : cutOutSpeedSpecifyInfoList){
|
|
|
+ Db.use().insertForGeneratedKey(
|
|
|
+ Entity.create("t_cut_out_speed_specify_info")
|
|
|
+// .set("C_ID",cs.getId())
|
|
|
+ .set("C_LOWER_WIND_SPEED_LIMIT",cs.getLowerWindSpeedLimit())
|
|
|
+ .set("C_HIGH_WIND_SPEED_LIMIT",cs.getHighWindSpeedLimit())
|
|
|
+ .set("C_POWER_GENERATION",cs.getPowerGeneration())
|
|
|
+ .set("C_UNIT_BELONGS",cs.getFanId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } catch (cn.hutool.poi.exceptions.POIException e){
|
|
|
+ return ResponseVO.error(e);
|
|
|
+ }
|
|
|
+ return ResponseVO.success(1);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|