src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ScenseServiceImpl.kt
@@ -1,8 +1,9 @@
package cn.flightfeather.supervision.lightshare.service.impl
import cn.flightfeather.supervision.business.location.LocationRoadNearby
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.lightshare.service.*
import cn.flightfeather.supervision.lightshare.vo.*
import com.github.pagehelper.PageHelper
@@ -16,13 +17,14 @@
@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,
) : ScenseService {
    @Autowired
@@ -264,10 +266,10 @@
        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
            Constant.SceneType.TYPE1.value -> sceneConstructionSiteMapper
            Constant.SceneType.TYPE2.value -> sceneWharfMapper
            Constant.SceneType.TYPE3.value -> sceneMixingPlantMapper
            Constant.SceneType.TYPE14.value -> sceneStorageYardMapper
            else -> null
        }
@@ -300,60 +302,92 @@
            }
        }
        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)
    }
}