课程相关代码优化

实现教师,管理员分角色登录,课程信息的筛选
教师信息的查询(username,name)
master
Alan 5 months ago
parent 78cec55647
commit 00238731ba
  1. 7
      pom.xml
  2. 7
      src/main/java/com/teaching/TeachingBackendApplication.java
  3. 5
      src/main/java/com/teaching/backend/common/ErrorCode.java
  4. 1
      src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java
  5. 2
      src/main/java/com/teaching/backend/controller/courses/CoursesController.java
  6. 5
      src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java
  7. 15
      src/main/java/com/teaching/backend/controller/umsAdmin/UmsAdminController.java
  8. 3
      src/main/java/com/teaching/backend/mapper/courses/CourseObjectivesMapper.java
  9. 3
      src/main/java/com/teaching/backend/mapper/courses/ObjectiveContentKnowMapper.java
  10. 4
      src/main/java/com/teaching/backend/mapper/courses/StudentCoursesMapper.java
  11. 12
      src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java
  12. 7
      src/main/java/com/teaching/backend/model/entity/courses/StudentCourses.java
  13. 12
      src/main/java/com/teaching/backend/model/query/CourseQuery.java
  14. 22
      src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java
  15. 2
      src/main/java/com/teaching/backend/service/courses/ICoursesService.java
  16. 2
      src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java
  17. 11
      src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java
  18. 75
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  19. 29
      src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java
  20. 25
      src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentsServiceImpl.java
  21. 45
      src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java
  22. 3
      src/main/java/com/teaching/backend/service/umsAdmin/UmsAdminService.java
  23. 31
      src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsAdminServiceImpl.java
  24. 2
      src/main/java/com/teaching/backend/utils/CourseCode.java
  25. 9
      src/main/resources/mapper/CourseObjectivesMapper.xml
  26. 8
      src/main/resources/mapper/ObjectiveContentKnowMapper.xml
  27. 7
      src/main/resources/mapper/StudentCoursesMapper.xml

@ -154,6 +154,13 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.5</version>
<scope>compile</scope>
</dependency>
<!--easypoi-->
<dependency>

@ -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);
}
}

@ -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, "请求数据不存在"),

@ -51,7 +51,6 @@ public class CourseObjectivesController {
}
/**
* 禁止修改课程编码和名称
* @param courseObjectivesDTO
* @return
*/

@ -91,7 +91,7 @@ public class CoursesController {
return ResultUtils.success("编辑成功");
}
//TODO:删除功能暂未完善,数据缺失
//TODO:删除功能暂未完善,数据缺失
@ApiOperation("根据id删除课程")
@DeleteMapping("/{id}")
public BaseResponse deleteCourses(@PathVariable String id){

@ -36,8 +36,9 @@ public class ObjectiveContentsController {
@ApiOperation("删除目标内容")
@DeleteMapping("/{id}")
public BaseResponse<String> deleteContent(@PathVariable String id){
objectiveContentsService.removeById(id);
return ResultUtils.success("删除成功");
// objectiveContentsService.removeById(id);
String data = objectiveContentsService.deleteById(id);
return ResultUtils.success(data);
}
@ApiOperation("修改目标内容")

@ -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<List<TeacherInfVO>> getTeacherInfList(){
List<TeacherInfVO> teacherInfVO = umsAdminService.getTeacherInfList();
return ResultUtils.success(teacherInfVO);
}
}

@ -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<CourseObjectives> {
List<CourseObjectivesTreeVO> selectTreeNodes(String courseObjectivesId);
void insertBatch(ArrayList<CourseObjectives> courseObjectivesFList);
}

@ -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;
/**
* <p>
* Mapper 接口
@ -13,4 +15,5 @@ import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
*/
public interface ObjectiveContentKnowMapper extends BaseMapper<ObjectiveContentKnow> {
void insertBatchSomeColumn(List<ObjectiveContentKnow> objectiveContentKnowList);
}

@ -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;
/**
* <p>
* Mapper 接口
@ -13,4 +16,5 @@ import com.teaching.backend.model.entity.courses.StudentCourses;
*/
public interface StudentCoursesMapper extends BaseMapper<StudentCourses> {
void insertBatchSomeColumn(List<StudentCourses> studentCoursesList);
}

@ -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

@ -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

@ -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;
}

@ -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;
}

@ -36,4 +36,6 @@ public interface ICoursesService extends IService<Courses> {
void updateCourse(CoursesDTO coursesDTO);
void down(HttpServletResponse response, String id) throws Exception;
void populateTeacherNames(List<CoursesVO> courseList);
}

@ -14,4 +14,6 @@ import com.teaching.backend.model.entity.courses.ObjectiveContents;
*/
public interface IObjectiveContentsService extends IService<ObjectiveContents> {
String deleteById(String id);
}

@ -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<CourseObjectivesMap
@Autowired
ObjectiveContentsMapper objectiveContentsMapper;
@Autowired
ObjectiveContentKnowMapper objectiveContentKnowMapper;
@Override
@Transactional
@ -88,6 +92,7 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
* 首先检查是不是思政目标如果是思政目标就要看此时的总目标下面有没有别的分项目标了如果有不准删除
* 如果此时只有分项目标检查分项目标下面有没有内容如果有禁止删除
* 删除分项目标也要检查下面有没有内容
* 内容还有关联的知识点也不能删在内容管理删除那边已实现
* @param id
* @return
*/
@ -102,6 +107,12 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
if (type == CourseCode.Total_EXIT.getValue()){
throw new BusinessException(ErrorCode.OPERATION_ERROR,"课程总目标只需清除所列内容即可!");
}
//TODO:等到删完内容后判断还是上来就判断?
Long count = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper<ObjectiveContentKnow>()
.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<CourseObjectives> queryWrapper = new LambdaQueryWrapper<>();

@ -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<CoursesMapper, Courses> impl
UmsAdminMapper umsAdminMapper;
@Autowired
UmsTeacherMapper umsTeacherMapper;
@Autowired
UmsAdminRoleRelationMapper umsAdminRoleRelationMapper;
@Override
@ -73,12 +78,15 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> 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<Courses> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("code", code);
@ -86,24 +94,27 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> 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<CourseObjectives>().eq(CourseObjectives::getCourseId, coursesNew.getId()));
(new LambdaQueryWrapper<CourseObjectives>().eq(CourseObjectives::getCourseId, courseId));
String courseTotalObjectivesId = courseTotalObjectives.getId();
List<ObjectivesType> objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper<ObjectivesType>());
ArrayList<CourseObjectives> 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<CoursesMapper, Courses> impl
@Override
public PageDTO<CoursesVO> 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<UmsAdmin>()
.eq(UmsAdmin::getUsername, username));
UmsAdminRoleRelation umsAdminRoleRelation = umsAdminRoleRelationMapper.selectOne(new LambdaQueryWrapper<UmsAdminRoleRelation>()
.eq(UmsAdminRoleRelation::getAdminId, umsAdmin.getId()));
// Determine if the user is a teacher
boolean isTeacher = umsAdminRoleRelation.getRoleId() == CourseCode.TEACHER_ROLE_ID.getValue();
Page<Courses> page = courseQuery.toMpPageDefaultSortByCreateTime();
// 2.分页查询
Page<Courses> 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<CoursesVO> coursesVOPageDTO = PageDTO.of(p, CoursesVO.class);
List<CoursesVO> pageDTOList = coursesVOPageDTO.getList();
List<String> teachers = null;
populateTeacherNames(coursesVOPageDTO.getList());
for (CoursesVO coursesVO : pageDTOList) {
return coursesVOPageDTO;
}
public void populateTeacherNames(List<CoursesVO> courseList) {
for (CoursesVO coursesVO : courseList) {
List<String> teacherNameList = new ArrayList<>();
String teacherIds = coursesVO.getTeacher();
teachers = new ArrayList<>(Arrays.asList(teacherIds.split(",")));
for (String teacher : teachers) {
UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper<UmsAdmin>().
eq(UmsAdmin::getUsername, teacher));
if (umsAdmin==null){
String[] teacherIds = coursesVO.getTeacher().split(",");
for (String teacherId : teacherIds) {
UmsAdmin umsAdminTea = umsAdminMapper.selectOne(new LambdaQueryWrapper<UmsAdmin>()
.eq(UmsAdmin::getUsername, teacherId));
if (umsAdminTea == null) {
throw new BusinessException(ErrorCode.OPERATION_ERROR);
}
Long adminId = umsAdmin.getId();
UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper<UmsTeacher>()
.eq(UmsTeacher::getUserId, adminId));
.eq(UmsTeacher::getUserId, umsAdminTea.getId()));
teacherNameList.add(umsTeacher.getName());
}
coursesVO.setTeacher(String.join(",", teacherNameList));
}
return coursesVOPageDTO;
}
@Override

@ -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<ObjectiveConten
CoursesMapper coursesMapper;
@Autowired
ObjectiveContentsMapper objectiveContentsMapper;
@Autowired
SnowflakeGenerator snowflakeGenerator;
//TODO:优化插入
@Override
@Transactional
public String saveKnowsWithObjectiveOrContent(ObjectiveContentKnowDTO objectiveContentKnowDTO) {
@ -63,18 +68,22 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl<ObjectiveConten
throw new BusinessException(ErrorCode.KONWID_NOT_EXIT);
}
List<String> knowIds = new ArrayList<>(Arrays.asList(knows.split(",")));
ObjectiveContentKnow objectiveContentKnow = null;
List<ObjectiveContentKnow> 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<ObjectiveConten
)))
.collect(Collectors.toList());
// 计算每个内容的比例(百分比)
// 计算每个内容的知识点总学时的比例(百分比)
contentKnowVOs.forEach(contentKnowVO -> {
BigDecimal contentPercentage = calculatePercentage(contentKnowVO.getKnowsTime(), classhours);
contentKnowVO.setPersent(contentPercentage + "%");
@ -161,8 +170,8 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl<ObjectiveConten
}
// 将classhours转换为BigDecimal类型,以便进行精确计算
BigDecimal classHoursBigDecimal = new BigDecimal(classhours);
// 计算knowsTime占classhours的比例,保留两位小数,并四舍五入
return knowsTime.divide(classHoursBigDecimal, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
// 计算knowsTime占classhours的比例,先除以classhours再乘以100,保留两位小数,并四舍五入
return knowsTime.divide(classHoursBigDecimal, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
}

@ -1,10 +1,18 @@
package com.teaching.backend.service.impl.courses;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.ObjectiveContentKnowMapper;
import com.teaching.backend.mapper.courses.ObjectiveContentsMapper;
import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
import com.teaching.backend.service.courses.IObjectiveContentsService;
import com.teaching.backend.utils.CourseCode;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@ -18,4 +26,21 @@ import org.springframework.stereotype.Service;
@Service
public class ObjectiveContentsServiceImpl extends ServiceImpl<ObjectiveContentsMapper, ObjectiveContents> 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<ObjectiveContentKnow>()
.eq(ObjectiveContentKnow::getObjectiveOrContent, id));
if(count > CourseCode.KNOWS_EXIT.getValue()){
throw new BusinessException(ErrorCode.KNOWS_EXIT);
}
int delete = objectiveContentsMapper.deleteById(id);
return delete>0 ? "删除成功!" : "删除失败!";
}
}

@ -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<StudentCoursesMapper,
UmsTeacherMapper umsTeacherMapper;
@Autowired
CoursesMapper coursesMapper;
@Autowired
SnowflakeGenerator snowflakeGenerator;
@Autowired
ICoursesService coursesService;
@Override
public String saveCoursesToStudents(StudentCoursesDTO studentCoursesDTO) {
String studentId = studentCoursesDTO.getStudent();
@ -61,14 +68,17 @@ public class StudentCoursesServiceImpl extends ServiceImpl<StudentCoursesMapper,
throw new BusinessException(ErrorCode.COURSES_NOT_EXIT);
}
List<String> coursesIds = new ArrayList<>(Arrays.asList(courses.split(",")));
List<StudentCourses> 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<StudentCoursesMapper,
@Override
public PageDTO<CoursesVO> 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> studentCourses = studentCoursesMapper.selectList(new LambdaQueryWrapper<StudentCourses>()
@ -99,26 +109,9 @@ public class StudentCoursesServiceImpl extends ServiceImpl<StudentCoursesMapper,
Page<Courses> p = this.coursesMapper.selectPage(page, queryWrapper);
PageDTO<CoursesVO> coursesVOPageDTO = PageDTO.of(p, CoursesVO.class);
List<CoursesVO> pageDTOList = coursesVOPageDTO.getList();
List<String> teachers = null;
for (CoursesVO coursesVO : pageDTOList) {
List<String> teacherNameList = new ArrayList<>();
String teacherIds = coursesVO.getTeacher();
teachers = new ArrayList<>(Arrays.asList(teacherIds.split(",")));
for (String teacher : teachers) {
UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper<UmsAdmin>().
eq(UmsAdmin::getUsername, teacher));
if (umsAdmin==null){
throw new BusinessException(ErrorCode.OPERATION_ERROR);
}
Long adminId = umsAdmin.getId();
UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper<UmsTeacher>()
.eq(UmsTeacher::getUserId, adminId));
teacherNameList.add(umsTeacher.getName());
}
coursesVO.setTeacher(String.join(",", teacherNameList));
}
coursesService.populateTeacherNames(coursesVOPageDTO.getList());
return coursesVOPageDTO;
}
}

@ -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<UmsAdmin> {
* 手机号登录
*/
String phoneLogin(String phone);
List<TeacherInfVO> getTeacherInfList();
}

@ -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<UmsAdminMapper, UmsAdmin> i
private AmqpTemplate amqpTemplate;
@Autowired
private StringRedisTemplate redisTemplate;
@Autowired
UmsTeacherMapper umsTeacherMapper;
@Autowired
UmsAdminMapper umsAdminMapper;
@Override
@ -128,6 +133,8 @@ public class UmsAdminServiceImpl extends ServiceImpl<UmsAdminMapper, UmsAdmin> i
return token;
}
@Override
public boolean updateUms(UmsAdmin umsadmin) {
if (umsadmin.getPassword().length() > 0){
@ -280,4 +287,20 @@ public class UmsAdminServiceImpl extends ServiceImpl<UmsAdminMapper, UmsAdmin> i
throw new UsernameNotFoundException("用户名或密码错误");
}
@Override
public List<TeacherInfVO> getTeacherInfList() {
List<UmsTeacher> umsTeachers = umsTeacherMapper.selectList(new LambdaQueryWrapper<UmsTeacher>());
TeacherInfVO teacherInfVO = null;
List<TeacherInfVO> teacherInfList = new ArrayList<>();;
for (UmsTeacher umsTeacher : umsTeachers) {
teacherInfVO = new TeacherInfVO();
UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper<UmsAdmin>()
.eq(UmsAdmin::getId, umsTeacher.getUserId()));
teacherInfVO.setName(umsTeacher.getName());
teacherInfVO.setUsername(umsAdmin.getUsername());
teacherInfList.add(teacherInfVO);
}
return teacherInfList;
}
}

@ -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, "课程正在修改中");

@ -12,4 +12,13 @@
select * from t1
order by t1.pid
</select>
<insert id="insertBatch" parameterType="java.util.List">
INSERT INTO course_objectives (id, type, name, pid)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.id}, #{item.type}, #{item.name},#{item.pid})
</foreach>
</insert>
</mapper>

@ -2,4 +2,12 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper">
<insert id="insertBatchSomeColumn" parameterType="java.util.List">
INSERT INTO objective_content_know (objective_or_content, know)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.objectiveOrContent}, #{item.know})
</foreach>
</insert>
</mapper>

@ -2,4 +2,11 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.teaching.backend.mapper.courses.StudentCoursesMapper">
<insert id="insertBatchSomeColumn" parameterType="java.util.List">
INSERT INTO student_courses (student, course)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.student}, #{item.course})
</foreach>
</insert>
</mapper>

Loading…
Cancel
Save