From 0516cba27e632f20efac2752787f38f0c87baafa Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期三, 25 九月 2024 09:24:05 +0800
Subject: [PATCH] 1. 新增自动评估添加和更新接口

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ScenseServiceImpl.kt |  235 +++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 167 insertions(+), 68 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ScenseServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ScenseServiceImpl.kt
index 5af47d9..8bf1dba 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ScenseServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ScenseServiceImpl.kt
@@ -1,28 +1,45 @@
 package cn.flightfeather.supervision.lightshare.service.impl
 
+import cn.flightfeather.supervision.business.import.SceneImport
+import cn.flightfeather.supervision.business.location.LocationRoadNearby
+import cn.flightfeather.supervision.common.exception.BizException
+import cn.flightfeather.supervision.common.utils.Constant
 import cn.flightfeather.supervision.domain.ds1.entity.*
 import cn.flightfeather.supervision.domain.ds1.mapper.*
-import cn.flightfeather.supervision.common.utils.Constant
+import cn.flightfeather.supervision.domain.ds1.repository.SceneRep
+import cn.flightfeather.supervision.domain.ds2.entity.UserMap
+import cn.flightfeather.supervision.domain.ds2.repository.BaseInfoRep
+import cn.flightfeather.supervision.domain.ds2.repository.UserMapRep
 import cn.flightfeather.supervision.lightshare.service.*
 import cn.flightfeather.supervision.lightshare.vo.*
 import com.github.pagehelper.PageHelper
 import com.google.gson.Gson
+import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
 import org.springframework.beans.BeanUtils
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Service
 import org.springframework.transaction.annotation.Transactional
+import org.springframework.web.multipart.MultipartFile
 import tk.mybatis.mapper.entity.Example
 import tk.mybatis.mapper.util.StringUtil
+import java.io.ByteArrayInputStream
+import java.util.*
+import kotlin.collections.ArrayList
 
 @Service
 class ScenseServiceImpl(
-        val scenseMapper: ScenseMapper,
-        val sceneConstructionSiteMapper: SceneConstructionSiteMapper,
-        val sceneDeviceMapper: SceneDeviceMapper,
-        val sceneMixingPlantMapper: SceneMixingPlantMapper,
-        val sceneStorageYardMapper: SceneStorageYardMapper,
-        val sceneWharfMapper: SceneWharfMapper,
-        val userinfoService: UserinfoService
+    val scenseMapper: ScenseMapper,
+    val sceneConstructionSiteMapper: SceneConstructionSiteMapper,
+    val sceneDeviceMapper: SceneDeviceMapper,
+    val sceneMixingPlantMapper: SceneMixingPlantMapper,
+    val sceneStorageYardMapper: SceneStorageYardMapper,
+    val sceneWharfMapper: SceneWharfMapper,
+    val userinfoService: UserinfoService,
+    private val locationRoadNearby: LocationRoadNearby,
+    private val sceneImport: SceneImport,
+    private val sceneRep: SceneRep,
+    private val baseInfoRep: BaseInfoRep,
+    private val userMapRep: UserMapRep,
 ) : ScenseService {
 
     @Autowired
@@ -130,12 +147,13 @@
     }
 
     override fun save(scense: Scense): Int {
-        // TODO: 2021/7/20 鏂板鍦烘櫙鐨勫悓鏃剁敓鎴愯处鎴�
-        val r = scenseMapper.insert(scense)
-        if (r == 1) {
-            scense.guid?.let { userinfoService.createAccount(it) }
+        return try {
+            createScene(scense)
+            1
+        } catch (e: BizException) {
+            println(e.message)
+            0
         }
-        return r
     }
 
     override fun update(scense: Scense): Int = scenseMapper.updateByPrimaryKeySelective(scense)
@@ -260,14 +278,14 @@
     override fun getSceneDetail(sceneId: String): BaseResponse<SceneDetail> {
         val sceneDetail = SceneDetail()
 
-        val scene = scenseMapper.selectByPrimaryKey(sceneId)
+        val scene = sceneRep.findScene(sceneId = sceneId)
         sceneDetail.scense = scene
 
-        val mapper = when (scene.typeid.toString()) {
-            Constant.ScenseType.TYPE1.value -> sceneConstructionSiteMapper
-            Constant.ScenseType.TYPE2.value -> sceneWharfMapper
-            Constant.ScenseType.TYPE3.value -> sceneMixingPlantMapper
-            Constant.ScenseType.TYPE14.value -> sceneStorageYardMapper
+        val mapper = when (scene?.typeid.toString()) {
+            Constant.SceneType.TYPE1.value -> sceneConstructionSiteMapper
+            Constant.SceneType.TYPE2.value -> sceneWharfMapper
+            Constant.SceneType.TYPE3.value -> sceneMixingPlantMapper
+            Constant.SceneType.TYPE14.value -> sceneStorageYardMapper
             else -> null
         }
 
@@ -300,60 +318,141 @@
             }
         }
 
-        var r = 0
-        var isUpdate = true
-        when (typeId.toString()) {
-            Constant.ScenseType.TYPE1.value -> {
-                val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneConstructionSite::class.java)
-                if (subScene.getsGuid() != null) {
-                    val record =sceneConstructionSiteMapper.selectByPrimaryKey(subScene.getsGuid())
-                    isUpdate = record != null
-                    r = if (record == null) {
-                        sceneConstructionSiteMapper.insert(subScene)
-                    } else {
-                        sceneConstructionSiteMapper.updateByPrimaryKeySelective(subScene)
+        if (sceneDetailStr.subScene != null) {
+            var r = 0
+            var isUpdate = true
+            when (typeId.toString()) {
+                Constant.SceneType.TYPE1.value -> {
+                    val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneConstructionSite::class.java)
+                    if (subScene.getsGuid() != null) {
+                        val record = sceneConstructionSiteMapper.selectByPrimaryKey(subScene.getsGuid())
+                        isUpdate = record != null
+                        r = if (record == null) {
+                            sceneConstructionSiteMapper.insert(subScene)
+                        } else {
+                            sceneConstructionSiteMapper.updateByPrimaryKeySelective(subScene)
+                        }
+                    }
+                }
+                Constant.SceneType.TYPE2.value -> {
+                    val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneWharf::class.java)
+                    if (subScene.getsGuid() != null) {
+                        val record = sceneWharfMapper.selectByPrimaryKey(subScene.getsGuid())
+                        isUpdate = record != null
+                        r = if (record == null) {
+                            sceneWharfMapper.insert(subScene)
+                        } else {
+                            sceneWharfMapper.updateByPrimaryKeySelective(subScene)
+                        }
+                    }
+                }
+                Constant.SceneType.TYPE3.value -> {
+                    val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneMixingPlant::class.java)
+                    if (subScene.getsGuid() != null) {
+                        val record = sceneMixingPlantMapper.selectByPrimaryKey(subScene.getsGuid())
+                        isUpdate = record != null
+                        r = if (record == null) {
+                            sceneMixingPlantMapper.insert(subScene)
+                        } else {
+                            sceneMixingPlantMapper.updateByPrimaryKeySelective(subScene)
+                        }
+                    }
+                }
+                Constant.SceneType.TYPE14.value -> {
+                    val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneStorageYard::class.java)
+                    if (subScene.getsGuid() != null) {
+                        val record = sceneStorageYardMapper.selectByPrimaryKey(subScene.getsGuid())
+                        isUpdate = record != null
+                        r = if (record == null) {
+                            sceneStorageYardMapper.insert(subScene)
+                        } else {
+                            sceneStorageYardMapper.updateByPrimaryKeySelective(subScene)
+                        }
                     }
                 }
             }
-            Constant.ScenseType.TYPE2.value -> {
-                val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneWharf::class.java)
-                if (subScene.getsGuid() != null) {
-                    val record =sceneWharfMapper.selectByPrimaryKey(subScene.getsGuid())
-                    isUpdate = record != null
-                    r = if (record == null) {
-                        sceneWharfMapper.insert(subScene)
-                    } else {
-                        sceneWharfMapper.updateByPrimaryKeySelective(subScene)
-                    }
-                }
-            }
-            Constant.ScenseType.TYPE3.value -> {
-                val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneMixingPlant::class.java)
-                if (subScene.getsGuid() != null) {
-                    val record =sceneMixingPlantMapper.selectByPrimaryKey(subScene.getsGuid())
-                    isUpdate = record != null
-                    r = if (record == null) {
-                        sceneMixingPlantMapper.insert(subScene)
-                    } else {
-                        sceneMixingPlantMapper.updateByPrimaryKeySelective(subScene)
-                    }
-                }
-            }
-            Constant.ScenseType.TYPE14.value -> {
-                val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneStorageYard::class.java)
-                if (subScene.getsGuid() != null) {
-                    val record =sceneStorageYardMapper.selectByPrimaryKey(subScene.getsGuid())
-                    isUpdate = record != null
-                    r = if (record == null) {
-                        sceneStorageYardMapper.insert(subScene)
-                    } else {
-                        sceneStorageYardMapper.updateByPrimaryKeySelective(subScene)
-                    }
-                }
-            }
+            result.append("鍦烘櫙鐗规湁淇℃伅${if (isUpdate) "鏇存柊" else "鏂板"}: $r; ")
         }
-        result.append("鍦烘櫙鐗规湁淇℃伅${if (isUpdate) "鏇存柊" else "鏂板"}: $r; ")
 
         return BaseResponse(true, data = result.toString())
     }
+
+    override fun searchScene(areaVo: AreaVo, page: Int?, perPage: Int?): BaseResponse<List<Scense>> {
+        val p = PageHelper.startPage<Scense>(page ?: 1, perPage ?: 30)
+        val list = scenseMapper.selectByExample(Example(Scense::class.java).apply {
+            createCriteria().apply {
+                areaVo.provincecode?.let { andEqualTo("provincecode", it) }
+                areaVo.citycode?.let { andEqualTo("citycode", it) }
+                areaVo.districtcode?.let { andEqualTo("districtcode", it) }
+                areaVo.towncode?.let { andEqualTo("towncode", it) }
+                areaVo.scensetypeid?.let { andEqualTo("typeid", it) }
+                areaVo.sceneName?.let { andLike("name", "%${it}%") }
+            }
+            areaVo.online?.let {
+                and(createCriteria().apply {
+                    if (it) {
+                        orNotEqualTo("extension1", "0").orIsNull("extension1")
+                    } else {
+                        andEqualTo("extension1", "0")
+                    }
+                })
+            }
+            orderBy("typeid").orderBy("index")
+        })
+        return BaseResponse(true, head = DataHead(p.pageNum, p.pages, p.total), data = list)
+    }
+
+    override fun searchByCoordinate(lng: Double, lat: Double, radius: Double): List<Scense> {
+        return locationRoadNearby.searchByRadius(Pair(lng, lat), radius)
+    }
+
+    override fun importSceneInfo(file: MultipartFile): Boolean {
+        val f = ByteArrayInputStream(file.bytes)
+        val scenes = sceneImport.readFromFile(f)
+        // 鏌ユ壘鍦烘櫙鍚嶇О鏄惁閲嶅
+        val names = scenes.map { it.name }
+        sceneRep.findSceneList(names).map { it?.name }.ifNotEmpty {
+            val str = this.joinToString("锛�")
+            throw BizException("瀛樺湪閲嶅鍦烘櫙锛屽涓嬶細${str}")
+        }
+        scenes.forEach {
+            createOneScene(it)
+        }
+        return true
+    }
+
+    override fun createScene(scense: Scense): Scense {
+        val names = listOf(scense.name)
+        sceneRep.findSceneList(names).map { it?.name }.ifNotEmpty {
+            val str = this.joinToString("锛�")
+            throw BizException("瀛樺湪閲嶅鍦烘櫙锛屽涓嬶細${str}")
+        }
+        createOneScene(scense)
+        return scense
+    }
+
+
+    override fun createOneScene(scense: Scense) {
+        //1. 鎻掑叆鍦烘櫙琛�
+        scense.townname = scense.townname?.trim()
+        sceneRep.insert(scense)
+        //2. 鐢熸垚瀵瑰簲璐︽埛淇℃伅
+        val userInfo = userinfoService.createAccount(scense)
+        createTZUserInfo(userInfo, scense)
+    }
+
+    override fun createTZUserInfo(userInfo: Userinfo, scense: Scense) {
+        //1. 鐢熸垚椋炵窘鐜绯荤粺瀵瑰簲璐︽埛鍜屽熀纭�淇℃伅
+        val userInfoTZ = userinfoService.createAccountTZ(userInfo, scense)
+        val baseInfo = baseInfoRep.create(userInfoTZ, scense)
+        //2. 鐢熸垚鐢ㄦ埛鍖归厤淇℃伅
+        userMapRep.insert(UserMap().apply {
+            tzUserId = userInfoTZ.guid
+            tzUserName = userInfoTZ.realname
+            svUserId = userInfo.guid
+            svUserName = userInfo.realname
+            umCreateTime = Date()
+        })
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3