package cn.flightfeather.supervision.business.report.template
|
|
import cn.flightfeather.supervision.business.report.BaseCols
|
import cn.flightfeather.supervision.business.report.BaseTemplate
|
import cn.flightfeather.supervision.business.report.DataSource
|
import cn.flightfeather.supervision.business.report.cols.*
|
import cn.flightfeather.supervision.common.utils.ExcelUtil
|
import kotlin.math.round
|
|
open class ProTypeRankSummary(dataSource: DataSource) : BaseTemplate(dataSource) {
|
override val cols: List<BaseCols> = listOf()
|
override val templateName: String = "问题与整改分类排名"
|
|
override fun execute() {
|
dataSource.reset()
|
|
val proMap = mutableMapOf<String?, Summary>()
|
dataSource.loop { _, rowData ->
|
rowData.problems.forEach {
|
val k = it.ptguid
|
if (!proMap.containsKey(k)) {
|
proMap[k] = Summary().apply {
|
for (p in rowData.problemTypes) {
|
if (p.guid == k) {
|
proType = p.typename ?: ""
|
proDes = p.description ?: ""
|
break
|
}
|
}
|
}
|
}
|
proMap[k]?.apply {
|
count++
|
if (it.ischanged == true) changeNum++
|
}
|
}
|
}
|
|
//占比统计
|
val summarys = mutableListOf<Summary>()
|
var tPros = 0
|
proMap.forEach {
|
val v = it.value
|
summarys.add(v)
|
tPros += v.count
|
}
|
summarys.sortByDescending { it.count }
|
for (i in summarys.indices) {
|
val it = summarys[i]
|
it.countPer = it.count.toDouble() / tPros
|
it.countRank = i + 1
|
it.changePer = it.changeNum.toDouble() / it.count
|
}
|
summarys.sortByDescending { it.changePer }
|
for (i in summarys.indices) {
|
val it = summarys[i]
|
it.changeRank = i + 1
|
}
|
|
formatTable(summarys)
|
}
|
|
open fun formatTable(summarys: List<Summary>) {
|
head.clear()
|
head.add(
|
mutableListOf(
|
ExcelUtil.MyCell("序号", rowSpan = 2),
|
ExcelUtil.MyCell("年度", rowSpan = 2),
|
ExcelUtil.MyCell("月份", rowSpan = 2),
|
ExcelUtil.MyCell("场景类别", rowSpan = 2),
|
ExcelUtil.MyCell("区域", rowSpan = 2),
|
ExcelUtil.MyCell("问题大类(二级指标)", rowSpan = 2),
|
ExcelUtil.MyCell("问题小类(三级指标)", rowSpan = 2),
|
ExcelUtil.MyCell("问题占比排名分析", colSpan = 3),
|
ExcelUtil.MyCell("整改率排名分析", colSpan = 3),
|
)
|
)
|
head.add(
|
mutableListOf(
|
ExcelUtil.MyCell(""),
|
ExcelUtil.MyCell(""),
|
ExcelUtil.MyCell(""),
|
ExcelUtil.MyCell(""),
|
ExcelUtil.MyCell(""),
|
ExcelUtil.MyCell(""),
|
ExcelUtil.MyCell(""),
|
ExcelUtil.MyCell("合计问题数"),
|
ExcelUtil.MyCell("问题占比"),
|
ExcelUtil.MyCell("问题排名"),
|
ExcelUtil.MyCell("整改数"),
|
ExcelUtil.MyCell("整改率"),
|
ExcelUtil.MyCell("整改排名"),
|
)
|
)
|
for (i in summarys.indices) {
|
val s = summarys[i]
|
contents.add(
|
mutableListOf(
|
i + 1, "", "", dataSource.rowData.scene?.type ?: "", "",
|
s.proType, s.proDes,
|
s.count, "${round(s.countPer * 1000) / 10}%", s.countRank,
|
s.changeNum, "${round(s.changePer * 1000) / 10}%", s.changeRank
|
)
|
)
|
}
|
}
|
|
inner class Summary() {
|
var proType = ""
|
var proDes = ""
|
var count = 0
|
var countPer = .0
|
set(value) {
|
field = if (value.isNaN()) .0 else value
|
}
|
var countRank = 0
|
|
var changeNum = 0
|
var changePer = .0
|
set(value) {
|
field = if (value.isNaN()) .0 else value
|
}
|
var changeRank = 0
|
}
|
}
|