package cn.flightfeather.supervision.business.autooutput.dataanalysis
|
|
import cn.flightfeather.supervision.business.autooutput.AopOutput
|
import cn.flightfeather.supervision.business.autooutput.datasource.AopDataSource
|
import cn.flightfeather.supervision.business.autooutput.datasource.AopDbMapper
|
import cn.flightfeather.supervision.business.autooutput.datasource.AopSceneTypeCheck
|
import cn.flightfeather.supervision.domain.ds3.entity.FumeDailyAnalysis
|
import cn.flightfeather.supervision.domain.ds3.entity.FumeExceptionData
|
import cn.flightfeather.supervision.domain.ds3.entity.FumeSiteMap
|
import cn.flightfeather.supervision.domain.ds3.mapper.FumeDailyAnalysisMapper
|
import cn.flightfeather.supervision.domain.ds3.mapper.FumeExceptionDataMapper
|
import cn.flightfeather.supervision.domain.ds3.mapper.FumeSiteMapMapper
|
import org.springframework.stereotype.Component
|
import tk.mybatis.mapper.entity.Example
|
import kotlin.math.round
|
|
/**
|
* 徐汇油烟监测数据统计
|
*/
|
@Component
|
class XHFuDataAnalysis(
|
aopDbMapper: AopDbMapper,
|
aopSceneTypeCheck: AopSceneTypeCheck,
|
aopOutput: AopOutput,
|
private val fumeSiteMapMapper: FumeSiteMapMapper,
|
private val fumeDailyAnalysisMapper: FumeDailyAnalysisMapper,
|
private val fumeExceptionDataMapper: FumeExceptionDataMapper,
|
) : AopDataAnalysis<FumeDailyAnalysis>(aopDbMapper, aopSceneTypeCheck, aopOutput) {
|
|
// 油烟数据暂无区均值的计算
|
override fun districtAvg(source: AopDataSource?): Double? {
|
return null
|
}
|
|
private fun getDeviceCodes(evaluationScene: AopDataSource.EvaluationScene): List<String?> {
|
val fumeSiteMaps = fumeSiteMapMapper.selectByExample(Example(FumeSiteMap::class.java).apply {
|
createCriteria().andEqualTo("svUserId", evaluationScene.userInfo.value?.guid)
|
.andIsNotNull("xhDeviceCode")
|
})
|
return fumeSiteMaps.map { it?.xhDeviceCode }
|
}
|
|
override fun fetchDataResources(evaluationScene: AopDataSource.EvaluationScene): List<List<FumeDailyAnalysis?>> {
|
val deviceCodeList = getDeviceCodes(evaluationScene)
|
val map = mutableMapOf<String?, MutableList<FumeDailyAnalysis?>>()
|
fumeDailyAnalysisMapper.selectByExample(Example(FumeDailyAnalysis::class.java).apply {
|
createCriteria().andBetween("fumeDate", evaluationScene.config?.startTime, evaluationScene.config?.endTime)
|
.apply {
|
if (deviceCodeList.isNotEmpty()) {
|
andIn("fumeDevId", deviceCodeList)
|
}
|
}
|
}).forEach {
|
if (!map.containsKey(it?.fumeDevId)) {
|
map[it?.fumeDevId] = mutableListOf()
|
}
|
map[it?.fumeDevId]?.add(it)
|
}
|
val res = mutableListOf<List<FumeDailyAnalysis?>>()
|
map.forEach { (_, u) ->
|
res.add(u)
|
}
|
return res
|
}
|
|
fun fetchExceptionData(evaluationScene: AopDataSource.EvaluationScene): List<FumeExceptionData?> {
|
val deviceCodeList = getDeviceCodes(evaluationScene)
|
return if (deviceCodeList.isEmpty()) {
|
emptyList()
|
} else {
|
val code = deviceCodeList[0]
|
fumeExceptionDataMapper.selectByExample(Example(FumeExceptionData::class.java).apply {
|
createCriteria().andBetween("beginTime",
|
evaluationScene.config?.startTime,
|
evaluationScene.config?.endTime)
|
.andEqualTo("devId", code)
|
.andEqualTo("exception", "数据异常")
|
.andEqualTo("exceptionType", "0")
|
})
|
}
|
}
|
|
/**
|
* 油烟超标数
|
* 只统计重点时段内(中午、晚上)的超标情况
|
*/
|
override fun exceedTimes(data: FumeDailyAnalysis, t: TempResult) {
|
data.noonExceedingNum?.toInt()?.let {
|
t.count += it
|
}
|
data.nightExceedingNum?.toInt()?.let {
|
t.count += it
|
}
|
}
|
|
override fun avg(data: FumeDailyAnalysis, t: TempResult) {
|
data.fumeDayAverage?.let {
|
t.total += it
|
t.count++
|
}
|
}
|
|
override fun max(data: FumeDailyAnalysis, t: TempResult) {
|
data.fumeDayMax?.let {
|
if (it > t.total) {
|
t.total = it
|
}
|
}
|
}
|
|
override fun min(data: FumeDailyAnalysis, t: TempResult) {
|
data.fumeDayMin?.let {
|
if (t.count == 0 || it < t.total) {
|
t.total = it
|
}
|
// 通过t.count 来判定是否是初始化状态
|
if (t.count == 0) t.count = 1
|
}
|
}
|
|
override fun overAvgRate(avg: Double, dAvg: Double?): Double? {
|
return null
|
}
|
|
override fun effectiveRate(
|
dataList: List<List<FumeDailyAnalysis?>>,
|
evaluationScene: AopDataSource.EvaluationScene,
|
): Double {
|
var total = .0
|
var count = 0
|
dataList.forEach { list ->
|
list.forEach {
|
val noon = it?.noonOnlineRate?.removeSuffix("%")?.toDouble()?.div(100)
|
val night = it?.nightOnlineRate?.removeSuffix("%")?.toDouble()?.div(100)
|
noon?.let {
|
total += noon
|
count++
|
}
|
night?.let {
|
total += night
|
count++
|
}
|
}
|
}
|
return if (count == 0) {
|
.0
|
} else {
|
round((total / count) * 1000) / 1000
|
}
|
}
|
}
|