diff --git a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseChatLogService.java b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseChatLogService.java index 3f68e416..9caf12e6 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseChatLogService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseChatLogService.java @@ -1,6 +1,7 @@ package com.ibeetl.jlw.service; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; @@ -38,6 +39,8 @@ import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser; @@ -49,9 +52,10 @@ import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser; @Service @Transactional @Slf4j -public class TeacherOpenCourseChatLogService extends CoreBaseService implements DeleteResourcesBy{ +public class TeacherOpenCourseChatLogService extends CoreBaseService implements DeleteResourcesBy { - @Autowired private TeacherOpenCourseChatLogDao teacherOpenCourseChatLogDao; + @Autowired + private TeacherOpenCourseChatLogDao teacherOpenCourseChatLogDao; @Autowired private TeacherDao teacherDao; @Autowired @@ -59,8 +63,8 @@ public class TeacherOpenCourseChatLogService extends CoreBaseServicequeryByCondition(PageQuery query){ - PageQuery ret = teacherOpenCourseChatLogDao.queryByCondition(query); + public PageQuery queryByCondition(PageQuery query) { + PageQuery ret = teacherOpenCourseChatLogDao.queryByCondition(query); CollectionUtil.emptyIfNull(ret.getList()).forEach(item -> { String headImg = webPlatformService.getHeadImgByIdentity(item.getUserId()); item.set("headImg", headImg); @@ -68,8 +72,9 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService queryByCondition(PageQuery query, Boolean placeholder){ - PageQuery ret = teacherOpenCourseChatLogDao.queryByCondition2(query); + + public PageQuery queryByCondition(PageQuery query, Boolean placeholder) { + PageQuery ret = teacherOpenCourseChatLogDao.queryByCondition2(query); CollectionUtil.emptyIfNull(ret.getList()).forEach(item -> { String headImg = webPlatformService.getHeadImgByIdentity(item.getUserId()); item.set("headImg", headImg); @@ -78,8 +83,8 @@ public class TeacherOpenCourseChatLogService extends CoreBaseServicequeryByConditionQuery(PageQuery query){ - PageQuery ret = teacherOpenCourseChatLogDao.queryByConditionQuery(query); + public PageQuery queryByConditionQuery(PageQuery query) { + PageQuery ret = teacherOpenCourseChatLogDao.queryByConditionQuery(query); CollectionUtil.emptyIfNull(ret.getList()).forEach(item -> { String headImg = webPlatformService.getHeadImgByIdentity(item.getUserId()); item.set("headImg", headImg); @@ -88,18 +93,106 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService queryByConditionQueryWithChangStatus(TeacherOpenCourseChatLogQuery query) { + PageQuery ret = teacherOpenCourseChatLogDao.queryByConditionQuery(query.getPageQuery()); + + if (CollUtil.isNotEmpty(ret.getList())) { + CoreUser user = getUser(); + Object bean = null; + // 学生或者教师身份才能看到真正的数字 + if (user != null && user.isTeacher()) { + Teacher teacher = teacherDao.getByUserId(user.getId()); + if (teacher != null) { + bean = teacher; + } + } else if (user != null && user.isStudent()) { + Student student = studentDao.getByUserId(user.getId()); + if (student != null) { + bean = student; + } + } + //remark /api/teacherOpenCourseChatLog/setScore.do 也有标记已读的逻辑 + if (bean != null) { + switch (query.getChatLogSendType()==null?ChatLogSendTypeEnum.normal:query.getChatLogSendType()) { + case normal: + if (query.getTeacherOpenCourseChatLogParentId()!=null){ + if (bean instanceof Student){ + List idList = ret.getList().stream().filter(e->Objects.equals(e.getStudentReadStatus(),0)).map(TeacherOpenCourseChatLog::getTeacherOpenCourseChatLogId).collect(Collectors.toList()); + readChatLogByIds(idList,1); + } + } + break; + case student_ask: + if (bean instanceof Teacher) { + List idList = ret.getList().stream().filter(e->Objects.equals(e.getTeacherReadStatus(),0)).map(TeacherOpenCourseChatLog::getTeacherOpenCourseChatLogId).collect(Collectors.toList()); + readChatLogByIds(idList,2); + } + break; + case specify_ask: + case random_ask: + //if (bean instanceof Student) { + // List idList = ret.getList().stream().filter(e->Objects.equals(e.getStudentReadStatus(),0)).map(TeacherOpenCourseChatLog::getTeacherOpenCourseChatLogId).collect(Collectors.toList()); + // readChatLogByIds(idList,1); + //} + break; + + default: + + break; + + } + + } + + } + + CollectionUtil.emptyIfNull(ret.getList()).forEach(item -> { + String headImg = webPlatformService.getHeadImgByIdentity(item.getUserId()); + item.set("headImg", headImg); + }); + queryListAfter(ret.getList()); + return ret; + } + + + /** + * 标记消息为已读 + * + * @param ids id + * @param type 类型 1学生 2教师 + * @author zhouzhao + * @date 2023/05/09 10:38:44 + */ + public void readChatLogByIds(List ids,int type) { + if (CollUtil.isEmpty(ids)) { + return; + } + for (Long id : ids) { + TeacherOpenCourseChatLog teacherOpenCourseChatLog = teacherOpenCourseChatLogDao.unique(id); + if (teacherOpenCourseChatLog != null) { + if (type==1) { + teacherOpenCourseChatLog.setStudentReadStatus(1); + }else { + teacherOpenCourseChatLog.setTeacherReadStatus(1); + } + teacherOpenCourseChatLog.setTeacherReadStatus(1); + teacherOpenCourseChatLogDao.updateById(teacherOpenCourseChatLog); + } + } + } + + public void deleteByList(List list) { String ids = ""; ToolUtils.deleteNullList(list); - for(int i=0;null != list && i teacherOpenCourseChatLogList = new ArrayList<>(); try { @@ -115,11 +208,12 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService0){ - for(int i=0;i 0) { + for (int i = 0; i < teacherOpenCourseChatLogList.size(); i++) { TeacherOpenCourseChatLog teacherOpenCourseChatLog = teacherOpenCourseChatLogList.get(i); teacherOpenCourseChatLog.setTeacherOpenCourseChatLogAddTime(new Date()); teacherOpenCourseChatLog.setUserId(teacherOpenCourseChatLogQuery.getUserId()); @@ -130,7 +224,7 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService 0; - if(!flag){ + if (!flag) { msg = "更新指定参数失败"; } - }else{ + } else { msg = "指定参数为空"; } return msg; } - public List getValues (Object paras){ + public List getValues(Object paras) { return sqlManager.select(SqlId.of("jlw.teacherOpenCourseChatLog.getTeacherOpenCourseChatLogValues"), TeacherOpenCourseChatLog.class, paras); } - public List getValuesByQuery (TeacherOpenCourseChatLogQuery teacherOpenCourseChatLogQuery){ + public List getValuesByQuery(TeacherOpenCourseChatLogQuery teacherOpenCourseChatLogQuery) { return teacherOpenCourseChatLogDao.getValuesByQuery(teacherOpenCourseChatLogQuery); } - public TeacherOpenCourseChatLog getInfo (Long teacherOpenCourseChatLogId){ + public TeacherOpenCourseChatLog getInfo(Long teacherOpenCourseChatLogId) { TeacherOpenCourseChatLogQuery teacherOpenCourseChatLogQuery = new TeacherOpenCourseChatLogQuery(); teacherOpenCourseChatLogQuery.setTeacherOpenCourseChatLogId(teacherOpenCourseChatLogId); teacherOpenCourseChatLogQuery.setTeacherOpenCourseChatLogStatusPlural("1,2");//需要根据实际情况来 List list = teacherOpenCourseChatLogDao.getValuesByQuery(teacherOpenCourseChatLogQuery); - if(null != list && list.size()>0){ + if (null != list && list.size() > 0) { return list.get(0); - }else{ + } else { return null; } } - public TeacherOpenCourseChatLog getInfo (TeacherOpenCourseChatLogQuery teacherOpenCourseChatLogQuery){ + public TeacherOpenCourseChatLog getInfo(TeacherOpenCourseChatLogQuery teacherOpenCourseChatLogQuery) { List list = teacherOpenCourseChatLogDao.getValuesByQuery(teacherOpenCourseChatLogQuery); - if(null != list && list.size()>0){ + if (null != list && list.size() > 0) { return list.get(0); - }else{ + } else { return null; } } @@ -279,7 +374,7 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService * 讨论日志-分析 * - * @param teacherOpenCourseId 开课ID + * @param teacherOpenCourseId 开课ID * @return {@link TeacherOpenCourseChatLogAnalysis} * @Author: lx * @Date: 2022/12/12 23:14 @@ -292,7 +387,7 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService * 评论添加的类型,分组汇总 * - * @param teacherOpenCourseId 开课ID + * @param teacherOpenCourseId 开课ID * @return {@link List< TeacherOpenCourseChatLogGroupInfoVO>} * @Author: lx * @Date: 2022/12/12 23:14 @@ -303,6 +398,7 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService values = teacherOpenCourseChatLogService.getValues(teacherOpenCourseChatLog); + if (CollUtil.isNotEmpty(values)){ + List idList = values.stream().filter(e-> Objects.equals(e.getTeacherReadStatus(),0)).map(TeacherOpenCourseChatLog::getTeacherOpenCourseChatLogId).collect(Collectors.toList()); + teacherOpenCourseChatLogService.readChatLogByIds(idList,2); + } return JsonResult.success(); } else { return JsonResult.failMessage("更新失败," + msg); diff --git a/web/src/main/resources/sql/jlw/teacherOpenCourseChatLog.md b/web/src/main/resources/sql/jlw/teacherOpenCourseChatLog.md index 1844323e..41cfba5c 100644 --- a/web/src/main/resources/sql/jlw/teacherOpenCourseChatLog.md +++ b/web/src/main/resources/sql/jlw/teacherOpenCourseChatLog.md @@ -698,10 +698,10 @@ getTeacherAskUnReadCountByTeacher === * 获取老师提问模块未读数量,对于老师来说 SELECT IFNULL(sum( - (select count(*) + IF((select count(*) from teacher_open_course_chat_log t2 where t2.teacher_open_course_chat_log_parent_id = t.teacher_open_course_chat_log_id - and t2.teacher_read_status = 0) + and t2.teacher_read_status = 0)>0,1,0) ),0) FROM teacher_open_course_chat_log t WHERE 1 @@ -727,8 +727,8 @@ getTeacherAskUnReadCountByStudent SELECT 1 FROM teacher_open_course_chat_log ta WHERE 1 - and t.student_id = #studentId# - AND t.teacher_open_course_id = #teacherOpenCourseId# + and ta.student_id = #studentId# + AND ta.teacher_open_course_id = #teacherOpenCourseId# AND ta.teacher_open_course_chat_log_parent_id = t.teacher_open_course_chat_log_id ) @@ -746,8 +746,8 @@ getStudentAskUnReadCountByTeacher SELECT 1 FROM teacher_open_course_chat_log ta WHERE 1 - and t.teacher_id = #teacherId# - AND t.teacher_open_course_id = #teacherOpenCourseId# + and ta.teacher_id = #teacherId# + AND ta.teacher_open_course_id = #teacherOpenCourseId# AND ta.teacher_open_course_chat_log_parent_id = t.teacher_open_course_chat_log_id ) @@ -760,7 +760,7 @@ getStudentAskUnReadCountByStudent (select count(*) from teacher_open_course_chat_log t2 where t2.teacher_open_course_chat_log_parent_id = t.teacher_open_course_chat_log_id - and t2.teacher_read_status = 0) + and t2.student_read_status = 0) ),0) FROM teacher_open_course_chat_log t WHERE 1