优化
This commit is contained in:
@@ -119,4 +119,6 @@ interface BookDao {
|
|||||||
@Query("update books set `group` = :newGroupId where `group` = :oldGroupId")
|
@Query("update books set `group` = :newGroupId where `group` = :oldGroupId")
|
||||||
fun upGroup(oldGroupId: Long, newGroupId: Long)
|
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 {
|
execute {
|
||||||
appDb.bookGroupDao.delete(*bookGroup)
|
appDb.bookGroupDao.delete(bookGroup)
|
||||||
bookGroup.forEach { group ->
|
appDb.bookDao.removeGroup(bookGroup.groupId)
|
||||||
val books = appDb.bookDao.getBooksByGroup(group.groupId)
|
|
||||||
books.forEach {
|
|
||||||
it.group = it.group - group.groupId
|
|
||||||
}
|
|
||||||
appDb.bookDao.update(*books.toTypedArray())
|
|
||||||
}
|
|
||||||
}.onFinally {
|
}.onFinally {
|
||||||
finally()
|
finally()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user