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
package cn.flightfeather.supervision.business.report.cols
 
import cn.flightfeather.supervision.business.report.BaseCols
import cn.flightfeather.supervision.business.report.DataSource
import cn.flightfeather.supervision.common.utils.ExcelUtil
import cn.flightfeather.supervision.domain.ds1.entity.Itemevaluation
import org.apache.poi.hssf.util.HSSFColor
 
class ColGrade(private val hasHead3: Boolean = true) : BaseCols() {
 
    override fun onHeads(dataSource: DataSource): MutableList<MutableList<ExcelUtil.MyCell>> {
        val h1 = mutableListOf<ExcelUtil.MyCell>()
        h1.add(ExcelUtil.MyCell("环信码", 3, 1))
        h1.add(ExcelUtil.MyCell("防治规范性", 3, 1))
        h1.add(ExcelUtil.MyCell("总分", 3, 1))
        val h2 = mutableListOf<ExcelUtil.MyCell>()
        h2.add(ExcelUtil.MyCell(""))
        h2.add(ExcelUtil.MyCell(""))
        h2.add(ExcelUtil.MyCell(""))
        val h3 = mutableListOf<ExcelUtil.MyCell>()
        h3.add(ExcelUtil.MyCell(""))
        h3.add(ExcelUtil.MyCell(""))
        h3.add(ExcelUtil.MyCell(""))
        dataSource.rowData.topItems.forEach {
            h1.add(ExcelUtil.MyCell(it.itemname ?: "", 1, 0))
            for (r in dataSource.rowData.rules) {
                if (r.first.fatherid == it.guid || r.first.guid == it.guid) {
                    h2.add(ExcelUtil.MyCell(r.first.itemname ?: "", 1, 0))
                    if (hasHead3) {
                        r.second.forEach { s ->
                            h3.add(ExcelUtil.MyCell(s.itemname ?: ""))
                            h2.last().colSpan++
                            h1.last().colSpan++
                        }
                    } else {
                        h2.last().colSpan++
                        h1.last().colSpan++
                    }
                }
            }
        }
 
        return mutableListOf(h1, h2, h3)
    }
 
    override fun onOneRow(rowData: DataSource.RowData): List<Any> {
        val row = mutableListOf<Any>()
 
        if (rowData.noRecord()) {
            repeat(heads.last().size) { row.add(("")) }
        } else {
            row.apply {
                //总分和环信码
                rowData.evaluation.let { e ->
                    val s = e?.resultscorebef?.toIntOrNull() ?: ""
                    val code = when (s) {
                        in 0..59 -> ExcelUtil.MyCell("红码", fontColor = HSSFColor.HSSFColorPredefined.RED.index)
                        in 60..89 -> ExcelUtil.MyCell("黄码", fontColor = HSSFColor.HSSFColorPredefined.GOLD.index)
                        in 90..100 -> ExcelUtil.MyCell("绿码", fontColor = HSSFColor.HSSFColorPredefined.BRIGHT_GREEN.index)
                        "" -> ExcelUtil.MyCell("", fontColor = HSSFColor.HSSFColorPredefined.BLACK.index)
                        else -> ExcelUtil.MyCell("超出范围:${s}", fontColor = HSSFColor.HSSFColorPredefined.BLACK.index)
                    }
                    val normalization = when (s) {
                        in 0..59 -> ExcelUtil.MyCell("严重不规范", fontColor = HSSFColor.HSSFColorPredefined.ROSE.index)
                        in 60..89 -> ExcelUtil.MyCell("不规范", fontColor = HSSFColor.HSSFColorPredefined.RED.index)
                        in 90..99 -> ExcelUtil.MyCell("基本规范", fontColor = HSSFColor.HSSFColorPredefined.GOLD.index)
                        100 -> ExcelUtil.MyCell("规范", fontColor = HSSFColor.HSSFColorPredefined.BRIGHT_GREEN.index)
                        "" -> ExcelUtil.MyCell("", fontColor = HSSFColor.HSSFColorPredefined.BLACK.index)
                        else -> ExcelUtil.MyCell("超出范围:${s}", fontColor = HSSFColor.HSSFColorPredefined.BLACK.index)
                    }
                    add(code)
                    add(normalization)
                    add(s)
                }
 
 
                //每一项具体得分
                rowData.topItems.forEach {
                    for (r in rowData.rules) {
                        if (r.first.fatherid == it.guid || r.first.guid == it.guid) {
                            // FIXME: 2021/4/25 决定是否写h3
                            if (hasHead3) {
                                r.second.forEach { s ->
                                    val v = searchScore(s.guid, rowData.itemevaluationList)
                                    add(v.toIntOrNull() ?: "")
                                }
                            } else {
                                val v = searchScore(r.first.guid, rowData.itemevaluationList)
                                add(v.toIntOrNull() ?: "")
                            }
                        }
                    }
                }
            }
        }
 
        return row
    }
 
    //查找得分记录内对应规则的得分
    private fun searchScore(ruleId: String?, itemevaluations: List<Itemevaluation>): String {
        var score = ""
        for (e in itemevaluations) {
            if (ruleId == e.esrguid) {
                score = e.value ?: ""
                break
            }
        }
        return score
    }
}