TemperatureInfoController.java 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.gyee.runeconomy.controller;
  2. import com.gyee.common.model.PointData;
  3. import com.gyee.runeconomy.init.CacheContext;
  4. import com.gyee.runeconomy.model.TagInfo;
  5. import com.gyee.runeconomy.model.TemperatureInfo;
  6. import com.gyee.runeconomy.util.realtimesource.IEdosUtil;
  7. import org.springframework.web.bind.annotation.GetMapping;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestParam;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import javax.annotation.Resource;
  12. import java.util.*;
  13. import java.util.stream.Collectors;
  14. @RestController
  15. @RequestMapping("/api")
  16. public class TemperatureInfoController {
  17. @Resource
  18. private IEdosUtil edosUtil;
  19. /**
  20. * 获取温度信息
  21. *
  22. * @param id 场站ID
  23. */
  24. @GetMapping("/windturbine/temperature-info")
  25. public Collection<TemperatureInfo> getStationTemperatureInfo(@RequestParam(value = "id", required = false) String id,
  26. @RequestParam(value = "status", required = false) String ts,
  27. @RequestParam(value = "projects", required = false) String projects,
  28. @RequestParam(value = "pagenum", required = false) Integer pageNum,
  29. @RequestParam(value = "pagesize", required = false) Integer pageSize) throws Exception {
  30. List<TemperatureInfo> ls = null;
  31. if (id == null || "".equals(id)) {
  32. ls = CacheContext.temperatureInfos;
  33. } else {
  34. ls = CacheContext.temperatureInfos.stream().filter(t -> t.getStationId().equals(id)).collect(Collectors.toList());
  35. }
  36. if (ts != null && !"".equals(ts)) {
  37. String[] tts = ts.split(",");
  38. ls = ls.stream().filter(wt -> wt.isHadByStatus(tts)).collect(Collectors.toList());
  39. }
  40. addTemperatureInfo(ls);
  41. if (projects == null || "".equals(projects)) {
  42. return getPage(ls, pageNum, pageSize);
  43. }
  44. String[] ps = projects.split(",");
  45. Set<String> psset = Arrays.stream(ps).collect(Collectors.toSet());
  46. ls = ls.stream().filter(w -> psset.contains(w.getProjectId())).collect(Collectors.toList());
  47. addTemperatureInfo(ls);
  48. return getPage(ls, pageNum, pageSize);
  49. }
  50. private void addTemperatureInfo(List<TemperatureInfo> ls) throws Exception {
  51. List<String> tag = new ArrayList<>();
  52. List<TagInfo> tagInfos = new ArrayList<>();
  53. for (TemperatureInfo tem : ls) {
  54. tagInfos.addAll(tem.getTemperatureInfos());
  55. }
  56. for (TagInfo tagInfo : tagInfos) {
  57. tag.add(tagInfo.getTag());
  58. }
  59. List<PointData> realData = edosUtil.getRealData(tag);
  60. for (TagInfo tagInfo : tagInfos) {
  61. for (PointData real : realData) {
  62. if (real.getPointName().equals(tagInfo.getTag())) {
  63. tagInfo.setValue(real.getPointValueInDouble());
  64. tagInfo.setTimestamp(real.getPointTime());
  65. }
  66. }
  67. }
  68. }
  69. private Collection<TemperatureInfo> getPage(List<TemperatureInfo> ls, Integer pageNum, Integer pageSize) {
  70. if (pageNum == null || pageSize == null) {
  71. return ls;
  72. }
  73. int pagenum = pageNum < 1 ? 1 : pageNum;
  74. return ls.stream().skip((long) (pagenum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
  75. }
  76. }