| | |
| | | package com.flightfeather.uav.biz.report |
| | | |
| | | import com.flightfeather.uav.biz.FactorFilter |
| | | import com.flightfeather.uav.biz.dataanalysis.ExceptionAnalysisController |
| | | import com.flightfeather.uav.biz.dataanalysis.model.ExceptionResult |
| | | import com.flightfeather.uav.biz.dataprocess.PreData |
| | | import com.flightfeather.uav.common.chart.ChartUtil |
| | | import com.flightfeather.uav.common.chart.DataToChartUtil |
| | | import com.flightfeather.uav.common.exception.BizException |
| | | import com.flightfeather.uav.common.location.LocationRoadNearby |
| | | import com.flightfeather.uav.common.pdf.GeneratePdfUtil |
| | | import com.flightfeather.uav.common.utils.DateUtil |
| | | import com.flightfeather.uav.common.utils.ImageUtil |
| | | import com.flightfeather.uav.domain.entity.Mission |
| | | import com.flightfeather.uav.domain.repository.MissionRep |
| | | import com.flightfeather.uav.domain.repository.RealTimeDataRep |
| | | import com.flightfeather.uav.socket.eunm.FactorType |
| | | import com.flightfeather.uav.domain.repository.SegmentInfoRep |
| | | import org.springframework.beans.BeanUtils |
| | | import org.springframework.beans.factory.annotation.Value |
| | | import org.springframework.stereotype.Component |
| | |
| | | */ |
| | | @Component |
| | | class MissionReport( |
| | | private val exceptionAnalysisController: ExceptionAnalysisController, |
| | | private val missionRep: MissionRep, |
| | | private val realTimeDataRep: RealTimeDataRep, |
| | | private val locationRoadNearby: LocationRoadNearby, |
| | | private val segmentInfoRep: SegmentInfoRep, |
| | | @Value("\${filePath}") |
| | | private val filePath: String, |
| | | ) { |
| | | |
| | | private val exceptionAnalysisController = |
| | | ExceptionAnalysisController(realTimeDataRep, locationRoadNearby, segmentInfoRep) |
| | | |
| | | data class Param( |
| | | val district: String, |
| | | val town: String, |
| | |
| | | */ |
| | | fun addExceptions(exceptions: List<ExceptionResult>) { |
| | | this.exceptions = exceptions.map { |
| | | val byteArray = DataToChartUtil.lineToByteArray(FactorType.getByValue(it.factorId!!), it.dataList) |
| | | val base64Str = ImageUtil.compressImage2(byteArray, 400, needPrefix = false) |
| | | val c = ExceptionChart() |
| | | BeanUtils.copyProperties(it, c) |
| | | c.pict = base64Str |
| | | // 创建主污染因子的数据折线图 |
| | | val byteArray = DataToChartUtil.lineToByteArray(it.selectedFactor?.main, it.dataList) |
| | | val base64Str = ImageUtil.compressImage2(byteArray, 800, needPrefix = false) |
| | | c.mainPict = base64Str |
| | | // 创建关联因子的数据折线图 |
| | | if (it.selectedFactor?.subs?.isNotEmpty() == true) { |
| | | val subList = mutableListOf<String>() |
| | | it.selectedFactor!!.subs.forEach { type -> |
| | | val byteArray1 = DataToChartUtil.lineToByteArray(type, it.dataList) |
| | | val base64Str1 = ImageUtil.compressImage2(byteArray1, 800, needPrefix = false) |
| | | subList.add(base64Str1) |
| | | } |
| | | c.subPictList = subList |
| | | } |
| | | return@map c |
| | | } |
| | | } |
| | |
| | | * 数据异常所在时段的折线图 |
| | | */ |
| | | class ExceptionChart : ExceptionResult() { |
| | | // 数据折线图Base64编码 |
| | | var pict: String? = null |
| | | // 污染因子的异常数据折线图Base64编码 |
| | | var mainPict: String? = null |
| | | |
| | | // 关联因子的异常数据折线图Base64编码 |
| | | var subPictList: List<String>? = null |
| | | } |
| | | |
| | | private val templateName = "report-underway.ftl" |
| | |
| | | private val dateFormatter = DateTimeFormatter.ofPattern("HH:mm") |
| | | |
| | | // 获取异常分析结果 |
| | | fun exceptionAnalysis(mission: Mission): List<ExceptionResult> { |
| | | return exceptionAnalysisController.run(mission) |
| | | fun exceptionAnalysis(mission: Mission, factorFilter: FactorFilter): List<ExceptionResult> { |
| | | return exceptionAnalysisController.execute(mission, factorFilter) |
| | | } |
| | | |
| | | // 计算均值和数据范围 |
| | | fun dataSummary(mission: Mission): List<Summary> { |
| | | val preData = PreData(DateUtil.instance.dateToString(mission.startTime, DateUtil.DateStyle.YYYY_MM_DD)) |
| | | fun dataSummary(mission: Mission, factorFilter: FactorFilter): List<Summary> { |
| | | val preData = PreData( |
| | | DateUtil.instance.dateToString(mission.startTime, DateUtil.DateStyle.YYYY_MM_DD), |
| | | factorFilter.mainList() |
| | | ) |
| | | val realTimeData = realTimeDataRep.fetchData(mission) |
| | | realTimeData.forEach { |
| | | preData.add(it.toDataVo()) |
| | |
| | | max = u.max |
| | | |
| | | val byteArray = DataToChartUtil.lineToByteArray(t, realTimeData) |
| | | val base64Str = ImageUtil.compressImage2(byteArray, 400, needPrefix = false) |
| | | val base64Str = ImageUtil.compressImage2(byteArray, 800, needPrefix = false) |
| | | pict = base64Str |
| | | }) |
| | | } |
| | |
| | | |
| | | // 生成参数 |
| | | // 根据报告模板生成对应报告 |
| | | fun execute(missionCode: String): String { |
| | | fun execute(missionCode: String, factorFilter: FactorFilter): String { |
| | | // 1. 任务合法性检查 |
| | | val mission = missionRep.findOne(missionCode) ?: throw BizException("该任务编号不存在") |
| | | // 2. 获取数据异常统计结果 |
| | | val exceptions = exceptionAnalysis(mission) |
| | | // 2. 获取数据异常统计结果,根据 |
| | | val exceptions = exceptionAnalysis(mission, factorFilter) |
| | | // 3. 获取均值、范围等统计数据 |
| | | val summaries = dataSummary(mission) |
| | | val summaries = dataSummary(mission, factorFilter) |
| | | // 4. 生成报告 |
| | | val fileName = "report/" + "${mission.districtName}走航监测报告-${ |
| | | DateUtil.instance.dateToString(mission.startTime, DateUtil.DateStyle.YYYY_MM_DD) |
| | | }.doc" |
| | | }(${mission.missionCode}).doc" |
| | | val reportTemplate = ReportTemplate(templateName, filePath, fileName) |
| | | val param = getParam(mission, exceptions, summaries) |
| | | val params = reportTemplate.getParam(param) |
| | | GeneratePdfUtil.generateWord(params) |
| | | return fileName |
| | | return filePath + fileName |
| | | } |
| | | |
| | | private fun getParam(mission: Mission, exceptions: List<ExceptionResult>, summaries: List<Summary>): Param { |