正在显示
6 个修改的文件
包含
43 行增加
和
22 行删除
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | #email: nheweijun@sina.com | 4 | #email: nheweijun@sina.com |
5 | 5 | ||
6 | 6 | ||
7 | -from app.models import Database,db,Table,TableVacuate | 7 | +from app.models import Database,db,Table,TableVacuate,DES |
8 | 8 | ||
9 | 9 | ||
10 | from app.util.component.ApiTemplate import ApiTemplate | 10 | from app.util.component.ApiTemplate import ApiTemplate |
@@ -16,11 +16,15 @@ class Api(ApiTemplate): | @@ -16,11 +16,15 @@ class Api(ApiTemplate): | ||
16 | api_name = "删除数据库" | 16 | api_name = "删除数据库" |
17 | def process(self): | 17 | def process(self): |
18 | re ={} | 18 | re ={} |
19 | - sys_ds = None | 19 | + va_ds = None |
20 | try: | 20 | try: |
21 | 21 | ||
22 | database = db.session.query(Database).filter_by(guid=self.para.get("guid")).one_or_none() | 22 | database = db.session.query(Database).filter_by(guid=self.para.get("guid")).one_or_none() |
23 | - sys_ds :DataSource= PGUtil.open_pg_data_source(1,configure.SQLALCHEMY_DATABASE_URI) | 23 | + if configure.VACUATE_DB_URI: |
24 | + va_ds: DataSource = PGUtil.open_pg_data_source(1, configure.VACUATE_DB_URI) | ||
25 | + else: | ||
26 | + va_ds: DataSource = PGUtil.open_pg_data_source(1, DES.decode(database.sqlalchemy_uri)) | ||
27 | + | ||
24 | if database: | 28 | if database: |
25 | # 删除table | 29 | # 删除table |
26 | re_tables = Table.query.filter_by(database_guid=database.guid).all() | 30 | re_tables = Table.query.filter_by(database_guid=database.guid).all() |
@@ -29,7 +33,7 @@ class Api(ApiTemplate): | @@ -29,7 +33,7 @@ class Api(ApiTemplate): | ||
29 | for tv in re_tvs: | 33 | for tv in re_tvs: |
30 | db.session.delete(tv) | 34 | db.session.delete(tv) |
31 | try: | 35 | try: |
32 | - sys_ds.DeleteLayer(tv.name) | 36 | + va_ds.DeleteLayer(tv.name) |
33 | except: | 37 | except: |
34 | current_app.logger.warning("{}不存在".format(tv.name)) | 38 | current_app.logger.warning("{}不存在".format(tv.name)) |
35 | db.session.delete(table) | 39 | db.session.delete(table) |
@@ -43,11 +47,11 @@ class Api(ApiTemplate): | @@ -43,11 +47,11 @@ class Api(ApiTemplate): | ||
43 | re["msg"] = "数据库不存在!" | 47 | re["msg"] = "数据库不存在!" |
44 | except Exception as e: | 48 | except Exception as e: |
45 | db.session.rollback() | 49 | db.session.rollback() |
46 | - sys_ds.RollbackTransaction() | 50 | + va_ds.RollbackTransaction() |
47 | raise e | 51 | raise e |
48 | finally: | 52 | finally: |
49 | - if sys_ds: | ||
50 | - sys_ds.Destroy() | 53 | + if va_ds: |
54 | + va_ds.Destroy() | ||
51 | return re | 55 | return re |
52 | 56 | ||
53 | 57 |
@@ -22,7 +22,7 @@ class Api(ApiTemplate): | @@ -22,7 +22,7 @@ class Api(ApiTemplate): | ||
22 | 22 | ||
23 | res = {} | 23 | res = {} |
24 | pg_ds = None | 24 | pg_ds = None |
25 | - sys_ds = None | 25 | + va_ds = None |
26 | try: | 26 | try: |
27 | 27 | ||
28 | table_guid = self.para.get("guid") | 28 | table_guid = self.para.get("guid") |
@@ -48,14 +48,19 @@ class Api(ApiTemplate): | @@ -48,14 +48,19 @@ class Api(ApiTemplate): | ||
48 | 48 | ||
49 | 49 | ||
50 | pg_ds: DataSource = PGUtil.open_pg_data_source(1, DES.decode(database.sqlalchemy_uri)) | 50 | pg_ds: DataSource = PGUtil.open_pg_data_source(1, DES.decode(database.sqlalchemy_uri)) |
51 | - sys_ds: DataSource = PGUtil.open_pg_data_source(1, configure.SQLALCHEMY_DATABASE_URI) | 51 | + |
52 | + if configure.VACUATE_DB_URI: | ||
53 | + va_ds: DataSource = PGUtil.open_pg_data_source(1, configure.VACUATE_DB_URI) | ||
54 | + else: | ||
55 | + va_ds: DataSource = PGUtil.open_pg_data_source(1, DES.decode(database.sqlalchemy_uri)) | ||
56 | + | ||
52 | 57 | ||
53 | #删除抽稀表 | 58 | #删除抽稀表 |
54 | vacuate_tables=table.relate_table_vacuates.all() | 59 | vacuate_tables=table.relate_table_vacuates.all() |
55 | for vt in vacuate_tables: | 60 | for vt in vacuate_tables: |
56 | db.session.delete(vt) | 61 | db.session.delete(vt) |
57 | try: | 62 | try: |
58 | - sys_ds.DeleteLayer(vt.name) | 63 | + va_ds.DeleteLayer(vt.name) |
59 | except: | 64 | except: |
60 | current_app.logger.warning("{}不存在!".format(vt.name)) | 65 | current_app.logger.warning("{}不存在!".format(vt.name)) |
61 | 66 | ||
@@ -76,8 +81,8 @@ class Api(ApiTemplate): | @@ -76,8 +81,8 @@ class Api(ApiTemplate): | ||
76 | finally: | 81 | finally: |
77 | if pg_ds: | 82 | if pg_ds: |
78 | pg_ds.Destroy() | 83 | pg_ds.Destroy() |
79 | - if sys_ds: | ||
80 | - sys_ds.Destroy() | 84 | + if va_ds: |
85 | + va_ds.Destroy() | ||
81 | return res | 86 | return res |
82 | 87 | ||
83 | api_doc={ | 88 | api_doc={ |
@@ -132,7 +132,7 @@ class Api(ApiTemplate): | @@ -132,7 +132,7 @@ class Api(ApiTemplate): | ||
132 | 132 | ||
133 | layer = pg_ds.GetLayerByName(table.name) | 133 | layer = pg_ds.GetLayerByName(table.name) |
134 | 134 | ||
135 | - vacuate_process:VacuateProcess = VacuateProcess(layer, table.guid, options) | 135 | + vacuate_process:VacuateProcess = VacuateProcess(layer, table.guid, options,database.sqlalchemy_uri) |
136 | 136 | ||
137 | 137 | ||
138 | for feature in layer: | 138 | for feature in layer: |
@@ -27,7 +27,7 @@ class Api(ApiTemplate): | @@ -27,7 +27,7 @@ class Api(ApiTemplate): | ||
27 | res = {} | 27 | res = {} |
28 | res["data"] = {} | 28 | res["data"] = {} |
29 | pg_ds = None | 29 | pg_ds = None |
30 | - sys_ds = None | 30 | + va_ds = None |
31 | try: | 31 | try: |
32 | table_guid = self.para.get("guid") | 32 | table_guid = self.para.get("guid") |
33 | table: Table = Table.query.filter_by(guid=table_guid).one_or_none() | 33 | table: Table = Table.query.filter_by(guid=table_guid).one_or_none() |
@@ -42,7 +42,12 @@ class Api(ApiTemplate): | @@ -42,7 +42,12 @@ class Api(ApiTemplate): | ||
42 | 42 | ||
43 | # 判断图层是否存在 | 43 | # 判断图层是否存在 |
44 | pg_ds :DataSource= PGUtil.open_pg_data_source(0,DES.decode(table.relate_database.sqlalchemy_uri)) | 44 | pg_ds :DataSource= PGUtil.open_pg_data_source(0,DES.decode(table.relate_database.sqlalchemy_uri)) |
45 | - sys_ds :DataSource= PGUtil.open_pg_data_source(0,configure.SQLALCHEMY_DATABASE_URI) | 45 | + |
46 | + if configure.VACUATE_DB_URI: | ||
47 | + va_ds: DataSource = PGUtil.open_pg_data_source(1, configure.VACUATE_DB_URI) | ||
48 | + else: | ||
49 | + va_ds: DataSource = PGUtil.open_pg_data_source(1,DES.decode(table.relate_database.sqlalchemy_uri)) | ||
50 | + | ||
46 | 51 | ||
47 | layer = pg_ds.GetLayerByName(table.name) | 52 | layer = pg_ds.GetLayerByName(table.name) |
48 | 53 | ||
@@ -56,7 +61,7 @@ class Api(ApiTemplate): | @@ -56,7 +61,7 @@ class Api(ApiTemplate): | ||
56 | for tv in tvs : | 61 | for tv in tvs : |
57 | db.session.delete(tv) | 62 | db.session.delete(tv) |
58 | try: | 63 | try: |
59 | - sys_ds.DeleteLayer(tv.name) | 64 | + va_ds.DeleteLayer(tv.name) |
60 | except Exception as e : | 65 | except Exception as e : |
61 | current_app.logger.warning("抽稀图层不存在!") | 66 | current_app.logger.warning("抽稀图层不存在!") |
62 | db.session.commit() | 67 | db.session.commit() |
@@ -67,8 +72,8 @@ class Api(ApiTemplate): | @@ -67,8 +72,8 @@ class Api(ApiTemplate): | ||
67 | finally: | 72 | finally: |
68 | if pg_ds: | 73 | if pg_ds: |
69 | pg_ds.Destroy() | 74 | pg_ds.Destroy() |
70 | - if sys_ds: | ||
71 | - sys_ds.Destroy() | 75 | + if va_ds: |
76 | + va_ds.Destroy() | ||
72 | return res | 77 | return res |
73 | 78 | ||
74 | 79 |
@@ -258,8 +258,12 @@ class VacuateProcess: | @@ -258,8 +258,12 @@ class VacuateProcess: | ||
258 | # 创建抽稀ds | 258 | # 创建抽稀ds |
259 | for l in range(self.max_level): | 259 | for l in range(self.max_level): |
260 | 260 | ||
261 | - pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, configure.SQLALCHEMY_DATABASE_URI) | ||
262 | - # pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, DES.decode(sqlalchemy_uri)) | 261 | + if configure.VACUATE_DB_URI: |
262 | + pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, configure.VACUATE_DB_URI) | ||
263 | + else: | ||
264 | + pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, DES.decode(sqlalchemy_uri)) | ||
265 | + | ||
266 | + | ||
263 | pg_ds_l.StartTransaction() | 267 | pg_ds_l.StartTransaction() |
264 | self.pg_ds_dict[l] = pg_ds_l | 268 | self.pg_ds_dict[l] = pg_ds_l |
265 | 269 |
@@ -422,7 +422,7 @@ class VacuateProcess: | @@ -422,7 +422,7 @@ class VacuateProcess: | ||
422 | this_gridsize=[] | 422 | this_gridsize=[] |
423 | 423 | ||
424 | 424 | ||
425 | - def __init__(self,layer:Layer,table_guid, options): | 425 | + def __init__(self,layer:Layer,table_guid, options,sqlalchemy_uri): |
426 | 426 | ||
427 | #是空间图层才初始化 | 427 | #是空间图层才初始化 |
428 | if layer.GetExtent()[0] > 0 or layer.GetExtent()[0] < 0: | 428 | if layer.GetExtent()[0] > 0 or layer.GetExtent()[0] < 0: |
@@ -487,7 +487,10 @@ class VacuateProcess: | @@ -487,7 +487,10 @@ class VacuateProcess: | ||
487 | # 创建抽稀ds | 487 | # 创建抽稀ds |
488 | for l in range(self.max_level): | 488 | for l in range(self.max_level): |
489 | # pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, DES.decode(sqlalchemy_uri)) | 489 | # pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, DES.decode(sqlalchemy_uri)) |
490 | - pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, configure.SQLALCHEMY_DATABASE_URI) | 490 | + if configure.VACUATE_DB_URI: |
491 | + pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, configure.VACUATE_DB_URI) | ||
492 | + else: | ||
493 | + pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, DES.decode(sqlalchemy_uri)) | ||
491 | pg_ds_l.StartTransaction() | 494 | pg_ds_l.StartTransaction() |
492 | self.pg_ds_dict[l] = pg_ds_l | 495 | self.pg_ds_dict[l] = pg_ds_l |
493 | 496 |
请
注册
或
登录
后发表评论