Commit c9a930ad authored by caotao's avatar caotao

1算法2 算法3调用

parent b6be8447
...@@ -25,6 +25,11 @@ ...@@ -25,6 +25,11 @@
<artifactId>amos-boot-biz-common</artifactId> <artifactId>amos-boot-biz-common</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.22</version>
</dependency>
<dependency> <dependency>
<groupId>com.yeejoin</groupId> <groupId>com.yeejoin</groupId>
<artifactId>amos-component-influxdb</artifactId> <artifactId>amos-component-influxdb</artifactId>
......
...@@ -16,8 +16,6 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel; ...@@ -16,8 +16,6 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List; import java.util.List;
/** /**
*
*
* @author system_generator * @author system_generator
* @date 2023-08-11 * @date 2023-08-11
*/ */
...@@ -27,30 +25,39 @@ import java.util.List; ...@@ -27,30 +25,39 @@ import java.util.List;
public class TestController extends BaseController { public class TestController extends BaseController {
@Autowired @Autowired
CommonServiceImpl commonServiceImpl; CommonServiceImpl commonServiceImpl;
/** /**
* 列表全部数据查询 * 列表全部数据查询
* *
* @return * @return
*/ */
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(httpMethod = "GET",value = "列表全部数据查询-风电", notes = "列表全部数据查询") @ApiOperation(httpMethod = "GET", value = "列表全部数据查询-风电", notes = "列表全部数据查询")
@GetMapping(value = "/listfan") @GetMapping(value = "/listfan")
public ResponseModel<List<IdxBizC80c>> selectForListFan() { public ResponseModel<List<IdxBizC80c>> selectForListFan() {
return ResponseHelper.buildResponse(commonServiceImpl.getAllFanstationTestPoint().subList(0,20)); return ResponseHelper.buildResponse(commonServiceImpl.getAllFanstationTestPoint().subList(0, 20));
} }
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@ApiOperation(httpMethod = "GET",value = "列表全部数据查询-光伏", notes = "列表全部数据查询") @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@GetMapping(value = "/listpv") @ApiOperation(httpMethod = "GET", value = "列表全部数据查询-光伏", notes = "列表全部数据查询")
public ResponseModel<List<IdxBizHjev>> selectForListPV() { @GetMapping(value = "/listpv")
return ResponseHelper.buildResponse(commonServiceImpl.getAllPVstationTestPoint().subList(0,20)); public ResponseModel<List<IdxBizHjev>> selectForListPV() {
} return ResponseHelper.buildResponse(commonServiceImpl.getAllPVstationTestPoint().subList(0, 20));
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false) }
@ApiOperation(httpMethod = "GET",value = "test", notes = "列表全部数据查询")
@GetMapping(value = "/test") @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
public void selectForListTest() { @ApiOperation(httpMethod = "GET", value = "test", notes = "列表全部数据查询")
commonServiceImpl.getIdxBizUxfvList(); @GetMapping(value = "/test")
} public void selectForListTest() {
commonServiceImpl.getIdxBizUxfvList();
}
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(httpMethod = "GET", value = "test", notes = "列表全部数据查询")
@GetMapping(value = "/getDateByTime")
public void getDateByTime(@RequestParam String startTime, @RequestParam String endTime) {
commonServiceImpl.getConditionVariablesByTime(startTime, endTime);
}
} }
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl; package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import cn.hutool.http.HttpUtil;
import cn.hutool.log.LogFactory;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBiz3yud; import com.yeejoin.amos.AmosJxiopAnalyseApplication;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizC80c; import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizC80c;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizHjev; import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizHjev;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizUxfv; import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizUxfv;
...@@ -10,16 +13,23 @@ import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizC80cMapper; ...@@ -10,16 +13,23 @@ import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizC80cMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizHjevMapper; import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizHjevMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizUxfvMapper; import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizUxfvMapper;
import com.yeejoin.amos.component.influxdb.InfluxdbUtil; import com.yeejoin.amos.component.influxdb.InfluxdbUtil;
import org.apache.poi.ss.formula.functions.T; import org.slf4j.Logger;
import org.elasticsearch.gateway.Gateway; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
public class CommonServiceImpl { public class CommonServiceImpl {
private static final Logger logger = LoggerFactory.getLogger(CommonServiceImpl.class);
@Value("${sleep.time:10}")
Integer sleepTime;
@Value("${gkbl.url:http://36.40.66.175:30009/maas/api/901b4627-4fb0-4527-ab2d-f6ea936c9b9d}")
String gkblurl;
// idx_biz_hjev 光伏监测变量 // idx_biz_hjev 光伏监测变量
// idx_biz_c80c 风电监测变量 (根据设备、系统、型号查分析和工况测点) // idx_biz_c80c 风电监测变量 (根据设备、系统、型号查分析和工况测点)
// idx_biz_3yud 光伏工况变量划分 // idx_biz_3yud 光伏工况变量划分
...@@ -71,7 +81,7 @@ public class CommonServiceImpl { ...@@ -71,7 +81,7 @@ public class CommonServiceImpl {
/** /**
* @return * @return
* @deprecated 获取网关及及工况变量列表 * @deprecated 获取工况变量列表
*/ */
public HashMap<String, List<IdxBizUxfv>> getIdxBizUxfvList() { public HashMap<String, List<IdxBizUxfv>> getIdxBizUxfvList() {
...@@ -85,6 +95,7 @@ public class CommonServiceImpl { ...@@ -85,6 +95,7 @@ public class CommonServiceImpl {
return IdxBizUxfvHashMap; return IdxBizUxfvHashMap;
} }
//遍历工况列表数据
public void getConditionVariablesByTime(String startTime, String endTime) { public void getConditionVariablesByTime(String startTime, String endTime) {
HashMap<String, List<IdxBizUxfv>> IdxBizUxfvHashMap = getIdxBizUxfvList(); HashMap<String, List<IdxBizUxfv>> IdxBizUxfvHashMap = getIdxBizUxfvList();
IdxBizUxfvHashMap.keySet().forEach(s -> { IdxBizUxfvHashMap.keySet().forEach(s -> {
...@@ -93,19 +104,224 @@ public class CommonServiceImpl { ...@@ -93,19 +104,224 @@ public class CommonServiceImpl {
}); });
} }
//遍历查询数据并调用并计算
public void foreachHandlerConditionVariab(String tableName, List<IdxBizUxfv> list, String startTime, String endTime) { public void foreachHandlerConditionVariab(String tableName, List<IdxBizUxfv> list, String startTime, String endTime) {
HashMap<String, List<IdxBizUxfv>> IdxBizUxfvHashMap = getIdxBizUxfvList();
List<Map<String, String>> params = new ArrayList<>();
list.forEach(idxBizUxfv -> { list.forEach(idxBizUxfv -> {
String sql = String.format("select value from %s wehre index_addres='%s' and where time >= '%s' and where time <= '%s' ", tableName, idxBizUxfv.getIndexAddress(), startTime, endTime); logger.info("--------------------------------------------开始查询--------------------------------");
List<Map<String, String>> params = new ArrayList<>();
// String sql = String.format("select value from %s where address='%s' and where time >= '%s' and where time <= '%s' ", tableName, idxBizUxfv.getIndexAddress(), startTime, endTime);
String sql = String.format("select value from %s where address='%s' ", tableName, idxBizUxfv.getIndexAddress());
List<Map<String, Object>> returnList = influxdbUtil.query(sql); List<Map<String, Object>> returnList = influxdbUtil.query(sql);
returnList.forEach((k) -> { returnList.forEach((k) -> {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("", k.get("value").toString()); map.put("processVariable", k.get("value").toString());
map.put("", idxBizUxfv.getSequenceNbr()); map.put("processVariableId", idxBizUxfv.getSequenceNbr());
params.add(map); params.add(map);
}); });
if (!params.isEmpty()) {
logger.info("------------------------------------------开始调用工况变量算法----------------------------------------");
HttpUtil.createPost(gkblurl).body(JSON.toJSONString(params)).execute().body();
try {
TimeUnit.SECONDS.sleep(sleepTime);
logger.info("------------------------------------------调用工况变量算法结束----------------------------------------");
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
}
public HashMap<String, List<IdxBizUxfv>> getIdxBizUxfvListOfAnaLyse() {
HashMap<String, List<IdxBizUxfv>> IdxBizUxfvHashMap = new HashMap<>();
List<String> gateWayIdList = idxBizUxfvMapper.gateWayIdListFan();
List<IdxBizUxfv> idxBizUxfvListFengxi = idxBizUxfvMapper.selectList(new QueryWrapper<IdxBizUxfv>().isNotNull("SEQUENCE_NBR").eq("TAG_CODE", "分析变量"));
List<IdxBizUxfv> finalIdxBizUxfvList = idxBizUxfvListFengxi;
gateWayIdList.forEach(s -> {
IdxBizUxfvHashMap.put("iot_data_" + s, finalIdxBizUxfvList.stream().filter(idxBizUxfv -> idxBizUxfv.getGatewayId().equals(s)).collect(Collectors.toList()));
});
return IdxBizUxfvHashMap;
}
public void getConditionVariablesByTimeAnalyse(String startTime, String endTime) {
HashMap<String, List<IdxBizUxfv>> IdxBizUxfvHashMap = getIdxBizUxfvListOfAnaLyse();
IdxBizUxfvHashMap.keySet().forEach(s -> {
List<IdxBizUxfv> list = IdxBizUxfvHashMap.get(s);
list.forEach(idxBizUxfv -> {
List<IdxBizC80c> gongkuangList = idxBizC80cMapper.selectList(new QueryWrapper<IdxBizC80c>().eq("ANALYSIS_GATEWAY_ID", idxBizUxfv.getGatewayId()).eq("ANALYSIS_POINT_ID", idxBizUxfv.getSequenceNbr()));
foreachHandlerConditionVariabAnalyse(s, gongkuangList, startTime, endTime, idxBizUxfv);
});
});
}
public void foreachHandlerConditionVariabAnalyse(String tableName, List<IdxBizC80c> list, String startTime, String endTime, IdxBizUxfv idxBizUxfv) {
String sql1 = String.format("select value from %s where address='%s' ", tableName, idxBizUxfv.getIndexAddress());
List<Map<String, Object>> returnList = influxdbUtil.query(sql1);
List<Map<String, String>> params = new ArrayList<>();
returnList.forEach((k) -> {
Map<String, String> map = new HashMap<>();
map.put("analysisVariable", k.get("value").toString());
map.put("analysisVariableId", idxBizUxfv.getSequenceNbr());
params.add(map);
});
final List<Map<String, String>> tempParams = params;
list.forEach(idxBizC80c -> {
logger.info("--------------------------------------------开始查询--------------------------------");
List<Map<String, String>> params1 = new ArrayList<>();
List<Map<String, String>> requestParams = new ArrayList<>();
// String sql = String.format("select value from %s where address='%s' and where time >= '%s' and where time <= '%s' ", tableName, idxBizUxfv.getIndexAddress(), startTime, endTime);
String sql = String.format("select value from %s where address='%s' ", tableName, idxBizC80c.getProcessIndexAddress());
List<Map<String, Object>> returnList1 = influxdbUtil.query(sql);
returnList.forEach((k) -> {
Map<String, String> map = new HashMap<>();
map.put("processVariable", k.get("value").toString());
map.put("processVariableId", idxBizC80c.getProcessPointId().toString());
params1.add(map);
});
if (tempParams.size() >= params1.size()) {
requestParams = megreMapList(tempParams, params1);
} else {
requestParams = megreMapList(params1, tempParams);
}
if (!requestParams.isEmpty()) {
logger.info("------------------------------------------开始调用工况变量算法----------------------------------------");
HttpUtil.createPost(gkblurl).body(JSON.toJSONString(requestParams)).execute().body();
try {
TimeUnit.SECONDS.sleep(sleepTime);
logger.info("------------------------------------------调用工况变量算法结束----------------------------------------");
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}); });
System.out.println(params.size()); }
public List<Map<String, String>> megreMapList(List<Map<String, String>> longList, List<Map<String, String>> shortList) {
List<Map<String, String>> resultList = new ArrayList<>();
for (int i = 0; i < longList.size(); i++) {
Map<String, String> map = longList.get(i);
Map<String, String> mapOfShortList = null;
if (i < mapOfShortList.size() - 1) {
mapOfShortList = shortList.get(i);
} else {
mapOfShortList = shortList.get(shortList.size() - 1);
}
if (map.containsKey("processVariable")) {
map.put("processVariable", mapOfShortList.get("processVariable"));
map.put("processVariableId", mapOfShortList.get("processVariableId"));
} else {
map.put("analysisVariable", mapOfShortList.get("analysisVariable"));
map.put("analysisVariableId", mapOfShortList.get("analysisVariableId"));
}
}
return resultList;
}
public void getConditionVariablesByTimeAnalyse1(String startTime, String endTime) {
HashMap<String, List<IdxBizUxfv>> IdxBizUxfvHashMap = getIdxBizUxfvListOfAnaLyse();
IdxBizUxfvHashMap.keySet().forEach(s -> {
List<IdxBizUxfv> list = IdxBizUxfvHashMap.get(s);
list.forEach(idxBizUxfv -> {
List<IdxBizC80c> gongkuangList = idxBizC80cMapper.selectList(new QueryWrapper<IdxBizC80c>().eq("ANALYSIS_GATEWAY_ID", idxBizUxfv.getGatewayId()).eq("ANALYSIS_POINT_ID", idxBizUxfv.getSequenceNbr()).orderByDesc("CORRELATION_COEFFICIENT").last("limit 0,3"));
foreachHandlerConditionVariabAnalyse(s, gongkuangList, startTime, endTime, idxBizUxfv);
});
});
}
public void foreachHandlerConditionVariabAnalyse1(String tableName, List<IdxBizC80c> list, String startTime, String endTime, IdxBizUxfv idxBizUxfv) {
String sql0 = String.format("select value from %s where address='%s' ", tableName, idxBizUxfv.getIndexAddress());
List<Map<String, Object>> returnList = influxdbUtil.query(sql0);
List<Map<String, String>> params = new ArrayList<>();
returnList.forEach((k) -> {
Map<String, String> map = new HashMap<>();
map.put("analysisVariable", k.get("value").toString());
map.put("analysisVariableId", idxBizUxfv.getSequenceNbr());
params.add(map);
});
final List<Map<String, String>> tempParams = params;
logger.info("--------------------------------------------开始查询--------------------------------");
List<Map<String, String>> params1 = new ArrayList<>();
List<Map<String, String>> requestParams = new ArrayList<>();
// String sql = String.format("select value from %s where address='%s' and where time >= '%s' and where time <= '%s' ", tableName, idxBizUxfv.getIndexAddress(), startTime, endTime);
String sql = String.format("select value from %s where address='%s' ", tableName, list.get(0).getProcessIndexAddress());
String sql1 = String.format("select value from %s where address='%s' ", tableName, list.get(1).getProcessIndexAddress());
String sql2 = String.format("select value from %s where address='%s' ", tableName, list.get(2).getProcessIndexAddress());
List<Map<String, Object>> returnList0 = influxdbUtil.query(sql);
List<Map<String, Object>> maxList = returnList0;
List<Map<String, Object>> returnList1 = influxdbUtil.query(sql);
maxList = maxList.size() > returnList1.size() ? maxList : returnList1;
List<Map<String, Object>> returnList2 = influxdbUtil.query(sql);
maxList = maxList.size() > returnList2.size() ? maxList : returnList2;
for (int j = 0; j < maxList.size(); j++) {
Map<String, String> map = new HashMap<>();
Map<String, Object> map1 = new HashMap<>();
Map<String, Object> map2 = new HashMap<>();
Map<String, Object> map3 = new HashMap<>();
if (j < returnList0.size() - 1) {
map1 = returnList0.get(j);
} else {
map1 = returnList0.get(returnList0.size() - 1);
}
if (j < returnList1.size() - 1) {
map2 = returnList1.get(j);
} else {
map2 = returnList1.get(returnList1.size() - 1);
}
if (j < returnList2.size() - 1) {
map3 = returnList2.get(j);
} else {
map3 = returnList2.get(returnList2.size() - 1);
}
map.put("processVariable1", map1.get("value").toString());
map.put("processVariable1Id", list.get(0).getProcessPointId().toString());
map.put("processVariable2", map2.get("value").toString());
map.put("processVariable2Id", list.get(1).getProcessPointId().toString());
map.put("processVariable3", map3.get("value").toString());
map.put("processVariable3Id", list.get(2).getProcessPointId().toString());
params1.add(map);
if (tempParams.size() >= params1.size()) {
requestParams = megreMapList1(tempParams, params1);
} else {
requestParams = megreMapList1(params1, tempParams);
}
if (!requestParams.isEmpty()) {
logger.info("------------------------------------------开始调用工况变量算法----------------------------------------");
HttpUtil.createPost(gkblurl).body(JSON.toJSONString(requestParams)).execute().body();
try {
TimeUnit.SECONDS.sleep(sleepTime);
logger.info("------------------------------------------调用工况变量算法结束----------------------------------------");
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
public List<Map<String, String>> megreMapList1(List<Map<String, String>> longList, List<Map<String, String>> shortList) {
List<Map<String, String>> resultList = new ArrayList<>();
for (int i = 0; i < longList.size(); i++) {
Map<String, String> map = longList.get(i);
Map<String, String> mapOfShortList = null;
if (i < mapOfShortList.size() - 1) {
mapOfShortList = shortList.get(i);
} else {
mapOfShortList = shortList.get(shortList.size() - 1);
}
if (map.containsKey("processVariable1")) {
map.put("processVariable1", mapOfShortList.get("processVariable1"));
map.put("processVariable1Id", mapOfShortList.get("processVariable1Id"));
map.put("processVariable2", mapOfShortList.get("processVariable2"));
map.put("processVariable2Id", mapOfShortList.get("processVariable2Id"));
map.put("processVariable3", mapOfShortList.get("processVariable3"));
map.put("processVariable3Id", mapOfShortList.get("processVariable3Id"));
} else {
map.put("analysisVariable", mapOfShortList.get("analysisVariable"));
map.put("analysisVariableId", mapOfShortList.get("analysisVariableId"));
}
}
return resultList;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment