正在显示
32 个修改的文件
包含
272 行增加
和
162 行删除
| @@ -72,7 +72,7 @@ def create_app(): | @@ -72,7 +72,7 @@ def create_app(): | ||
| 72 | 72 | ||
| 73 | # swagger设置 | 73 | # swagger设置 |
| 74 | swagger_config = Swagger.DEFAULT_CONFIG | 74 | swagger_config = Swagger.DEFAULT_CONFIG |
| 75 | - swagger_config.update(configure.swagger_configure) | 75 | + swagger_config.update({"title": "DMapManager"}) |
| 76 | Swagger(app, config=swagger_config) | 76 | Swagger(app, config=swagger_config) |
| 77 | 77 | ||
| 78 | # 创建数据库 | 78 | # 创建数据库 |
| @@ -93,7 +93,7 @@ def create_app(): | @@ -93,7 +93,7 @@ def create_app(): | ||
| 93 | config_oauth(app) | 93 | config_oauth(app) |
| 94 | 94 | ||
| 95 | # 注册blueprint,查找BlueprintApi的子类 | 95 | # 注册blueprint,查找BlueprintApi的子类 |
| 96 | - for scan in configure.scan_module: | 96 | + for scan in ["app.modules"]: |
| 97 | for api in find_class(scan, BlueprintApi): | 97 | for api in find_class(scan, BlueprintApi): |
| 98 | app.register_blueprint(api.bp) | 98 | app.register_blueprint(api.bp) |
| 99 | 99 |
| @@ -3,7 +3,7 @@ from authlib.integrations.flask_oauth2 import current_token | @@ -3,7 +3,7 @@ from authlib.integrations.flask_oauth2 import current_token | ||
| 3 | from flask import abort | 3 | from flask import abort |
| 4 | from app.modules.auth.oauth2 import require_oauth | 4 | from app.modules.auth.oauth2 import require_oauth |
| 5 | from flask import request | 5 | from flask import request |
| 6 | - | 6 | +import configure |
| 7 | # 认证装饰器 | 7 | # 认证装饰器 |
| 8 | 8 | ||
| 9 | 9 | ||
| @@ -17,25 +17,28 @@ class auth_decorator(object): | @@ -17,25 +17,28 @@ class auth_decorator(object): | ||
| 17 | 17 | ||
| 18 | @wraps(func) | 18 | @wraps(func) |
| 19 | def wrapped_function(*args, **kwargs): | 19 | def wrapped_function(*args, **kwargs): |
| 20 | - token = request.headers.get('Authorization') | ||
| 21 | - if not token: | ||
| 22 | - abort(401) | ||
| 23 | - validate_token() | ||
| 24 | - if current_token and current_token.user and current_token.user.role: | ||
| 25 | - print(func.__name__) | ||
| 26 | - if self.permission and len(self.permission) > 0: | ||
| 27 | - # 判断角色是否在permission列表中 | ||
| 28 | - role = current_token.user.role | ||
| 29 | - for p in self.permission: | ||
| 30 | - if role == p: | ||
| 31 | - return func(*args, **kwargs) | 20 | + if configure.PermissionActive: |
| 21 | + token = request.headers.get('Authorization') | ||
| 22 | + if not token: | ||
| 23 | + abort(401) | ||
| 24 | + validate_token() | ||
| 25 | + if current_token and current_token.user and current_token.user.role: | ||
| 26 | + print(func.__name__) | ||
| 27 | + if self.permission and len(self.permission) > 0: | ||
| 28 | + # 判断角色是否在permission列表中 | ||
| 29 | + role = current_token.user.role | ||
| 30 | + for p in self.permission: | ||
| 31 | + if role == p: | ||
| 32 | + return func(*args, **kwargs) | ||
| 32 | 33 | ||
| 33 | - abort(403) | 34 | + abort(403) |
| 35 | + else: | ||
| 36 | + # 无permission,不校验 | ||
| 37 | + return func(*args, **kwargs) | ||
| 34 | else: | 38 | else: |
| 35 | - # 无permission,不校验 | ||
| 36 | - return func(*args, **kwargs) | 39 | + abort(401) # 无token,401 |
| 37 | else: | 40 | else: |
| 38 | - abort(401) # 无token,401 | 41 | + return func(*args, **kwargs) |
| 39 | 42 | ||
| 40 | @require_oauth(self.scope) | 43 | @require_oauth(self.scope) |
| 41 | def validate_token(): | 44 | def validate_token(): |
| @@ -3,7 +3,7 @@ from authlib.integrations.flask_oauth2 import current_token | @@ -3,7 +3,7 @@ from authlib.integrations.flask_oauth2 import current_token | ||
| 3 | from flask import abort | 3 | from flask import abort |
| 4 | from app.modules.auth.oauth2 import require_oauth | 4 | from app.modules.auth.oauth2 import require_oauth |
| 5 | from flask import request | 5 | from flask import request |
| 6 | - | 6 | +import configure |
| 7 | # 认证装饰器 | 7 | # 认证装饰器 |
| 8 | 8 | ||
| 9 | 9 | ||
| @@ -14,16 +14,19 @@ class token_decorator(object): | @@ -14,16 +14,19 @@ class token_decorator(object): | ||
| 14 | def __call__(self, func): | 14 | def __call__(self, func): |
| 15 | @wraps(func) | 15 | @wraps(func) |
| 16 | def wrapped_function(*args, **kwargs): | 16 | def wrapped_function(*args, **kwargs): |
| 17 | - token = request.headers.get('Authorization') | ||
| 18 | - if token: | ||
| 19 | - validate_token() | ||
| 20 | - if current_token and current_token.user: | ||
| 21 | - return func(*args, **kwargs) | ||
| 22 | - else: | ||
| 23 | - abort(403) | 17 | + if configure.PermissionActive: |
| 18 | + token = request.headers.get('Authorization') | ||
| 19 | + if token: | ||
| 20 | + validate_token() | ||
| 21 | + if current_token and current_token.user: | ||
| 22 | + return func(*args, **kwargs) | ||
| 23 | + else: | ||
| 24 | + abort(403) | ||
| 24 | 25 | ||
| 26 | + else: | ||
| 27 | + abort(401) # 无token,401 | ||
| 25 | else: | 28 | else: |
| 26 | - abort(401) # 无token,401 | 29 | + return func(*args, **kwargs) |
| 27 | 30 | ||
| 28 | @require_oauth(self.scope) | 31 | @require_oauth(self.scope) |
| 29 | def validate_token(): | 32 | def validate_token(): |
| @@ -6,13 +6,12 @@ from app.util import BlueprintApi | @@ -6,13 +6,12 @@ from app.util import BlueprintApi | ||
| 6 | from flask import Blueprint, render_template, redirect, request, session, jsonify | 6 | from flask import Blueprint, render_template, redirect, request, session, jsonify |
| 7 | from sqlalchemy import and_ | 7 | from sqlalchemy import and_ |
| 8 | from .models import * | 8 | from .models import * |
| 9 | -from .oauth2 import authorization, generate_user_info | 9 | +from .oauth2 import authorization, generate_user_info,require_oauth |
| 10 | from authlib.oauth2 import OAuth2Error | 10 | from authlib.oauth2 import OAuth2Error |
| 11 | from authlib.integrations.flask_oauth2 import current_token | 11 | from authlib.integrations.flask_oauth2 import current_token |
| 12 | from . import user_create, client_create, client_query, user_query, user_update, user_delete | 12 | from . import user_create, client_create, client_query, user_query, user_update, user_delete |
| 13 | import configure | 13 | import configure |
| 14 | from app.decorators.auth_decorator import auth_decorator | 14 | from app.decorators.auth_decorator import auth_decorator |
| 15 | -from app.decorators.token_decorator import token_decorator | ||
| 16 | 15 | ||
| 17 | 16 | ||
| 18 | def current_user(): | 17 | def current_user(): |
| @@ -82,7 +81,7 @@ class DataManager(BlueprintApi): | @@ -82,7 +81,7 @@ class DataManager(BlueprintApi): | ||
| 82 | 81 | ||
| 83 | @staticmethod | 82 | @staticmethod |
| 84 | @bp.route("/userinfo") | 83 | @bp.route("/userinfo") |
| 85 | - @token_decorator("profile") | 84 | + @require_oauth("profile") |
| 86 | def api_me(): | 85 | def api_me(): |
| 87 | try: | 86 | try: |
| 88 | return jsonify(generate_user_info(current_token.user, current_token.scope)) | 87 | return jsonify(generate_user_info(current_token.user, current_token.scope)) |
| @@ -5,15 +5,13 @@ | @@ -5,15 +5,13 @@ | ||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | from ..models import Database,db,Table,TableVacuate,DES | 7 | from ..models import Database,db,Table,TableVacuate,DES |
| 8 | - | ||
| 9 | - | ||
| 10 | - | ||
| 11 | from app.util.component.ApiTemplate import ApiTemplate | 8 | from app.util.component.ApiTemplate import ApiTemplate |
| 12 | from app.util.component.PGUtil import PGUtil | 9 | from app.util.component.PGUtil import PGUtil |
| 13 | import configure | 10 | import configure |
| 14 | from osgeo.ogr import DataSource | 11 | from osgeo.ogr import DataSource |
| 15 | from flask import current_app | 12 | from flask import current_app |
| 16 | from authlib.integrations.flask_oauth2 import current_token | 13 | from authlib.integrations.flask_oauth2 import current_token |
| 14 | +from app.util.component.UserCheck import UserCheck | ||
| 17 | 15 | ||
| 18 | 16 | ||
| 19 | class Api(ApiTemplate): | 17 | class Api(ApiTemplate): |
| @@ -24,9 +22,8 @@ class Api(ApiTemplate): | @@ -24,9 +22,8 @@ class Api(ApiTemplate): | ||
| 24 | try: | 22 | try: |
| 25 | 23 | ||
| 26 | database = db.session.query(Database).filter_by(guid=self.para.get("guid")).one_or_none() | 24 | database = db.session.query(Database).filter_by(guid=self.para.get("guid")).one_or_none() |
| 27 | - if database.creator != current_token.user.username: | ||
| 28 | - raise Exception("缺乏权限!") | ||
| 29 | - | 25 | + #验证权限 |
| 26 | + UserCheck.verify(database.creator,current_token.user.username) | ||
| 30 | if configure.VACUATE_DB_URI: | 27 | if configure.VACUATE_DB_URI: |
| 31 | va_ds: DataSource = PGUtil.open_pg_data_source(1, configure.VACUATE_DB_URI) | 28 | va_ds: DataSource = PGUtil.open_pg_data_source(1, configure.VACUATE_DB_URI) |
| 32 | else: | 29 | else: |
| @@ -5,14 +5,12 @@ | @@ -5,14 +5,12 @@ | ||
| 5 | 5 | ||
| 6 | from ..models import Database,db,DES | 6 | from ..models import Database,db,DES |
| 7 | from contextlib import closing | 7 | from contextlib import closing |
| 8 | - | ||
| 9 | from sqlalchemy import create_engine | 8 | from sqlalchemy import create_engine |
| 10 | - | ||
| 11 | import datetime | 9 | import datetime |
| 12 | from . import database_alias_check | 10 | from . import database_alias_check |
| 13 | - | ||
| 14 | from app.util.component.ApiTemplate import ApiTemplate | 11 | from app.util.component.ApiTemplate import ApiTemplate |
| 15 | - | 12 | +from authlib.integrations.flask_oauth2 import current_token |
| 13 | +from app.util.component.UserCheck import UserCheck | ||
| 16 | from app.util.component.PGUtil import PGUtil | 14 | from app.util.component.PGUtil import PGUtil |
| 17 | class Api(ApiTemplate): | 15 | class Api(ApiTemplate): |
| 18 | api_name = "修改数据库" | 16 | api_name = "修改数据库" |
| @@ -28,8 +26,8 @@ class Api(ApiTemplate): | @@ -28,8 +26,8 @@ class Api(ApiTemplate): | ||
| 28 | database = Database.query.filter_by(guid=guid) | 26 | database = Database.query.filter_by(guid=guid) |
| 29 | dbase:Database = database.one_or_none() | 27 | dbase:Database = database.one_or_none() |
| 30 | 28 | ||
| 31 | - if dbase.creator != "": | ||
| 32 | - raise Exception("缺乏权限!") | 29 | + #验证权限 |
| 30 | + UserCheck.verify(dbase.creator,current_token.user.username) | ||
| 33 | 31 | ||
| 34 | update_dict={} | 32 | update_dict={} |
| 35 | 33 | ||
| @@ -40,7 +38,6 @@ class Api(ApiTemplate): | @@ -40,7 +38,6 @@ class Api(ApiTemplate): | ||
| 40 | res["msg"] = "请填写参数!" | 38 | res["msg"] = "请填写参数!" |
| 41 | return res | 39 | return res |
| 42 | 40 | ||
| 43 | - | ||
| 44 | if alias: | 41 | if alias: |
| 45 | # 检测一波别名 | 42 | # 检测一波别名 |
| 46 | check_alias = database_alias_check.Api().result | 43 | check_alias = database_alias_check.Api().result |
| @@ -74,7 +74,7 @@ class DataManager(BlueprintApi): | @@ -74,7 +74,7 @@ class DataManager(BlueprintApi): | ||
| 74 | @staticmethod | 74 | @staticmethod |
| 75 | @bp.route('/GetMeta', methods=['POST']) | 75 | @bp.route('/GetMeta', methods=['POST']) |
| 76 | @swag_from(get_meta.Api.api_doc) | 76 | @swag_from(get_meta.Api.api_doc) |
| 77 | - @auth_decorator(configure.DataPermission) | 77 | + # @auth_decorator(configure.DataPermission) |
| 78 | def get_meta(): | 78 | def get_meta(): |
| 79 | """ | 79 | """ |
| 80 | 数据Meta | 80 | 数据Meta |
| @@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
| 7 | from ..models import * | 7 | from ..models import * |
| 8 | 8 | ||
| 9 | import traceback | 9 | import traceback |
| 10 | - | 10 | +from .util.SchemaAdapter import SchemaAdapter |
| 11 | from osgeo.ogr import DataSource,Layer,FeatureDefn,FieldDefn,Feature | 11 | from osgeo.ogr import DataSource,Layer,FeatureDefn,FieldDefn,Feature |
| 12 | from osgeo import gdal,ogr | 12 | from osgeo import gdal,ogr |
| 13 | import os | 13 | import os |
| @@ -51,6 +51,15 @@ class Api(ApiTemplate): | @@ -51,6 +51,15 @@ class Api(ApiTemplate): | ||
| 51 | db.session.commit() | 51 | db.session.commit() |
| 52 | 52 | ||
| 53 | res["data"] = "下载任务已提交!" | 53 | res["data"] = "下载任务已提交!" |
| 54 | + | ||
| 55 | + # 提示信息 | ||
| 56 | + res["msg"] = "下载格式为shp时,属性名长度超过10个字符将截取为10个字符,binary类型的属性将改成integer类型且值为0。" | ||
| 57 | + # table_names = self.para.get("table_name").split(",") | ||
| 58 | + # | ||
| 59 | + # for tn in table_names: | ||
| 60 | + # table = Table.query.filter_by() | ||
| 61 | + | ||
| 62 | + res["msg"] = "" | ||
| 54 | res["result"] = True | 63 | res["result"] = True |
| 55 | 64 | ||
| 56 | except Exception as e: | 65 | except Exception as e: |
| @@ -64,11 +73,11 @@ class Api(ApiTemplate): | @@ -64,11 +73,11 @@ class Api(ApiTemplate): | ||
| 64 | task_writer = None | 73 | task_writer = None |
| 65 | 74 | ||
| 66 | # 设置编码 | 75 | # 设置编码 |
| 67 | - encoding = para.get("encoding") | ||
| 68 | - if encoding: | ||
| 69 | - gdal.SetConfigOption("SHAPE_ENCODING", encoding) | ||
| 70 | - else: | ||
| 71 | - gdal.SetConfigOption("SHAPE_ENCODING", "UTF-8") | 76 | + # encoding = para.get("encoding") |
| 77 | + # if encoding: | ||
| 78 | + # gdal.SetConfigOption("SHAPE_ENCODING", encoding) | ||
| 79 | + # else: | ||
| 80 | + # gdal.SetConfigOption("SHAPE_ENCODING", "GBK") | ||
| 72 | 81 | ||
| 73 | try: | 82 | try: |
| 74 | 83 | ||
| @@ -133,10 +142,14 @@ class Api(ApiTemplate): | @@ -133,10 +142,14 @@ class Api(ApiTemplate): | ||
| 133 | 142 | ||
| 134 | 143 | ||
| 135 | fid = layer.GetFIDColumn() | 144 | fid = layer.GetFIDColumn() |
| 136 | - pg_layer: Layer = data_source.CreateLayer(table_name, layer.GetSpatialRef(), layer.GetGeomType(),["ENCODING=UTF-8"]) | 145 | + pg_layer: Layer = data_source.CreateLayer(table_name, layer.GetSpatialRef(), layer.GetGeomType(),["ENCODING=GBK"]) |
| 146 | + | ||
| 137 | schema = [sche for sche in layer.schema if not sche.name.__eq__(fid)] | 147 | schema = [sche for sche in layer.schema if not sche.name.__eq__(fid)] |
| 148 | + # 忽略binary字段 | ||
| 149 | + SchemaAdapter.neglect_binary(schema) | ||
| 138 | 150 | ||
| 139 | pg_layer.CreateFields(schema) | 151 | pg_layer.CreateFields(schema) |
| 152 | + | ||
| 140 | layer.ResetReading() | 153 | layer.ResetReading() |
| 141 | 154 | ||
| 142 | count = 0 | 155 | count = 0 |
| @@ -147,6 +160,11 @@ class Api(ApiTemplate): | @@ -147,6 +160,11 @@ class Api(ApiTemplate): | ||
| 147 | StructurePrint().print("{}图层已下载{}个对象".format(table_name, count)) | 160 | StructurePrint().print("{}图层已下载{}个对象".format(table_name, count)) |
| 148 | 161 | ||
| 149 | data_source.Destroy() | 162 | data_source.Destroy() |
| 163 | + | ||
| 164 | + #增加cpg文件 | ||
| 165 | + with open(dirpath + "/{}.cpg".format(table_name),"w") as f: | ||
| 166 | + f.write("GBK") | ||
| 167 | + | ||
| 150 | ZipUtil.create_zip(os.path.join(parent, "file_tmp", table_name+"_"+uuid_) + ".zip", [dirpath]) | 168 | ZipUtil.create_zip(os.path.join(parent, "file_tmp", table_name+"_"+uuid_) + ".zip", [dirpath]) |
| 151 | return "http://" + configure.deploy_ip_host + "/API/IO/Download/{}".format(table_name+"_"+uuid_ + ".zip") | 169 | return "http://" + configure.deploy_ip_host + "/API/IO/Download/{}".format(table_name+"_"+uuid_ + ".zip") |
| 152 | 170 | ||
| @@ -208,6 +226,11 @@ class Api(ApiTemplate): | @@ -208,6 +226,11 @@ class Api(ApiTemplate): | ||
| 208 | return data | 226 | return data |
| 209 | 227 | ||
| 210 | 228 | ||
| 229 | + def msg(self): | ||
| 230 | + pass | ||
| 231 | + | ||
| 232 | + | ||
| 233 | + | ||
| 211 | api_doc={ | 234 | api_doc={ |
| 212 | "tags":["IO接口"], | 235 | "tags":["IO接口"], |
| 213 | "description":"下载数据", | 236 | "description":"下载数据", |
| @@ -215,10 +238,10 @@ class Api(ApiTemplate): | @@ -215,10 +238,10 @@ class Api(ApiTemplate): | ||
| 215 | {"name": "table_name", | 238 | {"name": "table_name", |
| 216 | "in": "formData", | 239 | "in": "formData", |
| 217 | "type":"string","description":"支持多图层下载,以逗号相隔","required":"true"}, | 240 | "type":"string","description":"支持多图层下载,以逗号相隔","required":"true"}, |
| 218 | - {"name": "encoding", | ||
| 219 | - "in": "formData", | ||
| 220 | - "type": "string", | ||
| 221 | - "enum":["GBK","UTF-8"]}, | 241 | + # {"name": "encoding", |
| 242 | + # "in": "formData", | ||
| 243 | + # "type": "string", | ||
| 244 | + # "enum":["GBK","UTF-8"]}, | ||
| 222 | {"name": "download_type", | 245 | {"name": "download_type", |
| 223 | "in": "formData", | 246 | "in": "formData", |
| 224 | "type": "string", | 247 | "type": "string", |
| @@ -13,7 +13,7 @@ import json | @@ -13,7 +13,7 @@ import json | ||
| 13 | from app.util.component.ApiTemplate import ApiTemplate | 13 | from app.util.component.ApiTemplate import ApiTemplate |
| 14 | from .get_meta import Api as MetaApi | 14 | from .get_meta import Api as MetaApi |
| 15 | from threading import Thread | 15 | from threading import Thread |
| 16 | -from ..util.EntryDataVacuate import EntryDataVacuate | 16 | +from .util.EntryDataVacuate import EntryDataVacuate |
| 17 | 17 | ||
| 18 | class Api(ApiTemplate): | 18 | class Api(ApiTemplate): |
| 19 | 19 |
| @@ -104,7 +104,7 @@ class EntryDataVacuate: | @@ -104,7 +104,7 @@ class EntryDataVacuate: | ||
| 104 | dir_path = os.path.dirname(dir_path) | 104 | dir_path = os.path.dirname(dir_path) |
| 105 | i+=1 | 105 | i+=1 |
| 106 | if i<30: | 106 | if i<30: |
| 107 | - # shutil.rmtree(dir_path,True) | 107 | + shutil.rmtree(dir_path,True) |
| 108 | StructurePrint().print("删除文件成功!") | 108 | StructurePrint().print("删除文件成功!") |
| 109 | else: | 109 | else: |
| 110 | raise Exception("找不到文件!") | 110 | raise Exception("找不到文件!") |
app/modules/data/io/util/SchemaAdapter.py
0 → 100644
| 1 | +# coding=utf-8 | ||
| 2 | +#author: 4N | ||
| 3 | +#createtime: 2022/1/17 | ||
| 4 | +#email: nheweijun@sina.com | ||
| 5 | +from osgeo import ogr | ||
| 6 | + | ||
| 7 | +class SchemaAdapter: | ||
| 8 | + @classmethod | ||
| 9 | + def neglect_binary(cls,schema): | ||
| 10 | + for sche in schema: | ||
| 11 | + if sche.GetType() == ogr.OFTBinary: | ||
| 12 | + sche.SetType(ogr.OFTInteger) | ||
| 13 | + | ||
| 14 | + return schema |
| @@ -4,11 +4,10 @@ | @@ -4,11 +4,10 @@ | ||
| 4 | 4 | ||
| 5 | from ..models import Columns | 5 | from ..models import Columns |
| 6 | import datetime | 6 | import datetime |
| 7 | - | ||
| 8 | - | ||
| 9 | from app.models import db | 7 | from app.models import db |
| 10 | from app.util.component.ApiTemplate import ApiTemplate | 8 | from app.util.component.ApiTemplate import ApiTemplate |
| 11 | - | 9 | +from authlib.integrations.flask_oauth2 import current_token |
| 10 | +from app.util.component.UserCheck import UserCheck | ||
| 12 | 11 | ||
| 13 | class Api(ApiTemplate): | 12 | class Api(ApiTemplate): |
| 14 | api_name = "修改属性" | 13 | api_name = "修改属性" |
| @@ -24,8 +23,8 @@ class Api(ApiTemplate): | @@ -24,8 +23,8 @@ class Api(ApiTemplate): | ||
| 24 | if not column: | 23 | if not column: |
| 25 | raise Exception("数据不存在!") | 24 | raise Exception("数据不存在!") |
| 26 | 25 | ||
| 27 | - if column.relate_table.relate_database.creator != "": | ||
| 28 | - raise Exception("缺乏权限!") | 26 | + #验证权限 |
| 27 | + UserCheck.verify(column.relate_table.relate_database.creator,current_token.user.username) | ||
| 29 | 28 | ||
| 30 | try: | 29 | try: |
| 31 | if self.para.get("column_alias"): | 30 | if self.para.get("column_alias"): |
| @@ -2,21 +2,16 @@ | @@ -2,21 +2,16 @@ | ||
| 2 | #createtime: 2021/1/27 | 2 | #createtime: 2021/1/27 |
| 3 | #email: nheweijun@sina.com | 3 | #email: nheweijun@sina.com |
| 4 | 4 | ||
| 5 | - | ||
| 6 | - | ||
| 7 | -import traceback | ||
| 8 | from ..models import Table,Database,DES | 5 | from ..models import Table,Database,DES |
| 9 | - | ||
| 10 | - | ||
| 11 | from osgeo.ogr import DataSource | 6 | from osgeo.ogr import DataSource |
| 12 | - | ||
| 13 | - | ||
| 14 | from app.models import db | 7 | from app.models import db |
| 15 | from app.util.component.ApiTemplate import ApiTemplate | 8 | from app.util.component.ApiTemplate import ApiTemplate |
| 16 | - | ||
| 17 | from app.util.component.PGUtil import PGUtil | 9 | from app.util.component.PGUtil import PGUtil |
| 18 | import configure | 10 | import configure |
| 19 | from flask import current_app | 11 | from flask import current_app |
| 12 | +from authlib.integrations.flask_oauth2 import current_token | ||
| 13 | +from app.util.component.UserCheck import UserCheck | ||
| 14 | + | ||
| 20 | class Api(ApiTemplate): | 15 | class Api(ApiTemplate): |
| 21 | api_name = "删除表" | 16 | api_name = "删除表" |
| 22 | def process(self): | 17 | def process(self): |
| @@ -37,11 +32,12 @@ class Api(ApiTemplate): | @@ -37,11 +32,12 @@ class Api(ApiTemplate): | ||
| 37 | 32 | ||
| 38 | 33 | ||
| 39 | table = table.one_or_none() | 34 | table = table.one_or_none() |
| 40 | - | ||
| 41 | - | ||
| 42 | - | ||
| 43 | # 删除真实数据 | 35 | # 删除真实数据 |
| 44 | database = Database.query.filter_by(guid=table.database_guid).one_or_none() | 36 | database = Database.query.filter_by(guid=table.database_guid).one_or_none() |
| 37 | + | ||
| 38 | + #验证权限 | ||
| 39 | + UserCheck.verify(database.creator,current_token.user.username) | ||
| 40 | + | ||
| 45 | if not database: | 41 | if not database: |
| 46 | res["result"]=False | 42 | res["result"]=False |
| 47 | res["msg"]= "数据库不存在!" | 43 | res["msg"]= "数据库不存在!" |
| @@ -2,16 +2,14 @@ | @@ -2,16 +2,14 @@ | ||
| 2 | #createtime: 2021/1/27 | 2 | #createtime: 2021/1/27 |
| 3 | #email: nheweijun@sina.com | 3 | #email: nheweijun@sina.com |
| 4 | 4 | ||
| 5 | - | ||
| 6 | - | ||
| 7 | from ..models import * | 5 | from ..models import * |
| 8 | - | ||
| 9 | import json | 6 | import json |
| 10 | - | ||
| 11 | from sqlalchemy.orm import Session | 7 | from sqlalchemy.orm import Session |
| 12 | import datetime | 8 | import datetime |
| 13 | from app.util.component.ApiTemplate import ApiTemplate | 9 | from app.util.component.ApiTemplate import ApiTemplate |
| 14 | from app.util.component.PGUtil import PGUtil | 10 | from app.util.component.PGUtil import PGUtil |
| 11 | +from authlib.integrations.flask_oauth2 import current_token | ||
| 12 | +from app.util.component.UserCheck import UserCheck | ||
| 15 | 13 | ||
| 16 | class Api(ApiTemplate): | 14 | class Api(ApiTemplate): |
| 17 | api_name = "修改表信息" | 15 | api_name = "修改表信息" |
| @@ -34,8 +32,8 @@ class Api(ApiTemplate): | @@ -34,8 +32,8 @@ class Api(ApiTemplate): | ||
| 34 | res["msg"]= "数据不存在!" | 32 | res["msg"]= "数据不存在!" |
| 35 | return res | 33 | return res |
| 36 | 34 | ||
| 37 | - if table.relate_database.creator != "": | ||
| 38 | - raise Exception("缺乏权限!") | 35 | + #验证权限 |
| 36 | + UserCheck.verify(table.relate_database.creator,current_token.user.username) | ||
| 39 | 37 | ||
| 40 | if self.para.__contains__("catalog_guid"): | 38 | if self.para.__contains__("catalog_guid"): |
| 41 | if catalog_guid is None: | 39 | if catalog_guid is None: |
| @@ -2,16 +2,11 @@ | @@ -2,16 +2,11 @@ | ||
| 2 | #createtime: 2021/1/27 | 2 | #createtime: 2021/1/27 |
| 3 | #email: nheweijun@sina.com | 3 | #email: nheweijun@sina.com |
| 4 | 4 | ||
| 5 | - | ||
| 6 | - | ||
| 7 | import traceback | 5 | import traceback |
| 8 | from ..models import Table,Database,Columns,db,TableVacuate,Task,Process,DES | 6 | from ..models import Table,Database,Columns,db,TableVacuate,Task,Process,DES |
| 9 | - | ||
| 10 | from osgeo.ogr import DataSource,FeatureDefn,FieldDefn,Layer | 7 | from osgeo.ogr import DataSource,FeatureDefn,FieldDefn,Layer |
| 11 | - | ||
| 12 | import datetime | 8 | import datetime |
| 13 | import uuid | 9 | import uuid |
| 14 | - | ||
| 15 | from sqlalchemy.orm import Session | 10 | from sqlalchemy.orm import Session |
| 16 | from app.util.component.SQLUtil import SQLUtil | 11 | from app.util.component.SQLUtil import SQLUtil |
| 17 | from app.util.component.PGUtil import PGUtil | 12 | from app.util.component.PGUtil import PGUtil |
| @@ -22,7 +17,8 @@ from app.util.component.TaskController import TaskController | @@ -22,7 +17,8 @@ from app.util.component.TaskController import TaskController | ||
| 22 | from app.util.component.TaskWriter import TaskWriter | 17 | from app.util.component.TaskWriter import TaskWriter |
| 23 | import multiprocessing | 18 | import multiprocessing |
| 24 | import configure | 19 | import configure |
| 25 | - | 20 | +from authlib.integrations.flask_oauth2 import current_token |
| 21 | +from app.util.component.UserCheck import UserCheck | ||
| 26 | class Api(ApiTemplate): | 22 | class Api(ApiTemplate): |
| 27 | api_name = "数据刷新" | 23 | api_name = "数据刷新" |
| 28 | def process(self): | 24 | def process(self): |
| @@ -32,6 +28,9 @@ class Api(ApiTemplate): | @@ -32,6 +28,9 @@ class Api(ApiTemplate): | ||
| 32 | database_guid = self.para.get("database_guid") | 28 | database_guid = self.para.get("database_guid") |
| 33 | database = Database.query.filter_by(guid=database_guid).one_or_none() | 29 | database = Database.query.filter_by(guid=database_guid).one_or_none() |
| 34 | 30 | ||
| 31 | + #验证权限 | ||
| 32 | + UserCheck.verify(database.creator,current_token.user.username) | ||
| 33 | + | ||
| 35 | if database.creator != "": | 34 | if database.creator != "": |
| 36 | raise Exception("缺乏权限!") | 35 | raise Exception("缺乏权限!") |
| 37 | 36 |
| @@ -21,10 +21,10 @@ from app.util.component.TaskController import TaskController | @@ -21,10 +21,10 @@ from app.util.component.TaskController import TaskController | ||
| 21 | from app.util.component.TaskWriter import TaskWriter | 21 | from app.util.component.TaskWriter import TaskWriter |
| 22 | from osgeo.ogr import DataSource,Layer,Geometry | 22 | from osgeo.ogr import DataSource,Layer,Geometry |
| 23 | from osgeo import ogr | 23 | from osgeo import ogr |
| 24 | +from authlib.integrations.flask_oauth2 import current_token | ||
| 25 | +from app.util.component.UserCheck import UserCheck | ||
| 24 | 26 | ||
| 25 | 27 | ||
| 26 | -from sqlalchemy.orm import Session | ||
| 27 | - | ||
| 28 | 28 | ||
| 29 | class Api(ApiTemplate): | 29 | class Api(ApiTemplate): |
| 30 | 30 | ||
| @@ -42,8 +42,8 @@ class Api(ApiTemplate): | @@ -42,8 +42,8 @@ class Api(ApiTemplate): | ||
| 42 | if not table: | 42 | if not table: |
| 43 | raise Exception("数据不存在!") | 43 | raise Exception("数据不存在!") |
| 44 | 44 | ||
| 45 | - if table.relate_database.creator != "": | ||
| 46 | - raise Exception("缺乏权限!") | 45 | + #验证权限 |
| 46 | + UserCheck.verify(table.relate_database.creator,current_token.user.username) | ||
| 47 | 47 | ||
| 48 | pg_ds :DataSource= PGUtil.open_pg_data_source(0,DES.decode(table.relate_database.sqlalchemy_uri)) | 48 | pg_ds :DataSource= PGUtil.open_pg_data_source(0,DES.decode(table.relate_database.sqlalchemy_uri)) |
| 49 | layer = pg_ds.GetLayerByName(table.name) | 49 | layer = pg_ds.GetLayerByName(table.name) |
| @@ -14,7 +14,8 @@ import uuid | @@ -14,7 +14,8 @@ import uuid | ||
| 14 | import configure | 14 | import configure |
| 15 | from osgeo.ogr import DataSource,Layer,Geometry | 15 | from osgeo.ogr import DataSource,Layer,Geometry |
| 16 | from osgeo import ogr | 16 | from osgeo import ogr |
| 17 | - | 17 | +from authlib.integrations.flask_oauth2 import current_token |
| 18 | +from app.util.component.UserCheck import UserCheck | ||
| 18 | from app.util.component.VacuateConf import VacuateConf | 19 | from app.util.component.VacuateConf import VacuateConf |
| 19 | from app.util.component.TaskController import TaskController | 20 | from app.util.component.TaskController import TaskController |
| 20 | from app.util.component.TaskWriter import TaskWriter | 21 | from app.util.component.TaskWriter import TaskWriter |
| @@ -40,8 +41,8 @@ class Api(ApiTemplate): | @@ -40,8 +41,8 @@ class Api(ApiTemplate): | ||
| 40 | if not table: | 41 | if not table: |
| 41 | raise Exception("数据不存在!") | 42 | raise Exception("数据不存在!") |
| 42 | 43 | ||
| 43 | - if table.relate_database.creator != "": | ||
| 44 | - raise Exception("缺乏权限!") | 44 | + #验证权限 |
| 45 | + UserCheck.verify(table.relate_database.creator,current_token.user.username) | ||
| 45 | 46 | ||
| 46 | # 判断图层是否存在 | 47 | # 判断图层是否存在 |
| 47 | 48 |
| @@ -4,10 +4,9 @@ | @@ -4,10 +4,9 @@ | ||
| 4 | #email: nheweijun@sina.com | 4 | #email: nheweijun@sina.com |
| 5 | 5 | ||
| 6 | from ..models import db,Task | 6 | from ..models import db,Task |
| 7 | - | ||
| 8 | - | ||
| 9 | from app.util.component.ApiTemplate import ApiTemplate | 7 | from app.util.component.ApiTemplate import ApiTemplate |
| 10 | - | 8 | +from authlib.integrations.flask_oauth2 import current_token |
| 9 | +from app.util.component.UserCheck import UserCheck | ||
| 11 | 10 | ||
| 12 | class Api(ApiTemplate): | 11 | class Api(ApiTemplate): |
| 13 | api_name = "删除任务" | 12 | api_name = "删除任务" |
| @@ -18,29 +17,19 @@ class Api(ApiTemplate): | @@ -18,29 +17,19 @@ class Api(ApiTemplate): | ||
| 18 | res = {} | 17 | res = {} |
| 19 | try: | 18 | try: |
| 20 | task_guid = self.para.get("task_guid") | 19 | task_guid = self.para.get("task_guid") |
| 21 | - state = self.para.get("state") | ||
| 22 | - creator = self.para.get("creator") | 20 | + task = Task.query.filter_by(guid=task_guid).one_or_none() |
| 21 | + | ||
| 22 | + if not task: | ||
| 23 | + raise Exception("任务不存在!") | ||
| 24 | + | ||
| 25 | + #验证权限 | ||
| 26 | + UserCheck.verify(task.creator,current_token.user.username) | ||
| 23 | 27 | ||
| 24 | - tasks = Task.query | ||
| 25 | - if task_guid: | ||
| 26 | - tasks = tasks.filter_by(guid=task_guid) | ||
| 27 | - if state: | ||
| 28 | - state = int(state) | ||
| 29 | - tasks = tasks.filter_by(state=state) | ||
| 30 | - if creator: | ||
| 31 | - tasks = tasks.filter_by(creator=creator) | ||
| 32 | - tasks = tasks.all() | 28 | + db.session.delete(task) |
| 29 | + db.session.commit() | ||
| 33 | 30 | ||
| 34 | - if not tasks: | ||
| 35 | - res["result"] = False | ||
| 36 | - res["msg"] = "数据不存在!" | ||
| 37 | - return res | ||
| 38 | - else: | ||
| 39 | - for task in tasks: | ||
| 40 | - db.session.delete(task) | ||
| 41 | - db.session.commit() | ||
| 42 | - res["msg"] = "删除成功!" | ||
| 43 | - res["result"] = True | 31 | + res["msg"] = "删除成功!" |
| 32 | + res["result"] = True | ||
| 44 | except Exception as e: | 33 | except Exception as e: |
| 45 | db.session.rollback() | 34 | db.session.rollback() |
| 46 | raise e | 35 | raise e |
| @@ -53,12 +42,6 @@ class Api(ApiTemplate): | @@ -53,12 +42,6 @@ class Api(ApiTemplate): | ||
| 53 | {"name": "task_guid", | 42 | {"name": "task_guid", |
| 54 | "in": "formData", | 43 | "in": "formData", |
| 55 | "type": "string"}, | 44 | "type": "string"}, |
| 56 | - {"name": "state", | ||
| 57 | - "in": "formData", | ||
| 58 | - "type": "string"}, | ||
| 59 | - {"name": "creator", | ||
| 60 | - "in": "formData", | ||
| 61 | - "type": "string"}, | ||
| 62 | 45 | ||
| 63 | ], | 46 | ], |
| 64 | "responses": { | 47 | "responses": { |
| @@ -13,6 +13,8 @@ import platform | @@ -13,6 +13,8 @@ import platform | ||
| 13 | import json | 13 | import json |
| 14 | import datetime | 14 | import datetime |
| 15 | import uuid | 15 | import uuid |
| 16 | +from authlib.integrations.flask_oauth2 import current_token | ||
| 17 | +from app.util.component.UserCheck import UserCheck | ||
| 16 | class Api(ApiTemplate): | 18 | class Api(ApiTemplate): |
| 17 | api_name = "停止任务" | 19 | api_name = "停止任务" |
| 18 | def para_check(self): | 20 | def para_check(self): |
| @@ -23,6 +25,12 @@ class Api(ApiTemplate): | @@ -23,6 +25,12 @@ class Api(ApiTemplate): | ||
| 23 | try: | 25 | try: |
| 24 | task_guid = self.para.get("task_guid") | 26 | task_guid = self.para.get("task_guid") |
| 25 | task = Task.query.filter_by(guid=task_guid).one_or_none() | 27 | task = Task.query.filter_by(guid=task_guid).one_or_none() |
| 28 | + if not task: | ||
| 29 | + raise Exception("任务不存在!") | ||
| 30 | + | ||
| 31 | + #验证权限 | ||
| 32 | + UserCheck.verify(task.creator,current_token.user.username) | ||
| 33 | + | ||
| 26 | pid = task.task_pid | 34 | pid = task.task_pid |
| 27 | try: | 35 | try: |
| 28 | if platform.system().lower().__contains__("windows"): | 36 | if platform.system().lower().__contains__("windows"): |
| @@ -19,6 +19,7 @@ class Api(ApiTemplate): | @@ -19,6 +19,7 @@ class Api(ApiTemplate): | ||
| 19 | catalogs = ServiceCatalog.query.all() | 19 | catalogs = ServiceCatalog.query.all() |
| 20 | res["data"]=[] | 20 | res["data"]=[] |
| 21 | 21 | ||
| 22 | + | ||
| 22 | # 获取全部影像服务 | 23 | # 获取全部影像服务 |
| 23 | image_engines = ServiceEngine.query.filter_by(type="ImageServer").all() | 24 | image_engines = ServiceEngine.query.filter_by(type="ImageServer").all() |
| 24 | image_services = [] | 25 | image_services = [] |
| @@ -30,6 +31,8 @@ class Api(ApiTemplate): | @@ -30,6 +31,8 @@ class Api(ApiTemplate): | ||
| 30 | else: | 31 | else: |
| 31 | image_services.extend(response.json()["data"]["list"]) | 32 | image_services.extend(response.json()["data"]["list"]) |
| 32 | 33 | ||
| 34 | + | ||
| 35 | + | ||
| 33 | for cata in catalogs: | 36 | for cata in catalogs: |
| 34 | catalog_guids = [c.guid for c in ServiceCatalog.query.filter(ServiceCatalog.path.like("%" + cata.guid + "%")).all()] | 37 | catalog_guids = [c.guid for c in ServiceCatalog.query.filter(ServiceCatalog.path.like("%" + cata.guid + "%")).all()] |
| 35 | service_count = Service.query.filter(Service.catalog_guid.in_(catalog_guids)).count() | 38 | service_count = Service.query.filter(Service.catalog_guid.in_(catalog_guids)).count() |
| @@ -47,7 +50,7 @@ class Api(ApiTemplate): | @@ -47,7 +50,7 @@ class Api(ApiTemplate): | ||
| 47 | res["data"].append(cata_json) | 50 | res["data"].append(cata_json) |
| 48 | 51 | ||
| 49 | res["result"] = True | 52 | res["result"] = True |
| 50 | - | 53 | + res["service_count"] = len(image_services) + Service.query.count() |
| 51 | except Exception as e: | 54 | except Exception as e: |
| 52 | raise e | 55 | raise e |
| 53 | return res | 56 | return res |
| @@ -6,6 +6,8 @@ | @@ -6,6 +6,8 @@ | ||
| 6 | 6 | ||
| 7 | from app.util.component.ApiTemplate import ApiTemplate | 7 | from app.util.component.ApiTemplate import ApiTemplate |
| 8 | import requests | 8 | import requests |
| 9 | +from authlib.integrations.flask_oauth2 import current_token | ||
| 10 | +from app.util.component.UserCheck import UserCheck | ||
| 9 | 11 | ||
| 10 | class Api(ApiTemplate): | 12 | class Api(ApiTemplate): |
| 11 | 13 | ||
| @@ -15,6 +17,14 @@ class Api(ApiTemplate): | @@ -15,6 +17,14 @@ class Api(ApiTemplate): | ||
| 15 | # 返回结果 | 17 | # 返回结果 |
| 16 | res = {} | 18 | res = {} |
| 17 | try: | 19 | try: |
| 20 | + | ||
| 21 | + user_req: requests.Response = requests.post("{}/API/Service/Info".format(self.para.get("url")), | ||
| 22 | + data={"guid":self.para.get("guid")}) | ||
| 23 | + if not user_req.json().get("result"): | ||
| 24 | + raise Exception("服务不存在!") | ||
| 25 | + # 验证权限 | ||
| 26 | + UserCheck.verify(user_req.json().get("data").get("service").get("creator"), current_token.user.username) | ||
| 27 | + | ||
| 18 | url = "{}/API/Service/Delete".format(self.para.get("url")) | 28 | url = "{}/API/Service/Delete".format(self.para.get("url")) |
| 19 | response:requests.Response = requests.post(url,data=self.para) | 29 | response:requests.Response = requests.post(url,data=self.para) |
| 20 | if not response.json().get("result"): | 30 | if not response.json().get("result"): |
| @@ -6,6 +6,8 @@ | @@ -6,6 +6,8 @@ | ||
| 6 | 6 | ||
| 7 | from app.util.component.ApiTemplate import ApiTemplate | 7 | from app.util.component.ApiTemplate import ApiTemplate |
| 8 | import requests | 8 | import requests |
| 9 | +from authlib.integrations.flask_oauth2 import current_token | ||
| 10 | +from app.util.component.UserCheck import UserCheck | ||
| 9 | 11 | ||
| 10 | class Api(ApiTemplate): | 12 | class Api(ApiTemplate): |
| 11 | 13 | ||
| @@ -15,6 +17,14 @@ class Api(ApiTemplate): | @@ -15,6 +17,14 @@ class Api(ApiTemplate): | ||
| 15 | # 返回结果 | 17 | # 返回结果 |
| 16 | res = {} | 18 | res = {} |
| 17 | try: | 19 | try: |
| 20 | + | ||
| 21 | + user_req: requests.Response = requests.post("{}/API/Service/Info".format(self.para.get("url")), | ||
| 22 | + data={"guid":self.para.get("guid")}) | ||
| 23 | + if not user_req.json().get("result"): | ||
| 24 | + raise Exception("服务不存在!") | ||
| 25 | + # 验证权限 | ||
| 26 | + UserCheck.verify(user_req.json().get("data").get("service").get("creator"), current_token.user.username) | ||
| 27 | + | ||
| 18 | url = "{}/API/Service/Edit".format(self.para.get("url")) | 28 | url = "{}/API/Service/Edit".format(self.para.get("url")) |
| 19 | response:requests.Response = requests.post(url,data=self.para) | 29 | response:requests.Response = requests.post(url,data=self.para) |
| 20 | if not response.json().get("result"): | 30 | if not response.json().get("result"): |
| @@ -7,9 +7,13 @@ | @@ -7,9 +7,13 @@ | ||
| 7 | from app.util.component.ApiTemplate import ApiTemplate | 7 | from app.util.component.ApiTemplate import ApiTemplate |
| 8 | import uuid | 8 | import uuid |
| 9 | from ..models import Service,MapService,db,ServiceFunction | 9 | from ..models import Service,MapService,db,ServiceFunction |
| 10 | - | ||
| 11 | - | 10 | +import requests |
| 11 | +import configure | ||
| 12 | +import json | ||
| 12 | import datetime | 13 | import datetime |
| 14 | +from authlib.integrations.flask_oauth2 import current_token | ||
| 15 | +from app.util.component.UserCheck import UserCheck | ||
| 16 | + | ||
| 13 | class Api(ApiTemplate): | 17 | class Api(ApiTemplate): |
| 14 | 18 | ||
| 15 | api_name = "修改MapService服务" | 19 | api_name = "修改MapService服务" |
| @@ -22,9 +26,14 @@ class Api(ApiTemplate): | @@ -22,9 +26,14 @@ class Api(ApiTemplate): | ||
| 22 | try: | 26 | try: |
| 23 | guid = self.para.get("guid") | 27 | guid = self.para.get("guid") |
| 24 | functions = self.para.get("functions") | 28 | functions = self.para.get("functions") |
| 25 | - service = Service.query.filter_by(guid=guid) | 29 | + service :Service = Service.query.filter_by(guid=guid) |
| 26 | this_time = datetime.datetime.now() | 30 | this_time = datetime.datetime.now() |
| 27 | 31 | ||
| 32 | + if not service: | ||
| 33 | + raise Exception("服务不存在!") | ||
| 34 | + | ||
| 35 | + #验证权限 | ||
| 36 | + UserCheck.verify(service.creator,current_token.user.username) | ||
| 28 | 37 | ||
| 29 | service_update = {"update_time":this_time} | 38 | service_update = {"update_time":this_time} |
| 30 | map_service_update = {} | 39 | map_service_update = {} |
| @@ -35,7 +44,20 @@ class Api(ApiTemplate): | @@ -35,7 +44,20 @@ class Api(ApiTemplate): | ||
| 35 | if key in ["name","tile","project","capabilities"]: | 44 | if key in ["name","tile","project","capabilities"]: |
| 36 | map_service_update[key] = self.para.get(key) | 45 | map_service_update[key] = self.para.get(key) |
| 37 | 46 | ||
| 38 | - | 47 | + para = {"name":self.para.get("name"), |
| 48 | + "title":self.para.get("title"), | ||
| 49 | + "type":"mapserver", | ||
| 50 | + "capabilities":2, | ||
| 51 | + "project":self.para.get("project")} | ||
| 52 | + | ||
| 53 | + map_service_register_url = "{}/dmap/api/manager/regservice".format(configure.vector_engine) | ||
| 54 | + resp: requests.Response = requests.post(map_service_register_url,data=json.dumps(para), | ||
| 55 | + headers={'Content-Type':'application/json'},timeout=3 | ||
| 56 | + ) | ||
| 57 | + resp.encoding="utf-8" | ||
| 58 | + resp_json = resp.json() | ||
| 59 | + if not resp_json["status"]=="1": | ||
| 60 | + raise Exception("调用矢量服务的修改服务接口失败!") | ||
| 39 | 61 | ||
| 40 | # 修改功能 | 62 | # 修改功能 |
| 41 | if functions: | 63 | if functions: |
| @@ -8,7 +8,9 @@ from app.models import db | @@ -8,7 +8,9 @@ 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 TileService | 9 | from app.modules.service.models import TileService |
| 10 | from app.modules.service.models import MapService | 10 | from app.modules.service.models import MapService |
| 11 | -import requests | 11 | +from authlib.integrations.flask_oauth2 import current_token |
| 12 | +from app.util.component.UserCheck import UserCheck | ||
| 13 | + | ||
| 12 | class Api(ApiTemplate): | 14 | class Api(ApiTemplate): |
| 13 | 15 | ||
| 14 | api_name = "服务删除" | 16 | api_name = "服务删除" |
| @@ -24,10 +26,12 @@ class Api(ApiTemplate): | @@ -24,10 +26,12 @@ class Api(ApiTemplate): | ||
| 24 | 26 | ||
| 25 | #删除本地服务 | 27 | #删除本地服务 |
| 26 | if s_type in ["切片服务","地图服务"]: | 28 | if s_type in ["切片服务","地图服务"]: |
| 27 | - service = Service.query.filter_by(guid=guid).one_or_none() | ||
| 28 | - | 29 | + service:Service = Service.query.filter_by(guid=guid).one_or_none() |
| 29 | if service: | 30 | if service: |
| 30 | 31 | ||
| 32 | + # 验证权限 | ||
| 33 | + UserCheck.verify(service.creator, current_token.user.username) | ||
| 34 | + | ||
| 31 | try: | 35 | try: |
| 32 | if service.type.__eq__("切片服务"): | 36 | if service.type.__eq__("切片服务"): |
| 33 | #调用接口 | 37 | #调用接口 |
| @@ -37,6 +41,7 @@ class Api(ApiTemplate): | @@ -37,6 +41,7 @@ class Api(ApiTemplate): | ||
| 37 | if service.type.__eq__("地图服务"): | 41 | if service.type.__eq__("地图服务"): |
| 38 | map_service = MapService.query.filter_by(service_guid=guid).one_or_none() | 42 | map_service = MapService.query.filter_by(service_guid=guid).one_or_none() |
| 39 | db.session.delete(map_service) | 43 | db.session.delete(map_service) |
| 44 | + | ||
| 40 | service_functions = service.relate_service_functions.all() | 45 | service_functions = service.relate_service_functions.all() |
| 41 | for function in service_functions: | 46 | for function in service_functions: |
| 42 | db.session.delete(function) | 47 | db.session.delete(function) |
| @@ -7,6 +7,7 @@ from app.util.component.ApiTemplate import ApiTemplate | @@ -7,6 +7,7 @@ from app.util.component.ApiTemplate import ApiTemplate | ||
| 7 | from app.modules.service.models import Service | 7 | from app.modules.service.models import Service |
| 8 | import requests | 8 | import requests |
| 9 | 9 | ||
| 10 | + | ||
| 10 | class Api(ApiTemplate): | 11 | class Api(ApiTemplate): |
| 11 | api_name = "修改服务" | 12 | api_name = "修改服务" |
| 12 | def process(self): | 13 | def process(self): |
| @@ -17,14 +17,14 @@ class DataManager(BlueprintApi): | @@ -17,14 +17,14 @@ class DataManager(BlueprintApi): | ||
| 17 | 17 | ||
| 18 | service_type = ["切片服务"] | 18 | service_type = ["切片服务"] |
| 19 | 19 | ||
| 20 | - @staticmethod | ||
| 21 | - @bp.route('/UploadOverview', methods=['POST']) | ||
| 22 | - @swag_from(upload_oview.Api.api_doc) | ||
| 23 | - def api_upload_oview(): | ||
| 24 | - """ | ||
| 25 | - 上传缩略图 | ||
| 26 | - """ | ||
| 27 | - return upload_oview.Api().result | 20 | + # @staticmethod |
| 21 | + # @bp.route('/UploadOverview', methods=['POST']) | ||
| 22 | + # @swag_from(upload_oview.Api.api_doc) | ||
| 23 | + # def api_upload_oview(): | ||
| 24 | + # """ | ||
| 25 | + # 上传缩略图 | ||
| 26 | + # """ | ||
| 27 | + # return upload_oview.Api().result | ||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | @staticmethod | 30 | @staticmethod |
| @@ -14,6 +14,9 @@ from .util.ProjectFile import ProjectFile | @@ -14,6 +14,9 @@ from .util.ProjectFile import ProjectFile | ||
| 14 | import json | 14 | import json |
| 15 | from requests import Response | 15 | from requests import Response |
| 16 | import configure | 16 | import configure |
| 17 | +from authlib.integrations.flask_oauth2 import current_token | ||
| 18 | +from app.util.component.UserCheck import UserCheck | ||
| 19 | + | ||
| 17 | class Api(ApiTemplate): | 20 | class Api(ApiTemplate): |
| 18 | 21 | ||
| 19 | api_name = "修改切片服务" | 22 | api_name = "修改切片服务" |
| @@ -23,6 +26,11 @@ class Api(ApiTemplate): | @@ -23,6 +26,11 @@ class Api(ApiTemplate): | ||
| 23 | try: | 26 | try: |
| 24 | guid = self.para.get("guid") | 27 | guid = self.para.get("guid") |
| 25 | service = Service.query.filter_by(guid=guid) | 28 | service = Service.query.filter_by(guid=guid) |
| 29 | + if not service: | ||
| 30 | + raise Exception("服务不存在!") | ||
| 31 | + #验证权限 | ||
| 32 | + UserCheck.verify(service.creator,current_token.user.username) | ||
| 33 | + | ||
| 26 | this_time = datetime.datetime.now() | 34 | this_time = datetime.datetime.now() |
| 27 | 35 | ||
| 28 | service_update = {"update_time":this_time} | 36 | service_update = {"update_time":this_time} |
| @@ -27,7 +27,6 @@ class FileProcess: | @@ -27,7 +27,6 @@ class FileProcess: | ||
| 27 | StructurePrint().print(store_file) | 27 | StructurePrint().print(store_file) |
| 28 | 28 | ||
| 29 | file.save(store_file) | 29 | file.save(store_file) |
| 30 | - | ||
| 31 | if platform.system().lower() == 'linux': | 30 | if platform.system().lower() == 'linux': |
| 32 | #设置为444权限 | 31 | #设置为444权限 |
| 33 | os.chmod(store_file, stat.S_IRUSR + stat.S_IRGRP + stat.S_IROTH) | 32 | os.chmod(store_file, stat.S_IRUSR + stat.S_IRGRP + stat.S_IROTH) |
app/util/component/UserCheck.py
0 → 100644
| 1 | +# coding=utf-8 | ||
| 2 | +#author: 4N | ||
| 3 | +#createtime: 2022/1/14 | ||
| 4 | +#email: nheweijun@sina.com | ||
| 5 | + | ||
| 6 | +import configure | ||
| 7 | +class UserCheck: | ||
| 8 | + | ||
| 9 | + @classmethod | ||
| 10 | + def verify(cls,owner,operator): | ||
| 11 | + if configure.PermissionActive: | ||
| 12 | + if configure.PermissionActive and operator != "admin" and owner !=operator: | ||
| 13 | + raise Exception("缺乏权限!") |
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | import zipfile | 6 | import zipfile |
| 7 | import os | 7 | import os |
| 8 | import uuid | 8 | import uuid |
| 9 | - | 9 | +import platform,stat |
| 10 | class ZipUtil: | 10 | class ZipUtil: |
| 11 | 11 | ||
| 12 | @classmethod | 12 | @classmethod |
| @@ -69,7 +69,6 @@ class ZipUtil: | @@ -69,7 +69,6 @@ class ZipUtil: | ||
| 69 | 69 | ||
| 70 | os.chdir(os.path.dirname(store_path)) | 70 | os.chdir(os.path.dirname(store_path)) |
| 71 | zip_file.close() | 71 | zip_file.close() |
| 72 | - | ||
| 73 | return store_path | 72 | return store_path |
| 74 | 73 | ||
| 75 | 74 |
| @@ -3,30 +3,22 @@ import logging | @@ -3,30 +3,22 @@ import logging | ||
| 3 | # 程序部署ip:host | 3 | # 程序部署ip:host |
| 4 | deploy_ip_host = "172.26.40.105:8840" | 4 | deploy_ip_host = "172.26.40.105:8840" |
| 5 | # 系统数据库 | 5 | # 系统数据库 |
| 6 | - | ||
| 7 | - | ||
| 8 | SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dmap_manager" | 6 | SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dmap_manager" |
| 9 | 7 | ||
| 10 | - | ||
| 11 | # 指定精华表所在位置(必须为空间库),设置为None则存放在各自的实体库中 | 8 | # 指定精华表所在位置(必须为空间库),设置为None则存放在各自的实体库中 |
| 12 | #VACUATE_DB_URI = None | 9 | #VACUATE_DB_URI = None |
| 13 | VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI | 10 | VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI |
| 14 | 11 | ||
| 15 | -zookeeper = "172.26.99.168:2181" | ||
| 16 | - | ||
| 17 | - | ||
| 18 | #切片引擎 | 12 | #切片引擎 |
| 19 | tile_engine = "http://172.26.99.160:6060" | 13 | tile_engine = "http://172.26.99.160:6060" |
| 20 | #矢量引擎 | 14 | #矢量引擎 |
| 21 | vector_engine = "http://172.26.99.160:6060" | 15 | vector_engine = "http://172.26.99.160:6060" |
| 22 | 16 | ||
| 23 | - | ||
| 24 | # 固定配置不需要修改 | 17 | # 固定配置不需要修改 |
| 25 | -swagger_configure = {"title": "DMapManager"} | ||
| 26 | entry_data_thread = 3 | 18 | entry_data_thread = 3 |
| 27 | -scan_module = ["app.modules"] # API所在的模块 | ||
| 28 | SECRET_KEY = b'_5#y2L"F4Q8z\n\xec]/' | 19 | SECRET_KEY = b'_5#y2L"F4Q8z\n\xec]/' |
| 29 | # 权限 | 20 | # 权限 |
| 21 | +PermissionActive = False | ||
| 30 | UserPermission = ['admin'] | 22 | UserPermission = ['admin'] |
| 31 | MonitorPermission = ['admin'] | 23 | MonitorPermission = ['admin'] |
| 32 | DataPermission = ['admin', 'dataman'] | 24 | DataPermission = ['admin', 'dataman'] |
| @@ -10,8 +10,8 @@ import threading | @@ -10,8 +10,8 @@ import threading | ||
| 10 | 10 | ||
| 11 | import time | 11 | import time |
| 12 | 12 | ||
| 13 | - | ||
| 14 | - | 13 | +from osgeo import ogr |
| 14 | +from osgeo.ogr import * | ||
| 15 | 15 | ||
| 16 | # session:Session = get_db_session("postgresql://postgres:chinadci@172.26.99.168:5432/postgres") | 16 | # session:Session = get_db_session("postgresql://postgres:chinadci@172.26.99.168:5432/postgres") |
| 17 | # bbox="113.2470703125 22.840576171875,113.258056640625 22.8515625" | 17 | # bbox="113.2470703125 22.840576171875,113.258056640625 22.8515625" |
| @@ -69,13 +69,41 @@ if __name__ == '__main__': | @@ -69,13 +69,41 @@ if __name__ == '__main__': | ||
| 69 | # print(zoo.connected) | 69 | # print(zoo.connected) |
| 70 | # print(zoo.get_children("/rpc")) | 70 | # print(zoo.get_children("/rpc")) |
| 71 | 71 | ||
| 72 | - if __name__ == '__main__': | ||
| 73 | - import re | 72 | + fn = "PG: user=postgres password=chinadci host=172.26.99.160 port=5432 dbname=ceshi " |
| 73 | + driver = ogr.GetDriverByName("PostgreSQL") | ||
| 74 | + if driver is None: | ||
| 75 | + raise Exception("打开PostgreSQL驱动失败,可能是当前GDAL未支持PostgreSQL驱动!") | ||
| 76 | + ds = driver.Open(fn, 1) | ||
| 74 | 77 | ||
| 75 | - line = "广州市区" | ||
| 76 | - pattern = r"的区" | ||
| 77 | - matchObj = re.search(pattern, line) | ||
| 78 | - if matchObj: | ||
| 79 | - print("y") | ||
| 80 | - else: | ||
| 81 | - print("n") | ||
| 78 | + layer:Layer = ds.GetLayerByName("shiyqzd_500_bdc") | ||
| 79 | + | ||
| 80 | + | ||
| 81 | + driver2 = ogr.GetDriverByName("ESRI Shapefile") | ||
| 82 | + data_source: DataSource = driver2.CreateDataSource("H://t3.shp") | ||
| 83 | + | ||
| 84 | + | ||
| 85 | + fid = layer.GetFIDColumn() | ||
| 86 | + pg_layer: Layer = data_source.CreateLayer("t", layer.GetSpatialRef(), layer.GetGeomType(),["ENCODING=GBK"]) | ||
| 87 | + | ||
| 88 | + #可能有问题,不支持binary | ||
| 89 | + schema = [sche for sche in layer.schema if not sche.name.__eq__(fid)] | ||
| 90 | + | ||
| 91 | + schema_chage = [] | ||
| 92 | + for sche in schema: | ||
| 93 | + ss :FieldDefn = sche | ||
| 94 | + if ss.GetType() == ogr.OFTBinary : | ||
| 95 | + print(ss.name) | ||
| 96 | + ss.SetType(ogr.OFTInteger) | ||
| 97 | + schema_chage.append(ss) | ||
| 98 | + | ||
| 99 | + pg_layer.CreateFields(schema_chage) | ||
| 100 | + | ||
| 101 | + | ||
| 102 | + count =0 | ||
| 103 | + for feature in layer: | ||
| 104 | + pg_layer.CreateFeature(feature) | ||
| 105 | + count+=1 | ||
| 106 | + if count==1000: | ||
| 107 | + break | ||
| 108 | + | ||
| 109 | + data_source.Destroy() |
请
注册
或
登录
后发表评论