| | |
| | | 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 |
| | |
| | | |
| | | 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 |
| | |
| | | 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 { |
| | |
| | | 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 { |
| | |
| | | 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) |
| | | .apply { |
| | | if (internal == true) { |
| | | andEqualTo("cqInternal", true) |
| | | } else { |
| | | and( |
| | | createCriteria().orIsNull("cqInternal") |
| | | .orEqualTo("cqInternal", false) |
| | | ) |
| | | } |
| | | } |
| | | orderBy("cqId") |
| | | }) |
| | | return res |
| | |
| | | createCriteria().andEqualTo("cqUploaded", false).apply { |
| | | questionIdList?.let { |
| | | andIn("cqId", it) |
| | | // 排除掉内部线索问题 |
| | | and( |
| | | createCriteria().orIsNull("cqInternal") |
| | | .orEqualTo("cqInternal", false) |
| | | ) |
| | | } |
| | | } |
| | | }).forEach { it?.let { clueHttpService.uploadQuestion(it) } } |
| | |
| | | } |
| | | |
| | | 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) |
| | | } |
| | | } |