已修改16个文件
已删除3个文件
已添加18个文件
已重命名4个文件
| | |
| | | <artifactId>commons-codec</artifactId> |
| | | <version>1.14</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>junit</groupId> |
| | | <artifactId>junit</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
ÎļþÃû´Ó src/main/java/com/flightfeather/monitor/QianduanApplication.java ÐÞ¸Ä |
| | |
| | | import org.springframework.context.annotation.Bean; |
| | | |
| | | @SpringBootApplication |
| | | public class QianduanApplication { |
| | | public class MonitorApplication { |
| | | @Autowired |
| | | private TaskController taskController; |
| | | |
| | |
| | | public ApplicationRunner runner() { |
| | | return args -> taskController.run(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | SpringApplication.run(QianduanApplication.class, args); |
| | | SpringApplication.run(MonitorApplication.class, args); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { |
| | | return builder.sources(QianduanApplication.class); |
| | | return builder.sources(MonitorApplication.class); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * çæä¸æ¡å¼å¸¸åæç»æ |
| | | */ |
| | | protected fun newResult(p: DustSiteData?, n: DustSiteData): DustExceptionData { |
| | | open fun newResult(p: DustSiteData, n: DustSiteData?): DustExceptionData { |
| | | val eType = getExceptionType() |
| | | return DustExceptionData().apply { |
| | | mnCode = n.mnCode |
| | | mnCode = p.mnCode |
| | | exception = eType.des |
| | | exceptionType = eType.value |
| | | region = config.region |
| | | beginTime = if (p == null) n.lst else p.lst |
| | | endTime = n.lst |
| | | beginTime = p.lst |
| | | endTime = if (n == null) p.lst else n.lst |
| | | } |
| | | } |
| | | } |
| | |
| | | */ |
| | | abstract class BaseExceptionContinuous(config: DustExceptionSetting) : BaseDustExceptionAnalysis(config) { |
| | | |
| | | // èµ·å§æ°æ®ä¸æ |
| | | private var sIndex = 0 |
| | | // èµ·å§æ°æ®å¯¹è±¡ |
| | | private var startData: DustSiteData? = null |
| | | // æ«å°¾æ°æ®ä¸æ |
| | | private var eIndex = -1 |
| | | // æ«å°¾æ°æ®å¯¹è±¡ |
| | | private var lastData: DustSiteData? = null |
| | | // èµ·å§æ°æ®ä¸æ«å°¾æ°æ®é´é |
| | | open var durationCount = 1 |
| | | private var existException = false |
| | | |
| | | /** |
| | | * 夿æ¯å¦æ»¡è¶³å¼å¸¸æ¡ä»¶ |
| | |
| | | abstract fun judgeDuration(sIndex: Int, eIndex: Int): Boolean |
| | | |
| | | override fun init() { |
| | | super.init() |
| | | startData = null |
| | | lastData = null |
| | | sIndex = 0 |
| | | eIndex = -1 |
| | | existException = false |
| | | } |
| | | |
| | | override fun onNextData(data: DustSiteData) { |
| | |
| | | startData = data |
| | | } |
| | | // 夿ç¸é»æ°æ®æ¯å¦è¿ç»å¹¶ä¸æ¯å¦æ»¡è¶³å¼å¸¸å¤æ |
| | | if (!(isContinuous(lastData, data) && judgeException(lastData, data))) { |
| | | if (!isContinuous(lastData, data)) { |
| | | checkResult() |
| | | if (eIndex - sIndex >= durationCount) { |
| | | sIndex = eIndex |
| | | startData = data |
| | | } |
| | | } else { |
| | | if (judgeException(lastData, data)) { |
| | | existException = true |
| | | } else { |
| | | checkResult() |
| | | if (eIndex - sIndex >= durationCount) { |
| | | sIndex = eIndex |
| | | startData = data |
| | | } |
| | | } |
| | | } |
| | | // if (!(isContinuous(lastData, data) && judgeException(lastData, data))) { |
| | | // |
| | | // } |
| | | lastData = data |
| | | } |
| | | |
| | |
| | | * æ£æ¥è¿ç»å¼å¸¸ç»ææ¶ï¼æ¯å¦ç¬¦åå¼å¸¸å卿¡ä»¶ |
| | | */ |
| | | private fun checkResult() { |
| | | if (judgeDuration(sIndex, eIndex)) { |
| | | resultList.add(newResult(lastData, startData!!)) |
| | | if (existException && judgeDuration(sIndex, eIndex)) { |
| | | startData?.let { |
| | | resultList.add(newResult(it, lastData)) |
| | | } |
| | | existException = false |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.analysis.dust |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustExceptionData |
| | | import com.flightfeather.monitor.domain.ds1.repository.DustExceptionDataRep |
| | | import com.flightfeather.monitor.domain.ds1.repository.DustExceptionSettingRep |
| | | import com.flightfeather.monitor.domain.ds1.repository.DustSiteDataRep |
| | | import com.flightfeather.monitor.domain.ds1.repository.DustSiteStatusRep |
| | | import com.flightfeather.monitor.enumration.dust.DeviceStatus |
| | | import com.flightfeather.monitor.utils.DateUtil |
| | | import org.springframework.stereotype.Component |
| | | import java.time.LocalDate |
| | | import java.time.LocalDateTime |
| | | import java.time.ZoneId |
| | | |
| | | /** |
| | | * æ°æ®å¼å¸¸åææ§å¶å¨ |
| | | */ |
| | | @Component |
| | | class ExceptionAnalysisController( |
| | | private val dustExceptionDataRep: DustExceptionDataRep, |
| | | private val dustExceptionSettingRep: DustExceptionSettingRep, |
| | | private val dustSiteDataRep: DustSiteDataRep, |
| | | private val dustSiteStatusRep: DustSiteStatusRep, |
| | | ) { |
| | | |
| | | private var running = false |
| | | |
| | | private val taskList = mutableListOf<BaseDustExceptionAnalysis>() |
| | | |
| | | fun init() { |
| | | dustExceptionSettingRep.findLatestSetting("éå±±åº")?.let { |
| | | taskList.clear() |
| | | taskList.apply { |
| | | add(ExceptionDataMissing(it)) |
| | | add(ExceptionNoFluctuation(it)) |
| | | add(ExceptionApproachExceeding(it)) |
| | | add(ExceptionExceedingTimes(it)) |
| | | add(ExceptionSlideAverage(it)) |
| | | add(ExceptionValueMutation(it)) |
| | | add(ExceptionDataLowValue(it)) |
| | | add(ExceptionDataExceed(it)) |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * èªå¨è¿è¡æ¶çå¤çé»è¾ |
| | | * åææ¨å¤©çæ°æ® |
| | | */ |
| | | fun autoRun() { |
| | | val data = dustExceptionDataRep.findLatestData() |
| | | val yesterday = LocalDate.now().minusDays(1) |
| | | if (data == null) { |
| | | // FIXME: 2023/10/23 åºè¯¥æ¯å°æææ°æ®è¿è¡ç»è®¡ |
| | | run(yesterday) |
| | | } else { |
| | | val date = LocalDateTime.ofInstant(data.endTime.toInstant(), ZoneId.systemDefault()) |
| | | val sT = if (date.hour == 0 && date.minute == 0 && date.second == 0) { |
| | | date.toLocalDate() |
| | | } else { |
| | | date.plusDays(1).toLocalDate() |
| | | } |
| | | val du = DateUtil.findDurationDate(sT, yesterday) |
| | | du.forEach { |
| | | run(it) |
| | | } |
| | | } |
| | | } |
| | | |
| | | fun run(date: LocalDate) { |
| | | running = true |
| | | // å¤æå¯¹åºæ¥æçå¼å¸¸åææ¯å¦åå¨ |
| | | // if (dustExceptionDataRep.findDataExist(date)) return |
| | | // è·åææå½åä¸çº¿çè®¾å¤ |
| | | val result = mutableListOf<DustExceptionData>() |
| | | dustSiteStatusRep.select(listOf(DeviceStatus.ONLINE, DeviceStatus.STOP)).forEach { s -> |
| | | s?.let { |
| | | taskList.forEach { it.init() } |
| | | // è½®è¯¢æ°æ®ï¼è®¡ç®å个å¼å¸¸ |
| | | dustSiteDataRep.select(s.mnCode, date).takeIf { it.isNotEmpty() }?.forEach {d -> |
| | | d?.let { taskList.forEach { it.onNextData(d) } } |
| | | } |
| | | // å个å¼å¸¸åæåå«ç»æ |
| | | taskList.forEach { it.onDone() } |
| | | // åå¨åæç»æ |
| | | taskList.forEach { |
| | | result.addAll(it.resultList) |
| | | } |
| | | } |
| | | } |
| | | // ææåæç»æå
¥åº |
| | | if (result.isNotEmpty()) { |
| | | dustExceptionDataRep.insert(result) |
| | | } |
| | | running = false |
| | | } |
| | | |
| | | fun debugRun() { |
| | | val result = mutableListOf<DustExceptionData>() |
| | | val date = LocalDate.of(2023, 7, 2) |
| | | taskList.forEach { it.init() } |
| | | // è½®è¯¢æ°æ®ï¼è®¡ç®å个å¼å¸¸ |
| | | val list = dustSiteDataRep.select("YZT0JS0150043", date) |
| | | list.takeIf { it.isNotEmpty() }?.forEach { d -> |
| | | d?.let { taskList[0].onNextData(d) } |
| | | } |
| | | // å个å¼å¸¸åæåå«ç»æ |
| | | taskList[0].onDone() |
| | | // åå¨åæç»æ |
| | | taskList.forEach { result.addAll(it.resultList) } |
| | | println(result) |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.analysis.dust |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustSiteData |
| | | import com.flightfeather.monitor.enumration.dust.ExceptionType |
| | | |
| | | /** |
| | | * æ°æ®è¶
æ å¼å¸¸åæ |
| | | */ |
| | | class ExceptionDataExceed(config: DustExceptionSetting) : BaseExceptionContinuous(config) { |
| | | |
| | | override fun getExceptionType(): ExceptionType = ExceptionType.TYPE1 |
| | | |
| | | override fun judgeException(p: DustSiteData?, n: DustSiteData): Boolean { |
| | | return n.dustValue >= config.exceedingStandard |
| | | } |
| | | |
| | | override fun judgeDuration(sIndex: Int, eIndex: Int): Boolean { |
| | | return true |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.analysis.dust |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustExceptionData |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustSiteData |
| | | import com.flightfeather.monitor.enumration.dust.ExceptionType |
| | | |
| | | /** |
| | | * æ°æ®è¶
ä½å¼å¸¸åæ |
| | | */ |
| | | class ExceptionDataLowValue(config: DustExceptionSetting) : BaseExceptionContinuous(config) { |
| | | |
| | | override fun getExceptionType(): ExceptionType = ExceptionType.TYPE1 |
| | | |
| | | override fun judgeException(p: DustSiteData?, n: DustSiteData): Boolean { |
| | | return n.dustValue <= config.dataLow |
| | | } |
| | | |
| | | override fun judgeDuration(sIndex: Int, eIndex: Int): Boolean { |
| | | return true |
| | | } |
| | | |
| | | override fun newResult(p: DustSiteData, n: DustSiteData?): DustExceptionData { |
| | | val eType = getExceptionType() |
| | | return DustExceptionData().apply { |
| | | mnCode = p.mnCode |
| | | exception = eType.des |
| | | exceptionType = eType.value |
| | | region = config.region |
| | | beginTime = n?.lst |
| | | endTime = n?.lst |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | private var lastData: DustSiteData? = null |
| | | |
| | | override fun init() { |
| | | super.init() |
| | | lastData = null |
| | | } |
| | | |
| | | override fun getExceptionType(): ExceptionType = ExceptionType.TYPE0 |
| | | |
| | | override fun onNextData(data: DustSiteData) { |
| | |
| | | private var exceedingCount = 0 |
| | | private var startData: DustSiteData? = null |
| | | |
| | | override fun init() { |
| | | super.init() |
| | | exceedingCount = 0 |
| | | startData = null |
| | | } |
| | | |
| | | override fun getExceptionType(): ExceptionType = ExceptionType.TYPE6 |
| | | |
| | | override fun onNextData(data: DustSiteData) { |
| | |
| | | if (exceedingCount >= config.dayExceedBorderlineLowNum && exceedingCount < config.dayExceedBorderlineHighNum) { |
| | | startData?.let { |
| | | val eType = getExceptionType() |
| | | val t = LocalDateTime.ofInstant(it.lst.toInstant(), ZoneId.systemDefault()) |
| | | t.withHour(0) |
| | | val sT = |
| | | val t = LocalDateTime.ofInstant(it.lst.toInstant(), ZoneId.systemDefault()).withHour(0).withMinute(0).withSecond(0) |
| | | val sT = Date.from(t.atZone(ZoneId.systemDefault()).toInstant()) |
| | | val n = t.plusDays(1).minusSeconds(1) |
| | | val eT = Date.from(n.atZone(ZoneId.systemDefault()).toInstant()) |
| | | |
| | | resultList.add(DustExceptionData().apply { |
| | | mnCode = it.mnCode |
| | | exception = eType.des |
| | | exceptionType = eType.value |
| | | region = config.region |
| | | // beginTime = if (p == null) n.lst else p.lst |
| | | // endTime = n.lst |
| | | beginTime = sT |
| | | endTime = eT |
| | | }) |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.analysis.dust |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustSiteData |
| | | import com.flightfeather.monitor.enumration.dust.ExceptionType |
| | | import kotlin.math.abs |
| | | |
| | | /** |
| | | * æ»å¨å¹³åå¼çªåå¼å¸¸ |
| | | */ |
| | | class ExceptionSlideAverage(config: DustExceptionSetting) : BaseDustExceptionAnalysis(config) { |
| | | |
| | | private val historyDataList = mutableListOf<DustSiteData>() |
| | | private val tempDataList = mutableListOf<DustSiteData>() |
| | | private val avgListReverse = mutableListOf<Double>() |
| | | private var startData: DustSiteData? = null |
| | | private var lastData: DustSiteData? = null |
| | | private var sIndex = 0 |
| | | private var eIndex = -1 |
| | | private var existException = false |
| | | |
| | | override fun init() { |
| | | super.init() |
| | | historyDataList.clear() |
| | | tempDataList.clear() |
| | | avgListReverse.clear() |
| | | startData = null |
| | | lastData = null |
| | | sIndex = 0 |
| | | eIndex = -1 |
| | | existException = false |
| | | } |
| | | |
| | | override fun getExceptionType(): ExceptionType = ExceptionType.TYPE7 |
| | | |
| | | override fun onNextData(data: DustSiteData) { |
| | | eIndex++ |
| | | if (startData == null) { |
| | | startData = data |
| | | } |
| | | historyDataList.add(data) |
| | | |
| | | // æ°æ®å å
¥ä¸´æ¶æ°ç» |
| | | tempDataList.add(data) |
| | | // æ°æ®éè¶
åºè®¾ç½®æ°éæ¶ï¼å»é¤å½åæ°æ®ç»é¦ä¸ªæ°æ® |
| | | if (tempDataList.size > config.changeTrendGroup) { |
| | | tempDataList.removeAt(0) |
| | | } |
| | | // æ°æ®éçäºè®¾ç½®æ°éæ¶ï¼è®¡ç®å½åæ°æ®ç»åå¼ |
| | | if (tempDataList.size == config.changeTrendGroup) { |
| | | calAvg(tempDataList) |
| | | if (checkSlideAvg()) { |
| | | existException = true |
| | | } else { |
| | | checkResult() |
| | | } |
| | | } |
| | | lastData = data |
| | | } |
| | | |
| | | override fun onDone() { |
| | | checkResult() |
| | | } |
| | | |
| | | /** |
| | | * 计ç®ä¸ç»æ°æ®çåå¼ |
| | | */ |
| | | private fun calAvg(list: List<DustSiteData>) { |
| | | var total = .0 |
| | | val count = list.size |
| | | if (count == 0) return |
| | | list.forEach { total += it.dustValue } |
| | | val avg = total / count |
| | | avgListReverse.add(0, avg) |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ°æ®ç»ä¹é´çåå¼å·®å¼æ¯å¦è¿ç»è¶
è¿é宿¯ç |
| | | */ |
| | | private fun checkSlideAvg(): Boolean { |
| | | // è®¡ç®æ»å¨å弿ä½è¦æ±ä¸ªæ° |
| | | val minSize = config.changeTrendTimes + config.changeTrendInterval |
| | | if (avgListReverse.size < minSize) { |
| | | return false |
| | | } else { |
| | | // æ»å¨å弿»¡è¶³æ°éæ¶ï¼è®¡ç®åå¼ä¹é´æ¯å¦è¿ç»è¶
è¿é宿¯ç |
| | | val rateList = mutableListOf<Double>() |
| | | for (i in avgListReverse.indices) { |
| | | if (i >= config.changeTrendTimes) break |
| | | val r = calAvgChangeRate(avgListReverse[i], avgListReverse[i + config.changeTrendInterval]) |
| | | rateList.add(r) |
| | | } |
| | | for (y in rateList) { |
| | | if (y < config.changeTrendRate) { |
| | | return false |
| | | } |
| | | } |
| | | return true |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ»å¨åå¼ååç |
| | | */ |
| | | private fun calAvgChangeRate(a1: Double, a2: Double): Double { |
| | | return if (a2 == .0) { |
| | | 1.0 |
| | | } else { |
| | | abs(a1 - a2) / a2 |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å½åæ°æ®æªåºç°å¼å¸¸æ¶ï¼ææ°æ®å¾ªç¯ç»ææ¶ï¼å¤æåç»æ¥éª¤ |
| | | */ |
| | | private fun checkResult() { |
| | | if (existException) { |
| | | resultList.add(newResult(startData!!, lastData)) |
| | | existException = false |
| | | } |
| | | // å¤æå¹¶æ´æ°èµ·å§ç¹ä½ç½® |
| | | val len = config.changeTrendGroup - 1 + config.changeTrendTimes + config.changeTrendInterval |
| | | if ((eIndex - sIndex + 1) > len) { |
| | | sIndex = eIndex + 1 - len |
| | | startData = historyDataList[sIndex] |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | override fun judgeDuration(sIndex: Int, eIndex: Int): Boolean { |
| | | return (eIndex - sIndex) >= config.mutationNum |
| | | return (eIndex - sIndex + 1) >= config.mutationNum |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.analysis.dust |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.repository.DustStatisticsValueRep |
| | | import com.flightfeather.monitor.utils.DateUtil |
| | | import org.springframework.stereotype.Component |
| | | import java.time.LocalDate |
| | | import java.time.LocalDateTime |
| | | import java.time.ZoneId |
| | | |
| | | /** |
| | | * æ°æ®ç»è®¡åææ§å¶å¨ |
| | | */ |
| | | @Component |
| | | class StatisticAnalysisController(private val dustStatisticsValueRep: DustStatisticsValueRep) { |
| | | |
| | | private var running1 = false |
| | | private var running2 = false |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | fun autoRunDailyStatics() { |
| | | val data = dustStatisticsValueRep.findLatestData("day") |
| | | val yesterday = LocalDate.now().minusDays(1) |
| | | if (data == null) { |
| | | // FIXME: 2023/10/23 åºè¯¥æ¯å°æææ°æ®è¿è¡ç»è®¡ |
| | | dailyStatics(yesterday) |
| | | } else { |
| | | val date = LocalDateTime.ofInstant(data.lst.toInstant(), ZoneId.systemDefault()) |
| | | val sT = date.plusDays(1).toLocalDate() |
| | | val du = DateUtil.findDurationDate(sT, yesterday) |
| | | du.forEach { |
| | | dailyStatics(it) |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | fun autoRunMonthlyStatics() { |
| | | val data = dustStatisticsValueRep.findLatestData("month") |
| | | val lastMonth = LocalDate.now().minusMonths(1).withDayOfMonth(1) |
| | | if (data == null) { |
| | | // FIXME: 2023/10/23 åºè¯¥æ¯å°æææ°æ®è¿è¡ç»è®¡ |
| | | monthlyStatics(lastMonth) |
| | | } else { |
| | | val date = LocalDateTime.ofInstant(data.lst.toInstant(), ZoneId.systemDefault()) |
| | | val sT = date.plusMonths(1).toLocalDate() |
| | | val du = DateUtil.findDurationMonth(sT, lastMonth) |
| | | du.forEach { |
| | | monthlyStatics(it) |
| | | } |
| | | } |
| | | } |
| | | |
| | | fun dailyStatics(date: LocalDate) { |
| | | running1 = true |
| | | // if (dustStatisticsValueRep.findDataExist(date, "day")) return |
| | | dustStatisticsValueRep.dailyStatics(date) |
| | | running1 = false |
| | | } |
| | | |
| | | fun monthlyStatics(date: LocalDate) { |
| | | running2 = true |
| | | // if (dustStatisticsValueRep.findDataExist(date, "month")) return |
| | | dustStatisticsValueRep.monthlyStatics(date) |
| | | running2 = false |
| | | } |
| | | } |
| | |
| | | @Column(name = "change_trend_rate") |
| | | private Double changeTrendRate; |
| | | |
| | | /** |
| | | * æ»å¨å¹³åå¼ååçå¼å¸¸è¿ç»æ¬¡æ° |
| | | */ |
| | | @Column(name = "change_trend_times") |
| | | private Integer changeTrendTimes; |
| | | |
| | | @Column(name = "exceeding_standard") |
| | | private Double exceedingStandard; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * è·åæ»å¨å¹³åå¼ååçå¼å¸¸è¿ç»æ¬¡æ° |
| | | * |
| | | * @return change_trend_times - æ»å¨å¹³åå¼ååçå¼å¸¸è¿ç»æ¬¡æ° |
| | | */ |
| | | public Integer getChangeTrendTimes() { |
| | | return changeTrendTimes; |
| | | } |
| | | |
| | | /** |
| | | * 设置æ»å¨å¹³åå¼ååçå¼å¸¸è¿ç»æ¬¡æ° |
| | | * |
| | | * @param changeTrendTimes æ»å¨å¹³åå¼ååçå¼å¸¸è¿ç»æ¬¡æ° |
| | | */ |
| | | public void setChangeTrendTimes(Integer changeTrendTimes) { |
| | | this.changeTrendTimes = changeTrendTimes; |
| | | } |
| | | |
| | | /** |
| | | * @return exceeding_standard |
| | | */ |
| | | public Double getExceedingStandard() { |
ÎļþÃû´Ó src/main/java/com/flightfeather/monitor/domain/ds1/entity/DustSiteLatestTime.java ÐÞ¸Ä |
| | |
| | | import javax.persistence.*; |
| | | |
| | | @Table(name = "du_js_t_site_latest_time") |
| | | public class DustSiteLatestTime { |
| | | public class DustSiteStatus { |
| | | @Id |
| | | @Column(name = "mn_code") |
| | | private String mnCode; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.domain.ds1.mapper |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustSiteStatus |
| | | import com.flightfeather.monitor.domain.util.MyMapper |
| | | import org.apache.ibatis.annotations.Mapper |
| | | |
| | | @Mapper |
| | | interface DustSiteStatusMapper : MyMapper<DustSiteStatus?> |
| | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustStatisticsValue |
| | | import com.flightfeather.monitor.domain.util.MyMapper |
| | | import org.apache.ibatis.annotations.Mapper |
| | | import java.time.LocalDateTime |
| | | |
| | | @Mapper |
| | | interface DustStatisticsValueMapper : MyMapper<DustStatisticsValue?> |
| | | interface DustStatisticsValueMapper : MyMapper<DustStatisticsValue?> { |
| | | |
| | | fun dailyStatics(beginTime: LocalDateTime, endTime: LocalDateTime) |
| | | |
| | | fun monthlyStatics(beginTime: LocalDateTime, endTime: LocalDateTime, count: Int) |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.domain.ds1.repository |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustExceptionData |
| | | import com.flightfeather.monitor.domain.ds1.mapper.DustExceptionDataMapper |
| | | import org.springframework.stereotype.Repository |
| | | import tk.mybatis.mapper.entity.Example |
| | | import java.time.LocalDate |
| | | |
| | | @Repository |
| | | class DustExceptionDataRep(private val dustExceptionDataMapper: DustExceptionDataMapper) { |
| | | |
| | | /** |
| | | * è·åææ°ä¸æ¡è®°å½ |
| | | */ |
| | | fun findLatestData(): DustExceptionData? { |
| | | return dustExceptionDataMapper.selectOneByExample(Example(DustExceptionData::class.java).apply { |
| | | orderBy("endTime").desc() |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * 夿æå¤©çå¼å¸¸åææ°æ®æ¯å¦åå¨ |
| | | */ |
| | | fun findDataExist(date: LocalDate): Boolean { |
| | | val s = date.atStartOfDay() |
| | | val e = s.plusDays(1).minusSeconds(1) |
| | | val res = dustExceptionDataMapper.selectOneByExample(Example(DustExceptionData::class.java).apply { |
| | | createCriteria().andBetween("endTime", s, e) |
| | | }) |
| | | return res != null |
| | | } |
| | | |
| | | /** |
| | | * åå¨å¼å¸¸åæç»æ |
| | | */ |
| | | fun insert(list: List<DustExceptionData>): Int { |
| | | return dustExceptionDataMapper.insertList(list) |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.domain.ds1.repository |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting |
| | | import com.flightfeather.monitor.domain.ds1.mapper.DustExceptionSettingMapper |
| | | import org.springframework.stereotype.Repository |
| | | import tk.mybatis.mapper.entity.Example |
| | | |
| | | @Repository |
| | | class DustExceptionSettingRep(private val dustExceptionSettingMapper: DustExceptionSettingMapper) { |
| | | |
| | | /** |
| | | * è·åææ°é
ç½® |
| | | * @param region åºå¿ |
| | | */ |
| | | fun findLatestSetting(region: String): DustExceptionSetting? { |
| | | return dustExceptionSettingMapper.selectOneByExample(Example(DustExceptionSetting::class.java).apply { |
| | | createCriteria().andEqualTo("region", region) |
| | | orderBy("version").desc() |
| | | }) |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.domain.ds1.repository |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustSiteData |
| | | import com.flightfeather.monitor.domain.ds1.mapper.DustSiteDataMapper |
| | | import org.springframework.stereotype.Repository |
| | | import tk.mybatis.mapper.entity.Example |
| | | import java.time.LocalDate |
| | | |
| | | @Repository |
| | | class DustSiteDataRep(private val dustSiteDataMapper: DustSiteDataMapper) { |
| | | |
| | | /** |
| | | * è·åæä¸ªç«ç¹æä¸å¤©çææè®°å½ |
| | | */ |
| | | fun select(mnCode: String, date: LocalDate): List<DustSiteData?> { |
| | | val s = date.atStartOfDay() |
| | | val e = s.plusDays(1).minusSeconds(1) |
| | | return dustSiteDataMapper.selectByExample(Example(DustSiteData::class.java).apply { |
| | | createCriteria().andBetween("lst", s, e) |
| | | .andEqualTo("mnCode", mnCode) |
| | | orderBy("lst") |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * 夿æå¤©ççæµæ°æ®æ¯å¦åå¨ |
| | | */ |
| | | fun findDataExist(date: LocalDate): Boolean { |
| | | val s = date.atStartOfDay() |
| | | val e = s.plusDays(1).minusSeconds(1) |
| | | val res = dustSiteDataMapper.selectOneByExample(Example(DustSiteData::class.java).apply { |
| | | createCriteria().andBetween("lst", s, e) |
| | | }) |
| | | return res != null |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.domain.ds1.repository |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustSiteStatus |
| | | import com.flightfeather.monitor.domain.ds1.mapper.DustSiteStatusMapper |
| | | import com.flightfeather.monitor.enumration.dust.DeviceStatus |
| | | import org.springframework.stereotype.Repository |
| | | import tk.mybatis.mapper.entity.Example |
| | | |
| | | @Repository |
| | | class DustSiteStatusRep(private val dustSiteStatusMapper: DustSiteStatusMapper) { |
| | | |
| | | /** |
| | | * è·åç«ç¹ç¶æ |
| | | * @param status ç«ç¹ç¶æ |
| | | */ |
| | | fun select(status: List<DeviceStatus>): List<DustSiteStatus?> { |
| | | return dustSiteStatusMapper.selectByExample(Example(DustSiteStatus::class.java).apply { |
| | | createCriteria().apply { |
| | | status.forEach { |
| | | orEqualTo("deviceStatus", it.value) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.domain.ds1.repository |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustExceptionData |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustSiteData |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustStatisticsValue |
| | | import com.flightfeather.monitor.domain.ds1.mapper.DustStatisticsValueMapper |
| | | import org.springframework.stereotype.Repository |
| | | import tk.mybatis.mapper.entity.Example |
| | | import java.time.Duration |
| | | import java.time.LocalDate |
| | | |
| | | @Repository |
| | | class DustStatisticsValueRep(private val dustStatisticsValueMapper: DustStatisticsValueMapper) { |
| | | |
| | | fun findLatestData(type: String): DustStatisticsValue? { |
| | | return dustStatisticsValueMapper.selectOneByExample(Example(DustStatisticsValue::class.java).apply { |
| | | createCriteria().andEqualTo("type", type) |
| | | orderBy("lst").desc() |
| | | }) |
| | | } |
| | | |
| | | |
| | | /** |
| | | * å¤æææ¥çç»è®¡æ¯å¦åå¨ |
| | | */ |
| | | fun findDataExist(date: LocalDate, type: String): Boolean { |
| | | val s = date.atStartOfDay() |
| | | val e = date.atStartOfDay().minusSeconds(1) |
| | | val res = dustStatisticsValueMapper.selectOneByExample(Example(DustStatisticsValue::class.java).apply { |
| | | createCriteria().andBetween("lst", s, e) |
| | | .andEqualTo("type", type) |
| | | }) |
| | | return res != null |
| | | } |
| | | |
| | | fun dailyStatics(date: LocalDate) { |
| | | val s = date.atStartOfDay() |
| | | val e = s.plusDays(1).minusSeconds(1) |
| | | dustStatisticsValueMapper.dailyStatics(s, e) |
| | | } |
| | | |
| | | fun monthlyStatics(date: LocalDate) { |
| | | val s = date.atStartOfDay() |
| | | val e = s.plusMonths(1).minusSeconds(1) |
| | | val d = Duration.between(s, e).toDays() + 1 |
| | | val dataCount = d * 96 |
| | | dustStatisticsValueMapper.monthlyStatics(s, e, dataCount.toInt()) |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.enumration.dust |
| | | |
| | | enum class DeviceStatus(val value: Int, val des: String) { |
| | | ONLINE(0, "å¨çº¿"), |
| | | STOP(1, "åè¿"), |
| | | OFFLINE(2, "离线"), |
| | | } |
| | |
| | | |
| | | enum class ExceptionType(val value:Int, val des:String) { |
| | | TYPE0(0, "æç½ææçº¿"), |
| | | TYPE1(1, "æ°æ®è¶
ä½å¼å¸¸"), |
| | | TYPE3(3, "æ°æ®é¿æ¶æ®µæ æ³¢å¨"), |
| | | TYPE4(4, "é级çªåå¼å¸¸"), |
| | | TYPE5(5, "临è¿è¶
æ å¼å¸¸"), |
| | | TYPE6(6, "忥è¶
æ æ¬¡æ°ä¸´è¿å¤ç½å¼å¸¸"), |
| | | TYPE7(7, "æ»å¨å¹³åå¼çªåå¼å¸¸"), |
| | | } |
| | |
| | | package cn.flightfeather.supervision.timingtask |
| | | package com.flightfeather.monitor.scheduledtasks |
| | | |
| | | import org.slf4j.Logger |
| | | import org.slf4j.LoggerFactory |
| | | import java.time.LocalDateTime |
| | | import java.util.concurrent.ExecutorService |
| | | import java.util.concurrent.Executors |
| | | |
| | | /** |
| | | * 宿¶ä»»å¡åºç±» |
| | | */ |
| | | abstract class BaseTimingTask { |
| | | |
| | | companion object { |
| | | val log: Logger = LoggerFactory.getLogger(BaseTimingTask::class.java) |
| | | } |
| | | |
| | | // è®°å½ä¸æ¬¡ä»»å¡æ§è¡çæ¶é´ç¹ï¼åä½ï¼æ¯«ç§ |
| | | private var lastTime: LocalDateTime = LocalDateTime.MIN |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.scheduledtasks |
| | | |
| | | import com.flightfeather.monitor.analysis.dust.StatisticAnalysisController |
| | | import lombok.extern.slf4j.Slf4j |
| | | import org.springframework.stereotype.Component |
| | | import java.time.LocalDateTime |
| | | |
| | | @Component |
| | | class DustDailyStatisticAnalysisTask(private val statisticAnalysisController: StatisticAnalysisController) : |
| | | BaseTimingTask() { |
| | | |
| | | override val period: Long = 15 |
| | | |
| | | override fun execute(localtime: LocalDateTime) { |
| | | // println("æ¥åæè½®è¯¢") |
| | | // println(localtime) |
| | | if (localtime.hour == 9 && localtime.minute == 0) { |
| | | doTask(localtime) |
| | | } |
| | | } |
| | | |
| | | override fun doTask(localtime: LocalDateTime) { |
| | | log.info("æ¥åææ§è¡") |
| | | statisticAnalysisController.autoRunDailyStatics() |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.scheduledtasks |
| | | |
| | | import com.flightfeather.monitor.analysis.dust.ExceptionAnalysisController |
| | | import org.springframework.stereotype.Component |
| | | import java.time.LocalDateTime |
| | | |
| | | @Component |
| | | class DustExceptionAnalysisTask(private val exceptionAnalysisController: ExceptionAnalysisController) : |
| | | BaseTimingTask() { |
| | | |
| | | override val period: Long = 15 |
| | | |
| | | override fun execute(localtime: LocalDateTime) { |
| | | // println("å¼å¸¸åæè½®è¯¢") |
| | | // println(localtime) |
| | | if (localtime.hour == 8 && localtime.minute == 0) { |
| | | doTask(localtime) |
| | | } |
| | | } |
| | | |
| | | override fun doTask(localtime: LocalDateTime) { |
| | | log.info("å¼å¸¸åææ§è¡") |
| | | exceptionAnalysisController.init() |
| | | exceptionAnalysisController.autoRun() |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.scheduledtasks |
| | | |
| | | import com.flightfeather.monitor.analysis.dust.StatisticAnalysisController |
| | | import org.springframework.stereotype.Component |
| | | import java.time.LocalDateTime |
| | | |
| | | @Component |
| | | class DustMonthlyStatisticAnalysisTask(private val statisticAnalysisController: StatisticAnalysisController) : |
| | | BaseTimingTask() { |
| | | |
| | | override val period: Long = 15 |
| | | |
| | | override fun execute(localtime: LocalDateTime) { |
| | | // println("æåæè½®è¯¢") |
| | | // println(localtime) |
| | | if (localtime.dayOfMonth == 2 && localtime.hour == 0 && localtime.minute == 0) { |
| | | doTask(localtime) |
| | | } |
| | | } |
| | | |
| | | override fun doTask(localtime: LocalDateTime) { |
| | | log.info("æåææ§è¡") |
| | | statisticAnalysisController.autoRunMonthlyStatics() |
| | | } |
| | | } |
| | |
| | | package com.flightfeather.monitor.scheduledtasks |
| | | |
| | | import cn.flightfeather.supervision.timingtask.BaseTimingTask |
| | | import lombok.extern.slf4j.Slf4j |
| | | import org.slf4j.Logger |
| | | import org.slf4j.LoggerFactory |
| | | import org.springframework.stereotype.Component |
| | | import java.time.LocalDateTime |
| | |
| | | /** |
| | | * æ°æ®è·åæ§å¶å¨ |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | class TaskController( |
| | | /*å®ä¾å ç±»å*/ |
| | | // fetchVOC: TaskFetchVOC, |
| | | // pushFume: TaskPushFume, |
| | | // ledgerCopy: TaskLedgerCopy, |
| | | // ledgerRemind: TaskLedgerRemind, |
| | | // taskJinAnLampEnterBaseInfo: TaskJinAnLampEnterBaseInfo, |
| | | // taskJinAnLampDeviceData: TaskJinAnLampDeviceData, |
| | | // taskJinAnConstructionSiteInfo: TaskJinAnConstructionSiteInfo, |
| | | // taskJinAnHourlyDustData: TaskJinAnHourlyDustData |
| | | dustExceptionAnalysisTask: DustExceptionAnalysisTask, |
| | | dustDailyStatisticAnalysisTask: DustDailyStatisticAnalysisTask, |
| | | dustMonthlyStatisticAnalysisTask: DustMonthlyStatisticAnalysisTask, |
| | | ) { |
| | | |
| | | companion object { |
| | | private const val FETCH_PERIOD_MIN = 1L * 60 |
| | | private const val MAINTAIN_PERIOD_MIN = 5L * 60 |
| | | val LOGGER = LoggerFactory.getLogger(TaskController::class.java) |
| | | val log: Logger = LoggerFactory.getLogger(TaskController::class.java) |
| | | } |
| | | |
| | | private val timeTask = mutableListOf<BaseTimingTask>() |
| | |
| | | private var maintainTime: Date = Date() |
| | | |
| | | init { |
| | | LOGGER.info("æ·»å 宿¶ä»»å¡") |
| | | log.info("æ·»å 宿¶ä»»å¡") |
| | | timeTask.clear() |
| | | |
| | | /*åç宿¶ä»»å¡å è¿æ¥*/ |
| | | |
| | | |
| | | LOGGER.info("æ·»å 宿¶ä»»å¡å®æï¼ä»»å¡æ»è®¡${timeTask.size}个") |
| | | timeTask.add(dustExceptionAnalysisTask) |
| | | timeTask.add(dustDailyStatisticAnalysisTask) |
| | | timeTask.add(dustMonthlyStatisticAnalysisTask) |
| | | log.info("æ·»å 宿¶ä»»å¡å®æï¼ä»»å¡æ»è®¡${timeTask.size}个") |
| | | } |
| | | |
| | | fun run() { |
| | |
| | | } |
| | | |
| | | private fun fetchTask(isFirst: Boolean = false) { |
| | | val cal = Calendar.getInstance() |
| | | val time = LocalTime.now() |
| | | val sec = time.second |
| | | val delay = 60L - sec |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.utils |
| | | |
| | | import java.time.LocalDate |
| | | |
| | | object DateUtil { |
| | | |
| | | fun findDurationDate(s: LocalDate, e: LocalDate): List<LocalDate> { |
| | | val res = mutableListOf<LocalDate>() |
| | | while (s.isBefore(e) || s.isEqual(e)) { |
| | | res.add(s) |
| | | s.plusDays(1) |
| | | } |
| | | return res |
| | | } |
| | | |
| | | fun findDurationMonth(s: LocalDate, e: LocalDate): List<LocalDate> { |
| | | val res = mutableListOf<LocalDate>() |
| | | while (s.monthValue <= e.monthValue) { |
| | | res.add(s) |
| | | s.plusMonths(1) |
| | | } |
| | | return res |
| | | } |
| | | } |
| | |
| | | datasource: |
| | | ds1: |
| | | driver-class-name: com.mysql.cj.jdbc.Driver |
| | | # url: jdbc:mysql://localhost:3306/fume |
| | | # username: fume |
| | | # password: fume_feiyu2023 |
| | | url: jdbc:mysql://localhost:3306/fume |
| | | username: fume |
| | | password: fume_feiyu2023 |
| | | |
| | | # url: jdbc:mysql://localhost:3306/qianduan_sql |
| | | # username: root |
| | | # password: 1234 |
| | | |
| | | url: jdbc:mysql://localhost:3306/fume |
| | | username: root |
| | | password: 123456 |
| | | # url: jdbc:mysql://localhost:3306/fume |
| | | # username: root |
| | | # password: 123456 |
| | | |
| | | mybatis: |
| | | configuration: |
| | |
| | | <!-- enableCountByExample="false"--> |
| | | <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> |
| | | <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> |
| | | <!-- <table tableName="du_js_t_site_latest_time" domainObjectName="DustSiteLatestTime"--> |
| | | <!-- enableCountByExample="false"--> |
| | | <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> |
| | | <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> |
| | | <table tableName="du_js_t_site_latest_time" domainObjectName="DustSiteStatus" |
| | | enableCountByExample="false" |
| | | enableUpdateByExample="false" enableDeleteByExample="false" |
| | | enableSelectByExample="false" selectByExampleQueryId="false"/> |
| | | <!-- <table tableName="du_js_t_site_map" domainObjectName="DustSiteMap"--> |
| | | <!-- enableCountByExample="false"--> |
| | | <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> |
| | |
| | | <!-- enableCountByExample="false"--> |
| | | <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> |
| | | <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> |
| | | <table tableName="dust_exception_setting" domainObjectName="DustExceptionSetting" |
| | | enableCountByExample="false" |
| | | enableUpdateByExample="false" enableDeleteByExample="false" |
| | | enableSelectByExample="false" selectByExampleQueryId="false"/> |
| | | <!-- <table tableName="dust_exception_setting" domainObjectName="DustExceptionSetting"--> |
| | | <!-- enableCountByExample="false"--> |
| | | <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> |
| | | <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> |
| | | <!-- <table tableName="dust_global_setting" domainObjectName="DustGlobalSetting"--> |
| | | <!-- enableCountByExample="false"--> |
| | | <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> |
| | |
| | | <result column="change_trend_group" jdbcType="INTEGER" property="changeTrendGroup" /> |
| | | <result column="change_trend_interval" jdbcType="INTEGER" property="changeTrendInterval" /> |
| | | <result column="change_trend_rate" jdbcType="DOUBLE" property="changeTrendRate" /> |
| | | <result column="change_trend_times" jdbcType="INTEGER" property="changeTrendTimes" /> |
| | | <result column="exceeding_standard" jdbcType="DOUBLE" property="exceedingStandard" /> |
| | | </resultMap> |
| | | <sql id="Base_Column_List"> |
| | |
| | | id, user, update_time, region, version, miss_data_minutes, data_low, long_time_no_change, |
| | | mutation_num, mutation_rate, near_exceed_low_value, near_exceed_high_value, near_exceed_num, |
| | | day_exceed_borderline_low_num, day_exceed_borderline_high_num, change_trend_group, |
| | | change_trend_interval, change_trend_rate, exceeding_standard |
| | | change_trend_interval, change_trend_rate, change_trend_times, exceeding_standard |
| | | </sql> |
| | | </mapper> |
ÎļþÃû´Ó src/main/resources/mapper/ds1/DustSiteLatestTimeMapper.xml ÐÞ¸Ä |
| | |
| | | <?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.monitor.domain.ds1.mapper.DustSiteLatestTimeMapper"> |
| | | <resultMap id="BaseResultMap" type="com.flightfeather.monitor.domain.ds1.entity.DustSiteLatestTime"> |
| | | <mapper namespace="com.flightfeather.monitor.domain.ds1.mapper.DustSiteStatusMapper"> |
| | | <resultMap id="BaseResultMap" type="com.flightfeather.monitor.domain.ds1.entity.DustSiteStatus"> |
| | | <!-- |
| | | WARNING - @mbg.generated |
| | | --> |
| | |
| | | --> |
| | | id, mn_code, lst, day_avg, min, max, day_online, day_valid, day_exceeding, type |
| | | </sql> |
| | | |
| | | <insert id="dailyStatics"> |
| | | insert into dust_statistics_value(mn_code,lst,day_avg,min,max,day_online,day_valid,day_exceeding,type) |
| | | select a.* |
| | | from (select |
| | | mn_code as mn_code, |
| | | DATE(lst) as lst, |
| | | ROUND(AVG(dust_value),3) as day_avg, |
| | | min(dust_value) as min, |
| | | max(dust_value) as max, |
| | | CONCAT(ROUND(COUNT(*)/96*100, 2), '%') as day_online, |
| | | CONCAT(ROUND(SUM(CASE WHEN dust_value >0 THEN 1 ELSE 0 END)/96 *100, 2), '%') as day_valid, |
| | | CONCAT(ROUND(SUM(CASE WHEN dust_value >= 1 THEN 1 ELSE 0 END)/96*100,2),'%') as day_exceeding, |
| | | 'day' as type |
| | | from ja_t_dust_site_data_info |
| | | where lst between #{beginTime} and #{endTime} |
| | | GROUP BY mn_code,DATE(lst) |
| | | ) as a |
| | | </insert> |
| | | <insert id="monthlyStatics"> |
| | | insert into dust_statistics_value(mn_code,lst,day_avg,min,max,day_online,day_valid,day_exceeding,type) |
| | | select a.* |
| | | from ( |
| | | SELECT |
| | | mn_code AS mn_code, |
| | | DATE_FORMAT(lst, '%Y-%m-01') AS month, |
| | | ROUND(AVG(dust_value), 3) AS month_avg, |
| | | MIN(dust_value) AS min, |
| | | MAX(dust_value) AS max, |
| | | CONCAT(ROUND(COUNT(*) / #{count} * 100, 2), '%') AS month_online, |
| | | CONCAT(ROUND(SUM(CASE WHEN flag = 'N' OR flag = 'A' THEN 1 ELSE 0 END) / #{count} * 100, 2), '%') AS month_valid, |
| | | CONCAT(ROUND(SUM(CASE WHEN dust_value >= 1 THEN 1 ELSE 0 END) / #{count} * 100, 2), '%') AS month_exceeding, |
| | | 'month' as type |
| | | FROM ja_t_dust_site_data_info |
| | | WHERE lst BETWEEN #{beginTime} and #{endTime} |
| | | GROUP BY mn_code, DATE_FORMAT(lst, '%Y-%m-01') |
| | | ) as a |
| | | </insert> |
| | | </mapper> |
ÎļþÃû´Ó src/test/java/com/flightfeather/monitor/QianduanApplicationTests.java ÐÞ¸Ä |
| | |
| | | import java.util.Locale; |
| | | |
| | | @SpringBootTest |
| | | class QianduanApplicationTests { |
| | | class MonitorApplicationTests { |
| | | |
| | | @Test |
| | | void contextLoads() throws ParseException { |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.analysis.dust |
| | | |
| | | import org.junit.jupiter.api.Test |
| | | import org.junit.jupiter.api.extension.ExtendWith |
| | | import org.junit.runner.RunWith |
| | | import org.springframework.beans.factory.annotation.Autowired |
| | | import org.springframework.boot.test.context.SpringBootTest |
| | | import org.springframework.test.context.junit.jupiter.SpringExtension |
| | | import org.springframework.test.context.junit4.SpringRunner |
| | | import java.time.LocalDate |
| | | |
| | | @RunWith(SpringRunner::class) |
| | | @ExtendWith(SpringExtension::class) |
| | | @SpringBootTest |
| | | class ExceptionAnalysisControllerTest { |
| | | |
| | | @Autowired |
| | | lateinit var exceptionAnalysisController: ExceptionAnalysisController |
| | | |
| | | @Test |
| | | fun autoRun() { |
| | | exceptionAnalysisController.init() |
| | | exceptionAnalysisController.autoRun() |
| | | } |
| | | |
| | | @Test |
| | | fun run() { |
| | | exceptionAnalysisController.init() |
| | | val d = LocalDate.of(2023, 7, 2) |
| | | exceptionAnalysisController.run(d) |
| | | // exceptionAnalysisController.debugRun() |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.flightfeather.monitor.analysis.dust |
| | | |
| | | import org.junit.Test |
| | | import org.junit.jupiter.api.extension.ExtendWith |
| | | import org.junit.runner.RunWith |
| | | import org.springframework.beans.factory.annotation.Autowired |
| | | import org.springframework.boot.test.context.SpringBootTest |
| | | import org.springframework.test.context.junit.jupiter.SpringExtension |
| | | import org.springframework.test.context.junit4.SpringRunner |
| | | import java.time.LocalDate |
| | | |
| | | @RunWith(SpringRunner::class) |
| | | @ExtendWith(SpringExtension::class) |
| | | @SpringBootTest |
| | | class StatisticAnalysisControllerTest { |
| | | @Autowired |
| | | lateinit var statisticAnalysisController: StatisticAnalysisController |
| | | |
| | | @Test |
| | | fun dailyStatics() { |
| | | val d = LocalDate.of(2023, 7, 2) |
| | | statisticAnalysisController.dailyStatics(d) |
| | | } |
| | | |
| | | @Test |
| | | fun monthlyStatics() { |
| | | val d = LocalDate.of(2023, 7, 1) |
| | | statisticAnalysisController.monthlyStatics(d) |
| | | } |
| | | |
| | | @Test |
| | | fun autoRunDailyStatics() { |
| | | statisticAnalysisController.autoRunDailyStatics() |
| | | } |
| | | |
| | | @Test |
| | | fun autoRunMonthlyStatics() { |
| | | statisticAnalysisController.autoRunMonthlyStatics() |
| | | } |
| | | } |