From eb3dd00b0b7fcda477229d518d250f9c842b790b Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 21 十月 2025 17:45:44 +0800
Subject: [PATCH] 2025.10.21 1. 走航季度报告相关数据计算逻辑调整
---
src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt | 115 +++++++++++++++++++++++++++++++++++----------------------
1 files changed, 71 insertions(+), 44 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt b/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt
index dc24be6..7e0c3ea 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt
@@ -3,8 +3,7 @@
import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.common.utils.ExcelUtil
import com.flightfeather.uav.socket.eunm.FactorType
-import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook
-import org.apache.poi.hssf.usermodel.HSSFWorkbook
+import org.apache.poi.xssf.streaming.SXSSFWorkbook
import java.io.File
import java.io.FileOutputStream
import java.util.*
@@ -14,7 +13,18 @@
* 姹℃煋婧愬奖鍝嶇▼搴︽潈閲嶅垎鏋愭ā鍨�
* 鍩虹被
*/
-abstract class BaseModel<M : BaseMData, S : BaseSOP> {
+abstract class BaseModel<M : BaseMData, S: BaseSOP> {
+
+ data class ResultCell(
+ var total: Double = 0.0,
+ var count: Int = 0,
+ var average: Double = 0.0
+ ) {
+ fun average(): Double {
+ average = if (count == 0) .0 else round(total / count * 100) / 100
+ return average
+ }
+ }
abstract var dataPrep: BaseDataPrep<M, S>
@@ -25,7 +35,7 @@
abstract var weights: List<BaseWeight<M, S>>
// 璁$畻缁撴灉
- private val result = mutableSetOf<BaseEffect>()
+ private val rMap = mutableMapOf<String, MutableMap<String, MutableMap<String, ResultCell>>>()
// 缁撴灉绛涢�夋柟寮�
abstract var sections: List<BaseSection<M, S>>
@@ -35,8 +45,8 @@
* @param mDataList 鐩戞祴鏁版嵁闆嗗悎
* @param sopList 姹℃煋婧愰泦鍚�
*/
- fun execute(mDataList: List<M>, sopList: List<S>) {
- result.clear()
+ open fun execute(mDataList: List<M>, sopList: List<S>, hasNext: Boolean = false) {
+ if (!hasNext) rMap.clear()
//1. 鏁版嵁棰勫鐞�
val mList = dataPrep.mDataPrep(mDataList)
@@ -73,20 +83,20 @@
sections.forEach { it.filter(mData, sop, effect) }
// 淇濆瓨缁撴灉
- result.add(effect)
+ formatConversion2(effect)
}
fun outputToExcel(
fName: String? = null,
- _workbook: HSSFWorkbook? = null,
+ _workbook: SXSSFWorkbook? = null,
_out: FileOutputStream? = null,
sheetName: String = "sheet1",
done: Boolean = true
- ): Pair<HSSFWorkbook, FileOutputStream>? {
- val rMap = formatConversion()
+ ): Pair<SXSSFWorkbook, FileOutputStream>? {
+// val rMap = formatConversion()
- val workbook = _workbook ?: HSSFWorkbook()
- val fileName = fName ?: "姹℃煋婧簮鏉冮噸妯″瀷${DateUtil().DateToString(Date(), "yyyy-MM-ddHHmmss")}.xls"
+ val workbook = _workbook ?: SXSSFWorkbook()
+ val fileName = fName ?: "姹℃煋婧簮鏉冮噸妯″瀷${DateUtil.instance.dateToString(Date(), "yyyy-MM-ddHHmmss")}.xls"
// val filePath = "E:\\work\\export\\$fileName"
// val filePath = "E:\\宸ヤ綔\\寮�鍙慭\璧拌埅鐩戞祴\\绠楁硶鐩稿叧\\鑷姩杈撳嚭\\$fileName"
val filePath = "E:\\宸ヤ綔\\寮�鍙慭\璧拌埅鐩戞祴\\绠楁硶鐩稿叧\\鑷姩杈撳嚭\\缃戞牸鍖朶\$fileName"
@@ -106,9 +116,8 @@
// 鏂板缓涓�琛�
val contentList = mutableListOf<Any>()
// 娣诲姞姹℃煋婧愬悕绉�
- val l = source.split("(")
- val index = l[1].substring(0, l[1].lastIndex)
- contentList.add(index.toIntOrNull() ?: 0)
+ val l = source.split(";")
+ contentList.add(l[1].toIntOrNull() ?: 0)
contentList.add(l[0])
tMap.forEach { (factorType, lMap) ->
sections.forEach {
@@ -118,11 +127,11 @@
}
var max = 0.0
var maxP = types[0]
- types.forEach {se ->
+ types.forEach type@{se ->
val lKey = "$se($factorType)"
if (lMap.containsKey(lKey)) {
- val dataList = lMap[lKey]
- val size = dataList?.size
+ val resultCell = lMap[lKey] ?: return@type
+// val size = resultCell.count
// 娣诲姞璇ュ垎绫讳綔涓鸿〃澶�
val h = lKey
// val h = "$lKey($size)"
@@ -130,17 +139,17 @@
h1.add(h)
}
- // 灏嗗師濮嬬殑鏁版嵁鎹㈢畻寰楀嚭缁撴灉锛屽彲浠ユ槸姹傚嚭鍧囧�笺�佹�诲拰绛夌瓑锛屽悗缁慨鏀逛负鍙敱鐢ㄦ埛璁惧畾
+ // 灏嗗師濮嬬殑鏁版嵁鎹㈢畻寰楀嚭缁撴灉锛屽彲浠ユ槸姹傚嚭鍧囧�笺�佹�诲拰绛夌瓑
// FIXME: 2021/6/23 姝ゅ鍏堥粯璁や负姹傚潎鍊�
- val average = dataList?.average()
+ val average = resultCell.average()
- if (average ?: 0.0 > max) {
- max = average ?: 0.0
+ if (average > max) {
+ max = average
maxP = se
}
// 褰撳墠琛屾坊鍔犺鍒嗙被涓嬬殑缁撴灉鍊�
- contentList.add(average ?: 0.0)
+ contentList.add(average)
}
}
if (isFirst) {
@@ -177,34 +186,52 @@
}
}
- private fun formatConversion(): Map<String, Map<String, Map<String?, MutableList<Double>>>> {
- val rMap = mutableMapOf<String, MutableMap<String, MutableMap<String?, MutableList<Double>>>>()
- println("缁撴灉闀垮害锛�${result.size}")
- result.forEach { e ->
- val rKey = "${e.sourceName}(${e.index})"
- if (!rMap.containsKey(rKey)) {
- rMap[rKey] = mutableMapOf()
- }
- val lMap = rMap[rKey]!!
- e.value.forEach { v ->
- if (!lMap.containsKey(v.first.des)) {
- lMap[v.first.des] = mutableMapOf()
- }
- val tMap = lMap[v.first.des]!!
- e.tag.forEach { t ->
- val factorName = v.first.des
- val lKey = t.levelName + "($factorName)"
- if (!tMap.containsKey(lKey)) {
- tMap[lKey] = mutableListOf()
- }
- tMap[lKey]?.add(v.second)
+ fun outputResult(): MutableMap<String, MutableMap<String, MutableMap<String, ResultCell>>> {
+ rMap.forEach { (_, v) ->
+ v.forEach { (_, v2) ->
+ v2.forEach { (_, v3) ->
+ v3.average()
}
}
}
+
return rMap
}
/**
+ * 灏嗚绠楃粨鏋滄牸寮忓寲涓哄灞傜骇鐨勯敭瀵瑰�肩粨鏋�
+ * 绗竴灞傛寜鐓т笉鍚屾薄鏌撴簮鐨勭储寮曞�艰繘琛屽垎绫�
+ * 绗簩灞傛寜鐓х洃娴嬪洜瀛愮被鍨嬭繘琛屽垎绫�
+ * 绗笁灞傛寜鐓ц嚜瀹氫箟鐨勬爣绛捐繘琛屽垎绫�
+ */
+ private fun formatConversion2(e: BaseEffect) {
+ val rKey = "${e.sourceName};${e.index}"
+ if (!rMap.containsKey(rKey)) {
+ rMap[rKey] = mutableMapOf()
+ }
+ val lMap = rMap[rKey]!!
+ e.value.forEach { v ->
+ if (!lMap.containsKey(v.first.des)) {
+ lMap[v.first.des] = mutableMapOf()
+ }
+ val tMap = lMap[v.first.des]!!
+ e.tag.forEach { t ->
+ val factorName = v.first.des
+ val lKey = t.levelName + "($factorName)"
+ if (!tMap.containsKey(lKey)) {
+ tMap[lKey] = ResultCell()
+ }
+ tMap[lKey]?.run {
+ total += v.second
+ if (factorName != FactorType.H2S.name || v.second > 0) {
+ count++
+ }
+ }
+ }
+ }
+ }
+
+ /**
* 鐩戞祴鏁版嵁鍚堟硶鎬ф鏌�
*/
abstract fun mDataCheck(m: M): Boolean
--
Gitblit v1.9.3