Selaa lähdekoodia

官网-栏目模块的相关接口开发

jichaobo 2 vuotta sitten
vanhempi
commit
c34c46ba96

+ 39 - 3
service-website/service-website-biz/src/main/java/com/usky/website/controller/web/SiteCategoryController.java

@@ -5,9 +5,7 @@ import com.usky.common.core.bean.ApiResult;
 import com.usky.website.domain.SiteCategory;
 import com.usky.website.service.SiteCategoryService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -35,5 +33,43 @@ public class SiteCategoryController {
     public ApiResult<List<SiteCategory>> siteCategoryList() {
         return ApiResult.success(siteCategoryService.siteCategoryList());
     }
+
+    /**
+     * 官网-栏目新增
+     *
+     * @param siteCategory
+     * @return
+     */
+    @PostMapping("addSiteCategory")
+    public ApiResult<Void> addSiteCategory(@RequestBody SiteCategory siteCategory) {
+        siteCategoryService.addSiteCategory(siteCategory);
+        return ApiResult.success();
+    }
+
+    /**
+     * 官网-栏目修改
+     *
+     * @param siteCategory
+     * @return
+     */
+    @PutMapping("updateSiteCategory")
+    public ApiResult<Void> updateSiteCategory(@RequestBody SiteCategory siteCategory) {
+        siteCategoryService.updateSiteCategory(siteCategory);
+        return ApiResult.success();
+    }
+
+    /**
+     * 官网-栏目删除
+     *
+     * @param id 主键ID
+     * @return
+     */
+    @DeleteMapping("delSiteCategory")
+    public ApiResult<Void> delSiteCategory(@RequestParam(value = "id") Integer id) {
+        siteCategoryService.delSiteCategory(id);
+        return ApiResult.success();
+    }
+
+
 }
 

+ 21 - 0
service-website/service-website-biz/src/main/java/com/usky/website/service/SiteCategoryService.java

@@ -21,4 +21,25 @@ public interface SiteCategoryService extends CrudService<SiteCategory> {
      * @return
      */
     List<SiteCategory> siteCategoryList();
+
+    /**
+     * 官网-栏目的新增
+     *
+     * @param siteCategory
+     */
+    void addSiteCategory(SiteCategory siteCategory);
+
+    /**
+     * 官网-栏目的修改
+     *
+     * @param siteCategory
+     */
+    void updateSiteCategory(SiteCategory siteCategory);
+
+    /**
+     * 官网-栏目的删除
+     *
+     * @param id 主键ID
+     */
+    void delSiteCategory(Integer id);
 }

+ 52 - 4
service-website/service-website-biz/src/main/java/com/usky/website/service/impl/SiteCategoryServiceImpl.java

@@ -2,12 +2,17 @@ package com.usky.website.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.usky.common.core.exception.BusinessException;
 import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.website.domain.SiteArticle;
 import com.usky.website.domain.SiteCategory;
 import com.usky.website.mapper.SiteCategoryMapper;
+import com.usky.website.service.SiteArticleService;
 import com.usky.website.service.SiteCategoryService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -22,6 +27,9 @@ import java.util.stream.Collectors;
 @Service
 public class SiteCategoryServiceImpl extends AbstractCrudService<SiteCategoryMapper, SiteCategory> implements SiteCategoryService {
 
+    @Autowired
+    private SiteArticleService siteArticleService;
+
     @Override
     public List<SiteCategory> siteCategoryList() {
         LambdaQueryWrapper<SiteCategory> queryWrapper = Wrappers.lambdaQuery();
@@ -40,10 +48,50 @@ public class SiteCategoryServiceImpl extends AbstractCrudService<SiteCategoryMap
     }
 
 
-//    public void addSiteCategory(SiteCategory siteCategory){
-//        LambdaQueryWrapper<SiteCategory> queryWrapper = Wrappers.lambdaQuery();
-//        queryWrapper.eq(SiteCategory::getStatus, 1).eq();
-//    }
+    @Override
+    public void addSiteCategory(SiteCategory siteCategory) {
+        LambdaQueryWrapper<SiteCategory> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(SiteCategory::getStatus, 1)
+                .eq(SiteCategory::getPid, siteCategory.getPid())
+                .eq(SiteCategory::getCategoryName, siteCategory.getCategoryName());
+        List<SiteCategory> list = this.list(queryWrapper);
+        if (list.size() > 0) {
+            throw new BusinessException("栏目名称不能重复,请重新填写栏目名称");
+        }
+        siteCategory.setCreatedate(LocalDateTime.now());
+        siteCategory.setStatus(1);
+        this.save(siteCategory);
+    }
+
+    @Override
+    public void updateSiteCategory(SiteCategory siteCategory) {
+        LambdaQueryWrapper<SiteCategory> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(SiteCategory::getStatus, 1)
+                .eq(SiteCategory::getPid, siteCategory.getPid())
+                .eq(SiteCategory::getCategoryName, siteCategory.getCategoryName())
+                .ne(SiteCategory::getId, siteCategory.getId());
+        List<SiteCategory> list = this.list(queryWrapper);
+        if (list.size() > 0) {
+            throw new BusinessException("栏目名称不能重复,请重新填写栏目名称");
+        }
+        siteCategory.setModifydate(LocalDateTime.now());
+        this.updateById(siteCategory);
+    }
+
+    @Override
+    public void delSiteCategory(Integer id) {
+        if (id == null || id == 0) {
+            throw new BusinessException("ID不能等于空或者等于0");
+        }
+        LambdaQueryWrapper<SiteArticle> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(SiteArticle::getCategoryid, id);
+        List<SiteArticle> list = siteArticleService.list(queryWrapper);
+        if (list.size() > 0) {
+            throw new BusinessException("该栏目存在栏目内容不可删除");
+        }
+        this.removeById(id);
+    }
+
 
     private List<SiteCategory> getChildrenData(SiteCategory root, List<SiteCategory> all) {
         List<SiteCategory> children = all.stream().filter(subjectVO ->

+ 0 - 98
service-website/service-website-biz/src/main/java/com/usky/website/service/vo/SiteCategoryVo.java

@@ -1,98 +0,0 @@
-package com.usky.website.service.vo;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import java.io.Serializable;
-import java.time.LocalDateTime;
-import java.util.List;
-
-/**
- * <p>
- * 官网_栏目管理
- * </p>
- *
- * @author ya
- * @since 2022-08-31
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-public class SiteCategoryVo implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    @TableId(value = "id", type = IdType.AUTO)
-    private Integer id;
-
-    /**
-     * 父级ID
-     */
-    private Integer pid;
-
-    /**
-     * 栏目名称
-     */
-    private String categoryName;
-
-    /**
-     * 栏目简称
-     */
-    private String sname;
-
-    /**
-     * 是否新栏目;0:否 1:是
-     */
-    @TableField("isNew")
-    private Integer isNew;
-
-    /**
-     * 页面模板
-     */
-    private String tpl;
-
-    /**
-     * 栏目图片;
-     */
-    @TableField("imagePath")
-    private String imagePath;
-
-    /**
-     * SEO关键字;
-     */
-    private String metakeywords;
-
-    /**
-     * SEO描述;
-     */
-    private String metadescription;
-
-    /**
-     * 创建时间;
-     */
-    private LocalDateTime createdate;
-
-    /**
-     * 修改时间;
-     */
-    private LocalDateTime modifydate;
-
-    /**
-     * 栏目排序
-     */
-    private Integer sortindex;
-
-    /**
-     * 状态;0:关闭 1:开启
-     */
-    private Integer status;
-
-    /**
-     * 子级
-     */
-    private List<SiteCategoryVo> children;
-
-
-}