Browse Source

/model-floor/query-list增加一个字段FetchUrl

lijie 3 years ago
parent
commit
5a77e0125b

+ 18 - 4
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/controllers/modelFile/FloorModelController.kt

@@ -19,7 +19,6 @@
  */
 package cn.sagacloud.server.algorithm.controllers.modelFile
 
-import cn.sagacloud.server.algorithm.backstage.state.ExportPassedState_3
 import cn.sagacloud.server.algorithm.backstage.sync.SyncUtil
 import cn.sagacloud.server.algorithm.dao.mapper.FloorMapper
 import cn.sagacloud.server.algorithm.models.config.MyProperties
@@ -32,7 +31,7 @@ import cn.sagacloud.server.algorithm.services.comparator.FloorComparator
 import cn.sagacloud.server.algorithm.services.datacenter.DataCenterService
 import cn.sagacloud.server.algorithm.services.endpoint.FloorModelService
 import cn.sagacloud.server.algorithm.services.endpoint.FloorService
-import com.alibaba.fastjson.JSONObject
+import cn.sagacloud.server.algorithm.services.endpoint.ModelFileService
 import com.sybotan.database.SFilter
 import com.sybotan.service.SPageContext
 import com.sybotan.service.models.enums.SResponseType
@@ -46,13 +45,15 @@ import com.sybotan.service.models.responses.SCreateResponse
 import com.sybotan.service.models.responses.SQueryResponse
 import io.swagger.annotations.Api
 import io.swagger.annotations.ApiOperation
+import org.apache.commons.lang3.StringUtils
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.web.bind.annotation.PostMapping
 import org.springframework.web.bind.annotation.RequestBody
 import org.springframework.web.bind.annotation.RequestMapping
 import org.springframework.web.bind.annotation.RestController
-import java.lang.StringBuilder
+import java.util.stream.Collector
+import java.util.stream.Collectors.toSet
 
 /**
  *
@@ -80,6 +81,9 @@ class FloorModelController {
     lateinit var floorService : FloorService
 
     @Autowired
+    lateinit var modelFileService : ModelFileService
+
+    @Autowired
     lateinit var floorMapper : FloorMapper
 
     @Autowired
@@ -105,8 +109,18 @@ class FloorModelController {
             response = FloorModelService.pageQuery(request)
         }
         val list = response.content
-        if(list != null && list.isNotEmpty())
+        if(list != null && list.isNotEmpty()) {
+            // 2021年12月23日11:24:57 新增一个预获取url
+            try{
+                val fileIds: Set<String> = list.stream().filter { model -> StringUtils.isNotBlank(model.url) }
+                        .map { model -> model.url!!.subSequence(model.url!!.lastIndexOf("key=")+4, model.url!!.length) }
+                        .collect(toSet<String>() as Collector<in CharSequence, out Any, Set<String>>)
+                val urlMap:Map<String,String> = modelFileService.queryFetchUrlsByFileIds(fileIds, myProperties)
+                list.forEach { model -> model.fetchUrl=urlMap
+                        .getOrDefault(model.url!!.subSequence(model.url!!.lastIndexOf("key=")+4, model.url!!.length),null) }
+            }catch (e:Exception){}
             response.content = list.sortedWith(floorComparator)
+        }
         return response
     } // Function queryList()
 

+ 1 - 0
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/models/config/FileServiceConfig.kt

@@ -24,4 +24,5 @@ class FileServiceConfig {
     lateinit var deletePath: String
     lateinit var registerMultipartUpload: String
     lateinit var mergeMultipartUpload: String
+    lateinit var queryFetchUrlsByFileIds: String
 }

+ 4 - 0
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/models/modelFile/FloorModelView.kt

@@ -121,4 +121,8 @@ open class FloorModelView : Serializable {
     @ApiModelProperty(value = "模型的revit版本")
     @Column(name = "revit_version")
     var revitVersion: String? = null
+
+    /** 文件预下载url */
+    @ApiModelProperty(value = "文件预下载url")
+    var fetchUrl: String? = null
 }

+ 22 - 2
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/services/endpoint/ModelFileService.kt

@@ -11,8 +11,8 @@ import cn.sagacloud.server.algorithm.services.BaseDataService
 import cn.sagacloud.server.algorithm.services.CommonService
 import cn.sagacloud.server.algorithm.services.http.HttpService
 import com.alibaba.fastjson.JSON
+import com.alibaba.fastjson.JSONObject
 import com.sybotan.database.SFilter
-import com.sybotan.database.extensions.keyValue
 import com.sybotan.service.SPageContext
 import com.sybotan.service.models.enums.SResponseType
 import com.sybotan.service.models.responses.SBaseResponse
@@ -22,7 +22,7 @@ import org.springframework.stereotype.Component
 import org.springframework.web.multipart.MultipartFile
 import java.util.*
 import java.util.regex.Pattern
-import kotlin.collections.ArrayList
+import kotlin.collections.HashMap
 
 /**
  *
@@ -445,4 +445,24 @@ class ModelFileService {
         val result = HttpService.sendPost(properties.fileService.mergeMultipartUpload + uploadId, "")
         return result.contains("success")
     }
+    fun queryFetchUrlsByFileIds(fileIds: Set<String>, properties: MyProperties) : Map<String,String> {
+        if (fileIds.isNullOrEmpty()){
+            return HashMap()
+        }
+        val param = JSONObject()
+        param["fileIds"] = fileIds
+        val result = HttpService.sendPost(properties.fileService.queryFetchUrlsByFileIds, param)
+        if (!result.contains("success") || !result.startsWith("{")){
+            return HashMap()
+        }
+        val queryObj:JSONObject = JSON.parseObject(result)
+        val data:JSONObject = queryObj["data"] as JSONObject
+        if (data.isNullOrEmpty()){
+            return HashMap()
+        }
+        val keys = data.keys
+        val map:HashMap<String,String> = HashMap()
+        keys.forEach{key->map.put(key,data.getString(key))}
+        return map
+    }
 }

+ 3 - 1
revit-algorithm/src/main/resources-dev/application.yml

@@ -92,7 +92,8 @@ properties:
   #文件服务器配置
   fileService:
     # 基本属性
-    url:                               http://api.sagacloud.cn/dp-auxiliary/image-service/ # http://47.93.33.207:28888/image-service/ #http://adm.sagacloud.cn/image-service/
+    # url:                               http://api.sagacloud.cn/dp-auxiliary/image-service/ # http://47.93.33.207:28888/image-service/ #http://adm.sagacloud.cn/image-service/
+    url:                               http://localhost:8080/ # http://47.93.33.207:28888/image-service/ #http://adm.sagacloud.cn/image-service/
     #url:                               http://image-service:8080/
     systemId: revit
     secret: 63afbef6906c342b
@@ -115,6 +116,7 @@ properties:
     deletePath:                        ${properties.fileService.url}common/files_delete${properties.fileService.suffixWithSecret}
     registerMultipartUpload:           ${properties.fileService.url}common/register_multipart_upload${properties.fileService.suffixWithSecret}&overwrite=true&key=${properties.fileService.dir}/
     mergeMultipartUpload:              ${properties.fileService.url}common/merge_multipart${properties.fileService.suffixWithSecret}&uploadId=
+    queryFetchUrlsByFileIds:           ${properties.fileService.url}/file/queryFetchUrlsByFileIds
 
   scheduler:
     #url:                               http://82.157.26.241:8080/