资讯管理

master
wenyu441069198 3 months ago
parent 531c440b13
commit 3c979067cb
  1. 64
      src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java
  2. 70
      src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java
  3. 17
      src/main/java/com/teaching/backend/mapper/cms/CmsCategoryMapper.java
  4. 17
      src/main/java/com/teaching/backend/mapper/cms/CmsEssayMapper.java
  5. 61
      src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java
  6. 75
      src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java
  7. 27
      src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java
  8. 27
      src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java
  9. 72
      src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java
  10. 48
      src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java
  11. 26
      src/main/java/com/teaching/backend/utils/MyMetaObjectHandler.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;
/**
* <p>
* 前端控制器
* </p>
*
* @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<String> addCategory(CmsCategory cmsCategory){
return cmsCategoryService.addCategory(cmsCategory);
}
/**'
* 删除栏目
* @param ids
* @return
*/
@DeleteMapping("/delete")
public BaseResponse<String> deleteCategory(@RequestParam List<Integer> ids){
return cmsCategoryService.deleteCategory(ids);
}
/**
* 编辑栏目
* @param cmsCategory
* @return
*/
@PutMapping("/edit")
public BaseResponse<String> editCategory(CmsCategory cmsCategory){
return cmsCategoryService.editCategory(cmsCategory);
}
/**
* 查询栏目
* @return
*/
@GetMapping("/query")
public BaseResponse<List<?>> queryCategory(){
return cmsCategoryService.queryCategory();
}
}

@ -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;
/**
* <p>
* 前端控制器
* </p>
*
* @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<String> addEssay(CmsEssay cmsEssay){
return cmsEssayService.addEssay(cmsEssay);
}
/**
* 删除文章
* @param ids
* @return
*/
@DeleteMapping("/delete")
public BaseResponse<String> deleteEssay(@RequestParam List<Integer> ids){
return cmsEssayService.deleteEssay(ids);
}
/**
* 编辑文章
* @param cmsEssay
* @return
*/
@PutMapping("/edit")
public BaseResponse<String> editEssay(CmsEssay cmsEssay){
return cmsEssayService.editEssay(cmsEssay);
}
/**
* 查询文章
* @param category_id
* @return
*/
@GetMapping("/query")
public BaseResponse<List<?>> queryEssay(Integer category_id){
return cmsEssayService.queryEssay(category_id);
}
}

@ -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;
/**
* <p>
* Mapper 接口
* </p>
*
* @author author
* @since 2024-08-13
*/
public interface CmsCategoryMapper extends BaseMapper<CmsCategory> {
}

@ -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;
/**
* <p>
* Mapper 接口
* </p>
*
* @author author
* @since 2024-08-13
*/
public interface CmsEssayMapper extends BaseMapper<CmsEssay> {
}

@ -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;
/**
* <p>
*
* </p>
*
* @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<CmsCategory> childrenNode;
}

@ -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;
/**
* <p>
*
* </p>
*
* @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;
}

@ -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;
/**
* <p>
* 服务类
* </p>
*
* @author author
* @since 2024-08-13
*/
public interface ICmsCategoryService extends IService<CmsCategory> {
BaseResponse<String> addCategory(CmsCategory cmsCategory);
BaseResponse<String> deleteCategory(List<Integer> ids);
BaseResponse<String> editCategory(CmsCategory cmsCategory);
BaseResponse<List<?>> queryCategory();
}

@ -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;
/**
* <p>
* 服务类
* </p>
*
* @author author
* @since 2024-08-13
*/
public interface ICmsEssayService extends IService<CmsEssay> {
BaseResponse<String> addEssay(CmsEssay cmsEssay);
BaseResponse<String> deleteEssay(List<Integer> ids);
BaseResponse<String> editEssay(CmsEssay cmsEssay);
BaseResponse<List<?>> queryEssay(Integer category_id);
}

@ -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;
/**
* <p>
* 服务实现类
* </p>
*
* @author author
* @since 2024-08-13
*/
@Service
public class CmsCategoryServiceImpl extends ServiceImpl<CmsCategoryMapper, CmsCategory> implements ICmsCategoryService {
/**
* 添加栏目
* @param cmsCategory
* @return
*/
@Override
public BaseResponse<String> addCategory(CmsCategory cmsCategory) {
save(cmsCategory);
return ResultUtils.success("添加成功");
}
/**'
* 删除栏目
* @param ids
* @return
*/
@Override
public BaseResponse<String> deleteCategory(List<Integer> ids) {
removeByIds(ids);
return ResultUtils.success("删除成功");
}
/**
* 编辑栏目
* @param cmsCategory
* @return
*/
@Override
public BaseResponse<String> editCategory(CmsCategory cmsCategory) {
updateById(cmsCategory);
return ResultUtils.success("编辑成功!");
}
/**
* 查询栏目
* @return
*/
@Override
public BaseResponse<List<?>> queryCategory() {
List<CmsCategory> 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);
}
}

@ -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;
/**
* <p>
* 服务实现类
* </p>
*
* @author author
* @since 2024-08-13
*/
@Service
public class CmsEssayServiceImpl extends ServiceImpl<CmsEssayMapper, CmsEssay> implements ICmsEssayService {
@Override
public BaseResponse<String> addEssay(CmsEssay cmsEssay) {
save(cmsEssay);
return ResultUtils.success("添加成功");
}
@Override
public BaseResponse<String> deleteEssay(List<Integer> ids) {
removeByIds(ids);
return ResultUtils.success("删除成功");
}
@Override
public BaseResponse<String> editEssay(CmsEssay cmsEssay) {
updateById(cmsEssay);
return ResultUtils.success("编辑成功!");
}
@Override
public BaseResponse<List<?>> queryEssay(Integer category_id) {
List<CmsEssay> list = query().eq("category_id", category_id).list();
return ResultUtils.success(list);
}
}

@ -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);
}
}
Loading…
Cancel
Save