feiyu02
2024-11-19 752e00503f672ddfe2066afb6c235721a3a912b5
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
package cn.flightfeather.supervision.common.risk
 
import cn.flightfeather.supervision.domain.entity.Userinfo
import cn.flightfeather.supervision.domain.enumeration.SceneType
import cn.flightfeather.supervision.infrastructure.utils.DateUtil
import cn.flightfeather.supervision.infrastructure.utils.ExcelUtil
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
import java.util.*
import kotlin.math.round
 
class UtilFile(private val config: DataSource.Config) {
 
    private val heads = mutableListOf<Array<Any>>()
    private val contents = mutableListOf<Array<Any>>()
    private var index = 1
    private var sceneType: String? = null
 
    init {
        sceneType = SceneType.getByValue(config.sceneType.toInt()).des
        val h1 = listOf(
            ExcelUtil.MyCell("${sceneType}单位基本信息", colSpan = 7),
            ExcelUtil.MyCell("守法帮扶微信小程序登录", colSpan = 1),
            ExcelUtil.MyCell("${sceneType}单位认证(单个企业允许多用户)", colSpan = 4),
            ExcelUtil.MyCell("守法承诺", colSpan = 1),
            ExcelUtil.MyCell("台账规范性", colSpan = 4),
            ExcelUtil.MyCell("自巡查规范性", colSpan = 3),
            ExcelUtil.MyCell("守法自测自评", colSpan = 3),
            ExcelUtil.MyCell("线上监管综合风险分析与对策", colSpan = 2),
        )
        val h2 = listOf(
            ExcelUtil.MyCell("序号", colSpan = 1),
            ExcelUtil.MyCell("账号", colSpan = 1),
            ExcelUtil.MyCell("单位名称", colSpan = 1),
            ExcelUtil.MyCell("经营状态", colSpan = 1),
            ExcelUtil.MyCell("单位地址", colSpan = 1),
            ExcelUtil.MyCell("常用联系人", colSpan = 1),
            ExcelUtil.MyCell("联系方式", colSpan = 1),
            ExcelUtil.MyCell("小程序登录情况", colSpan = 1),
            ExcelUtil.MyCell("企业认证", colSpan = 1),
            ExcelUtil.MyCell("个人认证", colSpan = 1),
            ExcelUtil.MyCell("认证人数", colSpan = 1),
            ExcelUtil.MyCell("认证角色", colSpan = 1),
            ExcelUtil.MyCell("承诺情况", colSpan = 1),
            ExcelUtil.MyCell("台账提交率", colSpan = 1),
            ExcelUtil.MyCell("必填台账提交率", colSpan = 1),
            ExcelUtil.MyCell("必填台账提交缺失情况", colSpan = 1),
            ExcelUtil.MyCell("必填台账不涉及情况", colSpan = 1),
            ExcelUtil.MyCell("自巡查提交率", colSpan = 1),
            ExcelUtil.MyCell("自巡查提交缺失情况", colSpan = 1),
            ExcelUtil.MyCell("自巡查不涉及情况", colSpan = 1),
            ExcelUtil.MyCell("自评情况", colSpan = 1),
            ExcelUtil.MyCell("自评分数", colSpan = 1),
            ExcelUtil.MyCell("自评风险等级", colSpan = 1),
            ExcelUtil.MyCell("线上监管风险", colSpan = 1),
            ExcelUtil.MyCell("监管执法建议", colSpan = 1),
        )
        heads.add(h1.toTypedArray())
        heads.add(h2.toTypedArray())
    }
 
    fun reset() {
        index = 1
        contents.clear()
    }
 
    /**
     * 生成一行excel数据
     */
    fun parseRow(
        u: Userinfo,
        r1: RiskLedger.Result,
        r2: RiskLedger.Result,
        r3: Triple<Boolean, Int?, String>,
        r4: RiskAuthenticated.Result,
        r5: Int,
        riskLevel: Int,
        summary: String,
    ) {
        val row = listOf<Any>(
            index.toDouble(),
            u.acountname ?: "",
            u.realname ?: "",
            if (u.isenable == true) "正常经营" else "关停",
            r4.baseInfo?.biAddress ?: "",
            r4.baseInfo?.biContact ?: "",
            r4.baseInfo?.biTelephone ?: "",
 
            if (r4.login) "已登录" else "未登录",
 
            // 认证
            if (r4.finished1) "已认证" else "未认证",
            if (r4.finished2) "已认证" else "未认证",
            r4.count,
            r4.type,
            // 守法承诺
            when (r5) {
                0 -> "未承诺"
                1 -> "已失效"
                else -> "有效"
            },
            // 台账规范性
            "${round(r1.rate1 * 10000) / 100}%",
            "${round(r1.rate2 * 10000) / 100}%",
            r1.unSubmitLedger,
            r1.notInvolvedLedger,
 
            "${round(r2.rate2 * 10000) / 100}%",
            r2.unSubmitLedger,
            r2.notInvolvedLedger,
 
            if (r3.first) "已自评" else "未自评",
            r3.second?.toDouble() ?: "/",
            r3.third,
 
            parseRisk(riskLevel),
            summary
        )
        contents.add(row.toTypedArray())
        index++
    }
 
    private fun parseRisk(riskLevel: Int) = when (riskLevel) {
        0->"低风险"
        1->"中风险"
        else->"高风险"
    }
 
    fun outPutToStream(out: OutputStream) {
        val workbook = HSSFWorkbook()
        ExcelUtil.write2(heads, contents, workbook)
        workbook.write(out)
        workbook.close()
        out.flush()
        out.close()
    }
 
    fun outPutToFile() {
        val area = if (config.areaName != null) "-" + config.areaName else ""
        val fileName = "综合风险评估-${config.district}-${sceneType}${area}-${config.year}年${config.month}月-" +
                "${DateUtil.DateToString(Date(), "yyyy-MM-dd-HHmmss")}.xls"
        val filePath = "C:\\work\\工作\\飞羽环境\\综合风险\\$fileName"
        val out = FileOutputStream(File(filePath))
        outPutToStream(out)
    }
}