mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-21 11:22:41 +08:00
新增资源分类管理
This commit is contained in:
parent
1025465356
commit
9759cc7b09
@ -35,6 +35,8 @@ public class AdminPermissionCheck implements ApplicationRunner {
|
|||||||
{"部门", "5", "部门-添加", BPermissionConstant.DEPARTMENT_STORE},
|
{"部门", "5", "部门-添加", BPermissionConstant.DEPARTMENT_STORE},
|
||||||
{"部门", "10", "部门-编辑", BPermissionConstant.DEPARTMENT_UPDATE},
|
{"部门", "10", "部门-编辑", BPermissionConstant.DEPARTMENT_UPDATE},
|
||||||
{"部门", "15", "部门-删除", BPermissionConstant.DEPARTMENT_DESTROY},
|
{"部门", "15", "部门-删除", BPermissionConstant.DEPARTMENT_DESTROY},
|
||||||
|
|
||||||
|
{"资源分类", "0", "资源分类管理", BPermissionConstant.RESOURCE_CATEGORY},
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,4 +21,6 @@ public class BPermissionConstant {
|
|||||||
public final static String DEPARTMENT_UPDATE = "department-update";
|
public final static String DEPARTMENT_UPDATE = "department-update";
|
||||||
public final static String DEPARTMENT_DESTROY = "department-destroy";
|
public final static String DEPARTMENT_DESTROY = "department-destroy";
|
||||||
|
|
||||||
|
public final static String RESOURCE_CATEGORY = "resource-category";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,7 @@ package xyz.playedu.api.constant;
|
|||||||
|
|
||||||
public class BackendConstant {
|
public class BackendConstant {
|
||||||
public final static String[] UN_AUTH_URI_WHITELIST = {"/backend/v1/system/image-captcha", "/backend/v1/auth/login",};
|
public final static String[] UN_AUTH_URI_WHITELIST = {"/backend/v1/system/image-captcha", "/backend/v1/auth/login",};
|
||||||
|
|
||||||
|
public final static String[] RESOURCE_TYPE_WHITELIST = {"IMAGE", "PDF", "VIDEO", "WORD", "PPT"};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,10 @@ import org.springframework.http.converter.HttpMessageNotReadableException;
|
|||||||
import org.springframework.validation.ObjectError;
|
import org.springframework.validation.ObjectError;
|
||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
|
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||||
import xyz.playedu.api.exception.NotFoundException;
|
import xyz.playedu.api.exception.NotFoundException;
|
||||||
import xyz.playedu.api.exception.ServiceException;
|
import xyz.playedu.api.exception.ServiceException;
|
||||||
import xyz.playedu.api.types.JsonResponse;
|
import xyz.playedu.api.types.JsonResponse;
|
||||||
@ -32,7 +34,7 @@ public class ExceptionController {
|
|||||||
|
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
public JsonResponse serviceExceptionHandler(MethodArgumentNotValidException e) {
|
public JsonResponse serviceExceptionHandler(MethodArgumentNotValidException e) {
|
||||||
StringBuffer errorMsg = new StringBuffer();
|
StringBuilder errorMsg = new StringBuilder();
|
||||||
List<ObjectError> allErrors = e.getBindingResult().getAllErrors();
|
List<ObjectError> allErrors = e.getBindingResult().getAllErrors();
|
||||||
for (ObjectError tmpError : allErrors) {
|
for (ObjectError tmpError : allErrors) {
|
||||||
errorMsg.append(tmpError.getDefaultMessage()).append(",");
|
errorMsg.append(tmpError.getDefaultMessage()).append(",");
|
||||||
@ -46,6 +48,16 @@ public class ExceptionController {
|
|||||||
return JsonResponse.error("请求method错误", 400);
|
return JsonResponse.error("请求method错误", 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
|
||||||
|
public JsonResponse serviceExceptionHandler(MethodArgumentTypeMismatchException e) {
|
||||||
|
return JsonResponse.error("请求错误", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(MissingServletRequestParameterException.class)
|
||||||
|
public JsonResponse serviceExceptionHandler(MissingServletRequestParameterException e) {
|
||||||
|
return JsonResponse.error("参数错误", 406);
|
||||||
|
}
|
||||||
|
|
||||||
@ExceptionHandler(NotFoundException.class)
|
@ExceptionHandler(NotFoundException.class)
|
||||||
public JsonResponse serviceExceptionHandler(NotFoundException e) {
|
public JsonResponse serviceExceptionHandler(NotFoundException e) {
|
||||||
return JsonResponse.error(e.getMessage(), 404);
|
return JsonResponse.error(e.getMessage(), 404);
|
||||||
|
@ -0,0 +1,105 @@
|
|||||||
|
package xyz.playedu.api.controller.backend;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import xyz.playedu.api.constant.BPermissionConstant;
|
||||||
|
import xyz.playedu.api.constant.BackendConstant;
|
||||||
|
import xyz.playedu.api.domain.ResourceCategory;
|
||||||
|
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||||
|
import xyz.playedu.api.request.backend.ResourceCategoryRequest;
|
||||||
|
import xyz.playedu.api.service.ResourceCategoryService;
|
||||||
|
import xyz.playedu.api.types.JsonResponse;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/2/23 09:46
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/backend/v1/resource-category")
|
||||||
|
public class ResourceCategoryController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ResourceCategoryService resourceCategoryService;
|
||||||
|
|
||||||
|
@GetMapping("/index")
|
||||||
|
public JsonResponse index(@RequestParam(name = "type") String type) {
|
||||||
|
List<ResourceCategory> categories = resourceCategoryService.getByType(type);
|
||||||
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
|
data.put("data", categories);
|
||||||
|
return JsonResponse.data(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_CATEGORY)
|
||||||
|
@GetMapping("/create")
|
||||||
|
public JsonResponse create() {
|
||||||
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
|
data.put("types", BackendConstant.RESOURCE_TYPE_WHITELIST);
|
||||||
|
return JsonResponse.data(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_CATEGORY)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public JsonResponse store(@RequestBody @Validated ResourceCategoryRequest request) {
|
||||||
|
if (!Arrays.asList(BackendConstant.RESOURCE_TYPE_WHITELIST).contains(request.getType())) {
|
||||||
|
return JsonResponse.error("资源类型不支持");
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceCategory category = new ResourceCategory();
|
||||||
|
|
||||||
|
category.setType(request.getType());
|
||||||
|
category.setSort(request.getSort());
|
||||||
|
category.setName(request.getName());
|
||||||
|
category.setCreatedAt(new Date());
|
||||||
|
category.setUpdatedAt(new Date());
|
||||||
|
|
||||||
|
resourceCategoryService.save(category);
|
||||||
|
|
||||||
|
return JsonResponse.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_CATEGORY)
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public JsonResponse edit(@PathVariable(name = "id") Integer id) {
|
||||||
|
ResourceCategory category = resourceCategoryService.getById(id);
|
||||||
|
if (category == null) {
|
||||||
|
return JsonResponse.error("分类不存在");
|
||||||
|
}
|
||||||
|
return JsonResponse.data(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_CATEGORY)
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public JsonResponse update(@PathVariable(name = "id") Integer id, @RequestBody @Validated ResourceCategoryRequest request) {
|
||||||
|
if (!Arrays.asList(BackendConstant.RESOURCE_TYPE_WHITELIST).contains(request.getType())) {
|
||||||
|
return JsonResponse.error("资源类型不支持");
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceCategory category = resourceCategoryService.getById(id);
|
||||||
|
if (category == null) {
|
||||||
|
return JsonResponse.error("分类不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceCategory newCategory = new ResourceCategory();
|
||||||
|
newCategory.setId(category.getId());
|
||||||
|
newCategory.setName(request.getName());
|
||||||
|
newCategory.setSort(request.getSort());
|
||||||
|
|
||||||
|
resourceCategoryService.updateById(newCategory);
|
||||||
|
|
||||||
|
return JsonResponse.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_CATEGORY)
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public JsonResponse destroy(@PathVariable(name = "id") Integer id) {
|
||||||
|
resourceCategoryService.removeById(id);
|
||||||
|
return JsonResponse.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package xyz.playedu.api.controller.backend;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import xyz.playedu.api.types.JsonResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/2/23 09:48
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/backend/v1/user")
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@GetMapping("/index")
|
||||||
|
public JsonResponse index() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/create")
|
||||||
|
public JsonResponse create() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
public JsonResponse store() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public JsonResponse edit(@PathVariable(name = "id") Integer id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public JsonResponse update(@PathVariable(name = "id") Integer id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public JsonResponse destroy(@PathVariable(name = "id") Integer id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
105
src/main/java/xyz/playedu/api/domain/ResourceCategory.java
Normal file
105
src/main/java/xyz/playedu/api/domain/ResourceCategory.java
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
package xyz.playedu.api.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName resource_categories
|
||||||
|
*/
|
||||||
|
@TableName(value ="resource_categories")
|
||||||
|
@Data
|
||||||
|
public class ResourceCategory implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源类别
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类名
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 升序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@JsonIgnore
|
||||||
|
private Date createdAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@JsonIgnore
|
||||||
|
private Date updatedAt;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object that) {
|
||||||
|
if (this == that) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (that == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != that.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ResourceCategory other = (ResourceCategory) that;
|
||||||
|
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
|
||||||
|
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
|
||||||
|
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
|
||||||
|
&& (this.getSort() == null ? other.getSort() == null : this.getSort().equals(other.getSort()))
|
||||||
|
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
|
||||||
|
&& (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||||
|
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
|
||||||
|
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
|
||||||
|
result = prime * result + ((getSort() == null) ? 0 : getSort().hashCode());
|
||||||
|
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
|
||||||
|
result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(getClass().getSimpleName());
|
||||||
|
sb.append(" [");
|
||||||
|
sb.append("Hash = ").append(hashCode());
|
||||||
|
sb.append(", id=").append(id);
|
||||||
|
sb.append(", type=").append(type);
|
||||||
|
sb.append(", name=").append(name);
|
||||||
|
sb.append(", sort=").append(sort);
|
||||||
|
sb.append(", createdAt=").append(createdAt);
|
||||||
|
sb.append(", updatedAt=").append(updatedAt);
|
||||||
|
sb.append(", serialVersionUID=").append(serialVersionUID);
|
||||||
|
sb.append("]");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package xyz.playedu.api.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import xyz.playedu.api.domain.ResourceCategory;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tengteng
|
||||||
|
* @description 针对表【resource_categories】的数据库操作Mapper
|
||||||
|
* @createDate 2023-02-23 09:50:18
|
||||||
|
* @Entity xyz.playedu.api.domain.ResourceCategory
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ResourceCategoryMapper extends BaseMapper<ResourceCategory> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
|||||||
|
package xyz.playedu.api.request.backend;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.hibernate.validator.constraints.Length;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/2/23 09:56
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ResourceCategoryRequest {
|
||||||
|
|
||||||
|
@NotNull(message = "资源类型不能为空")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@NotNull(message = "分类名不能为空")
|
||||||
|
@Length(min = 1, max = 12, message = "分类名长度在1-12个字符之间")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@NotNull(message = "请输入排序值")
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package xyz.playedu.api.service;
|
||||||
|
|
||||||
|
import xyz.playedu.api.domain.ResourceCategory;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tengteng
|
||||||
|
* @description 针对表【resource_categories】的数据库操作Service
|
||||||
|
* @createDate 2023-02-23 09:50:18
|
||||||
|
*/
|
||||||
|
public interface ResourceCategoryService extends IService<ResourceCategory> {
|
||||||
|
|
||||||
|
List<ResourceCategory> getByType(String type);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package xyz.playedu.api.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import xyz.playedu.api.domain.ResourceCategory;
|
||||||
|
import xyz.playedu.api.service.ResourceCategoryService;
|
||||||
|
import xyz.playedu.api.mapper.ResourceCategoryMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tengteng
|
||||||
|
* @description 针对表【resource_categories】的数据库操作Service实现
|
||||||
|
* @createDate 2023-02-23 09:50:18
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMapper, ResourceCategory>
|
||||||
|
implements ResourceCategoryService {
|
||||||
|
@Override
|
||||||
|
public List<ResourceCategory> getByType(String type) {
|
||||||
|
return list(query().getWrapper().eq("type", type).orderByAsc("id"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
20
src/main/resources/mapper/ResourceCategoryMapper.xml
Normal file
20
src/main/resources/mapper/ResourceCategoryMapper.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="xyz.playedu.api.mapper.ResourceCategoryMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.ResourceCategory">
|
||||||
|
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||||
|
<result property="type" column="type" jdbcType="VARCHAR"/>
|
||||||
|
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||||
|
<result property="sort" column="sort" jdbcType="INTEGER"/>
|
||||||
|
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,type,name,
|
||||||
|
sort,created_at,updated_at
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user