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