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, private val companyDeviceMapper: CompanyDeviceMapper
|
) : ElectricityService {
|
|
private var dateFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
|
override fun getMinuteData(
|
deviceCode: String, startTime: String?,
|
endTime: String?, page: Int?, perPage: Int?
|
): BaseResponse<List<ElectricMinuteValue>> {
|
val perP = perPage ?: 60
|
val p = page ?: 1
|
val sTime = startTime?.let { dateFormatter.parse(it) }
|
val eTime = endTime?.let { dateFormatter.parse(it) }
|
val pageInfo = PageHelper.startPage<ElectricMinuteValue>(p, perP)
|
val result = mutableListOf<ElectricMinuteValue>()
|
electricMinuteValueMapper.selectByExample(Example(ElectricMinuteValue::class.java).apply {
|
createCriteria().andEqualTo("mvStatCode", deviceCode)
|
.apply {
|
sTime?.let { andGreaterThanOrEqualTo("mvDataTime", it) }
|
eTime?.let { andLessThanOrEqualTo("mvDataTime", it) }
|
}
|
orderBy("mvDataTime").apply {
|
// 当请求接口不传递起始时间,默认获取最新的数据
|
if (startTime == null && endTime == null) {
|
desc()
|
}
|
}
|
}).forEach {
|
it?.let { result.add(it) }
|
}
|
if (startTime == null && endTime == null) {
|
result.reverse()
|
}
|
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)
|
}
|
}
|