From 84569abda51ecf6c5549dec4cadee8d043422379 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期二, 30 九月 2025 09:33:28 +0800 Subject: [PATCH] 2025.9.30 --- src/main/kotlin/com/flightfeather/grid/service/impl/ClueQuestionServiceImpl.kt | 96 ++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 77 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/grid/service/impl/ClueQuestionServiceImpl.kt b/src/main/kotlin/com/flightfeather/grid/service/impl/ClueQuestionServiceImpl.kt index 07ceb87..4da2338 100644 --- a/src/main/kotlin/com/flightfeather/grid/service/impl/ClueQuestionServiceImpl.kt +++ b/src/main/kotlin/com/flightfeather/grid/service/impl/ClueQuestionServiceImpl.kt @@ -10,6 +10,7 @@ import com.google.gson.Gson import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional import org.springframework.web.multipart.MultipartFile import tk.mybatis.mapper.entity.Example import java.io.IOException @@ -24,6 +25,7 @@ override fun uploadQuestionAndImage(question: String, files: Array<MultipartFile>?): Boolean { val questionVo = Gson().fromJson(question, ClueQuestion::class.java) + if (questionVo.cqInternal == null) questionVo.cqInternal = false newQuestionUid(questionVo) val picPath = saveImageFile(questionVo, files) questionVo.cqFilePath = picPath @@ -33,16 +35,18 @@ return res == 1 } - override fun updateQuestionAndImage(question: String, deleteImg: String, files: Array<MultipartFile>): Boolean { + override fun updateQuestionAndImage(question: String, deleteImg: String?, files: Array<MultipartFile>?): Boolean { val questionVo = Gson().fromJson(question, ClueQuestion::class.java) val oldOne = clueQuestionMapper.selectByPrimaryKey(questionVo.cqId) ?: throw BizException("闂涓嶅瓨鍦�") if (oldOne.cqUploaded) throw BizException("闂宸蹭笂浼狅紝鏃犳硶淇敼") - deleteImageFile(questionVo, deleteImg) - val picPath = saveImageFile(questionVo, files) - if (questionVo.cqFilePath.isEmpty()) { - questionVo.cqFilePath = picPath - } else { - questionVo.cqFilePath += ";${picPath}" + if (deleteImg != null) deleteImageFile(questionVo, deleteImg) + if (files != null) { + val picPath = saveImageFile(questionVo, files) + if (questionVo.cqFilePath.isEmpty()) { + questionVo.cqFilePath = picPath + } else { + questionVo.cqFilePath += ";${picPath}" + } } questionVo.cqCreateTime = Date() val res = clueQuestionMapper.updateByPrimaryKeySelective(questionVo) @@ -53,6 +57,20 @@ val oldOne = clueQuestionMapper.selectByPrimaryKey(questionId) ?: throw BizException("闂涓嶅瓨鍦�") if (oldOne.cqUploaded) throw BizException("闂宸蹭笂浼狅紝鏃犳硶鍒犻櫎") deleteImageDirectory(oldOne) + + PageHelper.startPage<ClueQuestion>(1, 1) + clueQuestionMapper.selectByExample(Example(ClueQuestion::class.java).apply { + createCriteria().andEqualTo("cId", oldOne.cId) + orderBy("cqUid").desc() + })?.takeIf { it.isNotEmpty() }?.let { + val q = it[0] + if (q?.cqUid != oldOne.cqUid) { + q?.cqUid = oldOne.cqUid + clueQuestionMapper.updateByPrimaryKeySelective(q) + } + } + +// clueQuestionMapper.select val res = clueQuestionMapper.deleteByPrimaryKey(questionId) return res == 1 } @@ -62,13 +80,22 @@ if (question.cqId != null || question.cqUid != null) return // 鍚﹀垯鏍规嵁涓婁竴涓棶棰樼紪鍙烽『寤剁敓鎴愭柊缂栧彿 PageHelper.startPage<ClueQuestion>(1, 1) - val clues = clueQuestionMapper.selectByExample(Example(ClueQuestion::class.java).apply { - createCriteria().andEqualTo("cId", question.cId) + val clueQuestions = clueQuestionMapper.selectByExample(Example(ClueQuestion::class.java).apply { + createCriteria().andEqualTo("cId", question.cId).apply { + if (question.cqInternal == true) { + andEqualTo("cqInternal", true) + } else { + and( + createCriteria().orIsNull("cqInternal") + .orEqualTo("cqInternal", false) + ) + } + } orderBy("cqId").desc() }) - if (clues.isNotEmpty()) { - val clue = clues[0] - clue?.cqUid?.split("-")?.let { + if (clueQuestions.isNotEmpty()) { + val clueQuestion = clueQuestions[0] + clueQuestion?.cqUid?.split("-")?.let { question.cqUid = "${it[0]}-${it[1].toInt() + 1}" } } else { @@ -84,7 +111,13 @@ val suffix = file.originalFilename?.split(".")?.last() val fileName = UUID.randomUUID().toString() + "." + suffix val basePath = imgPath - val path = "clue/${question.cId}/${question.cqUid}/" + + // 瀵逛簬鍐呴儴绾跨储闂锛屽浘鐗囪矾寰勮鍋氬嚭鍖哄垎 + val path = if (question.cqInternal) { + "internal-clue/${question.cId}/${question.cqUid}/" + } else { + "clue/${question.cId}/${question.cqUid}/" + } picPath += if (picPath.isEmpty()) { "$path$fileName" } else { @@ -100,23 +133,37 @@ return picPath } + @Transactional override fun deleteImageFile(question: ClueQuestion, deleteImg: String) { try { deleteImg.split(";").forEach { val path = imgPath + it - FileUtil.deleteFile(path) + if (FileUtil.deleteFile(path)) { + question.cqFilePath = question.cqFilePath.replace(it, "") + question.cqFilePath = question.cqFilePath.replace(";;", ";") + } } } catch (e: IOException) { throw BizException("鍥剧墖鍒犻櫎澶辫触锛屾湇鍔″櫒IO鎿嶄綔閿欒") } - question.cqFilePath.replace(deleteImg, "") - if (question.cqFilePath.isNotEmpty() && question.cqFilePath.last() == ';') question.cqFilePath.removeSuffix(";") + question.cqFilePath = question.cqFilePath.removePrefix(";") + question.cqFilePath = question.cqFilePath.removeSuffix(";") } - override fun getClueQuestion(clueId: String): List<ClueQuestion?> { + override fun getClueQuestion(clueId: String, internal: Boolean?): List<ClueQuestion?> { val res = clueQuestionMapper.selectByExample(Example(ClueQuestion::class.java).apply { createCriteria().andEqualTo("cId", clueId) - orderBy("cqId") + .apply { + if (internal == true) { + andEqualTo("cqInternal", true) + } else { + and( + createCriteria().orIsNull("cqInternal") + .orEqualTo("cqInternal", false) + ) + } + } + orderBy("cqUid") }) return res } @@ -126,6 +173,11 @@ createCriteria().andEqualTo("cqUploaded", false).apply { questionIdList?.let { andIn("cqId", it) + // 鎺掗櫎鎺夊唴閮ㄧ嚎绱㈤棶棰� + and( + createCriteria().orIsNull("cqInternal") + .orEqualTo("cqInternal", false) + ) } } }).forEach { it?.let { clueHttpService.uploadQuestion(it) } } @@ -133,7 +185,13 @@ } private fun deleteImageDirectory(question: ClueQuestion) { - val path = imgPath + "clue/${question.cId}/${question.cqUid}/" + // 瀵逛簬鍐呴儴绾跨储闂锛屽浘鐗囪矾寰勮鍋氬嚭鍖哄垎 + val p = if (question.cqInternal) { + "internal-clue/${question.cId}/${question.cqUid}/" + } else { + "clue/${question.cId}/${question.cqUid}/" + } + val path = imgPath + p FileUtil.deleteDirectory(path) } } \ No newline at end of file -- Gitblit v1.9.3