feiyu02
2024-04-25 0392c333ed3d987cb2ab3dac4e1a972cff405f21
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
package cn.flightfeather.supervision.lightshare.service.impl
 
import cn.flightfeather.supervision.common.exception.BizException
import cn.flightfeather.supervision.domain.ds1.entity.Problemlist
import cn.flightfeather.supervision.domain.ds1.entity.Scense
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.common.utils.FileUtil
import cn.flightfeather.supervision.common.utils.UUIDGenerator
import cn.flightfeather.supervision.domain.ds1.entity.Mediafile
import cn.flightfeather.supervision.domain.ds1.entity.Subtask
import cn.flightfeather.supervision.domain.ds1.mapper.*
import cn.flightfeather.supervision.domain.ds1.repository.ProblemRep
import cn.flightfeather.supervision.domain.ds1.repository.SubTaskRep
import cn.flightfeather.supervision.domain.ds1.repository.TaskRep
import cn.flightfeather.supervision.lightshare.service.MediafileService
import cn.flightfeather.supervision.lightshare.service.ProblemlistService
import cn.flightfeather.supervision.lightshare.service.TaskService
import cn.flightfeather.supervision.lightshare.vo.*
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.github.pagehelper.PageHelper
import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Service
import org.springframework.web.multipart.MultipartFile
import tk.mybatis.mapper.entity.Example
import tk.mybatis.mapper.util.StringUtil
import java.text.SimpleDateFormat
import javax.annotation.Resource
import java.math.BigDecimal
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.*
 
 
@Service
class ProblemlistServiceImpl(
    val problemlistMapper: ProblemlistMapper,
    val inspectionMapper: InspectionMapper,
    val mediafileMapper: MediafileMapper,
    private val taskRep: TaskRep,
    private val subTaskRep: SubTaskRep,
    private val problemRep: ProblemRep,
) : ProblemlistService {
 
    @Resource
    lateinit var scenseMapper: ScenseMapper
 
    @Resource
    lateinit var problemtypeMapper: ProblemtypeMapper
 
    @Resource
    lateinit var taskMapper: TaskMapper
 
    @Resource
    lateinit var taskService: TaskService
 
    @Resource
    lateinit var mediafileService: MediafileService
 
    override fun getByTopTask(tguid: String): List<ProblemlistVo> {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }
 
    //根据场景id和时间获取对应顶层任务下的所有问题
    override fun getProblemByScene(sceneId: String, date: String): List<ProblemlistVo> {
        val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        val date1 = simpleDateFormat.parse(date)
        val scene = scenseMapper.selectByPrimaryKey(sceneId)
        val district = scene.districtcode
        val taskVolist = taskService.getByDistrictCode(district!!, date1)
        val problemlistVolistTemp1 = mutableListOf<ProblemlistVo>()
        if (!taskVolist.isEmpty()) {
            val problemlists = (problemlistMapper.getProblemByScene(sceneId, taskVolist[0].tguid!!))
            problemlists.forEach {
                // 限制企业查看未审核的问题
                if (it.extension3 != Constant.PROBLEM_UNCHECKED && it.extension3 != Constant.PROBLEM_CHECK_FAIL) {
                    val problemVo = ProblemlistVo();
                    BeanUtils.copyProperties(it, problemVo)
                    problemlistVolistTemp1.add(problemVo)
                }
            }
            problemlistVolistTemp1.forEach {
                if (it.ptguid != null) {
                    val tmp1 = problemtypeMapper.selectByPrimaryKey(it.ptguid)
                    if (tmp1 != null) {
                        it.typeid = tmp1.typeid
                        it.typename = tmp1.typename
                    }
                }
                val mediafileVo = mediafileService.findByBusinessGUID(it.guid!!)
                //判断是否有媒体资料
                if (!mediafileVo.isEmpty()) {
                    //赋值
                    it.mediafileList = mediafileVo
                } else {
                    it.mediafileList = mutableListOf()
                }
            }
        }
        return problemlistVolistTemp1
    }
 
    //获取某顶层任务下,某个场景下的问题整改情况
    override fun getStatisticalResultById(topTaskId: String, sceneTypeId: String): List<StatisticsVo> {
        val map = problemlistMapper.getStatisticalResultById(topTaskId, sceneTypeId)
        val statisticsVos = mutableListOf<StatisticsVo>()
        map.forEach {
            if (!it.isEmpty() && it.get("name") != null) {
                val statisticsVo = StatisticsVo()
                statisticsVo.name = it.get("name").toString()
                try {
                    statisticsVo.count = it.get("count").toString().toInt()
                } catch (e: Exception) {
                }
                try {
                    statisticsVo.changeCount = it.get("changeCount").toString().toInt()
                } catch (e: Exception) {
                }
                statisticsVos.add(statisticsVo)
            }
        }
 
        return statisticsVos
    }
 
    //根据区县、场景类型、时间获取各个问题数量
    override fun getStatisticalResult(areaVo: AreaVo): List<StatisticsVo> {
        val districtcode = areaVo.districtcode
        val sceneType = areaVo.scensetypeid
        val startTime = areaVo.starttime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
        val endTime = areaVo.endtime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
        return problemlistMapper.getStatisticalResult(districtcode, startTime, endTime, sceneType, areaVo.sceneId)
    }
 
    override fun getChargeResult(areaVo: AreaVo): ChargeInfoVo {
//        val example = Example(Task::class.java)
//        example.createCriteria()
//                .andEqualTo("levelnum", "2")
//                .andLessThanOrEqualTo("starttime", areaVo.starttime)
//                .andGreaterThanOrEqualTo("endtime", areaVo.endtime)
//                .andEqualTo("districtcode", areaVo.districtcode)
        val chargeInfoVo = ChargeInfoVo()
        val sTime = areaVo.starttime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
        val eTime = areaVo.endtime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
        val sql =
            "select T_GUID, T_Name from tm_t_task where TS_GUID IS NULL and T_StartTime <= '" + sTime + "' and T_EndTime" +
                    " >= '" + eTime + "' and T_DistrictCode = '" + areaVo.districtcode + "'"
 
        val maps1 = taskMapper.selectSE(sql)
        var topTaskId = String()
        var topTaskName = String()
        if (maps1.isNotEmpty()) {
            topTaskName = maps1[0].get("T_Name").toString()
            topTaskId = maps1.get(0).get("T_GUID").toString()
            chargeInfoVo.topTaskId = topTaskId
            chargeInfoVo.topTaskName = topTaskName
        }
        val maps2 = problemlistMapper.getChangeResult(topTaskId, areaVo.scensetypeid)
        maps2.forEach {
            val sceneInfo = ChargeInfoVo.SceneInfo()
            sceneInfo.id = it["id"].toString()
            sceneInfo.name = it.get("name").toString()
            sceneInfo.type = it.get("type").toString()
            try {
                sceneInfo.problemCount = it.get("problemCount").toString().toInt()
            } catch (e: Exception) {
            }
            try {
                sceneInfo.changeCount = it.get("changeCount").toString().toInt()
            } catch (e: Exception) {
            }
            chargeInfoVo.sceneInfos.add(sceneInfo)
        }
        val scoreInfo1 = ChargeInfoVo.ScoreInfo()
        val scoreInfo2 = ChargeInfoVo.ScoreInfo()
        val scoreInfo3 = ChargeInfoVo.ScoreInfo()
        val scoreInfo4 = ChargeInfoVo.ScoreInfo()
        scoreInfo1.type = "规范"
        scoreInfo2.type = "基本规范"
        scoreInfo3.type = "不规范"
        scoreInfo4.type = "严重不规范"
        val maps3 = problemlistMapper.getScoreResult(topTaskId, areaVo.scensetypeid)
        maps3.forEach {
            if (it.isNotEmpty()) {
                var curScore = -1
                if (it.get("scoreAft") != null) {
                    curScore = it.get("scoreAft").toString().toInt()
                } else if (it.get("scoreBef") != null) {
                    curScore = it.get("scoreBef").toString().toInt()
                }
                if (curScore >= 100) {
                    scoreInfo1.count++
                } else if (curScore >= 78 && curScore < 100) {
                    scoreInfo2.count++
                } else if (curScore >= 54 && curScore < 78) {
                    scoreInfo3.count++
                } else if (curScore < 54 && curScore >= 0) {
                    scoreInfo4.count++
                }
            }
        }
        chargeInfoVo.scoreInfos.add(scoreInfo1)
        chargeInfoVo.scoreInfos.add(scoreInfo2)
        chargeInfoVo.scoreInfos.add(scoreInfo3)
        chargeInfoVo.scoreInfos.add(scoreInfo4)
 
        return chargeInfoVo
    }
 
    //根据地域获取问题
    override fun getByArea(areaVo: AreaVo): List<ProblemlistVo> {
        val problemlist = mutableListOf<ProblemlistVo>()
//        val tmpproblemlsit = mutableListOf<Problemlist>()
        val example = Example(Scense::class.java)
        val criteria = example.createCriteria()
        //根据区域和场景类型获取指定场景
        if (StringUtil.isNotEmpty(areaVo.provincecode))
            criteria.andEqualTo("provincecode", areaVo.provincecode)
        if (StringUtil.isNotEmpty(areaVo.citycode))
            criteria.andEqualTo("citycode", areaVo.citycode)
        if (StringUtil.isNotEmpty(areaVo.districtcode))
            criteria.andEqualTo("districtcode", areaVo.districtcode)
        if (StringUtil.isNotEmpty(areaVo.towncode))
            criteria.andEqualTo("towncode", areaVo.towncode)
        criteria.andEqualTo("typeid", areaVo.scensetypeid)
        val result1 = scenseMapper.selectByExample(example)
        if (result1.isNotEmpty()) {
            result1.forEach {
                val tmpexample = Example(Problemlist::class.java)
                val tmpcriteria = tmpexample.createCriteria()
                //对于确定的每个场景,根据时间查询问题
                tmpcriteria.andEqualTo("sguid", it.guid)
                tmpcriteria.andBetween("time", areaVo.starttime, areaVo.endtime)
                val tmp = problemlistMapper.selectByExample(tmpexample)
                tmp.forEach {
                    val problem = ProblemlistVo();
                    BeanUtils.copyProperties(it, problem)
                    problemlist.add(problem)
                }
            }
        }
        problemlist.forEach {
            if (it.ptguid != null) {
                val tmp1 = problemtypeMapper.selectByPrimaryKey(it.ptguid)
                if (tmp1 != null) {
                    it.typeid = tmp1.typeid
                    it.typename = tmp1.typename
                }
            }
        }
 
        return problemlist
    }
 
    //根据巡查ID获取问题
    override fun findByInspectionID(inspectionID: String): List<ProblemlistVo> {
        val problemlistVoList = mutableListOf<ProblemlistVo>()
        val problemlist = Problemlist()
        problemlist.iguid = inspectionID
        val problemlists = problemlistMapper.select(problemlist)
        problemlists.forEach {
            val problemlistVo = ProblemlistVo()
            if (it.remark != Constant.PROBLEM_DELETED) {
                BeanUtils.copyProperties(it, problemlistVo)
                problemlistVoList.add(problemlistVo)
            }
        }
        //排序
        problemlistVoList.sortBy { it.time }
        return problemlistVoList
    }
 
    //新增一个问题
    override fun addProblem(problemlistVo: ProblemlistVo) {
        val probemlist = Problemlist()
        BeanUtils.copyProperties(problemlistVo, probemlist)
        problemlistMapper.insert(probemlist)
    }
 
    //根据子任务ID查询问题
    override fun findBySubtaskId(subTaskID: String): List<ProblemlistVo> {
        val problemlistVoList = mutableListOf<ProblemlistVo>()
        val problemlist = Problemlist()
        problemlist.stguid = subTaskID
        val problemlists = problemlistMapper.select(problemlist)
        problemlists.forEach {
            val problemlistVo = ProblemlistVo()
            BeanUtils.copyProperties(it, problemlistVo)
            problemlistVoList.add(problemlistVo)
        }
        return problemlistVoList
    }
 
    //根据问题ID获取一个问题
    override fun findByID(id: String): ProblemlistVo {
        val problemlistVo = ProblemlistVo()
        val problemlist = problemlistMapper.selectByPrimaryKey(id)
        if (problemlist != null) {
            BeanUtils.copyProperties(problemlist, problemlistVo)
        }
        return problemlistVo
    }
 
    override fun findAll(): MutableList<Problemlist> = problemlistMapper.selectAll()
 
    override fun save(problemlist: Problemlist): Int = problemlistMapper.insert(problemlist)
 
    override fun update(problemlist: Problemlist): Int = problemlistMapper.updateByPrimaryKey(problemlist)
 
    override fun delete(id: String): Int = problemlistMapper.deleteByPrimaryKey(id)
 
    override fun setDeleteStatus(id: String): BaseResponse<Int> {
        val p = problemlistMapper.selectByPrimaryKey(id)
 
        return when {
            p.ischanged == true -> BaseResponse(false, "问题已整改,无法删除", data = 0)
            p.extension3 != Constant.PROBLEM_UNCHECKED -> BaseResponse(false, "问题已审核,无法删除", data = 0)
            else -> {
                // 2021/4/25 将原来的添加删除状态改为直接删除
//                p.remark = Constant.PROBLEM_DELETED
                val i = problemlistMapper.deleteByPrimaryKey(id)
                mediafileMapper.deleteByExample(Example(Mediafile::class.java).apply {
                    createCriteria().andEqualTo("businessguid", id)
                })
                //更新巡查信息中的问题数量
                val inspection = inspectionMapper.selectByPrimaryKey(p.iguid)
                if (inspection.problemcount != null && inspection.problemcount!! > 0) {
                    inspection.problemcount = inspection.problemcount!! - 1
                    inspectionMapper.updateByPrimaryKey(inspection)
                }
                BaseResponse(true, "问题删除成功", data = i)
            }
        }
    }
 
    //    @Override
////    public List<MonthProblemVo> findMonthProblemById(taskId: String, sceneId: String)
////    {
 
    override fun findMonthProblemById(taskId: String, sceneId: Int?): List<MonthProblemVo> {
        val monthProblemlistVoList = mutableListOf<MonthProblemVo>()
        var map = problemlistMapper.findMonthProblemById(taskId, sceneId)
        map.forEach { m ->
            val monthProblemVo = MonthProblemVo()
            monthProblemVo.townCode =
                if (m.get("towncode") != null) BigDecimal(m.get("towncode").toString()).toString() else null
            monthProblemVo.townName = if (m.get("townname") != null) m.get("townname").toString() else null
            monthProblemVo.scenetype = if (m.get("scenetype") != null) m.get("scenetype").toString().toInt() else null
            monthProblemVo.scenetypename =
                if (m.get("scenetypename") != null) m.get("scenetypename").toString() else null
            monthProblemVo.totalscenecount =
                if (m.get("totalscenecount") != null) m.get("totalscenecount").toString().toInt() else null
            monthProblemVo.problemscenes =
                if (m.get("problemscenes") != null) m.get("problemscenes").toString().toInt() else null
            monthProblemVo.totalproblems =
                if (m.get("totalproblems") != null) m.get("totalproblems").toString().toInt() else null
            monthProblemVo.changedproblems =
                if (m.get("changedproblems") != null) m.get("changedproblems").toString().toInt() else null
            monthProblemlistVoList.add(monthProblemVo)
        }
        return monthProblemlistVoList;
    }
 
    override fun check(
        pId: String,
        action: Byte,
        remark: String,
        userId: String,
        userName: String,
    ): BaseResponse<String> {
        if (action !in 0..3) {
            return BaseResponse(false, "非法的操作指令")
        }
        val p = problemlistMapper.selectByPrimaryKey(pId) ?: return BaseResponse(false, "问题不存在")
        val response = BaseResponse<String>(true)
 
        p.apply {
            this.remark = userName
            if (extension3 == Constant.PROBLEM_UNCHECKED) {
                when (action) {
                    0.toByte() -> extension3 = Constant.PROBLEM_CHECK_PASS
                    1.toByte() -> extension3 = Constant.PROBLEM_CHECK_FAIL
                    2.toByte(),
                    3.toByte(),
                    -> {
                        response.success = false
                        response.message = "问题提交还未审核,无法进行整改审核!"
                    }
                }
            } else if (extension3 == Constant.PROBLEM_CHECK_PASS || extension3 == Constant.PROBLEM_CHECK_FAIL) {
                when (action) {
                    0.toByte() -> extension3 = Constant.PROBLEM_CHECK_PASS
                    1.toByte() -> extension3 = Constant.PROBLEM_CHECK_FAIL
                    2.toByte(),
                    3.toByte(),
                    -> {
                        if (ischanged == true && extension3 == Constant.PROBLEM_CHECK_PASS) {
                            response.success = true
                            extension3 = if (action == 2.toByte()) {
                                Constant.CHANGE_CHECK_PASS
                            } else {
                                Constant.CHANGE_CHECK_FAIL
                            }
                        } else {
                            response.success = false
                            response.message = "问题还未整改,无法进行整改审核!操作无效"
                        }
                    }
                }
            } else if (extension3 == Constant.CHANGE_UNCHECKED) {
                when (action) {
                    0.toByte(),
                    1.toByte(),
                    -> {
                        response.success = false
                        response.message = "问题提交已审核,并且已被整改。操作无效"
                    }
                    2.toByte() -> extension3 = Constant.CHANGE_CHECK_PASS
                    3.toByte() -> extension3 = Constant.CHANGE_CHECK_FAIL
                }
            } else if (extension3 == Constant.CHANGE_CHECK_PASS || extension3 == Constant.CHANGE_CHECK_FAIL) {
                when (action) {
                    0.toByte(),
                    1.toByte(),
                    -> {
                        response.success = false
                        response.message = "问题提交已审核,并且已被整改。操作无效"
                    }
                    2.toByte() -> extension3 = Constant.CHANGE_CHECK_PASS
                    3.toByte() -> extension3 = Constant.CHANGE_CHECK_FAIL
                }
            }
        }
 
        if (response.success) {
            val r = problemlistMapper.updateByPrimaryKey(p)
            if (r != 1) {
                response.success = false
                response.message = "问题更新失败!"
            }
        }
        return response
    }
 
    override fun newProblem(problem: String, files: Array<MultipartFile>): BaseResponse<String> {
        val mapper = ObjectMapper()
 
        //json转object
        val problemVo = mapper.readValue(problem, object : TypeReference<ProblemVo>() {})
 
        // 保存问题
        val inspection = inspectionMapper.selectByPrimaryKey(problemVo.insGuid) ?: return BaseResponse(false, "巡查记录不存在")
        val scene = scenseMapper.selectByPrimaryKey(inspection.sguid) ?: return BaseResponse(false, "巡查记录对应场景不存在")
 
        val problemlist = Problemlist().apply {
            guid = UUIDGenerator.generate16ShortUUID()
            iguid = inspection.guid
            stguid = inspection.stguid
            sguid = inspection.sguid
            sensename = inspection.scensename
            senseaddress = inspection.scenseaddress
            ptguid = problemVo.ptGuid
            problemname = problemVo.proName
            longitude = problemVo.longitude ?: scene.longitude
            latitude = problemVo.latitude ?: scene.latitude
            locationid = problemVo.locationId
            location = problemVo.location
            time = Date()
            isrechecked = false
            ischanged = false
            advise = problemVo.advice
            extension3 = Constant.PROBLEM_UNCHECKED
        }
        problemlistMapper.insert(problemlist)
 
        // 保存图片
        val now = LocalDateTime.now()
        for (image in files) {
            val mediaFile = Mediafile().apply {
                guid = UUIDGenerator.generate16ShortUUID()
                iguid = inspection.guid
                businessguid = problemlist.guid
                longitude = problemlist.longitude
                latitude = problemlist.latitude
                address = problemlist.senseaddress
                filetype = 1
                businesstype = "问题"
                businesstypeid = 1
                path =
                    "FlightFeather/Photo/" + scene.districtname + "/" + now.year + "年" + now.monthValue + "月/" + now.monthValue + "月" + now.dayOfMonth + "日/" + scene.name + "/"
                description =
                    problemlist.problemname + " " + problemlist.location + " " + UUIDGenerator.generateUUID(4) + ".jpg"
                savetime = Date()
                ischanged = false
                extension1 =
                    scene.citycode + "/" + scene.districtcode + "/" + now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "/" + scene.guid + "/"
                remark = "已上传"
            }
            mediafileMapper.insert(mediaFile)
 
            val path = mediaFile.extension1
            val fileName = mediaFile.guid + ".jpg"
//            val filePath = "E:\\work\\第三方监管app\\自动评分\\餐饮\\"
            val filePath = "${Constant.DEFAULT_FILE_PATH}/images/$path/"
            try {
                //调用文件保存方法
                FileUtil.uploadFile(image.bytes, filePath, fileName)
            } catch (e: Exception) {
                // TODO: handle exception
            }
        }
 
        //更新巡查信息的问题数
        if (inspection.problemcount != null) {
            inspection.problemcount = inspection.problemcount!! + 1
            inspectionMapper.updateByPrimaryKey(inspection)
        }
 
        return BaseResponse(true)
    }
 
    override fun changeProblem(problemId: String, files: Array<MultipartFile>): BaseResponse<String> {
        // 更新问题
        val p = problemlistMapper.selectByPrimaryKey(problemId) ?: return BaseResponse(false, "问题不存在")
        p.apply {
            ischanged = true
            changedtime = Date()
            extension3 = Constant.CHANGE_UNCHECKED
            val today = LocalDate.now()
            val pTime = LocalDateTime.ofInstant(time?.toInstant(), ZoneId.systemDefault()).toLocalDate()
            changecatalog = if (p.extension1 != null) {
                if (today.isAfter(pTime)) {
                    Constant.PROMISE_CHANGE
                } else {
                    Constant.LOCAL_CHANGE
                }
            } else {
                Constant.UN_PROMISE_CHANGE
            }
        }
        problemlistMapper.updateByPrimaryKey(p)
 
        // 保存图片
        val now = LocalDateTime.now()
        val mediaFiles = mediafileMapper.selectByExample(Example(Mediafile::class.java).apply {
            createCriteria().andEqualTo("businessguid", p.guid)
                .andEqualTo("businesstypeid", 1)
                .andEqualTo("ischanged", false)
        })
        if (mediaFiles.isEmpty()) return BaseResponse(false, "场景问题数量为0,无法整改")
        val m = mediaFiles[0]
        m.path = m.path + "整改/"
        m.savetime = Date()
        m.ischanged = true
 
        for (image in files) {
            m.apply {
                guid = UUIDGenerator.generate16ShortUUID()
                description = p.problemname + " " + p.location + " 整改 " + UUIDGenerator.generateUUID(4) + ".jpg"
            }
            mediafileMapper.insert(m)
 
            val path = m.extension1
            val fileName = m.guid + ".jpg"
//            val filePath = "E:\\work\\第三方监管app\\自动评分\\餐饮\\"
            val filePath = "${Constant.DEFAULT_FILE_PATH}/images/$path"
            try {
                //调用文件保存方法
                FileUtil.uploadFile(image.bytes, filePath, fileName)
            } catch (e: Exception) {
                println(e)
            }
        }
 
        return BaseResponse(true)
    }
 
    override fun getBySubTask(stGuid: String, all: Boolean?): List<ProblemlistVo> {
        //根据子任务ID获取问题列表
        val problemListVo = mutableListOf<ProblemlistVo>()
        if (all == false) {
            //去除未审核以及审核不通过的问题
            findBySubtaskId(stGuid).forEach {
                if (it.extension3 != Constant.PROBLEM_UNCHECKED && it.extension3 != Constant.PROBLEM_CHECK_FAIL) {
                    problemListVo.add(it)
                }
            }
        } else {
            problemListVo.addAll(findBySubtaskId(stGuid))
        }
        //根据每个问题,获取媒体文件
        problemListVo.forEach {
            val mediafileVo = mediafileService.findByBusinessGUID(it.guid!!)
            //判断是否有媒体资料
            if (mediafileVo.isNotEmpty()) {
                //赋值
                it.mediafileList = mediafileVo
            }
        }
        return problemListVo
    }
 
    override fun getSceneByProType(areaVo: AreaVo, pType: String): List<Subtask?> {
        areaVo.scensetypeid ?: throw BizException("缺少场景类型参数")
        val task = taskRep.findOneTask(areaVo) ?: throw BizException("未找到对应的巡查总任务")
        return subTaskRep.findSubtasks(task.tguid!!, areaVo.scensetypeid!!, pType)
    }
 
    override fun getSceneProSummary(
        areaVo: AreaVo,
        sortBy: String,
        page: Int,
        per_page: Int,
    ): Pair<DataHead?, List<SceneProblemSummary>?> {
        areaVo.scensetypeid ?: throw BizException("缺少场景类型参数")
        val task = taskRep.findOneTask(areaVo) ?: throw BizException("未找到对应的巡查总任务")
        val p = PageHelper.startPage<SceneProblemSummary>(page, per_page)
        val res = problemRep.getSceneProSummary(task.tguid!!, areaVo.scensetypeid!!, areaVo.sort, sortBy)
        return DataHead(p.pageNum, p.pages, p.total) to res
    }
}