Compare commits

..

No commits in common. "c1a5340a73f77bd95284476d78da2b1d5a003af2" and "7984b7bc65f84d7de297492de7200b4ad58a3e74" have entirely different histories.

15 changed files with 35 additions and 246 deletions

View File

@ -447,8 +447,6 @@
}
await sendMessage(msg)
messages.success('转接成功')
conversation.value = null
} finally {
// todo
}

View File

@ -159,87 +159,24 @@
getRefreshToken() // 使 getRefreshToken() 使 getAccessToken() WebSocket 便访
) // WebSocket
let a = 0;
const {status, data, send, open, close} = useWebSocket(server.value, {
onConnected: function (ws) {
console.log('websocket 连接成功!', ws);
},
onDisconnected: function (ws, event) {
console.log('WebSocket 连接断开', event);
},
onError: function (ws, event) {
console.error('WebSocket 连接错误:', event);
if (event instanceof ErrorEvent) {
console.error('详细错误信息:', event.message);
} else {
console.error('非标准错误:', event);
const chick = ref('2')
const userInfo = async () =>{
chick.value = '1'
user.value = await UserApi.getUserInfo(userId.value)
}
},
onMessage: function (ws, event) {
console.log('收到的 WebSocket 消息:', event.data);
a = a + 1 ;
if(a == 2){
getConversationList()
keFuChatBoxRef.value?.refreshMessageList()
a = 0;
const zuoji = () =>{
chick.value = '2'
// keFuChatBoxRef.value?.getNewMessageList(conversations.value)
memberBrowsingHistoryRef.value?.initHistory(conversations.value)
}
//
// if (event.data) {
// let parsedData;
// //
// try {
// parsedData = JSON.parse(event.data);
// } catch (error) {
// console.error('JSON :', error, ':', event.data);
// return; //
// }
// // type
// const { type } = parsedData;
// if (!type) {
// console.warn(':', parsedData);
// return;
// }
// //
// switch (type) {
// case 'pong':
// //
// console.log(' ping ');
// // pong
// send(JSON.stringify({ type: 'pong' }));
// break;
// case 'chat':
// //
// console.log(':', parsedData.content);
// //
// break;
// case 'notification':
// //
// console.log(':', parsedData.message);
// //
// break;
// default:
// console.warn(':', type);
// break;
// }
// } else {
// console.warn(':', event);
// }
},
autoReconnect: false, //
/** 发起 WebSocket 连接 */
const {data, close, open} = useWebSocket(server.value, {
autoReconnect: false,
heartbeat: true
});
})
/** 监听 WebSocket 数据 */
watchEffect(() => {
@ -278,8 +215,6 @@
console.error(error)
}
})
// ======================= WebSocket end =======================
/** 加载会话列表 */
const keFuConversationRef = ref<InstanceType<typeof KeFuConversationList>>()
@ -303,31 +238,17 @@
// window.location.href = '/kefu/support-staff';
}
const chick = ref('2')
const userInfo = async () =>{
chick.value = '1'
user.value = await UserApi.getUserInfo(userId.value)
}
const zuoji = () =>{
chick.value = '2'
// keFuChatBoxRef.value?.getNewMessageList(conversations.value)
memberBrowsingHistoryRef.value?.initHistory(conversations.value)
}
/** 初始化 */
onMounted(() => {
getConversationList()
// websocket
open()
console.log('WebSocket 已初始化');
})
/** 销毁 */
onBeforeUnmount(() => {
// websocket
close()
console.log('WebSocket 已关闭');
})
</script>

View File

@ -29,6 +29,6 @@ public class WebSocketProperties {
* 可选值localredisrocketmqkafkarabbitmq
*/
@NotNull(message = "WebSocket 的消息发送者不能为空")
private String senderType = "redis";
private String senderType = "local";
}

View File

@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.mq.redis.core.RedisMQTemplate;
import cn.iocoder.yudao.framework.websocket.core.handler.JsonWebSocketMessageHandler;
import cn.iocoder.yudao.framework.websocket.core.listener.WebSocketMessageListener;
import cn.iocoder.yudao.framework.websocket.core.security.LoginUserHandshakeInterceptor;
import cn.iocoder.yudao.framework.websocket.core.security.WebSocketAuthorizeRequestsCustomizer;
import cn.iocoder.yudao.framework.websocket.core.sender.kafka.KafkaWebSocketMessageConsumer;
import cn.iocoder.yudao.framework.websocket.core.sender.kafka.KafkaWebSocketMessageSender;
import cn.iocoder.yudao.framework.websocket.core.sender.local.LocalWebSocketMessageSender;
@ -77,15 +76,10 @@ public class YudaoWebSocketAutoConfiguration {
return new WebSocketSessionManagerImpl();
}
@Bean
public WebSocketAuthorizeRequestsCustomizer webSocketAuthorizeRequestsCustomizer(WebSocketProperties webSocketProperties) {
return new WebSocketAuthorizeRequestsCustomizer(webSocketProperties);
}
// ==================== Sender 相关 ====================
@Configuration
@ConditionalOnProperty(prefix = "yudao.websocket", name = "sender-type", havingValue = "local")
@ConditionalOnProperty(prefix = "yudao.websocket", name = "sender-type", havingValue = "local", matchIfMissing = true)
public class LocalWebSocketMessageSenderConfiguration {
@Bean
@ -96,7 +90,7 @@ public class YudaoWebSocketAutoConfiguration {
}
@Configuration
@ConditionalOnProperty(prefix = "yudao.websocket", name = "sender-type", havingValue = "redis")
@ConditionalOnProperty(prefix = "yudao.websocket", name = "sender-type", havingValue = "redis", matchIfMissing = true)
public class RedisWebSocketMessageSenderConfiguration {
@Bean
@ -114,7 +108,7 @@ public class YudaoWebSocketAutoConfiguration {
}
@Configuration
@ConditionalOnProperty(prefix = "yudao.websocket", name = "sender-type", havingValue = "rocketmq")
@ConditionalOnProperty(prefix = "yudao.websocket", name = "sender-type", havingValue = "rocketmq", matchIfMissing = true)
public class RocketMQWebSocketMessageSenderConfiguration {
@Bean
@ -133,7 +127,7 @@ public class YudaoWebSocketAutoConfiguration {
}
@Configuration
@ConditionalOnProperty(prefix = "yudao.websocket", name = "sender-type", havingValue = "rabbitmq")
@ConditionalOnProperty(prefix = "yudao.websocket", name = "sender-type", havingValue = "rabbitmq", matchIfMissing = true)
public class RabbitMQWebSocketMessageSenderConfiguration {
@Bean
@ -162,7 +156,7 @@ public class YudaoWebSocketAutoConfiguration {
}
@Configuration
@ConditionalOnProperty(prefix = "yudao.websocket", name = "sender-type", havingValue = "kafka")
@ConditionalOnProperty(prefix = "yudao.websocket", name = "sender-type", havingValue = "kafka", matchIfMissing = true)
public class KafkaWebSocketMessageSenderConfiguration {
@Bean

View File

@ -43,7 +43,7 @@ public interface WebSocketSenderApi {
send(userType, userId, messageType, JsonUtils.toJsonString(messageContent));
}
default void sendObject(Integer userType, String messageType, Object messageContent) { //用户发送消息
default void sendObject(Integer userType, String messageType, Object messageContent) {
send(userType, messageType, JsonUtils.toJsonString(messageContent));
}

View File

@ -79,12 +79,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system-biz</artifactId>
<version>2.1.0-jdk8-snapshot</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -28,8 +28,4 @@ public class AppDiyTemplatePropertyRespVO {
@JsonRawValue
private String user;
private String goodsType;
private String themeType;
}

View File

@ -61,11 +61,4 @@ public class DiyTemplateDO extends BaseDO {
*/
private String property;
@TableField(exist = false)
private String goodsType;
@TableField(exist = false)
private String themeType;
}

View File

@ -11,15 +11,12 @@ import cn.iocoder.yudao.module.promotion.convert.diy.DiyPageConvert;
import cn.iocoder.yudao.module.promotion.convert.diy.DiyTemplateConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.diy.DiyTemplateMapper;
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
@ -39,9 +36,6 @@ public class DiyTemplateServiceImpl implements DiyTemplateService {
@Resource
private DiyPageService diyPageService;
@Resource
private DictDataApi dictDataApi;
@Transactional(rollbackFor = Exception.class)
@Override
public Long createDiyTemplate(DiyTemplateCreateReqVO createReqVO) {
@ -171,17 +165,7 @@ public class DiyTemplateServiceImpl implements DiyTemplateService {
@Override
public DiyTemplateDO getUsedDiyTemplate() {
DiyTemplateDO diyTemplateDO = diyTemplateMapper.selectByUsed(true);
List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList("diy-template-theme");
DictDataRespDTO dictDataRespDTO = dictDataList.get(0);
diyTemplateDO.setThemeType(dictDataRespDTO.getValue());
List<DictDataRespDTO> dictDataList1 = dictDataApi.getDictDataList("diy-template-goods");
DictDataRespDTO dictDataRespDTO1 = dictDataList1.get(0);
diyTemplateDO.setGoodsType(dictDataRespDTO1.getValue());
return diyTemplateDO;
return diyTemplateMapper.selectByUsed(true);
}
}

View File

@ -31,8 +31,6 @@ public interface KeFuMessageService {
* @return 编号
*/
Long sendKefuMessage(AppKeFuMessageSendReqVO sendReqVO);
String sendKefuMessageTest(String s);
/**

View File

@ -9,7 +9,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessagePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageSendReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessagePageReqVO;
@ -17,10 +16,7 @@ import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuM
import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuConversationDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.kefu.KeFuMessageMapper;
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -55,12 +51,9 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
@Resource
private WebSocketSenderApi webSocketSenderApi;
@Resource
private NotifyMessageMapper notifyMessageMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public Long sendKefuMessage(KeFuMessageSendReqVO sendReqVO) { //客服发消息
public Long sendKefuMessage(KeFuMessageSendReqVO sendReqVO) {
// 1.1 校验会话是否存在
KeFuConversationDO conversation = conversationService.validateKefuConversationExists(sendReqVO.getConversationId());
// 1.2 校验接收人是否存在
@ -81,39 +74,20 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
}
@Override
public Long sendKefuMessage(AppKeFuMessageSendReqVO sendReqVO) { //用户发消息
public Long sendKefuMessage(AppKeFuMessageSendReqVO sendReqVO) {
// 1.1 设置会话编号
KeFuMessageDO kefuMessage = BeanUtils.toBean(sendReqVO, KeFuMessageDO.class);
KeFuConversationDO conversation = conversationService.getOrCreateConversation(sendReqVO.getSenderId());
kefuMessage.setConversationId(conversation.getId());
// 1.2 保存消息
kefuMessage.setReceiverId(conversation.getKefuId()).setReceiverType(UserTypeEnum.ADMIN.getValue()); // 设置接收人
keFuMessageMapper.insert(kefuMessage);
// 2. 更新会话消息冗余
conversationService.updateConversationLastMessage(kefuMessage);
getSelf().sendAsyncMessageToMembers(conversation.getKefuId(), KEFU_MESSAGE_TYPE, kefuMessage);
// 3. 通知所有管理员更新对话
getSelf().sendAsyncMessageToAdmins(KEFU_MESSAGE_TYPE, kefuMessage);
getSelf().sendAsyncMessageToAdmin(KEFU_MESSAGE_TYPE, kefuMessage);
return kefuMessage.getId();
}
//添加站内信
// MemberUserRespDTO user = memberUserApi.getUser(sendReqVO.getSenderId());
// NotifyMessageDO notifyMessageDO = new NotifyMessageDO()
// .setUserId(sendReqVO.getSenderId())
// .setUserType(sendReqVO.getSenderType())
// .setTemplateId((long)1)
// .setTemplateCode()
// .setTemplateNickname(user.getNickname())
// .setTemplateContent("客户发来消息")
// .setTemplateType(2)
// .setTemplateParams()
// .setReadStatus(2);
// notifyMessageMapper.insert(notifyMessageDO);
@Override
public String sendKefuMessageTest(String s){
webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), 1L, "1", s);;
@ -163,21 +137,11 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
webSocketSenderApi.sendObject(UserTypeEnum.MEMBER.getValue(), userId, messageType, content);
}
@Async
public void sendAsyncMessageToMembers(Long userId, String messageType, Object content) {
webSocketSenderApi.sendObject(UserTypeEnum.MEMBER.getValue(), userId, messageType, content);
}
@Async
public void sendAsyncMessageToAdmin(String messageType, Object content) {
webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), messageType, content);
}
@Async
public void sendAsyncMessageToAdmins(String messageType, Object content) {
webSocketSenderApi.sendObject(UserTypeEnum.MEMBER.getValue(), messageType, content);
}
@Override
public PageResult<KeFuMessageDO> getKeFuMessagePage(KeFuMessagePageReqVO pageReqVO) {
return keFuMessageMapper.selectPage(pageReqVO);

View File

@ -27,7 +27,4 @@ public interface NotifyMessageSendApi {
*/
Long sendSingleMessageToMember(@Valid NotifySendSingleToUserReqDTO reqDTO);
}

View File

@ -40,12 +40,10 @@ public class DictDataController {
@Resource
private DictDataService dictDataService;
@Resource
public DictDataApi dictDataApi;
@PostMapping("/create")
@Operation(summary = "新增字典数据")
@PreAuthorize("@ss.hasPermission('system:dict:create')")
@ -161,54 +159,6 @@ public class DictDataController {
}
/**
* 修改装修商品分类字典数据
*/
@GetMapping(value = "/diy-template-goods")
public CommonResult<String> setGoods(String id) {
List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList("diy-template-goods");
DictDataRespDTO dictDataRespDTO = dictDataList.get(0);
DictDataSaveReqVO dictDataSaveReqVO = BeanUtils.toBean(dictDataRespDTO, DictDataSaveReqVO.class);
dictDataSaveReqVO.setValue(id);
dictDataService.updateDictData(dictDataSaveReqVO);
return success(id);
}
/**
* 修改装修商品分类字典数据
*/
@GetMapping(value = "/getGoods")
public CommonResult<String> getGoods() {
List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList("diy-template-goods");
DictDataRespDTO dictDataRespDTO = dictDataList.get(0);
return success(dictDataRespDTO.getValue());
}
/**
* 修改装修装修风格字典数据
*/
@GetMapping(value = "/diy-template-theme")
public CommonResult<String> setTheme(String id) {
List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList("diy-template-theme");
DictDataRespDTO dictDataRespDTO = dictDataList.get(0);
DictDataSaveReqVO dictDataSaveReqVO = BeanUtils.toBean(dictDataRespDTO, DictDataSaveReqVO.class);
dictDataSaveReqVO.setValue(id);
dictDataService.updateDictData(dictDataSaveReqVO);
return success(id);
}
/**
* 修改装修装修风格字典数据
*/
@GetMapping(value = "/getTheme")
public CommonResult<String> getTheme() {
List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList("diy-template-theme");
DictDataRespDTO dictDataRespDTO = dictDataList.get(0);
return success(dictDataRespDTO.getValue());
}
}

View File

@ -210,7 +210,7 @@ yudao:
websocket:
enable: true # websocket的开关
path: /infra/ws # 路径
sender-type: redis # 消息发送的类型,可选值为 local、redis、rocketmq、kafka、rabbitmq
sender-type: local # 消息发送的类型,可选值为 local、redis、rocketmq、kafka、rabbitmq
sender-rocketmq:
topic: ${spring.application.name}-websocket # 消息发送的 RocketMQ Topic
consumer-group: ${spring.application.name}-websocket-consumer # 消息发送的 RocketMQ Consumer Group