|
@@ -1,11 +1,119 @@
|
|
package com.backendsys.modules.cms.article.service.impl;
|
|
package com.backendsys.modules.cms.article.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
|
+import com.backendsys.exception.CustException;
|
|
import com.backendsys.modules.cms.article.dao.ArticleCategoryDao;
|
|
import com.backendsys.modules.cms.article.dao.ArticleCategoryDao;
|
|
|
|
+import com.backendsys.modules.cms.article.dao.ArticleCategoryDao;
|
|
|
|
+import com.backendsys.modules.cms.article.dao.ArticleCategoryI18nDao;
|
|
|
|
+import com.backendsys.modules.cms.article.entity.ArticleCategory;
|
|
import com.backendsys.modules.cms.article.entity.ArticleCategory;
|
|
import com.backendsys.modules.cms.article.entity.ArticleCategory;
|
|
|
|
+import com.backendsys.modules.cms.article.entity.ArticleCategoryI18n;
|
|
import com.backendsys.modules.cms.article.service.ArticleCategoryService;
|
|
import com.backendsys.modules.cms.article.service.ArticleCategoryService;
|
|
|
|
+import com.backendsys.modules.common.config.security.utils.HttpRequestUtil;
|
|
|
|
+import com.backendsys.utils.response.PageEntity;
|
|
|
|
+import com.backendsys.utils.response.PageInfoResult;
|
|
|
|
+import com.backendsys.utils.v2.PageUtils;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
-public class ArticleCategoryServiceImpl extends ServiceImpl<ArticleCategoryDao, ArticleCategory> implements ArticleCategoryService {
|
|
|
|
|
|
+public class ArticleCategoryServiceImpl implements ArticleCategoryService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ArticleCategoryDao articleCategoryDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ArticleCategoryI18nDao articleCategoryI18nDao;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取资讯分类列表
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public PageEntity selectArticleCategoryList(ArticleCategory article) {
|
|
|
|
+ PageUtils.startPage(); // 分页
|
|
|
|
+ List<ArticleCategory> list = articleCategoryDao.selectArticleCategoryList(article);
|
|
|
|
+ return new PageInfoResult(list).toEntity();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取资讯分类详情
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> selectArticleCategoryDetail(ArticleCategory article) {
|
|
|
|
+ Map<String, Object> detail = articleCategoryDao.selectArticleCategoryDetail(article);
|
|
|
|
+ if (detail == null) throw new CustException("资讯分类不存在");
|
|
|
|
+ return detail;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建资讯分类
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Map<String, Object> insertArticleCategory(ArticleCategory articleCategory) {
|
|
|
|
+
|
|
|
|
+ // 插入
|
|
|
|
+ articleCategoryDao.insert(articleCategory);
|
|
|
|
+
|
|
|
|
+ Long article_category_id = articleCategory.getId();
|
|
|
|
+
|
|
|
|
+ // 批量插入 (翻译字段)
|
|
|
|
+ List<ArticleCategoryI18n> translations = articleCategory.getTranslations().stream()
|
|
|
|
+ .map(t -> { t.setArticle_category_id(article_category_id); return t; })
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ articleCategoryI18nDao.insertBatch(translations);
|
|
|
|
+
|
|
|
|
+ return Map.of("article_category_id", article_category_id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 编辑资讯分类
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Map<String, Object> updateArticleCategory(ArticleCategory articleCategory) {
|
|
|
|
+
|
|
|
|
+ Long article_category_id = articleCategory.getArticle_category_id();
|
|
|
|
+
|
|
|
|
+ ArticleCategory detail = articleCategoryDao.selectById(article_category_id);
|
|
|
|
+ if (detail == null) throw new CustException("资讯分类不存在");
|
|
|
|
+
|
|
|
|
+ // 更新
|
|
|
|
+ articleCategory.setId(article_category_id);
|
|
|
|
+ articleCategoryDao.updateById(articleCategory);
|
|
|
|
+
|
|
|
|
+ // 批量更新 (翻译字段)
|
|
|
|
+ List<ArticleCategoryI18n> translations = articleCategory.getTranslations().stream()
|
|
|
|
+ .map(t -> { t.setArticle_category_id(article_category_id); return t; })
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ articleCategoryI18nDao.updateBatch(translations);
|
|
|
|
+
|
|
|
|
+ return Map.of("article_category_id", article_category_id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除资讯分类
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Map<String, Object> deleteArticleCategory(ArticleCategory articleCategory) {
|
|
|
|
+
|
|
|
|
+ Long article_category_id = articleCategory.getArticle_category_id();
|
|
|
|
+
|
|
|
|
+ ArticleCategory articleDetail = articleCategoryDao.selectById(article_category_id);
|
|
|
|
+ if (articleDetail == null) throw new CustException("资讯分类不存在");
|
|
|
|
+
|
|
|
|
+ articleCategoryDao.deleteById(article_category_id);
|
|
|
|
+ articleCategoryI18nDao.delete(new QueryWrapper<ArticleCategoryI18n>().eq("article_category_id", article_category_id));
|
|
|
|
+
|
|
|
|
+ return Map.of("article_category_id", article_category_id);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|