|
@@ -7,11 +7,11 @@ import androidx.lifecycle.ViewModel
|
|
|
import androidx.lifecycle.viewModelScope
|
|
|
import cn.sagacloud.cadengine.OkhttpUtil
|
|
|
import com.framework.app.*
|
|
|
+import com.framework.app.http.FileDownloadInfo
|
|
|
import com.framework.app.http.FileInfo
|
|
|
import com.framework.app.http.FileUploadInfo
|
|
|
import com.framework.app.tools.md5
|
|
|
import com.framework.app.tools.toBytes
|
|
|
-import com.framework.mvvm.model.data.Data
|
|
|
import com.framework.mvvm.model.data.Response
|
|
|
import com.framework.mvvm.model.data.SuccessResponse
|
|
|
import com.framework.mvvm.model.data.request
|
|
@@ -25,7 +25,6 @@ import com.framework.mvvm.model.vo.Client
|
|
|
import com.framework.mvvm.model.vo.Login
|
|
|
import com.sybotan.android.demo.DemoApp
|
|
|
import com.sybotan.android.demo.tools.LocalDataOperation
|
|
|
-import com.yuyh.library.imgsel.utils.LogUtils
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.async
|
|
|
import kotlinx.coroutines.flow.*
|
|
@@ -263,6 +262,55 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private suspend fun getFileDownloadInfo(
|
|
|
+ param: Map<String, String>,
|
|
|
+ fileId: String
|
|
|
+ ): Response<FileDownloadInfo> {
|
|
|
+ return request { repository.getFileDownloadInfo(param, fileId) }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传下载
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * mapOf(
|
|
|
+ * "appId" to "adm",
|
|
|
+ * "userId" to "bdtp",
|
|
|
+ * "groupCode" to "Pj1101080665",
|
|
|
+ * "projectId" to "BR"
|
|
|
+ * )
|
|
|
+ * @param file
|
|
|
+ * 例:
|
|
|
+ * val path: File? = getExternalFilesDir("/img/png")
|
|
|
+ * if (path == null || !path.exists()) {
|
|
|
+ * path?.mkdirs()
|
|
|
+ * }
|
|
|
+ * val file = File(path, "download.png")
|
|
|
+ * @param fileId
|
|
|
+ * fileId: 文件存储平台的 fileId
|
|
|
+ */
|
|
|
+ fun fileDownload(param: Map<String, String>, file: File, fileId: String) {
|
|
|
+
|
|
|
+ viewModelScope.launch(Dispatchers.IO) {
|
|
|
+ val response = getFileDownloadInfo(param, fileId)
|
|
|
+ if (response is SuccessResponse) {
|
|
|
+ val data: FileDownloadInfo = response.data
|
|
|
+ val url = data.fileDownloadUrl ?: ""
|
|
|
+
|
|
|
+ if (url.isNotEmpty()) {
|
|
|
+ val byteArray = repository.downloadFile(url)
|
|
|
+ val fos = FileOutputStream(file)
|
|
|
+ fos.use { out ->
|
|
|
+ out.write(byteArray)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Log.d("fileDownload", "fileDownload has something error:$response")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取服务端生成的客户端Id
|
|
|
*/
|