添加项目文件。

This commit is contained in:
2026-10-12 16:22:04 +08:00
parent 7c68a0ca0a
commit aad11be43d
1000 changed files with 120807 additions and 0 deletions
@@ -0,0 +1,101 @@
using System.Linq.Expressions;
using Common;
using CommonDomain;
using CommonDomain.Enum;
using Microsoft.Extensions.Logging;
using MongoRepository;
namespace AdminService.EmptyRoomRate
{
public class EmptyRoomRateConfigService : IEmptyRoomRateConfigService
{
private readonly IMongoBaseRepository<EmptyRoomRateConfig> _emptyRoomRateMongo;
public EmptyRoomRateConfigService(
IMongoBaseRepository<EmptyRoomRateConfig> emptyRoomRateMongo)
{
_emptyRoomRateMongo = emptyRoomRateMongo;
}
/// <inheritdoc/>
public async Task<(List<EmptyRoomRateConfig> list, long count)> GetList(int page, int size, GameTypeEnum? gameType, int? roomLevel)
{
Expression<Func<EmptyRoomRateConfig, bool>> filter = c => true;
if (gameType.HasValue)
{
var type = gameType.Value;
filter = filter.And(c => c.GameType == type);
}
if (roomLevel.HasValue)
{
var level = roomLevel.Value;
filter = filter.And(c => c.RoomLevel == level);
}
var (total, list) = await _emptyRoomRateMongo.QueryPageAsync(filter, c => c.Id, false, size, page);
return (list, total);
}
/// <inheritdoc/>
public async Task<(bool isok, string msg)> Add(GameTypeEnum gameType, int roomLevel, int emptyRoomRate)
{
if (emptyRoomRate < 0 || emptyRoomRate > 100)
return (false, "空房率必须在0到100之间");
if (gameType == GameTypeEnum.中国象棋)
roomLevel = 0;
var existing = gameType == GameTypeEnum.中国象棋
? await _emptyRoomRateMongo.FindOneAsync(c => c.GameType == gameType)
: await _emptyRoomRateMongo.FindOneAsync(c => c.GameType == gameType && c.RoomLevel == roomLevel);
if (existing != null)
{
return (false, "该游戏类型与房间等级的组合已存在");
}
await _emptyRoomRateMongo.InsertOneAsync(new EmptyRoomRateConfig
{
GameType = gameType,
RoomLevel = roomLevel,
EmptyRoomRate = emptyRoomRate
});
return (true, "新增成功");
}
/// <inheritdoc/>
public async Task<(bool isok, string msg)> Update(string id, int emptyRoomRate)
{
if (emptyRoomRate < 0 || emptyRoomRate > 100)
return (false, "空房率必须在0到100之间");
var config = await _emptyRoomRateMongo.FindByIdAsync(id);
if (config == null)
{
return (false, "配置不存在");
}
config.EmptyRoomRate = emptyRoomRate;
await _emptyRoomRateMongo.ReplaceOneAsync(config);
return (true, "修改成功");
}
/// <inheritdoc/>
public async Task<(bool isok, string msg)> Delete(string id)
{
var config = await _emptyRoomRateMongo.FindByIdAsync(id);
if (config == null)
{
return (false, "配置不存在");
}
await _emptyRoomRateMongo.DeleteByIdAsync(id);
return (true, "删除成功");
}
}
}