Przeglądaj źródła

feat 管道适应数据字典4.0

lihao1 3 lat temu
rodzic
commit
82df3a9ab4

+ 1 - 2
demo/src/main/java/com/sybotan/android/demo/adapter/PipeExpandAdapter.kt

@@ -80,8 +80,7 @@ class PipeExpandAdapter(
 //            sb.append("  ——  ")
 //        }
 //        sb.append(group.toName)
-        tvGroup.text =
-            group.entity.pipeSubType + "--" + group.entity.pipeType
+        tvGroup.text = group.pipeTypeName
         val add = holder?.findViewById(R.id.add) as ImageView
         add.setOnClickListener {
             addRel?.onAdd(group)

+ 1 - 0
demo/src/main/java/com/sybotan/android/demo/bean/PipeConfigEntityPackClass.java

@@ -10,6 +10,7 @@ import java.util.Objects;
  * Date: 2021/10/18
  */
 public class PipeConfigEntityPackClass {
+    public String pipeTypeName;
     public PipeConfigEntity entity;
     public ArrayList<TargetPipeType> targetTypes = new ArrayList<>();
 

+ 2 - 2
demo/src/main/java/com/sybotan/android/demo/view/PipeDialog.java

@@ -52,7 +52,7 @@ public class PipeDialog extends Dialog implements View.OnClickListener {
         toright = findViewById(R.id.toright);
         connect = findViewById(R.id.connect);
 
-        relationTitle.setText(configEntity.entity.getPipeType());
+        relationTitle.setText(configEntity.pipeTypeName);
 
         if (Objects.equals(configEntity.entity.getClassCodeFrom(), equip.getClassCode())) {
             leftName.setText(localId);
@@ -114,7 +114,7 @@ public class PipeDialog extends Dialog implements View.OnClickListener {
                 relationTv.setText("--");
                 break;
             case R.id.btnSubmit:
-                if (TextUtils.isEmpty(relationTv.getText().toString().trim())){
+                if (TextUtils.isEmpty(relationTv.getText().toString().trim())) {
                     ToastUtils.showMyToast("请选择方向");
                     return;
                 }

+ 5 - 3
demo/src/main/java/com/sybotan/android/demo/viewmodel/EquipDetailVM.kt

@@ -264,7 +264,7 @@ class EquipDetailVM(
             val fromList = repo.getRelConfigByCodeFrom(entity.code!!)
             val toList = repo.getRelConfigByCodeTo(entity.code!!)
             loadCfgs(entity.code, fromList, true, configParent)
-            loadCfgs(entity.code, toList, true, configParent)
+            loadCfgs(entity.code, toList, false, configParent)
             for (parent in configParent) {
                 var rel = ArrayList<RelationPackClass>()
                 for (child in parent.targetTypes) {
@@ -299,7 +299,7 @@ class EquipDetailVM(
             val pipeFromList = repo.getPipeConfigByCodeFrom(entity.code)
             val pipeToList = repo.getPipeConfigByCodeTo(entity.code)
             loadPipeCfgs(entity.code, pipeFromList, true, pipeParent)
-            loadPipeCfgs(entity.code, pipeToList, true, pipeParent)
+            loadPipeCfgs(entity.code, pipeToList, false, pipeParent)
             val floorPipes = repo.getPipeByFloorId(floorId)
             for (parent in pipeParent) {
                 var pipes = ArrayList<PipeEntity>()
@@ -338,7 +338,7 @@ class EquipDetailVM(
         }
     }
 
-    private fun loadPipeCfgs(
+    private suspend fun loadPipeCfgs(
         srcCode: String,
         cfgs: List<PipeConfigEntity>,
         targetAsTo: Boolean,
@@ -355,6 +355,8 @@ class EquipDetailVM(
             if (group == null) {
                 group = PipeConfigEntityPackClass()
                 group.entity = cfg
+                val equipment = repo.getEquipByCode(group.entity.pipeType!!)
+                group.pipeTypeName = equipment?.name
                 groups.add(group)
             }
             val cfgTarget = if (targetAsTo) cfg.classCodeTo else cfg.classCodeFrom

+ 0 - 579
demo/src/main/java/com/sybotan/android/demo/viewmodel/GraphyVM.kt

@@ -365,172 +365,8 @@ class GraphyVM(
 //        }
     }
 
-    fun refreshObject(space: TunableSpace, hashMap: HashMap<String, Any>) {
-        viewModelScope.launch {
-            var space = repo.getObject(space.id!!)
-//            space!!.infos = JSONObject(hashMap as Map<*, *>)
-            space!!.infos = gson.toJsonTree(hashMap)
-            space.state = "1"
-            repo.insObject(space)
-            mActivity.setResult(RESULT_OK)
-            mActivity.finish()
-        }
-    }
 
 
-    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.SendDirective(EQUIP_CLASS, equips)
-
-            if (!TextUtils.isEmpty(deviceId)) {
-                var equip = repo.getObject(deviceId)
-                val infos = gson.fromJson(equip!!.infos, HashMap::class.java)
-                mEmitter.SendDirective(SPACE_INFOS, infos)
-                mEmitter.SendDirective(Equip_INFOS, equip)
-            }
-        }
-    }
-
-    fun getEquipInfosConfig(equipmentEntity: EquipmentEntity) {
-        viewModelScope.launch {
-            val infosConfig = repo.getInfosConfigByEquipCode(equipmentEntity.code!!)
-            if (CommonUtils.IsNull(infosConfig)) {
-                mEmitter.SendDirective(EQUIP_INFO, null)
-                return@launch
-            }
-            val infos = infosConfig.get(0).infos
-            val infoList = gson.fromJson<List<Infos>>(
-                infos,
-                object : TypeToken<List<Infos?>?>() {}.type
-            )
-            mEmitter.SendDirective(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: Int,
-        position: Position,
-        containerId: String,
-    ) {
-        viewModelScope.launch {
-            val objects = repo.getObjects()
-            if (!CommonUtils.IsNull(objects)) {
-                for (obj in objects) {
-                    if (deviceId != obj.id && !TextUtils.isEmpty(obj.localId) && obj.localId!!.toUpperCase()
-                            .equals(localId.toUpperCase())
-                    ) {
-                        ToastUtils.showMyToast("已有此编码的设备")
-                        return@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 = "",
-                    modifier = "Android",
-                    modifiedTime = "",
-                    clientDevice = "",
-                    clientId = uuid,
-                    updateApp = "",
-                    uploadFlag = "",
-                    valid = 1,
-                    deliveryState = null,
-                    d2mState = null,
-                    virtualCodes = null,
-                    infos = gson.toJsonTree(hashMap),
-                    floorMap = null,
-                    state = "1",
-                    containerId = if (TextUtils.isEmpty(containerId)) "" else containerId
-                )
-                repo.insObject(objectEntity)
-            } else {
-                val equip = repo.getObject(deviceId!!)
-//                equip!!.infos = JSONObject(hashMap as Map<*, *>)
-                equip!!.classCode = equipEntity.code!!
-                equip.localId = localId
-                equip.infos = gson.toJsonTree(hashMap)
-                equip.state = "1"
-                repo.insObject(equip)
-            }
-            //插入文件数据
-            var order = 0
-            for (photo in beans) {
-                if (photo.itemType != 1) {
-                    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 = "", state = "1"
-                        )
-                        repo.insFile(file)
-                    }
-                    order++
-                }
-            }
-            mActivity.setResult(RESULT_OK)
-            mActivity.finish()
-        }
-    }
 
     fun getMap() {
         viewModelScope.launch {
@@ -551,387 +387,6 @@ class GraphyVM(
         }
     }
 
-    fun getRelConfig(entity: EquipmentEntity, deviceId: String, uuid: String) {
-        viewModelScope.launch {
-            val equipId = if (TextUtils.isEmpty(deviceId)) uuid else deviceId
-            //获取关系二级列表
-            val configParent = ArrayList<RelConfigEntityPackClass>()
-            val relList = mutableListOf<List<RelationPackClass>>()
-            val fromList = repo.getRelConfigByCodeFrom(entity.code!!)
-            val toList = repo.getRelConfigByCodeTo(entity.code!!)
-            loadCfgs(entity.code, fromList, true, configParent)
-            loadCfgs(entity.code, toList, true, configParent)
-            for (parent in configParent) {
-                var rel = ArrayList<RelationPackClass>()
-                for (child in parent.targetTypes) {
-                    if (child.canFrom) {
-                        val to = repo.getRelByCodeTo(
-                            parent.entity.graphCode!!,
-                            parent.entity.relCode!!,
-                            equipId
-                        )
-                        loadRelation(to, child, parent, rel)
-                    }
-
-                    if (child.canTo) {
-                        val from = repo.getRelByCodeFrom(
-                            parent.entity.graphCode!!,
-                            parent.entity.relCode!!,
-                            equipId
-                        )
-                        loadRelation(from, child, parent, rel)
-                    }
-                }
-                relList.add(rel)
-            }
-            val hashMap = HashMap<String, Any>()
-            hashMap.put("parent", configParent)
-            hashMap.put("child", relList)
-            mEmitter.SendDirective(EQUIP_REL, hashMap)
-
-            //获取管道二级列表
-            val pipeParent = ArrayList<PipeConfigEntityPackClass>()
-            val pipeChildren = mutableListOf<List<PipeEntity>>()
-            val pipeFromList = repo.getPipeConfigByCodeFrom(entity.code)
-            val pipeToList = repo.getPipeConfigByCodeTo(entity.code)
-            loadPipeCfgs(entity.code, pipeFromList, true, pipeParent)
-            loadPipeCfgs(entity.code, pipeToList, true, pipeParent)
-            val floorPipes = repo.getPipeByFloorId(floorId)
-            for (parent in pipeParent) {
-                var pipes = ArrayList<PipeEntity>()
-                for (floorPipe in floorPipes) {
-                    if ((floorPipe.objFrom.equals(equipId) || floorPipe.objTo.equals(equipId)) && floorPipe.pipeType.equals(
-                            parent.entity.pipeType
-                        ) && floorPipe.pipeSubType.equals(parent.entity.pipeSubType)
-                    ) {
-                        bindPipeName(floorPipe)
-                        pipes.add(floorPipe)
-                    }
-                }
-                pipeChildren.add(pipes)
-            }
-            val hashMap1 = HashMap<String, Any>()
-            hashMap1.put("parent", pipeParent)
-            hashMap1.put("child", pipeChildren)
-            mEmitter.SendDirective(PIPE, hashMap1)
-
-        }
-    }
-
-    private suspend fun bindPipeName(floorPipe: PipeEntity) {
-        val from = repo.getObject(floorPipe.objFrom!!)
-        if (from == null) {
-            floorPipe.objFromLocalId = "该设备"
-        } else {
-            floorPipe.objFromLocalId =
-                if (from!!.id.startsWith("Eq")) from!!.localId else from!!.localName
-        }
-        val to = repo.getObject(floorPipe.objTo!!)
-        if (to == null) {
-            floorPipe.objToLocalId = "该设备"
-        } else {
-            floorPipe.objToLocalId = if (to!!.id.startsWith("Eq")) to!!.localId else to!!.localName
-        }
-    }
-
-    private fun loadPipeCfgs(
-        srcCode: String,
-        cfgs: List<PipeConfigEntity>,
-        targetAsTo: Boolean,
-        groups: ArrayList<PipeConfigEntityPackClass>
-    ) {
-        for (cfg in cfgs) {
-            var group: PipeConfigEntityPackClass? = null
-            for (g in groups) {
-                if (g.samePipeConfig(cfg)) {
-                    group = g
-                    break
-                }
-            }
-            if (group == null) {
-                group = PipeConfigEntityPackClass()
-                group.entity = cfg
-                groups.add(group)
-            }
-            val cfgTarget = if (targetAsTo) cfg.classCodeTo else cfg.classCodeFrom
-
-            var targetType: PipeConfigEntityPackClass.TargetPipeType? = null
-            for (t in group.targetTypes) {
-                if (t.targetCode.equals(cfgTarget)) {
-                    targetType = t
-                    break
-                }
-            }
-            if (targetType == null) {
-                targetType = PipeConfigEntityPackClass.TargetPipeType()
-                targetType.srcCode = srcCode
-                targetType.pipeType = group.entity.pipeType
-                targetType.pipeSubType = group.entity.pipeSubType
-                targetType.targetCode = cfgTarget
-                group.targetTypes.add(targetType)
-            }
-            if (cfg.pipeDirection == 1) {
-                if (targetAsTo) {
-                    targetType.canTo = true
-                } else {
-                    targetType.canFrom = true
-                }
-            } else if (cfg.pipeDirection == -1) {
-                if (targetAsTo) {
-                    targetType.canFrom = true
-                } else {
-                    targetType.canTo = true
-                }
-            } else if (cfg.pipeDirection == 0) {
-                targetType.canConnect = true
-            }
-        }
-    }
-
-    private suspend fun loadRelation(
-        to: List<RelationEntity>,
-        child: RelConfigEntityPackClass.TargetRelType,
-        parent: RelConfigEntityPackClass,
-        rel: ArrayList<RelationPackClass>
-    ) {
-        bindRelationEntityName(to)
-        if (!CommonUtils.IsNull(to)) {
-            for (t in to) {
-                if (child.targetCode.equals(parent.entity.classCodeTo)) {
-                    val pack = RelationPackClass()
-                    pack.entity = t
-                    pack.targetPipeType = child
-                    rel.add(pack)
-                }
-            }
-        }
-    }
-
-    private suspend fun bindRelationEntityName(
-        entitys: List<RelationEntity>
-    ) {
-        for (rel in entitys) {
-            val from = repo.getObject(rel.objFrom!!)
-            if (from == null) {
-                rel.objFromLocalId = "该设备"
-            } else {
-                rel.objFromLocalId =
-                    if (from!!.id.startsWith("Eq")) from!!.localId else from!!.localName
-            }
-            val to = repo.getObject(rel.objTo!!)
-            if (to == null) {
-                rel.objToLocalId = "该设备"
-            } else {
-                rel.objToLocalId = if (to!!.id.startsWith("Eq")) to!!.localId else to!!.localName
-            }
-        }
-    }
-
-    private fun loadCfgs(
-        srcCode: String,
-        cfgs: List<RelConfigEntity>,
-        targetAsTo: Boolean,
-        groups: ArrayList<RelConfigEntityPackClass>
-    ) {
-        for (cfg in cfgs) {
-            var group: RelConfigEntityPackClass? = null
-            for (g in groups) {
-                if (g.sameRelConfig(cfg)) {
-                    group = g
-                    break
-                }
-            }
-            if (group == null) {
-                group = RelConfigEntityPackClass()
-                group.entity = cfg
-                groups.add(group)
-            }
-            val cfgTarget = if (targetAsTo) cfg.classCodeTo else cfg.classCodeFrom
-            var tartgetType: RelConfigEntityPackClass.TargetRelType? = null
-            for (t in group.targetTypes) {
-                if (t.targetCode.equals(cfgTarget)) {
-                    tartgetType = t
-                    break
-                }
-            }
-            if (tartgetType == null) {
-                tartgetType = RelConfigEntityPackClass.TargetRelType()
-                tartgetType.srcCode = srcCode
-                tartgetType.graphCode = group.entity.graphCode
-                tartgetType.relCode = group.entity.relCode
-                tartgetType.targetCode = cfgTarget
-                tartgetType.direction = cfg.direction
-                group.targetTypes.add(tartgetType)
-            }
-            if (targetAsTo) {
-                tartgetType.canTo = true
-            } else {
-                tartgetType.canFrom = true
-            }
-
-            if ("fixed".equals(cfg.direction)) {
-                if (targetAsTo)
-                    tartgetType.canTo = true
-                else
-                    tartgetType.canFrom = true
-            } else if ("optional".equals(cfg.direction)) {
-                tartgetType.canTo = true
-                tartgetType.canFrom = true
-            } else {
-                tartgetType.connect = true
-                // !targetCanBeTo && !targetCanBeFrom 表示无方向选择
-            }
-
-        }
-    }
-
-    fun getRelObj(group: RelConfigEntityPackClass, code: String) {
-        viewModelScope.launch {
-            val objects: ArrayList<ObjectEntity> = ArrayList()
-            for (type in group.targetTypes) {
-                val objs = repo.getObjectByCode(type.targetCode!!)
-                if (!CommonUtils.IsNull(objs)) {
-                    objects.addAll(objs)
-                }
-            }
-            mEmitter.SendDirective(REL_OBJECT, objects)
-        }
-    }
-
-    /**
-     * 获取可建立管道对象列表
-     */
-    fun getPipeObj(group: PipeConfigEntityPackClass, code: String) {
-        viewModelScope.launch {
-            val objects: ArrayList<ObjectEntity> = ArrayList()
-            for (type in group.targetTypes) {
-                val objs = repo.getObjectByCode(type.targetCode!!)
-                if (!CommonUtils.IsNull(objs)) {
-                    objects.addAll(objs)
-                }
-            }
-            mEmitter.SendDirective(PIPE_OBJECT, objects)
-        }
-    }
-
-    /**
-     * 增加关系
-     */
-    fun addRel(
-        deviceId: String, uuid: String, equipEntity: EquipmentEntity,
-        equip: ObjectEntity,
-        groupRelConfigEntity: RelConfigEntity,
-        eq: Boolean
-    ) {
-        viewModelScope.launch {
-            var equipId: String
-            if (TextUtils.isEmpty(deviceId)) {
-                equipId = uuid
-            } else {
-                equipId = deviceId
-            }
-            val objFrom: String
-            val objto: String
-            if (eq) {
-                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 = "",
-                modifiedTime = "",
-                modifier = null,
-                clientId = null,
-                clientDevice = null,
-                uploadFlag = null,
-                deliveryState = null,
-                valid = 1, d2mState = null, objFromLocalId = null, objToLocalId = null, state = "1"
-            )
-            repo.insRelation(relEntity)
-            getRelConfig(equipEntity, deviceId, uuid)
-        }
-    }
-
-    /**
-     * 增加管道
-     */
-    fun addPipe(
-        deviceId: String, uuid: String, equipEntity: EquipmentEntity,
-        equip: ObjectEntity,
-        groupPipeConfigEntity: PipeConfigEntity,
-        direction: String
-    ) {
-        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
-            }
-            var pipeDirection: Int
-            if (direction.equals("->")) {
-                pipeDirection = 1
-            } else if (direction.equals("<-")) {
-                pipeDirection = -1
-            } else {
-                pipeDirection = 0
-            }
-
-            val relEntity = PipeEntity(
-                id = UUID.randomUUID().toString(),
-                projectId = projectId,
-                buildingId = buildingId,
-                floorId = floorId,
-                objFrom = objFrom,
-                objTo = objto,
-                creator = null,
-                creationTime = "",
-                modifiedTime = "",
-                modifier = null,
-                uploadFlag = null,
-                deliveryState = null,
-                valid = 1,
-                d2mState = null,
-                objFromLocalId = null,
-                objToLocalId = null,
-                direction = pipeDirection,
-                typeFrom = "equipment",
-                typeTo = "equipment",
-                pipeType = groupPipeConfigEntity.pipeType,
-                pipeSubType = groupPipeConfigEntity.pipeSubType,
-                route = null,
-                infos = null, state = "1"
-            )
-            repo.insPipe(relEntity)
-            getRelConfig(equipEntity, deviceId, uuid)
-        }
-    }
 
     /**
      * 增加设备问题
@@ -971,40 +426,6 @@ class GraphyVM(
     }
 
     /**
-     * 删除关系
-     */
-    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)
-        }
-    }
-
-    /**
      * APP自动更新
      */
     fun queryAutoUpdate() {