desc:晚上传感器数据上传 接口参数映射
							parent
							
								
									d8215ab95d
								
							
						
					
					
						commit
						c5fe66581b
					
				| @ -0,0 +1,42 @@ | ||||
| package com.yinuo.safetywatcher.watcher.port | ||||
| 
 | ||||
| import com.common.commonlib.CommonApplication | ||||
| import com.common.commonlib.db.DBUtils | ||||
| import kotlinx.coroutines.DelicateCoroutinesApi | ||||
| import kotlinx.coroutines.Dispatchers | ||||
| import kotlinx.coroutines.GlobalScope | ||||
| import kotlinx.coroutines.launch | ||||
| 
 | ||||
| @OptIn(DelicateCoroutinesApi::class) | ||||
| object GasCache { | ||||
|     private val statusCache = HashMap<String, String>() | ||||
|     private val nicknameCache = HashMap<String, String>() | ||||
| 
 | ||||
|     init { | ||||
|         GlobalScope.launch(Dispatchers.IO) { | ||||
|             val typeDao = DBUtils.gasTypeDao() | ||||
|             val all = typeDao.getAll() | ||||
|             val context = CommonApplication.getContext() | ||||
|             all.forEach { | ||||
|                 setNickname(it.type, it.nickName ?: "") | ||||
|                 setStatus(it.type, getShowStatus(context, it.status)) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     fun getNickname(gas: String): String { | ||||
|         return nicknameCache[gas] ?: "" | ||||
|     } | ||||
| 
 | ||||
|     fun getStatus(gas: String): String { | ||||
|         return statusCache[gas] ?: "" | ||||
|     } | ||||
| 
 | ||||
|     fun setNickname(gas: String, nickname: String) { | ||||
|         nicknameCache[gas] = nickname | ||||
|     } | ||||
| 
 | ||||
|     fun setStatus(gas: String, status: String) { | ||||
|         statusCache[gas] = status | ||||
|     } | ||||
| } | ||||
					Loading…
					
					
				
		Reference in New Issue