diff --git a/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java b/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java new file mode 100644 index 0000000..8477b2a --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java @@ -0,0 +1,64 @@ +package com.teaching.backend.controller.cms; + + +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.model.entity.cms.CmsCategory; +import com.teaching.backend.service.impl.cms.CmsCategoryServiceImpl; +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + *

+ * 前端控制器 + *

+ * + * @author author + * @since 2024-08-13 + */ +@Api(tags = "栏目管理") +@RestController +@RequestMapping("/api/cms-category") +public class CmsCategoryController { + + @Resource + private CmsCategoryServiceImpl cmsCategoryService; + /** + * 添加栏目 + * @param cmsCategory + * @return + */ + @PostMapping("/add") + public BaseResponse addCategory(CmsCategory cmsCategory){ + return cmsCategoryService.addCategory(cmsCategory); + } + /**' + * 删除栏目 + * @param ids + * @return + */ + @DeleteMapping("/delete") + public BaseResponse deleteCategory(@RequestParam List ids){ + return cmsCategoryService.deleteCategory(ids); + } + /** + * 编辑栏目 + * @param cmsCategory + * @return + */ + @PutMapping("/edit") + public BaseResponse editCategory(CmsCategory cmsCategory){ + return cmsCategoryService.editCategory(cmsCategory); + } + /** + * 查询栏目 + * @return + */ + @GetMapping("/query") + public BaseResponse> queryCategory(){ + return cmsCategoryService.queryCategory(); + } + +} diff --git a/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java b/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java new file mode 100644 index 0000000..b89fa48 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java @@ -0,0 +1,70 @@ +package com.teaching.backend.controller.cms; + + +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.model.entity.cms.CmsCategory; +import com.teaching.backend.model.entity.cms.CmsEssay; +import com.teaching.backend.service.impl.cms.CmsEssayServiceImpl; +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + *

+ * 前端控制器 + *

+ * + * @author author + * @since 2024-08-13 + */ +@Api(tags = "文章管理") +@RestController +@RequestMapping("/api/cms-essay") +public class CmsEssayController { + + @Resource + private CmsEssayServiceImpl cmsEssayService; + + /** + * 添加文章 + * @param cmsEssay + * @return + */ + @PostMapping("/add") + public BaseResponse addEssay(CmsEssay cmsEssay){ + return cmsEssayService.addEssay(cmsEssay); + } + + /** + * 删除文章 + * @param ids + * @return + */ + @DeleteMapping("/delete") + public BaseResponse deleteEssay(@RequestParam List ids){ + return cmsEssayService.deleteEssay(ids); + } + + /** + * 编辑文章 + * @param cmsEssay + * @return + */ + @PutMapping("/edit") + public BaseResponse editEssay(CmsEssay cmsEssay){ + return cmsEssayService.editEssay(cmsEssay); + } + + /** + * 查询文章 + * @param category_id + * @return + */ + @GetMapping("/query") + public BaseResponse> queryEssay(Integer category_id){ + return cmsEssayService.queryEssay(category_id); + } + +} diff --git a/src/main/java/com/teaching/backend/mapper/cms/CmsCategoryMapper.java b/src/main/java/com/teaching/backend/mapper/cms/CmsCategoryMapper.java new file mode 100644 index 0000000..17f75d4 --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/cms/CmsCategoryMapper.java @@ -0,0 +1,17 @@ +package com.teaching.backend.mapper.cms; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.teaching.backend.model.entity.cms.CmsCategory; + +/** + *

+ * Mapper 接口 + *

+ * + * @author author + * @since 2024-08-13 + */ +public interface CmsCategoryMapper extends BaseMapper { + +} diff --git a/src/main/java/com/teaching/backend/mapper/cms/CmsEssayMapper.java b/src/main/java/com/teaching/backend/mapper/cms/CmsEssayMapper.java new file mode 100644 index 0000000..5ccce85 --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/cms/CmsEssayMapper.java @@ -0,0 +1,17 @@ +package com.teaching.backend.mapper.cms; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.teaching.backend.model.entity.cms.CmsEssay; + +/** + *

+ * Mapper 接口 + *

+ * + * @author author + * @since 2024-08-13 + */ +public interface CmsEssayMapper extends BaseMapper { + +} diff --git a/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java b/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java new file mode 100644 index 0000000..c4b91e7 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java @@ -0,0 +1,61 @@ +package com.teaching.backend.model.entity.cms; + +import com.baomidou.mybatisplus.annotation.*; + +import java.time.LocalDateTime; +import java.io.Serializable; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.springframework.format.annotation.DateTimeFormat; + +/** + *

+ * + *

+ * + * @author author + * @since 2024-08-13 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("cms_category") +@ApiModel(value="CmsCategory对象", description="") +public class CmsCategory implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "栏目id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "栏目名称") + private String categoryName; + + @ApiModelProperty(value = "创建该栏目的用户id") + private String creatorId; + + @ApiModelProperty(value = "栏目父id(若为一级栏目则父id等于栏目id)") + private Integer categoryPid; + + @ApiModelProperty(value = "创建时间") + @TableField(fill = FieldFill.INSERT) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + @ApiModelProperty(value = "更新时间") + @TableField(fill = FieldFill.INSERT_UPDATE) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime updateTime; + + @TableField(exist = false) + private List childrenNode; +} diff --git a/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java b/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java new file mode 100644 index 0000000..5038816 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java @@ -0,0 +1,75 @@ +package com.teaching.backend.model.entity.cms; + +import com.baomidou.mybatisplus.annotation.*; + +import java.time.LocalDateTime; +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.springframework.format.annotation.DateTimeFormat; + +/** + *

+ * + *

+ * + * @author author + * @since 2024-08-13 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("cms_essay") +@ApiModel(value="CmsEssay对象", description="") +public class CmsEssay implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "文章id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "文章标题") + private String title; + + @ApiModelProperty(value = "标题图片") + private String pic; + + @ApiModelProperty(value = "文章内容") + private String content; + + @ApiModelProperty(value = "发布时间") + private LocalDateTime publishTime; + + @ApiModelProperty(value = "浏览次数") + private Integer readingNumber; + + @ApiModelProperty(value = "评论条数") + private Integer commentCount; + + @ApiModelProperty(value = "所属栏目id") + private Integer categoryId; + + @ApiModelProperty(value = "发布文章的用户id") + private Integer userId; + + @ApiModelProperty(value = "文章文件") + private String file; + + @ApiModelProperty(value = "发布状态: 1: 已发布; 2未发布") + private Integer status; + + + @ApiModelProperty(value = "更新时间") + @TableField(fill = FieldFill.INSERT_UPDATE) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime updateTime; + + +} diff --git a/src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java b/src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java new file mode 100644 index 0000000..ebc31c8 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java @@ -0,0 +1,27 @@ +package com.teaching.backend.service.cms; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.model.entity.cms.CmsCategory; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author author + * @since 2024-08-13 + */ +public interface ICmsCategoryService extends IService { + + BaseResponse addCategory(CmsCategory cmsCategory); + + BaseResponse deleteCategory(List ids); + + BaseResponse editCategory(CmsCategory cmsCategory); + + BaseResponse> queryCategory(); +} diff --git a/src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java b/src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java new file mode 100644 index 0000000..f122edb --- /dev/null +++ b/src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java @@ -0,0 +1,27 @@ +package com.teaching.backend.service.cms; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.model.entity.cms.CmsEssay; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author author + * @since 2024-08-13 + */ +public interface ICmsEssayService extends IService { + + BaseResponse addEssay(CmsEssay cmsEssay); + + BaseResponse deleteEssay(List ids); + + BaseResponse editEssay(CmsEssay cmsEssay); + + BaseResponse> queryEssay(Integer category_id); +} diff --git a/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java new file mode 100644 index 0000000..e5f7e3a --- /dev/null +++ b/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java @@ -0,0 +1,72 @@ +package com.teaching.backend.service.impl.cms; + + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.mapper.cms.CmsCategoryMapper; +import com.teaching.backend.model.entity.cms.CmsCategory; +import com.teaching.backend.service.cms.ICmsCategoryService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author author + * @since 2024-08-13 + */ +@Service +public class CmsCategoryServiceImpl extends ServiceImpl implements ICmsCategoryService { + + /** + * 添加栏目 + * @param cmsCategory + * @return + */ + @Override + public BaseResponse addCategory(CmsCategory cmsCategory) { + save(cmsCategory); + return ResultUtils.success("添加成功"); + } + + /**' + * 删除栏目 + * @param ids + * @return + */ + @Override + public BaseResponse deleteCategory(List ids) { + removeByIds(ids); + return ResultUtils.success("删除成功"); + } + + /** + * 编辑栏目 + * @param cmsCategory + * @return + */ + @Override + public BaseResponse editCategory(CmsCategory cmsCategory) { + updateById(cmsCategory); + return ResultUtils.success("编辑成功!"); + } + + /** + * 查询栏目 + * @return + */ + @Override + public BaseResponse> queryCategory() { + List categoryPid = query().eq("category_pid", 0).list(); + for (int i = 0; i < categoryPid.size(); i++) { + //查孩子 + categoryPid.get(i).setChildrenNode(query().eq("category_pid", categoryPid.get(i).getId()).list()); + } + return ResultUtils.success(categoryPid); + } + +} diff --git a/src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java new file mode 100644 index 0000000..633b553 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java @@ -0,0 +1,48 @@ +package com.teaching.backend.service.impl.cms; + + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.mapper.cms.CmsEssayMapper; +import com.teaching.backend.model.entity.cms.CmsEssay; +import com.teaching.backend.service.cms.ICmsEssayService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author author + * @since 2024-08-13 + */ +@Service +public class CmsEssayServiceImpl extends ServiceImpl implements ICmsEssayService { + + @Override + public BaseResponse addEssay(CmsEssay cmsEssay) { + save(cmsEssay); + return ResultUtils.success("添加成功"); + } + + @Override + public BaseResponse deleteEssay(List ids) { + removeByIds(ids); + return ResultUtils.success("删除成功"); + } + + @Override + public BaseResponse editEssay(CmsEssay cmsEssay) { + updateById(cmsEssay); + return ResultUtils.success("编辑成功!"); + } + + @Override + public BaseResponse> queryEssay(Integer category_id) { + List list = query().eq("category_id", category_id).list(); + return ResultUtils.success(list); + } +} diff --git a/src/main/java/com/teaching/backend/utils/MyMetaObjectHandler.java b/src/main/java/com/teaching/backend/utils/MyMetaObjectHandler.java new file mode 100644 index 0000000..601b816 --- /dev/null +++ b/src/main/java/com/teaching/backend/utils/MyMetaObjectHandler.java @@ -0,0 +1,26 @@ +package com.teaching.backend.utils; + +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import org.apache.ibatis.reflection.MetaObject; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.util.Date; + +/** + * 自动填充时间 + */ +@Component +public class MyMetaObjectHandler implements MetaObjectHandler { + @Override + public void insertFill(MetaObject metaObject) { + this.setFieldValByName("createTime", LocalDateTime.now(), metaObject); + this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject); + } + + @Override + public void updateFill(MetaObject metaObject) { + this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject); + + } +}