feiyu02
2025-06-09 c17e9978745cfe6c983f3aff75c9182fffef32fd
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt
@@ -130,11 +130,11 @@
    //根据区县、场景类型、时间获取各个问题数量
    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)
//        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(areaVo)
    }
    override fun getChargeResult(areaVo: AreaVo): ChargeInfoVo {
@@ -373,7 +373,7 @@
        userId: String,
        userName: String,
    ): BaseResponse<String> {
        if (action !in 0..3) {
        if (action !in 0..5) {
            return BaseResponse(false, "非法的操作指令")
        }
        val p = problemlistMapper.selectByPrimaryKey(pId) ?: return BaseResponse(false, "问题不存在")
@@ -398,6 +398,14 @@
                        response.success = false
                        response.message = "问题提交还未审核,无法进行整改审核!"
                    }
                    4.toByte() -> {
                        response.success = false
                        response.message = "问题提交还未审核,无法进行撤回审核!"
                    }
                    5.toByte() -> {
                        response.success = false
                        response.message = "问题整改还未提交,无法进行撤回审核!"
                    }
                }
            } else if (extension3 == Constant.PROBLEM_CHECK_PASS || extension3 == Constant.PROBLEM_CHECK_FAIL) {
                when (action) {
@@ -419,6 +427,13 @@
                            response.message = "问题还未整改,无法进行整改审核!操作无效"
                        }
                    }
                    4.toByte() -> {
                        extension3 = Constant.PROBLEM_UNCHECKED
                    }
                    5.toByte() -> {
                        response.success = false
                        response.message = "问题整改还未审核,无法进行整改审核撤回操作!操作无效"
                    }
                }
            } else if (extension3 == Constant.CHANGE_UNCHECKED) {
                event = "在${subtask?.scensename}审核了一个整改"
@@ -431,6 +446,14 @@
                    }
                    2.toByte() -> extension3 = Constant.CHANGE_CHECK_PASS
                    3.toByte() -> extension3 = Constant.CHANGE_CHECK_FAIL
                    4.toByte() -> {
                        response.success = false
                        response.message = "问题整改还未审核,无法进行撤回审核!"
                    }
                    5.toByte() -> {
                        response.success = false
                        response.message = "问题提交已审核,并且已被整改。操作无效"
                    }
                }
            } else if (extension3 == Constant.CHANGE_CHECK_PASS || extension3 == Constant.CHANGE_CHECK_FAIL) {
                when (action) {
@@ -442,6 +465,13 @@
                    }
                    2.toByte() -> extension3 = Constant.CHANGE_CHECK_PASS
                    3.toByte() -> extension3 = Constant.CHANGE_CHECK_FAIL
                    4.toByte() -> {
                        response.success = false
                        response.message = "问题提交已审核,并且已被整改,无法进行问题审核撤销操作。操作无效"
                    }
                    5.toByte() -> {
                        extension3 = Constant.CHANGE_UNCHECKED
                    }
                }
            }
        }
@@ -459,20 +489,17 @@
    }
    override fun newProblem(problem: String, files: Array<MultipartFile>): BaseResponse<String> {
        val mapper = ObjectMapper()
        //json转object
        val problemVo = mapper.readValue(problem, object : TypeReference<ProblemVo>() {})
        val problemVo = ObjectMapper().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 = ProblemListVo.newPro(inspection, problemVo, scene)
        problemlistMapper.insert(problemlist)
        // 保存图片
        saveProFile(problemlist, inspection, scene, files)
        mediafileService.saveMediaFile(files) { MediaFileVo.newProFile(inspection, problemlist, scene) }
        //更新巡查信息的问题数
        if (inspection.problemcount != null) {
@@ -491,41 +518,26 @@
    override fun updateProblem(problem: ProblemListVo, deleteImg: List<String>, files: Array<MultipartFile>): String {
        problemRep.findOne(problem.guid) ?: throw BizException("该问题不存在")
        val inspection = inspectionMapper.selectByPrimaryKey(problem.guid) ?: throw BizException("巡查记录不存在")
        problemRep.update(problem)
        val inspection = inspectionMapper.selectByPrimaryKey(problem.iguid) ?: throw BizException("巡查记录不存在")
        val scene = scenseMapper.selectByPrimaryKey(inspection.sguid) ?: throw BizException("巡查记录对应场景不存在")
        saveProFile(problem, inspection, scene, files)
        mediafileService.saveMediaFile(files) { MediaFileVo.newProFile(inspection, problem, scene) }
        mediafileService.deleteList(deleteImg)
        return "success"
    }
    override fun saveProFile(
        problemlist: Problemlist,
        inspection: Inspection,
        scene: Scense,
        files: Array<MultipartFile>,
    ): Int {
        var res = 0
        // 保存图片
        for (image in files) {
            val mediaFile = MediaFileVo.newProFile(inspection, problemlist, scene)
            res += mediafileMapper.insert(mediaFile)
            val path = mediaFile.extension1
            val fileName = mediaFile.guid + ".jpg"
            val filePath = "${imgPath}/$path/"
            try {
                //调用文件保存方法
                FileUtil.uploadFile(image.bytes, filePath, fileName)
            } catch (e: Exception) {
                // TODO: handle exception
            }
        }
        return res
    }
    override fun changeProblem(problemId: String, files: Array<MultipartFile>): BaseResponse<String> {
        // 更新问题
        // 问题和问题图片合法性检查
        val p = problemlistMapper.selectByPrimaryKey(problemId) ?: return BaseResponse(false, "问题不存在")
        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, "问题不存在或已整改,无法重复整改")
        // 更新问题
        p.apply {
            ischanged = true
            changedtime = Date()
@@ -544,39 +556,41 @@
        }
        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) {
        mediafileService.saveMediaFile(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 = "${imgPath}/$path"
            try {
                //调用文件保存方法
                FileUtil.uploadFile(image.bytes, filePath, fileName)
            } catch (e: Exception) {
                println(e)
            }
        }
        return BaseResponse(true)
    }
    override fun updateChange(problemId: String, deleteImg: List<String>, files: Array<MultipartFile>): String {
        val p = problemRep.findOne(problemId) ?: throw BizException("该问题不存在")
        val mediaFiles = mediafileMapper.selectByExample(Example(Mediafile::class.java).apply {
            createCriteria().andEqualTo("businessguid", problemId)
                .andEqualTo("businesstypeid", 1)
                .andEqualTo("ischanged", true)
        })
        if (mediaFiles.isEmpty()) throw BizException("问题还未整改,无法修改整改")
        // 保存新的整改图片
        val m = mediaFiles[0]
        m.savetime = Date()
        mediafileService.saveMediaFile(files) {
            m.apply {
                guid = UUIDGenerator.generate16ShortUUID()
                description = p.problemname + " " + p.location + " 整改 " + UUIDGenerator.generateUUID(4) + ".jpg"
            }
        }
        mediafileService.deleteList(deleteImg)
        return "success"
    }
    override fun getBySubTask(stGuid: String, all: Boolean?): List<ProblemListVo> {
@@ -612,14 +626,13 @@
    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("未找到对应的巡查总任务")
//        areaVo.scensetypeid ?: throw BizException("缺少场景类型参数")
//        val task = taskRep.findOneTask(areaVo) ?: throw BizException("未找到对应的巡查总任务")
        val p = PageHelper.startPage<SceneProblemSummary>(page, per_page)
        val res = problemRep.selectSceneProSummary(task.tguid!!, areaVo.scensetypeid!!, areaVo.sort, sortBy)
        val res = problemRep.selectSceneProSummary(areaVo)
        return DataHead(p.pageNum, p.pages, p.total) to res
    }
}