cloudroam
2025-03-04 2a117297daf83b2e1a104603e9641226d5beeba3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.example.firstapp.database.repository
 
import androidx.annotation.WorkerThread
import com.example.firstapp.database.dao.CodeDao
import com.example.firstapp.database.entity.Code
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
 
 
class CodeRepository(private val codeDao: CodeDao) {
 
    @WorkerThread
    fun insert(code: Code): Long = codeDao.insert(code)
 
    @WorkerThread
    fun delete(id: Long) = codeDao.delete(id)
 
    fun getAll() = codeDao.getAllCodes()
 
    fun getAllDesc() = codeDao.getAllCodesDesc()
 
    @WorkerThread
    fun getByKeyword(keyword: String): List<Code> {
        return codeDao.getByKeyword(keyword)
    }
 
    fun queryByTypeAndCodeAndDate(content: String, code: String, dateString: String): Code {
        return codeDao.queryByTypeAndCodeAndDate(content, code, dateString)
    }
 
    @WorkerThread
    fun pickup(id: Long) = codeDao.pickup(id)
 
 
    fun getPackages(date: Long, dateType: String): Flow<List<Code>> {
        return when (dateType) {
            "DAY" -> codeDao.getPackagesByDay(date)
            "WEEK" -> codeDao.getPackagesByWeek(date)
            else -> codeDao.getPackagesByDay(date)
        }
    }
 
    fun getCourierStats(date: Long) = codeDao.getCourierStatsByWeek(date)
 
    fun getDailyStats(date: Long) = codeDao.getDailyStatsByWeek(date)
 
 
    @WorkerThread
    fun getPackagesByDay(date: Long): List<Code> {
        return codeDao.getNewPackagesByDay(date)
    }
 
 
}