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
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
            }
    }
}