Browse Source

邀请fx

master
nili 1 year ago
parent
commit
98a4374954
  1. 3
      game-dao/src/main/java/awesome/group/game/dao/bean/InviteRecord.java
  2. 1
      game-dao/src/main/java/awesome/group/game/dao/bean/WeGameUser.java
  3. 4
      game-dao/src/main/java/awesome/group/game/dao/mapper/InviteRecordMapper.java
  4. 3
      game-dao/src/main/java/awesome/group/game/dao/mapper/WeGameUserMapper.java
  5. 37
      game-service/src/main/java/awesome/group/game/service/WxService.java
  6. 28
      game-service/src/main/java/awesome/group/game/service/bo/InviteInfo.java
  7. 6
      game-web/src/main/java/awesome/group/controller/LoginController.java

3
game-dao/src/main/java/awesome/group/game/dao/bean/InviteRecord.java

@ -4,10 +4,13 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data; import lombok.Data;
import java.sql.Timestamp;
@Data @Data
public class InviteRecord { public class InviteRecord {
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
public Integer id; public Integer id;
public Integer userId; public Integer userId;
public Integer invitedUserId; public Integer invitedUserId;
public Timestamp lastTime;
} }

1
game-dao/src/main/java/awesome/group/game/dao/bean/WeGameUser.java

@ -21,6 +21,7 @@ public class WeGameUser {
private String sessionKey; private String sessionKey;
private Integer score; private Integer score;
private String inviteCode; private String inviteCode;
private Integer inviteCnt;
public String getNickname() { public String getNickname() {
if (StringUtils.hasText(nickname)) { if (StringUtils.hasText(nickname)) {

4
game-dao/src/main/java/awesome/group/game/dao/mapper/InviteRecordMapper.java

@ -8,6 +8,6 @@ import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
public interface InviteRecordMapper extends BaseMapper<InviteRecord> { public interface InviteRecordMapper extends BaseMapper<InviteRecord> {
@Select("select invited_user_id from invite_record where user_id = #{userId}") @Select("select * from invite_record where user_id = #{userId}")
List<Integer> query(@Param("userId") Integer userId); List<InviteRecord> query(@Param("userId") Integer userId);
} }

3
game-dao/src/main/java/awesome/group/game/dao/mapper/WeGameUserMapper.java

@ -20,4 +20,7 @@ public interface WeGameUserMapper extends BaseMapper<WeGameUser> {
@Select("select * from we_game_user where app_id = #{appId} and score > 0 order by score desc limit #{size}") @Select("select * from we_game_user where app_id = #{appId} and score > 0 order by score desc limit #{size}")
List<WeGameUser> queryTop(@Param("appId") String appId, @Param("size") Integer size); List<WeGameUser> queryTop(@Param("appId") String appId, @Param("size") Integer size);
@Update("update we_game_user set invite_cnt = invite_cnt + 1 where id = #{userId}")
int addInviteCnt(@Param("userId") Integer userId);
} }

37
game-service/src/main/java/awesome/group/game/service/WxService.java

@ -3,12 +3,11 @@ package awesome.group.game.service;
import awesome.group.game.dao.bean.GameApp; import awesome.group.game.dao.bean.GameApp;
import awesome.group.game.dao.bean.InviteRecord; import awesome.group.game.dao.bean.InviteRecord;
import awesome.group.game.dao.mapper.InviteRecordMapper;
import awesome.group.game.service.bo.*;
import awesome.group.game.dao.bean.WeGameUser; import awesome.group.game.dao.bean.WeGameUser;
import awesome.group.game.service.bo.WxUserInfo;
import awesome.group.game.dao.mapper.GameAppMapper; import awesome.group.game.dao.mapper.GameAppMapper;
import awesome.group.game.dao.mapper.InviteRecordMapper;
import awesome.group.game.dao.mapper.WeGameUserMapper; import awesome.group.game.dao.mapper.WeGameUserMapper;
import awesome.group.game.service.bo.*;
import awesome.group.game.service.common.exception.PaganiException; import awesome.group.game.service.common.exception.PaganiException;
import awesome.group.game.service.common.exception.PaganiExceptionCode; import awesome.group.game.service.common.exception.PaganiExceptionCode;
import awesome.group.game.service.util.EncryptUtil; import awesome.group.game.service.util.EncryptUtil;
@ -24,10 +23,12 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
public class WxService { public class WxService {
@ -58,15 +59,23 @@ public class WxService {
inviteRecordMapper.insert(record); inviteRecordMapper.insert(record);
} }
public List<UserInfo> myInviteRecord(Integer userId) { public InviteInfo myInviteRecord(Integer userId) {
List<Integer> list = inviteRecordMapper.query(userId); List<InviteRecord> list = inviteRecordMapper.query(userId);
WeGameUser u = weGameUserMapper.selectById(userId);
InviteInfo info = new InviteInfo();
info.inviteCnt = u.getInviteCnt();
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>(); return info;
} }
List<Integer> uids = list.stream().map(InviteRecord::getInvitedUserId).toList();
LambdaQueryWrapper<WeGameUser> query = Wrappers.lambdaQuery(); LambdaQueryWrapper<WeGameUser> query = Wrappers.lambdaQuery();
query.in(WeGameUser::getId, list); query.in(WeGameUser::getId, uids);
List<WeGameUser> data = weGameUserMapper.selectList(query); List<WeGameUser> data = weGameUserMapper.selectList(query);
return data.stream().map(UserInfo::new).toList(); Map<Integer, WeGameUser> map = data.stream().collect(Collectors.toMap(WeGameUser::getId, x -> x));
for (InviteRecord x : list) {
info.addInviteUser(map.get(x.invitedUserId),x);
}
return info;
} }
public WeGameUser login(String code, String appId) { public WeGameUser login(String code, String appId) {
@ -111,13 +120,21 @@ public class WxService {
LambdaQueryWrapper<InviteRecord> inviteQuery = Wrappers.lambdaQuery(); LambdaQueryWrapper<InviteRecord> inviteQuery = Wrappers.lambdaQuery();
inviteQuery.eq(InviteRecord::getInvitedUserId, u.getId()); inviteQuery.eq(InviteRecord::getInvitedUserId, u.getId());
if (inviteRecordMapper.selectOne(inviteQuery) != null) { InviteRecord record = inviteRecordMapper.selectOne(inviteQuery);
if (record != null && record.lastTime.getTime() + 3600_000 < System.currentTimeMillis()) {
return res; return res;
} }
InviteRecord record = new InviteRecord(); if (record == null) {
record = new InviteRecord();
record.userId = user.getId(); record.userId = user.getId();
record.invitedUserId = u.getId(); record.invitedUserId = u.getId();
record.lastTime = new Timestamp(System.currentTimeMillis());
inviteRecordMapper.insert(record); inviteRecordMapper.insert(record);
} else {
record.lastTime = new Timestamp(System.currentTimeMillis());
inviteRecordMapper.updateById(record);
}
weGameUserMapper.addInviteCnt(user.getId());
return res; return res;
} }

28
game-service/src/main/java/awesome/group/game/service/bo/InviteInfo.java

@ -0,0 +1,28 @@
package awesome.group.game.service.bo;
import awesome.group.game.dao.bean.InviteRecord;
import awesome.group.game.dao.bean.WeGameUser;
import java.util.ArrayList;
import java.util.List;
public class InviteInfo {
public int inviteCnt;
public List<InviteUserInfo> list;
public void addInviteUser(WeGameUser user, InviteRecord r) {
if (list == null) {
list = new ArrayList<>();
}
list.add(new InviteUserInfo(user, r.getLastTime().getTime()));
}
public static class InviteUserInfo extends UserInfo {
public Long lastTime;
public InviteUserInfo(WeGameUser user, Long lastTime) {
super(user);
this.lastTime = lastTime;
}
}
}

6
game-web/src/main/java/awesome/group/controller/LoginController.java

@ -4,15 +4,13 @@ import awesome.group.RequestContext;
import awesome.group.aop.RestApi; import awesome.group.aop.RestApi;
import awesome.group.game.service.WxService; import awesome.group.game.service.WxService;
import awesome.group.game.service.bo.CurrentUser; import awesome.group.game.service.bo.CurrentUser;
import awesome.group.game.service.bo.InviteInfo;
import awesome.group.game.service.bo.LoginBo; import awesome.group.game.service.bo.LoginBo;
import awesome.group.game.service.bo.RankList; import awesome.group.game.service.bo.RankList;
import awesome.group.game.service.bo.UserInfo;
import awesome.group.game.service.common.response.R; import awesome.group.game.service.common.response.R;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController @RestController
@RequestMapping("/api/game/auth") @RequestMapping("/api/game/auth")
public class LoginController { public class LoginController {
@ -54,7 +52,7 @@ public class LoginController {
@GetMapping("/myInviteRecord") @GetMapping("/myInviteRecord")
@RestApi @RestApi
public R<List<UserInfo>> myInviteRecord() { public R<InviteInfo> myInviteRecord() {
Integer userId = RequestContext.getUid(); Integer userId = RequestContext.getUid();
return new R<>(R.CODE_SUCCESS, "", wxService.myInviteRecord(userId)); return new R<>(R.CODE_SUCCESS, "", wxService.myInviteRecord(userId));
} }

Loading…
Cancel
Save