diff --git a/game-service/src/main/java/awesome/group/game/service/AdminDeviceService.java b/game-service/src/main/java/awesome/group/game/service/AdminDeviceService.java index efe6db1..bc7d178 100644 --- a/game-service/src/main/java/awesome/group/game/service/AdminDeviceService.java +++ b/game-service/src/main/java/awesome/group/game/service/AdminDeviceService.java @@ -72,9 +72,22 @@ public class AdminDeviceService { mapper.updateStatusByDeviceId(STATUS_OFFLINE, deviceId, adminId); } + public void setStatusOnline(Integer adminId, String deviceId) { + MatrixAdminDevice record = mapper.selectByDeviceId(deviceId); + if (record == null) { + return; + } + MatrixAdmin admin = adminMapper.selectById(record.getAdminId()); + long cnt = queryBindCnt(admin.getId(), record.getAppId()); + if (cnt >= admin.getDeviceCnt()) { + throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "绑定设备数已达上限"); + } + mapper.updateStatusByDeviceId(STATUS_DEFAULT, deviceId, adminId); + } + public String bind(String deviceId, String appCode, String adminName) { MatrixAdminDevice device = mapper.selectByDeviceId(deviceId); - if (device != null) { + if (device != null && device.getStatus() != STATUS_OFFLINE) { return "设备已绑定"; } MatrixAdmin admin = adminMapper.query(adminName); @@ -229,11 +242,11 @@ public class AdminDeviceService { query.between(MatrixAdvRecord::getCreatedAt, new Timestamp(dateBegin), new Timestamp(dateEnd)); query.eq(MatrixAdvRecord::getAdvType, 3);//设备主只算激励视频 query.gt(MatrixAdvRecord::getAdminId, 0); - query.groupBy(MatrixAdvRecord::getAdminId,MatrixAdvRecord::getAppId, MatrixAdvRecord::getPlatform); + query.groupBy(MatrixAdvRecord::getAdminId, MatrixAdvRecord::getAppId, MatrixAdvRecord::getPlatform); List records = advRecordMapper.selectList(query); List aggregations = new ArrayList<>(); List adminList = adminMapper.selectList(null); - Map adminMap = adminList.stream().collect(Collectors.toMap(x->x.getId(), x->x)); + Map adminMap = adminList.stream().collect(Collectors.toMap(x -> x.getId(), x -> x)); for (MatrixAdvRecord r : records) { MatrixAdvAggregationSub aggregation = new MatrixAdvAggregationSub(); aggregation.setAdminId(r.getAdminId()); diff --git a/game-web/src/main/java/awesome/group/game/web/rest/matrix/DeviceController.java b/game-web/src/main/java/awesome/group/game/web/rest/matrix/DeviceController.java index e1abc97..e40a2f5 100644 --- a/game-web/src/main/java/awesome/group/game/web/rest/matrix/DeviceController.java +++ b/game-web/src/main/java/awesome/group/game/web/rest/matrix/DeviceController.java @@ -35,6 +35,13 @@ public class DeviceController { return new R<>("ok"); } + @PostMapping("/online") + @RestApi + public R online(@RequestParam String deviceId) { + adminDeviceService.setStatusOnline(RequestContext.getAdminID(), deviceId); + return new R<>("ok"); + } + @GetMapping("/incomeOverview") @RestApi public R incomeOverview(@RequestParam(required = false) String appCode) {