From d978297ae85b2d7453054e616bbbe87bfabe9cbe Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 12 七月 2021 17:38:09 +0800
Subject: [PATCH] 1. 新增用电量数据查询接口 2. 调整污染权重算法

---
 src/main/kotlin/com/flightfeather/uav/lightshare/service/ElectricityService.kt               |    5 
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/CompanyServiceImpl.kt          |   59 ++++
 src/main/kotlin/com/flightfeather/uav/common/utils/DateUtil.kt                               |   35 ++
 src/main/kotlin/com/flightfeather/uav/socket/decoder/ElectricDataDecoder.kt                  |    2 
 src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt |   36 +++
 src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt              |    6 
 src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt                                  |    8 
 src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt                             |    7 
 src/test/kotlin/com/flightfeather/uav/model/epw/EPWModelTest.kt                              |   73 ++++-
 src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt                              |   27 ++
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt      |   43 +++
 src/main/resources/log4j2.xml                                                                |    2 
 src/main/resources/mapper/CompanyDeviceMapper.xml                                            |   18 +
 src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt                             |    5 
 src/main/resources/generator/generatorConfig.xml                                             |    9 
 src/main/kotlin/com/flightfeather/uav/lightshare/web/ElectricityController.kt                |   15 +
 src/main/kotlin/com/flightfeather/uav/lightshare/service/CompanyService.kt                   |   14 +
 src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt                                     |   83 +++---
 src/main/kotlin/com/flightfeather/uav/domain/entity/ExpandFun.kt                             |   95 +++++++
 src/main/kotlin/com/flightfeather/uav/domain/entity/CompanyDevice.java                       |   58 ++++
 src/main/kotlin/com/flightfeather/uav/lightshare/web/CompanyController.kt                    |   14 +
 src/main/kotlin/com/flightfeather/uav/domain/mapper/CompanyDeviceMapper.kt                   |    8 
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt     |   54 ++++
 src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt                               |   19 +
 24 files changed, 599 insertions(+), 96 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/common/utils/DateUtil.kt b/src/main/kotlin/com/flightfeather/uav/common/utils/DateUtil.kt
index 0b77150..62d5219 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/utils/DateUtil.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/utils/DateUtil.kt
@@ -5,7 +5,24 @@
 import java.text.SimpleDateFormat
 import java.util.*
 
-class DateUtil {
+class DateUtil private constructor(){
+
+    companion object {
+        @Volatile
+        private var dateUtil: DateUtil? = null
+
+        @JvmStatic
+        val instance: DateUtil
+        get() {
+            if (dateUtil == null) {
+                synchronized(DateUtil::class.java) {
+                    dateUtil = DateUtil()
+                }
+            }
+            return dateUtil!!
+        }
+    }
+
     private val threadLocal = ThreadLocal<SimpleDateFormat>()
 
     private val `object` = Any()
@@ -61,7 +78,7 @@
         if (dateStyle != null) {
             var myDate = StringToDate(date, dateStyle)
             myDate = addInteger(myDate, dateType, amount)
-            dateString = DateToString(myDate, dateStyle)
+            dateString = dateToString(myDate, dateStyle)
         }
         return dateString
     }
@@ -259,7 +276,7 @@
     fun LongToString(millisecondStamp: Long?, dateStyle: DateStyle?): String? {
         var dateString: String? = null
         if (dateStyle != null) {
-            dateString = DateToString(Date(millisecondStamp!!), dateStyle.value)
+            dateString = dateToString(Date(millisecondStamp!!), dateStyle.value)
         }
         return dateString
     }
@@ -270,7 +287,7 @@
      * @param pattern 鏃ユ湡鏍煎紡
      * @return 鏃ユ湡瀛楃涓�
      */
-    fun DateToString(date: Date?, pattern: String): String? {
+    fun dateToString(date: Date?, pattern: String): String? {
         var dateString: String? = null
         if (date != null) {
             try {
@@ -287,10 +304,10 @@
      * @param dateStyle 鏃ユ湡椋庢牸
      * @return 鏃ユ湡瀛楃涓�
      */
-    fun DateToString(date: Date?, dateStyle: DateStyle?): String? {
+    fun dateToString(date: Date?, dateStyle: DateStyle?): String? {
         var dateString: String? = null
         if (dateStyle != null) {
-            dateString = DateToString(date, dateStyle.value)
+            dateString = dateToString(date, dateStyle.value)
         }
         return dateString
     }
@@ -325,7 +342,7 @@
      * @return 鏂版棩鏈熷瓧绗︿覆
      */
     fun StringToString(date: String, olddPattern: String, newPattern: String): String? {
-        return DateToString(StringToDate(date, olddPattern), newPattern)
+        return dateToString(StringToDate(date, olddPattern), newPattern)
     }
 
     /**
@@ -616,7 +633,7 @@
      * @return 鏃ユ湡
      */
     fun getDate(date: Date?): String? {
-        return DateToString(date, DateStyle.YYYY_MM_DD)
+        return dateToString(date, DateStyle.YYYY_MM_DD)
     }
 
     /**
@@ -634,7 +651,7 @@
      * @return 鏃堕棿
      */
     fun getTime(date: Date): String? {
-        return DateToString(date, DateStyle.HH_MM_SS)
+        return dateToString(date, DateStyle.HH_MM_SS)
     }
 
     /**
diff --git a/src/main/kotlin/com/flightfeather/uav/domain/entity/CompanyDevice.java b/src/main/kotlin/com/flightfeather/uav/domain/entity/CompanyDevice.java
new file mode 100644
index 0000000..6c26ca5
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/domain/entity/CompanyDevice.java
@@ -0,0 +1,58 @@
+package com.flightfeather.uav.domain.entity;
+
+import javax.persistence.*;
+
+@Table(name = "el_company_device")
+public class CompanyDevice {
+    @Id
+    @Column(name = "CD_Id")
+    private Integer cdId;
+
+    @Column(name = "CD_Company_Id")
+    private String cdCompanyId;
+
+    @Column(name = "CD_Device_Code")
+    private String cdDeviceCode;
+
+    /**
+     * @return CD_Id
+     */
+    public Integer getCdId() {
+        return cdId;
+    }
+
+    /**
+     * @param cdId
+     */
+    public void setCdId(Integer cdId) {
+        this.cdId = cdId;
+    }
+
+    /**
+     * @return CD_Company_Id
+     */
+    public String getCdCompanyId() {
+        return cdCompanyId;
+    }
+
+    /**
+     * @param cdCompanyId
+     */
+    public void setCdCompanyId(String cdCompanyId) {
+        this.cdCompanyId = cdCompanyId == null ? null : cdCompanyId.trim();
+    }
+
+    /**
+     * @return CD_Device_Code
+     */
+    public String getCdDeviceCode() {
+        return cdDeviceCode;
+    }
+
+    /**
+     * @param cdDeviceCode
+     */
+    public void setCdDeviceCode(String cdDeviceCode) {
+        this.cdDeviceCode = cdDeviceCode == null ? null : cdDeviceCode.trim();
+    }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/domain/entity/ExpandFun.kt b/src/main/kotlin/com/flightfeather/uav/domain/entity/ExpandFun.kt
new file mode 100644
index 0000000..af678c0
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/domain/entity/ExpandFun.kt
@@ -0,0 +1,95 @@
+package com.flightfeather.uav.domain.entity
+
+import com.flightfeather.uav.common.utils.DateUtil
+import com.flightfeather.uav.common.utils.GsonUtils
+import com.flightfeather.uav.socket.bean.AirData
+
+/**
+ * 鏁版嵁搴撹〃瀹炰綋鎵╁睍鏂规硶
+ */
+fun RealTimeData.toRowTitle(): Array<String> {
+    val list = mutableListOf<String>()
+    list.add("缂栧彿")
+    list.add("閲囨牱鏃堕棿")
+    list.add("缁忓害")
+    list.add("绾害")
+    val values = GsonUtils.parserJsonToArrayBeans(factors, AirData::class.java)
+    values.forEach {
+        val name = it.factorName ?: ""
+        list.add(name)
+        list.add("$name(鐗╃悊閲�)")
+    }
+    return list.toTypedArray()
+}
+
+fun RealTimeData.toRowContent(): Array<Any> {
+    val row = mutableListOf<Any>()
+    row.add(deviceCode ?: "")
+    row.add(DateUtil.instance.dateToString(dataTime, "yyyy-MM-dd HH:mm:ss") ?: "")
+    if (longitude == null) {
+        row.add(-1.0)
+    } else {
+        row.add(longitude.toDouble())
+    }
+    if (latitude == null) {
+        row.add(-1.0)
+    } else {
+        row.add(latitude.toDouble())
+    }
+    val values = GsonUtils.parserJsonToArrayBeans(factors, AirData::class.java)
+    values.forEach {
+        row.add(it.factorData ?: -1.0)
+        row.add(it.physicalQuantity ?: -1.0)
+    }
+    return row.toTypedArray()
+}
+
+fun ElectricMinuteValue.toAirData(): List<AirData> {
+    return listOf(
+        AirData().apply {
+            factorId = "1"
+            factorName = "EA"
+            factorData = mvElectricityA
+        },
+        AirData().apply {
+            factorId = "2"
+            factorName = "EB"
+            factorData = mvElectricityB
+        },
+        AirData().apply {
+            factorId = "3"
+            factorName = "EC"
+            factorData = mvElectricityC
+        },
+        AirData().apply {
+            factorId = "4"
+            factorName = "VA"
+            factorData = mvVoltageA
+        },
+        AirData().apply {
+            factorId = "5"
+            factorName = "VB"
+            factorData = mvVoltageB
+        },
+        AirData().apply {
+            factorId = "6"
+            factorName = "VC"
+            factorData = mvVoltageC
+        },
+        AirData().apply {
+            factorId = "7"
+            factorName = "PA"
+            factorData = mvPowerA
+        },
+        AirData().apply {
+            factorId = "8"
+            factorName = "PB"
+            factorData = mvPowerB
+        },
+        AirData().apply {
+            factorId = "9"
+            factorName = "PC"
+            factorData = mvPowerC
+        },
+    )
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/domain/mapper/CompanyDeviceMapper.kt b/src/main/kotlin/com/flightfeather/uav/domain/mapper/CompanyDeviceMapper.kt
new file mode 100644
index 0000000..6da2270
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/domain/mapper/CompanyDeviceMapper.kt
@@ -0,0 +1,8 @@
+package com.flightfeather.uav.domain.mapper
+
+import com.flightfeather.uav.domain.MyMapper
+import com.flightfeather.uav.domain.entity.CompanyDevice
+import org.apache.ibatis.annotations.Mapper
+
+@Mapper
+interface CompanyDeviceMapper : MyMapper<CompanyDevice?>
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt
index 832df5a..9696b02 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt
@@ -31,4 +31,31 @@
                 }
                 return null
         }
+
+        fun toRowContent(): Array<Any> {
+                val row = mutableListOf<Any>()
+                row.add(deviceCode ?: "")
+                row.add(time ?: "")
+                row.add(lng ?: -1.0)
+                row.add(lat ?: -1.0)
+                values?.forEach {
+                        row.add(it.factorData ?: -1.0)
+                        row.add(it.physicalQuantity ?: -1.0)
+                }
+                return row.toTypedArray()
+        }
+
+        fun toRowTitle(): Array<String> {
+                val list = mutableListOf<String>()
+                list.add("缂栧彿")
+                list.add("閲囨牱鏃堕棿")
+                list.add("缁忓害")
+                list.add("绾害")
+                values?.forEach {
+                        val name = it.factorName ?: ""
+                        list.add(name)
+                        list.add("$name(鐗╃悊閲�)")
+                }
+                return list.toTypedArray()
+        }
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/CompanyService.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/CompanyService.kt
index 8d4c723..25754b3 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/CompanyService.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/CompanyService.kt
@@ -2,9 +2,21 @@
 
 import com.flightfeather.uav.domain.entity.Company
 import com.flightfeather.uav.lightshare.bean.BaseResponse
-import com.flightfeather.uav.lightshare.bean.DataVo
+import com.flightfeather.uav.model.BaseModel
 
 interface CompanyService {
 
     fun getCompanyInfo(): BaseResponse<List<Company>>
+
+    fun getCompany(cId: String): BaseResponse<Company>
+
+    /**
+     * 璁$畻姹℃煋婧愮殑姹℃煋鏉冮噸褰卞搷
+     */
+    fun getEpwModelResult(
+        deviceCode: String,
+        startTime: String,
+        endTime: String,
+        companyIds: List<String>? = null
+    ): BaseResponse<MutableMap<String, MutableMap<String, MutableMap<String, BaseModel.ResultCell>>>>
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/ElectricityService.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/ElectricityService.kt
index 4566dc8..006ea1c 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/ElectricityService.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/ElectricityService.kt
@@ -2,8 +2,13 @@
 
 import com.flightfeather.uav.domain.entity.ElectricMinuteValue
 import com.flightfeather.uav.lightshare.bean.BaseResponse
+import com.flightfeather.uav.lightshare.bean.DataVo
 
 interface ElectricityService {
 
     fun getMinuteData(deviceCode: String, startTime: String?, endTime: String?, page: Int?, perPage: Int?): BaseResponse<List<ElectricMinuteValue>>
+
+    fun getMinuteData2(deviceCode: String, startTime: String?, endTime: String?, page: Int?, perPage: Int?): BaseResponse<List<DataVo>>
+
+    fun getByCompany(cId:String):BaseResponse<List<ElectricMinuteValue>>
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt
index a1314d8..d94a2f2 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/RealTimeDataService.kt
@@ -3,7 +3,9 @@
 import com.flightfeather.uav.lightshare.bean.BaseResponse
 import com.flightfeather.uav.lightshare.bean.DataImportResult
 import com.flightfeather.uav.lightshare.bean.DataVo
+import org.apache.poi.hssf.usermodel.HSSFWorkbook
 import org.springframework.web.multipart.MultipartFile
+import javax.servlet.http.HttpServletResponse
 
 interface RealTimeDataService {
 
@@ -12,4 +14,8 @@
     fun getNextData(deviceCode: String, updateTime: String, page: Int?, perPage: Int?): BaseResponse<List<DataVo>>
 
     fun importData(file: MultipartFile): BaseResponse<DataImportResult>
+
+    fun outToWorkbook(deviceCode: String, startTime: String, endTime: String): HSSFWorkbook
+
+    fun outToExcel(deviceCode: String, startTime: String, endTime: String, response: HttpServletResponse): HttpServletResponse
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/CompanyServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/CompanyServiceImpl.kt
index 8e0c9af..9dab0f0 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/CompanyServiceImpl.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/CompanyServiceImpl.kt
@@ -3,14 +3,71 @@
 import com.flightfeather.uav.domain.entity.Company
 import com.flightfeather.uav.domain.mapper.CompanyMapper
 import com.flightfeather.uav.lightshare.bean.BaseResponse
+import com.flightfeather.uav.lightshare.bean.CompanySOP
 import com.flightfeather.uav.lightshare.service.CompanyService
+import com.flightfeather.uav.lightshare.service.RealTimeDataService
+import com.flightfeather.uav.model.BaseModel
+import com.flightfeather.uav.model.epw.EPWModel
+import org.springframework.beans.BeanUtils
 import org.springframework.stereotype.Service
 import tk.mybatis.mapper.entity.Example
 
 @Service
-class CompanyServiceImpl(private val companyMapper: CompanyMapper) : CompanyService {
+class CompanyServiceImpl(
+    private val companyMapper: CompanyMapper, private val realTimeDataService: RealTimeDataService) : CompanyService {
+
+
     override fun getCompanyInfo(): BaseResponse<List<Company>> {
         val result = companyMapper.selectAll()
         return BaseResponse(true, data = result)
     }
+
+    override fun getCompany(cId: String): BaseResponse<Company> {
+        companyMapper.selectByPrimaryKey(cId)?.let {
+            return BaseResponse(true, data = it)
+        }
+        return BaseResponse(false, "浼佷笟id涓嶅瓨鍦�")
+    }
+
+    override fun getEpwModelResult(
+        deviceCode: String,
+        startTime: String,
+        endTime: String,
+        companyIds: List<String>?
+    ): BaseResponse<MutableMap<String, MutableMap<String, MutableMap<String, BaseModel.ResultCell>>>> {
+        val company = if (companyIds == null) {
+            companyMapper.selectAll()
+        } else {
+            companyMapper.selectByExample(Example(Company::class.java).apply {
+                createCriteria().apply {
+                    companyIds.forEach { orEqualTo("ciGuid", it) }
+                }
+            })
+        }
+        val companySOPList = mutableListOf<CompanySOP>()
+        company.forEach {
+            val companySOP = CompanySOP(it.ciGuid, it.ciName, it.ciExtension1)
+            BeanUtils.copyProperties(it, companySOP)
+            companySOPList.add(companySOP)
+        }
+
+        val epwModel = EPWModel()
+        // TODO: 2021/7/6 閮ㄥ垎璁惧鏄浐瀹氱偣鐩戞祴璁惧锛屼笉浼氱Щ鍔紝鍥犳鏁版嵁涓病鏈夌粡绾害锛岄渶瑕侀澶栬缃洃娴嬬偣缁忕含搴�
+//        epwModel.defaultLocation =
+
+        var page = 1
+        var totalPage = -1
+        while (totalPage == -1 || page <= totalPage) {
+            realTimeDataService.getSecondData(deviceCode, startTime, endTime, page, 5000).apply {
+                if (totalPage == -1) {
+                    totalPage = head?.totalPage ?: 0
+                }
+                val dataList = data?: emptyList()
+                epwModel.execute(dataList, companySOPList, true)
+                page++
+            }
+        }
+        val r = epwModel.outputResult()
+        return BaseResponse(true, data = r)
+    }
 }
\ 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 dd0a575..afe80b0 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
@@ -1,17 +1,25 @@
 package com.flightfeather.uav.lightshare.service.impl
 
+import com.flightfeather.uav.common.utils.DateUtil
+import com.flightfeather.uav.domain.entity.CompanyDevice
 import com.flightfeather.uav.domain.entity.ElectricMinuteValue
+import com.flightfeather.uav.domain.entity.toAirData
+import com.flightfeather.uav.domain.mapper.CompanyDeviceMapper
 import com.flightfeather.uav.domain.mapper.ElectricMinuteValueMapper
 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.ElectricityService
+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 ElectricityServiceImpl(private val electricMinuteValueMapper: ElectricMinuteValueMapper) : ElectricityService {
+class ElectricityServiceImpl(
+    private val electricMinuteValueMapper: ElectricMinuteValueMapper, private val companyDeviceMapper: CompanyDeviceMapper
+) : ElectricityService {
 
     private var dateFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
 
@@ -37,4 +45,37 @@
         }
         return BaseResponse(true, head = DataHead(pageInfo.pageNum, pageInfo.pages), data = result)
     }
+
+    override fun getMinuteData2(deviceCode: String, startTime: String?, endTime: String?, page: Int?, perPage: Int?): BaseResponse<List<DataVo>> {
+        val result = mutableListOf<DataVo>()
+        getMinuteData(deviceCode, startTime, endTime, page, perPage).run {
+            data?.forEach {
+                result.add(DataVo(
+                    DateUtil.instance.dateToString(it.mvDataTime, DateUtil.DateStyle.YYYY_MM_DD_HH_MM_SS),
+                    it.mvStatCode,
+                    it.toAirData()
+                ))
+            }
+            return BaseResponse(success, head = head, data = result)
+        }
+    }
+
+    override fun getByCompany(cId: String): BaseResponse<List<ElectricMinuteValue>> {
+        val result = mutableListOf<ElectricMinuteValue>()
+        companyDeviceMapper.selectByExample(Example(CompanyDevice::class.java).apply {
+            createCriteria().andEqualTo("cdCompanyId", cId)
+        }).forEach {
+            val p = PageHelper.startPage<ElectricMinuteValue>(1, 1)
+            electricMinuteValueMapper.selectByExample(Example(ElectricMinuteValue::class.java).apply {
+                createCriteria().andEqualTo("mvStatCode", it?.cdDeviceCode)
+                orderBy("mvDataTime").desc()
+            })?.let {
+                if (it.isNotEmpty()) {
+                    it[0]?.let {e-> result.add(e) }
+                }
+            }
+        }
+
+        return BaseResponse(true, data = result)
+    }
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt
index 287c2e1..c7843aa 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt
@@ -1,16 +1,17 @@
 package com.flightfeather.uav.lightshare.service.impl
 
+import com.flightfeather.uav.common.utils.ExcelUtil
 import com.flightfeather.uav.common.utils.FileExchange
 import com.flightfeather.uav.common.utils.GsonUtils
 import com.flightfeather.uav.domain.entity.RealTimeData
+import com.flightfeather.uav.domain.entity.toRowContent
+import com.flightfeather.uav.domain.entity.toRowTitle
 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.DataImportResult
-import com.flightfeather.uav.lightshare.bean.DataVo
+import com.flightfeather.uav.lightshare.bean.*
 import com.flightfeather.uav.lightshare.service.RealTimeDataService
 import com.flightfeather.uav.socket.bean.AirData
 import com.github.pagehelper.PageHelper
+import org.apache.poi.hssf.usermodel.HSSFWorkbook
 import org.springframework.stereotype.Service
 import org.springframework.web.multipart.MultipartFile
 import tk.mybatis.mapper.entity.Example
@@ -19,6 +20,7 @@
 import java.io.InputStream
 import java.text.DateFormat
 import java.text.SimpleDateFormat
+import javax.servlet.http.HttpServletResponse
 
 @Service
 class RealTimeDataServiceImpl(val realTimeDataMapper: RealTimeDataMapper) : RealTimeDataService {
@@ -86,4 +88,48 @@
         }
         return BaseResponse(true, data = DataImportResult(""))
     }
+
+    override fun outToWorkbook(deviceCode: String, startTime: String, endTime: String): HSSFWorkbook {
+        val sTime = dateFormatter.parse(startTime)
+        val eTime = dateFormatter.parse(endTime)
+        val r = realTimeDataMapper.selectByExample(Example(RealTimeData::class.java).apply {
+            createCriteria().andEqualTo("deviceCode", deviceCode)
+                .apply {
+                    sTime?.let { andGreaterThanOrEqualTo("dataTime", it) }
+                    eTime?.let { andLessThanOrEqualTo("dataTime", it) }
+                }
+        })
+        val workbook = HSSFWorkbook()
+        if (r.isNotEmpty()) {
+            val heads = getTableTitle(r[0])
+            val contents = getTableContents(r)
+
+            ExcelUtil.write(heads, contents, workbook)
+        }
+        return workbook
+    }
+
+    override fun outToExcel(deviceCode: String, startTime: String, endTime: String, response: HttpServletResponse): HttpServletResponse {
+        val workbook = outToWorkbook(deviceCode, startTime, endTime)
+
+        val out = response.outputStream
+        workbook.write(out)
+        workbook.close()
+        out.flush()
+        out.close()
+
+        return response
+    }
+
+    fun getTableTitle(d: RealTimeData): List<Array<String>> {
+        return listOf(d.toRowTitle())
+    }
+
+    fun getTableContents(list: List<RealTimeData>): List<Array<Any>> {
+        val contents = mutableListOf<Array<Any>>()
+        list.forEach {
+            contents.add(it.toRowContent())
+        }
+        return contents
+    }
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/web/CompanyController.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/web/CompanyController.kt
index 10bef47..9e5afbe 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/web/CompanyController.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/web/CompanyController.kt
@@ -4,6 +4,7 @@
 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鎺ュ彛"])
@@ -13,4 +14,17 @@
 
     @GetMapping("/info")
     fun getCompanyInfo() = companyService.getCompanyInfo()
+
+    @GetMapping("/id")
+    fun getCompany(
+        @RequestParam(value = "cId", required = true) cId: String,
+    ) = companyService.getCompany(cId)
+
+    @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 = "companyIds", required = false) companyIds: List<String>?,
+    ) = companyService.getEpwModelResult(deviceCode, startTime, endTime, companyIds)
 }
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/web/ElectricityController.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/web/ElectricityController.kt
index bd69609..2bccb1c 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/web/ElectricityController.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/web/ElectricityController.kt
@@ -23,4 +23,19 @@
         @RequestParam(value = "page", required = false) page: Int?,
         @RequestParam(value = "perPage", required = false) perPage: Int?
     ) = electricityService.getMinuteData(deviceCode, startTime, endTime, page, perPage)
+
+    @ApiOperation(value = "鑾峰彇浼佷笟鐢ㄧ數閲忓垎閽熷潎鍊硷紝缁撴灉鏍煎紡涓鸿蛋鑸暟鎹牸寮�")
+    @GetMapping("/minute2")
+    fun getMinuteData2(
+        @ApiParam("璁惧缂栧彿") @RequestParam(value = "deviceCode") deviceCode: String,
+        @ApiParam(value = "寮�濮嬫椂闂�", example = "yyyy-MM-dd HH:mm:ss") @RequestParam(value = "startTime", required = false) startTime: String?,
+        @ApiParam(value = "缁撴潫鏃堕棿", example = "yyyy-MM-dd HH:mm:ss") @RequestParam(value = "endTime", required = false) endTime: String?,
+        @RequestParam(value = "page", required = false) page: Int?,
+        @RequestParam(value = "perPage", required = false) perPage: Int?
+    ) = electricityService.getMinuteData(deviceCode, startTime, endTime, page, perPage)
+
+    @GetMapping("/company")
+    fun  getByCompany(
+        @ApiParam("浼佷笟id") @RequestParam(value = "cId") cId: String,
+    ) = electricityService.getByCompany(cId)
 }
\ 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 e451fb3..7d472a4 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt
@@ -3,7 +3,6 @@
 import com.flightfeather.uav.common.utils.DateUtil
 import com.flightfeather.uav.common.utils.ExcelUtil
 import com.flightfeather.uav.socket.eunm.FactorType
-import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook
 import org.apache.poi.hssf.usermodel.HSSFWorkbook
 import java.io.File
 import java.io.FileOutputStream
@@ -16,6 +15,17 @@
  */
 abstract class BaseModel<M : BaseMData, S : BaseSOP> {
 
+    data class ResultCell(
+        var total: Double = 0.0,
+        var count: Int = 0,
+        var average: Double = 0.0
+    ) {
+        fun average(): Double {
+            average = if (count == 0) .0 else round(total / count * 100) / 100
+            return average
+        }
+    }
+
     abstract var dataPrep: BaseDataPrep<M, S>
 
     // 鏉冮噸鍥犲瓙锛屽湪杩涜璁$畻鍒嗘瀽鏃朵娇鐢ㄧ殑鐩戞祴鍥犲瓙
@@ -25,9 +35,7 @@
     abstract var weights: List<BaseWeight<M, S>>
 
     // 璁$畻缁撴灉
-    private val result = mutableSetOf<BaseEffect>()
-
-    private val rMap = mutableMapOf<String, MutableMap<String, MutableMap<String?, MutableList<Double>>>>()
+    private val rMap = mutableMapOf<String, MutableMap<String, MutableMap<String, ResultCell>>>()
 
     // 缁撴灉绛涢�夋柟寮�
     abstract var sections: List<BaseSection<M, S>>
@@ -37,9 +45,8 @@
      * @param mDataList 鐩戞祴鏁版嵁闆嗗悎
      * @param sopList 姹℃煋婧愰泦鍚�
      */
-    fun execute(mDataList: List<M>, sopList: List<S>) {
-        result.clear()
-        rMap.clear()
+    fun execute(mDataList: List<M>, sopList: List<S>, hasNext: Boolean = false) {
+        if (!hasNext) rMap.clear()
 
         //1. 鏁版嵁棰勫鐞�
         val mList = dataPrep.mDataPrep(mDataList)
@@ -76,7 +83,6 @@
         sections.forEach { it.filter(mData, sop, effect) }
 
         // 淇濆瓨缁撴灉
-//        result.add(effect)
         formatConversion2(effect)
     }
 
@@ -90,7 +96,7 @@
 //        val rMap = formatConversion()
 
         val workbook = _workbook ?: HSSFWorkbook()
-        val fileName = fName ?: "姹℃煋婧簮鏉冮噸妯″瀷${DateUtil().DateToString(Date(), "yyyy-MM-ddHHmmss")}.xls"
+        val fileName = fName ?: "姹℃煋婧簮鏉冮噸妯″瀷${DateUtil.instance.dateToString(Date(), "yyyy-MM-ddHHmmss")}.xls"
 //        val filePath = "E:\\work\\export\\$fileName"
 //        val filePath = "E:\\宸ヤ綔\\寮�鍙慭\璧拌埅鐩戞祴\\绠楁硶鐩稿叧\\鑷姩杈撳嚭\\$fileName"
         val filePath = "E:\\宸ヤ綔\\寮�鍙慭\璧拌埅鐩戞祴\\绠楁硶鐩稿叧\\鑷姩杈撳嚭\\缃戞牸鍖朶\$fileName"
@@ -110,9 +116,8 @@
             // 鏂板缓涓�琛�
             val contentList = mutableListOf<Any>()
             // 娣诲姞姹℃煋婧愬悕绉�
-            val l = source.split("(")
-            val index = l[1].substring(0, l[1].lastIndex)
-            contentList.add(index.toIntOrNull() ?: 0)
+            val l = source.split(";")
+            contentList.add(l[1].toIntOrNull() ?: 0)
             contentList.add(l[0])
             tMap.forEach { (factorType, lMap) ->
                 sections.forEach {
@@ -122,11 +127,11 @@
                     }
                     var max = 0.0
                     var maxP = types[0]
-                    types.forEach {se ->
+                    types.forEach type@{se ->
                         val lKey = "$se($factorType)"
                         if (lMap.containsKey(lKey)) {
-                            val dataList = lMap[lKey]
-                            val size = dataList?.size
+                            val resultCell = lMap[lKey] ?: return@type
+                            val size = resultCell.count
                             // 娣诲姞璇ュ垎绫讳綔涓鸿〃澶�
                             val h = lKey
 //                            val h = "$lKey($size)"
@@ -134,17 +139,17 @@
                                 h1.add(h)
                             }
 
-                            // 灏嗗師濮嬬殑鏁版嵁鎹㈢畻寰楀嚭缁撴灉锛屽彲浠ユ槸姹傚嚭鍧囧�笺�佹�诲拰绛夌瓑锛屽悗缁慨鏀逛负鍙敱鐢ㄦ埛璁惧畾
+                            // 灏嗗師濮嬬殑鏁版嵁鎹㈢畻寰楀嚭缁撴灉锛屽彲浠ユ槸姹傚嚭鍧囧�笺�佹�诲拰绛夌瓑
                             // FIXME: 2021/6/23 姝ゅ鍏堥粯璁や负姹傚潎鍊�
-                            val average = dataList?.average()
+                            val average = resultCell.average()
 
-                            if (average ?: 0.0 > max) {
-                                max = average ?: 0.0
+                            if (average > max) {
+                                max = average
                                 maxP = se
                             }
 
                             // 褰撳墠琛屾坊鍔犺鍒嗙被涓嬬殑缁撴灉鍊�
-                            contentList.add(average ?: 0.0)
+                            contentList.add(average)
                         }
                     }
                     if (isFirst) {
@@ -181,35 +186,20 @@
         }
     }
 
-    private fun formatConversion(): Map<String, Map<String, Map<String?, MutableList<Double>>>> {
-        val rMap = mutableMapOf<String, MutableMap<String, MutableMap<String?, MutableList<Double>>>>()
-        println("缁撴灉闀垮害锛�${result.size}")
-        result.forEach { e ->
-            val rKey = "${e.sourceName}(${e.index})"
-            if (!rMap.containsKey(rKey)) {
-                rMap[rKey] = mutableMapOf()
-            }
-            val lMap = rMap[rKey]!!
-            e.value.forEach { v ->
-                if (!lMap.containsKey(v.first.des)) {
-                    lMap[v.first.des] = mutableMapOf()
-                }
-                val tMap = lMap[v.first.des]!!
-                e.tag.forEach { t ->
-                    val factorName = v.first.des
-                    val lKey = t.levelName + "($factorName)"
-                    if (!tMap.containsKey(lKey)) {
-                        tMap[lKey] = mutableListOf()
-                    }
-                    tMap[lKey]?.add(v.second)
+    fun outputResult(): MutableMap<String, MutableMap<String, MutableMap<String, ResultCell>>> {
+        rMap.forEach { (_, v) ->
+            v.forEach { (_, v2) ->
+                v2.forEach { (_, v3) ->
+                    v3.average()
                 }
             }
         }
+
         return rMap
     }
 
     private fun formatConversion2(e: BaseEffect) {
-        val rKey = "${e.sourceName}(${e.index})"
+        val rKey = "${e.sourceName};${e.index}"
         if (!rMap.containsKey(rKey)) {
             rMap[rKey] = mutableMapOf()
         }
@@ -223,9 +213,14 @@
                 val factorName = v.first.des
                 val lKey = t.levelName + "($factorName)"
                 if (!tMap.containsKey(lKey)) {
-                    tMap[lKey] = mutableListOf()
+                    tMap[lKey] = ResultCell()
                 }
-                tMap[lKey]?.add(v.second)
+                tMap[lKey]?.run {
+                    total += v.second
+                    if (factorName != FactorType.H2S.name || v.second > 0) {
+                        count++
+                    }
+                }
             }
         }
     }
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 ed0a404..3f23d11 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
@@ -21,6 +21,8 @@
 //        emptyList<String>()
         WeightType.prep
 
+    private val lastData = mutableListOf<DataVo>()
+
     override fun mDataPrep(mDataList: List<DataVo>): List<DataVo> {
         mDataList.forEach {
             it.values?.forEach v@{a ->
@@ -40,6 +42,9 @@
 //        }
 
         var i = ncal
+        if (lastData.isNotEmpty()) {
+            i = 0
+        }
         while (i < mDataList.size) {
             for (y in mDataList[i].values?.indices ?: 0..0) {
                 val it = mDataList[i].values?.get(y) ?: continue
@@ -49,7 +54,14 @@
                 it.factorData ?: continue
 
                 if (it.factorData!! > vMax) {
-                    val list = mDataList.subList(i - ncal, i)
+                    val lastDataIndex = i
+                    val thisIndex = if (i-ncal<0) 0 else i - ncal
+                    val list = mutableListOf<DataVo>()
+                    if (lastDataIndex < lastData.size) {
+                        list.addAll(lastData.subList(lastDataIndex, lastData.lastIndex + 1))
+                    }
+                    list.addAll(mDataList.subList(thisIndex, i))
+
                     // 鍘婚櫎鏃犳晥鍊肩殑骞冲潎
                     val avg = average(list, it.factorName)
                     // 鍘婚櫎鏃犳晥鍊肩殑鏍囧噯宸�
@@ -73,6 +85,11 @@
             i++
         }
 
+        lastData.clear()
+        mDataList.subList(mDataList.lastIndex - ncal + 1, mDataList.lastIndex + 1).forEach {
+            lastData.add(it.copy())
+        }
+
         return mDataList
     }
 
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 b12dd82..2428a7b 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt
@@ -13,11 +13,17 @@
  */
 class EPWModel : BaseModel<DataVo, CompanySOP>() {
 
+    // 榛樿鐩戞祴鐐圭粡绾害
+    var defaultLocation: Pair<Double, Double>? = null
+        set(value) {
+            weights = listOf(WindDirWeight(value), WindDisWeight(value))
+        }
+
     override var dataPrep: BaseDataPrep<DataVo, CompanySOP> = EPWDataPrep()
 
     override var factorTypes: List<FactorType> = WeightType.weightType
 
-    override var weights: List<BaseWeight<DataVo, CompanySOP>> = listOf(WindDirWeight(), WindDisWeight())
+    override var weights: List<BaseWeight<DataVo, CompanySOP>> = listOf(WindDirWeight(defaultLocation), WindDisWeight(defaultLocation))
 
     override var sections: List<BaseSection<DataVo, CompanySOP>> = listOf(TimeSection())
 
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 1ede99c..3dbde08 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt
@@ -11,7 +11,7 @@
 /**
  * 椋庡悜鏉冮噸
  */
-class WindDirWeight : BaseWeight<DataVo, CompanySOP>() {
+class WindDirWeight(var defaultLocation: Pair<Double, Double>?) : BaseWeight<DataVo, CompanySOP>() {
 
     override val tag: String = "椋庡悜鏉冮噸"
 
@@ -19,8 +19,9 @@
 
     override val weights: List<Double> = listOf(1.0, 0.8, 0.5, 0.2, 0.1)
 
-    override fun onWeightFactor(mData: DataVo, sop: CompanySOP): Double? {
-        val p1 = Pair(mData.lng!!, mData.lat!!)
+    override fun onWeightFactor(mData: DataVo, sop: CompanySOP): 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())
         val wd = mData.getFactorData(FactorType.WIND_DIRECTION) ?: 0.0
         return getAngle(p1, p2, wd)
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 c2add4a..2c6864a 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt
@@ -12,7 +12,7 @@
  * 椋庨�熻窛绂绘潈閲�
  * 鐩戞祴鐐逛笌姹℃煋婧愪箣闂寸殑鐗╃悊璺濈涓庡綋鍓嶉閫熷緱鍑虹殑鏉冮噸
  */
-class WindDisWeight : BaseWeight<DataVo, CompanySOP>() {
+class WindDisWeight(var defaultLocation: Pair<Double, Double>?) : BaseWeight<DataVo, CompanySOP>() {
 
     override val tag: String = "椋庨�熻窛绂绘潈閲�"
 
@@ -21,7 +21,8 @@
     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? {
-        val p1 = Pair(mData.lng!!, mData.lat!!)
+        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())
         val ws = mData.getFactorData(FactorType.WIND_SPEED)
         return if (ws == null) null else getWindSpeed(p1, p2, ws)
diff --git a/src/main/kotlin/com/flightfeather/uav/socket/decoder/ElectricDataDecoder.kt b/src/main/kotlin/com/flightfeather/uav/socket/decoder/ElectricDataDecoder.kt
index 35232d5..7bafb9a 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/decoder/ElectricDataDecoder.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/decoder/ElectricDataDecoder.kt
@@ -6,7 +6,7 @@
 
 @Component
 class ElectricDataDecoder:BaseDataDecoder<ElectricMessage>() {
-    private val dateUtil = DateUtil()
+    private val dateUtil = DateUtil.instance
 
     override fun messageClass(): Class<ElectricMessage> = ElectricMessage::class.java
 
diff --git a/src/main/resources/generator/generatorConfig.xml b/src/main/resources/generator/generatorConfig.xml
index 1063179..a138b99 100644
--- a/src/main/resources/generator/generatorConfig.xml
+++ b/src/main/resources/generator/generatorConfig.xml
@@ -24,9 +24,9 @@
             <property name="suppressAllComments" value="true"/>
         </commentGenerator>
         <!--鏁版嵁搴撻摼鎺RL锛岀敤鎴峰悕銆佸瘑鐮� -->
-        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/dronemonitor"
-						userId="root"
-						password="123456">
+        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://47.100.191.150:3306/dronemonitor"
+						userId="remoteU1"
+						password="eSoF8DnzfGTlhAjE">
         </jdbcConnection>
         <javaTypeResolver>
             <property name="forceBigDecimals" value="false"/>
@@ -47,6 +47,7 @@
         <!-- 瑕佺敓鎴愮殑琛� tableName鏄暟鎹簱涓殑琛ㄥ悕鎴栬鍥惧悕 domainObjectName鏄疄浣撶被鍚�-->
 <!--        <table tableName="air_real_time_data" domainObjectName="RealTimeData" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
 <!--        <table tableName="mission" domainObjectName="Mission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
-        <table tableName="el_minutevalue" domainObjectName="ElectricMinuteValue" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
+<!--        <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"/>
     </context>
 </generatorConfiguration>
\ No newline at end of file
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
index 1a3f1e5..b19d1e8 100644
--- a/src/main/resources/log4j2.xml
+++ b/src/main/resources/log4j2.xml
@@ -60,7 +60,7 @@
 <!--			<appender-ref ref="Console"/>-->
 <!--			<appender-ref ref="allLog"/>-->
 <!--			<appender-ref ref="debugLog"/>-->
-<!--			<appender-ref ref="errorLog"/>-->
+			<appender-ref ref="errorLog"/>
 <!--			<appender-ref ref="RollingFile"/>-->
 		</root>
 	</loggers>
diff --git a/src/main/resources/mapper/CompanyDeviceMapper.xml b/src/main/resources/mapper/CompanyDeviceMapper.xml
new file mode 100644
index 0000000..e21368f
--- /dev/null
+++ b/src/main/resources/mapper/CompanyDeviceMapper.xml
@@ -0,0 +1,18 @@
+<?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.CompanyDeviceMapper">
+  <resultMap id="BaseResultMap" type="com.flightfeather.uav.domain.entity.CompanyDevice">
+    <!--
+      WARNING - @mbg.generated
+    -->
+    <id column="CD_Id" jdbcType="INTEGER" property="cdId" />
+    <result column="CD_Company_Id" jdbcType="VARCHAR" property="cdCompanyId" />
+    <result column="CD_Device_Code" jdbcType="VARCHAR" property="cdDeviceCode" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--
+      WARNING - @mbg.generated
+    -->
+    CD_Id, CD_Company_Id, CD_Device_Code
+  </sql>
+</mapper>
\ No newline at end of file
diff --git a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt
new file mode 100644
index 0000000..4845484
--- /dev/null
+++ b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt
@@ -0,0 +1,36 @@
+package com.flightfeather.uav.lightshare.service.impl
+
+import com.flightfeather.uav.common.utils.DateUtil
+import com.flightfeather.uav.lightshare.service.RealTimeDataService
+import org.junit.Test
+
+import org.junit.Assert.*
+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
+import java.io.File
+import java.io.FileOutputStream
+import java.util.*
+
+@RunWith(SpringRunner::class)
+@SpringBootTest
+class RealTimeDataServiceImplTest {
+
+    @Autowired
+    lateinit var realTimeDataService: RealTimeDataService
+
+    @Test
+    fun outToExcel() {
+        if (realTimeDataService is RealTimeDataServiceImpl) {
+            val workbook = realTimeDataService.outToWorkbook("0a0000000001", "2021-07-05 00:00:00", "2021-07-06 23:59:59")
+            val fileName = "姹℃煋婧簮鏉冮噸妯″瀷${DateUtil.instance.dateToString(Date(), "yyyy-MM-ddHHmmss")}.xls"
+            val filePath = "E:\\宸ヤ綔\\寮�鍙慭\璧拌埅鐩戞祴\\鏍煎紡鍖栨暟鎹甛\$fileName"
+            val out = FileOutputStream(File(filePath))
+            workbook.write(out)
+            workbook.close()
+            out.flush()
+            out.close()
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/test/kotlin/com/flightfeather/uav/model/epw/EPWModelTest.kt b/src/test/kotlin/com/flightfeather/uav/model/epw/EPWModelTest.kt
index 73dbd73..9dccf11 100644
--- a/src/test/kotlin/com/flightfeather/uav/model/epw/EPWModelTest.kt
+++ b/src/test/kotlin/com/flightfeather/uav/model/epw/EPWModelTest.kt
@@ -1,7 +1,6 @@
 package com.flightfeather.uav.model.epw
 
 import com.flightfeather.uav.common.utils.DateUtil
-import com.flightfeather.uav.domain.entity.Company
 import com.flightfeather.uav.domain.mapper.CompanyMapper
 import com.flightfeather.uav.lightshare.bean.CompanySOP
 import com.flightfeather.uav.lightshare.bean.DataVo
@@ -13,9 +12,10 @@
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.boot.test.context.SpringBootTest
 import org.springframework.test.context.junit4.SpringRunner
-import tk.mybatis.mapper.entity.Example
 import java.io.FileOutputStream
 import java.util.*
+import kotlin.math.ceil
+import kotlin.math.floor
 
 @RunWith(SpringRunner::class)
 @SpringBootTest
@@ -56,6 +56,7 @@
 
         val dataSet = mutableListOf<DataVo>()
         val timeSet = listOf(
+//            缃戞牸鍖栫洃娴嬫瘡鏃�
 //            Pair("2021-06-18 15:00:00", "2021-06-18 23:59:59"),
 //            Pair("2021-06-19 00:00:00", "2021-06-19 23:59:59"),
 //            Pair("2021-06-20 00:00:00", "2021-06-20 23:59:59"),
@@ -69,13 +70,20 @@
 //            Pair("2021-06-28 00:00:00", "2021-06-28 23:59:59"),
 //            Pair("2021-06-29 00:00:00", "2021-06-29 23:59:59"),
 //            Pair("2021-06-30 00:00:00", "2021-06-30 08:00:00"),
-            Pair("2021-03-26 11:28:12", "2021-03-26 21:30:00"),
-            Pair("2021-04-09 07:18:12", "2021-04-09 22:04:39"),
-            Pair("2021-04-10 08:00:02", "2021-04-10 09:44:18"),
-            Pair("2021-04-21 16:46:12", "2021-04-21 21:18:35"),
-            Pair("2021-05-24 11:10:12", "2021-05-24 19:31:02"),
-            Pair("2021-06-04 09:02:40", "2021-06-04 20:14:18"),
+
+//            缃戞牸鍖栫洃娴�
+            Pair("2021-06-18 15:00:00", "2021-06-30 08:00:00"),
+
+//            璧拌埅鐩戞祴
+//            Pair("2021-03-26 11:28:12", "2021-03-26 21:30:00"),
+//            Pair("2021-04-09 07:18:12", "2021-04-09 22:04:39"),
+//            Pair("2021-04-10 08:00:02", "2021-04-10 09:44:18"),
+//            Pair("2021-04-21 16:46:12", "2021-04-21 21:18:35"),
+//            Pair("2021-05-24 11:10:12", "2021-05-24 19:31:02"),
+//            Pair("2021-06-04 09:02:40", "2021-06-04 20:14:18"),
         )
+
+        val deviceCode = "0d0000000001"
 
         val epwModel = EPWModel()
         var workbook: HSSFWorkbook? = null
@@ -83,23 +91,38 @@
 
         for (i in timeSet.indices) {
             val it = timeSet[i]
-            val dataList =
-                realTimeDataService.getSecondData("0d0000000001", it.first, it.second, 1, 100000).data ?: emptyList()
-            dataList.forEach {
-                if (it.lng == 0.0 && it.lat == 0.0) {
-                    it.lng = 121.235813
-                    it.lat = 30.835898
+
+            var page = 1
+            var totalPage = -1
+            while (totalPage == -1 || page <= totalPage) {
+                realTimeDataService.getSecondData(deviceCode, it.first, it.second, page, 10000).apply {
+                    if (totalPage == -1) {
+                        totalPage = head?.totalPage ?: 0
+                    }
+
+                    val dataList = data?: emptyList()
+
+                    dataList.forEach {
+                        if (it.lng == 0.0 && it.lat == 0.0) {
+                            it.lng = 121.235813
+                            it.lat = 30.835898
+                        }
+                    }
+
+                    dataSet.addAll(dataList)
+//                    println()
+//                    println("[${page}]鏁版嵁閲�: ${dataList.size}")
+
+                    epwModel.execute(dataList, companySOPList, true)
+
+                    page++
                 }
             }
-            dataSet.addAll(dataList)
-            println()
-            println("[${it.first}]鏁版嵁閲�: ${dataList.size}")
 
-            epwModel.execute(dataList, companySOPList)
             val p = epwModel.outputToExcel(
-//                "姹℃煋鏉冮噸鍒嗘瀽缁撴灉-缁煎悎-${DateUtil().DateToString(Date(), "yyyy-MM-ddHHmmss")}.xls",
+                "姹℃煋鏉冮噸鍒嗘瀽缁撴灉-缁煎悎-${DateUtil.instance.dateToString(Date(), "yyyy-MM-ddHHmmss")}.xls",
 //                "姹℃煋鏉冮噸鍒嗘瀽缁撴灉-${it.first.substring(0, 10)}.xls",
-                "姹℃煋鏉冮噸鍒嗘瀽缁撴灉-缃戞牸鍖�-${it.first.substring(0, 10)}.xls",
+//                "姹℃煋鏉冮噸鍒嗘瀽缁撴灉-缃戞牸鍖�-${it.first.substring(0, 10)}.xls",
                 workbook,
                 out,
                 it.first.substring(0, 10),
@@ -110,8 +133,12 @@
 //            p?.second?.let { out = it }
         }
 
-        println(dataSet.size)
-        epwModel.execute(dataSet, companySOPList)
-        epwModel.outputToExcel("姹℃煋鏉冮噸鍒嗘瀽缁撴灉-缁煎悎-${DateUtil().DateToString(Date(), "yyyy-MM-ddHHmmss")}.xls", workbook, out, "缁煎悎")
+//        var page = 1
+//        var totalPage = ceil(dataSet.size.toDouble() / 5000)
+//        println(dataSet.size)
+
+//        val epwModel1 = EPWModel()
+//        epwModel1.execute(dataSet, companySOPList)
+//        epwModel1.outputToExcel("姹℃煋鏉冮噸鍒嗘瀽缁撴灉-缁煎悎-${DateUtil.instance.dateToString(Date(), "yyyy-MM-ddHHmmss")}.xls", workbook, out, "缁煎悎")
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3