package com.yami.shop.api.controller.im;
|
|
import cn.hutool.crypto.SecureUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.yami.shop.bean.app.dto.UserDto;
|
import com.yami.shop.bean.model.LuckUserFriend;
|
import com.yami.shop.bean.model.User;
|
import com.yami.shop.bean.param.im.ApplyFriendParam;
|
import com.yami.shop.bean.param.im.AuditFriendParam;
|
import com.yami.shop.bean.vo.UserVO;
|
import com.yami.shop.common.bean.AliOss;
|
import com.yami.shop.common.bean.HuaWeiOss;
|
import com.yami.shop.common.config.Constant;
|
import com.yami.shop.common.response.ServerResponseEntity;
|
import com.yami.shop.security.api.util.SecurityUtils;
|
import com.yami.shop.service.ILuckUserFriendService;
|
import com.yami.shop.service.QRCodeService;
|
import com.yami.shop.service.SysConfigService;
|
import com.yami.shop.service.UserService;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import ma.glasnost.orika.MapperFacade;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 用户聊天群组管理
|
*
|
*/
|
@RestController
|
@RequestMapping("/p/friend")
|
@Tag(name = "聊天好友管理")
|
public class LuckImFriendController {
|
|
@Autowired
|
private ILuckUserFriendService luckUserFriendService;
|
@Autowired
|
private UserService userService;
|
@Autowired
|
private MapperFacade mapperFacade;
|
@Autowired
|
private SysConfigService sysConfigService;
|
@Autowired
|
private QRCodeService qrCodeService;
|
|
@Operation(summary = "获取有效好友列表")
|
@GetMapping(value = "/getUserFriends")
|
public ServerResponseEntity<List<LuckUserFriend>> getUserFriends() {
|
String userId = SecurityUtils.getUser().getUserId();
|
List<LuckUserFriend> list = luckUserFriendService.list(new QueryWrapper<LuckUserFriend>()
|
.eq("user_id", userId)
|
.eq("status", 1)
|
.orderByDesc("create_time"));
|
return ServerResponseEntity.success(list);
|
}
|
|
@Operation(summary = "获取好友申请列表")
|
@GetMapping(value = "/getUserFriendsApply")
|
public ServerResponseEntity<List<LuckUserFriend>> getUserFriendsApply() {
|
String userId = SecurityUtils.getUser().getUserId();
|
List<LuckUserFriend> list = luckUserFriendService.list(new QueryWrapper<LuckUserFriend>()
|
.eq("user_id", userId)
|
.eq("status", 0)
|
.orderByDesc("create_time"));
|
return ServerResponseEntity.success(list);
|
}
|
|
@Operation(summary = "申请好友")
|
@PostMapping(value = "/applyFriend")
|
public ServerResponseEntity<Object> applyFriend(@RequestBody ApplyFriendParam params) {
|
String userId = SecurityUtils.getUser().getUserId();
|
params.setSelfUserId(userId);
|
User user = userService.getOne(new QueryWrapper<User>().eq("user_Mobile", params.getUserMobile()));
|
if (user == null){
|
return ServerResponseEntity.showFailMsg("用户不存在");
|
}
|
if (user.getUserId().equals(user)){
|
return ServerResponseEntity.showFailMsg("不能添加自己为好友");
|
}
|
luckUserFriendService.applyFriend(params);
|
return ServerResponseEntity.success();
|
}
|
|
@Operation(summary = "审核好友")
|
@PostMapping(value = "/auditFriend")
|
public ServerResponseEntity<Object> auditFriend(@RequestBody AuditFriendParam params) {
|
String userId = SecurityUtils.getUser().getUserId();
|
params.setSelfUserId(userId);
|
luckUserFriendService.auditFriend(params);
|
return ServerResponseEntity.success();
|
}
|
|
@Operation(summary = "删除好友")
|
@PostMapping(value = "/deleteById")
|
public ServerResponseEntity<Object> deleteById(@RequestBody ApplyFriendParam params) {
|
String userId = SecurityUtils.getUser().getUserId();
|
params.setSelfUserId(userId);
|
luckUserFriendService.deleteById(params);
|
return ServerResponseEntity.success();
|
}
|
|
@Operation(summary = "搜索好友信息名片")
|
@GetMapping(value = "/friendCard")
|
public ServerResponseEntity<UserDto> friendCard(@RequestParam String userMobile) {
|
User user = userService.getOne(new QueryWrapper<User>().eq("user_Mobile", userMobile));
|
UserDto userDto = mapperFacade.map(user, UserDto.class);
|
return ServerResponseEntity.success(userDto);
|
}
|
|
@Operation(summary = "获取好友信息")
|
@GetMapping(value = "/getFriendInfo")
|
public ServerResponseEntity<LuckUserFriend> getFriendInfo(@RequestParam String friendUserId) {
|
String userId = SecurityUtils.getUser().getUserId();
|
LuckUserFriend luckUserFriend = luckUserFriendService.getOne(new QueryWrapper<LuckUserFriend>()
|
.eq("friend_user_id", friendUserId)
|
.eq("user_id",userId));
|
User user = userService.getOne(new QueryWrapper<User>().eq("user_id", friendUserId));
|
luckUserFriend.setMobile(user.getUserMobile());
|
return ServerResponseEntity.success(luckUserFriend);
|
}
|
|
@Operation(summary = "设置好友信息")
|
@PostMapping(value = "/setFriendRemark")
|
public ServerResponseEntity<Object> setFriendRemark(@RequestBody LuckUserFriend luckUserFriend) {
|
String userId = SecurityUtils.getUser().getUserId();
|
luckUserFriend.setUserId(userId);
|
LambdaUpdateWrapper<LuckUserFriend> queryWrapper = new LambdaUpdateWrapper<>();
|
queryWrapper.eq(LuckUserFriend::getUserId, userId);
|
queryWrapper.eq(LuckUserFriend::getFriendUserId, luckUserFriend.getFriendUserId());
|
if (StringUtils.isNotBlank(luckUserFriend.getRemark())){
|
queryWrapper.set(LuckUserFriend::getRemark, luckUserFriend.getRemark());
|
}
|
if (luckUserFriend.getStatus() != null){
|
queryWrapper.set(LuckUserFriend::getStatus, luckUserFriend.getStatus());
|
}
|
luckUserFriendService.update(queryWrapper);
|
return ServerResponseEntity.success();
|
}
|
|
@Operation(summary = "设置消息免打扰")
|
@PostMapping(value = "/setFriendNoDisturb")
|
public ServerResponseEntity<Object> setFriendNoDisturb(@RequestBody LuckUserFriend luckUserFriend) {
|
String userId = SecurityUtils.getUser().getUserId();
|
LuckUserFriend luckUserFriend1 = new LuckUserFriend();
|
luckUserFriend1.setUserId(userId);
|
luckUserFriend1.setFriendUserId(luckUserFriend.getFriendUserId());
|
luckUserFriend1.setNoDisturb(luckUserFriend.getNoDisturb());
|
luckUserFriendService.update(Wrappers.lambdaUpdate(LuckUserFriend.class)
|
.set(LuckUserFriend::getNoDisturb, luckUserFriend.getNoDisturb())
|
.set(LuckUserFriend::getUpdateTime, new Date())
|
.eq(LuckUserFriend::getUserId, userId)
|
.eq(LuckUserFriend::getFriendUserId, luckUserFriend.getFriendUserId()));
|
return ServerResponseEntity.success();
|
}
|
|
@Operation(summary = "生成二维码")
|
@GetMapping(value = "/createQrCode")
|
public ServerResponseEntity<String> createGroupQrCode() {
|
String userId = SecurityUtils.getUser().getUserId();
|
User user = userService.getOne(new QueryWrapper<User>().eq("user_id", userId));
|
if (StringUtils.isNotBlank(user.getQrCode())){
|
return ServerResponseEntity.success(user.getQrCode());
|
}
|
HuaWeiOss aliOss = sysConfigService.getSysConfigObject(Constant.HUAWEI_OBS_CONFIG, HuaWeiOss.class);
|
String content = "/pages/im/selfIm/userInfo?friendId=" + userId;
|
String qrCodeUrl = qrCodeService.generateQRCodeUrl(content, aliOss);
|
userService.update(Wrappers.lambdaUpdate(User.class)
|
.set(User::getQrCode, qrCodeUrl)
|
.eq(User::getUserId, userId));
|
return ServerResponseEntity.success(qrCodeUrl);
|
}
|
|
}
|