Browse Source

加个接口

master
nili 1 year ago
parent
commit
0380c538f5
  1. 7
      game-dao/src/main/java/awesome/group/game/dao/bean/GameApp.java
  2. 45
      game-service/src/main/java/awesome/group/game/service/AppService.java
  3. 31
      game-service/src/main/java/awesome/group/game/service/bo/AppInfo.java
  4. 5
      game-service/src/main/java/awesome/group/game/service/bo/InviteInfo.java
  5. 25
      game-web/src/main/java/awesome/group/controller/AppController.java
  6. 1
      game-web/src/main/java/awesome/group/interceptor/InterceptorConfig.java

7
game-dao/src/main/java/awesome/group/game/dao/bean/GameApp.java

@ -1,10 +1,17 @@
package awesome.group.game.dao.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
@Data
public class GameApp {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String name;
private String appId;
private String appSecret;
private String icon;
private Integer inAudit;
private String recommend;
}

45
game-service/src/main/java/awesome/group/game/service/AppService.java

@ -0,0 +1,45 @@
package awesome.group.game.service;
import awesome.group.game.dao.bean.GameApp;
import awesome.group.game.dao.mapper.GameAppMapper;
import awesome.group.game.service.bo.AppInfo;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class AppService {
@Autowired
private GameAppMapper appMapper;
public AppInfo get(String appId) {
GameApp app = appMapper.query(appId);
Assert.isTrue(app != null, "非法请求");
AppInfo info = new AppInfo(app);
if (!StringUtils.hasText(app.getRecommend())) {
return info;
}
LambdaQueryWrapper<GameApp> query = Wrappers.lambdaQuery();
Gson gson = new Gson();
List<Integer> recommend = gson.fromJson(app.getRecommend(), new TypeToken<List<Integer>>() {
}.getType());
query.in(GameApp::getId, recommend);
List<GameApp> list = appMapper.selectList(query);
Map<Integer, GameApp> map = list.stream().collect(Collectors.toMap(GameApp::getId, x -> x));
for (Integer id : recommend) {
info.addRecommend(map.get(id));
}
return info;
}
}

31
game-service/src/main/java/awesome/group/game/service/bo/AppInfo.java

@ -0,0 +1,31 @@
package awesome.group.game.service.bo;
import awesome.group.game.dao.bean.GameApp;
import java.util.ArrayList;
import java.util.List;
public class AppInfo {
public String name;
public String icon;
public String appId;
public Integer inAudit;
public List<AppInfo> recommend = new ArrayList<>();
public AppInfo() {
}
public AppInfo(GameApp app) {
this.name = app.getName();
this.icon = app.getIcon();
this.appId = app.getAppId();
this.inAudit = app.getInAudit();
}
public void addRecommend(GameApp app) {
if (app == null) {
return;
}
this.recommend.add(new AppInfo(app));
}
}

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

@ -8,12 +8,9 @@ import java.util.List;
public class InviteInfo {
public int inviteCnt;
public List<InviteUserInfo> list;
public List<InviteUserInfo> list = new ArrayList<>();
public void addInviteUser(WeGameUser user, InviteRecord r) {
if (list == null) {
list = new ArrayList<>();
}
list.add(new InviteUserInfo(user, r.getLastTime().getTime()));
}

25
game-web/src/main/java/awesome/group/controller/AppController.java

@ -0,0 +1,25 @@
package awesome.group.controller;
import awesome.group.aop.RestApi;
import awesome.group.game.service.AppService;
import awesome.group.game.service.bo.AppInfo;
import awesome.group.game.service.common.response.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/game/app")
public class AppController {
@Resource
private AppService appService;
@GetMapping("/info")
@RestApi
public R<AppInfo> getAppInfo(@RequestParam String appId) {
return new R<>(R.CODE_SUCCESS, "ok", appService.get(appId));
}
}

1
game-web/src/main/java/awesome/group/interceptor/InterceptorConfig.java

@ -20,6 +20,7 @@ public class InterceptorConfig implements WebMvcConfigurer {
//拦截的路径
.addPathPatterns("/**")
//不拦截的路径
.excludePathPatterns("/api/game/app/info")
.excludePathPatterns("/api/game/auth/login")
.excludePathPatterns("/api/game/auth/loginV2")
.excludePathPatterns("/api/game/auth/test");

Loading…
Cancel
Save