feiyu02
2024-09-25 0516cba27e632f20efac2752787f38f0c87baafa
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt
@@ -459,20 +459,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 +488,25 @@
    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,41 +525,43 @@
        }
        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> {
        //根据子任务ID获取问题列表
        val problemListVo = mutableListOf<ProblemListVo>()