|
@@ -1,3 +1,7 @@
|
|
|
+import json
|
|
|
+import os
|
|
|
+
|
|
|
+import requests
|
|
|
import rq
|
|
|
|
|
|
from app.mission_jobs.image_slice_job import image_slice_job
|
|
@@ -7,16 +11,51 @@ from connection import Connection
|
|
|
|
|
|
class Application:
|
|
|
|
|
|
- # def __init__(self, config):
|
|
|
- # self._config = config
|
|
|
+ def __init__(self, config):
|
|
|
+ self._config = config
|
|
|
+
|
|
|
+ def new_mission(self, dms_params, data_path, output_path, tile_size, tile_grid, tile_format, epsg, auto_zoom, min_zoom, max_zoom):
|
|
|
+
|
|
|
+ # 获取token
|
|
|
+ login_data = {
|
|
|
+ 'userName': self._config.oauth.userName,
|
|
|
+ 'password': self._config.oauth.password,
|
|
|
+ 'clientId': self._config.oauth.clientId,
|
|
|
+ 'serviceId': self._config.oauth.serviceId
|
|
|
+ }
|
|
|
+ login_rep = requests.post(self._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": dms_params.get('title'),
|
|
|
+ "content": dms_params.get('content'),
|
|
|
+ "c_tile_grid": "墨卡托投影切片",
|
|
|
+ "c_name": dms_params.get('c_name'),
|
|
|
+ "c_tile_format": tile_format,
|
|
|
+ "c_epsg": '4326',
|
|
|
+ "c_url": self._config.nginx.URL + '/%s/{z}/{x}/{y}.%s' % (os.path.basename(data_path), tile_format),
|
|
|
+ "c_content": dms_params.get('c_content'),
|
|
|
+ "c_note": dms_params.get('c_note'),
|
|
|
+ "c_tile_size": tile_size,
|
|
|
+ "c_zoom_min": min_zoom,
|
|
|
+ "c_zoom_max": max_zoom,
|
|
|
+ "c_auto_zoom": auto_zoom,
|
|
|
+ "bbox": ''
|
|
|
+ }, ensure_ascii=False),
|
|
|
+ 'modelId': self._config.dms.modelId,
|
|
|
+ 'columnId': self._config.dms.columnId
|
|
|
+ }
|
|
|
+ dms_rep = requests.post(self._config.dms.URL + '/content/addContent', headers=headers, data=dms_data).json()
|
|
|
+ dms_id = dms_rep['content']
|
|
|
|
|
|
- def new_mission(self, data_path, tile_size, tile_grid, tile_format, epsg, auto_zoom, min_zoom, max_zoom, dms_id):
|
|
|
# 影像切片
|
|
|
config = Config()
|
|
|
connection = Connection(config)
|
|
|
# 添加任务
|
|
|
q = rq.Queue(name='default', connection=connection.redis_conn)
|
|
|
- output_path = config.common.OUTPUT_PATH
|
|
|
|
|
|
q.enqueue(image_slice_job,
|
|
|
kwargs={"data_path": data_path,
|
|
@@ -28,7 +67,8 @@ class Application:
|
|
|
"auto_zoom": auto_zoom,
|
|
|
"min_zoom": min_zoom,
|
|
|
"max_zoom": max_zoom,
|
|
|
- "dms_id": dms_id
|
|
|
+ "dms_id": dms_id,
|
|
|
+ "dms_data":dms_data
|
|
|
},
|
|
|
job_timeout=int(config.common.JOB_TIMEOUT)
|
|
|
)
|