Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
4a647ffb84
1
sql/20230418-wei-conversation-group.sql
Normal file
1
sql/20230418-wei-conversation-group.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE `joylink`.`rts_conversation_group_info` ADD COLUMN `image_url` varchar(255) NULL COMMENT '头像路径' AFTER `name`;
|
@ -25,6 +25,11 @@ public class RtsConversationGroupInfo {
|
|||||||
*/
|
*/
|
||||||
private Long mapId;
|
private Long mapId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 群头像
|
||||||
|
*/
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 项目code
|
* 项目code
|
||||||
*/
|
*/
|
||||||
|
@ -674,6 +674,76 @@ public class RtsConversationGroupInfoExample {
|
|||||||
addCriterion("leader_id not between", value1, value2, "leaderId");
|
addCriterion("leader_id not between", value1, value2, "leaderId");
|
||||||
return (Criteria) this;
|
return (Criteria) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlIsNull() {
|
||||||
|
addCriterion("image_url is null");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlIsNotNull() {
|
||||||
|
addCriterion("image_url is not null");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlEqualTo(String value) {
|
||||||
|
addCriterion("image_url =", value, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlNotEqualTo(String value) {
|
||||||
|
addCriterion("image_url <>", value, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlGreaterThan(String value) {
|
||||||
|
addCriterion("image_url >", value, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlGreaterThanOrEqualTo(String value) {
|
||||||
|
addCriterion("image_url >=", value, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlLessThan(String value) {
|
||||||
|
addCriterion("image_url <", value, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlLessThanOrEqualTo(String value) {
|
||||||
|
addCriterion("image_url <=", value, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlLike(String value) {
|
||||||
|
addCriterion("image_url like", value, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlNotLike(String value) {
|
||||||
|
addCriterion("image_url not like", value, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlIn(List<String> values) {
|
||||||
|
addCriterion("image_url in", values, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlNotIn(List<String> values) {
|
||||||
|
addCriterion("image_url not in", values, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlBetween(String value1, String value2) {
|
||||||
|
addCriterion("image_url between", value1, value2, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andImageUrlNotBetween(String value1, String value2) {
|
||||||
|
addCriterion("image_url not between", value1, value2, "imageUrl");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Criteria extends GeneratedCriteria {
|
public static class Criteria extends GeneratedCriteria {
|
||||||
|
@ -44,11 +44,16 @@ public class OperateParseServiceImpl implements VoiceTransactionalService {
|
|||||||
if (operateRule == null) {
|
if (operateRule == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 参数解析
|
|
||||||
List<ParamExtractResult> paramExtractResults = result.getParamExtractResultList();
|
List<ParamExtractResult> paramExtractResults = result.getParamExtractResultList();
|
||||||
Map<Integer,ParamExtractResult> paramExtractResultMap = IntStream.range(0,paramExtractResults.size()).boxed().collect(Collectors.toMap(i->++i,paramExtractResults::get));
|
Map<Integer,ParamExtractResult> paramExtractResultMap = IntStream.range(0,paramExtractResults.size()).boxed().collect(Collectors.toMap(i->++i,paramExtractResults::get));
|
||||||
OperateResult operateResult = new OperateResult(operateRule.getType());
|
OperateResult operateResult = new OperateResult(operateRule.getType());
|
||||||
int paramSize = paramExtractResults.size();
|
int paramSize = paramExtractResults.size();
|
||||||
|
// 成员解析
|
||||||
|
List<SimulationMember> simulationMemberList = filterSimulationMember(simulation, result, paramExtractResultMap, operateRule.getMemberRule());
|
||||||
|
if (CollectionUtils.isEmpty(simulationMemberList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 参数解析
|
||||||
for (CommandParamRule paramRule : operateRule.getParamRules()) {
|
for (CommandParamRule paramRule : operateRule.getParamRules()) {
|
||||||
ParamExtractResult[] paramArr = new ParamExtractResult[paramRule.getIndexArr().length];
|
ParamExtractResult[] paramArr = new ParamExtractResult[paramRule.getIndexArr().length];
|
||||||
for (int index = 0, len = paramArr.length; index < len; index ++) {
|
for (int index = 0, len = paramArr.length; index < len; index ++) {
|
||||||
@ -67,33 +72,18 @@ public class OperateParseServiceImpl implements VoiceTransactionalService {
|
|||||||
operateResult.putParam(getMethodParamName(paramRule.getParamIndex(), operateRule.getType().name()), val);
|
operateResult.putParam(getMethodParamName(paramRule.getParamIndex(), operateRule.getType().name()), val);
|
||||||
} else {
|
} else {
|
||||||
// 参数位置未指定
|
// 参数位置未指定
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 成员解析
|
|
||||||
MemberRule memberRule = operateRule.getMemberRule();
|
|
||||||
if (memberRule != null) {
|
|
||||||
List<SimulationMember> simulationMemberList = null;
|
|
||||||
if (memberRule.getIndex() == null) {
|
|
||||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
|
|
||||||
} else if (memberRule.getIndex() < paramExtractResults.size()) {
|
|
||||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, paramExtractResultMap.get(memberRule.getIndex()));
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (CollectionUtils.isEmpty(simulationMemberList)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
operateResult.setMember(simulationMemberList.get(0));
|
|
||||||
}
|
|
||||||
// 执行操作
|
// 执行操作
|
||||||
try {
|
simulationMemberList.forEach(member -> {
|
||||||
atsOperationDispatcher.execute(simulation, operateResult.getMember(), operateResult.getType().name(), operateResult.getParams());
|
try {
|
||||||
log.info("执行语音指令操作成功,操作[{}] 源指令[{}]",operateResult.getType().name(),result.getOriginContent());
|
atsOperationDispatcher.execute(simulation, member, operateResult.getType().name(), operateResult.getParams());
|
||||||
} catch (Exception e) {
|
log.info("[{}]执行语音指令操作成功,操作[{}] 源指令[{}]", member.getName(), operateResult.getType().name(), result.getOriginContent());
|
||||||
log.error("执行操作失败[{}] 输入源指令[{}] msg[{}]",operateResult.getType().name(),result.getOriginContent(),e.getMessage(),e);
|
} catch (Exception e) {
|
||||||
}
|
log.error("[{}]执行操作失败[{}] 输入源指令[{}] msg[{}]", member.getName(), operateResult.getType().name(), result.getOriginContent(),e.getMessage(),e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,7 +105,7 @@ public class OperateParseServiceImpl implements VoiceTransactionalService {
|
|||||||
* @param operateName 操作名称
|
* @param operateName 操作名称
|
||||||
* @return 参数名称
|
* @return 参数名称
|
||||||
*/
|
*/
|
||||||
public String getMethodParamName(int index, String operateName) {
|
private String getMethodParamName(int index, String operateName) {
|
||||||
OperateMethod handlerMethod = this.atsManager.getHandlerMethod(operateName);
|
OperateMethod handlerMethod = this.atsManager.getHandlerMethod(operateName);
|
||||||
Parameter[] parameters = handlerMethod.getMethod().getParameters();
|
Parameter[] parameters = handlerMethod.getMethod().getParameters();
|
||||||
if (parameters.length < index) {
|
if (parameters.length < index) {
|
||||||
@ -123,4 +113,29 @@ public class OperateParseServiceImpl implements VoiceTransactionalService {
|
|||||||
}
|
}
|
||||||
return parameters[index].getName();
|
return parameters[index].getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取执行操作的人员
|
||||||
|
* @return 人员列表
|
||||||
|
*/
|
||||||
|
private List<SimulationMember> filterSimulationMember(Simulation simulation, VoiceDiscriminateResult result
|
||||||
|
, Map<Integer,ParamExtractResult> paramExtractResultMap, MemberRule memberRule) {
|
||||||
|
int paramSize = result.getParamExtractResultList().size();
|
||||||
|
List<SimulationMember> simulationMemberList = null;
|
||||||
|
if (memberRule != null) { // 如果有指定成员解析规则,使用此规则解析
|
||||||
|
if (memberRule.getIndex() == null) {
|
||||||
|
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
|
||||||
|
} else if (memberRule.getIndex() < paramSize) {
|
||||||
|
simulationMemberList = memberRule.getParseRule().matchMember(simulation, paramExtractResultMap.get(memberRule.getIndex()));
|
||||||
|
}
|
||||||
|
return simulationMemberList; // 返回解析结果
|
||||||
|
} else {
|
||||||
|
simulationMemberList = result.getSimulationMemberList(); // 获取群组成员对象
|
||||||
|
if (CollectionUtils.isEmpty(simulationMemberList) || simulationMemberList.size() > 1) {
|
||||||
|
return List.of();
|
||||||
|
} else {
|
||||||
|
return simulationMemberList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,16 @@ public class ReplyParseServiceImpl implements VoiceTransactionalService {
|
|||||||
if (replyRule == null) {
|
if (replyRule == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 回复成员
|
||||||
|
List<SimulationMember> simulationMemberList = filterSimulationMember(simulation, result, replyRule.getMemberRule());
|
||||||
|
if (CollectionUtils.isEmpty(simulationMemberList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 格式化回复语句
|
||||||
List<ParamExtractResult> paramExtractResults = result.getParamExtractResultList();
|
List<ParamExtractResult> paramExtractResults = result.getParamExtractResultList();
|
||||||
ReplyResult replyResult = new ReplyResult(replyRule.getParamRules().size());
|
ReplyResult replyResult = new ReplyResult(replyRule.getParamRules().size());
|
||||||
ParamExtractResult[] paramArr = null;
|
|
||||||
int paramSize = paramExtractResults.size();
|
int paramSize = paramExtractResults.size();
|
||||||
|
ParamExtractResult[] paramArr = null;
|
||||||
for (CommandParamRule paramRule : replyRule.getParamRules()) {
|
for (CommandParamRule paramRule : replyRule.getParamRules()) {
|
||||||
paramArr = new ParamExtractResult[paramRule.getIndexArr().length];
|
paramArr = new ParamExtractResult[paramRule.getIndexArr().length];
|
||||||
for (int index = 0, len = paramArr.length; index < len; index ++) {
|
for (int index = 0, len = paramArr.length; index < len; index ++) {
|
||||||
@ -45,31 +51,33 @@ public class ReplyParseServiceImpl implements VoiceTransactionalService {
|
|||||||
}
|
}
|
||||||
replyResult.addParams(paramRule.getParseRule().extractParam(simulation, paramArr));
|
replyResult.addParams(paramRule.getParseRule().extractParam(simulation, paramArr));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化回复语句
|
|
||||||
Object[] objArr = new Object[replyResult.getParamList().size()];
|
Object[] objArr = new Object[replyResult.getParamList().size()];
|
||||||
replyResult.getParamList().toArray(objArr);
|
replyResult.getParamList().toArray(objArr);
|
||||||
replyResult.setContent(String.format(replyRule.getMessageFormat(), objArr));
|
replyResult.setContent(String.format(replyRule.getMessageFormat(), objArr));
|
||||||
// 匹配回复人员
|
// 执行回复
|
||||||
MemberRule memberRule = replyRule.getMemberRule();
|
simulationMemberList.forEach(member -> conversationManagerService.conversationChat(simulation, member, replyResult.getContent(), null));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取回复成员列表
|
||||||
|
*
|
||||||
|
* @param simulation 仿真
|
||||||
|
* @param result 封装的结果信息
|
||||||
|
* @param memberRule 成员解析规则
|
||||||
|
* @return 回复成员列表
|
||||||
|
*/
|
||||||
|
private List<SimulationMember> filterSimulationMember(Simulation simulation, VoiceDiscriminateResult result, MemberRule memberRule) {
|
||||||
|
List<ParamExtractResult> paramExtractResults = result.getParamExtractResultList();
|
||||||
|
List<SimulationMember> simulationMemberList = null;
|
||||||
if (memberRule != null) {
|
if (memberRule != null) {
|
||||||
List<SimulationMember> simulationMemberList = null;
|
|
||||||
if (memberRule.getIndex() == null) {
|
if (memberRule.getIndex() == null) {
|
||||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
|
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
|
||||||
} else if (memberRule.getIndex() < paramExtractResults.size()) {
|
} else if (memberRule.getIndex() < paramExtractResults.size()) {
|
||||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, paramExtractResults.get(memberRule.getIndex() - 1));
|
simulationMemberList = memberRule.getParseRule().matchMember(simulation, paramExtractResults.get(memberRule.getIndex() - 1));
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isEmpty(simulationMemberList)) {
|
return simulationMemberList;
|
||||||
return;
|
} else {
|
||||||
}
|
return result.getSimulationMemberList();
|
||||||
replyResult.setSimulationMemberList(simulationMemberList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 执行回复
|
|
||||||
replyResult.getSimulationMemberList().forEach(member -> {
|
|
||||||
conversationManagerService.conversationChat(simulation, member, replyResult.getContent(), null);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,27 @@
|
|||||||
package club.joylink.rtss.services.voice.discriminate;
|
package club.joylink.rtss.services.voice.discriminate;
|
||||||
|
|
||||||
|
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.conversation.ConversationMember;
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.event.conversation.SimulationConversationGroupDissolveEvent;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.event.conversation.SimulationConversationGroupMessageEvent;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 语音识别服务类(多例)
|
* 语音识别服务类
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -50,4 +61,33 @@ public class VoiceDiscriminateService {
|
|||||||
replyParseService.doExec(result, simulation); // 回复执行
|
replyParseService.doExec(result, simulation); // 回复执行
|
||||||
correctSourceService.doExec(result, simulation);// 原信息纠错
|
correctSourceService.doExec(result, simulation);// 原信息纠错
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接受语音文件、资源等必要条件,解析开始
|
||||||
|
*/
|
||||||
|
public void doAnalysis(Simulation simulation, String content, List<SimulationMember> memberList) {
|
||||||
|
VoiceDiscriminateResult result = voiceParseService.doParse(simulation, content);
|
||||||
|
result.setSimulationMemberList(memberList); // 匹配到人员集合
|
||||||
|
operateParseService.doExec(result, simulation); // 指令执行
|
||||||
|
replyParseService.doExec(result, simulation); // 回复执行
|
||||||
|
correctSourceService.doExec(result, simulation);// 原信息纠错
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理聊天信息
|
||||||
|
* @param event 聊天事件信息
|
||||||
|
*/
|
||||||
|
@EventListener
|
||||||
|
public void handleMessage(SimulationConversationGroupMessageEvent event) {
|
||||||
|
ConversationGroup conversationGroup = event.getConversationGroup();
|
||||||
|
SimulationMember member = event.getMember();
|
||||||
|
List<SimulationMember> memberList = conversationGroup.getMemberList().stream()
|
||||||
|
.filter(cm -> cm.isRobot() && !Objects.equals(cm.getMember(), member))
|
||||||
|
.map(ConversationMember::getMember).collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isEmpty(memberList)) { // 人员全部为真实人员时直接返回
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 执行语音识别
|
||||||
|
doAnalysis(event.getSimulation(), event.getContent(), memberList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,29 +278,56 @@ public class Simulation extends club.joylink.rtss.simulation.Simulation<Simulati
|
|||||||
return new ArrayList<>(this.simulationConversationMap.values());
|
return new ArrayList<>(this.simulationConversationMap.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加群组
|
||||||
|
* @param group 群组信息
|
||||||
|
*/
|
||||||
public void addConversationGroup(ConversationGroup group) {
|
public void addConversationGroup(ConversationGroup group) {
|
||||||
this.simulationConversationGroupMap.put(group.getId(), group);
|
this.simulationConversationGroupMap.put(group.getId(), group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除群组
|
||||||
|
* @param group 群组信息
|
||||||
|
*/
|
||||||
public void removeConversionGroup(ConversationGroup group) {
|
public void removeConversionGroup(ConversationGroup group) {
|
||||||
this.simulationConversationGroupMap.remove(group.getId());
|
this.simulationConversationGroupMap.remove(group.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化群组信息
|
||||||
|
* @param map 群组信息Map
|
||||||
|
*/
|
||||||
public void initDefaultConversationGroupMap(Map<Long, ConversationGroup> map) {
|
public void initDefaultConversationGroupMap(Map<Long, ConversationGroup> map) {
|
||||||
|
this.simulationConversationGroupMap.clear();
|
||||||
this.simulationConversationGroupMap.putAll(map);
|
this.simulationConversationGroupMap.putAll(map);
|
||||||
Long groupId = map.keySet().stream().max(Comparator.comparing(Long::longValue)).orElse(0L);
|
Long groupId = map.keySet().stream().max(Comparator.comparing(Long::longValue)).orElse(0L);
|
||||||
this.conversationGroupId.set(groupId);
|
this.conversationGroupId.set(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据名称查找群组
|
||||||
|
* @param name 名称
|
||||||
|
* @return 群组信息
|
||||||
|
*/
|
||||||
public ConversationGroup getConversationGroupByName(String name) {
|
public ConversationGroup getConversationGroupByName(String name) {
|
||||||
return this.simulationConversationGroupMap.values().stream().filter(group -> Objects.equals(group.getName(), name))
|
return this.simulationConversationGroupMap.values().stream().filter(group -> Objects.equals(group.getName(), name))
|
||||||
.findAny().orElse(null);
|
.findAny().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取下一个群组ID
|
||||||
|
* @return ID
|
||||||
|
*/
|
||||||
public Long getMaxConversationGroupId() {
|
public Long getMaxConversationGroupId() {
|
||||||
return conversationGroupId.incrementAndGet();
|
return conversationGroupId.incrementAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID获取群组信息
|
||||||
|
* @param id 群组ID
|
||||||
|
* @return 群组
|
||||||
|
*/
|
||||||
public ConversationGroup getConversationGroup(Long id) {
|
public ConversationGroup getConversationGroup(Long id) {
|
||||||
ConversationGroup group = this.simulationConversationGroupMap.get(id);
|
ConversationGroup group = this.simulationConversationGroupMap.get(id);
|
||||||
if (Objects.isNull(group)) {
|
if (Objects.isNull(group)) {
|
||||||
@ -310,6 +337,10 @@ public class Simulation extends club.joylink.rtss.simulation.Simulation<Simulati
|
|||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取群组列表
|
||||||
|
* @return 群组列表
|
||||||
|
*/
|
||||||
public List<ConversationGroup> queryAllConversationGroup(){
|
public List<ConversationGroup> queryAllConversationGroup(){
|
||||||
return new ArrayList<>(this.simulationConversationGroupMap.values());
|
return new ArrayList<>(this.simulationConversationGroupMap.values());
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -26,16 +27,16 @@ public class ConversationGroup extends Chat {
|
|||||||
*/
|
*/
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像路径
|
||||||
|
*/
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 聊天室名称
|
* 聊天室名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
|
||||||
* 群主
|
|
||||||
*/
|
|
||||||
private SimulationMember leader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 群消息列表
|
* 群消息列表
|
||||||
*/
|
*/
|
||||||
@ -55,34 +56,41 @@ public class ConversationGroup extends Chat {
|
|||||||
public ConversationGroup(Simulation simulation, ConversationGroupVO info) {
|
public ConversationGroup(Simulation simulation, ConversationGroupVO info) {
|
||||||
this.id = info.getId();
|
this.id = info.getId();
|
||||||
this.name = info.getName();
|
this.name = info.getName();
|
||||||
|
this.imageUrl = info.getImageUrl();
|
||||||
setTime(simulation.getCorrectSystemTime());
|
setTime(simulation.getCorrectSystemTime());
|
||||||
if (info.getLeaderId() != null) { // 设置群主
|
// 成员中放入群主
|
||||||
this.leader = simulation.getSimulationMemberById(info.getLeaderId());
|
SimulationMember leader = simulation.getSimulationMemberById(info.getLeaderId());
|
||||||
setCreator(this.leader);
|
setCreator(leader);
|
||||||
}
|
int size = CollectionUtils.isEmpty(info.getMemberIds()) ? 1 : info.getMemberIds().size() + 1;
|
||||||
setTime(simulation.getCorrectSystemTime());
|
List<ConversationMember> memberList = new ArrayList<>(size);
|
||||||
List<ConversationMember> memberList = null;
|
ConversationMember conversationLeader = new ConversationMember(leader);
|
||||||
if (!CollectionUtils.isEmpty(info.getMemberIds())) {
|
conversationLeader.setLeader();
|
||||||
memberList = info.getMemberIds().stream().distinct().map(simulation::getSimulationMemberById)
|
memberList.add(conversationLeader);
|
||||||
.map(ConversationMember::new).collect(Collectors.toList());
|
// 处理群成员
|
||||||
setMemberList(memberList);
|
if (size > 1) {
|
||||||
|
info.getMemberIds().stream().filter(id -> !Objects.equals(id, info.getLeaderId())).distinct()
|
||||||
|
.map(simulation::getSimulationMemberById)
|
||||||
|
.forEach(member -> memberList.add(new ConversationMember(member)));
|
||||||
}
|
}
|
||||||
|
setMemberList(memberList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConversationGroup(Long id, String name, LocalDateTime time, SimulationMember leader, List<SimulationMember> simulationMembers){
|
public ConversationGroup(Long id, String name, LocalDateTime time, SimulationMember leader, List<SimulationMember> simulationMembers){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.leader = leader;
|
|
||||||
setTime(time);
|
setTime(time);
|
||||||
setCreator(leader);
|
setCreator(leader);
|
||||||
if (!CollectionUtils.isEmpty(simulationMembers)) {
|
int size = CollectionUtils.isEmpty(simulationMembers) ? 1 : simulationMembers.size() + 1;
|
||||||
List<ConversationMember> memberList = simulationMembers.stream().map(member -> {
|
List<ConversationMember> memberList = new ArrayList<>(size);
|
||||||
ConversationMember conversationMember = new ConversationMember(member);
|
ConversationMember conversationLeader = new ConversationMember(leader);
|
||||||
conversationMember.setTime(time);
|
conversationLeader.setLeader();
|
||||||
return conversationMember;
|
memberList.add(conversationLeader);
|
||||||
}).collect(Collectors.toList());
|
// 处理群成员
|
||||||
setMemberList(memberList);
|
if (size > 1) {
|
||||||
|
simulationMembers.stream().filter(member -> !Objects.equals(member.getId(), leader.getId())).distinct()
|
||||||
|
.forEach(member -> memberList.add(new ConversationMember(member)));
|
||||||
}
|
}
|
||||||
|
setMemberList(memberList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,12 +150,69 @@ public class ConversationGroup extends Chat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置群主
|
||||||
|
* @param member 角色
|
||||||
|
*/
|
||||||
|
public void setLeader(SimulationMember member) {
|
||||||
|
ConversationMember leader = getMemberList().stream().filter(ConversationMember::isLeader).findFirst().orElse(null);
|
||||||
|
if (leader != null) {
|
||||||
|
leader.setMember();
|
||||||
|
}
|
||||||
|
ConversationMember conversationMember = getConversionMember(member);
|
||||||
|
conversationMember.setLeader();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否群主
|
* 是否群主
|
||||||
* @param member 成员
|
* @param member 成员
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public boolean isLeader(SimulationMember member) {
|
public boolean isLeader(SimulationMember member) {
|
||||||
return Objects.equals(member, this.leader);
|
ConversationMember conversationMember = getConversionMember(member);
|
||||||
|
return conversationMember != null && conversationMember.isLeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取成员用户ID
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public Set<String> getMemberUserId() {
|
||||||
|
return getMemberList().stream().filter(member -> !member.isRobot())
|
||||||
|
.map(member -> member.getMember().getUserId()).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取不含群组的用户ID
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public Set<String> getMemberUserIdWithOutLeader() {
|
||||||
|
return getMemberList().stream().filter(member -> !member.isRobot() && !member.isLeader())
|
||||||
|
.map(member -> member.getMember().getUserId()).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取成员用户ID
|
||||||
|
* @param memberIds 指定角色ID
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public Set<String> getMemberUserId(List<String> memberIds) {
|
||||||
|
if (CollectionUtils.isEmpty(memberIds)) {
|
||||||
|
return Set.of();
|
||||||
|
}
|
||||||
|
return getMemberList().stream().filter(m -> !m.isRobot() && memberIds.contains(m.getMember().getId()))
|
||||||
|
.map(member -> member.getMember().getUserId()).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取群主信息
|
||||||
|
* @return 群主角色
|
||||||
|
*/
|
||||||
|
public SimulationMember getLeader() {
|
||||||
|
ConversationMember member = getMemberList().stream().filter(ConversationMember::isLeader).findFirst().orElse(null);
|
||||||
|
if (member == null) {
|
||||||
|
throw new IllegalArgumentException("不存在群主");
|
||||||
|
}
|
||||||
|
return member.getMember();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,24 @@
|
|||||||
package club.joylink.rtss.simulation.cbtc.conversation;
|
package club.joylink.rtss.simulation.cbtc.conversation;
|
||||||
|
|
||||||
import club.joylink.rtss.services.voice.VoiceService;
|
import club.joylink.rtss.services.voice.VoiceService;
|
||||||
|
import club.joylink.rtss.services.voice.discriminate.VoiceDiscriminateService;
|
||||||
import club.joylink.rtss.simulation.cbtc.GroupSimulationCache;
|
import club.joylink.rtss.simulation.cbtc.GroupSimulationCache;
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO;
|
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupSocketMessageVO;
|
||||||
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupVO;
|
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupVO;
|
||||||
import club.joylink.rtss.simulation.cbtc.event.conversation.*;
|
import club.joylink.rtss.simulation.cbtc.event.conversation.*;
|
||||||
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
|
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
|
||||||
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
|
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
|
||||||
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
||||||
|
import club.joylink.rtss.vo.client.SocketMessageVO;
|
||||||
|
import club.joylink.rtss.vo.client.WebSocketMessageType;
|
||||||
|
import club.joylink.rtss.vo.client.factory.SocketMessageFactory;
|
||||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
||||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO;
|
import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO;
|
||||||
|
import club.joylink.rtss.websocket.StompMessageService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
@ -38,6 +45,9 @@ public class ConversationGroupHandlerService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationEventPublisher applicationEventPublisher;
|
private ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StompMessageService stompMessageService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有群组信息
|
* 获取所有群组信息
|
||||||
* @param group 仿真ID
|
* @param group 仿真ID
|
||||||
@ -79,7 +89,7 @@ public class ConversationGroupHandlerService {
|
|||||||
* @param groupId 群组主键
|
* @param groupId 群组主键
|
||||||
* @param name 群组名称
|
* @param name 群组名称
|
||||||
*/
|
*/
|
||||||
public void updateConversationGroup(Simulation simulation, SimulationMember member, Long groupId, String name) {
|
public void updateConversationGroupName(Simulation simulation, SimulationMember member, Long groupId, String name) {
|
||||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, groupId);
|
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, groupId);
|
||||||
// 查找名称是否已存在
|
// 查找名称是否已存在
|
||||||
ConversationGroup nameConversationGroup = simulation.getConversationGroupByName(name);
|
ConversationGroup nameConversationGroup = simulation.getConversationGroupByName(name);
|
||||||
@ -90,7 +100,7 @@ public class ConversationGroupHandlerService {
|
|||||||
}
|
}
|
||||||
conversationGroup.setName(name);
|
conversationGroup.setName(name);
|
||||||
// 通知其他用户群名变更
|
// 通知其他用户群名变更
|
||||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupUpdateEvent(this, simulation, conversationGroup));
|
applicationEventPublisher.publishEvent(new SimulationConversationGroupUpdateEvent(this, simulation, conversationGroup, ConversationGroupSocketMessageVO.MessageType.UPDATE_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,16 +111,16 @@ public class ConversationGroupHandlerService {
|
|||||||
* @param groupId 群组主键
|
* @param groupId 群组主键
|
||||||
* @param memberId 目标用户
|
* @param memberId 目标用户
|
||||||
*/
|
*/
|
||||||
public void setConversationGroupLeader(Simulation simulation, SimulationMember member, Long groupId, String memberId) {
|
public void updateConversationGroupLeader(Simulation simulation, SimulationMember member, Long groupId, String memberId) {
|
||||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, groupId);
|
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, groupId);
|
||||||
SimulationMember simulationMember = simulation.getSimulationMemberById(memberId);
|
SimulationMember simulationMember = simulation.getSimulationMemberById(memberId);
|
||||||
if (!conversationGroup.isConversationMember(simulationMember)) {
|
if (!conversationGroup.isConversationMember(simulationMember)) {
|
||||||
conversationGroup.addSimulationMember(simulationMember, simulation.getCorrectSystemTime());
|
conversationGroup.addSimulationMember(simulationMember, simulation.getCorrectSystemTime());
|
||||||
}
|
}
|
||||||
// 设置群组
|
// 设置群组
|
||||||
conversationGroup.setCreator(simulationMember);
|
conversationGroup.setLeader(simulationMember);
|
||||||
// 发送通知消息
|
// 发送通知消息
|
||||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupUpdateEvent(this, simulation, conversationGroup));
|
applicationEventPublisher.publishEvent(new SimulationConversationGroupUpdateEvent(this, simulation, conversationGroup, ConversationGroupSocketMessageVO.MessageType.UPDATE_MEMBER));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,12 +137,14 @@ public class ConversationGroupHandlerService {
|
|||||||
}
|
}
|
||||||
List<String> groupMemberIds = conversationGroup.getSimulationMemberIds();
|
List<String> groupMemberIds = conversationGroup.getSimulationMemberIds();
|
||||||
List<String> newMemberIds = memberIds.stream().filter(mid -> !groupMemberIds.contains(mid)).collect(Collectors.toList());
|
List<String> newMemberIds = memberIds.stream().filter(mid -> !groupMemberIds.contains(mid)).collect(Collectors.toList());
|
||||||
|
List<SimulationMember> newSimulationMemberList = new ArrayList<>(newMemberIds.size());
|
||||||
newMemberIds.forEach(memberId -> {
|
newMemberIds.forEach(memberId -> {
|
||||||
SimulationMember newMember = simulation.getSimulationMemberById(memberId);
|
SimulationMember newMember = simulation.getSimulationMemberById(memberId);
|
||||||
|
newSimulationMemberList.add(newMember);
|
||||||
conversationGroup.addSimulationMember(newMember, simulation.getCorrectSystemTime());
|
conversationGroup.addSimulationMember(newMember, simulation.getCorrectSystemTime());
|
||||||
});
|
});
|
||||||
// 给新加入的用户发送消息
|
// 给新加入的用户发送消息
|
||||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupInviteEvent(this, simulation, conversationGroup, groupMemberIds, newMemberIds));
|
applicationEventPublisher.publishEvent(new SimulationConversationGroupInviteEvent(this, simulation, conversationGroup, groupMemberIds, newSimulationMemberList));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -200,13 +212,12 @@ public class ConversationGroupHandlerService {
|
|||||||
* @return 消息信息实体
|
* @return 消息信息实体
|
||||||
*/
|
*/
|
||||||
public ConversationGroupMessageVO audioChat(Simulation simulation, SimulationMember member, Long groupId, String audioPath, String content) {
|
public ConversationGroupMessageVO audioChat(Simulation simulation, SimulationMember member, Long groupId, String audioPath, String content) {
|
||||||
ConversationGroupMessage message = sendMessage(simulation, member, groupId, () -> {
|
return sendMessage(simulation, member, groupId, () -> {
|
||||||
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
|
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
|
||||||
recognitionResult.setFilePath(audioPath);
|
recognitionResult.setFilePath(audioPath);
|
||||||
recognitionResult.setResult(content);
|
recognitionResult.setResult(content);
|
||||||
return recognitionResult;
|
return recognitionResult;
|
||||||
});
|
});
|
||||||
return new ConversationGroupMessageVO(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -219,12 +230,11 @@ public class ConversationGroupHandlerService {
|
|||||||
* @return 消息信息实体
|
* @return 消息信息实体
|
||||||
*/
|
*/
|
||||||
public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member, Long groupId, String content) {
|
public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member, Long groupId, String content) {
|
||||||
ConversationGroupMessage message = sendMessage(simulation, member, groupId, () -> {
|
return sendMessage(simulation, member, groupId, () -> {
|
||||||
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
|
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
|
||||||
recognitionResult.setResult(content);
|
recognitionResult.setResult(content);
|
||||||
return recognitionResult;
|
return recognitionResult;
|
||||||
});
|
});
|
||||||
return new ConversationGroupMessageVO(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -236,11 +246,10 @@ public class ConversationGroupHandlerService {
|
|||||||
* @return 消息信息实体
|
* @return 消息信息实体
|
||||||
*/
|
*/
|
||||||
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long groupId, String fileBase64Str) {
|
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long groupId, String fileBase64Str) {
|
||||||
ConversationGroupMessage message = sendMessage(simulation, member, groupId, () -> {
|
return sendMessage(simulation, member, groupId, () -> {
|
||||||
VoiceRecognitionVO vo = VoiceRecognitionVO.load(fileBase64Str);
|
VoiceRecognitionVO vo = VoiceRecognitionVO.load(fileBase64Str);
|
||||||
return iVoiceService.voiceRecognition(vo);
|
return iVoiceService.voiceRecognition(vo);
|
||||||
});
|
});
|
||||||
return new ConversationGroupMessageVO(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -275,7 +284,18 @@ public class ConversationGroupHandlerService {
|
|||||||
@EventListener
|
@EventListener
|
||||||
public void handleCreate(SimulationConversationGroupCreateEvent event) {
|
public void handleCreate(SimulationConversationGroupCreateEvent event) {
|
||||||
ConversationGroup conversationGroup = event.getConversationGroup();
|
ConversationGroup conversationGroup = event.getConversationGroup();
|
||||||
|
SimulationMember leader = conversationGroup.getLeader();
|
||||||
|
ConversationGroupSocketMessageVO messageVO = ConversationGroupSocketMessageVO.MessageType.JOIN.generateMessageVO(conversationGroup, null);
|
||||||
|
if (!leader.isRobot()) {
|
||||||
|
doSendMessage(event.getSimulation(), Set.of(leader.getUserId()), messageVO);
|
||||||
|
}
|
||||||
|
Set<String> userIds = conversationGroup.getMemberUserIdWithOutLeader();
|
||||||
|
if (CollectionUtils.isEmpty(userIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 给非群主的群人员发送消息、添加tips信息
|
||||||
|
messageVO.setMessageTips(String.format("你加入了【%s】", conversationGroup.getName()));
|
||||||
|
doSendMessage(event.getSimulation(), userIds, messageVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -284,7 +304,13 @@ public class ConversationGroupHandlerService {
|
|||||||
*/
|
*/
|
||||||
@EventListener
|
@EventListener
|
||||||
public void handleUpdate(SimulationConversationGroupUpdateEvent event) {
|
public void handleUpdate(SimulationConversationGroupUpdateEvent event) {
|
||||||
|
ConversationGroup conversationGroup = event.getConversationGroup();
|
||||||
|
Set<String> userIds = conversationGroup.getMemberUserId();
|
||||||
|
if (CollectionUtils.isEmpty(userIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ConversationGroupSocketMessageVO messageVO = event.getMessageType().generateMessageVO(conversationGroup, null);
|
||||||
|
doSendMessage(event.getSimulation(), userIds, messageVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -293,7 +319,29 @@ public class ConversationGroupHandlerService {
|
|||||||
*/
|
*/
|
||||||
@EventListener
|
@EventListener
|
||||||
public void handleInvite(SimulationConversationGroupInviteEvent event) {
|
public void handleInvite(SimulationConversationGroupInviteEvent event) {
|
||||||
|
ConversationGroup conversationGroup = event.getConversationGroup();
|
||||||
|
Set<String> newUserIdSet = new HashSet<>(); // 发送加入信息的用户列表
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
event.getNewMemberList().forEach(m -> {
|
||||||
|
if (!m.isRobot()) {
|
||||||
|
newUserIdSet.add(m.getUserId());
|
||||||
|
}
|
||||||
|
stringBuilder.append(m.getName()).append("、");
|
||||||
|
});
|
||||||
|
// 通知新成员
|
||||||
|
if (!CollectionUtils.isEmpty(newUserIdSet)) {
|
||||||
|
ConversationGroupSocketMessageVO joinMessageVO = ConversationGroupSocketMessageVO.MessageType.JOIN.generateMessageVO(conversationGroup, null);
|
||||||
|
// 添加tips信息
|
||||||
|
joinMessageVO.setMessageTips(String.format("你加入了【%s】", conversationGroup.getName()));
|
||||||
|
doSendMessage(event.getSimulation(), newUserIdSet, joinMessageVO);
|
||||||
|
}
|
||||||
|
Set<String> oldUserIdSet = conversationGroup.getMemberUserId(event.getGroupMemberIds());
|
||||||
|
// 通知老成员
|
||||||
|
if (!CollectionUtils.isEmpty(oldUserIdSet)) {
|
||||||
|
ConversationGroupSocketMessageVO updateMessageVO = ConversationGroupSocketMessageVO.MessageType.UPDATE_MEMBER.generateMessageVO(conversationGroup, null);
|
||||||
|
updateMessageVO.setMessageTips("欢迎【" + stringBuilder.substring(0, stringBuilder.length() - 1) + "】加入本群");
|
||||||
|
doSendMessage(event.getSimulation(), conversationGroup.getMemberUserId(event.getGroupMemberIds()), updateMessageVO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -303,7 +351,22 @@ public class ConversationGroupHandlerService {
|
|||||||
*/
|
*/
|
||||||
@EventListener
|
@EventListener
|
||||||
public void handleRemove(SimulationConversationGroupRemoveEvent event) {
|
public void handleRemove(SimulationConversationGroupRemoveEvent event) {
|
||||||
|
ConversationGroup conversationGroup = event.getConversationGroup();
|
||||||
|
Set<String> removeUserIdSet = event.getRemoveGroupMember().stream().filter(m -> !m.isRobot()).map(SimulationMember::getUserId).collect(Collectors.toSet());
|
||||||
|
// 通知移除
|
||||||
|
if (!CollectionUtils.isEmpty(removeUserIdSet)) {
|
||||||
|
ConversationGroupSocketMessageVO exitMessageVO = ConversationGroupSocketMessageVO.MessageType.EXIT.generateMessageVO(conversationGroup, null);
|
||||||
|
// 添加tips信息
|
||||||
|
exitMessageVO.setMessageTips(String.format("你被移出了【%s】", conversationGroup.getName()));
|
||||||
|
doSendMessage(event.getSimulation(), removeUserIdSet, exitMessageVO);
|
||||||
|
}
|
||||||
|
// 更新其他用户的成员列表
|
||||||
|
Set<String> userIdSet = conversationGroup.getMemberUserId();
|
||||||
|
if (CollectionUtils.isEmpty(userIdSet)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ConversationGroupSocketMessageVO updateMessageVO = ConversationGroupSocketMessageVO.MessageType.UPDATE_MEMBER.generateMessageVO(conversationGroup, null);
|
||||||
|
doSendMessage(event.getSimulation(), userIdSet, updateMessageVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -312,7 +375,12 @@ public class ConversationGroupHandlerService {
|
|||||||
*/
|
*/
|
||||||
@EventListener
|
@EventListener
|
||||||
public void handleExit(SimulationConversationGroupExitEvent event) {
|
public void handleExit(SimulationConversationGroupExitEvent event) {
|
||||||
|
if (event.getMember().isRobot()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ConversationGroup conversationGroup = event.getConversationGroup();
|
||||||
|
ConversationGroupSocketMessageVO exitMessageVO = ConversationGroupSocketMessageVO.MessageType.EXIT.generateMessageVO(conversationGroup, null);
|
||||||
|
doSendMessage(event.getSimulation(), Set.of(event.getMember().getUserId()), exitMessageVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -321,7 +389,15 @@ public class ConversationGroupHandlerService {
|
|||||||
*/
|
*/
|
||||||
@EventListener
|
@EventListener
|
||||||
public void handleDissolve(SimulationConversationGroupDissolveEvent event) {
|
public void handleDissolve(SimulationConversationGroupDissolveEvent event) {
|
||||||
|
ConversationGroup conversationGroup = event.getConversationGroup();
|
||||||
|
// 更新其他用户的成员列表
|
||||||
|
Set<String> userIdSet = conversationGroup.getMemberUserId();
|
||||||
|
if (CollectionUtils.isEmpty(userIdSet)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ConversationGroupSocketMessageVO exitMessageVO = ConversationGroupSocketMessageVO.MessageType.EXIT.generateMessageVO(conversationGroup, null);
|
||||||
|
exitMessageVO.setMessageTips(String.format("【%s】解散了", conversationGroup.getName()));
|
||||||
|
doSendMessage(event.getSimulation(), userIdSet, exitMessageVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -351,29 +427,45 @@ public class ConversationGroupHandlerService {
|
|||||||
* @param handleSupplier 处理消息方法
|
* @param handleSupplier 处理消息方法
|
||||||
* @return 用户组消息
|
* @return 用户组消息
|
||||||
*/
|
*/
|
||||||
private ConversationGroupMessage sendMessage(Simulation simulation, SimulationMember member, Long groupId
|
private ConversationGroupMessageVO sendMessage(Simulation simulation, SimulationMember member, Long groupId
|
||||||
, Supplier<VoiceRecognitionResult> handleSupplier) {
|
, Supplier<VoiceRecognitionResult> handleSupplier) {
|
||||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, groupId);
|
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, groupId);
|
||||||
if (!conversationGroup.isConversationMember(member)) {
|
if (!conversationGroup.isConversationMember(member)) {
|
||||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非本组成员,不能邀请用户");
|
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非本组成员");
|
||||||
}
|
}
|
||||||
|
|
||||||
VoiceRecognitionResult recognitionResult = handleSupplier.get();
|
VoiceRecognitionResult recognitionResult = handleSupplier.get();
|
||||||
String upperCaseResult = recognitionResult.getResult().toUpperCase();
|
String upperCaseResult = recognitionResult.getResult().toUpperCase();
|
||||||
String handledContent = simulationVoiceHandler.handle(upperCaseResult);
|
String handledContent = simulationVoiceHandler.handle(upperCaseResult);
|
||||||
|
|
||||||
// 创建消息信息
|
// 创建消息信息
|
||||||
String messageId = conversationGroup.generateMessageId();
|
String messageId = conversationGroup.generateMessageId();
|
||||||
ConversationGroupMessage message = new ConversationGroupMessage(messageId, member,
|
ConversationGroupMessage message = new ConversationGroupMessage(messageId, member,
|
||||||
simulation.getCorrectSystemTime(), handledContent, recognitionResult.getFilePath());
|
simulation.getCorrectSystemTime(), handledContent, recognitionResult.getFilePath());
|
||||||
conversationGroup.addMessage(message);
|
conversationGroup.addMessage(message);
|
||||||
|
|
||||||
// 发送消息
|
// 发送消息
|
||||||
|
ConversationGroupMessageVO messageVO = new ConversationGroupMessageVO(message);
|
||||||
|
Set<String> userIdSet = conversationGroup.getMemberUserId();
|
||||||
|
if (!CollectionUtils.isEmpty(userIdSet)) {
|
||||||
return message;
|
doSendMessage(simulation, userIdSet, ConversationGroupSocketMessageVO.MessageType.MESSAGE.generateMessageVO(conversationGroup, messageVO));
|
||||||
|
}
|
||||||
|
// 语音识别开始
|
||||||
|
applicationEventPublisher.publishEvent(new SimulationConversationGroupMessageEvent(this, simulation, conversationGroup, member, message.getContent()));
|
||||||
|
return messageVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送消息
|
||||||
|
*
|
||||||
|
* @param simulation 仿真
|
||||||
|
* @param userSet 用户列表
|
||||||
|
* @param messageVO 消息体
|
||||||
|
*/
|
||||||
|
private void doSendMessage(Simulation simulation, Set<String> userSet, ConversationGroupSocketMessageVO messageVO) {
|
||||||
|
if (CollectionUtils.isEmpty(userSet)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SocketMessageVO<ConversationGroupSocketMessageVO> chatMessage =
|
||||||
|
SocketMessageFactory.build(WebSocketMessageType.Simulation_Conversation_Group, simulation.getId(), messageVO);
|
||||||
|
stompMessageService.sendToUser(userSet, chatMessage);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public class ConversationGroupOperateHandler {
|
|||||||
*/
|
*/
|
||||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Name)
|
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Name)
|
||||||
public void updateConversationGroup(Simulation simulation, SimulationMember member, Long groupId, String name) {
|
public void updateConversationGroup(Simulation simulation, SimulationMember member, Long groupId, String name) {
|
||||||
conversationGroupManagerService.updateConversationGroup(simulation, member, groupId, name);
|
conversationGroupManagerService.updateConversationGroupName(simulation, member, groupId, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +51,7 @@ public class ConversationGroupOperateHandler {
|
|||||||
*/
|
*/
|
||||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Leader)
|
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Leader)
|
||||||
public void setConversationGroupLeader(Simulation simulation, SimulationMember member, Long groupId, String memberId) {
|
public void setConversationGroupLeader(Simulation simulation, SimulationMember member, Long groupId, String memberId) {
|
||||||
conversationGroupManagerService.setConversationGroupLeader(simulation, member, groupId, memberId);
|
conversationGroupManagerService.updateConversationGroupLeader(simulation, member, groupId, memberId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,7 +4,6 @@ import club.joylink.rtss.services.voice.VoiceService;
|
|||||||
import club.joylink.rtss.simulation.cbtc.GroupSimulationCache;
|
import club.joylink.rtss.simulation.cbtc.GroupSimulationCache;
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
import club.joylink.rtss.simulation.cbtc.competition.ScriptExecuteService;
|
import club.joylink.rtss.simulation.cbtc.competition.ScriptExecuteService;
|
||||||
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupVO;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationMessageVO;
|
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationMessageVO;
|
||||||
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationVO;
|
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationVO;
|
||||||
import club.joylink.rtss.simulation.cbtc.event.*;
|
import club.joylink.rtss.simulation.cbtc.event.*;
|
||||||
|
@ -5,6 +5,7 @@ import lombok.Getter;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class ConversationMember {
|
public class ConversationMember {
|
||||||
@ -19,16 +20,58 @@ public class ConversationMember {
|
|||||||
@Setter
|
@Setter
|
||||||
private LocalDateTime time;
|
private LocalDateTime time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
private Role role;
|
||||||
|
|
||||||
public ConversationMember(SimulationMember member) {
|
public ConversationMember(SimulationMember member) {
|
||||||
this.member = member;
|
this.member = member;
|
||||||
this.connect = false;
|
this.connect = false;
|
||||||
|
this.role = Role.Member;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRobot() {
|
public boolean isRobot() {
|
||||||
return member.isRobot();
|
return member.isRobot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否群主
|
||||||
|
*/
|
||||||
|
public boolean isLeader() {
|
||||||
|
return Objects.equals(this.role, Role.Leader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置群主
|
||||||
|
*/
|
||||||
|
public void setLeader() {
|
||||||
|
this.role = Role.Leader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置成员
|
||||||
|
*/
|
||||||
|
public void setMember() {
|
||||||
|
this.role = Role.Member;
|
||||||
|
}
|
||||||
|
|
||||||
public void connect() {
|
public void connect() {
|
||||||
this.connect = true;
|
this.connect = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成员角色
|
||||||
|
*/
|
||||||
|
public enum Role {
|
||||||
|
/**
|
||||||
|
* 群主
|
||||||
|
*/
|
||||||
|
Leader,
|
||||||
|
/**
|
||||||
|
* 成员
|
||||||
|
*/
|
||||||
|
Member;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
package club.joylink.rtss.simulation.cbtc.data.vo;
|
package club.joylink.rtss.simulation.cbtc.data.vo;
|
||||||
|
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.conversation.Conversation;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
|
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
|
||||||
import club.joylink.rtss.simulation.cbtc.conversation.ConversationMessage;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.ParamExtractResult;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 群组socket消息内容
|
||||||
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public class ConversationGroupSocketMessageVO {
|
public class ConversationGroupSocketMessageVO {
|
||||||
|
|
||||||
@ -26,11 +25,6 @@ public class ConversationGroupSocketMessageVO {
|
|||||||
*/
|
*/
|
||||||
private String creatorId;
|
private String creatorId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 群主
|
|
||||||
*/
|
|
||||||
private String leaderId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 成员列表
|
* 成员列表
|
||||||
*/
|
*/
|
||||||
@ -46,25 +40,27 @@ public class ConversationGroupSocketMessageVO {
|
|||||||
*/
|
*/
|
||||||
private MessageType messageType;
|
private MessageType messageType;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private String messageTips;
|
||||||
|
|
||||||
public enum MessageType {
|
public enum MessageType {
|
||||||
/**
|
/**
|
||||||
* 会话组创建
|
* 会话组创建
|
||||||
*/
|
*/
|
||||||
CREATE {
|
JOIN {
|
||||||
@Override
|
@Override
|
||||||
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
|
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
|
||||||
ConversationGroupSocketMessageVO messageVO = new ConversationGroupSocketMessageVO();
|
ConversationGroupSocketMessageVO messageVO = new ConversationGroupSocketMessageVO();
|
||||||
messageVO.id = group.getId();
|
messageVO.id = group.getId();
|
||||||
messageVO.name = group.getName();
|
messageVO.name = group.getName();
|
||||||
messageVO.creatorId = group.getCreator() != null ? group.getCreator().getId() : null;
|
messageVO.creatorId = group.getCreator() != null ? group.getCreator().getId() : null;
|
||||||
messageVO.leaderId = group.getLeader() != null ? group.getLeader().getId() : null;
|
|
||||||
messageVO.memberList = group.getMemberList().stream().map(ConversationMemberVO::new).collect(Collectors.toList());
|
messageVO.memberList = group.getMemberList().stream().map(ConversationMemberVO::new).collect(Collectors.toList());
|
||||||
messageVO.messageType = MessageType.CREATE;
|
messageVO.messageType = MessageType.JOIN;
|
||||||
return messageVO;
|
return messageVO;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 会话组更新
|
* 会话组全量更新
|
||||||
*/
|
*/
|
||||||
UPDATE {
|
UPDATE {
|
||||||
@Override
|
@Override
|
||||||
@ -72,37 +68,59 @@ public class ConversationGroupSocketMessageVO {
|
|||||||
ConversationGroupSocketMessageVO messageVO = new ConversationGroupSocketMessageVO();
|
ConversationGroupSocketMessageVO messageVO = new ConversationGroupSocketMessageVO();
|
||||||
messageVO.id = group.getId();
|
messageVO.id = group.getId();
|
||||||
messageVO.name = group.getName();
|
messageVO.name = group.getName();
|
||||||
messageVO.leaderId = group.getLeader() != null ? group.getLeader().getId() : null;
|
|
||||||
messageVO.memberList = group.getMemberList().stream().map(ConversationMemberVO::new).collect(Collectors.toList());
|
messageVO.memberList = group.getMemberList().stream().map(ConversationMemberVO::new).collect(Collectors.toList());
|
||||||
messageVO.messageType = MessageType.UPDATE;
|
messageVO.messageType = MessageType.UPDATE;
|
||||||
return messageVO;
|
return messageVO;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 修改名称
|
||||||
/** 会话组邀请 */
|
*/
|
||||||
INVITE {
|
UPDATE_NAME {
|
||||||
@Override
|
@Override
|
||||||
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
|
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
|
||||||
return null;
|
ConversationGroupSocketMessageVO messageVO = new ConversationGroupSocketMessageVO();
|
||||||
|
messageVO.id = group.getId();
|
||||||
|
messageVO.name = group.getName();
|
||||||
|
messageVO.messageType = MessageType.UPDATE_NAME;
|
||||||
|
return messageVO;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 修改人员信息
|
||||||
|
*/
|
||||||
|
UPDATE_MEMBER {
|
||||||
|
@Override
|
||||||
|
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
|
||||||
|
ConversationGroupSocketMessageVO messageVO = new ConversationGroupSocketMessageVO();
|
||||||
|
messageVO.id = group.getId();
|
||||||
|
messageVO.memberList = group.getMemberList().stream().map(ConversationMemberVO::new).collect(Collectors.toList());
|
||||||
|
messageVO.messageType = MessageType.UPDATE_MEMBER;
|
||||||
|
return messageVO;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/** 成员发送消息 */
|
/** 成员发送消息 */
|
||||||
MESSAGE {
|
MESSAGE {
|
||||||
@Override
|
@Override
|
||||||
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
|
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
|
||||||
return null;
|
ConversationGroupSocketMessageVO messageVO = new ConversationGroupSocketMessageVO();
|
||||||
|
messageVO.id = group.getId();
|
||||||
|
messageVO.message = message;
|
||||||
|
messageVO.messageType = MessageType.MESSAGE;
|
||||||
|
return messageVO;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/** 会话结束 */
|
/** 会话组解散 */
|
||||||
EXIT {
|
EXIT {
|
||||||
@Override
|
@Override
|
||||||
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
|
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
|
||||||
return null;
|
ConversationGroupSocketMessageVO messageVO = new ConversationGroupSocketMessageVO();
|
||||||
|
messageVO.id = group.getId();
|
||||||
|
messageVO.messageType = MessageType.EXIT;
|
||||||
|
return messageVO;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public abstract ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message);
|
public abstract ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,12 @@ public class ConversationGroupVO {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
private String creatorId;
|
private String creatorId;
|
||||||
|
|
||||||
|
private String leaderId;
|
||||||
|
|
||||||
private List<ConversationMemberVO> memberList;
|
private List<ConversationMemberVO> memberList;
|
||||||
|
|
||||||
private List<ConversationGroupMessageVO> messageList;
|
private List<ConversationGroupMessageVO> messageList;
|
||||||
@ -27,27 +31,13 @@ public class ConversationGroupVO {
|
|||||||
public ConversationGroupVO(ConversationGroup conversation) {
|
public ConversationGroupVO(ConversationGroup conversation) {
|
||||||
this.id = conversation.getId();
|
this.id = conversation.getId();
|
||||||
this.name = conversation.getName();
|
this.name = conversation.getName();
|
||||||
if (conversation.getCreator() != null) {
|
this.imageUrl = conversation.getImageUrl();
|
||||||
this.creatorId = conversation.getCreator().getId();
|
this.creatorId = conversation.getCreator() != null ? conversation.getCreator().getId() : null;
|
||||||
}
|
this.leaderId = conversation.getLeader() != null ? conversation.getLeader().getId() : null;
|
||||||
this.memberList = ConversationMemberVO.convert2VOList(conversation.getMemberList());
|
this.memberList = ConversationMemberVO.convert2VOList(conversation.getMemberList());
|
||||||
this.messageList = ConversationGroupMessageVO.convert2VO(conversation.getMessageList());
|
this.messageList = ConversationGroupMessageVO.convert2VO(conversation.getMessageList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成不带消息的VO对象
|
|
||||||
* @param conversation
|
|
||||||
*/
|
|
||||||
public void generateConversationGroupVOWithOutMessage(ConversationGroup conversation) {
|
|
||||||
this.id = conversation.getId();
|
|
||||||
this.name = conversation.getName();
|
|
||||||
if (conversation.getCreator() != null) {
|
|
||||||
this.creatorId = conversation.getCreator().getId();
|
|
||||||
}
|
|
||||||
this.memberList = ConversationMemberVO.convert2VOList(conversation.getMemberList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<ConversationGroupVO> convert2VOList(List<ConversationGroup> list) {
|
public static List<ConversationGroupVO> convert2VOList(List<ConversationGroup> list) {
|
||||||
List<ConversationGroupVO> voList = new ArrayList<>();
|
List<ConversationGroupVO> voList = new ArrayList<>();
|
||||||
if (!CollectionUtils.isEmpty(list)) {
|
if (!CollectionUtils.isEmpty(list)) {
|
||||||
|
@ -16,9 +16,12 @@ public class ConversationMemberVO {
|
|||||||
|
|
||||||
private boolean connect;
|
private boolean connect;
|
||||||
|
|
||||||
|
private ConversationMember.Role role;
|
||||||
|
|
||||||
public ConversationMemberVO(ConversationMember conversationMember) {
|
public ConversationMemberVO(ConversationMember conversationMember) {
|
||||||
this.memberId = conversationMember.getMember().getId();
|
this.memberId = conversationMember.getMember().getId();
|
||||||
this.connect = conversationMember.isConnect();
|
this.connect = conversationMember.isConnect();
|
||||||
|
this.role = conversationMember.getRole();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<ConversationMemberVO> convert2VOList(List<ConversationMember> list) {
|
public static List<ConversationMemberVO> convert2VOList(List<ConversationMember> list) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package club.joylink.rtss.simulation.cbtc.discriminate;
|
package club.joylink.rtss.simulation.cbtc.discriminate;
|
||||||
|
|
||||||
import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation;
|
import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation;
|
||||||
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -18,24 +17,15 @@ public class OperateResult {
|
|||||||
*/
|
*/
|
||||||
private Operation.Type type;
|
private Operation.Type type;
|
||||||
|
|
||||||
// private Boolean operationResult;
|
|
||||||
// private String errResultMsg;
|
|
||||||
/**
|
/**
|
||||||
* 指令参数
|
* 指令参数
|
||||||
*/
|
*/
|
||||||
private Map<String, Object> params = new HashMap<>();
|
private Map<String, Object> params = new HashMap<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* 角色ID
|
|
||||||
*/
|
|
||||||
private SimulationMember member;
|
|
||||||
|
|
||||||
public OperateResult(Operation.Type type) {
|
public OperateResult(Operation.Type type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数放入集合
|
* 参数放入集合
|
||||||
* @param key 集合key
|
* @param key 集合key
|
||||||
|
@ -3,6 +3,7 @@ package club.joylink.rtss.simulation.cbtc.event.conversation;
|
|||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
|
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
|
||||||
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
|
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -23,13 +24,13 @@ public class SimulationConversationGroupInviteEvent extends AbstractSimulationEv
|
|||||||
/**
|
/**
|
||||||
* 新加入的组员
|
* 新加入的组员
|
||||||
*/
|
*/
|
||||||
private List<String> newGroupMemberIds;
|
private List<SimulationMember> newMemberList;
|
||||||
|
|
||||||
public SimulationConversationGroupInviteEvent(Object source, Simulation simulation, ConversationGroup conversationGroup
|
public SimulationConversationGroupInviteEvent(Object source, Simulation simulation, ConversationGroup conversationGroup
|
||||||
, List<String> groupMemberIds, List<String> newGroupMemberIds) {
|
, List<String> groupMemberIds, List<SimulationMember> newMemberList) {
|
||||||
super(source, simulation);
|
super(source, simulation);
|
||||||
this.conversationGroup = conversationGroup;
|
this.conversationGroup = conversationGroup;
|
||||||
this.groupMemberIds = groupMemberIds;
|
this.groupMemberIds = groupMemberIds;
|
||||||
this.newGroupMemberIds = newGroupMemberIds;
|
this.newMemberList = newMemberList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package club.joylink.rtss.simulation.cbtc.event.conversation;
|
||||||
|
|
||||||
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 群组退群事件
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class SimulationConversationGroupMessageEvent extends AbstractSimulationEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话对象
|
||||||
|
*/
|
||||||
|
private ConversationGroup conversationGroup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作用户
|
||||||
|
*/
|
||||||
|
private SimulationMember member;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
public SimulationConversationGroupMessageEvent(Object source, Simulation simulation, ConversationGroup conversationGroup
|
||||||
|
, SimulationMember member, String content) {
|
||||||
|
super(source, simulation);
|
||||||
|
this.conversationGroup = conversationGroup;
|
||||||
|
this.member = member;
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc.event.conversation;
|
|||||||
|
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
|
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupSocketMessageVO;
|
||||||
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
|
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@ -13,8 +14,12 @@ public class SimulationConversationGroupUpdateEvent extends AbstractSimulationEv
|
|||||||
|
|
||||||
private ConversationGroup conversationGroup;
|
private ConversationGroup conversationGroup;
|
||||||
|
|
||||||
public SimulationConversationGroupUpdateEvent(Object source, Simulation simulation, ConversationGroup conversationGroup) {
|
private ConversationGroupSocketMessageVO.MessageType messageType;
|
||||||
|
|
||||||
|
public SimulationConversationGroupUpdateEvent(Object source, Simulation simulation, ConversationGroup conversationGroup
|
||||||
|
, ConversationGroupSocketMessageVO.MessageType messageType) {
|
||||||
super(source, simulation);
|
super(source, simulation);
|
||||||
this.conversationGroup = conversationGroup;
|
this.conversationGroup = conversationGroup;
|
||||||
|
this.messageType = messageType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,6 +168,11 @@ public enum WebSocketMessageType {
|
|||||||
*/
|
*/
|
||||||
Simulation_Operation_Mode_Apply,
|
Simulation_Operation_Mode_Apply,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仿真群组消息
|
||||||
|
*/
|
||||||
|
Simulation_Conversation_Group,
|
||||||
|
|
||||||
//------------------ 仿真剧本 ------------------
|
//------------------ 仿真剧本 ------------------
|
||||||
/**
|
/**
|
||||||
* 仿真-剧本已加载
|
* 仿真-剧本已加载
|
||||||
|
@ -103,7 +103,8 @@ public class SocketMessageFactory {
|
|||||||
case Competition_Practical:
|
case Competition_Practical:
|
||||||
case SIMULATION_RAIL_TICKET:
|
case SIMULATION_RAIL_TICKET:
|
||||||
case Simulation_Alarm:
|
case Simulation_Alarm:
|
||||||
case Simulation_Operation_Mode_Apply: {
|
case Simulation_Operation_Mode_Apply:
|
||||||
|
case Simulation_Conversation_Group: {
|
||||||
topicList.add(SimulationSubscribeTopic.Main.buildDestination(group));
|
topicList.add(SimulationSubscribeTopic.Main.buildDestination(group));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ public class ConversationGroupVO {
|
|||||||
*/
|
*/
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 名称
|
* 名称
|
||||||
*/
|
*/
|
||||||
@ -36,6 +37,11 @@ public class ConversationGroupVO {
|
|||||||
*/
|
*/
|
||||||
private String projectCode;
|
private String projectCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 群头像地址
|
||||||
|
*/
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 群主角色ID
|
* 群主角色ID
|
||||||
*/
|
*/
|
||||||
@ -50,6 +56,7 @@ public class ConversationGroupVO {
|
|||||||
this.id = info.getId();
|
this.id = info.getId();
|
||||||
this.name = info.getName();
|
this.name = info.getName();
|
||||||
this.mapId = info.getMapId();
|
this.mapId = info.getMapId();
|
||||||
|
this.imageUrl = info.getImageUrl();
|
||||||
this.leaderId = info.getLeaderId();
|
this.leaderId = info.getLeaderId();
|
||||||
this.projectCode = info.getProjectCode();
|
this.projectCode = info.getProjectCode();
|
||||||
if (StringUtils.hasText(info.getMemberIds())) {
|
if (StringUtils.hasText(info.getMemberIds())) {
|
||||||
@ -67,6 +74,7 @@ public class ConversationGroupVO {
|
|||||||
info.setId(this.id);
|
info.setId(this.id);
|
||||||
info.setName(this.name);
|
info.setName(this.name);
|
||||||
info.setMapId(this.mapId);
|
info.setMapId(this.mapId);
|
||||||
|
info.setImageUrl(this.imageUrl);
|
||||||
info.setProjectCode(this.projectCode);
|
info.setProjectCode(this.projectCode);
|
||||||
info.setLeaderId(this.leaderId);
|
info.setLeaderId(this.leaderId);
|
||||||
if (this.memberIds != null) {
|
if (this.memberIds != null) {
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||||
<result column="map_ids" jdbcType="BIGINT" property="mapId" />
|
<result column="map_ids" jdbcType="BIGINT" property="mapId" />
|
||||||
<result column="project_code" jdbcType="VARCHAR" property="projectCode" />
|
<result column="project_code" jdbcType="VARCHAR" property="projectCode" />
|
||||||
|
<result column="image_url" jdbcType="VARCHAR" property="imageUrl" />
|
||||||
<result column="leader_id" jdbcType="VARCHAR" property="leaderId" />
|
<result column="leader_id" jdbcType="VARCHAR" property="leaderId" />
|
||||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||||
@ -78,7 +79,7 @@
|
|||||||
</where>
|
</where>
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<sql id="Base_Column_List"> id, name, map_id, project_code, create_time, update_time, creator_id, status, leader_id </sql>
|
<sql id="Base_Column_List"> id, name, map_id, image_url, project_code, create_time, update_time, creator_id, status, leader_id </sql>
|
||||||
|
|
||||||
<sql id="Blob_Column_List"> member_ids </sql>
|
<sql id="Blob_Column_List"> member_ids </sql>
|
||||||
|
|
||||||
@ -130,10 +131,10 @@
|
|||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<insert id="insert" parameterType="club.joylink.rtss.entity.conversation.RtsConversationGroupInfo">
|
<insert id="insert" parameterType="club.joylink.rtss.entity.conversation.RtsConversationGroupInfo">
|
||||||
insert into rts_conversation_group_info (id, name, map_id, project_code, create_time, update_time, creator_id, status, member_ids, leader_id )
|
insert into rts_conversation_group_info (id, name, map_id, project_code, image_url, create_time, update_time, creator_id, status, member_ids, leader_id )
|
||||||
values (
|
values (
|
||||||
#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{mapId,jdbcType=BIGINT},
|
#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{mapId,jdbcType=BIGINT}, #{projectCode,jdbcType=VARCHAR},
|
||||||
#{projectCode,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
|
#{imageUrl,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
|
||||||
#{creatorId,jdbcType=BIGINT}, #{status,jdbcType=INTEGER}, #{memberIds,jdbcType=LONGVARCHAR},
|
#{creatorId,jdbcType=BIGINT}, #{status,jdbcType=INTEGER}, #{memberIds,jdbcType=LONGVARCHAR},
|
||||||
#{leaderId,jdbcType=VARCHAR}
|
#{leaderId,jdbcType=VARCHAR}
|
||||||
)
|
)
|
||||||
@ -172,6 +173,9 @@
|
|||||||
<if test="leaderId != null">
|
<if test="leaderId != null">
|
||||||
leader_id,
|
leader_id,
|
||||||
</if>
|
</if>
|
||||||
|
<if test="imageUrl != null">
|
||||||
|
image_url,
|
||||||
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="id != null">
|
<if test="id != null">
|
||||||
@ -204,6 +208,9 @@
|
|||||||
<if test="leaderId != null">
|
<if test="leaderId != null">
|
||||||
#{leaderId,jdbcType=VARCHAR},
|
#{leaderId,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
|
<if test="imageUrl != null">
|
||||||
|
#{imageUrl,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
@ -240,6 +247,9 @@
|
|||||||
<if test="record.leaderId != null">
|
<if test="record.leaderId != null">
|
||||||
leader_id = #{record.leaderId,jdbcType=VARCHAR},
|
leader_id = #{record.leaderId,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
|
<if test="record.imageUrl != null">
|
||||||
|
image_url = #{record.imageUrl,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
</set>
|
</set>
|
||||||
<if test="_parameter != null">
|
<if test="_parameter != null">
|
||||||
<include refid="Update_By_Example_Where_Clause" />
|
<include refid="Update_By_Example_Where_Clause" />
|
||||||
@ -257,7 +267,8 @@
|
|||||||
creator_id = #{record.creatorId,jdbcType=BIGINT},
|
creator_id = #{record.creatorId,jdbcType=BIGINT},
|
||||||
status = #{record.status,jdbcType=INTEGER},
|
status = #{record.status,jdbcType=INTEGER},
|
||||||
member_ids = #{record.memberIds,jdbcType=LONGVARCHAR},
|
member_ids = #{record.memberIds,jdbcType=LONGVARCHAR},
|
||||||
leader_id = #{record.leaderId,jdbcType=VARCHAR}
|
leader_id = #{record.leaderId,jdbcType=VARCHAR},
|
||||||
|
image_url = #{record.imageUrl,jdbcType=VARCHAR}
|
||||||
<if test="_parameter != null">
|
<if test="_parameter != null">
|
||||||
<include refid="Update_By_Example_Where_Clause" />
|
<include refid="Update_By_Example_Where_Clause" />
|
||||||
</if>
|
</if>
|
||||||
@ -273,7 +284,8 @@
|
|||||||
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
|
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
|
||||||
creator_id = #{record.creatorId,jdbcType=BIGINT},
|
creator_id = #{record.creatorId,jdbcType=BIGINT},
|
||||||
status = #{record.status,jdbcType=INTEGER},
|
status = #{record.status,jdbcType=INTEGER},
|
||||||
leader_id = #{record.leaderId,jdbcType=VARCHAR}
|
leader_id = #{record.leaderId,jdbcType=VARCHAR},
|
||||||
|
image_url = #{record.imageUrl,jdbcType=VARCHAR}
|
||||||
<if test="_parameter != null">
|
<if test="_parameter != null">
|
||||||
<include refid="Update_By_Example_Where_Clause" />
|
<include refid="Update_By_Example_Where_Clause" />
|
||||||
</if>
|
</if>
|
||||||
@ -309,6 +321,9 @@
|
|||||||
<if test="leaderId != null">
|
<if test="leaderId != null">
|
||||||
leader_id = #{leaderId,jdbcType=VARCHAR},
|
leader_id = #{leaderId,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
|
<if test="imageUrl != null">
|
||||||
|
image_url = #{imageUrl,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
</set>
|
</set>
|
||||||
where id = #{id,jdbcType=BIGINT}
|
where id = #{id,jdbcType=BIGINT}
|
||||||
</update>
|
</update>
|
||||||
@ -319,7 +334,7 @@
|
|||||||
project_code = #{projectCode,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=TIMESTAMP},
|
project_code = #{projectCode,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=TIMESTAMP},
|
||||||
update_time = #{updateTime,jdbcType=TIMESTAMP}, creator_id = #{creatorId,jdbcType=BIGINT},
|
update_time = #{updateTime,jdbcType=TIMESTAMP}, creator_id = #{creatorId,jdbcType=BIGINT},
|
||||||
status = #{status,jdbcType=INTEGER}, member_ids = #{memberIds,jdbcType=LONGVARCHAR},
|
status = #{status,jdbcType=INTEGER}, member_ids = #{memberIds,jdbcType=LONGVARCHAR},
|
||||||
leader_id = #{leaderId,jdbcType=VARCHAR}
|
leader_id = #{leaderId,jdbcType=VARCHAR}, image_url = #{imageUrl,jdbcType=VARCHAR}
|
||||||
where id = #{id,jdbcType=BIGINT}
|
where id = #{id,jdbcType=BIGINT}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
@ -327,7 +342,8 @@
|
|||||||
update rts_conversation_group_info
|
update rts_conversation_group_info
|
||||||
set name = #{name,jdbcType=VARCHAR}, map_id = #{mapId,jdbcType=BIGINT}, project_code = #{projectCode,jdbcType=VARCHAR},
|
set name = #{name,jdbcType=VARCHAR}, map_id = #{mapId,jdbcType=BIGINT}, project_code = #{projectCode,jdbcType=VARCHAR},
|
||||||
create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
|
create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
|
||||||
creator_id = #{creatorId,jdbcType=BIGINT}, status = #{status,jdbcType=INTEGER},leader_id = #{leaderId,jdbcType=VARCHAR}
|
creator_id = #{creatorId,jdbcType=BIGINT}, status = #{status,jdbcType=INTEGER},leader_id = #{leaderId,jdbcType=VARCHAR},
|
||||||
|
image_url = #{imageUrl,jdbcType=VARCHAR}
|
||||||
where id = #{id,jdbcType=BIGINT}
|
where id = #{id,jdbcType=BIGINT}
|
||||||
</update>
|
</update>
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue
Block a user