回采配置数据库并进场保存和查询测试
This commit is contained in:
@@ -6,9 +6,15 @@ import androidx.room.Room
|
|||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.room.migration.Migration
|
import androidx.room.migration.Migration
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
import com.zmkg.coaloperation.db.dao.MiningCoalHeightDao
|
||||||
|
import com.zmkg.coaloperation.db.dao.MiningWorkingFaceDao
|
||||||
|
import com.zmkg.coaloperation.db.dao.MiningWorkingFaceRecordDao
|
||||||
import com.zmkg.coaloperation.db.dao.TunnelRoofLithologyDao
|
import com.zmkg.coaloperation.db.dao.TunnelRoofLithologyDao
|
||||||
import com.zmkg.coaloperation.db.dao.TunnelWorkingFaceDao
|
import com.zmkg.coaloperation.db.dao.TunnelWorkingFaceDao
|
||||||
import com.zmkg.coaloperation.db.dao.TunnelWorkingFaceRecordDao
|
import com.zmkg.coaloperation.db.dao.TunnelWorkingFaceRecordDao
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningCoalHeightEntity
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceEntity
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceRecordEntity
|
||||||
import com.zmkg.coaloperation.db.entity.tunnel.TunnelRoofLithologyEntity
|
import com.zmkg.coaloperation.db.entity.tunnel.TunnelRoofLithologyEntity
|
||||||
import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceEntity
|
import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceEntity
|
||||||
import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceRecordEntity
|
import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceRecordEntity
|
||||||
@@ -18,6 +24,9 @@ import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceRecordEntity
|
|||||||
TunnelWorkingFaceEntity::class,
|
TunnelWorkingFaceEntity::class,
|
||||||
TunnelWorkingFaceRecordEntity::class,
|
TunnelWorkingFaceRecordEntity::class,
|
||||||
TunnelRoofLithologyEntity::class,
|
TunnelRoofLithologyEntity::class,
|
||||||
|
MiningWorkingFaceEntity::class,
|
||||||
|
MiningWorkingFaceRecordEntity::class,
|
||||||
|
MiningCoalHeightEntity::class,
|
||||||
],
|
],
|
||||||
version = 1,
|
version = 1,
|
||||||
exportSchema = true
|
exportSchema = true
|
||||||
@@ -26,6 +35,9 @@ abstract class AppDatabase : RoomDatabase() {
|
|||||||
abstract fun tunnelWorkingFaceDao(): TunnelWorkingFaceDao
|
abstract fun tunnelWorkingFaceDao(): TunnelWorkingFaceDao
|
||||||
abstract fun tunnelWorkingFaceRecordDao(): TunnelWorkingFaceRecordDao
|
abstract fun tunnelWorkingFaceRecordDao(): TunnelWorkingFaceRecordDao
|
||||||
abstract fun tunnelRoofLithologyDao(): TunnelRoofLithologyDao
|
abstract fun tunnelRoofLithologyDao(): TunnelRoofLithologyDao
|
||||||
|
abstract fun miningWorkingFaceDao(): MiningWorkingFaceDao
|
||||||
|
abstract fun miningWorkingFaceRecordDao(): MiningWorkingFaceRecordDao
|
||||||
|
abstract fun miningCoalHeightDao(): MiningCoalHeightDao
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@Volatile
|
@Volatile
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.zmkg.coaloperation.db.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import androidx.room.Update
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningCoalHeightEntity
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface MiningCoalHeightDao {
|
||||||
|
@Insert
|
||||||
|
fun insert(entity: MiningCoalHeightEntity): Long
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun insertList(list: MutableList<MiningCoalHeightEntity>): Array<Long>
|
||||||
|
|
||||||
|
@Update
|
||||||
|
fun update(entity: MiningCoalHeightEntity)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_coal_height WHERE recordId = :recordId ORDER BY createTime ASC")
|
||||||
|
fun getEntityList(recordId: Long): MutableList<MiningCoalHeightEntity>?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_coal_height WHERE dataState = :dataState ORDER BY createTime ASC")
|
||||||
|
fun getEntityListByState(dataState: String): MutableList<MiningCoalHeightEntity>?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_coal_height WHERE surfaceId = :surfaceId ORDER BY createTime ASC")
|
||||||
|
fun getEntityListByFaceId(surfaceId: Long): MutableList<MiningCoalHeightEntity>?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_coal_height WHERE surfaceId = :surfaceId AND recordId = :recordId ORDER BY createTime ASC")
|
||||||
|
fun getEntityListByRecordId(
|
||||||
|
surfaceId: Long,
|
||||||
|
recordId: Long
|
||||||
|
): MutableList<MiningCoalHeightEntity>?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_coal_height WHERE coalId = :lithologyId")
|
||||||
|
fun getEntityById(lithologyId: Long): MiningCoalHeightEntity?
|
||||||
|
|
||||||
|
@Query("DELETE FROM mining_coal_height")
|
||||||
|
fun deleteAll(): Int
|
||||||
|
|
||||||
|
@Query("DELETE FROM mining_coal_height WHERE recordId = :recordId")
|
||||||
|
fun deleteList(recordId: Long): Int
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.zmkg.coaloperation.db.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import androidx.room.RawQuery
|
||||||
|
import androidx.room.Update
|
||||||
|
import androidx.sqlite.db.SupportSQLiteQuery
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceEntity
|
||||||
|
|
||||||
|
//import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface MiningWorkingFaceDao {
|
||||||
|
@Insert
|
||||||
|
fun insert(entity: MiningWorkingFaceEntity): Long
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun insertList(list: MutableList<MiningWorkingFaceEntity>): Array<Long>
|
||||||
|
|
||||||
|
@Update
|
||||||
|
fun update(entity: MiningWorkingFaceEntity)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_working_face ORDER BY createTime DESC")
|
||||||
|
fun getEntityList(): MutableList<MiningWorkingFaceEntity>?
|
||||||
|
|
||||||
|
@RawQuery
|
||||||
|
fun getEntityListBySql(query: SupportSQLiteQuery): MutableList<MiningWorkingFaceEntity>?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_working_face WHERE dataState = :dataState ORDER BY createTime DESC")
|
||||||
|
fun getEntityListByState(dataState: String): MutableList<MiningWorkingFaceEntity>?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_working_face WHERE surfaceId = :surfaceId")
|
||||||
|
fun getEntityById(surfaceId: Long): MiningWorkingFaceEntity?
|
||||||
|
|
||||||
|
@Query("DELETE FROM mining_working_face")
|
||||||
|
fun deleteAll(): Int
|
||||||
|
|
||||||
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
package com.zmkg.coaloperation.db.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import androidx.room.Update
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceRecordEntity
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface MiningWorkingFaceRecordDao {
|
||||||
|
@Insert
|
||||||
|
fun insert(entity: MiningWorkingFaceRecordEntity): Long
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun insertList(list: MutableList<MiningWorkingFaceRecordEntity>): Array<Long>
|
||||||
|
|
||||||
|
@Update
|
||||||
|
fun update(entity: MiningWorkingFaceRecordEntity)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_working_face_record WHERE surfaceId = :surfaceId ORDER BY createTime DESC")
|
||||||
|
fun getEntityList(surfaceId: Long): MutableList<MiningWorkingFaceRecordEntity>?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_working_face_record WHERE dataState = :dataState ORDER BY createTime DESC")
|
||||||
|
fun getEntityListByState(dataState: String): MutableList<MiningWorkingFaceRecordEntity>?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_working_face_record WHERE surfaceId = :recordId")
|
||||||
|
fun getEntityById(recordId: Long): MiningWorkingFaceRecordEntity
|
||||||
|
|
||||||
|
@Query("SELECT * FROM mining_working_face_record WHERE surfaceId = :surfaceId AND latestRecordState = '1' ORDER BY createTime DESC LIMIT 1")
|
||||||
|
fun getLastEntity(surfaceId: Long): MiningWorkingFaceRecordEntity?
|
||||||
|
|
||||||
|
@Query("DELETE FROM mining_working_face_record")
|
||||||
|
fun deleteAll(): Int
|
||||||
|
}
|
||||||
+10
-15
@@ -9,32 +9,27 @@ import kotlinx.parcelize.Parcelize
|
|||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 回采工作面-顶板岩性数据表
|
* 回采工作面-煤层厚度数据表
|
||||||
*/
|
*/
|
||||||
@Parcelize
|
@Parcelize
|
||||||
@Entity(tableName = "mining_roof_lithology")
|
@Entity(tableName = "mining_coal_height")
|
||||||
class MiningRoofLithologyEntity (
|
class MiningCoalHeightEntity (
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 岩性Id
|
* 煤层Id
|
||||||
*/
|
*/
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
var lithologyId: Long = 0,
|
var coalId: Long = 0,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 岩性类型名称
|
* 支架号
|
||||||
*/
|
*/
|
||||||
var lithologyType: String = "",
|
var supportNo: String = "",
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 岩性值结束
|
* 煤层厚度值
|
||||||
*/
|
*/
|
||||||
var positionEnd: String = "",
|
var coalHeight: String = "",
|
||||||
|
|
||||||
/**
|
|
||||||
* 岩性值起始
|
|
||||||
*/
|
|
||||||
var positionStart: String = "",
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 工作面id
|
* 工作面id
|
||||||
@@ -62,5 +57,5 @@ class MiningRoofLithologyEntity (
|
|||||||
var dataState: String = "0"
|
var dataState: String = "0"
|
||||||
): Parcelable {
|
): Parcelable {
|
||||||
@Ignore
|
@Ignore
|
||||||
constructor():this(lithologyId = 0)
|
constructor():this(coalId = 0)
|
||||||
}
|
}
|
||||||
+1
-1
@@ -93,7 +93,7 @@ data class MiningWorkingFaceRecordEntity (
|
|||||||
var latestRecordState: String = "0",
|
var latestRecordState: String = "0",
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
var mineWorkingLithologyList: MutableList<MiningRoofLithologyEntity>? = null,
|
var coalHeightList: MutableList<MiningCoalHeightEntity>? = null,
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
var operationType: String = "1"
|
var operationType: String = "1"
|
||||||
|
|||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package com.zmkg.coaloperation.db.repository
|
||||||
|
|
||||||
|
import com.zmkg.coaloperation.db.dao.MiningCoalHeightDao
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningCoalHeightEntity
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
class MiningCoalHeightRepository(private val dao: MiningCoalHeightDao) {
|
||||||
|
suspend fun getEntityList(recordId: Long) = withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityList(recordId)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getEntityListByState(dataState: String) = withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityListByState(dataState)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun insert(entity: MiningCoalHeightEntity) = withContext(Dispatchers.IO) {
|
||||||
|
dao.insert(entity)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun insertList(list: MutableList<MiningCoalHeightEntity>) =
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
dao.insertList(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun update(entity: MiningCoalHeightEntity) = withContext(Dispatchers.IO) {
|
||||||
|
dao.update(entity)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getEntityListByFaceId(surfaceId: Long) = withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityListByFaceId(surfaceId)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getEntityListByRecordId(surfaceId: Long, recordId: Long) =
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityListByRecordId(surfaceId, recordId)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getEntityById(lithologyId: Long) = withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityById(lithologyId)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun deleteAll() = withContext(Dispatchers.IO) {
|
||||||
|
dao.deleteAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun deleteList(recordId: Long) = withContext(Dispatchers.IO) {
|
||||||
|
dao.deleteList(recordId)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
package com.zmkg.coaloperation.db.repository
|
||||||
|
|
||||||
|
import com.zmkg.coaloperation.db.dao.MiningWorkingFaceRecordDao
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceRecordEntity
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
class MiningWorkingFaceRecordRepository(private val dao: MiningWorkingFaceRecordDao) {
|
||||||
|
suspend fun getEntityList(surfaceId: Long) = withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityList(surfaceId)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getEntityListByState(dataState: String) =
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityListByState(dataState)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun insert(entity: MiningWorkingFaceRecordEntity) = withContext(Dispatchers.IO) {
|
||||||
|
dao.insert(entity)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun insertList(list: MutableList<MiningWorkingFaceRecordEntity>) =
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
dao.insertList(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun update(entity: MiningWorkingFaceRecordEntity) = withContext(Dispatchers.IO) {
|
||||||
|
dao.update(entity)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getEntityById(faceId: Long) = withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityById(faceId)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getLastEntity(surfaceId: Long) = withContext(Dispatchers.IO) {
|
||||||
|
dao.getLastEntity(surfaceId)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun deleteAll() = withContext(Dispatchers.IO) {
|
||||||
|
dao.deleteAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package com.zmkg.coaloperation.db.repository
|
||||||
|
|
||||||
|
import androidx.sqlite.db.SupportSQLiteQuery
|
||||||
|
import com.zmkg.coaloperation.db.dao.MiningWorkingFaceDao
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceEntity
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
class MiningWorkingFaceRepository(private val dao: MiningWorkingFaceDao) {
|
||||||
|
suspend fun getEntityList() = withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityList()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getEntityListBySql(query: SupportSQLiteQuery) = withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityListBySql(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getEntityListByState(dataState: String) = withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityListByState(dataState)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun insert(entity: MiningWorkingFaceEntity) = withContext(Dispatchers.IO) {
|
||||||
|
dao.insert(entity)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun insertList(list: MutableList<MiningWorkingFaceEntity>) = withContext(Dispatchers.IO) {
|
||||||
|
dao.insertList(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun update(entity: MiningWorkingFaceEntity) = withContext(Dispatchers.IO) {
|
||||||
|
dao.update(entity)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getEntityById(faceId: Long) = withContext(Dispatchers.IO) {
|
||||||
|
dao.getEntityById(faceId)
|
||||||
|
}
|
||||||
|
suspend fun deleteAll() = withContext(Dispatchers.IO) {
|
||||||
|
dao.deleteAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
+89
@@ -0,0 +1,89 @@
|
|||||||
|
package com.zmkg.coaloperation.db.viewmodel
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.lifecycle.AndroidViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import com.zmkg.coaloperation.db.AppDatabase
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningCoalHeightEntity
|
||||||
|
import com.zmkg.coaloperation.db.repository.MiningCoalHeightRepository
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class MiningCoalHeightViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
|
private val repository: MiningCoalHeightRepository
|
||||||
|
|
||||||
|
init {
|
||||||
|
val dao = AppDatabase.getDatabase(application).miningCoalHeightDao()
|
||||||
|
repository = MiningCoalHeightRepository(dao)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEntityList(recordId: Long, action: (MutableList<MiningCoalHeightEntity>?) -> Unit) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
val list: MutableList<MiningCoalHeightEntity>? = repository.getEntityList(recordId)
|
||||||
|
action(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEntityListByState(
|
||||||
|
dataState: String,
|
||||||
|
action: (MutableList<MiningCoalHeightEntity>?) -> Unit
|
||||||
|
) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
val list: MutableList<MiningCoalHeightEntity>? =
|
||||||
|
repository.getEntityListByState(dataState)
|
||||||
|
action(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEntityListByFaceId(
|
||||||
|
surfaceId: Long,
|
||||||
|
action: (MutableList<MiningCoalHeightEntity>?) -> Unit
|
||||||
|
) = viewModelScope.launch {
|
||||||
|
val list: MutableList<MiningCoalHeightEntity>? =
|
||||||
|
repository.getEntityListByFaceId(surfaceId)
|
||||||
|
action(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEntityListByRecordId(
|
||||||
|
surfaceId: Long,
|
||||||
|
recordId: Long,
|
||||||
|
action: (MutableList<MiningCoalHeightEntity>?) -> Unit
|
||||||
|
) = viewModelScope.launch {
|
||||||
|
val list: MutableList<MiningCoalHeightEntity>? =
|
||||||
|
repository.getEntityListByRecordId(surfaceId, recordId)
|
||||||
|
action(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun insertList(list: MutableList<MiningCoalHeightEntity>, action: () -> Unit = {}) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
repository.insertList(list)
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun insert(entity: MiningCoalHeightEntity, action: () -> Unit) = viewModelScope.launch {
|
||||||
|
repository.insert(entity)
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun update(entity: MiningCoalHeightEntity, action: () -> Unit) = viewModelScope.launch {
|
||||||
|
repository.update(entity)
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEntityById(faceId: Long, action: (MiningCoalHeightEntity) -> Unit) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
val entity = repository.getEntityById(faceId)
|
||||||
|
entity?.let { action(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteList(recordId: Long, action: () -> Unit = {}) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
repository.deleteList(recordId)
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteAll(action: () -> Unit = {}) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
repository.deleteAll()
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
package com.zmkg.coaloperation.db.viewmodel
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.lifecycle.AndroidViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import com.zmkg.coaloperation.db.AppDatabase
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceRecordEntity
|
||||||
|
import com.zmkg.coaloperation.db.repository.MiningWorkingFaceRecordRepository
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class MiningWorkingFaceRecordViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
|
private val repository: MiningWorkingFaceRecordRepository
|
||||||
|
|
||||||
|
init {
|
||||||
|
val dao = AppDatabase.getDatabase(application).miningWorkingFaceRecordDao()
|
||||||
|
repository = MiningWorkingFaceRecordRepository(dao)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEntityList(
|
||||||
|
surfaceId: Long,
|
||||||
|
action: (MutableList<MiningWorkingFaceRecordEntity>?) -> Unit
|
||||||
|
) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
val list: MutableList<MiningWorkingFaceRecordEntity>? =
|
||||||
|
repository.getEntityList(surfaceId)
|
||||||
|
action(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEntityListByState(
|
||||||
|
dataState: String,
|
||||||
|
action: (MutableList<MiningWorkingFaceRecordEntity>?) -> Unit
|
||||||
|
) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
val list: MutableList<MiningWorkingFaceRecordEntity>? =
|
||||||
|
repository.getEntityListByState(dataState)
|
||||||
|
action(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun insert(entity: MiningWorkingFaceRecordEntity, action: () -> Unit) = viewModelScope.launch {
|
||||||
|
repository.insert(entity)
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun insertList(list: MutableList<MiningWorkingFaceRecordEntity>, action: () -> Unit = {}) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
repository.insertList(list)
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun update(entity: MiningWorkingFaceRecordEntity, action: () -> Unit) = viewModelScope.launch {
|
||||||
|
repository.update(entity)
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEntityById(recordId: Long) = viewModelScope.launch {
|
||||||
|
repository.getEntityById(recordId)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getLastEntity(surfaceId: Long, action: (MiningWorkingFaceRecordEntity?) -> Unit) = viewModelScope.launch {
|
||||||
|
val record = repository.getLastEntity(surfaceId)
|
||||||
|
action(record)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteAll(action: () -> Unit={}) = viewModelScope.launch {
|
||||||
|
repository.deleteAll()
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
package com.zmkg.coaloperation.db.viewmodel
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.lifecycle.AndroidViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||||
|
import androidx.sqlite.db.SupportSQLiteQuery
|
||||||
|
import com.zmkg.coaloperation.db.AppDatabase
|
||||||
|
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceEntity
|
||||||
|
import com.zmkg.coaloperation.db.repository.MiningWorkingFaceRepository
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class MiningWorkingFaceViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
|
private val repository: MiningWorkingFaceRepository
|
||||||
|
|
||||||
|
val faceList = MutableSharedFlow<MutableList<MiningWorkingFaceEntity>?>()
|
||||||
|
val faceListByState = MutableSharedFlow<MutableList<MiningWorkingFaceEntity>?>()
|
||||||
|
val insertOne = MutableSharedFlow<Long>()
|
||||||
|
val updateOne = MutableSharedFlow<Boolean>()
|
||||||
|
val insertArray = MutableSharedFlow<Array<Long>>()
|
||||||
|
val queryOne = MutableSharedFlow<MiningWorkingFaceEntity>()
|
||||||
|
val deleteFinish = MutableSharedFlow<Boolean>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
val dao = AppDatabase.getDatabase(application).miningWorkingFaceDao()
|
||||||
|
repository = MiningWorkingFaceRepository(dao)
|
||||||
|
}
|
||||||
|
|
||||||
|
// fun getEntityList() = viewModelScope.launch {
|
||||||
|
// val list: MutableList<MiningWorkingFaceEntity>? = repository.getEntityList()
|
||||||
|
// faceList.emit(list)
|
||||||
|
// }
|
||||||
|
|
||||||
|
fun getEntityListByUserId(userId:String) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
val sql = buildString {
|
||||||
|
append("SELECT * FROM mining_working_face WHERE 1=1 ")
|
||||||
|
if (userId.isNotBlank()) {
|
||||||
|
append(" AND userId = $userId")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val query = SimpleSQLiteQuery(sql)
|
||||||
|
val list: MutableList<MiningWorkingFaceEntity>? = repository.getEntityListBySql(query)
|
||||||
|
faceList.emit(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEntityListBySql(
|
||||||
|
query: SupportSQLiteQuery,
|
||||||
|
action: (MutableList<MiningWorkingFaceEntity>?) -> Unit
|
||||||
|
) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
val list: MutableList<MiningWorkingFaceEntity>? = repository.getEntityListBySql(query)
|
||||||
|
action(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEntityListByState(dataState: String) = viewModelScope.launch {
|
||||||
|
val list: MutableList<MiningWorkingFaceEntity>? = repository.getEntityListByState(dataState)
|
||||||
|
faceListByState.emit(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun insert(entity: MiningWorkingFaceEntity) = viewModelScope.launch {
|
||||||
|
val faceId = repository.insert(entity)
|
||||||
|
insertOne.emit(faceId)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun insertList(list: MutableList<MiningWorkingFaceEntity>) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
val array = repository.insertList(list)
|
||||||
|
insertArray.emit(array)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun update(entity: MiningWorkingFaceEntity) = viewModelScope.launch {
|
||||||
|
repository.update(entity)
|
||||||
|
updateOne.emit(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getEntityById(faceId: Long) =
|
||||||
|
viewModelScope.launch {
|
||||||
|
val entity = repository.getEntityById(faceId)
|
||||||
|
entity?.let {
|
||||||
|
queryOne.emit(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteAll() =
|
||||||
|
viewModelScope.launch {
|
||||||
|
repository.deleteAll()
|
||||||
|
deleteFinish.emit(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
-20
@@ -4,6 +4,10 @@ import android.os.Bundle
|
|||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.zmkg.coaloperation.R
|
import com.zmkg.coaloperation.R
|
||||||
import com.zmkg.coaloperation.adapter.AddMiningFaceAdapter
|
import com.zmkg.coaloperation.adapter.AddMiningFaceAdapter
|
||||||
@@ -13,10 +17,15 @@ import com.zmkg.coaloperation.bean.AddMiningFaceItem
|
|||||||
import com.zmkg.coaloperation.bean.WorkOption
|
import com.zmkg.coaloperation.bean.WorkOption
|
||||||
import com.zmkg.coaloperation.databinding.ActivityAddMiningFaceBinding
|
import com.zmkg.coaloperation.databinding.ActivityAddMiningFaceBinding
|
||||||
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceEntity
|
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceEntity
|
||||||
|
import com.zmkg.coaloperation.db.viewmodel.MiningWorkingFaceViewModel
|
||||||
import com.zmkg.coaloperation.ui.tunneling.activity.AddWorkingFaceActivity
|
import com.zmkg.coaloperation.ui.tunneling.activity.AddWorkingFaceActivity
|
||||||
import com.zmkg.coaloperation.ui.tunneling.activity.WorkingFaceDetailActivity
|
import com.zmkg.coaloperation.ui.tunneling.activity.WorkingFaceDetailActivity
|
||||||
import com.zmkg.coaloperation.utils.DictUtils
|
import com.zmkg.coaloperation.utils.DictUtils
|
||||||
import com.zmkg.coaloperation.utils.PickerUtil
|
import com.zmkg.coaloperation.utils.PickerUtil
|
||||||
|
import com.zmkg.coaloperation.utils.SpTool
|
||||||
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
import org.greenrobot.eventbus.ThreadMode
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
|
|
||||||
@@ -48,6 +57,9 @@ class AddMiningFaceActivity :
|
|||||||
private var faceDetail: MiningWorkingFaceEntity? = null
|
private var faceDetail: MiningWorkingFaceEntity? = null
|
||||||
|
|
||||||
private val miningList = mutableListOf<AddMiningFaceItem>()
|
private val miningList = mutableListOf<AddMiningFaceItem>()
|
||||||
|
private val workingFaceViewModel: MiningWorkingFaceViewModel by lazy {
|
||||||
|
ViewModelProvider(this)[MiningWorkingFaceViewModel::class.java]
|
||||||
|
}
|
||||||
private val addFaceAdapter by lazy {
|
private val addFaceAdapter by lazy {
|
||||||
AddMiningFaceAdapter(miningList).apply {
|
AddMiningFaceAdapter(miningList).apply {
|
||||||
addChildClickViewIds(R.id.tvSelectValue, R.id.imgExpand)
|
addChildClickViewIds(R.id.tvSelectValue, R.id.imgExpand)
|
||||||
@@ -74,14 +86,14 @@ class AddMiningFaceActivity :
|
|||||||
when (stringExtra) {
|
when (stringExtra) {
|
||||||
WorkFaceType.ADD.name -> {
|
WorkFaceType.ADD.name -> {
|
||||||
currentFaceType = WorkFaceType.ADD
|
currentFaceType = WorkFaceType.ADD
|
||||||
mBinding.confirm.text = "确认新增"
|
mBinding.btnConfirm.text = "确认新增"
|
||||||
mBinding.toolbarLay.title = "新增工作面"
|
mBinding.toolbarLay.title = "新增工作面"
|
||||||
initMiningList(true)
|
initMiningList(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkFaceType.EDIT.name -> {
|
WorkFaceType.EDIT.name -> {
|
||||||
currentFaceType = WorkFaceType.EDIT
|
currentFaceType = WorkFaceType.EDIT
|
||||||
mBinding.confirm.text = "确认修改"
|
mBinding.btnConfirm.text = "确认修改"
|
||||||
mBinding.toolbarLay.title = "修改工作面"
|
mBinding.toolbarLay.title = "修改工作面"
|
||||||
faceDetail =
|
faceDetail =
|
||||||
intent.getParcelableExtra(WorkingFaceDetailActivity.Companion.FACE_WORK_DETAIL_DATA) as MiningWorkingFaceEntity?
|
intent.getParcelableExtra(WorkingFaceDetailActivity.Companion.FACE_WORK_DETAIL_DATA) as MiningWorkingFaceEntity?
|
||||||
@@ -123,11 +135,33 @@ class AddMiningFaceActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun bindEvent() {
|
override fun bindEvent() {
|
||||||
|
mBinding.btnConfirm.setOnClickListener {
|
||||||
|
if (currentFaceType == WorkFaceType.ADD) {
|
||||||
|
addNewFace()
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
if (currentFaceType == WorkFaceType.EDIT) {
|
||||||
|
editFace()
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
private var workingFaceEntity: MiningWorkingFaceEntity?=null
|
||||||
override fun createObserve() {
|
override fun createObserve() {
|
||||||
super.createObserve()
|
super.createObserve()
|
||||||
|
lifecycleScope.launch {
|
||||||
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
||||||
|
launch {
|
||||||
|
workingFaceViewModel.insertOne.collectLatest{
|
||||||
|
showToast("工作面新增完成")
|
||||||
|
workingFaceEntity?.let {
|
||||||
|
EventBus.getDefault().post(workingFaceEntity!!)
|
||||||
|
}
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processClick(v: View?) {
|
override fun processClick(v: View?) {
|
||||||
@@ -142,17 +176,6 @@ class AddMiningFaceActivity :
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
R.id.confirm -> {
|
|
||||||
if (currentFaceType == WorkFaceType.ADD) {
|
|
||||||
addNewFace()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (currentFaceType == WorkFaceType.EDIT) {
|
|
||||||
editFace()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,13 +183,16 @@ class AddMiningFaceActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addNewFace() {
|
private fun addNewFace() {
|
||||||
// workingFaceViewModel.insert(workingFaceEntity) {
|
workingFaceEntity = MiningWorkingFaceEntity().also {
|
||||||
// showToast("工作面新增完成")
|
it.surfaceId = System.currentTimeMillis()
|
||||||
// EventBus.getDefault().post(workingFaceEntity)
|
it.surfaceName = miningList[0].funcValue
|
||||||
// finish()
|
it.userId = SpTool.getString(SpTool.USER_ID)
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
workingFaceViewModel.insert(workingFaceEntity!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun editFace() {
|
private fun editFace() {
|
||||||
// workingFaceViewModel.update(workingFaceEntity) {
|
// workingFaceViewModel.update(workingFaceEntity) {
|
||||||
// showToast("工作面修改完成")
|
// showToast("工作面修改完成")
|
||||||
|
|||||||
+91
-37
@@ -2,7 +2,12 @@ package com.zmkg.coaloperation.ui.mining.activity
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.zmkg.coaloperation.R
|
import com.zmkg.coaloperation.R
|
||||||
import com.zmkg.coaloperation.adapter.MiningWorkingFaceAdapter
|
import com.zmkg.coaloperation.adapter.MiningWorkingFaceAdapter
|
||||||
@@ -16,10 +21,18 @@ import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceEntity
|
|||||||
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceRecordEntity
|
import com.zmkg.coaloperation.db.entity.mining.MiningWorkingFaceRecordEntity
|
||||||
import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceEntity
|
import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceEntity
|
||||||
import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceRecordEntity
|
import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceRecordEntity
|
||||||
|
import com.zmkg.coaloperation.db.viewmodel.MiningWorkingFaceRecordViewModel
|
||||||
|
import com.zmkg.coaloperation.db.viewmodel.MiningWorkingFaceViewModel
|
||||||
|
import com.zmkg.coaloperation.db.viewmodel.TunnelWorkingFaceRecordViewModel
|
||||||
|
import com.zmkg.coaloperation.db.viewmodel.TunnelWorkingFaceViewModel
|
||||||
import com.zmkg.coaloperation.ui.mining.activity.AddMiningFaceActivity.Companion.WORK_FACE_TYPE
|
import com.zmkg.coaloperation.ui.mining.activity.AddMiningFaceActivity.Companion.WORK_FACE_TYPE
|
||||||
import com.zmkg.coaloperation.ui.mining.activity.AddMiningFaceActivity.WorkFaceType
|
import com.zmkg.coaloperation.ui.mining.activity.AddMiningFaceActivity.WorkFaceType
|
||||||
import com.zmkg.coaloperation.ui.tunneling.activity.AddWorkingFaceRecordActivity
|
import com.zmkg.coaloperation.ui.tunneling.activity.AddWorkingFaceRecordActivity
|
||||||
import com.zmkg.coaloperation.ui.tunneling.activity.WorkingFaceStatisticsActivity
|
import com.zmkg.coaloperation.ui.tunneling.activity.WorkingFaceStatisticsActivity
|
||||||
|
import com.zmkg.coaloperation.utils.SpTool
|
||||||
|
import com.zmkg.coaloperation.utils.toJsonString
|
||||||
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
import org.greenrobot.eventbus.ThreadMode
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
|
|
||||||
@@ -29,6 +42,16 @@ import org.greenrobot.eventbus.ThreadMode
|
|||||||
class MiningActivity :
|
class MiningActivity :
|
||||||
BaseVMBActivity<TestViewModel, ActivityMiningBinding>(R.layout.activity_mining) {
|
BaseVMBActivity<TestViewModel, ActivityMiningBinding>(R.layout.activity_mining) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "MiningActivity"
|
||||||
|
}
|
||||||
|
|
||||||
|
private val workingFaceViewModel: MiningWorkingFaceViewModel by lazy {
|
||||||
|
ViewModelProvider(this)[MiningWorkingFaceViewModel::class.java]
|
||||||
|
}
|
||||||
|
private val workingFaceRecordViewModel: MiningWorkingFaceRecordViewModel by lazy {
|
||||||
|
ViewModelProvider(this)[MiningWorkingFaceRecordViewModel::class.java]
|
||||||
|
}
|
||||||
private val workingFaceList = mutableListOf<MiningWorkingFaceEntity>()
|
private val workingFaceList = mutableListOf<MiningWorkingFaceEntity>()
|
||||||
|
|
||||||
private val workingFaceAdapter: MiningWorkingFaceAdapter by lazy {
|
private val workingFaceAdapter: MiningWorkingFaceAdapter by lazy {
|
||||||
@@ -36,7 +59,10 @@ class MiningActivity :
|
|||||||
setOnItemChildClickListener { _, view, position ->
|
setOnItemChildClickListener { _, view, position ->
|
||||||
if (view.id == R.id.llWorkingFace) {
|
if (view.id == R.id.llWorkingFace) {
|
||||||
toActivity(MiningFaceStatisticsActivity::class.java, Bundle().apply {
|
toActivity(MiningFaceStatisticsActivity::class.java, Bundle().apply {
|
||||||
putParcelable(WorkingFaceStatisticsActivity.FACE_DETAIL, workingFaceList[position])
|
putParcelable(
|
||||||
|
WorkingFaceStatisticsActivity.FACE_DETAIL,
|
||||||
|
workingFaceList[position]
|
||||||
|
)
|
||||||
})
|
})
|
||||||
return@setOnItemChildClickListener
|
return@setOnItemChildClickListener
|
||||||
}
|
}
|
||||||
@@ -52,7 +78,10 @@ class MiningActivity :
|
|||||||
}
|
}
|
||||||
if (view.id == R.id.start_record) {
|
if (view.id == R.id.start_record) {
|
||||||
toActivity(MiningFaceRecordActivity::class.java, Bundle().apply {
|
toActivity(MiningFaceRecordActivity::class.java, Bundle().apply {
|
||||||
putString(MiningFaceRecordActivity.WORK_RECORD_TYPE, MiningFaceRecordActivity.WorkRecordType.ADD.name)
|
putString(
|
||||||
|
MiningFaceRecordActivity.WORK_RECORD_TYPE,
|
||||||
|
MiningFaceRecordActivity.WorkRecordType.ADD.name
|
||||||
|
)
|
||||||
putLong(
|
putLong(
|
||||||
MiningFaceRecordActivity.FACE_ID,
|
MiningFaceRecordActivity.FACE_ID,
|
||||||
workingFaceList[position].surfaceId
|
workingFaceList[position].surfaceId
|
||||||
@@ -79,41 +108,53 @@ class MiningActivity :
|
|||||||
val surfaceId02 = System.currentTimeMillis()
|
val surfaceId02 = System.currentTimeMillis()
|
||||||
val surfaceId03 = System.currentTimeMillis()
|
val surfaceId03 = System.currentTimeMillis()
|
||||||
val recordList = mutableListOf<MiningWorkingFaceRecordEntity>()
|
val recordList = mutableListOf<MiningWorkingFaceRecordEntity>()
|
||||||
recordList.add(MiningWorkingFaceRecordEntity(
|
recordList.add(
|
||||||
recordId = System.currentTimeMillis(),
|
MiningWorkingFaceRecordEntity(
|
||||||
surfaceId = surfaceId01,
|
recordId = System.currentTimeMillis(),
|
||||||
recordPerson = "张三",
|
surfaceId = surfaceId01,
|
||||||
workingDate = "2025-09-19 10:50:15"
|
recordPerson = "张三",
|
||||||
))
|
workingDate = "2025-09-19 10:50:15"
|
||||||
recordList.add(MiningWorkingFaceRecordEntity(
|
)
|
||||||
recordId = System.currentTimeMillis(),
|
)
|
||||||
surfaceId = surfaceId01,
|
recordList.add(
|
||||||
recordPerson = "李四",
|
MiningWorkingFaceRecordEntity(
|
||||||
workingDate = "2025-09-19 15:10:39"
|
recordId = System.currentTimeMillis(),
|
||||||
))
|
surfaceId = surfaceId01,
|
||||||
workingFaceList.add(MiningWorkingFaceEntity(
|
recordPerson = "李四",
|
||||||
surfaceId = surfaceId01,
|
workingDate = "2025-09-19 15:10:39"
|
||||||
surfaceName = "250919回采工作面",
|
)
|
||||||
totalFootage = "256",
|
)
|
||||||
createTime = "2025-09-19 10:27:43",
|
workingFaceList.add(
|
||||||
records = recordList
|
MiningWorkingFaceEntity(
|
||||||
))
|
surfaceId = surfaceId01,
|
||||||
workingFaceList.add(MiningWorkingFaceEntity(
|
surfaceName = "250919回采工作面",
|
||||||
surfaceId = surfaceId02,
|
totalFootage = "256",
|
||||||
surfaceName = "250901回采工作面",
|
createTime = "2025-09-19 10:27:43",
|
||||||
totalFootage = "256",
|
records = recordList
|
||||||
createTime = "2025-09-01 08:20:43"
|
)
|
||||||
))
|
)
|
||||||
workingFaceList.add(MiningWorkingFaceEntity(
|
workingFaceList.add(
|
||||||
surfaceId = surfaceId03,
|
MiningWorkingFaceEntity(
|
||||||
surfaceName = "250810回采工作面",
|
surfaceId = surfaceId02,
|
||||||
totalFootage = "256",
|
surfaceName = "250901回采工作面",
|
||||||
createTime = "2025-09-19 09:09:03"
|
totalFootage = "256",
|
||||||
))
|
createTime = "2025-09-01 08:20:43"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
workingFaceList.add(
|
||||||
|
MiningWorkingFaceEntity(
|
||||||
|
surfaceId = surfaceId03,
|
||||||
|
surfaceName = "250810回采工作面",
|
||||||
|
totalFootage = "256",
|
||||||
|
createTime = "2025-09-19 09:09:03"
|
||||||
|
)
|
||||||
|
)
|
||||||
workingFaceAdapter.notifyDataSetChanged()
|
workingFaceAdapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initData() {
|
override fun initData() {
|
||||||
|
val userId = SpTool.getString(SpTool.USER_ID)
|
||||||
|
workingFaceViewModel.getEntityListByUserId(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun bindEvent() {
|
override fun bindEvent() {
|
||||||
@@ -162,9 +203,9 @@ class MiningActivity :
|
|||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
//新增工作面
|
//新增工作面
|
||||||
val insertIndex = 0
|
val insertIndex = 0
|
||||||
workingFaceList.add(0,event)
|
workingFaceList.add(0, event)
|
||||||
workingFaceAdapter.notifyItemInserted(insertIndex)
|
workingFaceAdapter.notifyItemInserted(insertIndex)
|
||||||
workingFaceAdapter.notifyItemRangeChanged(insertIndex, insertIndex+1)
|
workingFaceAdapter.notifyItemRangeChanged(insertIndex, insertIndex + 1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//修改工作面
|
//修改工作面
|
||||||
@@ -184,7 +225,7 @@ class MiningActivity :
|
|||||||
faceEntity.records?.let { records ->
|
faceEntity.records?.let { records ->
|
||||||
val index = records.indexOfFirst { it.recordId == event.recordId }
|
val index = records.indexOfFirst { it.recordId == event.recordId }
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
records.add(0,event)
|
records.add(0, event)
|
||||||
} else {
|
} else {
|
||||||
records[index] = event
|
records[index] = event
|
||||||
}
|
}
|
||||||
@@ -196,10 +237,23 @@ class MiningActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SuspiciousIndentation")
|
@SuppressLint("SuspiciousIndentation")
|
||||||
private fun getRecordAdapter(position:Int):MiningWorkingFaceRecordAdapter {
|
private fun getRecordAdapter(position: Int): MiningWorkingFaceRecordAdapter {
|
||||||
val viewHolder =
|
val viewHolder =
|
||||||
mBinding.rvMiningList.findViewHolderForLayoutPosition(position) as MiningWorkingFaceAdapter.VH
|
mBinding.rvMiningList.findViewHolderForLayoutPosition(position) as MiningWorkingFaceAdapter.VH
|
||||||
return viewHolder.binding.rvFaceRecord.adapter as MiningWorkingFaceRecordAdapter
|
return viewHolder.binding.rvFaceRecord.adapter as MiningWorkingFaceRecordAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun createObserve() {
|
||||||
|
super.createObserve()
|
||||||
|
lifecycleScope.launch {
|
||||||
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
||||||
|
launch {
|
||||||
|
workingFaceViewModel.faceList.collectLatest {
|
||||||
|
Log.d(TAG, "createObserve: ${it.toJsonString()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.allen.library.shape.ShapeTextView
|
<com.allen.library.shape.ShapeTextView
|
||||||
android:id="@+id/confirm"
|
android:id="@+id/btnConfirm"
|
||||||
android:layout_width="250dp"
|
android:layout_width="250dp"
|
||||||
android:layout_height="52dp"
|
android:layout_height="52dp"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
android:id="@+id/tvItemUnit"
|
android:id="@+id/tvItemUnit"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginStart="20dp"
|
android:layout_marginStart="18dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
android:id="@+id/btnDataPull"
|
android:id="@+id/btnDataPull"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="20dp"
|
android:layout_marginEnd="15dp"
|
||||||
android:background="@drawable/bg_stroke_gray"
|
android:background="@drawable/bg_stroke_gray"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
android:id="@+id/btnDataPush"
|
android:id="@+id/btnDataPush"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="20dp"
|
android:layout_marginEnd="15dp"
|
||||||
android:background="@drawable/bg_stroke_gray"
|
android:background="@drawable/bg_stroke_gray"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|||||||
Reference in New Issue
Block a user