@@ -16,13 +16,27 @@ import kotlinx.parcelize.Parcelize
1616import kotlinx.serialization.Serializable
1717
1818
19+ private var lastId = 0L
20+
21+ @Synchronized
22+ private fun buildUniqueTimeMillisId (): Long {
23+ while (true ) {
24+ val id = System .currentTimeMillis()
25+ if (id != lastId) {
26+ lastId = id
27+ return id
28+ }
29+ Thread .sleep(1 )
30+ }
31+ }
32+
1933@Serializable
2034@Entity(
2135 tableName = " subs_config" ,
2236)
2337@Parcelize
2438data class SubsConfig (
25- @PrimaryKey @ColumnInfo(name = " id" ) val id : Long = System .currentTimeMillis (),
39+ @PrimaryKey @ColumnInfo(name = " id" ) val id : Long = buildUniqueTimeMillisId (),
2640 @ColumnInfo(name = " type" ) val type : Int ,
2741 @ColumnInfo(name = " enable" ) val enable : Boolean? = null ,
2842 @ColumnInfo(name = " subs_item_id" ) val subsItemId : Long ,
@@ -53,6 +67,12 @@ data class SubsConfig(
5367 @Delete
5468 suspend fun delete (vararg users : SubsConfig ): Int
5569
70+ @Transaction
71+ suspend fun insertAndDelete (newList : List <SubsConfig >, deleteList : List <SubsConfig >){
72+ insert(* newList.toTypedArray())
73+ delete(* deleteList.toTypedArray())
74+ }
75+
5676 @Query(" DELETE FROM subs_config WHERE subs_item_id=:subsItemId" )
5777 suspend fun delete (subsItemId : Long ): Int
5878
@@ -65,9 +85,20 @@ data class SubsConfig(
6585 @Query(" DELETE FROM subs_config WHERE type=${AppGroupType } AND subs_item_id=:subsItemId AND app_id=:appId AND group_key=:groupKey" )
6686 suspend fun deleteAppGroupConfig (subsItemId : Long , appId : String , groupKey : Int ): Int
6787
88+
89+ @Query(" DELETE FROM subs_config WHERE type=${AppGroupType } AND subs_item_id=:subsItemId AND app_id=:appId AND group_key IN (:keyList)" )
90+ suspend fun batchDeleteAppGroupConfig (
91+ subsItemId : Long ,
92+ appId : String ,
93+ keyList : List <Int >
94+ ): Int
95+
6896 @Query(" DELETE FROM subs_config WHERE type=${GlobalGroupType } AND subs_item_id=:subsItemId AND group_key=:groupKey" )
6997 suspend fun deleteGlobalGroupConfig (subsItemId : Long , groupKey : Int ): Int
7098
99+ @Query(" DELETE FROM subs_config WHERE type=${GlobalGroupType } AND subs_item_id=:subsItemId AND group_key IN (:keyList)" )
100+ suspend fun batchDeleteGlobalGroupConfig (subsItemId : Long , keyList : List <Int >): Int
101+
71102 @Query(" SELECT * FROM subs_config WHERE subs_item_id IN (SELECT si.id FROM subs_item si WHERE si.enable = 1)" )
72103 fun queryUsedList (): Flow <List <SubsConfig >>
73104
0 commit comments