优化
This commit is contained in:
@@ -119,4 +119,6 @@ interface BookDao {
|
||||
@Query("update books set `group` = :newGroupId where `group` = :oldGroupId")
|
||||
fun upGroup(oldGroupId: Long, newGroupId: Long)
|
||||
|
||||
@Query("update books set `group` = `group` - :group where `group` & :group > 0")
|
||||
fun removeGroup(group: Long)
|
||||
}
|
||||
@@ -29,16 +29,10 @@ class GroupViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
}
|
||||
|
||||
fun delGroup(vararg bookGroup: BookGroup, finally: () -> Unit) {
|
||||
fun delGroup(bookGroup: BookGroup, finally: () -> Unit) {
|
||||
execute {
|
||||
appDb.bookGroupDao.delete(*bookGroup)
|
||||
bookGroup.forEach { group ->
|
||||
val books = appDb.bookDao.getBooksByGroup(group.groupId)
|
||||
books.forEach {
|
||||
it.group = it.group - group.groupId
|
||||
}
|
||||
appDb.bookDao.update(*books.toTypedArray())
|
||||
}
|
||||
appDb.bookGroupDao.delete(bookGroup)
|
||||
appDb.bookDao.removeGroup(bookGroup.groupId)
|
||||
}.onFinally {
|
||||
finally()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user