添加已读操作逻辑

beetlsql3-dev
yaodan 2 years ago
parent 8dde08da8a
commit 218b477b31

@ -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;
@ -51,7 +54,8 @@ import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser;
@Slf4j
public class TeacherOpenCourseChatLogService extends CoreBaseService<TeacherOpenCourseChatLog> implements DeleteResourcesBy {
@Autowired private TeacherOpenCourseChatLogDao teacherOpenCourseChatLogDao;
@Autowired
private TeacherOpenCourseChatLogDao teacherOpenCourseChatLogDao;
@Autowired
private TeacherDao teacherDao;
@Autowired
@ -68,6 +72,7 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService<TeacherOpen
queryListAfter(ret.getList());
return ret;
}
public PageQuery<TeacherOpenCourseChatLogTree> queryByCondition(PageQuery query, Boolean placeholder) {
PageQuery<TeacherOpenCourseChatLogTree> ret = teacherOpenCourseChatLogDao.queryByCondition2(query);
CollectionUtil.emptyIfNull(ret.getList()).forEach(item -> {
@ -88,6 +93,94 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService<TeacherOpen
return ret;
}
public PageQuery<TeacherOpenCourseChatLog> queryByConditionQueryWithChangStatus(TeacherOpenCourseChatLogQuery query) {
PageQuery<TeacherOpenCourseChatLog> 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<Long> 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<Long> 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<Long> 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<Long> 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);
@ -115,7 +208,8 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService<TeacherOpen
} catch (Exception e) {
try {
teacherOpenCourseChatLogList.add(JSONObject.parseObject(teacherOpenCourseChatLogQuery.getTeacherOpenCourseChatLogJsonStr(), TeacherOpenCourseChatLog.class));
} catch (Exception e1) {}
} catch (Exception e1) {
}
}
ToolUtils.deleteNullList(teacherOpenCourseChatLogList);
if (null != teacherOpenCourseChatLogList && teacherOpenCourseChatLogList.size() > 0) {
@ -165,6 +259,7 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService<TeacherOpen
/**
* ID
*
* @param chatLog
* @return
*/
@ -303,6 +398,7 @@ public class TeacherOpenCourseChatLogService extends CoreBaseService<TeacherOpen
/**
*
*
* @param dto
* @return
*/

@ -1,6 +1,7 @@
package com.ibeetl.jlw.web;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
@ -40,6 +41,7 @@ import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import static com.ibeetl.admin.core.util.ExcelUtil.convertData;
@ -74,9 +76,7 @@ public class TeacherOpenCourseChatLogController extends BaseController {
if (null == coreUser) {
return JsonResult.failMessage("请登录后再操作");
} else {
PageQuery page = condition.getPageQuery();
teacherOpenCourseChatLogService.queryByConditionQuery(page);
return JsonResult.success(page);
return JsonResult.success(teacherOpenCourseChatLogService.queryByConditionQueryWithChangStatus(condition));
}
}
@ -138,12 +138,12 @@ public class TeacherOpenCourseChatLogController extends BaseController {
teacherOpenCourseChatLogQuery.setOrgId(coreUser.getOrgId());
if (ObjectUtil.isNotEmpty(teacher)) {
teacherOpenCourseChatLogQuery.setTeacherId(teacher.getTeacherId());
teacherOpenCourseChatLogQuery.setStudentReadStatus(0);
}
if (ObjectUtil.isNotEmpty(student)) {
teacherOpenCourseChatLogQuery.setStudentId(student.getStudentId());
teacherOpenCourseChatLogQuery.setTeacherReadStatus(0);
}
teacherOpenCourseChatLogQuery.setTeacherReadStatus(0);
teacherOpenCourseChatLogQuery.setStudentReadStatus(0);
return teacherOpenCourseChatLogService.add(teacherOpenCourseChatLogQuery);
}
}
@ -229,7 +229,16 @@ public class TeacherOpenCourseChatLogController extends BaseController {
teacherOpenCourseChatLogQuery.setTeacherOpenCourseChatLogId(teacherOpenCourseChatLogId);
teacherOpenCourseChatLogQuery.setStudentScore(studentScore);
String msg = teacherOpenCourseChatLogService.edit(teacherOpenCourseChatLogQuery);
if (StringUtils.isBlank(msg)) {
TeacherOpenCourseChatLog teacherOpenCourseChatLog = new TeacherOpenCourseChatLog();
teacherOpenCourseChatLog.setTeacherOpenCourseChatLogParentId(teacherOpenCourseChatLogId);
//获取所有子评论
List<TeacherOpenCourseChatLog> values = teacherOpenCourseChatLogService.getValues(teacherOpenCourseChatLog);
if (CollUtil.isNotEmpty(values)){
List<Long> 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);

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

Loading…
Cancel
Save