feiyu02
2025-07-31 6688232eaa889eeb6c58d0d804b587699db55ec2
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
package cn.flightfeather.supervision.business.location
 
import cn.flightfeather.supervision.common.utils.DateUtil
import cn.flightfeather.supervision.common.utils.ExcelUtil
import cn.flightfeather.supervision.domain.ds1.entity.Scense
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import java.io.File
import java.io.FileOutputStream
import java.util.*
 
class UtilFile(head: List<ExcelUtil.MyCell>? = null) {
 
    private val heads = mutableListOf<Array<Any>>()
    private val contents = mutableListOf<Array<Any>>()
    var index = 1
 
    init {
//        val h1 = listOf(
//            ExcelUtil.MyCell("汽修单位基本信息", colSpan = 6),
//            ExcelUtil.MyCell("守法帮扶微信小程序登录", colSpan = 1),
//            ExcelUtil.MyCell("汽修单位认证(单个企业允许多用户)", colSpan = 4),
//            ExcelUtil.MyCell("守法承诺", colSpan = 1),
//            ExcelUtil.MyCell("台账规范性", colSpan = 3),
//            ExcelUtil.MyCell("自巡查规范性", colSpan = 2),
//            ExcelUtil.MyCell("守法自测自评", colSpan = 3),
//            ExcelUtil.MyCell("线上监管综合风险分析与对策", colSpan = 3),
//        )
        val h2 = head ?: 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),
        )
//        heads.add(h1.toTypedArray())
        heads.add(h2.toTypedArray())
    }
 
    fun reset() {
        index = 1
        contents.clear()
    }
 
    fun addRow(row: List<Any>) {
        contents.add(row.toTypedArray())
    }
 
    fun updateLastRow(index: Int, cell: Any) {
        contents.last()[index] = cell
    }
 
    /**
     * 生成一行excel数据
     */
    fun parseRow(scense: Scense) {
        val row = listOf<Any>(
            "",
            index.toDouble(),
            scense.name ?: "",
            scense.type ?: "",
            scense.location ?: "",
            scense.longitude?.toDouble() ?: .0,
            scense.latitude?.toDouble() ?: .0,
            scense.districtname ?: "",
            scense.townname ?: "",
            scense.contacts ?: "",
            scense.contactst ?: ""
        )
        contents.add(row.toTypedArray())
        index++
    }
 
    fun outPutToFile(distance: Double? = null) {
        val workbook = HSSFWorkbook()
        val tag = if (distance == null) "" else  "${distance}米"
        val fileName = "周边${tag}点位-${DateUtil.DateToString(Date(), "yyyy-MM-ddhhmmss")}.xls"
        val filePath = "C:\\work\\工作\\第三方监管\\周边点位\\$fileName"
        val out = FileOutputStream(File(filePath))
        ExcelUtil.write(heads, contents, workbook)
        workbook.write(out)
        workbook.close()
        out.flush()
        out.close()
    }
}