| | |
| | | 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) { |
| | |
| | | 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) |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | 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() = codeDao.getDailyStatsByWeek() |
| | | // 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 |
| | |
| | | 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) |
| | | } |
| | | |
| | | } |