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);
|
}
|
|
|
}
|