diff --git a/src/main/java/com/kexue/skills/controller/CmsContentController.java b/src/main/java/com/kexue/skills/controller/CmsContentController.java index 148df7a..5143f37 100644 --- a/src/main/java/com/kexue/skills/controller/CmsContentController.java +++ b/src/main/java/com/kexue/skills/controller/CmsContentController.java @@ -2,6 +2,7 @@ package com.kexue.skills.controller; import com.github.pagehelper.PageInfo; import com.kexue.skills.annotation.RequireAuth; +import com.kexue.skills.common.Assert; import com.kexue.skills.common.CommonResult; import com.kexue.skills.entity.CmsContent; import com.kexue.skills.entity.base.IdDto; @@ -289,7 +290,7 @@ public class CmsContentController { /** * 获取CmsContent的content字段内容 * - * @param QueryContentDto 包含contentId和languageType的DTO对象 + * @param queryContentDto 包含contentId和languageType的DTO对象 * @return content或contentEn字段的内容 */ @PostMapping("/getContent") diff --git a/src/main/java/com/kexue/skills/service/impl/CmsContentServiceImpl.java b/src/main/java/com/kexue/skills/service/impl/CmsContentServiceImpl.java index e9cd790..3000678 100644 --- a/src/main/java/com/kexue/skills/service/impl/CmsContentServiceImpl.java +++ b/src/main/java/com/kexue/skills/service/impl/CmsContentServiceImpl.java @@ -3,6 +3,7 @@ package com.kexue.skills.service.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.github.pagehelper.util.StringUtil; +import com.kexue.skills.common.Assert; import com.kexue.skills.common.LoginUserCacheUtil; import com.kexue.skills.entity.CmsContent; import com.kexue.skills.entity.CmsContentView; @@ -218,6 +219,7 @@ public class CmsContentServiceImpl implements CmsContentService { */ @Override public CmsContent queryById(Long contentId) { + Assert.notNull(contentId, "内容ID不能为空"); CmsContent content = this.cmsContentMapper.queryById(contentId); if (content == null) { return null; @@ -265,6 +267,7 @@ public class CmsContentServiceImpl implements CmsContentService { * @return 实例对象 */ public CmsContent queryByIdWithPermission(Long contentId, Long userId) { + Assert.notNull(contentId, "内容ID不能为空"); CmsContent content = this.cmsContentMapper.queryById(contentId); if (content == null) { return null; @@ -324,6 +327,7 @@ public class CmsContentServiceImpl implements CmsContentService { */ @Override public CmsContent update(CmsContent cmsContent) { + Assert.notNull(cmsContent.getContentId(), "内容ID不能为空"); // 设置更新时间 cmsContent.setUpdateTime(new Date()); // 更新数据 @@ -344,6 +348,7 @@ public class CmsContentServiceImpl implements CmsContentService { */ @Override public int updateAuditStatus(Long contentId, Integer auditStatus, Long reviewerId, String reviewerName, String auditComment, String updateBy) { + Assert.notNull(contentId, "内容ID不能为空"); return this.cmsContentMapper.updateAuditStatus(contentId, auditStatus, reviewerId, reviewerName, auditComment, updateBy); } @@ -358,6 +363,7 @@ public class CmsContentServiceImpl implements CmsContentService { */ @Override public int updatePublishStatus(Long contentId, Integer publishStatus, String publishTime, String updateBy) { + Assert.notNull(contentId, "内容ID不能为空"); return this.cmsContentMapper.updatePublishStatus(contentId, publishStatus, publishTime, updateBy); } @@ -369,6 +375,7 @@ public class CmsContentServiceImpl implements CmsContentService { */ @Override public int increaseViewCount(Long contentId) { + Assert.notNull(contentId, "内容ID不能为空"); // 增加阅读量 int result = this.cmsContentMapper.increaseViewCount(contentId); @@ -393,6 +400,7 @@ public class CmsContentServiceImpl implements CmsContentService { */ @Override public int logicDeleteById(Long contentId, String updateBy) { + Assert.notNull(contentId, "内容ID不能为空"); return this.cmsContentMapper.logicDeleteById(contentId, updateBy); } @@ -404,6 +412,7 @@ public class CmsContentServiceImpl implements CmsContentService { */ @Override public int deleteById(Long contentId) { + Assert.notNull(contentId, "内容ID不能为空"); return this.cmsContentMapper.deleteById(contentId); } @@ -415,6 +424,7 @@ public class CmsContentServiceImpl implements CmsContentService { */ @Override public int addFavorite(Long contentId) { + Assert.notNull(contentId, "内容ID不能为空"); // 获取当前登录用户ID Long userId = Long.parseLong(StpUtil.getLoginId().toString()); // 获取当前登录用户名 @@ -425,6 +435,9 @@ public class CmsContentServiceImpl implements CmsContentService { if (content == null) { return 0; } + if(Objects.isNull(content.getLikeCount())){ + content.setLikeCount(0); + } // 检查用户是否已经收藏过该内容 CmsContentLike existingLike = cmsContentLikeMapper.queryByUserIdAndContentId(userId, contentId); @@ -475,6 +488,7 @@ public class CmsContentServiceImpl implements CmsContentService { */ @Override public int removeFavorite(Long contentId) { + Assert.notNull(contentId, "内容ID不能为空"); // 获取当前登录用户ID Long userId = Long.parseLong(StpUtil.getLoginId().toString()); @@ -513,6 +527,7 @@ public class CmsContentServiceImpl implements CmsContentService { */ @Override public boolean isFavorited(Long contentId) { + Assert.notNull(contentId, "内容ID不能为空"); try { // 获取当前登录用户ID Long userId = Long.parseLong(StpUtil.getLoginId().toString()); @@ -532,6 +547,7 @@ public class CmsContentServiceImpl implements CmsContentService { */ @Override public int addView(Long contentId) { + Assert.notNull(contentId, "内容ID不能为空"); try { // 获取当前登录用户ID Long userId = Long.parseLong(StpUtil.getLoginId().toString()); @@ -903,6 +919,7 @@ public class CmsContentServiceImpl implements CmsContentService { @Override public String getContent(Long contentId, Integer languageType) { + Assert.notNull(contentId, "内容ID不能为空"); CmsContent cmsContent = this.cmsContentMapper.queryById(contentId); if (cmsContent == null) { return null;