package cn.flightfeather.supervision.lightshare.service.impl
|
|
import cn.flightfeather.supervision.common.utils.Constant
|
import cn.flightfeather.supervision.common.utils.QueryByCache
|
import cn.flightfeather.supervision.domain.ds1.entity.SceneConstructionSite
|
import cn.flightfeather.supervision.lightshare.service.DataProdBaseService
|
import cn.flightfeather.supervision.lightshare.service.DataProdMiddleService
|
import cn.flightfeather.supervision.lightshare.vo.dataprod.QueryOpt
|
import cn.flightfeather.supervision.lightshare.vo.dataprod.middle.DPEvaluationByArea
|
import cn.flightfeather.supervision.lightshare.vo.dataprod.middle.DPInspectionSummary
|
import cn.flightfeather.supervision.lightshare.vo.dataprod.middle.DPProblemCountByArea
|
import cn.flightfeather.supervision.lightshare.vo.dataprod.middle.DPProblemTypeCount
|
import org.springframework.stereotype.Service
|
|
/**
|
*
|
* @date 2025/9/15
|
* @author feiyu02
|
*/
|
@Service
|
class DataProdMiddleServiceImpl(private val dataProdBaseService: DataProdBaseService) : DataProdMiddleService {
|
|
override fun getInspectionSummary(queryOpt: QueryOpt): DPInspectionSummary {
|
return QueryByCache.queryCache(
|
cache = { return@queryCache null },
|
calculate = {
|
val res = DPInspectionSummary()
|
val inspectionInfo = dataProdBaseService.getInspectionInfo(queryOpt)
|
val sceneInfo = dataProdBaseService.getSceneInfo(queryOpt)
|
res.sceneCount = sceneInfo.size
|
res.pointCount = inspectionInfo.size
|
res.reviewPointCount = inspectionInfo.size - inspectionInfo.distinctBy { it.subTask?.scenseid }.size
|
sceneInfo.forEach {
|
when (it.scene?.typeid.toString()) {
|
// 对于建筑工地类型,根据其csStatus判断是否停工或完工
|
Constant.SceneType.TYPE1.value -> {
|
when ((it.subScene as SceneConstructionSite).csStatus) {
|
"停工" -> {
|
res.stopSceneCount++
|
}
|
|
"完工" -> {
|
res.completeSceneCount++
|
}
|
}
|
}
|
// 对于其他类型,根据其extension1(代表是否上线)判断是否完工
|
else -> {
|
if (it.scene?.extension1 != "1") {
|
res.completeSceneCount++
|
}
|
}
|
}
|
}
|
return@queryCache res
|
},
|
save = {}
|
)
|
}
|
|
override fun getProblemTypeSummary(queryOpt: QueryOpt): List<DPProblemTypeCount> {
|
return QueryByCache.queryCache(
|
cache = { return@queryCache null },
|
calculate = {
|
val res = mutableListOf<DPProblemTypeCount>()
|
val inspectionInfo = dataProdBaseService.getInspectionInfo(queryOpt)
|
val allProblemList = inspectionInfo.flatMap { it.problems ?: emptyList() }
|
allProblemList.groupBy { it.typeid }.forEach { (typeid, problemList) ->
|
res.add(DPProblemTypeCount().apply {
|
this.typeId = typeid
|
this.typeName = problemList.firstOrNull()?.typename
|
this.count = problemList.size
|
this.ratio = problemList.size.toDouble() / allProblemList.size
|
})
|
}
|
return@queryCache res
|
},
|
save = {}
|
)
|
}
|
|
override fun getProblemCountByArea(queryOpt: QueryOpt): List<DPProblemCountByArea> {
|
return QueryByCache.queryCache(
|
cache = { return@queryCache null },
|
calculate = {
|
val res = mutableListOf<DPProblemCountByArea>()
|
val inspectionInfo = dataProdBaseService.getInspectionInfo(queryOpt)
|
inspectionInfo
|
.groupBy { it.subTask?.provincecode + it.subTask?.citycode + it.subTask?.districtcode + it.subTask?.towncode }
|
.forEach { (areaName, ins) ->
|
val firstSubtask = ins.first().subTask
|
val allProblemList = ins.flatMap { it.problems ?: emptyList() }
|
res.add(DPProblemCountByArea().apply {
|
this.provinceCode = firstSubtask?.provincecode
|
this.provinceName = firstSubtask?.provincename
|
this.cityCode = firstSubtask?.citycode
|
this.cityName = firstSubtask?.cityname
|
this.districtCode = firstSubtask?.districtcode
|
this.districtName = firstSubtask?.districtname
|
this.townCode = firstSubtask?.towncode
|
this.townName = firstSubtask?.townname
|
this.sceneCount = ins.distinctBy { it.subTask?.scenseid }.size
|
this.problemCount = allProblemList.size
|
this.ratio = problemCount.toDouble() / sceneCount
|
})
|
}
|
|
return@queryCache res
|
},
|
save = {}
|
)
|
}
|
|
override fun getEvaluationByArea(queryOpt: QueryOpt): List<DPEvaluationByArea> {
|
return QueryByCache.queryCache(
|
cache = { return@queryCache null },
|
calculate = {
|
val res = mutableListOf<DPEvaluationByArea>()
|
val sceneInfo = dataProdBaseService.getSceneInfo(queryOpt)
|
val evaluation = dataProdBaseService.getEvaluateInfo(queryOpt)
|
evaluation
|
.groupBy { it.subTask?.provincecode + it.subTask?.citycode + it.subTask?.districtcode + it.subTask?.towncode }
|
.forEach { (areaName, evals) ->
|
val firstSubtask = evals.first().subTask
|
res.add(DPEvaluationByArea().apply {
|
this.provinceCode = firstSubtask?.provincecode
|
this.provinceName = firstSubtask?.provincename
|
this.cityCode = firstSubtask?.citycode
|
this.cityName = firstSubtask?.cityname
|
this.districtCode = firstSubtask?.districtcode
|
this.districtName = firstSubtask?.districtname
|
this.townCode = firstSubtask?.towncode
|
this.townName = firstSubtask?.townname
|
this.validSceneCount = sceneInfo
|
.filter {
|
it.scene?.provincecode + it.scene?.citycode + it.scene?.districtcode + it.scene?.towncode == areaName
|
&& it.statusBool
|
}.size
|
this.evaluationCount = evals.size
|
this.evalLevelACount = evals.count { it.scoreLevel == Constant.EvaluationLevel.A.text }
|
this.evalLevelBCount = evals.count { it.scoreLevel == Constant.EvaluationLevel.B.text }
|
this.evalLevelCCount = evals.count { it.scoreLevel == Constant.EvaluationLevel.C.text }
|
this.evalLevelDCount = evals.count { it.scoreLevel == Constant.EvaluationLevel.D.text }
|
this.evalLevelRatioAB = (this.evalLevelACount + this.evalLevelBCount).toDouble() / this.evaluationCount
|
})
|
}
|
|
return@queryCache res
|
},
|
save = {}
|
)
|
}
|
}
|