123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- package com.gyee.runeconomy.controller.agc;
- import cn.hutool.core.date.DateTime;
- import cn.hutool.core.date.DateUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.TypeReference;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.gyee.common.model.PointData;
- import com.gyee.runeconomy.config.GyeeConfig;
- import com.gyee.runeconomy.init.CacheContext;
- import com.gyee.runeconomy.model.StatusTime;
- import com.gyee.runeconomy.model.auto.PointInfo;
- import com.gyee.runeconomy.model.auto.ProBasicEquipment;
- import com.gyee.runeconomy.model.auto.ProBasicEquipmentPoint;
- import com.gyee.runeconomy.service.agc.AgcDeviateService;
- import com.gyee.runeconomy.service.auto.IPointInfoService;
- import com.gyee.runeconomy.util.realtimesource.IEdosUtil;
- import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
- import org.springframework.data.redis.core.StringRedisTemplate;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.Resource;
- import java.util.*;
- import java.util.concurrent.ConcurrentHashMap;
- import java.util.stream.Collectors;
- /**
- * 获取各个场站AGC偏差分析数据
- */
- @RestController
- @RequestMapping("/agc")
- public class AgcDeviateController {
- public static Map<String, ConcurrentHashMap<Double, Double>> fitcoef = new ConcurrentHashMap<>();
- @Resource
- private AgcDeviateService agcDeviateService;
- @Resource
- private GyeeConfig gyeeConfig;
- @Resource
- private StringRedisTemplate stringRedisTemplate;
- @Resource
- private IEdosUtil edosUtil;
- @Resource
- private IPointInfoService pointInfoService;
- /**
- * 获取偏差信息
- *
- * @param startTs 开始时间
- * @param endTs 结束时间
- * @param id 场站id
- * @param interval 时间间隔
- * @return
- */
- @GetMapping("/deviate")
- public Map<String, AgcDeviateTag> getData(@RequestParam(value = "startTs") long startTs,
- @RequestParam(value = "endTs") long endTs,
- @RequestParam(value = "id") String id,
- @RequestParam(value = "interval", defaultValue = "60", required = false) int interval) {
- List<AgcDeviateTag> ls = new ArrayList<>();
- if (gyeeConfig.isOffLine()) {
- ls = agcDeviateService.getAgcDeviateTags(id, startTs, endTs, interval);
- } else {
- ls = agcDeviateService.getAgcDeviateTags(id, startTs, endTs, interval);
- }
- return ls.stream().collect(Collectors.toMap(AgcDeviateTag::getName, f -> f));
- }
- /**
- * 获取配置
- *
- * @return
- */
- @GetMapping("/config")
- public Object getAgcConifg() {
- return agcDeviateService.getConfig();
- }
- @GetMapping("/windturbine/curve")
- public Map<String, List<SpeedPowerAnalysis>> getWindturbineData(@RequestParam(value = "startTs") long startTs,
- @RequestParam(value = "endTs") long endTs,
- @RequestParam(value = "windturbineId") String windturbineId,
- @RequestParam(value = "interval", defaultValue = "60", required = false) int interval) throws Exception {
- //切换数据库
- LettuceConnectionFactory factory = (LettuceConnectionFactory) stringRedisTemplate.getConnectionFactory();
- int database = factory.getDatabase();
- factory.setDatabase(5);
- stringRedisTemplate.setConnectionFactory(factory);
- factory.afterPropertiesSet();
- factory.resetConnection();
- DateTime date = DateUtil.date(endTs * 1000);
- Map<String, List<SpeedPowerAnalysis>> map = new HashMap<>();
- List<SpeedPowerAnalysis> ls = new ArrayList<>();
- String[] wtIds = windturbineId.split(",");
- List<String> wtIdsLs = Arrays.asList(wtIds);
- for (String wtId : wtIdsLs) {
- SpeedPowerAnalysis spa = new SpeedPowerAnalysis();
- List<ProBasicEquipmentPoint> proBasicEquipmentPoints = CacheContext.pointNewMap.get(wtId);
- List<ProBasicEquipmentPoint> speedPoint = proBasicEquipmentPoints.stream().filter(p -> p.getUniformCode().equals("AI066")).collect(Collectors.toList());
- List<PointData> historyspeedDatas = edosUtil.getHistoryDatasSnap(speedPoint.get(0).getNemCode(), startTs, endTs, interval);
- List<Double> speedDatas = historyspeedDatas.stream().map(PointData::getPointValueInDouble).collect(Collectors.toList());
- spa.setWindSpeed(speedDatas);
- List<ProBasicEquipmentPoint> powerPoint = proBasicEquipmentPoints.stream().filter(p -> p.getUniformCode().equals("AI114")).collect(Collectors.toList());
- List<PointData> historyPowerDatas = edosUtil.getHistoryDatasSnap(powerPoint.get(0).getNemCode(), startTs, endTs, interval);
- List<Double> powerData = historyPowerDatas.stream().map(PointData::getPointValueInDouble).collect(Collectors.toList());
- spa.setActuatedPower(powerData);
- String powerCurveMonth = "glqxnh:" + date.month() + ":";
- Set<String> keys = stringRedisTemplate.keys(powerCurveMonth + wtId);
- Iterator<String> iterator = keys.iterator(); // 获取迭代器
- String firstKey = iterator.hasNext() ? iterator.next() : null;
- String yc = stringRedisTemplate.opsForValue().get(firstKey);
- ConcurrentHashMap<Double, Double> wtyc = JSON.parseObject(yc, new TypeReference<ConcurrentHashMap<Double, Double>>() {
- }.getType());
- fitcoef.put(firstKey.replaceFirst(powerCurveMonth, ""), wtyc);
- List<Double> llgl = speedDatas.stream().map(a -> fitcoef.get(wtId).get(a)).collect(Collectors.toList());
- spa.setTheoreticalPower(llgl);
- ls.add(spa);
- map.put(wtId, ls);
- }
- //关闭数据库切换
- factory.setDatabase(database);
- factory.afterPropertiesSet();
- factory.resetConnection();
- return map;
- }
- @GetMapping("/windtur")
- public Map<String, List<StatusTime>> getTestData(@RequestParam(value = "startTs") long startTs,
- @RequestParam(value = "endTs") long endTs,
- @RequestParam(value = "uniformcode") String uniformcode) throws Exception {
- Map<String, List<StatusTime>> map = new HashMap<>();
- QueryWrapper<PointInfo> qw = new QueryWrapper<>();
- qw.lambda().eq(PointInfo::getUniformCode, uniformcode);
- List<PointInfo> list = pointInfoService.list(qw);
- for (PointInfo ls : list) {
- List<StatusTime> ll = new ArrayList<>();
- List<PointData> historyDatasRaw = edosUtil.getHistoryDatasRaw(ls.getPointKey(), startTs, endTs);
- for (PointData pointData : historyDatasRaw) {
- StatusTime st = new StatusTime();
- st.setName(ls.getName());
- Date da=new Date(pointData.getPointTime());
- st.setTime(DateUtil.formatDateTime(da));
- String getstatus = getstatus((int) pointData.getPointValueInDouble());
- st.setStatus(getstatus);
- ll.add(st);
- }
- List<String> collect = CacheContext.wtls.stream().filter(w -> w.getId().equals(ls.getTurbineId())).map(ProBasicEquipment::getNemCode).collect(Collectors.toList());
- map.put(collect.get(0), ll);
- }
- List<String> sortedKeys = new ArrayList<>(map.keySet());
- Collections.sort(sortedKeys);
- Map<String, List<StatusTime>> sortedMap = new LinkedHashMap<>();
- for (String key : sortedKeys) {
- sortedMap.put(key, map.get(key));
- }
- return sortedMap;
- }
- private String getstatus(int number) {
- String statusText = "";
- switch (number) {
- case 0:
- statusText = "待机";
- break;
- case 1:
- statusText = "停机";
- break;
- case 2:
- statusText = "并网";
- break;
- case 4:
- statusText = "故障";
- break;
- case 6:
- statusText = "检修";
- break;
- case 8:
- statusText = "限电";
- break;
- case 12:
- statusText = "离线";
- break;
- default:
- statusText = "未知";
- break;
- }
- return statusText;
- }
- }
|