From d17cc66f3026be4609f91fc726b55660aec36e67 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期五, 06 九月 2024 17:16:52 +0800 Subject: [PATCH] 1. 新增设备管理接口 2. 优化第三方接口数据获取逻辑 --- src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DeviceServiceImpl.kt | 34 ++++++++++++++++++++++++++-------- 1 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DeviceServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DeviceServiceImpl.kt index f8708f9..499f724 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DeviceServiceImpl.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DeviceServiceImpl.kt @@ -1,18 +1,36 @@ package com.flightfeather.uav.lightshare.service.impl +import com.flightfeather.uav.common.exception.BizException import com.flightfeather.uav.domain.entity.DeviceInfo -import com.flightfeather.uav.domain.mapper.DeviceInfoMapper -import com.flightfeather.uav.lightshare.bean.BaseResponse +import com.flightfeather.uav.domain.repository.DeviceRep import com.flightfeather.uav.lightshare.service.DeviceService +import com.flightfeather.uav.socket.eunm.UWDeviceType import org.springframework.stereotype.Service +import java.util.* @Service -class DeviceServiceImpl( - private val deviceInfoMapper: DeviceInfoMapper -) : DeviceService { +class DeviceServiceImpl(private val deviceRep: DeviceRep) : DeviceService { - override fun getDeviceInfo(): BaseResponse<List<DeviceInfo>> { - val r = deviceInfoMapper.selectAll() - return BaseResponse(true, data = r) + override fun getDeviceInfo(type: String?): List<DeviceInfo> { + return deviceRep.find(UWDeviceType.fromValue(type)) + } + + override fun createDevice(deviceInfo: DeviceInfo): Int { + if (deviceRep.find(DeviceInfo().apply { deviceCode = deviceInfo.deviceCode }).isNotEmpty()) { + throw BizException("璁惧缂栧彿宸插瓨鍦�") + } + val deviceType = UWDeviceType.fromValue(deviceInfo.deviceType) ?: throw BizException("璁惧绫诲瀷涓嶅瓨鍦�") + val dList = deviceRep.find(deviceType, false) + val index = if (dList.isEmpty()) 1 else ++dList[0].displayIndex + deviceInfo.apply { + deviceName = "${deviceType.des}${index}鍙�" + displayIndex = index + createTime = Date() + } + return deviceRep.insert(deviceInfo) + } + + override fun deleteDevice(deviceCode: String): Int { + return deviceRep.delete(deviceCode) } } \ No newline at end of file -- Gitblit v1.9.3