feiyu02
2025-09-30 a3cc1d220f8a1de11874bebceba0130d32157ff1
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package cn.flightfeather.supervision.lightshare.service.impl
 
import cn.flightfeather.supervision.business.autooutput.datasource.AopDbMapper
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.common.utils.QueryByCache
import cn.flightfeather.supervision.domain.ds1.entity.*
import cn.flightfeather.supervision.lightshare.service.DataProdBaseService
import cn.flightfeather.supervision.lightshare.vo.ProblemListVo
import cn.flightfeather.supervision.lightshare.vo.dataprod.*
import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
 
/**
 *
 * @date 2025/9/15
 * @author feiyu02
 */
@Service
class DataProdBaseServiceImpl(private val aopDbMapper: AopDbMapper) : DataProdBaseService {
 
    override fun getSceneInfo(queryOpt: QueryOpt): List<DPSceneInfo> {
        return QueryByCache.queryCache(
            cache = { return@queryCache null },
            calculate = {
                val res = mutableListOf<DPSceneInfo>()
                val objList = aopDbMapper.monitorobjectversionMapper.selectByExample(Example(Monitorobjectversion::class.java).apply {
                    createCriteria().andEqualTo("tid", queryOpt.topTaskId)
                })
                if (objList.isEmpty()) return@queryCache emptyList<DPSceneInfo>()
 
                val guidList = objList.map { it.sguid }
                val baseScene = aopDbMapper.scenseMapper.selectByExample(Example(Scense::class.java).apply {
                    createCriteria().andIn("guid", guidList)
                        .andEqualTo("typeid", queryOpt.sceneTypeId)
                    orderBy("typeid").orderBy("index")
                })
                baseScene.groupBy { it.typeid }.forEach { (typeid, sceneList) ->
                    when (typeid.toString()) {
                        Constant.SceneType.TYPE1.value -> {
                            val subScene = aopDbMapper.sceneConstructionSiteMapper.selectByExample(Example(SceneConstructionSite::class.java).apply {
                                createCriteria().andIn("sGuid", sceneList.map { it.guid })
                            })
                            sceneList.forEach {
                                val sub = subScene.find { sub-> sub.getsGuid() == it.guid }
                                res.add(DPSceneInfo().apply {
                                    this.scene = it
                                    this.subScene = sub
                                    this.status = sub?.csStatus
                                    this.statusBool = sub?.csStatus == "建设中"
                                    this.stage = sub?.siExtension1
                                })
                            }
                        }
                        Constant.SceneType.TYPE2.value -> {
                            val subScene = aopDbMapper.sceneWharfMapper.selectByExample(Example(SceneWharf::class.java).apply {
                                createCriteria().andIn("sGuid", sceneList.map { it.guid })
                            })
                            sceneList.forEach {
                                val sub = subScene.find { sub-> sub.getsGuid() == it.guid }
                                res.add(DPSceneInfo().apply {
                                    this.scene = it
                                    this.subScene = sub
                                    this.status = sub?.getwStatus()
                                    this.statusBool = sub?.getwStatus() == "营运中"
                                })
                            }
                        }
                        Constant.SceneType.TYPE3.value -> {
                            val subScene = aopDbMapper.sceneMixingPlantMapper.selectByExample(Example(SceneMixingPlant::class.java).apply {
                                createCriteria().andIn("sGuid", sceneList.map { it.guid })
                            })
                            sceneList.forEach {
                                val sub = subScene.find { sub-> sub.getsGuid() == it.guid }
                                res.add(DPSceneInfo().apply {
                                    this.scene = it
                                    this.subScene = sub
                                    this.status = sub?.mpStatus
                                    this.statusBool = sub?.mpStatus == "营运中"
                                })
                            }
                        }
                        Constant.SceneType.TYPE14.value -> {
                            val subScene = aopDbMapper.sceneStorageYardMapper.selectByExample(Example
                                (SceneStorageYard::class.java).apply {
                                createCriteria().andIn("sGuid", sceneList.map { it.guid })
                            })
                            sceneList.forEach {
                                val sub = subScene.find { sub-> sub.getsGuid() == it.guid }
                                res.add(DPSceneInfo().apply {
                                    this.scene = it
                                    this.subScene = sub
                                    this.status = sub?.syStatus
                                    this.statusBool = sub?.syStatus == "营运中"
                                })
                            }
                        }
                        else -> {
                            sceneList.forEach {
                                res.add(DPSceneInfo().apply {
                                    this.scene = it
                                })
                            }
                        }
                    }
                }
                return@queryCache res
            }
        )
    }
 
    override fun getEvaluateInfo(queryOpt: QueryOpt): List<DPEvaluateInfo> {
        return QueryByCache.queryCache(
            cache = { return@queryCache null },
            calculate = {
                val res = mutableListOf<DPEvaluateInfo>()
                val subtaskList = aopDbMapper.subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
                    createCriteria().andEqualTo("tguid", queryOpt.topTaskId)
                })
                if (subtaskList.isEmpty()) return@queryCache emptyList<DPEvaluateInfo>()
 
                val sceneList = aopDbMapper.scenseMapper.selectByExample(Example(Scense::class.java).apply {
                    createCriteria().andIn("guid", subtaskList.map { it.scenseid })
                        .andEqualTo("typeid", queryOpt.sceneTypeId)
                })
 
                val validSubtaskList = subtaskList.filter { sceneList.find { scene -> scene.guid == it.scenseid } != null }
 
                aopDbMapper.evaluationMapper.selectByExample(Example(Evaluation::class.java).apply {
                    createCriteria().andIn("stguid", validSubtaskList.map { it.stguid })
                }).forEach {
                    res.add(DPEvaluateInfo().apply {
                        val scene = sceneList.find { sce-> sce.guid == it.sguid }
                        index = scene?.index
                        subTask = validSubtaskList.find { sub-> sub.stguid == it.stguid }?.apply {
                            towncode = scene?.towncode
                            townname = scene?.townname
                        }
                        evaluate = it
                        val score = it.resultscorebef?.toIntOrNull() ?: -1
                        scoreLevel = when {
                            score in 0..39 -> Constant.EvaluationLevel.D.text
                            score in 40..89 -> Constant.EvaluationLevel.C.text
                            score in 90..99 -> Constant.EvaluationLevel.B.text
                            score >= 100 -> Constant.EvaluationLevel.A.text
                            else -> ""
                        }
                    })
                }
                res.sortBy { it.index }
                return@queryCache res
            },
        )
    }
 
    override fun getInspectionInfo(queryOpt: QueryOpt): List<DPInspectionInfo> {
        return QueryByCache.queryCache(
            cache = { return@queryCache null },
            calculate = {
                val res = mutableListOf<DPInspectionInfo>()
                val subtaskList = aopDbMapper.subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
                    createCriteria().andEqualTo("tguid", queryOpt.topTaskId)
                })
                if (subtaskList.isEmpty()) return@queryCache emptyList<DPInspectionInfo>()
 
                val sceneList = aopDbMapper.scenseMapper.selectByExample(Example(Scense::class.java).apply {
                    createCriteria().andIn("guid", subtaskList.map { it.scenseid })
                        .andEqualTo("typeid", queryOpt.sceneTypeId)
                })
                val validSubtaskList = subtaskList.filter { sceneList.find { scene -> scene.guid == it.scenseid } != null }
 
                val problemList = aopDbMapper.problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
                    createCriteria().andIn("stguid", validSubtaskList.map { it.stguid })
                })
 
                val problemTypeList = aopDbMapper.problemtypeMapper.selectByExample(Example(Problemtype::class.java)
                    .apply { createCriteria().andIn("guid", problemList.map { it.ptguid }) })
 
                validSubtaskList.forEach {
                    res.add(DPInspectionInfo().apply {
                        val scene = sceneList.find { sce-> sce.guid == it.scenseid }
                        index = scene?.index
                        subTask = it.apply {
                            towncode = scene?.towncode
                            townname = scene?.townname
                        }
                        problems = problemList.filter { problem-> problem.stguid == it.stguid }.map { problem->
                            val problemListVo = ProblemListVo()
                            BeanUtils.copyProperties(problem, problemListVo)
                            problemListVo.apply {
                                problemTypeList.find { type-> type.guid == problem.ptguid }?.let {
                                    typeid = it.typeid
                                    typename = it.typename
                                }
                            }
                            // TODO 媒体文件
                        }
                    })
                }
                res.sortBy { it.index }
                return@queryCache res
            },
        )
    }
 
    override fun getMonitorDataInfo(queryOpt: QueryOpt): List<DPMonitorDataInfo> {
        return QueryByCache.queryCache(
            cache = { return@queryCache null },
            calculate = {
                val res = mutableListOf<DPMonitorDataInfo>()
                val sceneIdList = aopDbMapper.monitorobjectversionMapper.selectByExample(Example(Monitorobjectversion::class.java).apply {
                    createCriteria().andEqualTo("tid", queryOpt.topTaskId)
                }).map { it.sguid }
                if (sceneIdList.isEmpty()) return@queryCache res
 
                val sceneList = aopDbMapper.scenseMapper.selectByExample(Example(Scense::class.java).apply {
                    createCriteria().andIn("guid", sceneIdList)
                        .andEqualTo("typeid", queryOpt.sceneTypeId)
                })
 
                aopDbMapper.dustDataResultMapper.selectByExample(Example(DustDataResult::class.java).apply {
                    createCriteria().andBetween("drTime", queryOpt.startTime, queryOpt.endTime)
                        .andIn("drSceneId", sceneList.map { it.guid })
                }).forEach {
                    res.add(DPMonitorDataInfo().apply {
                        scene = sceneList.find { scene -> scene.guid == it?.drSceneId }
                        data = it
                    })
                }
 
                return@queryCache res
            },
        )
    }
}