riku
2024-12-31 b7b520bfe8b35683112284861f0dca8e645cbd56
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
package com.flightfeather.uav.lightshare.bean
 
import java.math.BigDecimal
import kotlin.math.round
 
/**
 * 企业信访投诉统计信息
 */
data class ComplaintVo(
    val ciGuid: String,
    val ciName: String,
    var ciLng: Double,
    var ciLat: Double,
    val index: Int,
    val ciAddress: String? = null,
    val result: MutableList<ComplaintType> = mutableListOf()
)
 
/**
 * 信访投诉类型信息
 */
data class ComplaintType(
    // 污染类型id
    val type: Int,
    // 污染类型名称
    val typeName: String,
    // 信访投诉计数
    val count: Int,
    // 占比
    val percent: Double = .0
)
 
/**
 * 信访投诉统计(数据库返回结构体)
 */
data class ComplaintRecord(
    var ciGuid: String,
    var ciName: String,
    var ciLng: BigDecimal,
    var ciLat: BigDecimal,
    var ciIndex: String,
    var ciAddress: String,
    var coType: Int,
    var coTypeName: String,
    var count: Long
) {
    var percent: Double = .0
}
 
/**
 * 求信访记录中每种投诉类型的各自占比
 */
fun List<ComplaintRecord>.percent() {
    val cMap = mutableMapOf<Int, Int>()
    this.forEach {
        if (!cMap.containsKey(it.coType)) {
            cMap[it.coType] = 0
        }
        cMap[it.coType] = cMap[it.coType]?.plus(it.count)?.toInt() ?: 0
    }
    this.forEach {
        val t = cMap[it.coType]
        it.percent = if (t != null && t != 0) round(it.count / t.toDouble() * 10000) / 10000 else .0
    }
}