提交 41a6b3d86ed44ae2158f976ad784e2de4b339bde

作者 nheweijun
1 个父辈 6f523f46

增加抽稀表存放位置功能

... ... @@ -4,7 +4,7 @@
4 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 10 from app.util.component.ApiTemplate import ApiTemplate
... ... @@ -16,11 +16,15 @@ class Api(ApiTemplate):
16 16 api_name = "删除数据库"
17 17 def process(self):
18 18 re ={}
19   - sys_ds = None
  19 + va_ds = None
20 20 try:
21 21
22 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 28 if database:
25 29 # 删除table
26 30 re_tables = Table.query.filter_by(database_guid=database.guid).all()
... ... @@ -29,7 +33,7 @@ class Api(ApiTemplate):
29 33 for tv in re_tvs:
30 34 db.session.delete(tv)
31 35 try:
32   - sys_ds.DeleteLayer(tv.name)
  36 + va_ds.DeleteLayer(tv.name)
33 37 except:
34 38 current_app.logger.warning("{}不存在".format(tv.name))
35 39 db.session.delete(table)
... ... @@ -43,11 +47,11 @@ class Api(ApiTemplate):
43 47 re["msg"] = "数据库不存在!"
44 48 except Exception as e:
45 49 db.session.rollback()
46   - sys_ds.RollbackTransaction()
  50 + va_ds.RollbackTransaction()
47 51 raise e
48 52 finally:
49   - if sys_ds:
50   - sys_ds.Destroy()
  53 + if va_ds:
  54 + va_ds.Destroy()
51 55 return re
52 56
53 57
... ...
... ... @@ -22,7 +22,7 @@ class Api(ApiTemplate):
22 22
23 23 res = {}
24 24 pg_ds = None
25   - sys_ds = None
  25 + va_ds = None
26 26 try:
27 27
28 28 table_guid = self.para.get("guid")
... ... @@ -48,14 +48,19 @@ class Api(ApiTemplate):
48 48
49 49
50 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 59 vacuate_tables=table.relate_table_vacuates.all()
55 60 for vt in vacuate_tables:
56 61 db.session.delete(vt)
57 62 try:
58   - sys_ds.DeleteLayer(vt.name)
  63 + va_ds.DeleteLayer(vt.name)
59 64 except:
60 65 current_app.logger.warning("{}不存在!".format(vt.name))
61 66
... ... @@ -76,8 +81,8 @@ class Api(ApiTemplate):
76 81 finally:
77 82 if pg_ds:
78 83 pg_ds.Destroy()
79   - if sys_ds:
80   - sys_ds.Destroy()
  84 + if va_ds:
  85 + va_ds.Destroy()
81 86 return res
82 87
83 88 api_doc={
... ...
... ... @@ -132,7 +132,7 @@ class Api(ApiTemplate):
132 132
133 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 138 for feature in layer:
... ...
... ... @@ -27,7 +27,7 @@ class Api(ApiTemplate):
27 27 res = {}
28 28 res["data"] = {}
29 29 pg_ds = None
30   - sys_ds = None
  30 + va_ds = None
31 31 try:
32 32 table_guid = self.para.get("guid")
33 33 table: Table = Table.query.filter_by(guid=table_guid).one_or_none()
... ... @@ -42,7 +42,12 @@ class Api(ApiTemplate):
42 42
43 43 # 判断图层是否存在
44 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 52 layer = pg_ds.GetLayerByName(table.name)
48 53
... ... @@ -56,7 +61,7 @@ class Api(ApiTemplate):
56 61 for tv in tvs :
57 62 db.session.delete(tv)
58 63 try:
59   - sys_ds.DeleteLayer(tv.name)
  64 + va_ds.DeleteLayer(tv.name)
60 65 except Exception as e :
61 66 current_app.logger.warning("抽稀图层不存在!")
62 67 db.session.commit()
... ... @@ -67,8 +72,8 @@ class Api(ApiTemplate):
67 72 finally:
68 73 if pg_ds:
69 74 pg_ds.Destroy()
70   - if sys_ds:
71   - sys_ds.Destroy()
  75 + if va_ds:
  76 + va_ds.Destroy()
72 77 return res
73 78
74 79
... ...
... ... @@ -258,8 +258,12 @@ class VacuateProcess:
258 258 # 创建抽稀ds
259 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 267 pg_ds_l.StartTransaction()
264 268 self.pg_ds_dict[l] = pg_ds_l
265 269
... ...
... ... @@ -422,7 +422,7 @@ class VacuateProcess:
422 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 428 if layer.GetExtent()[0] > 0 or layer.GetExtent()[0] < 0:
... ... @@ -487,7 +487,10 @@ class VacuateProcess:
487 487 # 创建抽稀ds
488 488 for l in range(self.max_level):
489 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 494 pg_ds_l.StartTransaction()
492 495 self.pg_ds_dict[l] = pg_ds_l
493 496
... ...
注册登录 后发表评论