接口数据拉取、保存本地数据库、工作面、记录、岩性等数据显示、增加、修改功能

This commit is contained in:
2025-09-12 13:38:09 +08:00
parent cc5ea0f2c6
commit b743bf566b
35 changed files with 742 additions and 188 deletions
+1
View File
@@ -103,5 +103,6 @@ dependencies {
// ViewModel
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
implementation 'com.google.code.gson:gson:2.10.1'
}
@@ -25,12 +25,6 @@
"iconNormal": "report_tab",
"iconSelected": "report_select_tab"
},
{
"tabName": "消息",
"tabTag": "key_message_fragment",
"iconNormal": "message_tab",
"iconSelected": "message_select_tab"
},
{
"tabName": "我的",
"tabTag": "key_my_fragment",
@@ -3,6 +3,7 @@ package com.zmkg.coaloperation
import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import android.os.Bundle
import android.os.StrictMode
import android.text.TextUtils
@@ -36,6 +37,16 @@ class MyApplication : Application(), ViewModelStoreOwner {
@JvmStatic
lateinit var appViewModel: AppViewModel
val TAG = MyApplication::class.java.simpleName
@Volatile
private var sharedPref: SharedPreferences? = null
fun getSharedPref(): SharedPreferences? {
if (sharedPref != null) {
return sharedPref
}
sharedPref = appContext.getSharedPreferences("sp_digital_coal_mining", Context.MODE_PRIVATE)
return sharedPref
}
}
override fun attachBaseContext(base: Context?) {
@@ -2,6 +2,7 @@ package com.zmkg.coaloperation.adapter
import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -16,13 +17,16 @@ import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceEntity
import com.zmkg.coaloperation.ui.tunneling.activity.TunnelingActivity
import com.zmkg.coaloperation.ui.tunneling.activity.WorkingPointActivity
import com.zmkg.coaloperation.utils.ScreenUtil
import com.zmkg.coaloperation.utils.toJsonString
class TunnelWorkingFaceAdapter(var list: MutableList<TunnelWorkingFaceEntity>) :
BaseQuickAdapter<TunnelWorkingFaceEntity, TunnelWorkingFaceAdapter.VH>(
R.layout.list_item_tunnel_working_face, list
) {
companion object {
private const val TAG = "TunnelWorkingFaceAdapter"
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
val inflater = LayoutInflater.from(context)
@@ -47,10 +51,10 @@ class TunnelWorkingFaceAdapter(var list: MutableList<TunnelWorkingFaceEntity>) :
binding.ivExpandRecord.tag = item.isExpandRecord.toString()
binding.rvFaceRecord.let { rv ->
rv.layoutManager = LinearLayoutManager(context)
if (item.recordList == null) {
item.recordList = mutableListOf()
if (item.records == null) {
item.records = mutableListOf()
}
val size = item.recordList!!.size
val size = item.records!!.size
rv.updateLayoutParams {
height = if (size >= 3)
ScreenUtil.dp2px(150F)
@@ -60,19 +64,20 @@ class TunnelWorkingFaceAdapter(var list: MutableList<TunnelWorkingFaceEntity>) :
rv.isVerticalScrollBarEnabled = size >= 3
rv.isVerticalFadingEdgeEnabled = size < 3
rv.overScrollMode = if (size >= 3) View.OVER_SCROLL_IF_CONTENT_SCROLLS else View.OVER_SCROLL_NEVER
rv.adapter = TunnelWorkingFaceRecordAdapter(item.recordList!!).apply {
rv.adapter = TunnelWorkingFaceRecordAdapter(item.records!!).apply {
setOnItemClickListener { adapter, view, recordPosition ->
// if (recordPosition == 0) {
// //0为头部表示,不需要点击操作
// return@setOnItemClickListener
// }
Log.d(TAG, "convert: ${item.records!![recordPosition].toJsonString()}")
context.let { ctx ->
if (ctx is TunnelingActivity) {
ctx.toActivity(WorkingPointActivity::class.java, Bundle().apply {
putString(WorkingPointActivity.FACE_NAME, item.surfaceName)
putParcelable(
WorkingPointActivity.FACE_RECORD,
item.recordList!![recordPosition]
item.records!![recordPosition]
)
})
}
@@ -13,6 +13,7 @@ import com.zmkg.coaloperation.bean.RockItem
import com.zmkg.coaloperation.bean.WorkingFaceItem
import com.zmkg.coaloperation.databinding.ListItemRockBinding
import com.zmkg.coaloperation.databinding.ListItemWorkingFaceBinding
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelRoofLithologyEntity
import com.zmkg.coaloperation.utils.ScreenUtil
class WorkingItemAdapter(data: MutableList<WorkingFaceItem>) :
@@ -84,7 +85,7 @@ class WorkingItemAdapter(data: MutableList<WorkingFaceItem>) :
binding.llContainer.visibility = View.GONE
}
private fun addChildToContainer(container: LinearLayout, list: MutableList<RockItem>?) {
private fun addChildToContainer(container: LinearLayout, list: MutableList<TunnelRoofLithologyEntity>?) {
list?.forEach { item ->
val itemBinding = ListItemRockBinding.inflate(
LayoutInflater.from(context),
@@ -95,17 +96,17 @@ class WorkingItemAdapter(data: MutableList<WorkingFaceItem>) :
tvRockStartLen.let {
it.focusable = EditText.NOT_FOCUSABLE
it.setOnKeyListener(null)
it.setText("${item.startLen}")
it.setText(item.positionStart)
}
tvRockEndLen.let {
it.focusable = EditText.NOT_FOCUSABLE
it.setOnKeyListener(null)
it.setText("${item.endLen}")
it.setText(item.positionEnd)
}
tvRockType.let {
it.focusable = EditText.NOT_FOCUSABLE
it.setOnKeyListener(null)
it.setText(item.rockType)
it.setText(item.lithologyType)
}
container.addView(root)
}
@@ -1,9 +1,11 @@
package com.zmkg.coaloperation.bean
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelRoofLithologyEntity
data class WorkingFaceItem(
var name: String? = "",
var value: String? = "",
var items: MutableList<RockItem>? = null,
var items: MutableList<TunnelRoofLithologyEntity>? = null,
var pageType:Int = 0
)
@@ -13,7 +15,7 @@ data class RockItem(
val rockType: String = ""
)
data class WorkTeam(
var teamId:String,
var teamName: String
data class WorkOption(
var id:String,
var name: String
)
@@ -1,11 +1,13 @@
package com.zmkg.coaloperation.data.api
import com.zmkg.coaloperation.data.bean.ApiResponse
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceEntity
import com.zmkg.coaloperation.retorfit.UrlConfig
import com.zmkg.coaloperation.ui.tunneling.bean.FaceWorkDetailBean
import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeBean
import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeItemBean
import com.zmkg.coaloperation.ui.home.bean.WaterLedgerBean
import kotlinx.coroutines.flow.MutableSharedFlow
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.GET
@@ -48,4 +50,10 @@ interface HomeApi {
@POST("/api/mine/tunnelling/surface/add")
suspend fun postTunnellingSurfaceAdd(@Body requestBody: RequestBody): ApiResponse<String>
@GET("/api/mine/tunnelling/surface/detailList")
suspend fun getTunnelHomeList(): ApiResponse<MutableList<TunnelWorkingFaceEntity>?>
@GET("/api/mine/tunnelling/dictionaries")
suspend fun getTunnelAllDict(): ApiResponse<Any?>
}
@@ -3,6 +3,7 @@ package com.zmkg.coaloperation.data.repository
import com.zmkg.coaloperation.base.repository.BaseRepository
import com.zmkg.coaloperation.data.api.HomeApi
import com.zmkg.coaloperation.data.bean.ApiResponse
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceEntity
import com.zmkg.coaloperation.retorfit.RetrofitManager
import com.zmkg.coaloperation.retorfit.RetrofitManager.toRequestBody
import com.zmkg.coaloperation.superfuntion.toJson
@@ -11,6 +12,7 @@ import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingFaceAddBean
import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeBean
import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeItemBean
import com.zmkg.coaloperation.ui.home.bean.WaterLedgerBean
import kotlinx.coroutines.flow.MutableSharedFlow
object HomeRepository : BaseRepository(){
@@ -66,5 +68,16 @@ object HomeRepository : BaseRepository(){
}
}
suspend fun getTunnelHomeList() : ApiResponse<MutableList<TunnelWorkingFaceEntity>?> {
return apiCall {
service.getTunnelHomeList()
}
}
suspend fun getTunnelAllDict() : ApiResponse<Any?> {
return apiCall {
service.getTunnelAllDict()
}
}
}
@@ -19,7 +19,7 @@ import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceRecordEntity
TunnelWorkingFaceRecordEntity::class,
TunnelRoofLithologyEntity::class,
],
version = 3,
version = 1,
exportSchema = true
)
abstract class AppDatabase : RoomDatabase() {
@@ -44,7 +44,7 @@ abstract class AppDatabase : RoomDatabase() {
}
})
// .addMigrations(MIGRATION_1_2)
.addMigrations(MIGRATION_2_3)
// .addMigrations(MIGRATION_2_3)
.build()
INSTANCE = instance
instance
@@ -2,6 +2,7 @@ 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.entiry.tunnel.TunnelRoofLithologyEntity
@@ -11,18 +12,33 @@ interface TunnelRoofLithologyDao {
@Insert
fun insert(entity: TunnelRoofLithologyEntity): Long
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertList(list: MutableList<TunnelRoofLithologyEntity>): Array<Long>
@Update
fun update(entity: TunnelRoofLithologyEntity)
@Query("SELECT * FROM tunnel_roof_lithology ORDER BY createTime ASC")
fun getEntityList(): MutableList<TunnelRoofLithologyEntity>?
@Query("SELECT * FROM tunnel_roof_lithology WHERE recordId = :recordId ORDER BY createTime ASC")
fun getEntityList(recordId: Long): MutableList<TunnelRoofLithologyEntity>?
@Query("SELECT * FROM tunnel_roof_lithology WHERE dataState = :dataState ORDER BY createTime ASC")
fun getEntityListByState(dataState: String): MutableList<TunnelRoofLithologyEntity>?
@Query("SELECT * FROM tunnel_roof_lithology WHERE surfaceId = :surfaceId ORDER BY createTime ASC")
fun getEntityListByFaceId(surfaceId: Long): MutableList<TunnelRoofLithologyEntity>?
@Query("SELECT * FROM tunnel_roof_lithology WHERE surfaceId = :surfaceId AND recordId = :recordId ORDER BY createTime ASC")
fun getEntityListByRecordId(surfaceId: Long, recordId: Long): MutableList<TunnelRoofLithologyEntity>?
fun getEntityListByRecordId(
surfaceId: Long,
recordId: Long
): MutableList<TunnelRoofLithologyEntity>?
@Query("SELECT * FROM tunnel_roof_lithology WHERE lithologyId = :lithologyId")
fun getEntityById(lithologyId: Long): TunnelRoofLithologyEntity?
@Query("DELETE FROM tunnel_roof_lithology")
fun deleteAll(): Int
@Query("DELETE FROM tunnel_roof_lithology WHERE recordId = :recordId")
fun deleteList(recordId: Long): Int
}
@@ -2,6 +2,7 @@ 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.entiry.tunnel.TunnelWorkingFaceEntity
@@ -13,12 +14,21 @@ interface TunnelWorkingFaceDao {
@Insert
fun insert(entity: TunnelWorkingFaceEntity): Long
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertList(list: MutableList<TunnelWorkingFaceEntity>): Array<Long>
@Update
fun update(entity: TunnelWorkingFaceEntity)
@Query("SELECT * FROM tunnel_working_face ORDER BY createTime ASC")
fun getEntityList(): MutableList<TunnelWorkingFaceEntity>?
@Query("SELECT * FROM tunnel_working_face WHERE dataState = :dataState ORDER BY createTime ASC")
fun getEntityListByState(dataState: String): MutableList<TunnelWorkingFaceEntity>?
@Query("SELECT * FROM tunnel_working_face WHERE surfaceId = :surfaceId")
fun getEntityById(surfaceId: Long): TunnelWorkingFaceEntity?
@Query("DELETE FROM tunnel_working_face")
fun deleteAll(): Int
}
@@ -2,8 +2,10 @@ 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.entiry.tunnel.TunnelWorkingFaceEntity
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceRecordEntity
//import kotlinx.coroutines.flow.Flow
@@ -13,12 +15,21 @@ interface TunnelWorkingFaceRecordDao {
@Insert
fun insert(entity: TunnelWorkingFaceRecordEntity): Long
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertList(list: MutableList<TunnelWorkingFaceRecordEntity>): Array<Long>
@Update
fun update(entity: TunnelWorkingFaceRecordEntity)
@Query("SELECT * FROM tunnel_working_face_record WHERE surfaceId = :surfaceId ORDER BY createTime ASC")
fun getEntityList(surfaceId: Long): MutableList<TunnelWorkingFaceRecordEntity>?
@Query("SELECT * FROM tunnel_working_face_record WHERE dataState = :dataState ORDER BY createTime ASC")
fun getEntityListByState(dataState: String): MutableList<TunnelWorkingFaceRecordEntity>?
@Query("SELECT * FROM tunnel_working_face_record WHERE surfaceId = :recordId")
fun getEntityById(recordId: Long): TunnelWorkingFaceRecordEntity
@Query("DELETE FROM tunnel_working_face_record")
fun deleteAll(): Int
}
@@ -12,42 +12,51 @@ import java.time.LocalDateTime
*/
@Parcelize
@Entity(tableName = "tunnel_roof_lithology")
class TunnelRoofLithologyEntity : Parcelable {
class TunnelRoofLithologyEntity (
/**
* 岩性Id
*/
@PrimaryKey
var lithologyId: Long = 0
var lithologyId: Long = 0,
/**
* 岩性类型名称
*/
var lithologyType: String = ""
var lithologyType: String = "",
/**
* 岩性值结束
*/
var positionEnd: String = ""
var positionEnd: String = "",
/**
* 岩性值起始
*/
var positionStart: String = ""
var positionStart: String = "",
/**
* 工作面id
*/
var surfaceId: Long = 0
var surfaceId: Long = 0,
/**
* 记录id
*/
var recordId: Long = 0
var recordId: Long = 0,
/**
* 创建时间
*/
var createTime: String = DateTimeUtil.formatDateTime(LocalDateTime.now())
var createTime: String? = "",
}
/**
* 更新时间
*/
var updateTime: String? = DateTimeUtil.formatDateTime(LocalDateTime.now()),
/**
* 数据状态:0-默认值,原始数据,1-已修改数据
*/
var dataState: String = "0"
): Parcelable
@@ -14,7 +14,7 @@ import java.time.LocalDateTime
*/
@Parcelize
@Entity(tableName = "tunnel_working_face")
data class TunnelWorkingFaceEntity(
class TunnelWorkingFaceEntity(
// @PrimaryKey(name = "faceId") val id: Int = 0
/**
* 工作面id,本地新增数据使用时间戳保证唯一性
@@ -31,10 +31,12 @@ data class TunnelWorkingFaceEntity(
* 总进尺
*/
var totalFootage: String? = "",
/**
* 累计进尺
*/
var accumulativeFootage: String? = "",
/**
* 剩余进尺
*/
@@ -43,7 +45,7 @@ data class TunnelWorkingFaceEntity(
/**
* 所属煤层编号
*/
var seamId: Int? = 0,
var seamId: Long? = 0,
/**
* 所属煤层名称
@@ -53,7 +55,7 @@ data class TunnelWorkingFaceEntity(
/**
* 所属采区域编号
*/
var areaId: Int? = 0,
var areaId: Long? = 0,
/**
* 所属采区域
@@ -120,14 +122,27 @@ data class TunnelWorkingFaceEntity(
*/
var surfaceSupportForm: String? = "",
var createTime: String = DateTimeUtil.formatDateTime(LocalDateTime.now()),
/**
* 创建时间
*/
var createTime: String? = "",
/**
* 更新时间
*/
var updateTime: String? = DateTimeUtil.formatDateTime(LocalDateTime.now()),
/**
* 数据状态:0-默认值,原始数据,1-已修改数据
*/
var dataState: String = "0",
@Ignore
var recordList: MutableList<TunnelWorkingFaceRecordEntity>? = null,
var records: MutableList<TunnelWorkingFaceRecordEntity>? = null,
@Ignore
var latestRecord: TunnelWorkingFaceRecordEntity? = null,
@Ignore
var isExpandRecord: Boolean = false
) : Parcelable {
// @Ignore
// constructor() : this(surfaceId = 0, recordList = null, isExpandRecord = false)
}
): Parcelable
@@ -11,59 +11,82 @@ import java.time.LocalDateTime
@Parcelize
@Entity(tableName = "tunnel_working_face_record")
data class TunnelWorkingFaceRecordEntity(
data class TunnelWorkingFaceRecordEntity (
/**
* 记录id
*/
@PrimaryKey
var recordId: Long = 0,
/**
* 工作面id
*/
var surfaceId: Long = 0,
/**
* 施工日期
*/
var workingDate: String? = null,
/**
* 记录人
*/
var recordPerson: String? = null,
/**
* 施工班次
*/
var teamShift: String? = null,
/**
* 施工队伍id
*/
var teamId: String? = null,
/**
* 施工队伍名称
*/
var teamName: String? = null,
/**
* 带队班长
*/
var teamLeader: String? = null,
/**
* 本班进尺
*/
var workingFootage: String? = null,
/**
* 煤层倾角
*/
var seamDip: String? = null,
/**
* 煤层高度
*/
var seamHeight: String? = null,
var createTime: String = DateTimeUtil.formatDateTime(LocalDateTime.now()),
/**
* 创建时间
*/
var createTime: String? = "",
/**
* 更新时间
*/
var updateTime: String? = DateTimeUtil.formatDateTime(LocalDateTime.now()),
/**
* 数据状态:0-默认值,原始数据,1-已修改数据
*/
var dataState: String = "0",
@Ignore
var mineWorkingLithologyList: MutableList<TunnelRoofLithologyEntity>? = null,
@Ignore
var operationType: String = "1"
) : Parcelable {
// @Ignore
// constructor() : this(recordId = 0)
}
): Parcelable
@@ -6,14 +6,23 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
class TunnelRoofLithologyRepository(private val dao: TunnelRoofLithologyDao) {
suspend fun getEntityList() = withContext(Dispatchers.IO) {
dao.getEntityList()
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: TunnelRoofLithologyEntity) = withContext(Dispatchers.IO) {
dao.insert(entity)
}
suspend fun insertList(list: MutableList<TunnelRoofLithologyEntity>) =
withContext(Dispatchers.IO) {
dao.insertList(list)
}
suspend fun update(entity: TunnelRoofLithologyEntity) = withContext(Dispatchers.IO) {
dao.update(entity)
}
@@ -22,11 +31,21 @@ class TunnelRoofLithologyRepository(private val dao: TunnelRoofLithologyDao) {
dao.getEntityListByFaceId(surfaceId)
}
suspend fun getEntityListByRecordId(surfaceId: Long, recordId: Long) = withContext(Dispatchers.IO) {
dao.getEntityListByRecordId(surfaceId, recordId)
}
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)
}
}
@@ -10,10 +10,20 @@ class TunnelWorkingFaceRecordRepository(private val dao: TunnelWorkingFaceRecord
dao.getEntityList(surfaceId)
}
suspend fun getEntityListByState(dataState: String) =
withContext(Dispatchers.IO) {
dao.getEntityListByState(dataState)
}
suspend fun insert(entity: TunnelWorkingFaceRecordEntity) = withContext(Dispatchers.IO) {
dao.insert(entity)
}
suspend fun insertList(list: MutableList<TunnelWorkingFaceRecordEntity>) =
withContext(Dispatchers.IO) {
dao.insertList(list)
}
suspend fun update(entity: TunnelWorkingFaceRecordEntity) = withContext(Dispatchers.IO) {
dao.update(entity)
}
@@ -21,4 +31,8 @@ class TunnelWorkingFaceRecordRepository(private val dao: TunnelWorkingFaceRecord
suspend fun getEntityById(faceId: Long) = withContext(Dispatchers.IO) {
dao.getEntityById(faceId)
}
suspend fun deleteAll() = withContext(Dispatchers.IO) {
dao.deleteAll()
}
}
@@ -10,10 +10,18 @@ class TunnelWorkingFaceRepository(private val dao: TunnelWorkingFaceDao) {
dao.getEntityList()
}
suspend fun getEntityListByState(dataState: String) = withContext(Dispatchers.IO) {
dao.getEntityListByState(dataState)
}
suspend fun insert(entity: TunnelWorkingFaceEntity) = withContext(Dispatchers.IO) {
dao.insert(entity)
}
suspend fun insertList(list: MutableList<TunnelWorkingFaceEntity>) = withContext(Dispatchers.IO) {
dao.insertList(list)
}
suspend fun update(entity: TunnelWorkingFaceEntity) = withContext(Dispatchers.IO) {
dao.update(entity)
}
@@ -21,4 +29,7 @@ class TunnelWorkingFaceRepository(private val dao: TunnelWorkingFaceDao) {
suspend fun getEntityById(faceId: Long) = withContext(Dispatchers.IO) {
dao.getEntityById(faceId)
}
suspend fun deleteAll() = withContext(Dispatchers.IO) {
dao.deleteAll()
}
}
@@ -16,22 +16,32 @@ class TunnelRoofLithologyViewModel(application: Application) : AndroidViewModel(
repository = TunnelRoofLithologyRepository(dao)
}
fun getEntityList(action: (MutableList<TunnelRoofLithologyEntity>?) -> Unit) =
fun getEntityList(recordId: Long, action: (MutableList<TunnelRoofLithologyEntity>?) -> Unit) =
viewModelScope.launch {
val list: MutableList<TunnelRoofLithologyEntity>? = repository.getEntityList()
val list: MutableList<TunnelRoofLithologyEntity>? = repository.getEntityList(recordId)
action(list)
}
fun getEntityList2(
fun getEntityListByState(
dataState: String,
action: (MutableList<TunnelRoofLithologyEntity>?) -> Unit
) =
viewModelScope.launch {
val list: MutableList<TunnelRoofLithologyEntity>? =
repository.getEntityListByState(dataState)
action(list)
}
fun getEntityListByFaceId(
surfaceId: Long,
action: (MutableList<TunnelRoofLithologyEntity>?) -> Unit
) = viewModelScope.launch {
val list: MutableList<TunnelRoofLithologyEntity>? =
repository.getEntityListByFaceId(surfaceId)
action(list)
}
val list: MutableList<TunnelRoofLithologyEntity>? =
repository.getEntityListByFaceId(surfaceId)
action(list)
}
fun getEntityList3(
fun getEntityListByRecordId(
surfaceId: Long,
recordId: Long,
action: (MutableList<TunnelRoofLithologyEntity>?) -> Unit
@@ -41,6 +51,12 @@ class TunnelRoofLithologyViewModel(application: Application) : AndroidViewModel(
action(list)
}
fun insertList(list: MutableList<TunnelRoofLithologyEntity>, action: () -> Unit = {}) =
viewModelScope.launch {
repository.insertList(list)
action()
}
fun insert(entity: TunnelRoofLithologyEntity, action: () -> Unit) = viewModelScope.launch {
repository.insert(entity)
action()
@@ -57,5 +73,17 @@ class TunnelRoofLithologyViewModel(application: Application) : AndroidViewModel(
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()
}
}
@@ -16,9 +16,23 @@ class TunnelWorkingFaceRecordViewModel(application: Application) : AndroidViewMo
repository = TunnelWorkingFaceRecordRepository(dao)
}
fun getEntityList(surfaceId: Long, action: (MutableList<TunnelWorkingFaceRecordEntity>?) -> Unit) =
fun getEntityList(
surfaceId: Long,
action: (MutableList<TunnelWorkingFaceRecordEntity>?) -> Unit
) =
viewModelScope.launch {
val list: MutableList<TunnelWorkingFaceRecordEntity>? = repository.getEntityList(surfaceId)
val list: MutableList<TunnelWorkingFaceRecordEntity>? =
repository.getEntityList(surfaceId)
action(list)
}
fun getEntityListByState(
dataState: String,
action: (MutableList<TunnelWorkingFaceRecordEntity>?) -> Unit
) =
viewModelScope.launch {
val list: MutableList<TunnelWorkingFaceRecordEntity>? =
repository.getEntityListByState(dataState)
action(list)
}
@@ -27,6 +41,12 @@ class TunnelWorkingFaceRecordViewModel(application: Application) : AndroidViewMo
action()
}
fun insertList(list: MutableList<TunnelWorkingFaceRecordEntity>, action: () -> Unit = {}) =
viewModelScope.launch {
repository.insertList(list)
action()
}
fun update(entity: TunnelWorkingFaceRecordEntity, action: () -> Unit) = viewModelScope.launch {
repository.update(entity)
action()
@@ -36,5 +56,10 @@ class TunnelWorkingFaceRecordViewModel(application: Application) : AndroidViewMo
repository.getEntityById(recordId)
}
fun deleteAll(action: () -> Unit={}) = viewModelScope.launch {
repository.deleteAll()
action()
}
}
@@ -6,7 +6,9 @@ import androidx.lifecycle.viewModelScope
import com.zmkg.coaloperation.db.AppDatabase
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceEntity
import com.zmkg.coaloperation.db.repository.TunnelWorkingFaceRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class TunnelWorkingFaceViewModel(application: Application) : AndroidViewModel(application) {
private val repository: TunnelWorkingFaceRepository
@@ -22,20 +24,39 @@ class TunnelWorkingFaceViewModel(application: Application) : AndroidViewModel(ap
action(list)
}
fun getEntityListByState(
dataState: String,
action: (MutableList<TunnelWorkingFaceEntity>?) -> Unit
) = viewModelScope.launch {
val list: MutableList<TunnelWorkingFaceEntity>? = repository.getEntityListByState(dataState)
action(list)
}
fun insert(entity: TunnelWorkingFaceEntity, action: () -> Unit) = viewModelScope.launch {
repository.insert(entity)
action()
}
fun update(entity: TunnelWorkingFaceEntity, action:()-> Unit) = viewModelScope.launch {
fun insertList(list: MutableList<TunnelWorkingFaceEntity>, action: () -> Unit = {}) =
viewModelScope.launch {
repository.insertList(list)
action()
}
fun update(entity: TunnelWorkingFaceEntity, action: () -> Unit) = viewModelScope.launch {
repository.update(entity)
action()
}
fun getEntityById(faceId: Long, action:(TunnelWorkingFaceEntity)-> Unit) = viewModelScope.launch {
val entity = repository.getEntityById(faceId)
entity?.let { action(it) }
}
fun getEntityById(faceId: Long, action: (TunnelWorkingFaceEntity) -> Unit) =
viewModelScope.launch {
val entity = repository.getEntityById(faceId)
entity?.let { action(it) }
}
fun deleteAll(action: () -> Unit = {}) =
viewModelScope.launch {
repository.deleteAll()
action()
}
}
@@ -10,19 +10,21 @@ import com.zmkg.coaloperation.R
import com.zmkg.coaloperation.adapter.TunnelRoofLithologyAdapter
import com.zmkg.coaloperation.base.BaseVMBActivity
import com.zmkg.coaloperation.base.viewmodel.TestViewModel
import com.zmkg.coaloperation.bean.WorkTeam
import com.zmkg.coaloperation.databinding.ActivityAddWorkingPointBinding
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelRoofLithologyEntity
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceRecordEntity
import com.zmkg.coaloperation.db.viewmodel.TunnelRoofLithologyViewModel
import com.zmkg.coaloperation.db.viewmodel.TunnelWorkingFaceRecordViewModel
import com.zmkg.coaloperation.superfuntion.toJson
import com.zmkg.coaloperation.utils.DateTimeUtil
import com.zmkg.coaloperation.utils.DictUtils
import com.zmkg.coaloperation.utils.KeyboardUtil
import com.zmkg.coaloperation.utils.PickerUtil
import com.zmkg.coaloperation.utils.clickWithDebounce
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.time.LocalDateTime
/**
* 开始记录
@@ -40,6 +42,7 @@ class AddWorkingPointActivity :
private var showType = 0
private var surfaceId: Long = 0
private var recordId: Long = 0
private var faceName: String? = null
private var faceRecord: TunnelWorkingFaceRecordEntity? = null
@@ -61,7 +64,7 @@ class AddWorkingPointActivity :
override fun initView(savedInstanceState: Bundle?) {
mBinding.toolbarLay.vLine.visibility = View.GONE
showType = intent.extras?.getInt(SHOW_TYPE) ?: 0
mBinding.toolbarLay.title= if (showType == 0) "开始记录" else "修改记录"
mBinding.toolbarLay.title = if (showType == 0) "开始记录" else "修改记录"
mBinding.btnSave.text = if (showType == 0) "保存" else "修改"
// mBinding.toolbarLay.rightText = ""
@@ -81,6 +84,7 @@ class AddWorkingPointActivity :
faceName = intent.getStringExtra(FACE_NAME)
if (showType == 0) {
surfaceId = intent.getLongExtra(FACE_ID, 0L)
recordId = System.currentTimeMillis()
} else if (showType == 1) {
faceRecord = intent.getParcelableExtra(FACE_RECORD)
if (faceRecord == null) {
@@ -88,32 +92,21 @@ class AddWorkingPointActivity :
return
}
surfaceId = faceRecord!!.surfaceId
recordId = faceRecord!!.recordId
loadFaceRecord()
}
mBinding.tvFaceName.text = faceName
val teamList = mutableListOf<WorkTeam>()
teamList.add(WorkTeam(teamId = "1", teamName = "A地区第1施工队"))
teamList.add(WorkTeam(teamId = "2", teamName = "A地区第2施工队"))
teamList.add(WorkTeam(teamId = "3", teamName = "B地区第1施工队"))
teamList.add(WorkTeam(teamId = "4", teamName = "B地区第2施工队"))
teamList.add(WorkTeam(teamId = "5", teamName = "C地区第1施工队"))
teamList.add(WorkTeam(teamId = "6", teamName = "C地区第2施工队"))
teamList.add(WorkTeam(teamId = "7", teamName = "D地区第1施工队"))
teamList.add(WorkTeam(teamId = "8", teamName = "D地区第2施工队"))
mBinding.tvWorkTeam.setOnClickListener { v ->
PickerUtil.showTeamsPicker(this, teamList) { team ->
mBinding.tvWorkTeam.text = team.teamName
mBinding.tvWorkTeam.tag = team.teamId
PickerUtil.showOptionPicker(this, "选择施工队伍", DictUtils.workTeamList) { option ->
mBinding.tvWorkTeam.text = option.name
mBinding.tvWorkTeam.tag = option.id
}
}
val workTypeList = mutableListOf<String>()
workTypeList.add("早班")
workTypeList.add("中班")
workTypeList.add("晚班")
mBinding.tvTeamShift.setOnClickListener { v ->
PickerUtil.showOptionsPicker(this, "请选择施工班次", workTypeList) { team ->
mBinding.tvTeamShift.text = team
PickerUtil.showOptionPicker(this, "请选择施工班次", DictUtils.workShiftList) { option ->
mBinding.tvTeamShift.text = option.name
mBinding.tvTeamShift.tag = option.id
}
}
mBinding.btnAddPoint.clickWithDebounce {
@@ -135,15 +128,30 @@ class AddWorkingPointActivity :
it.layoutManager = LinearLayoutManager(this)
it.adapter = roofLithologyAdapter
}
addRockPoint()
if (showType == 0) {
addRockPoint()
} else {
roofLithologyViewModel.getEntityList(recordId) {
if (it != null && it.isNotEmpty()) {
roofLithologyList.addAll(it)
roofLithologyAdapter.notifyDataSetChanged()
} else {
addRockPoint()
}
}
}
}
// TODO: 新增记录添加岩性数据,如果是修改,应该合并数据,后续处理
private fun addRockPoint() {
roofLithologyList.add(TunnelRoofLithologyEntity().also {
it.lithologyId = System.currentTimeMillis()
it.surfaceId = surfaceId
it.recordId = if (showType == 1) faceRecord!!.recordId else System.currentTimeMillis()
it.recordId = recordId
it.createTime = DateTimeUtil.formatDateTime(LocalDateTime.now())
it.dataState = "1"
})
// roofLithologyAdapter.notifyDataSetChanged()
val pos = roofLithologyList.size
@@ -202,7 +210,7 @@ class AddWorkingPointActivity :
}
val faceRecord = TunnelWorkingFaceRecordEntity().also {
it.recordId = System.currentTimeMillis()
it.recordId = recordId
it.surfaceId = surfaceId
it.workingDate = mBinding.tvWorkingDate.text.toString()
it.teamShift = mBinding.tvTeamShift.text.toString()
@@ -214,22 +222,25 @@ class AddWorkingPointActivity :
it.seamDip = mBinding.etSeamDip.text.toString().trim()
it.seamHeight = mBinding.etSeamHeight.text.toString().trim()
it.recordPerson = mBinding.etRecordPerson.text.toString().trim()
it.createTime = DateTimeUtil.formatDateTime(LocalDateTime.now())
it.dataState = "1"
}
Log.d(TAG, "saveFaceRecord: ${roofLithologyList.toJson()}")
workingFaceRecordViewModel.insert(faceRecord) {
roofLithologyList.forEach {
roofLithologyViewModel.insert(it) {}
roofLithologyViewModel.insertList(roofLithologyList) {
finish()
}
finish()
}
}
private fun loadFaceRecord() {
faceRecord?.let {
mBinding.tvWorkingDate.text = it.workingDate
mBinding.tvTeamShift.text = it.teamShift
mBinding.tvTeamShift.text = DictUtils.getTeamShift(it.teamShift)
mBinding.tvTeamShift.tag = it.teamShift
mBinding.tvWorkTeam.text = it.teamName
mBinding.tvWorkTeam.tag = it.teamId
@@ -243,10 +254,10 @@ class AddWorkingPointActivity :
private fun updateFaceRecord() {
val faceRecord = TunnelWorkingFaceRecordEntity().also {
it.recordId = faceRecord!!.recordId
it.recordId = recordId
it.surfaceId = surfaceId
it.workingDate = mBinding.tvWorkingDate.text.toString()
it.teamShift = mBinding.tvTeamShift.text.toString()
it.teamShift = mBinding.tvTeamShift.tag.toString()
it.teamName = mBinding.tvWorkTeam.text.toString()
it.teamId = mBinding.tvWorkTeam.tag.toString()
@@ -255,10 +266,17 @@ class AddWorkingPointActivity :
it.seamDip = mBinding.etSeamDip.text.toString().trim()
it.seamHeight = mBinding.etSeamHeight.text.toString().trim()
it.recordPerson = mBinding.etRecordPerson.text.toString().trim()
it.createTime = DateTimeUtil.formatDateTime(LocalDateTime.now())
it.dataState = "1"
}
workingFaceRecordViewModel.update(faceRecord) {
EventBus.getDefault().post(faceRecord)
finish()
roofLithologyViewModel.deleteList(recordId) {
roofLithologyViewModel.insertList(roofLithologyList) {
finish()
}
}
}
}
@@ -15,6 +15,7 @@ import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceRecordEntity
import com.zmkg.coaloperation.db.viewmodel.TunnelWorkingFaceRecordViewModel
import com.zmkg.coaloperation.db.viewmodel.TunnelWorkingFaceViewModel
import com.zmkg.coaloperation.ui.tunneling.viewmodel.TunnelingViewModel
import com.zmkg.coaloperation.utils.DictUtils
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
@@ -25,13 +26,7 @@ class TunnelingActivity :
BaseVMBActivity<TunnelingViewModel, ActivityTunnelingBinding>(R.layout.activity_tunneling) {
companion object {
val FACE_RECORD_HEADER = TunnelWorkingFaceRecordEntity(
recordId = -1,
surfaceId = -1,
workingDate = "时间",
recordPerson = "记录人",
operationType = "0"
)
const val TAG = "TunnelingActivity"
}
private val workingFaceViewModel: TunnelWorkingFaceViewModel by lazy {
@@ -89,6 +84,7 @@ class TunnelingActivity :
@SuppressLint("NotifyDataSetChanged")
override fun initData() {
DictUtils.initData()
workingFaceViewModel.getEntityList { it ->
if (it.isNullOrEmpty()) {
return@getEntityList
@@ -102,6 +98,7 @@ class TunnelingActivity :
override fun createObserve() {
super.createObserve()
}
@@ -118,9 +115,7 @@ class TunnelingActivity :
}
override fun onMessageEvent(event: Any?) {
// if (event is TunnelingWorkFaceRefreshEvent) {
// mViewModel.getTunnelingHomeData()
// }
}
@SuppressLint("NotifyDataSetChanged")
@@ -155,7 +150,7 @@ class TunnelingActivity :
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onFaceRecordEvent(event:TunnelWorkingFaceRecordEntity) {
fun onFaceRecordEvent(event: TunnelWorkingFaceRecordEntity) {
//TODO 折叠子列表
}
@@ -1,6 +1,5 @@
package com.zmkg.coaloperation.ui.tunneling.activity
import android.app.Activity
import android.os.Bundle
import android.text.TextUtils
import android.view.View
@@ -21,11 +20,15 @@ import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus
import androidx.core.view.isGone
import com.zmkg.coaloperation.bean.WorkOption
import com.zmkg.coaloperation.utils.DateTimeUtil
import com.zmkg.coaloperation.utils.DictUtils
import com.zmkg.coaloperation.utils.PickerUtil
import com.zmkg.coaloperation.utils.gone
import com.zmkg.coaloperation.utils.visible
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.time.LocalDateTime
/**
* 工作面
@@ -101,49 +104,37 @@ class WorkFaceActivity :
showDatePicker(it)
}
}
val seamNameList = mutableListOf<String>()
seamNameList.add("煤层---A---")
seamNameList.add("煤层---B---")
seamNameList.add("煤层---C---")
seamNameList.add("煤层---D---")
seamNameList.add("煤层---E---")
mBinding.tvSeamName.setOnClickListener { v ->
PickerUtil.showOptionsPicker(this, "请选择所属煤层", seamNameList) { option ->
mBinding.tvSeamName.text = option
mBinding.tvSeamName.tag = seamNameList.indexOf(option).toString()
PickerUtil.showOptionPicker(this, "请选择所属煤层", DictUtils.seamList) { option ->
mBinding.tvSeamName.text = option.name
mBinding.tvSeamName.tag = option.id
seamAreaList = DictUtils.areaMap[option.id]?:mutableListOf()
}
}
val areaNameList = mutableListOf<String>()
areaNameList.add("采区---A---")
areaNameList.add("采区---B---")
areaNameList.add("采区---C---")
areaNameList.add("采区---D---")
areaNameList.add("采区---E---")
mBinding.tvAreaName.setOnClickListener { v ->
PickerUtil.showOptionsPicker(this, "请选择所属采区域", areaNameList) { option ->
mBinding.tvAreaName.text = option
mBinding.tvAreaName.tag = areaNameList.indexOf(option).toString()
if (seamAreaList.isEmpty()) {
showToast("请先选择所属煤层")
return@setOnClickListener
}
PickerUtil.showOptionPicker(this, "请选择所属采区域", seamAreaList) { option ->
mBinding.tvAreaName.text = option.name
mBinding.tvAreaName.tag = option.id
}
}
val tunnelNatureList = mutableListOf<String>()
tunnelNatureList.add("A0001")
tunnelNatureList.add("A0002")
tunnelNatureList.add("B0001")
tunnelNatureList.add("B0002")
tunnelNatureList.add("C0001")
tunnelNatureList.add("C0002")
tunnelNatureList.add("D0001")
tunnelNatureList.add("D0002")
tunnelNatureList.add("E0001")
tunnelNatureList.add("E0002")
mBinding.tvTunnelNature.setOnClickListener { v ->
PickerUtil.showOptionsPicker(this, "请选择巷道性质", areaNameList) { option ->
mBinding.tvTunnelNature.text = option
mBinding.tvTunnelNature.tag = areaNameList.indexOf(option).toString()
PickerUtil.showOptionPicker(
this,
"请选择巷道性质",
DictUtils.seamRoadWayList
) { option ->
mBinding.tvTunnelNature.text = option.name
mBinding.tvTunnelNature.tag = option.id
}
}
}
private var seamAreaList: MutableList<WorkOption> = mutableListOf()
private fun showDatePicker(tv: TextView) {
tv.setOnClickListener {
PickerUtil.showTimePicker(this, tv.text.toString().trim()) { date ->
@@ -271,11 +262,11 @@ class WorkFaceActivity :
it.seamName = mBinding.tvSeamName.text.toString().trim()
if (it.seamName!!.isNotBlank()) {
it.seamId = mBinding.tvSeamName.tag.toString().toInt()
it.seamId = mBinding.tvSeamName.tag.toString().toLong()
}
it.areaName = mBinding.tvAreaName.text.toString().trim()
if (it.areaName!!.isNotBlank()) {
it.areaId = mBinding.tvAreaName.tag.toString().toInt()
it.areaId = mBinding.tvAreaName.tag.toString().toLong()
}
it.surfaceAzimuth = mBinding.etSurfaceAzimuth.text.toString().trim()
@@ -290,6 +281,9 @@ class WorkFaceActivity :
it.seamGas = mBinding.etSeamGas.text.toString().trim()
it.seamBumpPressure = mBinding.etSeamBumpPressure.text.toString().trim()
it.surfaceSupportForm = mBinding.etSurfaceSupportForm.text.toString().trim()
it.createTime = DateTimeUtil.formatDateTime(LocalDateTime.now())
it.dataState = "1"
}
workingFaceViewModel.insert(workingFaceEntity) {
showToast("工作面新增完成")
@@ -341,6 +335,9 @@ class WorkFaceActivity :
it.seamGas = mBinding.etSeamGas.text.toString().trim()
it.seamBumpPressure = mBinding.etSeamBumpPressure.text.toString().trim()
it.surfaceSupportForm = mBinding.etSurfaceSupportForm.text.toString().trim()
it.createTime = DateTimeUtil.formatDateTime(LocalDateTime.now())
it.dataState = "1"
}
workingFaceViewModel.update(workingFaceEntity) {
showToast("工作面修改完成")
@@ -354,8 +351,8 @@ class WorkFaceActivity :
}
private fun string2num(text: String?): Int {
return if (text.isNullOrBlank()) 0 else text.toInt()
private fun string2num(text: String?): Long {
return if (text.isNullOrBlank()) 0 else text.toLong()
}
}
@@ -2,7 +2,9 @@ package com.zmkg.coaloperation.ui.tunneling.activity
import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.zmkg.coaloperation.R
import com.zmkg.coaloperation.adapter.WorkingItemAdapter
@@ -11,7 +13,11 @@ import com.zmkg.coaloperation.base.viewmodel.TestViewModel
import com.zmkg.coaloperation.bean.RockItem
import com.zmkg.coaloperation.bean.WorkingFaceItem
import com.zmkg.coaloperation.databinding.ActivityWorkingPointBinding
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelRoofLithologyEntity
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceRecordEntity
import com.zmkg.coaloperation.db.viewmodel.TunnelRoofLithologyViewModel
import com.zmkg.coaloperation.utils.DictUtils
import com.zmkg.coaloperation.utils.toJsonString
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
@@ -22,6 +28,7 @@ class WorkingPointActivity :
BaseVMBActivity<TestViewModel, ActivityWorkingPointBinding>(R.layout.activity_working_point) {
companion object {
const val TAG = "WorkingPointActivity"
const val FACE_NAME = "faceName"
const val FACE_RECORD = "faceRecord"
}
@@ -29,6 +36,10 @@ class WorkingPointActivity :
private var faceName: String? = null
private var faceRecord: TunnelWorkingFaceRecordEntity? = null
private val list: MutableList<WorkingFaceItem> = mutableListOf()
private val roofLithologyViewModel: TunnelRoofLithologyViewModel by lazy {
ViewModelProvider(this)[TunnelRoofLithologyViewModel::class.java]
}
private val adapter by lazy {
WorkingItemAdapter(list)
}
@@ -53,8 +64,13 @@ class WorkingPointActivity :
override fun initData() {
faceName = intent.getStringExtra(FACE_NAME)
faceRecord = intent.getParcelableExtra(FACE_RECORD)
Log.d(TAG, "loadFaceRecord: ${faceRecord.toJsonString()}")
faceRecord?.let {
loadFaceRecord(it)
roofLithologyViewModel.getEntityList(it.recordId) { lithologyEntities ->
list[6].items = lithologyEntities
adapter.notifyItemChanged(6)
}
}
}
@@ -63,15 +79,21 @@ class WorkingPointActivity :
list.clear()
list.add(WorkingFaceItem(pageType = 1, name = "工作面名称", value = faceName))
list.add(WorkingFaceItem(pageType = 1, name = "施工日期", value = it.workingDate))
list.add(WorkingFaceItem(pageType = 1, name = "施工班次", value = it.teamShift))
list.add(
WorkingFaceItem(
pageType = 1,
name = "施工班次",
value = DictUtils.getTeamShift(it.teamShift)
)
)
list.add(WorkingFaceItem(pageType = 1, name = "施工队伍", value = it.teamName))
list.add(WorkingFaceItem(pageType = 1, name = "带班队长", value = it.teamLeader))
list.add(WorkingFaceItem(pageType = 1, name = "本班进尺", value = it.workingFootage))
list.add(WorkingFaceItem(pageType = 1, name = "本班进尺", value = it.workingFootage))
val rockList = mutableListOf<RockItem>()
rockList.add(RockItem(startLen = 0, endLen = 1, rockType = ""))
rockList.add(RockItem(startLen = 0, endLen = 1, rockType = ""))
list.add(WorkingFaceItem(pageType = 1, name = "顶板岩性", value = "", items = rockList))
// val rockList = mutableListOf<TunnelRoofLithologyEntity>()
// rockList.add(RockItem(startLen = 0, endLen = 1, rockType = "泥"))
// rockList.add(RockItem(startLen = 0, endLen = 1, rockType = "砂"))
list.add(WorkingFaceItem(pageType = 1, name = "顶板岩性", value = "", items = null))
list.add(WorkingFaceItem(pageType = 1, name = "煤层倾角", value = it.seamDip))
list.add(WorkingFaceItem(pageType = 1, name = "煤层高", value = it.seamHeight))
list.add(WorkingFaceItem(pageType = 1, name = "记录人", value = it.recordPerson))
@@ -86,7 +108,7 @@ class WorkingPointActivity :
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onFaceRecordEvent(event:TunnelWorkingFaceRecordEntity) {
fun onFaceRecordEvent(event: TunnelWorkingFaceRecordEntity) {
faceRecord = event
faceRecord?.let {
loadFaceRecord(it)
@@ -0,0 +1,10 @@
package com.zmkg.coaloperation.ui.tunneling.bean
data class DictBean(
var seam_list: Map<String, String>?,
var team_list: Map<String, String>?,
var mine_team_shift: Map<String, String>?,
var mine_tunnel_nature: Map<String, String>?,
var surface_list: Map<String, String>?,
var area_list:Map<String, Map<String, Any>?>?
)
@@ -2,11 +2,11 @@ package com.zmkg.coaloperation.ui.tunneling.viewmodel
import com.zmkg.coaloperation.base.viewmodel.BaseViewModel
import com.zmkg.coaloperation.data.repository.HomeRepository
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceEntity
import com.zmkg.coaloperation.superfuntion.handleRequest
import com.zmkg.coaloperation.superfuntion.launch
import com.zmkg.coaloperation.ui.tunneling.bean.FaceWorkDetailBean
import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingFaceAddBean
import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeBean
import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeItemBean
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
@@ -18,7 +18,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
class TunnelingViewModel : BaseViewModel() {
var tunnelingHomeList = MutableSharedFlow<MutableList<TunnelingHomeBean>?>()
// var tunnelingHomeList = MutableSharedFlow<MutableList<TunnelingHomeBean>?>()
var tunnelingHomeItemList = MutableSharedFlow<MutableList<TunnelingHomeItemBean>?>()
var tunnelingWorkFaceAdd = MutableSharedFlow<Boolean>()//新增面
var faceWorkDetailData = MutableStateFlow<FaceWorkDetailBean?>(null)//面详情
@@ -29,18 +29,18 @@ class TunnelingViewModel : BaseViewModel() {
}
fun getTunnelingHomeData() {
launch(
{
handleRequest(
HomeRepository.getTunnelingHomeData(),
successBlock = {
tunnelingHomeList.emit(it.data)
})
}
)
}
// fun getTunnelingHomeData() {
// launch(
// {
// handleRequest(
// HomeRepository.getTunnelingHomeData(),
// successBlock = {
// tunnelingHomeList.emit(it.data)
//
// })
// }
// )
// }
fun getTunnelingHomeItemData(index: Int,surfaceId: String?) {
launch(
@@ -81,4 +81,31 @@ class TunnelingViewModel : BaseViewModel() {
)
}
var tunnelFaceAndRecordList = MutableSharedFlow<MutableList<TunnelWorkingFaceEntity>?>()
fun getTunnelFaceAndRecordList() {
launch(
{
handleRequest(
HomeRepository.getTunnelHomeList(),
successBlock = {
tunnelFaceAndRecordList.emit(it.data)
})
}
)
}
var tunnelAllDict = MutableSharedFlow<Any?>()
fun getTunnelAllDict() {
launch(
{
handleRequest(
HomeRepository.getTunnelAllDict(),
successBlock = {
tunnelAllDict.emit(it.data)
})
}
)
}
}
@@ -1,20 +1,50 @@
package com.zmkg.coaloperation.ui.user.fragment
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.zmkg.coaloperation.R
import com.zmkg.coaloperation.base.BaseVMBFragment
import com.zmkg.coaloperation.base.viewmodel.TestViewModel
import com.zmkg.coaloperation.databinding.FragmentUserBinding
import com.zmkg.coaloperation.db.viewmodel.TunnelRoofLithologyViewModel
import com.zmkg.coaloperation.db.viewmodel.TunnelWorkingFaceRecordViewModel
import com.zmkg.coaloperation.db.viewmodel.TunnelWorkingFaceViewModel
import com.zmkg.coaloperation.superfuntion.hideLoading
import com.zmkg.coaloperation.superfuntion.logout
import com.zmkg.coaloperation.superfuntion.showLoading
import com.zmkg.coaloperation.superfuntion.startLoginActivity
import com.zmkg.coaloperation.ui.tunneling.viewmodel.TunnelingViewModel
import com.zmkg.coaloperation.ui.user.activity.AboutUsActivity
import com.zmkg.coaloperation.ui.user.activity.CacheManageActivity
import com.zmkg.coaloperation.ui.user.activity.NetworkConfigActivity
import com.zmkg.coaloperation.utils.SpTool
import com.zmkg.coaloperation.utils.toJsonString
import com.zmkg.coaloperation.view.CommonDialog
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
class UserFragment :
BaseVMBFragment<TestViewModel, FragmentUserBinding>(R.layout.fragment_user) {
BaseVMBFragment<TunnelingViewModel, FragmentUserBinding>(R.layout.fragment_user) {
companion object {
const val TAG = "UserFragment"
}
private val workingFaceViewModel: TunnelWorkingFaceViewModel by lazy {
ViewModelProvider(this)[TunnelWorkingFaceViewModel::class.java]
}
private val workingFaceRecordViewModel: TunnelWorkingFaceRecordViewModel by lazy {
ViewModelProvider(this)[TunnelWorkingFaceRecordViewModel::class.java]
}
private val roofLithologyViewModel: TunnelRoofLithologyViewModel by lazy {
ViewModelProvider(this)[TunnelRoofLithologyViewModel::class.java]
}
private val updateDialog: CommonDialog by lazy {
CommonDialog(requireContext(), R.layout.dialog_common_view) {
@@ -35,6 +65,7 @@ class UserFragment :
override fun initView(root: View?, savedInstanceState: Bundle?) {
mBinding.apply {
networkConfig.setOrderStateInfo("网络配置", R.mipmap.network)
dataPull.setOrderStateInfo("数据拉取", R.drawable.ic_data_pull)
cacheManage.setOrderStateInfo("缓存管理", R.mipmap.buffer)
checkUpdate.setOrderStateInfo("检查更新", R.mipmap.checkupdate)
systemExit.setOrderStateInfo("系统退出", R.mipmap.systemexit)
@@ -46,6 +77,7 @@ class UserFragment :
mBinding.apply {
addClickViews(
networkConfig,
dataPull,
cacheManage,
checkUpdate,
systemExit,
@@ -61,6 +93,28 @@ class UserFragment :
toActivity(NetworkConfigActivity::class.java)
}
R.id.data_pull -> {
showLoading("加载中")
checkDataState { state ->
if (state) {
showToast("本地存在待提交的数据")
return@checkDataState
}
workingFaceViewModel.deleteAll {
workingFaceRecordViewModel.deleteAll {
roofLithologyViewModel.deleteAll {
mViewModel.getTunnelFaceAndRecordList()
mViewModel.getTunnelAllDict()
mBinding.dataPull.postDelayed({
hideLoading()
}, 3000)
}
}
}
}
}
R.id.cache_manage -> {
toActivity(CacheManageActivity::class.java)
}
@@ -76,7 +130,77 @@ class UserFragment :
R.id.about_us -> {
toActivity(AboutUsActivity::class.java)
}
}
}
override fun createObserve() {
super.createObserve()
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.CREATED) {
launch {
getFaceAndRecordList()
}
launch {
getTunnelAllDict()
}
}
}
}
private suspend fun getFaceAndRecordList() {
mViewModel.tunnelFaceAndRecordList.collectLatest {
Log.d(TAG, "getFaceAndRecordList: ${it.toJsonString()}")
it?.let { list ->
//保存工作面数据
workingFaceViewModel.insertList(list) {}
list.forEach { faceEntity ->
faceEntity.records?.let { recordList ->
//保存工作面记录数据
workingFaceRecordViewModel.insertList(recordList)
recordList.forEach { recordEntity ->
recordEntity.mineWorkingLithologyList?.let { lithologyList ->
//保存工作面记录顶板岩性数据
roofLithologyViewModel.insertList(lithologyList)
}
}
}
}
}
}
}
private suspend fun getTunnelAllDict() {
mViewModel.tunnelAllDict.collectLatest {
val dictJson = it.toJsonString()
Log.d(TAG, "getTunnelAllDict: $dictJson")
SpTool.put(SpTool.DICT_JSON, dictJson)
}
}
/**
* 检查数据状态
* @param block 入参true-有待提交数据,false-无待提交数据
*/
private fun checkDataState(block: (Boolean) -> Unit) {
workingFaceViewModel.getEntityListByState("1") { faceList ->
if (faceList != null && faceList.isNotEmpty()) {
block(true)
return@getEntityListByState
}
workingFaceRecordViewModel.getEntityListByState("1") { recordList ->
if (recordList != null && recordList.isNotEmpty()) {
block(true)
return@getEntityListByState
}
roofLithologyViewModel.getEntityListByState("1") { lithologyList ->
if (lithologyList != null && lithologyList.isNotEmpty()) {
block(true)
return@getEntityListByState
}
block(false)
}
}
}
}
}
@@ -0,0 +1,59 @@
package com.zmkg.coaloperation.utils
import android.util.Log
import com.google.gson.internal.LazilyParsedNumber
import com.zmkg.coaloperation.bean.WorkOption
import com.zmkg.coaloperation.ui.tunneling.bean.DictBean
object DictUtils {
val workTeamList: MutableList<WorkOption> = mutableListOf()
val workShiftList: MutableList<WorkOption> = mutableListOf()
val seamList: MutableList<WorkOption> = mutableListOf()
val areaMap: MutableMap<String, MutableList<WorkOption>> = mutableMapOf()
val seamRoadWayList: MutableList<WorkOption> = mutableListOf()
fun initData() {
val dictJson = SpTool.getString(SpTool.DICT_JSON)
if (dictJson.isBlank()) {
return
}
val dict = dictJson.toObject<DictBean?>()
workTeamList.clear()
dict?.team_list?.forEach {
workTeamList.add(WorkOption(id = it.key, name = it.value))
}
workShiftList.clear()
dict?.mine_team_shift?.forEach {
workShiftList.add(WorkOption(id = it.key, name = it.value))
}
seamList.clear()
dict?.seam_list?.forEach {
seamList.add(WorkOption(id = it.key, name = it.value))
}
seamRoadWayList.clear()
dict?.mine_tunnel_nature?.forEach {
seamRoadWayList.add(WorkOption(id = it.key, name = it.value))
}
areaMap.clear()
var tempList: MutableList<WorkOption>?
dict?.area_list?.forEach {
if (areaMap.contains(it.key)) {
tempList = areaMap[it.key]
} else {
tempList =mutableListOf()
areaMap.put(it.key, tempList)
}
val seamId: LazilyParsedNumber = it.value?.get("seamId") as LazilyParsedNumber
//Log.d("DictUtils", "initData: idType= ${seamId?.javaClass?.name}, id=${seamId.toInt()},name=${it.value?.get("areaName")}")
tempList?.add(WorkOption(id = ""+ seamId.toInt(), ""+ it.value?.get("areaName")))
}
}
fun getTeamShift(shift: String?): String {
if (shift == null) return ""
return workShiftList.firstOrNull { it.id == shift }?.name ?: shift
}
}
@@ -1,5 +1,7 @@
package com.zmkg.coaloperation.utils
import android.annotation.SuppressLint
import android.content.SharedPreferences
import android.view.View
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -29,3 +31,27 @@ fun View.invisible() {
fun View.gone() {
visibility = View.GONE
}
@SuppressLint("ApplySharedPref")
inline fun SharedPreferences.edit(
commit: Boolean = false,
action: SharedPreferences.Editor.() -> Unit
) {
val editor = edit()
action(editor)
if (commit) editor.commit() else editor.apply()
}
fun SharedPreferences.put(vararg pairs: Pair<String, Any>) {
edit {
pairs.forEach { (key, value) ->
when (value) {
is Int -> putInt(key, value)
is String -> putString(key, value)
is Boolean -> putBoolean(key, value)
is Float -> putFloat(key, value)
is Long -> putLong(key, value)
}
}
}
}
@@ -1,16 +1,26 @@
package com.zmkg.coaloperation.utils
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.ToNumberPolicy
import com.google.gson.reflect.TypeToken
inline fun <reified T> String.toType(gson: Gson? = null, typeToken: TypeToken<T>): T {
var gson: Gson? = GsonBuilder()
// .setNumberToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
// .setNumberToObjectStrategy(ToNumberPolicy.STRING)
.setObjectToNumberStrategy(ToNumberPolicy.LAZILY_PARSED_NUMBER)
.create()
inline fun <reified T> String.toType(typeToken: TypeToken<T>): T {
return (gson ?: Gson()).fromJson(this, typeToken.type)
}
inline fun <reified T> String.toObject(gson: Gson? = null): T {
inline fun <reified T> String.toObject(): T {
return (gson ?: Gson()).fromJson(this, T::class.java)
}
fun Any?.toJsonString(gson: Gson? = null): String {
fun Any?.toJsonString(): String {
return (gson ?: Gson()).toJson(this) ?: ""
}
@@ -2,16 +2,11 @@ package com.zmkg.coaloperation.utils
import android.content.Context
import android.graphics.Color
import android.view.View
import com.bigkoo.pickerview.builder.OptionsPickerBuilder
import com.bigkoo.pickerview.builder.TimePickerBuilder
import com.bigkoo.pickerview.listener.OnOptionsSelectListener
import com.bigkoo.pickerview.listener.OnTimeSelectListener
import com.zmkg.coaloperation.bean.WorkTeam
import okio.Options
import com.zmkg.coaloperation.bean.WorkOption
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date
import java.util.Locale
@@ -47,19 +42,19 @@ object PickerUtil {
}
// 三级联动选择器示例
fun showTeamsPicker(context: Context, options: List<WorkTeam>, action: (WorkTeam) -> Unit) {
fun showOptionPicker(context: Context, title:String, options: List<WorkOption>, action: (WorkOption) -> Unit) {
OptionsPickerBuilder(context) { opt1, _, _, _ ->
action(options[opt1])
}.apply {
setTitleText("选择施工队伍")
setTitleText(title)
setContentTextSize(18)
setOutSideCancelable(true)
}.build<String>().apply {
setPicker( options.map { it.teamName } , null, null)
setPicker( options.map { it.name } , null, null)
show()
}
}
fun showOptionsPicker(context: Context, title:String, options: List<String>, action: (String) -> Unit) {
fun showTextPicker(context: Context, title:String, options: List<String>, action: (String) -> Unit) {
OptionsPickerBuilder(context) { opt1, _, _, _ ->
action(options[opt1])
}.apply {
@@ -0,0 +1,27 @@
package com.zmkg.coaloperation.utils
import com.zmkg.coaloperation.MyApplication
import kotlin.to
object SpTool {
const val DICT_JSON = "dictJson"
val pref = MyApplication.getSharedPref()!!
fun put(key: String, value: Any) {
pref.put(key to value)
}
fun getInt(key: String, defValue: Int = 0): Int {
return pref.getInt(key, defValue)
}
fun getString(key: String, defValue: String? = ""): String {
return pref.getString(key, defValue) ?: ""
}
fun getBoolean(key: String, defValue: Boolean = false): Boolean {
return pref.getBoolean(key, defValue)
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

@@ -48,6 +48,13 @@
android:layout_marginHorizontal="30dp"
android:layout_marginTop="15dp" />
<com.zmkg.coaloperation.view.CustomInfoView
android:id="@+id/data_pull"
android:layout_width="match_parent"
android:layout_height="68dp"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="15dp" />
<com.zmkg.coaloperation.view.CustomInfoView
android:id="@+id/cache_manage"
android:layout_width="match_parent"