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.*
|
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() {
|
val d = Date()
|
println(d.time)
|
d.time = 1666262747
|
println(d)
|
}
|
}
|