src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,70 @@ package com.flightfeather.uav.domain.entity import java.math.BigDecimal import java.util.* import javax.persistence.Column import javax.persistence.Id /** * 宿¶çæµæ°æ®åºç±» */ open class BaseRealTimeData { @Id var id: Int? = null @Column(name = "device_code") var deviceCode: String? = null var latitude: BigDecimal? = null var longitude: BigDecimal? = null var altitude: Float? = null @Column(name = "data_time") var dataTime: Date? = null @Column(name = "create_time") var createTime: Date? = null @Column(name = "NO2") var no2: Float? = null @Column(name = "CO") var co: Float? = null @Column(name = "H2S") var h2s: Float? = null @Column(name = "SO2") var so2: Float? = null @Column(name = "O3") var o3: Float? = null @Column(name = "PM25") var pm25: Float? = null @Column(name = "PM10") var pm10: Float? = null var temperature: Float? = null var humidity: Float? = null @Column(name = "VOC") var voc: Float? = null @Column(name = "NOI") var noi: Float? = null var velocity: Float? = null @Column(name = "wind_speed") var windSpeed: Float? = null @Column(name = "wind_direction") var windDirection: Float? = null var height: Float? = null } src/main/kotlin/com/flightfeather/uav/domain/entity/RealTimeDataGrid.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,9 @@ package com.flightfeather.uav.domain.entity; import java.math.BigDecimal; import java.util.Date; import javax.persistence.*; @Table(name = "real_time_data_grid") public class RealTimeDataGrid extends BaseRealTimeData { } src/main/kotlin/com/flightfeather/uav/domain/entity/RealTimeDataUav.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,9 @@ package com.flightfeather.uav.domain.entity; import java.math.BigDecimal; import java.util.Date; import javax.persistence.*; @Table(name = "real_time_data_uav") public class RealTimeDataUav extends BaseRealTimeData { } src/main/kotlin/com/flightfeather/uav/domain/entity/RealTimeDataVehicle.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,9 @@ package com.flightfeather.uav.domain.entity; import java.math.BigDecimal; import java.util.Date; import javax.persistence.*; @Table(name = "real_time_data_vehicle") public class RealTimeDataVehicle extends BaseRealTimeData { } src/main/kotlin/com/flightfeather/uav/domain/mapper/RealTimeDataGridMapper.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,8 @@ package com.flightfeather.uav.domain.mapper import com.flightfeather.uav.domain.MyMapper import com.flightfeather.uav.domain.entity.RealTimeDataGrid import org.apache.ibatis.annotations.Mapper @Mapper interface RealTimeDataGridMapper : MyMapper<RealTimeDataGrid?> src/main/kotlin/com/flightfeather/uav/domain/mapper/RealTimeDataUavMapper.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,8 @@ package com.flightfeather.uav.domain.mapper import com.flightfeather.uav.domain.MyMapper import com.flightfeather.uav.domain.entity.RealTimeDataUav import org.apache.ibatis.annotations.Mapper @Mapper interface RealTimeDataUavMapper : MyMapper<RealTimeDataUav?> src/main/kotlin/com/flightfeather/uav/domain/mapper/RealTimeDataVehicleMapper.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,8 @@ package com.flightfeather.uav.domain.mapper import com.flightfeather.uav.domain.MyMapper import com.flightfeather.uav.domain.entity.RealTimeDataVehicle import org.apache.ibatis.annotations.Mapper @Mapper interface RealTimeDataVehicleMapper : MyMapper<RealTimeDataVehicle?> src/main/kotlin/com/flightfeather/uav/repository/AirDataRepository.kt
@@ -1,5 +1,6 @@ package com.flightfeather.uav.repository import com.flightfeather.uav.domain.entity.RealTimeData import com.flightfeather.uav.socket.bean.AirDataPackage /** @@ -8,5 +9,16 @@ */ interface AirDataRepository { /** * åå§æ°æ®ä»¥jsonæ ¼å¼åå¨ */ fun saveAirData(dataPackage: AirDataPackage): Int /** * åå¨é¢å¤çåçæ°æ® */ fun savePrepData(dataPackage: AirDataPackage): Int fun savePrepData(dataList: List<RealTimeData>): Int } src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt
@@ -1,22 +1,33 @@ package com.flightfeather.uav.repository.impl import com.flightfeather.uav.domain.entity.RealTimeData import com.flightfeather.uav.common.utils.GsonUtils import com.flightfeather.uav.domain.MyMapper import com.flightfeather.uav.domain.entity.* import com.flightfeather.uav.domain.mapper.RealTimeDataGridMapper import com.flightfeather.uav.domain.mapper.RealTimeDataMapper import com.flightfeather.uav.domain.mapper.RealTimeDataUavMapper import com.flightfeather.uav.domain.mapper.RealTimeDataVehicleMapper import com.flightfeather.uav.lightshare.bean.DataVo import com.flightfeather.uav.repository.AirDataRepository import com.flightfeather.uav.socket.bean.AirData import com.flightfeather.uav.socket.bean.AirDataPackage import com.flightfeather.uav.socket.eunm.FactorType import com.flightfeather.uav.socket.eunm.UWDeviceType import com.google.gson.Gson import org.springframework.stereotype.Repository import java.text.SimpleDateFormat import java.util.* /** * @author riku * Date: 2020/6/11 */ @Repository class AirDataRepositoryImpl(private val realTimeDataMapper: RealTimeDataMapper): AirDataRepository { class AirDataRepositoryImpl( private val realTimeDataMapper: RealTimeDataMapper, private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper, private val realTimeDataUavMapper: RealTimeDataUavMapper, private val realTimeDataGridMapper: RealTimeDataGridMapper ): AirDataRepository { override fun saveAirData(dataPackage: AirDataPackage): Int { val data = RealTimeData().apply { @@ -45,10 +56,117 @@ } } } realTimeDataMapper.insert(data) return 0 } override fun savePrepData(dataPackage: AirDataPackage): Int { var mapper: MyMapper<out BaseRealTimeData?>? = null when (UWDeviceType.getType(dataPackage.deviceCode)) { UWDeviceType.VEHICLE -> { mapper = realTimeDataVehicleMapper RealTimeDataVehicle() } UWDeviceType.UAV -> { mapper = realTimeDataUavMapper RealTimeDataUav() } UWDeviceType.GRID -> { mapper = realTimeDataGridMapper RealTimeDataGrid() } else -> null }?.run { deviceCode = dataPackage.deviceCode dataPackage.dataUnit.forEach { if (it is AirData) { when (it.factorId?.toInt()) { FactorType.NO2.value -> no2 = it.factorData?.toFloat() FactorType.CO.value -> co = it.factorData?.toFloat() FactorType.H2S.value -> h2s = it.factorData?.toFloat() FactorType.SO2.value -> so2 = it.factorData?.toFloat() FactorType.O3.value -> o3 = it.factorData?.toFloat() FactorType.PM25.value -> pm25 = it.factorData?.toFloat() FactorType.PM10.value -> pm10 = it.factorData?.toFloat() FactorType.TEMPERATURE.value -> temperature = it.factorData?.toFloat() FactorType.HUMIDITY.value -> humidity = it.factorData?.toFloat() FactorType.VOC.value -> voc = it.factorData?.toFloat() FactorType.NOI.value -> noi = it.factorData?.toFloat() FactorType.VELOCITY.value -> velocity = it.factorData?.toFloat() FactorType.WIND_SPEED.value -> windSpeed = it.factorData?.toFloat() FactorType.WIND_DIRECTION.value -> windDirection = it.factorData?.toFloat() FactorType.HEIGHT.value -> height = it.factorData?.toFloat() FactorType.LAT.value -> latitude = it.factorData?.toBigDecimal() FactorType.LNG.value -> longitude = it.factorData?.toBigDecimal() FactorType.TIME.value -> it.statusList?.takeIf { l -> l.isNotEmpty() }?.get(0)?.let { d -> dataTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d) } } } } // mapper?.insert(this) return 1 } return 0 } override fun savePrepData(dataList: List<RealTimeData>): Int { var count = 0 dataList.forEach {vo -> when (UWDeviceType.getType(vo.deviceCode)) { UWDeviceType.VEHICLE -> { val d = RealTimeDataVehicle() dataTransform(vo, d) realTimeDataVehicleMapper.insert(d) count++ } UWDeviceType.UAV -> { val d = RealTimeDataUav() dataTransform(vo, d) realTimeDataUavMapper.insert(d) count++ } UWDeviceType.GRID -> { val d = RealTimeDataGrid() dataTransform(vo, d) realTimeDataGridMapper.insert(d) count++ } } } return count } private fun dataTransform(vo: RealTimeData, bean: BaseRealTimeData) { bean.apply { deviceCode = vo.deviceCode latitude = vo.latitude longitude = vo.longitude dataTime = vo.dataTime createTime = vo.createTime GsonUtils.parserJsonToArrayBeans(vo.factors, AirData::class.java).forEach { when (it.factorId?.toInt()) { FactorType.NO2.value -> no2 = it.factorData?.toFloat() FactorType.CO.value -> co = it.factorData?.toFloat() FactorType.H2S.value -> h2s = it.factorData?.toFloat() FactorType.SO2.value -> so2 = it.factorData?.toFloat() FactorType.O3.value -> o3 = it.factorData?.toFloat() FactorType.PM25.value -> pm25 = it.factorData?.toFloat() FactorType.PM10.value -> pm10 = it.factorData?.toFloat() FactorType.TEMPERATURE.value -> temperature = it.factorData?.toFloat() FactorType.HUMIDITY.value -> humidity = it.factorData?.toFloat() FactorType.VOC.value -> voc = it.factorData?.toFloat() FactorType.NOI.value -> noi = it.factorData?.toFloat() FactorType.VELOCITY.value -> velocity = it.factorData?.toFloat() FactorType.WIND_SPEED.value -> windSpeed = it.factorData?.toFloat() FactorType.WIND_DIRECTION.value -> windDirection = it.factorData?.toFloat() FactorType.HEIGHT.value -> height = it.factorData?.toFloat() } } } } } src/main/kotlin/com/flightfeather/uav/socket/DeviceSession.kt
@@ -14,13 +14,11 @@ companion object { private const val DEFAULT_DEVICE = "default_device" } private val deviceMap = ConcurrentHashMap<String, ChannelHandlerContext?>() private val deviceMap = ConcurrentHashMap<String?, ChannelHandlerContext?>() private val typeMap = ConcurrentHashMap<String, List<AirTypeData>>() fun saveDevice(deviceCode: String?, channel: ChannelHandlerContext?) { deviceCode?.let { deviceMap.put(deviceCode, channel) } deviceMap[deviceCode] = channel } fun getDevice(deviceCode: String?): ChannelHandlerContext? { src/main/kotlin/com/flightfeather/uav/socket/eunm/UWDeviceType.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,22 @@ package com.flightfeather.uav.socket.eunm /** * èµ°èªçæµè®¾å¤ç±»å */ enum class UWDeviceType(val value: String, val des: String) { UAV("0b", "æ 人æºè®¾å¤"), VEHICLE("0a", "车载设å¤"), GRID("0d", "ç½æ ¼å设å¤"); companion object { /** * æ ¹æ®è®¾å¤ç¼å·è·å设å¤ç±»å */ fun getType(deviceCode: String?): UWDeviceType? = when (deviceCode?.substring(0, 2)) { UAV.value -> UAV VEHICLE.value -> VEHICLE GRID.value -> GRID else -> null } } } src/main/kotlin/com/flightfeather/uav/socket/processor/UnderwayProcessor.kt
@@ -5,6 +5,7 @@ import com.flightfeather.uav.socket.decoder.AirDataDecoder import com.flightfeather.uav.socket.decoder.DataPackageDecoder import com.flightfeather.uav.socket.eunm.AirCommandUnit import com.flightfeather.uav.socket.eunm.UWDeviceType import io.netty.channel.ChannelHandlerContext import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component @@ -59,7 +60,10 @@ */ fun saveToDataBase(dataPackage: AirDataPackage) { when (dataPackage.commandUnit) { AirCommandUnit.AirData.value -> instance.airDataRepository.saveAirData(dataPackage) AirCommandUnit.AirData.value -> { // 以jsonæ ¼å¼åå¨åå§æ°æ® instance.airDataRepository.saveAirData(dataPackage) } } } src/main/resources/generator/generatorConfig.xml
@@ -50,6 +50,9 @@ <!-- <table tableName="el_minutevalue" domainObjectName="ElectricMinuteValue" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="el_company_device" domainObjectName="CompanyDevice" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="co_complaint" domainObjectName="Complaint" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <table tableName="co_assessment" domainObjectName="Assessment" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <!-- <table tableName="co_assessment" domainObjectName="Assessment" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <table tableName="real_time_data_grid" domainObjectName="RealTimeDataGrid" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="real_time_data_uav" domainObjectName="RealTimeDataUav" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="real_time_data_vehicle" domainObjectName="RealTimeDataVehicle" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> </context> </generatorConfiguration> src/main/resources/mapper/RealTimeDataGridMapper.xml
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,39 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.flightfeather.uav.domain.mapper.RealTimeDataGridMapper"> <resultMap id="BaseResultMap" type="com.flightfeather.uav.domain.entity.RealTimeDataGrid"> <!-- WARNING - @mbg.generated --> <id column="id" jdbcType="INTEGER" property="id" /> <result column="device_code" jdbcType="VARCHAR" property="deviceCode" /> <result column="latitude" jdbcType="DECIMAL" property="latitude" /> <result column="longitude" jdbcType="DECIMAL" property="longitude" /> <result column="altitude" jdbcType="REAL" property="altitude" /> <result column="data_time" jdbcType="TIMESTAMP" property="dataTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="NO2" jdbcType="REAL" property="no2" /> <result column="CO" jdbcType="REAL" property="co" /> <result column="H2S" jdbcType="REAL" property="h2s" /> <result column="SO2" jdbcType="REAL" property="so2" /> <result column="O3" jdbcType="REAL" property="o3" /> <result column="PM25" jdbcType="REAL" property="pm25" /> <result column="PM10" jdbcType="REAL" property="pm10" /> <result column="temperature" jdbcType="REAL" property="temperature" /> <result column="humidity" jdbcType="REAL" property="humidity" /> <result column="VOC" jdbcType="REAL" property="voc" /> <result column="NOI" jdbcType="REAL" property="noi" /> <result column="velocity" jdbcType="REAL" property="velocity" /> <result column="wind_speed" jdbcType="REAL" property="windSpeed" /> <result column="wind_direction" jdbcType="REAL" property="windDirection" /> <result column="height" jdbcType="REAL" property="height" /> </resultMap> <sql id="Base_Column_List"> <!-- WARNING - @mbg.generated --> id, device_code, latitude, longitude, altitude, data_time, create_time, NO2, CO, H2S, SO2, O3, PM25, PM10, temperature, humidity, VOC, NOI, velocity, wind_speed, wind_directon, height </sql> </mapper> src/main/resources/mapper/RealTimeDataUavMapper.xml
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,39 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.flightfeather.uav.domain.mapper.RealTimeDataUavMapper"> <resultMap id="BaseResultMap" type="com.flightfeather.uav.domain.entity.RealTimeDataUav"> <!-- WARNING - @mbg.generated --> <id column="id" jdbcType="INTEGER" property="id" /> <result column="device_code" jdbcType="VARCHAR" property="deviceCode" /> <result column="latitude" jdbcType="DECIMAL" property="latitude" /> <result column="longitude" jdbcType="DECIMAL" property="longitude" /> <result column="altitude" jdbcType="REAL" property="altitude" /> <result column="data_time" jdbcType="TIMESTAMP" property="dataTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="NO2" jdbcType="REAL" property="no2" /> <result column="CO" jdbcType="REAL" property="co" /> <result column="H2S" jdbcType="REAL" property="h2s" /> <result column="SO2" jdbcType="REAL" property="so2" /> <result column="O3" jdbcType="REAL" property="o3" /> <result column="PM25" jdbcType="REAL" property="pm25" /> <result column="PM10" jdbcType="REAL" property="pm10" /> <result column="temperature" jdbcType="REAL" property="temperature" /> <result column="humidity" jdbcType="REAL" property="humidity" /> <result column="VOC" jdbcType="REAL" property="voc" /> <result column="NOI" jdbcType="REAL" property="noi" /> <result column="velocity" jdbcType="REAL" property="velocity" /> <result column="wind_speed" jdbcType="REAL" property="windSpeed" /> <result column="wind_direction" jdbcType="REAL" property="windDirection" /> <result column="height" jdbcType="REAL" property="height" /> </resultMap> <sql id="Base_Column_List"> <!-- WARNING - @mbg.generated --> id, device_code, latitude, longitude, altitude, data_time, create_time, NO2, CO, H2S, SO2, O3, PM25, PM10, temperature, humidity, VOC, NOI, velocity, wind_speed, wind_directon, height </sql> </mapper> src/main/resources/mapper/RealTimeDataVehicleMapper.xml
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,39 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.flightfeather.uav.domain.mapper.RealTimeDataVehicleMapper"> <resultMap id="BaseResultMap" type="com.flightfeather.uav.domain.entity.RealTimeDataVehicle"> <!-- WARNING - @mbg.generated --> <id column="id" jdbcType="INTEGER" property="id" /> <result column="device_code" jdbcType="VARCHAR" property="deviceCode" /> <result column="latitude" jdbcType="DECIMAL" property="latitude" /> <result column="longitude" jdbcType="DECIMAL" property="longitude" /> <result column="altitude" jdbcType="REAL" property="altitude" /> <result column="data_time" jdbcType="TIMESTAMP" property="dataTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="NO2" jdbcType="REAL" property="no2" /> <result column="CO" jdbcType="REAL" property="co" /> <result column="H2S" jdbcType="REAL" property="h2s" /> <result column="SO2" jdbcType="REAL" property="so2" /> <result column="O3" jdbcType="REAL" property="o3" /> <result column="PM25" jdbcType="REAL" property="pm25" /> <result column="PM10" jdbcType="REAL" property="pm10" /> <result column="temperature" jdbcType="REAL" property="temperature" /> <result column="humidity" jdbcType="REAL" property="humidity" /> <result column="VOC" jdbcType="REAL" property="voc" /> <result column="NOI" jdbcType="REAL" property="noi" /> <result column="velocity" jdbcType="REAL" property="velocity" /> <result column="wind_speed" jdbcType="REAL" property="windSpeed" /> <result column="wind_direction" jdbcType="REAL" property="windDirection" /> <result column="height" jdbcType="REAL" property="height" /> </resultMap> <sql id="Base_Column_List"> <!-- WARNING - @mbg.generated --> id, device_code, latitude, longitude, altitude, data_time, create_time, NO2, CO, H2S, SO2, O3, PM25, PM10, temperature, humidity, VOC, NOI, velocity, wind_speed, wind_directon, height </sql> </mapper>