添加项目文件。

master
mzhifa 6 months ago
parent 71f9a9b4ad
commit af48e3ee7a

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Txgy.RBS.IBLL;
namespace Txgy.RBS.BLL
{
public class LoginBll: ILoginBll
{
public
public void Test()
{
}
}
}

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Txgy.RBS.IBLL\Txgy.RBS.IBLL.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,161 @@
using SqlSugar;
using System.Linq.Expressions;
using Txgy.RBS.IDAL;
namespace Txgy.RBS.DAL
{
public class BaseService : IBaseService
{
protected ISqlSugarClient _Client { get; set; }
/// <summary>
/// 构造函数
/// </summary>
/// <param name="context"></param>
public BaseService(ISqlSugarClient client)
{
_Client = client;
}
#region Query
public T Find<T>(int id) where T : class
{
return _Client.Queryable<T>().InSingle(id);
}
/// <summary>
/// 不应该暴露给上端使用者,尽量少用
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
//[Obsolete("尽量避免使用using 带表达式目录树的代替")]
public ISugarQueryable<T> Set<T>() where T : class
{
return _Client.Queryable<T>();
}
/// <summary>
/// 这才是合理的做法,上端给条件,这里查询
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="funcWhere"></param>
/// <returns></returns>
public ISugarQueryable<T> Query<T>(Expression<Func<T, bool>> funcWhere) where T : class
{
return _Client.Queryable<T>().Where(funcWhere);
}
public PagingData<T> QueryPage<T>(Expression<Func<T, bool>> funcWhere, int pageSize, int pageIndex, Expression<Func<T, object>> funcOrderby, bool isAsc = true) where T : class
{
var list = _Client.Queryable<T>();
if (funcWhere != null)
{
list = list.Where(funcWhere);
}
list = list.OrderByIF(true, funcOrderby, isAsc ? OrderByType.Asc : OrderByType.Desc);
PagingData<T> result = new PagingData<T>()
{
DataList = list.ToPageList(pageIndex, pageSize),
PageIndex = pageIndex,
PageSize = pageSize,
RecordCount = list.Count(),
};
return result;
}
#endregion
#region Insert
/// <summary>
/// 即使保存 不需要再Commit
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
/// <returns></returns>
public T Insert<T>(T t) where T : class, new()
{
_Client.Insertable(t).ExecuteCommand();
return t;
}
public IEnumerable<T> Insert<T>(List<T> tList) where T : class, new()
{
_Client.Insertable(tList.ToList()).ExecuteCommand();
return tList;
}
#endregion
#region Update
/// <summary>
/// 是没有实现查询,直接更新的,需要Attach和State
///
/// 如果是已经在context只能再封装一个(在具体的service)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
public void Update<T>(T t) where T : class, new()
{
if (t == null) throw new Exception("t is null");
_Client.Updateable(t).ExecuteCommand();
}
public void Update<T>(List<T> tList) where T : class, new()
{
_Client.Updateable(tList).ExecuteCommand();
}
#endregion
#region Delete
/// <summary>
/// 先附加 再删除
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
public void Delete<T>(T t) where T : class, new()
{
_Client.Deleteable(t).ExecuteCommand();
}
/// <summary>
/// 还可以增加非即时commit版本的
/// 做成protected
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Id"></param>
public void Delete<T>(int Id) where T : class, new()
{
T t = _Client.Queryable<T>().InSingle(Id);
_Client.Deleteable(t).ExecuteCommand();
}
public void Delete<T>(List<T> tList) where T : class
{
_Client.Deleteable(tList).ExecuteCommand();
}
#endregion
#region Other
public ISugarQueryable<T> ExcuteQuery<T>(string sql) where T : class, new()
{
return _Client.SqlQueryable<T>(sql);
}
public void Dispose()
{
if (_Client != null)
{
_Client.Dispose();
}
}
//public ISugarQueryable<T> ExcuteQuery<T>(string sql) where T : class, new()
//{
// return _Client.SqlQueryable<T>(sql);
//}
#endregion
}
}

@ -0,0 +1,43 @@
using SqlSugar;
using System.Data;
using Txgy.RBS.DbModel;
using Txgy.RBS.IDAL;
namespace Txgy.RBS.DAL
{
//sqlite数据库操作
public class DataAccessDal : BaseService, IDataAccessDal
{
public DataAccessDal( ISqlSugarClient sqlSugarClient) : base(sqlSugarClient)
{
}
public List<string> GetIcons()
{
var data= _Client.Queryable<Result>().ToList();
return null;
}
public Setting GetClientType(int userId = 1)
{
return new Setting();
}
public void UpdateClientDetail(double createTime, int mailRule, string mailbox, string appMessage)
{
}
public string GetDevices(int roadId)
{
return string.Empty;
}
public void UpdateDeviceType(int currentDevice)
{
}
}
}

@ -0,0 +1,14 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using Txgy.RBS.IDAL;
namespace Txgy.RBS.DAL
{
public class LoginDal : BaseService, ILoginDal
{
public LoginDal(ISqlSugarClient sqlSugarClient) : base(sqlSugarClient) { }
}
}

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SqlSugarCore" Version="5.1.4.148" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Txgy.RBS.DbModel\Txgy.RBS.DbModel.csproj" />
<ProjectReference Include="..\Txgy.RBS.IDAL\Txgy.RBS.IDAL.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Txgy.RBS.DTO.Reception
{
public class JWTTokenOptions
{
public string? Audience
{
get;
set;
}
public string? SecurityKey
{
get;
set;
}
//public SigningCredentials Credentials
//{
// get;
// set;
//}
public string? Issuer
{
get;
set;
}
}
}

@ -0,0 +1,31 @@
namespace Txgy.RBS.DTO
{
///<summary>
///
///</summary>
public partial class ResultJsonDTO
{
public int Id { get; set; }
public string? Name { get; set; }
public string? Mobile { get; set; }
public string? Address { get; set; }
public string? Email { get; set; }
public long? QQ { get; set; }
public string? WeChat { get; set; }
public int? Sex { get; set; }
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public string? UserImageUrl { get; set; }
}
}

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Txgy.RBS.DbModel\Txgy.RBS.DbModel.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,15 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace Txgy.RBS.DbModel
{
[SugarTable("current_monitoring")]
public class CurrentMonitoring
{
[SugarColumn(ColumnName = "current_moni_id", IsPrimaryKey = true, IsIdentity = true)]
public int CurrentMoniId { get; set; }
}
}

@ -0,0 +1,14 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace Txgy.RBS.DbModel
{
[SugarTable("current_workarea")]
public class CurrentWorkarea
{
[SugarColumn(ColumnName = "current_workarea_id", IsPrimaryKey = true, IsIdentity = true)]
public int CurrentWorkareaId { get; set; }
}
}

@ -0,0 +1,22 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace Txgy.RBS.DbModel
{
[SugarTable("monitoring_info")]
public class MonitoringInfo
{
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
[SugarColumn(ColumnName = "work_area_id")]
public int WorkAreaId { get; set; }
[SugarColumn(ColumnName = "layer_num")]
public int LayerNum { get; set; }
[SugarColumn(ColumnName = "moni_num")]
public int MoniNum { get; set; }
[SugarColumn(ColumnName = "moni_date")]
public string MoniDate { get; set; }
}
}

@ -0,0 +1,39 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace Txgy.RBS.DbModel
{
[SugarTable("result")]
public class Result
{
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
[SugarColumn(ColumnName = "project_id")]
public int ProjectId { get; set; }
[SugarColumn(ColumnName = "otime")]
public string Otime { get; set; }
[SugarColumn(ColumnName = "e")]
public double E { get; set; }
[SugarColumn(ColumnName = "n")]
public double N { get; set; }
[SugarColumn(ColumnName = "depth")]
public double Depth { get; set; }
[SugarColumn(ColumnName = "ml")]
public double Ml { get; set; }
[SugarColumn(ColumnName = "energy")]
public double Energy { get; set; }
[SugarColumn(ColumnName = "rms")]
public double Rms { get; set; }
[SugarColumn(ColumnName = "phases_count")]
public int PhasesCount { get; set; }
[SugarColumn(ColumnName = "amps_count")]
public int AmpsCount { get; set; }
[SugarColumn(ColumnName = "seismic_source")]
public string SeismicSource { get; set; }
[SugarColumn(ColumnName = "seismic_direction")]
public double SeismicDirection { get; set; }
}
}

@ -0,0 +1,19 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace Txgy.RBS.DbModel
{
[SugarTable("result_json")]
public class ResultJson
{
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
[SugarColumn(ColumnName = "result_id")]
public int ResultId { get; set; }
[SugarColumn(ColumnName = "json")]
public string Json { get; set; }
}
}

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SqlSugarCore" Version="5.1.4.148" />
</ItemGroup>
</Project>

@ -0,0 +1,59 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace Txgy.RBS.DbModel
{
[SugarTable("workarea")]
public class Workarea
{
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
[SugarColumn(ColumnName = "name")]
public string Name { get; set; }
[SugarColumn(ColumnName = "csv_path")]
public string CsvPath { get; set; }
[SugarColumn(ColumnName = "ttime_path")]
public string TtimePath { get; set; }
[SugarColumn(ColumnName = "x_min")]
public double Xmin { get; set; }
[SugarColumn(ColumnName = "x_max")]
public double Xmax { get; set; }
[SugarColumn(ColumnName = "y_min")]
public double Ymin { get; set; }
[SugarColumn(ColumnName = "y_max")]
public double Ymax { get; set; }
[SugarColumn(ColumnName = "z_min")]
public double Zmin { get; set; }
[SugarColumn(ColumnName = "z_max")]
public double Zmax { get; set; }
[SugarColumn(ColumnName = "save_result")]
public int SaveResult { get; set; }
[SugarColumn(ColumnName = "save_result_path")]
public string SaveResultPath { get; set; }
[SugarColumn(ColumnName = "push_wx")]
public int PushWx { get; set; }
[SugarColumn(ColumnName = "push_wx_value")]
public double PushWxValue { get; set; }
[SugarColumn(ColumnName = "push_dd")]
public int PushDd { get; set; }
[SugarColumn(ColumnName = "push_dd_value")]
public double PushDdValue { get; set; }
[SugarColumn(ColumnName = "save_waves")]
public int SaveWaves { get; set; }
[SugarColumn(ColumnName = "save_waves_path")]
public double SaveWavesPath { get; set; }
[SugarColumn(ColumnName = "send_redis")]
public int SendRedis { get; set; }
[SugarColumn(ColumnName = "mqtt_Server")]
public string MqttServer { get; set; }
[SugarColumn(ColumnName = "network")]
public string Network { get; set; }
[SugarColumn(ColumnName = "location")]
public string Location { get; set; }
[SugarColumn(ColumnName = "channels")]
public string Channels { get; set; }
}
}

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.RBS.Framework.Api
{
public class ApiResult
{
/// <summary>
/// 是否成功
/// </summary>
public bool Success
{
get
{
return string.IsNullOrWhiteSpace(Message);
}
}
public ReponseCodeEnum Code { get; set; }
/// <summary>
/// 特指错误消息
/// </summary>
public string? Message { get; set; }
/// <summary>
/// 数据源
/// </summary>
public object? Data { get; set; }
/// <summary>
/// 额外数据
/// </summary>
public object? Tag { get; set; }
}
public enum ReponseCodeEnum
{
NoAuthorize = 1
}
}

@ -0,0 +1,42 @@
namespace Txgy.RBS.Framework.CustomEnum
{
/// <summary>
/// 审批状态
/// </summary>
public enum ApprovalStatusEnum
{
/// <summary>
/// 普通用户 无需要审批
/// </summary>
NoApproval = 0,
/// <summary>
/// 审批驳回
/// </summary>
[Remark("审批驳回")]
ApprovalRejected = 1,
/// <summary>
///发起审批
/// </summary>
[Remark("发起审批")]
PendingApproval = 2,
/// <summary>
/// 审批通过
/// </summary>
[Remark("审批通过")]
Approved = 3
}
public class RemarkAttribute : Attribute
{
private string _Rmark;
public RemarkAttribute(string remark)
{
this._Rmark = remark;
}
public string GetRemark() => _Rmark;
}
}

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.RBS.Framework.CustomEnum
{
/// <summary>
/// 性别
/// </summary>
public enum GenderEnum
{
[Remark("男")]
Male = 1,
[Remark("女")]
Female = 2,
[Remark("人妖")]
Simon = 3
}
}

@ -0,0 +1,26 @@
namespace Txgy.RBS.Framework.CustomEnum
{
/// <summary>
/// 通用状态
/// </summary>
public enum StatusEnum
{
/// <summary>
/// 禁用
/// </summary>
[Remark("禁用")]
Disable = 0,
/// <summary>
/// 正常
/// </summary>
[Remark("正常")]
Normal = 1,
/// <summary>
/// 已删除
/// </summary>
[Remark("已删除")]
Delete = 2
}
}

@ -0,0 +1,26 @@
namespace Txgy.RBS.Framework.CustomEnum
{
/// <summary>
/// 用户状态
/// </summary>
public enum UserStatusEnum
{
/// <summary>
/// 已冻结
/// </summary>
[Remark("已冻结")]
Frozen = 0,
/// <summary>
/// 正常
/// </summary>
[Remark("正常")]
Normal = 1,
/// <summary>
/// 已删除
/// </summary>
[Remark("已删除")]
Delete = 2
}
}

@ -0,0 +1,26 @@
namespace Txgy.RBS.Framework.CustomEnum
{
/// <summary>
/// 用户类别
/// </summary>
public enum UserTypeEnum
{
/// <summary>
/// 后台用户
/// </summary>
[Remark("后台用户")]
Administrators = 1,
/// <summary>
/// 普通用户
/// </summary>
[Remark("普通用户")]
Member = 2,
/// <summary>
/// 主播用户
/// </summary>
[Remark("主播用户")]
Anchor = 3
}
}

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace Txgy.RBS.Framework
{
public class MD5Encrypt
{
#region MD5
/// <summary>
/// MD5加密,和动网上的16/32位MD5加密结果相同,
/// 使用的UTF8编码
/// </summary>
/// <param name="source">待加密字串</param>
/// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
/// <returns>加密后的字串</returns>
public static string Encrypt(string source, int length = 32)//默认参数
{
if (string.IsNullOrEmpty(source)) return string.Empty;
HashAlgorithm provider = CryptoConfig.CreateFromName("MD5") as HashAlgorithm;
byte[] bytes = Encoding.UTF8.GetBytes(source);//这里需要区别编码的
byte[] hashValue = provider.ComputeHash(bytes);
StringBuilder sb = new StringBuilder();
switch (length)
{
case 16://16位密文是32位密文的9到24位字符
for (int i = 4; i < 12; i++)
{
sb.Append(hashValue[i].ToString("x2"));
}
break;
case 32:
for (int i = 0; i < 16; i++)
{
sb.Append(hashValue[i].ToString("x2"));
}
break;
default:
for (int i = 0; i < hashValue.Length; i++)
{
sb.Append(hashValue[i].ToString("x2"));
}
break;
}
return sb.ToString();
}
#endregion MD5
#region MD5摘要
/// <summary>
/// 获取文件的MD5摘要
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string AbstractFile(string fileName)
{
using (FileStream file = new FileStream(fileName, FileMode.Open))
{
return AbstractFile(file);
}
}
/// <summary>
/// 根据stream获取文件摘要
/// </summary>
/// <param name="stream"></param>
/// <returns></returns>
public static string AbstractFile(Stream stream)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(stream);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}
#endregion
}
}

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.RBS.Framework
{
public class PagingData<T> where T : class
{
public int RecordCount { get; set; }
public int PageIndex { get; set; }
public int PageSize { get; set; }
public List<T>? DataList { get; set; }
public string? SearchString { get; set; }
}
}

@ -0,0 +1,45 @@
using System.Configuration;
namespace Txgy.RBS.Framework.RedisHelper.Init
{
/// <summary>
/// redis配置文件信息
/// 也可以放到配置文件去
/// </summary>
public sealed class RedisConfigInfo
{
/// <summary>
/// 可写的Redis链接地址
/// format:ip1,ip2
///
/// 默认6379端口
/// </summary>
public string WriteServerList = "127.0.0.1:6379";
/// <summary>
/// 可读的Redis链接地址
/// format:ip1,ip2
/// </summary>
public string ReadServerList = "127.0.0.1:6379";
/// <summary>
/// 最大写链接数
/// </summary>
public int MaxWritePoolSize = 60;
/// <summary>
/// 最大读链接数
/// </summary>
public int MaxReadPoolSize = 60;
/// <summary>
/// 本地缓存到期时间,单位:秒
/// </summary>
public int LocalCacheTime = 180;
/// <summary>
/// 自动重启
/// </summary>
public bool AutoStart = true;
/// <summary>
/// 是否记录日志,该设置仅用于排查redis运行时出现的问题,
/// 如redis工作正常,请关闭该项
/// </summary>
public bool RecordeLog = false;
}
}

@ -0,0 +1,52 @@
using ServiceStack.Redis;
namespace Txgy.RBS.Framework.RedisHelper.Init
{
/// <summary>
/// Redis管理中心 创建Redis链接
/// </summary>
public class RedisManager
{
/// <summary>
/// redis配置文件信息
/// </summary>
private static RedisConfigInfo RedisConfigInfo = new RedisConfigInfo();
/// <summary>
/// Redis客户端池化管理
/// </summary>
private static PooledRedisClientManager prcManager;
/// <summary>
/// 静态构造方法,初始化链接池管理对象
/// </summary>
static RedisManager()
{
CreateManager();
}
/// <summary>
/// 创建链接池管理对象
/// </summary>
private static void CreateManager()
{
string[] WriteServerConStr = RedisConfigInfo.WriteServerList.Split(',');
string[] ReadServerConStr = RedisConfigInfo.ReadServerList.Split(',');
prcManager = new PooledRedisClientManager(ReadServerConStr, WriteServerConStr,
new RedisClientManagerConfig
{
MaxWritePoolSize = RedisConfigInfo.MaxWritePoolSize,
MaxReadPoolSize = RedisConfigInfo.MaxReadPoolSize,
AutoStart = RedisConfigInfo.AutoStart,
});
}
/// <summary>
/// 客户端缓存操作对象
/// </summary>
public static IRedisClient GetClient(RedisConfigInfo configInfo)
{
return prcManager.GetClient();
}
}
}

@ -0,0 +1,88 @@
using Microsoft.Extensions.Options;
using ServiceStack.Redis;
using Txgy.RBS.Framework.RedisHelper.Init;
namespace Txgy.RBS.Framework.RedisHelper.Interface
{
/// <summary>
/// RedisBase类是redis操作的基类继承自IDisposable接口主要用于释放内存
/// </summary>
public abstract class RedisBase : IDisposable
{
public IRedisClient IClient { get; private set; }
/// <summary>
/// 构造时完成链接的打开
/// </summary>
public RedisBase(IOptionsMonitor<RedisConfigInfo> options)
{
IClient = RedisManager.GetClient(options.CurrentValue);
}
//public static IRedisClient iClient { get; private set; }
//static RedisBase()
//{
// iClient = RedisManager.GetClient();
//}
private bool _disposed = false;
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
IClient.Dispose();
IClient = null;
}
}
_disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Transcation()
{
using IRedisTransaction irt = IClient.CreateTransaction();
try
{
irt.QueueCommand(r => r.Set("key", 20));
irt.QueueCommand(r => r.Increment("key", 1));
irt.Commit(); // 提交事务
}
catch (Exception)
{
irt.Rollback();
throw;
}
}
/// <summary>
/// 清除全部数据 请小心
/// </summary>
public virtual void FlushAll()
{
IClient.FlushAll();
}
/// <summary>
/// 保存数据DB文件到硬盘
/// </summary>
public void Save()
{
IClient.Save();//阻塞式save
}
/// <summary>
/// 异步保存数据DB文件到硬盘
/// </summary>
public void SaveAsync()
{
IClient.SaveAsync();//异步save
}
}
}

@ -0,0 +1,143 @@

using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Txgy.RBS.Framework.RedisHelper.Init;
using Txgy.RBS.Framework.RedisHelper.Interface;
namespace Txgy.RBS.Framework.RedisHelper.Service
{
/// <summary>
/// Hash:类似dictionary通过索引快速定位到指定元素的耗时均等跟string的区别在于不用反序列化直接修改某个字段
/// string的话要么是 001:序列化整个实体
/// 要么是 001_name: 001_pwd: 多个key-value
/// Hash的话一个hashid-{key:value;key:value;key:value;}
/// 可以一次性查找实体,也可以单个,还可以单个修改
/// </summary>
public class RedisHashService : RedisBase
{
public RedisHashService(IOptionsMonitor<RedisConfigInfo> options) : base(options)
{
}
#region 添加
/// <summary>
/// 向hashid集合中添加key/value
/// </summary>
public bool SetEntryInHash(string hashid, string key, string value)
{
return IClient.SetEntryInHash(hashid, key, value);
}
public void SetRangeInHash(string hashid, IEnumerable<KeyValuePair<string, string>> value)
{
IClient.SetRangeInHash(hashid, value);
}
/// <summary>
/// 如果hashid集合中存在key/value则不添加返回false
/// 如果不存在在添加key/value,返回true
/// </summary>
public bool SetEntryInHashIfNotExists(string hashid, string key, string value)
{
return IClient.SetEntryInHashIfNotExists(hashid, key, value);
}
/// <summary>
/// 存储对象T t到hash集合中
/// 需要包含Id然后用Id获取
/// </summary>
public void StoreAsHash<T>(T t)
{
IClient.StoreAsHash<T>(t);
}
#endregion
#region 获取
/// <summary>
/// 获取对象T中ID为id的数据。
/// </summary>
public T GetFromHash<T>(object id)
{
return IClient.GetFromHash<T>(id);
}
/// <summary>
/// 获取所有hashid数据集的key/value数据集合
/// </summary>
public Dictionary<string, string> GetAllEntriesFromHash(string hashid)
{
return IClient.GetAllEntriesFromHash(hashid);
}
/// <summary>
/// 获取hashid数据集中的数据总数
/// </summary>
public long GetHashCount(string hashid)
{
return IClient.GetHashCount(hashid);
}
/// <summary>
/// 获取hashid数据集中所有key的集合
/// </summary>
public List<string> GetHashKeys(string hashid)
{
return IClient.GetHashKeys(hashid);
}
/// <summary>
/// 获取hashid数据集中的所有value集合
/// </summary>
public List<string> GetHashValues(string hashid)
{
return IClient.GetHashValues(hashid);
}
/// <summary>
/// 获取hashid数据集中key的value数据
/// </summary>
public string GetValueFromHash(string hashid, string key)
{
return IClient.GetValueFromHash(hashid, key);
}
/// <summary>
/// 获取hashid数据集中多个keys的value集合
/// </summary>
public List<string> GetValuesFromHash(string hashid, string[] keys)
{
return IClient.GetValuesFromHash(hashid, keys);
}
#endregion
#region 删除
/// <summary>
/// 删除hashid数据集中的key数据
/// </summary>
public bool RemoveEntryFromHash(string hashid, string key)
{
return IClient.RemoveEntryFromHash(hashid, key);
}
public bool RemoveEntry(string hashid)
{
return IClient.Remove(hashid);
}
#endregion
#region 其它
/// <summary>
/// 判断hashid数据集中是否存在key的数据
/// </summary>
public bool HashContainsEntry(string hashid, string key)
{
return IClient.HashContainsEntry(hashid, key);
}
/// <summary>
/// 给hashid数据集key的value加countby返回相加后的数据
/// </summary>
public double IncrementValueInHash(string hashid, string key, double countBy)
{
return IClient.IncrementValueInHash(hashid, key, countBy);
}
#endregion
}
}

@ -0,0 +1,271 @@

using Microsoft.Extensions.Options;
using ServiceStack.Redis;
using Txgy.RBS.Framework.RedisHelper.Init;
using Txgy.RBS.Framework.RedisHelper.Interface;
namespace Txgy.RBS.Framework.RedisHelper.Service
{
/// <summary>
/// Redis list的实现为一个双向链表即可以支持反向查找和遍历更方便操作不过带来了部分额外的内存开销
/// Redis内部的很多实现包括发送缓冲队列等也都是用的这个数据结构。
/// </summary>
public class RedisListService : RedisBase
{
public RedisListService(IOptionsMonitor<RedisConfigInfo> options) : base(options)
{
}
#region 赋值
/// <summary>
/// 从左侧向list中添加值
/// </summary>
public void LPush(string key, string value)
{
IClient.PushItemToList(key, value);
}
/// <summary>
/// 从左侧向list中添加值并设置过期时间
/// </summary>
public void LPush(string key, string value, DateTime dt)
{
IClient.PushItemToList(key, value);
IClient.ExpireEntryAt(key, dt);
}
/// <summary>
/// 从左侧向list中添加值设置过期时间
/// </summary>
public void LPush(string key, string value, TimeSpan sp)
{
IClient.PushItemToList(key, value);
IClient.ExpireEntryIn(key, sp);
}
/// <summary>
/// 从右侧向list中添加值
/// </summary>
public void RPush(string key, string value)
{
IClient.PrependItemToList(key, value);
}
/// <summary>
/// 从右侧向list中添加值并设置过期时间
/// </summary>
public void RPush(string key, string value, DateTime dt)
{
IClient.PrependItemToList(key, value);
IClient.ExpireEntryAt(key, dt);
}
/// <summary>
/// 从右侧向list中添加值并设置过期时间
/// </summary>
public void RPush(string key, string value, TimeSpan sp)
{
IClient.PrependItemToList(key, value);
IClient.ExpireEntryIn(key, sp);
}
/// <summary>
/// 添加key/value
/// </summary>
public void Add(string key, string value)
{
IClient.AddItemToList(key, value);
}
/// <summary>
/// 添加key/value ,并设置过期时间
/// </summary>
public void Add(string key, string value, DateTime dt)
{
IClient.AddItemToList(key, value);
IClient.ExpireEntryAt(key, dt);
}
/// <summary>
/// 添加key/value。并添加过期时间
/// </summary>
public void Add(string key, string value, TimeSpan sp)
{
IClient.AddItemToList(key, value);
IClient.ExpireEntryIn(key, sp);
}
/// <summary>
/// 为key添加多个值
/// </summary>
public void Add(string key, List<string> values)
{
IClient.AddRangeToList(key, values);
}
/// <summary>
/// 为key添加多个值并设置过期时间
/// </summary>
public void Add(string key, List<string> values, DateTime dt)
{
IClient.AddRangeToList(key, values);
IClient.ExpireEntryAt(key, dt);
}
/// <summary>
/// 为key添加多个值并设置过期时间
/// </summary>
public void Add(string key, List<string> values, TimeSpan sp)
{
IClient.AddRangeToList(key, values);
IClient.ExpireEntryIn(key, sp);
}
#endregion
#region 获取值
/// <summary>
/// 获取list中key包含的数据数量
/// </summary>
public long Count(string key)
{
return IClient.GetListCount(key);
}
/// <summary>
/// 获取key包含的所有数据集合
/// </summary>
public List<string> Get(string key)
{
return IClient.GetAllItemsFromList(key);
}
/// <summary>
/// 获取key中下标为star到end的值集合
/// </summary>
public List<string> Get(string key, int star, int end)
{
return IClient.GetRangeFromList(key, star, end);
}
#endregion
#region 阻塞命令
/// <summary>
/// 阻塞命令从list为key的尾部移除一个值并返回移除的值阻塞时间为sp
/// </summary>
public string BlockingPopItemFromList(string key, TimeSpan? sp)
{
return IClient.BlockingPopItemFromList(key, sp);
}
/// <summary>
/// 阻塞命令从多个list中尾部移除一个值,并返回移除的值&key阻塞时间为sp
/// </summary>
public ItemRef BlockingPopItemFromLists(string[] keys, TimeSpan? sp)
{
return IClient.BlockingPopItemFromLists(keys, sp);
}
/// <summary>
/// 阻塞命令从list中keys的尾部移除一个值并返回移除的值阻塞时间为sp
/// </summary>
public string BlockingDequeueItemFromList(string key, TimeSpan? sp)
{
return IClient.BlockingDequeueItemFromList(key, sp);
}
/// <summary>
/// 阻塞命令从多个list中尾部移除一个值并返回移除的值&key阻塞时间为sp
/// </summary>
public ItemRef BlockingDequeueItemFromLists(string[] keys, TimeSpan? sp)
{
return IClient.BlockingDequeueItemFromLists(keys, sp);
}
/// <summary>
/// 阻塞命令从list中一个fromkey的尾部移除一个值添加到另外一个tokey的头部并返回移除的值阻塞时间为sp
/// </summary>
public string BlockingPopAndPushItemBetweenLists(string fromkey, string tokey, TimeSpan? sp)
{
return IClient.BlockingPopAndPushItemBetweenLists(fromkey, tokey, sp);
}
#endregion
#region 删除
/// <summary>
/// 从尾部移除数据,返回移除的数据
/// </summary>
public string PopItemFromList(string key)
{
var sa = IClient.CreateSubscription();
return IClient.PopItemFromList(key);
}
/// <summary>
/// 从尾部移除数据,返回移除的数据
/// </summary>
public string DequeueItemFromList(string key)
{
return IClient.DequeueItemFromList(key);
}
/// <summary>
/// 移除list中key/value,与参数相同的值,并返回移除的数量
/// </summary>
public long RemoveItemFromList(string key, string value)
{
return IClient.RemoveItemFromList(key, value);
}
/// <summary>
/// 从list的尾部移除一个数据返回移除的数据
/// </summary>
public string RemoveEndFromList(string key)
{
return IClient.RemoveEndFromList(key);
}
/// <summary>
/// 从list的头部移除一个数据返回移除的值
/// </summary>
public string RemoveStartFromList(string key)
{
return IClient.RemoveStartFromList(key);
}
#endregion
#region 其它
/// <summary>
/// 从一个list的尾部移除一个数据添加到另外一个list的头部并返回移动的值
/// </summary>
public string PopAndPushItemBetweenLists(string fromKey, string toKey)
{
return IClient.PopAndPushItemBetweenLists(fromKey, toKey);
}
public void TrimList(string key, int start, int end)
{
IClient.TrimList(key, start, end);
}
#endregion
#region 发布订阅
public void Publish(string channel, string message)
{
IClient.PublishMessage(channel, message);
}
public void Subscribe(string channel, Action<string, string, IRedisSubscription> actionOnMessage)
{
var subscription = IClient.CreateSubscription();
subscription.OnSubscribe = c =>
{
Console.WriteLine($"订阅频道{c}");
Console.WriteLine();
};
//取消订阅
subscription.OnUnSubscribe = c =>
{
Console.WriteLine($"取消订阅 {c}");
Console.WriteLine();
};
subscription.OnMessage += (c, s) =>
{
actionOnMessage(c, s, subscription);
};
Console.WriteLine($"开始启动监听 {channel}");
subscription.SubscribeToChannels(channel); //blocking
}
public void UnSubscribeFromChannels(string channel)
{
var subscription = IClient.CreateSubscription();
subscription.UnSubscribeFromChannels(channel);
}
#endregion
}
}

@ -0,0 +1,124 @@
using Microsoft.Extensions.Options;
using Txgy.RBS.Framework.RedisHelper.Init;
using Txgy.RBS.Framework.RedisHelper.Interface;
namespace Txgy.RBS.Framework.RedisHelper.Service
{
/// <summary>
/// Set用哈希表来保持字符串的唯一性没有先后顺序存储一些集合性的数据
/// 1.共同好友、二度好友
/// 2.利用唯一性,可以统计访问网站的所有独立 IP
/// </summary>
public class RedisSetService : RedisBase
{
public RedisSetService(IOptionsMonitor<RedisConfigInfo> options) : base(options)
{
}
#region 添加
/// <summary>
/// key集合中添加value值
/// </summary>
public void Add(string key, string value)
{
IClient.AddItemToSet(key, value);
}
/// <summary>
/// key集合中添加list集合
/// </summary>
public void Add(string key, List<string> list)
{
IClient.AddRangeToSet(key, list);
}
#endregion
#region 获取
/// <summary>
/// 随机获取key集合中的一个值
/// </summary>
public string GetRandomItemFromSet(string key)
{
return IClient.GetRandomItemFromSet(key);
}
/// <summary>
/// 获取key集合值的数量
/// </summary>
public long GetCount(string key)
{
return IClient.GetSetCount(key);
}
/// <summary>
/// 获取所有key集合的值
/// </summary>
public HashSet<string> GetAllItemsFromSet(string key)
{
return IClient.GetAllItemsFromSet(key);
}
#endregion
#region 删除
/// <summary>
/// 随机删除key集合中的一个值
/// </summary>
public string RandomRemoveItemFromSet(string key)
{
return IClient.PopItemFromSet(key);
}
/// <summary>
/// 删除key集合中的value
/// </summary>
public void RemoveItemFromSet(string key, string value)
{
IClient.RemoveItemFromSet(key, value);
}
#endregion
#region 其它
/// <summary>
/// 从fromkey集合中移除值为value的值并把value添加到tokey集合中
/// </summary>
public void MoveBetweenSets(string fromkey, string tokey, string value)
{
IClient.MoveBetweenSets(fromkey, tokey, value);
}
/// <summary>
/// 返回keys多个集合中的并集返还hashset
/// </summary>
public HashSet<string> GetUnionFromSets(params string[] keys)
{
return IClient.GetUnionFromSets(keys);
}
/// <summary>
/// 返回keys多个集合中的交集返还hashset
/// </summary>
public HashSet<string> GetIntersectFromSets(params string[] keys)
{
return IClient.GetIntersectFromSets(keys);
}
/// <summary>
/// 返回keys多个集合中的差集返还hashset
/// </summary>
/// <param name="fromKey">原集合</param>
/// <param name="keys">其他集合</param>
/// <returns>出现在原集合,但不包含在其他集合</returns>
public HashSet<string> GetDifferencesFromSet(string fromKey, params string[] keys)
{
return IClient.GetDifferencesFromSet(fromKey, keys);
}
/// <summary>
/// keys多个集合中的并集放入newkey集合中
/// </summary>
public void StoreUnionFromSets(string newkey, string[] keys)
{
IClient.StoreUnionFromSets(newkey, keys);
}
/// <summary>
/// 把fromkey集合中的数据与keys集合中的数据对比fromkey集合中不存在keys集合中则把这些不存在的数据放入newkey集合中
/// </summary>
public void StoreDifferencesFromSet(string newkey, string fromkey, string[] keys)
{
IClient.StoreDifferencesFromSet(newkey, fromkey, keys);
}
#endregion
}
}

@ -0,0 +1,164 @@

using Microsoft.Extensions.Options;
using ServiceStack.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Txgy.RBS.Framework.RedisHelper.Init;
using Txgy.RBS.Framework.RedisHelper.Interface;
namespace Txgy.RBS.Framework.RedisHelper.Service
{
/// <summary>
/// key-value 键值对:value可以是序列化的数据
/// </summary>
public class RedisStringService : RedisBase
{
public RedisStringService(IOptionsMonitor<RedisConfigInfo> options) : base(options)
{
}
#region 赋值
/// <summary>
/// 设置key的value
/// </summary>
public bool Set<T>(string key, T value)
{
//iClient.Db =2;
return IClient.Set<T>(key, value);
}
/// <summary>
/// 设置key的value并设置过期时间
/// </summary>
public bool Set<T>(string key, T value, DateTime dt)
{
//iClient.Db = 2;
return IClient.Set<T>(key, value, dt);
}
/// <summary>
/// 设置key的value并设置过期时间
/// </summary>
public bool Set<T>(string key, T value, TimeSpan sp)
{
//iClient.Db = 2;
return IClient.Set<T>(key, value, sp);
}
/// <summary>
/// 设置多个key/value 可以一次保存多个key value ---多个key value 不是分多次,是一个独立的命令;
/// </summary>
public void Set(Dictionary<string, string> dic)
{
//iClient.Db = 2;
IClient.SetAll(dic);
}
#endregion
#region 追加
/// <summary>
/// 在原有key的value值之后追加value,没有就新增一项
/// </summary>
public long Append(string key, string value)
{
return IClient.AppendToValue(key, value);
}
#endregion
#region 获取值
/// <summary>
/// 获取key的value值
/// </summary>
public string Get(string key)
{
return IClient.GetValue(key);
}
/// <summary>
/// 获取多个key的value值
/// </summary>
public List<string> Get(List<string> keys)
{
return IClient.GetValues(keys);
}
/// <summary>
/// 获取多个key的value值
/// </summary>
public List<T> Get<T>(List<string> keys)
{
return IClient.GetValues<T>(keys);
}
public T Get<T>(string key)
{
return IClient.Get<T>(key);
}
#endregion
#region 获取旧值赋上新值
/// <summary>
/// 获取旧值赋上新值
/// </summary>
public string GetAndSetValue(string key, string value)
{
return IClient.GetAndSetValue(key, value);
}
#endregion
#region 辅助方法
/// <summary>
/// 获取值的长度
/// </summary>
public long GetLength(string key)
{
return IClient.GetStringCount(key);
}
/// <summary>
/// 自增1返回自增后的值 保存的是10 调用后,+1 返回11
/// </summary>
public long Incr(string key)
{
return IClient.IncrementValue(key);
}
/// <summary>
/// 自增count返回自增后的值 自定义自增的步长值
/// </summary>
public long IncrBy(string key, int count)
{
return IClient.IncrementValueBy(key, count);
}
/// <summary>
/// 自减1返回自减后的值Redis操作是单线程操作不会出现超卖的情况
/// </summary>
public long Decr(string key)
{
return IClient.DecrementValue(key);
}
/// <summary>
/// 自减count ,返回自减后的值
/// </summary>
/// <param name="key"></param>
/// <param name="count"></param>
/// <returns></returns>
public long DecrBy(string key, int count)
{
return IClient.DecrementValueBy(key, count);
}
/// <summary>
/// 设置滑动过期时间
/// </summary>
/// <param name="key"></param>
/// <param name="timeSpan"></param>
/// <returns></returns>
public bool ExpireEntryIn(string key, TimeSpan timeSpan)
{
return IClient.ExpireEntryIn(key, timeSpan);
}
#endregion
}
}

@ -0,0 +1,233 @@

using Microsoft.Extensions.Options;
using Txgy.RBS.Framework.RedisHelper.Init;
using Txgy.RBS.Framework.RedisHelper.Interface;
namespace Txgy.RBS.Framework.RedisHelper.Service
{
/// <summary>
/// Sorted Sets是将 Set 中的元素增加了一个权重参数 score使得集合中的元素能够按 score 进行有序排列
/// 1.带有权重的元素,比如一个游戏的用户得分排行榜
/// 2.比较复杂的数据结构,一般用到的场景不算太多
/// </summary>
public class RedisZSetService : RedisBase
{
public RedisZSetService(IOptionsMonitor<RedisConfigInfo> options) : base(options)
{
}
#region 添加
/// <summary>
/// 添加key/value默认分数是从1.多*10的9次方以此递增的,自带自增效果
/// </summary>
public bool Add(string key, string value)
{
return IClient.AddItemToSortedSet(key, value);
}
/// <summary>
/// 添加key/value,并设置value的分数
/// </summary>
public bool AddItemToSortedSet(string key, string value, double score)
{
return IClient.AddItemToSortedSet(key, value, score);
}
/// <summary>
/// 为key添加values集合values集合中每个value的分数设置为score
/// </summary>
public bool AddRangeToSortedSet(string key, List<string> values, double score)
{
return IClient.AddRangeToSortedSet(key, values, score);
}
/// <summary>
/// 为key添加values集合values集合中每个value的分数设置为score
/// </summary>
public bool AddRangeToSortedSet(string key, List<string> values, long score)
{
return IClient.AddRangeToSortedSet(key, values, score);
}
#endregion
#region 获取
/// <summary>
/// 获取key的所有集合
/// </summary>
public List<string> GetAll(string key)
{
return IClient.GetAllItemsFromSortedSet(key);
}
/// <summary>
/// 获取key的所有集合倒叙输出
/// </summary>
public List<string> GetAllDesc(string key)
{
return IClient.GetAllItemsFromSortedSetDesc(key);
}
/// <summary>
/// 获取集合,带分数
/// </summary>
public IDictionary<string, double> GetAllWithScoresFromSortedSet(string key)
{
return IClient.GetAllWithScoresFromSortedSet(key);
}
/// <summary>
/// 获取key为value的下标值
/// </summary>
public long GetItemIndexInSortedSet(string key, string value)
{
return IClient.GetItemIndexInSortedSet(key, value);
}
/// <summary>
/// 倒叙排列获取key为value的下标值
/// </summary>
public long GetItemIndexInSortedSetDesc(string key, string value)
{
return IClient.GetItemIndexInSortedSetDesc(key, value);
}
/// <summary>
/// 获取key为value的分数
/// </summary>
public double GetItemScoreInSortedSet(string key, string value)
{
return IClient.GetItemScoreInSortedSet(key, value);
}
/// <summary>
/// 获取key所有集合的数据总数
/// </summary>
public long GetSortedSetCount(string key)
{
return IClient.GetSortedSetCount(key);
}
/// <summary>
/// key集合数据从分数为fromscore到分数为toscore的数据总数
/// </summary>
public long GetSortedSetCount(string key, double fromScore, double toScore)
{
return IClient.GetSortedSetCount(key, fromScore, toScore);
}
/// <summary>
/// 获取key集合从高分到低分排序数据分数从fromscore到分数为toscore的数据
/// </summary>
public List<string> GetRangeFromSortedSetByHighestScore(string key, double fromscore, double toscore)
{
return IClient.GetRangeFromSortedSetByHighestScore(key, fromscore, toscore);
}
/// <summary>
/// 获取key集合从低分到高分排序数据分数从fromscore到分数为toscore的数据
/// </summary>
public List<string> GetRangeFromSortedSetByLowestScore(string key, double fromscore, double toscore)
{
return IClient.GetRangeFromSortedSetByLowestScore(key, fromscore, toscore);
}
/// <summary>
/// 获取key集合从高分到低分排序数据分数从fromscore到分数为toscore的数据带分数
/// </summary>
public IDictionary<string, double> GetRangeWithScoresFromSortedSetByHighestScore(string key, double fromscore, double toscore)
{
return IClient.GetRangeWithScoresFromSortedSetByHighestScore(key, fromscore, toscore);
}
/// <summary>
/// 获取key集合从低分到高分排序数据分数从fromscore到分数为toscore的数据带分数
/// </summary>
public IDictionary<string, double> GetRangeWithScoresFromSortedSetByLowestScore(string key, double fromscore, double toscore)
{
return IClient.GetRangeWithScoresFromSortedSetByLowestScore(key, fromscore, toscore);
}
/// <summary>
/// 获取key集合数据下标从fromRank到分数为toRank的数据
/// </summary>
public List<string> GetRangeFromSortedSet(string key, int fromRank, int toRank)
{
return IClient.GetRangeFromSortedSet(key, fromRank, toRank);
}
/// <summary>
/// 获取key集合倒叙排列数据下标从fromRank到分数为toRank的数据
/// </summary>
public List<string> GetRangeFromSortedSetDesc(string key, int fromRank, int toRank)
{
return IClient.GetRangeFromSortedSetDesc(key, fromRank, toRank);
}
/// <summary>
/// 获取key集合数据下标从fromRank到分数为toRank的数据带分数
/// </summary>
public IDictionary<string, double> GetRangeWithScoresFromSortedSet(string key, int fromRank, int toRank)
{
return IClient.GetRangeWithScoresFromSortedSet(key, fromRank, toRank);
}
/// <summary>
/// 获取key集合倒叙排列数据下标从fromRank到分数为toRank的数据带分数
/// </summary>
public IDictionary<string, double> GetRangeWithScoresFromSortedSetDesc(string key, int fromRank, int toRank)
{
return IClient.GetRangeWithScoresFromSortedSetDesc(key, fromRank, toRank);
}
#endregion
#region 删除
/// <summary>
/// 删除key为value的数据
/// </summary>
public bool RemoveItemFromSortedSet(string key, string value)
{
return IClient.RemoveItemFromSortedSet(key, value);
}
/// <summary>
/// 删除下标从minRank到maxRank的key集合数据
/// </summary>
public long RemoveRangeFromSortedSet(string key, int minRank, int maxRank)
{
return IClient.RemoveRangeFromSortedSet(key, minRank, maxRank);
}
/// <summary>
/// 删除分数从fromscore到toscore的key集合数据
/// </summary>
public long RemoveRangeFromSortedSetByScore(string key, double fromscore, double toscore)
{
return IClient.RemoveRangeFromSortedSetByScore(key, fromscore, toscore);
}
/// <summary>
/// 删除key集合中分数最大的数据
/// </summary>
public string PopItemWithHighestScoreFromSortedSet(string key)
{
return IClient.PopItemWithHighestScoreFromSortedSet(key);
}
/// <summary>
/// 删除key集合中分数最小的数据
/// </summary>
public string PopItemWithLowestScoreFromSortedSet(string key)
{
return IClient.PopItemWithLowestScoreFromSortedSet(key);
}
#endregion
#region 其它
/// <summary>
/// 判断key集合中是否存在value数据
/// </summary>
public bool SortedSetContainsItem(string key, string value)
{
return IClient.SortedSetContainsItem(key, value);
}
/// <summary>
/// 为key集合值为value的数据分数加scoreby返回相加后的分数
/// </summary>
public double IncrementItemInSortedSet(string key, string value, double scoreBy)
{
return IClient.IncrementItemInSortedSet(key, value, scoreBy);
}
/// <summary>
/// 获取keys多个集合的交集并把交集添加的newkey集合中返回交集数据的总数
/// </summary>
public long StoreIntersectFromSortedSets(string newkey, string[] keys)
{
return IClient.StoreIntersectFromSortedSets(newkey, keys);
}
/// <summary>
/// 获取keys多个集合的并集并把并集数据添加到newkey集合中返回并集数据的总数
/// </summary>
public long StoreUnionFromSortedSets(string newkey, string[] keys)
{
return IClient.StoreUnionFromSortedSets(newkey, keys);
}
#endregion
}
}

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="ServiceStack.Interfaces" Version="6.10.0" />
<PackageReference Include="ServiceStack.Redis" Version="6.10.0" />
</ItemGroup>
</Project>

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.RBS.IBLL
{
public interface ILoginBll
{
}
}

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Txgy.RBS.IDAL\Txgy.RBS.IDAL.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.RBS.IDAL
{
public class DbConnectionOptions
{
public string ConnectionString { get; set; } = string.Empty;
public ConnectionTypeEnum ConnectionType { get; set; }
}
public enum ConnectionTypeEnum
{
Sqlite = 0,
SqlServer = 1
}
}

@ -0,0 +1,106 @@
using SqlSugar;
using System.Linq.Expressions;
namespace Txgy.RBS.IDAL
{
public interface IBaseService
{
#region Query
/// <summary>
/// 根据id查询实体
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
T Find<T>(int id) where T : class;
/// <summary>
/// 提供对单表的查询
/// </summary>
/// <returns>ISugarQueryable类型集合</returns>
[Obsolete("尽量避免使用using 带表达式目录树的 代替")]
ISugarQueryable<T> Set<T>() where T : class;
/// <summary>
/// 查询
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="funcWhere"></param>
/// <returns></returns>
ISugarQueryable<T> Query<T>(Expression<Func<T, bool>> funcWhere) where T : class;
/// <summary>
/// 分页查询
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="S"></typeparam>
/// <param name="funcWhere"></param>
/// <param name="pageSize"></param>
/// <param name="pageIndex"></param>
/// <param name="funcOrderby"></param>
/// <param name="isAsc"></param>
/// <returns></returns>
PagingData<T> QueryPage<T>(Expression<Func<T, bool>> funcWhere, int pageSize, int pageIndex, Expression<Func<T, object>> funcOrderby, bool isAsc = true) where T : class;
#endregion
#region Add
/// <summary>
/// 新增数据即时Commit
/// </summary>
/// <param name="t"></param>
/// <returns>返回带主键的实体</returns>
T Insert<T>(T t) where T : class, new();
/// <summary>
/// 新增数据即时Commit
/// 多条sql 一个连接,事务插入
/// </summary>
/// <param name="tList"></param>
IEnumerable<T> Insert<T>(List<T> tList) where T : class, new();
#endregion
#region Update
/// <summary>
/// 更新数据即时Commit
/// </summary>
/// <param name="t"></param>
void Update<T>(T t) where T : class, new();
/// <summary>
/// 更新数据即时Commit
/// </summary>
/// <param name="tList"></param>
void Update<T>(List<T> tList) where T : class, new();
#endregion
#region Delete
/// <summary>
/// 根据主键删除数据即时Commit
/// </summary>
/// <param name="t"></param>
void Delete<T>(int Id) where T : class, new();
/// <su+mary>
/// 删除数据即时Commit
/// </summary>
/// <param name="t"></param>
void Delete<T>(T t) where T : class, new();
/// <summary>
/// 删除数据即时Commit
/// </summary>
/// <param name="tList"></param>
void Delete<T>(List<T> tList) where T : class;
#endregion
#region Other
/// <summary>
/// 执行sql 返回集合
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="sql"></param>
/// <returns></returns>
ISugarQueryable<T> ExcuteQuery<T>(string sql) where T : class, new();
#endregion
}
}

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.RBS.IDAL
{
public interface IDataAccessDal
{
List<string> GetIcons();
/// <summary>
/// 获取客户端类型
/// </summary>
/// <returns></returns>
Setting GetClientType(int useId = 1);
void UpdateClientDetail(double createTime, int mailRule, string mailbox, string appMessage);
/// <summary>
/// 根据车道ID获取对应的设备信息
/// </summary>
/// <param name="roadId"></param>
/// <returns></returns>
string GetDevices(int roadId);
void UpdateDeviceType(int currentDevice);
}
}

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Txgy.RBS.IDAL
{
public interface ILoginDal : IBaseService
{
}
}

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.RBS.IDAL
{
public class PageResult<T>
{
public PageResult()
{ }
public PageResult(int pageIndex, int pageSize)
{
PageIndex = pageIndex;
PageSize = pageSize;
}
public int PageIndex { get; set; }
public int PageSize { get; set; }
public long TotalCount { get; set; }
public List<T> DataList { get; set; }
}
}

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.RBS.IDAL
{
public class PagingData<T> where T : class
{
public int RecordCount { get; set; }
public int PageIndex { get; set; }
public int PageSize { get; set; }
public List<T>? DataList { get; set; }
public string? SearchString { get; set; }
}
}

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.RBS.IDAL
{
public class Setting
{
public int ClientType { get; set; }
public string Mailbox { get; set; }
public int MailRule { get; set; }
//为了统计1个整月的数据如果修改时间超过每月28号统一设置成每月28号
public double CreateTime { get; set; }
public int CurrentDevice { get; set; }
public string AppMessage { get; set; }
}
}

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SqlSugarCore" Version="5.1.4.148" />
</ItemGroup>
</Project>

@ -0,0 +1,18 @@
using AutoMapper;
using Txgy.RBS.DbModel;
using Txgy.RBS.DTO;
using Txgy.RBS.DTO.Reception;
using Txgy.RBS.Framework;
namespace Txgy.RBS.IServices
{
public class AutoMapObject : Profile
{
public AutoMapObject()
{
CreateMap<ResultJson, ResultJsonDTO>().ReverseMap();
//CreateMap<MenueInfo, MenueInfoDTO>().ReverseMap();
//CreateMap<PagingData<MenueInfo>, PagingData<MenueInfoDTO>>();
}
}
}

@ -0,0 +1,108 @@
using SqlSugar;
using System.Linq.Expressions;
using Txgy.RBS.Framework;
namespace Txgy.RBS.IServices
{
public interface IBaseService
{
#region Query
/// <summary>
/// 根据id查询实体
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
T Find<T>(int id) where T : class;
/// <summary>
/// 提供对单表的查询
/// </summary>
/// <returns>ISugarQueryable类型集合</returns>
[Obsolete("尽量避免使用using 带表达式目录树的 代替")]
ISugarQueryable<T> Set<T>() where T : class;
/// <summary>
/// 查询
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="funcWhere"></param>
/// <returns></returns>
ISugarQueryable<T> Query<T>(Expression<Func<T, bool>> funcWhere) where T : class;
/// <summary>
/// 分页查询
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="S"></typeparam>
/// <param name="funcWhere"></param>
/// <param name="pageSize"></param>
/// <param name="pageIndex"></param>
/// <param name="funcOrderby"></param>
/// <param name="isAsc"></param>
/// <returns></returns>
PagingData<T> QueryPage<T>(Expression<Func<T, bool>> funcWhere, int pageSize, int pageIndex, Expression<Func<T, object>> funcOrderby, bool isAsc = true) where T : class;
#endregion
#region Add
/// <summary>
/// 新增数据即时Commit
/// </summary>
/// <param name="t"></param>
/// <returns>返回带主键的实体</returns>
T Insert<T>(T t) where T : class, new();
/// <summary>
/// 新增数据即时Commit
/// 多条sql 一个连接,事务插入
/// </summary>
/// <param name="tList"></param>
IEnumerable<T> Insert<T>(List<T> tList) where T : class, new();
#endregion
#region Update
/// <summary>
/// 更新数据即时Commit
/// </summary>
/// <param name="t"></param>
void Update<T>(T t) where T : class, new();
/// <summary>
/// 更新数据即时Commit
/// </summary>
/// <param name="tList"></param>
void Update<T>(List<T> tList) where T : class, new();
#endregion
#region Delete
/// <summary>
/// 根据主键删除数据即时Commit
/// </summary>
/// <param name="t"></param>
void Delete<T>(int Id) where T : class, new();
/// <su+mary>
/// 删除数据即时Commit
/// </summary>
/// <param name="t"></param>
void Delete<T>(T t) where T : class, new();
/// <summary>
/// 删除数据即时Commit
/// </summary>
/// <param name="tList"></param>
void Delete<T>(List<T> tList) where T : class;
#endregion
#region Other
/// <summary>
/// 执行sql 返回集合
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="sql"></param>
/// <returns></returns>
ISugarQueryable<T> ExcuteQuery<T>(string sql) where T : class, new();
#endregion
}
}

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.RBS.IServices
{
public interface IDataAccessService
{
List<string> GetIcons();
/// <summary>
/// 获取客户端类型
/// </summary>
/// <returns></returns>
Setting GetClientType(int useId = 1);
void UpdateClientDetail(double createTime, int mailRule, string mailbox, string appMessage);
/// <summary>
/// 根据车道ID获取对应的设备信息
/// </summary>
/// <param name="roadId"></param>
/// <returns></returns>
string GetDevices(int roadId);
void UpdateDeviceType(int currentDevice);
}
}

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Txgy.RBS.IServices
{
public interface ILoginService : IBaseService
{
}
}

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.RBS.IServices
{
public class Setting
{
public int ClientType { get; set; }
public string Mailbox { get; set; }
public int MailRule { get; set; }
//为了统计1个整月的数据如果修改时间超过每月28号统一设置成每月28号
public double CreateTime { get; set; }
public int CurrentDevice { get; set; }
public string AppMessage { get; set; }
}
}

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Txgy.RBS.DbModel\Txgy.RBS.DbModel.csproj" />
<ProjectReference Include="..\Txgy.RBS.DTO\Txgy.RBS.DTO.csproj" />
<ProjectReference Include="..\Txgy.RBS.Framework\Txgy.RBS.Framework.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,55 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34316.72
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Txgy.RBS.DbModel", "Txgy.RBS.DbModel\Txgy.RBS.DbModel.csproj", "{4C41E1CF-BA9C-45F8-9055-70EDA35579A2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Txgy.RBS.Server.WebApi", "Txgy.RBS.Server.WebApi\Txgy.RBS.Server.WebApi.csproj", "{AA0B6F7F-60BE-4194-AF85-ABD5F9CEB949}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Txgy.RBS.IServices", "Txgy.RBS.IServices\Txgy.RBS.IServices.csproj", "{E80A6A7C-514E-4E98-B5D3-92076960D15D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Txgy.RBS.Services", "Txgy.RBS.Services\Txgy.RBS.Services.csproj", "{62C154B8-02B1-4373-9CC3-E1BE98BD5185}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Txgy.RBS.DTO", "Txgy.RBS.DTO\Txgy.RBS.DTO.csproj", "{AD9839D2-4CDE-49CC-BFC2-B5E2C7A3D8D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Txgy.RBS.Framework", "Txgy.RBS.Framework\Txgy.RBS.Framework.csproj", "{192F744E-9C15-46F5-94CE-801C65E67AED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4C41E1CF-BA9C-45F8-9055-70EDA35579A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C41E1CF-BA9C-45F8-9055-70EDA35579A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C41E1CF-BA9C-45F8-9055-70EDA35579A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C41E1CF-BA9C-45F8-9055-70EDA35579A2}.Release|Any CPU.Build.0 = Release|Any CPU
{AA0B6F7F-60BE-4194-AF85-ABD5F9CEB949}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA0B6F7F-60BE-4194-AF85-ABD5F9CEB949}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA0B6F7F-60BE-4194-AF85-ABD5F9CEB949}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA0B6F7F-60BE-4194-AF85-ABD5F9CEB949}.Release|Any CPU.Build.0 = Release|Any CPU
{E80A6A7C-514E-4E98-B5D3-92076960D15D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E80A6A7C-514E-4E98-B5D3-92076960D15D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E80A6A7C-514E-4E98-B5D3-92076960D15D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E80A6A7C-514E-4E98-B5D3-92076960D15D}.Release|Any CPU.Build.0 = Release|Any CPU
{62C154B8-02B1-4373-9CC3-E1BE98BD5185}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62C154B8-02B1-4373-9CC3-E1BE98BD5185}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62C154B8-02B1-4373-9CC3-E1BE98BD5185}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62C154B8-02B1-4373-9CC3-E1BE98BD5185}.Release|Any CPU.Build.0 = Release|Any CPU
{AD9839D2-4CDE-49CC-BFC2-B5E2C7A3D8D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD9839D2-4CDE-49CC-BFC2-B5E2C7A3D8D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD9839D2-4CDE-49CC-BFC2-B5E2C7A3D8D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD9839D2-4CDE-49CC-BFC2-B5E2C7A3D8D8}.Release|Any CPU.Build.0 = Release|Any CPU
{192F744E-9C15-46F5-94CE-801C65E67AED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{192F744E-9C15-46F5-94CE-801C65E67AED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{192F744E-9C15-46F5-94CE-801C65E67AED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{192F744E-9C15-46F5-94CE-801C65E67AED}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3E38EDAF-193F-45CF-8DAD-2449AF53DAAB}
EndGlobalSection
EndGlobal

@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Mvc;
using Txgy.RBS.IServices;
namespace Txgy.RBS.Server.WebApi.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
private readonly IDataAccessService _dataAccessDal;
public WeatherForecastController(ILogger<WeatherForecastController> logger, IDataAccessService dataAccessDal)
{
_logger = logger;
this._dataAccessDal = dataAccessDal;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
var a = _dataAccessDal.GetIcons();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

@ -0,0 +1,53 @@
using SqlSugar;
using System.ComponentModel;
using Txgy.RBS.IServices;
using Txgy.RBS.Server.WebApi.Register;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Register(); //业务逻辑层的注册
//支持Automapper映射
builder.Services.AddAutoMapper(typeof(AutoMapObject));
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
//配置sqlsugar
builder.Services.AddTransient<ISqlSugarClient>(context =>
{
string con = builder.Configuration.GetConnectionString("ConnectionSqlite");
SqlSugarClient client = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = builder.Configuration.GetConnectionString("ConnectionSqlite"),
DbType = DbType.Sqlite,
InitKeyType = InitKeyType.Attribute,
});
//支持sql语句的输出方便排除错误
client.Aop.OnLogExecuting = (sql, par) =>
{
Console.WriteLine("\r\n");
Console.WriteLine($"Sql语句:{sql}");
Console.WriteLine($"======================================================================");
};
return client;
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:37391",
"sslPort": 44354
}
},
"profiles": {
"Txgy.RBS.Server.WebApi": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7117;http://localhost:5094",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -0,0 +1,46 @@
using Microsoft.IdentityModel.Tokens;
using System.Text;
namespace Txgy.RBS.Server.WebApi.Register
{
/// <summary>
///
/// </summary>
public static class AuthorizationExtend
{
/// <summary>
/// 支持授权的扩展方法
/// </summary>
/// <param name="builder"></param>
public static void AuthorizationExt(this WebApplicationBuilder builder)
{
//JWTTokenOptions tokenOptions = new JWTTokenOptions();
//builder.Configuration.Bind("JWTTokenOptions", tokenOptions);
//builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)//Scheme
//.AddJwtBearer(options => //这里是配置的鉴权的逻辑
//{
// options.TokenValidationParameters = new TokenValidationParameters
// {
// //JWT有一些默认的属性就是给鉴权时就可以筛选了
// ValidateIssuer = true,//是否验证Issuer
// ValidateAudience = true,//是否验证Audience
// ValidateLifetime = true,//是否验证失效时间
// ValidateIssuerSigningKey = true,//是否验证SecurityKey
// ValidAudience = tokenOptions.Audience,//
// ValidIssuer = tokenOptions.Issuer,//Issuer这两项和前面签发jwt的设置一致
// IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenOptions.SecurityKey)),
// AudienceValidator = (m, n, z) => //可以添加一些自定义的动作
// {
// return true;
// },
// LifetimeValidator = (notBefore, expires, securityToken, validationParameters) =>
// {
// return true;
// }
// };
//});
}
}
}

@ -0,0 +1,73 @@
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Reflection;
namespace Txgy.RBS.Server.WebApi.Register
{
public static class HostBuilderExtend
{
public static void Register(this WebApplicationBuilder applicationBuilder)
{
//替换容器Autofac
applicationBuilder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
applicationBuilder.Host.ConfigureContainer<ContainerBuilder>(ConfigurationBinder =>
{
//ConfigurationBinder.RegisterType<UserManagerService>().As<IUserManagerService>();
#region 通过接口和实现类所在程序集注册
Assembly interfaceAssembly = Assembly.Load("Txgy.RBS.Services");
Assembly serviceAssembly = Assembly.Load("Txgy.RBS.IServices");
ConfigurationBinder.RegisterAssemblyTypes(interfaceAssembly, serviceAssembly).AsImplementedInterfaces();
#endregion
#region 注册每个控制器和抽象之间的关系
var controllerBaseType = typeof(ControllerBase);
ConfigurationBinder.RegisterAssemblyTypes(typeof(Program).Assembly)
.Where(t => controllerBaseType.IsAssignableFrom(t) && t != controllerBaseType);
#endregion
#region 注册SqlSugar
ConfigurationBinder.Register<ISqlSugarClient>(context =>
{
SqlSugarClient client = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = applicationBuilder.Configuration.GetConnectionString("ConnectionSqlite"), // "Data Source=DESKTOP-T2D6ILD;Initial Catalog=LiveBackgroundManagementNew;Persist Security Info=True;User ID=sa;Password=sa123",
DbType = DbType.Sqlite,
InitKeyType = InitKeyType.Attribute,
//SlaveConnectionConfigs = new List<SlaveConnectionConfig> {
// new SlaveConnectionConfig(){
// ConnectionString="Data Source=DESKTOP-T2D6ILD;Initial Catalog=LiveBackgroundManagementNew;Persist Security Info=True;User ID=sa;Password=sa123",
// HitRate=10
// }
// }
});
//支持sql语句的输出方便排除错误
client.Aop.OnLogExecuting = (sql, par) =>
{
Console.WriteLine("\r\n");
Console.WriteLine($"Sql语句:{sql}");
Console.WriteLine($"=========================================================================================================================================================================================================");
};
return client;
});
#endregion
#region 注册Redis
//{
// ConfigurationBinder.RegisterType<RedisHashService>();
// ConfigurationBinder.RegisterType<RedisListService>();
// ConfigurationBinder.RegisterType<RedisSetService>();
// ConfigurationBinder.RegisterType<RedisStringService>();
// ConfigurationBinder.RegisterType<RedisZSetService>();
//}
#endregion
});
}
}
}

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="7.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.148" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Txgy.RBS.IServices\Txgy.RBS.IServices.csproj" />
<ProjectReference Include="..\Txgy.RBS.Services\Txgy.RBS.Services.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="rbs_server_db.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

@ -0,0 +1,13 @@
namespace Txgy.RBS.Server.WebApi
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"ConnectionSqlServer": "Server=localhost;Database=rbs_server_db.db;Trusted_Connection=True;",
"ConnectionSqlite": "Data Source=rbs_server_db.db",
"ConnectionType": "0"
},
"AllowedHosts": "*"
}

@ -0,0 +1,157 @@
using SqlSugar;
using System.Linq.Expressions;
using Txgy.RBS.Framework;
using Txgy.RBS.IServices;
namespace Txgy.RBS.Services
{
public class BaseService : IBaseService
{
protected ISqlSugarClient _Client { get; set; }
/// <summary>
/// 构造函数
/// </summary>
/// <param name="context"></param>
public BaseService(ISqlSugarClient client)
{
_Client = client;
}
#region Query
public T Find<T>(int id) where T : class
{
return _Client.Queryable<T>().InSingle(id);
}
/// <summary>
/// 不应该暴露给上端使用者,尽量少用
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
[Obsolete("尽量避免使用using 带表达式目录树的代替")]
public ISugarQueryable<T> Set<T>() where T : class
{
return _Client.Queryable<T>();
}
/// <summary>
/// 这才是合理的做法,上端给条件,这里查询
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="funcWhere"></param>
/// <returns></returns>
public ISugarQueryable<T> Query<T>(Expression<Func<T, bool>> funcWhere) where T : class
{
return _Client.Queryable<T>().Where(funcWhere);
}
public PagingData<T> QueryPage<T>(Expression<Func<T, bool>> funcWhere, int pageSize, int pageIndex, Expression<Func<T, object>> funcOrderby, bool isAsc = true) where T : class
{
var list = _Client.Queryable<T>();
if (funcWhere != null)
{
list = list.Where(funcWhere);
}
list = list.OrderByIF(true, funcOrderby, isAsc ? OrderByType.Asc : OrderByType.Desc);
PagingData<T> result = new PagingData<T>()
{
DataList = list.ToPageList(pageIndex, pageSize),
PageIndex = pageIndex,
PageSize = pageSize,
RecordCount = list.Count(),
};
return result;
}
#endregion
#region Insert
/// <summary>
/// 即使保存 不需要再Commit
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
/// <returns></returns>
public T Insert<T>(T t) where T : class, new()
{
_Client.Insertable(t).ExecuteCommand();
return t;
}
public IEnumerable<T> Insert<T>(List<T> tList) where T : class, new()
{
_Client.Insertable(tList.ToList()).ExecuteCommand();
return tList;
}
#endregion
#region Update
/// <summary>
/// 是没有实现查询,直接更新的,需要Attach和State
///
/// 如果是已经在context只能再封装一个(在具体的service)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
public void Update<T>(T t) where T : class, new()
{
if (t == null) throw new Exception("t is null");
_Client.Updateable(t).ExecuteCommand();
}
public void Update<T>(List<T> tList) where T : class, new()
{
_Client.Updateable(tList).ExecuteCommand();
}
#endregion
#region Delete
/// <summary>
/// 先附加 再删除
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
public void Delete<T>(T t) where T : class, new()
{
_Client.Deleteable(t).ExecuteCommand();
}
/// <summary>
/// 还可以增加非即时commit版本的
/// 做成protected
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Id"></param>
public void Delete<T>(int Id) where T : class, new()
{
T t = _Client.Queryable<T>().InSingle(Id);
_Client.Deleteable(t).ExecuteCommand();
}
public void Delete<T>(List<T> tList) where T : class
{
_Client.Deleteable(tList).ExecuteCommand();
}
#endregion
#region Other
ISugarQueryable<T> IBaseService.ExcuteQuery<T>(string sql) where T : class
{
return _Client.SqlQueryable<T>(sql);
}
public void Dispose()
{
if (_Client != null)
{
_Client.Dispose();
}
}
#endregion
}
}

@ -0,0 +1,43 @@
using SqlSugar;
using System.Data;
using Txgy.RBS.DbModel;
using Txgy.RBS.IServices;
namespace Txgy.RBS.Services
{
//sqlite数据库操作
public class DataAccessService : BaseService, IDataAccessService
{
public DataAccessService(ISqlSugarClient sqlSugarClient) : base(sqlSugarClient)
{
}
public List<string> GetIcons()
{
var data = _Client.Queryable<Result>().ToList();
return null;
}
public Setting GetClientType(int userId = 1)
{
return new Setting();
}
public void UpdateClientDetail(double createTime, int mailRule, string mailbox, string appMessage)
{
}
public string GetDevices(int roadId)
{
return string.Empty;
}
public void UpdateDeviceType(int currentDevice)
{
}
}
}

@ -0,0 +1,14 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using Txgy.RBS.IServices;
namespace Txgy.RBS.Services
{
public class LoginService : BaseService, ILoginService
{
public LoginService(ISqlSugarClient sqlSugarClient) : base(sqlSugarClient) { }
}
}

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.148" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Txgy.RBS.IServices\Txgy.RBS.IServices.csproj" />
</ItemGroup>
</Project>
Loading…
Cancel
Save