admin
2022-04-26 36681e15e12aaa9135f69260472de65303cdcba3
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package com.yeshi.makemoney.app.controller.client.api;
 
import com.yeshi.makemoney.app.entity.team.TeamInviteRelation;
import com.yeshi.makemoney.app.entity.team.UserSpreadImg;
import com.yeshi.makemoney.app.entity.user.UserInfo;
import com.yeshi.makemoney.app.exception.team.SpreadImgException;
import com.yeshi.makemoney.app.exception.team.TeamInviteRelationException;
import com.yeshi.makemoney.app.exception.team.UserSpreadImgException;
import com.yeshi.makemoney.app.exception.user.UserInfoException;
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetRecordService;
import com.yeshi.makemoney.app.service.inter.team.TeamInviteRelationService;
import com.yeshi.makemoney.app.service.inter.team.UserSpreadImgService;
import com.yeshi.makemoney.app.service.inter.user.UserExtraInfoService;
import com.yeshi.makemoney.app.service.inter.user.UserInfoService;
import com.yeshi.makemoney.app.service.inter.user.WXUserInfoService;
import com.yeshi.makemoney.app.utils.Constant;
import com.yeshi.makemoney.app.utils.annotation.UserLogin;
import com.yeshi.makemoney.app.vo.AcceptData;
import com.yeshi.makemoney.app.vo.team.TeamInfoVO;
import com.yeshi.makemoney.app.vo.team.TeamMemberListVO;
import com.yeshi.makemoney.app.vo.user.UserInfoVO;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.TimeUtil;
 
import javax.annotation.Resource;
import java.util.*;
 
/**
 * @author hxh
 * @title: TeamController
 * @description: 团队接口
 * @date 2021/11/16 17:37
 */
@Controller
@RequestMapping("api/v1/team")
public class TeamController {
 
    @Resource
    private UserInfoService userInfoService;
 
    @Resource
    private UserExtraInfoService userExtraInfoService;
 
    @Resource
    private TeamInviteRelationService teamInviteRelationService;
 
    @Resource
    private GoldCornGetRecordService goldCornGetRecordService;
 
    @Resource
    private UserSpreadImgService userSpreadImgService;
 
 
    /**
     * @return java.lang.String
     * @author hxh
     * @description 获取上级
     * @date 12:13 2022/4/20
     * @param: acceptData
     * @param: uid
     * @param: inviteCode
     **/
    @UserLogin(uid = "#uid")
    @ResponseBody
    @RequestMapping("getUserByInviteCode")
    public String getUserByInviteCode(AcceptData acceptData, Long uid, String inviteCode) {
 
        Long uID = userExtraInfoService.selectUidByInviteCode(inviteCode.toUpperCase());
        if (uID == null) {
            return JsonUtil.loadFalseResult("用户不存在");
        }
 
        if (uID.longValue() == uid) {
            return JsonUtil.loadFalseResult("不能输入自己的邀请码");
        }
 
        UserInfo user = userInfoService.getAvaiableUser(uID);
        if (user == null || user.getSystem() != acceptData.getSystem()) {
            return JsonUtil.loadFalseResult("用户不存在或被封禁");
        }
        return JsonUtil.loadTrueResult(UserInfoVO.create(user));
    }
 
    /**
     * @return java.lang.String
     * @author hxh
     * @description 加入团队
     * @date 12:13 2022/4/20
     * @param: acceptData
     * @param: uid
     * @param: bossUid
     **/
    @UserLogin(uid = "#uid")
    @ResponseBody
    @RequestMapping("joinTeam")
    public String joinTeam(AcceptData acceptData, Long uid, Long bossUid) {
 
        if (bossUid.longValue() == uid) {
            return JsonUtil.loadFalseResult("不能加入自己的团队");
        }
 
        //是否已经有上级
        Long buid = teamInviteRelationService.getBossUid(uid);
        if (buid != null) {
            if (bossUid.longValue() != buid) {
                return JsonUtil.loadFalseResult("已经加入别的团队");
            }
        }
        UserInfo bossUser = userInfoService.getAvaiableUser(bossUid);
        if (bossUser == null || bossUser.getSystem() != acceptData.getSystem()) {
            return JsonUtil.loadFalseResult("用户不存在或被封禁");
        }
        //加入团队
        if (buid == null) {
            TeamInviteRelation teamInviteRelation = new TeamInviteRelation();
            teamInviteRelation.setUid(bossUid);
            teamInviteRelation.setTargetUid(uid);
            try {
                teamInviteRelationService.add(teamInviteRelation);
            } catch (TeamInviteRelationException e) {
                return JsonUtil.loadFalseResult("加入出错");
            }
        }
 
        return JsonUtil.loadTrueResult(UserInfoVO.create(bossUser));
    }
 
 
    @UserLogin(uid = "#uid")
    @ResponseBody
    @RequestMapping("getTeamInfo")
    public String getTeamInfo(AcceptData acceptData, Long uid) {
        TeamInfoVO vo = new TeamInfoVO();
        vo.setHasBoss(teamInviteRelationService.getBossUid(uid) != null);
        long first = teamInviteRelationService.countFirstTeam(uid);
        long second = teamInviteRelationService.countSecondTeam(uid);
        vo.setFirstTeamCount((int) first);
        vo.setSecondTeamCount((int) second);
        return JsonUtil.loadTrueResult(vo);
    }
 
 
    @UserLogin(uid = "#uid")
    @ResponseBody
    @RequestMapping("getMyBossInfo")
    public String getMyBossInfo(AcceptData acceptData, Long uid) {
 
        Long bossUid = teamInviteRelationService.getBossUid(uid);
        if (bossUid == null) {
            return JsonUtil.loadFalseResult("邀请人不存在");
        }
        UserInfo user = userInfoService.get(bossUid);
        if (user == null) {
            return JsonUtil.loadFalseResult("邀请人不存在");
        }
 
        return JsonUtil.loadTrueResult(UserInfoVO.create(user));
    }
 
 
    /**
     * @return java.lang.String
     * @author hxh
     * @description 获取我的队员列表
     * @date 15:12 2022/4/20
     * @param: acceptData
     * @param: uid
     * @param: first
     **/
    @UserLogin(uid = "#uid")
    @ResponseBody
    @RequestMapping("getMyTeamList")
    public String getMyTeamList(AcceptData acceptData, Long uid, boolean first, int page) {
        String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd");
        long count = 0;
        List<TeamInviteRelation> list = null;
        if (first) {
            list = teamInviteRelationService.getFirstTeamList(uid, page, Constant.PAGE_SIZE);
            count = teamInviteRelationService.countFirstTeam(uid);
        } else {
            list = teamInviteRelationService.getSecondTeamList(uid, page, Constant.PAGE_SIZE);
            count = teamInviteRelationService.countSecondTeam(uid);
        }
 
        List<Long> uidList = new ArrayList<>();
        List<Long> bossUidList = new ArrayList<>();
        if (list != null) {
            for (TeamInviteRelation relation : list) {
                uidList.add(relation.getTargetUid());
                //不是自己直接邀请的用户
                if (!bossUidList.contains(relation.getUid()) && relation.getUid().longValue() != uid) {
                    bossUidList.add(relation.getUid());
                }
            }
        }
        //查询个人信息
 
        Set<Long> uids = new HashSet<>();
        uids.addAll(uidList);
        uids.addAll(bossUidList);
        List<UserInfo> userInfoList = userInfoService.list(uids);
        Map<Long, UserInfo> userMap = new HashMap<>();
        for (UserInfo user : userInfoList) {
            userMap.put(user.getId(), user);
        }
 
        //查询赚取金币信息
        Map<Long, Integer> goldCornMap = goldCornGetRecordService.sumGoldCornByFromUids(uid, uidList, day);
 
        List<TeamMemberListVO> voList = new ArrayList<>();
        for (TeamInviteRelation relation : list) {
            //组织数据
            TeamMemberListVO vo = new TeamMemberListVO();
            vo.setJoinTime(TimeUtil.getGernalTime(relation.getCreateTime().getTime(), "yyyy.MM.dd"));
            if (uid.longValue() != relation.getUid()) {
                vo.setTag(String.format("由\"%s\"邀请", userMap.get(relation.getUid()).getNickName()));
            }
            vo.setTodayGoldCorn(goldCornMap.get(relation.getTargetUid()));
            vo.setUser(UserInfoVO.create(userMap.get(relation.getTargetUid())));
            voList.add(vo);
        }
        JSONObject data = new JSONObject();
        data.put("count", count);
        data.put("list", JsonUtil.getSimpleGson().toJson(voList));
        return JsonUtil.loadTrueResult(data);
    }
 
    /**
     * @return java.lang.String
     * @author hxh
     * @description 获取邀请图
     * @date 16:41 2022/4/20
     * @param: acceptData
     * @param: uid
     **/
    @UserLogin(uid = "#uid")
    @ResponseBody
    @RequestMapping("getSpreadImgs")
    public String getSpreadImgs(AcceptData acceptData, Long uid) {
        //先绘图
        try {
            userSpreadImgService.drawImgs(uid);
        } catch (UserInfoException e) {
            e.printStackTrace();
        } catch (SpreadImgException e) {
            e.printStackTrace();
        } catch (UserSpreadImgException e) {
            e.printStackTrace();
        }
        List<UserSpreadImg> list = userSpreadImgService.getUserSpreadImgs(uid);
        List<String> urlList = new ArrayList<>();
        if (list != null) {
            for (UserSpreadImg img : list) {
                urlList.add(img.getUrl());
            }
        }
 
        if (urlList.size() == 0) {
            return JsonUtil.loadFalseResult("无分享图");
        }
 
        JSONObject data=new JSONObject();
        data.put("list",urlList);
 
        return JsonUtil.loadTrueResult(data);
    }
 
 
}