Commit 2bac498a authored by shiyu's avatar shiyu

聊天记录

parent c955233a
...@@ -125,6 +125,7 @@ ...@@ -125,6 +125,7 @@
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -114,6 +114,9 @@ public class ShiroConfig { ...@@ -114,6 +114,9 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/admin/item/synToEs", "anon"); filterChainDefinitionMap.put("/admin/item/synToEs", "anon");
filterChainDefinitionMap.put("/admin/category/copy", "anon"); filterChainDefinitionMap.put("/admin/category/copy", "anon");
filterChainDefinitionMap.put("/admin/sysIM/**", "anon");
filterChainDefinitionMap.put("/admin/sysAiAssistant/**", "anon");
filterChainDefinitionMap.put("/admin/sysIMRecord/**", "anon");
filterChainDefinitionMap.put("/admin/invitationCode/**", "anon"); filterChainDefinitionMap.put("/admin/invitationCode/**", "anon");
// filterChainDefinitionMap.put("/admin/**", "anon"); // filterChainDefinitionMap.put("/admin/**", "anon");
......
...@@ -6,6 +6,9 @@ import com.wwdz.ch.core.consts.ResultCode; ...@@ -6,6 +6,9 @@ import com.wwdz.ch.core.consts.ResultCode;
import com.wwdz.ch.core.entity.im.IMChatRequestDto; import com.wwdz.ch.core.entity.im.IMChatRequestDto;
import com.wwdz.ch.core.entity.im.SendChatMsgRequestDto; import com.wwdz.ch.core.entity.im.SendChatMsgRequestDto;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dto.request.ConversationRequestDto;
import com.wwdz.ch.db.dto.request.ImRecordRequestDto;
import com.wwdz.ch.db.dto.request.UserRequestDto;
import com.xxdxxs.utils.StringUtils; import com.xxdxxs.utils.StringUtils;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -50,4 +53,24 @@ public class SysIMController { ...@@ -50,4 +53,24 @@ public class SysIMController {
return sysIMService.getUserSig(dto); return sysIMService.getUserSig(dto);
} }
@ApiOperation(value = "查询对话用户的信息")
@PostMapping("/findChatUserInfo")
public Result findChatUserInfo(@RequestBody ConversationRequestDto dto) {
logger.info("【请求开始】查询对话用户的信息,请求参数:{}", JSON.toJSONString(dto));
if (StringUtils.isEmpty(dto.getFromAccount()) || StringUtils.isEmpty(dto.getToAccount())) {
return Result.failed(ResultCode.PARAM_ERROR);
}
return sysIMService.findChatUserInfo(dto);
}
@ApiOperation(value = "设置用户备注")
@PostMapping("/setChatUserRemark")
public Result setChatUserRemark(@RequestBody UserRequestDto dto) {
logger.info("【请求开始】设置用户备注,请求参数:{}", JSON.toJSONString(dto));
if (StringUtils.isEmpty(dto.getUserId())) {
return Result.failed(ResultCode.PARAM_ERROR);
}
return sysIMService.setChatUserRemark(dto);
}
} }
package com.wwdz.ch.admin.controller;
import com.alibaba.fastjson.JSON;
import com.wwdz.ch.admin.service.SysIMRecordService;
import com.wwdz.ch.admin.service.SysIMService;
import com.wwdz.ch.core.consts.ResultCode;
import com.wwdz.ch.core.entity.im.IMChatRequestDto;
import com.wwdz.ch.core.entity.im.SendChatMsgRequestDto;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dto.request.ConversationRequestDto;
import com.wwdz.ch.db.dto.request.ImRecordRequestDto;
import com.wwdz.ch.db.dto.request.UserRequestDto;
import com.xxdxxs.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 后台管理人工介入ai会话
*/
@RestController
@RequestMapping("/admin/sysIMRecord")
public class SysIMRecordController {
private static final Logger logger = LoggerFactory.getLogger(SysIMRecordController.class);
@Autowired
SysIMRecordService sysIMRecordService;
@ApiOperation(value = "查询ai会话列表")
@PostMapping("/findAiChatList")
public Result findAiChatList(@RequestBody ConversationRequestDto dto) {
logger.info("【请求开始】查询ai会话列表,请求参数:{}", JSON.toJSONString(dto));
return sysIMRecordService.findAiChatList(dto);
}
@ApiOperation(value = "查询ai会话聊天记录")
@PostMapping("/findHistoryRecord")
public Result findHistoryRecord(@RequestBody ImRecordRequestDto dto) {
logger.info("【请求开始】查询ai会话聊天记录,请求参数:{}", JSON.toJSONString(dto));
return sysIMRecordService.findHistoryRecord(dto);
}
}
package com.wwdz.ch.admin.entity.vo;
import com.xxdxxs.entity.Entity;
import lombok.Data;
import java.util.Date;
@Data
public class ConversationVo implements Entity {
/**
* 消息发送账户
*/
private String fromAccount;
private String fromAccountName;
/**
* 消息接收账户
*/
private String toAccount;
private String toAccountName;
private Long msgNum;
/**
* 创建时间
*/
private Date createTime;
}
package com.wwdz.ch.admin.entity.vo;
import com.xxdxxs.entity.Entity;
import lombok.Data;
import java.util.Date;
@Data
public class IMRecordVo implements Entity {
/**
* 发送者
*/
private String fromAccount;
private String fromAccountIcon;
/**
* 接收者
*/
private String toAccount;
/**
* 头像
*/
private String toAccountIcon;
/**
* 消息的唯一标识
*/
private String msgKey;
/**
* 消息发送时间
*/
private Date msgTime;
/**
* 消息下发结果
*/
private Integer sendMsgResult;
/**
* 消息类型
*/
private Integer msgType;
/**
* 消息内容
*/
private String msgContent;
/**
* 自定义消息数据
*/
private String cloudCustomData;
/**
* 是否人工代介入
*/
private Boolean isRealPerson = false;
}
package com.wwdz.ch.admin.impl;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.admin.entity.vo.ConversationVo;
import com.wwdz.ch.admin.entity.vo.IMRecordVo;
import com.wwdz.ch.admin.service.SysIMRecordService;
import com.wwdz.ch.core.type.PageSearchResult;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.CacheUtil;
import com.wwdz.ch.db.dao.ConversationDao;
import com.wwdz.ch.db.dao.ImRecordDao;
import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.domain.Conversation;
import com.wwdz.ch.db.domain.ImRecord;
import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.dto.request.ConversationRequestDto;
import com.wwdz.ch.db.dto.request.ImRecordRequestDto;
import com.xxdxxs.entity.Entity;
import com.xxdxxs.utils.EntityMapper;
import com.xxdxxs.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class SysIMRecordServiceImpl implements SysIMRecordService {
private static final Logger logger = LoggerFactory.getLogger(SysIMRecordServiceImpl.class);
@Autowired
ConversationDao conversationDao;
@Autowired
UserDao userDao;
@Autowired
CacheUtil cacheUtil;
@Autowired
ImRecordDao imRecordDao;
@Override
public Result findAiChatList(ConversationRequestDto dto) {
try {
if (StringUtils.hasLength(dto.getFromAccountName())) {
//根据用户名称查询id
List<User> userList = userDao.findByNickName(dto.getFromAccountName());
List<Long> fromAccountIdList = userList.stream().map(User::getId).collect(Collectors.toList());
List<String> fromAccountList = fromAccountIdList.stream().map(String::valueOf).collect(Collectors.toList());
dto.setFromAccountList(fromAccountList);
}
List<Conversation> list = conversationDao.findList(dto);
PageInfo<Conversation> pageInfo = new PageInfo<>(list);
List<ConversationVo> conversationVos = new ArrayList<>();
list.forEach(conversation -> {
ConversationVo conversationVo = new ConversationVo();
EntityMapper.copyAttribute(conversation, conversationVo);
conversationVo.setFromAccountName(cacheUtil.getAppletUserNameById(Long.valueOf(conversation.getFromAccount())));
conversationVo.setToAccountName(cacheUtil.getAiNameByCode(conversation.getToAccount()));
ImRecordRequestDto imRecordRequestDto = new ImRecordRequestDto();
imRecordRequestDto.setFromAccount(conversation.getFromAccount());
imRecordRequestDto.setToAccount(conversation.getToAccount());
long num = imRecordDao.count(imRecordRequestDto);
conversationVo.setMsgNum(num);
conversationVos.add(conversationVo);
});
return Result.success(PageSearchResult.of(pageInfo, conversationVos));
} catch (Exception e) {
logger.error("查询ai对话列表error:{}", e);
}
return Result.failed();
}
@Override
public Result findHistoryRecord(ImRecordRequestDto dto) {
try {
List<ImRecord> list = imRecordDao.find(dto);
PageInfo<ImRecord> pageInfo = new PageInfo<>(list);
List<IMRecordVo> imRecordVos = new ArrayList<>();
list.forEach(imRecord -> {
IMRecordVo imRecordVo = new IMRecordVo();
EntityMapper.copyAttribute(imRecord, imRecordVo);
if (imRecord.getFromAccount().contains("ai")) {
imRecordVo.setFromAccountIcon(cacheUtil.getAiAssistantByCode(imRecord.getFromAccount()).getAvatar());
imRecordVo.setToAccountIcon(cacheUtil.getAppletUserById(Long.valueOf(imRecord.getToAccount())).getAvatar());
} else if (imRecord.getToAccount().contains("ai")) {
imRecordVo.setFromAccountIcon(cacheUtil.getAppletUserById(Long.valueOf(imRecord.getFromAccount())).getAvatar());
imRecordVo.setToAccountIcon(cacheUtil.getAiAssistantByCode(imRecord.getToAccount()).getAvatar());
}
if (StringUtils.hasLength(imRecord.getCloudCustomData())){
imRecordVo.setIsRealPerson(true);
}
imRecordVos.add(imRecordVo);
});
return Result.success(PageSearchResult.of(pageInfo, imRecordVos));
} catch (Exception e) {
logger.error("查询ai会话聊天记录 error:{}", e);
}
return Result.failed();
}
}
...@@ -7,12 +7,18 @@ import com.wwdz.ch.core.im.api.ConversationApi; ...@@ -7,12 +7,18 @@ import com.wwdz.ch.core.im.api.ConversationApi;
import com.wwdz.ch.core.im.api.TLSSigApi; import com.wwdz.ch.core.im.api.TLSSigApi;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.IMUtil; import com.wwdz.ch.core.util.IMUtil;
import com.wwdz.ch.db.dao.AiAssistantDao;
import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.domain.AiAssistant;
import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.dto.request.ConversationRequestDto;
import com.wwdz.ch.db.dto.request.ImRecordRequestDto;
import com.wwdz.ch.db.dto.request.UserRequestDto;
import com.xxdxxs.utils.JsonUtils; import com.xxdxxs.utils.JsonUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -31,6 +37,12 @@ public class SysIMServiceImpl implements SysIMService { ...@@ -31,6 +37,12 @@ public class SysIMServiceImpl implements SysIMService {
@Autowired @Autowired
IMUtil imUtil; IMUtil imUtil;
@Autowired
UserDao userDao;
@Autowired
AiAssistantDao aiAssistantDao;
@Override @Override
public Result sendChatMsg(SendChatMsgRequestDto dto) { public Result sendChatMsg(SendChatMsgRequestDto dto) {
try { try {
...@@ -49,7 +61,7 @@ public class SysIMServiceImpl implements SysIMService { ...@@ -49,7 +61,7 @@ public class SysIMServiceImpl implements SysIMService {
@Override @Override
public Result getUserSig(IMChatRequestDto dto) { public Result getUserSig(IMChatRequestDto dto) {
try { try {
String userSig = tlsSigApi.getUserSig(imUtil.formatUserId(String.valueOf(dto.getUserId()))); String userSig = tlsSigApi.getUserSig(imUtil.formatUserId(dto.getUserId()));
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("userSig", userSig); map.put("userSig", userSig);
logger.info(">>>>>>>>>>>>> 获取用户签名 userId:{}, userSig:{} <<<<<<<<<<<<<", dto.getUserId(), userSig); logger.info(">>>>>>>>>>>>> 获取用户签名 userId:{}, userSig:{} <<<<<<<<<<<<<", dto.getUserId(), userSig);
...@@ -60,4 +72,31 @@ public class SysIMServiceImpl implements SysIMService { ...@@ -60,4 +72,31 @@ public class SysIMServiceImpl implements SysIMService {
return Result.failed(); return Result.failed();
} }
@Override
public Result findChatUserInfo(ConversationRequestDto dto) {
try {
User user = userDao.queryById(Long.valueOf(dto.getFromAccount()));
AiAssistant aiAssistant = aiAssistantDao.findByCode(dto.getToAccount());
Map<String, Object> map = new HashMap<>();
map.put("user", user);
map.put("aiAssistant", aiAssistant);
return Result.success(map);
} catch (Exception e) {
logger.error("获取用户信息失败:{}", e);
}
return Result.failed();
}
@Override
public Result setChatUserRemark(UserRequestDto dto) {
try {
User user = new User();
user.setId(dto.getUserId());
userDao.updateById(user);
return Result.success(user);
} catch (Exception e) {
logger.error("获取用户信息失败:{}", e);
}
return Result.failed();
}
} }
package com.wwdz.ch.admin.service;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dto.request.ConversationRequestDto;
import com.wwdz.ch.db.dto.request.ImRecordRequestDto;
public interface SysIMRecordService {
Result findAiChatList(ConversationRequestDto dto);
Result findHistoryRecord(ImRecordRequestDto dto);
}
...@@ -3,6 +3,9 @@ package com.wwdz.ch.admin.service; ...@@ -3,6 +3,9 @@ package com.wwdz.ch.admin.service;
import com.wwdz.ch.core.entity.im.IMChatRequestDto; import com.wwdz.ch.core.entity.im.IMChatRequestDto;
import com.wwdz.ch.core.entity.im.SendChatMsgRequestDto; import com.wwdz.ch.core.entity.im.SendChatMsgRequestDto;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dto.request.ConversationRequestDto;
import com.wwdz.ch.db.dto.request.ImRecordRequestDto;
import com.wwdz.ch.db.dto.request.UserRequestDto;
public interface SysIMService { public interface SysIMService {
...@@ -20,4 +23,19 @@ public interface SysIMService { ...@@ -20,4 +23,19 @@ public interface SysIMService {
* @return * @return
*/ */
Result getUserSig(IMChatRequestDto dto); Result getUserSig(IMChatRequestDto dto);
/**
* 查询对话用户的信息
* @param dto
* @return
*/
Result findChatUserInfo(ConversationRequestDto dto);
/**
* 设置用户备注
* @param dto
* @return
*/
Result setChatUserRemark(UserRequestDto dto);
} }
...@@ -2,6 +2,7 @@ package com.wwdz.ch.admin.shiro; ...@@ -2,6 +2,7 @@ package com.wwdz.ch.admin.shiro;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Stream;
import com.wwdz.ch.core.util.StringUtil; import com.wwdz.ch.core.util.StringUtil;
import com.wwdz.ch.db.dao.dts.DtsAdminDao; import com.wwdz.ch.db.dao.dts.DtsAdminDao;
......
...@@ -18,7 +18,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -18,7 +18,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
public class SysIMServiceImplTest { public class SysIMServiceImplTest {
private static final Logger logger = LoggerFactory.getLogger(BidRecordServiceImplTest.class); private static final Logger logger = LoggerFactory.getLogger(SysIMServiceImplTest.class);
@Autowired @Autowired
......
...@@ -53,6 +53,7 @@ public class ConversationApi { ...@@ -53,6 +53,7 @@ public class ConversationApi {
Random random = new Random(4294967295L); Random random = new Random(4294967295L);
int randomNum = random.nextInt(); int randomNum = random.nextInt();
String url = imUtil.formatIMUrl(SEND_MSG_URL); String url = imUtil.formatIMUrl(SEND_MSG_URL);
logger.info("发送对话信息 URL = {}", url);
OkHttpUtil okHttpUtil = OkHttpUtil.builder().url(url); OkHttpUtil okHttpUtil = OkHttpUtil.builder().url(url);
IMChatMsg imChatMsg = imUtil.convert(sendChatMsgRequestDto); IMChatMsg imChatMsg = imUtil.convert(sendChatMsgRequestDto);
//消息同步至发送方 //消息同步至发送方
......
...@@ -2,13 +2,16 @@ package com.wwdz.ch.core.util; ...@@ -2,13 +2,16 @@ package com.wwdz.ch.core.util;
import com.github.benmanes.caffeine.cache.AsyncLoadingCache; import com.github.benmanes.caffeine.cache.AsyncLoadingCache;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
import com.wwdz.ch.db.dao.AiAssistantDao;
import com.wwdz.ch.db.dao.CategoryDao; import com.wwdz.ch.db.dao.CategoryDao;
import com.wwdz.ch.db.dao.UserDao; import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.dao.dts.DtsAdminDao; import com.wwdz.ch.db.dao.dts.DtsAdminDao;
import com.wwdz.ch.db.dao.dts.DtsUserDao; import com.wwdz.ch.db.dao.dts.DtsUserDao;
import com.wwdz.ch.db.domain.Admin; import com.wwdz.ch.db.domain.Admin;
import com.wwdz.ch.db.domain.AiAssistant;
import com.wwdz.ch.db.domain.Category; import com.wwdz.ch.db.domain.Category;
import com.wwdz.ch.db.domain.User; import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.dto.request.AiAssistantRequestDto;
import com.wwdz.ch.db.dto.request.CategorySearchRequestDto; import com.wwdz.ch.db.dto.request.CategorySearchRequestDto;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -36,6 +39,9 @@ public class CacheUtil { ...@@ -36,6 +39,9 @@ public class CacheUtil {
@Autowired @Autowired
UserDao userDao; UserDao userDao;
@Autowired
AiAssistantDao aiAssistantDao;
public String getAppletUserNameById(long key) { public String getAppletUserNameById(long key) {
try { try {
...@@ -56,6 +62,15 @@ public class CacheUtil { ...@@ -56,6 +62,15 @@ public class CacheUtil {
return new User(); return new User();
} }
public AiAssistant getAiAssistantByCode(String key) {
try {
return aiAssistantCache.get(key).get(3, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
return new AiAssistant();
}
public String getSystemUserNameById(int key) { public String getSystemUserNameById(int key) {
try { try {
...@@ -66,6 +81,23 @@ public class CacheUtil { ...@@ -66,6 +81,23 @@ public class CacheUtil {
return null; return null;
} }
public String getAiNameByCode(String key) {
try {
return aiAssistantCache.get(key).get(3, TimeUnit.SECONDS).getName();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* ai机器人缓存
*/
public AsyncLoadingCache<String, AiAssistant> aiAssistantCache = Caffeine.newBuilder()
.maximumSize(5000)
.expireAfterWrite(13, TimeUnit.MINUTES)
.buildAsync(k -> getAiAssistantList(k));
/** /**
* 小程序会员缓存 * 小程序会员缓存
...@@ -116,6 +148,17 @@ public class CacheUtil { ...@@ -116,6 +148,17 @@ public class CacheUtil {
return map.get(key); return map.get(key);
} }
/**
* 查询ai列表
* @param key
* @return
*/
public AiAssistant getAiAssistantList(String key) {
List<AiAssistant> userList = aiAssistantDao.find(new AiAssistantRequestDto());
Map<String, AiAssistant> map = userList.stream().collect(Collectors.toMap(AiAssistant::getCode, Function.identity(), (k1, k2) -> k2));
return map.get(key);
}
/** /**
* 查询后台用户 * 查询后台用户
......
...@@ -30,6 +30,7 @@ public class RedisUtils { ...@@ -30,6 +30,7 @@ public class RedisUtils {
this.redisTemplate = redisTemplate; this.redisTemplate = redisTemplate;
this.redisTemplate.setHashKeySerializer(new StringRedisSerializer()); this.redisTemplate.setHashKeySerializer(new StringRedisSerializer());
this.redisTemplate.setKeySerializer(new StringRedisSerializer()); this.redisTemplate.setKeySerializer(new StringRedisSerializer());
this.redisTemplate.setValueSerializer(new StringRedisSerializer());
this.redisTemplate.setStringSerializer(new StringRedisSerializer()); this.redisTemplate.setStringSerializer(new StringRedisSerializer());
} }
......
package com.wwdz.ch.db.dao;
import com.wwdz.ch.db.domain.Conversation;
import com.wwdz.ch.db.dto.request.ConversationRequestDto;
import java.util.List;
public interface ConversationDao {
List<Conversation> findList(ConversationRequestDto dto);
boolean create(Conversation conversation);
/**
* 是否已经存在会话
* @param fromAccount
* @param toAccount
* @return
*/
boolean isExisted(String fromAccount, String toAccount);
}
...@@ -2,8 +2,15 @@ package com.wwdz.ch.db.dao; ...@@ -2,8 +2,15 @@ package com.wwdz.ch.db.dao;
import com.wwdz.ch.db.domain.ImRecord; import com.wwdz.ch.db.domain.ImRecord;
import com.wwdz.ch.db.dto.request.ImRecordRequestDto;
import java.util.List;
public interface ImRecordDao { public interface ImRecordDao {
boolean create(ImRecord imRecord); boolean create(ImRecord imRecord);
List<ImRecord> find(ImRecordRequestDto dto);
long count(ImRecordRequestDto dto);
} }
...@@ -75,5 +75,7 @@ public interface UserDao { ...@@ -75,5 +75,7 @@ public interface UserDao {
List<User> queryAll(); List<User> queryAll();
List<User> findByNickName(String name);
} }
package com.wwdz.ch.db.domain; package com.wwdz.ch.db.domain;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import com.xxdxxs.entity.Entity; import com.xxdxxs.entity.Entity;
import lombok.Data; import lombok.Data;
......
...@@ -10,7 +10,7 @@ import lombok.Data; ...@@ -10,7 +10,7 @@ import lombok.Data;
/** /**
* @author shiyu * @author shiyu
* @date 2023/10/31 * @date 2023/11/01
*/ */
@Data @Data
public class User implements Entity { public class User implements Entity {
...@@ -136,6 +136,11 @@ public class User implements Entity { ...@@ -136,6 +136,11 @@ public class User implements Entity {
private Long shareUserId; private Long shareUserId;
/**
* 备注
*/
private String remark;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
...@@ -166,6 +171,7 @@ public class User implements Entity { ...@@ -166,6 +171,7 @@ public class User implements Entity {
sb.append(", updateTime=").append(updateTime); sb.append(", updateTime=").append(updateTime);
sb.append(", deleted=").append(deleted); sb.append(", deleted=").append(deleted);
sb.append(", shareUserId=").append(shareUserId); sb.append(", shareUserId=").append(shareUserId);
sb.append(", remark=").append(remark);
sb.append(", serialVersionUID=").append(serialVersionUID); sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();
...@@ -204,7 +210,8 @@ public class User implements Entity { ...@@ -204,7 +210,8 @@ public class User implements Entity {
&& (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime())) && (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
&& (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted())) && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()))
&& (this.getShareUserId() == null ? other.getShareUserId() == null : this.getShareUserId().equals(other.getShareUserId())); && (this.getShareUserId() == null ? other.getShareUserId() == null : this.getShareUserId().equals(other.getShareUserId()))
&& (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark()));
} }
@Override @Override
...@@ -233,6 +240,7 @@ public class User implements Entity { ...@@ -233,6 +240,7 @@ public class User implements Entity {
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode()); result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
result = prime * result + ((getShareUserId() == null) ? 0 : getShareUserId().hashCode()); result = prime * result + ((getShareUserId() == null) ? 0 : getShareUserId().hashCode());
result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode());
return result; return result;
} }
...@@ -276,7 +284,8 @@ public class User implements Entity { ...@@ -276,7 +284,8 @@ public class User implements Entity {
addTime("add_time", "addTime", "TIMESTAMP", false), addTime("add_time", "addTime", "TIMESTAMP", false),
updateTime("update_time", "updateTime", "TIMESTAMP", false), updateTime("update_time", "updateTime", "TIMESTAMP", false),
deleted("deleted", "deleted", "BIT", false), deleted("deleted", "deleted", "BIT", false),
shareUserId("share_user_id", "shareUserId", "BIGINT", false); shareUserId("share_user_id", "shareUserId", "BIGINT", false),
remark("remark", "remark", "VARCHAR", false);
/** /**
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
......
...@@ -3198,6 +3198,148 @@ public class UserExample { ...@@ -3198,6 +3198,148 @@ public class UserExample {
addCriterion("share_user_id not between", value1, value2, "shareUserId"); addCriterion("share_user_id not between", value1, value2, "shareUserId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andRemarkIsNull() {
addCriterion("remark is null");
return (Criteria) this;
}
public Criteria andRemarkIsNotNull() {
addCriterion("remark is not null");
return (Criteria) this;
}
public Criteria andRemarkEqualTo(String value) {
addCriterion("remark =", value, "remark");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andRemarkEqualToColumn(User.Column column) {
addCriterion(new StringBuilder("remark = ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andRemarkNotEqualTo(String value) {
addCriterion("remark <>", value, "remark");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andRemarkNotEqualToColumn(User.Column column) {
addCriterion(new StringBuilder("remark <> ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andRemarkGreaterThan(String value) {
addCriterion("remark >", value, "remark");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andRemarkGreaterThanColumn(User.Column column) {
addCriterion(new StringBuilder("remark > ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andRemarkGreaterThanOrEqualTo(String value) {
addCriterion("remark >=", value, "remark");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andRemarkGreaterThanOrEqualToColumn(User.Column column) {
addCriterion(new StringBuilder("remark >= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andRemarkLessThan(String value) {
addCriterion("remark <", value, "remark");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andRemarkLessThanColumn(User.Column column) {
addCriterion(new StringBuilder("remark < ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andRemarkLessThanOrEqualTo(String value) {
addCriterion("remark <=", value, "remark");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table user
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andRemarkLessThanOrEqualToColumn(User.Column column) {
addCriterion(new StringBuilder("remark <= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andRemarkLike(String value) {
addCriterion("remark like", value, "remark");
return (Criteria) this;
}
public Criteria andRemarkNotLike(String value) {
addCriterion("remark not like", value, "remark");
return (Criteria) this;
}
public Criteria andRemarkIn(List<String> values) {
addCriterion("remark in", values, "remark");
return (Criteria) this;
}
public Criteria andRemarkNotIn(List<String> values) {
addCriterion("remark not in", values, "remark");
return (Criteria) this;
}
public Criteria andRemarkBetween(String value1, String value2) {
addCriterion("remark between", value1, value2, "remark");
return (Criteria) this;
}
public Criteria andRemarkNotBetween(String value1, String value2) {
addCriterion("remark not between", value1, value2, "remark");
return (Criteria) this;
}
} }
public static class Criteria extends GeneratedCriteria { public static class Criteria extends GeneratedCriteria {
......
package com.wwdz.ch.db.dto.request;
import com.xxdxxs.entity.Entity;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class ConversationRequestDto extends BaseRequestDto implements Entity {
/**
* 会话id
*/
private String chatId;
/**
* 消息发送账户名称
*/
private String fromAccountName;
/**
* 消息发送账户
*/
private String fromAccount;
private List<String> fromAccountList;
/**
* 消息接收账户
*/
private String toAccount;
/**
* 创建时间
*/
private Date createTime;
}
package com.wwdz.ch.db.dto.request;
import com.xxdxxs.entity.Entity;
import lombok.Data;
import java.util.Date;
@Data
public class ImRecordRequestDto extends BaseRequestDto implements Entity {
private Long id;
/**
* 发送者
*/
private String fromAccount;
/**
* 接收者
*/
private String toAccount;
/**
* 消息的唯一标识
*/
private String msgKey;
/**
* 消息发送时间
*/
private Date msgTime;
/**
* 消息时间(开始)
* 用于前端查询
*/
private String startTime;
/**
* 消息时间(结束)
* 用于前端查询
*/
private String endTime;
/**
* 消息下发结果
*/
private Integer sendMsgResult;
/**
* 消息类型
*/
private Integer msgType;
/**
* 是否仅发送给在线用户标识,1代表仅发送给在线用户,否则为0;
*/
private Integer onlineOnlyFlag;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 消息状态
*/
private Integer state;
}
package com.wwdz.ch.wx.entity.request; package com.wwdz.ch.db.dto.request;
import com.xxdxxs.entity.Entity; import com.xxdxxs.entity.Entity;
import lombok.Data; import lombok.Data;
......
package com.wwdz.ch.db.impl;
import com.github.pagehelper.PageHelper;
import com.wwdz.ch.db.dao.ConversationDao;
import com.wwdz.ch.db.domain.Conversation;
import com.wwdz.ch.db.domain.ConversationExample;
import com.wwdz.ch.db.dto.request.ConversationRequestDto;
import com.wwdz.ch.db.mapper.ConversationMapper;
import com.xxdxxs.db.component.JdbcHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class ConversationDaoImpl implements ConversationDao {
@Autowired
ConversationMapper conversationMapper;
@Override
public List<Conversation> findList(ConversationRequestDto dto) {
ConversationExample conversationExample = new ConversationExample();
ConversationExample.Criteria criteria = conversationExample.createCriteria();
JdbcHelper.ifPresent(dto.getFromAccount(), criteria::andFromAccountEqualTo);
JdbcHelper.ifPresent(dto.getToAccount(), criteria::andToAccountEqualTo);
PageHelper.startPage(dto.getPage(), dto.getLimit());
return conversationMapper.selectByExample(conversationExample);
}
@Override
public boolean create(Conversation conversation) {
return conversationMapper.insert(conversation) > 0;
}
@Override
public boolean isExisted(String fromAccount, String toAccount) {
ConversationExample conversationExample = new ConversationExample();
ConversationExample.Criteria criteria = conversationExample.createCriteria();
criteria.andFromAccountEqualTo(fromAccount);
criteria.andToAccountEqualTo(toAccount);
return conversationMapper.countByExample(conversationExample) > 0;
}
}
package com.wwdz.ch.db.impl; package com.wwdz.ch.db.impl;
import com.github.pagehelper.PageHelper;
import com.wwdz.ch.db.dao.ImRecordDao; import com.wwdz.ch.db.dao.ImRecordDao;
import com.wwdz.ch.db.domain.ImRecord; import com.wwdz.ch.db.domain.ImRecord;
import com.wwdz.ch.db.domain.ImRecordExample;
import com.wwdz.ch.db.dto.request.ImRecordRequestDto;
import com.wwdz.ch.db.dto.request.InviteRecordRequestDto;
import com.wwdz.ch.db.mapper.ImRecordMapper; import com.wwdz.ch.db.mapper.ImRecordMapper;
import com.xxdxxs.db.component.JdbcHelper;
import com.xxdxxs.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;
import java.util.List;
@Repository @Repository
public class ImRecordDaoImpl implements ImRecordDao { public class ImRecordDaoImpl implements ImRecordDao {
...@@ -17,4 +26,35 @@ public class ImRecordDaoImpl implements ImRecordDao { ...@@ -17,4 +26,35 @@ public class ImRecordDaoImpl implements ImRecordDao {
public boolean create(ImRecord imRecord) { public boolean create(ImRecord imRecord) {
return imRecordMapper.insert(imRecord) > 0; return imRecordMapper.insert(imRecord) > 0;
} }
@Override
public List<ImRecord> find(ImRecordRequestDto dto) {
ImRecordExample imRecordExample = new ImRecordExample();
ImRecordExample.Criteria criteria = imRecordExample.createCriteria();
criteria.andFromAccountEqualTo(dto.getFromAccount())
.andToAccountEqualTo(dto.getToAccount());
imRecordExample.or(imRecordExample.createCriteria()
.andFromAccountEqualTo(dto.getToAccount())
.andToAccountEqualTo(dto.getFromAccount()));
if (StringUtils.hasLength(dto.getStartTime())) {
imRecordExample.createCriteria().andMsgTimeGreaterThanOrEqualTo(DateUtils.parseString(dto.getStartTime()));
}
if (StringUtils.hasLength(dto.getEndTime())) {
imRecordExample.createCriteria().andMsgTimeLessThanOrEqualTo(DateUtils.parseString(dto.getEndTime()));
}
imRecordExample.orderBy("msg_time asc");
PageHelper.startPage(dto.getPage(), dto.getLimit());
return imRecordMapper.selectByExampleWithBLOBs(imRecordExample);
}
@Override
public long count(ImRecordRequestDto dto) {
ImRecordExample imRecordExample = new ImRecordExample();
ImRecordExample.Criteria criteria = imRecordExample.createCriteria();
criteria.andFromAccountEqualTo(dto.getFromAccount())
.andToAccountEqualTo(dto.getToAccount());
return imRecordMapper.countByExample(imRecordExample);
}
} }
...@@ -81,4 +81,12 @@ public class UserDaoImpl implements UserDao { ...@@ -81,4 +81,12 @@ public class UserDaoImpl implements UserDao {
example.createCriteria().andDeletedEqualTo(false); example.createCriteria().andDeletedEqualTo(false);
return userMapper.selectByExample(example); return userMapper.selectByExample(example);
} }
@Override
public List<User> findByNickName(String name) {
UserExample example = new UserExample();
example.createCriteria().andNicknameLike("%" + name + "%");
return userMapper.selectByExample(example);
}
} }
...@@ -2,10 +2,11 @@ package com.wwdz.ch.db.mapper; ...@@ -2,10 +2,11 @@ package com.wwdz.ch.db.mapper;
import com.wwdz.ch.db.domain.User; import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.domain.UserExample; import com.wwdz.ch.db.domain.UserExample;
import java.util.List;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper @Mapper
public interface UserMapper { public interface UserMapper {
...@@ -15,7 +16,7 @@ public interface UserMapper { ...@@ -15,7 +16,7 @@ public interface UserMapper {
int deleteByPrimaryKey(Long id); int deleteByPrimaryKey(Long id);
long insert(User record); int insert(User record);
int insertSelective(User record); int insertSelective(User record);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="deleted" jdbcType="BIT" property="deleted" /> <result column="deleted" jdbcType="BIT" property="deleted" />
<result column="share_user_id" jdbcType="BIGINT" property="shareUserId" /> <result column="share_user_id" jdbcType="BIGINT" property="shareUserId" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
...@@ -86,7 +87,7 @@ ...@@ -86,7 +87,7 @@
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level, id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level,
nickname, mobile, avatar, profile, background, weixin_openid, weixin_unionid, alipay_user_id, nickname, mobile, avatar, profile, background, weixin_openid, weixin_unionid, alipay_user_id,
wechat_id, `status`, add_time, update_time, deleted, share_user_id wechat_id, `status`, add_time, update_time, deleted, share_user_id, remark
</sql> </sql>
<select id="selectByExample" parameterType="com.wwdz.ch.db.domain.UserExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="com.wwdz.ch.db.domain.UserExample" resultMap="BaseResultMap">
select select
...@@ -123,7 +124,7 @@ ...@@ -123,7 +124,7 @@
<otherwise> <otherwise>
id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level, id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level,
nickname, mobile, avatar, profile, background, weixin_openid, weixin_unionid, alipay_user_id, nickname, mobile, avatar, profile, background, weixin_openid, weixin_unionid, alipay_user_id,
wechat_id, `status`, add_time, update_time, deleted, share_user_id wechat_id, `status`, add_time, update_time, deleted, share_user_id, remark
</otherwise> </otherwise>
</choose> </choose>
from user from user
...@@ -176,7 +177,7 @@ ...@@ -176,7 +177,7 @@
<otherwise> <otherwise>
id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level, id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level,
nickname, mobile, avatar, profile, background, weixin_openid, weixin_unionid, alipay_user_id, nickname, mobile, avatar, profile, background, weixin_openid, weixin_unionid, alipay_user_id,
wechat_id, `status`, add_time, update_time, deleted, share_user_id wechat_id, `status`, add_time, update_time, deleted, share_user_id, remark
</otherwise> </otherwise>
</choose> </choose>
from user from user
...@@ -202,16 +203,16 @@ ...@@ -202,16 +203,16 @@
avatar, profile, background, avatar, profile, background,
weixin_openid, weixin_unionid, alipay_user_id, weixin_openid, weixin_unionid, alipay_user_id,
wechat_id, `status`, add_time, wechat_id, `status`, add_time,
update_time, deleted, share_user_id update_time, deleted, share_user_id,
) remark)
values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{gender,jdbcType=TINYINT}, values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{gender,jdbcType=TINYINT},
#{birthday,jdbcType=DATE}, #{lastLoginTime,jdbcType=TIMESTAMP}, #{lastLoginIp,jdbcType=VARCHAR}, #{birthday,jdbcType=DATE}, #{lastLoginTime,jdbcType=TIMESTAMP}, #{lastLoginIp,jdbcType=VARCHAR},
#{userLevel,jdbcType=TINYINT}, #{nickname,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{userLevel,jdbcType=TINYINT}, #{nickname,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR},
#{avatar,jdbcType=VARCHAR}, #{profile,jdbcType=VARCHAR}, #{background,jdbcType=VARCHAR}, #{avatar,jdbcType=VARCHAR}, #{profile,jdbcType=VARCHAR}, #{background,jdbcType=VARCHAR},
#{weixinOpenid,jdbcType=VARCHAR}, #{weixinUnionid,jdbcType=VARCHAR}, #{alipayUserId,jdbcType=VARCHAR}, #{weixinOpenid,jdbcType=VARCHAR}, #{weixinUnionid,jdbcType=VARCHAR}, #{alipayUserId,jdbcType=VARCHAR},
#{wechatId,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT}, #{addTime,jdbcType=TIMESTAMP}, #{wechatId,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT}, #{addTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT}, #{shareUserId,jdbcType=BIGINT} #{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT}, #{shareUserId,jdbcType=BIGINT},
) #{remark,jdbcType=VARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.User"> <insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.User">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long"> <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
...@@ -282,6 +283,9 @@ ...@@ -282,6 +283,9 @@
<if test="shareUserId != null"> <if test="shareUserId != null">
share_user_id, share_user_id,
</if> </if>
<if test="remark != null">
remark,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="username != null"> <if test="username != null">
...@@ -347,6 +351,9 @@ ...@@ -347,6 +351,9 @@
<if test="shareUserId != null"> <if test="shareUserId != null">
#{shareUserId,jdbcType=BIGINT}, #{shareUserId,jdbcType=BIGINT},
</if> </if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="com.wwdz.ch.db.domain.UserExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="com.wwdz.ch.db.domain.UserExample" resultType="java.lang.Long">
...@@ -424,6 +431,9 @@ ...@@ -424,6 +431,9 @@
<if test="record.shareUserId != null"> <if test="record.shareUserId != null">
share_user_id = #{record.shareUserId,jdbcType=BIGINT}, share_user_id = #{record.shareUserId,jdbcType=BIGINT},
</if> </if>
<if test="record.remark != null">
remark = #{record.remark,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" />
...@@ -452,7 +462,8 @@ ...@@ -452,7 +462,8 @@
add_time = #{record.addTime,jdbcType=TIMESTAMP}, add_time = #{record.addTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
deleted = #{record.deleted,jdbcType=BIT}, deleted = #{record.deleted,jdbcType=BIT},
share_user_id = #{record.shareUserId,jdbcType=BIGINT} share_user_id = #{record.shareUserId,jdbcType=BIGINT},
remark = #{record.remark,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>
...@@ -523,6 +534,9 @@ ...@@ -523,6 +534,9 @@
<if test="shareUserId != null"> <if test="shareUserId != null">
share_user_id = #{shareUserId,jdbcType=BIGINT}, share_user_id = #{shareUserId,jdbcType=BIGINT},
</if> </if>
<if test="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
</set> </set>
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
...@@ -548,7 +562,8 @@ ...@@ -548,7 +562,8 @@
add_time = #{addTime,jdbcType=TIMESTAMP}, add_time = #{addTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=BIT}, deleted = #{deleted,jdbcType=BIT},
share_user_id = #{shareUserId,jdbcType=BIGINT} share_user_id = #{shareUserId,jdbcType=BIGINT},
remark = #{remark,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
<select id="selectOneByExample" parameterType="com.wwdz.ch.db.domain.UserExample" resultMap="BaseResultMap"> <select id="selectOneByExample" parameterType="com.wwdz.ch.db.domain.UserExample" resultMap="BaseResultMap">
...@@ -586,7 +601,7 @@ ...@@ -586,7 +601,7 @@
<otherwise> <otherwise>
id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level, id, username, `password`, gender, birthday, last_login_time, last_login_ip, user_level,
nickname, mobile, avatar, profile, background, weixin_openid, weixin_unionid, alipay_user_id, nickname, mobile, avatar, profile, background, weixin_openid, weixin_unionid, alipay_user_id,
wechat_id, `status`, add_time, update_time, deleted, share_user_id wechat_id, `status`, add_time, update_time, deleted, share_user_id, remark
</otherwise> </otherwise>
</choose> </choose>
from user from user
......
...@@ -71,6 +71,7 @@ public class IMCallbackController { ...@@ -71,6 +71,7 @@ public class IMCallbackController {
String onlineOnlyFlag = JsonUtils.getValueByPath(jsonStr, "OnlineOnlyFlag"); String onlineOnlyFlag = JsonUtils.getValueByPath(jsonStr, "OnlineOnlyFlag");
String sendMsgResult = JsonUtils.getValueByPath(jsonStr, "SendMsgResult"); String sendMsgResult = JsonUtils.getValueByPath(jsonStr, "SendMsgResult");
String errorInfo = JsonUtils.getValueByPath(jsonStr, "ErrorInfo"); String errorInfo = JsonUtils.getValueByPath(jsonStr, "ErrorInfo");
String cloudCustomData = JsonUtils.getValueByPath(jsonStr, "CloudCustomData");
if (!"0".equals(sendMsgResult)) { if (!"0".equals(sendMsgResult)) {
logger.error("msgKey:{}, 消息下发失败错误信息:{}", msgKey, errorInfo); logger.error("msgKey:{}, 消息下发失败错误信息:{}", msgKey, errorInfo);
imRecord.setState(IMEnum.MsgStateEnum.FAILED.getCode()); imRecord.setState(IMEnum.MsgStateEnum.FAILED.getCode());
...@@ -86,7 +87,7 @@ public class IMCallbackController { ...@@ -86,7 +87,7 @@ public class IMCallbackController {
if (IMEnum.MsgTypeEnum.TIMTextElem.getValue().equals(msgType)) { if (IMEnum.MsgTypeEnum.TIMTextElem.getValue().equals(msgType)) {
content = JsonUtils.getValueByPath(contentJsonStr, "Text"); content = JsonUtils.getValueByPath(contentJsonStr, "Text");
} }
imRecord.setCloudCustomData(cloudCustomData);
imRecord.setFromAccount(imUtil.revertAppletUserId(fromAccount)); imRecord.setFromAccount(imUtil.revertAppletUserId(fromAccount));
imRecord.setToAccount(imUtil.revertAppletUserId(toAccount)); imRecord.setToAccount(imUtil.revertAppletUserId(toAccount));
imRecord.setMsgTime(new Date(msgTime * 1000L)); imRecord.setMsgTime(new Date(msgTime * 1000L));
......
...@@ -9,8 +9,10 @@ import com.wwdz.ch.core.type.Result; ...@@ -9,8 +9,10 @@ import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.IMUtil; import com.wwdz.ch.core.util.IMUtil;
import com.wwdz.ch.core.util.RedisUtils; import com.wwdz.ch.core.util.RedisUtils;
import com.wwdz.ch.db.dao.AiAssistantDao; import com.wwdz.ch.db.dao.AiAssistantDao;
import com.wwdz.ch.db.dao.ConversationDao;
import com.wwdz.ch.db.dao.ImRecordDao; import com.wwdz.ch.db.dao.ImRecordDao;
import com.wwdz.ch.db.domain.AiAssistant; import com.wwdz.ch.db.domain.AiAssistant;
import com.wwdz.ch.db.domain.Conversation;
import com.wwdz.ch.db.domain.ImRecord; import com.wwdz.ch.db.domain.ImRecord;
import com.wwdz.ch.wx.api.ChatApi; import com.wwdz.ch.wx.api.ChatApi;
import com.wwdz.ch.wx.service.IMService; import com.wwdz.ch.wx.service.IMService;
...@@ -55,6 +57,9 @@ public class ImServiceImpl implements IMService { ...@@ -55,6 +57,9 @@ public class ImServiceImpl implements IMService {
@Autowired @Autowired
ImRecordService imRecordService; ImRecordService imRecordService;
@Autowired
ConversationDao conversationDao;
/** /**
* 新增ai会话,发送默认打招呼的消息 * 新增ai会话,发送默认打招呼的消息
* @param dto * @param dto
...@@ -121,6 +126,19 @@ public class ImServiceImpl implements IMService { ...@@ -121,6 +126,19 @@ public class ImServiceImpl implements IMService {
if (!askResult.getSuccess()) { if (!askResult.getSuccess()) {
return askResult; return askResult;
} }
//创建会话,先判断是否存在对话
boolean isExisted = conversationDao.isExisted(dto.getFromAccount(), dto.getToAccount());
if (!isExisted) {
Conversation conversation = new Conversation();
conversation.setFromAccount(dto.getFromAccount());
conversation.setToAccount(dto.getToAccount());
String chatId = dto.getFromAccount() + "_to_" + dto.getToAccount();
conversation.setChatId(chatId);
conversation.setCreateTime(new Date());
conversationDao.create(conversation);
logger.info(">>>>>>>> chatId : {}, 创建会话成功 <<<<<<<<", chatId);
}
logger.info("=========== userid:{}, 提问ai的消息发送成功 ==========", dto.getFromAccount()); logger.info("=========== userid:{}, 提问ai的消息发送成功 ==========", dto.getFromAccount());
if (dto.getMsgType() == IMEnum.MsgTypeEnum.TIMTextElem.getCode()) { if (dto.getMsgType() == IMEnum.MsgTypeEnum.TIMTextElem.getCode()) {
String question = (String) dto.getMsgContent(); String question = (String) dto.getMsgContent();
......
...@@ -26,7 +26,7 @@ import com.wwdz.ch.wx.constant.CacheCodeConstants; ...@@ -26,7 +26,7 @@ import com.wwdz.ch.wx.constant.CacheCodeConstants;
import com.wwdz.ch.wx.constant.LoginTypeEnum; import com.wwdz.ch.wx.constant.LoginTypeEnum;
import com.wwdz.ch.wx.dao.UserInfo; import com.wwdz.ch.wx.dao.UserInfo;
import com.wwdz.ch.wx.dao.UserToken; import com.wwdz.ch.wx.dao.UserToken;
import com.wwdz.ch.wx.entity.request.UserRequestDto; import com.wwdz.ch.db.dto.request.UserRequestDto;
import com.wwdz.ch.wx.manager.AlipayLoginManager; import com.wwdz.ch.wx.manager.AlipayLoginManager;
import com.wwdz.ch.wx.manager.TikTokLoginManager; import com.wwdz.ch.wx.manager.TikTokLoginManager;
import com.wwdz.ch.wx.manager.UserTokenManager; import com.wwdz.ch.wx.manager.UserTokenManager;
......
...@@ -6,8 +6,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; ...@@ -6,8 +6,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.wwdz.ch.core.util.OkHttpUtil; import com.wwdz.ch.core.util.OkHttpUtil;
import com.wwdz.ch.core.util.RedisUtils; import com.wwdz.ch.core.util.RedisUtils;
import com.wwdz.ch.db.domain.User; import com.wwdz.ch.db.dto.request.UserRequestDto;
import com.wwdz.ch.wx.entity.request.UserRequestDto;
import com.xxdxxs.utils.JsonUtils; import com.xxdxxs.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
......
package com.wwdz.ch.wx.service; package com.wwdz.ch.wx.service;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.wx.entity.request.UserRequestDto; import com.wwdz.ch.db.dto.request.UserRequestDto;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
......
...@@ -5,7 +5,7 @@ import com.alibaba.fastjson.JSON; ...@@ -5,7 +5,7 @@ import com.alibaba.fastjson.JSON;
import com.wwdz.ch.core.consts.ResultCode; import com.wwdz.ch.core.consts.ResultCode;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.domain.User; import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.wx.entity.request.UserRequestDto; import com.wwdz.ch.db.dto.request.UserRequestDto;
import com.wwdz.ch.wx.service.OfficialAccountSubscribeRecordService; import com.wwdz.ch.wx.service.OfficialAccountSubscribeRecordService;
import com.wwdz.ch.wx.service.UserService; import com.wwdz.ch.wx.service.UserService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
......
...@@ -6,7 +6,7 @@ import com.wwdz.ch.core.type.Result; ...@@ -6,7 +6,7 @@ import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dto.request.InviteRecordRequestDto; import com.wwdz.ch.db.dto.request.InviteRecordRequestDto;
import com.wwdz.ch.wx.constant.CacheCodeConstants; import com.wwdz.ch.wx.constant.CacheCodeConstants;
import com.wwdz.ch.wx.constant.LoginTypeEnum; import com.wwdz.ch.wx.constant.LoginTypeEnum;
import com.wwdz.ch.wx.entity.request.UserRequestDto; import com.wwdz.ch.db.dto.request.UserRequestDto;
import com.wwdz.ch.wx.service.InviteRecordService; import com.wwdz.ch.wx.service.InviteRecordService;
import com.wwdz.ch.wx.service.UserService; import com.wwdz.ch.wx.service.UserService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
......
...@@ -14,6 +14,7 @@ import com.wwdz.ch.db.domain.AiAssistant; ...@@ -14,6 +14,7 @@ import com.wwdz.ch.db.domain.AiAssistant;
import com.wwdz.ch.db.domain.User; import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.dto.request.AiAssistantRequestDto; import com.wwdz.ch.db.dto.request.AiAssistantRequestDto;
import com.wwdz.ch.wx.manager.WxLoginManager; import com.wwdz.ch.wx.manager.WxLoginManager;
import com.wwdz.ch.wx.service.IMService;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -51,6 +52,9 @@ public class ChatApiTest { ...@@ -51,6 +52,9 @@ public class ChatApiTest {
@Autowired @Autowired
WxLoginManager wxLoginManager; WxLoginManager wxLoginManager;
@Autowired
IMService imService;
@Test @Test
public void chatWithModel() { public void chatWithModel() {
String question = "什么是站洋,请回答钱币相关的内容"; String question = "什么是站洋,请回答钱币相关的内容";
...@@ -118,6 +122,26 @@ public class ChatApiTest { ...@@ -118,6 +122,26 @@ public class ChatApiTest {
} }
/**
* 发送IM消息
*/
@Test
public void sendAiChatMsg() {
SendChatMsgRequestDto sendChatMsgRequestDto = new SendChatMsgRequestDto();
sendChatMsgRequestDto.setToAccount("ai10000");
sendChatMsgRequestDto.setFromAccount("251");
sendChatMsgRequestDto.setMsgType(IMEnum.MsgTypeEnum.TIMTextElem.getCode());
sendChatMsgRequestDto.setReqId("12123123123");
long timestamp = System.currentTimeMillis();
String msgContent = "什么是站洋";
// String msgContent = "Hi,欢迎来到老猫的世界";
sendChatMsgRequestDto.setMsgContent(msgContent);
Result<String> result = imService.sendAiChatMsg(sendChatMsgRequestDto);
}
/** /**
* 给已经创建的用户发送默认机器人消息 * 给已经创建的用户发送默认机器人消息
*/ */
...@@ -142,7 +166,7 @@ public class ChatApiTest { ...@@ -142,7 +166,7 @@ public class ChatApiTest {
@Test @Test
public void getChatList() { public void getChatList() {
IMChatRequestDto imChatRequestDto = new IMChatRequestDto(); IMChatRequestDto imChatRequestDto = new IMChatRequestDto();
imChatRequestDto.setUserId(238L); imChatRequestDto.setUserId("238");
conversationApi.getChatList(imChatRequestDto); conversationApi.getChatList(imChatRequestDto);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment