| | |
| | | import androidx.room.Update |
| | | import com.example.firstapp.database.entity.Code |
| | | import com.example.firstapp.database.entity.Msg |
| | | import com.example.firstapp.model.CourierStat |
| | | import com.example.firstapp.model.DailyStat |
| | | import io.reactivex.Completable |
| | | import kotlinx.coroutines.flow.Flow |
| | | |
| | | @Dao |
| | | interface CodeDao { |
| | |
| | | @Query(""" |
| | | SELECT * FROM Code |
| | | WHERE type LIKE '%' || :keyword || '%' |
| | | AND pickup = '0' |
| | | ORDER BY time DESC |
| | | """) |
| | | fun getByKeyword(keyword: String): List<Code> |
| | | |
| | | @Query("SELECT * FROM Code WHERE type = :content and code= :code and createtime = :dateString LIMIT 1") |
| | | fun queryByTypeAndCodeAndDate(content: String, code: String, dateString: String): Code |
| | | |
| | | |
| | | @Query("update Code set pickup = '1' , pickuptime = CURRENT_TIMESTAMP where id=:id") |
| | | fun pickup(id: Long) |
| | | |
| | | //查询当天包裹信息 |
| | | @Query("SELECT * FROM code WHERE date(createtime) = date(:date/1000, 'unixepoch', 'localtime') ORDER BY createtime DESC") |
| | | fun getNewPackagesByDay(date: Long): List<Code> |
| | | |
| | | @Query(""" |
| | | SELECT * FROM code |
| | | WHERE substr(createtime, 1, 10) = |
| | | date(:date/1000, 'unixepoch', 'localtime') |
| | | ORDER BY createtime DESC |
| | | """) |
| | | fun getPackagesByDay(date: Long): Flow<List<Code>> |
| | | |
| | | @Query(""" |
| | | SELECT type as courierName, COUNT(*) as count |
| | | FROM code |
| | | WHERE strftime('%Y-%W', substr(createtime, 1, 10)) = |
| | | strftime('%Y-%W', datetime(:date/1000, 'unixepoch', 'localtime')) |
| | | GROUP BY type |
| | | ORDER BY count DESC |
| | | """) |
| | | fun getCourierStatsByWeek(date: Long): Flow<List<CourierStat>> |
| | | |
| | | @Query(""" |
| | | SELECT strftime('%W', createtime) as date, |
| | | COUNT(*) as count, |
| | | MIN(createtime) as week_start |
| | | FROM code |
| | | WHERE strftime('%Y', createtime) = strftime('%Y', 'now') |
| | | GROUP BY strftime('%W', createtime) |
| | | ORDER BY week_start ASC |
| | | """) |
| | | fun getDailyStatsByWeek(): Flow<List<DailyStat>> |
| | | |
| | | @Query(""" |
| | | SELECT * FROM code |
| | | WHERE substr(createtime, 1, 10) = |
| | | date(:date/1000, 'unixepoch', 'localtime') |
| | | ORDER BY createtime DESC |
| | | """) |
| | | fun getPackagesByWeek(date: Long): Flow<List<Code>> |
| | | } |