feiyu02
2024-07-05 b2e89ca1b11f33417f3e83223c4aa188186c8155
1. 新增走航报告自动道路识别模块
已修改6个文件
已删除1个文件
338 ■■■■■ 文件已修改
pom.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/common/net/HttpMethod.kt 86 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/common/net/SkipCertificateValidation.kt 150 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/domain/repository/SegmentInfoRep.kt 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -211,11 +211,11 @@
            <artifactId>jfreechart</artifactId>
            <version>1.5.3</version>
        </dependency>
        <!-- Httpclient-->
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.0</version>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.5.14</version>
        </dependency>
    </dependencies>
src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt
@@ -42,7 +42,11 @@
                avgGPS.add(d.longitude!!.toDouble() to d.latitude!!.toDouble())
            }
        }
        val gdGPS = AMapService.coordinateConvert(avgGPS)
        val gdGPS = mutableListOf<Pair<Double, Double>>()
        val _avgGPS = prepareForConvert(avgGPS)
        _avgGPS.forEach {
            gdGPS.addAll(AMapService.coordinateConvert(it))
        }
        // é€šè¿‡é«˜å¾·API查询坐标对应的路段
        val segmentInfoList = mutableListOf<SegmentInfo>()
        gdGPS.forEachIndexed { i, pair ->
@@ -62,6 +66,49 @@
            })
        }
        // ç»“果入库
        segmentInfoRep.insert(segmentInfoList)
        saveResult(segmentInfoList)
    }
    /**
     * åæ ‡è½¬æ¢åˆ†æ®µå‡†å¤‡
     * é«˜å¾·API的坐标转换接口一次访问最多支持40对坐标
     */
    private fun prepareForConvert(gpsList: List<Pair<Double, Double>>): List<List<Pair<Double, Double>>> {
        val res = mutableListOf<List<Pair<Double, Double>>>()
        val maxLen = 40
        var start = 0
        var end = start + maxLen
        while (end < gpsList.size) {
            res.add(gpsList.subList(start, end))
            start += maxLen
            end += maxLen
        }
        if (start < gpsList.size) {
            res.add(gpsList.subList(start, gpsList.size))
        }
        return res
    }
    /**
     * ç»“果入库
     * å…¥åº“之前,将连续并属于同一道路的记录合并
     */
    private fun saveResult(segmentInfoList:List<SegmentInfo>) {
        val res = mutableListOf<SegmentInfo>()
        segmentInfoList.forEach { s ->
            // åˆ¤æ–­å½“前记录和上个记录是否数据同一条道路
            if (res.isNotEmpty()) {
                val lastOne = res.last()
                // è‹¥å±žäºŽåŒä¸€é“路,合并
                if (lastOne.street == s.street) {
                    lastOne.endTime = s.endTime
                } else {
                    res.add(s)
                }
            } else {
                res.add(s)
            }
        }
        segmentInfoRep.insert(res)
    }
}
src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt
@@ -5,6 +5,8 @@
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import org.apache.http.util.EntityUtils
import java.net.URLEncoder
import java.nio.charset.Charset
/**
@@ -13,7 +15,7 @@
object AMapService {
    private const val TAG = "AMapService"
    private const val KEY = "520c5e5cf44c7793104e500cbf0ed711"
    private const val KEY = "b36a93bac8950d3d7c6c06f21133de51"
    private val httpMethod = HttpMethod("restapi.amap.com", 443, true)
@@ -64,9 +66,10 @@
     * @param coordsys åŽŸåæ ‡ç³»ï¼Œå¯é€‰å€¼ï¼šgps;mapbar;baidu;autonavi(不进行转换)
     */
    fun coordinateConvert(locations: List<Pair<Double, Double>>, coordsys:String="gps"): List<Pair<Double, Double>> {
        val locationsStr = URLEncoder.encode(locations.joinToString("|") { "${it.first},${it.second}" }, "UTF-8")
        val res = httpMethod.get("/v3/assistant/coordinate/convert", listOf(
            "key" to KEY,
            "locations" to locations.joinToString("|") { "${it.first},${it.second}" },
            "locations" to locationsStr,
            "coordsys" to coordsys
        ))
        val obj = handleRes(res)
@@ -82,16 +85,11 @@
    private fun handleRes(res: HttpMethod.MyResponse):JsonObject {
        if (res.success) {
//            val str = if (res.m.responseCharSet == "utf-8") {
//                res.m.responseBodyAsString
//            } else {
//                String(res.m.responseBody, Charset.forName("utf-8"))
//            }
            val str = res.m.responseBodyAsString
            val str = EntityUtils.toString(res.m.entity)
            val json = JsonParser.parseString(str)
            return resCheck(json)
        } else {
            throw BizException("高德API网路链接错误,状态码:${res.m.statusCode}")
            throw BizException("高德API网路链接错误,状态码:${res.m.statusLine.statusCode}")
        }
    }
src/main/kotlin/com/flightfeather/uav/common/net/HttpMethod.kt
@@ -1,41 +1,33 @@
package com.flightfeather.uav.common.net
import org.apache.commons.httpclient.HttpClient
import org.apache.commons.httpclient.HttpMethodBase
import org.apache.commons.httpclient.methods.GetMethod
import org.apache.commons.httpclient.methods.PostMethod
import org.apache.commons.httpclient.methods.StringRequestEntity
import org.apache.commons.httpclient.protocol.Protocol
import org.slf4j.LoggerFactory
import org.apache.http.HttpEntity
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.methods.HttpGet
import org.apache.http.client.methods.HttpPost
import org.apache.http.client.methods.HttpRequestBase
import org.apache.http.entity.ContentType
import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.HttpClients
/**
 * @author riku
 * Date: 2020/10/14
 */
class HttpMethod(
        private val host: String, private val port: Int, private val isHttps: Boolean = false
    private val host: String, private val port: Int, private val isHttps: Boolean = false,
) {
    private val logger = LoggerFactory.getLogger(HttpMethod::class.java)
    data class MyResponse(
        val success: Boolean,
        val m: HttpMethodBase,
        val m: CloseableHttpResponse,
    )
    object Head {
        val TEXT_PLAIN = Pair("Content-Type", "text/plain")
    }
    private val httpClient = HttpClient()
    init {
        Protocol.registerProtocol("https", Protocol("https", SkipCertificateValidation.MySecureProtocolSocketFactory(), port))
        if (isHttps) {
            httpClient.hostConfiguration.setHost(host, port, Protocol.getProtocol("https"))
        } else {
            httpClient.hostConfiguration.setHost(host, port)
        }
    }
    private val httpClient = HttpClients.createDefault()
    private val baseUrl = "${if (isHttps) "https" else "http"}://${host}:${port}"
    fun get(url: String, params: List<Pair<String, String>> = emptyList(), headers: List<Pair<String, String>> = emptyList()): MyResponse {
        var p: String = ""
@@ -46,46 +38,58 @@
                "&" + it.first + "=" + it.second
            }
        }
        val getMethod = GetMethod("$url?$p")
        val getMethod = HttpGet("$baseUrl$url?$p")
        defaultConfig(getMethod)
        headers.forEach {
            getMethod.setRequestHeader(it.first, it.second)
            getMethod.addHeader(it.first, it.second)
        }
        return when (httpClient.executeMethod(getMethod)) {
            200 -> MyResponse(true, getMethod)
            else -> MyResponse(false, getMethod)
        val res = httpClient.execute(getMethod)
        return when (res.statusLine.statusCode) {
            200 -> MyResponse(true, res)
            else -> MyResponse(false, res)
        }
    }
    fun post(url: String, data: String = "", headers: List<Pair<String, String>> = emptyList()): MyResponse {
        val postMethod = PostMethod(url)
        val postMethod = HttpPost(baseUrl + url)
        defaultConfig(postMethod)
        headers.forEach {
            postMethod.setRequestHeader(it.first, it.second)
            postMethod.setHeader(it.first, it.second)
        }
        if (data.isNotBlank()) {
            postMethod.requestEntity = StringRequestEntity(data, "application/json", "utf-8")
            postMethod.entity = StringEntity(data, ContentType.APPLICATION_JSON)
        }
        return try {
            when (httpClient.executeMethod(postMethod)) {
                200 -> MyResponse(true, postMethod)
                else -> MyResponse(false, postMethod)
            }
        } catch (e: Exception) {
            logger.error(e.message)
            MyResponse(false, postMethod)
        val res = httpClient.execute(postMethod)
        return when (res.statusLine.statusCode) {
            200 -> MyResponse(true, res)
            else -> MyResponse(false, res)
        }
    }
    private fun defaultConfig(method: HttpMethodBase) {
        method.setRequestHeader("Accept", "*/*");
        method.setRequestHeader("Connection", "Keep-Alive");
    fun post(url: String, entity: HttpEntity, headers: List<Pair<String, String>> = emptyList()):
            MyResponse {
        val postMethod = HttpPost(baseUrl + url)
        headers.forEach {
            postMethod.addHeader(it.first, it.second)
        }
        postMethod.entity = entity
        val res = httpClient.execute(postMethod)
        return when (res.statusLine.statusCode) {
            200 -> MyResponse(true, res)
            else -> MyResponse(false, res)
        }
    }
    private fun defaultConfig(method: HttpRequestBase) {
        method.addHeader("Accept", "*/*");
        method.addHeader("Connection", "Keep-Alive");
//        method.setRequestHeader("Accept-Language", "zh-cn,zh;q=0.5");
        method.setRequestHeader("Accept-Encoding", "gzip,deflate,br");
        method.addHeader("Accept-Encoding", "gzip,deflate,br");
//        method.setRequestHeader("Content-Type", "application/json;charset=utf-8")
        method.setRequestHeader("Content-Type", "application/json")
        method.addHeader("Content-Type", "application/json")
//        method.setRequestHeader("Content-Type", "application/json;charset=GBK")
    }
src/main/kotlin/com/flightfeather/uav/common/net/SkipCertificateValidation.kt
ÎļþÒÑɾ³ý
src/main/kotlin/com/flightfeather/uav/domain/repository/SegmentInfoRep.kt
@@ -15,4 +15,8 @@
    fun insert(list: List<SegmentInfo>):Int {
        return segmentInfoMapper.insertList(list)
    }
    fun findList(segmentInfo: SegmentInfo): List<SegmentInfo?> {
        return segmentInfoMapper.select(segmentInfo)
    }
}
src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt
@@ -11,6 +11,7 @@
import com.flightfeather.uav.domain.mapper.*
import com.flightfeather.uav.domain.repository.MissionRep
import com.flightfeather.uav.domain.repository.RealTimeDataRep
import com.flightfeather.uav.domain.repository.SegmentInfoRep
import com.flightfeather.uav.lightshare.bean.*
import com.flightfeather.uav.lightshare.service.RealTimeDataService
import com.flightfeather.uav.model.epw.EPWDataPrep
@@ -45,6 +46,7 @@
    private val missionMapper: MissionMapper,
    private val missionRep: MissionRep,
    private val realTimeDataRep: RealTimeDataRep,
    private val segmentInfoRep: SegmentInfoRep,
) : RealTimeDataService {
    @Value("\${filePath}")
@@ -189,7 +191,26 @@
    override fun getSegmentData(missionCode: String): List<List<DataVo>> {
        val mission = missionRep.findOne(missionCode) ?: throw BizException("任务不存在")
        val data = realTimeDataRep.fetchData(mission)
        return TrackSegment.segmentWithRoad(data).map { it.map { b -> b.toDataVo() } }
        val segInfo = SegmentInfo().apply { this.missionCode = missionCode }
        val segList = segmentInfoRep.findList(segInfo)
//        return TrackSegment.segmentWithRoad(data).map { it.map { b -> b.toDataVo() } }
        val res = mutableListOf<MutableList<DataVo>>()
        res.add(mutableListOf())
        var index = 0
        data.forEach {
            if (it.dataTime == null) return@forEach
            if (it.dataTime!! <= segList[index]?.endTime) {
                res[index].add(it.toDataVo())
                if (it.dataTime!! == segList[index]?.endTime) {
                    index++
                    res.add(mutableListOf())
                }
            }
        }
        // ç§»é™¤æœ€åŽä¸€ä¸ªç©ºé›†åˆ
        if (res.last().isEmpty()) res.removeLast()
        return res
    }
    override fun importData(file: MultipartFile): BaseResponse<DataImportResult> {