nili
1 year ago
6 changed files with 110 additions and 4 deletions
@ -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; |
|||
} |
|||
|
@ -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; |
|||
} |
|||
} |
@ -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)); |
|||
} |
|||
} |
@ -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)); |
|||
} |
|||
} |
Loading…
Reference in new issue