package com.flightfeather.obd.socket
|
|
import com.flightfeather.obd.lightshare.bean.BaseJson
|
import com.flightfeather.obd.lightshare.bean.ObdDataVo
|
import com.flightfeather.obd.repository.ObdDataRepository
|
import com.google.gson.Gson
|
import io.netty.channel.ChannelHandlerContext
|
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.stereotype.Component
|
import javax.annotation.PostConstruct
|
import javax.annotation.Resource
|
|
/**
|
* 处理socket接收的消息
|
* Date: 2019.8.27
|
* @author riku
|
*/
|
|
@Component
|
class MessageManager{
|
|
companion object{
|
private lateinit var instance: MessageManager
|
}
|
|
@Autowired
|
lateinit var obdDataRepository: ObdDataRepository
|
|
@PostConstruct
|
fun init() {
|
instance = this
|
instance.obdDataRepository = this.obdDataRepository
|
}
|
|
fun dealMsg(msg: String, ctx: ChannelHandlerContext?) {
|
try {
|
val baseJson = Gson().fromJson<BaseJson>(msg, BaseJson::class.java)
|
when (baseJson.cmdCode) {
|
2001 -> {
|
val data = Gson().fromJson(msg, ObdDataVo::class.java)
|
DeviceSession.saveDevice(data.obdVin, ctx)
|
instance.obdDataRepository.saveObdData(data)
|
}
|
}
|
} catch (e: Throwable) {
|
// println("------收到格式错误的数据:$msg")
|
}
|
}
|
}
|