diff --git a/pom.xml b/pom.xml index 1bc5502..ee03296 100644 --- a/pom.xml +++ b/pom.xml @@ -154,6 +154,13 @@ org.springframework.boot spring-boot-starter-data-redis + + com.fasterxml.jackson.core + jackson-databind + 2.12.5 + compile + + diff --git a/src/main/java/com/teaching/TeachingBackendApplication.java b/src/main/java/com/teaching/TeachingBackendApplication.java index 0db15d2..fd5e055 100644 --- a/src/main/java/com/teaching/TeachingBackendApplication.java +++ b/src/main/java/com/teaching/TeachingBackendApplication.java @@ -1,8 +1,10 @@ package com.teaching; +import cn.hutool.core.lang.generator.SnowflakeGenerator; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; @SpringBootApplication @MapperScan("com.teaching.backend.mapper") @@ -11,8 +13,11 @@ public class TeachingBackendApplication { public static void main(String[] args) { SpringApplication.run(TeachingBackendApplication.class, args); + } - + @Bean + SnowflakeGenerator snowflakeGenerator(){ + return new SnowflakeGenerator(1,0); } } diff --git a/src/main/java/com/teaching/backend/common/ErrorCode.java b/src/main/java/com/teaching/backend/common/ErrorCode.java index 99341f2..f166ba9 100644 --- a/src/main/java/com/teaching/backend/common/ErrorCode.java +++ b/src/main/java/com/teaching/backend/common/ErrorCode.java @@ -14,10 +14,11 @@ public enum ErrorCode { KONWID_NOT_EXIT(40002, "没有选择知识点"), OBJECTIVE_OR_CONTENT_EXIT(40003, "该记录已存在"), KNOW_NOT_EXIT(40004, "知识点不存在"), - TEACHER_NOT_EXIT(40005, "缺少教师信息"), + USERNAME_NOT_EXIT(40005, "缺少用户信息"), STUDENT_NOT_EXIT(40006, "缺少学生信息"), COURSES_NOT_EXIT(40007, "缺少课程信息"), - + CONTENT_NOT_EXIT(40008, "内容id不存在"), + KNOWS_EXIT(40009, "该项下面存在关联的知识点"), NOT_LOGIN_ERROR(40100, "未登录"), NO_AUTH_ERROR(40101, "无权限"), NOT_FOUND_ERROR(40400, "请求数据不存在"), 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 777e7b6..2a6e1a1 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java @@ -51,7 +51,6 @@ public class CourseObjectivesController { } /** - * 禁止修改课程编码和名称 * @param courseObjectivesDTO * @return */ 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 078809c..16ca638 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -91,7 +91,7 @@ public class CoursesController { return ResultUtils.success("编辑成功"); } - //TODO:删除功能暂未完善,数据表缺失 + //TODO:删除功能暂未完善,数据缺失 @ApiOperation("根据id删除课程") @DeleteMapping("/{id}") public BaseResponse deleteCourses(@PathVariable String id){ 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 66afe28..0fd4b7f 100644 --- a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java +++ b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java @@ -36,8 +36,9 @@ public class ObjectiveContentsController { @ApiOperation("删除目标内容") @DeleteMapping("/{id}") public BaseResponse deleteContent(@PathVariable String id){ - objectiveContentsService.removeById(id); - return ResultUtils.success("删除成功"); +// objectiveContentsService.removeById(id); + String data = objectiveContentsService.deleteById(id); + return ResultUtils.success(data); } @ApiOperation("修改目标内容") diff --git a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsAdminController.java b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsAdminController.java index 13d1cf5..441a979 100644 --- a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsAdminController.java +++ b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsAdminController.java @@ -2,15 +2,23 @@ package com.teaching.backend.controller.umsAdmin; import cn.hutool.core.collection.CollUtil; import com.teaching.backend.api.CommonResult; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.ErrorCode; +import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.exception.BusinessException; import com.teaching.backend.model.dto.UmsAdminParam; import com.teaching.backend.model.dto.UpdateAdminPasswordParam; +import com.teaching.backend.model.dto.courses.CoursesDTO; +import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; import com.teaching.backend.model.entity.umsAdmin.UmsRole; +import com.teaching.backend.model.vo.courses.TeacherInfVO; import com.teaching.backend.service.umsAdmin.UmsAdminService; import com.teaching.backend.service.umsAdmin.UmsRoleService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; @@ -166,4 +174,11 @@ public class UmsAdminController { } } + @ApiOperation("获取教师信息列表,关联教师的username和name") + @GetMapping("/get_teacherinf_list") + public BaseResponse> getTeacherInfList(){ + List teacherInfVO = umsAdminService.getTeacherInfList(); + return ResultUtils.success(teacherInfVO); + } + } diff --git a/src/main/java/com/teaching/backend/mapper/courses/CourseObjectivesMapper.java b/src/main/java/com/teaching/backend/mapper/courses/CourseObjectivesMapper.java index 7de5035..4dc7e25 100644 --- a/src/main/java/com/teaching/backend/mapper/courses/CourseObjectivesMapper.java +++ b/src/main/java/com/teaching/backend/mapper/courses/CourseObjectivesMapper.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.teaching.backend.model.entity.courses.CourseObjectives; import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; +import java.util.ArrayList; import java.util.List; /** @@ -17,4 +18,6 @@ import java.util.List; public interface CourseObjectivesMapper extends BaseMapper { List selectTreeNodes(String courseObjectivesId); + + void insertBatch(ArrayList courseObjectivesFList); } diff --git a/src/main/java/com/teaching/backend/mapper/courses/ObjectiveContentKnowMapper.java b/src/main/java/com/teaching/backend/mapper/courses/ObjectiveContentKnowMapper.java index 98d2b90..1222d1a 100644 --- a/src/main/java/com/teaching/backend/mapper/courses/ObjectiveContentKnowMapper.java +++ b/src/main/java/com/teaching/backend/mapper/courses/ObjectiveContentKnowMapper.java @@ -3,6 +3,8 @@ package com.teaching.backend.mapper.courses; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.teaching.backend.model.entity.courses.ObjectiveContentKnow; +import java.util.List; + /** *

* Mapper 接口 @@ -13,4 +15,5 @@ import com.teaching.backend.model.entity.courses.ObjectiveContentKnow; */ public interface ObjectiveContentKnowMapper extends BaseMapper { + void insertBatchSomeColumn(List objectiveContentKnowList); } diff --git a/src/main/java/com/teaching/backend/mapper/courses/StudentCoursesMapper.java b/src/main/java/com/teaching/backend/mapper/courses/StudentCoursesMapper.java index ea9cb28..b6042f9 100644 --- a/src/main/java/com/teaching/backend/mapper/courses/StudentCoursesMapper.java +++ b/src/main/java/com/teaching/backend/mapper/courses/StudentCoursesMapper.java @@ -1,8 +1,11 @@ package com.teaching.backend.mapper.courses; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.teaching.backend.model.entity.courses.ObjectiveContentKnow; import com.teaching.backend.model.entity.courses.StudentCourses; +import java.util.List; + /** *

* Mapper 接口 @@ -13,4 +16,5 @@ import com.teaching.backend.model.entity.courses.StudentCourses; */ public interface StudentCoursesMapper extends BaseMapper { + void insertBatchSomeColumn(List studentCoursesList); } diff --git a/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java b/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java index b49a21c..fb91204 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java +++ b/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java @@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; @@ -24,8 +27,13 @@ public class ObjectiveContentKnow implements Serializable { private static final long serialVersionUID = 1L; - @TableId(value = "id", type = IdType.ASSIGN_UUID) - private String id; + @ApiModelProperty(value = "雪花算法生成的主键") + @JsonFormat(shape = JsonFormat.Shape.STRING)//此句为问题关键相当于吧Long转换为String + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + +// @TableId(value = "id", type = IdType.NONE) +// private Long id; /** * 分项目标或内容 的 id diff --git a/src/main/java/com/teaching/backend/model/entity/courses/StudentCourses.java b/src/main/java/com/teaching/backend/model/entity/courses/StudentCourses.java index acc0c54..b3125f7 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/StudentCourses.java +++ b/src/main/java/com/teaching/backend/model/entity/courses/StudentCourses.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; @@ -24,8 +26,9 @@ public class StudentCourses implements Serializable { private static final long serialVersionUID = 1L; - @TableId(value = "id", type = IdType.ASSIGN_UUID) - private String id; + @TableId(value = "id", type = IdType.ASSIGN_ID) + @JsonFormat(shape = JsonFormat.Shape.STRING)//此句为问题关键相当于吧Long转换为String + private Long id; /** * 学生的username diff --git a/src/main/java/com/teaching/backend/model/query/CourseQuery.java b/src/main/java/com/teaching/backend/model/query/CourseQuery.java index d091993..13dbc8b 100644 --- a/src/main/java/com/teaching/backend/model/query/CourseQuery.java +++ b/src/main/java/com/teaching/backend/model/query/CourseQuery.java @@ -14,4 +14,16 @@ public class CourseQuery extends PageQuery { @ApiModelProperty(value = "用户的username",required = true) private String username; + + @ApiModelProperty("课程任课教师") + private String teacher; + + @ApiModelProperty("课程类别") + private String category; + + @ApiModelProperty("课程性质") + private String nature; + + @ApiModelProperty("课程考核类型") + private String assessmenttype; } diff --git a/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java b/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java new file mode 100644 index 0000000..66a317e --- /dev/null +++ b/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java @@ -0,0 +1,22 @@ +package com.teaching.backend.model.vo.courses; + + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(description = "教师具体信息VO实体") +public class TeacherInfVO { + + /** + * 教师username + */ + @ApiModelProperty("教师username") + private String username; + /** + * 课程封面 + */ + @ApiModelProperty("教师name") + private String name; +} diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index c69b060..2737450 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -36,4 +36,6 @@ public interface ICoursesService extends IService { void updateCourse(CoursesDTO coursesDTO); void down(HttpServletResponse response, String id) throws Exception; + + void populateTeacherNames(List courseList); } diff --git a/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java b/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java index c3a75d1..b031659 100644 --- a/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java +++ b/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java @@ -14,4 +14,6 @@ import com.teaching.backend.model.entity.courses.ObjectiveContents; */ public interface IObjectiveContentsService extends IService { + + String deleteById(String id); } 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 88c4816..a1d58f4 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 @@ -6,9 +6,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.common.ErrorCode; 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.model.dto.courses.CourseObjectivesDTO; import com.teaching.backend.model.entity.courses.CourseObjectives; +import com.teaching.backend.model.entity.courses.ObjectiveContentKnow; import com.teaching.backend.model.entity.courses.ObjectiveContents; import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; import com.teaching.backend.service.courses.ICourseObjectivesService; @@ -39,6 +41,8 @@ public class CourseObjectivesServiceImpl extends ServiceImpl() + .eq(ObjectiveContentKnow::getObjectiveOrContent, id)); + if(count > CourseCode.KNOWS_EXIT.getValue()){ + throw new BusinessException(ErrorCode.KNOWS_EXIT); + } String pid = courseObjectives.getPid(); if (type.equals(CourseCode.SI_ZHENG_TYPE.getValue())){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); 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 23bf545..9a7d330 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 @@ -3,6 +3,7 @@ package com.teaching.backend.service.impl.courses; import cn.afterturn.easypoi.word.WordExportUtil; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.lang.UUID; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -14,6 +15,7 @@ import com.teaching.backend.mapper.courses.CoursesMapper; import com.teaching.backend.mapper.courses.ObjectiveContentsMapper; import com.teaching.backend.mapper.courses.ObjectivesTypeMapper; import com.teaching.backend.mapper.umsAdmin.UmsAdminMapper; +import com.teaching.backend.mapper.umsAdmin.UmsAdminRoleRelationMapper; import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; import com.teaching.backend.model.dto.courses.CoursesDTO; import com.teaching.backend.model.dto.courses.PageDTO; @@ -22,6 +24,7 @@ import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.courses.ObjectiveContents; import com.teaching.backend.model.entity.courses.ObjectivesType; import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; +import com.teaching.backend.model.entity.umsAdmin.UmsAdminRoleRelation; import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; import com.teaching.backend.model.query.CourseQuery; import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; @@ -66,6 +69,8 @@ public class CoursesServiceImpl extends ServiceImpl impl UmsAdminMapper umsAdminMapper; @Autowired UmsTeacherMapper umsTeacherMapper; + @Autowired + UmsAdminRoleRelationMapper umsAdminRoleRelationMapper; @Override @@ -73,12 +78,15 @@ public class CoursesServiceImpl extends ServiceImpl impl public String saveCourseWithObjective(CoursesDTO coursesDTO) { String teacher = coursesDTO.getTeacher(); if (teacher == null || teacher.equals("")) { - throw new BusinessException(ErrorCode.TEACHER_NOT_EXIT); + throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT); } Courses courses = new Courses(); + String courseId = UUID.randomUUID().toString().replace("-", ""); + CourseObjectives courseObjectives = new CourseObjectives(); BeanUtils.copyProperties(coursesDTO, courses); courses.setCreateTime(LocalDateTime.now()); + courses.setId(courseId); String code = coursesDTO.getCode(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("code", code); @@ -86,24 +94,27 @@ public class CoursesServiceImpl extends ServiceImpl impl if (count == 0) { int insert = coursesMapper.insert(courses); if (insert > 0) { - Courses coursesNew = coursesMapper.selectOne(queryWrapper); - courseObjectives.setCourseId(coursesNew.getId()); + Courses coursesNew = coursesMapper.selectById(courseId); + courseObjectives.setCourseId(courseId); courseObjectives.setName(coursesNew.getName() + "课程总体目标"); int insertTotal = courseObjectivesMapper.insert(courseObjectives); if (insertTotal>0){ CourseObjectives courseTotalObjectives = courseObjectivesMapper.selectOne - (new LambdaQueryWrapper().eq(CourseObjectives::getCourseId, coursesNew.getId())); + (new LambdaQueryWrapper().eq(CourseObjectives::getCourseId, courseId)); String courseTotalObjectivesId = courseTotalObjectives.getId(); List objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper()); + ArrayList courseObjectivesFList = new ArrayList<>(); + CourseObjectives courseObjectivesF = null; for (ObjectivesType objectivesType : objectivesTypes) { Integer typeId = objectivesType.getId(); String typeName = objectivesType.getTypeName(); - CourseObjectives courseObjectivesF = new CourseObjectives(); + courseObjectivesF = new CourseObjectives(); courseObjectivesF.setType(typeId); courseObjectivesF.setName(typeName); courseObjectivesF.setPid(courseTotalObjectivesId); - courseObjectivesMapper.insert(courseObjectivesF); + courseObjectivesFList.add(courseObjectivesF); } + courseObjectivesMapper.insertBatch(courseObjectivesFList); courseTotalObjectives.setHasChild(1); courseObjectivesMapper.updateById(courseTotalObjectives); } @@ -118,42 +129,50 @@ public class CoursesServiceImpl extends ServiceImpl impl @Override public PageDTO queryCourses(CourseQuery courseQuery) { String username = courseQuery.getUsername(); - if (username==null || username.equals("")){ - throw new BusinessException(ErrorCode.TEACHER_NOT_EXIT); + if (username == null || username.isEmpty()) { + throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT); } - //要搜索的课程名字 - String name = courseQuery.getName(); - // 1.1构建分页条件 + + UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper() + .eq(UmsAdmin::getUsername, username)); + UmsAdminRoleRelation umsAdminRoleRelation = umsAdminRoleRelationMapper.selectOne(new LambdaQueryWrapper() + .eq(UmsAdminRoleRelation::getAdminId, umsAdmin.getId())); + + // Determine if the user is a teacher + boolean isTeacher = umsAdminRoleRelation.getRoleId() == CourseCode.TEACHER_ROLE_ID.getValue(); + Page page = courseQuery.toMpPageDefaultSortByCreateTime(); - // 2.分页查询 Page p = lambdaQuery() - .like(name != null, Courses::getName, name) -// .eq(Courses::getTeacher,teacherId) -// .apply("JSON_CONTAINS(teacher, JSON_QUOTE({0}))", teacherId) - .apply("FIND_IN_SET({0}, teacher)", username) + .like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) + .apply(isTeacher, "FIND_IN_SET({0}, teacher)", username) + .eq(!isTeacher && courseQuery.getCategory() != null, Courses::getCategory, courseQuery.getCategory()) + .eq(!isTeacher && courseQuery.getNature() != null, Courses::getNature, courseQuery.getNature()) + .eq(!isTeacher && courseQuery.getAssessmenttype() != null, Courses::getAssessmenttype, courseQuery.getAssessmenttype()) + .apply(!isTeacher && courseQuery.getTeacher() != null && !courseQuery.getTeacher().isEmpty(), "FIND_IN_SET({0}, teacher)", courseQuery.getTeacher()) .page(page); + PageDTO coursesVOPageDTO = PageDTO.of(p, CoursesVO.class); - List pageDTOList = coursesVOPageDTO.getList(); - List teachers = null; + populateTeacherNames(coursesVOPageDTO.getList()); - for (CoursesVO coursesVO : pageDTOList) { + return coursesVOPageDTO; + } + + public void populateTeacherNames(List courseList) { + for (CoursesVO coursesVO : courseList) { List teacherNameList = new ArrayList<>(); - String teacherIds = coursesVO.getTeacher(); - teachers = new ArrayList<>(Arrays.asList(teacherIds.split(","))); - for (String teacher : teachers) { - UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper(). - eq(UmsAdmin::getUsername, teacher)); - if (umsAdmin==null){ + String[] teacherIds = coursesVO.getTeacher().split(","); + for (String teacherId : teacherIds) { + UmsAdmin umsAdminTea = umsAdminMapper.selectOne(new LambdaQueryWrapper() + .eq(UmsAdmin::getUsername, teacherId)); + if (umsAdminTea == null) { throw new BusinessException(ErrorCode.OPERATION_ERROR); } - Long adminId = umsAdmin.getId(); UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsTeacher::getUserId, adminId)); + .eq(UmsTeacher::getUserId, umsAdminTea.getId())); teacherNameList.add(umsTeacher.getName()); } coursesVO.setTeacher(String.join(",", teacherNameList)); } - return coursesVOPageDTO; } @Override diff --git a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java index 6b42b66..2dac173 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java @@ -1,5 +1,6 @@ package com.teaching.backend.service.impl.courses; +import cn.hutool.core.lang.generator.SnowflakeGenerator; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.common.ErrorCode; @@ -26,6 +27,7 @@ import java.sql.SQLIntegrityConstraintViolationException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.UUID; import java.util.stream.Collectors; /** @@ -49,7 +51,10 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl knowIds = new ArrayList<>(Arrays.asList(knows.split(","))); - ObjectiveContentKnow objectiveContentKnow = null; + List objectiveContentKnowList = new ArrayList<>(); + for (String knowId : knowIds) { + ObjectiveContentKnow objectiveContentKnow = new ObjectiveContentKnow(); +// objectiveContentKnow.setId(snowflakeGenerator.next()); + objectiveContentKnow.setObjectiveOrContent(objectiveOrContent); + objectiveContentKnow.setKnow(knowId); + objectiveContentKnowList.add(objectiveContentKnow); + } + try { - for (String knowId : knowIds) { - objectiveContentKnow = new ObjectiveContentKnow(); - objectiveContentKnow.setObjectiveOrContent(objectiveOrContent); - objectiveContentKnow.setKnow(knowId); - objectiveContentKnowMapper.insert(objectiveContentKnow); - } + objectiveContentKnowMapper.insertBatchSomeColumn(objectiveContentKnowList); } catch (Exception e) { e.printStackTrace(); throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_EXIT); } + return "添加成功"; } @@ -118,7 +127,7 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl { BigDecimal contentPercentage = calculatePercentage(contentKnowVO.getKnowsTime(), classhours); contentKnowVO.setPersent(contentPercentage + "%"); @@ -161,8 +170,8 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl implements IObjectiveContentsService { + @Autowired + ObjectiveContentKnowMapper objectiveContentKnowMapper; + @Autowired + ObjectiveContentsMapper objectiveContentsMapper; + @Override + public String deleteById(String id) { + if (id == null){ + throw new BusinessException(ErrorCode.CONTENT_NOT_EXIT); + } + Long count = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper() + .eq(ObjectiveContentKnow::getObjectiveOrContent, id)); + if(count > CourseCode.KNOWS_EXIT.getValue()){ + throw new BusinessException(ErrorCode.KNOWS_EXIT); + } + int delete = objectiveContentsMapper.deleteById(id); + return delete>0 ? "删除成功!" : "删除失败!"; + } } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java index 63e6b64..c553c44 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java @@ -1,6 +1,7 @@ package com.teaching.backend.service.impl.courses; +import cn.hutool.core.lang.generator.SnowflakeGenerator; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -20,6 +21,7 @@ import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; import com.teaching.backend.model.query.CourseQuery; import com.teaching.backend.model.vo.courses.CoursesVO; +import com.teaching.backend.service.courses.ICoursesService; import com.teaching.backend.service.courses.IStudentCoursesService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -49,6 +51,11 @@ public class StudentCoursesServiceImpl extends ServiceImpl coursesIds = new ArrayList<>(Arrays.asList(courses.split(","))); + List studentCoursesList = new ArrayList<>(); StudentCourses studentCourses = null; + + for (String course : coursesIds) { + studentCourses = new StudentCourses(); + studentCourses.setStudent(studentId); + studentCourses.setCourse(course); + studentCoursesList.add(studentCourses); + } try { - for (String course : coursesIds) { - studentCourses = new StudentCourses(); - studentCourses.setStudent(studentId); - studentCourses.setCourse(course); - studentCoursesMapper.insert(studentCourses); - } + studentCoursesMapper.insertBatchSomeColumn(studentCoursesList); } catch (Exception e) { e.printStackTrace(); throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_EXIT); @@ -79,7 +89,7 @@ public class StudentCoursesServiceImpl extends ServiceImpl queryCourses(CourseQuery courseQuery) { String username = courseQuery.getUsername(); - if (username==null || username.equals("")){ + if (username == null || username.equals("")) { throw new BusinessException(ErrorCode.STUDENT_NOT_EXIT); } List studentCourses = studentCoursesMapper.selectList(new LambdaQueryWrapper() @@ -99,26 +109,9 @@ public class StudentCoursesServiceImpl extends ServiceImpl p = this.coursesMapper.selectPage(page, queryWrapper); PageDTO coursesVOPageDTO = PageDTO.of(p, CoursesVO.class); - List pageDTOList = coursesVOPageDTO.getList(); - List teachers = null; - for (CoursesVO coursesVO : pageDTOList) { - List teacherNameList = new ArrayList<>(); - String teacherIds = coursesVO.getTeacher(); - teachers = new ArrayList<>(Arrays.asList(teacherIds.split(","))); - for (String teacher : teachers) { - UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper(). - eq(UmsAdmin::getUsername, teacher)); - if (umsAdmin==null){ - throw new BusinessException(ErrorCode.OPERATION_ERROR); - } - Long adminId = umsAdmin.getId(); - UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsTeacher::getUserId, adminId)); - teacherNameList.add(umsTeacher.getName()); - } - coursesVO.setTeacher(String.join(",", teacherNameList)); - } + coursesService.populateTeacherNames(coursesVOPageDTO.getList()); + return coursesVOPageDTO; } } diff --git a/src/main/java/com/teaching/backend/service/umsAdmin/UmsAdminService.java b/src/main/java/com/teaching/backend/service/umsAdmin/UmsAdminService.java index 8e90b61..2c02b2f 100644 --- a/src/main/java/com/teaching/backend/service/umsAdmin/UmsAdminService.java +++ b/src/main/java/com/teaching/backend/service/umsAdmin/UmsAdminService.java @@ -6,6 +6,7 @@ import com.teaching.backend.model.dto.UpdateAdminPasswordParam; import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; import com.teaching.backend.model.entity.umsAdmin.UmsResource; import com.teaching.backend.model.entity.umsAdmin.UmsRole; +import com.teaching.backend.model.vo.courses.TeacherInfVO; import org.springframework.security.core.userdetails.UserDetails; import java.util.List; @@ -76,4 +77,6 @@ public interface UmsAdminService extends IService { * 手机号登录 */ String phoneLogin(String phone); + + List getTeacherInfList(); } diff --git a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsAdminServiceImpl.java b/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsAdminServiceImpl.java index 0eeb61f..c9dfb79 100644 --- a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsAdminServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsAdminServiceImpl.java @@ -4,18 +4,18 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.gson.Gson; import com.teaching.backend.exception.Asserts; import com.teaching.backend.exception.LyException; import com.teaching.backend.mapper.umsAdmin.UmsAdminMapper; import com.teaching.backend.mapper.umsAdmin.UmsAdminRoleRelationMapper; +import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; import com.teaching.backend.model.dto.UmsAdminParam; import com.teaching.backend.model.dto.UpdateAdminPasswordParam; -import com.teaching.backend.model.entity.umsAdmin.AdminUserDetails; -import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; -import com.teaching.backend.model.entity.umsAdmin.UmsResource; -import com.teaching.backend.model.entity.umsAdmin.UmsRole; +import com.teaching.backend.model.entity.umsAdmin.*; +import com.teaching.backend.model.vo.courses.TeacherInfVO; import com.teaching.backend.service.umsAdmin.UmsAdminService; import com.teaching.backend.utils.JwtTokenUtil; import com.teaching.backend.utils.RegexUtils; @@ -40,6 +40,7 @@ import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.profile.DefaultProfile; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -58,6 +59,10 @@ public class UmsAdminServiceImpl extends ServiceImpl i private AmqpTemplate amqpTemplate; @Autowired private StringRedisTemplate redisTemplate; + @Autowired + UmsTeacherMapper umsTeacherMapper; + @Autowired + UmsAdminMapper umsAdminMapper; @Override @@ -128,6 +133,8 @@ public class UmsAdminServiceImpl extends ServiceImpl i return token; } + + @Override public boolean updateUms(UmsAdmin umsadmin) { if (umsadmin.getPassword().length() > 0){ @@ -280,4 +287,20 @@ public class UmsAdminServiceImpl extends ServiceImpl i throw new UsernameNotFoundException("用户名或密码错误"); } + @Override + public List getTeacherInfList() { + List umsTeachers = umsTeacherMapper.selectList(new LambdaQueryWrapper()); + TeacherInfVO teacherInfVO = null; + List teacherInfList = new ArrayList<>();; + for (UmsTeacher umsTeacher : umsTeachers) { + teacherInfVO = new TeacherInfVO(); + UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper() + .eq(UmsAdmin::getId, umsTeacher.getUserId())); + teacherInfVO.setName(umsTeacher.getName()); + teacherInfVO.setUsername(umsAdmin.getUsername()); + teacherInfList.add(teacherInfVO); + } + return teacherInfList; + } + } diff --git a/src/main/java/com/teaching/backend/utils/CourseCode.java b/src/main/java/com/teaching/backend/utils/CourseCode.java index 18f50fb..0c9fc7b 100644 --- a/src/main/java/com/teaching/backend/utils/CourseCode.java +++ b/src/main/java/com/teaching/backend/utils/CourseCode.java @@ -7,6 +7,8 @@ public enum CourseCode { CONTENT_EXIT(1, "存在内容"), SI_ZHENG_TYPE(1, "思政目标类型"), SI_ZHENG_EXIT(1, "思政目标存在"), + KNOWS_EXIT(0, "存在关联的知识点"), + TEACHER_ROLE_ID(1, "教师的角色id是1"), Total_EXIT(0, "课程总目标"), COURSE_UODATING(1, "课程正在修改中"); diff --git a/src/main/resources/mapper/CourseObjectivesMapper.xml b/src/main/resources/mapper/CourseObjectivesMapper.xml index 1204030..91dd5a0 100644 --- a/src/main/resources/mapper/CourseObjectivesMapper.xml +++ b/src/main/resources/mapper/CourseObjectivesMapper.xml @@ -12,4 +12,13 @@ select * from t1 order by t1.pid + + + INSERT INTO course_objectives (id, type, name, pid) + VALUES + + (#{item.id}, #{item.type}, #{item.name},#{item.pid}) + + + diff --git a/src/main/resources/mapper/ObjectiveContentKnowMapper.xml b/src/main/resources/mapper/ObjectiveContentKnowMapper.xml index b764958..9ae17ca 100644 --- a/src/main/resources/mapper/ObjectiveContentKnowMapper.xml +++ b/src/main/resources/mapper/ObjectiveContentKnowMapper.xml @@ -2,4 +2,12 @@ + + INSERT INTO objective_content_know (objective_or_content, know) + VALUES + + (#{item.objectiveOrContent}, #{item.know}) + + + diff --git a/src/main/resources/mapper/StudentCoursesMapper.xml b/src/main/resources/mapper/StudentCoursesMapper.xml index 6b5568e..dfd2bba 100644 --- a/src/main/resources/mapper/StudentCoursesMapper.xml +++ b/src/main/resources/mapper/StudentCoursesMapper.xml @@ -2,4 +2,11 @@ + + INSERT INTO student_courses (student, course) + VALUES + + (#{item.student}, #{item.course}) + +