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.common.utils.Constant
|
import cn.flightfeather.supervision.common.utils.ExcelUtil
|
import cn.flightfeather.supervision.domain.ds1.entity.SceneConstructionSite
|
import kotlin.math.round
|
|
class ProTypeStatusSummary(dataSource: DataSource) : BaseTemplate(dataSource) {
|
override val cols: List<BaseCols> = listOf()
|
override val templateName: String = "工地施工阶段问题分类分析表"
|
|
@Throws(Exception::class)
|
override fun execute() {
|
if (dataSource.config.sceneType.toString() != Constant.ScenseType.TYPE1.value) {
|
throw IllegalStateException("${templateName}只能针对工地进行分析,当前传入场景类型编号为${dataSource.config.sceneType}")
|
}
|
|
dataSource.reset()
|
|
val proMap = mutableMapOf<String?, MutableMap<String?, Summary>>()
|
dataSource.loop { _, rowData ->
|
rowData.problems.forEach {
|
val s = (rowData.baseScene as SceneConstructionSite?)?.csStatus
|
if (!proMap.containsKey(s)) {
|
proMap[s] = mutableMapOf()
|
}
|
val pt = it.ptguid
|
if (proMap[s]?.containsKey(pt) == false) {
|
proMap[s]?.put(pt, Summary().apply {
|
for (p in rowData.problemTypes) {
|
if (p.guid == pt) {
|
status = s ?: ""
|
proType = p.typename ?: ""
|
proDes = p.description ?: ""
|
break
|
}
|
}
|
})
|
}
|
proMap[s]?.get(pt)?.apply {
|
count++
|
if (it.ischanged == true) changeNum++
|
}
|
}
|
}
|
|
//占比统计
|
val summarys = mutableListOf<Summary>()
|
var tPros = 0
|
proMap.forEach {
|
it.value.forEach {e ->
|
val v = e.value
|
summarys.add(v)
|
tPros += v.count
|
}
|
}
|
summarys.forEach {
|
it.countPer = it.count.toDouble() / tPros
|
it.changePer = it.changeNum.toDouble() / it.count
|
}
|
|
|
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("问题大类(二级指标)", rowSpan = 2),
|
ExcelUtil.MyCell("问题小类(三级指标)", rowSpan = 2),
|
ExcelUtil.MyCell("问题占比排名分析", colSpan = 2),
|
ExcelUtil.MyCell("整改率排名分析", colSpan = 2),
|
)
|
)
|
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.status, s.status,
|
s.proType, s.proDes,
|
s.count, "${round(s.countPer * 1000) / 10}%",
|
s.changeNum, "${round(s.changePer * 1000) / 10}%",
|
)
|
)
|
}
|
}
|
|
inner class Summary() {
|
var status = ""
|
var proType = ""
|
var proDes = ""
|
var count = 0
|
var countPer = .0
|
set(value) {
|
field = if (value.isNaN()) .0 else value
|
}
|
|
var changeNum = 0
|
var changePer = .0
|
set(value) {
|
field = if (value.isNaN()) .0 else value
|
}
|
}
|
}
|