cloudroam
2025-04-15 3466799c94227c5ebba9fb201621e745058867ee
app/src/main/java/com/example/firstapp/database/repository/CodeRepository.kt
@@ -3,6 +3,8 @@
import androidx.annotation.WorkerThread
import com.example.firstapp.database.dao.CodeDao
import com.example.firstapp.database.entity.Code
import com.example.firstapp.model.DailyStat
import com.example.firstapp.model.StationGroup
import kotlinx.coroutines.flow.Flow
@@ -14,6 +16,9 @@
    @WorkerThread
    fun delete(id: Long) = codeDao.delete(id)
    @WorkerThread
    fun deleteAll() = codeDao.deleteAll()
    fun getAll() = codeDao.getAllCodes()
    fun getAllDesc() = codeDao.getAllCodesDesc()
@@ -23,7 +28,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)
    }
@@ -34,6 +40,14 @@
    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 getPackagesUnread(date: Long, dateType: String): Flow<List<Code>> {
        return when (dateType) {
            "DAY" -> codeDao.getPackagesByDayUnread(date)
            "WEEK" -> codeDao.getPackagesByWeek(date)
            else -> codeDao.getPackagesByDay(date)
        }
@@ -70,4 +84,22 @@
    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)
    }
    fun getCurrentWeekStats2(startDateCur: String, endDateCur: String) = codeDao.getCurrentWeekStats2(startDateCur,endDateCur)
    fun getWeeklyStatsChart(startDateCur: String, endDateCur: String): Flow<List<DailyStat>> = codeDao.getWeeklyStatsChart(startDateCur,endDateCur)
}