From 7a99e45c445b48e599adfb948350d0c9d22f441f Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期二, 09 十一月 2021 11:59:25 +0800 Subject: [PATCH] 1. 添加车载走航动态校准功能 2. 添加网格化数据校准功能 3. 添加网格化数据分钟均值转换功能(待完成) --- src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 171 insertions(+), 0 deletions(-) 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 0d933f4..1a696eb 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 @@ -9,12 +9,16 @@ 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.bean.ElectricVo 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 +import java.time.LocalDateTime +import java.time.ZoneId +import java.time.format.DateTimeFormatter @Service class ElectricityServiceImpl( @@ -22,6 +26,7 @@ ) : ElectricityService { private var dateFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") + private var dateFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm") override fun getMinuteData( deviceCode: String, startTime: String?, @@ -86,4 +91,170 @@ return BaseResponse(true, data = result) } + + override fun getElectricityInfo(cId: String, startTime: String?, endTime: String?, page: Int?, perPage: Int?): BaseResponse<List<ElectricVo>> { + val perP = perPage ?: 60 + val p = page ?: 1 + val sTime = startTime?.let { dateFormatter.parse(it) } + val eTime = endTime?.let { dateFormatter.parse(it) } + val result = mutableListOf<ElectricVo>() + val deviceCodeList = companyDeviceMapper.selectByExample(Example(CompanyDevice::class.java).apply { + createCriteria().andEqualTo("cdCompanyId", cId) + }) + //浜х嚎椋庢満 + var d1: String? = null + //搴熸皵鍑�鍖栬缃� + var d2: String? = null + + deviceCodeList.forEach { + // FIXME: 2021/11/5 姝ゅ鏆傛椂鍐欐锛屽悗缁慨鏀� + if (it?.cdDeviceCode == "31011020210602" || it?.cdDeviceCode == "31011020210603") { + d1 = it.cdDeviceCode + }else if (it?.cdDeviceCode == "31011020210601" || it?.cdDeviceCode == "31011020210604") { + d2 = it.cdDeviceCode + } + } + + var pageInfo = PageHelper.startPage<ElectricMinuteValue>(p, perP) + val dataList1 = electricMinuteValueMapper.selectByExample(Example(ElectricMinuteValue::class.java).apply { + createCriteria().andEqualTo("mvStatCode", d1) + .apply { + sTime?.let { andGreaterThanOrEqualTo("mvDataTime", it) } + eTime?.let { andLessThanOrEqualTo("mvDataTime", it) } + } + orderBy("mvDataTime").apply { + // 褰撹姹傛帴鍙d笉浼犻�掕捣濮嬫椂闂达紝榛樿鑾峰彇鏈�鏂扮殑鏁版嵁 + if (startTime == null && endTime == null) { + desc() + } + } + }) + if (startTime == null && endTime == null) { + dataList1.reverse() + } + pageInfo = PageHelper.startPage<ElectricMinuteValue>(p, perP) + val dataList2 = electricMinuteValueMapper.selectByExample(Example(ElectricMinuteValue::class.java).apply { + createCriteria().andEqualTo("mvStatCode", d2) + .apply { + sTime?.let { andGreaterThanOrEqualTo("mvDataTime", it) } + eTime?.let { andLessThanOrEqualTo("mvDataTime", it) } + } + orderBy("mvDataTime").apply { + // 褰撹姹傛帴鍙d笉浼犻�掕捣濮嬫椂闂达紝榛樿鑾峰彇鏈�鏂扮殑鏁版嵁 + if (startTime == null && endTime == null) { + desc() + } + } + }) + if (startTime == null && endTime == null) { + dataList2.reverse() + } + + // FIXME: 2021/11/5 杩斿洖缁撴灉闇�瑕佹牴鎹袱鍙拌澶囩殑鏁版嵁濮嬫湯鏃堕棿锛岄�夊彇鏈�闀跨殑涓や釜濮嬫湯鏃堕棿 + val sT = if (dataList1.isEmpty() && dataList2.isNotEmpty()) { + dataList2[0]?.mvDataTime + }else if (dataList1.isNotEmpty() && dataList2.isEmpty()) { + dataList1[0]?.mvDataTime + } else if (dataList1.isNotEmpty() && dataList2.isNotEmpty()) { + if (dataList1[0]?.mvDataTime?.after(dataList2[0]?.mvDataTime) == true) { + dataList2[0]?.mvDataTime + } else { + dataList1[0]?.mvDataTime + } + } else { + null + } + val eT = if (dataList1.isEmpty() && dataList2.isNotEmpty()) { + dataList2.last()?.mvDataTime + }else if (dataList1.isNotEmpty() && dataList2.isEmpty()) { + dataList1.last()?.mvDataTime + } else if (dataList1.isNotEmpty() && dataList2.isNotEmpty()) { + if (dataList1.last()?.mvDataTime?.after(dataList2.last()?.mvDataTime) == true) { + dataList1.last()?.mvDataTime + } else { + dataList2.last()?.mvDataTime + } + } else { + null + } + + var lsT = LocalDateTime.ofInstant(sT?.toInstant(), ZoneId.systemDefault()).withSecond(0) + val leT = LocalDateTime.ofInstant(eT?.toInstant(), ZoneId.systemDefault()).withSecond(0) + + if (sT != null && eT != null) { + while (!lsT.isAfter(leT)) { + val vo = ElectricVo(lsT.format(dateFormatter2)) + if (dataList1.isNotEmpty()) { + val d = dataList1[0] + val t = LocalDateTime.ofInstant(d?.mvDataTime?.toInstant(), ZoneId.systemDefault()).withSecond(0) + if (lsT.isEqual(t)) { + vo.apply { + d1eA = d?.mvElectricityA ?: .0 + d1eB = d?.mvElectricityB ?: .0 + d1eC = d?.mvElectricityC ?: .0 + d1Status = getStatus(d) + } + dataList1.removeAt(0) + } + } + if (dataList2.isNotEmpty()) { + val d = dataList2[0] + val t = LocalDateTime.ofInstant(d?.mvDataTime?.toInstant(), ZoneId.systemDefault()).withSecond(0) + if (lsT.isEqual(t)) { + vo.apply { + d2eA = d?.mvElectricityA ?: .0 + d2eB = d?.mvElectricityB ?: .0 + d2eC = d?.mvElectricityC ?: .0 + d2Status = getStatus(d) + } + dataList2.removeAt(0) + } + } + result.add(vo) + + lsT = lsT.plusMinutes(1) + } + } + + return BaseResponse(true, head = DataHead(pageInfo.pageNum, pageInfo.pages), data = result) + } + + // FIXME: 2021/11/5 姝ゅ鏆傛椂鍐欐锛屽悗缁慨鏀� + private fun getStatus(e: ElectricMinuteValue?): String { + var values = listOf(1, 100) + var status = listOf("0", "2", "3") + if (e == null) { + return status.first() + } + when (e.mvStatCode) { + "31011020210601" -> { + values = listOf(1, 100) + status = listOf("0", "2", "3") + } + "31011020210602" -> { + values = listOf(13, 30) + status = listOf("0", "2", "3") + } + "31011020210603" -> { + values = listOf(1, 50, 80) + status = listOf("0", "1", "2", "3") + } + "31011020210604" -> { + values = listOf(15, 90, 125) + status = listOf("0", "1", "2", "3") + } + } + val electricityList = mutableListOf<Double>() + electricityList.add(e.mvElectricityA) + electricityList.add(e.mvElectricityB) + electricityList.add(e.mvElectricityC) + + val avg = electricityList.average() + for (i in values.indices) { + if (avg < values[i]) { + return status[i] + } + } + return status.last() + } } \ No newline at end of file -- Gitblit v1.9.3