chore: initialize qiming workspace repository
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.xspaceagi</groupId>
|
||||
<artifactId>app-platform-im</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>app-platform-im-domain</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.xspaceagi</groupId>
|
||||
<artifactId>app-platform-im-infra</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.xspaceagi.im.domain.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.im.infra.dao.enitity.ImChannelConfig;
|
||||
|
||||
public interface ImChannelConfigRepository extends IService<ImChannelConfig> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.xspaceagi.im.domain.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.im.infra.dao.enitity.ImSession;
|
||||
|
||||
public interface ImSessionRepository extends IService<ImSession> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.xspaceagi.im.domain.repository.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.im.domain.repository.ImChannelConfigRepository;
|
||||
import com.xspaceagi.im.infra.dao.enitity.ImChannelConfig;
|
||||
import com.xspaceagi.im.infra.dao.mapper.ImChannelConfigMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class ImChannelConfigRepositoryImpl
|
||||
extends ServiceImpl<ImChannelConfigMapper, ImChannelConfig>
|
||||
implements ImChannelConfigRepository {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.xspaceagi.im.domain.repository.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.im.domain.repository.ImSessionRepository;
|
||||
import com.xspaceagi.im.infra.dao.enitity.ImSession;
|
||||
import com.xspaceagi.im.infra.dao.mapper.ImSessionMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class ImSessionRepositoryImpl extends ServiceImpl<ImSessionMapper, ImSession> implements ImSessionRepository {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.xspaceagi.im.domain.service;
|
||||
|
||||
import com.xspaceagi.im.infra.dao.enitity.ImChannelConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ImChannelConfigDomainService {
|
||||
|
||||
ImChannelConfig findOne(String channel, String targetType, String imTargetId);
|
||||
|
||||
/**
|
||||
* 按渠道+目标类型+targetId 查找(不限制 enabled),用于同一 iLink 账号重复扫码刷新 token
|
||||
*/
|
||||
ImChannelConfig findOneIgnoreEnabled(String channel, String targetType, String imTargetId);
|
||||
|
||||
/**
|
||||
* 新增配置
|
||||
*/
|
||||
ImChannelConfig add(ImChannelConfig config);
|
||||
|
||||
/**
|
||||
* 查询配置列表
|
||||
*/
|
||||
List<ImChannelConfig> list(ImChannelConfig query);
|
||||
|
||||
/**
|
||||
* 分页查询配置列表
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @param offset 偏移量
|
||||
* @param limit 限制数量
|
||||
* @return 配置列表
|
||||
*/
|
||||
List<ImChannelConfig> listByPage(ImChannelConfig query, int offset, int limit);
|
||||
|
||||
/**
|
||||
* 根据 ID 查询配置
|
||||
*/
|
||||
ImChannelConfig getById(Long id);
|
||||
|
||||
/**
|
||||
* 根据 ID 更新配置
|
||||
*/
|
||||
ImChannelConfig updateById(ImChannelConfig config);
|
||||
|
||||
/**
|
||||
* 启用/禁用配置
|
||||
*/
|
||||
boolean updateEnabled(ImChannelConfig config);
|
||||
|
||||
/**
|
||||
* 删除配置(逻辑删除)
|
||||
*
|
||||
* @param id 配置ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
boolean delete(Long id);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.xspaceagi.im.domain.service;
|
||||
|
||||
|
||||
import com.xspaceagi.im.infra.dao.enitity.ImSession;
|
||||
|
||||
public interface ImSessionDomainService {
|
||||
|
||||
ImSession findSession(ImSession imSession);
|
||||
|
||||
ImSession saveSession(ImSession imSession);
|
||||
|
||||
boolean deleteSession(ImSession imSession);
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package com.xspaceagi.im.domain.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xspaceagi.im.domain.repository.ImChannelConfigRepository;
|
||||
import com.xspaceagi.im.domain.service.ImChannelConfigDomainService;
|
||||
import com.xspaceagi.im.infra.dao.enitity.ImChannelConfig;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ImChannelConfigDomainServiceImpl implements ImChannelConfigDomainService {
|
||||
|
||||
@Resource
|
||||
private ImChannelConfigRepository imChannelConfigRepository;
|
||||
|
||||
@Override
|
||||
public ImChannelConfig findOne(String channel, String targetType, String imTargetId) {
|
||||
Assert.hasText(channel, "platform不能为空");
|
||||
Assert.hasText(targetType, "targetType不能为空");
|
||||
Assert.hasText(imTargetId, "imTargetId不能为空");
|
||||
|
||||
LambdaQueryWrapper<ImChannelConfig> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImChannelConfig::getChannel, channel)
|
||||
.eq(ImChannelConfig::getTargetType, targetType)
|
||||
.eq(ImChannelConfig::getTargetId, imTargetId)
|
||||
.eq(ImChannelConfig::getYn, 1)
|
||||
.eq(ImChannelConfig::getEnabled, true);
|
||||
return imChannelConfigRepository.getOne(wrapper, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImChannelConfig findOneIgnoreEnabled(String channel, String targetType, String imTargetId) {
|
||||
Assert.hasText(channel, "platform不能为空");
|
||||
Assert.hasText(targetType, "targetType不能为空");
|
||||
Assert.hasText(imTargetId, "imTargetId不能为空");
|
||||
|
||||
LambdaQueryWrapper<ImChannelConfig> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImChannelConfig::getChannel, channel)
|
||||
.eq(ImChannelConfig::getTargetType, targetType)
|
||||
.eq(ImChannelConfig::getTargetId, imTargetId)
|
||||
.eq(ImChannelConfig::getYn, 1);
|
||||
return imChannelConfigRepository.getOne(wrapper, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImChannelConfig add(ImChannelConfig config) {
|
||||
checkParams(config);
|
||||
|
||||
// 检查是否已存在相同配置
|
||||
ImChannelConfig existing = findOne(
|
||||
config.getChannel(),
|
||||
config.getTargetType(),
|
||||
config.getTargetId()
|
||||
);
|
||||
|
||||
if (existing != null) {
|
||||
throw new IllegalArgumentException("Channel configuration already exists; duplicate add is not allowed");
|
||||
}
|
||||
|
||||
imChannelConfigRepository.save(config);
|
||||
return config;
|
||||
}
|
||||
|
||||
private void checkParams(ImChannelConfig config) {
|
||||
Assert.notNull(config, "ImChannelConfig不能为空");
|
||||
Assert.notNull(config.getTenantId(), "_tenant_id不能为空");
|
||||
Assert.notNull(config.getSpaceId(), "spaceId不能为空");
|
||||
Assert.hasText(config.getChannel(), "channel不能为空");
|
||||
Assert.hasText(config.getTargetType(), "targetType不能为空");
|
||||
Assert.hasText(config.getTargetId(), "targetId不能为空");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImChannelConfig> list(ImChannelConfig query) {
|
||||
LambdaQueryWrapper<ImChannelConfig> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImChannelConfig::getYn, 1);
|
||||
|
||||
if (query != null) {
|
||||
if (StringUtils.isNotBlank(query.getChannel())) {
|
||||
wrapper.eq(ImChannelConfig::getChannel, query.getChannel());
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getTargetType())) {
|
||||
wrapper.eq(ImChannelConfig::getTargetType, query.getTargetType());
|
||||
}
|
||||
if (query.getAgentId() != null) {
|
||||
wrapper.eq(ImChannelConfig::getAgentId, query.getAgentId());
|
||||
}
|
||||
if (query.getUserId() != null) {
|
||||
wrapper.eq(ImChannelConfig::getUserId, query.getUserId());
|
||||
}
|
||||
if (query.getEnabled() != null) {
|
||||
wrapper.eq(ImChannelConfig::getEnabled, query.getEnabled());
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getName())) {
|
||||
wrapper.like(ImChannelConfig::getName, query.getName());
|
||||
}
|
||||
if (query.getId() != null) {
|
||||
wrapper.eq(ImChannelConfig::getId, query.getId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getTargetId())) {
|
||||
wrapper.eq(ImChannelConfig::getTargetId, query.getTargetId());
|
||||
}
|
||||
if (query.getSpaceId() != null) {
|
||||
wrapper.eq(ImChannelConfig::getSpaceId, query.getSpaceId());
|
||||
}
|
||||
if (query.getTenantId() != null) {
|
||||
wrapper.eq(ImChannelConfig::getTenantId, query.getTenantId());
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.orderByDesc(ImChannelConfig::getModified);
|
||||
return imChannelConfigRepository.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImChannelConfig> listByPage(ImChannelConfig query, int offset, int limit) {
|
||||
LambdaQueryWrapper<ImChannelConfig> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImChannelConfig::getYn, 1);
|
||||
|
||||
if (query != null) {
|
||||
if (StringUtils.isNotBlank(query.getChannel())) {
|
||||
wrapper.eq(ImChannelConfig::getChannel, query.getChannel());
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getTargetType())) {
|
||||
wrapper.eq(ImChannelConfig::getTargetType, query.getTargetType());
|
||||
}
|
||||
if (query.getAgentId() != null) {
|
||||
wrapper.eq(ImChannelConfig::getAgentId, query.getAgentId());
|
||||
}
|
||||
if (query.getUserId() != null) {
|
||||
wrapper.eq(ImChannelConfig::getUserId, query.getUserId());
|
||||
}
|
||||
if (query.getEnabled() != null) {
|
||||
wrapper.eq(ImChannelConfig::getEnabled, query.getEnabled());
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getName())) {
|
||||
wrapper.like(ImChannelConfig::getName, query.getName());
|
||||
}
|
||||
if (query.getId() != null) {
|
||||
wrapper.eq(ImChannelConfig::getId, query.getId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getTargetId())) {
|
||||
wrapper.eq(ImChannelConfig::getTargetId, query.getTargetId());
|
||||
}
|
||||
if (query.getSpaceId() != null) {
|
||||
wrapper.eq(ImChannelConfig::getSpaceId, query.getSpaceId());
|
||||
}
|
||||
if (query.getTenantId() != null) {
|
||||
wrapper.eq(ImChannelConfig::getTenantId, query.getTenantId());
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.orderByDesc(ImChannelConfig::getModified);
|
||||
// 添加分页
|
||||
wrapper.last("LIMIT " + limit + " OFFSET " + offset);
|
||||
return imChannelConfigRepository.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImChannelConfig getById(Long id) {
|
||||
Assert.notNull(id, "id不能为空");
|
||||
LambdaQueryWrapper<ImChannelConfig> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImChannelConfig::getId, id)
|
||||
.eq(ImChannelConfig::getYn, 1);
|
||||
return imChannelConfigRepository.getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImChannelConfig updateById(ImChannelConfig config) {
|
||||
Assert.notNull(config, "config不能为空");
|
||||
Assert.notNull(config.getId(), "id不能为空");
|
||||
imChannelConfigRepository.updateById(config);
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateEnabled(ImChannelConfig config) {
|
||||
Assert.notNull(config.getId(), "id不能为空");
|
||||
Assert.notNull(config.getEnabled(), "enabled不能为空");
|
||||
return imChannelConfigRepository.updateById(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Long id) {
|
||||
Assert.notNull(id, "id不能为空");
|
||||
return imChannelConfigRepository.removeById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.xspaceagi.im.domain.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xspaceagi.im.domain.repository.ImSessionRepository;
|
||||
import com.xspaceagi.im.domain.service.ImSessionDomainService;
|
||||
import com.xspaceagi.im.infra.dao.enitity.ImSession;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@Service
|
||||
public class ImSessesionDomainServiceImpl implements ImSessionDomainService {
|
||||
|
||||
@Resource
|
||||
private ImSessionRepository imSessionRepository;
|
||||
|
||||
@Override
|
||||
public ImSession findSession(ImSession imSession) {
|
||||
checkParams(imSession);
|
||||
|
||||
LambdaQueryWrapper<ImSession> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImSession::getChannel, imSession.getChannel())
|
||||
.eq(ImSession::getTargetType, imSession.getTargetType())
|
||||
.eq(ImSession::getSessionKey, imSession.getSessionKey())
|
||||
.eq(ImSession::getAgentId, imSession.getAgentId())
|
||||
.eq(ImSession::getTenantId, imSession.getTenantId());
|
||||
return imSessionRepository.getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImSession saveSession(ImSession imSession) {
|
||||
checkParams(imSession);
|
||||
|
||||
ImSession existing = findSession(imSession);
|
||||
|
||||
if (existing != null) {
|
||||
// 更新
|
||||
existing.setSessionName(imSession.getSessionName());
|
||||
existing.setChatType(imSession.getChatType());
|
||||
existing.setUserId(imSession.getUserId());
|
||||
existing.setConversationId(imSession.getConversationId());
|
||||
imSessionRepository.updateById(existing);
|
||||
return existing;
|
||||
} else {
|
||||
// 新增
|
||||
imSessionRepository.save(imSession);
|
||||
return imSession;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteSession(ImSession imSession) {
|
||||
checkParams(imSession);
|
||||
|
||||
LambdaQueryWrapper<ImSession> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImSession::getChannel, imSession.getChannel())
|
||||
.eq(ImSession::getTargetType, imSession.getTargetType())
|
||||
.eq(ImSession::getSessionKey, imSession.getSessionKey())
|
||||
.eq(ImSession::getAgentId, imSession.getAgentId())
|
||||
.eq(ImSession::getTenantId, imSession.getTenantId());
|
||||
return imSessionRepository.remove(wrapper);
|
||||
}
|
||||
|
||||
private void checkParams(ImSession imSession) {
|
||||
Assert.notNull(imSession, "imSession不能为空");
|
||||
Assert.notNull(imSession.getChannel(), "imSession.channel不能为空");
|
||||
Assert.notNull(imSession.getTargetType(), "imSession.targetType不能为空");
|
||||
Assert.notNull(imSession.getSessionKey(), "imSession.sessionKey不能为空");
|
||||
Assert.notNull(imSession.getAgentId(), "imSession.agentId不能为空");
|
||||
Assert.notNull(imSession.getTenantId(), "imSession.tenantId不能为空");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user