diff --git a/pom.xml b/pom.xml index 85d25d5..4f5717c 100644 --- a/pom.xml +++ b/pom.xml @@ -190,6 +190,12 @@ easypoi-spring-boot-starter 4.1.3 + + + commons-io + commons-io + 2.8.0 + diff --git a/src/main/java/com/teaching/backend/common/ErrorCode.java b/src/main/java/com/teaching/backend/common/ErrorCode.java index 9314b01..352cffa 100644 --- a/src/main/java/com/teaching/backend/common/ErrorCode.java +++ b/src/main/java/com/teaching/backend/common/ErrorCode.java @@ -36,6 +36,8 @@ public enum ErrorCode { PARAMS_COURSE_NOTEXISTS(4004,"课程不存在"), SYSTEM_ERROR(50000, "系统内部异常"), + UNKNOW_ERROR(50002, "系统内部异常"), + OPERATION_ERROR(50001, "操作失败"); /** diff --git a/src/main/java/com/teaching/backend/config/WebConfig.java b/src/main/java/com/teaching/backend/config/WebConfig.java new file mode 100644 index 0000000..d2460c5 --- /dev/null +++ b/src/main/java/com/teaching/backend/config/WebConfig.java @@ -0,0 +1,19 @@ +package com.teaching.backend.config; + +import com.teaching.backend.filter.ValidationInterceptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Autowired + private ValidationInterceptor validationInterceptor; + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(validationInterceptor).addPathPatterns("/**"); + } +} diff --git a/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java b/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java index 650af6a..acc3cf7 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java @@ -4,6 +4,7 @@ package com.teaching.backend.controller.courses; import cn.hutool.core.bean.BeanUtil; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.filter.ValidateParams; import com.teaching.backend.mapper.courses.CourseObjectivesMapper; import com.teaching.backend.model.dto.courses.CourseObjectivesDTO; import com.teaching.backend.model.entity.courses.CourseObjectives; @@ -37,6 +38,7 @@ public class CourseObjectivesController { CourseObjectivesMapper courseObjectivesMapper; @ApiOperation("新增分项目标-默认第一个必须添加思政目标") + @ValidateParams({"name","type","pid"}) @PostMapping("/addobjectives") public BaseResponse saveCourseObjectives(@RequestBody CourseObjectivesDTO courseObjectivesDTO){ String data = courseObjectivesService.addObjectives(courseObjectivesDTO); @@ -44,6 +46,7 @@ public class CourseObjectivesController { } @ApiOperation("删除分项目标-只能最后一个删除思政目标-总目标只需删除关联的内容") + @ValidateParams({"id"}) @DeleteMapping("/{id}") public BaseResponse deleteCourseObjectivesByIds(@PathVariable String id){ String data = courseObjectivesService.deleteObjectives(id); @@ -54,6 +57,7 @@ public class CourseObjectivesController { * @param courseObjectivesDTO * @return */ + //TODO:分项目标按理说不能编辑,只可以新增 删除 @ApiOperation("编辑分项目标") @PutMapping public BaseResponse updateCourseObjectives(@RequestBody CourseObjectivesDTO courseObjectivesDTO){ @@ -65,6 +69,7 @@ public class CourseObjectivesController { } @ApiOperation("查询课程目标内容") + @ValidateParams({"id"}) @GetMapping("/list/{id}") public BaseResponse> queryCourseObjectivesTree(@PathVariable String id){ List courseObjectivesTreeVO = courseObjectivesService.queryCourseObjectivesTree(id); diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java index 9bac23f..3d4cb48 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -6,6 +6,7 @@ import com.teaching.backend.common.ErrorCode; import com.teaching.backend.common.ResultUtils; import com.teaching.backend.exception.BusinessException; +import com.teaching.backend.filter.ValidateParams; import com.teaching.backend.model.dto.courses.CoursesDTO; import com.teaching.backend.model.dto.courses.PageDTO; @@ -56,6 +57,7 @@ public class CoursesController { } @ApiOperation("新增课程--同步新增课程的总体目标并同时添加所有的分项目标") + @ValidateParams({"teacher","img", "category", "nature","name","code","credit","classhours","assessmenttype","assessmentway"}) // 需要校验的参数 @PostMapping("/addcourse") public BaseResponse saveCourse(@RequestBody CoursesDTO coursesDTO){ String data = coursesService.saveCourseWithObjective(coursesDTO); @@ -63,8 +65,8 @@ public class CoursesController { } - //TODO:此处需要调整前端的接口 @ApiOperation("查询课程列表") + @ValidateParams({"username"}) @GetMapping("/page") public BaseResponse> getCourses(CourseQuery courseQuery){ PageDTO coursesList = coursesService.queryCourses(courseQuery); @@ -74,9 +76,6 @@ public class CoursesController { @ApiOperation("根据id查询课程") @GetMapping("/{id}") public BaseResponse getByIdCourse(@PathVariable String id){ - if(id==null){ - throw new BusinessException(ErrorCode.PARAMS_ERROR,"课程id为空"); - } Courses course = coursesService.getById(id); CoursesDTO coursesDTO = new CoursesDTO(); BeanUtils.copyProperties(course,coursesDTO); @@ -84,6 +83,7 @@ public class CoursesController { } @ApiOperation("根据id修改课程") + @ValidateParams({"id","teacher","img", "category", "nature","name","code","credit","classhours","assessmenttype","assessmentway"}) @PutMapping public BaseResponse editCourse(@RequestBody CoursesDTO coursesDTO){ coursesService.updateCourse(coursesDTO); @@ -92,6 +92,7 @@ public class CoursesController { //TODO:删除功能暂未完善,数据缺失 @ApiOperation("根据id删除课程") + @ValidateParams({"id"}) @DeleteMapping("/{id}") public BaseResponse deleteCourses(@PathVariable String id){ diff --git a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentKnowController.java b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentKnowController.java index 5b12e02..628dec6 100644 --- a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentKnowController.java +++ b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentKnowController.java @@ -3,6 +3,7 @@ package com.teaching.backend.controller.courses; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.filter.ValidateParams; import com.teaching.backend.model.dto.courses.CoursesDTO; import com.teaching.backend.model.dto.courses.ObjectiveContentKnowDTO; import com.teaching.backend.model.vo.courses.ObjectiveContentKnowVO; @@ -31,6 +32,7 @@ public class ObjectiveContentKnowController { @ApiOperation("给分项目标或者是内容添加知识点") + @ValidateParams({"objectiveId","know"}) @PostMapping("/addknows") public BaseResponse saveKnowsWithObjectiveOrContent(@RequestBody ObjectiveContentKnowDTO objectiveContentKnowDTO){ String data = objectiveContentKnowService.saveKnowsWithObjectiveOrContent(objectiveContentKnowDTO); @@ -38,6 +40,7 @@ public class ObjectiveContentKnowController { } @ApiOperation("针对分项目标统计,支撑分项目标知识点的个数、学时合计、占比") + @ValidateParams({"objectiveId"}) @GetMapping("/{objectiveId}") public BaseResponse getCountData(@PathVariable String objectiveId){ ObjectiveContentKnowVO objectiveContentKnowVO= objectiveContentKnowService.getCountData(objectiveId); diff --git a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java index 755b53c..4dbabf0 100644 --- a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java +++ b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java @@ -3,6 +3,7 @@ package com.teaching.backend.controller.courses; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.filter.ValidateParams; import com.teaching.backend.model.entity.courses.ObjectiveContents; import com.teaching.backend.service.courses.IObjectiveContentsService; import io.swagger.annotations.Api; @@ -27,6 +28,7 @@ public class ObjectiveContentsController { IObjectiveContentsService objectiveContentsService; @ApiOperation("添加目标内容") + @ValidateParams({"objectiveId"}) @PostMapping("/addcontent") public BaseResponse saveContent(@RequestBody ObjectiveContents objectiveContents){ objectiveContentsService.save(objectiveContents); @@ -34,6 +36,7 @@ public class ObjectiveContentsController { } @ApiOperation("删除目标内容") + @ValidateParams({"id"}) @DeleteMapping("/{id}") public BaseResponse deleteContent(@PathVariable String id){ // objectiveContentsService.removeById(id); @@ -42,6 +45,7 @@ public class ObjectiveContentsController { } @ApiOperation("修改目标内容") + @ValidateParams({"id","objectiveId"}) @PutMapping("/update") public BaseResponse updateContent(@RequestBody ObjectiveContents objectiveContents){ objectiveContentsService.updateById(objectiveContents); @@ -49,6 +53,7 @@ public class ObjectiveContentsController { } @ApiOperation("根据id查询目标内容") + @ValidateParams({"id"}) @GetMapping("/{id}") public BaseResponse updateContent(@PathVariable String id){ ObjectiveContents objectiveContent = objectiveContentsService.getById(id); diff --git a/src/main/java/com/teaching/backend/exception/GlobalExceptionHandler.java b/src/main/java/com/teaching/backend/exception/GlobalExceptionHandler.java index 5af0a92..b904f85 100644 --- a/src/main/java/com/teaching/backend/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/teaching/backend/exception/GlobalExceptionHandler.java @@ -1,5 +1,8 @@ package com.teaching.backend.exception; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.ErrorCode; +import com.teaching.backend.common.ResultUtils; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -14,6 +17,11 @@ public class GlobalExceptionHandler { return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); } + @ExceptionHandler(Exception.class) + public BaseResponse handleException(Exception ex) { + return ResultUtils.error(ErrorCode.UNKNOW_ERROR, ex.getMessage()); + } + // 其他异常处理器可以按需添加 public static class ErrorResponse { diff --git a/src/main/java/com/teaching/backend/filter/BodyReaderWrapper.java b/src/main/java/com/teaching/backend/filter/BodyReaderWrapper.java new file mode 100644 index 0000000..adcab71 --- /dev/null +++ b/src/main/java/com/teaching/backend/filter/BodyReaderWrapper.java @@ -0,0 +1,51 @@ +package com.teaching.backend.filter; + +import org.apache.commons.io.IOUtils; + +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import java.io.*; + +public class BodyReaderWrapper extends HttpServletRequestWrapper { + private final byte[] requestBody; + + public BodyReaderWrapper(HttpServletRequest request) throws IOException { + super(request); + try (InputStream inputStream = request.getInputStream()) { + requestBody = IOUtils.toByteArray(inputStream); + } + } + + @Override + public ServletInputStream getInputStream() { + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(requestBody); + return new ServletInputStream() { + @Override + public boolean isFinished() { + return byteArrayInputStream.available() == 0; + } + + @Override + public boolean isReady() { + return true; + } + + @Override + public void setReadListener(ReadListener readListener) { + // no-op + } + + @Override + public int read() throws IOException { + return byteArrayInputStream.read(); + } + }; + } + + @Override + public BufferedReader getReader() throws IOException { + return new BufferedReader(new InputStreamReader(getInputStream())); + } +} diff --git a/src/main/java/com/teaching/backend/filter/ReplaceStreamFilter.java b/src/main/java/com/teaching/backend/filter/ReplaceStreamFilter.java new file mode 100644 index 0000000..b462e1a --- /dev/null +++ b/src/main/java/com/teaching/backend/filter/ReplaceStreamFilter.java @@ -0,0 +1,37 @@ +package com.teaching.backend.filter; + +import org.springframework.stereotype.Component; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +@Component +@WebFilter(urlPatterns = "/*") +public class ReplaceStreamFilter implements Filter { + + @Override + public void init(FilterConfig filterConfig) { + // no-op + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + ServletRequest requestWrapper = null; + if (request instanceof HttpServletRequest) { + requestWrapper = new BodyReaderWrapper((HttpServletRequest) request); + } + if (requestWrapper == null) { + chain.doFilter(request, response); + } else { + chain.doFilter(requestWrapper, response); + } + } + + @Override + public void destroy() { + // no-op + } +} + diff --git a/src/main/java/com/teaching/backend/filter/ValidateParams.java b/src/main/java/com/teaching/backend/filter/ValidateParams.java new file mode 100644 index 0000000..f582217 --- /dev/null +++ b/src/main/java/com/teaching/backend/filter/ValidateParams.java @@ -0,0 +1,13 @@ +package com.teaching.backend.filter; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface ValidateParams { + String[] value(); // 要校验的参数名称 +} + diff --git a/src/main/java/com/teaching/backend/filter/ValidationInterceptor.java b/src/main/java/com/teaching/backend/filter/ValidationInterceptor.java new file mode 100644 index 0000000..560935e --- /dev/null +++ b/src/main/java/com/teaching/backend/filter/ValidationInterceptor.java @@ -0,0 +1,83 @@ +package com.teaching.backend.filter; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +@Component +public class ValidationInterceptor implements HandlerInterceptor { + + @Autowired + private ObjectMapper objectMapper; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + if (handler instanceof HandlerMethod) { + HandlerMethod handlerMethod = (HandlerMethod) handler; + Method method = handlerMethod.getMethod(); + ValidateParams validateParams = method.getAnnotation(ValidateParams.class); + + if (validateParams != null) { + Map parameterMap = new HashMap<>(); + + // 处理路径变量 + parameterMap.putAll(getPathVariableValues(request, handlerMethod)); + + // 处理请求参数 + parameterMap.putAll(getRequestParamValues(request)); + + // 处理请求体中的参数 + if ("POST".equalsIgnoreCase(request.getMethod()) || "PUT".equalsIgnoreCase(request.getMethod())) { + Map bodyParams = objectMapper.readValue(request.getInputStream(), Map.class); + parameterMap.putAll(bodyParams); + } + + for (String paramName : validateParams.value()) { + Object paramValue = parameterMap.get(paramName); + + if (paramValue == null || (paramValue instanceof String && ((String) paramValue).trim().isEmpty())) { + handleErrorResponse(response, paramName + " 参数不能为空"); + return false; + } + } + } + } + return true; + } + + private Map getPathVariableValues(HttpServletRequest request, HandlerMethod handlerMethod) { + Map pathVariableValues = new HashMap<>(); + Map uriTemplateVars = (Map) request.getAttribute("org.springframework.web.servlet.HandlerMapping.uriTemplateVariables"); + if (uriTemplateVars != null) { + pathVariableValues.putAll(uriTemplateVars); + } + return pathVariableValues; + } + + private Map getRequestParamValues(HttpServletRequest request) { + Map requestParamValues = new HashMap<>(); + Map paramMap = request.getParameterMap(); + for (Map.Entry entry : paramMap.entrySet()) { + if (entry.getValue() != null && entry.getValue().length > 0) { + requestParamValues.put(entry.getKey(), entry.getValue()[0]); + } else { + requestParamValues.put(entry.getKey(), null); + } + } + return requestParamValues; + } + + private void handleErrorResponse(HttpServletResponse response, String errorMessage) throws IOException { + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.setContentType("application/json;charset=UTF-8"); + response.getWriter().write("{\"error\": \"" + errorMessage + "\"}"); + } +} diff --git a/src/main/java/com/teaching/backend/model/dto/courses/CoursesDTO.java b/src/main/java/com/teaching/backend/model/dto/courses/CoursesDTO.java index c038cf1..db604dd 100644 --- a/src/main/java/com/teaching/backend/model/dto/courses/CoursesDTO.java +++ b/src/main/java/com/teaching/backend/model/dto/courses/CoursesDTO.java @@ -28,7 +28,7 @@ public class CoursesDTO { /** * 课程封面 */ - @ApiModelProperty("图片") + @ApiModelProperty(value = "图片",required = true) private String img; /** diff --git a/src/main/java/com/teaching/backend/model/entity/courses/CourseObjectives.java b/src/main/java/com/teaching/backend/model/entity/courses/CourseObjectives.java index b037c6d..383fcf9 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/CourseObjectives.java +++ b/src/main/java/com/teaching/backend/model/entity/courses/CourseObjectives.java @@ -39,8 +39,6 @@ public class CourseObjectives implements Serializable { @ApiModelProperty(value = "是否有子节点") private Integer hasChild; - @ApiModelProperty(value = "目标名称") - private String name; @ApiModelProperty(value = "目标类型") private Integer type; diff --git a/src/main/java/com/teaching/backend/model/vo/courses/CourseObjectivesTreeVO.java b/src/main/java/com/teaching/backend/model/vo/courses/CourseObjectivesTreeVO.java index 21ee381..6fa8afd 100644 --- a/src/main/java/com/teaching/backend/model/vo/courses/CourseObjectivesTreeVO.java +++ b/src/main/java/com/teaching/backend/model/vo/courses/CourseObjectivesTreeVO.java @@ -13,6 +13,10 @@ import java.util.List; @ApiModel(description = "课程目标参数实体") public class CourseObjectivesTreeVO extends CourseObjectives implements Serializable { + + @ApiModelProperty(value = "目标名称") + private String name; + @ApiModelProperty(value = "目标内容列表") private List contents; diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java index a1d58f4..0272eb0 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java @@ -8,6 +8,7 @@ import com.teaching.backend.exception.BusinessException; import com.teaching.backend.mapper.courses.CourseObjectivesMapper; import com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper; import com.teaching.backend.mapper.courses.ObjectiveContentsMapper; +import com.teaching.backend.mapper.courses.ObjectivesTypeMapper; import com.teaching.backend.model.dto.courses.CourseObjectivesDTO; import com.teaching.backend.model.entity.courses.CourseObjectives; import com.teaching.backend.model.entity.courses.ObjectiveContentKnow; @@ -43,6 +44,8 @@ public class CourseObjectivesServiceImpl extends ServiceImpl objectives = courseObjectivesMapper.selectTreeNodes(courseObjectivesId); Map map = new HashMap<>(); for (CourseObjectivesTreeVO objective : objectives) { + objective.setName(objectivesTypeMapper.selectById(objective.getType()).getTypeName()); map.put(objective.getId(), objective); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index 19da937..ac1f8a5 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -81,10 +81,10 @@ public class CoursesServiceImpl extends ServiceImpl impl @Override @Transactional public String saveCourseWithObjective(CoursesDTO coursesDTO) { - String teacher = coursesDTO.getTeacher(); - if (teacher == null || teacher.equals("")) { - throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT); - } +// String teacher = coursesDTO.getTeacher(); +// if (teacher == null || teacher.equals("")) { +// throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT); +// } Courses courses = new Courses(); String courseId = UUID.randomUUID().toString().replace("-", ""); @@ -101,7 +101,8 @@ public class CoursesServiceImpl extends ServiceImpl impl if (insert > 0) { Courses coursesNew = coursesMapper.selectById(courseId); courseObjectives.setCourseId(courseId); - courseObjectives.setName(coursesNew.getName() + "课程总体目标"); + courseObjectives.setType(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue()); +// courseObjectives.setName(coursesNew.getName() + "课程总体目标"); int insertTotal = courseObjectivesMapper.insert(courseObjectives); if (insertTotal>0){ CourseObjectives courseTotalObjectives = courseObjectivesMapper.selectOne @@ -112,12 +113,14 @@ public class CoursesServiceImpl extends ServiceImpl impl CourseObjectives courseObjectivesF = null; for (ObjectivesType objectivesType : objectivesTypes) { Integer typeId = objectivesType.getId(); - String typeName = objectivesType.getTypeName(); - courseObjectivesF = new CourseObjectives(); - courseObjectivesF.setType(typeId); - courseObjectivesF.setName(typeName); - courseObjectivesF.setPid(courseTotalObjectivesId); - courseObjectivesFList.add(courseObjectivesF); + if (!typeId.equals(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue())){ +// String typeName = objectivesType.getTypeName(); + courseObjectivesF = new CourseObjectives(); + courseObjectivesF.setType(typeId); +// courseObjectivesF.setName(typeName); + courseObjectivesF.setPid(courseTotalObjectivesId); + courseObjectivesFList.add(courseObjectivesF); + } } courseObjectivesMapper.insertBatch(courseObjectivesFList); courseTotalObjectives.setHasChild(1); @@ -133,9 +136,9 @@ public class CoursesServiceImpl extends ServiceImpl impl @Override public PageDTO queryCourses(CourseQuery courseQuery) { String username = courseQuery.getUsername(); - if (username == null || username.isEmpty()) { - throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT); - } +// if (username == null || username.isEmpty()) { +// throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT); +// } UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper() .eq(UmsAdmin::getUsername, username)); @@ -220,9 +223,9 @@ public class CoursesServiceImpl extends ServiceImpl impl @Override public void deleteBatchByIds(String id) { - if(id==null){ - throw new BusinessException(ErrorCode.PARAMS_ERROR,"课程id为空"); - } +// if(id==null){ +// throw new BusinessException(ErrorCode.PARAMS_ERROR,"课程id为空"); +// } CourseObjectives courseObjectives= courseObjectivesMapper.selectOne (new LambdaQueryWrapper().eq(CourseObjectives::getCourseId, id)); if(courseObjectives == null){ diff --git a/src/main/java/com/teaching/backend/utils/CourseCode.java b/src/main/java/com/teaching/backend/utils/CourseCode.java index 0c9fc7b..ebac46b 100644 --- a/src/main/java/com/teaching/backend/utils/CourseCode.java +++ b/src/main/java/com/teaching/backend/utils/CourseCode.java @@ -9,6 +9,8 @@ public enum CourseCode { SI_ZHENG_EXIT(1, "思政目标存在"), KNOWS_EXIT(0, "存在关联的知识点"), TEACHER_ROLE_ID(1, "教师的角色id是1"), + TOTAL_OBJECTIVE_TYPE(5, "课程总目标"), + Total_EXIT(0, "课程总目标"), COURSE_UODATING(1, "课程正在修改中");