WaterCollecationDao.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package com.shkpr.service.aimodelpower.dbdao.shizilaishuiDataSource;
  2. import com.shkpr.service.aimodelpower.bizmgr.KprAimWaterCollecationBizFun;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.beans.factory.annotation.Qualifier;
  6. import org.springframework.jdbc.core.JdbcTemplate;
  7. import org.springframework.stereotype.Repository;
  8. import org.springframework.util.StringUtils;
  9. import javax.sql.DataSource;
  10. import java.util.List;
  11. import java.util.Map;
  12. /**
  13. * @ClassName WaterCollecationDao
  14. * @Description: TODO
  15. * @Author LX
  16. * @Date 2024/5/27
  17. * @Version V1.0
  18. **/
  19. @Slf4j
  20. @Repository
  21. public class WaterCollecationDao {
  22. @Autowired
  23. @Qualifier("childDatasource")
  24. private DataSource childDataSource;
  25. @Autowired
  26. @Qualifier("child2Datasource")
  27. private DataSource child2DataSource;
  28. //TODO 查询样本及预测水量表;支持是否分页
  29. public List<Map<String,Object>> getTbMWater(boolean isPage,int limit,int offset,String extend){
  30. String sql = "";
  31. if ("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)){
  32. sql = "SELECT " +
  33. " a.\"id\",to_char(a.\"date\", 'YYYY-MM-DD') AS \"date\",a.\"max_temperature\",a.\"min_temperature\",a.\"weather\",a.\"month\",a.\"week\",a.\"holiday\",a.\"last_actual_water_withdrawals\",a.\"last_actual_water_supply\",a.\"actual_water_withdrawals\",a.\"actual_water_supply\",a.\"forecast_water_withdrawals\",a.\"forecast_actual_water_supply\",a.\"is_abnormal\",a.\"is_forecast\",a.\"last_modify_time\",a.\"zone_id\" " +
  34. " FROM tb_m_water AS a WHERE 1=1 ";
  35. }else {
  36. sql = "SELECT " +
  37. " a.\"ID\",to_char(a.\"Date\", 'YYYY-MM-DD') AS \"Date\",a.\"Max_temperature\",a.\"Min_temperature\",a.\"Weather\",a.\"Month\",a.\"Week\",a.\"Holiday\",a.\"LastActualWaterWithdrawals\",a.\"LastActualWaterSupply\",a.\"ActualWaterWithdrawals\",a.\"ActualWaterSupply\",a.\"ForecastWaterWithdrawals\",a.\"ForecastActualWaterSupply\",a.\"isAbnormal\",a.\"isForecast\",a.\"LastModifyTime\",a.\"orgId\" " +
  38. " FROM tb_m_water AS a WHERE 1=1 ";
  39. }
  40. if(!StringUtils.isEmpty(extend)){
  41. sql+=extend;
  42. }
  43. if(isPage) {
  44. sql += " LIMIT " + limit + " OFFSET " + offset;
  45. }
  46. JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
  47. List<Map<String, Object>> tableData = pgJdbc.queryForList(sql);
  48. return tableData;
  49. }
  50. //TODO 查询小时水量预测表;支持是否分页
  51. public List<Map<String,Object>> getTbMHourwater(boolean isPage,int limit,int offset,String extend){
  52. String sql = "";
  53. if ("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)){
  54. sql = "SELECT " +
  55. " a.\"id\",to_char(a.\"date\", 'YYYY-MM-DD') AS \"date\",a.\"hour\",a.\"hour_forecast_water_withdrawals\",a.\"hour_forecast_actual_water_supply\",a.\"water_withdrawals_energy\",a.\"water_supply_energy\",a.\"real_water_withdrawals_energy\",a.\"real_water_supply_energy\",a.\"last_modify_time\",a.\"zone_id\"," +
  56. " a.\"hour_actual_water_withdrawals\",a.\"hour_actual_water_supply\" " +
  57. " FROM tb_m_hourwater AS a WHERE 1=1 ";
  58. }else {
  59. sql = "SELECT " +
  60. " a.\"ID\",to_char(a.\"Date\", 'YYYY-MM-DD') AS \"Date\",a.\"Hour\",a.\"HourForecastWaterWithdrawals\",a.\"HourForecastActualWaterSupply\",a.\"WaterWithdrawalsEnergy\",a.\"WaterSupplyEnergy\",a.\"RealWaterWithdrawalsEnergy\",a.\"RealWaterSupplyEnergy\",a.\"LastModifyTime\",a.\"orgId\"," +
  61. " a.\"HourActualWaterWithdrawals\",a.\"HourActualWaterSupply\" " +
  62. " FROM tb_m_hourwater AS a WHERE 1=1 ";
  63. }
  64. if(!StringUtils.isEmpty(extend)){
  65. sql+=extend;
  66. }
  67. if(isPage) {
  68. sql += " LIMIT " + limit + " OFFSET " + offset;
  69. }
  70. JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
  71. List<Map<String, Object>> tableData = pgJdbc.queryForList(sql);
  72. return tableData;
  73. }
  74. //TODO 查询取水泵房电耗预测接口,支持是否分页
  75. public List<Map<String,Object>> getTbMHourwaterWaterwithdrawals(boolean isPage,int limit,int offset,String extend){
  76. String sql = "";
  77. if ("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)){
  78. sql = "SELECT " +
  79. " to_char(a.\"date\", 'YYYY-MM-DD') AS \"date\",a.\"hour\",a.\"pump_id\",a.\"pump_status\",a.\"hour_forecast_water_withdrawals\",a.\"pump_water\",a.\"real_pump_status\",a.\"pump_energy\",a.\"real_pump_energy\",a.\"last_modify_time\",a.\"id\",a.\"zone_id\" " +
  80. " FROM tb_m_hourwater_waterwithdrawals AS a WHERE 1=1 ";
  81. }else {
  82. sql = "SELECT " +
  83. " to_char(a.\"Date\", 'YYYY-MM-DD') AS \"Date\",a.\"Hour\",a.\"PumpID\",a.\"PumpStatus\",a.\"HourForecastWaterWithdrawals\",a.\"PumpWater\",a.\"RealPumpStatus\",a.\"PumpEnergy\",a.\"RealPumpEnergy\",a.\"LastModifyTime\",a.\"ID\",a.\"orgId\" " +
  84. " FROM tb_m_hourwater_waterwithdrawals AS a WHERE 1=1 ";
  85. }
  86. if(!StringUtils.isEmpty(extend)){
  87. sql+=extend;
  88. }
  89. if(isPage) {
  90. sql += " LIMIT " + limit + " OFFSET " + offset;
  91. }
  92. JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
  93. List<Map<String, Object>> tableData = pgJdbc.queryForList(sql);
  94. return tableData;
  95. }
  96. //TODO 查询供水泵房电耗预测接口,支持是否分页
  97. public List<Map<String,Object>> getTbMHourwaterWatersupply(boolean isPage,int limit,int offset,String extend){
  98. String sql = "";
  99. if ("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)){
  100. sql = "SELECT " +
  101. " a.\"id\",to_char(a.\"date\", 'YYYY-MM-DD') AS \"date\",a.\"hour\",a.\"pump_id\",a.\"pump_status\",a.\"hour_forecast_actual_water_supply\",a.\"pump_water\",a.\"real_pump_status\",a.\"pump_energy\",a.\"real_pump_energy\",a.\"last_modify_time\",a.\"zone_id\" " +
  102. " FROM tb_m_hourwater_watersupply AS a WHERE 1=1 ";
  103. }else {
  104. sql = "SELECT " +
  105. " a.\"ID\",to_char(a.\"Date\", 'YYYY-MM-DD') AS \"Date\",a.\"Hour\",a.\"PumpID\",a.\"PumpStatus\",a.\"HourForecastActualWaterSupply\",a.\"PumpWater\",a.\"RealPumpStatus\",a.\"PumpEnergy\",a.\"RealPumpEnergy\",a.\"LastModifyTime\",a.\"orgId\" " +
  106. " FROM tb_m_hourwater_watersupply AS a WHERE 1=1 ";
  107. }
  108. if(!StringUtils.isEmpty(extend)){
  109. sql+=extend;
  110. }
  111. if(isPage) {
  112. sql += " LIMIT " + limit + " OFFSET " + offset;
  113. }
  114. JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
  115. List<Map<String, Object>> tableData = pgJdbc.queryForList(sql);
  116. return tableData;
  117. }
  118. //TODO 查询水厂id配置列表
  119. public List<Map<String,Object>> getOrgConfig(boolean isPage,int limit,int offset,String extend){
  120. String sql = "SELECT * FROM water_org_config WHERE 1=1 ";
  121. if(!StringUtils.isEmpty(extend)){
  122. sql+=extend;
  123. }
  124. if(isPage) {
  125. sql += " LIMIT " + limit + " OFFSET " + offset;
  126. }
  127. JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
  128. List<Map<String, Object>> tableData = pgJdbc.queryForList(sql);
  129. return tableData;
  130. }
  131. //TODO 查询取水泵房方案数据,支持是否分页
  132. public List<Map<String,Object>> getTbMWaterwithdrawalspump(boolean isPage,int limit,int offset,String extend){
  133. String sql = "SELECT * FROM tb_m_waterwithdrawalspump WHERE 1=1 ";
  134. if(!StringUtils.isEmpty(extend)){
  135. sql+=extend;
  136. }
  137. if(isPage) {
  138. sql += " LIMIT " + limit + " OFFSET " + offset;
  139. }
  140. JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
  141. List<Map<String, Object>> tableData = pgJdbc.queryForList(sql);
  142. return tableData;
  143. }
  144. //TODO 查询供水泵房方案数据,支持是否分页
  145. public List<Map<String,Object>> getTbMWatersupplypump(boolean isPage,int limit,int offset,String extend){
  146. String sql = "SELECT * FROM tb_m_watersupplypump WHERE 1=1 ";
  147. if(!StringUtils.isEmpty(extend)){
  148. sql+=extend;
  149. }
  150. if(isPage) {
  151. sql += " LIMIT " + limit + " OFFSET " + offset;
  152. }
  153. JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
  154. List<Map<String, Object>> tableData = pgJdbc.queryForList(sql);
  155. return tableData;
  156. }
  157. /**
  158. * TODO 水位预测相关
  159. */
  160. //TODO 查询小时水位预测表;支持是否分页
  161. public List<Map<String,Object>> getTbLevelHourwater(boolean isPage,int limit,int offset,String extend){
  162. String sql = "";
  163. sql = "select aTable.id,TO_CHAR(aTable.date, 'YYYY-MM-DD') AS date,aTable.hour,aTable.hour_forecast_actual_level,aTable.hour_actual_water_level,aTable.last_modify_time,aTable.device_code,bTable.site_id,bTable.zone_id " +
  164. "from tb_m_hourlevel as aTable " +
  165. "left JOIN water_level_config as bTable " +
  166. "ON aTable.device_code = bTable.device_code " +
  167. "WHERE 1=1 ";
  168. if(!StringUtils.isEmpty(extend)){
  169. sql+=extend;
  170. }
  171. if(isPage) {
  172. sql += " LIMIT " + limit + " OFFSET " + offset;
  173. }
  174. JdbcTemplate pgJdbc = new JdbcTemplate(child2DataSource);
  175. List<Map<String, Object>> tableData = pgJdbc.queryForList(sql);
  176. return tableData;
  177. }
  178. }