leiy пре 2 година
родитељ
комит
d390efa210
24 измењених фајлова са 690 додато и 282 уклоњено
  1. 164 23
      OASystem/OASystem.Api/Controllers/SystemController.cs
  2. 4 1
      OASystem/OASystem.Api/GlobalUsings.cs
  3. 2 0
      OASystem/OASystem.Api/OASystem.API.csproj
  4. 0 10
      OASystem/OASystem.Api/Program.cs
  5. 0 8
      OASystem/OASystem.Api/appsettings.json
  6. 3 2
      OASystem/OASystem.Domain/AutoMappers/_baseMappingProfile.cs
  7. 130 0
      OASystem/OASystem.Domain/Dtos/System/CompanyDto.cs
  8. 1 1
      OASystem/OASystem.Domain/Dtos/System/DepartmentDto.cs
  9. 1 1
      OASystem/OASystem.Domain/Entities/EntityBase.cs
  10. 1 0
      OASystem/OASystem.Domain/Entities/System/Sys_Company.cs
  11. 10 3
      OASystem/OASystem.Domain/ViewModels/CompanyView.cs
  12. 9 2
      OASystem/OASystem.Domain/ViewModels/System/DepartmentView.cs
  13. 9 62
      OASystem/OASystem.Domain/ViewModels/System/UserInfoView.cs
  14. 1 0
      OASystem/OASystem.Infrastructure/GlobalUsings.cs
  15. 1 1
      OASystem/OASystem.Infrastructure/Repositories/System/DepartmentRepository.cs
  16. 0 74
      OASystem/OASystem.Infrastructure/Tools/RedisHelper.cs
  17. 2 2
      OASystem/OASystem.RedisRepository/Config/RedisConnection.cs
  18. 88 91
      OASystem/OASystem.RedisRepository/RedisAsyncHelper/IRedisHelper.cs
  19. 93 0
      OASystem/OASystem.RedisRepository/RedisAsyncHelper/RedisHashHelperAsync.cs
  20. 31 0
      OASystem/OASystem.RedisRepository/RedisAsyncHelper/RedisKeyHelperAsync.cs
  21. 99 0
      OASystem/OASystem.RedisRepository/RedisAsyncHelper/RedisListHelperAsync.cs
  22. 19 0
      OASystem/OASystem.RedisRepository/RedisAsyncHelper/RedisSetHelper.cs
  23. 1 1
      OASystem/OASystem.RedisRepository/RedisAsyncHelper/RedisStringHelperAsync.cs
  24. 21 0
      OASystem/OASystem.RedisRepository/RedisFactory.cs

+ 164 - 23
OASystem/OASystem.Api/Controllers/SystemController.cs

@@ -1,10 +1,6 @@
 
-using MySqlX.XDevAPI.Common;
-using OASystem.Domain.Dtos.System;
-using OASystem.Domain.Entities.System;
-using OASystem.Domain.ViewModels.System;
-using OASystem.Infrastructure.Repositories.Login;
-using OASystem.Infrastructure.Repositories.System;
+
+
 
 namespace OASystem.API.Controllers
 {
@@ -15,6 +11,7 @@ namespace OASystem.API.Controllers
     [Route("api/[controller]/[action]")]
     public class SystemController : ControllerBase
     {
+      
         private readonly CompanyRepository _syscomRep;
         private readonly DepartmentRepository _sysDepRep;
         private readonly UsersRepository _userRep;
@@ -30,9 +27,13 @@ namespace OASystem.API.Controllers
         }
 
         #region user 操作
-
+        /// <summary>
+        /// 查询所有员工(web)
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
         [HttpPost]
-        [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> GetUserList(DtoBase dto)
         {
             try
@@ -55,46 +56,181 @@ namespace OASystem.API.Controllers
         #endregion
 
         #region 企业操作
-        [HttpGet]
-        [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> getCompanyList()
+        /// <summary>
+        /// 查询企业数据
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> getCompanyList(DtoBase dto)
         {
             try
             {
-                //var companyList = _sysDepRep.QueryDto<Sys_Company, CompanyView>(c=>c.IsDel!=null).ToList();
-                string sqlWhere = "select * from Sys_Company";
-                var companyList = _syscomRep.GetListBySqlWithNolock(sqlWhere);
-                List<CompanyView> DataList = _mapper.Map<List<CompanyView>>(companyList);
-                if (DataList.Count == 0)
+                if (dto.PortType == 1)
+                {
+                    return Ok(JsonView(false, "暂无数据!"));
+                }
+                else if (dto.PortType == 2)
+                {
+                    var companyList = _sysDepRep.QueryDto<Sys_Company, CompanyView>(a=>a.ToBool(true)).ToList();
+                    if (companyList.Count == 0)
+                    {
+                        return Ok(JsonView(false, "暂无数据!"));
+                    }
+                    return Ok(JsonView(companyList));
+                }
+                else if (dto.PortType == 3)
+                {
+                    return Ok(JsonView(false, "暂无数据!"));
+                }
+                else
                 {
                     return Ok(JsonView(false, "暂无数据!"));
                 }
-                return Ok(JsonView(DataList));
             }
             catch (Exception ex)
             {
                 return Ok(JsonView(false, "程序错误!"));
                 throw;
             }
+        }
+
+        /// <summary>
+        /// 添加企业数据
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView),StatusCodes.Status200OK)]
+        public async Task<IActionResult> AddCompany(AddCompanyDto dto)
+        {
+            if (string.IsNullOrWhiteSpace(dto.CompanyName) || dto.CreateUserId==0 || !string.IsNullOrWhiteSpace(dto.CompanyCode))
+            {
+                return Ok(JsonView(-1, "请检查信息是否输入完整!", null));
+            }
+            else if (string.IsNullOrWhiteSpace(dto.Tel))
+            {
+                return Ok(JsonView(-1, "请检查联系方式是否输入正确!", null));
+            }
+            else
+            {
+                Sys_Company _Company = _mapper.Map<Sys_Company>(dto);
+                int id = await _syscomRep.AddAsyncReturnId(_Company);
+                if (id == 0)
+                {
+                    return Ok(JsonView(-1, "添加失败!", null));
+
+                }
+                return Ok(JsonView(0, "成功", id));
+            }
+            
+        }
+
+        /// <summary>
+        /// 企业修改
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult>EditCompany(EditCompanyDto dto)
+        {
+            try
+            {
+                if (string.IsNullOrWhiteSpace(dto.CompanyName) || string.IsNullOrWhiteSpace(dto.CompanyCode) || string.IsNullOrWhiteSpace(dto.Address) || dto.ParentCompanyId == 0 || dto.ContactUserId == 0)
+                {
+                    return Ok(JsonView(-1, "请检查信息是否输入完整!", null));
+                }
+                else if (string.IsNullOrWhiteSpace(dto.Tel))
+                {
+                    return Ok(JsonView(-1, "请检查联系方式是否输入正确!", null));
+                }
+                else
+                {
+                    bool res = await _syscomRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Company
+                    {
+                        CompanyName = dto.CompanyName,
+                        CompanyCode = dto.CompanyCode,
+                        Address = dto.Address,
+                        ParentCompanyId = dto.ParentCompanyId,
+                        Tel = dto.Tel,
+                        ContactUserId = dto.ContactUserId,
+                    });
+                    if (!res) { return Ok(JsonView(-1, "失败", null)); }
+                    return Ok(JsonView(0, "成功", null));
+                }
+            }
+            catch (Exception)
+            {
+                return Ok(JsonView(false, "程序错误!"));
+                throw;
+            }
+            
+            
+        }
+
+         /// <summary>
+        /// 企业删除
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> DelCompany(DelCompanyDto dto)
+        {
+            try
+            {
+                bool res = await _syscomRep.SoftDeleteAsync<Sys_Company>(dto.Id.ToString());
+                if (!res) { return Ok(JsonView(-1, "失败", null)); }
+                return Ok(JsonView(0, "成功", null));
+            }
+            catch (Exception)
+            {
+                return Ok(JsonView(false, "程序错误!"));
+                throw;
+            }
+           
+            
+
         }
         #endregion
 
         #region 部门操作
 
-       
+        /// <summary>
+        /// 查询部门数据
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
         //[Authorize]
         [HttpPost]
-        [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> QueryDepartmentList(DepartmentDto dto)
         {
             try
             {
-                var result = _sysDepRep.QueryDto<Sys_Department, DepartmentView>(s => s.CompanyId == dto.CompanyId).ToList();
-                if (result.Count==0)
+                if (dto.PortType==1)
+                {
+                    return Ok(JsonView(false, "暂无数据!"));
+                }
+                else if (dto.PortType==2)
+                {
+                    var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
+                    if (result.Count == 0)
+                    {
+                        return Ok(JsonView(false, "暂无数据!"));
+                    }
+                    return Ok(JsonView(result));
+                }
+                else if (dto.PortType == 3)
+                {
+                    return Ok(JsonView(false, "暂无数据!"));
+                }
+                else
                 {
                     return Ok(JsonView(false, "暂无数据!"));
                 }
-                return Ok(JsonView(result));
             }
             catch (Exception ex)
             {
@@ -106,8 +242,13 @@ namespace OASystem.API.Controllers
         #endregion
 
         #region 用户操作
+        /// <summary>
+        /// 查询用户数据
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
         [HttpPost]
-        [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> QueryUserList(UserDto dto)
         {
             try

+ 4 - 1
OASystem/OASystem.Api/GlobalUsings.cs

@@ -47,6 +47,9 @@ global using System;
 global using System.Collections.Generic;
 global using System.Linq;
 global using OASystem.Domain;
-
+global using OASystem.Domain.Dtos.System;
+global using OASystem.Domain.Entities.System;
+global using OASystem.Domain.ViewModels.System;
+global using OASystem.Infrastructure.Repositories.System;
 
 

+ 2 - 0
OASystem/OASystem.Api/OASystem.API.csproj

@@ -5,6 +5,7 @@
     <Nullable>enable</Nullable>
     <ImplicitUsings>enable</ImplicitUsings>
     <GenerateDocumentationFile>True</GenerateDocumentationFile>
+<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
   </PropertyGroup>
 
   <ItemGroup>
@@ -36,6 +37,7 @@
   <ItemGroup>
     <ProjectReference Include="..\OASystem.Domain\OASystem.Domain.csproj" />
     <ProjectReference Include="..\OASystem.Infrastructure\OASystem.Infrastructure.csproj" />
+    <ProjectReference Include="..\OASystem.RedisRepository\OASystem.RedisRepository.csproj" />
   </ItemGroup>
 
   <ProjectExtensions><VisualStudio><UserProperties properties_4launchsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>

+ 0 - 10
OASystem/OASystem.Api/Program.cs

@@ -16,16 +16,6 @@ builder.Services.AddControllersWithViews();
 
 #region redis
 
-//redis缓存
-var section = builder.Configuration.GetSection("Redis:Default");
-//连接字符串
-string _connectionString = section.GetSection("Connection").Value;
-//实例名称
-string _instanceName = section.GetSection("InstanceName").Value;
-//默认数据库 
-int _defaultDB = int.Parse(section.GetSection("DefaultDB").Value ?? "0");
-builder.Services.AddSingleton(new RedisHelper(_connectionString+",password=123456", _instanceName, _defaultDB));
-
 #endregion
 
 

+ 0 - 8
OASystem/OASystem.Api/appsettings.json

@@ -4,13 +4,5 @@
   },
   "JwtSecurityKey": "48d3f4fe770940a1068052f581536b81", //jwt密钥
   "UseSwagger": "true", //启用Swagger
-  "Redis": {
-    "Default": {
-      "Connection": "132.232.92.186:6379", //redis连接地址,端口号,密码
-      "InstanceName": "local", //实例名
-      "DefaultDB": "0" //Db8数据库
-    }
-  }
-  ,"RedisServer": "11"
 
 }

+ 3 - 2
OASystem/OASystem.Domain/AutoMappers/_baseMappingProfile.cs

@@ -18,11 +18,12 @@ namespace OASystem.Domain.AutoMappers
 
             #region 公司板块
             CreateMap<Sys_Company, CompanyView>();
+            CreateMap<AddCompanyDto, Sys_Company>();
+            CreateMap<EditCompanyDto, Sys_Company>();
             #endregion
 
             #region 部门板块
-            CreateMap<DepartmentDto, Sys_Department>();
-            CreateMap<Sys_Department, DepartmentView>();
+            CreateMap<Sys_Department, DepartmentIView>();
             #endregion
 
             #region 用户板块

+ 130 - 0
OASystem/OASystem.Domain/Dtos/System/CompanyDto.cs

@@ -0,0 +1,130 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.System
+{
+    /// <summary>
+    /// 企业添加Dto
+    /// </summary>
+    public class AddCompanyDto
+    {
+        /// <summary>
+        /// 公司Code
+        /// </summary>
+        public string CompanyCode { get; set; }
+        /// <summary>
+        /// 公司名称
+        /// </summary>
+        public string CompanyName { get; set; }
+
+        /// <summary>
+        /// 公司所在地
+        /// </summary>
+        public string Address { get; set; }
+        /// <summary>
+        /// 负责人Id
+        /// </summary>
+        public int ContactUserId { get; set; }
+        /// <summary>
+        /// 联系方式
+        /// </summary>
+        private string tel;
+        public string Tel
+        {
+            get
+            {
+                return tel;
+            }
+            set
+            {
+                if (Regex.IsMatch(value, @"^[1]+[2,3,4,5,6,7,8,9]+\d{9}"))
+                {
+                    tel = value;
+                }
+                else
+                {
+                    tel = "";
+                }
+               
+            }
+        }
+        /// <summary>
+        /// 父级公司Id
+        /// </summary>
+        public int ParentCompanyId { get; set; }
+
+        /// <summary>
+        /// 创建者Id
+        /// </summary>
+
+        public int CreateUserId { get; set; }
+    }
+
+    /// <summary>
+    /// 修改企业dto
+    /// </summary>
+    public class EditCompanyDto
+    {
+        /// <summary>
+        /// 公司Id
+        /// </summary>
+        public int Id { get; set; }
+        /// <summary>
+        /// 公司Code
+        /// </summary>
+        public string CompanyCode { get; set; }
+        /// <summary>
+        /// 公司名称
+        /// </summary>
+        public string CompanyName { get; set; }
+
+        /// <summary>
+        /// 公司所在地
+        /// </summary>
+        public string Address { get; set; }
+        /// <summary>
+        /// 负责人Id
+        /// </summary>
+        public int ContactUserId { get; set; }
+        /// <summary>
+        /// 联系方式
+        /// </summary>
+        private string tel;
+        public string Tel
+        {
+            get
+            {
+                return tel;
+            }
+            set
+            {
+                if (Regex.IsMatch(value, @"^[1]+[2,3,4,5,6,7,8,9]+\d{9}"))
+                {
+                    tel = value;
+                }
+                else
+                {
+                    tel = "";
+                }
+
+            }
+        }
+        /// <summary>
+        /// 父级公司Id
+        /// </summary>
+        public int ParentCompanyId { get; set; }
+
+    }
+
+    /// <summary>
+    /// 删除企业dto
+    /// </summary>
+    public class DelCompanyDto
+    {
+        public int Id { get; set; }
+    }
+}

+ 1 - 1
OASystem/OASystem.Domain/Dtos/System/DepartmentDto.cs

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 
 namespace OASystem.Domain.Dtos.System
 {
-    public class DepartmentDto
+    public class DepartmentDto:DtoBase
     {
         /// <summary>
         /// 公司Id

+ 1 - 1
OASystem/OASystem.Domain/Entities/EntityBase.cs

@@ -8,7 +8,7 @@
         /// <summary>
         /// 编号
         /// </summary>
-        [SugarColumn(ColumnDescription = "主键", IsPrimaryKey = true, /*IsIdentity = true,*/ IsNullable = false)]
+        [SugarColumn(ColumnDescription = "主键", IsPrimaryKey = true, IsIdentity = true, IsNullable = false)]
         public int Id { get; set; }
         /// <summary>
         /// 创建者Id

+ 1 - 0
OASystem/OASystem.Domain/Entities/System/Sys_Company.cs

@@ -39,4 +39,5 @@
         public int ParentCompanyId { get; set; }
     }
 
+    
 }

+ 10 - 3
OASystem/OASystem.Domain/ViewModels/CompanyView.cs

@@ -8,10 +8,17 @@ using System.Threading.Tasks;
 namespace OASystem.Domain.ViewModels
 {
     /// <summary>
-    /// 公司视图表(返回数据model)
+    /// 公司视图表(返回数据model)安卓端
     /// </summary>
-    public class CompanyView:Sys_Company
+    public class CompanyView
     {
-        
+        /// <summary>
+        /// 公司Id
+        /// </summary>
+        public int Id { get; set; }
+        /// <summary>
+        /// 公司名称
+        /// </summary>
+        public string CompanyName { get; set; }
     }
 }

+ 9 - 2
OASystem/OASystem.Domain/ViewModels/System/DepartmentView.cs

@@ -7,8 +7,15 @@ using System.Threading.Tasks;
 
 namespace OASystem.Domain.ViewModels.System
 {
-    public class DepartmentView:Sys_Department
+    public class DepartmentIView
     {
-       
+        /// <summary>
+        /// 用户Id
+        /// </summary>
+        public int Id { get; set; }
+        /// <summary>
+        /// 部门名称
+        /// </summary>
+        public string DepName { get; set; }
     }
 }

+ 9 - 62
OASystem/OASystem.Domain/ViewModels/System/UserInfoView.cs

@@ -14,16 +14,21 @@ namespace OASystem.Domain.ViewModels.System
     /// </summary>
     public class UserView
     {
+
         /// <summary>
-        /// 公司名称
+        /// 部门Id
         /// </summary>
-        public string CompanyName { get; set; }
 
+        public int DepId { get; set; }
+       
         /// <summary>
         /// 部门名称
         /// </summary>
         public string DepName { get; set; }
-
+        /// <summary>
+        /// 岗位Id
+        /// </summary>
+        public int JobPostId { get; set; }
         /// <summary>
         /// 岗位名称
         /// </summary>
@@ -37,43 +42,13 @@ namespace OASystem.Domain.ViewModels.System
         /// </summary>
         
         public string CnName { get; set; }
-        /// <summary>
-        /// 英文姓名
-        /// </summary>
-        
-        public string EnName { get; set; }
+       
         /// <summary>
         /// 工号
         /// </summary>
         
         public string Number { get; set; }
         /// <summary>
-        /// 公司Id
-        /// </summary>
-       
-        public int CompanyId { get; set; }
-        /// <summary>
-        /// 部门Id
-        /// </summary>
-        
-        public int DepId { get; set; }
-        /// <summary>
-        /// 岗位Id
-        /// </summary>
-        
-        public int JobPostId { get; set; }
-        
-        /// <summary>
-        /// 性别0 男1 女  2 未设置
-        /// </summary>
-        
-        public int Sex { get; set; }
-        /// <summary>
-        /// 分机号
-        /// </summary>
-        
-        public string Ext { get; set; }
-        /// <summary>
         /// 手机号
         /// </summary>
         
@@ -88,34 +63,6 @@ namespace OASystem.Domain.ViewModels.System
         /// </summary>
         
         public string Email { get; set; }
-        /// <summary>
-        /// 住址
-        /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(200)")]
-        public string Address { get; set; }
-        /// <summary>
-        /// 入职时间
-        /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "DateTime")]
-        public DateTime Edate { get; set; }
-        /// <summary>
-        /// 离职时间
-        /// </summary>
-        [SugarColumn(IsNullable = true, ColumnDataType = "DateTime")]
-        public DateTime Rdate { get; set; }
-        
-       
-        /// <summary>
-        /// 身份证号码
-        /// </summary>
-        public string IDCard { get; set; }
-        
-        
-        /// <summary>
-        /// 家庭地址
-        /// </summary>
-        public string HomeAddress { get; set; }
-        
     }
 
     /// <summary>

+ 1 - 0
OASystem/OASystem.Infrastructure/GlobalUsings.cs

@@ -10,3 +10,4 @@ global using System.Text.Json;
 global using Microsoft.AspNetCore.Http;
 global using System.Text.RegularExpressions;
 global using OASystem.Domain.Entities.System;
+global using OASystem.Domain.ViewModels.System;

+ 1 - 1
OASystem/OASystem.Infrastructure/Repositories/System/DepartmentRepository.cs

@@ -9,7 +9,7 @@ using System.Threading.Tasks;
 
 namespace OASystem.Infrastructure.Repositories.System
 {
-    public class DepartmentRepository : BaseRepository<Sys_Department, DepartmentView>
+    public class DepartmentRepository : BaseRepository<Sys_Department, DepartmentIView>
     {
         public DepartmentRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
         {

+ 0 - 74
OASystem/OASystem.Infrastructure/Tools/RedisHelper.cs

@@ -1,74 +0,0 @@
-
-using Newtonsoft.Json;
-using StackExchange.Redis;
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-
-namespace OASystem.Infrastructure.Tools
-{
-
-    public class RedisHelper : IDisposable
-    {
-        //连接字符串
-        private string _connectionString;
-        //实例名称
-        private string _instanceName;
-        //默认数据库
-        private int _defaultDB;
-
-        private ConcurrentDictionary<string, ConnectionMultiplexer> _connections;
-        public RedisHelper(string connectionString, string instanceName, int defaultDB = 0)
-        {
-            _connectionString = connectionString;
-            _instanceName = instanceName;
-            _defaultDB = defaultDB;
-            _connections = new ConcurrentDictionary<string, ConnectionMultiplexer>();
-        }
-
-        /// <summary>
-        /// 获取ConnectionMultiplexer
-        /// </summary>
-        /// <returns></returns>
-        private ConnectionMultiplexer GetConnect()
-        {
-            return _connections.GetOrAdd(_instanceName, p => ConnectionMultiplexer.Connect(_connectionString));
-        }
-
-        /// <summary>
-        /// 获取数据库
-        /// </summary>
-        /// <param name="configName"></param>
-        /// <param name="db">默认为0:优先代码的db配置,其次config中的配置</param>
-        /// <returns></returns>
-        public IDatabase GetDatabase(RedisEnum redisEnum)
-        {
-            return GetConnect().GetDatabase((int)redisEnum);
-        }
-
-        public IServer GetServer(string configName = null, int endPointsIndex = 0)
-        {
-            var confOption = ConfigurationOptions.Parse(_connectionString);
-            return GetConnect().GetServer(confOption.EndPoints[endPointsIndex]);
-        }
-
-        public ISubscriber GetSubscriber(string configName = null)
-        {
-            return GetConnect().GetSubscriber();
-        }
-        public void Dispose()
-        {
-            if (_connections != null && _connections.Count > 0)
-            {
-                foreach (var item in _connections.Values)
-                {
-                    item.Close();
-                }
-            }
-        }
-    }
-}

+ 2 - 2
OASystem/OASystem.RedisRepository/Config/RedisConnection.cs

@@ -27,8 +27,8 @@ namespace OASystem.RedisRepository.Config
                             Password = RedisClientConfig.RedisAuth,
                             EndPoints =
                             {
-                                {RedisClientConfig.Server, RedisClientConfig.Port},
-                                {RedisClientConfig.SlaveServer, RedisClientConfig.SlavePort}
+                                {RedisClientConfig.Server, RedisClientConfig.Port}
+                                //,{RedisClientConfig.SlaveServer, RedisClientConfig.SlavePort}
                             }
                         };
                         _connection = ConnectionMultiplexer.Connect(configurationOptions);

+ 88 - 91
OASystem/OASystem.RedisRepository/RedisAsyncHelper/IRedisHelper.cs

@@ -313,92 +313,92 @@ namespace OASystem.RedisRepository.RedisAsyncHelper
         /// <returns></returns>
         Task<long> SetCombineAndStoreAsync(SetOperation operation, string destKey, List<string> combineKeys);
 
-        /// <summary>
-        /// 指定集合计算操作operation枚举,指定需要参与计算的多个key
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="operation"></param>
-        /// <param name="combineKeys"></param>
-        /// <returns></returns>
-        Task<List<T>> SetCombineAsync<T>(SetOperation operation, List<string> combineKeys);
-
-        /// <summary>
-        /// 指定值是否存在于指定集合中
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="key"></param>
-        /// <param name="value"></param>
-        /// <returns></returns>
-        Task<bool> SetContainsAsync<T>(string key, T value);
-
-        /// <summary>
-        /// 获取指定集合中元素个数
-        /// </summary>
-        /// <param name="key"></param>
-        /// <returns></returns>
-        Task<long> SetLengthAsync(string key);
-
-        /// <summary>
-        /// 获取指定集合中的所有元素
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="key"></param>
-        /// <param name="value"></param>
-        /// <returns></returns>
-        Task<List<T>> SetMembersAsync<T>(string key, T value);
-
-        /// <summary>
-        /// 从sourceKey移除指定value到目标distKey集合当中
-        /// 如果sourceKey存在指定value则返回true,否则不做任何操作返回false
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="sourcekey"></param>
-        /// <param name="distKey"></param>
-        /// <param name="value"></param>
-        /// <returns></returns>
-        Task<bool> SetMoveAsync<T>(string sourcekey, string distKey, T value);
-
-        /// <summary>
-        /// 从指定集合当中随机取出一个元素
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="key"></param>
-        /// <returns></returns>
-        Task<T> SetRandomMemberAsync<T>(string key);
-
-        /// <summary>
-        /// 从指定集合随机弹出(删除并获取)一个元素
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="key"></param>
-        /// <returns></returns>
-        Task<T> SetPopAsync<T>(string key);
-
-        /// <summary>
-        /// 从集合中随机弹出(删除并获取)多个元素
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="key"></param>
-        /// <returns></returns>
-        Task<List<T>> SetRandomMembersAsync<T>(string key);
-
-        /// <summary>
-        /// 从集合中移除指定元素
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="key"></param>
-        /// <param name="value"></param>
-        /// <returns></returns>
-        Task<bool> SetRemoveAsync<T>(string key, T value);
-
-        /// <summary>
-        /// 从集合中批量移除元素
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="key"></param>
-        /// <param name="values"></param>
-        /// <returns></returns>
-        Task<long> SetMultiRemoveAsync<T>(string key, List<T> values);
+        ///// <summary>
+        ///// 指定集合计算操作operation枚举,指定需要参与计算的多个key
+        ///// </summary>
+        ///// <typeparam name="T"></typeparam>
+        ///// <param name="operation"></param>
+        ///// <param name="combineKeys"></param>
+        ///// <returns></returns>
+        //Task<List<T>> SetCombineAsync<T>(SetOperation operation, List<string> combineKeys);
+
+        ///// <summary>
+        ///// 指定值是否存在于指定集合中
+        ///// </summary>
+        ///// <typeparam name="T"></typeparam>
+        ///// <param name="key"></param>
+        ///// <param name="value"></param>
+        ///// <returns></returns>
+        //Task<bool> SetContainsAsync<T>(string key, T value);
+
+        ///// <summary>
+        ///// 获取指定集合中元素个数
+        ///// </summary>
+        ///// <param name="key"></param>
+        ///// <returns></returns>
+        //Task<long> SetLengthAsync(string key);
+
+        ///// <summary>
+        ///// 获取指定集合中的所有元素
+        ///// </summary>
+        ///// <typeparam name="T"></typeparam>
+        ///// <param name="key"></param>
+        ///// <param name="value"></param>
+        ///// <returns></returns>
+        //Task<List<T>> SetMembersAsync<T>(string key, T value);
+
+        ///// <summary>
+        ///// 从sourceKey移除指定value到目标distKey集合当中
+        ///// 如果sourceKey存在指定value则返回true,否则不做任何操作返回false
+        ///// </summary>
+        ///// <typeparam name="T"></typeparam>
+        ///// <param name="sourcekey"></param>
+        ///// <param name="distKey"></param>
+        ///// <param name="value"></param>
+        ///// <returns></returns>
+        //Task<bool> SetMoveAsync<T>(string sourcekey, string distKey, T value);
+
+        ///// <summary>
+        ///// 从指定集合当中随机取出一个元素
+        ///// </summary>
+        ///// <typeparam name="T"></typeparam>
+        ///// <param name="key"></param>
+        ///// <returns></returns>
+        //Task<T> SetRandomMemberAsync<T>(string key);
+
+        ///// <summary>
+        ///// 从指定集合随机弹出(删除并获取)一个元素
+        ///// </summary>
+        ///// <typeparam name="T"></typeparam>
+        ///// <param name="key"></param>
+        ///// <returns></returns>
+        //Task<T> SetPopAsync<T>(string key);
+
+        ///// <summary>
+        ///// 从集合中随机弹出(删除并获取)多个元素
+        ///// </summary>
+        ///// <typeparam name="T"></typeparam>
+        ///// <param name="key"></param>
+        ///// <returns></returns>
+        //Task<List<T>> SetRandomMembersAsync<T>(string key);
+
+        ///// <summary>
+        ///// 从集合中移除指定元素
+        ///// </summary>
+        ///// <typeparam name="T"></typeparam>
+        ///// <param name="key"></param>
+        ///// <param name="value"></param>
+        ///// <returns></returns>
+        //Task<bool> SetRemoveAsync<T>(string key, T value);
+
+        ///// <summary>
+        ///// 从集合中批量移除元素
+        ///// </summary>
+        ///// <typeparam name="T"></typeparam>
+        ///// <param name="key"></param>
+        ///// <param name="values"></param>
+        ///// <returns></returns>
+        //Task<long> SetMultiRemoveAsync<T>(string key, List<T> values);
 
         #endregion
 
@@ -423,7 +423,7 @@ namespace OASystem.RedisRepository.RedisAsyncHelper
         /// <param name="key"></param>
         /// <param name="expireAt"></param>
         /// <returns></returns>
-        Task<bool> KeyExpireAtAsync(string key, DateTime expireAt);
+        //Task<bool> KeyExpireAtAsync(string key, DateTime expireAt);
 
         /// <summary>
         /// 设置key在将来的timeout后过期(TimeSpan)
@@ -457,12 +457,9 @@ namespace OASystem.RedisRepository.RedisAsyncHelper
         /// </summary>
         /// <param name="ranOperations"></param>
         /// <returns></returns>
-        Task<bool> DoInTranscationAsync(Action<ITransaction> ranOperations);
+        //Task<bool> DoInTranscationAsync(Action<ITransaction> ranOperations);
 
         #endregion
 
-
-
-        Task<RedisResult> Test();
     }
 }

+ 93 - 0
OASystem/OASystem.RedisRepository/RedisAsyncHelper/RedisHashHelperAsync.cs

@@ -0,0 +1,93 @@
+using OASystem.RedisRepository.CommonHelper;
+using StackExchange.Redis;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.RedisRepository.RedisAsyncHelper
+{
+    /// <summary>
+    ///  Redis异步操作类  Hash部分类
+    /// </summary>
+    internal partial class RedisHelper //: IRedisHelper
+    {
+        #region Hash 写操作
+
+        public async Task<bool> HashSetAsync<T>(string key, string field, T value)
+        {
+            return await _client.HashSetAsync(key, field, SerializeHelper.Serialize(value));
+        }
+
+        public async Task HashMultiSetAsync<T>(string key, Dictionary<string, T> hashFields)
+        {
+            List<HashEntry> entries = new List<HashEntry>();
+            hashFields.ToList().ForEach(d => entries.Add(new HashEntry(d.Key, SerializeHelper.Serialize(d.Value))));
+            await _client.HashSetAsync(key, entries.ToArray());
+        }
+
+        public async Task<long> HashIncrementAsync(string key, string field, long incrCount = 1)
+        {
+            return await _client.HashIncrementAsync(key, field, incrCount);
+        }
+
+        public async Task<long> HashDecrementAsync(string key, string field, long decrCount = 1)
+        {
+            return await _client.HashDecrementAsync(key, field, decrCount);
+        }
+
+        public async Task<bool> HashDeleteFieldAsync(string key, string field)
+        {
+            return await _client.HashDeleteAsync(key, field);
+        }
+
+        public async Task<long> HashMultiDeleteFieldAsync(string key, List<string> fields)
+        {
+            List<RedisValue> values = new List<RedisValue>();
+            fields.ForEach(f => values.Add(f));
+            return await _client.HashDeleteAsync(key, values.ToArray());
+        }
+
+        #endregion
+
+        #region Hash 读操作
+
+        /// <summary>
+        /// Redis 指定hash类型key中field是否存在
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="field"></param>
+        /// <returns></returns>
+        public async Task<bool> HashFieldExistAsync(string key, string field)
+        {
+            return await _client.HashExistsAsync(key, field, CommandFlags.PreferSlave);
+        }
+        public async Task<List<string>> HashFieldsAsync(string key)
+        {
+            RedisValue[] values = await _client.HashKeysAsync(key, CommandFlags.PreferSlave);
+            return RedisInnerTypeHelper.RedisValuesToGenericList<string>(values);
+        }
+        public async Task<List<T>> HashValuesAsync<T>(string key)
+        {
+            var values = await _client.HashValuesAsync(key, CommandFlags.PreferSlave);
+            return RedisInnerTypeHelper.RedisValuesToGenericList<T>(values);
+        }
+
+        public async Task<T> HashGetAsync<T>(string key, string field)
+        {
+            return SerializeHelper.Deserialize<T>(await _client.HashGetAsync(key, field, CommandFlags.PreferSlave));
+        }
+
+        public async Task<Dictionary<string, T>> HashGetAllAsync<T>(string key)
+        {
+            HashEntry[] entries = await _client.HashGetAllAsync(key, CommandFlags.PreferSlave);
+            Dictionary<string, T> dic = new Dictionary<string, T>();
+            entries.ToList().ForEach(e => dic.Add(e.Name, SerializeHelper.Deserialize<T>(e.Value)));
+            return dic;
+        }
+
+        #endregion
+
+    }
+}

+ 31 - 0
OASystem/OASystem.RedisRepository/RedisAsyncHelper/RedisKeyHelperAsync.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.RedisRepository.RedisAsyncHelper
+{
+    internal partial class RedisHelper
+    {
+        public async Task<bool> KeyDeleteAsync(string key)
+        {
+            return await _client.KeyDeleteAsync(key);
+        }
+
+        public async Task<bool> KeyExpireInAsync(string key, TimeSpan timeout)
+        {
+            return await _client.KeyExpireAsync(key, timeout);
+        }
+
+        public async Task<bool> KeyRenameAsync(string key, string newKey)
+        {
+            return await _client.KeyRenameAsync(key, newKey);
+        }
+
+        public async Task<bool> KeyExistsAsync(string key)
+        {
+            return await _client.KeyExistsAsync(key);
+        }
+    }
+}

+ 99 - 0
OASystem/OASystem.RedisRepository/RedisAsyncHelper/RedisListHelperAsync.cs

@@ -0,0 +1,99 @@
+using OASystem.RedisRepository.CommonHelper;
+using StackExchange.Redis;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.RedisRepository.RedisAsyncHelper
+{
+    /// <summary>
+    /// Redis异步操作类  List部分类
+    /// </summary>
+    internal partial class RedisHelper //: IRedisHelper
+    {
+        //    _client.ListRightPopLeftPushAsync();
+        //    _client.ListTrimAsync();
+
+        #region List 写操作
+
+        public async Task<long> ListInsertAfterAsync<T>(string key, string pivot, T value)
+        {
+            return await _client.ListInsertAfterAsync(key, pivot, SerializeHelper.Serialize(value));
+        }
+
+        public async Task<long> ListInsertBeforeAsync<T>(string key, string pivot, T value)
+        {
+            return await _client.ListInsertBeforeAsync(key, pivot, SerializeHelper.Serialize(value));
+        }
+
+        public async Task<T> ListLeftPopAsync<T>(string key)
+        {
+            return SerializeHelper.Deserialize<T>(await _client.ListLeftPopAsync(key));
+        }
+
+        public async Task<long> ListLeftPushAsync<T>(string key, T value)
+        {
+            return await _client.ListLeftPushAsync(key, SerializeHelper.Serialize(value));
+        }
+
+        public async Task<long> ListLeftMultiPushAsync<T>(string key, List<T> values)
+        {
+            return await _client.ListLeftPushAsync(key, SerializeHelper.Serialize(RedisInnerTypeHelper.GenericListToRedisValues(values)));
+        }
+
+        public async Task<long> ListRemoveAsync<T>(string key, T value, long count = 0L)
+        {
+            return await _client.ListRemoveAsync(key, SerializeHelper.Serialize(value), count);
+        }
+
+        public async Task<T> ListRightPopAsync<T>(string key)
+        {
+            return SerializeHelper.Deserialize<T>(await _client.ListRightPopAsync(key));
+        }
+
+        public async Task<long> ListRightPushAsync<T>(string key, T value)
+        {
+            return await _client.ListRightPushAsync(key, SerializeHelper.Serialize(value));
+        }
+
+        public async Task<long> ListRightMultiPushAsync<T>(string key, List<T> values)
+        {
+            return
+                await
+                    _client.ListRightPushAsync(key,
+                        SerializeHelper.Serialize(RedisInnerTypeHelper.GenericListToRedisValues(values)));
+        }
+
+        public async Task ListSetByIndexAsync<T>(string key, int index, T value)
+        {
+            await _client.ListSetByIndexAsync(key, index, SerializeHelper.Serialize(value));
+        }
+
+        public async Task ListTrimAsync(string key, long start, long stop)
+        {
+            await _client.ListTrimAsync(key, start, stop);
+        }
+        #endregion
+
+        #region List 读操作
+
+        public async Task<T> ListGetByIndexAsync<T>(string key, long index)
+        {
+            return SerializeHelper.Deserialize<T>(await _client.ListGetByIndexAsync(key, index, CommandFlags.PreferSlave));
+        }
+
+        public async Task<long> ListLengthAsync<T>(string key)
+        {
+            return await _client.ListLengthAsync(key, CommandFlags.PreferSlave);
+        }
+
+        public async Task<List<T>> ListRangeAsync<T>(string key, long start = 0L, long stop = -1L)
+        {
+            return RedisInnerTypeHelper.RedisValuesToGenericList<T>(await _client.ListRangeAsync(key, start, stop, CommandFlags.PreferSlave));
+        }
+
+        #endregion
+    }
+}

+ 19 - 0
OASystem/OASystem.RedisRepository/RedisAsyncHelper/RedisSetHelper.cs

@@ -0,0 +1,19 @@
+using OASystem.RedisRepository.CommonHelper;
+using StackExchange.Redis;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.RedisRepository.RedisAsyncHelper
+{
+    internal partial class RedisHelper
+    {
+        public async Task<bool> SetAddAsync<T>(string key, T value)
+        {
+            return await _client.SetAddAsync(key, SerializeHelper.Serialize(value));
+        }
+
+    }
+}

+ 1 - 1
OASystem/OASystem.RedisRepository/RedisAsyncHelper/RedisStringHelperAsync.cs

@@ -11,7 +11,7 @@ namespace OASystem.RedisRepository.RedisAsyncHelper
 {/// <summary>
  /// Redis异步操作类  String部分类
  /// </summary>
-    internal partial class RedisHelper// : IRedisHelper
+    internal partial class RedisHelper : IRedisHelper
     {
 
         private static IDatabase _client;

+ 21 - 0
OASystem/OASystem.RedisRepository/RedisFactory.cs

@@ -0,0 +1,21 @@
+using OASystem.RedisRepository.RedisAsyncHelper;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.RedisRepository
+{
+    public class RedisFactory
+    {
+        /// <summary>
+        /// 外部访问redis入口,暂时只暴露异步方法
+        /// </summary>
+        /// <returns></returns>
+        public static IRedisHelper CreateRedisRepository()
+        {
+            return new RedisHelper();
+        }
+    }
+}