| | |
| | | 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) |
| | | } |
| | | } |