From e27f54aa7e10836e2741dc590559e1039fbade78 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 23 七月 2021 15:06:41 +0800
Subject: [PATCH] 1. 创建子任务时,执行用户默认为当前登录用户或执行组中的第一人 2. 修复部分企业类型问题图标错误 3. 新增场景账户自动生成功能

---
 app/src/main/java/cn/flightfeather/thirdapp/repository/dao/MediaFileDao.kt |   50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 49 insertions(+), 1 deletions(-)

diff --git a/app/src/main/java/cn/flightfeather/thirdapp/repository/dao/MediaFileDao.kt b/app/src/main/java/cn/flightfeather/thirdapp/repository/dao/MediaFileDao.kt
index ed00c3e..b7174b8 100644
--- a/app/src/main/java/cn/flightfeather/thirdapp/repository/dao/MediaFileDao.kt
+++ b/app/src/main/java/cn/flightfeather/thirdapp/repository/dao/MediaFileDao.kt
@@ -1,9 +1,14 @@
 package cn.flightfeather.thirdapp.repository.dao
 
-import cn.flightfeather.thirdapp.bean.Mediafile
+import cn.flightfeather.thirdapp.bean.entity.MediaFileCache
+import cn.flightfeather.thirdapp.bean.entity.Mediafile
 import cn.flightfeather.thirdapp.common.database.DbFactory
+import cn.flightfeather.thirdapp.common.database.FlatSaveInterface
+import cn.flightfeather.thirdapp.common.database.flatMapDbSaveResult
+import com.ping.greendao.gen.MediaFileCacheDao
 import com.ping.greendao.gen.MediafileDao
 import io.reactivex.Observable
+import org.greenrobot.greendao.AbstractDao
 
 /**
  * @author riku
@@ -70,4 +75,47 @@
             true
         }
     }
+
+    /**
+     * 鑾峰彇缂撳瓨鐨勬枃浠�
+     */
+    fun getFileCache(url: String?): Observable<String> {
+        return DbFactory.getGreenDaoObservable().map {
+            val resultList = it.mediaFileCacheDao.queryBuilder()
+                    .where(MediaFileCacheDao.Properties.Url.eq(url))
+                    .list()
+            if (resultList.isNotEmpty()) {
+                resultList[0].path
+            } else {
+                ""
+            }
+        }
+    }
+
+    /**
+     * 淇濆瓨缂撳瓨鐨勬枃浠�
+     */
+    fun saveFileCache(url: String, localPath: String, thumbnailPath: String? = null) {
+        flatMapDbSaveResult(DbFactory.getInstance().mediaFileCacheDao,
+                object : FlatSaveInterface<MediaFileCache, Long> {
+                    override fun onQuery(dao: AbstractDao<MediaFileCache, Long>): List<MediaFileCache> {
+                        return dao.queryBuilder()
+                                .where(MediaFileCacheDao.Properties.Url.eq(url))
+                                .list()
+                    }
+
+                    override fun onUpdate(list: List<MediaFileCache>) {
+                        list[0].apply {
+                            path = localPath
+                        }
+                    }
+
+                    override fun onInsert(): List<MediaFileCache> {
+                        return listOf(MediaFileCache().apply {
+                            this.url = url
+                            this.path = localPath
+                        })
+                    }
+                })
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3