掘进增加userid
This commit is contained in:
@@ -4,7 +4,9 @@ import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.RawQuery
|
||||
import androidx.room.Update
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceEntity
|
||||
|
||||
//import kotlinx.coroutines.flow.Flow
|
||||
@@ -23,6 +25,9 @@ interface TunnelWorkingFaceDao {
|
||||
@Query("SELECT * FROM tunnel_working_face ORDER BY createTime DESC")
|
||||
fun getEntityList(): MutableList<TunnelWorkingFaceEntity>?
|
||||
|
||||
@RawQuery
|
||||
fun getEntityListBySql(query: SupportSQLiteQuery): MutableList<TunnelWorkingFaceEntity>?
|
||||
|
||||
@Query("SELECT * FROM tunnel_working_face WHERE dataState = :dataState ORDER BY createTime DESC")
|
||||
fun getEntityListByState(dataState: String): MutableList<TunnelWorkingFaceEntity>?
|
||||
|
||||
|
||||
+2
@@ -22,6 +22,8 @@ class TunnelWorkingFaceEntity(
|
||||
@PrimaryKey
|
||||
var surfaceId: Long = 0,
|
||||
|
||||
var userId: String = "",
|
||||
|
||||
/**
|
||||
* 工作面名称
|
||||
*/
|
||||
|
||||
+5
@@ -1,5 +1,6 @@
|
||||
package com.zmkg.coaloperation.db.repository
|
||||
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.zmkg.coaloperation.db.dao.TunnelWorkingFaceDao
|
||||
import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceEntity
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -10,6 +11,10 @@ class TunnelWorkingFaceRepository(private val dao: TunnelWorkingFaceDao) {
|
||||
dao.getEntityList()
|
||||
}
|
||||
|
||||
suspend fun getEntityListBySql(query: SupportSQLiteQuery) = withContext(Dispatchers.IO) {
|
||||
dao.getEntityListBySql(query)
|
||||
}
|
||||
|
||||
suspend fun getEntityListByState(dataState: String) = withContext(Dispatchers.IO) {
|
||||
dao.getEntityListByState(dataState)
|
||||
}
|
||||
|
||||
+24
@@ -3,6 +3,8 @@ package com.zmkg.coaloperation.db.viewmodel
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.zmkg.coaloperation.db.AppDatabase
|
||||
import com.zmkg.coaloperation.db.entity.tunnel.TunnelWorkingFaceEntity
|
||||
import com.zmkg.coaloperation.db.repository.TunnelWorkingFaceRepository
|
||||
@@ -22,6 +24,28 @@ class TunnelWorkingFaceViewModel(application: Application) : AndroidViewModel(ap
|
||||
action(list)
|
||||
}
|
||||
|
||||
fun getEntityListByUserId(userId:String, action: (MutableList<TunnelWorkingFaceEntity>?) -> Unit) =
|
||||
viewModelScope.launch {
|
||||
val sql = buildString {
|
||||
append("SELECT * FROM tunnel_working_face WHERE 1=1 ")
|
||||
if (userId.isNotBlank()) {
|
||||
append(" AND userId = $userId")
|
||||
}
|
||||
}
|
||||
val query = SimpleSQLiteQuery(sql)
|
||||
val list: MutableList<TunnelWorkingFaceEntity>? = repository.getEntityListBySql(query)
|
||||
action(list)
|
||||
}
|
||||
|
||||
fun getEntityListBySql(
|
||||
query: SupportSQLiteQuery,
|
||||
action: (MutableList<TunnelWorkingFaceEntity>?) -> Unit
|
||||
) =
|
||||
viewModelScope.launch {
|
||||
val list: MutableList<TunnelWorkingFaceEntity>? = repository.getEntityListBySql(query)
|
||||
action(list)
|
||||
}
|
||||
|
||||
fun getEntityListByState(
|
||||
dataState: String,
|
||||
action: (MutableList<TunnelWorkingFaceEntity>?) -> Unit
|
||||
|
||||
+17
-11
@@ -9,13 +9,18 @@ import com.zmkg.coaloperation.base.BaseVMBActivity
|
||||
import com.zmkg.coaloperation.base.viewmodel.TestViewModel
|
||||
import com.zmkg.coaloperation.databinding.ActivityLoginBinding
|
||||
import com.zmkg.coaloperation.local.DataStoreManager
|
||||
import com.zmkg.coaloperation.local.DataStoreUtils
|
||||
import com.zmkg.coaloperation.superfuntion.loginIm
|
||||
import com.zmkg.coaloperation.utils.UserUtils
|
||||
import com.zmkg.coaloperation.utils.toJsonString
|
||||
import com.zmkg.coaloperation.utils.toObject
|
||||
|
||||
class LoginActivity : BaseVMBActivity<TestViewModel,ActivityLoginBinding>(R.layout.activity_login) {
|
||||
class LoginActivity :
|
||||
BaseVMBActivity<TestViewModel, ActivityLoginBinding>(R.layout.activity_login) {
|
||||
|
||||
override fun initView(savedInstanceState: Bundle?) {
|
||||
if (!TextUtils.isEmpty(DataStoreManager.getUserName())) {
|
||||
loginIm(DataStoreManager.getUserName()){}
|
||||
loginIm(DataStoreManager.getUserName()) {}
|
||||
toActivity(MainActivity::class.java)
|
||||
finish()
|
||||
}
|
||||
@@ -31,10 +36,10 @@ class LoginActivity : BaseVMBActivity<TestViewModel,ActivityLoginBinding>(R.layo
|
||||
}
|
||||
|
||||
override fun processClick(v: View?) {
|
||||
when(v?.id) {
|
||||
R.id.submit->{
|
||||
val userId = mBinding.loginEtUserName.text.toString()
|
||||
if (TextUtils.isEmpty(userId)) {
|
||||
when (v?.id) {
|
||||
R.id.submit -> {
|
||||
val userName = mBinding.loginEtUserName.text.toString()
|
||||
if (TextUtils.isEmpty(userName)) {
|
||||
showToast("请输入用户名")
|
||||
return
|
||||
}
|
||||
@@ -44,18 +49,19 @@ class LoginActivity : BaseVMBActivity<TestViewModel,ActivityLoginBinding>(R.layo
|
||||
return
|
||||
}
|
||||
|
||||
loginIm(userId) {}
|
||||
DataStoreManager.setUserName(userId)
|
||||
loginIm(userName) {}
|
||||
DataStoreManager.setUserName(userName)
|
||||
|
||||
UserUtils.saveUserData(userName)
|
||||
|
||||
toActivity(MainActivity::class.java)
|
||||
finish()
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun transparentStatusBar():Boolean {
|
||||
override fun transparentStatusBar(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -16,6 +16,7 @@ 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 com.zmkg.coaloperation.utils.SpTool
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
@@ -77,7 +78,7 @@ class TunnelingActivity :
|
||||
|
||||
override fun initView(savedInstanceState: Bundle?) {
|
||||
mBinding.toolbarLay.rightText = "新增工作面"
|
||||
mBinding.rvList.let {
|
||||
mBinding.rvTunnelingList.let {
|
||||
it.layoutManager = LinearLayoutManager(this)
|
||||
it.adapter = workingFaceAdapter
|
||||
}
|
||||
@@ -86,9 +87,10 @@ class TunnelingActivity :
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun initData() {
|
||||
DictUtils.initData()
|
||||
workingFaceViewModel.getEntityList { it ->
|
||||
val userId = SpTool.getString(SpTool.USER_ID)
|
||||
workingFaceViewModel.getEntityListByUserId(userId) { it ->
|
||||
if (it.isNullOrEmpty()) {
|
||||
return@getEntityList
|
||||
return@getEntityListByUserId
|
||||
}
|
||||
workingFaceList.clear()
|
||||
workingFaceList.addAll(it)
|
||||
@@ -99,7 +101,6 @@ class TunnelingActivity :
|
||||
|
||||
override fun createObserve() {
|
||||
super.createObserve()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import kotlin.to
|
||||
object SpTool {
|
||||
|
||||
const val DICT_JSON = "dictJson"
|
||||
const val USER_JSON = "userJson"
|
||||
const val USER_ACCOUNT = "userAccount"
|
||||
|
||||
val pref = MyApplication.getSharedPref()!!
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.zmkg.coaloperation.utils
|
||||
|
||||
import com.zmkg.coaloperation.local.DataStoreManager
|
||||
import com.zmkg.coaloperation.local.DataStoreUtils
|
||||
|
||||
object UserUtils {
|
||||
|
||||
const val USER_DATA = "userData"
|
||||
|
||||
fun saveUserData(userName: String) {
|
||||
var userData = DataStoreUtils.getSyncData(USER_DATA, "")
|
||||
var userMap: MutableMap<String, String?> = mutableMapOf()
|
||||
if (userData.isBlank()) {
|
||||
userMap.put(userName, System.currentTimeMillis().toString())
|
||||
} else {
|
||||
userMap = userData.toObject<MutableMap<String, String?>>()
|
||||
val userId = userMap[userName]
|
||||
if (userId.isNullOrBlank()) {
|
||||
// TODO: -----------
|
||||
}
|
||||
}
|
||||
userData = userMap.toJsonString()
|
||||
DataStoreUtils.putSyncData(USER_DATA, userData)
|
||||
}
|
||||
|
||||
fun getUserName() = DataStoreManager.getUserName()
|
||||
|
||||
fun getUserId(userName: String = getUserName()): String? {
|
||||
val userData = DataStoreUtils.getSyncData(USER_DATA, "")
|
||||
if (userData.isBlank()) {
|
||||
return null
|
||||
}
|
||||
val userMap = userData.toObject<MutableMap<String, String?>>()
|
||||
return userMap[userName]
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
layout="@layout/lay_title_right_bar" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_list"
|
||||
android:id="@+id/rvMiningList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:overScrollMode="never"
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
app:title="@{@string/title_tunneling}" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvMiningList"
|
||||
android:id="@+id/rvTunnelingList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:overScrollMode="never"
|
||||
|
||||
Reference in New Issue
Block a user