From 49832a5bba94c816e83e7e74095106643f0a433e Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 16 十二月 2021 13:24:28 +0800
Subject: [PATCH] 1. 用电量日分析 2. 网格权重污染分析

---
 src/main/kotlin/com/flightfeather/uav/model/NoTag.kt                                     |    5 
 src/main/kotlin/com/flightfeather/uav/lightshare/bean/ElectricDailyInfo.kt               |   14 +-
 src/main/kotlin/com/flightfeather/uav/model/BaseSOP.kt                                   |   16 ++
 src/main/kotlin/com/flightfeather/uav/lightshare/bean/CompanySOP.kt                      |   12 -
 src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt                            |   27 +++
 src/main/kotlin/com/flightfeather/uav/lightshare/service/EPWModelService.kt              |   16 ++
 src/main/kotlin/com/flightfeather/uav/lightshare/web/EPWModelController.kt               |   22 +++
 src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt                              |   10 
 src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImplTest.kt |   24 +++
 src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt                         |    5 
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt  |    6 
 src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt                         |    5 
 src/main/kotlin/com/flightfeather/uav/common/Contanst.kt                                 |    6 
 src/main/kotlin/com/flightfeather/uav/lightshare/bean/GridVo.kt                          |   22 +++
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImpl.kt     |  141 ++++++++++++++++++++
 src/main/kotlin/com/flightfeather/uav/model/epw/TimeSection.kt                           |    9 
 src/main/kotlin/com/flightfeather/uav/lightshare/web/DeviceInfoController.kt             |    2 
 src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt                                 |   14 +-
 src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt                           |    5 
 src/main/kotlin/com/flightfeather/uav/model/epw/EPWGridModel.kt                          |   28 ++++
 src/main/kotlin/com/flightfeather/uav/model/epw/NoSection.kt                             |   19 ++
 21 files changed, 361 insertions(+), 47 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/common/Contanst.kt b/src/main/kotlin/com/flightfeather/uav/common/Contanst.kt
index 8db1652..2e7c844 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/Contanst.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/Contanst.kt
@@ -37,4 +37,8 @@
     put(21, listOf(1.460621712f, 1.131760740f, 1.121104299f, 1.088876154f, 0.827697109f, 1.0f, 1.0f, 1.015988031f))
     put(22, listOf(1.357157189f, 1.155444400f, 1.184586476f, 1.085940877f, 0.841801847f, 1.0f, 1.0f, 1.018320115f))
     put(23, listOf(1.312873355f, 1.191067031f, 1.189618093f, 1.106982786f, 0.848180982f, 1.0f, 1.0f, 1.019044077f))
-}
\ No newline at end of file
+}
+
+//缃戞牸鍖栫洃娴嬭澶囩粡绾害锛坓ps锛�
+const val GridLng = 121.235813
+const val GridLat = 30.835898
diff --git a/src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt b/src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt
new file mode 100644
index 0000000..f45b316
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/common/utils/MapUtil.kt
@@ -0,0 +1,27 @@
+package com.flightfeather.uav.common.utils
+
+import kotlin.math.PI
+import kotlin.math.cos
+import kotlin.math.sin
+
+object MapUtil {
+
+    private const val Ea = 6378137 //璧ら亾鍗婂緞
+    private const val Eb = 6356725 //鏋佸崐寰�
+
+    /**
+     * 鏍规嵁鍧愭爣鐐广�佽窛绂诲拰瑙掑害锛岃幏鍙栧彟涓�涓潗鏍�
+     * @param pos 鍧愭爣鐐�(GPS绯�)
+     * @param len 璺濈锛堢背锛�
+     * @param radian 寮у害
+     */
+    fun getPointByLen(pos: Pair<Double, Double>, len: Double, radian: Double): Pair<Double, Double> {
+        val dx = len * sin(radian)
+        val dy = len * cos(radian)
+        val ec = Eb + (Ea - Eb) * (90.0 - pos.second) / 90.0
+        val ed = ec * cos(pos.second * PI / 180)
+        val lng = (dx / ed + pos.first * PI / 180.0) * 180.0 / PI
+        val lat = (dy / ec + pos.second * PI / 180.0) * 180.0 / PI
+        return Pair(lng, lat)
+    }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/CompanySOP.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/CompanySOP.kt
index 46329d7..68c9158 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/CompanySOP.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/CompanySOP.kt
@@ -82,18 +82,6 @@
     var ciAddress: String? = null
 
     /**
-     * 涓績缁忓害
-     */
-
-    var ciLongitude: BigDecimal? = null
-
-    /**
-     * 涓績绾害
-     */
-
-    var ciLatitude: BigDecimal? = null
-
-    /**
      * 缁勭粐鏈烘瀯浠g爜
      */
 
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/ElectricDailyInfo.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/ElectricDailyInfo.kt
index 57d8442..cf868ae 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/ElectricDailyInfo.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/ElectricDailyInfo.kt
@@ -30,13 +30,13 @@
     private var pfRunTime: Int = 0
     private var pfRunPeriod = mutableListOf<Int>()
 
-    private var rTimeDiff:Int = 0 //姝e紡杩愯鏃堕棿宸�
-    private var sResult:Boolean = false //璁惧寮�鍚槸鍚﹀悎瑙�
-    private var eTimeDiff: Int = 0 //鍏抽棴鏃堕棿宸�
-    private var eResult: Boolean = false //璁惧鍏抽棴鏄惁鍚堣
-    private var runningTimeDiff = 0 //杩愯鏃堕暱宸�
-    private var rResult:Boolean = false //杩愯杩囩▼鏄惁鍚堣
-    private var dailyResult: String = ""// 褰撴棩鍒嗘瀽缁撴灉鎻忚堪
+    var rTimeDiff:Int = 0 //姝e紡杩愯鏃堕棿宸�
+    var sResult:Boolean = false //璁惧寮�鍚槸鍚﹀悎瑙�
+    var eTimeDiff: Int = 0 //鍏抽棴鏃堕棿宸�
+    var eResult: Boolean = false //璁惧鍏抽棴鏄惁鍚堣
+    var runningTimeDiff = 0 //杩愯鏃堕暱宸�
+    var rResult:Boolean = false //杩愯杩囩▼鏄惁鍚堣
+    var dailyResult: String = ""// 褰撴棩鍒嗘瀽缁撴灉鎻忚堪
 
     // 褰撳墠璁惧绫诲瀷锛岀敤浜庢彃鍏ユ暟鎹椂鍐冲畾璧嬪�煎瓧娈�
     private var deviceType: ElectricityType = ElectricityType.ProductionLine
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/GridVo.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/GridVo.kt
new file mode 100644
index 0000000..bd63b47
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/GridVo.kt
@@ -0,0 +1,22 @@
+package com.flightfeather.uav.lightshare.bean
+
+import com.flightfeather.uav.model.BaseModel
+import com.flightfeather.uav.model.BaseSOP
+
+/**
+ * 椋庨櫓鍒嗘瀽缃戞牸瀵硅薄
+ * Date: 2021/12/8
+ */
+class GridVo(sourceName: String) : BaseSOP("", sourceName, "") {
+    // 宸︿笅鍧愭爣
+    var lb: Pair<Double, Double>? = null
+
+    // 鍙充笂鍧愭爣
+    var rt: Pair<Double, Double>? = null
+
+    // 鏉冮噸缁撴灉<鐩戞祴鍥犲瓙, 鏉冮噸缁撴灉>
+    var result = mutableMapOf<String, Double>()
+
+    // 鐩稿褰卞搷绛夌骇锛�0锛氬奖鍝嶆渶澶э紙鍓�33%锛夛紱1锛氬奖鍝嶉�備腑锛堜腑闂�33%锛夛紱2锛氬奖鍝嶈交寰紙鏈�鍚�33%锛�
+    var level = mutableMapOf<String, Int>()
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/EPWModelService.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/EPWModelService.kt
new file mode 100644
index 0000000..f05de7c
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/EPWModelService.kt
@@ -0,0 +1,16 @@
+package com.flightfeather.uav.lightshare.service
+
+import com.flightfeather.uav.lightshare.bean.BaseResponse
+import com.flightfeather.uav.lightshare.bean.GridVo
+import com.flightfeather.uav.socket.eunm.UWDeviceType
+
+interface EPWModelService {
+
+    /**
+     * 缃戞牸鍒嗘瀽鍒嗘瀽
+     * @param type 鏁版嵁婧愮被鍨� @see [UWDeviceType], 0a,0b,0c,0d
+     * @param len 缃戞牸闀垮害
+     */
+    fun getEpwModelResult(deviceCode: String, startTime: String, endTime: String, len: Double): BaseResponse<List<GridVo>>
+
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImpl.kt
new file mode 100644
index 0000000..e18a148
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImpl.kt
@@ -0,0 +1,141 @@
+package com.flightfeather.uav.lightshare.service.impl
+
+import com.flightfeather.uav.common.GridLat
+import com.flightfeather.uav.common.GridLng
+import com.flightfeather.uav.common.utils.MapUtil
+import com.flightfeather.uav.lightshare.bean.BaseResponse
+import com.flightfeather.uav.lightshare.bean.GridVo
+import com.flightfeather.uav.lightshare.service.EPWModelService
+import com.flightfeather.uav.lightshare.service.RealTimeDataService
+import com.flightfeather.uav.model.epw.EPWGridModel
+import com.flightfeather.uav.model.epw.EPWModel
+import com.flightfeather.uav.socket.eunm.UWDeviceType
+import org.springframework.stereotype.Service
+import kotlin.math.PI
+
+@Service
+class EPWModelServiceImpl(
+    private val realTimeDataService: RealTimeDataService,
+) : EPWModelService {
+
+    val epwModel = EPWGridModel()
+
+    override fun getEpwModelResult(deviceCode: String, startTime: String, endTime: String, len: Double): BaseResponse<List<GridVo>> {
+        if (deviceCode.length < 2) return BaseResponse(false, "璁惧缂栧彿鏍煎紡閿欒")
+        val type = deviceCode.substring(0, 2)
+        // 纭畾鏁版嵁婧愮被鍨嬶紝鍖哄垎涓衡�樺畾鐐圭洃娴嬫暟鎹�欏拰鈥樼Щ鍔ㄧ洃娴嬫暟鎹袱绉嶁��
+        val gridType = when (type) {
+            UWDeviceType.UAV.value -> '0'
+            UWDeviceType.VEHICLE.value -> '0'
+            UWDeviceType.GRID.value -> '1'
+            UWDeviceType.BOAT.value -> 'f'
+            else -> 'f'
+        }
+        if (gridType == 'f') return BaseResponse(false)
+
+        val points = mutableListOf<GridVo>()
+        // 鏍规嵁涓嶅悓绫诲瀷锛岀‘瀹氫笉鍚岀殑缃戞牸鐢熸垚鏂瑰紡锛屽緱鍑虹綉鏍间腑蹇冪偣闆嗗悎(缃戞牸榛樿閲囩敤姝f柟褰�)
+        // 璧拌埅鐩戞祴
+        if (gridType == '0') {
+            // TODO: 2021/12/6 璧拌埅鐩戞祴缃戞牸鐐圭敓鎴�
+        }
+        // 瀹氱偣鐩戞祴
+        else if (gridType == '1') {
+            // FIXME: 2021/12/6 姝ゅ涓轰簡娴嬭瘯鏆傛椂灏嗙珯鐐圭粡绾害鍐欐锛屽悗缁�氳繃鏁版嵁搴撻厤缃幏鍙�
+            val center = Pair(121.235813, 30.835898)
+            // a.纭畾缃戞牸闀垮害瀵瑰簲鐨勫潗鏍囧樊鍊�
+            val p1 = MapUtil.getPointByLen(center, len, PI / 2)//姝d笢鏂瑰悜锛�90掳锛夌殑鍧愭爣鐐�
+            val p2 = MapUtil.getPointByLen(center, len, PI)//姝e崡鏂瑰悜锛�180掳锛夌殑鍧愭爣鐐�
+            val dx = p1.first - center.first
+            val dy = center.second - p2.second
+            // b.纭畾鍗曡竟鏈夊灏戜釜缃戞牸(瑙勫畾鐩戞祴鐐瑰湪涓績缃戞牸鐨勪腑鐐逛笂锛屽洜姝ゅ崟杈圭綉鏍兼暟涓�瀹氫负濂囨暟)
+            val totalLen = 2000 // 缃戞牸鑼冨洿锛岃竟闀夸负20鍗冪背鐨勬鏂瑰舰
+            val gridNum = ((totalLen / 2 / len).toInt() - 1) * 2 + 1
+            // c.纭畾宸︿笂瑙掔綉鏍煎乏涓嬪拰鍙充笂鐨勪袱涓瑙掔偣鍧愭爣
+            //涓績鐐瑰潗鏍�
+            val g1CenterLng = center.first - (gridNum - 1) / 2 * dx//缁忓害鍑忓皬
+            val g1CenterLat = center.second + (gridNum - 1) / 2 * dy//绾害澧炲姞
+            //宸︿笅鍧愭爣
+            val g1LB = Pair(g1CenterLng - dx / 2, g1CenterLat - dy / 2)
+            //鍙充笂鍧愭爣
+            val g1RT = Pair(g1CenterLng + dx / 2, g1CenterLat + dy / 2)
+            // d.寰楀嚭鎵�鏈夌綉鏍肩殑涓や釜瀵硅鐐瑰潗鏍�
+            for (x in 0 until gridNum) {
+                for (y in 0 until gridNum) {
+                    points.add(GridVo("$x-$y").apply {
+                        this.lb = Pair(g1LB.first + dx * x, g1LB.second - dy * y)
+                        this.rt = Pair(g1RT.first + dx * x, g1RT.second - dy * y)
+                        this.ciLongitude = (lb!!.first + dx / 2).toBigDecimal()
+                        this.ciLatitude = (lb!!.second + dy / 2).toBigDecimal()
+                    })
+                }
+            }
+        }
+        // 璁$畻鍚勪腑蹇冪偣姹℃煋椋庨櫓鏉冮噸缁撴灉骞惰祴浜堝搴斿奖鍝嶇瓑绾�
+        var page = 1
+        var totalPage = -1
+        while (totalPage == -1 || page <= totalPage) {
+            realTimeDataService.getSecondData(deviceCode, startTime, endTime, 0, page, 5000).apply {
+                if (totalPage == -1) {
+                    totalPage = head?.totalPage ?: 0
+                }
+                val dataList = data ?: emptyList()
+
+                // FIXME: 2021/7/13 姝ゅ涓轰簡娴嬭瘯鏆傛椂灏嗙珯鐐圭粡绾害鍐欐锛屽悗缁�氳繃鏁版嵁搴撻厤缃幏鍙�
+                dataList.forEach {
+                    if (it.lng == 0.0 && it.lat == 0.0) {
+                        it.lng = GridLng
+                        it.lat = GridLat
+                    }
+                }
+
+                epwModel.execute(dataList, points, true)
+                page++
+            }
+        }
+        val r = epwModel.outputResult()
+
+        val max = mutableMapOf<String, Double>()//璁板綍姣忕鐩戞祴鍥犲瓙鐨勬渶澶у��
+//        val min = mutableMapOf<String, Double>()//璁板綍姣忕鐩戞祴鍥犲瓙鐨勬渶灏忓��
+        //涓烘瘡涓綉鏍艰祴鍊兼潈閲嶇粨鏋滃苟涓旂瓫閫夊悇鐩戞祴鍥犲瓙鐨勬渶澶ф渶灏忓��
+        points.forEach {
+            val key = "${it.sourceName};${it.index}"
+            val d = r[key]
+            d?.forEach { (t, u) ->
+                it.result[t] = u["缁煎悎(${t})"]?.average ?: .0
+
+                //绛涢�夋渶澶у��
+                if (!max.containsKey(t)) {
+                    max[t] = it.result[t]!!
+                } else {
+                    if (max[t]!! < it.result[t]!!) {
+                        max[t] = it.result[t]!!
+                    }
+                }
+//                //绛涢�夋渶灏忓��
+//                if (!min.containsKey(t)) {
+//                    min[t] = it.result[t]!!
+//                } else {
+//                    if (min[t]!! > it.result[t]!!) {
+//                        min[t] = it.result[t]!!
+//                    }
+//                }
+            }
+        }
+        // 鏍规嵁鏈�澶ф渶灏忓�硷紝璁$畻姣忎釜缃戞牸鐨勫悇鐩戞祴鍥犲瓙鐨勫奖鍝嶇瓑绾�(0->2)(褰卞搷澶�->灏�)
+        points.forEach {
+            it.result.forEach{ (k, v) ->
+                max[k]?.let {m ->
+                    val level = when (v / m) {
+                        in 0.6666..1.0 -> 0
+                        in 0.3333..0.6665 -> 1
+                        in .0..0.3332 -> 2
+                        else -> 2
+                    }
+                    it.level[k] = level
+                }
+            }
+        }
+        return BaseResponse(true, data = points)
+    }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt
index fa10e71..967c5a0 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt
@@ -132,11 +132,13 @@
         if (startTime == null && endTime == null) {
             dataList1.reverse()
         }
-        pageInfo = PageHelper.startPage<ElectricMinuteValue>(p, perP)
+        if (dataList1.isEmpty()) return BaseResponse(true, data = result)
+
+//        pageInfo = PageHelper.startPage<ElectricMinuteValue>(p, perP)
         val dataList2 = electricMinuteValueMapper.selectByExample(Example(ElectricMinuteValue::class.java).apply {
             createCriteria().andEqualTo("mvStatCode", d2?.cdDeviceCode)
                 .apply {
-                    sTime?.let { andGreaterThanOrEqualTo("mvDataTime", it) }
+                    andGreaterThanOrEqualTo("mvDataTime", sTime ?: dataList1[0].mvDataTime)
                     eTime?.let { andLessThanOrEqualTo("mvDataTime", it) }
                 }
             orderBy("mvDataTime").apply {
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/web/DeviceInfoController.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/web/DeviceInfoController.kt
index af92baa..214195a 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/web/DeviceInfoController.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/web/DeviceInfoController.kt
@@ -2,6 +2,7 @@
 
 import com.flightfeather.uav.lightshare.service.DeviceService
 import io.swagger.annotations.Api
+import org.springframework.web.bind.annotation.GetMapping
 import org.springframework.web.bind.annotation.RequestMapping
 import org.springframework.web.bind.annotation.RestController
 
@@ -10,5 +11,6 @@
 @RequestMapping("air/device")
 class DeviceInfoController(private val deviceService: DeviceService) {
 
+    @GetMapping("/all")
     fun getDeviceInfo() = deviceService.getDeviceInfo()
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/web/EPWModelController.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/web/EPWModelController.kt
new file mode 100644
index 0000000..949b8cd
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/web/EPWModelController.kt
@@ -0,0 +1,22 @@
+package com.flightfeather.uav.lightshare.web
+
+import com.flightfeather.uav.lightshare.service.EPWModelService
+import io.swagger.annotations.Api
+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
+
+@Api(tags = ["姹℃煋鏉冮噸鍒嗘瀽API鎺ュ彛"])
+@RestController
+@RequestMapping("air/analysis")
+class EPWModelController (private val epwModelService: EPWModelService){
+
+    @GetMapping("/epw")
+    fun epwModel(
+        @RequestParam(value = "deviceCode", required = true) deviceCode: String,
+        @RequestParam(value = "startTime", required = true) startTime: String,
+        @RequestParam(value = "endTime", required = true) endTime: String,
+        @RequestParam(value = "len", required = true) len: Double,
+    ) = epwModelService.getEpwModelResult(deviceCode, startTime, endTime, len)
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt b/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt
index 42a5b09..0f5ea52 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt
@@ -14,7 +14,7 @@
  * 姹℃煋婧愬奖鍝嶇▼搴︽潈閲嶅垎鏋愭ā鍨�
  * 鍩虹被
  */
-abstract class BaseModel<M : BaseMData, S : BaseSOP> {
+abstract class BaseModel<M : BaseMData> {
 
     data class ResultCell(
         var total: Double = 0.0,
@@ -27,26 +27,26 @@
         }
     }
 
-    abstract var dataPrep: BaseDataPrep<M, S>
+    abstract var dataPrep: BaseDataPrep<M, BaseSOP>
 
     // 鏉冮噸鍥犲瓙锛屽湪杩涜璁$畻鍒嗘瀽鏃朵娇鐢ㄧ殑鐩戞祴鍥犲瓙
     abstract var factorTypes: List<FactorType>
 
     // 鏉冮噸鍊硷紝澶氱鏉冮噸杩涜涔樼Н璁$畻
-    abstract var weights: List<BaseWeight<M, S>>
+    abstract var weights: List<BaseWeight<M, BaseSOP>>
 
     // 璁$畻缁撴灉
     private val rMap = mutableMapOf<String, MutableMap<String, MutableMap<String, ResultCell>>>()
 
     // 缁撴灉绛涢�夋柟寮�
-    abstract var sections: List<BaseSection<M, S>>
+    abstract var sections: List<BaseSection<M, BaseSOP>>
 
     /**
      * 姹℃煋婧愬奖鍝嶇▼搴﹁绠�
      * @param mDataList 鐩戞祴鏁版嵁闆嗗悎
      * @param sopList 姹℃煋婧愰泦鍚�
      */
-    fun execute(mDataList: List<M>, sopList: List<S>, hasNext: Boolean = false) {
+    fun execute(mDataList: List<M>, sopList: List<BaseSOP>, hasNext: Boolean = false) {
         if (!hasNext) rMap.clear()
 
         //1. 鏁版嵁棰勫鐞�
@@ -68,7 +68,7 @@
      * @param mData 鐩戞祴鏁版嵁
      * @param sop 姹℃煋婧�
      */
-    private fun weightCompute(mData: M, sop: S) {
+    private fun weightCompute(mData: M, sop: BaseSOP) {
         val effect = BaseEffect(sop.sourceId, sop.sourceName, sop.index)
 
         // 灏嗗師鐩戞祴鏁版嵁鎸夌収鏉冮噸璁$畻鍑虹粨鏋滃��
@@ -234,5 +234,5 @@
     /**
      * 姹℃煋婧愭暟鎹悎娉曟�ф鏌�
      */
-    abstract fun sopCheck(s: S): Boolean
+    abstract fun sopCheck(s: BaseSOP): Boolean
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/BaseSOP.kt b/src/main/kotlin/com/flightfeather/uav/model/BaseSOP.kt
index 2c7d1d8..7e9d2a1 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/BaseSOP.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/BaseSOP.kt
@@ -1,5 +1,7 @@
 package com.flightfeather.uav.model
 
+import java.math.BigDecimal
+
 /**
  * Source of pollution
  * 姹℃煋婧� 鍩虹被
@@ -9,4 +11,16 @@
     var sourceId: String,
     var sourceName: String,
     var index: String
-)
\ No newline at end of file
+) {
+    /**
+     * 涓績缁忓害
+     */
+
+    var ciLongitude: BigDecimal? = null
+
+    /**
+     * 涓績绾害
+     */
+
+    var ciLatitude: BigDecimal? = null
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/NoTag.kt b/src/main/kotlin/com/flightfeather/uav/model/NoTag.kt
new file mode 100644
index 0000000..b9c0183
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/model/NoTag.kt
@@ -0,0 +1,5 @@
+package com.flightfeather.uav.model
+
+class NoTag : BaseTag() {
+    override var name: String = "鏃犲垎绫�"
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
index 08c1e5e..3539828 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
@@ -5,6 +5,7 @@
 import com.flightfeather.uav.lightshare.bean.CompanySOP
 import com.flightfeather.uav.lightshare.bean.DataVo
 import com.flightfeather.uav.model.BaseDataPrep
+import com.flightfeather.uav.model.BaseSOP
 import com.flightfeather.uav.socket.bean.AirData
 import com.flightfeather.uav.socket.bean.AirDataPackage
 import com.flightfeather.uav.socket.eunm.FactorType
@@ -13,7 +14,7 @@
 import kotlin.math.round
 import kotlin.math.sqrt
 
-class EPWDataPrep : BaseDataPrep<DataVo, CompanySOP>() {
+class EPWDataPrep : BaseDataPrep<DataVo, BaseSOP>() {
 
     // 鍚戝墠妫�绱㈢殑鏁版嵁璁板綍鏁�
     private val ncal = 15
@@ -99,7 +100,7 @@
         return mDataList
     }
 
-    override fun sopPrep(sopList: List<CompanySOP>): List<CompanySOP> {
+    override fun sopPrep(sopList: List<BaseSOP>): List<BaseSOP> {
         return sopList
     }
 
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWGridModel.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWGridModel.kt
new file mode 100644
index 0000000..50e5bb9
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWGridModel.kt
@@ -0,0 +1,28 @@
+package com.flightfeather.uav.model.epw
+
+import com.flightfeather.uav.lightshare.bean.DataVo
+import com.flightfeather.uav.model.*
+import com.flightfeather.uav.socket.eunm.FactorType
+import java.math.BigDecimal
+
+/**
+ * 缃戞牸鍖栨潈閲嶅垎鏋愭ā鍨�
+ * 鏍规嵁璧拌埅鐩戞祴鏁版嵁銆佸畾鐐圭洃娴嬫暟鎹紝缁撳悎椋庨�熴�侀鍚戙�佺洃娴嬬偣涓庣綉鏍间腑蹇冪殑鐩稿浣嶇疆绛夊洜绱狅紝璁$畻缃戞牸鍖哄煙瀵圭洃娴嬪尯鍩熺殑褰卞搷绋嬪害
+ * @author riku
+ */
+class EPWGridModel : BaseModel<DataVo>() {
+    // 榛樿鐩戞祴鐐圭粡绾害
+    var defaultLocation: Pair<Double, Double>? = null
+        set(value) {
+            weights = listOf(WindDirWeight(value), WindDisWeight(value))
+        }
+    override var dataPrep: BaseDataPrep<DataVo, BaseSOP> = EPWDataPrep()
+    override var factorTypes: List<FactorType> = WeightType.weightType
+    override var weights: List<BaseWeight<DataVo, BaseSOP>> = listOf(WindDirWeight(defaultLocation), WindDisWeight(defaultLocation))
+    override var sections: List<BaseSection<DataVo, BaseSOP>> = listOf(NoSection())
+
+    override fun mDataCheck(m: DataVo): Boolean = !(m.lng == null || m.lng == 0.0 || m.lat == null || m.lat == 0.0)
+
+    override fun sopCheck(s: BaseSOP): Boolean =
+        !(s.ciLongitude == null || s.ciLongitude == BigDecimal(0) || s.ciLatitude == null || s.ciLatitude == BigDecimal(0))
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt
index 2428a7b..b832b60 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt
@@ -11,7 +11,7 @@
  * 鏍规嵁璧拌埅鐩戞祴鏁版嵁锛岀粨鍚堥閫熴�侀鍚戙�佺洃娴嬬偣涓庝紒涓氱殑鐩稿浣嶇疆绛夊洜绱狅紝璁$畻浼佷笟瀵圭洃娴嬪尯鍩熺殑褰卞搷绋嬪害
  * @author riku
  */
-class EPWModel : BaseModel<DataVo, CompanySOP>() {
+class EPWModel : BaseModel<DataVo>() {
 
     // 榛樿鐩戞祴鐐圭粡绾害
     var defaultLocation: Pair<Double, Double>? = null
@@ -19,17 +19,17 @@
             weights = listOf(WindDirWeight(value), WindDisWeight(value))
         }
 
-    override var dataPrep: BaseDataPrep<DataVo, CompanySOP> = EPWDataPrep()
+    override var dataPrep: BaseDataPrep<DataVo, BaseSOP> = EPWDataPrep()
 
     override var factorTypes: List<FactorType> = WeightType.weightType
 
-    override var weights: List<BaseWeight<DataVo, CompanySOP>> = listOf(WindDirWeight(defaultLocation), WindDisWeight(defaultLocation))
+    override var weights: List<BaseWeight<DataVo, BaseSOP>> = listOf(WindDirWeight(defaultLocation), WindDisWeight(defaultLocation))
 
-    override var sections: List<BaseSection<DataVo, CompanySOP>> = listOf(TimeSection())
+    override var sections: List<BaseSection<DataVo, BaseSOP>> = listOf(TimeSection())
 
     override fun mDataCheck(m: DataVo): Boolean = !(m.lng == null || m.lng == 0.0 || m.lat == null || m.lat == 0.0)
 
-    override fun sopCheck(s: CompanySOP): Boolean =
+    override fun sopCheck(s: BaseSOP): Boolean =
         !(s.ciLongitude == null || s.ciLongitude == BigDecimal(0) || s.ciLatitude == null || s.ciLatitude == BigDecimal(0))
 
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/NoSection.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/NoSection.kt
new file mode 100644
index 0000000..4441f33
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/NoSection.kt
@@ -0,0 +1,19 @@
+package com.flightfeather.uav.model.epw
+
+import com.flightfeather.uav.lightshare.bean.DataVo
+import com.flightfeather.uav.model.*
+
+/**
+ * 涓嶅仛鍒嗙被缁熻
+ */
+class NoSection : BaseSection<DataVo, BaseSOP>() {
+    override val sectionValues: List<Double> = listOf(1.0)
+
+    override val sectionType: List<String> = listOf("缁煎悎")
+
+    override val tagClz: Class<out BaseTag> = NoTag::class.java
+
+    override fun onSectionValue(mData: DataVo, sop: BaseSOP, effect: BaseEffect): Double {
+        return .0
+    }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/TimeSection.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/TimeSection.kt
index 2b5f476..c6d22ac 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/epw/TimeSection.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/TimeSection.kt
@@ -2,16 +2,13 @@
 
 import com.flightfeather.uav.lightshare.bean.CompanySOP
 import com.flightfeather.uav.lightshare.bean.DataVo
-import com.flightfeather.uav.model.BaseEffect
-import com.flightfeather.uav.model.BaseSection
-import com.flightfeather.uav.model.BaseTag
-import com.flightfeather.uav.model.TimeTag
+import com.flightfeather.uav.model.*
 
 /**
  * 鏃舵鍒嗙被缁熻
  * [6,9,12,14,17,20]; [6,9)涓烘棭涓婏紝涔嬪悗渚濇涓轰笂鍗堬紝涓崍锛屼笅鍗堬紝鍌嶆櫄鍜屾櫄涓�
  */
-class TimeSection : BaseSection<DataVo, CompanySOP>() {
+class TimeSection : BaseSection<DataVo, BaseSOP>() {
 
     override val sectionValues: List<Double> = listOf(6.0, 9.0, 12.0, 14.0, 17.0, 20.0)
 
@@ -21,7 +18,7 @@
 
     override val constType: List<String> = listOf("缁煎悎")
 
-    override fun onSectionValue(mData: DataVo, sop: CompanySOP, effect: BaseEffect): Double {
+    override fun onSectionValue(mData: DataVo, sop: BaseSOP, effect: BaseEffect): Double {
         return getHour(mData.time!!)
     }
 
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt
index 3dbde08..73335b8 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt
@@ -2,6 +2,7 @@
 
 import com.flightfeather.uav.lightshare.bean.CompanySOP
 import com.flightfeather.uav.lightshare.bean.DataVo
+import com.flightfeather.uav.model.BaseSOP
 import com.flightfeather.uav.model.BaseWeight
 import com.flightfeather.uav.socket.eunm.FactorType
 import kotlin.math.PI
@@ -11,7 +12,7 @@
 /**
  * 椋庡悜鏉冮噸
  */
-class WindDirWeight(var defaultLocation: Pair<Double, Double>?) : BaseWeight<DataVo, CompanySOP>() {
+class WindDirWeight(var defaultLocation: Pair<Double, Double>?) : BaseWeight<DataVo, BaseSOP>() {
 
     override val tag: String = "椋庡悜鏉冮噸"
 
@@ -19,7 +20,7 @@
 
     override val weights: List<Double> = listOf(1.0, 0.8, 0.5, 0.2, 0.1)
 
-    override fun onWeightFactor(mData: DataVo, sop: CompanySOP): Double {
+    override fun onWeightFactor(mData: DataVo, sop: BaseSOP): Double {
         val p1 = if (mData.lng == null || mData.lat == null || mData.lng == .0 || mData.lat == .0) defaultLocation else Pair(mData.lng!!, mData.lat!!)
         p1 ?: return .0
         val p2 = Pair(sop.ciLongitude!!.toDouble(), sop.ciLatitude!!.toDouble())
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt
index 2c6864a..bb38313 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt
@@ -2,6 +2,7 @@
 
 import com.flightfeather.uav.lightshare.bean.CompanySOP
 import com.flightfeather.uav.lightshare.bean.DataVo
+import com.flightfeather.uav.model.BaseSOP
 import com.flightfeather.uav.model.BaseWeight
 import com.flightfeather.uav.socket.eunm.FactorType
 import kotlin.math.abs
@@ -12,7 +13,7 @@
  * 椋庨�熻窛绂绘潈閲�
  * 鐩戞祴鐐逛笌姹℃煋婧愪箣闂寸殑鐗╃悊璺濈涓庡綋鍓嶉閫熷緱鍑虹殑鏉冮噸
  */
-class WindDisWeight(var defaultLocation: Pair<Double, Double>?) : BaseWeight<DataVo, CompanySOP>() {
+class WindDisWeight(var defaultLocation: Pair<Double, Double>?) : BaseWeight<DataVo, BaseSOP>() {
 
     override val tag: String = "椋庨�熻窛绂绘潈閲�"
 
@@ -20,7 +21,7 @@
 
     override val weights: List<Double> = listOf(1.0, 0.8, 0.6, 0.5, 0.3, 0.0)
 
-    override fun onWeightFactor(mData: DataVo, sop: CompanySOP): Double? {
+    override fun onWeightFactor(mData: DataVo, sop: BaseSOP): Double? {
         val p1 = if (mData.lng == null || mData.lat == null || mData.lng == .0 || mData.lat == .0) defaultLocation else Pair(mData.lng!!, mData.lat!!)
         p1 ?: return .0
         val p2 = Pair(sop.ciLongitude!!.toDouble(), sop.ciLatitude!!.toDouble())
diff --git a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImplTest.kt b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImplTest.kt
new file mode 100644
index 0000000..45a6815
--- /dev/null
+++ b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImplTest.kt
@@ -0,0 +1,24 @@
+package com.flightfeather.uav.lightshare.service.impl
+
+import com.flightfeather.uav.lightshare.service.EPWModelService
+import com.flightfeather.uav.lightshare.service.ElectricityService
+import junit.framework.TestCase
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.test.context.junit4.SpringRunner
+
+@RunWith(SpringRunner::class)
+@SpringBootTest
+class EPWModelServiceImplTest : TestCase() {
+
+    @Autowired
+    lateinit var epwModelService: EPWModelService
+
+    @Test
+    fun testGetEpwModelResult() {
+        val r= epwModelService.getEpwModelResult("0d0000000001", "2021-07-01 00:00:00", "2021-07-01 23:59:59", 1000.0)
+        println(r)
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3