[yxf] 22 hours ago
parent
commit
d0a96074c8
  1. 17
      im-platform/src/main/java/com/bx/implatform/controller/UserController.java
  2. 6
      im-platform/src/main/java/com/bx/implatform/service/UserService.java
  3. 20
      im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java
  4. 23
      im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java
  5. 6
      im-web/src/view/Login.vue

17
im-platform/src/main/java/com/bx/implatform/controller/UserController.java

@ -19,7 +19,9 @@ import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import static com.bx.implatform.enums.ResultCode.XSS_PARAM_ERROR; import static com.bx.implatform.enums.ResultCode.XSS_PARAM_ERROR;
@ -69,7 +71,7 @@ public class UserController {
@PostMapping("/getEnableChangeCustomer") @PostMapping("/getEnableChangeCustomer")
@Operation(summary = "获取可转接的客服", description = "转接客服") @Operation(summary = "获取可转接的客服", description = "转接客服")
public Result<List<User>> getEnableChangeCustomer() { public Result<List<Map<String, Object>>> getEnableChangeCustomer() {
// 获取当前客服id、转接客服id、转接用户id // 获取当前客服id、转接客服id、转接用户id
UserSession session = SessionContext.getSession(); UserSession session = SessionContext.getSession();
Long userId = session.getUserId(); Long userId = session.getUserId();
@ -81,7 +83,15 @@ public class UserController {
List<User> list = userService.getEnableChangeCustomerList(userId); List<User> list = userService.getEnableChangeCustomerList(userId);
return ResultUtils.success(list); //使用Map返回id、昵称
List<Map<String, Object>> result = list.stream().map(user -> {
Map<String, Object> map = new HashMap<>();
map.put("id", user.getId());
map.put("nickName", user.getNickName());
return map;
}).toList();
return ResultUtils.success(result);
} }
@PostMapping("/changeCustomer") @PostMapping("/changeCustomer")
@ -95,8 +105,9 @@ public class UserController {
Long targetId = jsonObject.getLong("targetId"); Long targetId = jsonObject.getLong("targetId");
Long userId = jsonObject.getLong("userId"); Long userId = jsonObject.getLong("userId");
boolean check = userService.chenckRelation(customerId,targetId, userId);
if(ObjectUtil.isNull(customerId) || ObjectUtil.isNull(targetId) || ObjectUtil.isNull(userId)){ if(!check){
return ResultUtils.error(XSS_PARAM_ERROR); return ResultUtils.error(XSS_PARAM_ERROR);
} }

6
im-platform/src/main/java/com/bx/implatform/service/UserService.java

@ -103,6 +103,12 @@ public interface UserService extends IService<User> {
*/ */
void changeCustomer(Long customerId,Long targetId, Long userId); void changeCustomer(Long customerId,Long targetId, Long userId);
/**
* 校验转接客服关系
* @param customerId 客服id targetId 转接的客服id userId 转接的用户id
*/
boolean chenckRelation(Long customerId,Long targetId, Long userId);
/** /**
* 获取可转接的客服 * 获取可转接的客服
* @param userId 用户id * @param userId 用户id

20
im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java

@ -156,6 +156,7 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme
@Override @Override
public void changeFriendRelation(Long customerId, Long targetId, Long userId) { public void changeFriendRelation(Long customerId, Long targetId, Long userId) {
//获取原好友关系并校验
LambdaQueryWrapper<Friend> wrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<Friend> wrapper = Wrappers.lambdaQuery();
wrapper.eq(Friend::getUserId, customerId); wrapper.eq(Friend::getUserId, customerId);
wrapper.eq(Friend::getFriendId, userId); wrapper.eq(Friend::getFriendId, userId);
@ -176,6 +177,25 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme
ids.add(friendAnother.getId()); ids.add(friendAnother.getId());
this.baseMapper.deleteByIds(ids); this.baseMapper.deleteByIds(ids);
//如果转接的客服与转接用户有关系,则删除
//1.客服与转接用户关系
LambdaQueryWrapper<Friend> wrapperTarget = Wrappers.lambdaQuery();
wrapperTarget.eq(Friend::getUserId, targetId);
wrapperTarget.eq(Friend::getFriendId, customerId);
Friend friendTarget = this.getOne(wrapperTarget);
if(Objects.nonNull(friendTarget)){
this.baseMapper.deleteById(friendTarget.getId());
}
//2.转接用户与客服关系
LambdaQueryWrapper<Friend> wrapperTarget2 = Wrappers.lambdaQuery();
wrapperTarget2.eq(Friend::getUserId, customerId);
wrapperTarget2.eq(Friend::getFriendId, targetId);
Friend friendTarget2 = this.getOne(wrapperTarget2);
if(Objects.nonNull(friendTarget2)){
this.baseMapper.deleteById(friendTarget2.getId());
}
//获取转移目标客服对象 //获取转移目标客服对象
User user = userMapper.selectById(targetId); User user = userMapper.selectById(targetId);
if(Objects.isNull(user)){ if(Objects.isNull(user)){

23
im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java

@ -1,5 +1,6 @@
package com.bx.implatform.service.impl; package com.bx.implatform.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -20,6 +21,7 @@ import com.bx.implatform.entity.User;
import com.bx.implatform.enums.ResultCode; import com.bx.implatform.enums.ResultCode;
import com.bx.implatform.exception.GlobalException; import com.bx.implatform.exception.GlobalException;
import com.bx.implatform.mapper.UserMapper; import com.bx.implatform.mapper.UserMapper;
import com.bx.implatform.result.ResultUtils;
import com.bx.implatform.service.FriendService; import com.bx.implatform.service.FriendService;
import com.bx.implatform.service.GroupMemberService; import com.bx.implatform.service.GroupMemberService;
import com.bx.implatform.service.PrivateMessageService; import com.bx.implatform.service.PrivateMessageService;
@ -41,6 +43,8 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.bx.implatform.enums.ResultCode.XSS_PARAM_ERROR;
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@ -361,6 +365,25 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
} }
@Override
public boolean chenckRelation(Long customerId, Long targetId, Long userId) {
// 检查参数
if(ObjectUtil.isNull(customerId) || ObjectUtil.isNull(targetId) || ObjectUtil.isNull(userId)){
return false;
}
// 检查本身之间的关系
if(customerId.equals(targetId) || customerId.equals(userId) || targetId.equals(userId)){
return false;
}
// 检查是原客服和用户是否是好友
if(!friendService.isFriend(customerId, userId)){
return false;
}
return true;
}
@Override @Override
public List<User> getEnableChangeCustomerList(Long userId) { public List<User> getEnableChangeCustomerList(Long userId) {
LambdaQueryWrapper<User> queryWrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<User> queryWrapper = Wrappers.lambdaQuery();

6
im-web/src/view/Login.vue

@ -8,7 +8,7 @@
@keyup.enter.native="submitForm('loginForm')"> @keyup.enter.native="submitForm('loginForm')">
<div class="title"> <div class="title">
<img class="logo" src="../../public/logo.png" /> <img class="logo" src="../../public/logo.png" />
<div>登录盒子IM</div> <div>登录客服</div>
</div> </div>
<el-form-item prop="terminal" v-show="false"> <el-form-item prop="terminal" v-show="false">
<el-input type="terminal" v-model="loginForm.terminal" autocomplete="off"></el-input> <el-input type="terminal" v-model="loginForm.terminal" autocomplete="off"></el-input>
@ -25,12 +25,14 @@
<el-button type="primary" @click="submitForm('loginForm')">登录</el-button> <el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
<el-button @click="resetForm('loginForm')">清空</el-button> <el-button @click="resetForm('loginForm')">清空</el-button>
</el-form-item> </el-form-item>
<!--
<div class="register"> <div class="register">
<router-link to="/register">没有账号,前往注册</router-link> <router-link to="/register">没有账号,前往注册</router-link>
</div> </div>
-->
</el-form> </el-form>
</div> </div>
<icp></icp> <!-- <icp></icp> -->
</div> </div>
</template> </template>

Loading…
Cancel
Save