| | |
| | | import cn.flightfeather.supervision.common.utils.DateUtil |
| | | import cn.flightfeather.supervision.common.utils.FileUtil |
| | | import cn.flightfeather.supervision.common.utils.JsonUtil |
| | | import cn.flightfeather.supervision.domain.ds1.entity.DeviceInfo |
| | | import cn.flightfeather.supervision.domain.ds1.entity.DeviceLocation |
| | | import cn.flightfeather.supervision.domain.ds1.entity.* |
| | | import cn.flightfeather.supervision.domain.ds1.repository.DeviceRep |
| | | import cn.flightfeather.supervision.lightshare.service.DeviceService |
| | | import com.google.gson.Gson |
| | | import org.springframework.beans.factory.annotation.Value |
| | | import org.springframework.stereotype.Service |
| | | import org.springframework.web.multipart.MultipartFile |
| | | import java.util.* |
| | |
| | | * @author feiyu02 |
| | | */ |
| | | @Service |
| | | class DeviceServiceImpl(private val deviceRep: DeviceRep) : DeviceService { |
| | | class DeviceServiceImpl( |
| | | private val deviceRep: DeviceRep, |
| | | @Value("\${filePath}") var filePath: String, |
| | | @Value("\${imgPath}") var imgPath: String, |
| | | ) : DeviceService { |
| | | |
| | | companion object{ |
| | | private const val BASE_IMG_PATH = "${Constant.DEFAULT_FILE_PATH}/images/" |
| | | override fun findDevices(sceneId: String, deviceType: Constant.DeviceType): List<BaseDevice> { |
| | | return deviceRep.findDeviceList(sceneId, deviceType) |
| | | } |
| | | |
| | | override fun findDevices(sceneId: String): List<DeviceInfo> { |
| | | return deviceRep.findDeviceList(sceneId) |
| | | override fun insertDevice(deviceInfo: String, deviceType: Constant.DeviceType): Int { |
| | | return when (deviceType) { |
| | | Constant.DeviceType.MONITOR_DEVICE -> { |
| | | val info = Gson().fromJson(deviceInfo, MonitorDeviceInfo::class.java) |
| | | info.diCreateTime = Date() |
| | | deviceRep.insertDevice(info) |
| | | } |
| | | Constant.DeviceType.TREATMENT_DEVICE -> { |
| | | val info = Gson().fromJson(deviceInfo, TreatmentDeviceInfo::class.java) |
| | | info.piCreateTime = Date() |
| | | deviceRep.insertDevice(info) |
| | | } |
| | | Constant.DeviceType.PRODUCTION_DEVICE -> { |
| | | val info = Gson().fromJson(deviceInfo, ProductionDeviceInfo::class.java) |
| | | info.wiCreateTime = Date() |
| | | deviceRep.insertDevice(info) |
| | | } |
| | | } |
| | | } |
| | | |
| | | override fun insertDevice(deviceInfo: DeviceInfo): Int { |
| | | return deviceRep.insertDevice(deviceInfo) |
| | | override fun updateDevice(deviceInfo: String, deviceType: Constant.DeviceType): Int { |
| | | return when (deviceType) { |
| | | Constant.DeviceType.MONITOR_DEVICE -> { |
| | | val info = Gson().fromJson(deviceInfo, MonitorDeviceInfo::class.java) |
| | | deviceRep.updateDevice(info) |
| | | } |
| | | Constant.DeviceType.TREATMENT_DEVICE -> { |
| | | val info = Gson().fromJson(deviceInfo, TreatmentDeviceInfo::class.java) |
| | | deviceRep.updateDevice(info) |
| | | } |
| | | Constant.DeviceType.PRODUCTION_DEVICE -> { |
| | | val info = Gson().fromJson(deviceInfo, ProductionDeviceInfo::class.java) |
| | | deviceRep.updateDevice(info) |
| | | } |
| | | } |
| | | } |
| | | |
| | | override fun updateDevice(deviceInfo: DeviceInfo): Int { |
| | | return deviceRep.updateDevice(deviceInfo) |
| | | } |
| | | |
| | | override fun findDeviceLocations(deviceId: Int): List<DeviceLocation> { |
| | | return deviceRep.findLocations(deviceId) |
| | | override fun findDeviceLocations( |
| | | sceneId: String?, |
| | | deviceId: Int, |
| | | deviceType: Constant.DeviceType, |
| | | ): List<DeviceStatus> { |
| | | return emptyList() |
| | | } |
| | | |
| | | override fun insertDeviceLocation(deviceLocation: String, files: Array<MultipartFile>): Int { |
| | | val obj = JsonUtil.gson.fromJson(deviceLocation, DeviceLocation::class.java) |
| | | val obj = JsonUtil.gson.fromJson(deviceLocation, DeviceStatus::class.java) |
| | | val time = DateUtil.DateToString(obj.dlCreateTime, DateUtil.DateStyle.YYYY_MM_DD) |
| | | val picPath = FileUtil.saveFiles(files, BASE_IMG_PATH, "device/${obj.dlId}/${time}") |
| | | val picPath = FileUtil.saveFiles(files, imgPath, "device/${obj.dlId}/${time}") |
| | | obj.dlPicUrl = picPath.joinToString(";") |
| | | return deviceRep.insertLocation(obj) |
| | | obj.dlCreateTime = Date() |
| | | return deviceRep.insertStatus(obj) |
| | | } |
| | | |
| | | override fun updateDeviceLocation( |
| | |
| | | files: Array<MultipartFile>, |
| | | ): Int { |
| | | // 获取更新信息 |
| | | val obj = JsonUtil.gson.fromJson(deviceLocation, DeviceLocation::class.java) |
| | | val obj = JsonUtil.gson.fromJson(deviceLocation, DeviceStatus::class.java) |
| | | |
| | | // 获取原位置信息,删除图片路径和对应图片 |
| | | val dL = deviceRep.findLocation(obj.dlId) ?: throw BizException("该设备位置信息不存在,无法修改") |
| | | val dL = deviceRep.findStatus(obj.dlId) ?: throw BizException("该设备位置信息不存在,无法修改") |
| | | val oldImg = dL.dlPicUrl.split(";").toMutableList() |
| | | deleteImg.forEach { |
| | | if (oldImg.contains(it)) { |
| | | if (FileUtil.delFile(BASE_IMG_PATH + it)) { |
| | | if (FileUtil.delFile(imgPath + it)) { |
| | | oldImg.remove(it) |
| | | } |
| | | } |
| | |
| | | |
| | | // 保存新增图片 |
| | | val time = DateUtil.DateToString(obj.dlCreateTime, DateUtil.DateStyle.YYYY_MM_DD) |
| | | val picPath = FileUtil.saveFiles(files, BASE_IMG_PATH, "device/${obj.dlId}/${time}") |
| | | val picPath = FileUtil.saveFiles(files, imgPath, "device/${obj.dlId}/${time}") |
| | | |
| | | oldImg.addAll(picPath) |
| | | obj.dlPicUrl = oldImg.joinToString(";") |
| | | return deviceRep.updateLocation(obj) |
| | | return deviceRep.updateStatus(obj) |
| | | } |
| | | } |