feiyu02
2025-09-19 7cbe1610b87da19ed8a146a09b1117f92d9d3d98
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/UserMapServiceImpl.kt
@@ -17,7 +17,9 @@
import cn.flightfeather.supervision.domain.ds2.repository.UserMapRep
import cn.flightfeather.supervision.lightshare.service.UserMapService
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import cn.flightfeather.supervision.lightshare.vo.DataHead
import cn.flightfeather.supervision.lightshare.vo.DeviceMapVo
import cn.flightfeather.supervision.lightshare.vo.DeviceSiteVo
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
import java.util.*
@@ -48,12 +50,13 @@
        return userMapRep.findFromSupervision(tzUserId)
    }
    override fun autoCreateMap() {
    override fun autoCreateMap(userList: List<Userinfo?>) {
        // 选择需要处理的账户
        val userList = userinfoMapper.selectByExample(Example(Userinfo::class.java).apply {
            createCriteria().andEqualTo("remark", "徐汇区")
        })
//        val userList = userinfoMapper.selectByExample(Example(Userinfo::class.java).apply {
//            createCriteria().andEqualTo("remark", "徐汇区")
//        })
        userList.forEach {
            it ?: return@forEach
            // 查找是否已经有账户匹配记录
            val records = userMapMapper.selectByExample(Example(UserMap::class.java).apply {
                createCriteria().andEqualTo("svUserId", it.guid)
@@ -72,6 +75,7 @@
                            tzUserName = tzU.realname
                            svUserId = it.guid
                            svUserName = it.realname
                            umCreateTime = Date()
                        })
                    }
                }
@@ -94,24 +98,70 @@
        }
    }
    override fun fetchDeviceMap(areaVo: AreaVo): List<DeviceMapVo?> {
    override fun fetchDeviceMap(page: Int?, perPage: Int?, areaVo: AreaVo): List<DeviceMapVo?> {
        // 1.通过区域条件获取主体用户
        val userIdList = when (areaVo.sourceType) {
            //以飞羽环境系统中的用户为主体
            1 -> {
                val u = userInfoTZRep.findEnterpriseUser(areaVo.districtname, areaVo.scensetypeid?.toInt())
                u.map { it?.guid }
                u.map { it?.guid to it?.realname }
            }
            //以飞羽监管系统中的用户为主体
            2 -> {
                val task = taskRep.findOneTask(areaVo) ?: throw BizException("当前查询条件下未找到对应顶层任务")
                val scenes = sceneRep.findScene(task.tguid!!, areaVo.scensetypeid?.toInt(), areaVo.towncode)
                val scenes = sceneRep.findSceneList(task.tguid!!, areaVo.scensetypeid?.toInt(), areaVo.towncode)
                    .map { it?.guid }
                userInfoSVRep.findUser(scenes).map { it?.guid }
                userInfoSVRep.findUser(scenes).map { it?.guid to it?.realname }
            }
            else -> emptyList()
        }
        // 2.通过区域条件决定匹配的数据来源
        return aopDataDeviceMap.findMapSet(areaVo, userIdList)
        val mapSet = aopDataDeviceMap.findMapSet(areaVo, userIdList.map { it.first })
        val result = mutableListOf<DeviceMapVo>()
        // 将不在mapSet中的用户,添加到结果集中
        userIdList.forEach {u ->
            val ddm = mapSet.find { m->
                when (areaVo.sourceType) {
                    //以飞羽环境系统中的用户为主体
                    1 -> m.tzUserId == u.first
                    //以飞羽监管系统中的用户为主体
                    2 -> m.svUserId == u.first
                    else -> false
                }
            }
            if (ddm == null) {
                result.add(DeviceMapVo().apply {
                    when (areaVo.sourceType) {
                        //以飞羽环境系统中的用户为主体
                        1 -> {
                            tzUserId = u.first
                            tzUserName = u.second
                        }
                        //以飞羽监管系统中的用户为主体
                        2 -> {
                            svUserId = u.first
                            svUserName = u.second
                        }
                    }
                })
            }
        }
        // 将mapSet中的数据添加到结果集中
        result.addAll(mapSet)
        return result.sortedBy { it.svUserId }
    }
    override fun insertOrUpdate(param: Pair<AreaVo, DeviceMapVo>): Int {
        return aopDataDeviceMap.insertOrUpdate(param.first, listOf(param.second))
    }
    override fun searchThirdPartyDevice(
        areaVo: AreaVo,
        keyword: String,
        page: Int?,
        perPage: Int?,
    ): Pair<DataHead, List<DeviceSiteVo>> {
        return aopDataDeviceMap.searchDevice(areaVo, keyword, page ?: 1, perPage ?: 30)
    }
}