From aa7fbc8166f0c55506b0de10fae4b2f9d4ff1128 Mon Sep 17 00:00:00 2001 From: nili Date: Sat, 25 May 2024 14:37:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B7=E6=95=B0=E6=8D=AE=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E9=80=89=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/mapper/MatrixMockScheduleMapper.java | 9 +++++ .../game/service/bo/AddMockScheduleReq.java | 2 +- .../game/service/matrix/AdminService.java | 35 ++++++++++++------- .../game/web/rest/matrix/AdminController.java | 2 +- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixMockScheduleMapper.java b/game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixMockScheduleMapper.java index 287b77f..c50a4f7 100644 --- a/game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixMockScheduleMapper.java +++ b/game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixMockScheduleMapper.java @@ -2,12 +2,21 @@ package awesome.group.game.dao.mapper; import awesome.group.game.dao.bean.MatrixMockSchedule; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Update; +import java.util.List; + public interface MatrixMockScheduleMapper extends BaseMapper { @Update("update matrix_mock_schedule set status=#{status} where id = #{id}") int updateStatus(int status, int id); @Update("update matrix_mock_schedule set mock_income = mock_income + #{incrMockIncome} where id = #{id}") int updateMockIncome(long incrMockIncome, int id); + + @Insert("") + int insertBatch(List scheduleList); } diff --git a/game-service/src/main/java/awesome/group/game/service/bo/AddMockScheduleReq.java b/game-service/src/main/java/awesome/group/game/service/bo/AddMockScheduleReq.java index ed1cd20..c1018b8 100644 --- a/game-service/src/main/java/awesome/group/game/service/bo/AddMockScheduleReq.java +++ b/game-service/src/main/java/awesome/group/game/service/bo/AddMockScheduleReq.java @@ -3,7 +3,7 @@ package awesome.group.game.service.bo; import java.util.List; public class AddMockScheduleReq { - public Integer appId; + public List appId; public Integer incomeYuan; public List scheduleTime;//毫秒 } diff --git a/game-service/src/main/java/awesome/group/game/service/matrix/AdminService.java b/game-service/src/main/java/awesome/group/game/service/matrix/AdminService.java index 3cb5a8e..8865bf8 100644 --- a/game-service/src/main/java/awesome/group/game/service/matrix/AdminService.java +++ b/game-service/src/main/java/awesome/group/game/service/matrix/AdminService.java @@ -23,6 +23,7 @@ import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -312,20 +313,28 @@ public class AdminService { return data; } - public void addMockSchedule(AddMockScheduleReq bo) { - MatrixApp app = appMapper.selectById(bo.appId); - if (app == null || !StringUtils.hasText(app.getChannel())) { - throw new PaganiException(PaganiExceptionCode.ILLEGAL_REQUEST, "应用不存在或渠道为空"); - } - bo.scheduleTime.forEach(x -> { - MatrixMockSchedule schedule = new MatrixMockSchedule(); - schedule.setAppId(bo.appId); - schedule.setScheduleTime(new Timestamp(x)); - schedule.setChannel(app.getChannel()); - schedule.setIncomeYuan(bo.incomeYuan); - mockScheduleMapper.insert(schedule); - }); + public void addMockSchedule(AddMockScheduleReq bo, Integer adminId) { + MatrixAdmin admin = adminMapper.selectById(adminId); + Assert.isTrue(admin != null && admin.getRole() == SUPER_ADMIN, "非法请求"); + Assert.isTrue(!CollectionUtils.isEmpty(bo.scheduleTime), "时间不能为空"); + Assert.isTrue(!CollectionUtils.isEmpty(bo.appId), "应用不能为空"); + List list = new ArrayList<>(); + for(Integer appId: bo.appId) { + MatrixApp app = appMapper.selectById(appId); + if (app == null || !StringUtils.hasText(app.getChannel())) { + throw new PaganiException(PaganiExceptionCode.ILLEGAL_REQUEST, "应用不存在或渠道为空"); + } + bo.scheduleTime.forEach(x -> { + MatrixMockSchedule schedule = new MatrixMockSchedule(); + schedule.setAppId(appId); + schedule.setScheduleTime(new Timestamp(x)); + schedule.setChannel(app.getChannel()); + schedule.setIncomeYuan(bo.incomeYuan); + list.add(schedule); + }); + } + mockScheduleMapper.insertBatch(list); } public OverviewBo incomeOverview(int adminId, String code) { diff --git a/game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java b/game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java index 27dd1e6..9c8ac07 100644 --- a/game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java +++ b/game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java @@ -133,7 +133,7 @@ public class AdminController { @PostMapping("/addSchedule") @RestApi public R addSchedule(@RequestBody AddMockScheduleReq bo) { - adminService.addMockSchedule(bo); + adminService.addMockSchedule(bo, RequestContext.getAdminID()); return new R<>(R.CODE_SUCCESS, "ok", null); }