|
@@ -1,10 +1,9 @@
|
|
|
package com.cclotus.cms.service
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
|
|
|
-import com.cclotus.cms.domain.CmsPost
|
|
|
-import com.cclotus.cms.domain.CmsPostMeta
|
|
|
-import com.cclotus.cms.domain.CmsReviewForm
|
|
|
-import com.cclotus.cms.domain.CmsTermRelationships
|
|
|
+import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
|
|
|
+import com.cclotus.cms.domain.*
|
|
|
+import com.cclotus.cms.mapper.CmsPostAttachmentMapper
|
|
|
import com.cclotus.cms.mapper.CmsPostMapper
|
|
|
import com.cclotus.cms.mapper.CmsPostMetaMapper
|
|
|
import com.cclotus.cms.mapper.CmsTermRelationshipsMapper
|
|
@@ -42,6 +41,9 @@ class CmsPostService {
|
|
|
@Autowired
|
|
|
lateinit var cmsTermMetaService: CmsTermMetaService
|
|
|
|
|
|
+ @Autowired
|
|
|
+ lateinit var cmsPostAttachmentMapper: CmsPostAttachmentMapper
|
|
|
+
|
|
|
/**
|
|
|
* 查询内容列表
|
|
|
* @param termAlias 分类别名
|
|
@@ -112,8 +114,7 @@ class CmsPostService {
|
|
|
.eq(!post.status.isNullOrBlank(), "status", post.status)
|
|
|
.eq(post.topStatus != null, "top_status", post.topStatus)
|
|
|
.eq(!post.visible.isNullOrBlank(), "visible", post.visible)
|
|
|
- .eq(!post.createBy.isNullOrBlank(), "create_by", post.createBy)
|
|
|
- .orderByDesc("top_status", "create_time")
|
|
|
+ .eq(!post.createBy.isNullOrBlank(), "create_by", post.createBy).orderByDesc("top_status", "create_time")
|
|
|
|
|
|
// 查询post主表,并处理分页
|
|
|
pageParam?.let {
|
|
@@ -227,6 +228,18 @@ class CmsPostService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 插入内容附件信息
|
|
|
+ post.urls?.split(",")?.forEach { url ->
|
|
|
+ CmsPostAttachment().apply {
|
|
|
+ this.url = url
|
|
|
+ this.postId = cmsPost.postId
|
|
|
+ }.also {
|
|
|
+ if (cmsPostAttachmentMapper.insert(it) != 1) {
|
|
|
+ throw ServiceException("插入内容附件失败", 500)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return 1
|
|
|
}
|
|
|
|
|
@@ -277,6 +290,11 @@ class CmsPostService {
|
|
|
updatePostMetas(postId, it)
|
|
|
}
|
|
|
|
|
|
+ // 更新内容附件列表
|
|
|
+ post.urls?.split(",")?.let {
|
|
|
+ updataPostAttachments(postId, it)
|
|
|
+ }
|
|
|
+
|
|
|
// 更新发布内容
|
|
|
entity.apply {
|
|
|
BeanUtils.copyProperties(post, this, "origin")
|
|
@@ -294,10 +312,12 @@ class CmsPostService {
|
|
|
@Transactional
|
|
|
fun deleteByIds(postIds: Array<Int>): Int {
|
|
|
if (postIds.isEmpty()) return 0
|
|
|
-
|
|
|
+ // 删除指定内容的配置信息
|
|
|
cmsPostMetaMapper.delete(QueryWrapper<CmsPostMeta>().`in`("post_id", postIds.toList()))
|
|
|
-
|
|
|
+ // 删除内容与栏目的关联
|
|
|
cmsTermRelationshipsMapper.deleteObjectIds(postIds.toList())
|
|
|
+ // 删除内容的附件信息
|
|
|
+ cmsPostAttachmentMapper.delete(QueryWrapper<CmsPostAttachment>().`in`("post_id", postIds.toList()))
|
|
|
|
|
|
return cmsPostMapper.deleteBatchIds(postIds.toList())
|
|
|
}
|
|
@@ -392,4 +412,43 @@ class CmsPostService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 更新内容附件列表
|
|
|
+ private fun updataPostAttachments(postId: Int, urls: List<String>) {
|
|
|
+ // 获取内容附件列表
|
|
|
+ val attachments = cmsPostAttachmentMapper.selectList(
|
|
|
+ KtQueryWrapper(CmsPostAttachment()).eq(
|
|
|
+ CmsPostAttachment::postId, postId
|
|
|
+ )
|
|
|
+ )
|
|
|
+ val attachmentsUrls = attachments.map { it.url }.toList()
|
|
|
+
|
|
|
+ // 计算待删除栏目类别列表,和待插入栏目类别列表
|
|
|
+ val deleteList = mutableListOf<CmsPostAttachment>()
|
|
|
+ val addList = mutableListOf<CmsPostAttachment>()
|
|
|
+ attachments.forEach {
|
|
|
+ if (!urls.contains(it.url)) {
|
|
|
+ deleteList.add(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ urls.forEach {
|
|
|
+ if (!attachmentsUrls.contains(it)) {
|
|
|
+ addList.add(CmsPostAttachment().apply {
|
|
|
+ this.postId = postId
|
|
|
+ this.url = it
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ addList.forEach {
|
|
|
+ cmsPostAttachmentMapper.insert(it)
|
|
|
+ }
|
|
|
+
|
|
|
+ deleteList.map { it.attachmentId }.run {
|
|
|
+ cmsPostAttachmentMapper.deleteBatchIds(this)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|