feiyu02
2022-07-19 b041775dae4438e428d2b70d2b22cfe8c49844fe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
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
    }
}