diff --git a/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseChatLog.java b/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseChatLog.java index 56cca526..6d177e2d 100644 --- a/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseChatLog.java +++ b/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseChatLog.java @@ -31,7 +31,7 @@ public class TeacherOpenCourseChatLog extends BaseEntity{ //上级ID, 默认0L 顶级:0L - private Long teacherOpenCourseChatLogParentId = 0L; + private Long teacherOpenCourseChatLogParentId; @FetchSql("select * from teacher_open_course_chat_log t " + "where t.teacher_open_course_id = #teacherOpenCourseId# " + diff --git a/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseChatLogController.java b/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseChatLogController.java index cc381413..35a6ac2e 100644 --- a/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseChatLogController.java +++ b/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseChatLogController.java @@ -1,6 +1,9 @@ package com.ibeetl.jlw.web; import cn.hutool.core.lang.Assert; +import cn.hutool.extra.validation.BeanValidationResult; +import cn.hutool.extra.validation.ValidationUtil; +import cn.hutool.json.JSONUtil; import cn.jlw.Interceptor.SCoreUser; import cn.jlw.validate.ValidateConfig; import com.ibeetl.admin.core.annotation.Function; @@ -21,14 +24,20 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; +import javax.validation.constraints.NotNull; +import java.math.BigDecimal; import java.util.List; +import static com.ibeetl.jlw.web.query.TeacherOpenCourseChatLogQuery.STUDENT_ADD; +import static com.ibeetl.jlw.web.query.TeacherOpenCourseChatLogQuery.TEACHER_ADD; + /** * 开课互动 课程开课-互动-评论日志 接口 * 切记不要对非线程安全的静态变量进行写操作 */ @RestController +@Validated public class TeacherOpenCourseChatLogController{ private final Log log = LogFactory.getLog(this.getClass()); @@ -177,6 +186,74 @@ public class TeacherOpenCourseChatLogController{ } } + /** + * 教师端-学生端-添加互动消息 + * @param teacherOpenCourseChatLogQuery + * @param type 1: 教师端, 其他:学生端 + * @param result + * @param coreUser + * @return + */ + @PostMapping(MODEL + "/addByType.json") + @Function("teacherOpenCourseChatLog.add") + public JsonResult addByType( + @RequestBody TeacherOpenCourseChatLogQuery teacherOpenCourseChatLogQuery, + Integer type, + BindingResult result, @SCoreUser CoreUser coreUser){ + + Boolean isTeacherAdding = type.equals(1); + // 验证 + BeanValidationResult validationResult = ValidationUtil + .warpValidate(teacherOpenCourseChatLogQuery, isTeacherAdding ? TEACHER_ADD.class : STUDENT_ADD.class); + Assert.isTrue(validationResult.isSuccess(), JSONUtil.toJsonStr(validationResult.getErrorMessages())); + + // 教师身份,添加上级ID为0 + if(isTeacherAdding) { + teacherOpenCourseChatLogQuery.setTeacherOpenCourseChatLogParentId(0L); + } + + if(result.hasErrors()){ + return JsonResult.failMessage(result); + }else{ + teacherOpenCourseChatLogQuery.setUserId(coreUser.getId()); + teacherOpenCourseChatLogQuery.setOrgId(coreUser.getOrgId()); + if(null == teacherOpenCourseChatLogQuery.getTeacherOpenCourseChatLogStatus()){ + teacherOpenCourseChatLogQuery.setTeacherOpenCourseChatLogStatus(1); + } + return teacherOpenCourseChatLogService.add(teacherOpenCourseChatLogQuery); + } + } + + /** + * 教师端-给学生打分 + * @param teacherOpenCourseChatLogId + * @param studentScore + * @param result + * @return + */ + @PostMapping(MODEL + "/setScore.json") + @Function("teacherOpenCourseChatLog.add") + public JsonResult setScore( + @NotNull(message = "互动ID不能为空!") + Long teacherOpenCourseChatLogId, + @NotNull(message = "学生分数不能为空!") + BigDecimal studentScore, BindingResult result){ + + if(result.hasErrors()){ + return JsonResult.failMessage(result); + }else{ + TeacherOpenCourseChatLogQuery teacherOpenCourseChatLogQuery = new TeacherOpenCourseChatLogQuery(); + teacherOpenCourseChatLogQuery.setTeacherOpenCourseChatLogId(teacherOpenCourseChatLogId); + teacherOpenCourseChatLogQuery.setStudentScore(studentScore); + String msg = teacherOpenCourseChatLogService.edit(teacherOpenCourseChatLogQuery); + if (StringUtils.isBlank(msg)) { + return JsonResult.success(); + } else { + return JsonResult.failMessage("更新失败,"+msg); + } + } + } + @PostMapping(MODEL + "/edit.json") @Function("teacherOpenCourseChatLog.edit") public JsonResult update(@Validated(ValidateConfig.UPDATE.class) @RequestBody TeacherOpenCourseChatLogQuery teacherOpenCourseChatLogQuery, BindingResult result) { diff --git a/web/src/main/java/com/ibeetl/jlw/web/query/TeacherOpenCourseChatLogQuery.java b/web/src/main/java/com/ibeetl/jlw/web/query/TeacherOpenCourseChatLogQuery.java index 44086a62..d1bf3ac9 100644 --- a/web/src/main/java/com/ibeetl/jlw/web/query/TeacherOpenCourseChatLogQuery.java +++ b/web/src/main/java/com/ibeetl/jlw/web/query/TeacherOpenCourseChatLogQuery.java @@ -5,6 +5,7 @@ import com.ibeetl.admin.core.annotation.Query; import com.ibeetl.admin.core.web.query.PageParam; import com.ibeetl.jlw.entity.TeacherOpenCourseChatLog; +import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; import java.math.BigDecimal; import java.util.Date; @@ -14,22 +15,34 @@ import java.util.Date; */ public class TeacherOpenCourseChatLogQuery extends PageParam { - @NotNull(message = "ID不能为空", groups =ValidateConfig.UPDATE.class) + /** + * 教师添加验证 + */ + public static interface TEACHER_ADD {} + /** + * 学生添加验证 + */ + public static interface STUDENT_ADD {} + + @NotNull(message = "ID不能为空", groups ={ValidateConfig.UPDATE.class}) @Query(name = "课程开课--讨论-日志ID", display = false) private Long teacherOpenCourseChatLogId; + @NotNull(message = "上级ID不能为空", groups ={ STUDENT_ADD.class }) + @Min(value = 1L, message = "学生互动上级ID最小支持:1L", groups = { STUDENT_ADD.class }) @Query(name = "上级ID", display = false) private Long teacherOpenCourseChatLogParentId; - @NotNull(message = "课程开课ID不能为空", groups =ValidateConfig.ADD.class) + @NotNull(message = "课程开课ID不能为空", groups ={ ValidateConfig.ADD.class, TEACHER_ADD.class, STUDENT_ADD.class }) @Query(name = "课程开课ID", display = true,type=Query.TYPE_DICT,dict="teacher_open_course.teacher_open_course_title.teacher_open_course_status=1") private Long teacherOpenCourseId; @Query(name = "班级ID集合", display = false) private String schoolClassIds; - @NotNull(message = "教师ID不能为空", groups =ValidateConfig.ADD.class) + @NotNull(message = "教师ID不能为空", groups ={ ValidateConfig.ADD.class, TEACHER_ADD.class }) @Query(name = "教师ID", display = true,type=Query.TYPE_DICT,dict="teacher.teacher_name.teacher_status=1") private Long teacherId; + @NotNull(message = "学生ID不能为空", groups ={ ValidateConfig.ADD.class, STUDENT_ADD.class }) @Query(name = "学生ID", display = true,type=Query.TYPE_DICT,dict="student.student_name.student_status=1") private Long studentId; - @NotNull(message = "讨论内容不能为空", groups =ValidateConfig.ADD.class) + @NotNull(message = "讨论内容不能为空", groups ={ ValidateConfig.ADD.class, TEACHER_ADD.class, STUDENT_ADD.class }) @Query(name = "讨论内容", display = false) private String chatContent; @Query(name = "关键字(多个逗号隔开)", display = false)