|
@@ -1,5 +1,6 @@
|
|
|
package com.sybotan.android.demo.viewmodel
|
|
|
|
|
|
+import android.app.Activity.RESULT_OK
|
|
|
import android.app.Application
|
|
|
import android.graphics.PointF
|
|
|
import android.text.TextUtils
|
|
@@ -7,15 +8,11 @@ import androidx.lifecycle.viewModelScope
|
|
|
import cn.sagacloud.android.cadengine.items.PointItem
|
|
|
import cn.sagacloud.android.cadengine.items.SpaceItem
|
|
|
import cn.sagacloud.android.cadengine.items.TunableSpaceItem
|
|
|
-import cn.sagacloud.android.cadengine.types.Photos
|
|
|
-import cn.sagacloud.android.cadengine.types.Point
|
|
|
-import cn.sagacloud.android.cadengine.types.PointZ
|
|
|
-import cn.sagacloud.android.cadengine.types.TunableSpace
|
|
|
+import cn.sagacloud.android.cadengine.types.*
|
|
|
import com.framework.mvvm.model.db.entity.*
|
|
|
import com.framework.mvvm.model.repository.AdmRepository
|
|
|
import com.sybotan.android.demo.bean.result.ProblemsModel
|
|
|
import com.google.gson.Gson
|
|
|
-import com.google.gson.JsonObject
|
|
|
import com.google.gson.reflect.TypeToken
|
|
|
import com.sybotan.android.demo.activities.BaseActivity
|
|
|
import com.sybotan.android.demo.bean.request.*
|
|
@@ -25,6 +22,9 @@ import com.sybotan.android.demo.bean.result.Z
|
|
|
import com.sybotan.android.demo.retrofit.BaseObserver
|
|
|
import com.sybotan.android.demo.retrofit.BaseViewModelInterface
|
|
|
import com.sybotan.android.demo.retrofit.RetrofitFactory
|
|
|
+import com.sybotan.android.demo.tools.CommonUtils
|
|
|
+import com.sybotan.android.demo.tools.ToastUtils
|
|
|
+import com.sybotan.base.utils.SJsonUtil
|
|
|
import kotlinx.coroutines.launch
|
|
|
import org.json.JSONObject
|
|
|
import org.kodein.di.DI
|
|
@@ -34,6 +34,7 @@ import org.kodein.di.instance
|
|
|
import java.text.SimpleDateFormat
|
|
|
import java.util.*
|
|
|
import kotlin.collections.ArrayList
|
|
|
+import kotlin.collections.HashMap
|
|
|
|
|
|
/**
|
|
|
* Created by lihao.
|
|
@@ -152,17 +153,21 @@ class GraphyVM(
|
|
|
}
|
|
|
|
|
|
var problem = ProblemArchEntity(
|
|
|
- toString,
|
|
|
- floorId,
|
|
|
- projectId,
|
|
|
- buildingId,
|
|
|
- "point", "",
|
|
|
- "",
|
|
|
- 1,
|
|
|
- content,
|
|
|
- "",
|
|
|
- time,
|
|
|
- "android", time, "0", 1, toJson
|
|
|
+ id = toString,
|
|
|
+ floorId = floorId,
|
|
|
+ projectId = projectId,
|
|
|
+ buildingId = buildingId,
|
|
|
+ geomType = "point", workId = "",
|
|
|
+ problemType = "",
|
|
|
+ problemState = 1,
|
|
|
+ message = content,
|
|
|
+ creator = "",
|
|
|
+ creationTime = time,
|
|
|
+ modifier = "android",
|
|
|
+ modifiedTime = time,
|
|
|
+ uploadFlag = "",
|
|
|
+ valid = 1,
|
|
|
+ geom = toJson
|
|
|
)
|
|
|
repo.insProblem(problem)
|
|
|
|
|
@@ -179,24 +184,24 @@ class GraphyVM(
|
|
|
}
|
|
|
|
|
|
val file = FileEntity(
|
|
|
- uuid,
|
|
|
- "problem_arch",
|
|
|
- photo.key,
|
|
|
- "photo",
|
|
|
- photo.path,
|
|
|
- toString,
|
|
|
- "",
|
|
|
- "",
|
|
|
- order,
|
|
|
- projectId,
|
|
|
- buildingId,
|
|
|
- floorId,
|
|
|
- "android",
|
|
|
- time,
|
|
|
- "",
|
|
|
- time,
|
|
|
- 1,
|
|
|
- "0"
|
|
|
+ id = uuid,
|
|
|
+ bizType = "problem_arch",
|
|
|
+ filePath = photo.key,
|
|
|
+ fileType = "photo",
|
|
|
+ clientPath = photo.path,
|
|
|
+ refObjId = toString,
|
|
|
+ refInfoCode = "",
|
|
|
+ remark = "",
|
|
|
+ orderNum = order,
|
|
|
+ projectId = projectId,
|
|
|
+ buildingId = buildingId,
|
|
|
+ floorId = floorId,
|
|
|
+ creator = "android",
|
|
|
+ creationTime = time,
|
|
|
+ modifier = "",
|
|
|
+ modifiedTime = time,
|
|
|
+ valid = 1,
|
|
|
+ uploadFlag = ""
|
|
|
)
|
|
|
repo.insFile(file)
|
|
|
}
|
|
@@ -316,7 +321,7 @@ class GraphyVM(
|
|
|
modifier = "Android",
|
|
|
modifiedTime = time,
|
|
|
valid = 1,
|
|
|
- uploadFlag = "0"
|
|
|
+ uploadFlag = ""
|
|
|
)
|
|
|
repo.insQrcode(qrcode)
|
|
|
mEmitter.SendDircetive(BIND_QECODE, null)
|
|
@@ -418,15 +423,78 @@ class GraphyVM(
|
|
|
* @param choseSpace 选中的空间
|
|
|
*/
|
|
|
fun getSpaceEq(choseSpace: TunableSpaceItem?) {
|
|
|
- val bean = ReqSpaceEq()
|
|
|
- bean.group = true
|
|
|
- bean.spaceId = choseSpace!!.data.id
|
|
|
- val observable = RetrofitFactory.getInstance().getSpaceEq(getRequestBody(bean))
|
|
|
- sendRequest(observable, object : BaseObserver<List<SpaceEqModel>>(mActivity, this) {
|
|
|
- override fun onSuccess(models: List<SpaceEqModel>) {
|
|
|
- mEmitter.SendDircetive(SPACE_EQ, models)
|
|
|
+ viewModelScope.launch {
|
|
|
+ var equips = repo.getEquipByFloorId(floorId)
|
|
|
+
|
|
|
+ var models: ArrayList<SpaceEqModel> = ArrayList()
|
|
|
+ for (equip in equips) {
|
|
|
+ var hasParent = false
|
|
|
+ for (model in models) {
|
|
|
+ if (model.type!!.equals(equip.classCode)) {
|
|
|
+ hasParent = true
|
|
|
+ val child = Children()
|
|
|
+ child.deviceId = equip.id
|
|
|
+ child.name = equip.name
|
|
|
+ val strInfo = gson.fromJson(equip.strInfos, StrInfosforEquip::class.java)
|
|
|
+ val eqProblems = repo.getEqProblem(equip.id)
|
|
|
+ if (eqProblems != null && !TextUtils.isEmpty(eqProblems.id)) {
|
|
|
+ child.type = 3
|
|
|
+ } else if (strInfo.equipCheck) {
|
|
|
+ child.type = 2
|
|
|
+ } else {
|
|
|
+ child.type = 1
|
|
|
+ }
|
|
|
+ val position = Position()
|
|
|
+ position.x = strInfo.location.x.toString()
|
|
|
+ position.y = strInfo.location.y.toString()
|
|
|
+ val z = Z()
|
|
|
+ z.offset = strInfo.location.z.toString()
|
|
|
+ z.region = strInfo.zRegion
|
|
|
+ position.z = z
|
|
|
+ child.position = gson.toJson(position)
|
|
|
+ model.children.add(child)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!hasParent) {
|
|
|
+ val spaceModel = SpaceEqModel()
|
|
|
+ spaceModel.type = equip.classCode
|
|
|
+ var equipEntity = repo.getEquipByCode(equip.classCode)
|
|
|
+ spaceModel.typeName = equipEntity.name
|
|
|
+ val child = Children()
|
|
|
+ child.deviceId = equip.id
|
|
|
+ child.name = equip.name
|
|
|
+ val strInfo = gson.fromJson(equip.strInfos, StrInfosforEquip::class.java)
|
|
|
+ val eqProblems = repo.getEqProblem(equip.id)
|
|
|
+ if (eqProblems != null && !TextUtils.isEmpty(eqProblems.id)) {
|
|
|
+ child.type = 3
|
|
|
+ } else if (strInfo.equipCheck) {
|
|
|
+ child.type = 2
|
|
|
+ } else {
|
|
|
+ child.type = 1
|
|
|
+ }
|
|
|
+ val position = Position()
|
|
|
+ position.x = strInfo.location.x.toString()
|
|
|
+ position.y = strInfo.location.y.toString()
|
|
|
+ val z = Z()
|
|
|
+ z.offset = strInfo.location.z.toString()
|
|
|
+ z.region = strInfo.zRegion
|
|
|
+ position.z = z
|
|
|
+ child.position = gson.toJson(position)
|
|
|
+ spaceModel.children.add(child)
|
|
|
+ models.add(spaceModel)
|
|
|
+ }
|
|
|
}
|
|
|
- }, true)
|
|
|
+ mEmitter.SendDircetive(SPACE_EQ, models)
|
|
|
+ }
|
|
|
+// val bean = ReqSpaceEq()
|
|
|
+// bean.group = true
|
|
|
+// bean.spaceId = choseSpace!!.data.id
|
|
|
+// val observable = RetrofitFactory.getInstance().getSpaceEq(getRequestBody(bean))
|
|
|
+// sendRequest(observable, object : BaseObserver<List<SpaceEqModel>>(mActivity, this) {
|
|
|
+// override fun onSuccess(models: List<SpaceEqModel>) {
|
|
|
+// mEmitter.SendDircetive(SPACE_EQ, models)
|
|
|
+// }
|
|
|
+// }, true)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -450,42 +518,80 @@ class GraphyVM(
|
|
|
* @param choseSpace 被选中的空间
|
|
|
*/
|
|
|
fun addPipe(
|
|
|
- model: PipeListModel,
|
|
|
- pipeLineList: java.util.ArrayList<PointF>,
|
|
|
- remark: String,
|
|
|
- choseSpace: TunableSpaceItem?
|
|
|
+// model: PipeListModel,
|
|
|
+// pipeLineList: java.util.ArrayList<PointF>,
|
|
|
+// remark: String,
|
|
|
+// choseSpace: TunableSpaceItem?
|
|
|
) {
|
|
|
- val bean = ReqAddPipe()
|
|
|
- bean.spaceId = choseSpace!!.data.id
|
|
|
- bean.sys = model.sysCode
|
|
|
- bean.type = model.code
|
|
|
- bean.position = pipeLineList
|
|
|
- bean.remark = remark
|
|
|
- bean.name = model.name
|
|
|
- val observable = RetrofitFactory.getInstance().addPipe(getRequestBody(bean))
|
|
|
- sendRequest(observable, object : BaseObserver<AddPipeModel>(mActivity, this) {
|
|
|
- override fun onSuccess(models: AddPipeModel) {
|
|
|
- mEmitter.SendDircetive(ADD_PIPE, null)
|
|
|
- }
|
|
|
- }, true)
|
|
|
+// val bean = ReqAddPipe()
|
|
|
+// bean.spaceId = choseSpace!!.data.id
|
|
|
+// bean.sys = model.sysCode
|
|
|
+// bean.type = model.code
|
|
|
+// bean.position = pipeLineList
|
|
|
+// bean.remark = remark
|
|
|
+// bean.name = model.name
|
|
|
+// val observable = RetrofitFactory.getInstance().addPipe(getRequestBody(bean))
|
|
|
+// sendRequest(observable, object : BaseObserver<AddPipeModel>(mActivity, this) {
|
|
|
+// override fun onSuccess(models: AddPipeModel) {
|
|
|
+// mEmitter.SendDircetive(ADD_PIPE, null)
|
|
|
+// }
|
|
|
+// }, true)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询楼层下的管道数据
|
|
|
*/
|
|
|
fun floorPipe() {
|
|
|
- val bean = ReqFloorPipe()
|
|
|
- bean.floorId = floorId
|
|
|
- val observable = RetrofitFactory.getInstance().floorPipe(getRequestBody(bean))
|
|
|
- sendRequest(
|
|
|
- observable,
|
|
|
- object : BaseObserver<java.util.ArrayList<SpacePipeModel>>(mActivity, this) {
|
|
|
- override fun onSuccess(models: java.util.ArrayList<SpacePipeModel>) {
|
|
|
- mEmitter.SendDircetive(SPACE_PIPE, models)
|
|
|
+ viewModelScope.launch {
|
|
|
+ val pipeModels = ArrayList<SpacePipeModel>()
|
|
|
+ val pipes = repo.getPipeByFloorId(floorId)
|
|
|
+ for (pipe in pipes) {
|
|
|
+ var hasParent = false
|
|
|
+ for (model in pipeModels) {
|
|
|
+ if (model.type!!.equals(pipe.pipeType)) {
|
|
|
+ val child = ChildrenZ()
|
|
|
+ val objFrom = repo.getObject(pipe.objFrom!!)
|
|
|
+ val objTo = repo.getObject(pipe.objTo!!)
|
|
|
+ val strInfoFrom =
|
|
|
+ gson.fromJson(objFrom.strInfos, StrInfosforEquip::class.java)
|
|
|
+ child.position.add(PointF(strInfoFrom.location.x, strInfoFrom.location.y))
|
|
|
+
|
|
|
+ val strInfoTo = gson.fromJson(objTo.strInfos, StrInfosforEquip::class.java)
|
|
|
+ child.position.add(PointF(strInfoTo.location.x, strInfoTo.location.y))
|
|
|
+ model.children.add(child)
|
|
|
+ hasParent = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!hasParent) {
|
|
|
+ val pipeModel = SpacePipeModel()
|
|
|
+ pipeModel.typeName = pipe.pipeType
|
|
|
+
|
|
|
+ val child = ChildrenZ()
|
|
|
+ val objFrom = repo.getObject(pipe.objFrom!!)
|
|
|
+ val objTo = repo.getObject(pipe.objTo!!)
|
|
|
+ val strInfoFrom = gson.fromJson(objFrom.strInfos, StrInfosforEquip::class.java)
|
|
|
+ child.position.add(PointF(strInfoFrom.location.x, strInfoFrom.location.y))
|
|
|
+
|
|
|
+ val strInfoTo = gson.fromJson(objTo.strInfos, StrInfosforEquip::class.java)
|
|
|
+ child.position.add(PointF(strInfoTo.location.x, strInfoTo.location.y))
|
|
|
+ pipeModel.children.add(child)
|
|
|
+ pipeModels.add(pipeModel)
|
|
|
}
|
|
|
- },
|
|
|
- true
|
|
|
- )
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+// val bean = ReqFloorPipe()
|
|
|
+// bean.floorId = floorId
|
|
|
+// val observable = RetrofitFactory.getInstance().floorPipe(getRequestBody(bean))
|
|
|
+// sendRequest(
|
|
|
+// observable,
|
|
|
+// object : BaseObserver<ArrayList<SpacePipeModel>>(mActivity, this) {
|
|
|
+// override fun onSuccess(models: java.util.ArrayList<SpacePipeModel>) {
|
|
|
+// mEmitter.SendDircetive(SPACE_PIPE, models)
|
|
|
+// }
|
|
|
+// },
|
|
|
+// true
|
|
|
+// )
|
|
|
}
|
|
|
|
|
|
fun getInfosConfig(spaceId: String) {
|
|
@@ -498,15 +604,34 @@ class GraphyVM(
|
|
|
strInfos,
|
|
|
object : TypeToken<List<Infos?>?>() {}.type
|
|
|
)
|
|
|
+ var spaceObject = repo.getObject(spaceId)
|
|
|
+ var infos = spaceObject.infos
|
|
|
+
|
|
|
+ mEmitter.SendDircetive(SPACE_INFOS, jsonObjectToHashMap(infos))
|
|
|
mEmitter.SendDircetive(SPACE_INFO, infoList)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ fun jsonObjectToHashMap(jsonObj: JSONObject?): HashMap<String, String>? {
|
|
|
+ if (jsonObj == null) {
|
|
|
+ return null
|
|
|
+ }
|
|
|
+ val data = HashMap<String, String>()
|
|
|
+ val it: Iterator<*> = jsonObj.keys()
|
|
|
+ while (it.hasNext()) {
|
|
|
+ val key = it.next().toString()
|
|
|
+ data[key] = jsonObj[key].toString()
|
|
|
+ }
|
|
|
+ System.out.println(data)
|
|
|
+ return data
|
|
|
+ }
|
|
|
+
|
|
|
fun refreshObject(space: TunableSpace, hashMap: HashMap<String, Any>) {
|
|
|
viewModelScope.launch {
|
|
|
var space = repo.getObject(space.id!!)
|
|
|
space.infos = JSONObject(hashMap as Map<*, *>)
|
|
|
repo.insObject(space)
|
|
|
+ mActivity.setResult(RESULT_OK)
|
|
|
mActivity.finish()
|
|
|
// var objectEntity = ObjectEntity(
|
|
|
// id = space.id!!,
|
|
@@ -517,7 +642,440 @@ class GraphyVM(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ fun getEquipment(deviceId: String) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ val equips = repo.getEquipment()
|
|
|
+ for (equip in equips) {
|
|
|
+ if (!TextUtils.isEmpty(equip.systemCode)) {
|
|
|
+ val systemEntity = repo.getSysByCode(equip.systemCode!!)
|
|
|
+ equip.systemName = systemEntity.name
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mEmitter.SendDircetive(EQUIP_CLASS, equips)
|
|
|
+
|
|
|
+ if (!TextUtils.isEmpty(deviceId)) {
|
|
|
+ var equip = repo.getObject(deviceId)
|
|
|
+ var infos = equip.infos
|
|
|
+ mEmitter.SendDircetive(SPACE_INFOS, jsonObjectToHashMap(infos))
|
|
|
+ mEmitter.SendDircetive(Equip_INFOS, equip)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// var infoList = gson.fromJson(strInfos, ArrayList<Infos>()::class.java)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun getEquipInfosConfig(equipmentEntity: EquipmentEntity) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ val infosConfig = repo.getInfosConfigByEquipCode(equipmentEntity.code!!)
|
|
|
+ if (CommonUtils.IsNull(infosConfig)) {
|
|
|
+ mEmitter.SendDircetive(EQUIP_INFO, null)
|
|
|
+ return@launch
|
|
|
+ }
|
|
|
+ val strInfos = infosConfig.get(0).strInfos
|
|
|
+ val infoList = gson.fromJson<List<Infos>>(
|
|
|
+ strInfos,
|
|
|
+ object : TypeToken<List<Infos?>?>() {}.type
|
|
|
+ )
|
|
|
+ mEmitter.SendDircetive(EQUIP_INFO, infoList)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun insEquip(
|
|
|
+ uuid: String,
|
|
|
+ deviceId: String?,
|
|
|
+ hashMap: HashMap<String, Any>?,
|
|
|
+ equipContent: String,
|
|
|
+ beans: ArrayList<Photos>,
|
|
|
+ equipEntity: EquipmentEntity,
|
|
|
+ localName: String,
|
|
|
+ localId: String,
|
|
|
+ checked: Boolean,
|
|
|
+ position: Position
|
|
|
+ ) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ hashMap!!.put("equipContent", equipContent)
|
|
|
+ hashMap!!.put("equipPhoto", gson.toJson(beans))
|
|
|
+ hashMap!!.put("equipCheck", checked)
|
|
|
+ val z = PointZ()
|
|
|
+ z.x = position.x.toFloat()
|
|
|
+ z.y = -position.y.toFloat()
|
|
|
+ z.z = position.z.offset.toFloat()
|
|
|
+ hashMap!!.put("location", z)
|
|
|
+ hashMap!!.put("zRegion", position.z.region)
|
|
|
+ if (TextUtils.isEmpty(deviceId)) {
|
|
|
+ val objectEntity = ObjectEntity(
|
|
|
+ id = uuid,
|
|
|
+ name = localName,
|
|
|
+ projectId = projectId,
|
|
|
+ objType = "equipment",
|
|
|
+ classCode = equipEntity.code!!,
|
|
|
+ localId = localId,
|
|
|
+ localName = localName,
|
|
|
+ groupCode = "",
|
|
|
+ grouping = 1,
|
|
|
+ buildingId = buildingId,
|
|
|
+ floorId = floorId,
|
|
|
+ creator = "Android",
|
|
|
+ createApp = "",
|
|
|
+ creationTime = SimpleDateFormat("yyyyMMddHHmmss").format(Date(System.currentTimeMillis()))
|
|
|
+ .toLong(),
|
|
|
+ modifier = "Android",
|
|
|
+ modifiedTime = 0,
|
|
|
+ clientDevice = "",
|
|
|
+ clientId = uuid,
|
|
|
+ updateApp = "",
|
|
|
+ uploadFlag = "",
|
|
|
+ valid = 1,
|
|
|
+ deliveryState = null,
|
|
|
+ d2mState = null,
|
|
|
+ virtualCodes = null,
|
|
|
+ infos = JSONObject(hashMap as Map<*, *>),
|
|
|
+ strInfos = gson.toJson(hashMap),
|
|
|
+ floorMap = null
|
|
|
+ )
|
|
|
+ repo.insObject(objectEntity)
|
|
|
+ } else {
|
|
|
+ val equip = repo.getObject(deviceId!!)
|
|
|
+ equip.infos = JSONObject(hashMap as Map<*, *>)
|
|
|
+ equip.strInfos = gson.toJson(hashMap)
|
|
|
+ repo.insObject(equip)
|
|
|
+ }
|
|
|
+ //插入文件数据
|
|
|
+ var order = 0
|
|
|
+ for (photo in beans) {
|
|
|
+ if (order != 0) {
|
|
|
+ var phUuid = ""
|
|
|
+ if (TextUtils.isEmpty(photo.id)) {
|
|
|
+ phUuid = UUID.randomUUID().toString().replace("-", "")
|
|
|
+ } else {
|
|
|
+ phUuid = photo.id
|
|
|
+ }
|
|
|
+
|
|
|
+ val file = FileEntity(
|
|
|
+ id = phUuid,
|
|
|
+ bizType = "problem_arch",
|
|
|
+ filePath = photo.key,
|
|
|
+ fileType = "photo",
|
|
|
+ clientPath = photo.path,
|
|
|
+ refObjId = if (TextUtils.isEmpty(deviceId)) uuid else deviceId,
|
|
|
+ refInfoCode = "",
|
|
|
+ remark = "",
|
|
|
+ orderNum = order,
|
|
|
+ projectId = projectId,
|
|
|
+ buildingId = buildingId,
|
|
|
+ floorId = floorId,
|
|
|
+ creator = "android",
|
|
|
+ creationTime = "",
|
|
|
+ modifier = "",
|
|
|
+ modifiedTime = null,
|
|
|
+ valid = 1,
|
|
|
+ uploadFlag = ""
|
|
|
+ )
|
|
|
+ repo.insFile(file)
|
|
|
+ }
|
|
|
+ order++
|
|
|
+ }
|
|
|
+
|
|
|
+ mActivity.finish()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun getMap() {
|
|
|
+ viewModelScope.launch {
|
|
|
+ val floors = repo.getFloors()
|
|
|
+ for (floor in floors) {
|
|
|
+ if (floor.id.equals(floorId)) {
|
|
|
+ if (TextUtils.isEmpty(floor.floorMap)) {
|
|
|
+ ToastUtils.showMyToast("没有地图")
|
|
|
+ break
|
|
|
+ }
|
|
|
+ val floorOfflineData =
|
|
|
+ SJsonUtil.fromJson(floor.floorMap!!, FloorData::class.java)
|
|
|
+ mEmitter.SendDircetive(MAP_LOAD, gson.toJson(floorOfflineData))
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun getRelConfig(entity: EquipmentEntity, deviceId: String, uuid: String) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ val equipId = if (TextUtils.isEmpty(deviceId)) uuid else deviceId
|
|
|
+ //获取关系二级列表
|
|
|
+ val configParent = ArrayList<RelConfigEntity>()
|
|
|
+ val relList = mutableListOf<List<RelationEntity>>()
|
|
|
+ val fromList = repo.getRelConfigByCodeFrom(entity.code!!)
|
|
|
+ val toList = repo.getRelConfigByCodeTo(entity.code!!)
|
|
|
+ configParent.addAll(fromList)
|
|
|
+ for (config in fromList) {
|
|
|
+ val relsFrom = repo.getRelByCodeFrom(config.graphCode!!, config.relCode!!, equipId)
|
|
|
+ if (!CommonUtils.IsNull(relsFrom)) {
|
|
|
+ for (rel in relsFrom) {
|
|
|
+ val objFrom = repo.getObject(rel.objFrom!!)
|
|
|
+ val objTo = repo.getObject(rel.objTo!!)
|
|
|
+ rel.objFromLocalId = objFrom.localId
|
|
|
+ rel.objToLocalId = objTo.localId
|
|
|
+ }
|
|
|
+ relList.add(relsFrom)
|
|
|
+ } else {
|
|
|
+ relList.add(ArrayList<RelationEntity>())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ configParent.addAll(toList)
|
|
|
+ for (config in toList) {
|
|
|
+ val relsTo = repo.getRelByCodeTo(config.graphCode!!, config.relCode!!, equipId)
|
|
|
+ if (!CommonUtils.IsNull(relsTo)) {
|
|
|
+ for (rel in relsTo) {
|
|
|
+ val objFrom = repo.getObject(rel.objFrom!!)
|
|
|
+ val objTo = repo.getObject(rel.objTo!!)
|
|
|
+ rel.objFromLocalId = objFrom.localId
|
|
|
+ rel.objToLocalId = objTo.localId
|
|
|
+ }
|
|
|
+ relList.add(relsTo)
|
|
|
+ } else {
|
|
|
+ relList.add(ArrayList<RelationEntity>())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val hashMap = HashMap<String, Any>()
|
|
|
+ hashMap.put("parent", configParent)
|
|
|
+ hashMap.put("child", relList)
|
|
|
+ mEmitter.SendDircetive(EQUIP_REL, hashMap)
|
|
|
+
|
|
|
+ //获取管道二级列表
|
|
|
+ val pipeParent = ArrayList<PipeConfigEntity>()
|
|
|
+ val pipeChildren = mutableListOf<List<PipeEntity>>()
|
|
|
+ val pipeFromList = repo.getPipeConfigByCodeFrom(entity.code!!)
|
|
|
+ val pipeToList = repo.getPipeConfigByCodeTo(entity.code!!)
|
|
|
+
|
|
|
+ pipeParent.addAll(pipeFromList)
|
|
|
+ for (config in pipeFromList) {
|
|
|
+ val pipeFrom = repo.getPipeByIdFrom(equipId, config.pipeType!!)
|
|
|
+ if (!CommonUtils.IsNull(pipeFrom)) {
|
|
|
+ for (rel in pipeFrom) {
|
|
|
+ val objFrom = repo.getObject(rel.objFrom!!)
|
|
|
+ val objTo = repo.getObject(rel.objTo!!)
|
|
|
+ rel.objFromLocalId = objFrom.localId
|
|
|
+ rel.objToLocalId = objTo.localId
|
|
|
+ }
|
|
|
+ pipeChildren.add(pipeFrom)
|
|
|
+ } else {
|
|
|
+ pipeChildren.add(ArrayList<PipeEntity>())
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pipeParent.addAll(pipeToList)
|
|
|
+ for (config in pipeToList) {
|
|
|
+ val pipeFrom = repo.getPipeByIdTo(equipId, config.pipeType!!)
|
|
|
+ if (!CommonUtils.IsNull(pipeFrom)) {
|
|
|
+ for (rel in pipeFrom) {
|
|
|
+ val objFrom = repo.getObject(rel.objFrom!!)
|
|
|
+ val objTo = repo.getObject(rel.objTo!!)
|
|
|
+ rel.objFromLocalId = objFrom.localId
|
|
|
+ rel.objToLocalId = objTo.localId
|
|
|
+ }
|
|
|
+ pipeChildren.add(pipeFrom)
|
|
|
+ } else {
|
|
|
+ pipeChildren.add(ArrayList<PipeEntity>())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val hashMap1 = HashMap<String, Any>()
|
|
|
+ hashMap1.put("parent", pipeParent)
|
|
|
+ hashMap1.put("child", pipeChildren)
|
|
|
+ mEmitter.SendDircetive(PIPE, hashMap1)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun getRelObj(group: RelConfigEntity, code: String) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ val objects: List<ObjectEntity>
|
|
|
+ if (group.classCodeFrom.equals(code)) {
|
|
|
+ objects = repo.getObjectByCode(group.classCodeTo!!)
|
|
|
+ } else {
|
|
|
+ objects = repo.getObjectByCode(group.classCodeFrom!!)
|
|
|
+ }
|
|
|
+ mEmitter.SendDircetive(REL_OBJECT, objects)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun getPipeObj(group: PipeConfigEntity, code: String) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ val objects: List<ObjectEntity>
|
|
|
+ if (group.classCodeFrom.equals(code)) {
|
|
|
+ objects = repo.getObjectByCode(group.classCodeTo!!)
|
|
|
+ } else {
|
|
|
+ objects = repo.getObjectByCode(group.classCodeFrom!!)
|
|
|
+ }
|
|
|
+ mEmitter.SendDircetive(PIPE_OBJECT, objects)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun addRel(
|
|
|
+ deviceId: String, uuid: String, equipEntity: EquipmentEntity,
|
|
|
+ equip: ObjectEntity,
|
|
|
+ groupRelConfigEntity: RelConfigEntity
|
|
|
+ ) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ var equipId: String
|
|
|
+ if (TextUtils.isEmpty(deviceId)) {
|
|
|
+ equipId = uuid
|
|
|
+ } else {
|
|
|
+ equipId = deviceId
|
|
|
+ }
|
|
|
+ val objFrom: String
|
|
|
+ val objto: String
|
|
|
+ if (groupRelConfigEntity.classCodeFrom.equals(equipEntity!!.code)) {
|
|
|
+ objFrom = equipId
|
|
|
+ objto = equip.id
|
|
|
+ } else {
|
|
|
+ objto = equipId
|
|
|
+ objFrom = equip.id
|
|
|
+ }
|
|
|
+
|
|
|
+ val relEntity = RelationEntity(
|
|
|
+ id = UUID.randomUUID().toString(),
|
|
|
+ projectId = projectId,
|
|
|
+ buildingId = buildingId,
|
|
|
+ floorId = floorId,
|
|
|
+ graphCode = groupRelConfigEntity.graphCode,
|
|
|
+ graphId = null,
|
|
|
+ groupCode = null,
|
|
|
+ relCode = groupRelConfigEntity.relCode,
|
|
|
+ relValue = null,
|
|
|
+ objFrom = objFrom,
|
|
|
+ objTo = objto,
|
|
|
+ createApp = null,
|
|
|
+ updateApp = null,
|
|
|
+ creator = null,
|
|
|
+ creationTime = null,
|
|
|
+ modifiedTime = null,
|
|
|
+ modifier = null,
|
|
|
+ clientId = null,
|
|
|
+ clientDevice = null,
|
|
|
+ uploadFlag = null,
|
|
|
+ deliveryState = null,
|
|
|
+ valid = 1, d2mState = null, objFromLocalId = null, objToLocalId = null
|
|
|
+ )
|
|
|
+ repo.insRelation(relEntity)
|
|
|
+ getRelConfig(equipEntity, deviceId, uuid)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun addPipe(
|
|
|
+ deviceId: String, uuid: String, equipEntity: EquipmentEntity,
|
|
|
+ equip: ObjectEntity,
|
|
|
+ groupPipeConfigEntity: PipeConfigEntity
|
|
|
+ ) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ var equipId: String
|
|
|
+ if (TextUtils.isEmpty(deviceId)) {
|
|
|
+ equipId = uuid
|
|
|
+ } else {
|
|
|
+ equipId = deviceId
|
|
|
+ }
|
|
|
+ val objFrom: String
|
|
|
+ val objto: String
|
|
|
+ if (groupPipeConfigEntity.classCodeFrom.equals(equipEntity!!.code)) {
|
|
|
+ objFrom = equipId
|
|
|
+ objto = equip.id
|
|
|
+ } else {
|
|
|
+ objto = equipId
|
|
|
+ objFrom = equip.id
|
|
|
+ }
|
|
|
+
|
|
|
+ val relEntity = PipeEntity(
|
|
|
+ id = UUID.randomUUID().toString(),
|
|
|
+ projectId = projectId,
|
|
|
+ buildingId = buildingId,
|
|
|
+ floorId = floorId,
|
|
|
+
|
|
|
+ objFrom = objFrom,
|
|
|
+ objTo = objto,
|
|
|
+
|
|
|
+ creator = null,
|
|
|
+ creationTime = null,
|
|
|
+ modifiedTime = null,
|
|
|
+ modifier = null,
|
|
|
+ uploadFlag = null,
|
|
|
+ deliveryState = null,
|
|
|
+ valid = 1,
|
|
|
+ d2mState = null,
|
|
|
+ objFromLocalId = null,
|
|
|
+ objToLocalId = null,
|
|
|
+ direction = groupPipeConfigEntity.pipeDirection,
|
|
|
+ typeFrom = "equipment",
|
|
|
+ typeTo = "equipment",
|
|
|
+ pipeType = groupPipeConfigEntity.pipeType,
|
|
|
+ pipeSubType = groupPipeConfigEntity.pipeSubType,
|
|
|
+ route = null,
|
|
|
+ infos = null
|
|
|
+ )
|
|
|
+ repo.insPipe(relEntity)
|
|
|
+ getRelConfig(equipEntity, deviceId, uuid)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun insProblemEquip(space: TunableSpaceItem, deviceId: String) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ val entity = ProblemEquipEntity(
|
|
|
+ id = UUID.randomUUID().toString(),
|
|
|
+ floorId = floorId,
|
|
|
+ projectId = projectId,
|
|
|
+ buildingId = buildingId,
|
|
|
+ equipId = deviceId,
|
|
|
+ workId = null,
|
|
|
+ problemType = null,
|
|
|
+ problemState = 1,
|
|
|
+ message = null,
|
|
|
+ creator = null,
|
|
|
+ creationTime = null,
|
|
|
+ modifier = null,
|
|
|
+ modifiedTime = null,
|
|
|
+ uploadFlag = null,
|
|
|
+ valid = 1
|
|
|
+ )
|
|
|
+ repo.insProblemEquipEntity(entity)
|
|
|
+ }
|
|
|
+ getSpaceEq(space)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun deleteRel(
|
|
|
+ item: RelationEntity,
|
|
|
+ equipEntity: EquipmentEntity?,
|
|
|
+ deviceId: String,
|
|
|
+ uuid: String
|
|
|
+ ) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ var rel = repo.getRelById(item.id)
|
|
|
+ rel.valid = 0
|
|
|
+ repo.insRelation(rel)
|
|
|
+ getRelConfig(equipEntity!!, deviceId, uuid)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun deletePipe(
|
|
|
+ item: PipeEntity,
|
|
|
+ equipEntity: EquipmentEntity?,
|
|
|
+ deviceId: String,
|
|
|
+ uuid: String
|
|
|
+ ) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ var rel = repo.getPipeById(item.id)
|
|
|
+ rel.valid = 0
|
|
|
+ repo.insPipe(rel)
|
|
|
+ getRelConfig(equipEntity!!, deviceId, uuid)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
companion object {
|
|
|
+ const val MAP_LOAD = "MAP_LOAD"
|
|
|
+ const val EQUIP_CLASS = "EQUIP_CLASS"
|
|
|
+
|
|
|
//
|
|
|
const val REFRESH_OBJECT = "SPACE_JOB"
|
|
|
|
|
@@ -554,11 +1112,22 @@ class GraphyVM(
|
|
|
//添加管线
|
|
|
const val ADD_PIPE = "ADD_PIPE"
|
|
|
|
|
|
- //查询空间下的管道
|
|
|
+ //查询空间下的管道Equip_INFOS
|
|
|
const val SPACE_PIPE = "SPACE_PIPE"
|
|
|
|
|
|
//查询空间详情
|
|
|
const val SPACE_INFO = "SPACE_INFO"
|
|
|
+ const val SPACE_INFOS = "SPACE_INFOS"
|
|
|
+
|
|
|
+
|
|
|
+ //查询设备详情
|
|
|
+ const val EQUIP_INFO = "EQUIP_INFO"
|
|
|
+ const val Equip_INFOS = "Equip_INFOS"
|
|
|
+ const val EQUIP_REL = "EQUIP_REL"
|
|
|
+
|
|
|
+ const val REL_OBJECT = "REL_OBJECT"
|
|
|
+ const val PIPE_OBJECT = "PIPE_OBJECT"
|
|
|
+ const val PIPE = "PIPE"
|
|
|
}
|
|
|
|
|
|
}
|