GYEE 9 months ago
parent
commit
bffc7970d1

+ 26 - 7
ruoyi-admin/src/main/java/com/ruoyi/web/runner/LoadDataSourceRunner.java

@@ -1,8 +1,11 @@
 package com.ruoyi.web.runner;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.io.file.FileReader;
+import cn.hutool.core.io.resource.ResourceUtil;
 import com.alibaba.druid.pool.DruidDataSource;
-import com.alibaba.fastjson2.JSONObject;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.TypeReference;
 import com.ruoyi.framework.datasource.DynamicDataSource;
 import com.ruoyi.quartz.glue.GlueFactory;
@@ -17,12 +20,16 @@ import com.ruoyi.quartz.handler.IJobHandler;
 import com.ruoyi.ucp.service.*;
 import com.ruoyi.ucp.util.CalcCache;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.system.ApplicationHome;
 import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.io.File;
+import java.io.InputStream;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -54,6 +61,8 @@ public class LoadDataSourceRunner implements CommandLineRunner {
     @Resource
     @Autowired
     private RedisTemplate redisTemplate;
+    @Value("${ruoyi.profile}")
+    private String path;
 
     @Override
     public void run(String... args) {
@@ -69,7 +78,10 @@ public class LoadDataSourceRunner implements CommandLineRunner {
 
         List<Method> methods = methodService.list();
         List<Formula> formulas = formulaService.list();
-        String functionCode = GlueFactory.getFunctionTemplate();
+//        String functionCode = GlueFactory.getFunctionTemplate();
+        String jarPath = path + "FunctionTemplate.java";
+        String functionCode = FileReader.create(new File(jarPath)).readString();
+//        String functionCode = ResourceUtil.readUtf8Str("FunctionTemplate.java");
         try {
             for (Method method : methods) {
                 //engine.eval(method.getMethodExpression());
@@ -86,17 +98,24 @@ public class LoadDataSourceRunner implements CommandLineRunner {
         }
 
         LettuceConnectionFactory factory = (LettuceConnectionFactory) redisTemplate.getConnectionFactory();
+        int database = factory.getDatabase();
         factory.setDatabase(9);
         redisTemplate.setConnectionFactory(factory);
-        Set<String> keys = redisTemplate.keys("monthCurve_");
+        factory.afterPropertiesSet();
+        factory.resetConnection();
+        Set<String> keys = redisTemplate.keys("monthCurve_*");
         for (String key : keys) {
             //redis缓存中获取到字符串
-            String o = (String) redisTemplate.opsForValue().get(key);
+            JSONArray o = (JSONArray) redisTemplate.opsForValue().get(key);
             //字符串类型转换为list月拟合曲线集合
-            List<ProEconWtCurveFittingMonth> powerList = JSONObject.parseObject(o, new TypeReference<List<ProEconWtCurveFittingMonth>>() {});
-            Map<Double, Double> collect = powerList.stream().collect(Collectors.toMap(ProEconWtCurveFittingMonth::getSpeed, ProEconWtCurveFittingMonth::getActualPower));
+            List<ProEconWtCurveFittingMonth> powerList = JSON.parseObject(o.toJSONString(), new TypeReference<List<ProEconWtCurveFittingMonth>>() {}.getType());
+
+//            List<ProEconWtCurveFittingMonth> powerList = JSONObject.parseObject((String) o, new TypeReference<List<ProEconWtCurveFittingMonth>>() {});
+            Map<Double, Double> collect = powerList.stream().collect(Collectors.toMap(ProEconWtCurveFittingMonth::getSpeed, ProEconWtCurveFittingMonth::getActualPower,(v1,v2)->v1));
             CalcCache.wtMcfMap.put(powerList.get(0).getWindturbineId(), collect);
         }
-        factory.setDatabase(5);
+        factory.setDatabase(database);
+        factory.afterPropertiesSet();
+        factory.resetConnection();
     }
 }

+ 60 - 0
ruoyi-admin/src/main/resources/FunctionTemplate.java

@@ -0,0 +1,60 @@
+package com.ruoyi;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.NumberUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.quartz.handler.IJobHandler;
+import com.ruoyi.quartz.task.ChangedSave;
+import com.ruoyi.ucp.entity.*;
+import com.ruoyi.ucp.feign.AdapterApi;
+import com.ruoyi.ucp.service.*;
+import com.ruoyi.ucp.util.CalcCache;
+import org.springframework.data.redis.core.RedisTemplate;
+
+import javax.annotation.Resource;
+import java.net.URI;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public class JavaFunctionJobHandler extends IJobHandler {
+
+    @Resource
+    private AdapterApi adapter;
+    @Resource
+    private IPointInfoService pointService;
+    @Resource
+    private IStationInfoHourService stationInfoHourService;
+    @Resource
+    private IStationInfoDayService stationInfoDayService;
+    @Resource
+    private ILineInfoDayService lineInfoDayService;
+    @Resource
+    private IStateAiService stateAiService;
+    @Resource
+    private RedisTemplate redisTemplate;
+    @Resource
+    private IEquipmentModelService equipmentModelService;
+    @Resource
+    private ITurbineInfoDayService turbineInfoDayService;
+    @Resource
+    private IProEconReportIndicatorPoolService reportIndicatorPoolService;
+
+    @Override
+    public void execute() throws Exception {
+
+    }
+
+    @Override
+    public IJobHandler getFunctionHandler() {
+        return null;
+    }
+
+    @Override
+    public void setFunctionHandler(IJobHandler jobHandler) {
+
+    }
+//此处加公式
+}

+ 15 - 75
ruoyi-admin/src/test/java/com/ruoyi/JavaFunctionJobHandler.java

@@ -36,8 +36,6 @@ public class JavaFunctionJobHandler extends IJobHandler {
     private RedisTemplate redisTemplate;
     @Resource
     private IEquipmentModelService equipmentModelService;
-    @Resource
-    private ITurbineInfoDayService turbineInfoDayService;
 
     @Override
     public void execute() throws Exception {
@@ -141,7 +139,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
             collect = byHours.stream().collect(
                     Collectors.toMap(StationInfoHour::getStationId, Function.identity()));
         }
-        List<DoubleStatData> stat;
+        DoubleStatData stat;
         List<StationInfoHour> byHours2 = new ArrayList<>();
         for (PointInfo point : entity) {
             stat = adapter.getHistoryStat(taosGoldenUriTest(),
@@ -150,11 +148,11 @@ public class JavaFunctionJobHandler extends IJobHandler {
                 StationInfoHour info = new StationInfoHour();
                 info.setStationId(point.getStationId());
                 info.setRecordDate(DateUtil.beginOfHour(hour));
-                if (stat.isEmpty()) info.setPjgl(0.0);
-                info.setPjgl(stat.get(0).getAvg().getDoubleValue());
+                if (stat==null) info.setPjgl(0.0);
+                info.setPjgl(stat.getAvg().getDoubleValue());
                 byHours2.add(info);
             } else {
-                collect.get(point.getStationId()).setPjgl(stat.get(0).getAvg().getDoubleValue());
+                collect.get(point.getStationId()).setPjgl(stat.getAvg().getDoubleValue());
             }
         }
         stationInfoHourService.saveOrUpdateBatch(byHours.isEmpty() ? byHours2 : byHours);
@@ -308,10 +306,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
         stationInfoDayService.saveOrUpdateBatch(infoDays);
     }
 
-    public void calcTurbine5s() {
+    public void calcTurbine5s(){
 
     }
-
     //此处加公式
     public void calcTurbineSsztAi(Date date) {
         PointInfo pi = new PointInfo();
@@ -355,8 +352,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
         //redisTemplate.opsForHash().put("state_point",key,value);
 
     }
-
-    public void calcStationXd(boolean priorRation) {
+    public void calcStationXd(boolean priorRation){
         //限电状态
         PointInfo piAgc = new PointInfo();
         //AGC
@@ -377,8 +373,8 @@ public class JavaFunctionJobHandler extends IJobHandler {
         Map<String, PointData> statAgc = adapter.getLatest(goldenUri(), keysAgc);
         Map<String, PointData> statCx = adapter.getLatest(goldenUri(), keysCx);
         DateTime time5 = DateUtil.offsetMinute(DateUtil.date(), -5);
-        List<DoubleStatData> statAgc5 = adapter.getHistoryStat(goldenUri(), keysAgc, time5.getTime(), DateUtil.date().getTime());
-        List<DoubleStatData> statCx5 = adapter.getHistoryStat(goldenUri(), keysCx, time5.getTime(), DateUtil.date().getTime());
+        DoubleStatData statAgc5 = adapter.getHistoryStat(goldenUri(), keysAgc, time5.getTime(), DateUtil.date().getTime());
+        DoubleStatData statCx5 = adapter.getHistoryStat(goldenUri(), keysCx, time5.getTime(), DateUtil.date().getTime());
 
         //AI066
         for (PointInfo info : entityAgc) {
@@ -419,7 +415,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
     }
 
 
-    public void calcNhglZs(boolean priorRation) {
+    public void calcNhglZs(boolean priorRation){
         //拟合功率(自算)
         //实时风速
         PointInfo piFs = new PointInfo();
@@ -446,18 +442,18 @@ public class JavaFunctionJobHandler extends IJobHandler {
 
         DateTime time = DateUtil.beginOfMinute(DateUtil.date());
         DateTime time5 = DateUtil.offsetMinute(time, -5);
-        List<DoubleStatData> statFs5;
+        DoubleStatData statFs5;
         PointData avg;
         List<PointData> avgs = new ArrayList<>();
-        double value, v;
+        double value,v;
         for (Map.Entry<String, List<PointInfo>> entry : collect.entrySet()) {
-            double stV = 0;
+            double stV=0;
             for (PointInfo info : entry.getValue()) {
                 //todo
                 statFs5 = adapter.getHistoryStat(goldenUri(), info.getPointKey(), time5.getTime(), time.getTime());
-                if (CollUtil.isNotEmpty(statFs5)) {
+                if(statFs5!=null){
                     //todo
-                    value = statFs5.get(0).getAvg().getValue();
+                    value = statFs5.getAvg().getValue();
                     avg = new PointData();
                     v = CalcCache.wtMcfMap.get(info.getTurbineId()).get(value);
                     stV += v;
@@ -476,63 +472,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
         }
     }
 
-    public URI goldenUri() {
+    public URI goldenUri(){
         return URI.create("http://172.16.12.103:8011/ts");
     }
-
-    public void calcTurbineRFDL(Date date) {
-        //date当天零点
-        DateTime time = DateUtil.beginOfDay(date);
-        //date昨天零点
-        DateTime time0 = DateUtil.offsetDay(time, -1);
-        //date当天零点加三分钟
-        DateTime time2 = DateUtil.offsetMinute(time, 3);
-        //date昨天零点加三分钟
-        DateTime time1 = DateUtil.offsetMinute(time0, 3);
-
-        PointInfo pi = new PointInfo();
-        pi.setUniformCode("AI121");
-        pi.setInstitutionType("turbine");
-        List<PointInfo> entity = pointService.getByEntity(pi);
-        Map<String, String> turMap = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointKey));
-
-        String keys = pointInfos2Keys(entity);
-
-        Map<String, PointData> swdlL2 = adapter.getHistorySection(goldenUri(), keys, time2.getTime());
-        Map<String, PointData> swdlL1 = adapter.getHistorySection(goldenUri(), keys, time1.getTime());
-
-        List<TurbineInfoDay> byDate = getTurbineinfoByDate(time0.toJdkDate());
-        Map<String, TurbineInfoDay> collect = new HashMap<>();
-        if (byDate.size() > 0) {
-            collect = byDate.stream().collect(Collectors.toMap(TurbineInfoDay::getLineId, Function.identity()));
-        }
-        TurbineInfoDay infoDay;
-        String turbineId, key;
-        List<TurbineInfoDay> infoDays = new ArrayList<>();
-        for (PointInfo info : entity) {
-            turbineId = info.getTurbineId();
-            if (byDate.isEmpty()) {
-                infoDay = new TurbineInfoDay();
-                infoDay.setStationId(info.getStationId());
-                infoDay.setProjectId(info.getProjectId());
-                infoDay.setLineId(info.getLineId());
-                infoDay.setTurbineId(turbineId);
-                infoDay.setRecordDate(time0.toJdkDate());
-            } else {
-                infoDay = collect.get(turbineId);
-            }
-            key = turMap.get(turbineId);
-            double v = (swdlL2.get(key).getValue() - swdlL2.get(key).getValue()) * info.getCoef();
-            if (v < 0 || v > 1000000) v = 0;
-            infoDay.setRfdl(v);
-            infoDays.add(infoDay);
-        }
-        turbineInfoDayService.saveOrUpdateBatch(infoDays);
-    }
-
-    public List<TurbineInfoDay> getTurbineinfoByDate(Date date) {
-        QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
-        wrapper.eq("record_date", date);
-        return turbineInfoDayService.list(wrapper);
-    }
 }

+ 2 - 0
ruoyi-quartz/src/main/java/com/ruoyi/quartz/glue/GlueFactory.java

@@ -62,6 +62,8 @@ public class GlueFactory {
 				"    private RedisTemplate redisTemplate;" +
 				"    @Resource\n" +
 				"    private IEquipmentModelService equipmentModelService;" +
+				"    @Resource\n" +
+				"    private IProEconReportIndicatorPoolService reportIndicatorPoolService;" +
 				"\n" +
 				"    @Override\n" +
 				"    public void execute() throws Exception {\n" +

+ 1 - 0
universal-computing-platform/src/main/java/com/ruoyi/ucp/entity/TurbineInfoDay.java

@@ -36,4 +36,5 @@ public class TurbineInfoDay implements Serializable {
     private Double slss;
     private Double xnss;
     private Double llfdl;
+    private Double pjfs;
 }

+ 1 - 1
universal-computing-platform/src/main/java/com/ruoyi/ucp/feign/AdapterApi.java

@@ -32,7 +32,7 @@ public interface AdapterApi {
                                   @RequestParam("interval") int interval);
 
     @GetMapping("/history/stat2")
-    List<DoubleStatData> getHistoryStat(URI baseUri, @RequestParam("tagName") String tagName,
+    DoubleStatData getHistoryStat(URI baseUri, @RequestParam("tagName") String tagName,
                                         @RequestParam("startTs") long startTs,
                                         @RequestParam("endTs") long endTs);
                                         //@RequestParam("interval") int interval);

+ 15 - 0
universal-computing-platform/src/main/java/com/ruoyi/ucp/service/impl/TurbineInfoDayServiceImpl.java

@@ -1,11 +1,17 @@
 package com.ruoyi.ucp.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.annotation.DataSource;
+import com.ruoyi.common.enums.DataSourceType;
 import com.ruoyi.ucp.entity.TurbineInfoDay;
 import com.ruoyi.ucp.mapper.TurbineInfoDayMapper;
 import com.ruoyi.ucp.service.ITurbineInfoDayService;
 import org.springframework.stereotype.Service;
 
+import java.util.Collection;
+import java.util.List;
+
 /**
  * <p>
  *  服务实现类
@@ -15,6 +21,15 @@ import org.springframework.stereotype.Service;
  * @since 2024-05-29
  */
 @Service
+@DataSource(DataSourceType.SLAVE)
 public class TurbineInfoDayServiceImpl extends ServiceImpl<TurbineInfoDayMapper, TurbineInfoDay> implements ITurbineInfoDayService {
+    @Override
+    public List<TurbineInfoDay> list(Wrapper<TurbineInfoDay> queryWrapper) {
+        return super.list(queryWrapper);
+    }
 
+    @Override
+    public boolean saveOrUpdateBatch(Collection<TurbineInfoDay> entityList) {
+        return super.saveOrUpdateBatch(entityList);
+    }
 }