|
@@ -1,18 +1,25 @@
|
|
|
package com.backendsys.modules.cms.page.service.impl;
|
|
|
|
|
|
import com.backendsys.exception.CustException;
|
|
|
+import com.backendsys.modules.cms.article.entity.ArticleI18n;
|
|
|
import com.backendsys.modules.cms.page.dao.PageDao;
|
|
|
+import com.backendsys.modules.cms.page.dao.PageI18nDao;
|
|
|
import com.backendsys.modules.cms.page.entity.Page;
|
|
|
+import com.backendsys.modules.cms.page.entity.PageI18n;
|
|
|
import com.backendsys.modules.cms.page.service.PageService;
|
|
|
+import com.backendsys.modules.common.utils.ValidationUtil;
|
|
|
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.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
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
|
|
|
public class PageServiceImpl implements PageService {
|
|
@@ -20,6 +27,9 @@ public class PageServiceImpl implements PageService {
|
|
|
@Autowired
|
|
|
private PageDao pageDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PageI18nDao pageI18nDao;
|
|
|
+
|
|
|
/**
|
|
|
* 获取单页列表
|
|
|
*/
|
|
@@ -35,7 +45,68 @@ public class PageServiceImpl implements PageService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Map<String, Object> selectPageDetail(Page page) {
|
|
|
- return pageDao.selectPageDetail(page);
|
|
|
+ Map<String, Object> detail = pageDao.selectPageDetail(page);
|
|
|
+ if (detail == null) throw new CustException("单页不存在");
|
|
|
+ return detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建单页
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map<String, Object> insertPage(Page page) {
|
|
|
+
|
|
|
+ Boolean isExist = pageDao.exists(new LambdaQueryWrapper<Page>().eq(Page::getPage_sign, page.getPage_sign()));
|
|
|
+ if (isExist) throw new CustException("单页标识: " + page.getPage_sign() + " 已存在");
|
|
|
+
|
|
|
+ // 插入
|
|
|
+ pageDao.insert(page);
|
|
|
+ // 批量插入 (翻译字段)
|
|
|
+ List<PageI18n> translations = page.getTranslations().stream()
|
|
|
+ .peek(item -> { ValidationUtil.validateObject(item, PageI18n.Create.class); })
|
|
|
+ .map(item -> { item.setPage_sign(page.getPage_sign()); return item; })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ pageI18nDao.insertBatch(translations);
|
|
|
+ return Map.of("page_sign", page.getPage_sign());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑单页
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map<String, Object> updatePage(Page page) {
|
|
|
+
|
|
|
+ Boolean isExist = pageDao.exists(new LambdaQueryWrapper<Page>().eq(Page::getPage_sign, page.getPage_sign()));
|
|
|
+ if (!isExist) throw new CustException("单页不存在");
|
|
|
+
|
|
|
+ // 更新
|
|
|
+ pageDao.update(page, new LambdaQueryWrapper<Page>().eq(Page::getPage_sign, page.getPage_sign()));
|
|
|
+ // 批量更新 (翻译字段)
|
|
|
+ List<PageI18n> translations = page.getTranslations().stream()
|
|
|
+ .peek(item -> { ValidationUtil.validateObject(item, PageI18n.Update.class); })
|
|
|
+ .map(t -> { t.setPage_sign(page.getPage_sign()); return t; })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ pageI18nDao.updateBatch(translations);
|
|
|
+
|
|
|
+ return Map.of("page_sign", page.getPage_sign());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除单页
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map<String, Object> deletePage(Page page) {
|
|
|
+
|
|
|
+ Boolean isExist = pageDao.exists(new LambdaQueryWrapper<Page>().eq(Page::getPage_sign, page.getPage_sign()));
|
|
|
+ if (!isExist) throw new CustException("单页不存在");
|
|
|
+
|
|
|
+ pageDao.delete(new LambdaQueryWrapper<Page>().eq(Page::getPage_sign, page.getPage_sign()));
|
|
|
+ pageI18nDao.delete(new LambdaQueryWrapper<PageI18n>().eq(PageI18n::getPage_sign, page.getPage_sign()));
|
|
|
+
|
|
|
+ return Map.of("page_sign", page.getPage_sign());
|
|
|
}
|
|
|
|
|
|
}
|