feat: initial commit - HJHA game server full source
6 major server modules (PdkFriendServer/GlobalSever/ServerCore/GameModule/GameNetModule) + game logic (GameFix/GameDAL/ServerData) + network layer (NetWorkMessage) + data layer (ObjectModel) + utilities (MrWu/Core/Config/CloudAPI/dll) + adapters (zyxAdapter/base) .NET 8.0 C# solution, 16 projects, 958 source files
This commit is contained in:
116
GameDAL/Club/ClubBankPlayerInGame.cs
Normal file
116
GameDAL/Club/ClubBankPlayerInGame.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Server.DB.Redis;
|
||||
using System.Text;
|
||||
using StackExchange.Redis;
|
||||
using MrWu.Debug;
|
||||
|
||||
namespace GameDAL {
|
||||
/// <summary>
|
||||
/// 竞技比赛的 禁止玩家游玩
|
||||
/// </summary>
|
||||
public class ClubBankPlayerInGame {
|
||||
|
||||
public const int DbIdx = 6;
|
||||
|
||||
private ClubBankPlayerInGame() { }
|
||||
|
||||
static ClubBankPlayerInGame() {
|
||||
instance = new ClubBankPlayerInGame();
|
||||
}
|
||||
|
||||
public static ClubBankPlayerInGame instance {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据库单项操作
|
||||
/// </summary>
|
||||
public IDatabaseProxy dbp {
|
||||
get {
|
||||
return redisManager.Getdb(DbIdx);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据库操作
|
||||
/// </summary>
|
||||
public IDatabase db {
|
||||
get {
|
||||
return redisManager.GetDataBase(DbStyle.main, DbIdx);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据结构
|
||||
*
|
||||
* ClubBankPlayers:clubid [243633,243663]
|
||||
* ClubBankPlayers:clubid [243634,246338]
|
||||
*
|
||||
* */
|
||||
public const string baseKey = "ClubBankPlayers";
|
||||
|
||||
/// <summary>
|
||||
/// 获取竞技比赛的 禁止同桌 所有集合的 key
|
||||
/// </summary>
|
||||
/// <param name="clubid"></param>
|
||||
/// <returns></returns>
|
||||
public string GetClubBankKey(int clubid) {
|
||||
return $"{baseKey}:{clubid}";
|
||||
}
|
||||
|
||||
public List<int> GetAll(int clubId)
|
||||
{
|
||||
string key = GetClubBankKey(clubId);
|
||||
var values = dbp.SetMembers(key);
|
||||
var ret = values.Select(x=>int.Parse(x)).ToList();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个禁止游玩的玩家 (过期时间一年)
|
||||
/// </summary>
|
||||
/// <param name="clubId">竞技比赛id</param>
|
||||
/// <param name="userId">用户id</param>
|
||||
/// <returns></returns>
|
||||
public bool Add(int clubId, int userId) {
|
||||
string key = GetClubBankKey(clubId);
|
||||
var isSuccess = dbp.SetAdd(key, userId);
|
||||
db.KeyExpire(key, TimeSpan.FromDays(365));
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除玩家限制
|
||||
/// <param name="clubId">竞技比赛id</param>
|
||||
/// <param name="userId">用户id</param>
|
||||
/// </summary>
|
||||
public bool Remove(int clubId, int userId) {
|
||||
string key = GetClubBankKey(clubId);
|
||||
var isSuccess = dbp.SetRemove(key, userId);
|
||||
db.KeyExpire(key, TimeSpan.FromDays(365));
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除
|
||||
/// </summary>
|
||||
public bool Remove(int clubId) {
|
||||
string key = GetClubBankKey(clubId);
|
||||
var isSuccess = dbp.KeyDelete(key);
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含玩家
|
||||
/// <param name="clubId">竞技比赛id</param>
|
||||
/// <param name="userId">用户id</param>
|
||||
/// </summary>
|
||||
public bool Contains(int clubId, int userId) {
|
||||
string key = GetClubBankKey(clubId);
|
||||
return dbp.SetContains(key, userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
296
GameDAL/Club/ClubDBUtil.cs
Normal file
296
GameDAL/Club/ClubDBUtil.cs
Normal file
@ -0,0 +1,296 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using GameData;
|
||||
using GameData.Club;
|
||||
using GameMessage;
|
||||
using MrWu.Debug;
|
||||
using ObjectModel.Club;
|
||||
using Server.DB.Sql;
|
||||
|
||||
namespace GameDAL.Club
|
||||
{
|
||||
public static class ClubDBUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// id增量
|
||||
/// </summary>
|
||||
public const int IdIncrement = 100000;
|
||||
|
||||
#region ClubExitMatchClubList
|
||||
|
||||
/// <summary>
|
||||
/// 移除淘汰(退赛俱乐部)
|
||||
/// 直接添加解禁标记 (ReliefId),不直接删除
|
||||
/// </summary>
|
||||
public static async Task RemoveClubExitMatchAsync(int leagueClubId, int clubId)
|
||||
{
|
||||
long timeStamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
string sql = "UPDATE ClubExitMatchClubList SET ReliefId=@ReliefId where ClubId=@ClubId AND LeagueClubId=@LeagueClubId AND ReliefId=0";
|
||||
await GameDB.Instance.DapperExecuteAsync(dbbase.game2018, sql,
|
||||
new {
|
||||
ClubId = clubId,
|
||||
LeagueClubId = leagueClubId,
|
||||
ReliefId = timeStamp
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加淘汰(退赛俱乐部)
|
||||
/// </summary>
|
||||
public static async Task AddClubExitMatchAsync(LeagueMatchClubExitScore data)
|
||||
{
|
||||
const string sql = @"
|
||||
INSERT INTO ClubExitMatchClubList (
|
||||
[ClubId],
|
||||
[LeagueClubId],
|
||||
[MatchId],
|
||||
[CardScore],
|
||||
[DeskScore],
|
||||
[ClubUserSumScore],
|
||||
[LeagueScore],
|
||||
[JoinRoom],
|
||||
[UpdateTime],
|
||||
[ReliefId],
|
||||
[AwardId]
|
||||
) VALUES (
|
||||
@ClubId,
|
||||
@LeagueClubId,
|
||||
@MatchId,
|
||||
@CardScore,
|
||||
@DeskScore,
|
||||
@ClubUserSumScore,
|
||||
@LeagueScore,
|
||||
@JoinRoom,
|
||||
@UpdateTime,
|
||||
@ReliefId,
|
||||
@AwardId
|
||||
)";
|
||||
await GameDB.Instance.DapperExecuteAsync(dbbase.game2018, sql, data);
|
||||
}
|
||||
|
||||
public static async Task UpdateAwardIdOnMatchClose(int matchId)
|
||||
{
|
||||
string sql =
|
||||
$"UPDATE ClubExitMatchClubList SET AwardId = {ConstData.AwardId_InHistoryCloseMatchWithResetScore} where MatchId=@MatchId AND ReliefId <> 0";
|
||||
await GameDB.Instance.DapperExecuteAsync(dbbase.game2018, sql, new { MatchId = matchId });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联盟下退赛俱乐部的列表
|
||||
/// </summary>
|
||||
public static List<LeagueMatchClubExitScore> GetLeagueExitMathClubList(int leagueClubId)
|
||||
{
|
||||
// ReliefId = 0 表示当前没有解禁的俱乐部数据
|
||||
string sql = "SELECT * FROM ClubExitMatchClubList where LeagueClubId=@LeagueClubId AND ReliefId=0";
|
||||
var list = GameDB.Instance.DapperQuery<LeagueMatchClubExitScore>(dbbase.game2018, sql, new { LeagueClubId = leagueClubId });
|
||||
return list?.ToList() ?? new List<LeagueMatchClubExitScore>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联盟下已经解禁但是没有产生颁奖记录的俱乐部数据
|
||||
/// </summary>
|
||||
/// <param name="leagueClubId">联盟俱乐部Id</param>
|
||||
/// <param name="startTime">比赛开始时间</param>
|
||||
/// <param name="endTime">比赛结束时间</param>
|
||||
/// <param name="isHistoryMatch">是否是历史比赛</param>
|
||||
public static async Task<List<LeagueMatchClubExitScore>> GetLeagueExitClubReliefDataAsync(int leagueClubId, int leagueMatchId,
|
||||
DateTime startTime, DateTime endTime, bool isHistoryMatch)
|
||||
{
|
||||
var parameters = new DynamicParameters();
|
||||
string sql = "SELECT * FROM ClubExitMatchClubList where LeagueClubId=@LeagueClubId";
|
||||
parameters.Add("LeagueClubId", leagueClubId);
|
||||
parameters.Add("MatchId", leagueMatchId);
|
||||
parameters.Add("StartTime", new DateTimeOffset(startTime).ToUnixTimeSeconds());
|
||||
parameters.Add("EndTime", new DateTimeOffset(endTime).ToUnixTimeSeconds());
|
||||
|
||||
sql += isHistoryMatch
|
||||
? $" AND MatchId=@MatchId AND ReliefId>=@StartTime AND ReliefId<=@EndTime AND AwardId < {ConstData.AwardId_Default} AND AwardId > 0"
|
||||
: $" AND AwardId = {ConstData.AwardId_Default}";
|
||||
|
||||
var list = await GameDB.Instance.DapperQueryAsync<LeagueMatchClubExitScore>(dbbase.game2018, sql,
|
||||
parameters);
|
||||
return list?.ToList() ?? new List<LeagueMatchClubExitScore>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联盟下已经解禁的颁奖记录历史数据
|
||||
/// </summary>
|
||||
public static async Task<List<LeagueMatchClubExitScore>> GetLeagueAwardExitClubReliefRecord(int leagueClubId, int leagueMatchId, List<long> awardIds)
|
||||
{
|
||||
string sql = "SELECT * FROM ClubExitMatchClubList where LeagueClubId=@LeagueClubId AND AwardId In @AwardIds";
|
||||
var list = await GameDB.Instance.DapperQueryAsync<LeagueMatchClubExitScore>(dbbase.game2018, sql,
|
||||
new { LeagueClubId = leagueClubId, MatchId = leagueMatchId, AwardIds = awardIds });
|
||||
return list?.ToList() ?? new List<LeagueMatchClubExitScore>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接数据库的联盟颁奖逻辑,并对解禁数据进行标记
|
||||
/// </summary>
|
||||
public static async Task<bool> DoLeagueAwardRecord(long awardId, int leagueClubId, int leagueMatchId, List<AwardRecord> list)
|
||||
{
|
||||
if (list == null || list.Count < 1) return false;
|
||||
|
||||
string awardSql = @"
|
||||
INSERT INTO LeagueAwardRecord([RecordId],[CreateTime],[ClubMatchId],[ClubName],[ClubId],
|
||||
[CardScore],[DeskScore],[ClubUserSumScore],[JoinRoom],[LeagueScore],[Index]) Values
|
||||
(@RecordId,@CreateTime,@ClubMatchId,@ClubName,@ClubId,@CardScore,@DeskScore,@ClubUserSumScore,@JoinRoom,@LeagueScore,@Index)";
|
||||
// 记录颁奖数据 (如果为1就表示已经颁奖过,但是不会在颁奖记录中汇总)
|
||||
string exitReliefSql = @$"UPDATE ClubExitMatchClubList
|
||||
SET AwardId = CASE
|
||||
WHEN (ReliefId <> 0 AND AwardId = {ConstData.AwardId_Default}) THEN @AwardId
|
||||
ELSE {ConstData.AwardId_AwardNoInHistory}
|
||||
END
|
||||
WHERE LeagueClubId = @LeagueClubId
|
||||
AND MatchId = @MatchId";
|
||||
|
||||
Debug.Log(exitReliefSql);
|
||||
|
||||
return await GameDB.Instance.DapperExecuteTransactionAsync(dbbase.game2018, async (conn, tran) =>
|
||||
{
|
||||
await conn.ExecuteAsync(awardSql, list, tran);
|
||||
await conn.ExecuteAsync(exitReliefSql, new
|
||||
{
|
||||
AwardId = awardId,
|
||||
LeagueClubId = leagueClubId,
|
||||
MatchId = leagueMatchId
|
||||
}, tran);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region clubPayCard
|
||||
|
||||
/// <summary>
|
||||
/// 带日志的添加房卡操作 (目前只处理添加的情况)
|
||||
/// </summary>
|
||||
public static async Task<bool> AddClubPayCardAsync(List<ClubPayCardDBEntity> entities)
|
||||
{
|
||||
if(entities == null || entities.Count <= 0) return false;
|
||||
int clubId = entities[0].clubId;
|
||||
int cardCount = 0;
|
||||
foreach (var e in entities)
|
||||
{
|
||||
if (clubId != e.clubId)
|
||||
{
|
||||
Debug.Warning("[Club]批处理暂时只处理一个俱乐部的数据。");
|
||||
return false;
|
||||
}
|
||||
cardCount += e.cardCount;
|
||||
}
|
||||
|
||||
if (cardCount <= 0)
|
||||
{
|
||||
Debug.Warning("[Club]添加的房卡数量小于0!暂不处理减逻辑");
|
||||
return false;
|
||||
}
|
||||
|
||||
const string logSql = @"
|
||||
INSERT INTO clubPayCard ([clubId],[userId],[cardCount],[nickName],[datetime],[sex],[origin]
|
||||
) VALUES (@clubId,@userId,@cardCount,@nickName,@datetime,@sex,@origin)";
|
||||
const string clubUpdateSql = @"
|
||||
UPDATE top(1) clubs SET [cards] = [cards] + @cardCount
|
||||
WHERE [id] = @clubId";
|
||||
clubId = clubId - IdIncrement;
|
||||
await GameDB.Instance.DapperExecuteAsync(dbbase.game2018, clubUpdateSql, new { clubId, cardCount });
|
||||
await GameDB.Instance.DapperExecuteAsync(dbbase.gamedb, logSql, entities);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 分页获取俱乐部的房卡记录
|
||||
/// </summary>
|
||||
public static async Task<(int Count, List<ClubPayCardDBEntity> Data)> GetClubPayCardAsync(int clubId, int pageNumber, int pageSize)
|
||||
{
|
||||
int skip = pageSize * (pageNumber - 1);
|
||||
// 分页获取
|
||||
string sql = @"
|
||||
WITH Results As (SELECT *, ROW_NUMBER() OVER (ORDER BY id DESC) AS RowNum FROM clubPayCard WHERE clubId=@clubId)
|
||||
SELECT * FROM Results WHERE RowNum BETWEEN @StartIndex AND @EndIndex;
|
||||
SELECT COUNT(*) FROM clubPayCard WHERE clubId=@clubId;
|
||||
";
|
||||
return await GameDB.Instance.DapperQueryMultipleAsync(dbbase.gamedb, sql,
|
||||
new { clubId, StartIndex = skip, EndIndex = skip + pageSize },
|
||||
async reader =>
|
||||
{
|
||||
var datas = (await reader.ReadAsync<ClubPayCardDBEntity>()).ToList();
|
||||
var count = await reader.ReadSingleAsync<int>();
|
||||
return (count, datas);
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region clubs_rm
|
||||
public static async Task<List<int>> GetRemoveClubIds()
|
||||
{
|
||||
string sql = "SELECT Id FROM ClubsRM";
|
||||
var list = await GameDB.Instance.DapperQueryAsync<DBEntitys.ClubRM>(dbbase.game2018, sql, null);
|
||||
return list?.Select(x => x.Id).ToList() ?? new List<int>();
|
||||
}
|
||||
|
||||
|
||||
public static async Task<bool> DeleteClubAsync(DBEntitys.ClubRM club, List<DBEntitys.ClubPlayerDBEntity> clubPlayers)
|
||||
{
|
||||
string clubsSql = "DELETE FROM clubs WHERE ID = @Id";
|
||||
string clubsRmSql = @"
|
||||
INSERT INTO ClubsRM (
|
||||
[Id],[ClubName],[Notice],[Cards],[ManCnt],[Mans],[Newways],[WayVer],[Password],[CreateTime],[DeleteTime],[LeaderUserId], [Setting]
|
||||
) VALUES (
|
||||
@Id,@ClubName,@Notice,@Cards,@ManCnt,@Mans,@Newways,@WayVer,@Password,@CreateTime,@DeleteTime,@LeaderUserId,@Setting
|
||||
)";
|
||||
string leaguePowerSql = $"DELETE FROM LeagueClubLeaguePower WHERE ClubId = @Id + {IdIncrement}";
|
||||
string playerUpdateSql = "UPDATE TOP(1) players SET myclubinfodata=@myclubinfodata, joinclubinfodata=@joinclubinfodata WHERE userid2018 = @userid2018";
|
||||
string clubmsgRmSql = "DELETE FROM clubmsg WHERE receiveid = @Id";
|
||||
|
||||
return await GameDB.Instance.DapperExecuteTransactionAsync(dbbase.game2018, async (conn, tran) =>
|
||||
{
|
||||
await conn.ExecuteAsync(clubsRmSql, club, tran);
|
||||
await conn.ExecuteAsync(clubsSql, club, tran);
|
||||
await conn.ExecuteAsync(leaguePowerSql, club, tran);
|
||||
if (clubPlayers.Count > 0)
|
||||
await conn.ExecuteAsync(playerUpdateSql, clubPlayers, tran);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新导出club
|
||||
/// </summary>
|
||||
public static async Task<bool> UpdateExportClubAsync(DBEntitys.ClubsDBEntity club, List<DBEntitys.ClubPlayerDBEntity> clubPlayers)
|
||||
{
|
||||
string playerUpdateSql = "UPDATE TOP(1) players SET myclubinfodata=@myclubinfodata, joinclubinfodata=@joinclubinfodata WHERE userid2018 = @userid2018";
|
||||
string clubUpdateSql = "UPDATE TOP(1) clubs SET mans=@mans, manCnt=@manCnt, wayVer=@wayVer, newways=@newways WHERE ID = @ID";
|
||||
return await GameDB.Instance.DapperExecuteTransactionAsync(dbbase.game2018, async (conn, tran) =>
|
||||
{
|
||||
await conn.ExecuteAsync(clubUpdateSql, club, tran);
|
||||
await conn.ExecuteAsync(playerUpdateSql, clubPlayers, tran);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region clubs
|
||||
|
||||
public static async Task<bool> UpdateClubSettingAsync(int clubId, ClubSetting setting)
|
||||
{
|
||||
if (setting == null) return false;
|
||||
|
||||
clubId = clubId - IdIncrement;
|
||||
string settingJson = JsonPack.GetJson(setting);
|
||||
string sql = "UPDATE TOP(1) clubs SET [setting] = @Setting WHERE [id] = @ClubId";
|
||||
|
||||
int result = await GameDB.Instance.DapperExecuteAsync(dbbase.game2018, sql,
|
||||
new { ClubId = clubId, Setting = settingJson });
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
1670
GameDAL/Club/ClubDataManager.cs
Normal file
1670
GameDAL/Club/ClubDataManager.cs
Normal file
@ -0,0 +1,1670 @@
|
||||
/*
|
||||
* 由SharpDevelop创建。
|
||||
* 用户: Administrator
|
||||
* 日期: 2019-03-28
|
||||
* 时间: 14:23
|
||||
*
|
||||
* 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using Server.DB.Sql;
|
||||
using System.Data;
|
||||
using MrWu.Debug;
|
||||
using System.Collections.Generic;
|
||||
using MrWu.Time;
|
||||
using MrWu.Binary;
|
||||
using MrWu.Basic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MrWu.DB;
|
||||
using GameData;
|
||||
using Server.Data.ClubDef;
|
||||
using Server.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Text;
|
||||
using Server.DB.Redis;
|
||||
using StackExchange.Redis;
|
||||
using System.Data.SqlTypes;
|
||||
using GameData.Club;
|
||||
using GameMessage;
|
||||
|
||||
namespace GameDAL
|
||||
{
|
||||
/// <summary>
|
||||
/// 竞技比赛数据管理
|
||||
/// </summary>
|
||||
public static class ClubDataManager
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 竞技比赛表名称
|
||||
/// </summary>
|
||||
public const string tb_clubs = "clubs";
|
||||
|
||||
/// <summary>
|
||||
/// id列名
|
||||
/// </summary>
|
||||
public const string fd_id = "id";
|
||||
|
||||
/// <summary>
|
||||
/// 竞技比赛名称列名
|
||||
/// </summary>
|
||||
public const string fd_clubname = "clubname";
|
||||
|
||||
/// <summary>
|
||||
/// 公告列名
|
||||
/// </summary>
|
||||
public const string fd_notice = "notice";
|
||||
|
||||
/// <summary>
|
||||
/// 竞技比赛会长列名
|
||||
/// </summary>
|
||||
public const string fd_leadername = "leadername";
|
||||
|
||||
/// <summary>
|
||||
/// 玩法版本
|
||||
/// </summary>
|
||||
public const string fd_wayVer = "wayVer";
|
||||
|
||||
/// <summary>
|
||||
/// 时间小时部分列名
|
||||
/// </summary>
|
||||
public const string fd_createtimeh = "createtimeh";
|
||||
|
||||
/// <summary>
|
||||
/// 时间分钟部分列名
|
||||
/// </summary>
|
||||
public const string fd_createtimem = "createtimem";
|
||||
|
||||
/// <summary>
|
||||
/// 时间秒部分列名
|
||||
/// </summary>
|
||||
public const string fd_createtimes = "createtimes";
|
||||
|
||||
/// <summary>
|
||||
/// 关闭时间小时部分列名
|
||||
/// </summary>
|
||||
public const string fd_closetimeh = "closetimeh";
|
||||
|
||||
/// <summary>
|
||||
/// 关闭时间分钟部分列名
|
||||
/// </summary>
|
||||
public const string fd_closetimem = "closetimem";
|
||||
|
||||
/// <summary>
|
||||
/// 关闭时间秒钟部分列名
|
||||
/// </summary>
|
||||
public const string fd_closetimes = "closetimes";
|
||||
|
||||
/// <summary>
|
||||
/// 房卡 列名
|
||||
/// </summary>
|
||||
public const string fd_cards = "cards";
|
||||
|
||||
/// <summary>
|
||||
/// 玩家数量 列名
|
||||
/// </summary>
|
||||
public const string fd_manCnt = "manCnt";
|
||||
|
||||
/// <summary>
|
||||
/// 所有的竞技比赛玩家数据 列名
|
||||
/// </summary>
|
||||
public const string fd_mans = "mans";
|
||||
|
||||
/// <summary>
|
||||
/// 俱乐部密码
|
||||
/// </summary>
|
||||
public const string fd_Password = "password";
|
||||
|
||||
/// <summary>
|
||||
/// 新玩法列
|
||||
/// </summary>
|
||||
public const string fd_newways = "newways";
|
||||
|
||||
/// <summary>
|
||||
/// 设置
|
||||
/// </summary>
|
||||
public const string fd_setting = "setting";
|
||||
|
||||
/// <summary>
|
||||
/// 积分 消耗一张房卡得1积分
|
||||
/// </summary>
|
||||
public const string fd_integral = "integral";
|
||||
|
||||
/// <summary>
|
||||
/// 竞技比赛所有玩家表
|
||||
/// </summary>
|
||||
public const string tb_players = "players";
|
||||
|
||||
/// <summary>
|
||||
/// userid列
|
||||
/// </summary>
|
||||
public const string fd_userid2018 = "userid2018";
|
||||
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
public const string fd_nickname2018 = "nickname2018";
|
||||
|
||||
/// <summary>
|
||||
/// 联系方式-没用上
|
||||
/// </summary>
|
||||
//public const string fd_contact = "contact";
|
||||
|
||||
/// <summary>
|
||||
/// 我的竞技比赛信息_老的
|
||||
/// </summary>
|
||||
public const string fd_myclubinfo = "myclubinfo";
|
||||
|
||||
/// <summary>
|
||||
/// 我的竞技比赛信息 新的
|
||||
/// </summary>
|
||||
public const string fd_myclubinfodata = "myclubinfodata";
|
||||
|
||||
/// <summary>
|
||||
/// 我加入的竞技比赛信息 老的
|
||||
/// </summary>
|
||||
public const string fd_joinclubinfo = "joinclubinfo";
|
||||
|
||||
/// <summary>
|
||||
/// 我加入的竞技比赛信息 新的
|
||||
/// </summary>
|
||||
public const string fd_joinclubinfodata = "joinclubinfodata";
|
||||
|
||||
/// <summary>
|
||||
/// 战斗记录id 老的
|
||||
/// </summary>
|
||||
public const string fd_fightcord = "fightrecordid";
|
||||
|
||||
/// <summary>
|
||||
/// 战斗记录 新的
|
||||
/// </summary>
|
||||
public const string fd_fightcorddata = "fightrecordiddata";
|
||||
|
||||
/// <summary>
|
||||
/// 竞技比赛消息白哦
|
||||
/// </summary>
|
||||
public const string tb_message = "clubmsg";
|
||||
|
||||
/// <summary>
|
||||
/// 消息类型字段
|
||||
/// </summary>
|
||||
public const string fd_style = "style";
|
||||
|
||||
/// <summary>
|
||||
/// 消息状态
|
||||
/// </summary>
|
||||
public const string fd_state = "state";
|
||||
|
||||
/// <summary>
|
||||
/// 内容
|
||||
/// </summary>
|
||||
public const string fd_strcontent = "strcontent";
|
||||
|
||||
/// <summary>
|
||||
/// 接收时间
|
||||
/// </summary>
|
||||
public const string fd_sendTime = "sendTime";
|
||||
|
||||
/// <summary>
|
||||
/// 处理时间
|
||||
/// </summary>
|
||||
public const string fd_dotime = "dotime";
|
||||
|
||||
/// <summary>
|
||||
/// 处理者
|
||||
/// </summary>
|
||||
public const string fd_doman = "doman";
|
||||
|
||||
/// <summary>
|
||||
/// 处理人名称
|
||||
/// </summary>
|
||||
public const string fd_domanname = "domanname";
|
||||
|
||||
/// <summary>
|
||||
/// 接收人id 转变为竞技比赛id
|
||||
/// </summary>
|
||||
public const string fd_receiveid = "receiveid";
|
||||
|
||||
/// <summary>
|
||||
/// 发送者id 转变为用户id
|
||||
/// </summary>
|
||||
public const string fd_sendid = "sendid";
|
||||
|
||||
/// <summary>
|
||||
/// 发送者名称
|
||||
/// </summary>
|
||||
public const string fd_sendname = "sendname";
|
||||
|
||||
/// <summary>
|
||||
/// 竞技比赛战斗记录表
|
||||
/// </summary>
|
||||
public const string tb_ClubFightRecord = "club_FightRecord";
|
||||
|
||||
/// <summary>
|
||||
/// 竞技比赛大赢家表
|
||||
/// </summary>
|
||||
public const string tb_ClubBigWiner = "Club_BigWiner";
|
||||
|
||||
/// <summary>
|
||||
/// 竞技比赛id
|
||||
/// </summary>
|
||||
public const string fd_clubid = "clubid";
|
||||
|
||||
/// <summary>
|
||||
/// 玩法id
|
||||
/// </summary>
|
||||
public const string fd_wayid = "wayid";
|
||||
|
||||
/// <summary>
|
||||
/// 房间的唯一码
|
||||
/// </summary>
|
||||
public const string fd_weiyima = "weiyima";
|
||||
|
||||
/// <summary>
|
||||
/// 游戏服务器id
|
||||
/// </summary>
|
||||
public const string fd_gameserid = "gameserid";
|
||||
|
||||
/// <summary>
|
||||
/// 房间号
|
||||
/// </summary>
|
||||
public const string fd_roomnum = "roomnum";
|
||||
|
||||
/// <summary>
|
||||
/// 房间战斗次数
|
||||
/// </summary>
|
||||
public const string fd_warcnt = "warcnt";
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间
|
||||
/// </summary>
|
||||
public const string fd_startTime = "startTime";
|
||||
|
||||
/// <summary>
|
||||
/// 结束时间
|
||||
/// </summary>
|
||||
public const string fd_endTime = "endTime";
|
||||
|
||||
/// <summary>
|
||||
/// 玩家分值信息
|
||||
/// </summary>
|
||||
public const string fd_scores = "scores";
|
||||
|
||||
/// <summary>
|
||||
/// userid
|
||||
/// </summary>
|
||||
public const string fd_userid = "userid";
|
||||
|
||||
/// <summary>
|
||||
/// 昵称
|
||||
/// </summary>
|
||||
public const string fd_nickname = "nickname";
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public const string fd_remark = "remark";
|
||||
|
||||
/// <summary>
|
||||
/// 头像
|
||||
/// </summary>
|
||||
public const string fd_photo = "photo";
|
||||
|
||||
/// <summary>
|
||||
/// id增量
|
||||
/// </summary>
|
||||
public const int idIncrement = 100000;
|
||||
|
||||
/// <summary>
|
||||
/// 创建竞技比赛存储过程
|
||||
/// </summary>
|
||||
public const string pr_createclubnew = "createclubnew";
|
||||
|
||||
/// <summary>
|
||||
/// 创建竞技比赛玩家
|
||||
/// </summary>
|
||||
public const string pr_createplayer = "CreateClubPlayer";
|
||||
|
||||
/// <summary>
|
||||
/// 加载所有的竞技比赛数据
|
||||
/// </summary>
|
||||
public static List<Club_Base> LoadClubs()
|
||||
{
|
||||
List<Club_Base> clubs = new List<Club_Base>();
|
||||
DataTable dt = GameDB.Instance.selectDb(dbbase.game2018, tb_clubs);
|
||||
int len = dt.Rows.Count;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
clubs.Add(_LoadClub(dt.Rows[i]));
|
||||
}
|
||||
return clubs;
|
||||
}
|
||||
|
||||
public static async Task<Club_Base> LoadClubAsync(int clubid)
|
||||
{
|
||||
return await Task.Run(()=>LoadClub(clubid));
|
||||
}
|
||||
|
||||
public static Club_Base LoadClub(int clubid)
|
||||
{
|
||||
clubid = clubid -= 100000;
|
||||
DataTable dt = GameDB.Instance.selectDb(dbbase.game2018, tb_clubs, null, $"id={clubid}");
|
||||
if (dt.Rows.Count <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _LoadClub(dt.Rows[0]);
|
||||
}
|
||||
|
||||
public static bool ExistClub(int clubId)
|
||||
{
|
||||
clubId = clubId -= 100000;
|
||||
bool exists = GameDB.Instance.DapperExecuteScalar<int>(dbbase.game2018,
|
||||
$"SELECT COUNT(1) FROM {tb_clubs} WHERE Id = @Id",
|
||||
new { Id = clubId }) > 0;
|
||||
return exists;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从行数据中加载竞技比赛数据
|
||||
/// </summary>
|
||||
/// <param name="row">行</param>
|
||||
/// <returns></returns>
|
||||
private static Club_Base _LoadClub(DataRow row)
|
||||
{
|
||||
Club_Base club = new Club_Base();
|
||||
club.Init();
|
||||
club.id = int.Parse(row[fd_id].ToString()) + idIncrement;
|
||||
club.clubname = row[fd_clubname].ToString();
|
||||
club.notice = row[fd_notice].ToString();
|
||||
club.leadername = row[fd_leadername].ToString();
|
||||
club.wayVer = (int)row[fd_wayVer];
|
||||
int timeh = int.Parse(row[fd_createtimeh].ToString());
|
||||
int timem = int.Parse(row[fd_createtimem].ToString());
|
||||
int times = int.Parse(row[fd_createtimes].ToString());
|
||||
|
||||
//if (club.id > 100050)
|
||||
// Console.WriteLine("1111");
|
||||
|
||||
CustomTime custime = new CustomTime(timeh, (byte)timem, (byte)times, 0);
|
||||
club.createTime = TimeConvert.CustomTimeToDateTime(custime);
|
||||
club.card = int.Parse(row[fd_cards].ToString());
|
||||
club.mancnt = int.Parse(row[fd_manCnt].ToString());
|
||||
byte[] bts = row[fd_mans] as byte[];
|
||||
tr_clubMans mans = BinaryConvert.BytesToStruct<tr_clubMans>(bts, 0);
|
||||
if (mans.ids != null)
|
||||
{
|
||||
club.mansid.AddRange(mans.ids.GetNewArray(0, club.mancnt));
|
||||
}
|
||||
|
||||
if (club.mancnt != club.mansid.Count)
|
||||
{
|
||||
Debug.Error($"数据错误,玩家数量与真实数量不一致! {club.id}");
|
||||
}
|
||||
|
||||
string ways = row[fd_newways].ToString();
|
||||
|
||||
if (club.wayVer == Club_Base.allServerVer)
|
||||
{
|
||||
PlayWay[] plways = JsonPack.GetData<PlayWay[]>(ways);
|
||||
if (plways != null)
|
||||
club.ways.AddRange(plways);
|
||||
}
|
||||
|
||||
club.PassWord = row[fd_Password].ToString();
|
||||
|
||||
string setting = row[fd_setting].ToString();
|
||||
if (!string.IsNullOrEmpty(setting))
|
||||
{
|
||||
club.Setting = JsonPack.GetData<ClubSetting>(setting);
|
||||
}
|
||||
else
|
||||
{
|
||||
club.Setting = new ClubSetting();
|
||||
}
|
||||
Debug.Info("加载竞技比赛:" + club.clubname);
|
||||
// Thread.Sleep(2);//不知为何要等待100ms, 单元测试,当数据较多时(大于200),将导致测试因超时失败,因此由原100修改为2
|
||||
return club;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载所有的拥有竞技比赛的玩家
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<ClubPlayer> LoadPlayers()
|
||||
{
|
||||
List<ClubPlayer> players = new List<ClubPlayer>();
|
||||
|
||||
DataTable dt = GameDB.Instance.selectDb(dbbase.game2018, tb_players);
|
||||
int len = dt.Rows.Count;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
players.Add(_LoadPlayer(dt.Rows[i]));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
public static ClubPlayer LoadPlayer(int userId)
|
||||
{
|
||||
DataTable dt = GameDB.Instance.selectDb(dbbase.game2018, tb_players, null, $"userid2018={userId}");
|
||||
int len = dt.Rows.Count;
|
||||
if (len > 0)
|
||||
{
|
||||
return _LoadPlayer(dt.Rows[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除俱乐部玩家
|
||||
/// </summary>
|
||||
/// <param name="userid"></param>
|
||||
/// <returns></returns>
|
||||
public static bool DeletePlayer(int userid)
|
||||
{
|
||||
string sql = $"delete from players where userid2018={userid}";
|
||||
return 1 == GameDB.Instance.ExceSql(dbbase.game2018, sql);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除俱乐部
|
||||
/// </summary>
|
||||
/// <param name="clubid"></param>
|
||||
/// <returns></returns>
|
||||
public static bool DeleteClub(int clubid)
|
||||
{
|
||||
string sql = $"DELETE FROM clubs WHERE ID = {clubid}";
|
||||
string leaguePowerSql = $"DELETE FROM LeagueClubLeaguePower WHERE ClubId = {clubid}";
|
||||
var ret = dbbase.game2018.ExecuteTransaction(t =>
|
||||
{
|
||||
t.ExecuteNonQuery(sql);
|
||||
t.ExecuteNonQuery(leaguePowerSql);
|
||||
|
||||
return true;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除俱乐部消息,申请加入之类的消息
|
||||
/// </summary>
|
||||
/// <param name="clubId">俱乐部Id,减去了100000的id,真实的俱乐部Id</param>
|
||||
/// <returns></returns>
|
||||
public static bool DeleteClubsByClubId(int clubId)
|
||||
{
|
||||
string sql = $"DELETE FROM clubmsg WHERE receiveid = {clubId}";
|
||||
var c = GameDB.Instance.ExceSql(dbbase.game2018, sql);
|
||||
Debug.ImportantLog($"删除俱乐部:{clubId} 的消息条数为:{c}");
|
||||
return c > 0;
|
||||
}
|
||||
|
||||
public static Task<bool> PlayerIsInClubAsync(int userid)
|
||||
{
|
||||
return Task.Run(() => PlayerIsInClub(userid));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 玩家是否在俱乐部里面有数据
|
||||
/// </summary>
|
||||
/// <returns>true有数据 false没有数据</returns>
|
||||
public static bool PlayerIsInClub(int userid)
|
||||
{
|
||||
string sql = $"select top 1 * from players where userid2018={userid}";
|
||||
DataSet ds = new DataSet();
|
||||
GameDB.Instance.ExceSql(dbbase.game2018, sql, null, ds);
|
||||
var b = ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0;
|
||||
if (!b) return false;
|
||||
var myinfo = ds.Tables[0].Rows[0][fd_myclubinfodata] == DBNull.Value;
|
||||
var joinInfo = ds.Tables[0].Rows[0][fd_joinclubinfodata] == DBNull.Value;
|
||||
//Debug.ImportantLog($"b m:{myinfo} ,j:{joinInfo}");
|
||||
if (myinfo && joinInfo)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
string myText = ds.Tables[0].Rows[0][fd_myclubinfodata] as string; //空数据一般是[]
|
||||
string joinText = ds.Tables[0].Rows[0][fd_joinclubinfodata] as string;
|
||||
//Debug.ImportantLog($"mytext:{myText}, join:{joinText}");
|
||||
if (myText.Length <= 3 && joinText.Length <= 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载竞技比赛玩家
|
||||
///
|
||||
/// 2020-06-21 修改竞技比赛的玩家表
|
||||
/// 原来存储的是二进制数据,完全没有办法拓展。
|
||||
/// 所以把我的竞技比赛信息,加入的竞技比赛信息,战斗记录的id,换成 josn 格式存储 新增数据库字段
|
||||
/// 也就是这个版本升级之contact 字段 myclubinfo 字段 joinclubinfo 字段 fightrecordid 字段 都废弃了
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="row">行</param>
|
||||
/// <returns>竞技比赛玩家</returns>
|
||||
private static ClubPlayer _LoadPlayer(DataRow row)
|
||||
{
|
||||
ClubPlayer player = new ClubPlayer();
|
||||
//userid
|
||||
player.userid = int.Parse(row[fd_userid2018].ToString());
|
||||
//用户昵称
|
||||
player.nickname = row[fd_nickname2018].ToString();
|
||||
if (row["sex"] != DBNull.Value)
|
||||
{ //这是新加的字段
|
||||
player.sex = int.Parse(row["sex"].ToString());
|
||||
}
|
||||
bool isSave = false;
|
||||
|
||||
//先去加载新的, 如果加载不到 就去加载老的
|
||||
if (row[fd_myclubinfodata] == DBNull.Value)
|
||||
{ //新的是空 去加载老的, 并把这个数据存到新的里面去
|
||||
byte[] bts = row[fd_myclubinfo] as byte[];
|
||||
tr_clubsOfPlayer myclubinfo = BinaryConvert.BytesToStruct<tr_clubsOfPlayer>(bts);
|
||||
player.myClubs = tr_clubsOfPlayerToListPlayerofClub(ref myclubinfo);
|
||||
//存到新的里去
|
||||
isSave = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string text = row[fd_myclubinfodata] as string;
|
||||
player.myClubs = JsonPack.GetData<List<playerofClub>>(text);
|
||||
if (player.myClubs == null)
|
||||
{
|
||||
Debug.Error("新表中没有存储到我的竞技比赛数据" + player.userid);
|
||||
player.myClubs = new List<playerofClub>();
|
||||
}
|
||||
}
|
||||
|
||||
if (row[fd_joinclubinfodata] == DBNull.Value)
|
||||
{ //新的是空 去加载老的,并把这个数据存到新的里面去
|
||||
byte[] bts = row[fd_joinclubinfo] as byte[];
|
||||
tr_clubsOfPlayer joinclubinfo = BinaryConvert.BytesToStruct<tr_clubsOfPlayer>(bts);
|
||||
player.joinClubs = tr_clubsOfPlayerToListPlayerofClub(ref joinclubinfo);
|
||||
//存到新的里面去
|
||||
isSave = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string text = row[fd_joinclubinfodata] as string;
|
||||
player.joinClubs = JsonPack.GetData<List<playerofClub>>(text);
|
||||
if (player.joinClubs == null)
|
||||
{
|
||||
Debug.Error("新表中没有存储到我加入的竞技比赛数据:" + player.userid);
|
||||
player.joinClubs = new List<playerofClub>();
|
||||
}
|
||||
}
|
||||
|
||||
if (row[fd_fightcorddata] == DBNull.Value)
|
||||
{
|
||||
byte[] bts = row[fd_fightcord] as byte[];
|
||||
tr_playerFightRecordId fightrecord = BinaryConvert.BytesToStruct<tr_playerFightRecordId>(bts);
|
||||
player.fightRecordids = FightRecordidToListid(ref fightrecord);
|
||||
//存到新的里面去
|
||||
isSave = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string text = row[fd_fightcorddata] as string;
|
||||
player.fightRecordids = JsonPack.GetData<List<int>>(text);
|
||||
if (player.fightRecordids == null)
|
||||
{
|
||||
Debug.Error("新表中没有存储到战斗记录数据的id:" + player.userid);
|
||||
player.fightRecordids = new List<int>();
|
||||
}
|
||||
}
|
||||
|
||||
if (isSave)
|
||||
UpdatePlayer(player);
|
||||
|
||||
return player;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 时间转换
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <returns></returns>
|
||||
private static DateTime ConvertTime(ref tr_sifangdatetime time)
|
||||
{
|
||||
CustomTime ct = new CustomTime(time.hours, time.minute, time.second);
|
||||
return TimeConvert.CustomTimeToDateTime(ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 时间转换
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <returns></returns>
|
||||
private static tr_sifangdatetime ConvertTime(DateTime time)
|
||||
{
|
||||
CustomTime ct = TimeConvert.DateTimeToCustomTime(time);
|
||||
tr_sifangdatetime sftime;
|
||||
sftime.hours = ct.hours;
|
||||
sftime.minute = ct.minute;
|
||||
sftime.second = ct.second;
|
||||
return sftime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 玩家的单个竞技比赛结构数据转类数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static playerofClub Tr_playerInfoOfClubToplayerofClub(ref tr_playerInfoOfClub tpic)
|
||||
{
|
||||
playerofClub item = new playerofClub();
|
||||
item.clubid = tpic.clubid;
|
||||
item.inGame = tpic.ingame;
|
||||
item.position = tpic.position;
|
||||
item.remark = BinaryConvert.BytesToShortString(tpic.remark, BinaryConvert.GB2312);
|
||||
if (item.remark.Length != 0)
|
||||
Console.WriteLine(item.remark);
|
||||
item.joinTime = ConvertTime(ref tpic.jointime);
|
||||
item.permission = tpic.bak1;
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 玩家的单个竞技比赛类数据转结构数据
|
||||
/// </summary>
|
||||
/// <param name="pc"></param>
|
||||
/// <returns></returns>
|
||||
private static tr_playerInfoOfClub PlayerofClubTotr_playerInfoOfClub(playerofClub pc)
|
||||
{
|
||||
tr_playerInfoOfClub tpic = tr_playerInfoOfClub.CreateTr_playerInfoOfClub();
|
||||
tpic.clubid = pc.clubid;
|
||||
tpic.ingame = (byte)pc.inGame;
|
||||
tpic.jointime = ConvertTime(pc.joinTime);
|
||||
tpic.position = (byte)pc.position;
|
||||
tpic.bak1 = (ushort)pc.permission;
|
||||
BinaryConvert.ShortStringToBytes(pc.remark, tpic.remark, 0, BinaryConvert.GB2312);
|
||||
return tpic;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 玩家的竞技比赛结构数据 转类数据
|
||||
/// </summary>
|
||||
/// <param name="tcp"></param>
|
||||
/// <returns></returns>
|
||||
private static List<playerofClub> tr_clubsOfPlayerToListPlayerofClub(ref tr_clubsOfPlayer tcp)
|
||||
{
|
||||
List<playerofClub> pc = new List<playerofClub>();
|
||||
for (int i = 0; i < tcp.cnt; i++)
|
||||
{
|
||||
pc.Add(Tr_playerInfoOfClubToplayerofClub(ref tcp.datas[i]));
|
||||
}
|
||||
return pc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 玩家的竞技比赛类数据 转结构数据
|
||||
/// </summary>
|
||||
/// <param name="clubdata"></param>
|
||||
/// <returns></returns>
|
||||
private static tr_clubsOfPlayer ListPlayerofClubTotr_clubsOfPlayer(List<playerofClub> clubdata)
|
||||
{
|
||||
tr_clubsOfPlayer tcp = tr_clubsOfPlayer.CreateTr_clubsOfPlayer();//new tr_clubsOfPlayer();
|
||||
tcp.cnt = clubdata.Count;
|
||||
for (int i = 0; i < tcp.cnt; i++)
|
||||
{
|
||||
if (i < tcp.datas.Length)
|
||||
tcp.datas[i] = PlayerofClubTotr_playerInfoOfClub(clubdata[i]);
|
||||
}
|
||||
return tcp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 玩家战斗记录id结构体转链表
|
||||
/// </summary>
|
||||
/// <param name="pfr"></param>
|
||||
/// <returns></returns>
|
||||
private static List<int> FightRecordidToListid(ref tr_playerFightRecordId pfr)
|
||||
{
|
||||
List<int> records = new List<int>();
|
||||
for (int i = 0; i < pfr.cnt; i++)
|
||||
{
|
||||
records.Add(pfr.fightrecords[i]);
|
||||
}
|
||||
return records;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 玩家战斗记录id链表转结构体
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public static tr_playerFightRecordId ListidToFightRecordid(List<int> ids)
|
||||
{
|
||||
tr_playerFightRecordId tpfr = new tr_playerFightRecordId();
|
||||
tpfr.cnt = ids.Count;
|
||||
for (int i = 0; i < tpfr.cnt; i++)
|
||||
{
|
||||
tpfr.fightrecords[i] = ids[i];
|
||||
}
|
||||
return tpfr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数组转 竞技比赛 中的玩家数据
|
||||
/// </summary>
|
||||
/// <param name="mansid"></param>
|
||||
/// <returns></returns>
|
||||
public static tr_clubMans ArrayTotr_clubMans(List<int> mansid)
|
||||
{
|
||||
tr_clubMans mans = tr_clubMans.CreateClubMans();
|
||||
int len = mansid.Count;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
mans.ids[i] = mansid[i];
|
||||
}
|
||||
return mans;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建竞技比赛存储过程
|
||||
/// </summary>
|
||||
/// <param name="club">竞技比赛数据</param>
|
||||
/// <param name="myclubs">我的竞技比赛数据</param>
|
||||
/// <param name="createuser">创建者userid</param>
|
||||
/// <returns>0程序出错 -1未找到创建者 -2竞技比赛名称同名 -3表示已存在竞技比赛id</returns>
|
||||
public static int CreateClub(Club_Base club, List<playerofClub> myclubs, int createuser)
|
||||
{
|
||||
var spp = GameDB.Instance.BeginSetProcedureParameter(dbbase.game2018, pr_createclubnew);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@clubid", SqlDbType.Int, club.id - ClubDataManager.idIncrement);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@clubname", SqlDbType.NVarChar, club.clubname);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@clubnotice", SqlDbType.NVarChar, club.notice);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@createruser", SqlDbType.NVarChar, createuser);
|
||||
CustomTime ct = TimeConvert.DateTimeToCustomTime(club.createTime);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@createH", SqlDbType.Int, ct.hours);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@createM", SqlDbType.Int, ct.minute);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@createS", SqlDbType.Int, ct.second);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@cards", SqlDbType.Int, club.card);
|
||||
var ids = ArrayTotr_clubMans(club.mansid);
|
||||
byte[] bts = BinaryConvert.StructToBytes(ids);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@mans", SqlDbType.Binary, bts);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@mancnt", SqlDbType.Int, club.mancnt);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@ways", SqlDbType.Text, JsonPack.GetJson(club.ways));
|
||||
var clubsinfo = JsonPack.GetJson(myclubs);
|
||||
/* 老的二进制方式
|
||||
var clubsinfo = ListPlayerofClubTotr_clubsOfPlayer(myclubs);
|
||||
bts = BinaryConvert.StructToBytes(clubsinfo);
|
||||
*/
|
||||
GameDB.Instance.AddProdureParameters(spp, "@myclubinfo", SqlDbType.Text, clubsinfo);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@result", SqlDbType.Int, 0, ParameterDirection.Output);
|
||||
DataSet ds = new DataSet();
|
||||
Dictionary<string, object> pars = GameDB.Instance.EndAddProdureParameters(spp, ds);
|
||||
return (int)pars["@result"];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个竞技比赛玩家
|
||||
/// </summary>
|
||||
/// <param name="player"></param>
|
||||
/// <returns></returns>
|
||||
public static bool CreatePlayer(ClubPlayer player)
|
||||
{
|
||||
var spp = GameDB.Instance.BeginSetProcedureParameter(dbbase.game2018, pr_createplayer);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@userid", SqlDbType.Int, player.userid);
|
||||
|
||||
/* 老的
|
||||
var clubsinfo = ListPlayerofClubTotr_clubsOfPlayer(player.myClubs);
|
||||
byte[] bts = BinaryConvert.StructToBytes(clubsinfo);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@myclubinfo", SqlDbType.Binary, bts);
|
||||
*/
|
||||
|
||||
var clubsinfo = JsonPack.GetJson(player.myClubs);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@myclubinfo", SqlDbType.Text, clubsinfo);
|
||||
|
||||
/* 老的
|
||||
clubsinfo = ListPlayerofClubTotr_clubsOfPlayer(player.joinClubs);
|
||||
bts = BinaryConvert.StructToBytes(clubsinfo);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@joinclubinfo", SqlDbType.Binary, bts);
|
||||
*/
|
||||
|
||||
clubsinfo = JsonPack.GetJson(player.joinClubs);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@joinclubinfo", SqlDbType.Text, clubsinfo);
|
||||
|
||||
/* 老的
|
||||
var pfr = ListidToFightRecordid(player.fightRecordids);
|
||||
bts = BinaryConvert.StructToBytes(pfr);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@fightrecordids", SqlDbType.Binary, bts);
|
||||
*/
|
||||
|
||||
var pfr = JsonPack.GetJson(player.fightRecordids);
|
||||
GameDB.Instance.AddProdureParameters(spp, "@fightrecordids", SqlDbType.Text, pfr);
|
||||
|
||||
|
||||
GameDB.Instance.AddProdureParameters(spp, "@result", SqlDbType.Int, 0, ParameterDirection.Output);
|
||||
DataSet ds = new DataSet();
|
||||
Dictionary<string, object> pars = GameDB.Instance.EndAddProdureParameters(spp, ds);
|
||||
if (ds.Tables.Count > 0)
|
||||
{
|
||||
player.nickname = ds.Tables[0].Rows[0][fd_nickname].ToString();
|
||||
}
|
||||
|
||||
return (int)pars["@result"] == 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新玩家 修改玩家权限,设置小黑屋都需要调用更新 玩家数据
|
||||
/// </summary>
|
||||
/// <param name="player"></param>
|
||||
public static bool UpdatePlayer(ClubPlayer player)
|
||||
{
|
||||
string sql = string.Format("update Top(1) {0} set {1}=@nickname,{2}=@myclubinfo,{3}=@joinclubinfo,{4}=@fightrecord where {5}={6};",
|
||||
tb_players, fd_nickname2018, fd_myclubinfodata, fd_joinclubinfodata, fd_fightcorddata, fd_userid2018, player.userid);
|
||||
|
||||
//List<ISqlAloneParameter<SqlDbType>> sqlpms = new List<ISqlAloneParameter<SqlDbType>>();
|
||||
|
||||
/* 老的存储
|
||||
var clubsinfo = ListPlayerofClubTotr_clubsOfPlayer(player.myClubs);
|
||||
byte[] bts1 = BinaryConvert.StructToBytes(clubsinfo);
|
||||
var param1 = new SqlParameter("@myclubinfo", SqlDbType.Binary, bts1.Length) { Value = bts1 };//sqlpms.Add(new SqlAloneParameter("@myclubinfo", bts, bts.Length));
|
||||
*/
|
||||
var paramNick = new SqlParameter("@nickname", SqlDbType.Text) { Value = player.nickname };
|
||||
|
||||
var clubsinfo = JsonPack.GetJson(player.myClubs);
|
||||
var param1 = new SqlParameter("@myclubinfo", SqlDbType.Text) { Value = clubsinfo };
|
||||
|
||||
/* 老的存储
|
||||
var clubsinfo2 = ListPlayerofClubTotr_clubsOfPlayer(player.joinClubs);
|
||||
var bts2 = BinaryConvert.StructToBytes(clubsinfo2);
|
||||
var param2 = new SqlParameter("@joinclubinfo", SqlDbType.Binary, bts2.Length) { Value = bts2 };//sqlpms.Add(new SqlAloneParameter("@joinclubinfo", bts, bts.Length));
|
||||
*/
|
||||
var clubsinfo2 = JsonPack.GetJson(player.joinClubs);
|
||||
var param2 = new SqlParameter("@joinclubinfo", SqlDbType.Text) { Value = clubsinfo2 };
|
||||
|
||||
/* 老的存储
|
||||
var pfr = ListidToFightRecordid(player.fightRecordids);
|
||||
var bts3 = BinaryConvert.StructToBytes(pfr);
|
||||
var param3 = new SqlParameter("@fightrecord", SqlDbType.Binary, bts3.Length) { Value = bts3 };//sqlpms.Add(new SqlAloneParameter("@fightrecord", bts, bts.Length));
|
||||
*/
|
||||
var pfd = JsonPack.GetJson(player.fightRecordids);
|
||||
var param3 = new SqlParameter("@fightrecord", SqlDbType.Text) { Value = pfd };
|
||||
|
||||
var sqlpms = new SqlParameter[] { paramNick, param1, param2, param3 };
|
||||
return 1 == GameDB.Instance.ExceSql(dbbase.game2018, sql, sqlpms);
|
||||
}
|
||||
|
||||
public static bool UpdatePlayers(IEnumerable<ClubPlayer> players)
|
||||
{
|
||||
var transaction = GameDB.Instance.BeginTransaction(dbbase.game2018);
|
||||
var succ = false;
|
||||
try
|
||||
{
|
||||
foreach (var player in players)
|
||||
{
|
||||
string sql = string.Format("update Top(1) {0} set {1}=@nickname,{2}=@myclubinfo,{3}=@joinclubinfo,{4}=@fightrecord where {5}={6};",
|
||||
tb_players, fd_nickname2018, fd_myclubinfodata, fd_joinclubinfodata, fd_fightcorddata, fd_userid2018, player.userid);
|
||||
var paramNick = new SqlAloneParameter("@nickname", player.nickname, player.nickname.Length, SqlDbType.Text);
|
||||
var clubsinfo = JsonPack.GetJson(player.myClubs);
|
||||
var param1 = new SqlAloneParameter("@myclubinfo", clubsinfo, clubsinfo.Length, SqlDbType.Text);
|
||||
var clubsinfo2 = JsonPack.GetJson(player.joinClubs);
|
||||
var param2 = new SqlAloneParameter("@joinclubinfo", clubsinfo2, clubsinfo2.Length, SqlDbType.Text);
|
||||
var pfd = JsonPack.GetJson(player.fightRecordids);
|
||||
var param3 = new SqlAloneParameter("@fightrecord", pfd, pfd.Length, SqlDbType.Text);
|
||||
var sqlpms = new List<ISqlAloneParameter<SqlDbType>> { paramNick, param1, param2, param3 };
|
||||
succ = GameDB.Instance.TransactionAddSql(transaction, sql, sqlpms) == 1;
|
||||
if (transaction.isException)
|
||||
{
|
||||
throw transaction.exception;//发生异常,抛出
|
||||
}
|
||||
if (!succ)
|
||||
{
|
||||
throw new Exception($"UpdatePlayers failed, sql: {sql}");
|
||||
}
|
||||
}
|
||||
succ = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.Error($"UpdatePlayers ex:{ex}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
succ &= GameDB.Instance.SubTransaction(transaction);
|
||||
}
|
||||
return succ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下一个竞技比赛id
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int GetNextClubId()
|
||||
{
|
||||
string sql = string.Format("select top(1) id from {0} order by {1} desc", tb_clubs, fd_id);
|
||||
DataSet ds = new DataSet();
|
||||
GameDB.Instance.ExceSql(dbbase.game2018, sql, null, ds);
|
||||
if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count < 1) return 1;
|
||||
return int.Parse(ds.Tables[0].Rows[0]["id"].ToString()) + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查看公告格式
|
||||
/// </summary>
|
||||
/// <param name="notice"></param>
|
||||
/// <returns></returns>
|
||||
private static bool CheckNotice(string notice)
|
||||
{
|
||||
return BaseFun.CheckStringLength(notice, 0, 32, true, Encoding.GetEncoding("gb2312"))
|
||||
&& BaseFun.ProcessSqlStr(notice);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行sql语句修改竞技比赛公告
|
||||
/// </summary>
|
||||
/// <param name="clubid"></param>
|
||||
/// <param name="notice"></param>
|
||||
public static void ExceSqlSetClubNotice(int clubid, string notice)
|
||||
{
|
||||
//string sql = string.Format("update top(1) {2} set {3} = '{0}' where {4} = {1}", notice, clubid, tb_clubs, fd_notice, fd_id);
|
||||
// update top(1) {tb_clubs} set {fd_notice} = '{notice}' where {fd_id} = {clubid}
|
||||
|
||||
string sql = string.Format("update top(1) {0} set {1} = @notice where [ID] = @p2", tb_clubs, fd_notice);
|
||||
GameDB.Instance.ExceSql(dbbase.game2018, sql, new SqlParameter[]{
|
||||
new SqlParameter("@p2", SqlDbType.Int){ Value = clubid - ClubDataManager.idIncrement },
|
||||
new SqlParameter("@notice",notice ?? (object)DBNull.Value)
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存俱乐部密码
|
||||
/// </summary>
|
||||
/// <param name="clubid"></param>
|
||||
/// <param name="notice"></param>
|
||||
public static void SaveClubPassword(int clubid, string password)
|
||||
{
|
||||
string sql = string.Format("update top(1) {0} set {1} = @password where [ID] = @p2", tb_clubs, fd_Password);
|
||||
GameDB.Instance.ExceSql(dbbase.game2018, sql, new SqlParameter[]{
|
||||
new SqlParameter("@p2", SqlDbType.Int){ Value = clubid - ClubDataManager.idIncrement },
|
||||
new SqlParameter("@password",password ?? string.Empty)
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改俱乐部群主的名字
|
||||
/// </summary>
|
||||
/// <param name="clubid"></param>
|
||||
/// <param name="nickName"></param>
|
||||
public static void UpdateLeaderName(int clubid, string nickName)
|
||||
{
|
||||
string sql = string.Format("update top(1) {0} set {1} = @nickName where [ID] = @p2", tb_clubs, fd_leadername);
|
||||
GameDB.Instance.ExceSql(dbbase.game2018, sql, new SqlParameter[]{
|
||||
new SqlParameter("@p2", SqlDbType.Int){ Value = clubid - ClubDataManager.idIncrement },
|
||||
new SqlParameter("@nickName",nickName ?? string.Empty)
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置竞技比赛公告
|
||||
/// </summary>
|
||||
/// <param name="clubid">竞技比赛id</param>
|
||||
/// <param name="notice">公告</param>
|
||||
/// <returns>公告符不符合格式</returns>
|
||||
public static bool SetClubNotice(int clubid, string notice)
|
||||
{
|
||||
bool r = CheckNotice(notice);
|
||||
|
||||
if (r)
|
||||
{
|
||||
ExceSqlSetClubNotice(clubid, notice);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置竞技比赛公告
|
||||
/// </summary>
|
||||
/// <param name="clubid">竞技比赛id</param>
|
||||
/// <param name="notice">公告</param>
|
||||
/// <returns></returns>
|
||||
public static bool SetClubNoticeAsyn(int clubid, string notice)
|
||||
{
|
||||
bool r = CheckNotice(notice);
|
||||
|
||||
if (r)
|
||||
{
|
||||
Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
ExceSqlSetClubNotice(clubid, notice);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算带折扣房卡的最终值
|
||||
/// </summary>
|
||||
public static int CalClubCardWithDiscount(int clubId, int cardCnt)
|
||||
{
|
||||
var discount = ClubRCDiscountRedisUtil.GetClub(clubId);
|
||||
return (int)Math.Round(cardCnt / discount);
|
||||
}
|
||||
|
||||
public static Task<bool> AddClubCardAsync(int clubId,int cardCnt)
|
||||
{
|
||||
return Task.Run(() => AddClubCard(clubId, cardCnt));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加竞技比赛房卡
|
||||
/// </summary>
|
||||
/// <param name="clubid">竞技比赛id</param>
|
||||
/// <param name="cardCnt">房卡数量</param>
|
||||
public static bool AddClubCard(int clubid, int cardCnt)
|
||||
{
|
||||
string sql;
|
||||
int cnt = Math.Abs(cardCnt);
|
||||
|
||||
if (cardCnt >= 0) //返还房卡
|
||||
sql = $"update top(1) {tb_clubs} set {fd_cards} = {fd_cards} + {cnt},{fd_integral} = {fd_integral} - {cnt} where {fd_id} = {clubid - idIncrement}";
|
||||
//sql = string.Format("update Top(1) {0} set {1} = {1} + {2}, {5} = {5} - {2} where {3} = {4}", tb_clubs, fd_cards, cardCnt, fd_id, , (clubid - idIncrement));
|
||||
else
|
||||
sql = $"update top(1) {tb_clubs} set {fd_cards} = {fd_cards} - {cnt},{fd_integral} = {fd_integral} + {cnt} where {fd_id} = {clubid - idIncrement}";
|
||||
//sql = string.Format("update Top(1) {0} set {1} = {1} {2} where {3} = {4}", tb_clubs, fd_cards, cardCnt, fd_id, (clubid - idIncrement));
|
||||
|
||||
Debug.ImportantLog(sql);
|
||||
return GameDB.Instance.ExceSql(dbbase.game2018, sql) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步添加竞技比赛房卡
|
||||
/// </summary>
|
||||
/// <param name="clubid"></param>
|
||||
/// <param name="cardCnt"></param>
|
||||
public static async Task<bool> AddClubCardAsyn(int clubid, int cardCnt)
|
||||
{
|
||||
return await Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
return AddClubCard(clubid, cardCnt);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// 获取竞技比赛消息_未处理的
|
||||
/// </summary>
|
||||
/// <param name="clubid">竞技比赛id</param>
|
||||
/// <param name="count">最大接收数量</param>
|
||||
/// <returns></returns>
|
||||
public static List<ClubMessage> GetClubMessage(int clubid, int count) {
|
||||
List<ClubMessage> msgs = new List<ClubMessage>();
|
||||
string sql = string.Format("select Top({0}) * from {1} where {2}={3} and {4}=0 Order By sendTime desc;",
|
||||
count, tb_message, fd_receiveid, clubid - idIncrement, fd_state);
|
||||
DataSet ds = new DataSet();
|
||||
GameDB.Instance.ExceSql(dbbase.game2018, sql, null, ds);
|
||||
if (ds.Tables.Count == 0)
|
||||
return msgs;
|
||||
DataTable dt = ds.Tables[0];
|
||||
for (int i = 0; i < dt.Rows.Count; i++) {
|
||||
msgs.Add(LoadClubMessage(dt.Rows[i]));
|
||||
}
|
||||
return msgs;
|
||||
}
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// 加载竞技比赛消息
|
||||
/// </summary>
|
||||
/// <param name="row">行</param>
|
||||
/// <returns></returns>
|
||||
public static ClubMessage LoadClubMessage(DataRow row)
|
||||
{
|
||||
ClubMessage clubmsg = new ClubMessage();
|
||||
clubmsg.id = (int)row[fd_id];
|
||||
clubmsg.style = (int)row[fd_style];
|
||||
clubmsg.state = (int)row[fd_state];
|
||||
clubmsg.content = row[fd_strcontent].ToString();
|
||||
clubmsg.sendTime = DateTime.Parse(row[fd_sendTime].ToString());
|
||||
string doTime = row[fd_dotime].ToString();
|
||||
if (!string.IsNullOrEmpty(doTime))
|
||||
{
|
||||
clubmsg.doTime = DateTime.Parse(doTime);
|
||||
}
|
||||
if (row[fd_doman] != DBNull.Value)
|
||||
clubmsg.doman = (int)row[fd_doman];
|
||||
if (row[fd_domanname] != DBNull.Value)
|
||||
clubmsg.domanname = row[fd_domanname].ToString();
|
||||
if (row[fd_receiveid] != DBNull.Value)
|
||||
clubmsg.reciveid = (int)row[fd_receiveid] + idIncrement;
|
||||
clubmsg.sendid = (int)row[fd_sendid];
|
||||
clubmsg.sendname = row[fd_sendname].ToString();
|
||||
if (row.Table.Columns.Contains("Sex"))
|
||||
if (row["Sex"] != DBNull.Value)
|
||||
clubmsg.SendSex = (int)row["Sex"];
|
||||
clubmsg.param1 = (int)row["param1"];
|
||||
clubmsg.param2 = row["param2"] is DBNull ? null : (string)row["param2"];
|
||||
return clubmsg;
|
||||
}
|
||||
|
||||
public static Task<ClubMessage> GetClubMessageAsync(int msgid)
|
||||
{
|
||||
return Task.Run(
|
||||
() => GetClubMessage(msgid)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取竞技比赛消息
|
||||
/// </summary>
|
||||
/// <param name="msgid"></param>
|
||||
/// <returns></returns>
|
||||
public static ClubMessage GetClubMessage(int msgid)
|
||||
{
|
||||
string sql = string.Format($"select Top(1) * from {tb_message} where {fd_id} = {msgid}");
|
||||
|
||||
DataSet ds = new DataSet();
|
||||
GameDB.Instance.ExceSql(dbbase.game2018, sql, null, ds);
|
||||
if (ds.Tables.Count == 0)
|
||||
return null;
|
||||
|
||||
DataTable dt = ds.Tables[0];
|
||||
return LoadClubMessage(dt.Rows[0]);
|
||||
}
|
||||
|
||||
public static Task<List<ClubMessage>> GetClubMessageByClubAsync(int clubId)
|
||||
{
|
||||
return Task.Run(() => GetClubMessageByClub(clubId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取竞技比赛未处理的消息
|
||||
/// </summary>
|
||||
/// <param name="club"></param>
|
||||
/// <returns></returns>
|
||||
public static List<ClubMessage> GetClubMessageByClub(int clubid)
|
||||
{
|
||||
List<ClubMessage> lst = new List<ClubMessage>();
|
||||
string sql = $"SELECT TOP 500 c.[id],c.[style],c.[state],c.[sendTime],c.[dotime],c.[doman],c.[domanname],c.[receiveid],c.[sendid],c.[sendname],c.[strcontent],c.[param1],c.[param2],us.Sex FROM [game2018].[dbo].[clubmsg] c INNER JOIN jnxdgame.dbo.tbUserBaseInfo us on c.sendid=us.UserID where c.receiveid= {clubid - idIncrement} and (((c.style=0 or c.style=2) and c.state=0) or (c.style=1 and c.state=4)) order by c.id desc";//and (c.style=0 or c.style=2)
|
||||
DataSet ds = new DataSet();
|
||||
GameDB.Instance.ExceSql(dbbase.game2018, sql, null, ds);
|
||||
if (BaseFun.DataSetIsNullOrEmpty(ds) || BaseFun.DataTableIsNullOrEmpty(ds.Tables[0]))
|
||||
return lst;
|
||||
|
||||
var dt = ds.Tables[0];
|
||||
int len = dt.Rows.Count;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
lst.Add(LoadClubMessage(dt.Rows[i]));
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取个人的消息记录
|
||||
/// </summary>
|
||||
/// <param name="userid"></param>
|
||||
/// <returns></returns>
|
||||
public static List<ClubMessage> GetClubMessageByPerson(int userid)
|
||||
{
|
||||
List<ClubMessage> lst = new List<ClubMessage>();
|
||||
string sql = string.Format($"select * from {tb_message} where {fd_sendid} = {userid} order by {fd_id} desc");
|
||||
DataSet ds = new DataSet();
|
||||
GameDB.Instance.ExceSql(dbbase.game2018, sql, null, ds);
|
||||
if (BaseFun.DataSetIsNullOrEmpty(ds) || BaseFun.DataTableIsNullOrEmpty(ds.Tables[0]))
|
||||
return lst;
|
||||
|
||||
var dt = ds.Tables[0];
|
||||
int len = dt.Rows.Count;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
lst.Add(LoadClubMessage(dt.Rows[i]));
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
public static Task<int> DoClubMessageAsync(ClubMessage clubmsg)
|
||||
{
|
||||
return Task.Run(() => DoClubMessage(clubmsg));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新竞技比赛消息
|
||||
/// </summary>
|
||||
/// <param name="clubmsg"></param>
|
||||
public static int DoClubMessage(ClubMessage clubmsg)
|
||||
{
|
||||
string sql = string.Format($"update top(1) {tb_message} set {fd_state}={clubmsg.state},{fd_doman}='{clubmsg.doman}',{fd_dotime}='{clubmsg.doTime}',{fd_domanname}=@domanname where {fd_id}={clubmsg.id} and ((({fd_style}=0 or {fd_style}=2) and {fd_state} = 0) or ({fd_style}=1 and {fd_state} = 4))");
|
||||
return GameDB.Instance.ExceSql(dbbase.game2018, sql, new[] { new SqlParameter("@domanname", clubmsg.domanname ?? (object)DBNull.Value) });
|
||||
}
|
||||
|
||||
public static Task<bool> InsertClubMessageAsync(ClubMessage clubmsg)
|
||||
{
|
||||
return Task.Run(() => InsertClubMessage(clubmsg));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入一条消息
|
||||
/// </summary>
|
||||
/// <param name="clubmsg"></param>
|
||||
/// <returns></returns>
|
||||
public static bool InsertClubMessage(ClubMessage clubmsg)
|
||||
{
|
||||
|
||||
if (clubmsg.domanname == null)
|
||||
clubmsg.domanname = string.Empty;
|
||||
|
||||
if (clubmsg.content == null)
|
||||
clubmsg.content = string.Empty;
|
||||
|
||||
|
||||
string sql = $"insert into {tb_message}({fd_style},{fd_state},{fd_sendTime},{fd_receiveid},{fd_sendid},{fd_sendname},{fd_strcontent})" +
|
||||
$" values({clubmsg.style},{clubmsg.state},'{clubmsg.sendTime}',{clubmsg.reciveid},{clubmsg.sendid},@sendname,@content)";
|
||||
|
||||
return GameDB.Instance.ExceSql(dbbase.game2018, sql, new[] {
|
||||
new SqlParameter("@content", clubmsg.content ?? (object)DBNull.Value),
|
||||
new SqlParameter("@sendname", clubmsg.sendname ?? (object)string.Empty)//clubmsg 的sendname字段不允许为null
|
||||
}) == 1;
|
||||
|
||||
}
|
||||
|
||||
public static Task<bool> AskForJoinClubMessageAsync(ClubMessage clubmsg)
|
||||
{
|
||||
return Task.Run(() => AskForJoinClubMessage(clubmsg));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求加入竞技比赛
|
||||
/// </summary>
|
||||
/// <param name="clubmsg"></param>
|
||||
public static bool AskForJoinClubMessage(ClubMessage clubmsg)
|
||||
{
|
||||
string sql = string.Empty;
|
||||
try
|
||||
{
|
||||
if (clubmsg.domanname == null)
|
||||
clubmsg.domanname = string.Empty;
|
||||
|
||||
if (clubmsg.content == null)
|
||||
clubmsg.content = string.Empty;
|
||||
|
||||
//如果不存在 这个竞技比赛的申请 就可以去申请
|
||||
sql = string.Format($"if not exists(select Top(1) 1 from {tb_message} where {fd_receiveid} = {clubmsg.reciveid - idIncrement} and {fd_sendid} = {clubmsg.sendid} and {fd_style} = {clubmsg.style} and {fd_state} = {clubmsg.state}) begin{Environment.NewLine}");
|
||||
sql += string.Format($"insert into {tb_message}({fd_style},{fd_state},{fd_sendTime},{fd_doman},{fd_domanname},{fd_receiveid},{fd_sendid},{fd_sendname},{fd_strcontent}, param1, param2) " +
|
||||
$"values({clubmsg.style},{clubmsg.state},'{clubmsg.sendTime}',{clubmsg.doman},@domanname,{clubmsg.reciveid - idIncrement},{clubmsg.sendid},@sendname,@content, {clubmsg.param1}, @param2);");//{(clubmsg.param2 == null ? "NULL" : string.Format("'{0}'", clubmsg.param2))}
|
||||
sql += " end;";
|
||||
|
||||
//Debug.Warning("AskForJoinClubMessage:" + sql);
|
||||
|
||||
/*
|
||||
* 0724 帮看下,这里有语法错误,输出日志看下 --over
|
||||
*
|
||||
*
|
||||
* */
|
||||
|
||||
return GameDB.Instance.ExceSql(dbbase.game2018, sql, new[]{
|
||||
new SqlParameter("@domanname", clubmsg.domanname),
|
||||
new SqlParameter("@sendname", clubmsg.sendname),
|
||||
new SqlParameter("@content", clubmsg.content),
|
||||
new SqlParameter("@param2", clubmsg.param2 ?? (object)DBNull.Value)
|
||||
}) == 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("AskForJoinClubMessage: " + sql, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加入竞技比赛数据处理_异步的
|
||||
/// </summary>
|
||||
/// <param name="club"></param>
|
||||
/// <param name="clubPlayer"></param>
|
||||
/// <returns></returns>
|
||||
public static Task ClubPlayerChange_Asyn(Club_Base club, ClubPlayer clubPlayer)
|
||||
{
|
||||
return Task.Factory.StartNew(
|
||||
() => ClubPlayerChange(club, clubPlayer)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加入竞技比赛数据处理
|
||||
/// </summary>
|
||||
/// <param name="club"></param>
|
||||
/// <param name="clubPlayer"></param>
|
||||
public static void ClubPlayerChange(Club_Base club, ClubPlayer clubPlayer)
|
||||
{
|
||||
//保存竞技比赛数据以及玩家数据
|
||||
var spp = GameDB.Instance.BeginTransaction(dbbase.game2018);
|
||||
string sql = string.Format("update Top(1) {0} set {1} = {2}, {3}=@mans where {4} = {5};" //更改竞技比赛
|
||||
, tb_clubs, fd_manCnt, club.mancnt, fd_mans, fd_id, club.id - idIncrement);
|
||||
|
||||
var ids = ArrayTotr_clubMans(club.mansid);
|
||||
byte[] bts = BinaryConvert.StructToBytes(ids);
|
||||
List<ISqlAloneParameter<SqlDbType>> sqlpms = new List<ISqlAloneParameter<SqlDbType>>();
|
||||
sqlpms.Add(new SqlAloneParameter("@mans", bts, bts.Length));
|
||||
GameDB.Instance.TransactionAddSql(spp, sql, sqlpms);
|
||||
|
||||
sql = string.Format("update Top(1) {0} set {1} = @joinclub,{4}=@joinclubnew where {2} = {3};",
|
||||
tb_players, fd_joinclubinfo, fd_userid2018, clubPlayer.userid, fd_joinclubinfodata);
|
||||
|
||||
var clubsinfo = ListPlayerofClubTotr_clubsOfPlayer(clubPlayer.joinClubs);
|
||||
bts = BinaryConvert.StructToBytes(clubsinfo);
|
||||
var strJoin = JsonPack.GetJson(clubPlayer.joinClubs);
|
||||
sqlpms = new List<ISqlAloneParameter<SqlDbType>>();
|
||||
sqlpms.Add(new SqlAloneParameter("joinclub", bts, bts.Length));
|
||||
sqlpms.Add(new SqlAloneParameter("joinclubnew", strJoin, strJoin.Length, SqlDbType.Text));
|
||||
GameDB.Instance.TransactionAddSql(spp, sql, sqlpms);
|
||||
|
||||
if (!GameDB.Instance.SubTransaction(spp))
|
||||
throw spp.exception;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存玩法
|
||||
/// </summary>
|
||||
/// <param name="clubid"></param>
|
||||
/// <param name="ways"></param>
|
||||
static void SavePlayWay(int clubid, string ways)
|
||||
{
|
||||
string sql = string.Format("update Top(1) {0} set {1}={2},{3}=@way where {4}={5};",
|
||||
tb_clubs, fd_wayVer, Club_Base.allServerVer, fd_newways, fd_id, clubid - idIncrement);
|
||||
|
||||
//List<ISqlAloneParameter<SqlDbType>> sqlpms = new List<ISqlAloneParameter<SqlDbType>>();
|
||||
//sqlpms.Add(new SqlAloneParameter("@way", ways, ways.Length, SqlDbType.Text));
|
||||
|
||||
GameDB.Instance.ExceSql(dbbase.game2018, sql, new SqlParameter[] { new SqlParameter("@way", SqlDbType.Text, ways.Length) { Value = ways } });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存玩法
|
||||
/// </summary>
|
||||
/// <param name="club"></param>
|
||||
public static void SavePlayWay(Club_Base club)
|
||||
{
|
||||
int clubid = club.id;
|
||||
string ways = JsonPack.GetJson(club.ways);
|
||||
|
||||
SavePlayWay(clubid, ways);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存玩法_异步操作
|
||||
/// </summary>
|
||||
/// <param name="club"></param>
|
||||
public static void SavePlayWayAysn(Club_Base club)
|
||||
{
|
||||
int clubid = club.id;
|
||||
string ways = JsonPack.GetJson(club.ways);
|
||||
|
||||
Task.Factory.StartNew(
|
||||
() => SavePlayWay(clubid, ways)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询
|
||||
/// </summary>
|
||||
public static List<FightScore> GetFightScoresByPage(int clubId, DateTime startDateTime, DateTime endDateTime,
|
||||
int pageSize, int pageIndex)
|
||||
{
|
||||
var sqlclubId = clubId - ClubDataManager.idIncrement;
|
||||
string subSql = "(SELECT ROW_NUMBER() OVER (ORDER BY id ASC) AS rownumber, * FROM club_FightRecord";
|
||||
subSql += $" WHERE clubid={sqlclubId} AND endtime BETWEEN '{startDateTime}' and '{endDateTime}')";
|
||||
string sql = $"SELECT TOP {pageSize} * FROM {subSql} AS temp_row WHERE rownumber > {pageSize * pageIndex}";
|
||||
Debug.Info($"sql:{sql}");
|
||||
return GetFightScoreBySql(sql, sqlclubId);
|
||||
}
|
||||
|
||||
private static List<FightScore> GetFightScoreBySql(string sql,int clubId=0)
|
||||
{
|
||||
List<FightScore> fights = new List<FightScore>();
|
||||
DataSet ds = new DataSet();
|
||||
GameDB.Instance.ExceSql(dbbase.game2018, sql, null, ds);
|
||||
if (ds.Tables == null || ds.Tables.Count == 0)
|
||||
{
|
||||
//没有记录
|
||||
return fights;
|
||||
}
|
||||
DataTable dt = ds.Tables[0];
|
||||
if (dt.Rows != null && dt.Rows.Count > 0)
|
||||
{
|
||||
int len = dt.Rows.Count;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
fights.Add(GetFightScore(clubId, dt.Rows[i]));
|
||||
}
|
||||
}
|
||||
return fights;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取某个俱乐部的某个玩法的前多少条战斗记录
|
||||
/// </summary>
|
||||
/// <param name="clubid">界面显示的俱乐部ID</param>
|
||||
/// <param name="wayId">玩法ID</param>
|
||||
/// <param name="top">前多少条</param>
|
||||
/// <returns></returns>
|
||||
public static List<FightScore> GetFightScoreByWayId(int clubid,string wayId,int top = 100)
|
||||
{
|
||||
var sql = $"select top {top} * from club_FightRecord where clubid = {clubid- idIncrement} and wayid='{wayId}' order by id desc";
|
||||
return GetFightScoreBySql(sql);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载战斗记录
|
||||
/// </summary>
|
||||
/// <param name="clubid"></param>
|
||||
/// <param name="weiyima"></param>
|
||||
/// <returns></returns>
|
||||
public static FightScore LoadFightScore(int clubid, string weiyima)
|
||||
{
|
||||
DataTable dt = GameDB.Instance.selectDb(dbbase.game2018, tb_ClubFightRecord, null, string.Format("clubid={0} and weiyima='{1}'", clubid - idIncrement, weiyima));
|
||||
if (dt.Rows != null && dt.Rows.Count > 0)
|
||||
{
|
||||
return GetFightScore(clubid, dt.Rows[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据id获取战绩记录
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public static FightScore GetFightScoreById(int id)
|
||||
{
|
||||
DataTable dt = GameDB.Instance.selectDb(dbbase.game2018, tb_ClubFightRecord, null, string.Format("id={0}", id));
|
||||
if (dt.Rows != null && dt.Rows.Count > 0)
|
||||
{
|
||||
return GetFightScore(-1, dt.Rows[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取战斗记录
|
||||
/// </summary>
|
||||
/// <param name="row"></param>
|
||||
/// <returns></returns>
|
||||
public static FightScore GetFightScore(int clubid, DataRow row)
|
||||
{
|
||||
FightScore fs = new FightScore();
|
||||
fs.clubid = clubid > 0 ? clubid : (idIncrement + (int)row["clubid"]);
|
||||
fs.id = (int)row[fd_id];
|
||||
fs.roomnum = (int)row[fd_roomnum];
|
||||
fs.warCnt = (int)row[fd_warcnt];
|
||||
fs.wayid = row[fd_wayid].ToString(); //未使用
|
||||
fs.game_serid = (int)row[fd_gameserid];
|
||||
fs.weiyima = row[fd_weiyima].ToString();
|
||||
string json = row[fd_scores].ToString();
|
||||
fs.scores = JsonPack.GetData<FightScore.Player[]>(json);
|
||||
fs.startTime = DateTime.Parse(row[fd_startTime].ToString());
|
||||
fs.endTime = DateTime.Parse(row[fd_endTime].ToString());
|
||||
if (row["CardNum"] != DBNull.Value)
|
||||
{
|
||||
fs.CardNum = (int)row["CardNum"];
|
||||
}
|
||||
if (row["style"] != DBNull.Value)
|
||||
{
|
||||
fs.Style = (short)row["style"];
|
||||
}
|
||||
if (row["disUserId"] != DBNull.Value)
|
||||
{
|
||||
fs.DisUserId = (int)row["disUserId"];
|
||||
}
|
||||
//if (row["playclub"] != DBNull.Value)
|
||||
//{
|
||||
// string strp = row["playclub"].ToString();
|
||||
// if (!string.IsNullOrEmpty(strp) && strp.Length > 2)
|
||||
// {
|
||||
// if (strp.IndexOf("Name") >= 0)
|
||||
// {
|
||||
// fs.PlayInClubInfo = JsonPack.GetData<Dictionary<int, IdName>>(strp);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// fs.PlayInClub = JsonPack.GetData<Dictionary<int, int>>(strp);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
return fs;
|
||||
}
|
||||
|
||||
static string GetHidesKey(int clubid)
|
||||
{
|
||||
return $"HidesWay:{clubid}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存俱乐部隐藏玩法
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <param name="list"></param>
|
||||
public static void SaveHideWays(int clubId, List<string> list,bool isSync = false)
|
||||
{
|
||||
if (clubId <= 0 || list == null) return;
|
||||
var key = GetHidesKey(clubId);
|
||||
var str = JsonPack.GetJson(list);
|
||||
|
||||
Debug.Info($"保存隐藏:{clubId}{str}");
|
||||
if (isSync)
|
||||
{
|
||||
redisManager.GetBiSaidb(6).StringSetAsync(key, str);
|
||||
}
|
||||
else
|
||||
{
|
||||
redisManager.GetBiSaidb(6).StringSet(key, str);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除隐藏玩法
|
||||
/// </summary>
|
||||
public static void RemoveHideWays(int clubId)
|
||||
{
|
||||
var key = GetHidesKey(clubId);
|
||||
redisManager.GetBiSaidb(6).KeyDelete(key);
|
||||
}
|
||||
|
||||
public static Task<List<string>> GetHidesAsync(int clubId)
|
||||
{
|
||||
return Task.Run(() => GetHides(clubId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取俱乐部隐藏玩法
|
||||
/// </summary>
|
||||
/// <param name="clubid"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string> GetHides(int clubid)
|
||||
{
|
||||
if (clubid <= 0) return new List<string>();
|
||||
var key = GetHidesKey(clubid);
|
||||
string str = redisManager.GetBiSaidb(6).StringGet(key);
|
||||
if (!string.IsNullOrWhiteSpace(str) && str.Length > 2)
|
||||
{
|
||||
Debug.Info($"读取隐藏:{clubid}{str}");
|
||||
return JsonPack.GetData<List<string>>(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
static string GetPlayerHideWayKey(int clubId)
|
||||
{
|
||||
return $"GetPlayerHideWayKey:{clubId}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存玩家不能玩哪些玩法
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <param name="data"></param>
|
||||
public static void SavePlayerHideWay(int clubId, Dictionary<int, List<string>> data)
|
||||
{
|
||||
if (clubId <= 0 || data == null) return;
|
||||
var key = GetPlayerHideWayKey(clubId);
|
||||
var str = JsonPack.GetJson(data);
|
||||
redisManager.GetBiSaidb(6).StringSet(key, str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取玩家不能玩哪些玩法
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<int, List<string>> GetPlayerHideWay(int clubId)
|
||||
{
|
||||
if (clubId <= 0) return new Dictionary<int, List<string>>();
|
||||
var key = GetPlayerHideWayKey(clubId);
|
||||
string str = redisManager.GetBiSaidb(6).StringGet(key);
|
||||
if (!string.IsNullOrWhiteSpace(str) && str.Length > 2)
|
||||
{
|
||||
return JsonPack.GetData<Dictionary<int, List<string>>>(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Dictionary<int, List<string>>();
|
||||
}
|
||||
}
|
||||
|
||||
static string GetClubFightRecordKey()
|
||||
{
|
||||
return "GetClubFightRecordKey";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏报错战斗结束数据到reids,俱乐部服务器去redis里面去拿
|
||||
/// </summary>
|
||||
/// <param name="jsonData"></param>
|
||||
/// <returns>true保存成功 false保存失败</returns>
|
||||
public static bool SaveClubFightRecord(string jsonData)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(jsonData)) return true;
|
||||
try
|
||||
{
|
||||
redisManager.Getdb(9).ListRightPush(GetClubFightRecordKey(), jsonData); //从尾部添加
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Error($"保存战绩数据失败,msg:{e.Message},code:{e.StackTrace}");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string GetOneClubFightRecord()
|
||||
{
|
||||
return redisManager.Getdb(9).ListLeftPop(GetClubFightRecordKey()); //从头部取
|
||||
}
|
||||
}
|
||||
}
|
||||
330
GameDAL/Club/ClubLeagueMatchAdo.cs
Normal file
330
GameDAL/Club/ClubLeagueMatchAdo.cs
Normal file
@ -0,0 +1,330 @@
|
||||
using ObjectModel.Club;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GameDAL.Game;
|
||||
using MrWu.DB;
|
||||
using MrWu.Debug;
|
||||
using Server.DB.Sql;
|
||||
|
||||
namespace GameDAL.Club
|
||||
{
|
||||
/// <summary>
|
||||
/// 俱乐部联赛数据逻辑
|
||||
/// </summary>
|
||||
public static class ClubLeagueMatchAdo
|
||||
{
|
||||
public static readonly dbbase sqldb = dbbase.game2018;
|
||||
public static readonly string tb_JoinInClubLeagueMatch = "JoinInClubLeagueMatch";
|
||||
public static readonly string tb_LeagueAwardRecord = "LeagueAwardRecord";
|
||||
public static readonly string tb_LeagueClubLeaguePower = "LeagueClubLeaguePower";
|
||||
public static readonly string tb_LeagueClubLiveTask = "LeagueClubLiveTask";
|
||||
public static readonly string tb_LeagueMatchBanDesk = "LeagueMatchBanDesk";
|
||||
public static readonly string tb_LeagueMatchClubScore = "LeagueMatchClubScore";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取俱乐部权限 异步的
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <returns></returns>
|
||||
public static Task<ClubLeaguePower> GetClubLeaguePowerAsync(int clubId)
|
||||
{
|
||||
return Task.Run(() => GetClubLeaguePower(clubId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取俱乐部权限
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <returns></returns>
|
||||
public static ClubLeaguePower GetClubLeaguePower(int clubId)
|
||||
{
|
||||
var sql = $"select top 1 * from {tb_LeagueClubLeaguePower} where clubId = {clubId}";
|
||||
return sqldb.ExecuteEntities(sql, p => p.ToObject<ClubLeaguePower>()).FirstOrDefault();
|
||||
}
|
||||
|
||||
public static bool SaveClubLeaguePower(ClubLeaguePower model)
|
||||
{
|
||||
var sql = new StringBuilder();
|
||||
if (model.ClubLeaguePowerId < 1)
|
||||
{
|
||||
sql.Append(
|
||||
$"insert into {tb_LeagueClubLeaguePower}({nameof(model.ClubId)},{nameof(model.IsCanCreate)},{nameof(model.IsCanJoin)}) ");
|
||||
sql.Append($"values({model.ClubId},{model.IsCanCreate.SQLValue()},{model.IsCanJoin.SQLValue()})");
|
||||
sql.AppendLine($"if @@rowcount > 0 begin");
|
||||
sql.AppendLine(
|
||||
$" select top 1 {nameof(model.ClubLeaguePowerId)} from {tb_LeagueClubLeaguePower} where {nameof(model.ClubLeaguePowerId)} = SCOPE_IDENTITY()");
|
||||
sql.AppendLine("end");
|
||||
var result = sqldb.ExecuteScalar(sql.ToString());
|
||||
model.ClubLeaguePowerId = result is int id ? id : throw new Exception("增加记录失败, sql:" + sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
sql.Append($"update {tb_LeagueClubLeaguePower} set ");
|
||||
sql.Append($"{nameof(model.ClubId)} = {model.ClubId},");
|
||||
sql.Append($"{nameof(model.IsCanCreate)} = {model.IsCanCreate.SQLValue()},");
|
||||
sql.Append($"{nameof(model.IsCanJoin)} = {model.IsCanJoin.SQLValue()}");
|
||||
sql.Append($" where {nameof(model.ClubLeaguePowerId)} = {model.ClubLeaguePowerId}");
|
||||
if (1 != sqldb.ExecuteNonQuery(sql.ToString()))
|
||||
{
|
||||
throw new Exception("更新记录失败,sql: " + sql);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存联赛禁桌数据,每次删除数据在保存。根据ClubMatchId 删除
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
public static bool SaveBanDesks(List<LeagueMatchBanDesk> list, int clubMatchId)
|
||||
{
|
||||
return sqldb.ExecuteTransaction(false, t =>
|
||||
{
|
||||
//var todeleteItems = list.Select(p => clubMatchId).Distinct().Where(p => p > 0).ToArray();
|
||||
//if (todeleteItems.Length > 0) {
|
||||
var deleteSql = $"delete {tb_LeagueMatchBanDesk} where ClubMatchId = {clubMatchId}";
|
||||
var deletedCount = t.ExecuteNonQuery(deleteSql);
|
||||
if (deletedCount > 0)
|
||||
{
|
||||
Console.WriteLine("SaveBanDesks delete count:" + deletedCount);
|
||||
}
|
||||
|
||||
//}
|
||||
var sql = new StringBuilder();
|
||||
foreach (var p in list)
|
||||
{
|
||||
sql.Append(
|
||||
$"insert into {tb_LeagueMatchBanDesk}(ClubMatchId,{nameof(p.WayId)},{nameof(p.JSONString)}) ");
|
||||
sql.AppendLine($"values({clubMatchId}, @wayId, @json)");
|
||||
sql.AppendLine($"if @@rowcount > 0 begin");
|
||||
sql.AppendLine(
|
||||
$" select top 1 {nameof(p.LeagueMatchBanDeskId)} from {tb_LeagueMatchBanDesk} where {nameof(p.LeagueMatchBanDeskId)} = SCOPE_IDENTITY()");
|
||||
sql.AppendLine("end");
|
||||
var result = t.ExecuteScalar(sql.ToString(), new SqlParameter("@wayId", p.WayId),
|
||||
new SqlParameter("@json", p.GetClubsToString()));
|
||||
p.LeagueMatchBanDeskId = result is int id ? id : throw new Exception("增加记录失败, sql:" + sql);
|
||||
sql.Clear();
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联赛禁桌数据
|
||||
/// </summary>
|
||||
/// <param name="clubMatchId"></param>
|
||||
/// <returns></returns>
|
||||
public static List<LeagueMatchBanDesk> GetLeagueMatchBanDesks(int clubMatchId)
|
||||
{
|
||||
var sql = $"select * from {tb_LeagueMatchBanDesk} where ClubMatchId = {clubMatchId}";
|
||||
return sqldb.ExecuteEntities(sql, p =>
|
||||
{
|
||||
var model = p.ToObject<LeagueMatchBanDesk>();
|
||||
model.ClubIds = model.GetClubIdsByJSON();
|
||||
return model;
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存联赛俱乐部统计数据,每次删除数据在保存。根据ClubMatchId 删除
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
public static bool SaveLeagueMatchClubScore(List<LeagueMatchClubScore> list, int matchId)
|
||||
{
|
||||
return sqldb.ExecuteTransaction(false, t =>
|
||||
{
|
||||
var deleteSql =
|
||||
$"delete {tb_LeagueMatchClubScore} where ClubMatchId = {matchId}";
|
||||
var deletedCount = t.ExecuteNonQuery(deleteSql);
|
||||
if (deletedCount > 0)
|
||||
{
|
||||
Console.WriteLine("SaveLeagueMatchClubScore delete count:" + deletedCount);
|
||||
}
|
||||
|
||||
var sql = new StringBuilder();
|
||||
foreach (var p in list)
|
||||
{
|
||||
sql.Append(
|
||||
$"insert into {tb_LeagueMatchClubScore}(ClubMatchId,{nameof(p.ClubName)},{nameof(p.ClubId)},{nameof(p.CardScore)},{nameof(p.DeskScore)},{nameof(p.ClubUserSumScore)},{nameof(p.JoinRoom)},[Index],{nameof(p.LeagueScore)}) ");
|
||||
sql.AppendLine(
|
||||
$"values({matchId}, @clubName,{p.ClubId},{p.CardScore},{p.DeskScore},{p.ClubUserSumScore},{p.JoinRoom},0,@score)");
|
||||
sql.AppendLine($"if @@rowcount > 0 begin");
|
||||
sql.AppendLine(
|
||||
$" select top 1 {nameof(p.LeagueMatchClubScoreId)} from {tb_LeagueMatchClubScore} where {nameof(p.LeagueMatchClubScoreId)} = SCOPE_IDENTITY()");
|
||||
sql.AppendLine("end");
|
||||
var result = t.ExecuteScalar(sql.ToString(), new SqlParameter("@clubName", p.ClubName),
|
||||
new SqlParameter("@score", p.LeagueScore));
|
||||
p.LeagueMatchClubScoreId = result is int id ? id : throw new Exception("增加记录失败, sql:" + sql);
|
||||
sql.Clear();
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联赛俱乐部统计数据,过期时间7天
|
||||
/// </summary>
|
||||
/// <param name="clubMatchId"></param>
|
||||
/// <returns></returns>
|
||||
public static List<LeagueMatchClubScore> GetLeagueMatchClubScores(int clubMatchId)
|
||||
{
|
||||
var sql = $"select * from {tb_LeagueMatchClubScore} where clubMatchId = {clubMatchId}";
|
||||
return sqldb.ExecuteEntities(sql, p => p.ToObject<LeagueMatchClubScore>()).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存联赛颁奖记录,清空对应clubMatchId比赛的缓存(每次都是新的数据,不用做删除操作)
|
||||
/// </summary>
|
||||
/// <param name="mode"></param>
|
||||
public static bool SaveAwardRecord(List<AwardRecord> list)
|
||||
{
|
||||
return sqldb.ExecuteTransaction(false, t =>
|
||||
{
|
||||
var sql = new StringBuilder();
|
||||
foreach (var p in list)
|
||||
{
|
||||
sql.Append(
|
||||
$"insert into {tb_LeagueAwardRecord}({nameof(p.ClubMatchId)},{nameof(p.ClubName)},{nameof(p.ClubId)},{nameof(p.CardScore)},{nameof(p.DeskScore)},{nameof(p.ClubUserSumScore)},{nameof(p.JoinRoom)},[{nameof(p.Index)}],{nameof(p.RecordId)},{nameof(p.LeagueScore)}) ");
|
||||
sql.AppendLine(
|
||||
$"values({p.ClubMatchId}, @clubName,{p.ClubId},{p.CardScore},{p.DeskScore},{p.ClubUserSumScore},{p.JoinRoom},{p.Index},{p.RecordId},@score)");
|
||||
// sql.AppendLine($"if @@rowcount > 0 begin");
|
||||
// sql.AppendLine(
|
||||
// $" select top 1 {nameof(p.AwardRecordId)} from {tb_LeagueAwardRecord} where {nameof(p.AwardRecordId)} = SCOPE_IDENTITY()");
|
||||
// sql.AppendLine("end");
|
||||
var result = t.ExecuteScalar(sql.ToString(), new SqlParameter("@clubName", p.ClubName),
|
||||
new SqlParameter("@score", p.LeagueScore));
|
||||
//p.AwardRecordId = result is int id ? id : throw new Exception("增加记录失败, sql:" + sql);
|
||||
sql.Clear();
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联赛颁奖记录 近几条
|
||||
/// </summary>
|
||||
/// <param name="clubMatchId"></param>
|
||||
/// <param name="topNum"></param>
|
||||
/// <returns></returns>
|
||||
public static AwardRecord GetAwardByTop(int clubMatchId, int topNum = 1)
|
||||
{
|
||||
var sql = $"select top 1 * from {tb_LeagueAwardRecord} where clubMatchId = {clubMatchId}";
|
||||
return sqldb.ExecuteEntities(sql, p => p.ToObject<AwardRecord>()).FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联赛颁奖记录。根据主键id倒序
|
||||
/// </summary>
|
||||
/// <param name="clubMatchId">比赛Id</param>
|
||||
/// <param name="dateTime"> CreateTime>dateTime </param>
|
||||
/// <returns></returns>
|
||||
public static List<AwardRecord> GetAwardRecords(int clubMatchId, DateTime dateTime)
|
||||
{
|
||||
var sql =
|
||||
$"select * from {tb_LeagueAwardRecord} where clubMatchId = {clubMatchId} and CreateTime > @datetime";
|
||||
return sqldb.ExecuteEntities(sql, p => p.ToObject<AwardRecord>(), new SqlParameter("@datetime", dateTime))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联赛颁奖记录。根据主键id倒序,根据比赛:clubMatchId缓存 时间1天
|
||||
/// </summary>
|
||||
/// <param name="clubMatchId"></param>
|
||||
/// <returns></returns>
|
||||
public static List<AwardRecord> GetAwardRecords(int clubMatchId)
|
||||
{
|
||||
var sql = $"select * from {tb_LeagueAwardRecord} where clubMatchId = {clubMatchId}";
|
||||
return sqldb.ExecuteEntities(sql, p => p.ToObject<AwardRecord>()).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存生存任务,先删除再保存
|
||||
/// </summary>
|
||||
/// <param name="lists"></param>
|
||||
public static bool SaveLeagueClubLiveTasks(List<LeagueClubLiveTask> list, int clubMatchId)
|
||||
{
|
||||
return sqldb.ExecuteTransaction(false, t =>
|
||||
{
|
||||
if (clubMatchId > 0)
|
||||
{
|
||||
var deleteSql = $"delete {tb_LeagueClubLiveTask} where ClubMatchId = {clubMatchId}";
|
||||
Debug.Info($"执行Sql语句{deleteSql}");
|
||||
var deletedCount = t.ExecuteNonQuery(deleteSql);
|
||||
if (deletedCount > 0)
|
||||
{
|
||||
Console.WriteLine("SaveLeagueClubLiveTasks delete count:" + deletedCount);
|
||||
}
|
||||
}
|
||||
|
||||
var sql = new StringBuilder();
|
||||
foreach (var p in list)
|
||||
{
|
||||
sql.Append(
|
||||
$"insert into {tb_LeagueClubLiveTask}(ClubMatchId,{nameof(p.ClubId)},{nameof(p.TaskScore)},{nameof(p.IsActive)}) ");
|
||||
sql.AppendLine($"values({clubMatchId}, {p.ClubId},{p.TaskScore},{p.IsActive.SQLValue()})");
|
||||
sql.AppendLine($"if @@rowcount > 0 begin");
|
||||
sql.AppendLine(
|
||||
$" select top 1 LeagueClubLiveTaskId from {tb_LeagueClubLiveTask} where LeagueClubLiveTaskId = SCOPE_IDENTITY()");
|
||||
sql.AppendLine("end");
|
||||
var result = t.ExecuteScalar(sql.ToString());
|
||||
p.LeagueClubLiveTaskId = result is int id ? id : throw new Exception("增加记录失败, sql:" + sql);
|
||||
sql.Clear();
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存加入到联赛的俱乐部集合
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
public static bool SaveJoinInClubLeagueMatch(JoinInClubLeagueMatch model)
|
||||
{
|
||||
Debug.Info($"保存加入联赛的俱乐部集合:{model.ClubMatchId} {model.GetJoinInLeagueMatchClubsToString()}");
|
||||
|
||||
var spp = GameDB.Instance.BeginTransaction(dbbase.game2018);
|
||||
|
||||
string sql =
|
||||
$@"if not exists (select 1 from {tb_JoinInClubLeagueMatch} where ClubMatchId = {model.ClubMatchId})
|
||||
insert into {tb_JoinInClubLeagueMatch}(ClubMatchId,JoinInLeagueMatchClubs) values ({model.ClubMatchId},@json)
|
||||
else
|
||||
update {tb_JoinInClubLeagueMatch} set JoinInLeagueMatchClubs=@json where ClubMatchId = {model.ClubMatchId}";
|
||||
List<ISqlAloneParameter<SqlDbType>> sqlpms = new List<ISqlAloneParameter<SqlDbType>>();
|
||||
sqlpms.Add(new SqlAloneParameter("@json", model.GetJoinInLeagueMatchClubsToString(),5000, SqlDbType.VarChar));
|
||||
GameDB.Instance.TransactionAddSql(spp, sql, sqlpms);
|
||||
|
||||
if (!GameDB.Instance.SubTransaction(spp))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 保存加入到联赛的俱乐部集合 对象
|
||||
/// </summary>
|
||||
/// <param name="clubMatchId"></param>
|
||||
/// <returns></returns>
|
||||
public static JoinInClubLeagueMatch GetJoinInClubLeagueMatch(int clubMatchId)
|
||||
{
|
||||
var sql = $"select top 1 * from {tb_JoinInClubLeagueMatch} where clubMatchId = {clubMatchId}";
|
||||
Debug.Info(sql);
|
||||
return sqldb.ExecuteEntities(sql, p =>
|
||||
{
|
||||
var model = p.ToObject<JoinInClubLeagueMatch>();
|
||||
model.ClubIds = model.GetClubIdsByJSON();
|
||||
return model;
|
||||
}).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
268
GameDAL/Club/ClubLeagueMatchDal.cs
Normal file
268
GameDAL/Club/ClubLeagueMatchDal.cs
Normal file
@ -0,0 +1,268 @@
|
||||
using GameData;
|
||||
using ObjectModel.Club;
|
||||
using Server.DB.Redis;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GameData.Club;
|
||||
|
||||
namespace GameDAL.Club
|
||||
{
|
||||
/// <summary>
|
||||
/// 俱乐部联赛数据逻辑
|
||||
/// </summary>
|
||||
public static class ClubLeagueMatchDal
|
||||
{
|
||||
|
||||
public static readonly string clubMatchKeyPrefix = "ClubLeagueMatch";
|
||||
public static readonly DbStyle redisdb = DbStyle.main;
|
||||
public static readonly int dbidx = 7;
|
||||
static TimeSpan expiry = TimeSpan.FromDays(1);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取俱乐部权限
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <returns></returns>
|
||||
public static ClubLeaguePower GetClubLeaguePower(int clubId)
|
||||
{
|
||||
if (clubId <= 0) return null;
|
||||
return ClubLeagueMatchAdo.GetClubLeaguePower(clubId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取俱乐部权限
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <returns></returns>
|
||||
public static Task<ClubLeaguePower> GetClubLeaguePowerAsync(int clubId)
|
||||
{
|
||||
return ClubLeagueMatchAdo.GetClubLeaguePowerAsync(clubId);
|
||||
}
|
||||
|
||||
public static async Task<bool> SaveClubLeaguePowerAsync(ClubLeaguePower leaguePower)
|
||||
{
|
||||
return await Task.Run(()=>ClubLeagueMatchAdo.SaveClubLeaguePower(leaguePower));
|
||||
}
|
||||
|
||||
public static Task SaveBanDesksAsync(List<LeagueMatchBanDesk> list,int matchId)
|
||||
{
|
||||
return Task.Run(() => SaveBanDesks(list, matchId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存联赛禁桌数据,每次删除数据在保存。根据ClubMatchId 删除
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
public static void SaveBanDesks(List<LeagueMatchBanDesk> list,int matchId)
|
||||
{
|
||||
if (list == null || list.Count < 1) return;
|
||||
ClubLeagueMatchAdo.SaveBanDesks(list,matchId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联赛禁桌数据
|
||||
/// </summary>
|
||||
/// <param name="clubMatchId"></param>
|
||||
/// <returns></returns>
|
||||
public static List<LeagueMatchBanDesk> GetLeagueMatchBanDesks(int clubMatchId)
|
||||
{
|
||||
if (clubMatchId <= 0) return null;
|
||||
return ClubLeagueMatchAdo.GetLeagueMatchBanDesks(clubMatchId);
|
||||
}
|
||||
|
||||
public static Task SaveLeagueMatchClubScoreAsync(List<LeagueMatchClubScore> list,int matchId)
|
||||
{
|
||||
return Task.Run(() => SaveLeagueMatchClubScore(list, matchId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存联赛俱乐部统计数据,每次删除数据在保存。根据ClubMatchId 删除
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
public static void SaveLeagueMatchClubScore(List<LeagueMatchClubScore> list,int matchId)
|
||||
{
|
||||
if (list == null || list.Count < 1) return;
|
||||
ClubLeagueMatchAdo.SaveLeagueMatchClubScore(list,matchId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联赛俱乐部统计数据
|
||||
/// </summary>
|
||||
/// <param name="clubMatchId"></param>
|
||||
/// <returns></returns>
|
||||
public static List<LeagueMatchClubScore> GetLeagueMatchClubScores(int clubMatchId)
|
||||
{
|
||||
if (clubMatchId <= 0) return null;
|
||||
return ClubLeagueMatchAdo.GetLeagueMatchClubScores(clubMatchId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存联赛颁奖记录,清空对应clubMatchId比赛的缓存(每次都是新的数据,不用做删除操作)
|
||||
/// </summary>
|
||||
public static async Task<bool> SaveAwardRecord(long awardId, int leagueClubId, int leagueMatchId, List<AwardRecord> list)
|
||||
{
|
||||
if (list == null || list.Count < 1) return false;
|
||||
var b = await ClubDBUtil.DoLeagueAwardRecord(awardId, leagueClubId, leagueMatchId, list);
|
||||
if (b)
|
||||
{
|
||||
var clubMatchIds = list.Select(p => p.ClubMatchId).Distinct().ToArray();
|
||||
var keys1 = clubMatchIds.Select(p => GetAwardRecordListKey(p));
|
||||
var keys2 = clubMatchIds.Select(p => GetAwardRecordKey(p));
|
||||
var keys3 = clubMatchIds.Select(p => GetAwardRecordListByDateKey(p));
|
||||
_ = redisdb.DeleteAsync(dbidx, keys1.Concat(keys2).Concat(keys3).ToArray());
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取联赛颁奖记录 近几条
|
||||
// /// </summary>
|
||||
// /// <param name="clubMatchId"></param>
|
||||
// /// <param name="topNum"></param>
|
||||
// /// <returns></returns>
|
||||
// public static AwardRecord GetAwardByTop(int clubMatchId, int topNum = 1)
|
||||
// {
|
||||
// if (clubMatchId <= 0) return null;
|
||||
// var result = redisdb.GetOrAdd(RedisType.String, GetAwardRecordKey(clubMatchId), () =>
|
||||
// {
|
||||
// return ClubLeagueMatchAdo.GetAwardByTop(clubMatchId, topNum) ?? new AwardRecord();
|
||||
// }, dbidx, expiry);
|
||||
// return result.AwardRecordId != 0 ? result : null;
|
||||
// }
|
||||
|
||||
#if Server
|
||||
/// <summary>
|
||||
/// 获取联赛颁奖记录。根据主键id倒序
|
||||
/// </summary>
|
||||
/// <param name="clubMatchId">比赛Id</param>
|
||||
/// <param name="dateTime"> CreateTime>dateTime </param>
|
||||
/// <returns></returns>
|
||||
public static List<AwardRecord> GetAwardRecords(int clubMatchId, DateTime dateTime)
|
||||
{
|
||||
if (clubMatchId <= 0) return null;
|
||||
return redisdb.GetOrAdd(GetAwardRecordListByDateKey(clubMatchId), dateTime.ToString("yyyyMMddHHmmss"), () =>
|
||||
ClubLeagueMatchAdo.GetAwardRecords(clubMatchId, dateTime)
|
||||
, dbidx, expiry);
|
||||
}
|
||||
|
||||
public static FightScore GetFightScorebyId(int id)
|
||||
{
|
||||
return DbStyle.bisai.GetOrAdd(RedisType.String, GetFightScoreByIdKey(id), () =>
|
||||
ClubDataManager.GetFightScoreById(id)
|
||||
, dbidx, TimeSpan.FromMinutes(30));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
static RedisKey GetFightScoreByIdKey(int id)
|
||||
{
|
||||
return $"GetFightScores:id:{id}";
|
||||
}
|
||||
|
||||
static RedisKey GetAwardRecordListByDateKey(int clubMatchId)
|
||||
{
|
||||
return $"{clubMatchKeyPrefix}:AwardRecordListBydate:{clubMatchId}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联赛颁奖记录。根据主键id倒序,根据比赛:clubMatchId缓存 时间1天
|
||||
/// </summary>
|
||||
/// <param name="clubMatchId"></param>
|
||||
/// <returns></returns>
|
||||
public static List<AwardRecord> GetAwardRecords(int clubMatchId)
|
||||
{
|
||||
if (clubMatchId <= 0) return null;
|
||||
return redisdb.GetOrAdd(RedisType.String, GetAwardRecordListKey(clubMatchId),
|
||||
() => ClubLeagueMatchAdo.GetAwardRecords(clubMatchId)
|
||||
, dbidx, expiry);
|
||||
}
|
||||
|
||||
static RedisKey GetAwardRecordListKey(int clubMatchId)
|
||||
{
|
||||
return $"{clubMatchKeyPrefix}:AwardRecordList:{clubMatchId}";
|
||||
}
|
||||
|
||||
static RedisKey GetAwardRecordKey(int clubMatchId)
|
||||
{
|
||||
return $"{clubMatchKeyPrefix}:AwardRecord:{clubMatchId}";
|
||||
}
|
||||
|
||||
public static Task SaveLeagueClubLiveTasksAsync(List<LeagueClubLiveTask> list,int matchId)
|
||||
{
|
||||
return Task.Run(() => SaveLeagueClubLiveTasks(list, matchId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存生存任务,先删除再保存
|
||||
/// </summary>
|
||||
/// <param name="lists"></param>
|
||||
public static void SaveLeagueClubLiveTasks(List<LeagueClubLiveTask> list,int matchId)
|
||||
{
|
||||
if (list == null || list.Count < 1) return;
|
||||
ClubLeagueMatchAdo.SaveLeagueClubLiveTasks(list,matchId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存加入到联赛的俱乐部集合
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
public static void SaveJoinInClubLeagueMatch(JoinInClubLeagueMatch model)
|
||||
{
|
||||
if (model == null) return;
|
||||
ClubLeagueMatchAdo.SaveJoinInClubLeagueMatch(model);
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取 保存加入到联赛的俱乐部集合 对象
|
||||
// /// </summary>
|
||||
// /// <param name="clubMatchId"></param>
|
||||
// /// <returns></returns>
|
||||
// public static JoinInClubLeagueMatch GetJoinInClubLeagueMatch(int clubMatchId)
|
||||
// {
|
||||
// if (clubMatchId <= 0) return null;
|
||||
// return ClubLeagueMatchAdo.GetJoinInClubLeagueMatch(clubMatchId);
|
||||
// }
|
||||
|
||||
static string GetLeagueAdminClubsKey(int clubId)
|
||||
{
|
||||
return $"GetLeagueAdminClubsKey:{clubId}";
|
||||
}
|
||||
|
||||
#if Server
|
||||
/// <summary>
|
||||
/// 保存联赛俱乐部管理员
|
||||
/// </summary>
|
||||
public static void SaveLeagueAdminClubs(int clubId, List<LeagueAdminClub> data)
|
||||
{
|
||||
if (clubId <= 0 || data == null) return;
|
||||
var key = GetLeagueAdminClubsKey(clubId);
|
||||
var str = JsonPack.GetJson(data);
|
||||
redisManager.GetBiSaidb(6).StringSet(key, str, TimeSpan.FromDays(365)); //数据缓存一年
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取联赛管理员列表
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <returns></returns>
|
||||
public static List<LeagueAdminClub> GetLeagueAdminClubs(int clubId)
|
||||
{
|
||||
var result = new List<LeagueAdminClub>();
|
||||
if (clubId <= 0) return result;
|
||||
var key = GetLeagueAdminClubsKey(clubId);
|
||||
string str = redisManager.GetBiSaidb(6).StringGet(key);
|
||||
if (!string.IsNullOrWhiteSpace(str) && str.Length > 2)
|
||||
{
|
||||
return JsonPack.GetData<List<LeagueAdminClub>>(str);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
459
GameDAL/Club/ClubMatchManagerAdo.cs
Normal file
459
GameDAL/Club/ClubMatchManagerAdo.cs
Normal file
@ -0,0 +1,459 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GameData;
|
||||
using ObjectModel.Club;
|
||||
using MrWu;
|
||||
using MrWu.Debug;
|
||||
using Server.DB.Sql;
|
||||
using GameData.Club;
|
||||
|
||||
/// <summary>
|
||||
/// 竞技比赛统计数据存取
|
||||
/// </summary>
|
||||
public static class ClubMatchManagerAdo {
|
||||
|
||||
public const dbbase sqldb = dbbase.game2018;
|
||||
public static readonly string tb_ClubMatch = "ClubMatch";
|
||||
public static readonly string tb_ClubMatchNotes = "ClubMatchNotes";
|
||||
public static readonly string tb_ClubMatchPlayWay = "ClubMatchPlayWay";
|
||||
public static readonly string tb_ClubMatchScoreNotes = "ClubMatchScoreNotes";
|
||||
public static readonly string tb_ClubMatchUserScore = "ClubMatchUserScore";
|
||||
public static readonly string tb_ClubMatchPlayWayMaxWinnerScoreRange = "ClubMatchPlayWayMaxWinnerScoreRange";
|
||||
|
||||
public static bool DeleteMatchPlayWayById(int id)
|
||||
{
|
||||
if (id <= 0) return false;
|
||||
var sql = " DELETE from ClubMatchPlayWay where MatchPlayWayId = @id";
|
||||
return sqldb.ExecuteTransaction(t => {
|
||||
|
||||
var succ = t.ExecuteNonQuery(sql, new SqlParameter[]{
|
||||
new SqlParameter("@id",id)
|
||||
}) == 1;
|
||||
if (!succ)
|
||||
{
|
||||
throw new Exception("DELETE ClubMatchPlayWay 记录失败!" + sql);
|
||||
}
|
||||
return succ;
|
||||
});
|
||||
}
|
||||
|
||||
//这里需要加个新表
|
||||
|
||||
public static ClubMatch GetClubMatchByClubId(int clubId, out List<ClubMatchUserScore> list, int statusFlag = 1) {
|
||||
var statusFlagWhere = statusFlag >= 0 ? $"and statusFlag = {statusFlag} " : string.Empty;
|
||||
list = null;
|
||||
var sql = new StringBuilder();
|
||||
|
||||
//查询比赛 比赛表 连接 玩法表 以及比赛规则 找的是最后一条数据
|
||||
sql.AppendLine($"select p1.*, p2.*, p3.* from");//比赛与玩法及子项,
|
||||
sql.AppendLine($" (select top(1) * from {tb_ClubMatch} where clubId = {clubId} {statusFlagWhere} order by ClubMatchId desc) as p1");
|
||||
sql.AppendLine($"left join {tb_ClubMatchPlayWay} as p2");
|
||||
sql.AppendLine($"on p1.ClubMatchId = p2.ClubMatchId");
|
||||
sql.AppendLine($"left join {tb_ClubMatchPlayWayMaxWinnerScoreRange} as p3");
|
||||
sql.AppendLine($"on p2.MatchPlayWayId = p3.MatchPlayWayId");
|
||||
sql.AppendLine($"order by p1.ClubMatchId desc, p2.MatchPlayWayId desc");
|
||||
|
||||
sql.AppendLine($"select p2.* from");//参加比赛的玩家分数
|
||||
sql.AppendLine($" (select top(1) * from {tb_ClubMatch} where clubId = {clubId} {statusFlagWhere} order by ClubMatchId desc) as p1");
|
||||
sql.AppendLine($"left join {tb_ClubMatchUserScore} as p2");
|
||||
sql.AppendLine($"on p1.ClubMatchId = p2.ClubMatchId");
|
||||
sql.AppendLine($"where p2.ClubMatchId > 0");
|
||||
sql.AppendLine($"order by p2.UserScoreId desc");
|
||||
|
||||
var tabs = sqldb.ExecuteTables(sql.ToString());
|
||||
if (tabs.Length > 0 && tabs[0].Rows.Count > 0) {
|
||||
var clubMatchs = tabs[0].GetClubMatche();
|
||||
|
||||
list = new List<ClubMatchUserScore>();
|
||||
if (tabs.Length > 1 && tabs[1].Rows.Count > 0) {
|
||||
foreach (DataRow row in tabs[1].Rows) {
|
||||
var score = row.ToObject<ClubMatchUserScore>();
|
||||
list.Add(score);
|
||||
}
|
||||
}
|
||||
return clubMatchs.Single();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool SaveClubMatch(ClubMatch model) {
|
||||
|
||||
Debug.Info($"保存比赛数据:{model.ClubId},{model.StatusFlag},{model.ClubMatchId}");
|
||||
|
||||
if (model.ClubMatchId == 0) {
|
||||
return AddClubMatch(model);
|
||||
} else {
|
||||
return UpdateClubMatch(model);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AddClubMatch(ClubMatch model) {
|
||||
var sql = new StringBuilder();
|
||||
sql.Append($"insert into {tb_ClubMatch}(");
|
||||
sql.Append($"clubid,ClubMatchName,MatchStartTime,MatchEndTime,DieOutNum,StatusFlag,AutoOpen,HowTopUser,Round,MatchRate,VisibleDesk,isOnlyVisibleMyClub,isVisibleScoreBak,isScoreReset,JsonData) ");
|
||||
sql.AppendLine($"values({model.ClubId},@ClubMatchName,@MatchStartTime,@MatchEndTime,{model.DieOutNum},{model.StatusFlag},{model.AutoOpen.SQLValue()},{model.HowTopUser},{model.Round},{model.MatchRate},{model.VisibleDesk},{model.isOnlyVisibleMyClub},{model.isVisibleScoreBak},{model.isScoreReset},@JsonData)");
|
||||
sql.AppendLine($"select cast(SCOPE_IDENTITY() as int)");
|
||||
return sqldb.ExecuteTransaction(t => {
|
||||
var result = t.ExecuteScalar(sql.ToString(), new SqlParameter[]{
|
||||
new SqlParameter("@ClubMatchName",model.ClubMatchName),
|
||||
new SqlParameter("@MatchStartTime", model.MatchStartTime),
|
||||
new SqlParameter("@MatchEndTime",model.MatchEndTime),
|
||||
new SqlParameter("@JsonData",model.GetJsonData())
|
||||
});
|
||||
if (result is int id) {
|
||||
model.ClubMatchId = id;
|
||||
} else {
|
||||
throw new Exception("AddClubMatch 增加新记录失败!" + sql);
|
||||
}
|
||||
|
||||
if (model.LeagueClubMatch == null) //只有创建比赛的俱乐部才需要保存玩法信息
|
||||
{
|
||||
if (model.MatchPlayWays != null && model.MatchPlayWays.Count > 0) {
|
||||
foreach (var way in model.MatchPlayWays) {
|
||||
AddOrUpdateClubMatchPlayWay(t, way, model.ClubMatchId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public static bool UpdateClubMatch(ClubMatch model) {
|
||||
return sqldb.ExecuteTransaction(t => {
|
||||
var sql = new StringBuilder();
|
||||
sql.Append($"update {tb_ClubMatch} set ");
|
||||
sql.Append($"ClubMatchName = @ClubMatchName,");
|
||||
sql.Append($"MatchStartTime = @MatchStartTime,");
|
||||
sql.Append($"MatchEndTime = @MatchEndTime,");
|
||||
sql.Append($"JsonData = @JsonData,");
|
||||
sql.Append($"DieOutNum = {model.DieOutNum},");
|
||||
sql.Append($"StatusFlag = {model.StatusFlag},");
|
||||
sql.Append($"AutoOpen = {model.AutoOpen.SQLValue()},");
|
||||
sql.Append($"HowTopUser = {model.HowTopUser},");
|
||||
sql.Append($"Round = {model.Round},");
|
||||
sql.Append($"isOnlyVisibleMyClub = {model.isOnlyVisibleMyClub},");
|
||||
sql.Append($"VisibleDesk = {model.VisibleDesk},");
|
||||
sql.Append($"MatchRate = {model.MatchRate},");
|
||||
sql.Append($"isVisibleScoreBak={model.isVisibleScoreBak},");
|
||||
sql.Append($"isScoreReset={model.isScoreReset} ");
|
||||
sql.Append($"where ClubMatchId = {model.ClubMatchId}");
|
||||
|
||||
var succ = t.ExecuteNonQuery(sql.ToString(), new SqlParameter[]{
|
||||
new SqlParameter("@ClubMatchName",model.ClubMatchName),
|
||||
new SqlParameter("@MatchStartTime", model.MatchStartTime),
|
||||
new SqlParameter("@MatchEndTime",model.MatchEndTime),
|
||||
new SqlParameter("@JsonData",model.GetJsonData())
|
||||
}) == 1;
|
||||
if (!succ) {
|
||||
throw new Exception("UpdateClubMatch 更新记录失败!" + sql);
|
||||
}
|
||||
|
||||
if (model.LeagueClubMatch == null)
|
||||
{
|
||||
if (model.MatchPlayWays != null && model.MatchPlayWays.Count > 0) {
|
||||
foreach (var way in model.MatchPlayWays) {
|
||||
AddOrUpdateClubMatchPlayWay(t, way, model.ClubMatchId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return succ;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 只更新ClubMatchModel
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public static bool UpdateClubMatchModel(ClubMatch model) {
|
||||
return sqldb.ExecuteTransaction(t => {
|
||||
var sql = new StringBuilder();
|
||||
sql.Append($"update {tb_ClubMatch} set ");
|
||||
sql.Append($"ClubMatchName = @ClubMatchName,");
|
||||
sql.Append($"MatchStartTime = @MatchStartTime,");
|
||||
sql.Append($"MatchEndTime = @MatchEndTime,");
|
||||
sql.Append($"DieOutNum = {model.DieOutNum},");
|
||||
sql.Append($"StatusFlag = {model.StatusFlag},");
|
||||
sql.Append($"AutoOpen = {model.AutoOpen.SQLValue()},");
|
||||
sql.Append($"HowTopUser = {model.HowTopUser},");
|
||||
sql.Append($"Round = {model.Round},");
|
||||
sql.Append($"MatchRate = {model.MatchRate} ");
|
||||
sql.Append($"where ClubMatchId = {model.ClubMatchId}");
|
||||
|
||||
var succ = t.ExecuteNonQuery(sql.ToString(), new SqlParameter[]{
|
||||
new SqlParameter("@ClubMatchName",model.ClubMatchName),
|
||||
new SqlParameter("@MatchStartTime", model.MatchStartTime),
|
||||
new SqlParameter("@MatchEndTime",model.MatchEndTime)
|
||||
}) == 1;
|
||||
if (!succ) {
|
||||
throw new Exception("UpdateClubMatch 更新记录失败!" + sql);
|
||||
}
|
||||
return succ;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void AddOrUpdateClubMatchPlayWay(SqlTransaction t, MatchPlayWay way, int ClubMatchId) {
|
||||
var sql = new StringBuilder();
|
||||
if (way.MatchPlayWayId == 0) {
|
||||
sql.Append($"insert into {tb_ClubMatchPlayWay} (ClubMatchId,weiyima,MinScore,DeskCost,TypeMode,MinFreeDeskCostNum,IsFirstCalcDeskCost,BuresMinScore,IsBuresMin,IsRealCalcScore,LeagueDeskScore)");
|
||||
sql.AppendLine($"values({ClubMatchId},@weiyima,{way.MinScore},{way.DeskCost},{way.TypeMode},{way.MinFreeDeskCostNum},{way.IsFirstCalcDeskCost.SQLValue()},{way.BuresMinScore},{way.IsBuresMin.SQLValue()},{way.IsRealCalcScore.SQLValue()},{way.LeagueDeskScore})");
|
||||
sql.AppendLine($"select cast(SCOPE_IDENTITY() as int)");
|
||||
var result = t.ExecuteScalar(sql.ToString(), new SqlParameter("@weiyima", way.weiyima));
|
||||
if (result is int id) {
|
||||
way.MatchPlayWayId = id;
|
||||
} else {
|
||||
throw new Exception("AddOrUpdateClubMatchPlayWay ClubMatchPlayWay 增加新记录失败!" + sql);
|
||||
}
|
||||
way.ClubMatchId = ClubMatchId;
|
||||
} else {
|
||||
sql.Append($"update {tb_ClubMatchPlayWay} set ");
|
||||
sql.Append($"weiyima = @weiyima,");
|
||||
sql.Append($"MinScore = {way.MinScore},");
|
||||
sql.Append($"DeskCost = {way.DeskCost},");
|
||||
sql.Append($"TypeMode = {way.TypeMode},");
|
||||
sql.Append($"MinFreeDeskCostNum = {way.MinFreeDeskCostNum},");
|
||||
sql.Append($"IsFirstCalcDeskCost = {way.IsFirstCalcDeskCost.SQLValue()},");
|
||||
sql.Append($"BuresMinScore = {way.BuresMinScore},");
|
||||
sql.Append($"IsBuresMin = {way.IsBuresMin.SQLValue()},");
|
||||
sql.Append($"IsRealCalcScore = {way.IsRealCalcScore.SQLValue()}, ");
|
||||
sql.Append($"LeagueDeskScore = @score ");
|
||||
sql.Append($"where MatchPlayWayId = {way.MatchPlayWayId}");
|
||||
if (t.ExecuteNonQuery(sql.ToString(), new SqlParameter("@weiyima", way.weiyima), new SqlParameter("@score", way.LeagueDeskScore)) != 1) {
|
||||
throw new Exception("AddOrUpdateClubMatchPlayWay ClubMatchPlayWay 更新记录失败!" + sql);
|
||||
}
|
||||
t.ExecuteNonQuery($"delete {tb_ClubMatchPlayWayMaxWinnerScoreRange} where MatchPlayWayId = {way.MatchPlayWayId}");
|
||||
}
|
||||
if (way.MaxWinnerScoreRanges != null && way.MaxWinnerScoreRanges.Count > 0) {
|
||||
foreach (var item in way.MaxWinnerScoreRanges) {
|
||||
AddWayMaxWinnerScoreRange(t, item, way.MatchPlayWayId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回俱乐部的比赛日志
|
||||
/// </summary>
|
||||
/// <param name="clubId">记录表的Id</param>
|
||||
/// <param name="createTime">返回该时间之后的日志 按时间倒序排序</param>
|
||||
/// <returns></returns>
|
||||
public static List<ClubMatchNotes> GetClubMatchNotesByClubId(int clubId, DateTime createTime,int topCnt) {
|
||||
var sql = new StringBuilder();
|
||||
sql.AppendLine($"select top {topCnt} * from {tb_ClubMatchNotes} where clubId = {clubId} and createTime >= '{createTime.Date}' order by ClubMatchNotesId desc");
|
||||
Debug.Info($"执行Sql:{sql}");
|
||||
var list = sqldb.ExecuteEntities(sql.ToString(), p => p.ToObject<ClubMatchNotes>()).ToList();
|
||||
return list;
|
||||
}
|
||||
|
||||
static void AddWayMaxWinnerScoreRange(SqlTransaction t, MaxWinnerScoreRange maxWinnerScoreRange, int matchPlayWayId) {
|
||||
var sql = new StringBuilder();
|
||||
sql.Append($"insert into {tb_ClubMatchPlayWayMaxWinnerScoreRange} (matchPlayWayId,MaxWinnerMinScore,DeskScore)");
|
||||
sql.AppendLine($"values({matchPlayWayId},{maxWinnerScoreRange.MaxWinnerMinScore},{maxWinnerScoreRange.DeskScore})");
|
||||
sql.AppendLine($"select cast(SCOPE_IDENTITY() as int)");
|
||||
var result = t.ExecuteScalar(sql.ToString());
|
||||
if (result is int id) {
|
||||
maxWinnerScoreRange.MaxWinnerScoreRangeId = id;
|
||||
} else {
|
||||
throw new Exception("AddOrUpdateWayMaxWinnerScoreRange MaxWinnerScoreRange 增加新记录失败!" + sql);
|
||||
}
|
||||
maxWinnerScoreRange.MatchPlayWayId = matchPlayWayId;
|
||||
}
|
||||
|
||||
// public static List<ClubMatch> GetClubMatches(int clubId, DateTime date) {
|
||||
// return GetClubMatches(clubId, $"and MatchStartTime >= '{date.Date}'");
|
||||
// }
|
||||
|
||||
// public static List<ClubMatch> GetClubMatches(int clubId, string otherWhere, int size = -1) {
|
||||
// var sql = new StringBuilder();
|
||||
// var topSize = size > 0 ? $" top ({size})" : string.Empty;
|
||||
//
|
||||
// sql.AppendLine($"select p1.*, p2.*, p3.* from");
|
||||
// sql.AppendLine($" (select {topSize} * from {tb_ClubMatch} where clubId = {clubId} {otherWhere}) as p1");
|
||||
// sql.AppendLine($"left join {tb_ClubMatchPlayWay} as p2");
|
||||
// sql.AppendLine($"on p1.ClubMatchId = p2.ClubMatchId");
|
||||
// sql.AppendLine($"left join {tb_ClubMatchPlayWayMaxWinnerScoreRange} as p3");
|
||||
// sql.AppendLine($"on p2.MatchPlayWayId = p3.MatchPlayWayId");
|
||||
// sql.AppendLine($"order by p1.ClubMatchId desc, p2.MatchPlayWayId desc, p3.MaxWinnerScoreRangeId desc");
|
||||
//
|
||||
// var table = sqldb.ExecuteTable(sql.ToString());
|
||||
// return table.GetClubMatche().ToList();
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 获取比赛数据,不关联其他数据
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <param name="topSize"></param>
|
||||
/// <returns></returns>
|
||||
public static List<ClubMatch> GetClubMatches(int clubId,int topSize=5)
|
||||
{
|
||||
if(topSize<=0) topSize = 5;
|
||||
string sql = $"SELECT top {topSize} * from ClubMatch where ClubId={clubId} order by ClubMatchId desc";
|
||||
//Debug.ImportantLog($"获取比赛数据,不关联其他数据 sql:{sql}");
|
||||
var table = sqldb.ExecuteTable(sql.ToString());
|
||||
return table.GetClubMatche().ToList();
|
||||
}
|
||||
|
||||
static IEnumerable<ClubMatch> GetClubMatche(this DataTable table) {
|
||||
var clubMatchs = new Dictionary<int, ClubMatch>();
|
||||
foreach (DataRow row in table.Rows) {
|
||||
var newWay = row.ToObject<MatchPlayWay>();
|
||||
if (newWay.MatchPlayWayId > 0) {
|
||||
newWay.MaxWinnerScoreRanges = new List<MaxWinnerScoreRange>();
|
||||
if (!clubMatchs.TryGetValue(newWay.ClubMatchId, out var clubMatch)) {
|
||||
clubMatch = row.ToObject<ClubMatch>();
|
||||
clubMatch.InitOtherSetting();
|
||||
clubMatch.MatchPlayWays = new List<MatchPlayWay>();
|
||||
clubMatchs.Add(clubMatch.ClubMatchId, clubMatch);
|
||||
}
|
||||
var way = clubMatch.MatchPlayWays.SingleOrDefault(p => p.MatchPlayWayId == newWay.MatchPlayWayId);
|
||||
if (way == null) {
|
||||
clubMatch.MatchPlayWays.Add(newWay);
|
||||
way = newWay;
|
||||
}
|
||||
var maxWinnerScoreRange = row.ToObject<MaxWinnerScoreRange>();
|
||||
if (maxWinnerScoreRange.MaxWinnerScoreRangeId != 0) {
|
||||
way.MaxWinnerScoreRanges.Add(maxWinnerScoreRange);
|
||||
}
|
||||
} else {
|
||||
//玩法为空的比赛
|
||||
var clubMatch = row.ToObject<ClubMatch>();
|
||||
clubMatch.InitOtherSetting();
|
||||
if (clubMatch.ClubMatchId > 0 && !clubMatchs.Keys.Contains(clubMatch.ClubMatchId)) {
|
||||
clubMatch.MatchPlayWays = new List<MatchPlayWay>();
|
||||
clubMatchs.Add(clubMatch.ClubMatchId, clubMatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
return clubMatchs.Values;
|
||||
}
|
||||
|
||||
// public static List<ClubMatch> GetTopOneClubMatch(int clubId, int top) {
|
||||
// return GetClubMatches(clubId, "order by ClubMatchId desc", top);
|
||||
// }
|
||||
|
||||
// public static void SaveClubMatchScoreNotes(ClubMatchScoreNotes model) {
|
||||
// sqldb.ExecuteTransaction(t => SaveClubMatchScoreNote(t, model));
|
||||
// }
|
||||
|
||||
// static bool SaveClubMatchScoreNote(SqlTransaction t, ClubMatchScoreNotes model) {
|
||||
//
|
||||
// var sql = new StringBuilder();
|
||||
// sql.Append($"insert into {tb_ClubMatchScoreNotes} (clubId,ClubMatchId,UserId,TypeId,Score,DeskScore,NewScore)");
|
||||
// sql.Append($"values({model.ClubId},{model.ClubMatchId},{model.UserId},{model.TypeId},@Score,@DeskScore,@NewScore)");
|
||||
// if (t.ExecuteNonQuery(sql.ToString(), new SqlParameter("@Score", model.Score), new SqlParameter("@DeskScore", model.DeskScore)
|
||||
// , new SqlParameter("@NewScore", model.NewScore)) != 1) {
|
||||
// throw new Exception("SaveClubMatchScoreNotes ClubMatchScoreNotes 增加新记录失败!" + sql);
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public static List<ClubMatchScoreNotes> GetClubMatchScoreNotes(int clubId, int clubMatchId, int userId,int cnt) {
|
||||
var sql = new StringBuilder();
|
||||
sql.Append($"select top {cnt} * from {tb_ClubMatchScoreNotes} where clubId = {clubId} and clubMatchId = {clubMatchId} and userId = {userId} order by ScoreNotesId desc");
|
||||
Debug.Info(sql);
|
||||
var list = sqldb.ExecuteEntities(sql.ToString(), p => p.ToObject<ClubMatchScoreNotes>()).ToList();
|
||||
return list;
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// 批量保存比赛日志
|
||||
// /// </summary>
|
||||
// /// <param name="model"></param>
|
||||
// public static void SaveClubMatchNotes(List<ClubMatchNotes> model)
|
||||
// {
|
||||
// if (model == null || model.Count <= 0) return;
|
||||
// var transaction = GameDB.Instance.BeginTransaction(dbbase.game2018);
|
||||
// foreach (var item in model)
|
||||
// {
|
||||
// var sql = $"insert into {tb_ClubMatchNotes} (TypeId,clubId,ClubMatchId,Content) values({(int)item.TypeId},{item.ClubId},{item.ClubMatchId},'{item.Content}')";
|
||||
// if (1 != GameDB.Instance.TransactionAddSql(transaction, sql))
|
||||
// {
|
||||
// GameDB.Instance.Rollback(transaction);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// GameDB.Instance.SubTransaction(transaction);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 返回俱乐部的操作日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<ClubMatchNotes> GetClubMatchNotesByClubIdType(int clubId,int type, DateTime createTime)
|
||||
{
|
||||
var sql = new StringBuilder();
|
||||
sql.AppendLine($"select * from {tb_ClubMatchNotes} where clubId = {clubId} and createTime >= '{createTime.Date}' and TypeId={type} order by ClubMatchNotesId desc");
|
||||
var list = sqldb.ExecuteEntities(sql.ToString(), p => p.ToObject<ClubMatchNotes>()).ToList();
|
||||
return list;
|
||||
}
|
||||
|
||||
// public static void SaveClubMatchNotes(ClubMatchNotes model) {
|
||||
// var sql = new StringBuilder();
|
||||
// sql.Append($"insert into {tb_ClubMatchNotes} (TypeId,clubId,ClubMatchId,Content)");
|
||||
// sql.Append($"values({(int)model.TypeId},{model.ClubId},{model.ClubMatchId},@content)");
|
||||
// if (sqldb.ExecuteNonQuery(sql.ToString(), new SqlParameter("@Content", model.Content)) != 1) {
|
||||
// Debug.Fatal("SaveClubMatchNotes ClubMatchNotes 增加新记录失败!" + sql);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static List<ClubMatchNotes> GetClubMatchNotes(int clubId, int clubMatchId) {
|
||||
// var sql = new StringBuilder();
|
||||
// sql.Append($"select * from {tb_ClubMatchNotes} where clubId = {clubId} and clubMatchId = {clubMatchId} order by ClubMatchNotesId desc");
|
||||
// var list = sqldb.ExecuteEntities(sql.ToString(), p => p.ToObject<ClubMatchNotes>()).ToList();
|
||||
// return list;
|
||||
// }
|
||||
|
||||
// public static void SaveClubMatchScoreNotesList(List<ClubMatchScoreNotes> model) {
|
||||
// sqldb.ExecuteTransaction(t => model.All(p => SaveClubMatchScoreNote(t, p)));
|
||||
// }
|
||||
|
||||
public static ClubMatchUserScore GetClubMatchUserScore(int clubId, int clubMatchId, int userId) {
|
||||
var sql = new StringBuilder();
|
||||
sql.Append($"select * from {tb_ClubMatchUserScore} where clubId = {clubId} and clubMatchId = {clubMatchId} and userId = {userId}");
|
||||
var item = sqldb.ExecuteEntities(sql.ToString(), p => p.ToObject<ClubMatchUserScore>()).SingleOrDefault();
|
||||
return item;
|
||||
}
|
||||
|
||||
public static bool SaveClubMatchUserScore(ClubMatchUserScore model) {
|
||||
return sqldb.ExecuteTransaction(t => SaveClubMatchUserScore(t, model));
|
||||
}
|
||||
|
||||
public static bool SaveClubMatchUserScores(List<ClubMatchUserScore> models) {
|
||||
return sqldb.ExecuteTransaction(t => models.All(model => SaveClubMatchUserScore(t, model)));
|
||||
}
|
||||
|
||||
public static bool SaveClubMatchUserScore(SqlTransaction t, ClubMatchUserScore model) {
|
||||
var sql = new StringBuilder();
|
||||
var parameters = new[] { new SqlParameter("@Score", model.Score), new SqlParameter("@deskScore", model.DeskScore)
|
||||
, new SqlParameter("@ScoreBak", model.ScoreBak)};
|
||||
if (model.UserScoreId == 0) {
|
||||
sql.Append($"insert into {tb_ClubMatchUserScore} (clubId,ClubMatchId,UserId,Score,DeskScore,ScoreBak)");
|
||||
sql.AppendLine($"values({model.ClubId},{model.ClubMatchId},{model.UserId},@Score,@DeskScore,@ScoreBak)");
|
||||
sql.Append($"select cast(SCOPE_IDENTITY() as int)");
|
||||
var result = t.ExecuteScalar(sql.ToString(), parameters);
|
||||
if (result is int id) {
|
||||
model.UserScoreId = id;
|
||||
} else {
|
||||
throw new Exception($"SaveClubMatchUserScore ClubMatchUserScore 增加记录失败!" + sql);
|
||||
}
|
||||
} else {
|
||||
sql.AppendLine($"update {tb_ClubMatchUserScore} set score = @Score, deskScore = @deskScore,ScoreBak=@ScoreBak where UserScoreId = {model.UserScoreId}");
|
||||
if (t.ExecuteNonQuery(sql.ToString(), parameters) != 1) {
|
||||
throw new Exception("SaveClubMatchUserScore ClubMatchUserScore 更新记录失败!" + sql);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static List<ClubMatchUserScore> GetClubMatchUserScores(int clubId, int clubMatchId) {
|
||||
var sql = new StringBuilder();
|
||||
sql.Append($"select * from {tb_ClubMatchUserScore} where clubId = {clubId} and clubMatchId = {clubMatchId} order by UserScoreId desc");
|
||||
var list = sqldb.ExecuteEntities(sql.ToString(), p => p.ToObject<ClubMatchUserScore>()).ToList();
|
||||
return list;
|
||||
}
|
||||
}
|
||||
373
GameDAL/Club/ClubMatchManagerDal.cs
Normal file
373
GameDAL/Club/ClubMatchManagerDal.cs
Normal file
@ -0,0 +1,373 @@
|
||||
using ObjectModel.Club;
|
||||
using Server.DB.Redis;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GameDAL.Club
|
||||
{
|
||||
/// <summary>
|
||||
/// 俱乐部比赛数据库操作对象
|
||||
/// 先从redis获取数据,没有在从数据库获取并保存到redis
|
||||
/// </summary>
|
||||
public static class ClubMatchManagerDal
|
||||
{
|
||||
public static readonly string clubMatchKeyPrefix = "ClubMatch";
|
||||
public static readonly DbStyle redisdb = DbStyle.main;
|
||||
public static readonly int dbidx = 7;
|
||||
static TimeSpan expiry = TimeSpan.FromDays(3);
|
||||
|
||||
static RedisKey GetTopOneClubMatch2Key(int clubId) => $"{clubMatchKeyPrefix}:GetTopOneClubMatch2:{clubId}";
|
||||
|
||||
// /// <summary>
|
||||
// /// 返回比赛数据
|
||||
// /// </summary>
|
||||
// /// <param name="clubId">俱乐部Id</param>
|
||||
// /// <param name="list">需要返回的数据</param>
|
||||
// /// <param name="statusFlag">1进行中 2已结束</param>
|
||||
// /// <returns></returns>
|
||||
// public static ClubMatch GetClubMatchByClubId(int clubId, out List<ClubMatchUserScore> list, int statusFlag = 1)
|
||||
// {
|
||||
// list = null;
|
||||
// var result = redisdb.GetOrAdd(GetClubMatchByClubIdKey(clubId), statusFlag, () =>
|
||||
// {
|
||||
// var clubMatch = ClubMatchManagerAdo.GetClubMatchByClubId(clubId, out var list2, statusFlag);
|
||||
// var ts = clubMatch != null ? expiry : TimeSpan.FromMinutes(10);
|
||||
// return Tuple.Create(Tuple.Create(clubMatch ?? new ClubMatch(), list2 ?? new List<ClubMatchUserScore>()), ts);
|
||||
// }, dbidx, false);
|
||||
// if (result.Item1.ClubMatchId == 0)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// list = result.Item2;
|
||||
// return result.Item1;
|
||||
// }
|
||||
|
||||
// static RedisKey GetClubMatchByClubIdKey(int clubId) => $"{clubMatchKeyPrefix}:ClubMatchByClubId:{clubId}";
|
||||
|
||||
/// <summary>
|
||||
/// 保存比赛数据库到数据库
|
||||
/// 这里要做 比赛玩法保存的逻辑,
|
||||
/// 保存完以后把自增Id赋值
|
||||
/// </summary>
|
||||
public static bool SaveClubMatch(ClubMatch model)
|
||||
{
|
||||
if (model == null) return false;
|
||||
var succ = ClubMatchManagerAdo.SaveClubMatch(model);
|
||||
if (succ)
|
||||
{
|
||||
RemoveCachingOfClubMatch(model.ClubId, model.ClubMatchId);
|
||||
}
|
||||
return succ;
|
||||
}
|
||||
|
||||
public static async Task<bool> SaveClubMatchAsync(ClubMatch model)
|
||||
{
|
||||
return await Task.Run(() => SaveClubMatch(model));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 只更新ClubMatchModel
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public static bool UpdateClubMatchModel(ClubMatch model)
|
||||
{
|
||||
if (model == null || model.ClubMatchId <= 0) return false;
|
||||
var succ = ClubMatchManagerAdo.UpdateClubMatchModel(model);
|
||||
if (succ)
|
||||
{
|
||||
RemoveCachingOfClubMatch(model.ClubId, model.ClubMatchId);
|
||||
}
|
||||
return succ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除缓存的比赛数据
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <param name="clubMatchId"></param>
|
||||
static void RemoveCachingOfClubMatch(int clubId, int clubMatchId)
|
||||
{
|
||||
var key1 = GetClubMatchesKey(clubId);
|
||||
var key2 = GetTopOneClubMatchKey(clubId);
|
||||
redisdb.GetRedisDataBase(dbidx).KeyDelete(new[] { key1, key2 });
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取俱乐部的比赛,,要把比赛玩法的数据组合进来返回
|
||||
// /// </summary>
|
||||
// /// <param name="clubId">俱乐部Id</param>
|
||||
// /// <param name="date">截止时间与比赛开始比较</param>
|
||||
// /// <returns></returns>
|
||||
// public static List<ClubMatch> GetClubMatches(int clubId, DateTime date)
|
||||
// {
|
||||
// return redisdb.GetOrAdd(GetClubMatchesKey(clubId), date.ToString("yyyyMMdd"), () =>
|
||||
// {
|
||||
// var list = ClubMatchManagerAdo.GetClubMatches(clubId, date);
|
||||
// var ts = list.Count > 0 ? expiry : TimeSpan.FromMinutes(10);
|
||||
// return Tuple.Create(list, ts);
|
||||
// }, dbidx, false);
|
||||
// }
|
||||
|
||||
#region 获取最近5局的一个比赛信息
|
||||
|
||||
public static void DeleteGetClubMatchesByTopRedis(int clubId)
|
||||
{
|
||||
string key = $"GetClubMatchesByTop:{clubId}";
|
||||
redisManager.Getdb(dbidx).KeyDelete(key);
|
||||
}
|
||||
|
||||
public static Task<List<ClubMatch>> GetClubMatchesByTopAsync(int clubId, int top = 5)
|
||||
{
|
||||
return Task.Run(() => GetClubMatchesByTop(clubId, top));
|
||||
}
|
||||
|
||||
public static List<ClubMatch> GetClubMatchesByTop(int clubId,int top =5)
|
||||
{
|
||||
string key = $"GetClubMatchesByTop:{clubId}";
|
||||
return redisdb.GetOrAdd(key, string.Empty, () =>
|
||||
{
|
||||
var list = ClubMatchManagerAdo.GetClubMatches(clubId, top);
|
||||
var ts = TimeSpan.FromHours(12);
|
||||
return Tuple.Create(list, ts);
|
||||
}, dbidx, false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
static RedisKey GetClubMatchesKey(int clubId) => $"{clubMatchKeyPrefix}:ClubMatches:{clubId}";
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取俱乐部比赛最近几条 ,要把比赛玩法的数据组合进来返回
|
||||
// /// </summary>
|
||||
// /// <param name="clubId"></param>
|
||||
// /// <param name="top"></param>
|
||||
// /// <returns></returns>
|
||||
// public static List<ClubMatch> GetTopOneClubMatch(int clubId, int top = 1)
|
||||
// {
|
||||
// return redisdb.GetOrAdd(GetTopOneClubMatchKey(clubId), top, () =>
|
||||
// {
|
||||
// var list = ClubMatchManagerAdo.GetTopOneClubMatch(clubId, top);
|
||||
// var ts = list.Count > 0 ? expiry : TimeSpan.FromMinutes(10);
|
||||
// return Tuple.Create(list, ts);
|
||||
// }, dbidx, false);
|
||||
// }
|
||||
static RedisKey GetTopOneClubMatchKey(int clubId) => $"{clubMatchKeyPrefix}:TopOneClubMatch:{clubId}";
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取某个玩家的比赛的积分记录
|
||||
// /// </summary>
|
||||
// /// <param name="clubId"></param>
|
||||
// /// <param name="clubMatchId"></param>
|
||||
// /// <param name="userId"></param>
|
||||
// /// <param name="IsNow">是否是当前的比赛。true是 false不是。如果是当前比赛过期时间只能设置分钟如5分钟,结束的比赛过期时间可以设置长一点如3天</param>
|
||||
// /// <returns></returns>
|
||||
// public static List<ClubMatchScoreNotes> GetClubMatchScoreNotes(int clubId, int clubMatchId, int userId, bool IsNow = false)
|
||||
// {
|
||||
// return redisdb.GetOrAdd(RedisType.List, GetClubMatchScoreNotesKey(clubId, clubMatchId, userId), () =>
|
||||
// {
|
||||
// var list = ClubMatchManagerAdo.GetClubMatchScoreNotes(clubId, clubMatchId, userId);
|
||||
// var ts = IsNow ? TimeSpan.FromMinutes(5) : list.Count > 0 ? expiry : TimeSpan.FromMinutes(3);
|
||||
// return Tuple.Create(list, ts);
|
||||
// }, dbidx, false);
|
||||
// }
|
||||
|
||||
// static RedisKey GetClubMatchScoreNotesKey(int clubId, int clubMatchId, int userId) => $"{clubMatchKeyPrefix}:ClubMatchScoreNotes:{clubId}:{clubMatchId}:{userId}";
|
||||
|
||||
// /// <summary>
|
||||
// /// 保存玩家分值日志
|
||||
// /// </summary>
|
||||
// /// <param name="model"></param>
|
||||
// public static void SaveClubMatchScoreNotes(ClubMatchScoreNotes model)
|
||||
// {
|
||||
// ClubMatchManagerAdo.SaveClubMatchScoreNotes(model);
|
||||
// RemoveCachingOfClubMatchScoreNotes(model.ClubId, model.ClubMatchId, model.UserId);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 批量保存玩家分值日志
|
||||
// /// </summary>
|
||||
// /// <param name="model"></param>
|
||||
// public static void SaveClubMatchScoreNotesList(List<ClubMatchScoreNotes> model)
|
||||
// {
|
||||
// if (model.Count > 0)
|
||||
// {
|
||||
// ClubMatchManagerAdo.SaveClubMatchScoreNotesList(model);
|
||||
// RemoveCachingOfClubMatchScoreNotes(model[0].ClubId, model[0].ClubMatchId, model.Select(p => p.UserId).ToArray());
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 移除缓存的玩家分值日志
|
||||
// /// </summary>
|
||||
// /// <param name="clubId"></param>
|
||||
// /// <param name="clubMatchId"></param>
|
||||
// /// <param name="userIds"></param>
|
||||
// static void RemoveCachingOfClubMatchScoreNotes(int clubId, int clubMatchId, params int[] userIds)
|
||||
// {
|
||||
// var keys = userIds.Select(p => GetClubMatchScoreNotesKey(clubId, clubMatchId, p)).ToArray();
|
||||
// redisdb.GetRedisDataBase(dbidx).KeyDelete(keys);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取比赛记录
|
||||
// /// </summary>
|
||||
// /// <param name="clubId"></param>
|
||||
// /// <param name="clubMatchId"></param>
|
||||
// /// <param name="IsNow">是否是当前的比赛。true是 false不是。如果是当前比赛过期时间只能设置分钟如5分钟,结束的比赛过期时间可以设置长一点如3天</param>
|
||||
// /// <returns></returns>
|
||||
// public static List<ClubMatchNotes> GetClubMatchNotes(int clubId, int clubMatchId, bool IsNow = false)
|
||||
// {
|
||||
// return redisdb.GetOrAdd(RedisType.List, GetClubMatchNotesKey(clubId, clubMatchId), () =>
|
||||
// {
|
||||
// var list = ClubMatchManagerAdo.GetClubMatchNotes(clubId, clubMatchId);
|
||||
// var ts = IsNow ? TimeSpan.FromMinutes(5) : list.Count > 0 ? expiry : TimeSpan.FromMinutes(3);
|
||||
// return Tuple.Create(list, ts);
|
||||
// }, dbidx, false);
|
||||
// }
|
||||
// static RedisKey GetClubMatchNotesKey(int clubId, int clubMatchId) => $"{clubMatchKeyPrefix}:ClubMatchNotes:{clubId}:{clubMatchId}";
|
||||
|
||||
// /// <summary>
|
||||
// /// 返回俱乐部的比赛日志
|
||||
// /// </summary>
|
||||
// /// <param name="clubId">记录表的Id</param>
|
||||
// /// <param name="createTime">返回该时间之后的日志 按时间倒序排序</param>
|
||||
// /// <returns></returns>
|
||||
// public static List<ClubMatchNotes> GetClubMatchNotesByClubId(int clubId, DateTime createTime)
|
||||
// {
|
||||
// return redisdb.GetOrAdd(GetClubMatchNotesByClubIdKey(clubId), createTime.ToString("yyyyMMdd"), () =>
|
||||
// {
|
||||
// var list = ClubMatchManagerAdo.GetClubMatchNotesByClubId(clubId, createTime);
|
||||
// var ts = TimeSpan.FromMinutes(5); //这个是累积实时的,故过期时间短
|
||||
// return Tuple.Create(list, ts);
|
||||
// }, dbidx, false);
|
||||
// }
|
||||
// static RedisKey GetClubMatchNotesByClubIdKey(int clubId) => $"{clubMatchKeyPrefix}:GetClubMatchNotesByClubId:{clubId}";
|
||||
|
||||
// /// <summary>
|
||||
// /// 返回俱乐部的比赛日志
|
||||
// /// </summary>
|
||||
// public static List<ClubMatchNotes> GetClubMatchNotesByClubIdType(int clubId, int type ,DateTime createTime)
|
||||
// {
|
||||
// return redisdb.GetOrAdd(GetClubMatchNotesByClubIdKeyType(clubId,type), createTime.ToString("yyyyMMdd"), () =>
|
||||
// {
|
||||
// var list = ClubMatchManagerAdo.GetClubMatchNotesByClubIdType(clubId, type, createTime);
|
||||
// var ts = TimeSpan.FromMinutes(5); //这个是累积实时的,故过期时间短
|
||||
// return Tuple.Create(list, ts);
|
||||
// }, dbidx, false);
|
||||
// }
|
||||
//static RedisKey GetClubMatchNotesByClubIdKeyType(int clubId,int type) => $"{clubMatchKeyPrefix}:GetClubMatchNotesByClubId:{clubId}_t{type}";
|
||||
|
||||
// public static void RemoveGetClubMatchNotesByClubIdKeyType(int clubId,int type)
|
||||
// {
|
||||
// var key = GetClubMatchNotesByClubIdKeyType(clubId, type);
|
||||
// redisdb.GetRedisDataBase(dbidx).KeyDelete(key);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 保存俱乐部日志记录
|
||||
// /// </summary>
|
||||
// /// <param name="model"></param>
|
||||
// public static void SaveClubMatchNotes(ClubMatchNotes model)
|
||||
// {
|
||||
// ClubMatchManagerAdo.SaveClubMatchNotes(model);
|
||||
// RemoveCachingOfClubMatchNotes(model.ClubId, model.ClubMatchId);
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 移除缓存的群主俱乐部日志记录
|
||||
// /// </summary>
|
||||
// /// <param name="clubId"></param>
|
||||
// /// <param name="clubMatchId"></param>
|
||||
// static void RemoveCachingOfClubMatchNotes(int clubId, int clubMatchId)
|
||||
// {
|
||||
// var key1 = GetClubMatchNotesKey(clubId, clubMatchId);
|
||||
// var key2 = GetClubMatchNotesByClubIdKey(clubId);
|
||||
// redisdb.GetRedisDataBase(dbidx).KeyDelete(new[] { key1, key2 });
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有玩家的比赛积分 过期时间3天
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <param name="clubMatchId"></param>
|
||||
/// <returns></returns>
|
||||
public static List<ClubMatchUserScore> GetClubMatchUserScores(int clubId, int clubMatchId)
|
||||
{
|
||||
return redisdb.GetOrAdd(RedisType.List, GetClubMatchUserScoresKey(clubId, clubMatchId), () =>
|
||||
{
|
||||
//去数据库查询历史数据, 在放到 Redis 中
|
||||
var list = ClubMatchManagerAdo.GetClubMatchUserScores(clubId, clubMatchId);
|
||||
var ts = list.Count > 0 ? expiry : TimeSpan.FromMinutes(10);
|
||||
return Tuple.Create(list, ts);
|
||||
}, dbidx, false);
|
||||
}
|
||||
|
||||
static RedisKey GetClubMatchUserScoresKey(int clubId, int clubMatchId) => $"{clubMatchKeyPrefix}:ClubMatchUserScores:{clubId}:{clubMatchId}";
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取单个玩家的比赛积分
|
||||
// /// </summary>
|
||||
// /// <param name="clubId"></param>
|
||||
// /// <param name="clubMatchId"></param>
|
||||
// /// <param name="userId"></param>
|
||||
// /// <returns></returns>
|
||||
// public static ClubMatchUserScore GetClubMatchUserScore(int clubId, int clubMatchId, int userId)
|
||||
// {
|
||||
// var userScore = redisdb.GetOrAdd(RedisType.String, GetClubMatchUserScoreKey(clubId, clubMatchId, userId), () =>
|
||||
// {
|
||||
// var item = ClubMatchManagerAdo.GetClubMatchUserScore(clubId, clubMatchId, userId);
|
||||
// var ts = item != null ? expiry : TimeSpan.FromMinutes(10);
|
||||
// return Tuple.Create(item ?? new ClubMatchUserScore(), ts);
|
||||
// }, dbidx, false);
|
||||
// return userScore.ClubMatchId != 0 ? userScore : null;
|
||||
// }
|
||||
// static RedisKey GetClubMatchUserScoreKey(int clubId, int clubMatchId, int userId) => $"{clubMatchKeyPrefix}:ClubMatchUserScore:{clubId}:{clubMatchId}:{userId}";
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 保存玩家记录
|
||||
// /// </summary>
|
||||
// /// <param name="model"></param>
|
||||
// public static void SaveClubMatchUserScore(ClubMatchUserScore model)
|
||||
// {
|
||||
// if (ClubMatchManagerAdo.SaveClubMatchUserScore(model))
|
||||
// {
|
||||
// RemoveCachingOfClubMatchUserScore(model.ClubId, model.ClubMatchId, model.UserId);
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 批量保存玩家记录
|
||||
/// </summary>
|
||||
/// <param name="models"></param>
|
||||
public static void SaveSaveClubMatchUserScores(List<ClubMatchUserScore> models)
|
||||
{
|
||||
if (models == null || models.Count < 1) return;
|
||||
if (models.Count > 0)
|
||||
{
|
||||
if (ClubMatchManagerAdo.SaveClubMatchUserScores(models))
|
||||
{
|
||||
RemoveCachingOfClubMatchUserScore(models[0].ClubId, models[0].ClubMatchId, models.Select(p => p.UserId).ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除缓存的玩家记录
|
||||
/// </summary>
|
||||
/// <param name="clubId"></param>
|
||||
/// <param name="clubMatchId"></param>
|
||||
/// <param name="userIds"></param>
|
||||
static void RemoveCachingOfClubMatchUserScore(int clubId, int clubMatchId, params int[] userIds)
|
||||
{
|
||||
var keys = new List<RedisKey>();
|
||||
keys.Add(GetClubMatchUserScoresKey(clubId, clubMatchId));
|
||||
redisdb.GetRedisDataBase(dbidx).KeyDelete(keys.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
209
GameDAL/Club/ClubRCDiscountRedisUtil.cs
Normal file
209
GameDAL/Club/ClubRCDiscountRedisUtil.cs
Normal file
@ -0,0 +1,209 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Server.DB.Redis;
|
||||
using System.Text;
|
||||
using StackExchange.Redis;
|
||||
using MrWu.Debug;
|
||||
|
||||
namespace GameDAL {
|
||||
/// <summary>
|
||||
/// 俱乐部房卡折扣记录
|
||||
/// </summary>
|
||||
public static class ClubRCDiscountRedisUtil {
|
||||
|
||||
private const int DbIdx = 5;
|
||||
private static IDatabaseProxy dbp => redisManager.Getdb(DbIdx);
|
||||
private static IDatabase db => redisManager.GetDataBase(DbStyle.main, DbIdx);
|
||||
private const string baseKey = "ClubRCDiscount";
|
||||
|
||||
#region 直充俱乐部折扣
|
||||
|
||||
private static string GetClubKey() {
|
||||
return $"{baseKey}:Club";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的折扣信息
|
||||
/// </summary>
|
||||
public static List<string> GetClubAll()
|
||||
{
|
||||
string key = GetClubKey();
|
||||
var allEntry = dbp.HashGetAll(key);
|
||||
List<string> list = allEntry.Select(x=>$"{x.Name}, {Convert.ToSingle(x.Value)}").ToList();
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<(int Id, float Discount)> GetClubAllEntry()
|
||||
{
|
||||
string key = GetClubKey();
|
||||
var allEntry = dbp.HashGetAll(key);
|
||||
List<(int, float)> list = new List<(int, float)>();
|
||||
foreach (var item in allEntry)
|
||||
{
|
||||
list.Add((int.Parse(item.Name), float.Parse(item.Value)));
|
||||
}
|
||||
return list.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加折扣
|
||||
/// </summary>
|
||||
public static bool AddClub(int clubId, float discount) {
|
||||
string key = GetClubKey();
|
||||
return dbp.HashSet(key, clubId, discount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除折扣
|
||||
/// </summary>
|
||||
public static bool RemoveClub(int clubId) {
|
||||
string key = GetClubKey();
|
||||
return dbp.HashDelete(key, clubId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取折扣
|
||||
/// </summary>
|
||||
public static float GetClub(int clubId) {
|
||||
string key = GetClubKey();
|
||||
var value = dbp.HashGet(key, clubId);
|
||||
if (value.HasValue && float.TryParse(value, out var discount))
|
||||
{
|
||||
return discount;
|
||||
}
|
||||
return 0.7f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 玩家房卡折扣
|
||||
private static string GetPlayerKey() {
|
||||
return $"{baseKey}:Player";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的折扣信息
|
||||
/// </summary>
|
||||
public static List<string> GetPlayerAll()
|
||||
{
|
||||
string key = GetPlayerKey();
|
||||
var allEntry = dbp.HashGetAll(key);
|
||||
List<string> list = allEntry.Select(x=>$"{x.Name}, {Convert.ToSingle(x.Value)}").ToList();
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<(int Id, float Discount)> GetPlayerAllEntry()
|
||||
{
|
||||
string key = GetPlayerKey();
|
||||
var allEntry = dbp.HashGetAll(key);
|
||||
List<(int, float)> list = new List<(int, float)>();
|
||||
foreach (var item in allEntry)
|
||||
{
|
||||
list.Add((int.Parse(item.Name), float.Parse(item.Value)));
|
||||
}
|
||||
return list.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加折扣
|
||||
/// </summary>
|
||||
public static bool AddPlayer(int userId, float discount) {
|
||||
string key = GetPlayerKey();
|
||||
return dbp.HashSet(key, userId, discount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除折扣
|
||||
/// </summary>
|
||||
public static bool RemovePlayer(int userId) {
|
||||
string key = GetPlayerKey();
|
||||
return dbp.HashDelete(key, userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取折扣
|
||||
/// </summary>
|
||||
public static float GetPlayer(int userId) {
|
||||
string key = GetPlayerKey();
|
||||
var value = dbp.HashGet(key, userId);
|
||||
if (value.HasValue && float.TryParse(value, out var discount))
|
||||
{
|
||||
return discount;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 玩家俱乐部房卡转入限制
|
||||
private static string GetPlayerClubLimitKey(int userId) {
|
||||
return $"{baseKey}:PlayerClubLimit:{userId}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加玩家俱乐部转入限制
|
||||
/// </summary>
|
||||
public static bool AddPlayerClubLimit(int userId, int clubId) {
|
||||
string key = GetPlayerClubLimitKey(userId);
|
||||
return dbp.SetAdd(key,clubId);
|
||||
}
|
||||
|
||||
public static bool AddPlayerClubLimit(int userId, List<int> ids) {
|
||||
string key = GetPlayerClubLimitKey(userId);
|
||||
dbp.KeyDelete(key);
|
||||
RedisValue[] redisValues = ids.Select(id => (RedisValue)id).ToArray();
|
||||
if (redisValues.Length == 0)
|
||||
return true;
|
||||
return dbp.SetAdd(key, redisValues) > 0;
|
||||
}
|
||||
|
||||
public static bool RemovePlayerClubLimit(int userId) {
|
||||
string key = GetPlayerClubLimitKey(userId);
|
||||
return dbp.KeyDelete(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许转入房卡
|
||||
/// </summary>
|
||||
public static bool IsPlayerClubGiveEnable(int userId, int clubId) {
|
||||
string key = GetPlayerClubLimitKey(userId);
|
||||
if (!dbp.KeyExists(key)) return true; // 不存在key就没有限制,都可以转入
|
||||
return dbp.SetContains(key, clubId); // 存在key,只能转入对应的俱乐部
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取玩家俱乐部转入限制
|
||||
/// </summary>
|
||||
public static List<int> GetPlayerClubLimit(int userId)
|
||||
{
|
||||
string key = GetPlayerClubLimitKey(userId);
|
||||
if (!dbp.KeyExists(key)) return new List<int>();
|
||||
return dbp.SetMembers(key).Select(x=>int.Parse(x)).ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 工具方法
|
||||
|
||||
public static (int TotalNum, int GiveNum) CalPlayerCardWithDiscount(int userId, int cardCnt)
|
||||
{
|
||||
var discount = GetPlayer(userId);
|
||||
if (discount <=0 || discount >= 1) return (cardCnt, 0);
|
||||
var totalNum = (int)Math.Round(cardCnt / discount);
|
||||
var giveNum = totalNum - cardCnt;
|
||||
return (totalNum, giveNum);
|
||||
}
|
||||
|
||||
public static (int TotalNum, int GiveNum) CalClubCardWithDiscount(int clubId, int cardCnt)
|
||||
{
|
||||
var discount = GetClub(clubId);
|
||||
if (discount <= 0 || discount >= 1) return (cardCnt, 0);
|
||||
var totalNum = (int)Math.Round(cardCnt / discount);
|
||||
var giveNum = totalNum - cardCnt;
|
||||
return (totalNum, giveNum);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user