提交roll日创建
This commit is contained in:
+4
@@ -3,6 +3,7 @@ package com.ruoyi.admin.domain.body;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class AddRobotBody {
|
||||
@@ -11,4 +12,7 @@ public class AddRobotBody {
|
||||
private Integer rollId;
|
||||
|
||||
private Integer robotNum;
|
||||
|
||||
/** 需要排除的机器人ID列表(例如已在其他官方房中使用的机器人) */
|
||||
private List<Integer> excludeRobotIds;
|
||||
}
|
||||
|
||||
@@ -18,4 +18,9 @@ public interface TtRollMapper extends BaseMapper<TtRoll> {
|
||||
List<TtUser> getRollUser(Integer rollId);
|
||||
|
||||
List<Integer> getRollRobotIds(Integer rollId);
|
||||
|
||||
/**
|
||||
* 查询所有未开奖官方日Roll房中的机器人ID
|
||||
*/
|
||||
List<Integer> getActiveOfficialRollRobotIds();
|
||||
}
|
||||
|
||||
+12
@@ -63,6 +63,16 @@ public class TtOfficialRollConfigServiceImpl
|
||||
if (config.getRobotNum() != null && config.getRobotNum() < 0) {
|
||||
return AjaxResult.error("机器人数量不能为负数");
|
||||
}
|
||||
if (config.getRobotMin() != null && config.getRobotMin() < 0) {
|
||||
return AjaxResult.error("机器人数量下限不能为负数");
|
||||
}
|
||||
if (config.getRobotMax() != null && config.getRobotMax() < 0) {
|
||||
return AjaxResult.error("机器人数量上限不能为负数");
|
||||
}
|
||||
if (config.getRobotMin() != null && config.getRobotMax() != null
|
||||
&& config.getRobotMin() > config.getRobotMax()) {
|
||||
return AjaxResult.error("机器人数量下限不能大于上限");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -72,6 +82,8 @@ public class TtOfficialRollConfigServiceImpl
|
||||
private void normalize(TtOfficialRollConfig config) {
|
||||
if (config.getMinRecharge() == null) config.setMinRecharge(BigDecimal.ZERO);
|
||||
if (config.getRobotNum() == null) config.setRobotNum(0);
|
||||
if (config.getRobotMin() == null) config.setRobotMin(0);
|
||||
if (config.getRobotMax() == null) config.setRobotMax(0);
|
||||
if (config.getSortBy() == null) config.setSortBy(0);
|
||||
if (StringUtils.isEmpty(config.getStatus())) config.setStatus("0");
|
||||
}
|
||||
|
||||
+5
-1
@@ -556,9 +556,13 @@ public class TtRollServiceImpl extends ServiceImpl<TtRollMapper, TtRoll> impleme
|
||||
// 查询已经在房间中的机器人ID
|
||||
List<Integer> rollRobotIds = ttRollMapper.getRollRobotIds(addRobotBody.getRollId());
|
||||
|
||||
// 过滤掉已经在房间中的机器人ID
|
||||
// 查询需要排除的机器人ID(例如已在其他官方房中使用的机器人)
|
||||
List<Integer> excludeRobotIds = addRobotBody.getExcludeRobotIds();
|
||||
|
||||
// 过滤掉已经在房间中或被排除的机器人ID
|
||||
List<Integer> filteredRobotIdList = robotIdList.stream()
|
||||
.filter(robotId -> !rollRobotIds.contains(robotId))
|
||||
.filter(robotId -> excludeRobotIds == null || !excludeRobotIds.contains(robotId))
|
||||
.collect(Collectors.toList());
|
||||
if (filteredRobotIdList.size() < addRobotBody.getRobotNum()) {
|
||||
return AjaxResult.error("可用机器人数量不足");
|
||||
|
||||
+33
-4
@@ -4,11 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.ruoyi.admin.domain.body.AddRobotBody;
|
||||
import com.ruoyi.admin.mapper.TtRollMapper;
|
||||
import com.ruoyi.admin.service.TtOfficialRollConfigService;
|
||||
import com.ruoyi.admin.service.TtRollCdkService;
|
||||
import com.ruoyi.admin.service.TtRollService;
|
||||
import com.ruoyi.admin.service.TtUserService;
|
||||
import com.ruoyi.admin.service.impl.TtOfficialRollConfigServiceImpl;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.domain.entity.roll.TtOfficialRollConfig;
|
||||
import com.ruoyi.domain.entity.roll.TtRoll;
|
||||
import com.ruoyi.domain.entity.sys.TtUser;
|
||||
@@ -20,6 +22,7 @@ import java.math.BigDecimal;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* 官方周期Roll房定时创建任务。
|
||||
@@ -54,6 +57,9 @@ public class OfficialRollTask {
|
||||
@Autowired
|
||||
private TtRollCdkService rollCdkService;
|
||||
|
||||
@Autowired
|
||||
private TtRollMapper rollMapper;
|
||||
|
||||
/**
|
||||
* 每天为所有启用的 DAILY 配置创建当日官方roll房并自动加入机器人。
|
||||
* 充值统计起点=当天0点(今日充值),开奖=当日23:59:59。
|
||||
@@ -135,10 +141,12 @@ public class OfficialRollTask {
|
||||
}
|
||||
|
||||
/**
|
||||
* 为指定房间按配置数量加入机器人。数量取 min(配置机器人数, 可用机器人总数),避免"可用机器人数量不足"导致一个都不加。
|
||||
* 为指定房间按配置数量加入机器人。
|
||||
* 若配置指定了 robotMin/robotMax 范围,则在范围内随机生成数量;否则使用固定 robotNum。
|
||||
* 会排除当前已在其他未开奖官方日Roll房中的机器人,保证不同日期的官方房间机器人不重复。
|
||||
*/
|
||||
private void addRobots(Integer rollId, TtOfficialRollConfig config) {
|
||||
Integer robotNum = config.getRobotNum();
|
||||
Integer robotNum = resolveRobotNum(config);
|
||||
if (rollId == null || robotNum == null || robotNum <= 0) {
|
||||
return;
|
||||
}
|
||||
@@ -149,16 +157,37 @@ public class OfficialRollTask {
|
||||
log.warn("[官方周期Roll] 配置{}需要{}个机器人,但用户表无可用机器人,跳过加入", config.getId(), robotNum);
|
||||
return;
|
||||
}
|
||||
// 查询其他未开奖官方日Roll房中已使用的机器人,避免重复
|
||||
List<Integer> activeOfficialRobots = rollMapper.getActiveOfficialRollRobotIds();
|
||||
AddRobotBody body = new AddRobotBody();
|
||||
body.setRollId(rollId);
|
||||
body.setRobotNum(toAdd);
|
||||
rollService.addRobot(body);
|
||||
log.info("[官方周期Roll] 配置{} 房间{} 已尝试加入{}个机器人", config.getId(), rollId, toAdd);
|
||||
body.setExcludeRobotIds(activeOfficialRobots);
|
||||
AjaxResult result = rollService.addRobot(body);
|
||||
if (!result.isSuccess()) {
|
||||
log.warn("[官方周期Roll] 配置{} 房间{} 加入机器人结果:{}", config.getId(), rollId, result.get(AjaxResult.MSG_TAG));
|
||||
} else {
|
||||
log.info("[官方周期Roll] 配置{} 房间{} 已尝试加入{}个机器人", config.getId(), rollId, toAdd);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[官方周期Roll] 配置{} 房间{} 加入机器人失败:{}", config.getId(), rollId, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析配置中的机器人数量:优先使用 robotMin/robotMax 范围随机,否则回退到固定 robotNum
|
||||
*/
|
||||
private Integer resolveRobotNum(TtOfficialRollConfig config) {
|
||||
Integer min = config.getRobotMin();
|
||||
Integer max = config.getRobotMax();
|
||||
if (min != null && min > 0 && max != null && max > 0) {
|
||||
int lower = Math.min(min, max);
|
||||
int upper = Math.max(min, max);
|
||||
return ThreadLocalRandom.current().nextInt(lower, upper + 1);
|
||||
}
|
||||
return config.getRobotNum();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按配置数量为房间生成CDK;0或空则不生成(使用普通密码)。
|
||||
*/
|
||||
|
||||
+16
@@ -61,4 +61,20 @@
|
||||
WHERE
|
||||
tru.roll_id = #{rollId} AND tu.user_type = 03
|
||||
</select>
|
||||
|
||||
<select id="getActiveOfficialRollRobotIds" resultType="Integer">
|
||||
SELECT DISTINCT
|
||||
tu.user_id
|
||||
FROM
|
||||
tt_roll_user AS tru
|
||||
LEFT JOIN
|
||||
tt_user AS tu ON tru.user_id = tu.user_id
|
||||
LEFT JOIN
|
||||
tt_roll AS tr ON tru.roll_id = tr.id
|
||||
WHERE
|
||||
tu.user_type = '03'
|
||||
AND tr.roll_type = '0'
|
||||
AND tr.official_config_id IS NOT NULL
|
||||
AND tr.roll_status = '0'
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user