浏览代码

250817-1代码。

baoyubo 1 周之前
父节点
当前提交
6c60cae34e
共有 4 个文件被更改,包括 26 次插入8 次删除
  1. 3 2
      routers/api/rainfall/chemical_company.py
  2. 3 2
      routers/api/rainfall/dzzh.py
  3. 3 2
      routers/api/rainfall/rain_pits.py
  4. 17 2
      utils/rainfall_util.py

+ 3 - 2
routers/api/rainfall/chemical_company.py

@@ -84,8 +84,9 @@ async def get_list(
             if video_unit_info:
                 data['have_video'] = True
                 data['video_unit_indexcode'] = video_unit_info.indexCode
-            data['weather_warning_type'] = '暴雨预警'
-            data['weather_warninglevel'] = '3'
+            data['weather_warning_type'],data['weather_warninglevel'] = get_weather_warning(data['area'], db)
+            # data['weather_warning_type'] = '暴雨预警'
+            # data['weather_warninglevel'] = '3'
             if history_time:
                 real_code = get_real_code(db,data['longitude'],data['latitude'])
                 rainfall = get_rainfall(real_code,history_time,db)

+ 3 - 2
routers/api/rainfall/dzzh.py

@@ -75,8 +75,9 @@ async def get_list(
         result_list = []
         for row in result:
             data = dict(row)
-            data['weather_warning_type'] = '暴雨预警'
-            data['weather_warninglevel'] = '3'
+            data['weather_warning_type'],data['weather_warninglevel'] = get_weather_warning(data['area'], db)
+            # data['weather_warning_type'] = '暴雨预警'
+            # data['weather_warninglevel'] = '3'
             if history_time:
                 real_code = get_real_code(db, data['longitude'], data['latitude'])
                 rainfall = get_rainfall(real_code, history_time, db)

+ 3 - 2
routers/api/rainfall/rain_pits.py

@@ -73,8 +73,9 @@ async def get_list(
         result_list = []
         for row in result:
             data = dict(row)
-            data['weather_warning_type'] = '暴雨预警'
-            data['weather_warninglevel'] = '3'
+            data['weather_warning_type'],data['weather_warninglevel'] = get_weather_warning(data['district'], db)
+            # data['weather_warning_type'] = '暴雨预警'
+            # data['weather_warninglevel'] = '3'
             if history_time:
                 real_code = get_real_code(db,data['longitude'],data['latitude'])
                 rainfall = get_rainfall(real_code,history_time,db)

+ 17 - 2
utils/rainfall_util.py

@@ -73,8 +73,9 @@ def get_rainfall(
     twenty_four_hours_ago = now - timedelta(hours=num+1)
     formatted_now = f"{now.strftime('%Y-%m-%d %H')}:00:00"
     formatted_twenty_four_hours_ago = f"{twenty_four_hours_ago.strftime('%Y-%m-%d %H')}:00:00"
-    sql = text("""SELECT SUM(rainfall) as rainfall FROM `govdata_rain_data_info` where `code`=:code and create_time BETWEEN :formatted_twenty_four_hours_ago and :formatted_now""").bindparams(code=code,formatted_twenty_four_hours_ago=formatted_twenty_four_hours_ago,formatted_now=formatted_now)
+    sql = text("""SELECT SUM(rainfall) as rainfall FROM sharedb.`govdata_rain_data_info` where `code`=:code and create_time BETWEEN :formatted_twenty_four_hours_ago and :formatted_now""").bindparams(code=code,formatted_twenty_four_hours_ago=formatted_twenty_four_hours_ago,formatted_now=formatted_now)
     # 执行查询
+    # print(sql,formatted_now,formatted_twenty_four_hours_ago)
     result = db.execute(sql).fetchone()
 
     # 处理结果
@@ -86,4 +87,18 @@ def get_rainfall(
     # for i in rainfulldata:
     #     value += i['F3070220000034_000018005']
     #
-    # return value
+    # return value
+
+def get_weather_warning(area_name : str,db: Session = Depends(get_db)):
+    area_name= area_name.replace('区','').replace('市','').replace('技术开发区','').replace('新区','')
+    sql = text(
+        """SELECT CONCAT(`type`,`state`) as `weather_warning_type`,levelnum as `weather_warninglevel` FROM sharedb.weather_latest_warnings where county = :county or county='茂名' ORDER BY `levelnum` desc LIMIT 1""").bindparams(
+        county=area_name)
+    # 执行查询
+    # print(sql,formatted_now,formatted_twenty_four_hours_ago)
+    result = db.execute(sql).fetchone()
+    # 处理结果
+    if result:
+        return dict(result)['weather_warning_type'],dict(result)['weather_warninglevel']
+    else:
+        return '-','-'