This commit is contained in:
张良(004796)
2024-01-09 20:50:55 +08:00
parent 1f2a9791f9
commit 4d24793cdb
21 changed files with 620 additions and 13 deletions

View File

@@ -2,21 +2,21 @@ package com.ruoyi.cai.manager;
import com.ruoyi.cai.domain.Account;
import com.ruoyi.cai.domain.User;
import com.ruoyi.cai.domain.UserVisitor;
import com.ruoyi.cai.domain.UserChatRecord;
import com.ruoyi.cai.domain.UserMember;
import com.ruoyi.cai.dto.app.dto.ImMessageDTO;
import com.ruoyi.cai.dto.app.vo.ImResp;
import com.ruoyi.cai.dto.app.vo.user.UserStarOrVisitorList;
import com.ruoyi.cai.enums.GenderEnum;
import com.ruoyi.cai.enums.ImTypeEnum;
import com.ruoyi.cai.enums.SystemConfigEnum;
import com.ruoyi.cai.service.AccountService;
import com.ruoyi.cai.service.UserFollowService;
import com.ruoyi.cai.service.UserService;
import com.ruoyi.cai.service.UserVisitorService;
import com.ruoyi.cai.enums.UserMemberTypeEnum;
import com.ruoyi.cai.mapper.AccountMapper;
import com.ruoyi.cai.service.*;
import com.ruoyi.common.exception.ServiceException;
import org.apache.xmlbeans.impl.xb.xsdschema.UnionDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Set;
@Component
@@ -30,6 +30,10 @@ public class ImService {
private AccountService accountService;
@Autowired
private UserFollowService userFollowService;
@Autowired
private UserMemberService userMemberService;
@Autowired
private UserChatRecordService userChatRecordService;
public ImResp sendMessage(Long fromUserId, ImMessageDTO message) {
ImTypeEnum typeEnum = ImTypeEnum.getByType(message.getType());
@@ -37,9 +41,20 @@ public class ImService {
throw new ServiceException("参数异常");
}
// 检测用户是否被封号
User user = userService.getById(fromUserId);
if(user.getStatus() == 1){
throw new ServiceException("该账户已被封禁,无法发送消息");
User fromUser = userService.getById(fromUserId);
if(fromUser == null){
throw new ServiceException("发送人不存在!");
}
if(fromUser.getStatus() == 1){
throw new ServiceException("发送人账号不可用!");
}
Long toUserId = message.getToUserId();
User toUser = userService.getById(toUserId);
if(toUser == null){
throw new ServiceException("接收人不存在!");
}
if(toUser.getStatus() == 1){
throw new ServiceException("接收人账号不可用!");
}
// 自定义消息跳过所有流程
if(typeEnum == ImTypeEnum.CUSTOM){
@@ -48,8 +63,14 @@ public class ImService {
resp.setCoin(account.getCoin()+ account.getIncomeCoin());
return resp;
}
Long toUserId = message.getToUserId();
Set<Long> systemCustomerService = systemConfigManager.getSystemConfigOfLongSet(SystemConfigEnum.SYSTEM_CUSTOMER_SERVICE);
// 有内部用户参与的 跳过所有校验
if(systemCustomerService.contains(fromUserId) || systemCustomerService.contains(toUserId)){
Account account = accountService.getByUserId(fromUserId);
ImResp resp = new ImResp();
resp.setCoin(account.getCoin()+ account.getIncomeCoin());
return resp;
}
boolean fileType = typeEnum.isFileType();
if(fileType){
if(!systemCustomerService.contains(fromUserId) && !systemCustomerService.contains(toUserId)){
@@ -63,7 +84,69 @@ public class ImService {
if(typeEnum == ImTypeEnum.MESSAGE && !systemCustomerService.contains(fromUserId) && !systemCustomerService.contains(toUserId)){
}
if(fromUserId.equals(toUserId)){
throw new ServiceException("不能给自己发送哦!");
}
// 更新活跃时间
// 检查拉黑
boolean isBlack = userBlacklistService.existsBlack(fromUserId, toUserId);
if(isBlack){
throw new ServiceException("您已经将对方拉黑!");
}
isBlack = userBlacklistService.existsBlack(toUserId, fromUserId);
if(isBlack){
throw new ServiceException("对方已经将您拉黑!");
}
if (fromUser.getGender().equals(GenderEnum.WOMEN.getCode()) && toUser.getGender().equals(GenderEnum.WOMEN.getCode())) {
throw new ServiceException("女生之间暂不支持私信!");
}
if (fromUser.getGender().equals(GenderEnum.MAN.getCode()) && toUser.getGender().equals(GenderEnum.MAN.getCode())) {
throw new ServiceException("男生之间暂不支持私信!");
}
if (fromUser.getGender().equals(GenderEnum.MAN.getCode()) && toUser.getIsAnchor().equals(0)) {
throw new ServiceException("只能给女神私信!");
}
if (fromUser.getGender().equals(GenderEnum.WOMEN.getCode()) && toUser.getIsAnchor().equals(0)) {
throw new ServiceException("成为女神才能私信!");
}
if (fromUser.getIsAnchor().equals(1) && toUser.getIsAnchor().equals(1)) {
throw new ServiceException("女神之间暂不支持私信!");
}
if (fromUser.getIsAnchor().equals(0) && toUser.getIsAnchor().equals(0)) {
throw new ServiceException("目前只能和女神私信!");
}
if(){
Account account = accountService.getByUserId(fromUserId);
ImResp resp = new ImResp();
resp.setCoin(account.getCoin()+ account.getIncomeCoin());
return resp;
}
// 判断VIP获取价格
Long imPrice = getByImPrice(fromUserId);
Long traceId = null;
if(imPrice > 0){
// 扣费
traceId = accountService.imDesc(fromUser, toUser, imPrice);
}
// 存储聊天记录
userChatRecordService.saveRecord(fromUser,toUser,traceId,message);
return null;
}
@Autowired
private UserBlacklistService userBlacklistService;
private Long getByImPrice(Long userId){
UserMember userMember = userMemberService.getNormalMember(userId);
if(userMember == null){
return 10L;
}
if(userMember.getMemberType().equals(UserMemberTypeEnum.NORMAL_VIP.getCode())){
return 5L;
}
if(userMember.getMemberType().equals(UserMemberTypeEnum.SUPER_VIP.getCode())){
return 0L;
}
return 10L;
}
}