Browse Source

解决合并冲突

wangh 2 years ago
parent
commit
e361a88b3b

+ 6 - 3
OASystem/EntitySync/Program.cs

@@ -74,8 +74,11 @@ db.CodeFirst.SetStringDefaultLength(50).BackupTable().InitTables(new Type[]
     //typeof(Res_CarData),
     //typeof(Res_CarData),
     //typeof(Res_LocalGuideData)
     //typeof(Res_LocalGuideData)
 
 
-    typeof(Grp_ScheduleInfo),
-    typeof(Grp_ScheduleDetailInfo),
-    typeof(Grp_SchedulePersonInfo)
+    //typeof(Grp_ScheduleInfo),
+    //typeof(Grp_ScheduleDetailInfo),
+    //typeof(Grp_SchedulePersonInfo)
+
+    //typeof(Sys_Message),
+    //typeof(Sys_MessageReadAuth)
 });
 });
 Console.WriteLine("数据库结构同步完成!");
 Console.WriteLine("数据库结构同步完成!");

+ 51 - 28
OASystem/OASystem.Api/Controllers/AuthController.cs

@@ -1,12 +1,11 @@
 
 
-using Microsoft.Extensions.Caching.Distributed;
 using OASystem.Infrastructure.Repositories.Login;
 using OASystem.Infrastructure.Repositories.Login;
 using System.IdentityModel.Tokens.Jwt;
 using System.IdentityModel.Tokens.Jwt;
 using System.Security.Claims;
 using System.Security.Claims;
-using StackExchange.Redis;
 using OASystem.Domain.Dtos.UserDto;
 using OASystem.Domain.Dtos.UserDto;
-using OASystem.RedisRepository;
-using OASystem.Infrastructure.Repositories.System;
+using OASystem.API.OAMethodLib;
+using Serilog.Parsing;
+using OASystem.Domain.Dtos.System;
 
 
 namespace OASystem.API.Controllers
 namespace OASystem.API.Controllers
 {
 {
@@ -19,17 +18,13 @@ namespace OASystem.API.Controllers
         private readonly IMapper _mapper;
         private readonly IMapper _mapper;
         private readonly IConfiguration _config;
         private readonly IConfiguration _config;
         private readonly LoginRepository _loginRep;
         private readonly LoginRepository _loginRep;
-        private readonly UsersRepository _usersRepository;
-      
-        //private IDatabase _redis; 
-        //private RedisHelper _redisHelper;
-        public AuthController(IConfiguration config, LoginRepository loginRep, IMapper mapper)
+        private readonly MessageRepository _message; 
+        public AuthController(IConfiguration config, LoginRepository loginRep, IMapper mapper,MessageRepository message)
         {
         {
             _config = config;
             _config = config;
             _loginRep = loginRep;
             _loginRep = loginRep;
             _mapper = mapper;
             _mapper = mapper;
-           
-            //_usersRepository = usersRepository;
+            _message = message;
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -54,27 +49,55 @@ namespace OASystem.API.Controllers
             #endregion
             #endregion
             var view = new LoginView
             var view = new LoginView
             {
             {
-                Expires = DateTime.Now.AddMinutes(30),
                 UserInfo = userData.Result.Data
                 UserInfo = userData.Result.Data
             };
             };
 
 
+
+            DateTime createZebraTime = DateTime.UtcNow;
             string authorId = dto.Number + "Token";
             string authorId = dto.Number + "Token";
+            string authorToken = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>(authorId);//string 取
+            if (authorToken !=  null)
+            {
+                #region 解析出过期时间
+                var jwtHandler = new JwtSecurityTokenHandler();
+                JwtSecurityToken securityToken = jwtHandler.ReadJwtToken(authorToken);
+                DateTime expDt = (securityToken.Payload[JwtRegisteredClaimNames.Exp] ?? 0).GetInt().GetTimeSpmpToDate();
+                #endregion
+
+                if (expDt >= createZebraTime)  //超时重新获取token
+                {
+                    authorToken = GeneralMethod.GetToken(_config, dto.Number, createZebraTime);
+                }
+
+                view.Expires = expDt;
+                view.Token = authorToken;
+
+            }
+            else
+            {
+                view.Expires = createZebraTime.AddMinutes(30);
+                view.Token = GeneralMethod.GetToken(_config, dto.Number, createZebraTime);
+                TimeSpan ts = view.Expires.AddMinutes(-1) - createZebraTime; //设置redis 过期时间 比 jwt 时间 快一分钟
+                await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>(authorId, view.Token, ts);//string 存
+            }
 
 
-            var claims = new[] { new Claim(ClaimTypes.NameIdentifier, "Future") };
-            var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"]));
-            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
-            var token = new JwtSecurityToken(
-                issuer: "OASystem.com",
-                audience: "OASystem.com",
-                claims: claims,
-                expires: view.Expires,
-                signingCredentials: creds);
-            view.Token = new JwtSecurityTokenHandler().WriteToken(token);
-
-            //Redis  String使用示例
-            //TimeSpan ts = new TimeSpan(0, 30, 0);
-            //await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("key01", "value01", ts);//string 存
-            //string redisString = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("key01");//string 取
+
+            #region 测试添加系统消息
+
+            //await _message.AddMsg(new MessageDto()
+            //{
+            //    Type = 1,
+            //    IssuerId = 208,
+            //    Title = "测试添加消息标题",
+            //    Content = "消息体测试",
+            //    ReleaseTime = DateTime.Now,
+            //    UIdList = new List<int> {
+            //        5,
+            //        208,
+            //        219
+            //    }
+            //});
+            #endregion
 
 
             return Ok(JsonView(view));
             return Ok(JsonView(view));
         }
         }
@@ -134,7 +157,7 @@ namespace OASystem.API.Controllers
         /// </summary>
         /// </summary>
         /// <param name="dto"></param>
         /// <param name="dto"></param>
         /// <returns></returns>
         /// <returns></returns>
-        [Authorize]
+        [OASystemAuthentication]
         [HttpPost("TestToken")]
         [HttpPost("TestToken")]
         [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
         [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
         public async Task<IActionResult> TestToken(LoginDto dto)
         public async Task<IActionResult> TestToken(LoginDto dto)

+ 163 - 4
OASystem/OASystem.Api/Controllers/SystemController.cs

@@ -1,5 +1,5 @@
-using OASystem.Domain.Entities.System;
-using System.Collections;
+using System.Collections;
+using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
 
 
 namespace OASystem.API.Controllers
 namespace OASystem.API.Controllers
 {
 {
@@ -23,11 +23,13 @@ namespace OASystem.API.Controllers
         private readonly SystemMenuAndFunctionRepository _SystemMenuAndFunctionRepository;
         private readonly SystemMenuAndFunctionRepository _SystemMenuAndFunctionRepository;
         private readonly JobPostAuthorityRepository _JobPostAuthorityRepository;
         private readonly JobPostAuthorityRepository _JobPostAuthorityRepository;
         private readonly JobPostRepository _jobRep;
         private readonly JobPostRepository _jobRep;
+        private readonly UserAuthorityRepository _UserAuthorityRepository;
 
 
         public SystemController( CompanyRepository syscom, DepartmentRepository sysDepRep, UsersRepository userRep,
         public SystemController( CompanyRepository syscom, DepartmentRepository sysDepRep, UsersRepository userRep,
             IMapper mapper, SetDataRepository setDataRepository, CompanyRepository companyRepository,
             IMapper mapper, SetDataRepository setDataRepository, CompanyRepository companyRepository,
             SystemMenuPermissionRepository systemMenuPermissionRepository, PageFunctionPermissionRepository pageFunctionPermissionRepository,
             SystemMenuPermissionRepository systemMenuPermissionRepository, PageFunctionPermissionRepository pageFunctionPermissionRepository,
-            SystemMenuAndFunctionRepository systemMenuAndFunctionRepository, JobPostAuthorityRepository jobPostAuthorityRepository, JobPostRepository jobRep)
+            SystemMenuAndFunctionRepository systemMenuAndFunctionRepository, JobPostAuthorityRepository jobPostAuthorityRepository, JobPostRepository jobRep
+            , UserAuthorityRepository userAuthorityRepository)
             
             
         {
         {
             _syscomRep = syscom;
             _syscomRep = syscom;
@@ -40,6 +42,7 @@ namespace OASystem.API.Controllers
             _PageFunctionPermissionRepository = pageFunctionPermissionRepository;
             _PageFunctionPermissionRepository = pageFunctionPermissionRepository;
             _SystemMenuAndFunctionRepository = systemMenuAndFunctionRepository;
             _SystemMenuAndFunctionRepository = systemMenuAndFunctionRepository;
             _JobPostAuthorityRepository = jobPostAuthorityRepository;
             _JobPostAuthorityRepository = jobPostAuthorityRepository;
+            _UserAuthorityRepository = userAuthorityRepository;
         }
         }
 
 
         #region 企业操作
         #region 企业操作
@@ -508,6 +511,7 @@ namespace OASystem.API.Controllers
         /// </summary>
         /// </summary>
         /// <param name="dto"></param>
         /// <param name="dto"></param>
         /// <returns></returns>
         /// <returns></returns>
+        //[OASystemAuthentication]
         [HttpPost]
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> GetUserList(DtoBase dto)
         public async Task<IActionResult> GetUserList(DtoBase dto)
@@ -838,9 +842,45 @@ namespace OASystem.API.Controllers
 
 
             _JobPostAuthorityRepository.BeginTran();
             _JobPostAuthorityRepository.BeginTran();
             try
             try
-            {
+            {   //删除岗位
                 bool isdel = await _JobPostAuthorityRepository.DeleteAsync<Sys_JobPostAuthority>(x => x.JpId == dto.Jpid);
                 bool isdel = await _JobPostAuthorityRepository.DeleteAsync<Sys_JobPostAuthority>(x => x.JpId == dto.Jpid);
                 int UpRows = _JobPostAuthorityRepository.Adds<Sys_JobPostAuthority>(adds);
                 int UpRows = _JobPostAuthorityRepository.Adds<Sys_JobPostAuthority>(adds);
+
+                //获取所有职位员工
+                var jobUserAll = await QueryUserList(new UserDto { PortType = 2, JobPostId = dto.Jpid });
+                List<UserInfoWebView> users = null;
+                var QueryUserListApiResult = (((jobUserAll as OkObjectResult).Value) as OASystem.Domain.ViewModels.JsonView);
+                if (QueryUserListApiResult != null)
+                {
+                    if (QueryUserListApiResult.Code == 200)
+                    {
+                        users = QueryUserListApiResult.Data as List<UserInfoWebView>;
+                    }
+                }
+
+                if (users != null && users.Count > 0)
+                {
+                    List<Sys_UserAuthority> userAuth = null;
+                    foreach (var user in users)
+                    {
+                        //删除个人级岗位权限
+                        isdel = await _UserAuthorityRepository.DeleteAsync<Sys_UserAuthority>(x => x.IsTemp == 1 &&
+                        x.UId == user.UserId);
+
+                        userAuth = adds.Select(x=> new Sys_UserAuthority
+                        {
+                            CreateTime = DateTime.Now,
+                            CreateUserId = 235,
+                            FId = x.FId,
+                            SmId = x.SmId,
+                            UId = user.UserId,
+                            IsTemp = 1,
+                        }).ToList();
+
+                        //添加个人级别岗位
+                        int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
+                    }
+                }
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
@@ -852,6 +892,125 @@ namespace OASystem.API.Controllers
             return Ok(JsonView(200, "成功", new { }));
             return Ok(JsonView(200, "成功", new { }));
         }
         }
 
 
+
+        /// <summary>
+        /// 获取员工权限
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public IActionResult QueryUserAuth(QueryUserAuthDto dto)
+        {
+            //选中的员工操作权限
+            var DBdata = _UserAuthorityRepository.QueryDto<Sys_UserAuthority, UserAuthorityView>(x => x.UId == dto.Userid).ToList();
+            var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
+            if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
+            {
+                return Ok(JsonView("暂无数据"));
+            }
+
+            //所有操作
+            var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>().ToList();
+
+            //获取所有关联页面
+            var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
+
+            ArrayList viewData = new ArrayList();
+            //组合页面数据
+            foreach (var item in SystemMenuPermissionData)
+            {
+                ArrayList ids = new ArrayList();
+                foreach (var viewop in PageOperation)
+                {
+                    var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
+                    if (op != null)
+                    {
+                        ids.Add(viewop.Id);
+                    }
+                }
+
+                //获取本员工拥有的权限
+                var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.UId == dto.Userid).ToList();
+
+                viewData.Add(new
+                {
+                    Id = item.Id,
+                    Mid = item.Mid,
+                    Name = item.Name,
+                    SystemMenuCode = item.SystemMenuCode,
+                    opList = ids,
+                    selList = DBwhere.Select(x => x.FId)
+                });
+            }
+
+            return Ok(JsonView(200, "成功!", viewData));
+        }
+
+
+        /// <summary>
+        /// 保存员工权限
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> SaveUserAuth(SaveUserDto dto)
+        {
+            //获取所有关联页面
+            var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
+
+            List<Sys_UserAuthority> adds = new List<Sys_UserAuthority>();
+            foreach (var item in dto.Savejobs)
+            {
+                foreach (var fid in item.FIds)
+                {
+                    var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
+                    if (whereobj != null)
+                    {
+                        adds.Add(new Sys_UserAuthority
+                        {
+                            CreateTime = DateTime.Now,
+                            CreateUserId = 235,
+                            FId = fid,
+                            UId = dto.uid,
+                            SmId = item.SmId,
+                            IsTemp = 0
+                        });
+                    }
+                }
+            }
+
+            _JobPostAuthorityRepository.BeginTran();
+            try
+            {
+                List<Sys_UserAuthority> userAuth = null;
+                //删除个人级岗位权限
+                bool isdel = await _UserAuthorityRepository.DeleteAsync<Sys_UserAuthority>(x => x.IsTemp == 0 &&
+                x.UId == dto.uid);
+
+                userAuth = adds.Select(x => new Sys_UserAuthority
+                {
+                    CreateTime = DateTime.Now,
+                    CreateUserId = 235,
+                    FId = x.FId,
+                    SmId = x.SmId,
+                    UId = dto.uid,
+                    IsTemp = 0,
+                }).ToList();
+
+                //添加个人级别岗位
+                int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
+            }
+            catch (Exception ex)
+            {
+                _JobPostAuthorityRepository.RollbackTran();
+                return Ok(JsonView("系统错误!"));
+            }
+
+            _JobPostAuthorityRepository.CommitTran();
+            return Ok(JsonView(200, "成功", new { }));
+        }
         #endregion
         #endregion
     }
     }
 }
 }

+ 127 - 0
OASystem/OASystem.Api/OAMethodLib/GeneralMethod.cs

@@ -0,0 +1,127 @@
+using OASystem.Domain.Entities.System;
+using System.IdentityModel.Tokens.Jwt;
+using System.Security.Claims;
+
+namespace OASystem.API.OAMethodLib
+{
+    public static class GeneralMethod
+    {
+       
+        #region 消息
+
+        
+
+        #endregion
+
+        #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.IsNullOrWhiteSpace(source))
+                return string.Empty;
+            HashAlgorithm hashAlgorithm = CryptoConfig.CreateFromName("MD5") as HashAlgorithm;
+            byte[] bytes = Encoding.UTF8.GetBytes(source);
+            byte[] hashValue = hashAlgorithm.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
+
+        #region jwt
+
+        /// <summary>
+        ///  获取token 
+        /// </summary>
+        /// <param name="_config"></param>
+        /// <param name="Number"></param>
+        /// <param name="exp"></param>
+        /// <returns></returns>
+        public static string GetToken(IConfiguration _config,string Number,DateTime exp) 
+        {
+            var claims = new[] {
+                new Claim(ClaimTypes.NameIdentifier, "Future"),
+                new Claim("Number",Number)
+            };
+            var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"]));
+            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
+            var token = new JwtSecurityToken(
+                issuer: "OASystem.com",
+                audience: "OASystem.com",
+                claims: claims,
+                expires: exp,
+                signingCredentials: creds);
+           
+            
+            return   new JwtSecurityTokenHandler().WriteToken(token);
+
+        }
+
+
+        #endregion
+
+        #region  数据类型转换
+
+        /// <summary>
+        /// object 转 Int
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <returns></returns>
+        public static int GetInt(this object obj)
+        {
+            if (obj == null)
+                return 0;
+            int _number = 0;
+            bool reslut = Int32.TryParse(obj.ToString(), out _number);
+            return _number;
+
+        }
+
+        private static DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
+        private static long longTime = 621355968000000000;
+        private static int samllTime = 10000000;
+        /// <summary>
+        /// 时间戳 转 datetime
+        /// </summary>
+        /// <param name="timeStamp"></param>
+        /// <returns></returns>
+        public static DateTime GetTimeSpmpToDate(this object timeStamp)
+        {
+            if (timeStamp == null) return dateStart;
+            DateTime dateTime = new DateTime(longTime + Convert.ToInt64(timeStamp) * samllTime, DateTimeKind.Utc).ToLocalTime();
+            return dateTime;
+        }
+
+        #endregion
+
+    }
+}

+ 38 - 2
OASystem/OASystem.Api/OASystemAuthentication.cs

@@ -1,13 +1,49 @@
 using Microsoft.AspNetCore.Mvc.Filters;
 using Microsoft.AspNetCore.Mvc.Filters;
-using Microsoft.IdentityModel.Tokens;
 using System.IdentityModel.Tokens.Jwt;
 using System.IdentityModel.Tokens.Jwt;
-using IAuthorizationFilter = Microsoft.AspNetCore.Mvc.Filters.IAuthorizationFilter;
 
 
 namespace OASystem.API
 namespace OASystem.API
 {
 {
     public class OASystemAuthentication : AuthorizeAttribute
     public class OASystemAuthentication : AuthorizeAttribute
     {
     {
+        public void OnAuthorization(AuthorizationFilterContext context)
+        {
+            string id = context.HttpContext.User.FindFirst("id")?.Value;
+            if (string.IsNullOrEmpty(id))
+            {
+                context.Result = new StatusCodeResult(401); //返回鉴权失败
+                return;
+            }
 
 
+            Console.WriteLine("我是Authorization过滤器");
+            // 请求的地址
+            //var url = context.HttpContext.Request.Path.Value;
+            // 请求头信息
+            var heads = context.HttpContext.Request.Headers;
 
 
+
+
+            string token = heads["Authorization"];
+            token = token.Replace("Bearer ", "");//去掉 "Bearer "才是真正的token
+            if (string.IsNullOrEmpty(token))
+            {
+                Console.WriteLine("校验不通过");
+                return;
+            }
+
+            //redis校验这个token的有效性,确定来源是sso和确定会话没过期
+            //解析员工userNumber
+            var jwtHandler = new JwtSecurityTokenHandler();
+            JwtSecurityToken securityToken = jwtHandler.ReadJwtToken(token);
+            //DateTime expDt = (securityToken.Payload[JwtRegisteredClaimNames.c] ?? 0).GetInt().GetTimeSpmpToDate();
+
+
+            //if (!_cacheService.StringGet<bool>($"token:{token}"))
+            //{
+            //    Console.WriteLine($"token无效,token:{token}");
+            //    context.Result = new StatusCodeResult(401); //返回鉴权失败
+            //    return;
+            //}
+
+        }
     }
     }
 }
 }

+ 16 - 32
OASystem/OASystem.Api/Program.cs

@@ -31,8 +31,6 @@ builder.Services.AddCors(policy =>
 
 
 #endregion
 #endregion
 
 
-
-
 #region 接口分组
 #region 接口分组
 var groups = new List<Tuple<string, string>>
 var groups = new List<Tuple<string, string>>
 {
 {
@@ -140,21 +138,22 @@ if (AppSettingsHelper.Get("UseSwagger").ToBool())
 #region 添加校验
 #region 添加校验
 
 
 //builder.Services.AddTransient<OASystemAuthentication>();
 //builder.Services.AddTransient<OASystemAuthentication>();
-builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
-{
-    options.TokenValidationParameters = new TokenValidationParameters
-    {
-        ValidateIssuer = true,
-        ValidateAudience = true,
-        ValidateLifetime = true,
-        ValidateIssuerSigningKey = true,
-        ValidAudience = "OASystem.com",
-        ValidIssuer = "OASystem.com",
-        IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"])),
-        ClockSkew = TimeSpan.FromSeconds(30), //过期时间容错值,解决服务器端时间不同步问题(秒)
-        RequireExpirationTime = true,
-    };
-});
+builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
+    .AddJwtBearer(options =>
+        {
+            options.TokenValidationParameters = new TokenValidationParameters
+            {
+                ValidateIssuer = true,
+                ValidateAudience = true,
+                ValidateLifetime = true,
+                ValidateIssuerSigningKey = true,
+                ValidAudience = "OASystem.com",
+                ValidIssuer = "OASystem.com",
+                IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"])),
+                ClockSkew = TimeSpan.FromSeconds(30), //过期时间容错值,解决服务器端时间不同步问题(秒)
+                RequireExpirationTime = true,
+            };
+        });
 #endregion
 #endregion
 
 
 #region 初始化日志
 #region 初始化日志
@@ -191,23 +190,8 @@ builder.Services.AddScoped<IMapper, Mapper>();
 
 
 #endregion
 #endregion
 
 
-#region 跨域配置
-builder.Services.AddCors(c =>
-{
-    c.AddPolicy("AllowAllOrigins", policy =>
-    {
-        policy.AllowAnyOrigin()
-        .AllowAnyMethod()
-        .AllowAnyHeader();
-    });
-});
-#endregion
-
-
 var app = builder.Build();
 var app = builder.Build();
 
 
-app.UseCors("AllowAllOrigins");
-
 // Configure the HTTP request pipeline.
 // Configure the HTTP request pipeline.
 if (!app.Environment.IsDevelopment())
 if (!app.Environment.IsDevelopment())
 {
 {

+ 7 - 1
OASystem/OASystem.Domain/AutoMappers/_baseMappingProfile.cs

@@ -11,11 +11,17 @@ namespace OASystem.Domain.AutoMappers
     {
     {
         public _baseMappingProfile()
         public _baseMappingProfile()
         {
         {
-            //CreateMap<OrderDto, Order>();
             #region Login
             #region Login
             CreateMap<LoginDto, Sys_Users>();
             CreateMap<LoginDto, Sys_Users>();
             #endregion
             #endregion
 
 
+
+            #region 消息
+
+            CreateMap<Sys_Message, DepartmentIView>();
+            CreateMap<Sys_MessageReadAuth, DepartmentIView>();
+            #endregion
+
             #region 公司板块
             #region 公司板块
             CreateMap<Sys_Company, CompanyView>();
             CreateMap<Sys_Company, CompanyView>();
             CreateMap<AddCompanyDto, Sys_Company>();
             CreateMap<AddCompanyDto, Sys_Company>();

+ 47 - 0
OASystem/OASystem.Domain/Dtos/System/MessageDto.cs

@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.System
+{
+    /// <summary>
+    /// 发布消息 提交参数实体类
+    /// </summary>
+    public class MessageDto
+    {
+        /// <summary>
+        /// 消息类型
+        /// 0 用户登录消息
+        /// 1 系统消息
+        /// 2 业务消息
+        /// </summary>
+        public int Type { get; set; }
+
+        /// <summary>
+        /// 发布人
+        /// </summary>
+        public int IssuerId { get; set; }
+
+        /// <summary>
+        /// 消息标题
+        /// </summary>
+        public string Title { get; set; }
+
+        /// <summary>
+        /// 消息内容
+        /// </summary>
+        public string Content { get; set; }
+
+        /// <summary>
+        /// 发布时间
+        /// </summary>
+        public DateTime ReleaseTime { get; set; }
+
+        /// <summary>
+        /// 可阅读员工
+        /// </summary>
+        public List<int> UIdList { get; set; }
+    }
+}

+ 15 - 0
OASystem/OASystem.Domain/Dtos/System/QueryUserAuthDto.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.System
+{
+    public class QueryUserAuthDto
+    {
+        public int Userid { get; set; }
+
+        public int moduleId { get; set; }
+    }
+}

+ 19 - 0
OASystem/OASystem.Domain/Dtos/System/SaveJobDto.cs

@@ -8,13 +8,32 @@ namespace OASystem.Domain.Dtos.System
 {
 {
     public class SaveJobDto
     public class SaveJobDto
     {
     {
+        /// <summary>
+        /// 职位id
+        /// </summary>
         public int Jpid { get; set; }
         public int Jpid { get; set; }
         public List<savejob> Savejobs { get; set; }
         public List<savejob> Savejobs { get; set; }
     }
     }
 
 
+    public class SaveUserDto
+    {
+        /// <summary>
+        /// 员工id
+        /// </summary>
+        public int uid { get; set; }
+        public List<savejob> Savejobs { get; set; }
+    }
+
     public class savejob
     public class savejob
     {
     {
+        /// <summary>
+        /// 页面id
+        /// </summary>
         public int SmId { get; set; }
         public int SmId { get; set; }
+
+        /// <summary>
+        /// 功能id
+        /// </summary>
         public List<int> FIds { get; set; }
         public List<int> FIds { get; set; }
     }
     }
 }
 }

+ 47 - 0
OASystem/OASystem.Domain/Entities/System/Sys_Message.cs

@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Entities.System
+{
+    /// <summary>
+    /// 系统消息 表
+    /// </summary>
+    public class Sys_Message :EntityBase
+    {
+        /// <summary>
+        /// 类型
+        /// 0 用户登录消息
+        /// 1 系统消息
+        /// 2 业务消息
+        /// </summary>
+        [SugarColumn(IsNullable = true,ColumnDataType = "int")]
+        public int Type { get; set; }
+
+        /// <summary>
+        /// 发布者用户Id
+        /// </summary>
+        [SugarColumn(IsNullable = true,ColumnDataType = "int")]
+        public int IssuerId { get; set; }
+
+        /// <summary>
+        /// 消息标题
+        /// </summary>
+        [SugarColumn(IsNullable = true,ColumnDataType = "varchar(100)")]
+        public string Title { get; set; }
+
+        /// <summary>
+        /// 消息内容
+        /// </summary>
+        [SugarColumn(IsNullable = true,ColumnDataType = "varchar(500)")]
+        public string Content { get; set; }
+
+        /// <summary>
+        /// 发布时间
+        /// </summary>
+        [SugarColumn(IsNullable = true , ColumnDataType = "datetime")]
+        public DateTime ReleaseTime { get; set; }
+    }
+}

+ 40 - 0
OASystem/OASystem.Domain/Entities/System/Sys_MessageReadAuth.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Entities.System
+{
+    /// <summary>
+    /// 消息可读员工
+    /// </summary>
+    public class Sys_MessageReadAuth:EntityBase
+    {
+        /// <summary>
+        /// 消息Id
+        /// </summary>
+        [SugarColumn(IsNullable = true,ColumnDataType = "int")]
+        public int MsgId { get; set; }
+
+        /// <summary>
+        /// 可读用户Id
+        /// </summary>
+        [SugarColumn(IsNullable = true,ColumnDataType = "int")]
+        public int ReadableUId { get; set; }
+
+        /// <summary>
+        /// 是否已读
+        /// 0 未读
+        /// 1 已读
+        /// </summary>
+        [SugarColumn(IsNullable = true,ColumnDataType = "int")]
+        public int IsRead { get; set; }
+
+        /// <summary>
+        /// 阅读时间
+        /// </summary>
+        [SugarColumn(IsNullable = true,ColumnDataType = "datetime")]
+        public DateTime ReadTime { get; set; }
+    }
+}

+ 6 - 0
OASystem/OASystem.Domain/Entities/System/Sys_UserAuthority.cs

@@ -27,5 +27,11 @@ namespace OASystem.Domain.Entities.System
         /// </summary>
         /// </summary>
         [SugarColumn(IsNullable = true, ColumnDataType = "int")]
         [SugarColumn(IsNullable = true, ColumnDataType = "int")]
         public int FId { get; set; }
         public int FId { get; set; }
+
+        /// <summary>
+        /// 是否由职位模板导入
+        /// </summary>
+        [SugarColumn(ColumnDescription = "是否由职位模板导入", IsNullable = true, ColumnDataType = "int")]
+        public int IsTemp { get; set; }
     }
     }
 }
 }

+ 13 - 0
OASystem/OASystem.Domain/ViewModels/System/MessageReadAuthView.cs

@@ -0,0 +1,13 @@
+using OASystem.Domain.Entities.System;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.System
+{
+    public class MessageReadAuthView : Sys_MessageReadAuth
+    {
+    }
+}

+ 14 - 0
OASystem/OASystem.Domain/ViewModels/System/MessageView.cs

@@ -0,0 +1,14 @@
+using OASystem.Domain.Entities.System;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.System
+{
+    public class MessageView : Sys_Message
+    {
+    }
+
+}

+ 33 - 0
OASystem/OASystem.Domain/ViewModels/System/UserAuthorityView.cs

@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.System
+{
+    public class UserAuthorityView
+    {
+        /// <summary>
+        /// 数据id
+        /// </summary>
+        public int ID { get; set; }
+        /// 用户Id
+        /// </summary>
+        public int UId { get; set; }
+        /// <summary>
+        /// 页面权限Id
+        /// </summary>
+        public int SmId { get; set; }
+        /// <summary>
+        /// 页面功能Id
+        /// </summary>
+        public int FId { get; set; }
+
+        /// <summary>
+        /// 是否由职位模板导入
+        /// </summary>
+        public int IsTemp { get; set; }
+
+    }
+}

+ 15 - 0
OASystem/OASystem.Infrastructure/Repositories/System/MessageReadAuthRepository.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Infrastructure.Repositories.System
+{
+    public class MessageReadAuthRepository : BaseRepository<Sys_MessageReadAuth, MessageReadAuthView>
+    {
+
+        public MessageReadAuthRepository(SqlSugarClient sqlSugar) : base(sqlSugar) { }
+
+    }
+}

+ 88 - 0
OASystem/OASystem.Infrastructure/Repositories/System/MessageRepository.cs

@@ -0,0 +1,88 @@
+using OASystem.Domain.Dtos.System;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Infrastructure.Repositories.System
+{
+    public class MessageRepository : BaseRepository<Sys_Message, MessageView>
+    {
+        public MessageRepository(SqlSugarClient sqlSugar) : base(sqlSugar) { }
+
+
+        /// <summary>
+        /// 发布消息
+        /// </summary>
+        /// <param name="msgDto"></param>
+        /// <returns></returns>
+        public async Task<bool> AddMsg(MessageDto msgDto)
+        {
+            #region 参数处理
+
+            if (msgDto == null) { return false; }
+            if (string.IsNullOrEmpty(msgDto.Title)) { return false; }
+            if (string.IsNullOrEmpty(msgDto.Content)) { return false; }
+            if (msgDto.UIdList.Count <= 0) { return false; }
+
+            #endregion
+
+            _sqlSugar.BeginTran();
+            try
+            {
+                Sys_Message message = new Sys_Message()
+                {
+                    Type = msgDto.Type,
+                    IssuerId = msgDto.IssuerId,
+                    Title = msgDto.Title,
+                    Content = msgDto.Content,
+                    ReleaseTime = msgDto.ReleaseTime,
+                    CreateUserId = msgDto.IssuerId,
+                    CreateTime = DateTime.Now,
+                    DeleteUserId = null,
+                    DeleteTime = "1990-01-01 00:00:00.000",
+                    Remark = "",
+                    IsDel = 0
+                };
+
+                int? msgId = await _sqlSugar.Insertable(message).ExecuteReturnIdentityAsync();
+                if (!msgId.HasValue) { _sqlSugar.RollbackTran(); return false; }
+
+                List<Sys_MessageReadAuth> messageReadAuths = new List<Sys_MessageReadAuth>();
+                foreach (int item in msgDto.UIdList)
+                {
+                    Sys_MessageReadAuth messageReadAuth = new Sys_MessageReadAuth() 
+                    {
+                        MsgId = msgId.Value,
+                        ReadableUId = item,
+                        ReadTime = new DateTime(1990,1,1),
+                        CreateUserId = msgDto.IssuerId,
+                        CreateTime = DateTime.Now,
+                        DeleteUserId = null,
+                        DeleteTime = "1990-01-01 00:00:00.000",
+                        Remark = "",
+                        IsDel = 0
+                    };
+                    messageReadAuths.Add(messageReadAuth);
+                }
+
+                int? readIds = await _sqlSugar.Insertable<Sys_MessageReadAuth>(messageReadAuths).ExecuteCommandAsync();
+                if (!readIds.HasValue)
+                {
+                    _sqlSugar.RollbackTran();
+                    return false;
+                }
+                _sqlSugar.CommitTran();
+            }
+            catch (Exception)
+            {
+                _sqlSugar.RollbackTran();
+                return false;
+            }
+
+            return true;
+        }
+
+    }
+}

+ 10 - 0
OASystem/OASystem.Infrastructure/Repositories/System/UserAuthorityRepository.cs

@@ -0,0 +1,10 @@
+
+namespace OASystem.Infrastructure.Repositories.System
+{
+    public class UserAuthorityRepository : BaseRepository<Sys_UserAuthority, UserAuthorityView>
+    {
+        public UserAuthorityRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
+        {
+        }
+    }
+}

+ 1 - 5
OASystem/OASystem.Infrastructure/Repositories/System/UsersRepository.cs

@@ -13,11 +13,7 @@ namespace OASystem.Infrastructure.Repositories.System
 {
 {
     public class UsersRepository : BaseRepository<UserInfo, JsonView>
     public class UsersRepository : BaseRepository<UserInfo, JsonView>
     {
     {
-        private readonly IMapper _mapper;
-        public UsersRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
-        {
-            _mapper = mapper;
-        }
+        public UsersRepository(SqlSugarClient sqlSugar) : base(sqlSugar){}
 
 
         /// <summary>
         /// <summary>
         /// 用户查询列表
         /// 用户查询列表

+ 6 - 0
OASystem/_Doc/OA2023数据字典.docx

@@ -494,6 +494,12 @@ Null
 
 
 页面功能Id
 页面功能Id
 页面功能表Id
 页面功能表Id
+IsTemp
+Int
+Null
+
+是否由职位模板导入
+是否由职位模板导入
 
 
 9) 岗位权限表:Sys_JobPostAuthority(新增)
 9) 岗位权限表:Sys_JobPostAuthority(新增)
                                    字段名
                                    字段名