基于mall4j产品的二开项目后端
lee
2024-12-18 efdb99f8cecc4afb592afad79c761081d5d5cf22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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);
    }
 
}