From b8cc591541b88dd2bb93f111f8e8075842dce7ca Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 13 八月 2024 17:21:06 +0800
Subject: [PATCH] 1. 新增设备信息相关功能 2. 修正自评估中数据自动评分的部分逻辑

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DeviceServiceImpl.kt |   81 +++++++++++++++++++++++++++++-----------
 1 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DeviceServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DeviceServiceImpl.kt
index d4a05aa..eac25dd 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DeviceServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DeviceServiceImpl.kt
@@ -5,10 +5,11 @@
 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.*
@@ -19,34 +20,68 @@
  * @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(
@@ -55,14 +90,14 @@
         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)
                 }
             }
@@ -70,10 +105,10 @@
 
         // 淇濆瓨鏂板鍥剧墖
         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)
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3