feiyu02
2024-08-15 196bb14112448857a885e32dc4149e308e00b01a
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
149
150
151
152
153
154
155
156
157
158
159
160
161
package cn.flightfeather.supervision
 
import cn.flightfeather.supervision.common.docimport.UserExcelRule
import cn.flightfeather.supervision.common.net.JinAnLianTongHttpService
import cn.flightfeather.supervision.common.nlp.NlpController
import cn.flightfeather.supervision.common.pdf.PdfUtil
import cn.flightfeather.supervision.infrastructure.utils.DateUtil
import cn.flightfeather.supervision.infrastructure.utils.FileUtil
import cn.flightfeather.supervision.websocket.MsgType
import cn.flightfeather.supervision.websocket.PersonalServerMsgVo
import cn.flightfeather.supervision.websocket.WebSocketMsg
import com.google.gson.Gson
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.codec.digest.Md5Crypt
import org.fit.pdfdom.PDFDomTreeConfig
import org.junit.Test
import org.springframework.boot.json.GsonJsonParser
import java.io.File
import java.io.FileInputStream
import java.time.Duration
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.*
import java.util.regex.Pattern
import kotlin.random.Random
import kotlin.random.nextInt
import kotlin.reflect.jvm.internal.impl.load.kotlin.JvmType
 
 
/**
 * @author riku
 * Date: 2019/11/15
 */
class CommonTest {
 
    @Test
    fun foo1() {
        val json  ="{\"msgType\": 1, \"msgVoList\": [{\"time\": 2019-11-12}, {\"time\": 2019-11-13}]}"
        val m = GsonJsonParser().parseMap(json)
    }
 
    @Test
    fun foo2() {
        val resultList = mutableListOf<String>()
        val text = "@所有人 请发言,@2www@com,"
        var i = 0
        while (i < text.length) {
            if (text[i] == '@') {
                if (i == 0 || (Pattern.matches("[^A-Za-z0-9]", text[i - 1].toString()))) {
                    var index = i + 1
                    while (index < text.length) {
                        //找到@ 开始,空格结束的字符串,即为@的用户名
                        if (text[index] == ' ') {
                            val user = text.substring(i + 1, index)
                            resultList.add(user)
                            i = index
                            break
                        }
                        index++
                    }
                }
            }
            i++
        }
        resultList.forEach {
            println(it)
        }
    }
 
    @Test
    fun foo3() {
        val msgVoList = listOf<PersonalServerMsgVo>(PersonalServerMsgVo("meetingId",
                mapOf(
                        Pair("id1", true),
                        Pair("id2", false)
                ),
                listOf(
                        "id1", "id2"
                )))
        val msg = WebSocketMsg<PersonalServerMsgVo>(MsgType.MsgPersonal.value, msgVoList)
        val text = Gson().toJson(msg)
        println(text)
    }
 
    @Test
    fun foo4() {
        val d = Date()
        println(d.time)
        d.time = 1666262747
        println(d)
    }
 
    @Test
    fun foo5() {
        val n = NlpController()
        n.execute("吃苹果")
    }
 
    @Test
    fun foo6() {
        repeat(20) {
            val r = Random.nextInt(100..999)
            println(r)
        }
    }
 
    @Test
    fun foo7() {
        var s = "2022/10-12"
        val list = s.split("-")
        val endM = list[1].toInt()
        val list2 = list[0].split("/")
        val year = list2[0].toInt()
        val startM = list2[1].toInt()
//        s = s.replace("/", "-")
        val st = LocalDateTime.of(year, startM, 1, 0, 0, 0, 0)
        val et = LocalDateTime.of(year, endM, 1, 0, 0, 0, 0).plusMonths(1)
        println(st)
        println(et)
    }
 
    @Test
    @Throws(Exception::class)
    open fun test_convert_pdf_to_html() {
        val config = PDFDomTreeConfig.createDefaultConfig()
        config.imageHandler = PDFDomTreeConfig.saveToDirectory(File("/target/res/"))
        config.fontHandler = config.imageHandler
        val html = PdfUtil.parseWithPdfDomTree(FileInputStream("C:\\work\\工作\\守法自主小程序\\汽修/2 大气污染物综合排放标准(DB31933—2015).pdf"), 0, 10, config)
//        FileUtils.write(File("/mnt/test.html"), htmlOutput, "utf-8")
        html?.toByteArray()?.let { FileUtil.uploadFile(it, "/target/", "test.html") }
    }
 
    @Test
    fun foo8() {
//        val now = Date().time / 1000
        val now = 1667870335
        val key = "${now}e6dc8bb9e1ff0ce973fb92b4af2e4c3f"
        val sign = DigestUtils.md5Hex(key)
        println(sign)
    }
 
    @Test
    fun foo10() {
        val clz = UserExcelRule::class.java
        val params = mutableListOf<Any>()
//        val u = clz.newInstance()
//        println(u)
        repeat(14) { params.add(it.toString()) }
        println(params)
//        val n = clz.constructors[0].newInstance("","","","","","","","","","","","","","")
        val n = clz.constructors[0].newInstance(*params.toTypedArray())
        println(n)
    }
 
    @Test
    fun foo11(){
        val s = DateUtil.getStartMonthByPeriod(5, 12)
        println(s)
    }
}