Browse Source

@task: add map param

bai 3 years ago
parent
commit
35f0cc17d5

+ 2 - 12
demo/src/main/java/com/framework/app/api/Api.kt

@@ -49,12 +49,7 @@ interface Api {
      */
     @POST("http://www.ysbdtp.com/dmp-file/file/initSingleUpload")
     suspend fun getFileUploadInfo(
-        @QueryMap param: Map<String, String> = mapOf(
-            "appId" to "adm",
-            "userId" to "bdtp",
-            "groupCode" to "XG",
-            "projectId" to "Pj5001120003"
-        ),
+        @QueryMap param: Map<String, String>,
         @Body file: FileInfo
     ): Model<FileUploadInfo>
 
@@ -69,12 +64,7 @@ interface Api {
      */
     @POST("http://www.ysbdtp.com/dmp-file/file/initFileDownload")
     fun getFileDownloadInfo(
-        @QueryMap param: Map<String, String> = mapOf(
-            "appId" to "adm",
-            "userId" to "bdtp",
-            "groupCode" to "XG",
-            "projectId" to "Pj5001120003"
-        ),
+        @QueryMap param: Map<String, String>,
         @Body fileId: String
     ): Model<FileDownloadInfo>
 

+ 15 - 5
demo/src/main/java/com/framework/mvvm/model/repository/AdmRepository.kt

@@ -196,7 +196,11 @@ class AdmRepository(
         return db.objectDao().getObjectByCode(code, buildingId)
     }
 
-    suspend fun getObjectByCode(code: String, buildingId: String, floorId: String): List<ObjectEntity> {
+    suspend fun getObjectByCode(
+        code: String,
+        buildingId: String,
+        floorId: String
+    ): List<ObjectEntity> {
         return db.objectDao().getObjectByCode(code, buildingId, floorId)
     }
 
@@ -605,8 +609,11 @@ class AdmRepository(
     /**
      *  获取文件信息
      */
-    suspend fun getFileUploadInfo(file: FileInfo): Model<FileUploadInfo> {
-        return api.getFileUploadInfo(file = file)
+    suspend fun getFileUploadInfo(
+        param: Map<String, String>,
+        file: FileInfo
+    ): Model<FileUploadInfo> {
+        return api.getFileUploadInfo(param = param, file = file)
     }
 
     /**
@@ -619,8 +626,11 @@ class AdmRepository(
     /**
      * 获取文件下载信息
      */
-    suspend fun getFileDownloadInfo(fileId: String): Model<FileDownloadInfo> {
-        return api.getFileDownloadInfo(fileId = fileId)
+    suspend fun getFileDownloadInfo(
+        param: Map<String, String>,
+        fileId: String
+    ): Model<FileDownloadInfo> {
+        return api.getFileDownloadInfo(param = param, fileId = fileId)
     }
 
     /**

+ 7 - 4
demo/src/main/java/com/framework/mvvm/mv/AdmViewModel.kt

@@ -212,8 +212,11 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
     /**
      * 获取文件上传信息
      */
-    private suspend fun getFileUploadInfo(basic: FileInfo): Response<FileUploadInfo> {
-        return request { repository.getFileUploadInfo(basic) }
+    private suspend fun getFileUploadInfo(
+        param: Map<String, String>,
+        file: FileInfo
+    ): Response<FileUploadInfo> {
+        return request { repository.getFileUploadInfo(param, file) }
     }
 
     /**
@@ -226,7 +229,7 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
     /**
      * 上传文件
      */
-    fun fileUpload(file: File) {
+    fun fileUpload(param: Map<String, String>, file: File) {
         val bytes = file.toBytes()
 
         val md5 = md5(bytes)
@@ -238,7 +241,7 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
         )
 
         viewModelScope.launch(Dispatchers.IO) {
-            val response = getFileUploadInfo(info)
+            val response = getFileUploadInfo(param, info)
             if (response is SuccessResponse) {
                 val data = response.data
                 val url = data.content?.get(0)?.uploadUrl ?: ""