cloudroam
2025-04-10 5fc9567cfa6b6beee4f52a9f835f304865d693e1
app/src/main/java/com/example/firstapp/database/repository/CodeRepository.kt
@@ -3,9 +3,8 @@
import androidx.annotation.WorkerThread
import com.example.firstapp.database.dao.CodeDao
import com.example.firstapp.database.entity.Code
import kotlinx.coroutines.Dispatchers
import com.example.firstapp.model.StationGroup
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
class CodeRepository(private val codeDao: CodeDao) {
@@ -25,7 +24,8 @@
        return codeDao.getByKeyword(keyword)
    }
    fun queryByTypeAndCodeAndDate(content: String, code: String, dateString: String): Code {
    @WorkerThread
    fun queryByTypeAndCodeAndDate(content: String, code: String, dateString: String): Code? {
        return codeDao.queryByTypeAndCodeAndDate(content, code, dateString)
    }
@@ -41,9 +41,19 @@
        }
    }
    fun getCourierStats(date: Long) = codeDao.getCourierStatsByWeek(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 getDailyStats(date: Long) = codeDao.getDailyStatsByWeek(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
@@ -51,5 +61,30 @@
        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)
    @WorkerThread
    fun getStationsByType(type: String): List<StationGroup> {
        return codeDao.getStationsByType(type)
    }
    @WorkerThread
    fun getPackagesByTypeAndStation(type: String, stationName: String): List<Code> {
        return codeDao.getPackagesByTypeAndStation(type, stationName)
    }
}