Browse Source

设备主及相关功能

master
nili 9 months ago
parent
commit
54d023894f
  1. 3
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixAdmin.java
  2. 19
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixAdminDevice.java
  3. 1
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixAdvRecord.java
  4. 14
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdminDeviceMapper.java
  5. 2
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAppMapper.java
  6. 92
      game-service/src/main/java/awesome/group/game/service/AdminDeviceService.java
  7. 10
      game-service/src/main/java/awesome/group/game/service/AdminService.java
  8. 7
      game-service/src/main/java/awesome/group/game/service/MatrixService.java
  9. 2
      game-service/src/main/java/awesome/group/game/service/bo/MatrixAdminBo.java
  10. 10
      game-web/src/main/java/awesome/group/game/web/controller/MatrixController.java
  11. 7
      game-web/src/main/java/awesome/group/game/web/filter/LoginFilter.java
  12. 4
      game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java
  13. 34
      game-web/src/main/java/awesome/group/game/web/rest/matrix/DeviceController.java

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

@ -13,4 +13,7 @@ public class MatrixAdmin {
private String appIds;
private Integer role;//1超级管理员,2管理员,3普通账号
private String channel;//fanmiyou,qiji
private Integer parentAdminId;
private Integer deviceCnt;
private Integer incomeRate;
}

19
game-dao/src/main/java/awesome/group/game/dao/bean/MatrixAdminDevice.java

@ -0,0 +1,19 @@
package awesome.group.game.dao.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class MatrixAdminDevice {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String deviceId;
private Integer appId;
private Integer adminId;
private Integer status;//0默认,-1下线
private Timestamp createdAt;
private Timestamp updatedAt;
}

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

@ -19,6 +19,7 @@ public class MatrixAdvRecord {
private String deviceBrand;
private String deviceName;
private String ip;
private Integer adminId;
private Timestamp createdAt;
}

14
game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdminDeviceMapper.java

@ -0,0 +1,14 @@
package awesome.group.game.dao.mapper;
import awesome.group.game.dao.bean.MatrixAdminDevice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
public interface MatrixAdminDeviceMapper extends BaseMapper<MatrixAdminDevice> {
@Select("select * from matrix_admin_device where device_id = #{deviceId}")
MatrixAdminDevice selectByDeviceId(String deviceId);
@Update("update matrix_admin_device set status = #{status} where admin_id=#{adminId} and device_id = #{deviceId}")
int updateStatusByDeviceId(int status, String deviceId, int adminId);
}

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

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

92
game-service/src/main/java/awesome/group/game/service/AdminDeviceService.java

@ -0,0 +1,92 @@
package awesome.group.game.service;
import awesome.group.game.dao.bean.MatrixAdmin;
import awesome.group.game.dao.bean.MatrixAdminDevice;
import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.mapper.MatrixAdminDeviceMapper;
import awesome.group.game.dao.mapper.MatrixAdminMapper;
import awesome.group.game.dao.mapper.MatrixAppMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.Arrays;
import java.util.List;
@Service
public class AdminDeviceService {
public static final int STATUS_DEFAULT = 0;
public static final int STATUS_OFFLINE = -1;
@Autowired
private MatrixAdminDeviceMapper mapper;
@Autowired
private MatrixAdminMapper adminMapper;
@Autowired
private MatrixAppMapper appMapper;
public Integer getAdminId(String deviceId) {
MatrixAdminDevice device = mapper.selectByDeviceId(deviceId);
if (device == null || device.getStatus() == STATUS_OFFLINE) {
return null;
}
return device.getAdminId();
}
public List<MatrixAdminDevice> getDeviceList(Integer adminId, String appCode ) {
MatrixApp app = appMapper.queryByCode(appCode);
Assert.isTrue(app != null, "非法请求");
LambdaQueryWrapper<MatrixAdminDevice> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MatrixAdminDevice::getAdminId, adminId);
queryWrapper.eq(MatrixAdminDevice::getAppId, app.getId());
return mapper.selectList(queryWrapper);
}
public void setStatusOffline(Integer adminId, String deviceId) {
mapper.updateStatusByDeviceId(STATUS_OFFLINE, deviceId, adminId);
}
public String bind(String deviceId, String appCode, String adminName) {
MatrixAdminDevice device = mapper.selectByDeviceId(deviceId);
if(device != null){
return "设备已绑定";
}
MatrixAdmin admin = adminMapper.query(adminName);
if (admin == null || admin.getRole() != AdminService.DEVICE_OWNER) {
return "设备主不存在";
}
MatrixApp app = appMapper.queryByCode(appCode);
if (app == null) {
return "应用不存在";
}
if(!StringUtils.hasText(admin.getAppIds()) ||
!Arrays.stream(admin.getAppIds().split(",")).map(Integer::parseInt).toList().contains(app.getId())){
return "无权限绑定该应用";
}
long cnt = queryBindCnt(admin.getId(), app.getId());
if (cnt >= admin.getDeviceCnt()) {
return "绑定设备数已达上限";
}
device = new MatrixAdminDevice();
device.setDeviceId(deviceId);
device.setAppId(app.getId());
device.setAdminId(admin.getId());
device.setStatus(STATUS_DEFAULT);
mapper.insert(device);
return "绑定成功";
}
public long queryBindCnt(int adminId, int appId){
LambdaQueryWrapper<MatrixAdminDevice> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MatrixAdminDevice::getAdminId, adminId);
queryWrapper.eq(MatrixAdminDevice::getAppId, appId);
queryWrapper.eq(MatrixAdminDevice::getStatus, STATUS_DEFAULT);
return mapper.selectCount(queryWrapper);
}
}

10
game-service/src/main/java/awesome/group/game/service/AdminService.java

@ -79,6 +79,10 @@ public class AdminService {
if (app.isEmpty()) {
return null;
}
MatrixAdmin admin = adminMapper.selectById(adminId);
if (admin.getRole() == DEVICE_OWNER) {
wrapper.eq(MatrixAdvRecord::getAdminId, adminId);
}
wrapper.eq(MatrixAdvRecord::getAppId, app.get().getId());
if (param.advType != null) {
wrapper.eq(MatrixAdvRecord::getAdvType, param.advType);
@ -132,20 +136,22 @@ public class AdminService {
adminMapper.updateAppIds(str, adminId);
}
public List<MatrixAdminBo> adminList(String channel) {
public List<MatrixAdminBo> adminList(int adminId, String channel) {
LambdaQueryWrapper<MatrixAdmin> query = Wrappers.lambdaQuery();
query.eq(MatrixAdmin::getChannel, channel);
query.eq(MatrixAdmin::getParentAdminId, adminId);
List<MatrixAdmin> res = adminMapper.selectList(query);
return res.stream().map(MatrixAdminBo::new).toList();
}
public void saveAdmin(MatrixAdminBo bo, String channel) {
public void saveAdmin(int adminId, MatrixAdminBo bo, String channel) {
MatrixAdmin admin = new MatrixAdmin();
BeanUtils.copyProperties(bo, admin);
if (!CollectionUtils.isEmpty(bo.getAppIds())) {
admin.setAppIds(Joiner.on(",").join(bo.getAppIds()));
}
admin.setParentAdminId(adminId);
admin.setChannel(channel);
if (admin.getId() != null) {
if (StringUtils.hasText(admin.getPassword())) {

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

@ -20,12 +20,16 @@ public class MatrixService {
@Resource
private MatrixAppMapper appMapper;
@Resource
private AdminDeviceService adminDeviceService;
public void saveRecord(MatrixAdvRecordEditBo bo, String ip) {
Assert.isTrue(StringUtils.hasText(bo.appCode), "appCode不能为空");
MatrixApp app = mapper.queryApp(bo.appCode);
if (app == null) {
return;//非法请求,直接忽略
}
MatrixAdvRecord record = new MatrixAdvRecord();
record.setDeviceId(bo.deviceId);
record.setAppId(app.getId());
@ -36,6 +40,9 @@ public class MatrixService {
record.setDeviceName(bo.deviceName);
record.setIp(ip);
record.setAdvId(bo.advId);
Integer adminId = adminDeviceService.getAdminId(bo.deviceId);
record.setAdminId(adminId);
mapper.insert(record);
}

2
game-service/src/main/java/awesome/group/game/service/bo/MatrixAdminBo.java

@ -15,6 +15,8 @@ public class MatrixAdminBo {
private String password;
private List<Integer> appIds;
private Integer role;//1超级管理员,2管理员,3普通账号
private Integer deviceCnt;
private Integer incomeRate;
public MatrixAdminBo() {
}

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

@ -1,5 +1,6 @@
package awesome.group.game.web.controller;
import awesome.group.game.service.AdminDeviceService;
import awesome.group.game.web.RequestContext;
import awesome.group.game.web.aop.RestApi;
import awesome.group.game.service.MatrixService;
@ -14,6 +15,9 @@ public class MatrixController {
@Resource
private MatrixService matrixService;
@Resource
private AdminDeviceService deviceService;
@PostMapping("/saveAdvRecord")
@RestApi
public R<Void> saveAdvRecord(@RequestBody MatrixAdvRecordEditBo bo) {
@ -40,4 +44,10 @@ public class MatrixController {
matrixService.addIntoWhiteList(deviceId, appCode);
return new R<>(R.CODE_SUCCESS, "ok", null);
}
@PostMapping("/bindDevice")
@RestApi
public R<String> bindDevice(@RequestParam String deviceId, @RequestParam String appCode, @RequestParam String adminName){
return new R<>(R.CODE_SUCCESS, "ok", deviceService.bind(deviceId, appCode, adminName));
}
}

7
game-web/src/main/java/awesome/group/game/web/filter/LoginFilter.java

@ -18,7 +18,7 @@ import java.util.List;
/**
* @author nidaren
*/
@WebFilter(filterName = "ContextFilter", urlPatterns = {"/api/game/*"})
@WebFilter(filterName = "ContextFilter", urlPatterns = {"/api/game/auth"})
public class LoginFilter implements Filter {
@ -33,14 +33,9 @@ public class LoginFilter implements Filter {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String token = httpRequest.getHeader("Authorization");
List<String> openApi = List.of(
"/api/game/user/demo",
"/api/game/app/info",
"/api/game/auth/login",
"/api/game/auth/loginV2",
"/api/game/auth/loginV3",
"/api/game/matrix/saveAdvRecord",
"/api/game/matrix/whiteList",
"/api/game/matrix/addWhiteList",
"/api/game/auth/test");
boolean pass = false;
Integer userId = null;

4
game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java

@ -64,13 +64,13 @@ public class AdminController {
@GetMapping("/adminList")
@RestApi
public R<List<MatrixAdminBo>> adminList() {
return new R<>(R.CODE_SUCCESS, "ok", adminService.adminList(RequestContext.getRequestChannel()));
return new R<>(R.CODE_SUCCESS, "ok", adminService.adminList(RequestContext.getAdminID(),RequestContext.getRequestChannel()));
}
@PostMapping("/saveAdmin")
@RestApi
public R<Void> saveAdmin(@RequestBody MatrixAdminBo matrixAdmin) {
adminService.saveAdmin(matrixAdmin, RequestContext.getRequestChannel());
adminService.saveAdmin(RequestContext.getAdminID(),matrixAdmin, RequestContext.getRequestChannel());
return new R<>(R.CODE_SUCCESS, "ok", null);
}

34
game-web/src/main/java/awesome/group/game/web/rest/matrix/DeviceController.java

@ -0,0 +1,34 @@
package awesome.group.game.web.rest.matrix;
import awesome.group.game.dao.bean.MatrixAdminDevice;
import awesome.group.game.service.AdminDeviceService;
import awesome.group.game.service.common.response.R;
import awesome.group.game.web.RequestContext;
import awesome.group.game.web.aop.RestApi;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/admin/device")
@Tag(name = "device")
public class DeviceController {
@Autowired
private AdminDeviceService adminDeviceService;
@GetMapping("/list")
@RestApi
public R<List<MatrixAdminDevice>> deviceList(@RequestParam String appCode) {
return new R<>(adminDeviceService.getDeviceList(RequestContext.getAdminID(), appCode));
}
@PostMapping("/offline")
@RestApi
public R<String> offline(@RequestParam String deviceId) {
adminDeviceService.setStatusOffline(RequestContext.getAdminID(), deviceId);
return new R<>("ok");
}
}
Loading…
Cancel
Save