QueryDataService.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package com.jiayue.client.service;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.springframework.jdbc.core.JdbcTemplate;
  4. import org.springframework.stereotype.Repository;
  5. import java.text.ParseException;
  6. import java.text.SimpleDateFormat;
  7. import java.util.Date;
  8. import java.util.List;
  9. import java.util.Map;
  10. @Repository
  11. @Slf4j
  12. public class QueryDataService {
  13. private final static String WHITH_AND_SQL_STR = "'and '";
  14. private final JdbcTemplate jdbcTemplate;
  15. public QueryDataService(JdbcTemplate jdbcTemplate) {
  16. this.jdbcTemplate = jdbcTemplate;
  17. }
  18. public static Long changStrTimeToLongTime(String strTime) {
  19. long resultTime = -1L;
  20. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  21. //设置要读取的时间字符串格式
  22. try {
  23. Date date = format.parse(strTime);
  24. resultTime = date.getTime();
  25. } catch (ParseException e) {
  26. log.error("转换时间 {} 为Long格式出错:{}", strTime, e);
  27. }
  28. return resultTime;
  29. }
  30. /**
  31. * 查询所有电站信息
  32. */
  33. public List<Map<String, Object>> getStations() {
  34. String stationsSql = "SELECT C_STATION_CODE,C_NAME,C_CAPACITY " +
  35. "from t_electric_field ";
  36. return jdbcTemplate.queryForList(stationsSql);
  37. }
  38. /**
  39. * 查询实际功率
  40. *
  41. * @param startTime
  42. * @param endTime
  43. * @param stationCode
  44. * @return
  45. */
  46. public List<Map<String, Object>> getRps(String startTime, String endTime, String stationCode) {
  47. String rpsSql = "SELECT C_TIME,C_STATION_CODE,C_REAL_VALUE " +
  48. "from t_power_station_status_data where C_STATION_CODE='" + stationCode +
  49. "' and C_TIME between '" + startTime + WHITH_AND_SQL_STR + endTime + "'";
  50. log.info("实际功率回传数据查询sql:{}", rpsSql);
  51. return jdbcTemplate.queryForList(rpsSql);
  52. }
  53. /**
  54. * 查询短期数据
  55. *
  56. * @param startTime
  57. * @param endTime
  58. * @param stationCode
  59. * @return
  60. */
  61. public List<Map<String, Object>> getDqs(String startTime, String endTime, String stationCode) {
  62. String dqsSql = "SELECT C_FORECAST_TIME,C_STATION_CODE,C_ABLE_VALUE " +
  63. "from t_forecast_power_short_term_his where C_STATION_CODE='" + stationCode +
  64. "' and C_FORECAST_TIME between '" + changStrTimeToLongTime(startTime) +
  65. WHITH_AND_SQL_STR + changStrTimeToLongTime(endTime) + "'";
  66. log.info("短期回传数据查询sql:{}", dqsSql);
  67. return jdbcTemplate.queryForList(dqsSql);
  68. }
  69. /**
  70. * 查询超短期数据
  71. *
  72. * @param startTime
  73. * @param endTime
  74. * @param stationCode
  75. * @return
  76. */
  77. public List<Map<String, Object>> getCdqs(String startTime, String endTime, String stationCode) {
  78. String cdqsSql = "SELECT C_FORECAST_TIME,C_STATION_CODE,C_ABLE_VALUE " +
  79. "from t_forecast_power_ultra_short_term_his where C_STATION_CODE='" + stationCode +
  80. "' and C_FORECAST_TIME between '" + changStrTimeToLongTime(startTime) +
  81. WHITH_AND_SQL_STR + changStrTimeToLongTime(endTime) + "'";
  82. log.info("超短期回传数据查询sql:{}", cdqsSql);
  83. return jdbcTemplate.queryForList(cdqsSql);
  84. }
  85. /**
  86. * 查询环境检测仪数据:时间,设备编号,总辐射,环境温度
  87. *
  88. * @param startTime
  89. * @param endTime
  90. * @param equirpmentNo
  91. * @return
  92. */
  93. public List<Map<String, Object>> getWeatherds(String startTime, String endTime, String equirpmentNo) {
  94. String wedSql = "SELECT C_TIME,C_EQUIPMENT_ID,C_GLOBALR,C_AIRT " +
  95. "from t_weather_station_status_data where C_EQUIPMENT_ID='" + equirpmentNo
  96. + "' and C_TIME between '" + startTime
  97. + WHITH_AND_SQL_STR + endTime + "'";
  98. log.info("超短期回传数据查询sql:{}", wedSql);
  99. return jdbcTemplate.queryForList(wedSql);
  100. }
  101. /**
  102. * 查询测风塔数据 :时间,设备编号,风速,风向
  103. *
  104. * @param startTime
  105. * @param endTime
  106. * @param equirpmentNo
  107. * @return
  108. */
  109. public List<Map<String, Object>> getCfts(String startTime, String endTime, String equirpmentNo) {
  110. String cftsSql = "SELECT C_TIME,C_EQUIPMENT_ID,C_WS_INST_HUB_HEIGHT,C_WD_INST_HUB_HEIGHT " +
  111. "from t_wind_tower_status_data where C_EQUIPMENT_ID='" + equirpmentNo
  112. + "' and C_TIME between '" + startTime
  113. + WHITH_AND_SQL_STR + endTime + "'";
  114. log.info("测风塔回传数据查询sql:{}", cftsSql);
  115. return jdbcTemplate.queryForList(cftsSql);
  116. }
  117. /**
  118. * 查询风机信息:时间,设备编号,风速,风向
  119. *
  120. * @param startTime
  121. * @param endTime
  122. * @param equirpmentNo
  123. * @return
  124. */
  125. public List<Map<String, Object>> getFjs(String startTime, String endTime, String equirpmentNo) {
  126. String fjsSql = "SELECT C_TIME,C_EQUIPMENT_ID,C_WS,C_WD " +
  127. "from t_wind_turbine_status_data where C_EQUIPMENT_ID='" + equirpmentNo
  128. + "' and C_TIME between '" + startTime
  129. + WHITH_AND_SQL_STR + endTime + "'";
  130. log.info("风机回传数据查询sql:{}", fjsSql);
  131. return jdbcTemplate.queryForList(fjsSql);
  132. }
  133. /**
  134. * 查询环境检测仪信息
  135. *
  136. * @param stationCode
  137. * @return
  138. */
  139. public List<Map<String, Object>> getWeatherStations(String stationCode) {
  140. String fjsSql = "SELECT C_ID,C_EQUIPMENT_NO,C_EQUIPMENT_TYPE " +
  141. "from t_weather_station_info where C_STATION_CODE='" + stationCode + "' ";
  142. log.info("环境检测仪设备信息查询sql:{}", fjsSql);
  143. return jdbcTemplate.queryForList(fjsSql);
  144. }
  145. /**
  146. * 查询测风塔信息
  147. *
  148. * @param stationCode
  149. * @return
  150. */
  151. public List<Map<String, Object>> getWindTower(String stationCode) {
  152. String fjsSql = "SELECT C_ID,C_EQUIPMENT_NO,C_EQUIPMENT_TYPE " +
  153. "from t_wind_tower_info where C_STATION_CODE='" + stationCode + "' ";
  154. log.info("测风塔设备信息查询sql:{}", fjsSql);
  155. return jdbcTemplate.queryForList(fjsSql);
  156. }
  157. /**
  158. * 查询风机信息
  159. *
  160. * @param stationCode
  161. * @return
  162. */
  163. public List<Map<String, Object>> getWindTurbine(String stationCode) {
  164. String fjsSql = "SELECT C_ID,C_EQUIPMENT_NO,C_EQUIPMENT_TYPE " +
  165. "from t_wind_turbine_info where C_STATION_CODE='" + stationCode + "' ";
  166. log.info("风机设备信息查询sql:{}", fjsSql);
  167. return jdbcTemplate.queryForList(fjsSql);
  168. }
  169. }