From 2de612e9b260df2e76d4dd620ca739aa3b6e8c57 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 25 八月 2025 16:07:16 +0800
Subject: [PATCH] 2025.8.25 1. 添加走航季度报告相关统计功能(待完成)

---
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImpl.kt |   48 ++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImpl.kt
index a7a0458..d00408f 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImpl.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImpl.kt
@@ -1,18 +1,23 @@
 package com.flightfeather.uav.lightshare.service.impl
 
 import com.flightfeather.uav.biz.FactorFilter
+import com.flightfeather.uav.biz.mission.MissionUtil
 import com.flightfeather.uav.biz.report.MissionReport
 import com.flightfeather.uav.common.exception.BizException
 import com.flightfeather.uav.domain.entity.Mission
 import com.flightfeather.uav.domain.entity.RealTimeDataVehicle
 import com.flightfeather.uav.domain.mapper.MissionMapper
 import com.flightfeather.uav.domain.mapper.RealTimeDataVehicleMapper
+import com.flightfeather.uav.domain.repository.MissionRep
+import com.flightfeather.uav.domain.repository.RealTimeDataRep
 import com.flightfeather.uav.lightshare.bean.BaseResponse
 import com.flightfeather.uav.lightshare.bean.DataHead
 import com.flightfeather.uav.lightshare.service.MissionService
 import com.github.pagehelper.PageHelper
 import org.springframework.stereotype.Service
 import tk.mybatis.mapper.entity.Example
+import java.io.File
+import java.util.*
 import javax.servlet.http.HttpServletResponse
 
 @Service
@@ -20,8 +25,10 @@
     private val missionMapper: MissionMapper,
     private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper,
     private val missionReport: MissionReport,
+    private val missionRep: MissionRep,
+    private val realTimeDataRep: RealTimeDataRep
 ) : MissionService {
-    override fun getMission(type: String?, page: Int?, perPage: Int?): BaseResponse<List<Mission>> {
+    override fun getMission(type: String?, page: Int?, perPage: Int?): Pair<DataHead, List<Mission>> {
         val _perPage = perPage ?: 60
         val _page = page ?: 1
         val pageInfo = PageHelper.startPage<Mission>(_page, _perPage)
@@ -32,21 +39,30 @@
             }
             orderBy("startTime").desc()
         }).forEach { it?.let { result.add(it) } }
-        return BaseResponse(true, head = DataHead(pageInfo.pageNum, pageInfo.pages),data = result)
+//        return BaseResponse(true, head = DataHead(pageInfo.pageNum, pageInfo.pages),data = result)
+        return DataHead(pageInfo.pageNum, pageInfo.pages) to result
     }
 
-    override fun createMission(mission: Mission): BaseResponse<Boolean> {
+    @Synchronized
+    override fun createMission(mission: Mission): Boolean {
         missionMapper.selectByPrimaryKey(mission.missionCode)?.run {
-            return BaseResponse(false, "浠诲姟缂栧彿宸插瓨鍦�")
+//            return BaseResponse(false, "浠诲姟缂栧彿宸插瓨鍦�")
+            throw BizException("浠诲姟缂栧彿宸插瓨鍦�")
         }
         missionMapper.insert(mission).let {
-            return BaseResponse(it == 1)
+            return it == 1
         }
     }
 
-    override fun deleteMission(missionCode: String): BaseResponse<Boolean> {
+    override fun updateMission(mission: Mission): Boolean {
+        missionMapper.updateByPrimaryKey(mission).let {
+            return it == 1
+        }
+    }
+
+    override fun deleteMission(missionCode: String): Boolean {
         missionMapper.deleteByPrimaryKey(missionCode).let {
-            return BaseResponse(it == 1)
+            return it == 1
         }
     }
 
@@ -61,6 +77,22 @@
     }
 
     override fun getReport(missionCode: String, response: HttpServletResponse) {
-        missionReport.execute(missionCode, FactorFilter.default())
+        val path = missionReport.execute(missionCode, FactorFilter.default())
+        val pathArr = path.split("/")
+        val file = File(path)
+        if (file.exists()) {
+            response.contentType = "application/vnd.ms-excel;charset=UTF-8"
+            val name = Base64.getEncoder().encodeToString(pathArr.last().toByteArray())
+            response.setHeader("fileName", name)
+            response.outputStream.write(file.readBytes())
+        }
+        return
+    }
+
+    override fun calMissionInfo(missionCode: String): Boolean {
+        val mission = missionRep.findOne(missionCode) ?: throw BizException("璧拌埅浠诲姟涓嶅瓨鍦�")
+        val data = realTimeDataRep.fetchData(mission)
+        mission.kilometres = MissionUtil.calKilometres(data).toFloat()
+        return updateMission(mission)
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3