src/main/kotlin/com/flightfeather/uav/common/config/CorsConfig.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,29 @@ package com.flightfeather.uav.common.config import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.web.cors.CorsConfiguration import org.springframework.web.cors.UrlBasedCorsConfigurationSource import org.springframework.web.filter.CorsFilter @Configuration class CorsConfig { private fun buildConfig(): CorsConfiguration { return CorsConfiguration().apply { addAllowedOrigin("*") addAllowedHeader("*") addAllowedMethod("*") allowCredentials = true } } @Bean fun corsFilter(): CorsFilter { val source = UrlBasedCorsConfigurationSource().apply { registerCorsConfiguration("/**", buildConfig()) } return CorsFilter(source) } } src/main/kotlin/com/flightfeather/uav/common/utils/FileUtil.kt
@@ -13,7 +13,7 @@ class FileUtil { private var file: File private var basePath:String = "${File.separator}ObdData${File.separator}" private var basePath:String = "${File.separator}UAVData${File.separator}" private var closeThread: Thread? = null private var fw: FileWriter? = null private var bw: BufferedWriter? = null src/main/kotlin/com/flightfeather/uav/common/utils/GsonUtils.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,85 @@ package com.flightfeather.uav.common.utils import com.google.gson.Gson import com.google.gson.JsonParser import java.util.ArrayList /** * @author riku * Date: 2019/4/28 * GSONåºååå·¥å ·ç±» */ object GsonUtils { fun getNoteJsonString(jsonString: String, note: String): String { if (jsonString.isEmpty()) { throw RuntimeException("getNoteJsonString jsonString empty") } if (note.isEmpty()) { throw RuntimeException("getNoteJsonString note empty") } val element = JsonParser().parse(jsonString) if (element.isJsonNull) { throw RuntimeException("getNoteJsonString element empty") } return element.asJsonObject.get(note).toString() } fun <T> parserJsonToArrayBeans(jsonString: String, note: String, beanClazz: Class<T>): List<T> { val noteJsonString = getNoteJsonString(jsonString, note) return parserJsonToArrayBeans(noteJsonString, beanClazz) } fun <T> parserJsonToArrayBeans(jsonString: String, beanClazz: Class<T>): List<T> { if (jsonString.isEmpty()) { throw RuntimeException("parserJsonToArrayBeans jsonString empty") } val jsonElement = JsonParser().parse(jsonString) if (jsonElement.isJsonNull) { throw RuntimeException("parserJsonToArrayBeans jsonElement empty") } if (!jsonElement.isJsonArray) { throw RuntimeException("parserJsonToArrayBeans jsonElement is not JsonArray") } val jsonArray = jsonElement.asJsonArray val beans = ArrayList<T>() for (jsonElement2 in jsonArray) { val bean = Gson().fromJson(jsonElement2, beanClazz) beans.add(bean) } return beans } fun <T> parserJsonToBean(jsonString: String, clazzBean: Class<T>): T { if (jsonString.isEmpty()) { throw RuntimeException("parserJsonToBean jsonString empty") } val jsonElement = JsonParser().parse(jsonString) if (jsonElement.isJsonNull) { throw RuntimeException("parserJsonToBean jsonElement empty") } if (!jsonElement.isJsonObject) { throw RuntimeException("parserJsonToBean is not object") } return Gson().fromJson(jsonElement, clazzBean) } fun <T> parserJsonToBean(jsonString: String, note: String, clazzBean: Class<T>): T { val noteJsonString = getNoteJsonString(jsonString, note) return parserJsonToBean(noteJsonString, clazzBean) } fun toJsonString(obj: Any?): String { return if (obj != null) { Gson().toJson(obj) } else { throw RuntimeException("obj could not be empty") } } } src/main/kotlin/com/flightfeather/uav/lightshare/bean/BaseJson.kt
ÎļþÒÑɾ³ý src/main/kotlin/com/flightfeather/uav/lightshare/bean/BaseResponse.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,34 @@ package com.flightfeather.uav.lightshare.bean import com.fasterxml.jackson.annotation.JsonInclude /** * @author riku * Date: 2020/10/9 * ç½ç»è¯·æ±è¿åæ°æ®åºç±» */ //"请æ±è¿ååºæ¬ç»æ" @JsonInclude(JsonInclude.Include.NON_NULL) data class BaseResponse<T>( var success: Boolean, var message: String = "", val head: DataHead? = null, val data: T? = null ){ init { if (message.isBlank()) { message = if (success) { "è¯·æ±æå" } else { "请æ±å¤±è´¥" } } } } //"å页信æ¯" data class DataHead( var page: Int = 1, var totalPage: Int = 1 ) src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,22 @@ package com.flightfeather.uav.lightshare.bean import com.fasterxml.jackson.annotation.JsonInclude import com.flightfeather.uav.socket.bean.AirData /** * @author riku * Date: 2020/9/10 */ @JsonInclude(JsonInclude.Include.NON_NULL) data class DataVo( //æ¶é´, yyyy-MM-dd HH:mm:ss var time: String? = null, //ç«ç¹ç¼å· var deviceCode: String? = null, //æ°æ®å¼ var values: List<AirData>? = null, //ç»åº¦ var lng: Double? = null, //纬度 var lat: Double? = null ) src/main/kotlin/com/flightfeather/uav/lightshare/bean/VehicleInfoVo.kt
ÎļþÒÑɾ³ý src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,9 @@ package com.flightfeather.uav.lightshare.service import com.flightfeather.uav.lightshare.bean.BaseResponse import com.flightfeather.uav.lightshare.bean.DataVo interface RealTimeDataService { fun getSecondData(deviceCode: String?, page: Int?, perPage: Int?): BaseResponse<List<DataVo>> } src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,40 @@ package com.flightfeather.uav.lightshare.service.impl import com.flightfeather.uav.common.utils.GsonUtils import com.flightfeather.uav.domain.entity.RealTimeData import com.flightfeather.uav.domain.mapper.RealTimeDataMapper import com.flightfeather.uav.lightshare.bean.BaseResponse import com.flightfeather.uav.lightshare.bean.DataHead import com.flightfeather.uav.lightshare.bean.DataVo import com.flightfeather.uav.lightshare.service.RealTimeDataService import com.flightfeather.uav.socket.bean.AirData import com.github.pagehelper.PageHelper import org.springframework.stereotype.Service import tk.mybatis.mapper.entity.Example import java.text.SimpleDateFormat @Service class RealTimeDataServiceImpl(val realTimeDataMapper: RealTimeDataMapper) : RealTimeDataService { override fun getSecondData(deviceCode: String?, page: Int?, perPage: Int?): BaseResponse<List<DataVo>> { val _perPage = perPage ?: 60 val _page = page ?: 1 val pageInfo = PageHelper.startPage<RealTimeData>(_page, _perPage) val result = mutableListOf<DataVo>() realTimeDataMapper.selectByExample(Example(RealTimeData::class.java).apply { createCriteria().apply { deviceCode?.let { andEqualTo("deviceCode", it) } } orderBy("dataTime").desc() }).forEach { result.add(DataVo( SimpleDateFormat.getDateTimeInstance().format(it.dataTime), it.deviceCode, GsonUtils.parserJsonToArrayBeans(it.factors, AirData::class.java), it.longitude.toDouble(), it.latitude.toDouble() )) } result.reverse() return BaseResponse(true, head = DataHead(pageInfo.pageNum, pageInfo.pages), data = result) } } src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,19 @@ package com.flightfeather.uav.lightshare.web import com.flightfeather.uav.lightshare.service.RealTimeDataService import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("air/realtime") class RealTimeDataController(val realTimeDataService: RealTimeDataService) { @GetMapping("/sec") fun getSecondData( @RequestParam(value = "deviceCode", required = false) deviceCode: String?, @RequestParam(value = "page", required = false) page: Int?, @RequestParam(value = "perPage", required = false) perPage: Int? ) = realTimeDataService.getSecondData(deviceCode,page, perPage) } src/main/kotlin/com/flightfeather/uav/repository/VehicleRepository.kt
ÎļþÒÑɾ³ý src/main/kotlin/com/flightfeather/uav/socket/MessageManager.kt
@@ -24,6 +24,8 @@ companion object{ private lateinit var instance: MessageManager private const val TAG = "UAV" } @Autowired @@ -46,10 +48,10 @@ if (bccCheck(msg)) { //ä¿å DeviceSession.saveDevice(packageData.deviceCode, ctx) // saveToTxt(msg) saveToTxt(msg) saveToDataBase(packageData) } else { println("------æ°æ®BCCæ ¡éªå¤±è´¥ï¼èå¼ [${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}]") println("------${TAG}æ°æ®BCCæ ¡éªå¤±è´¥ï¼èå¼ [${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}]") } } src/main/kotlin/com/flightfeather/uav/socket/ServerHandler.kt
@@ -10,16 +10,22 @@ class ServerHandler : ChannelInboundHandlerAdapter() { companion object { private const val TAG = "UAV" } val attributeKey = AttributeKey.valueOf<String>("deviceCode") override fun channelRegistered(ctx: ChannelHandlerContext?) { super.channelRegistered(ctx) println("------ç«¯å£æIPè¿æ¥ï¼[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") println() println("------${TAG}ç«¯å£æIPè¿æ¥ï¼[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") // ctx?.fireChannelActive() } override fun channelActive(ctx: ChannelHandlerContext?) { println("------ç«¯å£æIPæ¿æ´»ï¼[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") println() println("------${TAG}ç«¯å£æIPæ¿æ´»ï¼[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") super.channelActive(ctx) } @@ -29,7 +35,8 @@ val sb = StringBuilder() if (msg is ByteArray) { println("------æ¶å°çåå§æ°æ®ï¼[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") println() println("------${TAG}æ¶å°çåå§æ°æ®ï¼[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") msg.forEach { val a: Int = if (it < 0) { it + 256 @@ -58,7 +65,7 @@ } override fun channelInactive(ctx: ChannelHandlerContext?) { println("------ç«¯å£æIP䏿´»å¨ï¼[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") println("------${TAG}ç«¯å£æIP䏿´»å¨ï¼[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") super.channelInactive(ctx) } src/main/kotlin/com/flightfeather/uav/socket/bean/DataUnit.kt
@@ -11,5 +11,5 @@ * æ ¹æ®å½ä»¤åå @see [AirCommandUnit] çåç±»ï¼ä¸åç±»åçç»æä¸åï¼è§ååç±» */ open class DataUnit { var time: Date? = null } src/main/resources/application.yml
@@ -8,6 +8,11 @@ url: jdbc:mysql://114.215.109.124:3306/dronemonitor?serverTimezone=Asia/Shanghai&prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false username: root password: 123456 hikari: maximum-pool-size: 500 minimum-idle: 20 idle-timeout: 60000 connection-timeout: 60000 jmx: enabled: false src/test/kotlin/com/flightfeather/uav/Test.kt
@@ -1,10 +1,33 @@ package com.flightfeather.uav import org.junit.Test import java.text.SimpleDateFormat import java.util.* /** * @author riku * Date: 2019/9/12 */ class Test { @Test fun foo1() { val s = SimpleDateFormat.getDateTimeInstance().format(Date()) println(s) } @Test fun foo2() { val b = arrayOf("41", "79", "24", "04", "0B", "45") val i = 0 val valid = b[i].toInt(16).toChar()//ç»çº¬åº¦æ¯å¦ææï¼ææ: A; æ æ: Vï¼ val a1 = b[i + 1].toInt(16) val b1 = b[i + 2].toInt(16) var b2 = "${b[i + 3]}${b[i + 4]}".toInt(16).toDouble() while (b2 >= 1) { b2 /= 10 } val lng = a1 + (b1 + b2) / 60 val s = b[i + 5].toInt(16).toChar() } }