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

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 // ViewModel
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1" implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-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", "iconNormal": "report_tab",
"iconSelected": "report_select_tab" "iconSelected": "report_select_tab"
}, },
{
"tabName": "消息",
"tabTag": "key_message_fragment",
"iconNormal": "message_tab",
"iconSelected": "message_select_tab"
},
{ {
"tabName": "我的", "tabName": "我的",
"tabTag": "key_my_fragment", "tabTag": "key_my_fragment",
@@ -3,6 +3,7 @@ package com.zmkg.coaloperation
import android.app.Activity import android.app.Activity
import android.app.Application import android.app.Application
import android.content.Context import android.content.Context
import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
import android.os.StrictMode import android.os.StrictMode
import android.text.TextUtils import android.text.TextUtils
@@ -36,6 +37,16 @@ class MyApplication : Application(), ViewModelStoreOwner {
@JvmStatic @JvmStatic
lateinit var appViewModel: AppViewModel lateinit var appViewModel: AppViewModel
val TAG = MyApplication::class.java.simpleName 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?) { override fun attachBaseContext(base: Context?) {
@@ -2,6 +2,7 @@ package com.zmkg.coaloperation.adapter
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup 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.TunnelingActivity
import com.zmkg.coaloperation.ui.tunneling.activity.WorkingPointActivity import com.zmkg.coaloperation.ui.tunneling.activity.WorkingPointActivity
import com.zmkg.coaloperation.utils.ScreenUtil import com.zmkg.coaloperation.utils.ScreenUtil
import com.zmkg.coaloperation.utils.toJsonString
class TunnelWorkingFaceAdapter(var list: MutableList<TunnelWorkingFaceEntity>) : class TunnelWorkingFaceAdapter(var list: MutableList<TunnelWorkingFaceEntity>) :
BaseQuickAdapter<TunnelWorkingFaceEntity, TunnelWorkingFaceAdapter.VH>( BaseQuickAdapter<TunnelWorkingFaceEntity, TunnelWorkingFaceAdapter.VH>(
R.layout.list_item_tunnel_working_face, list R.layout.list_item_tunnel_working_face, list
) { ) {
companion object {
private const val TAG = "TunnelWorkingFaceAdapter"
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
val inflater = LayoutInflater.from(context) val inflater = LayoutInflater.from(context)
@@ -47,10 +51,10 @@ class TunnelWorkingFaceAdapter(var list: MutableList<TunnelWorkingFaceEntity>) :
binding.ivExpandRecord.tag = item.isExpandRecord.toString() binding.ivExpandRecord.tag = item.isExpandRecord.toString()
binding.rvFaceRecord.let { rv -> binding.rvFaceRecord.let { rv ->
rv.layoutManager = LinearLayoutManager(context) rv.layoutManager = LinearLayoutManager(context)
if (item.recordList == null) { if (item.records == null) {
item.recordList = mutableListOf() item.records = mutableListOf()
} }
val size = item.recordList!!.size val size = item.records!!.size
rv.updateLayoutParams { rv.updateLayoutParams {
height = if (size >= 3) height = if (size >= 3)
ScreenUtil.dp2px(150F) ScreenUtil.dp2px(150F)
@@ -60,19 +64,20 @@ class TunnelWorkingFaceAdapter(var list: MutableList<TunnelWorkingFaceEntity>) :
rv.isVerticalScrollBarEnabled = size >= 3 rv.isVerticalScrollBarEnabled = size >= 3
rv.isVerticalFadingEdgeEnabled = size < 3 rv.isVerticalFadingEdgeEnabled = size < 3
rv.overScrollMode = if (size >= 3) View.OVER_SCROLL_IF_CONTENT_SCROLLS else View.OVER_SCROLL_NEVER 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 -> setOnItemClickListener { adapter, view, recordPosition ->
// if (recordPosition == 0) { // if (recordPosition == 0) {
// //0为头部表示,不需要点击操作 // //0为头部表示,不需要点击操作
// return@setOnItemClickListener // return@setOnItemClickListener
// } // }
Log.d(TAG, "convert: ${item.records!![recordPosition].toJsonString()}")
context.let { ctx -> context.let { ctx ->
if (ctx is TunnelingActivity) { if (ctx is TunnelingActivity) {
ctx.toActivity(WorkingPointActivity::class.java, Bundle().apply { ctx.toActivity(WorkingPointActivity::class.java, Bundle().apply {
putString(WorkingPointActivity.FACE_NAME, item.surfaceName) putString(WorkingPointActivity.FACE_NAME, item.surfaceName)
putParcelable( putParcelable(
WorkingPointActivity.FACE_RECORD, 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.bean.WorkingFaceItem
import com.zmkg.coaloperation.databinding.ListItemRockBinding import com.zmkg.coaloperation.databinding.ListItemRockBinding
import com.zmkg.coaloperation.databinding.ListItemWorkingFaceBinding import com.zmkg.coaloperation.databinding.ListItemWorkingFaceBinding
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelRoofLithologyEntity
import com.zmkg.coaloperation.utils.ScreenUtil import com.zmkg.coaloperation.utils.ScreenUtil
class WorkingItemAdapter(data: MutableList<WorkingFaceItem>) : class WorkingItemAdapter(data: MutableList<WorkingFaceItem>) :
@@ -84,7 +85,7 @@ class WorkingItemAdapter(data: MutableList<WorkingFaceItem>) :
binding.llContainer.visibility = View.GONE binding.llContainer.visibility = View.GONE
} }
private fun addChildToContainer(container: LinearLayout, list: MutableList<RockItem>?) { private fun addChildToContainer(container: LinearLayout, list: MutableList<TunnelRoofLithologyEntity>?) {
list?.forEach { item -> list?.forEach { item ->
val itemBinding = ListItemRockBinding.inflate( val itemBinding = ListItemRockBinding.inflate(
LayoutInflater.from(context), LayoutInflater.from(context),
@@ -95,17 +96,17 @@ class WorkingItemAdapter(data: MutableList<WorkingFaceItem>) :
tvRockStartLen.let { tvRockStartLen.let {
it.focusable = EditText.NOT_FOCUSABLE it.focusable = EditText.NOT_FOCUSABLE
it.setOnKeyListener(null) it.setOnKeyListener(null)
it.setText("${item.startLen}") it.setText(item.positionStart)
} }
tvRockEndLen.let { tvRockEndLen.let {
it.focusable = EditText.NOT_FOCUSABLE it.focusable = EditText.NOT_FOCUSABLE
it.setOnKeyListener(null) it.setOnKeyListener(null)
it.setText("${item.endLen}") it.setText(item.positionEnd)
} }
tvRockType.let { tvRockType.let {
it.focusable = EditText.NOT_FOCUSABLE it.focusable = EditText.NOT_FOCUSABLE
it.setOnKeyListener(null) it.setOnKeyListener(null)
it.setText(item.rockType) it.setText(item.lithologyType)
} }
container.addView(root) container.addView(root)
} }
@@ -1,9 +1,11 @@
package com.zmkg.coaloperation.bean package com.zmkg.coaloperation.bean
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelRoofLithologyEntity
data class WorkingFaceItem( data class WorkingFaceItem(
var name: String? = "", var name: String? = "",
var value: String? = "", var value: String? = "",
var items: MutableList<RockItem>? = null, var items: MutableList<TunnelRoofLithologyEntity>? = null,
var pageType:Int = 0 var pageType:Int = 0
) )
@@ -13,7 +15,7 @@ data class RockItem(
val rockType: String = "" val rockType: String = ""
) )
data class WorkTeam( data class WorkOption(
var teamId:String, var id:String,
var teamName: String var name: String
) )
@@ -1,11 +1,13 @@
package com.zmkg.coaloperation.data.api package com.zmkg.coaloperation.data.api
import com.zmkg.coaloperation.data.bean.ApiResponse 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.retorfit.UrlConfig
import com.zmkg.coaloperation.ui.tunneling.bean.FaceWorkDetailBean import com.zmkg.coaloperation.ui.tunneling.bean.FaceWorkDetailBean
import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeBean import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeBean
import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeItemBean import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeItemBean
import com.zmkg.coaloperation.ui.home.bean.WaterLedgerBean import com.zmkg.coaloperation.ui.home.bean.WaterLedgerBean
import kotlinx.coroutines.flow.MutableSharedFlow
import okhttp3.RequestBody import okhttp3.RequestBody
import retrofit2.http.Body import retrofit2.http.Body
import retrofit2.http.GET import retrofit2.http.GET
@@ -48,4 +50,10 @@ interface HomeApi {
@POST("/api/mine/tunnelling/surface/add") @POST("/api/mine/tunnelling/surface/add")
suspend fun postTunnellingSurfaceAdd(@Body requestBody: RequestBody): ApiResponse<String> 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.base.repository.BaseRepository
import com.zmkg.coaloperation.data.api.HomeApi import com.zmkg.coaloperation.data.api.HomeApi
import com.zmkg.coaloperation.data.bean.ApiResponse 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
import com.zmkg.coaloperation.retorfit.RetrofitManager.toRequestBody import com.zmkg.coaloperation.retorfit.RetrofitManager.toRequestBody
import com.zmkg.coaloperation.superfuntion.toJson 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.TunnelingHomeBean
import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeItemBean import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingHomeItemBean
import com.zmkg.coaloperation.ui.home.bean.WaterLedgerBean import com.zmkg.coaloperation.ui.home.bean.WaterLedgerBean
import kotlinx.coroutines.flow.MutableSharedFlow
object HomeRepository : BaseRepository(){ 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, TunnelWorkingFaceRecordEntity::class,
TunnelRoofLithologyEntity::class, TunnelRoofLithologyEntity::class,
], ],
version = 3, version = 1,
exportSchema = true exportSchema = true
) )
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
@@ -44,7 +44,7 @@ abstract class AppDatabase : RoomDatabase() {
} }
}) })
// .addMigrations(MIGRATION_1_2) // .addMigrations(MIGRATION_1_2)
.addMigrations(MIGRATION_2_3) // .addMigrations(MIGRATION_2_3)
.build() .build()
INSTANCE = instance INSTANCE = instance
instance instance
@@ -2,6 +2,7 @@ package com.zmkg.coaloperation.db.dao
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import androidx.room.Update import androidx.room.Update
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelRoofLithologyEntity import com.zmkg.coaloperation.db.entiry.tunnel.TunnelRoofLithologyEntity
@@ -11,18 +12,33 @@ interface TunnelRoofLithologyDao {
@Insert @Insert
fun insert(entity: TunnelRoofLithologyEntity): Long fun insert(entity: TunnelRoofLithologyEntity): Long
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertList(list: MutableList<TunnelRoofLithologyEntity>): Array<Long>
@Update @Update
fun update(entity: TunnelRoofLithologyEntity) fun update(entity: TunnelRoofLithologyEntity)
@Query("SELECT * FROM tunnel_roof_lithology ORDER BY createTime ASC") @Query("SELECT * FROM tunnel_roof_lithology WHERE recordId = :recordId ORDER BY createTime ASC")
fun getEntityList(): MutableList<TunnelRoofLithologyEntity>? 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") @Query("SELECT * FROM tunnel_roof_lithology WHERE surfaceId = :surfaceId ORDER BY createTime ASC")
fun getEntityListByFaceId(surfaceId: Long): MutableList<TunnelRoofLithologyEntity>? fun getEntityListByFaceId(surfaceId: Long): MutableList<TunnelRoofLithologyEntity>?
@Query("SELECT * FROM tunnel_roof_lithology WHERE surfaceId = :surfaceId AND recordId = :recordId ORDER BY createTime ASC") @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") @Query("SELECT * FROM tunnel_roof_lithology WHERE lithologyId = :lithologyId")
fun getEntityById(lithologyId: Long): TunnelRoofLithologyEntity? 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.Dao
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import androidx.room.Update import androidx.room.Update
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceEntity import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceEntity
@@ -13,12 +14,21 @@ interface TunnelWorkingFaceDao {
@Insert @Insert
fun insert(entity: TunnelWorkingFaceEntity): Long fun insert(entity: TunnelWorkingFaceEntity): Long
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertList(list: MutableList<TunnelWorkingFaceEntity>): Array<Long>
@Update @Update
fun update(entity: TunnelWorkingFaceEntity) fun update(entity: TunnelWorkingFaceEntity)
@Query("SELECT * FROM tunnel_working_face ORDER BY createTime ASC") @Query("SELECT * FROM tunnel_working_face ORDER BY createTime ASC")
fun getEntityList(): MutableList<TunnelWorkingFaceEntity>? 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") @Query("SELECT * FROM tunnel_working_face WHERE surfaceId = :surfaceId")
fun getEntityById(surfaceId: Long): TunnelWorkingFaceEntity? 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.Dao
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import androidx.room.Update import androidx.room.Update
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceEntity
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceRecordEntity import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceRecordEntity
//import kotlinx.coroutines.flow.Flow //import kotlinx.coroutines.flow.Flow
@@ -13,12 +15,21 @@ interface TunnelWorkingFaceRecordDao {
@Insert @Insert
fun insert(entity: TunnelWorkingFaceRecordEntity): Long fun insert(entity: TunnelWorkingFaceRecordEntity): Long
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertList(list: MutableList<TunnelWorkingFaceRecordEntity>): Array<Long>
@Update @Update
fun update(entity: TunnelWorkingFaceRecordEntity) fun update(entity: TunnelWorkingFaceRecordEntity)
@Query("SELECT * FROM tunnel_working_face_record WHERE surfaceId = :surfaceId ORDER BY createTime ASC") @Query("SELECT * FROM tunnel_working_face_record WHERE surfaceId = :surfaceId ORDER BY createTime ASC")
fun getEntityList(surfaceId: Long): MutableList<TunnelWorkingFaceRecordEntity>? 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") @Query("SELECT * FROM tunnel_working_face_record WHERE surfaceId = :recordId")
fun getEntityById(recordId: Long): TunnelWorkingFaceRecordEntity fun getEntityById(recordId: Long): TunnelWorkingFaceRecordEntity
@Query("DELETE FROM tunnel_working_face_record")
fun deleteAll(): Int
} }
@@ -12,42 +12,51 @@ import java.time.LocalDateTime
*/ */
@Parcelize @Parcelize
@Entity(tableName = "tunnel_roof_lithology") @Entity(tableName = "tunnel_roof_lithology")
class TunnelRoofLithologyEntity : Parcelable { class TunnelRoofLithologyEntity (
/** /**
* 岩性Id * 岩性Id
*/ */
@PrimaryKey @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 * 工作面id
*/ */
var surfaceId: Long = 0 var surfaceId: Long = 0,
/** /**
* 记录id * 记录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 @Parcelize
@Entity(tableName = "tunnel_working_face") @Entity(tableName = "tunnel_working_face")
data class TunnelWorkingFaceEntity( class TunnelWorkingFaceEntity(
// @PrimaryKey(name = "faceId") val id: Int = 0 // @PrimaryKey(name = "faceId") val id: Int = 0
/** /**
* 工作面id,本地新增数据使用时间戳保证唯一性 * 工作面id,本地新增数据使用时间戳保证唯一性
@@ -31,10 +31,12 @@ data class TunnelWorkingFaceEntity(
* 总进尺 * 总进尺
*/ */
var totalFootage: String? = "", var totalFootage: String? = "",
/** /**
* 累计进尺 * 累计进尺
*/ */
var accumulativeFootage: 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 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 @Ignore
var recordList: MutableList<TunnelWorkingFaceRecordEntity>? = null, var records: MutableList<TunnelWorkingFaceRecordEntity>? = null,
@Ignore
var latestRecord: TunnelWorkingFaceRecordEntity? = null,
@Ignore @Ignore
var isExpandRecord: Boolean = false var isExpandRecord: Boolean = false
) : Parcelable { ): Parcelable
// @Ignore
// constructor() : this(surfaceId = 0, recordList = null, isExpandRecord = false)
}
@@ -11,59 +11,82 @@ import java.time.LocalDateTime
@Parcelize @Parcelize
@Entity(tableName = "tunnel_working_face_record") @Entity(tableName = "tunnel_working_face_record")
data class TunnelWorkingFaceRecordEntity( data class TunnelWorkingFaceRecordEntity (
/** /**
* 记录id * 记录id
*/ */
@PrimaryKey @PrimaryKey
var recordId: Long = 0, var recordId: Long = 0,
/** /**
* 工作面id * 工作面id
*/ */
var surfaceId: Long = 0, var surfaceId: Long = 0,
/** /**
* 施工日期 * 施工日期
*/ */
var workingDate: String? = null, var workingDate: String? = null,
/** /**
* 记录人 * 记录人
*/ */
var recordPerson: String? = null, var recordPerson: String? = null,
/** /**
* 施工班次 * 施工班次
*/ */
var teamShift: String? = null, var teamShift: String? = null,
/** /**
* 施工队伍id * 施工队伍id
*/ */
var teamId: String? = null, var teamId: String? = null,
/** /**
* 施工队伍名称 * 施工队伍名称
*/ */
var teamName: String? = null, var teamName: String? = null,
/** /**
* 带队班长 * 带队班长
*/ */
var teamLeader: String? = null, var teamLeader: String? = null,
/** /**
* 本班进尺 * 本班进尺
*/ */
var workingFootage: String? = null, var workingFootage: String? = null,
/** /**
* 煤层倾角 * 煤层倾角
*/ */
var seamDip: String? = null, var seamDip: String? = null,
/** /**
* 煤层高度 * 煤层高度
*/ */
var seamHeight: 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 @Ignore
var operationType: String = "1" var operationType: String = "1"
) : Parcelable { ): Parcelable
// @Ignore
// constructor() : this(recordId = 0)
}
@@ -6,14 +6,23 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
class TunnelRoofLithologyRepository(private val dao: TunnelRoofLithologyDao) { class TunnelRoofLithologyRepository(private val dao: TunnelRoofLithologyDao) {
suspend fun getEntityList() = withContext(Dispatchers.IO) { suspend fun getEntityList(recordId: Long) = withContext(Dispatchers.IO) {
dao.getEntityList() dao.getEntityList(recordId)
}
suspend fun getEntityListByState(dataState: String) = withContext(Dispatchers.IO) {
dao.getEntityListByState(dataState)
} }
suspend fun insert(entity: TunnelRoofLithologyEntity) = withContext(Dispatchers.IO) { suspend fun insert(entity: TunnelRoofLithologyEntity) = withContext(Dispatchers.IO) {
dao.insert(entity) dao.insert(entity)
} }
suspend fun insertList(list: MutableList<TunnelRoofLithologyEntity>) =
withContext(Dispatchers.IO) {
dao.insertList(list)
}
suspend fun update(entity: TunnelRoofLithologyEntity) = withContext(Dispatchers.IO) { suspend fun update(entity: TunnelRoofLithologyEntity) = withContext(Dispatchers.IO) {
dao.update(entity) dao.update(entity)
} }
@@ -22,11 +31,21 @@ class TunnelRoofLithologyRepository(private val dao: TunnelRoofLithologyDao) {
dao.getEntityListByFaceId(surfaceId) dao.getEntityListByFaceId(surfaceId)
} }
suspend fun getEntityListByRecordId(surfaceId: Long, recordId: Long) = withContext(Dispatchers.IO) { suspend fun getEntityListByRecordId(surfaceId: Long, recordId: Long) =
dao.getEntityListByRecordId(surfaceId, recordId) withContext(Dispatchers.IO) {
} dao.getEntityListByRecordId(surfaceId, recordId)
}
suspend fun getEntityById(lithologyId: Long) = withContext(Dispatchers.IO) { suspend fun getEntityById(lithologyId: Long) = withContext(Dispatchers.IO) {
dao.getEntityById(lithologyId) 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) dao.getEntityList(surfaceId)
} }
suspend fun getEntityListByState(dataState: String) =
withContext(Dispatchers.IO) {
dao.getEntityListByState(dataState)
}
suspend fun insert(entity: TunnelWorkingFaceRecordEntity) = withContext(Dispatchers.IO) { suspend fun insert(entity: TunnelWorkingFaceRecordEntity) = withContext(Dispatchers.IO) {
dao.insert(entity) dao.insert(entity)
} }
suspend fun insertList(list: MutableList<TunnelWorkingFaceRecordEntity>) =
withContext(Dispatchers.IO) {
dao.insertList(list)
}
suspend fun update(entity: TunnelWorkingFaceRecordEntity) = withContext(Dispatchers.IO) { suspend fun update(entity: TunnelWorkingFaceRecordEntity) = withContext(Dispatchers.IO) {
dao.update(entity) dao.update(entity)
} }
@@ -21,4 +31,8 @@ class TunnelWorkingFaceRecordRepository(private val dao: TunnelWorkingFaceRecord
suspend fun getEntityById(faceId: Long) = withContext(Dispatchers.IO) { suspend fun getEntityById(faceId: Long) = withContext(Dispatchers.IO) {
dao.getEntityById(faceId) dao.getEntityById(faceId)
} }
suspend fun deleteAll() = withContext(Dispatchers.IO) {
dao.deleteAll()
}
} }
@@ -10,10 +10,18 @@ class TunnelWorkingFaceRepository(private val dao: TunnelWorkingFaceDao) {
dao.getEntityList() dao.getEntityList()
} }
suspend fun getEntityListByState(dataState: String) = withContext(Dispatchers.IO) {
dao.getEntityListByState(dataState)
}
suspend fun insert(entity: TunnelWorkingFaceEntity) = withContext(Dispatchers.IO) { suspend fun insert(entity: TunnelWorkingFaceEntity) = withContext(Dispatchers.IO) {
dao.insert(entity) dao.insert(entity)
} }
suspend fun insertList(list: MutableList<TunnelWorkingFaceEntity>) = withContext(Dispatchers.IO) {
dao.insertList(list)
}
suspend fun update(entity: TunnelWorkingFaceEntity) = withContext(Dispatchers.IO) { suspend fun update(entity: TunnelWorkingFaceEntity) = withContext(Dispatchers.IO) {
dao.update(entity) dao.update(entity)
} }
@@ -21,4 +29,7 @@ class TunnelWorkingFaceRepository(private val dao: TunnelWorkingFaceDao) {
suspend fun getEntityById(faceId: Long) = withContext(Dispatchers.IO) { suspend fun getEntityById(faceId: Long) = withContext(Dispatchers.IO) {
dao.getEntityById(faceId) dao.getEntityById(faceId)
} }
suspend fun deleteAll() = withContext(Dispatchers.IO) {
dao.deleteAll()
}
} }
@@ -16,22 +16,32 @@ class TunnelRoofLithologyViewModel(application: Application) : AndroidViewModel(
repository = TunnelRoofLithologyRepository(dao) repository = TunnelRoofLithologyRepository(dao)
} }
fun getEntityList(action: (MutableList<TunnelRoofLithologyEntity>?) -> Unit) = fun getEntityList(recordId: Long, action: (MutableList<TunnelRoofLithologyEntity>?) -> Unit) =
viewModelScope.launch { viewModelScope.launch {
val list: MutableList<TunnelRoofLithologyEntity>? = repository.getEntityList() val list: MutableList<TunnelRoofLithologyEntity>? = repository.getEntityList(recordId)
action(list) 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, surfaceId: Long,
action: (MutableList<TunnelRoofLithologyEntity>?) -> Unit action: (MutableList<TunnelRoofLithologyEntity>?) -> Unit
) = viewModelScope.launch { ) = viewModelScope.launch {
val list: MutableList<TunnelRoofLithologyEntity>? = val list: MutableList<TunnelRoofLithologyEntity>? =
repository.getEntityListByFaceId(surfaceId) repository.getEntityListByFaceId(surfaceId)
action(list) action(list)
} }
fun getEntityList3( fun getEntityListByRecordId(
surfaceId: Long, surfaceId: Long,
recordId: Long, recordId: Long,
action: (MutableList<TunnelRoofLithologyEntity>?) -> Unit action: (MutableList<TunnelRoofLithologyEntity>?) -> Unit
@@ -41,6 +51,12 @@ class TunnelRoofLithologyViewModel(application: Application) : AndroidViewModel(
action(list) action(list)
} }
fun insertList(list: MutableList<TunnelRoofLithologyEntity>, action: () -> Unit = {}) =
viewModelScope.launch {
repository.insertList(list)
action()
}
fun insert(entity: TunnelRoofLithologyEntity, action: () -> Unit) = viewModelScope.launch { fun insert(entity: TunnelRoofLithologyEntity, action: () -> Unit) = viewModelScope.launch {
repository.insert(entity) repository.insert(entity)
action() action()
@@ -57,5 +73,17 @@ class TunnelRoofLithologyViewModel(application: Application) : AndroidViewModel(
entity?.let { action(it) } 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) repository = TunnelWorkingFaceRecordRepository(dao)
} }
fun getEntityList(surfaceId: Long, action: (MutableList<TunnelWorkingFaceRecordEntity>?) -> Unit) = fun getEntityList(
surfaceId: Long,
action: (MutableList<TunnelWorkingFaceRecordEntity>?) -> Unit
) =
viewModelScope.launch { 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) action(list)
} }
@@ -27,6 +41,12 @@ class TunnelWorkingFaceRecordViewModel(application: Application) : AndroidViewMo
action() action()
} }
fun insertList(list: MutableList<TunnelWorkingFaceRecordEntity>, action: () -> Unit = {}) =
viewModelScope.launch {
repository.insertList(list)
action()
}
fun update(entity: TunnelWorkingFaceRecordEntity, action: () -> Unit) = viewModelScope.launch { fun update(entity: TunnelWorkingFaceRecordEntity, action: () -> Unit) = viewModelScope.launch {
repository.update(entity) repository.update(entity)
action() action()
@@ -36,5 +56,10 @@ class TunnelWorkingFaceRecordViewModel(application: Application) : AndroidViewMo
repository.getEntityById(recordId) 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.AppDatabase
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceEntity import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceEntity
import com.zmkg.coaloperation.db.repository.TunnelWorkingFaceRepository import com.zmkg.coaloperation.db.repository.TunnelWorkingFaceRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class TunnelWorkingFaceViewModel(application: Application) : AndroidViewModel(application) { class TunnelWorkingFaceViewModel(application: Application) : AndroidViewModel(application) {
private val repository: TunnelWorkingFaceRepository private val repository: TunnelWorkingFaceRepository
@@ -22,20 +24,39 @@ class TunnelWorkingFaceViewModel(application: Application) : AndroidViewModel(ap
action(list) 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 { fun insert(entity: TunnelWorkingFaceEntity, action: () -> Unit) = viewModelScope.launch {
repository.insert(entity) repository.insert(entity)
action() 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) repository.update(entity)
action() action()
} }
fun getEntityById(faceId: Long, action:(TunnelWorkingFaceEntity)-> Unit) = viewModelScope.launch { fun getEntityById(faceId: Long, action: (TunnelWorkingFaceEntity) -> Unit) =
val entity = repository.getEntityById(faceId) viewModelScope.launch {
entity?.let { action(it) } 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.adapter.TunnelRoofLithologyAdapter
import com.zmkg.coaloperation.base.BaseVMBActivity import com.zmkg.coaloperation.base.BaseVMBActivity
import com.zmkg.coaloperation.base.viewmodel.TestViewModel import com.zmkg.coaloperation.base.viewmodel.TestViewModel
import com.zmkg.coaloperation.bean.WorkTeam
import com.zmkg.coaloperation.databinding.ActivityAddWorkingPointBinding import com.zmkg.coaloperation.databinding.ActivityAddWorkingPointBinding
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelRoofLithologyEntity import com.zmkg.coaloperation.db.entiry.tunnel.TunnelRoofLithologyEntity
import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceRecordEntity import com.zmkg.coaloperation.db.entiry.tunnel.TunnelWorkingFaceRecordEntity
import com.zmkg.coaloperation.db.viewmodel.TunnelRoofLithologyViewModel import com.zmkg.coaloperation.db.viewmodel.TunnelRoofLithologyViewModel
import com.zmkg.coaloperation.db.viewmodel.TunnelWorkingFaceRecordViewModel import com.zmkg.coaloperation.db.viewmodel.TunnelWorkingFaceRecordViewModel
import com.zmkg.coaloperation.superfuntion.toJson 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.KeyboardUtil
import com.zmkg.coaloperation.utils.PickerUtil import com.zmkg.coaloperation.utils.PickerUtil
import com.zmkg.coaloperation.utils.clickWithDebounce import com.zmkg.coaloperation.utils.clickWithDebounce
import org.greenrobot.eventbus.EventBus 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
import java.time.LocalDateTime
/** /**
* 开始记录 * 开始记录
@@ -40,6 +42,7 @@ class AddWorkingPointActivity :
private var showType = 0 private var showType = 0
private var surfaceId: Long = 0 private var surfaceId: Long = 0
private var recordId: Long = 0
private var faceName: String? = null private var faceName: String? = null
private var faceRecord: TunnelWorkingFaceRecordEntity? = null private var faceRecord: TunnelWorkingFaceRecordEntity? = null
@@ -61,7 +64,7 @@ class AddWorkingPointActivity :
override fun initView(savedInstanceState: Bundle?) { override fun initView(savedInstanceState: Bundle?) {
mBinding.toolbarLay.vLine.visibility = View.GONE mBinding.toolbarLay.vLine.visibility = View.GONE
showType = intent.extras?.getInt(SHOW_TYPE) ?: 0 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.btnSave.text = if (showType == 0) "保存" else "修改"
// mBinding.toolbarLay.rightText = "" // mBinding.toolbarLay.rightText = ""
@@ -81,6 +84,7 @@ class AddWorkingPointActivity :
faceName = intent.getStringExtra(FACE_NAME) faceName = intent.getStringExtra(FACE_NAME)
if (showType == 0) { if (showType == 0) {
surfaceId = intent.getLongExtra(FACE_ID, 0L) surfaceId = intent.getLongExtra(FACE_ID, 0L)
recordId = System.currentTimeMillis()
} else if (showType == 1) { } else if (showType == 1) {
faceRecord = intent.getParcelableExtra(FACE_RECORD) faceRecord = intent.getParcelableExtra(FACE_RECORD)
if (faceRecord == null) { if (faceRecord == null) {
@@ -88,32 +92,21 @@ class AddWorkingPointActivity :
return return
} }
surfaceId = faceRecord!!.surfaceId surfaceId = faceRecord!!.surfaceId
recordId = faceRecord!!.recordId
loadFaceRecord() loadFaceRecord()
} }
mBinding.tvFaceName.text = faceName 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 -> mBinding.tvWorkTeam.setOnClickListener { v ->
PickerUtil.showTeamsPicker(this, teamList) { team -> PickerUtil.showOptionPicker(this, "选择施工队伍", DictUtils.workTeamList) { option ->
mBinding.tvWorkTeam.text = team.teamName mBinding.tvWorkTeam.text = option.name
mBinding.tvWorkTeam.tag = team.teamId mBinding.tvWorkTeam.tag = option.id
} }
} }
val workTypeList = mutableListOf<String>()
workTypeList.add("早班")
workTypeList.add("中班")
workTypeList.add("晚班")
mBinding.tvTeamShift.setOnClickListener { v -> mBinding.tvTeamShift.setOnClickListener { v ->
PickerUtil.showOptionsPicker(this, "请选择施工班次", workTypeList) { team -> PickerUtil.showOptionPicker(this, "请选择施工班次", DictUtils.workShiftList) { option ->
mBinding.tvTeamShift.text = team mBinding.tvTeamShift.text = option.name
mBinding.tvTeamShift.tag = option.id
} }
} }
mBinding.btnAddPoint.clickWithDebounce { mBinding.btnAddPoint.clickWithDebounce {
@@ -135,15 +128,30 @@ class AddWorkingPointActivity :
it.layoutManager = LinearLayoutManager(this) it.layoutManager = LinearLayoutManager(this)
it.adapter = roofLithologyAdapter it.adapter = roofLithologyAdapter
} }
if (showType == 0) {
addRockPoint() addRockPoint()
} else {
roofLithologyViewModel.getEntityList(recordId) {
if (it != null && it.isNotEmpty()) {
roofLithologyList.addAll(it)
roofLithologyAdapter.notifyDataSetChanged()
} else {
addRockPoint()
}
}
}
} }
// TODO: 新增记录添加岩性数据,如果是修改,应该合并数据,后续处理
private fun addRockPoint() { private fun addRockPoint() {
roofLithologyList.add(TunnelRoofLithologyEntity().also { roofLithologyList.add(TunnelRoofLithologyEntity().also {
it.lithologyId = System.currentTimeMillis() it.lithologyId = System.currentTimeMillis()
it.surfaceId = surfaceId 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() // roofLithologyAdapter.notifyDataSetChanged()
val pos = roofLithologyList.size val pos = roofLithologyList.size
@@ -202,7 +210,7 @@ class AddWorkingPointActivity :
} }
val faceRecord = TunnelWorkingFaceRecordEntity().also { val faceRecord = TunnelWorkingFaceRecordEntity().also {
it.recordId = System.currentTimeMillis() it.recordId = recordId
it.surfaceId = surfaceId it.surfaceId = surfaceId
it.workingDate = mBinding.tvWorkingDate.text.toString() it.workingDate = mBinding.tvWorkingDate.text.toString()
it.teamShift = mBinding.tvTeamShift.text.toString() it.teamShift = mBinding.tvTeamShift.text.toString()
@@ -214,22 +222,25 @@ class AddWorkingPointActivity :
it.seamDip = mBinding.etSeamDip.text.toString().trim() it.seamDip = mBinding.etSeamDip.text.toString().trim()
it.seamHeight = mBinding.etSeamHeight.text.toString().trim() it.seamHeight = mBinding.etSeamHeight.text.toString().trim()
it.recordPerson = mBinding.etRecordPerson.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()}") Log.d(TAG, "saveFaceRecord: ${roofLithologyList.toJson()}")
workingFaceRecordViewModel.insert(faceRecord) { workingFaceRecordViewModel.insert(faceRecord) {
roofLithologyList.forEach { roofLithologyViewModel.insertList(roofLithologyList) {
roofLithologyViewModel.insert(it) {} finish()
} }
finish()
} }
} }
private fun loadFaceRecord() { private fun loadFaceRecord() {
faceRecord?.let { faceRecord?.let {
mBinding.tvWorkingDate.text = it.workingDate 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.text = it.teamName
mBinding.tvWorkTeam.tag = it.teamId mBinding.tvWorkTeam.tag = it.teamId
@@ -243,10 +254,10 @@ class AddWorkingPointActivity :
private fun updateFaceRecord() { private fun updateFaceRecord() {
val faceRecord = TunnelWorkingFaceRecordEntity().also { val faceRecord = TunnelWorkingFaceRecordEntity().also {
it.recordId = faceRecord!!.recordId it.recordId = recordId
it.surfaceId = surfaceId it.surfaceId = surfaceId
it.workingDate = mBinding.tvWorkingDate.text.toString() 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.teamName = mBinding.tvWorkTeam.text.toString()
it.teamId = mBinding.tvWorkTeam.tag.toString() it.teamId = mBinding.tvWorkTeam.tag.toString()
@@ -255,10 +266,17 @@ class AddWorkingPointActivity :
it.seamDip = mBinding.etSeamDip.text.toString().trim() it.seamDip = mBinding.etSeamDip.text.toString().trim()
it.seamHeight = mBinding.etSeamHeight.text.toString().trim() it.seamHeight = mBinding.etSeamHeight.text.toString().trim()
it.recordPerson = mBinding.etRecordPerson.text.toString().trim() it.recordPerson = mBinding.etRecordPerson.text.toString().trim()
it.createTime = DateTimeUtil.formatDateTime(LocalDateTime.now())
it.dataState = "1"
} }
workingFaceRecordViewModel.update(faceRecord) { workingFaceRecordViewModel.update(faceRecord) {
EventBus.getDefault().post(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.TunnelWorkingFaceRecordViewModel
import com.zmkg.coaloperation.db.viewmodel.TunnelWorkingFaceViewModel import com.zmkg.coaloperation.db.viewmodel.TunnelWorkingFaceViewModel
import com.zmkg.coaloperation.ui.tunneling.viewmodel.TunnelingViewModel import com.zmkg.coaloperation.ui.tunneling.viewmodel.TunnelingViewModel
import com.zmkg.coaloperation.utils.DictUtils
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
@@ -25,13 +26,7 @@ class TunnelingActivity :
BaseVMBActivity<TunnelingViewModel, ActivityTunnelingBinding>(R.layout.activity_tunneling) { BaseVMBActivity<TunnelingViewModel, ActivityTunnelingBinding>(R.layout.activity_tunneling) {
companion object { companion object {
val FACE_RECORD_HEADER = TunnelWorkingFaceRecordEntity( const val TAG = "TunnelingActivity"
recordId = -1,
surfaceId = -1,
workingDate = "时间",
recordPerson = "记录人",
operationType = "0"
)
} }
private val workingFaceViewModel: TunnelWorkingFaceViewModel by lazy { private val workingFaceViewModel: TunnelWorkingFaceViewModel by lazy {
@@ -89,6 +84,7 @@ class TunnelingActivity :
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
override fun initData() { override fun initData() {
DictUtils.initData()
workingFaceViewModel.getEntityList { it -> workingFaceViewModel.getEntityList { it ->
if (it.isNullOrEmpty()) { if (it.isNullOrEmpty()) {
return@getEntityList return@getEntityList
@@ -102,6 +98,7 @@ class TunnelingActivity :
override fun createObserve() { override fun createObserve() {
super.createObserve() super.createObserve()
} }
@@ -118,9 +115,7 @@ class TunnelingActivity :
} }
override fun onMessageEvent(event: Any?) { override fun onMessageEvent(event: Any?) {
// if (event is TunnelingWorkFaceRefreshEvent) {
// mViewModel.getTunnelingHomeData()
// }
} }
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
@@ -155,7 +150,7 @@ class TunnelingActivity :
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun onFaceRecordEvent(event:TunnelWorkingFaceRecordEntity) { fun onFaceRecordEvent(event: TunnelWorkingFaceRecordEntity) {
//TODO 折叠子列表 //TODO 折叠子列表
} }
@@ -1,6 +1,5 @@
package com.zmkg.coaloperation.ui.tunneling.activity package com.zmkg.coaloperation.ui.tunneling.activity
import android.app.Activity
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils import android.text.TextUtils
import android.view.View import android.view.View
@@ -21,11 +20,15 @@ import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import androidx.core.view.isGone 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.PickerUtil
import com.zmkg.coaloperation.utils.gone import com.zmkg.coaloperation.utils.gone
import com.zmkg.coaloperation.utils.visible import com.zmkg.coaloperation.utils.visible
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
import java.time.LocalDateTime
/** /**
* 工作面 * 工作面
@@ -101,49 +104,37 @@ class WorkFaceActivity :
showDatePicker(it) 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 -> mBinding.tvSeamName.setOnClickListener { v ->
PickerUtil.showOptionsPicker(this, "请选择所属煤层", seamNameList) { option -> PickerUtil.showOptionPicker(this, "请选择所属煤层", DictUtils.seamList) { option ->
mBinding.tvSeamName.text = option mBinding.tvSeamName.text = option.name
mBinding.tvSeamName.tag = seamNameList.indexOf(option).toString() 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 -> mBinding.tvAreaName.setOnClickListener { v ->
PickerUtil.showOptionsPicker(this, "请选择所属采区域", areaNameList) { option -> if (seamAreaList.isEmpty()) {
mBinding.tvAreaName.text = option showToast("请先选择所属煤层")
mBinding.tvAreaName.tag = areaNameList.indexOf(option).toString() 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 -> mBinding.tvTunnelNature.setOnClickListener { v ->
PickerUtil.showOptionsPicker(this, "请选择巷道性质", areaNameList) { option -> PickerUtil.showOptionPicker(
mBinding.tvTunnelNature.text = option this,
mBinding.tvTunnelNature.tag = areaNameList.indexOf(option).toString() "请选择巷道性质",
DictUtils.seamRoadWayList
) { option ->
mBinding.tvTunnelNature.text = option.name
mBinding.tvTunnelNature.tag = option.id
} }
} }
} }
private var seamAreaList: MutableList<WorkOption> = mutableListOf()
private fun showDatePicker(tv: TextView) { private fun showDatePicker(tv: TextView) {
tv.setOnClickListener { tv.setOnClickListener {
PickerUtil.showTimePicker(this, tv.text.toString().trim()) { date -> PickerUtil.showTimePicker(this, tv.text.toString().trim()) { date ->
@@ -271,11 +262,11 @@ class WorkFaceActivity :
it.seamName = mBinding.tvSeamName.text.toString().trim() it.seamName = mBinding.tvSeamName.text.toString().trim()
if (it.seamName!!.isNotBlank()) { 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() it.areaName = mBinding.tvAreaName.text.toString().trim()
if (it.areaName!!.isNotBlank()) { 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() it.surfaceAzimuth = mBinding.etSurfaceAzimuth.text.toString().trim()
@@ -290,6 +281,9 @@ class WorkFaceActivity :
it.seamGas = mBinding.etSeamGas.text.toString().trim() it.seamGas = mBinding.etSeamGas.text.toString().trim()
it.seamBumpPressure = mBinding.etSeamBumpPressure.text.toString().trim() it.seamBumpPressure = mBinding.etSeamBumpPressure.text.toString().trim()
it.surfaceSupportForm = mBinding.etSurfaceSupportForm.text.toString().trim() it.surfaceSupportForm = mBinding.etSurfaceSupportForm.text.toString().trim()
it.createTime = DateTimeUtil.formatDateTime(LocalDateTime.now())
it.dataState = "1"
} }
workingFaceViewModel.insert(workingFaceEntity) { workingFaceViewModel.insert(workingFaceEntity) {
showToast("工作面新增完成") showToast("工作面新增完成")
@@ -341,6 +335,9 @@ class WorkFaceActivity :
it.seamGas = mBinding.etSeamGas.text.toString().trim() it.seamGas = mBinding.etSeamGas.text.toString().trim()
it.seamBumpPressure = mBinding.etSeamBumpPressure.text.toString().trim() it.seamBumpPressure = mBinding.etSeamBumpPressure.text.toString().trim()
it.surfaceSupportForm = mBinding.etSurfaceSupportForm.text.toString().trim() it.surfaceSupportForm = mBinding.etSurfaceSupportForm.text.toString().trim()
it.createTime = DateTimeUtil.formatDateTime(LocalDateTime.now())
it.dataState = "1"
} }
workingFaceViewModel.update(workingFaceEntity) { workingFaceViewModel.update(workingFaceEntity) {
showToast("工作面修改完成") showToast("工作面修改完成")
@@ -354,8 +351,8 @@ class WorkFaceActivity :
} }
private fun string2num(text: String?): Int { private fun string2num(text: String?): Long {
return if (text.isNullOrBlank()) 0 else text.toInt() 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.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.ViewModelProvider
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.WorkingItemAdapter 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.RockItem
import com.zmkg.coaloperation.bean.WorkingFaceItem import com.zmkg.coaloperation.bean.WorkingFaceItem
import com.zmkg.coaloperation.databinding.ActivityWorkingPointBinding 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.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.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
@@ -22,6 +28,7 @@ class WorkingPointActivity :
BaseVMBActivity<TestViewModel, ActivityWorkingPointBinding>(R.layout.activity_working_point) { BaseVMBActivity<TestViewModel, ActivityWorkingPointBinding>(R.layout.activity_working_point) {
companion object { companion object {
const val TAG = "WorkingPointActivity"
const val FACE_NAME = "faceName" const val FACE_NAME = "faceName"
const val FACE_RECORD = "faceRecord" const val FACE_RECORD = "faceRecord"
} }
@@ -29,6 +36,10 @@ class WorkingPointActivity :
private var faceName: String? = null private var faceName: String? = null
private var faceRecord: TunnelWorkingFaceRecordEntity? = null private var faceRecord: TunnelWorkingFaceRecordEntity? = null
private val list: MutableList<WorkingFaceItem> = mutableListOf() private val list: MutableList<WorkingFaceItem> = mutableListOf()
private val roofLithologyViewModel: TunnelRoofLithologyViewModel by lazy {
ViewModelProvider(this)[TunnelRoofLithologyViewModel::class.java]
}
private val adapter by lazy { private val adapter by lazy {
WorkingItemAdapter(list) WorkingItemAdapter(list)
} }
@@ -53,8 +64,13 @@ class WorkingPointActivity :
override fun initData() { override fun initData() {
faceName = intent.getStringExtra(FACE_NAME) faceName = intent.getStringExtra(FACE_NAME)
faceRecord = intent.getParcelableExtra(FACE_RECORD) faceRecord = intent.getParcelableExtra(FACE_RECORD)
Log.d(TAG, "loadFaceRecord: ${faceRecord.toJsonString()}")
faceRecord?.let { faceRecord?.let {
loadFaceRecord(it) loadFaceRecord(it)
roofLithologyViewModel.getEntityList(it.recordId) { lithologyEntities ->
list[6].items = lithologyEntities
adapter.notifyItemChanged(6)
}
} }
} }
@@ -63,15 +79,21 @@ class WorkingPointActivity :
list.clear() list.clear()
list.add(WorkingFaceItem(pageType = 1, name = "工作面名称", value = faceName)) 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.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.teamName))
list.add(WorkingFaceItem(pageType = 1, name = "带班队长", value = it.teamLeader)) 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>() // val rockList = mutableListOf<TunnelRoofLithologyEntity>()
rockList.add(RockItem(startLen = 0, endLen = 1, rockType = "")) // rockList.add(RockItem(startLen = 0, endLen = 1, rockType = "泥"))
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)) 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.seamDip))
list.add(WorkingFaceItem(pageType = 1, name = "煤层高", value = it.seamHeight)) list.add(WorkingFaceItem(pageType = 1, name = "煤层高", value = it.seamHeight))
list.add(WorkingFaceItem(pageType = 1, name = "记录人", value = it.recordPerson)) list.add(WorkingFaceItem(pageType = 1, name = "记录人", value = it.recordPerson))
@@ -86,7 +108,7 @@ class WorkingPointActivity :
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun onFaceRecordEvent(event:TunnelWorkingFaceRecordEntity) { fun onFaceRecordEvent(event: TunnelWorkingFaceRecordEntity) {
faceRecord = event faceRecord = event
faceRecord?.let { faceRecord?.let {
loadFaceRecord(it) 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.base.viewmodel.BaseViewModel
import com.zmkg.coaloperation.data.repository.HomeRepository 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.handleRequest
import com.zmkg.coaloperation.superfuntion.launch import com.zmkg.coaloperation.superfuntion.launch
import com.zmkg.coaloperation.ui.tunneling.bean.FaceWorkDetailBean import com.zmkg.coaloperation.ui.tunneling.bean.FaceWorkDetailBean
import com.zmkg.coaloperation.ui.tunneling.bean.TunnelingFaceAddBean 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.tunneling.bean.TunnelingHomeItemBean
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
@@ -18,7 +18,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
class TunnelingViewModel : BaseViewModel() { class TunnelingViewModel : BaseViewModel() {
var tunnelingHomeList = MutableSharedFlow<MutableList<TunnelingHomeBean>?>() // var tunnelingHomeList = MutableSharedFlow<MutableList<TunnelingHomeBean>?>()
var tunnelingHomeItemList = MutableSharedFlow<MutableList<TunnelingHomeItemBean>?>() var tunnelingHomeItemList = MutableSharedFlow<MutableList<TunnelingHomeItemBean>?>()
var tunnelingWorkFaceAdd = MutableSharedFlow<Boolean>()//新增面 var tunnelingWorkFaceAdd = MutableSharedFlow<Boolean>()//新增面
var faceWorkDetailData = MutableStateFlow<FaceWorkDetailBean?>(null)//面详情 var faceWorkDetailData = MutableStateFlow<FaceWorkDetailBean?>(null)//面详情
@@ -29,18 +29,18 @@ class TunnelingViewModel : BaseViewModel() {
} }
fun getTunnelingHomeData() { // fun getTunnelingHomeData() {
launch( // launch(
{ // {
handleRequest( // handleRequest(
HomeRepository.getTunnelingHomeData(), // HomeRepository.getTunnelingHomeData(),
successBlock = { // successBlock = {
tunnelingHomeList.emit(it.data) // tunnelingHomeList.emit(it.data)
//
}) // })
} // }
) // )
} // }
fun getTunnelingHomeItemData(index: Int,surfaceId: String?) { fun getTunnelingHomeItemData(index: Int,surfaceId: String?) {
launch( 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 package com.zmkg.coaloperation.ui.user.fragment
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 com.zmkg.coaloperation.R import com.zmkg.coaloperation.R
import com.zmkg.coaloperation.base.BaseVMBFragment import com.zmkg.coaloperation.base.BaseVMBFragment
import com.zmkg.coaloperation.base.viewmodel.TestViewModel
import com.zmkg.coaloperation.databinding.FragmentUserBinding 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.logout
import com.zmkg.coaloperation.superfuntion.showLoading
import com.zmkg.coaloperation.superfuntion.startLoginActivity 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.AboutUsActivity
import com.zmkg.coaloperation.ui.user.activity.CacheManageActivity import com.zmkg.coaloperation.ui.user.activity.CacheManageActivity
import com.zmkg.coaloperation.ui.user.activity.NetworkConfigActivity 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 com.zmkg.coaloperation.view.CommonDialog
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
class UserFragment : 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 { private val updateDialog: CommonDialog by lazy {
CommonDialog(requireContext(), R.layout.dialog_common_view) { CommonDialog(requireContext(), R.layout.dialog_common_view) {
@@ -35,6 +65,7 @@ class UserFragment :
override fun initView(root: View?, savedInstanceState: Bundle?) { override fun initView(root: View?, savedInstanceState: Bundle?) {
mBinding.apply { mBinding.apply {
networkConfig.setOrderStateInfo("网络配置", R.mipmap.network) networkConfig.setOrderStateInfo("网络配置", R.mipmap.network)
dataPull.setOrderStateInfo("数据拉取", R.drawable.ic_data_pull)
cacheManage.setOrderStateInfo("缓存管理", R.mipmap.buffer) cacheManage.setOrderStateInfo("缓存管理", R.mipmap.buffer)
checkUpdate.setOrderStateInfo("检查更新", R.mipmap.checkupdate) checkUpdate.setOrderStateInfo("检查更新", R.mipmap.checkupdate)
systemExit.setOrderStateInfo("系统退出", R.mipmap.systemexit) systemExit.setOrderStateInfo("系统退出", R.mipmap.systemexit)
@@ -46,6 +77,7 @@ class UserFragment :
mBinding.apply { mBinding.apply {
addClickViews( addClickViews(
networkConfig, networkConfig,
dataPull,
cacheManage, cacheManage,
checkUpdate, checkUpdate,
systemExit, systemExit,
@@ -61,6 +93,28 @@ class UserFragment :
toActivity(NetworkConfigActivity::class.java) 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 -> { R.id.cache_manage -> {
toActivity(CacheManageActivity::class.java) toActivity(CacheManageActivity::class.java)
} }
@@ -76,7 +130,77 @@ class UserFragment :
R.id.about_us -> { R.id.about_us -> {
toActivity(AboutUsActivity::class.java) 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 package com.zmkg.coaloperation.utils
import android.annotation.SuppressLint
import android.content.SharedPreferences
import android.view.View import android.view.View
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@@ -29,3 +31,27 @@ fun View.invisible() {
fun View.gone() { fun View.gone() {
visibility = 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 package com.zmkg.coaloperation.utils
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.ToNumberPolicy
import com.google.gson.reflect.TypeToken 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) 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) return (gson ?: Gson()).fromJson(this, T::class.java)
} }
fun Any?.toJsonString(gson: Gson? = null): String { fun Any?.toJsonString(): String {
return (gson ?: Gson()).toJson(this) ?: "" return (gson ?: Gson()).toJson(this) ?: ""
} }
@@ -2,16 +2,11 @@ package com.zmkg.coaloperation.utils
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.view.View
import com.bigkoo.pickerview.builder.OptionsPickerBuilder import com.bigkoo.pickerview.builder.OptionsPickerBuilder
import com.bigkoo.pickerview.builder.TimePickerBuilder import com.bigkoo.pickerview.builder.TimePickerBuilder
import com.bigkoo.pickerview.listener.OnOptionsSelectListener import com.zmkg.coaloperation.bean.WorkOption
import com.bigkoo.pickerview.listener.OnTimeSelectListener
import com.zmkg.coaloperation.bean.WorkTeam
import okio.Options
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Calendar import java.util.Calendar
import java.util.Date
import java.util.Locale 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, _, _, _ -> OptionsPickerBuilder(context) { opt1, _, _, _ ->
action(options[opt1]) action(options[opt1])
}.apply { }.apply {
setTitleText("选择施工队伍") setTitleText(title)
setContentTextSize(18) setContentTextSize(18)
setOutSideCancelable(true) setOutSideCancelable(true)
}.build<String>().apply { }.build<String>().apply {
setPicker( options.map { it.teamName } , null, null) setPicker( options.map { it.name } , null, null)
show() 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, _, _, _ -> OptionsPickerBuilder(context) { opt1, _, _, _ ->
action(options[opt1]) action(options[opt1])
}.apply { }.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_marginHorizontal="30dp"
android:layout_marginTop="15dp" /> 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 <com.zmkg.coaloperation.view.CustomInfoView
android:id="@+id/cache_manage" android:id="@+id/cache_manage"
android:layout_width="match_parent" android:layout_width="match_parent"