Browse Source

白名单

master
nili 8 months ago
parent
commit
b4df0e3b67
  1. 3
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixApp.java
  2. 10
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdvRecordMapper.java
  3. 3
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAppMapper.java
  4. 26
      game-service/src/main/java/awesome/group/game/service/MatrixService.java
  5. 13
      game-web/src/main/java/awesome/group/controller/MatrixController.java

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

@ -11,5 +11,6 @@ public class MatrixApp {
private String name; private String name;
private String code; private String code;
private String url; private String url;
private Integer income; private Integer income;//分
private String channel;
} }

10
game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdvRecordMapper.java

@ -2,15 +2,17 @@ package awesome.group.game.dao.mapper;
import awesome.group.game.dao.bean.MatrixAdvRecord; import awesome.group.game.dao.bean.MatrixAdvRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface MatrixAdvRecordMapper extends BaseMapper<MatrixAdvRecord> { public interface MatrixAdvRecordMapper extends BaseMapper<MatrixAdvRecord> {
@Select("select id from matrix_app where code = #{code}") @Select("select id from matrix_app where code = #{code}")
Integer queryAppId(String code); Integer queryAppId(String code);
@Select("select device_id from matrix_white_device") @Select("select count(*) from matrix_white_device")
List<String> queryWhitelist(); Integer queryWhitelist(String channel, String deviceId);
@Insert("insert ignore into matrix_white_device (channel, device_id) values (#{channel}, #{deviceId})")
void insertWhiteList(String channel, String deviceId);
} }

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

@ -2,6 +2,9 @@ package awesome.group.game.dao.mapper;
import awesome.group.game.dao.bean.MatrixApp; import awesome.group.game.dao.bean.MatrixApp;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
public interface MatrixAppMapper extends BaseMapper<MatrixApp> { public interface MatrixAppMapper extends BaseMapper<MatrixApp> {
@Select("select * from matrix_app where code = #{code}")
MatrixApp queryByCode(String code);
} }

26
game-service/src/main/java/awesome/group/game/service/MatrixService.java

@ -1,21 +1,24 @@
package awesome.group.game.service; package awesome.group.game.service;
import awesome.group.game.dao.bean.MatrixAdvRecord; import awesome.group.game.dao.bean.MatrixAdvRecord;
import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.mapper.MatrixAdvRecordMapper; import awesome.group.game.dao.mapper.MatrixAdvRecordMapper;
import awesome.group.game.dao.mapper.MatrixAppMapper;
import awesome.group.game.service.bo.MatrixAdvRecordEditBo; import awesome.group.game.service.bo.MatrixAdvRecordEditBo;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.List;
@Service @Service
public class MatrixService { public class MatrixService {
@Resource @Resource
private MatrixAdvRecordMapper mapper; private MatrixAdvRecordMapper mapper;
@Resource
private MatrixAppMapper appMapper;
public void saveRecord(MatrixAdvRecordEditBo bo, String ip) { public void saveRecord(MatrixAdvRecordEditBo bo, String ip) {
Assert.isTrue(StringUtils.hasText(bo.appCode), "appCode不能为空"); Assert.isTrue(StringUtils.hasText(bo.appCode), "appCode不能为空");
Integer appId = mapper.queryAppId(bo.appCode); Integer appId = mapper.queryAppId(bo.appCode);
@ -34,7 +37,22 @@ public class MatrixService {
mapper.insert(record); mapper.insert(record);
} }
public List<String> whiteList() { public boolean whiteList(String deviceId, String appCode) {
return mapper.queryWhitelist(); MatrixApp app = appMapper.queryByCode(appCode);
if (app == null) {
return false;
}
return mapper.queryWhitelist(app.getChannel(), deviceId) > 0;
}
public void addIntoWhiteList(String deviceId, String appCode) {
MatrixApp app = appMapper.queryByCode(appCode);
if (app == null) {
return;
}
if (mapper.queryWhitelist(app.getChannel(), deviceId) > 0) {
return;
}
mapper.insertWhiteList(app.getChannel(), deviceId);
} }
} }

13
game-web/src/main/java/awesome/group/controller/MatrixController.java

@ -8,8 +8,6 @@ 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/matrix") @RequestMapping("/api/game/matrix")
public class MatrixController { public class MatrixController {
@ -25,7 +23,14 @@ public class MatrixController {
@GetMapping("/whiteList") @GetMapping("/whiteList")
@RestApi @RestApi
public R<List<String>> whiteList(){ public R<Boolean> whiteList(@RequestParam String deviceId, @RequestParam String appCode){
return new R<>(R.CODE_SUCCESS, "ok", matrixService.whiteList()); return new R<>(R.CODE_SUCCESS, "ok", matrixService.whiteList(deviceId, appCode));
}
@PostMapping("/addWhiteList")
@RestApi
public R<Void> addWhiteList(@RequestParam String deviceId, @RequestParam String appCode){
matrixService.addIntoWhiteList(deviceId, appCode);
return new R<>(R.CODE_SUCCESS, "ok", null);
} }
} }

Loading…
Cancel
Save