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.ColGrade
|
import cn.flightfeather.supervision.common.utils.ExcelUtil
|
import kotlin.math.round
|
|
class ScoreAnalysisSummary(dataSource: DataSource) : BaseTemplate(dataSource) {
|
override val cols: List<BaseCols> = listOf(ColGrade())
|
|
override val templateName: String = "分街镇规范性分析表"
|
|
override fun execute() {
|
dataSource.reset()
|
cols.forEach { it.combineHead(head,dataSource) }
|
|
val districtMap = mutableMapOf<String?, Summary>()
|
dataSource.loop { index, rowData ->
|
|
val r = cols[0].getOneRow(rowData)
|
|
val k = rowData.scene?.townname
|
if (!districtMap.containsKey(k)) {
|
districtMap[k] = Summary().apply {
|
townCode = rowData.scene?.towncode ?: ""
|
townName = rowData.scene?.townname ?: ""
|
type = rowData.scene?.type ?: ""
|
}
|
}
|
if (r[1] is String) {
|
val s = r[1]
|
}
|
districtMap[k]?.apply {
|
sceneCount++
|
rowData.evaluation?.run { gradeCount++ }
|
if ((r[1] is String) && (r[1] as String).isBlank()) return@loop
|
when ((r[1] as ExcelUtil.MyCell).text) {
|
"规范" -> {
|
level1++
|
standard++
|
}
|
"基本规范" -> {
|
level2++
|
standard++
|
}
|
"不规范" -> {
|
level3++
|
nonstandard++
|
}
|
"严重不规范" -> {
|
level4++
|
nonstandard++
|
}
|
}
|
}
|
}
|
|
//占比统计
|
val summarys = mutableListOf<Summary>()
|
var tLevel1 = 0
|
var tLevel2 = 0
|
var tLevel3 = 0
|
var tLevel4 = 0
|
var tNonstandard = 0
|
var tStandard = 0
|
districtMap.forEach {
|
val v = it.value
|
summarys.add(v)
|
tLevel1 += v.level1
|
tLevel2 += v.level2
|
tLevel3 += v.level3
|
tLevel4 += v.level4
|
tNonstandard += v.nonstandard
|
tStandard += v.standard
|
}
|
summarys.sortByDescending { it.standardPer }
|
for (i in summarys.indices) {
|
val it = summarys[i]
|
//参评百分比
|
it.gradePer = it.gradeCount.toDouble() / it.sceneCount
|
//规范、基本规范、不规范和严重不规范区域占比
|
it.level1Per = it.level1.toDouble() / tLevel1
|
it.level2Per = it.level2.toDouble() / tLevel2
|
it.level3Per = it.level3.toDouble() / tLevel3
|
it.level4Per = it.level4.toDouble() / tLevel4
|
//不规范区域占比
|
it.nonstandardPer = it.nonstandard.toDouble() / tNonstandard
|
//规范区域占比
|
it.standardPer = it.standard.toDouble() / tStandard
|
//规范占比排名
|
it.rank = i + 1
|
}
|
|
head.clear()
|
head.add(mutableListOf(
|
ExcelUtil.MyCell("街镇序号", rowSpan = 2),
|
ExcelUtil.MyCell("街镇/工业区", rowSpan = 2),
|
ExcelUtil.MyCell("场景类别", rowSpan = 2),
|
ExcelUtil.MyCell("参评情况", colSpan = 3),
|
ExcelUtil.MyCell("规范性分类分析", colSpan = 8),
|
ExcelUtil.MyCell("规范性汇总分析", colSpan = 5),
|
))
|
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("防治严重不规范"),
|
ExcelUtil.MyCell("区域占比"),
|
ExcelUtil.MyCell("各类不规范合计"),
|
ExcelUtil.MyCell("各类不规范合计区域占比"),
|
ExcelUtil.MyCell("各类规范合计"),
|
ExcelUtil.MyCell("各类规范合计区域占比"),
|
ExcelUtil.MyCell("规范性排名"),
|
))
|
|
summarys.forEach {
|
contents.add(
|
mutableListOf(
|
it.townCode, it.townName, it.type, it.sceneCount, it.gradeCount, "${round(it.gradePer * 1000) / 10}%",
|
it.level1, "${round(it.level1Per * 1000) / 10}%",
|
it.level2, "${round(it.level2Per * 1000) / 10}%",
|
it.level3, "${round(it.level3Per * 1000) / 10}%",
|
it.level4, "${round(it.level4Per * 1000) / 10}%",
|
it.nonstandard, "${round(it.nonstandardPer * 1000) / 10}%",
|
it.standard, "${round(it.standardPer * 1000) / 10}%",
|
it.rank
|
)
|
)
|
}
|
}
|
|
inner class Summary(){
|
var townCode = ""
|
var townName = ""
|
var type = ""
|
var sceneCount = 0
|
//参评数
|
var gradeCount = 0
|
var gradePer = .0
|
set(value) { field = if (value.isNaN()) .0 else value }
|
//规范、基本规范、不规范和严重不规范数量及区域占比
|
var level1 = 0
|
var level1Per = .0
|
set(value) { field = if (value.isNaN()) .0 else value }
|
var level2 = 0
|
var level2Per = .0
|
set(value) { field = if (value.isNaN()) .0 else value }
|
var level3 = 0
|
var level3Per = .0
|
set(value) { field = if (value.isNaN()) .0 else value }
|
var level4 = 0
|
var level4Per = .0
|
set(value) { field = if (value.isNaN()) .0 else value }
|
//不规范合计及区域占比
|
var nonstandard = 0
|
var nonstandardPer = .0
|
set(value) { field = if (value.isNaN()) .0 else value }
|
//规范合计及区域占比
|
var standard = 0
|
var standardPer = .0
|
set(value) { field = if (value.isNaN()) .0 else value }
|
//规范占比排名
|
var rank = 0
|
}
|
}
|