cloudroam
2025-03-24 380d70f2f1cd03b314fa6de64df30eab914956ba
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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.flow.Flow
 
 
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, dateType: String) = when(dateType) {
        "WEEK" -> codeDao.getCourierStatsByWeek(date)
        "MONTH" -> codeDao.getCourierStatsByMonth(date)
        "YEAR" -> codeDao.getCourierStatsByYear(date)
        else -> codeDao.getCourierStatsByWeek(date)
    }
 
//    fun getStats(date: Long, dateType: String) = when(dateType) {
//        "WEEK" -> codeDao.getDailyStatsByWeek(date)
//        "MONTH" -> codeDao.getMonthlyStats(date)
//        "YEAR" -> codeDao.getYearlyStats(date)
//        else -> codeDao.getDailyStatsByWeek(date)
//    }
 
 
    @WorkerThread
    fun getPackagesByDay(date: Long): List<Code> {
        return codeDao.getNewPackagesByDay(date)
    }
 
    fun getYearlyHeatmap(date: Long) = codeDao.getYearlyHeatmap(date)
 
    fun getWeeklyStats(date: Long, weekCount: Int) = codeDao.getWeeklyStats(date, weekCount)
    
    fun getMonthlyStats(date: Long) = codeDao.getMonthlyStats(date)
 
 
    fun getYearlyStats(date: Long) = codeDao.getYearlyStats(date)
 
    fun getYearMonthlyStats(date: Long) = codeDao.getYearMonthlyStats(date)
 
 
    fun getCurrentWeekStats(date: Long) = codeDao.getCurrentWeekStats(date)
 
    fun getCurrentYearStats(date: Long) = codeDao.getCurrentYearStats(date)
 
}