Browse Source

@task: floor map path in db

bai 3 years ago
parent
commit
3305dce008

+ 1 - 1
demo/src/main/java/com/framework/app/Constants.kt

@@ -9,7 +9,7 @@ const val test2IP = "http://192.168.0.11:8876/"
 
 const val tencentIP = "http://82.157.28.170:8876/"
 
-const val IP = tencentIP
+const val IP = testIP
 
 const val devFileServiceUrl = "http://develop.persagy.com/image-service/"
 

+ 0 - 1
demo/src/main/java/com/framework/app/tools/FileTools.kt

@@ -13,7 +13,6 @@ import java.io.FileInputStream
  * 读取文件,返回字节数组
  */
 fun File.toBytes(): ByteArray {
-
     val fis = FileInputStream(this)
     return fis.readBytes()
 }

+ 16 - 5
demo/src/main/java/com/framework/mvvm/mv/AdmViewModel.kt

@@ -11,11 +11,14 @@ import com.framework.app.http.FileInfo
 import com.framework.app.http.FileUploadInfo
 import com.framework.app.tools.md5
 import com.framework.app.tools.toBytes
-import com.framework.mvvm.model.data.*
+import com.framework.mvvm.model.data.Response
+import com.framework.mvvm.model.data.SuccessResponse
+import com.framework.mvvm.model.data.request
 import com.framework.mvvm.model.db.entity.task.ObjectEntity
 import com.framework.mvvm.model.repository.AdmRepository
 import com.framework.mvvm.model.vo.AdmRequest
 import com.framework.mvvm.model.vo.User
+import com.sybotan.android.demo.DemoApp
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.SharingStarted.Companion.WhileSubscribed
 import kotlinx.coroutines.flow.StateFlow
@@ -26,6 +29,7 @@ import kotlinx.coroutines.withContext
 import okhttp3.RequestBody
 import okhttp3.RequestBody.Companion.toRequestBody
 import java.io.File
+import java.io.FileOutputStream
 
 
 class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
@@ -86,12 +90,16 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
         viewModelScope.launch(Dispatchers.IO) {
             val buildings = repository.getBuildings()
             println("downloadBuilding will download : ${buildings.size} $buildings")
+            if (buildings.isEmpty()) {
+                Log.d("downloadBuilding","buildings is empty")
+                return@launch
+            }
             for (building in buildings) {
                 repository.requestBuilding(
                     AdmRequest(
-                        userId = "admjd", // just for jd
+                        userId = "bdtp",
                         projectId = building.projectId!!,
-                        groupCode = building.groupCode,
+                        groupCode = building.groupCode!!,
                         buildingId = if (isOnlyRelation) "" else building.id,
                         clientId = sp.getString(CLIENT_ID, "") ?: "",
                         bdtpDownloadTs = sp.getLong("${building.buildingId}.$BDTP_TS", 0L),
@@ -113,8 +121,11 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
                 val json = it.infos?.asJsonObject
                 val floorMap = json?.get("floorMap")?.asString ?: ""
                 if (floorMap.isNotEmpty()) {
-                    val map = OkhttpUtil.getGzipMap("$IP$pathDownloadMap${floorMap}")
-                    it.floorMap = map
+                    val mapString = OkhttpUtil.getGzipMap("$IP$pathDownloadMap${floorMap}")
+                    val mapFile =
+                        File(DemoApp.getInstance()?.getExternalFilesDir("floorMap"), it.id)
+                    FileOutputStream(mapFile).use { output -> output.write(mapString.toByteArray()) }
+                    it.floorMap = mapFile.absolutePath
                     repository.updateObject(it)
                 }
             }

+ 8 - 4
demo/src/main/java/com/sybotan/android/demo/activities/PocActivity.kt

@@ -57,7 +57,11 @@ class PocActivity : BaseActivity(), DIAware {
     private lateinit var version: TextView
 
     // 测试用,后期动态设置
-    private val jdRequest = AdmRequest(userId = admjd, projectId = "Pj9909990002", groupCode = "JD")
+    //private val request =
+    //    AdmRequest(userId = "admjd", projectId = "Pj9909990002", groupCode = "JD")
+
+    private val request =
+        AdmRequest(userId = "bdtp", projectId = "Pj5001120003", groupCode = "XG")
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -107,7 +111,7 @@ class PocActivity : BaseActivity(), DIAware {
 
         dictBtn.setOnClickListener {
             mVm.requestDict(
-                jdRequest
+                request
             ) {
                 val builder = AlertDialog.Builder(this)
                 val dialog = builder.setMessage("数据字典下载成功")
@@ -120,7 +124,7 @@ class PocActivity : BaseActivity(), DIAware {
 
         configBtn.setOnClickListener {
             mVm.requestConfig(
-                jdRequest
+                request
             ) {
                 val builder = AlertDialog.Builder(this)
                 val dialog = builder.setMessage("配置信息下载成功")
@@ -133,7 +137,7 @@ class PocActivity : BaseActivity(), DIAware {
 
         frameBtn.setOnClickListener {
             mVm.requestFrame(
-                jdRequest
+                request
             ) {
                 val builder = AlertDialog.Builder(this)
                 val dialog = builder.setMessage("框架数据下载成功")

+ 30 - 16
demo/src/main/java/com/sybotan/android/demo/viewmodel/ChooseSpaceVM.kt

@@ -5,21 +5,21 @@ import android.graphics.PointF
 import android.text.TextUtils
 import androidx.lifecycle.viewModelScope
 import cn.hutool.core.util.IdUtil
-import cn.sagacloud.android.cadengine.Lasso
-import cn.sagacloud.android.cadengine.items.PipeLineItem
-import cn.sagacloud.android.cadengine.items.PointItem
 import cn.sagacloud.android.cadengine.items.TunableSpaceItem
-import cn.sagacloud.android.cadengine.types.*
-import com.framework.mvvm.model.db.entity.task.*
+import cn.sagacloud.android.cadengine.types.FloorData
+import cn.sagacloud.android.cadengine.types.PointZ
+import cn.sagacloud.android.cadengine.types.TunableSpace
+import com.framework.mvvm.model.db.entity.task.InfosforBuild
+import com.framework.mvvm.model.db.entity.task.ObjectEntity
+import com.framework.mvvm.model.db.entity.task.RelationEntity
+import com.framework.mvvm.model.db.entity.task.ServeAreaEntity
 import com.framework.mvvm.model.repository.AdmRepository
 import com.google.gson.Gson
-import com.google.gson.JsonArray
 import com.google.gson.reflect.TypeToken
 import com.sybotan.android.demo.activities.BaseActivity
 import com.sybotan.android.demo.bean.RelConfigEntityPackClass
 import com.sybotan.android.demo.bean.RelationPackClass
 import com.sybotan.android.demo.bean.SpaceInfo
-import com.sybotan.android.demo.bean.result.*
 import com.sybotan.android.demo.entitiies.Floor
 import com.sybotan.android.demo.entitiies.Info
 import com.sybotan.android.demo.entitiies.Statistics
@@ -32,8 +32,7 @@ import org.kodein.di.DI
 import org.kodein.di.DIAware
 import org.kodein.di.android.x.closestDI
 import org.kodein.di.instance
-import java.util.*
-import kotlin.collections.ArrayList
+import java.io.File
 
 
 /**
@@ -62,8 +61,9 @@ class ChooseSpaceVM(
                         ToastUtils.showMyToast("没有地图")
                         break
                     }
-                    val floorOfflineData =
-                        SJsonUtil.fromJson(floor.floorMap!!, FloorData::class.java)
+                    val mapFile = File("${floor.floorMap}")
+                    val map = mapFile.bufferedReader().use { it.readText() }
+                    val floorOfflineData = SJsonUtil.fromJson(map, FloorData::class.java)
                     mEmitter.SendDirective(MAP_LOAD, gson.toJson(floorOfflineData))
                     break
                 }
@@ -178,8 +178,9 @@ class ChooseSpaceVM(
                         ToastUtils.showMyToast("没有地图")
                         break
                     }
-                    val floorOfflineData =
-                        SJsonUtil.fromJson(floor.floorMap!!, FloorData::class.java)
+                    val mapFile = File("${floor.floorMap}")
+                    val map = mapFile.bufferedReader().use { it.readText() }
+                    val floorOfflineData = SJsonUtil.fromJson(map, FloorData::class.java)
                     mEmitter.SendDirective(FLOOR_MAP, gson.toJson(floorOfflineData))
                     break
                 }
@@ -188,7 +189,11 @@ class ChooseSpaceVM(
         }
     }
 
-    fun insRel(deviceId: String, spaceIds: ArrayList<String>, groupRelConfigEntity: RelConfigEntityPackClass) {
+    fun insRel(
+        deviceId: String,
+        spaceIds: ArrayList<String>,
+        groupRelConfigEntity: RelConfigEntityPackClass
+    ) {
         viewModelScope.launch {
             val rels = getRelations(groupRelConfigEntity, deviceId)
             for (rel in rels) {
@@ -205,7 +210,12 @@ class ChooseSpaceVM(
                     objFrom = deviceId
                     objto = id
                 }
-                val en = repo.getRelByGraphCodeAndRelCodeAndObjFromAndObjTo(groupRelConfigEntity.entity.graphCode!!, groupRelConfigEntity.entity.relCode!!, objFrom, objto)
+                val en = repo.getRelByGraphCodeAndRelCodeAndObjFromAndObjTo(
+                    groupRelConfigEntity.entity.graphCode!!,
+                    groupRelConfigEntity.entity.relCode!!,
+                    objFrom,
+                    objto
+                )
                 if (en == null) {
                     val relEntity = RelationEntity(
                         id = IdUtil.simpleUUID(),
@@ -222,7 +232,11 @@ class ChooseSpaceVM(
                         clientId = null,
                         clientDevice = null,
                         deliveryState = -1,
-                        valid = 1, d2mState = -1, objFromLocalId = null, objToLocalId = null, state = 1
+                        valid = 1,
+                        d2mState = -1,
+                        objFromLocalId = null,
+                        objToLocalId = null,
+                        state = 1
                     )
                     repo.insRelation(relEntity)
                 }

+ 4 - 2
demo/src/main/java/com/sybotan/android/demo/viewmodel/GraphyVM.kt

@@ -36,6 +36,7 @@ import kotlin.collections.ArrayList
 import kotlin.collections.HashMap
 import com.sybotan.android.demo.bean.*
 import com.sybotan.base.extensions.toInt
+import java.io.File
 
 
 /**
@@ -372,8 +373,9 @@ class GraphyVM(
                         ToastUtils.showMyToast("没有地图")
                         break
                     }
-                    val floorOfflineData =
-                        SJsonUtil.fromJson(floor.floorMap!!, FloorData::class.java)
+                    val mapFile = File("${floor.floorMap}")
+                    val map = mapFile.bufferedReader().use { it.readText() }
+                    val floorOfflineData = SJsonUtil.fromJson(map, FloorData::class.java)
                     mEmitter.SendDirective(MAP_LOAD, gson.toJson(floorOfflineData))
                     break
                 }

+ 4 - 2
demo/src/main/java/com/sybotan/android/demo/viewmodel/SpaceMapVM.kt

@@ -29,6 +29,7 @@ import org.kodein.di.DI
 import org.kodein.di.DIAware
 import org.kodein.di.android.x.closestDI
 import org.kodein.di.instance
+import java.io.File
 
 
 /**
@@ -372,8 +373,9 @@ class SpaceMapVM(
                         ToastUtils.showMyToast("没有地图")
                         break
                     }
-                    val floorOfflineData =
-                        SJsonUtil.fromJson(floor.floorMap!!, FloorData::class.java)
+                    val mapFile = File("${floor.floorMap}")
+                    val map = mapFile.bufferedReader().use { it.readText() }
+                    val floorOfflineData = SJsonUtil.fromJson(map, FloorData::class.java)
                     mEmitter.SendDirective(MAP_LOAD, gson.toJson(floorOfflineData))
                     break
                 }