riku
2021-12-10 98d774555f6207ac07dbfb9c542b1b489839b827
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
package cn.flightfeather.supervision
 
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.junit.Test
import org.springframework.boot.json.GsonJsonParser
import java.util.regex.Pattern
 
/**
 * @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() {
 
    }
}