Browse Source

修改scheduler调用方式,改为直接保存

liuyang 3 years ago
parent
commit
6bb5df19a4

+ 18 - 0
revit-algorithm/src/main/java/cn/sagacloud/dao/TaskServiceDao.kt

@@ -0,0 +1,18 @@
+package cn.sagacloud.dao
+
+import cn.sagacloud.server.algorithm.models.modelFile.DownloadEntity
+import cn.sagacloud.server.algorithm.models.modelFile.TaskEntity
+import cn.sagacloud.server.algorithm.models.modelFile.TaskResultEntity
+import com.sybotan.mybatis.SMybatisDao
+import com.sybotan.service.SObjectService
+
+object TaskServiceDao {
+    // 任务数据服务
+    var taskService = SObjectService(SMybatisDao(TaskEntity::class.java))
+
+    // 下载任务数据服务
+    var downloadService = SObjectService(SMybatisDao(DownloadEntity::class.java))
+
+    // 任务结果数据服务
+    var taskResultService = SObjectService(SMybatisDao(TaskResultEntity::class.java))
+}

+ 89 - 0
revit-algorithm/src/main/java/cn/sagacloud/service/TaskServiceRequest.java

@@ -0,0 +1,89 @@
+package cn.sagacloud.service;
+
+import cn.sagacloud.dao.TaskServiceDao;
+import cn.sagacloud.server.algorithm.backstage.model.CreateRequest;
+import cn.sagacloud.server.algorithm.backstage.model.CreateResponse;
+import cn.sagacloud.server.algorithm.backstage.model.QueryRequest;
+import cn.sagacloud.server.algorithm.backstage.model.QueryResponse;
+import cn.sagacloud.server.algorithm.models.modelFile.DownloadEntity;
+import cn.sagacloud.server.algorithm.models.modelFile.TaskEntity;
+import cn.sagacloud.server.algorithm.models.modelFile.TaskResultEntity;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
+import com.sybotan.database.SFilter;
+import com.sybotan.service.models.requests.SCreateRequest;
+import com.sybotan.service.models.requests.SQueryRequest;
+import com.sybotan.service.models.responses.SCreateResponse;
+import com.sybotan.service.models.responses.SQueryResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+
+@Component
+public class TaskServiceRequest {
+
+    @Autowired
+    private TaskServiceDao taskServiceDao;
+
+    /**
+     * 保存定时任务实体
+     *
+     * @param request
+     * @return
+     */
+    public CreateResponse<TaskEntity> createTask(CreateRequest<TaskEntity> request) {
+        SCreateRequest<TaskEntity> taskRequest = JSON.parseObject(JSONObject.toJSONString(request), new TypeReference<SCreateRequest<TaskEntity>>() {
+        });
+        SCreateResponse<TaskEntity> sCreateResponse = taskServiceDao.getTaskService().createList(taskRequest);
+        CreateResponse<TaskEntity> response = JSON.parseObject(JSONObject.toJSONString(sCreateResponse), new TypeReference<CreateResponse<TaskEntity>>() {
+        });
+        return response;
+    }
+
+    /**
+     * 更新模型文件的url和md5
+     *
+     * @param request
+     * @return
+     */
+    public CreateResponse<DownloadEntity> createDownload(CreateRequest<DownloadEntity> request) {
+        SCreateRequest<DownloadEntity> downloadRequest = JSON.parseObject(JSONObject.toJSONString(request), new TypeReference<SCreateRequest<DownloadEntity>>() {
+        });
+        SCreateResponse<DownloadEntity> sCreateResponse = taskServiceDao.getDownloadService().createList(downloadRequest);
+        CreateResponse<DownloadEntity> response = JSON.parseObject(JSONObject.toJSONString(sCreateResponse), new TypeReference<CreateResponse<DownloadEntity>>() {
+        });
+        return response;
+    }
+
+    /**
+     * 查询任务实体
+     *
+     * @param request
+     * @return
+     */
+    public QueryResponse<TaskEntity> queryTask(QueryRequest request) {
+        SQueryRequest taskRequest = JSON.parseObject(JSONObject.toJSONString(request), new TypeReference<SQueryRequest>() {
+        });
+        SQueryResponse<TaskEntity> sQueryResponse = taskServiceDao.getTaskService().pageQuery(taskRequest, new ArrayList<SFilter>());
+        QueryResponse<TaskEntity> queryResponse = JSON.parseObject(JSONObject.toJSONString(sQueryResponse), new TypeReference<QueryResponse<TaskEntity>>() {
+        });
+        return queryResponse;
+    }
+
+    /**
+     * 查询任务结果详细信息实体
+     *
+     * @param request
+     * @return
+     */
+    public QueryResponse<TaskResultEntity> queryTaskResult(QueryRequest request) {
+        SQueryRequest taskResultRequest = JSON.parseObject(JSONObject.toJSONString(request), new TypeReference<SQueryRequest>() {
+        });
+        SQueryResponse<TaskResultEntity> sQueryResponse = taskServiceDao.getTaskResultService().pageQuery(taskResultRequest, new ArrayList<SFilter>());
+        QueryResponse<TaskResultEntity> queryResponse = JSON.parseObject(JSONObject.toJSONString(sQueryResponse), new TypeReference<QueryResponse<TaskResultEntity>>() {
+        });
+        return queryResponse;
+    }
+}

+ 6 - 5
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/services/modelCheck/TaskService.kt

@@ -7,6 +7,7 @@ import cn.sagacloud.server.algorithm.models.dataCheck.*
 import cn.sagacloud.server.algorithm.models.entities.Project
 import cn.sagacloud.server.algorithm.models.modelFile.*
 import cn.sagacloud.server.algorithm.services.endpoint.ReportService
+import cn.sagacloud.service.TaskServiceRequest
 import com.alibaba.fastjson.JSON
 import com.alibaba.fastjson.JSONArray
 import com.alibaba.fastjson.JSONObject
@@ -30,7 +31,7 @@ class TaskService {
 
     // var taskRequest = TaskRequest()
     @Autowired
-    private lateinit var taskRequest: TaskRequest
+    private lateinit var taskServiceRequest: TaskServiceRequest
 
     @Autowired
     private lateinit var reportService: ReportService
@@ -72,7 +73,7 @@ class TaskService {
         }
         sb.append("]")
         request.filters = sb.toString()
-        val response = taskRequest.queryTask(request)
+        val response = taskServiceRequest.queryTask(request)
         if(response.result == "success"){
             return response.content
         }else
@@ -87,7 +88,7 @@ class TaskService {
         val sb = StringBuilder()
         sb.append("TaskId in [\"${taskId}\"]")
         request.filters = sb.toString()
-        val response = taskRequest.queryTaskResult(request)
+        val response = taskServiceRequest.queryTaskResult(request)
         if(response.result == "success"){
             try {
                 return response.content?.get(0)!!.content
@@ -124,7 +125,7 @@ class TaskService {
                 request.content!!.add(download)
             }
         }
-        val response = taskRequest.createDownload(request)
+        val response = taskServiceRequest.createDownload(request)
         return response.result == "success"
     }
 
@@ -167,7 +168,7 @@ class TaskService {
                 request.content = ArrayList()
             request.content!!.add(task)
         }
-        val response = taskRequest.createTask(request)
+        val response = taskServiceRequest.createTask(request)
         val map = HashMap<String, String>()  // modelId --> 调度器taskId
         val resultMap = HashMap<String, TaskEntity>()
         if(response!!.entityList != null && response.entityList!!.isNotEmpty()){