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. 11
      game-dao/src/main/java/awesome/group/game/dao/mapper/WeGameUserMapper.java
  5. 43
      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 lombok.Data;
import java.sql.Timestamp;
@Data
public class InviteRecord {
@TableId(value = "id", type = IdType.AUTO)
public Integer id;
public Integer userId;
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 Integer score;
private String inviteCode;
private Integer inviteCnt;
public String getNickname() {
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;
public interface InviteRecordMapper extends BaseMapper<InviteRecord> {
@Select("select invited_user_id from invite_record where user_id = #{userId}")
List<Integer> query(@Param("userId") Integer userId);
@Select("select * from invite_record where user_id = #{userId}")
List<InviteRecord> query(@Param("userId") Integer userId);
}

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

@ -10,14 +10,17 @@ import java.util.List;
public interface WeGameUserMapper extends BaseMapper<WeGameUser> {
@Select("select * from we_game_user where app_id = #{appId} and open_id = #{openId}")
WeGameUser query(@Param("appId")String appId, @Param("openId")String openId);
WeGameUser query(@Param("appId") String appId, @Param("openId") String openId);
@Update("update we_game_user set session_key = #{sessionKey} where id = #{id}")
int updateSessionKey(@Param("sessionKey")String sessionKey, @Param("id")Integer id);
int updateSessionKey(@Param("sessionKey") String sessionKey, @Param("id") Integer id);
@Update("update we_game_user set score = #{score} where id = #{id}")
int updateScore(@Param("score")Integer score, @Param("id")Integer id);
int updateScore(@Param("score") Integer score, @Param("id") Integer id);
@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);
}

43
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.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.service.bo.WxUserInfo;
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.service.bo.*;
import awesome.group.game.service.common.exception.PaganiException;
import awesome.group.game.service.common.exception.PaganiExceptionCode;
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.StringUtils;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class WxService {
@ -58,15 +59,23 @@ public class WxService {
inviteRecordMapper.insert(record);
}
public List<UserInfo> myInviteRecord(Integer userId) {
List<Integer> list = inviteRecordMapper.query(userId);
public InviteInfo myInviteRecord(Integer userId) {
List<InviteRecord> list = inviteRecordMapper.query(userId);
WeGameUser u = weGameUserMapper.selectById(userId);
InviteInfo info = new InviteInfo();
info.inviteCnt = u.getInviteCnt();
if (CollectionUtils.isEmpty(list)) {
return new ArrayList<>();
return info;
}
List<Integer> uids = list.stream().map(InviteRecord::getInvitedUserId).toList();
LambdaQueryWrapper<WeGameUser> query = Wrappers.lambdaQuery();
query.in(WeGameUser::getId, list);
query.in(WeGameUser::getId, uids);
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) {
@ -111,13 +120,21 @@ public class WxService {
LambdaQueryWrapper<InviteRecord> inviteQuery = Wrappers.lambdaQuery();
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;
}
InviteRecord record = new InviteRecord();
record.userId = user.getId();
record.invitedUserId = u.getId();
inviteRecordMapper.insert(record);
if (record == null) {
record = new InviteRecord();
record.userId = user.getId();
record.invitedUserId = u.getId();
record.lastTime = new Timestamp(System.currentTimeMillis());
inviteRecordMapper.insert(record);
} else {
record.lastTime = new Timestamp(System.currentTimeMillis());
inviteRecordMapper.updateById(record);
}
weGameUserMapper.addInviteCnt(user.getId());
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.game.service.WxService;
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.RankList;
import awesome.group.game.service.bo.UserInfo;
import awesome.group.game.service.common.response.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/game/auth")
public class LoginController {
@ -54,7 +52,7 @@ public class LoginController {
@GetMapping("/myInviteRecord")
@RestApi
public R<List<UserInfo>> myInviteRecord() {
public R<InviteInfo> myInviteRecord() {
Integer userId = RequestContext.getUid();
return new R<>(R.CODE_SUCCESS, "", wxService.myInviteRecord(userId));
}

Loading…
Cancel
Save