正在显示
32 个修改的文件
包含
272 行增加
和
162 行删除
| ... | ... | @@ -72,7 +72,7 @@ def create_app(): |
| 72 | 72 | |
| 73 | 73 | # swagger设置 |
| 74 | 74 | swagger_config = Swagger.DEFAULT_CONFIG |
| 75 | - swagger_config.update(configure.swagger_configure) | |
| 75 | + swagger_config.update({"title": "DMapManager"}) | |
| 76 | 76 | Swagger(app, config=swagger_config) |
| 77 | 77 | |
| 78 | 78 | # 创建数据库 |
| ... | ... | @@ -93,7 +93,7 @@ def create_app(): |
| 93 | 93 | config_oauth(app) |
| 94 | 94 | |
| 95 | 95 | # 注册blueprint,查找BlueprintApi的子类 |
| 96 | - for scan in configure.scan_module: | |
| 96 | + for scan in ["app.modules"]: | |
| 97 | 97 | for api in find_class(scan, BlueprintApi): |
| 98 | 98 | app.register_blueprint(api.bp) |
| 99 | 99 | ... | ... |
| ... | ... | @@ -3,7 +3,7 @@ from authlib.integrations.flask_oauth2 import current_token |
| 3 | 3 | from flask import abort |
| 4 | 4 | from app.modules.auth.oauth2 import require_oauth |
| 5 | 5 | from flask import request |
| 6 | - | |
| 6 | +import configure | |
| 7 | 7 | # 认证装饰器 |
| 8 | 8 | |
| 9 | 9 | |
| ... | ... | @@ -17,25 +17,28 @@ class auth_decorator(object): |
| 17 | 17 | |
| 18 | 18 | @wraps(func) |
| 19 | 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 | 38 | else: |
| 35 | - # 无permission,不校验 | |
| 36 | - return func(*args, **kwargs) | |
| 39 | + abort(401) # 无token,401 | |
| 37 | 40 | else: |
| 38 | - abort(401) # 无token,401 | |
| 41 | + return func(*args, **kwargs) | |
| 39 | 42 | |
| 40 | 43 | @require_oauth(self.scope) |
| 41 | 44 | def validate_token(): | ... | ... |
| ... | ... | @@ -3,7 +3,7 @@ from authlib.integrations.flask_oauth2 import current_token |
| 3 | 3 | from flask import abort |
| 4 | 4 | from app.modules.auth.oauth2 import require_oauth |
| 5 | 5 | from flask import request |
| 6 | - | |
| 6 | +import configure | |
| 7 | 7 | # 认证装饰器 |
| 8 | 8 | |
| 9 | 9 | |
| ... | ... | @@ -14,16 +14,19 @@ class token_decorator(object): |
| 14 | 14 | def __call__(self, func): |
| 15 | 15 | @wraps(func) |
| 16 | 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 | 28 | else: |
| 26 | - abort(401) # 无token,401 | |
| 29 | + return func(*args, **kwargs) | |
| 27 | 30 | |
| 28 | 31 | @require_oauth(self.scope) |
| 29 | 32 | def validate_token(): | ... | ... |
| ... | ... | @@ -6,13 +6,12 @@ from app.util import BlueprintApi |
| 6 | 6 | from flask import Blueprint, render_template, redirect, request, session, jsonify |
| 7 | 7 | from sqlalchemy import and_ |
| 8 | 8 | from .models import * |
| 9 | -from .oauth2 import authorization, generate_user_info | |
| 9 | +from .oauth2 import authorization, generate_user_info,require_oauth | |
| 10 | 10 | from authlib.oauth2 import OAuth2Error |
| 11 | 11 | from authlib.integrations.flask_oauth2 import current_token |
| 12 | 12 | from . import user_create, client_create, client_query, user_query, user_update, user_delete |
| 13 | 13 | import configure |
| 14 | 14 | from app.decorators.auth_decorator import auth_decorator |
| 15 | -from app.decorators.token_decorator import token_decorator | |
| 16 | 15 | |
| 17 | 16 | |
| 18 | 17 | def current_user(): |
| ... | ... | @@ -82,7 +81,7 @@ class DataManager(BlueprintApi): |
| 82 | 81 | |
| 83 | 82 | @staticmethod |
| 84 | 83 | @bp.route("/userinfo") |
| 85 | - @token_decorator("profile") | |
| 84 | + @require_oauth("profile") | |
| 86 | 85 | def api_me(): |
| 87 | 86 | try: |
| 88 | 87 | return jsonify(generate_user_info(current_token.user, current_token.scope)) | ... | ... |
| ... | ... | @@ -5,15 +5,13 @@ |
| 5 | 5 | |
| 6 | 6 | |
| 7 | 7 | from ..models import Database,db,Table,TableVacuate,DES |
| 8 | - | |
| 9 | - | |
| 10 | - | |
| 11 | 8 | from app.util.component.ApiTemplate import ApiTemplate |
| 12 | 9 | from app.util.component.PGUtil import PGUtil |
| 13 | 10 | import configure |
| 14 | 11 | from osgeo.ogr import DataSource |
| 15 | 12 | from flask import current_app |
| 16 | 13 | from authlib.integrations.flask_oauth2 import current_token |
| 14 | +from app.util.component.UserCheck import UserCheck | |
| 17 | 15 | |
| 18 | 16 | |
| 19 | 17 | class Api(ApiTemplate): |
| ... | ... | @@ -24,9 +22,8 @@ class Api(ApiTemplate): |
| 24 | 22 | try: |
| 25 | 23 | |
| 26 | 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 | 27 | if configure.VACUATE_DB_URI: |
| 31 | 28 | va_ds: DataSource = PGUtil.open_pg_data_source(1, configure.VACUATE_DB_URI) |
| 32 | 29 | else: | ... | ... |
| ... | ... | @@ -5,14 +5,12 @@ |
| 5 | 5 | |
| 6 | 6 | from ..models import Database,db,DES |
| 7 | 7 | from contextlib import closing |
| 8 | - | |
| 9 | 8 | from sqlalchemy import create_engine |
| 10 | - | |
| 11 | 9 | import datetime |
| 12 | 10 | from . import database_alias_check |
| 13 | - | |
| 14 | 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 | 14 | from app.util.component.PGUtil import PGUtil |
| 17 | 15 | class Api(ApiTemplate): |
| 18 | 16 | api_name = "修改数据库" |
| ... | ... | @@ -28,8 +26,8 @@ class Api(ApiTemplate): |
| 28 | 26 | database = Database.query.filter_by(guid=guid) |
| 29 | 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 | 32 | update_dict={} |
| 35 | 33 | |
| ... | ... | @@ -40,7 +38,6 @@ class Api(ApiTemplate): |
| 40 | 38 | res["msg"] = "请填写参数!" |
| 41 | 39 | return res |
| 42 | 40 | |
| 43 | - | |
| 44 | 41 | if alias: |
| 45 | 42 | # 检测一波别名 |
| 46 | 43 | check_alias = database_alias_check.Api().result | ... | ... |
| ... | ... | @@ -74,7 +74,7 @@ class DataManager(BlueprintApi): |
| 74 | 74 | @staticmethod |
| 75 | 75 | @bp.route('/GetMeta', methods=['POST']) |
| 76 | 76 | @swag_from(get_meta.Api.api_doc) |
| 77 | - @auth_decorator(configure.DataPermission) | |
| 77 | + # @auth_decorator(configure.DataPermission) | |
| 78 | 78 | def get_meta(): |
| 79 | 79 | """ |
| 80 | 80 | 数据Meta | ... | ... |
| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | from ..models import * |
| 8 | 8 | |
| 9 | 9 | import traceback |
| 10 | - | |
| 10 | +from .util.SchemaAdapter import SchemaAdapter | |
| 11 | 11 | from osgeo.ogr import DataSource,Layer,FeatureDefn,FieldDefn,Feature |
| 12 | 12 | from osgeo import gdal,ogr |
| 13 | 13 | import os |
| ... | ... | @@ -51,6 +51,15 @@ class Api(ApiTemplate): |
| 51 | 51 | db.session.commit() |
| 52 | 52 | |
| 53 | 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 | 63 | res["result"] = True |
| 55 | 64 | |
| 56 | 65 | except Exception as e: |
| ... | ... | @@ -64,11 +73,11 @@ class Api(ApiTemplate): |
| 64 | 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 | 82 | try: |
| 74 | 83 | |
| ... | ... | @@ -133,10 +142,14 @@ class Api(ApiTemplate): |
| 133 | 142 | |
| 134 | 143 | |
| 135 | 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 | 147 | schema = [sche for sche in layer.schema if not sche.name.__eq__(fid)] |
| 148 | + # 忽略binary字段 | |
| 149 | + SchemaAdapter.neglect_binary(schema) | |
| 138 | 150 | |
| 139 | 151 | pg_layer.CreateFields(schema) |
| 152 | + | |
| 140 | 153 | layer.ResetReading() |
| 141 | 154 | |
| 142 | 155 | count = 0 |
| ... | ... | @@ -147,6 +160,11 @@ class Api(ApiTemplate): |
| 147 | 160 | StructurePrint().print("{}图层已下载{}个对象".format(table_name, count)) |
| 148 | 161 | |
| 149 | 162 | data_source.Destroy() |
| 163 | + | |
| 164 | + #增加cpg文件 | |
| 165 | + with open(dirpath + "/{}.cpg".format(table_name),"w") as f: | |
| 166 | + f.write("GBK") | |
| 167 | + | |
| 150 | 168 | ZipUtil.create_zip(os.path.join(parent, "file_tmp", table_name+"_"+uuid_) + ".zip", [dirpath]) |
| 151 | 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 | 226 | return data |
| 209 | 227 | |
| 210 | 228 | |
| 229 | + def msg(self): | |
| 230 | + pass | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 211 | 234 | api_doc={ |
| 212 | 235 | "tags":["IO接口"], |
| 213 | 236 | "description":"下载数据", |
| ... | ... | @@ -215,10 +238,10 @@ class Api(ApiTemplate): |
| 215 | 238 | {"name": "table_name", |
| 216 | 239 | "in": "formData", |
| 217 | 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 | 245 | {"name": "download_type", |
| 223 | 246 | "in": "formData", |
| 224 | 247 | "type": "string", | ... | ... |
| ... | ... | @@ -13,7 +13,7 @@ import json |
| 13 | 13 | from app.util.component.ApiTemplate import ApiTemplate |
| 14 | 14 | from .get_meta import Api as MetaApi |
| 15 | 15 | from threading import Thread |
| 16 | -from ..util.EntryDataVacuate import EntryDataVacuate | |
| 16 | +from .util.EntryDataVacuate import EntryDataVacuate | |
| 17 | 17 | |
| 18 | 18 | class Api(ApiTemplate): |
| 19 | 19 | ... | ... |
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 | |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -4,11 +4,10 @@ |
| 4 | 4 | |
| 5 | 5 | from ..models import Columns |
| 6 | 6 | import datetime |
| 7 | - | |
| 8 | - | |
| 9 | 7 | from app.models import db |
| 10 | 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 | 12 | class Api(ApiTemplate): |
| 14 | 13 | api_name = "修改属性" |
| ... | ... | @@ -24,8 +23,8 @@ class Api(ApiTemplate): |
| 24 | 23 | if not column: |
| 25 | 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 | 29 | try: |
| 31 | 30 | if self.para.get("column_alias"): | ... | ... |
| ... | ... | @@ -2,21 +2,16 @@ |
| 2 | 2 | #createtime: 2021/1/27 |
| 3 | 3 | #email: nheweijun@sina.com |
| 4 | 4 | |
| 5 | - | |
| 6 | - | |
| 7 | -import traceback | |
| 8 | 5 | from ..models import Table,Database,DES |
| 9 | - | |
| 10 | - | |
| 11 | 6 | from osgeo.ogr import DataSource |
| 12 | - | |
| 13 | - | |
| 14 | 7 | from app.models import db |
| 15 | 8 | from app.util.component.ApiTemplate import ApiTemplate |
| 16 | - | |
| 17 | 9 | from app.util.component.PGUtil import PGUtil |
| 18 | 10 | import configure |
| 19 | 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 | 15 | class Api(ApiTemplate): |
| 21 | 16 | api_name = "删除表" |
| 22 | 17 | def process(self): |
| ... | ... | @@ -37,11 +32,12 @@ class Api(ApiTemplate): |
| 37 | 32 | |
| 38 | 33 | |
| 39 | 34 | table = table.one_or_none() |
| 40 | - | |
| 41 | - | |
| 42 | - | |
| 43 | 35 | # 删除真实数据 |
| 44 | 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 | 41 | if not database: |
| 46 | 42 | res["result"]=False |
| 47 | 43 | res["msg"]= "数据库不存在!" | ... | ... |
| ... | ... | @@ -2,16 +2,14 @@ |
| 2 | 2 | #createtime: 2021/1/27 |
| 3 | 3 | #email: nheweijun@sina.com |
| 4 | 4 | |
| 5 | - | |
| 6 | - | |
| 7 | 5 | from ..models import * |
| 8 | - | |
| 9 | 6 | import json |
| 10 | - | |
| 11 | 7 | from sqlalchemy.orm import Session |
| 12 | 8 | import datetime |
| 13 | 9 | from app.util.component.ApiTemplate import ApiTemplate |
| 14 | 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 | 14 | class Api(ApiTemplate): |
| 17 | 15 | api_name = "修改表信息" |
| ... | ... | @@ -34,8 +32,8 @@ class Api(ApiTemplate): |
| 34 | 32 | res["msg"]= "数据不存在!" |
| 35 | 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 | 38 | if self.para.__contains__("catalog_guid"): |
| 41 | 39 | if catalog_guid is None: | ... | ... |
| ... | ... | @@ -2,16 +2,11 @@ |
| 2 | 2 | #createtime: 2021/1/27 |
| 3 | 3 | #email: nheweijun@sina.com |
| 4 | 4 | |
| 5 | - | |
| 6 | - | |
| 7 | 5 | import traceback |
| 8 | 6 | from ..models import Table,Database,Columns,db,TableVacuate,Task,Process,DES |
| 9 | - | |
| 10 | 7 | from osgeo.ogr import DataSource,FeatureDefn,FieldDefn,Layer |
| 11 | - | |
| 12 | 8 | import datetime |
| 13 | 9 | import uuid |
| 14 | - | |
| 15 | 10 | from sqlalchemy.orm import Session |
| 16 | 11 | from app.util.component.SQLUtil import SQLUtil |
| 17 | 12 | from app.util.component.PGUtil import PGUtil |
| ... | ... | @@ -22,7 +17,8 @@ from app.util.component.TaskController import TaskController |
| 22 | 17 | from app.util.component.TaskWriter import TaskWriter |
| 23 | 18 | import multiprocessing |
| 24 | 19 | import configure |
| 25 | - | |
| 20 | +from authlib.integrations.flask_oauth2 import current_token | |
| 21 | +from app.util.component.UserCheck import UserCheck | |
| 26 | 22 | class Api(ApiTemplate): |
| 27 | 23 | api_name = "数据刷新" |
| 28 | 24 | def process(self): |
| ... | ... | @@ -32,6 +28,9 @@ class Api(ApiTemplate): |
| 32 | 28 | database_guid = self.para.get("database_guid") |
| 33 | 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 | 34 | if database.creator != "": |
| 36 | 35 | raise Exception("缺乏权限!") |
| 37 | 36 | ... | ... |
| ... | ... | @@ -21,10 +21,10 @@ from app.util.component.TaskController import TaskController |
| 21 | 21 | from app.util.component.TaskWriter import TaskWriter |
| 22 | 22 | from osgeo.ogr import DataSource,Layer,Geometry |
| 23 | 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 | 29 | class Api(ApiTemplate): |
| 30 | 30 | |
| ... | ... | @@ -42,8 +42,8 @@ class Api(ApiTemplate): |
| 42 | 42 | if not table: |
| 43 | 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 | 48 | pg_ds :DataSource= PGUtil.open_pg_data_source(0,DES.decode(table.relate_database.sqlalchemy_uri)) |
| 49 | 49 | layer = pg_ds.GetLayerByName(table.name) | ... | ... |
| ... | ... | @@ -14,7 +14,8 @@ import uuid |
| 14 | 14 | import configure |
| 15 | 15 | from osgeo.ogr import DataSource,Layer,Geometry |
| 16 | 16 | from osgeo import ogr |
| 17 | - | |
| 17 | +from authlib.integrations.flask_oauth2 import current_token | |
| 18 | +from app.util.component.UserCheck import UserCheck | |
| 18 | 19 | from app.util.component.VacuateConf import VacuateConf |
| 19 | 20 | from app.util.component.TaskController import TaskController |
| 20 | 21 | from app.util.component.TaskWriter import TaskWriter |
| ... | ... | @@ -40,8 +41,8 @@ class Api(ApiTemplate): |
| 40 | 41 | if not table: |
| 41 | 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 | 4 | #email: nheweijun@sina.com |
| 5 | 5 | |
| 6 | 6 | from ..models import db,Task |
| 7 | - | |
| 8 | - | |
| 9 | 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 | 11 | class Api(ApiTemplate): |
| 13 | 12 | api_name = "删除任务" |
| ... | ... | @@ -18,29 +17,19 @@ class Api(ApiTemplate): |
| 18 | 17 | res = {} |
| 19 | 18 | try: |
| 20 | 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 | 33 | except Exception as e: |
| 45 | 34 | db.session.rollback() |
| 46 | 35 | raise e |
| ... | ... | @@ -53,12 +42,6 @@ class Api(ApiTemplate): |
| 53 | 42 | {"name": "task_guid", |
| 54 | 43 | "in": "formData", |
| 55 | 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 | 47 | "responses": { | ... | ... |
| ... | ... | @@ -13,6 +13,8 @@ import platform |
| 13 | 13 | import json |
| 14 | 14 | import datetime |
| 15 | 15 | import uuid |
| 16 | +from authlib.integrations.flask_oauth2 import current_token | |
| 17 | +from app.util.component.UserCheck import UserCheck | |
| 16 | 18 | class Api(ApiTemplate): |
| 17 | 19 | api_name = "停止任务" |
| 18 | 20 | def para_check(self): |
| ... | ... | @@ -23,6 +25,12 @@ class Api(ApiTemplate): |
| 23 | 25 | try: |
| 24 | 26 | task_guid = self.para.get("task_guid") |
| 25 | 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 | 34 | pid = task.task_pid |
| 27 | 35 | try: |
| 28 | 36 | if platform.system().lower().__contains__("windows"): | ... | ... |
| ... | ... | @@ -19,6 +19,7 @@ class Api(ApiTemplate): |
| 19 | 19 | catalogs = ServiceCatalog.query.all() |
| 20 | 20 | res["data"]=[] |
| 21 | 21 | |
| 22 | + | |
| 22 | 23 | # 获取全部影像服务 |
| 23 | 24 | image_engines = ServiceEngine.query.filter_by(type="ImageServer").all() |
| 24 | 25 | image_services = [] |
| ... | ... | @@ -30,6 +31,8 @@ class Api(ApiTemplate): |
| 30 | 31 | else: |
| 31 | 32 | image_services.extend(response.json()["data"]["list"]) |
| 32 | 33 | |
| 34 | + | |
| 35 | + | |
| 33 | 36 | for cata in catalogs: |
| 34 | 37 | catalog_guids = [c.guid for c in ServiceCatalog.query.filter(ServiceCatalog.path.like("%" + cata.guid + "%")).all()] |
| 35 | 38 | service_count = Service.query.filter(Service.catalog_guid.in_(catalog_guids)).count() |
| ... | ... | @@ -47,7 +50,7 @@ class Api(ApiTemplate): |
| 47 | 50 | res["data"].append(cata_json) |
| 48 | 51 | |
| 49 | 52 | res["result"] = True |
| 50 | - | |
| 53 | + res["service_count"] = len(image_services) + Service.query.count() | |
| 51 | 54 | except Exception as e: |
| 52 | 55 | raise e |
| 53 | 56 | return res | ... | ... |
| ... | ... | @@ -6,6 +6,8 @@ |
| 6 | 6 | |
| 7 | 7 | from app.util.component.ApiTemplate import ApiTemplate |
| 8 | 8 | import requests |
| 9 | +from authlib.integrations.flask_oauth2 import current_token | |
| 10 | +from app.util.component.UserCheck import UserCheck | |
| 9 | 11 | |
| 10 | 12 | class Api(ApiTemplate): |
| 11 | 13 | |
| ... | ... | @@ -15,6 +17,14 @@ class Api(ApiTemplate): |
| 15 | 17 | # 返回结果 |
| 16 | 18 | res = {} |
| 17 | 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 | 28 | url = "{}/API/Service/Delete".format(self.para.get("url")) |
| 19 | 29 | response:requests.Response = requests.post(url,data=self.para) |
| 20 | 30 | if not response.json().get("result"): | ... | ... |
| ... | ... | @@ -6,6 +6,8 @@ |
| 6 | 6 | |
| 7 | 7 | from app.util.component.ApiTemplate import ApiTemplate |
| 8 | 8 | import requests |
| 9 | +from authlib.integrations.flask_oauth2 import current_token | |
| 10 | +from app.util.component.UserCheck import UserCheck | |
| 9 | 11 | |
| 10 | 12 | class Api(ApiTemplate): |
| 11 | 13 | |
| ... | ... | @@ -15,6 +17,14 @@ class Api(ApiTemplate): |
| 15 | 17 | # 返回结果 |
| 16 | 18 | res = {} |
| 17 | 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 | 28 | url = "{}/API/Service/Edit".format(self.para.get("url")) |
| 19 | 29 | response:requests.Response = requests.post(url,data=self.para) |
| 20 | 30 | if not response.json().get("result"): | ... | ... |
| ... | ... | @@ -7,9 +7,13 @@ |
| 7 | 7 | from app.util.component.ApiTemplate import ApiTemplate |
| 8 | 8 | import uuid |
| 9 | 9 | from ..models import Service,MapService,db,ServiceFunction |
| 10 | - | |
| 11 | - | |
| 10 | +import requests | |
| 11 | +import configure | |
| 12 | +import json | |
| 12 | 13 | import datetime |
| 14 | +from authlib.integrations.flask_oauth2 import current_token | |
| 15 | +from app.util.component.UserCheck import UserCheck | |
| 16 | + | |
| 13 | 17 | class Api(ApiTemplate): |
| 14 | 18 | |
| 15 | 19 | api_name = "修改MapService服务" |
| ... | ... | @@ -22,9 +26,14 @@ class Api(ApiTemplate): |
| 22 | 26 | try: |
| 23 | 27 | guid = self.para.get("guid") |
| 24 | 28 | functions = self.para.get("functions") |
| 25 | - service = Service.query.filter_by(guid=guid) | |
| 29 | + service :Service = Service.query.filter_by(guid=guid) | |
| 26 | 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 | 38 | service_update = {"update_time":this_time} |
| 30 | 39 | map_service_update = {} |
| ... | ... | @@ -35,7 +44,20 @@ class Api(ApiTemplate): |
| 35 | 44 | if key in ["name","tile","project","capabilities"]: |
| 36 | 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 | 63 | if functions: | ... | ... |
| ... | ... | @@ -8,7 +8,9 @@ from app.models import db |
| 8 | 8 | from app.modules.service.models import Service |
| 9 | 9 | from app.modules.service.models import TileService |
| 10 | 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 | 14 | class Api(ApiTemplate): |
| 13 | 15 | |
| 14 | 16 | api_name = "服务删除" |
| ... | ... | @@ -24,10 +26,12 @@ class Api(ApiTemplate): |
| 24 | 26 | |
| 25 | 27 | #删除本地服务 |
| 26 | 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 | 30 | if service: |
| 30 | 31 | |
| 32 | + # 验证权限 | |
| 33 | + UserCheck.verify(service.creator, current_token.user.username) | |
| 34 | + | |
| 31 | 35 | try: |
| 32 | 36 | if service.type.__eq__("切片服务"): |
| 33 | 37 | #调用接口 |
| ... | ... | @@ -37,6 +41,7 @@ class Api(ApiTemplate): |
| 37 | 41 | if service.type.__eq__("地图服务"): |
| 38 | 42 | map_service = MapService.query.filter_by(service_guid=guid).one_or_none() |
| 39 | 43 | db.session.delete(map_service) |
| 44 | + | |
| 40 | 45 | service_functions = service.relate_service_functions.all() |
| 41 | 46 | for function in service_functions: |
| 42 | 47 | db.session.delete(function) | ... | ... |
| ... | ... | @@ -17,14 +17,14 @@ class DataManager(BlueprintApi): |
| 17 | 17 | |
| 18 | 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 | 30 | @staticmethod | ... | ... |
| ... | ... | @@ -14,6 +14,9 @@ from .util.ProjectFile import ProjectFile |
| 14 | 14 | import json |
| 15 | 15 | from requests import Response |
| 16 | 16 | import configure |
| 17 | +from authlib.integrations.flask_oauth2 import current_token | |
| 18 | +from app.util.component.UserCheck import UserCheck | |
| 19 | + | |
| 17 | 20 | class Api(ApiTemplate): |
| 18 | 21 | |
| 19 | 22 | api_name = "修改切片服务" |
| ... | ... | @@ -23,6 +26,11 @@ class Api(ApiTemplate): |
| 23 | 26 | try: |
| 24 | 27 | guid = self.para.get("guid") |
| 25 | 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 | 34 | this_time = datetime.datetime.now() |
| 27 | 35 | |
| 28 | 36 | service_update = {"update_time":this_time} | ... | ... |
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 | 6 | import zipfile |
| 7 | 7 | import os |
| 8 | 8 | import uuid |
| 9 | - | |
| 9 | +import platform,stat | |
| 10 | 10 | class ZipUtil: |
| 11 | 11 | |
| 12 | 12 | @classmethod |
| ... | ... | @@ -69,7 +69,6 @@ class ZipUtil: |
| 69 | 69 | |
| 70 | 70 | os.chdir(os.path.dirname(store_path)) |
| 71 | 71 | zip_file.close() |
| 72 | - | |
| 73 | 72 | return store_path |
| 74 | 73 | |
| 75 | 74 | ... | ... |
| ... | ... | @@ -3,30 +3,22 @@ import logging |
| 3 | 3 | # 程序部署ip:host |
| 4 | 4 | deploy_ip_host = "172.26.40.105:8840" |
| 5 | 5 | # 系统数据库 |
| 6 | - | |
| 7 | - | |
| 8 | 6 | SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dmap_manager" |
| 9 | 7 | |
| 10 | - | |
| 11 | 8 | # 指定精华表所在位置(必须为空间库),设置为None则存放在各自的实体库中 |
| 12 | 9 | #VACUATE_DB_URI = None |
| 13 | 10 | VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI |
| 14 | 11 | |
| 15 | -zookeeper = "172.26.99.168:2181" | |
| 16 | - | |
| 17 | - | |
| 18 | 12 | #切片引擎 |
| 19 | 13 | tile_engine = "http://172.26.99.160:6060" |
| 20 | 14 | #矢量引擎 |
| 21 | 15 | vector_engine = "http://172.26.99.160:6060" |
| 22 | 16 | |
| 23 | - | |
| 24 | 17 | # 固定配置不需要修改 |
| 25 | -swagger_configure = {"title": "DMapManager"} | |
| 26 | 18 | entry_data_thread = 3 |
| 27 | -scan_module = ["app.modules"] # API所在的模块 | |
| 28 | 19 | SECRET_KEY = b'_5#y2L"F4Q8z\n\xec]/' |
| 29 | 20 | # 权限 |
| 21 | +PermissionActive = False | |
| 30 | 22 | UserPermission = ['admin'] |
| 31 | 23 | MonitorPermission = ['admin'] |
| 32 | 24 | DataPermission = ['admin', 'dataman'] | ... | ... |
| ... | ... | @@ -10,8 +10,8 @@ import threading |
| 10 | 10 | |
| 11 | 11 | import time |
| 12 | 12 | |
| 13 | - | |
| 14 | - | |
| 13 | +from osgeo import ogr | |
| 14 | +from osgeo.ogr import * | |
| 15 | 15 | |
| 16 | 16 | # session:Session = get_db_session("postgresql://postgres:chinadci@172.26.99.168:5432/postgres") |
| 17 | 17 | # bbox="113.2470703125 22.840576171875,113.258056640625 22.8515625" |
| ... | ... | @@ -69,13 +69,41 @@ if __name__ == '__main__': |
| 69 | 69 | # print(zoo.connected) |
| 70 | 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") | |
| \ No newline at end of file | ||
| 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() | |
| \ No newline at end of file | ... | ... |
请
注册
或
登录
后发表评论