正在显示
26 个修改的文件
包含
319 行增加
和
270 行删除
| @@ -8,7 +8,7 @@ from app.util import BlueprintApi | @@ -8,7 +8,7 @@ from app.util import BlueprintApi | ||
| 8 | 8 | ||
| 9 | from flask import send_from_directory | 9 | from flask import send_from_directory |
| 10 | import os | 10 | import os |
| 11 | -from . import data_download,data_download_task | 11 | +from . import data_download_task |
| 12 | from . import get_meta | 12 | from . import get_meta |
| 13 | from . import data_entry_by_meta | 13 | from . import data_entry_by_meta |
| 14 | from . import get_data_list | 14 | from . import get_data_list |
| @@ -55,14 +55,6 @@ class DataManager(BlueprintApi): | @@ -55,14 +55,6 @@ class DataManager(BlueprintApi): | ||
| 55 | result["message"] ="删除文件失败!" | 55 | result["message"] ="删除文件失败!" |
| 56 | return result | 56 | return result |
| 57 | 57 | ||
| 58 | - @staticmethod | ||
| 59 | - @bp.route('/DataDownload', methods=['POST']) | ||
| 60 | - @swag_from(data_download.Api.api_doc) | ||
| 61 | - def table_download(): | ||
| 62 | - """ | ||
| 63 | - 下载数据 | ||
| 64 | - """ | ||
| 65 | - return data_download.Api().result | ||
| 66 | 58 | ||
| 67 | @staticmethod | 59 | @staticmethod |
| 68 | @bp.route('/DataDownloadTask', methods=['POST']) | 60 | @bp.route('/DataDownloadTask', methods=['POST']) |
app/modules/data/io/data_download.py
deleted
100644 → 0
| 1 | -# coding=utf-8 | ||
| 2 | -#author: 4N | ||
| 3 | -#createtime: 2020/11/27 | ||
| 4 | -#email: nheweijun@sina.com | ||
| 5 | - | ||
| 6 | - | ||
| 7 | -from ..models import * | ||
| 8 | - | ||
| 9 | - | ||
| 10 | -from osgeo.ogr import DataSource,Layer,FeatureDefn,FieldDefn,Feature | ||
| 11 | -from osgeo import gdal,ogr | ||
| 12 | -import os | ||
| 13 | -import uuid | ||
| 14 | -import configure | ||
| 15 | -from app.util.component.ApiTemplate import ApiTemplate | ||
| 16 | -from app.util.component.PGUtil import PGUtil | ||
| 17 | -from app.util.component.ZipUtil import ZipUtil | ||
| 18 | - | ||
| 19 | -class Api(ApiTemplate): | ||
| 20 | - | ||
| 21 | - def process(self): | ||
| 22 | - #获取参数 | ||
| 23 | - | ||
| 24 | - #返回结果 | ||
| 25 | - result={} | ||
| 26 | - #设置编码 | ||
| 27 | - encoding = self.para.get("encoding") | ||
| 28 | - if encoding: | ||
| 29 | - gdal.SetConfigOption("SHAPE_ENCODING",encoding) | ||
| 30 | - else: | ||
| 31 | - gdal.SetConfigOption("SHAPE_ENCODING", "UTF-8") | ||
| 32 | - | ||
| 33 | - ds:DataSource = None | ||
| 34 | - try: | ||
| 35 | - table_names = self.para.get("table_name").split(",") | ||
| 36 | - database_guid = self.para.get("database_guid") | ||
| 37 | - database = Database.query.filter_by(guid=database_guid).one_or_none() | ||
| 38 | - if not database: | ||
| 39 | - raise Exception("数据库不存在!") | ||
| 40 | - | ||
| 41 | - | ||
| 42 | - ds:DataSource = PGUtil.open_pg_data_source(0,DES.decode(database.sqlalchemy_uri)) | ||
| 43 | - | ||
| 44 | - download_type = self.para.get("download_type") | ||
| 45 | - | ||
| 46 | - data = None | ||
| 47 | - if download_type.__eq__("shp"): | ||
| 48 | - data = self.download_shp(table_names,ds) | ||
| 49 | - if download_type.__eq__("gdb"): | ||
| 50 | - data = self.download_gdb(table_names, ds,database_guid) | ||
| 51 | - | ||
| 52 | - result["data"] = data | ||
| 53 | - result["result"] = True | ||
| 54 | - except Exception as e: | ||
| 55 | - raise e | ||
| 56 | - | ||
| 57 | - finally: | ||
| 58 | - if ds: | ||
| 59 | - ds.Destroy() | ||
| 60 | - return result | ||
| 61 | - | ||
| 62 | - | ||
| 63 | - def download_shp(self,table_names,ds): | ||
| 64 | - data = [] | ||
| 65 | - for table_name in table_names: | ||
| 66 | - url = self.download_one(ds, table_name) | ||
| 67 | - data.append({"name": table_name, "download_url": url}) | ||
| 68 | - return data | ||
| 69 | - | ||
| 70 | - def download_one(self,ds,table_name): | ||
| 71 | - | ||
| 72 | - layer: Layer = ds.GetLayerByName(table_name) | ||
| 73 | - driver = ogr.GetDriverByName("ESRI Shapefile") | ||
| 74 | - uuid_ = uuid.uuid1().__str__() | ||
| 75 | - parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | ||
| 76 | - dirpath = os.path.join(parent, "file_tmp", uuid_) | ||
| 77 | - os.makedirs(dirpath) | ||
| 78 | - data_source: DataSource = driver.CreateDataSource(dirpath + "/{}.shp".format(table_name)) | ||
| 79 | - | ||
| 80 | - fid = layer.GetFIDColumn() | ||
| 81 | - pg_layer: Layer = data_source.CreateLayer(table_name, layer.GetSpatialRef(), layer.GetGeomType()) | ||
| 82 | - schema = [sche for sche in layer.schema if not sche.name.__eq__(fid)] | ||
| 83 | - | ||
| 84 | - pg_layer.CreateFields(schema) | ||
| 85 | - layer.ResetReading() | ||
| 86 | - for feature in layer: | ||
| 87 | - pg_layer.CreateFeature(feature) | ||
| 88 | - | ||
| 89 | - data_source.Destroy() | ||
| 90 | - | ||
| 91 | - | ||
| 92 | - ZipUtil.create_zip(os.path.join(parent, "file_tmp", table_name+"_"+uuid_) + ".zip", [dirpath]) | ||
| 93 | - | ||
| 94 | - return "http://" + configure.deploy_ip_host + "/API/IO/Download/{}".format(table_name+"_"+uuid_ + ".zip") | ||
| 95 | - | ||
| 96 | - | ||
| 97 | - def download_gdb(self,table_names,ds,database_guid): | ||
| 98 | - ogr.RegisterAll() | ||
| 99 | - data = [] | ||
| 100 | - gdal.UseExceptions() | ||
| 101 | - gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES") | ||
| 102 | - | ||
| 103 | - # 创建一个gdb datasource | ||
| 104 | - gdb_driver = ogr.GetDriverByName('FileGDB') | ||
| 105 | - uuid_ = uuid.uuid1().__str__() | ||
| 106 | - parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | ||
| 107 | - gdb_path = os.path.join(parent, "file_tmp", uuid_+".gdb") | ||
| 108 | - gdb_ds: DataSource = gdb_driver.CreateDataSource(gdb_path) | ||
| 109 | - | ||
| 110 | - | ||
| 111 | - for table_name in table_names: | ||
| 112 | - | ||
| 113 | - layer: Layer = ds.GetLayerByName(table_name) | ||
| 114 | - table = Table.query.filter_by(name=table_name, database_guid=database_guid).one_or_none() | ||
| 115 | - feature_defn: FeatureDefn = layer.GetLayerDefn() | ||
| 116 | - | ||
| 117 | - for i in range(feature_defn.GetFieldCount()): | ||
| 118 | - field_defn:FieldDefn = feature_defn.GetFieldDefn(i) | ||
| 119 | - field_alias = Columns.query.filter_by(table_guid=table.guid,name=field_defn.GetName()).one_or_none().alias | ||
| 120 | - field_defn.SetAlternativeName(field_alias) | ||
| 121 | - | ||
| 122 | - table_alias= table.alias | ||
| 123 | - | ||
| 124 | - | ||
| 125 | - fid = layer.GetFIDColumn() | ||
| 126 | - pg_layer: Layer = gdb_ds.CreateLayer(table_name, layer.GetSpatialRef(), layer.GetGeomType(),["LAYER_ALIAS={}".format(table_alias)]) | ||
| 127 | - schema = [sche for sche in layer.schema if not sche.name.__eq__(fid)] | ||
| 128 | - pg_layer.CreateFields(schema) | ||
| 129 | - | ||
| 130 | - # gdb 不支持fid=0的要素,所以识别到后要+1 | ||
| 131 | - offset = 0 | ||
| 132 | - f1:Feature = layer.GetNextFeature() | ||
| 133 | - if f1: | ||
| 134 | - if f1.GetFID().__eq__(0): | ||
| 135 | - offset = 1 | ||
| 136 | - layer.ResetReading() | ||
| 137 | - for feature in layer: | ||
| 138 | - feature.SetFID(feature.GetFID()+offset) | ||
| 139 | - pg_layer.CreateFeature(feature) | ||
| 140 | - | ||
| 141 | - gdb_ds.Destroy() | ||
| 142 | - ZipUtil.create_zip(gdb_path + ".zip", [gdb_path]) | ||
| 143 | - data.append({"name": ",".join(table_names), "download_url": "http://" + configure.deploy_ip_host + "/API/IO/Download/{}".format(uuid_+".gdb" + ".zip")}) | ||
| 144 | - | ||
| 145 | - | ||
| 146 | - return data | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - | ||
| 150 | - api_doc={ | ||
| 151 | - "tags":["IO接口"], | ||
| 152 | - "description":"下载数据", | ||
| 153 | - "parameters":[ | ||
| 154 | - {"name": "table_name", | ||
| 155 | - "in": "formData", | ||
| 156 | - "type":"string","description":"支持多图层下载,以逗号相隔","required":"true"}, | ||
| 157 | - {"name": "encoding", | ||
| 158 | - "in": "formData", | ||
| 159 | - "type": "string", | ||
| 160 | - "enum":["GBK","UTF-8"]}, | ||
| 161 | - {"name": "download_type", | ||
| 162 | - "in": "formData", | ||
| 163 | - "type": "string", | ||
| 164 | - "enum": ["shp", "gdb"],"required":"true" | ||
| 165 | - }, | ||
| 166 | - {"name": "database_guid", | ||
| 167 | - "in": "formData", | ||
| 168 | - "type": "string","required":"true" | ||
| 169 | - } | ||
| 170 | - ], | ||
| 171 | - "responses":{ | ||
| 172 | - 200:{ | ||
| 173 | - "schema":{ | ||
| 174 | - "properties":{ | ||
| 175 | - "content":{ | ||
| 176 | - "type": "string", | ||
| 177 | - "description": "The name of the user" | ||
| 178 | - } | ||
| 179 | - } | ||
| 180 | - } | ||
| 181 | - } | ||
| 182 | - } | ||
| 183 | -} |
| @@ -133,7 +133,7 @@ class Api(ApiTemplate): | @@ -133,7 +133,7 @@ class Api(ApiTemplate): | ||
| 133 | 133 | ||
| 134 | 134 | ||
| 135 | fid = layer.GetFIDColumn() | 135 | fid = layer.GetFIDColumn() |
| 136 | - pg_layer: Layer = data_source.CreateLayer(table_name, layer.GetSpatialRef(), layer.GetGeomType()) | 136 | + pg_layer: Layer = data_source.CreateLayer(table_name, layer.GetSpatialRef(), layer.GetGeomType(),["ENCODING=UTF-8"]) |
| 137 | schema = [sche for sche in layer.schema if not sche.name.__eq__(fid)] | 137 | schema = [sche for sche in layer.schema if not sche.name.__eq__(fid)] |
| 138 | 138 | ||
| 139 | pg_layer.CreateFields(schema) | 139 | pg_layer.CreateFields(schema) |
| @@ -18,7 +18,6 @@ class Api(ApiTemplate): | @@ -18,7 +18,6 @@ class Api(ApiTemplate): | ||
| 18 | try: | 18 | try: |
| 19 | task_guid = self.para.get("task_guid") | 19 | task_guid = self.para.get("task_guid") |
| 20 | task:Task = Task.query.filter_by(guid=task_guid).one_or_none() | 20 | task:Task = Task.query.filter_by(guid=task_guid).one_or_none() |
| 21 | - | ||
| 22 | if not task : | 21 | if not task : |
| 23 | raise Exception("任务不存在!") | 22 | raise Exception("任务不存在!") |
| 24 | else: | 23 | else: |
app/modules/service/engine/__init__.py
0 → 100644
| 1 | +# coding=utf-8 | ||
| 2 | +#author: 4N | ||
| 3 | +#createtime: 2021/12/13 | ||
| 4 | +#email: nheweijun@sina.com | ||
| 5 | + | ||
| 6 | + | ||
| 7 | +from flasgger import swag_from | ||
| 8 | +from flask import Blueprint | ||
| 9 | +from app.util import BlueprintApi | ||
| 10 | +from . import service_engine_register | ||
| 11 | +from . import service_engine_delete | ||
| 12 | +from . import service_engine_edit | ||
| 13 | +from . import service_engine_list | ||
| 14 | + | ||
| 15 | +class EngineManager(BlueprintApi): | ||
| 16 | + | ||
| 17 | + bp = Blueprint("Engine", __name__, url_prefix="/API/Service/Engine") | ||
| 18 | + | ||
| 19 | + @staticmethod | ||
| 20 | + @bp.route('/Register', methods=['POST']) | ||
| 21 | + @swag_from(service_engine_register.Api.api_doc) | ||
| 22 | + def service_engine_register(): | ||
| 23 | + """ | ||
| 24 | + Engine Register | ||
| 25 | + """ | ||
| 26 | + return service_engine_register.Api().result | ||
| 27 | + | ||
| 28 | + @staticmethod | ||
| 29 | + @bp.route('/List', methods=['POST']) | ||
| 30 | + @swag_from(service_engine_list.Api.api_doc) | ||
| 31 | + def service_engine_list(): | ||
| 32 | + """ | ||
| 33 | + Engine List | ||
| 34 | + """ | ||
| 35 | + return service_engine_list.Api().result | ||
| 36 | + | ||
| 37 | + @staticmethod | ||
| 38 | + @bp.route('/Edit', methods=['POST']) | ||
| 39 | + @swag_from(service_engine_edit.Api.api_doc) | ||
| 40 | + def service_engine_edit(): | ||
| 41 | + """ | ||
| 42 | + Engine Edit | ||
| 43 | + """ | ||
| 44 | + return service_engine_edit.Api().result | ||
| 45 | + | ||
| 46 | + | ||
| 47 | + @staticmethod | ||
| 48 | + @bp.route('/Delete', methods=['POST']) | ||
| 49 | + @swag_from(service_engine_delete.Api.api_doc) | ||
| 50 | + def service_engine_delete(): | ||
| 51 | + """ | ||
| 52 | + Engine Delete | ||
| 53 | + """ | ||
| 54 | + return service_engine_delete.Api().result |
| 1 | +# coding=utf-8 | ||
| 2 | +#author: 4N | ||
| 3 | +#createtime: 2021/9/14 | ||
| 4 | +#email: nheweijun@sina.com | ||
| 5 | + | ||
| 6 | +from app.util.component.ApiTemplate import ApiTemplate | ||
| 7 | +from app.modules.service.models import ServiceEngine,db | ||
| 8 | +class Api(ApiTemplate): | ||
| 9 | + api_name = "注销服务引擎" | ||
| 10 | + def process(self): | ||
| 11 | + res = {} | ||
| 12 | + try: | ||
| 13 | + guid = self.para.get("guid") | ||
| 14 | + service_engine = ServiceEngine.query.filter_by(guid=guid).one_or_none() | ||
| 15 | + if not service_engine: | ||
| 16 | + raise Exception("服务不存在!") | ||
| 17 | + db.session.delete(service_engine) | ||
| 18 | + db.session.commit() | ||
| 19 | + res["result"] = True | ||
| 20 | + except Exception as e: | ||
| 21 | + raise e | ||
| 22 | + return res | ||
| 23 | + | ||
| 24 | + api_doc = { | ||
| 25 | + "tags": ["引擎接口"], | ||
| 26 | + "parameters": [ | ||
| 27 | + {"name": "guid", | ||
| 28 | + "in": "formData", | ||
| 29 | + "type": "string", | ||
| 30 | + "description": "guid"}, | ||
| 31 | + ], | ||
| 32 | + "responses": { | ||
| 33 | + 200: { | ||
| 34 | + "schema": { | ||
| 35 | + "properties": { | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + } |
| 1 | +# coding=utf-8 | ||
| 2 | +#author: 4N | ||
| 3 | +#createtime: 2021/9/14 | ||
| 4 | +#email: nheweijun@sina.com | ||
| 5 | + | ||
| 6 | +from app.util.component.ApiTemplate import ApiTemplate | ||
| 7 | +import requests | ||
| 8 | +from app.modules.service.models import ServiceEngine,db | ||
| 9 | +class Api(ApiTemplate): | ||
| 10 | + api_name = "修改服务引擎" | ||
| 11 | + def process(self): | ||
| 12 | + res = {} | ||
| 13 | + try: | ||
| 14 | + | ||
| 15 | + udpate = {} | ||
| 16 | + guid = self.para.get("guid") | ||
| 17 | + | ||
| 18 | + for key in self.para.keys(): | ||
| 19 | + if key in ["name","url","out_url"]: | ||
| 20 | + udpate[key] = self.para.get(key) | ||
| 21 | + | ||
| 22 | + ServiceEngine.query.filter_by(guid=guid).update(udpate) | ||
| 23 | + db.session.commit() | ||
| 24 | + res["result"] = True | ||
| 25 | + except Exception as e: | ||
| 26 | + raise e | ||
| 27 | + return res | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + api_doc = { | ||
| 31 | + "tags": ["引擎接口"], | ||
| 32 | + "parameters": [ | ||
| 33 | + {"name": "guid", | ||
| 34 | + "in": "formData", | ||
| 35 | + "type": "string", | ||
| 36 | + "description": "guid"}, | ||
| 37 | + {"name": "name", | ||
| 38 | + "in": "formData", | ||
| 39 | + "type": "string"}, | ||
| 40 | + {"name": "url", | ||
| 41 | + "in": "formData", | ||
| 42 | + "type": "string"}, | ||
| 43 | + {"name": "out_url", | ||
| 44 | + "in": "formData", | ||
| 45 | + "type": "string"}, | ||
| 46 | + | ||
| 47 | + ], | ||
| 48 | + "responses": { | ||
| 49 | + 200: { | ||
| 50 | + "schema": { | ||
| 51 | + "properties": { | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + } |
| 1 | +# coding=utf-8 | ||
| 2 | +#author: 4N | ||
| 3 | +#createtime: 2021/9/14 | ||
| 4 | +#email: nheweijun@sina.com | ||
| 5 | + | ||
| 6 | +from app.util.component.ApiTemplate import ApiTemplate | ||
| 7 | +from app.modules.service.models import ServiceEngine | ||
| 8 | +from app.util.component.ModelVisitor import ModelVisitor | ||
| 9 | + | ||
| 10 | +class Api(ApiTemplate): | ||
| 11 | + api_name = "服务引擎List" | ||
| 12 | + def process(self): | ||
| 13 | + res = {} | ||
| 14 | + try: | ||
| 15 | + page_index = int(self.para.get("page_index", "0")) | ||
| 16 | + page_size = int(self.para.get("page_size", "10")) | ||
| 17 | + name = self.para.get("name") | ||
| 18 | + s_type = self.para.get("type") | ||
| 19 | + | ||
| 20 | + service_engines = ServiceEngine.query | ||
| 21 | + if name: | ||
| 22 | + service_engines = service_engines.filter_by(name=name) | ||
| 23 | + | ||
| 24 | + if s_type: | ||
| 25 | + service_engines = service_engines.filter_by(type=s_type) | ||
| 26 | + res["data"] = {} | ||
| 27 | + res["data"]["count"] = service_engines.count() | ||
| 28 | + service_engines = service_engines.limit(page_size).offset(page_index * page_size).all() | ||
| 29 | + res["data"]["list"] = ModelVisitor.objects_to_jsonarray(service_engines) | ||
| 30 | + except Exception as e: | ||
| 31 | + raise e | ||
| 32 | + return res | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + api_doc = { | ||
| 36 | + "tags": ["引擎接口"], | ||
| 37 | + "parameters": [ | ||
| 38 | + {"name": "page_index", | ||
| 39 | + "in": "formData", | ||
| 40 | + "type": "int", | ||
| 41 | + "description": "页"}, | ||
| 42 | + {"name": "page_size", | ||
| 43 | + "in": "formData", | ||
| 44 | + "type": "int", | ||
| 45 | + "description": "页大小"}, | ||
| 46 | + {"name": "name", | ||
| 47 | + "in": "formData", | ||
| 48 | + "type": "string"}, | ||
| 49 | + {"name": "type", | ||
| 50 | + "in": "formData", | ||
| 51 | + "type": "string", | ||
| 52 | + "enum":["ImageServer"]}, | ||
| 53 | + ], | ||
| 54 | + "responses": { | ||
| 55 | + 200: { | ||
| 56 | + "schema": { | ||
| 57 | + "properties": { | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + } |
| 1 | +# coding=utf-8 | ||
| 2 | +#author: 4N | ||
| 3 | +#createtime: 2021/9/14 | ||
| 4 | +#email: nheweijun@sina.com | ||
| 5 | + | ||
| 6 | +from app.util.component.ApiTemplate import ApiTemplate | ||
| 7 | +import requests | ||
| 8 | +from app.modules.service.models import ServiceEngine,db | ||
| 9 | +import datetime | ||
| 10 | +import uuid | ||
| 11 | + | ||
| 12 | +class Api(ApiTemplate): | ||
| 13 | + api_name = "注册服务引擎" | ||
| 14 | + def process(self): | ||
| 15 | + res = {} | ||
| 16 | + try: | ||
| 17 | + url = self.para.get("url") | ||
| 18 | + response:requests.Response = requests.get(url) | ||
| 19 | + if response.status_code != 200: | ||
| 20 | + raise Exception("服务引擎连接失败!") | ||
| 21 | + service_engine = ServiceEngine(guid=uuid.uuid1().__str__(), | ||
| 22 | + name=response.json().get("Name"), | ||
| 23 | + url=url, | ||
| 24 | + type=response.json().get("Type"), | ||
| 25 | + create_time=datetime.datetime.now() | ||
| 26 | + ) | ||
| 27 | + db.session.add(service_engine) | ||
| 28 | + db.session.commit() | ||
| 29 | + | ||
| 30 | + res["result"] = True | ||
| 31 | + except Exception as e: | ||
| 32 | + raise Exception("引擎已注册!") | ||
| 33 | + return res | ||
| 34 | + | ||
| 35 | + | ||
| 36 | + api_doc = { | ||
| 37 | + "tags": ["引擎接口"], | ||
| 38 | + "parameters": [ | ||
| 39 | + {"name": "url", | ||
| 40 | + "in": "formData", | ||
| 41 | + "type": "string", | ||
| 42 | + "description": "服务地址"}, | ||
| 43 | + ], | ||
| 44 | + "responses": { | ||
| 45 | + 200: { | ||
| 46 | + "schema": { | ||
| 47 | + "properties": { | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + } |
| @@ -29,7 +29,7 @@ class ImageServerInstance: | @@ -29,7 +29,7 @@ class ImageServerInstance: | ||
| 29 | class ImageManager(BlueprintApi): | 29 | class ImageManager(BlueprintApi): |
| 30 | 30 | ||
| 31 | bp = Blueprint("ImageService", __name__, url_prefix="/API/Service/Image") | 31 | bp = Blueprint("ImageService", __name__, url_prefix="/API/Service/Image") |
| 32 | - service_type = ["影像服务"] | 32 | + # service_type = ["影像服务"] |
| 33 | 33 | ||
| 34 | @staticmethod | 34 | @staticmethod |
| 35 | @bp.route('/Register', methods=['POST']) | 35 | @bp.route('/Register', methods=['POST']) |
| @@ -253,3 +253,16 @@ class MapService(db.Model): | @@ -253,3 +253,16 @@ class MapService(db.Model): | ||
| 253 | thumbnail = Column(String) | 253 | thumbnail = Column(String) |
| 254 | layer_style = Column(Text) | 254 | layer_style = Column(Text) |
| 255 | service_guid = Column(String,ForeignKey('dmap_service.guid')) | 255 | service_guid = Column(String,ForeignKey('dmap_service.guid')) |
| 256 | + | ||
| 257 | +class ServiceEngine(db.Model): | ||
| 258 | + ''' | ||
| 259 | + 服务引擎 | ||
| 260 | + ''' | ||
| 261 | + __tablename__ = 'dmap_service_engine' | ||
| 262 | + | ||
| 263 | + guid = Column(String(256), primary_key=True) | ||
| 264 | + name = Column(String) | ||
| 265 | + url = Column(String(256), unique=True) | ||
| 266 | + out_url = Column(String(256)) | ||
| 267 | + type = Column(String(256)) | ||
| 268 | + create_time = Column(DateTime) |
| @@ -21,7 +21,6 @@ class Api(ApiTemplate): | @@ -21,7 +21,6 @@ class Api(ApiTemplate): | ||
| 21 | 21 | ||
| 22 | try: | 22 | try: |
| 23 | # 业务逻辑 | 23 | # 业务逻辑 |
| 24 | - | ||
| 25 | guid = self.para.get("guid") | 24 | guid = self.para.get("guid") |
| 26 | scheme = TileScheme.query.filter_by(guid=guid).one_or_none() | 25 | scheme = TileScheme.query.filter_by(guid=guid).one_or_none() |
| 27 | if not scheme: | 26 | if not scheme: |
| @@ -6,7 +6,7 @@ from app.util.component.ApiTemplate import ApiTemplate | @@ -6,7 +6,7 @@ from app.util.component.ApiTemplate import ApiTemplate | ||
| 6 | 6 | ||
| 7 | from app.models import db | 7 | from app.models import db |
| 8 | from app.modules.service.models import Service | 8 | from app.modules.service.models import Service |
| 9 | -from app.modules.service.models import ImageService | 9 | +from app.modules.service.models import ServiceEngine |
| 10 | from app.modules.service.models import TileService | 10 | from app.modules.service.models import TileService |
| 11 | from app.modules.service.models import MapService | 11 | from app.modules.service.models import MapService |
| 12 | class Api(ApiTemplate): | 12 | class Api(ApiTemplate): |
| @@ -21,21 +21,25 @@ class Api(ApiTemplate): | @@ -21,21 +21,25 @@ class Api(ApiTemplate): | ||
| 21 | try: | 21 | try: |
| 22 | guid = self.para.get("guid") | 22 | guid = self.para.get("guid") |
| 23 | 23 | ||
| 24 | + #删除本地服务 | ||
| 24 | service = Service.query.filter_by(guid=guid).one_or_none() | 25 | service = Service.query.filter_by(guid=guid).one_or_none() |
| 25 | - if service.type.__eq__("影像服务"): | ||
| 26 | - image_service = ImageService.query.filter_by(service_guid=guid).one_or_none() | ||
| 27 | - db.session.delete(image_service) | ||
| 28 | - if service.type.__eq__("切片服务"): | ||
| 29 | - tile_service = TileService.query.filter_by(service_guid=guid).one_or_none() | ||
| 30 | - db.session.delete(tile_service) | ||
| 31 | - if service.type.__eq__("地图服务"): | ||
| 32 | - map_service = MapService.query.filter_by(service_guid=guid).one_or_none() | ||
| 33 | - db.session.delete(map_service) | ||
| 34 | - | ||
| 35 | - service_functions = service.relate_service_functions.all() | ||
| 36 | - for function in service_functions: | ||
| 37 | - db.session.delete(function) | ||
| 38 | - db.session.delete(service) | 26 | + if service: |
| 27 | + if service.type.__eq__("切片服务"): | ||
| 28 | + #调用接口 | ||
| 29 | + tile_service = TileService.query.filter_by(service_guid=guid).one_or_none() | ||
| 30 | + db.session.delete(tile_service) | ||
| 31 | + if service.type.__eq__("地图服务"): | ||
| 32 | + map_service = MapService.query.filter_by(service_guid=guid).one_or_none() | ||
| 33 | + db.session.delete(map_service) | ||
| 34 | + service_functions = service.relate_service_functions.all() | ||
| 35 | + for function in service_functions: | ||
| 36 | + db.session.delete(function) | ||
| 37 | + db.session.delete(service) | ||
| 38 | + else: | ||
| 39 | + pass | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + | ||
| 39 | db.session.commit() | 43 | db.session.commit() |
| 40 | res["result"] = True | 44 | res["result"] = True |
| 41 | except Exception as e: | 45 | except Exception as e: |
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | from app.util.component.ApiTemplate import ApiTemplate | 8 | from app.util.component.ApiTemplate import ApiTemplate |
| 9 | -import configure | 9 | +from .models import ServiceEngine |
| 10 | from app.util import find_class,BlueprintApi | 10 | from app.util import find_class,BlueprintApi |
| 11 | 11 | ||
| 12 | 12 | ||
| @@ -21,7 +21,10 @@ class Api(ApiTemplate): | @@ -21,7 +21,10 @@ class Api(ApiTemplate): | ||
| 21 | try: | 21 | try: |
| 22 | for scan in ["app.modules.service"]: | 22 | for scan in ["app.modules.service"]: |
| 23 | for api in find_class(scan, BlueprintApi): | 23 | for api in find_class(scan, BlueprintApi): |
| 24 | - service_types.extend(api.service_type) | 24 | + if hasattr(api,"service_type"): |
| 25 | + service_types.extend(api.service_type) | ||
| 26 | + if ServiceEngine.query.filter_by(type="ImageServer").first(): | ||
| 27 | + service_types.append("影像服务") | ||
| 25 | res["data"] = service_types | 28 | res["data"] = service_types |
| 26 | res["result"] = True | 29 | res["result"] = True |
| 27 | 30 |
| @@ -14,8 +14,10 @@ class Api(ApiTemplate): | @@ -14,8 +14,10 @@ class Api(ApiTemplate): | ||
| 14 | service = Service.query.filter_by(name=self.para.get("name")).one_or_none() | 14 | service = Service.query.filter_by(name=self.para.get("name")).one_or_none() |
| 15 | if service: | 15 | if service: |
| 16 | raise Exception("服务已存在!") | 16 | raise Exception("服务已存在!") |
| 17 | + | ||
| 17 | if self.para.get("type").__eq__("影像服务"): | 18 | if self.para.get("type").__eq__("影像服务"): |
| 18 | from app.modules.service.image.image_service_register import Api as RealApi | 19 | from app.modules.service.image.image_service_register import Api as RealApi |
| 20 | + | ||
| 19 | elif self.para.get("type").__eq__("地图服务"): | 21 | elif self.para.get("type").__eq__("地图服务"): |
| 20 | from app.modules.service.map_service.map_service_register import Api as RealApi | 22 | from app.modules.service.map_service.map_service_register import Api as RealApi |
| 21 | elif self.para.get("type").__eq__("切片服务"): | 23 | elif self.para.get("type").__eq__("切片服务"): |
| @@ -19,8 +19,6 @@ class Api(ApiTemplate): | @@ -19,8 +19,6 @@ class Api(ApiTemplate): | ||
| 19 | 19 | ||
| 20 | service = Service.query.filter_by(guid=guid).one_or_none() | 20 | service = Service.query.filter_by(guid=guid).one_or_none() |
| 21 | 21 | ||
| 22 | - | ||
| 23 | - | ||
| 24 | service.state=state | 22 | service.state=state |
| 25 | db.session.commit() | 23 | db.session.commit() |
| 26 | res["result"] = True | 24 | res["result"] = True |
| @@ -51,8 +51,10 @@ class Api(ApiTemplate): | @@ -51,8 +51,10 @@ class Api(ApiTemplate): | ||
| 51 | 51 | ||
| 52 | tile_service_edit_url = "{}/dmap/api/manager/RegService".format(configure.wmts_url) | 52 | tile_service_edit_url = "{}/dmap/api/manager/RegService".format(configure.wmts_url) |
| 53 | 53 | ||
| 54 | - resp: Response = requests.post(tile_service_edit_url,para).json() | ||
| 55 | - if not resp.json()["status"].__eq__("true"): | 54 | + resp: Response = requests.post(tile_service_edit_url,data=json.dumps(para),headers={'Content-Type':'application/json'}) |
| 55 | + resp.encoding="utf-8" | ||
| 56 | + resp_json = resp.json() | ||
| 57 | + if not resp_json["status"].__eq__("true"): | ||
| 56 | raise Exception("调用切片服务的注册服务接口失败!") | 58 | raise Exception("调用切片服务的注册服务接口失败!") |
| 57 | 59 | ||
| 58 | #修改数据库 | 60 | #修改数据库 |
| @@ -34,9 +34,10 @@ class Api(ApiTemplate): | @@ -34,9 +34,10 @@ class Api(ApiTemplate): | ||
| 34 | "type":"tileserver","capabilities":1,"project":project_file} | 34 | "type":"tileserver","capabilities":1,"project":project_file} |
| 35 | 35 | ||
| 36 | tile_service_register_url = "{}/dmap/api/manager/RegService".format(configure.wmts_url) | 36 | tile_service_register_url = "{}/dmap/api/manager/RegService".format(configure.wmts_url) |
| 37 | - | ||
| 38 | - resp: Response = requests.post(tile_service_register_url,para).json() | ||
| 39 | - if not resp.json()["status"].__eq__("true"): | 37 | + resp: Response = requests.post(tile_service_register_url,data=json.dumps(para),headers={'Content-Type':'application/json'}) |
| 38 | + resp.encoding="utf-8" | ||
| 39 | + resp_json = resp.json() | ||
| 40 | + if not resp_json["status"].__eq__("true"): | ||
| 40 | raise Exception("调用切片服务的注册服务接口失败!") | 41 | raise Exception("调用切片服务的注册服务接口失败!") |
| 41 | 42 | ||
| 42 | service = Service( | 43 | service = Service( |
| @@ -41,7 +41,7 @@ class ProjectFile: | @@ -41,7 +41,7 @@ class ProjectFile: | ||
| 41 | <extent> | 41 | <extent> |
| 42 | <xmin>{xmin}</xmin> | 42 | <xmin>{xmin}</xmin> |
| 43 | <ymin>{xmax}</ymin> | 43 | <ymin>{xmax}</ymin> |
| 44 | - <xmax>{xmax}</xmax> | 44 | + <xmax>{ymin}</xmax> |
| 45 | <ymax>{ymax}</ymax> | 45 | <ymax>{ymax}</ymax> |
| 46 | </extent> | 46 | </extent> |
| 47 | <style>{layer_style}</style> | 47 | <style>{layer_style}</style> |
| @@ -123,7 +123,7 @@ class ProjectFile: | @@ -123,7 +123,7 @@ class ProjectFile: | ||
| 123 | </spatialrefsys> | 123 | </spatialrefsys> |
| 124 | </projectCrs> | 124 | </projectCrs> |
| 125 | <projectlayers> | 125 | <projectlayers> |
| 126 | - <maplayer name="{name}" alias="{alias}" type="3"> | 126 | + <maplayer name="{name}" alias="{alias}" type="0"> |
| 127 | <extent> | 127 | <extent> |
| 128 | <xmin>{xmin}</xmin> | 128 | <xmin>{xmin}</xmin> |
| 129 | <ymin>{xmax}</ymin> | 129 | <ymin>{xmax}</ymin> |
| @@ -11,16 +11,11 @@ SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dma | @@ -11,16 +11,11 @@ SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dma | ||
| 11 | #VACUATE_DB_URI = None | 11 | #VACUATE_DB_URI = None |
| 12 | VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI | 12 | VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI |
| 13 | 13 | ||
| 14 | -# 部署模式cluster,standalone | ||
| 15 | -# deployment_mode = "cluster" | ||
| 16 | -# 部署模式味cluster时有用,master,slave | ||
| 17 | -# application_name = "master" | ||
| 18 | - | ||
| 19 | zookeeper = "172.26.99.168:2181" | 14 | zookeeper = "172.26.99.168:2181" |
| 20 | 15 | ||
| 21 | #WMTS服务器 | 16 | #WMTS服务器 |
| 22 | -wmts_url = "http://172.26.99.160:6080" | ||
| 23 | - | 17 | +wmts_url = "http://172.26.99.160:6060" |
| 18 | +wms_url = "" | ||
| 24 | 19 | ||
| 25 | # 固定配置不需要修改 | 20 | # 固定配置不需要修改 |
| 26 | swagger_configure = {"title": "DMapManager"} | 21 | swagger_configure = {"title": "DMapManager"} |
| @@ -6,5 +6,5 @@ import os | @@ -6,5 +6,5 @@ import os | ||
| 6 | os.environ['AUTHLIB_INSECURE_TRANSPORT'] = '1' | 6 | os.environ['AUTHLIB_INSECURE_TRANSPORT'] = '1' |
| 7 | app: Flask = create_app() | 7 | app: Flask = create_app() |
| 8 | if __name__ == '__main__': | 8 | if __name__ == '__main__': |
| 9 | - app.run(host="0.0.0.0", port="8840", threaded=True, debug=True) | 9 | + app.run(host="0.0.0.0", port="8841", threaded=True, debug=True) |
| 10 | # app.run(host="0.0.0.0", port="8840", threaded=True) | 10 | # app.run(host="0.0.0.0", port="8840", threaded=True) |
请
注册
或
登录
后发表评论