From d6a4e2730aeff24b8e28eee486926b945bf671d6 Mon Sep 17 00:00:00 2001
From: wuww <252740454@qq.com>
Date: 星期三, 14 五月 2025 17:44:49 +0800
Subject: [PATCH] 修改数据库表名、调整降雨文件、连通模拟过程。

---
 data/init.sql |   96 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 64 insertions(+), 32 deletions(-)

diff --git a/data/init.sql b/data/init.sql
index 1fefb81..2e94e8d 100644
--- a/data/init.sql
+++ b/data/init.sql
@@ -4,9 +4,12 @@
 create extension if not exists "uuid-ossp";
 
 create schema if not exists nsl;
+
+alter table nsl.simu rename to tbl_yj_tr_simulate;
+alter table nsl.region rename to tbl_yj_tr_region;
 ---------------------------------------------- 1.鎺ㄦ紨妯℃嫙
--- drop table if exists nsl.simu;
-create table nsl.simu (
+-- drop table if exists nsl.tbl_yj_tr_simulate;
+create table nsl.tbl_yj_tr_simulate (
   	id serial primary key,
   	name varchar(200),
   	service_name varchar(200),
@@ -24,50 +27,50 @@
 	geom geometry(MultiPolygon, 4490)
 );
 -- drop index nsl.idx_nsl_simu_geom;
-create index idx_nsl_simu_geom on nsl.simu using GIST (geom);
+create index idx_nsl_simu_geom on nsl.tbl_yj_tr_simulate using GIST (geom);
 
-comment on table nsl.simu is '鎺ㄦ紨妯℃嫙琛�';
-comment on column nsl.simu.id is '涓婚敭ID';
-comment on column nsl.simu.name is '鍚嶇О';
-comment on column nsl.simu.service_name is '鏈嶅姟鍚嶇О';
-comment on column nsl.simu.type is '绫诲埆锛�1-棰勬祴妯℃嫙锛�2-瀹炴椂妯℃嫙锛�3-鍘嗗彶妯℃嫙';
-comment on column nsl.simu.area_type is '鍖哄煙绫诲埆锛�0-鑷畾涔夛紝1-琛屾斂鍖哄垝锛�2-閲嶇偣鍖哄煙锛�3-閲嶇偣娌�';
-comment on column nsl.simu.area_name is '鍖哄煙鍚嶇О';
-comment on column nsl.simu.data is '鏁版嵁(JSON)';
-comment on column nsl.simu.status is '鐘舵�侊細0-鍒涘缓浠跨湡锛�1-棰勫鐞嗭紝2-鍒嗘瀽涓紝10-瀹屾垚锛�20-鍑洪敊';
-comment on column nsl.simu.result is '缁撴灉(JSON)';
-comment on column nsl.simu.create_time is '鍒涘缓鏃堕棿';
-comment on column nsl.simu.create_user is '鍒涘缓浜�';
-comment on column nsl.simu.update_time is '鏇存柊鏃堕棿';
-comment on column nsl.simu.update_user is '鏇存柊浜�';
-comment on column nsl.simu.bak is '澶囨敞';
-comment on column nsl.simu.geom is '绌洪棿浣嶇疆';
+comment on table nsl.tbl_yj_tr_simulate is '鎺ㄦ紨妯℃嫙琛�';
+comment on column nsl.tbl_yj_tr_simulate.id is '涓婚敭ID';
+comment on column nsl.tbl_yj_tr_simulate.name is '鍚嶇О';
+comment on column nsl.tbl_yj_tr_simulate.service_name is '鏈嶅姟鍚嶇О';
+comment on column nsl.tbl_yj_tr_simulate.type is '绫诲埆锛�1-棰勬祴妯℃嫙锛�2-瀹炴椂妯℃嫙锛�3-鍘嗗彶妯℃嫙';
+comment on column nsl.tbl_yj_tr_simulate.area_type is '鍖哄煙绫诲埆锛�0-鑷畾涔夛紝1-琛屾斂鍖哄垝锛�2-閲嶇偣鍖哄煙锛�3-閲嶇偣娌�';
+comment on column nsl.tbl_yj_tr_simulate.area_name is '鍖哄煙鍚嶇О';
+comment on column nsl.tbl_yj_tr_simulate.data is '鏁版嵁(JSON)';
+comment on column nsl.tbl_yj_tr_simulate.status is '鐘舵�侊細0-鍒涘缓浠跨湡锛�1-棰勫鐞嗭紝2-鍒嗘瀽涓紝10-瀹屾垚锛�20-鍑洪敊';
+comment on column nsl.tbl_yj_tr_simulate.result is '缁撴灉(JSON)';
+comment on column nsl.tbl_yj_tr_simulate.create_time is '鍒涘缓鏃堕棿';
+comment on column nsl.tbl_yj_tr_simulate.create_user is '鍒涘缓浜�';
+comment on column nsl.tbl_yj_tr_simulate.update_time is '鏇存柊鏃堕棿';
+comment on column nsl.tbl_yj_tr_simulate.update_user is '鏇存柊浜�';
+comment on column nsl.tbl_yj_tr_simulate.bak is '澶囨敞';
+comment on column nsl.tbl_yj_tr_simulate.geom is '绌洪棿浣嶇疆';
 
 -- insert into nsl.simu (name, service_name, type, area_type, area_name, status, geom) values ('棰勬祴妯℃嫙-0416', '20250416100000', 1, 1, '澶у叴鍖�', 0, ST_GeomFromText('MULTIPOLYGON(((116.666748 39.639859,116.659403 39.626287,116.665956 39.654698,116.666748 39.639859)))'));
 
-select id,name,service_name,type,area_type,area_name,status,result,create_time,update_time,bak,data,st_astext(geom) from nsl.simu where id > 0 order by id desc;
--- update nsl.simu set status=0,area_name='鎴垮北鍖�',result=null,data = '{"startTime":"2025-05-01 11:10:54","type":3,"total":50,"duration":6,"intensity":70,"history":"XX骞�50mm闄嶉洦"}' where id = 17;
--- update nsl.simu set status=0,area_name='鎴垮北鍖�',result=null,data = '{"startTime":"2025-05-06 14:31:58","type":3,"total":1025,"duration":14,"intensity":78.5,"rainfalls":[{"time":"2023-07-29 22:00:00","intensity":2,"total":2},{"time":"2023-07-29 23:00:00","intensity":2,"total":4},{"time":"2023-07-30 00:00:00","intensity":3.5,"total":7.5},{"time":"2023-07-30 01:00:00","intensity":2.5,"total":10},{"time":"2023-07-30 02:00:00","intensity":2,"total":244.5},{"time":"2023-07-30 03:00:00","intensity":3.5,"total":339.5},{"time":"2023-07-30 04:00:00","intensity":6,"total":345.5},{"time":"2023-07-30 05:00:00","intensity":10.5,"total":356},{"time":"2023-07-30 06:00:00","intensity":4.5,"total":360.5},{"time":"2023-07-30 07:00:00","intensity":5.5,"total":366},{"time":"2023-07-30 08:00:00","intensity":13,"total":379},{"time":"2023-07-30 09:00:00","intensity":17,"total":396},{"time":"2023-07-30 10:00:00","intensity":15.5,"total":25.5},{"time":"2023-07-30 11:00:00","intensity":17.5,"total":43},{"time":"2023-07-30 12:00:00","intensity":16,"total":59},{"time":"2023-07-30 13:00:00","intensity":18.5,"total":77.5},{"time":"2023-07-30 14:00:00","intensity":13,"total":90.5},{"time":"2023-07-30 15:00:00","intensity":23.5,"total":114},{"time":"2023-07-30 16:00:00","intensity":28.5,"total":142.5},{"time":"2023-07-30 17:00:00","intensity":24.5,"total":167},{"time":"2023-07-30 18:00:00","intensity":43,"total":210},{"time":"2023-07-30 19:00:00","intensity":32.5,"total":242.5},{"time":"2023-07-30 20:00:00","intensity":49.5,"total":294},{"time":"2023-07-30 21:00:00","intensity":18.5,"total":312.5},{"time":"2023-07-30 22:00:00","intensity":8,"total":320.5},{"time":"2023-07-30 23:00:00","intensity":15.5,"total":336},{"time":"2023-07-31 00:00:00","intensity":12.5,"total":408.5},{"time":"2023-07-31 01:00:00","intensity":15,"total":423.5},{"time":"2023-07-31 02:00:00","intensity":4,"total":537},{"time":"2023-07-31 03:00:00","intensity":12,"total":647},{"time":"2023-07-31 04:00:00","intensity":5,"total":652},{"time":"2023-07-31 05:00:00","intensity":36.5,"total":688.5},{"time":"2023-07-31 06:00:00","intensity":18,"total":706.5},{"time":"2023-07-31 07:00:00","intensity":26,"total":732.5},{"time":"2023-07-31 08:00:00","intensity":38,"total":770.5},{"time":"2023-07-31 09:00:00","intensity":39.5,"total":810},{"time":"2023-07-31 10:00:00","intensity":38,"total":461.5},{"time":"2023-07-31 11:00:00","intensity":27,"total":488.5},{"time":"2023-07-31 12:00:00","intensity":5.5,"total":494},{"time":"2023-07-31 13:00:00","intensity":2.5,"total":496.5},{"time":"2023-07-31 14:00:00","intensity":4,"total":500.5},{"time":"2023-07-31 15:00:00","intensity":8,"total":508.5},{"time":"2023-07-31 16:00:00","intensity":8.5,"total":517},{"time":"2023-07-31 17:00:00","intensity":0.5,"total":517.5},{"time":"2023-07-31 18:00:00","intensity":10,"total":527.5},{"time":"2023-07-31 19:00:00","intensity":5.5,"total":533},{"time":"2023-07-31 20:00:00","intensity":20.5,"total":557.5},{"time":"2023-07-31 21:00:00","intensity":25,"total":582.5},{"time":"2023-07-31 22:00:00","intensity":25.5,"total":608},{"time":"2023-07-31 23:00:00","intensity":27,"total":635},{"time":"2023-08-01 00:00:00","intensity":78.5,"total":888.5},{"time":"2023-08-01 01:00:00","intensity":32.5,"total":921},{"time":"2023-08-01 02:00:00","intensity":9.5,"total":956.5},{"time":"2023-08-01 03:00:00","intensity":6.5,"total":981.5},{"time":"2023-08-01 04:00:00","intensity":22.5,"total":1004},{"time":"2023-08-01 05:00:00","intensity":1,"total":1005},{"time":"2023-08-01 06:00:00","intensity":0,"total":1005},{"time":"2023-08-01 07:00:00","intensity":8,"total":1013},{"time":"2023-08-01 08:00:00","intensity":6,"total":1019},{"time":"2023-08-01 09:00:00","intensity":5.5,"total":1024.5},{"time":"2023-08-01 10:00:00","intensity":3,"total":924},{"time":"2023-08-01 11:00:00","intensity":5.5,"total":929.5},{"time":"2023-08-01 12:00:00","intensity":8.5,"total":938},{"time":"2023-08-01 13:00:00","intensity":8,"total":946},{"time":"2023-08-01 14:00:00","intensity":0.5,"total":946.5},{"time":"2023-08-01 16:00:00","intensity":0,"total":946.5},{"time":"2023-08-01 18:00:00","intensity":0.5,"total":947},{"time":"2023-08-01 20:00:00","intensity":17,"total":973.5},{"time":"2023-08-01 21:00:00","intensity":1,"total":974.5},{"time":"2023-08-01 22:00:00","intensity":0.5,"total":975},{"time":"2023-08-02 00:00:00","intensity":0,"total":1024.5},{"time":"2023-08-02 02:00:00","intensity":0,"total":1025},{"time":"2023-08-02 03:00:00","intensity":0.5,"total":1025.5},{"time":"2023-08-02 04:00:00","intensity":0,"total":1025.5},{"time":"2023-08-02 06:00:00","intensity":0,"total":1025.5},{"time":"2023-08-02 08:00:00","intensity":0,"total":1025.5},{"time":"2023-08-02 12:00:00","intensity":0,"total":1024.5},{"time":"2023-08-02 14:00:00","intensity":0,"total":1024.5},{"time":"2023-08-02 15:00:00","intensity":0.5,"total":1025},{"time":"2023-08-02 18:00:00","intensity":0,"total":1025},{"time":"2023-08-02 20:00:00","intensity":0,"total":1025},{"time":"2023-08-02 22:00:00","intensity":0,"total":1025}]}' where id = 17;
+select id,name,service_name,type,area_type,area_name,status,result,create_time,update_time,bak,data,st_astext(geom) from nsl.tbl_yj_tr_simulate where id > 0 order by id desc;
+-- update nsl.tbl_yj_tr_simulate set status=0,area_name='鎴垮北鍖�',result=null,data = '{"startTime":"2025-05-01 11:10:54","type":3,"total":150,"duration":6,"intensity":60,"history":"XX骞�50mm闄嶉洦"}' where id = 17;
+-- update nsl.tbl_yj_tr_simulate set status=0,area_name='鎴垮北鍖�',result=null,data = '{"startTime":"2025-05-06 14:31:58","type":3,"total":1000,"duration":6,"intensity":78.5,"rainfalls":[{"time":"2023-07-29 22:00:00","intensity":2,"total":2},{"time":"2023-07-29 23:00:00","intensity":2,"total":4},{"time":"2023-07-30 00:00:00","intensity":3.5,"total":7.5},{"time":"2023-07-30 01:00:00","intensity":2.5,"total":10},{"time":"2023-07-30 02:00:00","intensity":2,"total":244.5},{"time":"2023-07-30 03:00:00","intensity":3.5,"total":339.5},{"time":"2023-07-30 04:00:00","intensity":6,"total":345.5},{"time":"2023-07-30 05:00:00","intensity":10.5,"total":356},{"time":"2023-07-30 06:00:00","intensity":4.5,"total":360.5},{"time":"2023-07-30 07:00:00","intensity":5.5,"total":366},{"time":"2023-07-30 08:00:00","intensity":13,"total":379},{"time":"2023-07-30 09:00:00","intensity":17,"total":396},{"time":"2023-07-30 10:00:00","intensity":15.5,"total":25.5},{"time":"2023-07-30 11:00:00","intensity":17.5,"total":43},{"time":"2023-07-30 12:00:00","intensity":16,"total":59},{"time":"2023-07-30 13:00:00","intensity":18.5,"total":77.5},{"time":"2023-07-30 14:00:00","intensity":13,"total":90.5},{"time":"2023-07-30 15:00:00","intensity":23.5,"total":114},{"time":"2023-07-30 16:00:00","intensity":28.5,"total":142.5},{"time":"2023-07-30 17:00:00","intensity":24.5,"total":167},{"time":"2023-07-30 18:00:00","intensity":43,"total":210},{"time":"2023-07-30 19:00:00","intensity":32.5,"total":242.5},{"time":"2023-07-30 20:00:00","intensity":49.5,"total":294},{"time":"2023-07-30 21:00:00","intensity":18.5,"total":312.5},{"time":"2023-07-30 22:00:00","intensity":8,"total":320.5},{"time":"2023-07-30 23:00:00","intensity":15.5,"total":336},{"time":"2023-07-31 00:00:00","intensity":12.5,"total":408.5},{"time":"2023-07-31 01:00:00","intensity":15,"total":423.5},{"time":"2023-07-31 02:00:00","intensity":4,"total":537},{"time":"2023-07-31 03:00:00","intensity":12,"total":647},{"time":"2023-07-31 04:00:00","intensity":5,"total":652},{"time":"2023-07-31 05:00:00","intensity":36.5,"total":688.5},{"time":"2023-07-31 06:00:00","intensity":18,"total":706.5},{"time":"2023-07-31 07:00:00","intensity":26,"total":732.5},{"time":"2023-07-31 08:00:00","intensity":38,"total":770.5},{"time":"2023-07-31 09:00:00","intensity":39.5,"total":810},{"time":"2023-07-31 10:00:00","intensity":38,"total":461.5},{"time":"2023-07-31 11:00:00","intensity":27,"total":488.5},{"time":"2023-07-31 12:00:00","intensity":5.5,"total":494},{"time":"2023-07-31 13:00:00","intensity":2.5,"total":496.5},{"time":"2023-07-31 14:00:00","intensity":4,"total":500.5},{"time":"2023-07-31 15:00:00","intensity":8,"total":508.5},{"time":"2023-07-31 16:00:00","intensity":8.5,"total":517},{"time":"2023-07-31 17:00:00","intensity":0.5,"total":517.5},{"time":"2023-07-31 18:00:00","intensity":10,"total":527.5},{"time":"2023-07-31 19:00:00","intensity":5.5,"total":533},{"time":"2023-07-31 20:00:00","intensity":20.5,"total":557.5},{"time":"2023-07-31 21:00:00","intensity":25,"total":582.5},{"time":"2023-07-31 22:00:00","intensity":25.5,"total":608},{"time":"2023-07-31 23:00:00","intensity":27,"total":635},{"time":"2023-08-01 00:00:00","intensity":78.5,"total":888.5},{"time":"2023-08-01 01:00:00","intensity":32.5,"total":921},{"time":"2023-08-01 02:00:00","intensity":9.5,"total":956.5},{"time":"2023-08-01 03:00:00","intensity":6.5,"total":981.5},{"time":"2023-08-01 04:00:00","intensity":22.5,"total":1004},{"time":"2023-08-01 05:00:00","intensity":1,"total":1005},{"time":"2023-08-01 06:00:00","intensity":0,"total":1005},{"time":"2023-08-01 07:00:00","intensity":8,"total":1013},{"time":"2023-08-01 08:00:00","intensity":6,"total":1019},{"time":"2023-08-01 09:00:00","intensity":5.5,"total":1024.5},{"time":"2023-08-01 10:00:00","intensity":3,"total":924},{"time":"2023-08-01 11:00:00","intensity":5.5,"total":929.5},{"time":"2023-08-01 12:00:00","intensity":8.5,"total":938},{"time":"2023-08-01 13:00:00","intensity":8,"total":946},{"time":"2023-08-01 14:00:00","intensity":0.5,"total":946.5},{"time":"2023-08-01 16:00:00","intensity":0,"total":946.5},{"time":"2023-08-01 18:00:00","intensity":0.5,"total":947},{"time":"2023-08-01 20:00:00","intensity":17,"total":973.5},{"time":"2023-08-01 21:00:00","intensity":1,"total":974.5},{"time":"2023-08-01 22:00:00","intensity":0.5,"total":975},{"time":"2023-08-02 00:00:00","intensity":0,"total":1024.5},{"time":"2023-08-02 02:00:00","intensity":0,"total":1025},{"time":"2023-08-02 03:00:00","intensity":0.5,"total":1025.5},{"time":"2023-08-02 04:00:00","intensity":0,"total":1025.5},{"time":"2023-08-02 06:00:00","intensity":0,"total":1025.5},{"time":"2023-08-02 08:00:00","intensity":0,"total":1025.5},{"time":"2023-08-02 12:00:00","intensity":0,"total":1024.5},{"time":"2023-08-02 14:00:00","intensity":0,"total":1024.5},{"time":"2023-08-02 15:00:00","intensity":0.5,"total":1025},{"time":"2023-08-02 18:00:00","intensity":0,"total":1025},{"time":"2023-08-02 20:00:00","intensity":0,"total":1025},{"time":"2023-08-02 22:00:00","intensity":0,"total":1025}]}' where id = 17;
 ---------------------------------------------- 2.鎺ㄦ紨鍖哄煙
--- drop table if exists nsl.region;
-create table nsl.region (
+-- drop table if exists nsl.tbl_yj_tr_region;
+create table nsl.tbl_yj_tr_region (
   	id serial primary key,
   	name varchar(200),
     type smallint default 1,
 	geom geometry(MultiPolygon, 4490)
 );
 -- drop index nsl.idx_nsl_region_geom;
-create index idx_nsl_region_geom on nsl.region using GIST (geom);
+create index idx_nsl_region_geom on nsl.tbl_yj_tr_region using GIST (geom);
 
-comment on table nsl.region is '鎺ㄦ紨鍖哄煙琛�';
-comment on column nsl.region.id is '涓婚敭ID';
-comment on column nsl.region.name is '鍚嶇О';
-comment on column nsl.region.type is '绫诲埆锛�1-琛屾斂鍖哄垝锛�2-閲嶇偣鍖哄煙锛�3-閲嶇偣娌�';
-comment on column nsl.region.geom is '绌洪棿浣嶇疆';
+comment on table nsl.tbl_yj_tr_region is '鎺ㄦ紨鍖哄煙琛�';
+comment on column nsl.tbl_yj_tr_region.id is '涓婚敭ID';
+comment on column nsl.tbl_yj_tr_region.name is '鍚嶇О';
+comment on column nsl.tbl_yj_tr_region.type is '绫诲埆锛�1-琛屾斂鍖哄垝锛�2-閲嶇偣鍖哄煙锛�3-閲嶇偣娌�';
+comment on column nsl.tbl_yj_tr_region.geom is '绌洪棿浣嶇疆';
 
 -- insert into nsl.region (name, type, geom) values ('澶у叴', 1, ST_GeomFromText('MULTIPOLYGON(((116.666748 39.639859,116.659403 39.626287,116.665956 39.654698,116.666748 39.639859)))'));
 
-select id, name, type, st_astext(geom) from nsl.region order by type, id;
+select id, name, type, st_astext(geom) from nsl.tbl_yj_tr_region order by type, id;
 ---------------------------------------------- 3.闆ㄩ噺璁� *
 -- drop table if exists nsl.udometer;
 create table nsl.udometer (
@@ -89,9 +92,38 @@
 ---------------------------------------------- 灏� MULTIPOLYGON 杞崲涓� POLYGON
 select st_astext(ST_GeometryN(geom, generate_series(1, ST_NumGeometries(geom)))) as geom from nsl.region limit 1;
 
+---------------------------------------------- 闆姳涓婚敭
+create sequence nsl.seq_tab_id
+   start with 0   -- 搴忓垪鍊煎紑濮嬪��
+   increment by 1 -- 姝ラ暱
+   minvalue 0     -- 鏈�灏忓��
+   no maxvalue    -- 涓轰簡淇濊瘉 搴忓垪鏈夊簭锛� 濡傛灉璁惧畾浜嗘渶澶у�硷紝鍒欒鎵撳紑cycle
+   cache 100;
 
+create or replace function nsl.fn_generate_snow_id(input_machine_id integer)
+   returns bigint as $$
+declare
+   -- our_epoch bigint := 1672502400000; --2023-1-1 00:00:00 鐨勬椂闂存埑 , 淇敼鍩哄噯鏃堕棿涓�2023-01-01. 杩欐牱灏卞彲浠ヤ娇鐢ㄥ埌 2023 +69 = 2092骞淬��
+   seq_id bigint := 0;
+   machine_id int := 0;
+   now_millis bigint := 0;
+   result bigint := 0;
+begin
+   seq_id := nextval('nsl.seq_tab_id') % 4096; -- 搴忓垪鍙峰�煎ぇ浜�4096锛岄渶瑕佸惊鐜�
+   machine_id := input_machine_id % 1024 ;
+   -- select floor(extract(epoch from clock_timestamp()) * 1000) into now_millis;
+   -- result := result | ((now_millis - our_epoch) << 22) ; -- 璋冩暣鍩哄噯鏃堕棿鐨勫疄鐜�
+   select floor(extract(epoch from clock_timestamp()) * 1000) into now_millis;
+   result := result | (now_millis  << 22) ;
+   result := result | (machine_id << 10) ;
+   result := result | (seq_id & 4095);  
+   
+   return result;
+end;
+$$ language plpgsql;
 
-
+select nsl.fn_generate_snow_id(32);
+----------------------------------------------
 
 
 

--
Gitblit v1.9.3