Browse Source

添加适配器stat(区间数据,avg,min,max实体类)

malijun 1 year ago
parent
commit
2a9e61fa25

+ 76 - 0
electricity/meter/src/main/java/com/gyee/gaia/meter/entity/TDEquipmentMeterInfo.java

@@ -0,0 +1,76 @@
+package com.gyee.gaia.meter.entity;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 风机信息(1分钟平均风速,理论功率,实际功率,理论发电量,实际发电量等)
+ * </p>
+ */
+@TableName("equipmentmeterinfo")
+@Data
+@DS("meter")
+public class TDEquipmentMeterInfo extends Model<TDEquipmentMeterInfo> implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 子表名
+     */
+    private String tbName;
+
+
+    /**
+     * 时间
+     */
+    private long  ts;
+    /**
+     * 1分钟平均风速
+     */
+    private double speed;
+
+    /**
+     * 理论功率
+     */
+    private double theoreticalPower;
+
+    /**
+     * 实际功率
+     */
+    private double actualPower;
+
+    /**
+     * 理论发电量
+     */
+    private double TheoreticalPowerGeneration;
+
+    /**
+     * 实际发电量
+     */
+    private double actualGeneration;
+
+
+
+
+    /**
+     * 型号
+     */
+    private String model;
+
+    /**
+     * 场站
+     */
+    private String station;
+
+
+
+
+
+
+
+}

+ 59 - 0
electricity/meter/src/main/java/com/gyee/gaia/meter/mapper/TDEquipmentMeterInfoMapper.java

@@ -0,0 +1,59 @@
+package com.gyee.gaia.meter.mapper;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.gyee.gaia.meter.entity.TDEquipmentMeterInfo;
+import com.gyee.gaia.meter.entity.TDLineFDL15Min;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+
+@Mapper
+@DS("meter")
+public interface TDEquipmentMeterInfoMapper extends BaseMapper<TDEquipmentMeterInfo> {
+
+    /**
+     * 插入数据,sql拼接字符串
+     * @param entity 后面拼的字符串
+     */
+    @Insert("insert into ${entity}")
+    int insert(String entity);
+
+
+    /**
+     * 插入数据,如果没有表则使用超级表自动建表
+     * @param tbName 子表名
+     * @param powerstationId 场站ID
+     * @param projectId 期次
+     * @param name 名称
+     * @param ts 时间戳
+     * @param bottom 底码
+     * @param meter 电量
+     */
+    @Insert("INSERT INTO #{tbName} USING equipmentmeterinfo TAGS(#{model},#{station}) VALUES (#{ts}, #{speed},#{theoreticalPower},#{actualPower},#{TheoreticalPowerGeneration},#{actualGeneration})")
+    void insertTDEquiomentMeterInfo(
+            @Param("tbName") String tbName,
+            @Param("model") String model,
+            @Param("station") String station,
+            @Param("ts") long ts,
+            @Param("speed") double speed,
+            @Param("theoreticalPower") double theoreticalPower,
+            @Param("actualPower") double actualPower,
+            @Param("TheoreticalPowerGeneration") double TheoreticalPowerGeneration,
+            @Param("actualGeneration") double actualGeneration
+
+    );
+
+
+    /**
+     * 查询
+     */
+    @Select("select tbname,* from  linefdl15min")
+    List<TDLineFDL15Min> selectLineFDL15Min1();
+
+
+}

+ 16 - 0
electricity/meter/src/main/java/com/gyee/gaia/meter/service/iService/ITDEquipmentMeterInfoService.java

@@ -0,0 +1,16 @@
+package com.gyee.gaia.meter.service.iService;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.gyee.gaia.meter.entity.TDEquipmentMeterInfo;
+
+/**
+ * <p>
+ * 公司日发电量表 服务类
+ * </p>
+ *
+ * @author gfhd
+ * @since 2023-04-28
+ */
+public interface ITDEquipmentMeterInfoService extends IService<TDEquipmentMeterInfo> {
+
+}

+ 27 - 0
electricity/meter/src/main/java/com/gyee/gaia/meter/service/impl/TDEquipmentMeterInfoServiceImpl.java

@@ -0,0 +1,27 @@
+package com.gyee.gaia.meter.service.impl;
+
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.gaia.meter.entity.TDEquipmentMeterInfo;
+import com.gyee.gaia.meter.mapper.TDEquipmentMeterInfoMapper;
+import com.gyee.gaia.meter.mapper.TDLineFDL15MinMapper;
+import com.gyee.gaia.meter.service.iService.ITDEquipmentMeterInfoService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+@Service
+public class TDEquipmentMeterInfoServiceImpl extends ServiceImpl<TDEquipmentMeterInfoMapper, TDEquipmentMeterInfo> implements ITDEquipmentMeterInfoService {
+
+    @Resource
+    TDLineFDL15MinMapper tdLineFDL15MinMapper;
+
+    public int saveBatch() {
+
+        int count = 0;
+
+            count += tdLineFDL15MinMapper.insert(" MHSDJL_NX_GD_MHSF_DD_P1_L1_001_ZXYG045  VALUES (NOW, 888);");
+
+        return count;
+    }
+}

+ 0 - 434
electricity/meter/src/main/java/com/gyee/gaia/meter/service/saveTDengine/TDSaveLLFDL1MinTest.java

@@ -1,434 +0,0 @@
-package com.gyee.gaia.meter.service.saveTDengine;
-
-import cn.hutool.core.date.DateTime;
-import cn.hutool.core.date.DateUtil;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gyee.gaia.meter.adapter.Adapter;
-import com.gyee.gaia.meter.entity.*;
-import com.gyee.gaia.meter.service.impl.EquipmentServiceImpl;
-import com.gyee.gaia.meter.service.impl.ModelPowerDetailsServiceImpl;
-import com.gyee.gaia.meter.service.impl.TestingPointServiceImpl;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.test.context.SpringBootTest;
-
-import javax.annotation.Resource;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Author: malijun
- * Data  : 2023: 04: 27
- **/
-@SpringBootTest
-class TDSaveLLFDL1MinTest {
-
-    @Resource
-    Adapter adapter;
-    @Resource
-    private EquipmentServiceImpl equipmentService;
-    @Resource
-    private ModelPowerDetailsServiceImpl modelPowerDetailsService;
-    @Resource
-    private TestingPointServiceImpl testingPointService;
-
-    @Value("${start.time}")
-    private String startTimeString;
-    @Value("${end.time}")
-    private String endTimeString;
-
-    /*
-     * 日理论发电量(每台风机,综合到每个场站,每个期次,每条线路)
-     * 1分钟平均风速乘model_power_details的理论功率
-     * w=pt,理论功率乘时间(kw/h)除以60为1分钟理论发电量
-     * pro_basic_equipment表中获取到所有风机,每台风机型号等
-     * uniFormCode AI022 从testing_point中获取到所有风速测点
-     * 从适配器中取1分钟平均风速,根据风速从model_power_details中取到理论功率
-     * 计算1分钟理论发电量
-     * 保存到taos数据库中
-     */
-
-    //理论发电量
-    @Test
-    public void llfdl_1Min() {
-
-        //设置取值开始时间
-        String startString = startTimeString;
-        DateTime startDateTime = DateUtil.parse(startString);
-
-        //设置取值结束时间
-        String endDateString = endTimeString;
-        DateTime endDateTime0 = DateUtil.parse(endDateString);
-        DateTime endDateTime = DateUtil.endOfDay(endDateTime0);
-
-        //从pro_basic_equipment(实体类为Equipment)表中获取到所有风机,每台风机型号等
-        List<Equipment> equipmentList = equipmentService.list(new QueryWrapper<Equipment>()
-                .eq("spare1", "WT")
-        );
-
-        //model_power_details表中获取到所有型号各风速对应的理论功率
-        List<ModelPowerDetails> modelPowerDetailsList = modelPowerDetailsService.list();
-
-        //遍历modelPowerDetailsList,放入map集合中,键为model_id,值为map集合,值的map集合的键为speed,值为theory_power
-        Map<String, Map<BigDecimal, Double>> map = new HashMap<>();
-        for (ModelPowerDetails modelPowerDetails : modelPowerDetailsList) {
-            String modelId = modelPowerDetails.getModelId();
-            double speed0 = modelPowerDetails.getSpeed();
-            BigDecimal speed = new BigDecimal(speed0).setScale(2, RoundingMode.HALF_EVEN);
-            Double theoryPower = modelPowerDetails.getTheoryPower();
-
-            // 检查是否已存在该modelId的映射关系
-            if (map.containsKey(modelId)) {
-                // 如果已存在,获取对应的内层HashMap,并添加新的映射关系
-                Map<BigDecimal, Double> innerMap = map.get(modelId);
-                innerMap.put(speed, theoryPower);
-            } else {
-                // 如果不存在,创建新的内层HashMap,并添加映射关系
-                Map<BigDecimal, Double> innerMap = new HashMap<>();
-                innerMap.put(speed, theoryPower);
-                map.put(modelId, innerMap);
-            }
-        }
-
-
-        //根据uniform_code=AI130从testing_point表中获取到风机的实际功率测点
-        List<TestingPoint> testingPointList1 = testingPointService.list(new QueryWrapper<TestingPoint>()
-                .eq("uniform_code", "AI022")
-        );
-        //遍历testingPointList1,把code取出放入一个string集合
-        List<String> codeList1 = new ArrayList<>();
-        for (TestingPoint testingPoint : testingPointList1) {
-            String code = testingPoint.getCode();
-            codeList1.add(code);
-        }
-        //遍历codeList作为适配器的参数,获取到1分钟实际平均功率
-        for (String code : codeList1) {
-            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
-
-        }
-
-        //根据uniform_code=AI022从testing_point表中获取到风机的风速测点
-        List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>()
-                .eq("uniform_code", "AI022")
-        );
-        //遍历testingPointList,把code取出放入一个string集合
-        List<String> codeList = new ArrayList<>();
-        for (TestingPoint testingPoint : testingPointList) {
-            String code = testingPoint.getCode();
-            codeList.add(code);
-        }
-
-        //新建一个map,键为风机编码,值为map集合,值的map集合的键为时间,值为1分钟理论发电量
-        Map<String, Map<Long, BigDecimal>> map1 = new HashMap<>();
-
-        //遍历codeList作为适配器的参数,获取到1分钟平均风速
-        for (String code : codeList) {
-            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
-
-            //遍历testingPointList,根据code取到风机编码thing_id
-            for (TestingPoint testingPoint : testingPointList) {
-                String code1 = testingPoint.getCode();
-                if (code.equals(code1)) {
-                    String thingId = testingPoint.getThingId();
-                    //根据thingId从equipmentList中取出型号
-                    for (Equipment equipment : equipmentList) {
-                        String nemCode = equipment.getNemCode();
-                        if (thingId.equals(nemCode)) {
-                            String modelId = equipment.getModelId();
-                            //根据modelId从map中取出map集合,键为speed,值为theory_power
-                            Map<BigDecimal, Double> map2 = map.get(modelId);
-                            //遍历pointDataList,拿到风速,根据风速从map2中取到理论功率,计算1分钟理论发电量
-                            for (PointDatas pointData : pointDataList) {
-                                //风速
-                                double speed0 = pointData.getAvg().getValue();
-                                BigDecimal speed = new BigDecimal(speed0).setScale(2, RoundingMode.HALF_EVEN);
-
-                                Double theoryPower = 0.0;
-                                if (speed0 >= 3 && speed0 <= 25) {
-                                    //理论功率
-                                    theoryPower = map2.get(speed);
-                                }
-                                //时间
-                                DateTime dateTime = DateTime.of(pointData.getAvg().getTs());
-
-
-                                BigDecimal llfdl = BigDecimal.valueOf(0);
-                                //1分钟理论发电量
-                                if (theoryPower != null) {
-                                    llfdl = new BigDecimal(Double.toString(theoryPower))
-                                            .multiply(new BigDecimal(Double.toString(1)))
-                                            .divide(new BigDecimal(Double.toString(60)), 2, RoundingMode.HALF_UP);
-                                }
-
-
-                                //存入map1,键为风机编码,值为map集合,值的map集合的键为时间,值为1分钟理论发电量
-                                if (map1.containsKey(nemCode)) {
-                                    // 如果已存在,获取对应的内层HashMap,并添加新的映射关系
-                                    Map<Long, BigDecimal> innerMap = map1.get(nemCode);
-                                    innerMap.put(dateTime.getTime(), llfdl);
-                                } else {
-                                    // 如果不存在,创建新的内层HashMap,并添加映射关系
-                                    Map<Long, BigDecimal> innerMap = new HashMap<>();
-                                    innerMap.put(dateTime.getTime(), llfdl);
-                                    map1.put(nemCode, innerMap);
-                                }
-
-                            }
-
-
-                        }
-                    }
-                }
-
-
-            }
-        }
-
-        HashMap<String, BigDecimal> map2 = new HashMap<>();
-        for (String key : map1.keySet()) {
-            Map<Long, BigDecimal> mapValues = map1.get(key);
-            BigDecimal llfdl = BigDecimal.valueOf(0);
-            for (BigDecimal mapValue : mapValues.values()) {
-                llfdl = llfdl.add(mapValue);
-            }
-            map2.put(key, llfdl);
-        }
-
-        BigDecimal mhsllfdl = BigDecimal.valueOf(0);
-        BigDecimal nssllfdl = BigDecimal.valueOf(0);
-        BigDecimal qsllfdl = BigDecimal.valueOf(0);
-        BigDecimal sbqllfdl = BigDecimal.valueOf(0);
-        BigDecimal xsllfdl = BigDecimal.valueOf(0);
-
-        for (String key : map2.keySet()) {
-            if (key.contains("NX_GDDL_MHS_F_WT_")) {
-                mhsllfdl = mhsllfdl.add(map2.get(key));
-            }
-            if (key.contains("NX_GDDL_NSS_F_WT_")) {
-                nssllfdl = nssllfdl.add(map2.get(key));
-            }
-            if (key.contains("NX_GDDL_QS_F_WT_")) {
-                qsllfdl = qsllfdl.add(map2.get(key));
-            }
-            if (key.contains("NX_GDDL_SBQ_F_WT_")) {
-                sbqllfdl = sbqllfdl.add(map2.get(key));
-            }
-            if (key.contains("NX_GDDL_XS_F_WT_")) {
-                xsllfdl = xsllfdl.add(map2.get(key));
-            }
-
-
-        }
-        System.out.println("麻黄山理论发电量:" + mhsllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
-        System.out.println("牛首山理论发电量:" + nssllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
-        System.out.println("青山理论发电量:" + qsllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
-        System.out.println("石板泉理论发电量:" + sbqllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
-        System.out.println("香山理论发电量:" + xsllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
-
-
-
-
-    }
-
-    //理论发电量
-    @Test
-    public void llfdl_1Min1() {
-
-        //设置取值开始时间
-        String startString = startTimeString;
-        DateTime startDateTime = DateUtil.parse(startString);
-
-        //设置取值结束时间
-        String endDateString = endTimeString;
-        DateTime endDateTime0 = DateUtil.parse(endDateString);
-        DateTime endDateTime = DateUtil.endOfDay(endDateTime0);
-
-        //从pro_basic_equipment(实体类为Equipment)表中获取到所有风机,每台风机型号等
-        List<Equipment> equipmentList = equipmentService.list(new QueryWrapper<Equipment>()
-                .eq("spare1", "WT")
-        );
-
-        //model_power_details表中获取到所有型号各风速对应的理论功率
-        List<ModelPowerDetails> modelPowerDetailsList = modelPowerDetailsService.list();
-
-        //遍历modelPowerDetailsList,放入map集合中,键为model_id,值为map集合,值的map集合的键为speed,值为theory_power
-        Map<String, Map<BigDecimal, Double>> map = new HashMap<>();
-        for (ModelPowerDetails modelPowerDetails : modelPowerDetailsList) {
-            String modelId = modelPowerDetails.getModelId();
-            double speed0 = modelPowerDetails.getSpeed();
-            BigDecimal speed = new BigDecimal(speed0).setScale(2, RoundingMode.HALF_EVEN);
-            Double theoryPower = modelPowerDetails.getTheoryPower();
-
-            // 检查是否已存在该modelId的映射关系
-            if (map.containsKey(modelId)) {
-                // 如果已存在,获取对应的内层HashMap,并添加新的映射关系
-                Map<BigDecimal, Double> innerMap = map.get(modelId);
-                innerMap.put(speed, theoryPower);
-            } else {
-                // 如果不存在,创建新的内层HashMap,并添加映射关系
-                Map<BigDecimal, Double> innerMap = new HashMap<>();
-                innerMap.put(speed, theoryPower);
-                map.put(modelId, innerMap);
-            }
-        }
-
-
-        //根据uniform_code=AI130从testing_point表中获取到风机的实际功率测点
-        List<TestingPoint> testingPointList1 = testingPointService.list(new QueryWrapper<TestingPoint>()
-                .eq("uniform_code", "AI022")
-        );
-        //遍历testingPointList1,把code取出放入一个string集合
-        List<String> codeList1 = new ArrayList<>();
-        for (TestingPoint testingPoint : testingPointList1) {
-            String code = testingPoint.getCode();
-            codeList1.add(code);
-        }
-        //遍历codeList作为适配器的参数,获取到1分钟实际平均功率
-        for (String code : codeList1) {
-            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
-
-        }
-
-        //根据uniform_code=AI022从testing_point表中获取到风机的风速测点
-        List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>()
-                .eq("uniform_code", "AI022")
-        );
-        //遍历testingPointList,把code取出放入一个string集合
-        List<String> codeList = new ArrayList<>();
-        for (TestingPoint testingPoint : testingPointList) {
-            String code = testingPoint.getCode();
-            codeList.add(code);
-        }
-
-        //新建一个map,键为风机编码,值为map集合,值的map集合的键为时间,值为1分钟理论发电量
-        Map<String, Map<Long, BigDecimal>> map1 = new HashMap<>();
-
-        //遍历codeList作为适配器的参数,获取到1分钟平均风速
-        for (String code : codeList) {
-            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
-
-            //遍历testingPointList,根据code取到风机编码thing_id
-            for (TestingPoint testingPoint : testingPointList) {
-                String code1 = testingPoint.getCode();
-                if (code.equals(code1)) {
-                    String thingId = testingPoint.getThingId();
-                    //根据thingId从equipmentList中取出型号
-                    for (Equipment equipment : equipmentList) {
-                        String nemCode = equipment.getNemCode();
-                        if (thingId.equals(nemCode)) {
-                            String modelId = equipment.getModelId();
-                            //根据modelId从map中取出map集合,键为speed,值为theory_power
-                            Map<BigDecimal, Double> map2 = map.get(modelId);
-                            //遍历pointDataList,拿到风速,根据风速从map2中取到理论功率,计算1分钟理论发电量
-                            for (PointDatas pointData : pointDataList) {
-                                //风速
-                                double speed0 = pointData.getAvg().getValue();
-                                BigDecimal speed = new BigDecimal(speed0).setScale(2, RoundingMode.HALF_EVEN);
-
-                                Double theoryPower = 0.0;
-                                if (speed0 >= 3 && speed0 <= 25) {
-                                    //理论功率
-                                    theoryPower = map2.get(speed);
-                                }
-
-
-
-
-
-
-                                //时间
-                                DateTime dateTime = DateTime.of(pointData.getAvg().getTs());
-
-
-                                BigDecimal llfdl = BigDecimal.valueOf(0);
-                                //1分钟理论发电量
-                                if (theoryPower != null) {
-                                    llfdl = new BigDecimal(Double.toString(theoryPower))
-                                            .multiply(new BigDecimal(Double.toString(1)))
-                                            .divide(new BigDecimal(Double.toString(60)), 2, RoundingMode.HALF_UP);
-                                }
-
-
-                                //存入map1,键为风机编码,值为map集合,值的map集合的键为时间,值为1分钟理论发电量
-                                if (map1.containsKey(nemCode)) {
-                                    // 如果已存在,获取对应的内层HashMap,并添加新的映射关系
-                                    Map<Long, BigDecimal> innerMap = map1.get(nemCode);
-                                    innerMap.put(dateTime.getTime(), llfdl);
-                                } else {
-                                    // 如果不存在,创建新的内层HashMap,并添加映射关系
-                                    Map<Long, BigDecimal> innerMap = new HashMap<>();
-                                    innerMap.put(dateTime.getTime(), llfdl);
-                                    map1.put(nemCode, innerMap);
-                                }
-
-                            }
-
-
-                        }
-                    }
-                }
-
-
-            }
-        }
-
-        HashMap<String, BigDecimal> map2 = new HashMap<>();
-        for (String key : map1.keySet()) {
-            Map<Long, BigDecimal> mapValues = map1.get(key);
-            BigDecimal llfdl = BigDecimal.valueOf(0);
-            for (BigDecimal mapValue : mapValues.values()) {
-                llfdl = llfdl.add(mapValue);
-            }
-            map2.put(key, llfdl);
-        }
-
-        BigDecimal mhsllfdl = BigDecimal.valueOf(0);
-        BigDecimal nssllfdl = BigDecimal.valueOf(0);
-        BigDecimal qsllfdl = BigDecimal.valueOf(0);
-        BigDecimal sbqllfdl = BigDecimal.valueOf(0);
-        BigDecimal xsllfdl = BigDecimal.valueOf(0);
-
-        for (String key : map2.keySet()) {
-            if (key.contains("NX_GDDL_MHS_F_WT_")) {
-                mhsllfdl = mhsllfdl.add(map2.get(key));
-            }
-            if (key.contains("NX_GDDL_NSS_F_WT_")) {
-                nssllfdl = nssllfdl.add(map2.get(key));
-            }
-            if (key.contains("NX_GDDL_QS_F_WT_")) {
-                qsllfdl = qsllfdl.add(map2.get(key));
-            }
-            if (key.contains("NX_GDDL_SBQ_F_WT_")) {
-                sbqllfdl = sbqllfdl.add(map2.get(key));
-            }
-            if (key.contains("NX_GDDL_XS_F_WT_")) {
-                xsllfdl = xsllfdl.add(map2.get(key));
-            }
-
-
-        }
-        System.out.println("麻黄山理论发电量:" + mhsllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
-        System.out.println("牛首山理论发电量:" + nssllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
-        System.out.println("青山理论发电量:" + qsllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
-        System.out.println("石板泉理论发电量:" + sbqllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
-        System.out.println("香山理论发电量:" + xsllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
-
-
-
-
-    }
-
-}
-
-
-
-
-
-
-
-
-

+ 706 - 0
electricity/meter/src/main/java/com/gyee/gaia/meter/service/saveTDengine/TDSaveLLFDLTest.java

@@ -0,0 +1,706 @@
+package com.gyee.gaia.meter.service.saveTDengine;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.gyee.gaia.meter.adapter.Adapter;
+import com.gyee.gaia.meter.entity.*;
+import com.gyee.gaia.meter.mapper.TDEquipmentMeterInfoMapper;
+import com.gyee.gaia.meter.service.impl.EquipmentServiceImpl;
+import com.gyee.gaia.meter.service.impl.ModelPowerDetailsServiceImpl;
+import com.gyee.gaia.meter.service.impl.TestingPointServiceImpl;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
+
+/**
+ * Author: malijun
+ * Data  : 2023: 04: 27
+ **/
+@SpringBootTest
+class TDSaveLLFDLTest {
+
+    @Resource
+    Adapter adapter;
+    @Resource
+    private EquipmentServiceImpl equipmentService;
+    @Resource
+    private ModelPowerDetailsServiceImpl modelPowerDetailsService;
+    @Resource
+    private TestingPointServiceImpl testingPointService;
+
+    @Resource
+    private TDEquipmentMeterInfoMapper tdEquipmentMeterInfoMapper;
+
+    @Value("${start.time}")
+    private String startTimeString;
+    @Value("${end.time}")
+    private String endTimeString;
+
+    /*
+     * 日理论发电量(每台风机,综合到每个场站,每个期次,每条线路)
+     * 1分钟平均风速乘model_power_details的理论功率
+     * w=pt,理论功率乘时间(kw/h)除以60为1分钟理论发电量
+     * pro_basic_equipment表中获取到所有风机,每台风机型号等
+     * uniFormCode AI022 从testing_point中获取到所有风速测点
+     * 从适配器中取1分钟平均风速,根据风速从model_power_details中取到理论功率
+     * 计算1分钟理论发电量
+     * 保存到taos数据库中
+     */
+
+    //理论发电量
+    @Test
+    public void llfdl_1Min() {
+
+        //设置取值开始时间
+        String startString = startTimeString;
+        DateTime startDateTime = DateUtil.parse(startString);
+
+        //设置取值结束时间
+        String endDateString = endTimeString;
+        DateTime endDateTime0 = DateUtil.parse(endDateString);
+        DateTime endDateTime = DateUtil.endOfDay(endDateTime0);
+
+        //从pro_basic_equipment(实体类为Equipment)表中获取到所有风机,每台风机型号等
+        List<Equipment> equipmentList = equipmentService.list(new QueryWrapper<Equipment>()
+                .eq("spare1", "WT")
+        );
+
+        //model_power_details表中获取到所有型号各风速对应的理论功率
+        List<ModelPowerDetails> modelPowerDetailsList = modelPowerDetailsService.list();
+
+        //遍历modelPowerDetailsList,放入map集合中,键为model_id,值为map集合,值的map集合的键为speed,值为theory_power
+        Map<String, Map<BigDecimal, Double>> map = new HashMap<>();
+        for (ModelPowerDetails modelPowerDetails : modelPowerDetailsList) {
+            String modelId = modelPowerDetails.getModelId();
+            double speed0 = modelPowerDetails.getSpeed();
+            BigDecimal speed = new BigDecimal(speed0).setScale(2, RoundingMode.HALF_EVEN);
+            Double theoryPower = modelPowerDetails.getTheoryPower();
+
+            // 检查是否已存在该modelId的映射关系
+            if (map.containsKey(modelId)) {
+                // 如果已存在,获取对应的内层HashMap,并添加新的映射关系
+                Map<BigDecimal, Double> innerMap = map.get(modelId);
+                innerMap.put(speed, theoryPower);
+            } else {
+                // 如果不存在,创建新的内层HashMap,并添加映射关系
+                Map<BigDecimal, Double> innerMap = new HashMap<>();
+                innerMap.put(speed, theoryPower);
+                map.put(modelId, innerMap);
+            }
+        }
+
+
+        //根据uniform_code=AI130从testing_point表中获取到风机的实际功率测点
+        List<TestingPoint> testingPointList1 = testingPointService.list(new QueryWrapper<TestingPoint>()
+                .eq("uniform_code", "AI022")
+        );
+        //遍历testingPointList1,把code取出放入一个string集合
+        List<String> codeList1 = new ArrayList<>();
+        for (TestingPoint testingPoint : testingPointList1) {
+            String code = testingPoint.getCode();
+            codeList1.add(code);
+        }
+        //遍历codeList作为适配器的参数,获取到1分钟实际平均功率
+        for (String code : codeList1) {
+            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
+
+        }
+
+        //根据uniform_code=AI022从testing_point表中获取到风机的风速测点
+        List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>()
+                .eq("uniform_code", "AI022")
+        );
+        //遍历testingPointList,把code取出放入一个string集合
+        List<String> codeList = new ArrayList<>();
+        for (TestingPoint testingPoint : testingPointList) {
+            String code = testingPoint.getCode();
+            codeList.add(code);
+        }
+
+        //新建一个map,键为风机编码,值为map集合,值的map集合的键为时间,值为1分钟理论发电量
+        Map<String, Map<Long, BigDecimal>> map1 = new HashMap<>();
+
+        //遍历codeList作为适配器的参数,获取到1分钟平均风速
+        for (String code : codeList) {
+            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
+
+            //遍历testingPointList,根据code取到风机编码thing_id
+            for (TestingPoint testingPoint : testingPointList) {
+                String code1 = testingPoint.getCode();
+                if (code.equals(code1)) {
+                    String thingId = testingPoint.getThingId();
+                    //根据thingId从equipmentList中取出型号
+                    for (Equipment equipment : equipmentList) {
+                        String nemCode = equipment.getNemCode();
+                        if (thingId.equals(nemCode)) {
+                            String modelId = equipment.getModelId();
+                            //根据modelId从map中取出map集合,键为speed,值为theory_power
+                            Map<BigDecimal, Double> map2 = map.get(modelId);
+                            //遍历pointDataList,拿到风速,根据风速从map2中取到理论功率,计算1分钟理论发电量
+                            for (PointDatas pointData : pointDataList) {
+                                //风速
+                                double speed0 = pointData.getAvg().getValue();
+                                BigDecimal speed = new BigDecimal(speed0).setScale(2, RoundingMode.HALF_EVEN);
+
+                                Double theoryPower = 0.0;
+                                if (speed0 >= 3 && speed0 <= 25) {
+                                    //理论功率
+                                    theoryPower = map2.get(speed);
+                                }
+                                //时间
+                                DateTime dateTime = DateTime.of(pointData.getAvg().getTs());
+
+
+                                BigDecimal llfdl = BigDecimal.valueOf(0);
+                                //1分钟理论发电量
+                                if (theoryPower != null) {
+                                    llfdl = new BigDecimal(Double.toString(theoryPower))
+                                            .multiply(new BigDecimal(Double.toString(1)))
+                                            .divide(new BigDecimal(Double.toString(60)), 2, RoundingMode.HALF_UP);
+                                }
+
+
+                                //存入map1,键为风机编码,值为map集合,值的map集合的键为时间,值为1分钟理论发电量
+                                if (map1.containsKey(nemCode)) {
+                                    // 如果已存在,获取对应的内层HashMap,并添加新的映射关系
+                                    Map<Long, BigDecimal> innerMap = map1.get(nemCode);
+                                    innerMap.put(dateTime.getTime(), llfdl);
+                                } else {
+                                    // 如果不存在,创建新的内层HashMap,并添加映射关系
+                                    Map<Long, BigDecimal> innerMap = new HashMap<>();
+                                    innerMap.put(dateTime.getTime(), llfdl);
+                                    map1.put(nemCode, innerMap);
+                                }
+
+                            }
+
+
+                        }
+                    }
+                }
+
+
+            }
+        }
+
+        HashMap<String, BigDecimal> map2 = new HashMap<>();
+        for (String key : map1.keySet()) {
+            Map<Long, BigDecimal> mapValues = map1.get(key);
+            BigDecimal llfdl = BigDecimal.valueOf(0);
+            for (BigDecimal mapValue : mapValues.values()) {
+                llfdl = llfdl.add(mapValue);
+            }
+            map2.put(key, llfdl);
+        }
+
+        BigDecimal mhsllfdl = BigDecimal.valueOf(0);
+        BigDecimal nssllfdl = BigDecimal.valueOf(0);
+        BigDecimal qsllfdl = BigDecimal.valueOf(0);
+        BigDecimal sbqllfdl = BigDecimal.valueOf(0);
+        BigDecimal xsllfdl = BigDecimal.valueOf(0);
+
+        for (String key : map2.keySet()) {
+            if (key.contains("NX_GDDL_MHS_F_WT_")) {
+                mhsllfdl = mhsllfdl.add(map2.get(key));
+            }
+            if (key.contains("NX_GDDL_NSS_F_WT_")) {
+                nssllfdl = nssllfdl.add(map2.get(key));
+            }
+            if (key.contains("NX_GDDL_QS_F_WT_")) {
+                qsllfdl = qsllfdl.add(map2.get(key));
+            }
+            if (key.contains("NX_GDDL_SBQ_F_WT_")) {
+                sbqllfdl = sbqllfdl.add(map2.get(key));
+            }
+            if (key.contains("NX_GDDL_XS_F_WT_")) {
+                xsllfdl = xsllfdl.add(map2.get(key));
+            }
+
+
+        }
+        System.out.println("麻黄山理论发电量:" + mhsllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
+        System.out.println("牛首山理论发电量:" + nssllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
+        System.out.println("青山理论发电量:" + qsllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
+        System.out.println("石板泉理论发电量:" + sbqllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
+        System.out.println("香山理论发电量:" + xsllfdl.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
+
+
+    }
+
+
+    /**
+     * 理论发电量,每台风机每分钟平均风速乘机型理论功率
+     * (如果理论功率小于实际功率,用实际功率)或者1分钟理论发电量小于1分钟实际发电量,用实际发电量
+     * 1分钟平均风速
+     */
+    @Test
+    public void llfdl_1Min1() {
+
+        //设置取值开始时间
+        String startString = startTimeString;
+        DateTime startDateTime0 = DateUtil.parse(startString);
+        DateTime startDateTime = DateUtil.beginOfDay(startDateTime0);
+
+        //设置取值结束时间
+        String endDateString = endTimeString;
+        DateTime endDateTime0 = DateUtil.parse(endDateString);
+        DateTime endDateTime = DateUtil.endOfDay(endDateTime0);
+//        DateTime endDateTime = DateUtil.offsetMinute(startDateTime, 1);
+
+        int a = 0;
+
+        ArrayList<TDEquipmentMeterInfo> tdEquiomentMeterInfos = new ArrayList<>();
+        ArrayList<TDEquipmentMeterInfo> tdEquiomentMeterInfoSpeed = new ArrayList<>();
+        ArrayList<TDEquipmentMeterInfo> tdEquiomentMeterInfoPower = new ArrayList<>();
+
+
+        //model_power_details表中获取到所有型号各风速对应的理论功率
+        List<ModelPowerDetails> modelPowerDetailsList = modelPowerDetailsService.list();
+//        System.out.println("modelPowerDetailsList"+modelPowerDetailsList);
+
+        //从testingPont表中根据uniform_code=AI022获取到设备风速测点
+        List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>()
+                .eq("uniform_code", "AI022")
+        );
+//        System.out.println("testingPointList"+testingPointList);
+
+        //遍历testingPointList拿到code作为适配器参数
+        for (TestingPoint testingPoint : testingPointList) {
+            String code = testingPoint.getCode();
+            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
+
+            System.out.println("风速返回数据:" + pointDataList.size());
+            //遍历pointDataList,取出1分钟平均风速,和时间
+            for (PointDatas pointData : pointDataList) {
+                //1分钟平均风速
+                double speed0 = pointData.getAvg().getValue();
+                BigDecimal speed = new BigDecimal(speed0).setScale(2, RoundingMode.HALF_EVEN);
+
+                //时间
+                long ts0 = pointData.getAvg().getTs();
+                long ts = DateUtil.beginOfMinute(DateTime.of(ts0)).getTime();
+
+                TDEquipmentMeterInfo tdEquiomentMeterInfo = new TDEquipmentMeterInfo();
+                tdEquiomentMeterInfo.setTbName(testingPoint.getThingId());
+                tdEquiomentMeterInfo.setTs(ts);
+                tdEquiomentMeterInfo.setSpeed(speed.doubleValue());
+                tdEquiomentMeterInfo.setActualPower(0);
+                tdEquiomentMeterInfo.setTheoreticalPower(0);
+                tdEquiomentMeterInfo.setModel(testingPoint.getModel());
+                tdEquiomentMeterInfo.setStation(testingPoint.getStationId());
+                tdEquiomentMeterInfoSpeed.add(tdEquiomentMeterInfo);
+
+            }
+
+        }
+//        System.out.println(tdEquiomentMeterInfoSpeed);
+
+        //从testingPont表中根据uniform_code=AI022获取到设备风速测点
+        List<TestingPoint> testingPointList2 = testingPointService.list(new QueryWrapper<TestingPoint>()
+                .eq("uniform_code", "AI130")
+                .eq("thing_type", "windturbine")
+        );
+
+        //遍历testingPointList拿到code作为适配器参数
+        for (TestingPoint testingPoint : testingPointList2) {
+            String code = testingPoint.getCode();
+            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
+
+            System.out.println("实际功率返回数据:" + pointDataList.size());
+            //遍历pointDataList,取出1分钟平均风速,和时间
+            for (PointDatas pointData : pointDataList) {
+                //1分钟平均实际功率
+                double power = pointData.getAvg().getValue();
+
+                //时间
+                long ts0 = pointData.getAvg().getTs();
+                long ts = DateUtil.beginOfMinute(DateTime.of(ts0)).getTime();
+
+                TDEquipmentMeterInfo tdEquiomentMeterInfo = new TDEquipmentMeterInfo();
+                tdEquiomentMeterInfo.setTbName(testingPoint.getThingId());
+                tdEquiomentMeterInfo.setTs(ts);
+                tdEquiomentMeterInfo.setActualPower(power);
+                tdEquiomentMeterInfo.setModel(testingPoint.getModel());
+                tdEquiomentMeterInfo.setStation(testingPoint.getStationId());
+                tdEquiomentMeterInfoPower.add(tdEquiomentMeterInfo);
+
+            }
+
+        }
+
+        System.out.println("tdEquiomentMeterInfoSpeed" + tdEquiomentMeterInfoSpeed.size());
+
+        System.out.println("tdEquiomentMeterInfoPower" + tdEquiomentMeterInfoPower.size());
+        // 遍历 tdEquiomentMeterInfoSpeed 集合
+        for (TDEquipmentMeterInfo speedInfo : tdEquiomentMeterInfoSpeed) {
+            String tbName = speedInfo.getTbName();
+            long ts = speedInfo.getTs();
+            BigDecimal bigDecimal1 = new BigDecimal(ts);
+
+            for (TDEquipmentMeterInfo powerInfo : tdEquiomentMeterInfoPower) {
+                BigDecimal bigDecimal2 = new BigDecimal(powerInfo.getTs());
+                if (powerInfo.getTbName().equals(tbName) && bigDecimal1.equals(bigDecimal2)) {
+                    a++;
+                    speedInfo.setActualPower(powerInfo.getActualPower());
+                    // 退出内部循环,继续查找下一个 speedInfo 对象
+                    break;
+                }
+            }
+        }
+
+
+        for (TDEquipmentMeterInfo tdEquiomentMeterInfo : tdEquiomentMeterInfoSpeed) {
+
+            for (ModelPowerDetails modelPowerDetails : modelPowerDetailsList) {
+                if (tdEquiomentMeterInfo.getSpeed() == modelPowerDetails.getSpeed() && tdEquiomentMeterInfo.getModel().equals(modelPowerDetails.getModelId())) {
+                    tdEquiomentMeterInfo.setTheoreticalPower(modelPowerDetails.getEnsurePower());
+                }
+            }
+
+
+        }
+        tdEquiomentMeterInfoPower.sort(Comparator.comparing(TDEquipmentMeterInfo::getTbName).thenComparing(TDEquipmentMeterInfo::getTs));
+//        System.out.println("tdEquiomentMeterInfos"+tdEquiomentMeterInfos.size());
+        tdEquiomentMeterInfoSpeed.sort(Comparator.comparing(TDEquipmentMeterInfo::getTbName).thenComparing(TDEquipmentMeterInfo::getTs));
+
+
+        double c = 0;
+        double b = 0;
+
+        for (TDEquipmentMeterInfo tDEquiomentMeterInfo : tdEquiomentMeterInfoSpeed) {
+            tDEquiomentMeterInfo.setTheoreticalPowerGeneration(tDEquiomentMeterInfo.getTheoreticalPower() / 60);
+            tDEquiomentMeterInfo.setActualGeneration(tDEquiomentMeterInfo.getActualPower() / 60);
+
+            c = c + tDEquiomentMeterInfo.getTheoreticalPowerGeneration();
+            b = b + tDEquiomentMeterInfo.getActualGeneration();
+        }
+
+
+        System.out.println("理论发电量" + c);
+        System.out.println("实际发电量" + b);
+
+
+    }
+
+    //理论功率
+    @Test
+    public void llfdl_1Min2() {
+
+        //设置取值开始时间
+        String startString = startTimeString;
+        DateTime startDateTime0 = DateUtil.parse(startString);
+        DateTime startDateTime = DateUtil.beginOfDay(startDateTime0);
+
+        //设置取值结束时间
+        String endDateString = endTimeString;
+        DateTime endDateTime0 = DateUtil.parse(endDateString);
+//        DateTime endDateTime = DateUtil.endOfDay(endDateTime0);
+        DateTime endDateTime = DateUtil.offsetMinute(startDateTime, 1);
+
+        int a = 0;
+
+        ArrayList<TDEquipmentMeterInfo> tdEquiomentMeterInfos = new ArrayList<>();
+        ArrayList<TDEquipmentMeterInfo> tdEquiomentMeterInfoSpeed = new ArrayList<>();
+        ArrayList<TDEquipmentMeterInfo> tdEquiomentMeterInfoPower = new ArrayList<>();
+
+
+        //model_power_details表中获取到所有型号各风速对应的理论功率
+        List<ModelPowerDetails> modelPowerDetailsList = modelPowerDetailsService.list();
+//        System.out.println("modelPowerDetailsList"+modelPowerDetailsList);
+
+        //从testingPont表中根据uniform_code=AI022获取到设备风速测点
+        List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>()
+                .eq("uniform_code", "AI022")
+        );
+//        System.out.println("testingPointList"+testingPointList);
+
+        //遍历testingPointList拿到code作为适配器参数
+        for (TestingPoint testingPoint : testingPointList) {
+            String code = testingPoint.getCode();
+            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
+
+            System.out.println("风速返回数据:" + pointDataList.size());
+            //遍历pointDataList,取出1分钟平均风速,和时间
+            for (PointDatas pointData : pointDataList) {
+                //1分钟平均风速
+                double speed0 = pointData.getAvg().getValue();
+                BigDecimal speed = new BigDecimal(speed0).setScale(2, RoundingMode.HALF_EVEN);
+
+                //时间
+                long ts0 = pointData.getAvg().getTs();
+                long ts = DateUtil.beginOfMinute(DateTime.of(ts0)).getTime();
+
+                TDEquipmentMeterInfo tdEquiomentMeterInfo = new TDEquipmentMeterInfo();
+                tdEquiomentMeterInfo.setTbName(testingPoint.getThingId());
+                tdEquiomentMeterInfo.setTs(ts);
+                tdEquiomentMeterInfo.setSpeed(speed.doubleValue());
+                tdEquiomentMeterInfo.setActualPower(0);
+                tdEquiomentMeterInfo.setTheoreticalPower(0);
+                tdEquiomentMeterInfo.setModel(testingPoint.getModel());
+                tdEquiomentMeterInfo.setStation(testingPoint.getStationId());
+                tdEquiomentMeterInfoSpeed.add(tdEquiomentMeterInfo);
+
+            }
+
+        }
+//        System.out.println(tdEquiomentMeterInfoSpeed);
+
+        //从testingPont表中根据uniform_code=AI022获取到设备风速测点
+        List<TestingPoint> testingPointList2 = testingPointService.list(new QueryWrapper<TestingPoint>()
+                .eq("uniform_code", "AI130")
+                .eq("thing_type", "windturbine")
+        );
+
+        //遍历testingPointList拿到code作为适配器参数
+        for (TestingPoint testingPoint : testingPointList2) {
+            String code = testingPoint.getCode();
+            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
+
+            System.out.println("实际功率返回数据:" + pointDataList.size());
+            //遍历pointDataList,取出1分钟平均风速,和时间
+            for (PointDatas pointData : pointDataList) {
+                //1分钟平均实际功率
+                double power = pointData.getAvg().getValue();
+
+                //时间
+                long ts0 = pointData.getAvg().getTs();
+                long ts = DateUtil.beginOfMinute(DateTime.of(ts0)).getTime();
+
+                TDEquipmentMeterInfo tdEquiomentMeterInfo = new TDEquipmentMeterInfo();
+                tdEquiomentMeterInfo.setTbName(testingPoint.getThingId());
+                tdEquiomentMeterInfo.setTs(ts);
+                tdEquiomentMeterInfo.setActualPower(power);
+                tdEquiomentMeterInfo.setModel(testingPoint.getModel());
+                tdEquiomentMeterInfo.setStation(testingPoint.getStationId());
+                tdEquiomentMeterInfoPower.add(tdEquiomentMeterInfo);
+
+            }
+
+        }
+
+        System.out.println("tdEquiomentMeterInfoSpeed" + tdEquiomentMeterInfoSpeed.size());
+
+        System.out.println("tdEquiomentMeterInfoPower" + tdEquiomentMeterInfoPower.size());
+        // 遍历 tdEquiomentMeterInfoSpeed 集合
+        for (TDEquipmentMeterInfo speedInfo : tdEquiomentMeterInfoSpeed) {
+            String tbName = speedInfo.getTbName();
+            long ts = speedInfo.getTs();
+            BigDecimal bigDecimal1 = new BigDecimal(ts);
+
+            for (TDEquipmentMeterInfo powerInfo : tdEquiomentMeterInfoPower) {
+                BigDecimal bigDecimal2 = new BigDecimal(powerInfo.getTs());
+                if (powerInfo.getTbName().equals(tbName) && bigDecimal1.equals(bigDecimal2)) {
+                    a++;
+                    speedInfo.setActualPower(powerInfo.getActualPower());
+                    // 退出内部循环,继续查找下一个 speedInfo 对象
+                    break;
+                }
+            }
+        }
+
+
+        for (TDEquipmentMeterInfo tdEquiomentMeterInfo : tdEquiomentMeterInfoSpeed) {
+
+            for (ModelPowerDetails modelPowerDetails : modelPowerDetailsList) {
+                if (tdEquiomentMeterInfo.getSpeed() == modelPowerDetails.getSpeed() && tdEquiomentMeterInfo.getModel().equals(modelPowerDetails.getModelId())) {
+                        tdEquiomentMeterInfo.setTheoreticalPower(modelPowerDetails.getTheoryPower());
+
+                }
+
+            }
+
+
+        }
+        tdEquiomentMeterInfoPower.sort(Comparator.comparing(TDEquipmentMeterInfo::getTbName).thenComparing(TDEquipmentMeterInfo::getTs));
+        tdEquiomentMeterInfoSpeed.sort(Comparator.comparing(TDEquipmentMeterInfo::getTbName).thenComparing(TDEquipmentMeterInfo::getTs));
+
+        //日理论发电量
+        //日实际发电量
+        double c = 0;
+//        double b = 0;
+        for (TDEquipmentMeterInfo tDEquiomentMeterInfo : tdEquiomentMeterInfoSpeed) {
+//            tDEquiomentMeterInfo.setTheoreticalPowerGeneration(tDEquiomentMeterInfo.getTheoreticalPower() / 60);
+            tDEquiomentMeterInfo.setActualGeneration(tDEquiomentMeterInfo.getActualPower() / 60);
+
+            //选择功率大的
+            tDEquiomentMeterInfo.setTheoreticalPowerGeneration(Math.max(tDEquiomentMeterInfo.getTheoreticalPower(), tDEquiomentMeterInfo.getActualPower())/60);
+
+
+            c = c + tDEquiomentMeterInfo.getTheoreticalPowerGeneration();
+//            b = b + tDEquiomentMeterInfo.getActualGeneration();
+
+            //保存到taos
+            tdEquipmentMeterInfoMapper.insertTDEquiomentMeterInfo(tDEquiomentMeterInfo.getTbName(), tDEquiomentMeterInfo.getModel(), tDEquiomentMeterInfo.getStation(), tDEquiomentMeterInfo.getTs(), tDEquiomentMeterInfo.getSpeed(), tDEquiomentMeterInfo.getTheoreticalPower(), tDEquiomentMeterInfo.getActualPower(), tDEquiomentMeterInfo.getTheoreticalPowerGeneration(), tDEquiomentMeterInfo.getActualGeneration());
+
+        }
+
+//        System.out.println("理论发电量" + c);
+//        System.out.println("实际发电量" + b);
+
+
+    }
+
+    //并行处理优化查询速度
+    @Test
+    public void llfdl_1Min3() {
+        // 设置取值开始时间
+        DateTime startDateTime = DateUtil.beginOfDay(DateUtil.parse(startTimeString));
+
+        // 设置取值结束时间
+        DateTime endDateTime = DateUtil.endOfDay(DateUtil.parse(endTimeString));
+
+        ArrayList<TDEquipmentMeterInfo> tdEquiomentMeterInfoSpeed = new ArrayList<>();
+        ArrayList<TDEquipmentMeterInfo> tdEquiomentMeterInfoPower = new ArrayList<>();
+
+        // 从testingPont表中根据uniform_code=AI022获取到设备风速测点
+        List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>()
+                .eq("uniform_code", "AI022")
+        );
+
+        // 并行获取风速数据
+        testingPointList.parallelStream().forEach(testingPoint -> {
+            String code = testingPoint.getCode();
+            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
+
+            // 遍历pointDataList,取出1分钟平均风速,和时间
+            for (PointDatas pointData : pointDataList) {
+                // 1分钟平均风速
+                double speed0 = pointData.getAvg().getValue();
+                BigDecimal speed = new BigDecimal(speed0).setScale(2, RoundingMode.HALF_EVEN);
+
+                // 时间
+                long ts0 = pointData.getAvg().getTs();
+                long ts = DateUtil.beginOfMinute(DateTime.of(ts0)).getTime();
+
+                TDEquipmentMeterInfo tdEquiomentMeterInfo = new TDEquipmentMeterInfo();
+                tdEquiomentMeterInfo.setTbName(testingPoint.getThingId());
+                tdEquiomentMeterInfo.setTs(ts);
+                tdEquiomentMeterInfo.setSpeed(speed.doubleValue());
+                tdEquiomentMeterInfo.setActualPower(0);
+                tdEquiomentMeterInfo.setTheoreticalPower(0);
+                tdEquiomentMeterInfo.setModel(testingPoint.getModel());
+                tdEquiomentMeterInfo.setStation(testingPoint.getStationId());
+
+                synchronized (tdEquiomentMeterInfoSpeed) {
+                    tdEquiomentMeterInfoSpeed.add(tdEquiomentMeterInfo);
+                }
+            }
+        });
+
+        // 从testingPont表中根据uniform_code=AI022获取到设备风速测点
+        List<TestingPoint> testingPointList2 = testingPointService.list(new QueryWrapper<TestingPoint>()
+                .eq("uniform_code", "AI130")
+                .eq("thing_type", "windturbine")
+        );
+
+        // 并行获取实际功率数据
+        testingPointList2.parallelStream().forEach(testingPoint -> {
+            String code = testingPoint.getCode();
+            List<PointDatas> pointDataList = adapter.getHistoryStat(code, startDateTime.getTime(), endDateTime.getTime(), 60);
+
+            // 遍历pointDataList,取出1分钟平均实际功率,和时间
+            for (PointDatas pointData : pointDataList) {
+                // 1分钟平均实际功率
+                double power = pointData.getAvg().getValue();
+
+                // 时间
+                long ts0 = pointData.getAvg().getTs();
+                long ts = DateUtil.beginOfMinute(DateTime.of(ts0)).getTime();
+
+                TDEquipmentMeterInfo tdEquiomentMeterInfo = new TDEquipmentMeterInfo();
+                tdEquiomentMeterInfo.setTbName(testingPoint.getThingId());
+                tdEquiomentMeterInfo.setTs(ts);
+                tdEquiomentMeterInfo.setActualPower(power);
+                tdEquiomentMeterInfo.setModel(testingPoint.getModel());
+                tdEquiomentMeterInfo.setStation(testingPoint.getStationId());
+
+                synchronized (tdEquiomentMeterInfoPower) {
+                    tdEquiomentMeterInfoPower.add(tdEquiomentMeterInfo);
+                }
+            }
+        });
+
+
+        // 创建HashMap用于加速查找
+        Map<String, TDEquipmentMeterInfo> powerInfoMap = new HashMap<>();
+        for (TDEquipmentMeterInfo powerInfo : tdEquiomentMeterInfoPower) {
+            powerInfoMap.put(powerInfo.getTbName() + "_" + powerInfo.getTs(), powerInfo);
+        }
+
+        // 匹配风速和实际功率数据
+        for (TDEquipmentMeterInfo speedInfo : tdEquiomentMeterInfoSpeed) {
+            String tbName = speedInfo.getTbName();
+            long ts = speedInfo.getTs();
+            TDEquipmentMeterInfo powerInfo = powerInfoMap.get(tbName + "_" + ts);
+            if (powerInfo != null) {
+                speedInfo.setActualPower(powerInfo.getActualPower());
+            }
+        }
+
+        // 获取所有型号对应的理论功率数据
+        List<ModelPowerDetails> modelPowerDetailsList = modelPowerDetailsService.list();
+
+        // 使用HashSet提高查找速度
+        Set<String> modelSet = new HashSet<>();
+        for (ModelPowerDetails modelPowerDetails : modelPowerDetailsList) {
+            modelSet.add(modelPowerDetails.getModelId());
+        }
+
+        // 匹配理论功率数据
+        for (TDEquipmentMeterInfo tdEquiomentMeterInfo : tdEquiomentMeterInfoSpeed) {
+            if (modelSet.contains(tdEquiomentMeterInfo.getModel())) {
+                for (ModelPowerDetails modelPowerDetails : modelPowerDetailsList) {
+                    if (tdEquiomentMeterInfo.getSpeed() == modelPowerDetails.getSpeed() && tdEquiomentMeterInfo.getModel().equals(modelPowerDetails.getModelId())) {
+                        if (tdEquiomentMeterInfo.getSpeed() < 4.5) {
+                            tdEquiomentMeterInfo.setTheoreticalPower(modelPowerDetails.getEnsurePower());
+                        }else {tdEquiomentMeterInfo.setTheoreticalPower(modelPowerDetails.getTheoryPower());
+                        }
+
+                    }
+                }
+            }
+        }
+
+        // 根据tbName和ts排序
+//        tdEquiomentMeterInfoPower.sort(Comparator.comparing(TDEquipmentMeterInfo::getTbName).thenComparing(TDEquipmentMeterInfo::getTs));
+//        tdEquiomentMeterInfoSpeed.sort(Comparator.comparing(TDEquipmentMeterInfo::getTbName).thenComparing(TDEquipmentMeterInfo::getTs));
+
+        // 日理论发电量和日实际发电量
+        double c = 0;
+        double b = 0;
+        double d = 0;
+        for (TDEquipmentMeterInfo tDEquiomentMeterInfo : tdEquiomentMeterInfoSpeed) {
+            tDEquiomentMeterInfo.setTheoreticalPowerGeneration(tDEquiomentMeterInfo.getTheoreticalPower() / 60);
+            tDEquiomentMeterInfo.setActualGeneration(tDEquiomentMeterInfo.getActualPower() / 60);
+
+//            c += tDEquiomentMeterInfo.getTheoreticalPowerGeneration();
+//            b += tDEquiomentMeterInfo.getActualGeneration();
+            double c1 = tDEquiomentMeterInfo.getTheoreticalPowerGeneration();
+//            double b1 = tDEquiomentMeterInfo.getActualGeneration();
+            c += c1;
+//            b += b1;
+//            d += Math.max(c1, b1);
+        }
+
+        System.out.println("理论功率功率理论发电量: " + c);
+        System.out.println("实际平均功率发电量: " + b);
+        System.out.println("优化理论发电量发电量: " + d);
+    }
+
+
+}
+
+
+
+
+
+
+
+
+

+ 6 - 0
electricity/meter/src/main/resources/mappers-postgresql/TDEquipmentMeterInfoMapper.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.gyee.gaia.meter.mapper.TDEquipmentMeterInfoMapper">
+
+
+</mapper>

+ 1 - 0
electricity/wind/src/main/java/com/gyee/gaia/electricity/wind/iservice/IEquipPowerGenDayService.java

@@ -16,4 +16,5 @@ import java.util.List;
 public interface IEquipPowerGenDayService extends IService<EquipPowerGenDay> {
 
     List<EquipPowerGenDay> fjjxb(String wpids, String projectids, String lineids, String beginDate, String endDate, String type, String target, String sort);
+
 }