Commit 6b16f6de by 邓敏 Committed by 涂亚平

更新班级WebSocket消息通知

1 parent de277cb7
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.subsidy.model.ClassDictDO;
import com.subsidy.model.ClassMemberMappingDO;
import com.subsidy.vo.administer.ClassDailyInfoVO;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
......@@ -39,4 +40,6 @@ public interface ClassMemberMappingMapper extends BaseMapper<ClassMemberMappingD
* 获取学生当前有效班级
*/
long getMemberClassCount(Long memberId);
List<ClassMemberMappingDO> getCLassMemberByCompanyId(@Param("companyId") Long companyId);
}
......@@ -11,6 +11,7 @@ import com.subsidy.model.MemberDO;
import com.subsidy.vo.classdict.GetAllClassesVO;
import com.subsidy.vo.classdict.GetClassBaseInfoVO;
import java.io.IOException;
import java.util.List;
/**
......
package com.subsidy.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.common.ResponseData;
import com.subsidy.common.constant.CourseNotification;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.classDict.AddClassDTO;
......@@ -33,14 +36,20 @@ import com.subsidy.util.ConstantUtils;
import com.subsidy.util.DateFormatUtil;
import com.subsidy.util.QuartzUtil;
import com.subsidy.util.SMSUtils;
import com.subsidy.util.websocket.WebSocketUtil;
import com.subsidy.vo.classdict.ClassSettingsVO;
import com.subsidy.vo.classdict.GetAllClassesVO;
import com.subsidy.vo.classdict.GetClassBaseInfoVO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
......@@ -154,6 +163,23 @@ public class ClassDictServiceImpl extends ServiceImpl<ClassDictMapper, ClassDict
public String updateClass(ClassDictDO classDictDO) {
this.baseMapper.updateById(classDictDO);
List<ClassMemberMappingDO> list = classMemberMappingMapper.selectList(new QueryWrapper<ClassMemberMappingDO>()
.lambda()
.eq(ClassMemberMappingDO::getClassId, classDictDO.getId()));
if(CollectionUtils.isNotEmpty(list)) {
for (ClassMemberMappingDO classMemberMappingDO : list) {
WebSocketSession webSocketSession = WebSocketUtil.webSocketMap.get(classMemberMappingDO.getMemberId());
if(null != webSocketSession && webSocketSession.isOpen()) {
try {
List<ClassSettingsVO> classSettings = this.baseMapper.getClassSettings(classMemberMappingDO.getMemberId());
String data = JSONObject.toJSONString(ResponseData.generateCreatedResponse(0, classSettings), SerializerFeature.WriteMapNullValue);
webSocketSession.sendMessage(new TextMessage(data));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
return ConstantUtils.SET_SUCCESS;
}
......
package com.subsidy.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.common.ResponseData;
import com.subsidy.common.configure.VODConfig;
import com.subsidy.common.constant.VodConstant;
import com.subsidy.common.exception.HttpException;
......@@ -33,7 +36,9 @@ import com.subsidy.util.ConstantUtils;
import com.subsidy.util.DateFormatUtil;
import com.subsidy.util.EhCacheUtil;
import com.subsidy.util.VodUtil;
import com.subsidy.util.websocket.WebSocketUtil;
import com.subsidy.vo.administer.OperatorsVO;
import com.subsidy.vo.classdict.ClassSettingsVO;
import com.subsidy.vo.company.CDNStatDetailsVO;
import com.subsidy.vo.company.DataOverviewVO;
import com.subsidy.vo.company.GetAllCompanyVO;
......@@ -44,6 +49,9 @@ import com.subsidy.vo.company.MemberSummaryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
......@@ -105,6 +113,9 @@ public class CompanyDictServiceImpl extends ServiceImpl<CompanyDictMapper, Compa
private VodPlayHistoryMapper vodPlayHistoryMapper;
@Autowired
private ClassMemberMappingMapper classMemberMappingMapper;
@Autowired
private VODConfig vodConfig;
public IPage<OperatorsVO> operators(OperatorsDTO operatorsDTO) {
......@@ -281,6 +292,22 @@ public class CompanyDictServiceImpl extends ServiceImpl<CompanyDictMapper, Compa
public String updateCompanySettings(CompanyDictDO companyDictDO) {
this.baseMapper.updateById(companyDictDO);
List<ClassMemberMappingDO> list = classMemberMappingMapper.getCLassMemberByCompanyId(companyDictDO.getId());
if(CollectionUtils.isNotEmpty(list)) {
for (ClassMemberMappingDO classMemberMappingDO : list) {
WebSocketSession webSocketSession = WebSocketUtil.webSocketMap.get(classMemberMappingDO.getMemberId());
if(null != webSocketSession && webSocketSession.isOpen()) {
try {
List<ClassSettingsVO> classSettings = classDictMapper.getClassSettings(classMemberMappingDO.getMemberId());
String data = JSONObject.toJSONString(ResponseData.generateCreatedResponse(0, classSettings), SerializerFeature.WriteMapNullValue);
webSocketSession.sendMessage(new TextMessage(data));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
return ConstantUtils.SET_SUCCESS;
}
......
package com.subsidy.util.websocket;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
......@@ -20,8 +19,6 @@ import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketMessage;
import org.springframework.web.socket.WebSocketSession;
import javax.websocket.OnMessage;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
......@@ -51,13 +48,13 @@ public class WebSocketUtil implements WebSocketHandler {
private ClassDictMapper classDictMapper;
private int heartbeatMin = 1; // 断连最小心跳次数
private int heartbeatMax = 3; // 断连最大心跳次数
private int heartbeatMax = 2; // 断连最大心跳次数
private int reconnectionSeconds = 60; //每次断连间隔重新连接秒
/**
* 存放建立连接webSocket对象
*/
private ConcurrentHashMap<Long, WebSocketSession> webSocketMap = new ConcurrentHashMap();
public static ConcurrentHashMap<Long, WebSocketSession> webSocketMap = new ConcurrentHashMap();
ConcurrentHashMap<String, ScheduledFuture> taskMap = new ConcurrentHashMap<>(1);
......
......@@ -76,4 +76,17 @@
and t.member_id = #{memberId}
</select>
<select id="getCLassMemberByCompanyId" resultType="com.subsidy.model.ClassMemberMappingDO">
SELECT
t.*
FROM
class_member_mapping t
LEFT JOIN class_dict t1 ON t1.id = t.class_id
WHERE
t1.company_id = #{companyId}
AND t.delete_date IS NULL
AND t1.delete_date IS NULL
GROUP BY t.member_id
</select>
</mapper>
......@@ -39,7 +39,7 @@
t2.content,
t.order_no,
t.vod_code,
t3.vod_alias_name
IFNULL( t3.vod_alias_name, t.vod_name ) AS vod_alias_name
FROM
vod_dict t
LEFT JOIN content_vod_mapping t3 ON t3.vod_id = t.id
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!