feiyu02
2025-08-28 ddaa44400aa478058ffe9349d59904a130b7ce9c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.flightfeather.uav.lightshare.service.impl
 
import com.flightfeather.uav.biz.FactorFilter
import com.flightfeather.uav.biz.dataanalysis.BaseExceptionResult
import com.flightfeather.uav.biz.dataanalysis.ExceptionAnalysisController
import com.flightfeather.uav.biz.dataanalysis.model.ExceptionResult
import com.flightfeather.uav.biz.report.MissionSummary
import com.flightfeather.uav.biz.sourcetrace.model.BasePollutedMsg
import com.flightfeather.uav.biz.sourcetrace.model.PollutedClue
import com.flightfeather.uav.common.exception.BizException
import com.flightfeather.uav.common.location.LocationRoadNearby
import com.flightfeather.uav.common.utils.GsonUtils
import com.flightfeather.uav.domain.entity.Mission
import com.flightfeather.uav.domain.mapper.MissionMapper
import com.flightfeather.uav.domain.repository.MissionRep
import com.flightfeather.uav.domain.repository.RealTimeDataRep
import com.flightfeather.uav.domain.repository.SegmentInfoRep
import com.flightfeather.uav.domain.repository.SourceTraceRep
import com.flightfeather.uav.lightshare.bean.AreaVo
import com.flightfeather.uav.lightshare.service.DataAnalysisService
import com.flightfeather.uav.socket.eunm.FactorType
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
import java.time.LocalDateTime
import java.time.ZoneId
import java.util.*
 
/**
 *
 * @date 2025/5/8
 * @author feiyu02
 */
@Service
class DataAnalysisServiceImpl(
    private val missionRep: MissionRep,
    private val missionMapper: MissionMapper,
    private val realTimeDataRep: RealTimeDataRep,
    private val locationRoadNearby: LocationRoadNearby,
    private val segmentInfoRep: SegmentInfoRep,
    private val sourceTraceRep: SourceTraceRep
) : DataAnalysisService {
 
    override fun pollutionTrace(missionCode: String): List<ExceptionResult> {
        val mission = missionRep.findOne(missionCode) ?: throw BizException("走航任务不存在")
 
        val exceptionAnalysisController =
            ExceptionAnalysisController(realTimeDataRep, locationRoadNearby, segmentInfoRep)
 
        return exceptionAnalysisController.execute(
            mission, FactorFilter.builder()
//                .withMain(FactorType.NO2)
                .withMain(FactorType.CO)
//                .withMain(FactorType.H2S)
//                .withMain(FactorType.SO2)
//                .withMain(FactorType.O3)
                .withMain(FactorType.PM25)
                .withMain(FactorType.PM10)
                .withMain(FactorType.VOC)
                .create()
        )
    }
 
    override fun fetchHistory(missionCode: String): String {
        val mission = missionRep.findOne(missionCode) ?: throw BizException("走航任务不存在")
 
        val res = sourceTraceRep.fetchList(mission.deviceCode, mission.startTime, mission.endTime)
        return GsonUtils.gson.toJson(res)
    }
 
    override fun missionSummary(startTime: Date, endTime: Date, areaVo: AreaVo): MissionSummary.Summary {
        val clues = mutableListOf<PollutedClue?>()
        val missions = missionMapper.selectByExample(Example(Mission::class.java).apply {
            createCriteria().andBetween("startTime", startTime, endTime)
                .andEqualTo("provinceCode", areaVo.provinceCode)
                .andEqualTo("cityCode", areaVo.cityCode)
                .andEqualTo("districtCode", areaVo.districtCode)
                .andIsNotNull("kilometres")
                .andNotEqualTo("kilometres", 0)
        }).onEach {
            it ?: return@onEach
            val clue = sourceTraceRep.fetchList(it.deviceCode, it.startTime, it.endTime).filterIsInstance<PollutedClue?>()
            clues.addAll(clue)
        }
        val summary = MissionSummary().execute(startTime, endTime, missions, clues)
        return summary
    }
}