|
@@ -1,3 +1,4 @@
|
|
|
+import json
|
|
|
import os.path
|
|
|
import traceback
|
|
|
|
|
@@ -14,6 +15,10 @@ config = Config()
|
|
|
ns = Namespace('mission', description='任务管理 API接口')
|
|
|
|
|
|
slice_mission_parser = reqparse.RequestParser(bundle_errors=True)
|
|
|
+slice_mission_parser.add_argument(name='title', type=str, location='form', required=False, help='dms 标题')
|
|
|
+slice_mission_parser.add_argument(name='content', type=str, location='form', required=False, help='dms 描述')
|
|
|
+slice_mission_parser.add_argument(name='c_name', type=str, location='form', required=False, help='dms 名称')
|
|
|
+
|
|
|
slice_mission_parser.add_argument(name='data_path', type=str, location='form', required=False, help='数据目录')
|
|
|
slice_mission_parser.add_argument(name='tile_size', type=int, location='form', required=False, help='瓦片大小')
|
|
|
slice_mission_parser.add_argument(name='tile_format', type=str, location='form', required=False,
|
|
@@ -33,6 +38,12 @@ class MissionAPI(Resource):
|
|
|
"""添加任务"""
|
|
|
try:
|
|
|
form = request.form
|
|
|
+
|
|
|
+ # dms
|
|
|
+ title = form.get('title')
|
|
|
+ content = form.get('content')
|
|
|
+ c_name = form.get('c_name')
|
|
|
+
|
|
|
data_path = form.get('data_path')
|
|
|
tile_size = int(form.get('tile_size', 256))
|
|
|
tile_grid = form.get('tile_grid', 'WebMercatorQuad')
|
|
@@ -43,6 +54,39 @@ class MissionAPI(Resource):
|
|
|
|
|
|
if not data_path:
|
|
|
return jsonify(code=StatesCode.PARA_ERROR, message='输入路径错误')
|
|
|
+ # 获取token
|
|
|
+ login_data = {
|
|
|
+ 'userName': config.oauth.userName,
|
|
|
+ 'password': config.oauth.password,
|
|
|
+ 'clientId': config.oauth.clientId,
|
|
|
+ 'serviceId': config.oauth.serviceId
|
|
|
+ }
|
|
|
+ login_rep = requests.post(config.oauth.URL + '/api/user/login', data=login_data).json()
|
|
|
+
|
|
|
+ # 添加DMS
|
|
|
+ headers = {'token': login_rep.get('message'), 'Content-Type': 'application/x-www-form-urlencoded'}
|
|
|
+ dms_data = \
|
|
|
+ {
|
|
|
+ 'content': json.dumps({
|
|
|
+ "title": title,
|
|
|
+ "content": content,
|
|
|
+ "c_tile_grid": tile_grid,
|
|
|
+ "c_name": c_name,
|
|
|
+ "c_tile_format": tile_format,
|
|
|
+ "c_epsg": '4326',
|
|
|
+ "c_url": config.nginx.URL + config.common.OUTPUT_PATH,
|
|
|
+ "c_content": "0",
|
|
|
+ "c_note": "0",
|
|
|
+ "c_tile_size": tile_size,
|
|
|
+ "c_zoom_min": min_zoom,
|
|
|
+ "c_zoom_max": max_zoom,
|
|
|
+ "c_auto_zoom": auto_zoom
|
|
|
+ }),
|
|
|
+ 'modelId': config.dms.modelId,
|
|
|
+ 'columnId': config.dms.columnId
|
|
|
+ }
|
|
|
+ dms_rep = requests.post(config.dms.URL + '/content/addContent', headers=headers, data=dms_data).json()
|
|
|
+ dms_id = dms_rep['content']
|
|
|
|
|
|
application = Application()
|
|
|
application.new_mission(
|
|
@@ -52,42 +96,13 @@ class MissionAPI(Resource):
|
|
|
tile_format=tile_format,
|
|
|
auto_zoom=auto_zoom,
|
|
|
min_zoom=min_zoom,
|
|
|
- max_zoom=max_zoom
|
|
|
+ max_zoom=max_zoom,
|
|
|
+ # dms
|
|
|
+ dms_id=dms_id
|
|
|
)
|
|
|
|
|
|
- # 添加至dem
|
|
|
- try:
|
|
|
- # 获取token
|
|
|
- login_data = {
|
|
|
- 'userName': config.oauth.userName,
|
|
|
- 'password': config.oauth.password,
|
|
|
- 'clientId': config.oauth.clientId,
|
|
|
- 'serviceId': config.oauth.serviceId
|
|
|
- }
|
|
|
- login_rep = requests.post(config.oauth.URL + '/api/user/login', data=login_data).json()
|
|
|
- headers = {'token': login_rep.get('message')}
|
|
|
- dms_data = {
|
|
|
- "title": os.path.basename(data_path),
|
|
|
- "content": os.path.basename(data_path),
|
|
|
- "c_tile_grid": tile_grid,
|
|
|
- "c_name": os.path.basename(data_path),
|
|
|
- "c_tile_format": tile_format,
|
|
|
- "c_epsg": '4326',
|
|
|
- "c_url": config.nginx.URL + config.common.OUTPUT_PATH,
|
|
|
- "c_content": "0",
|
|
|
- "c_note": "0",
|
|
|
- "c_tile_size": tile_size,
|
|
|
- "c_zoom_min": min_zoom,
|
|
|
- "c_zoom_max": max_zoom,
|
|
|
- "c_auto_zoom": auto_zoom
|
|
|
- }
|
|
|
- dms_rep = requests.post(config.dms.URL + '/content/addContent', headers=headers, data=dms_data)
|
|
|
-
|
|
|
- except Exception as err:
|
|
|
- traceback.print_exc()
|
|
|
- print_log('dms添加失败')
|
|
|
-
|
|
|
- return {"code": StatesCode.SUCCESS, "message": "任务添加成功"}
|
|
|
+ return {"code": StatesCode.SUCCESS,
|
|
|
+ "message": "开始切片预计需要%s分钟,请耐心等待" % str(len(os.listdir(data_path)) * 8)}
|
|
|
|
|
|
except Exception as err:
|
|
|
|