fix(cms): 处理栏目模型为null的情况并添加日志警告
- CmsArticleServiceImpl中新增@Slf4j注解支持日志输出 - 保存文章时,增加cmsNavigation.getModelInfo()为null的判断,避免空指针异常 - 模型信息不存在时,记录警告日志提醒栏目未关联模型 - 修正CmsNavigationServiceImpl中获取模型信息时的null处理 - 只有模型信息不为空且banner为空时才赋值栏目banner和mpBanner - 增强代码健壮性,避免空模型导致相关操作失败或异常
This commit is contained in:
@@ -18,6 +18,7 @@ import com.gxwebsoft.common.core.utils.RedisUtil;
|
|||||||
import com.gxwebsoft.common.core.web.PageParam;
|
import com.gxwebsoft.common.core.web.PageParam;
|
||||||
import com.gxwebsoft.common.core.web.PageResult;
|
import com.gxwebsoft.common.core.web.PageResult;
|
||||||
import com.gxwebsoft.common.system.service.UserService;
|
import com.gxwebsoft.common.system.service.UserService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
@@ -37,6 +38,7 @@ import static com.gxwebsoft.common.core.constants.ArticleConstants.CACHE_KEY_ART
|
|||||||
* @author 科技小王子
|
* @author 科技小王子
|
||||||
* @since 2024-09-10 20:47:57
|
* @since 2024-09-10 20:47:57
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class CmsArticleServiceImpl extends ServiceImpl<CmsArticleMapper, CmsArticle> implements CmsArticleService {
|
public class CmsArticleServiceImpl extends ServiceImpl<CmsArticleMapper, CmsArticle> implements CmsArticleService {
|
||||||
@Resource
|
@Resource
|
||||||
@@ -145,7 +147,10 @@ public class CmsArticleServiceImpl extends ServiceImpl<CmsArticleMapper, CmsArti
|
|||||||
try {
|
try {
|
||||||
// 保存文章模型
|
// 保存文章模型
|
||||||
final CmsNavigation cmsNavigation = cmsNavigationService.getByIdRel(article.getCategoryId());
|
final CmsNavigation cmsNavigation = cmsNavigationService.getByIdRel(article.getCategoryId());
|
||||||
final CmsModel modelInfo = cmsNavigation.getModelInfo();
|
final CmsModel modelInfo = cmsNavigation != null ? cmsNavigation.getModelInfo() : null;
|
||||||
|
if (modelInfo == null) {
|
||||||
|
log.warn("栏目 {} 未关联到模型,跳过模型详情设置", article.getCategoryId());
|
||||||
|
} else {
|
||||||
final String componentDetail = modelInfo.getComponentDetail();
|
final String componentDetail = modelInfo.getComponentDetail();
|
||||||
if (ObjectUtil.isNotEmpty(componentDetail)) {
|
if (ObjectUtil.isNotEmpty(componentDetail)) {
|
||||||
final String[] split = componentDetail.split("/");
|
final String[] split = componentDetail.split("/");
|
||||||
@@ -156,6 +161,7 @@ public class CmsArticleServiceImpl extends ServiceImpl<CmsArticleMapper, CmsArti
|
|||||||
article.setDetail(split[2]);
|
article.setDetail(split[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 是否密码可见
|
// 是否密码可见
|
||||||
if (article.getPermission() != null && article.getPermission() == PERMISSION_PASSWORD) {
|
if (article.getPermission() != null && article.getPermission() == PERMISSION_PASSWORD) {
|
||||||
article.setPassword(userService.encodePassword(article.getPassword()));
|
article.setPassword(userService.encodePassword(article.getPassword()));
|
||||||
@@ -193,6 +199,9 @@ public class CmsArticleServiceImpl extends ServiceImpl<CmsArticleMapper, CmsArti
|
|||||||
// 模型信息
|
// 模型信息
|
||||||
if (ObjectUtil.isNotEmpty(cmsNavigation)) {
|
if (ObjectUtil.isNotEmpty(cmsNavigation)) {
|
||||||
final CmsModel modelInfo = cmsNavigation.getModelInfo();
|
final CmsModel modelInfo = cmsNavigation.getModelInfo();
|
||||||
|
if (modelInfo == null) {
|
||||||
|
log.warn("栏目 {} 未关联到模型,跳过模型详情设置", article.getCategoryId());
|
||||||
|
} else {
|
||||||
final String componentDetail = modelInfo.getComponentDetail();
|
final String componentDetail = modelInfo.getComponentDetail();
|
||||||
if (ObjectUtil.isNotEmpty(componentDetail)) {
|
if (ObjectUtil.isNotEmpty(componentDetail)) {
|
||||||
final String[] split = componentDetail.split("/");
|
final String[] split = componentDetail.split("/");
|
||||||
@@ -204,6 +213,7 @@ public class CmsArticleServiceImpl extends ServiceImpl<CmsArticleMapper, CmsArti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 修正父级栏目ID
|
// 修正父级栏目ID
|
||||||
if (article.getParentId().equals(0)) {
|
if (article.getParentId().equals(0)) {
|
||||||
final CmsNavigation current = cmsNavigationService.getById(article.getCategoryId());
|
final CmsNavigation current = cmsNavigationService.getById(article.getCategoryId());
|
||||||
|
|||||||
@@ -76,10 +76,11 @@ public class CmsNavigationServiceImpl extends ServiceImpl<CmsNavigationMapper, C
|
|||||||
navigation.setDesign(cmsDesignService.getOne(new LambdaQueryWrapper<CmsDesign>().eq(CmsDesign::getCategoryId, navigation.getNavigationId()).last("limit 1")));
|
navigation.setDesign(cmsDesignService.getOne(new LambdaQueryWrapper<CmsDesign>().eq(CmsDesign::getCategoryId, navigation.getNavigationId()).last("limit 1")));
|
||||||
// 所属模型
|
// 所属模型
|
||||||
if (StrUtil.isNotBlank(navigation.getModel())) {
|
if (StrUtil.isNotBlank(navigation.getModel())) {
|
||||||
navigation.setModelInfo(cmsModelService.getOne(new LambdaQueryWrapper<CmsModel>().eq(CmsModel::getModel, navigation.getModel()).last("limit 1")));
|
final CmsModel modelInfo = cmsModelService.getOne(new LambdaQueryWrapper<CmsModel>().eq(CmsModel::getModel, navigation.getModel()).last("limit 1"));
|
||||||
if (StrUtil.isBlank(navigation.getBanner())) {
|
navigation.setModelInfo(modelInfo);
|
||||||
navigation.setBanner(navigation.getModelInfo().getBanner());
|
if (modelInfo != null && StrUtil.isBlank(navigation.getBanner())) {
|
||||||
navigation.setMpBanner(navigation.getModelInfo().getThumb());
|
navigation.setBanner(modelInfo.getBanner());
|
||||||
|
navigation.setMpBanner(modelInfo.getThumb());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return navigation;
|
return navigation;
|
||||||
@@ -178,10 +179,11 @@ public class CmsNavigationServiceImpl extends ServiceImpl<CmsNavigationMapper, C
|
|||||||
navigation.setDesign(cmsDesignService.getOne(new LambdaQueryWrapper<CmsDesign>().eq(CmsDesign::getCategoryId, navigation.getNavigationId()).last("limit 1")));
|
navigation.setDesign(cmsDesignService.getOne(new LambdaQueryWrapper<CmsDesign>().eq(CmsDesign::getCategoryId, navigation.getNavigationId()).last("limit 1")));
|
||||||
// 所属模型
|
// 所属模型
|
||||||
if (StrUtil.isNotBlank(navigation.getModel())) {
|
if (StrUtil.isNotBlank(navigation.getModel())) {
|
||||||
navigation.setModelInfo(cmsModelService.getOne(new LambdaQueryWrapper<CmsModel>().eq(CmsModel::getModel, navigation.getModel()).last("limit 1")));
|
final CmsModel modelInfo = cmsModelService.getOne(new LambdaQueryWrapper<CmsModel>().eq(CmsModel::getModel, navigation.getModel()).last("limit 1"));
|
||||||
if (StrUtil.isBlank(navigation.getBanner())) {
|
navigation.setModelInfo(modelInfo);
|
||||||
navigation.setBanner(navigation.getModelInfo().getBanner());
|
if (modelInfo != null && StrUtil.isBlank(navigation.getBanner())) {
|
||||||
navigation.setMpBanner(navigation.getModelInfo().getThumb());
|
navigation.setBanner(modelInfo.getBanner());
|
||||||
|
navigation.setMpBanner(modelInfo.getThumb());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return navigation;
|
return navigation;
|
||||||
|
|||||||
Reference in New Issue
Block a user