Browse Source

添加公司默认新增部门,岗位,管理员

wangh 1 year ago
parent
commit
02d8045b8a

+ 16 - 5
OASystem/OASystem.Api/Controllers/SystemController.cs

@@ -23,6 +23,7 @@ namespace OASystem.API.Controllers
         private readonly DepartmentRepository _sysDepRep;
         private readonly UsersRepository _userRep;
         private readonly IMapper _mapper;
+        private readonly SqlSugarClient _sqlSugar;
         private readonly MessageRepository _messageRep;
         private readonly SetDataRepository _setDataRepository;
         private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
@@ -35,7 +36,7 @@ namespace OASystem.API.Controllers
         private readonly UserAuthorityRepository _UserAuthorityRepository;
 
         public SystemController( CompanyRepository syscom, DepartmentRepository sysDepRep, UsersRepository userRep,
-            IMapper mapper, SetDataRepository setDataRepository, CompanyRepository companyRepository,
+            IMapper mapper,SqlSugarClient sqlSugar, SetDataRepository setDataRepository, CompanyRepository companyRepository,
             SystemMenuPermissionRepository systemMenuPermissionRepository, PageFunctionPermissionRepository pageFunctionPermissionRepository,
             SystemMenuAndFunctionRepository systemMenuAndFunctionRepository, JobPostAuthorityRepository jobPostAuthorityRepository, 
             JobPostRepository jobRep,UserAuthorityRepository userAuthorityRepository, MessageRepository messageRep,SetDataTypeRepository setDataTypeRep)
@@ -46,6 +47,7 @@ namespace OASystem.API.Controllers
             _messageRep = messageRep;
             _userRep = userRep;
             _mapper = mapper;
+            _sqlSugar = sqlSugar;
             _setDataRepository = setDataRepository;
             _CompanyRepository = companyRepository;
             _SystemMenuPermissionRepository = systemMenuPermissionRepository;
@@ -418,13 +420,13 @@ namespace OASystem.API.Controllers
                 else
                 {
                     Sys_Company _Company = _mapper.Map<Sys_Company>(dto);
-                    int id = await _syscomRep.AddAsyncReturnId(_Company);
-                    if (id == 0)
+                    Result data = await _syscomRep.AddCompany(_Company);
+                    if (data.Code != 0)
                     {
                         return Ok(JsonView(false, "添加失败!"));
 
                     }
-                    return Ok(JsonView(true,"添加成功", new { Id = id }));
+                    return Ok(JsonView(true,"添加成功"));
                 }
             }
             catch (Exception)
@@ -1056,7 +1058,16 @@ namespace OASystem.API.Controllers
                 {
                     return Ok(JsonView(false, "参数不能为空!"));
                 }
-
+                Sys_Users _Users=_sqlSugar.Queryable<Sys_Users>().First(a=>a.IsDel==0 && a.Id==dto.Id);
+                if (_Users != null)
+                {
+                    List<Sys_Users> sys_UsersList=_sqlSugar.Queryable<Sys_Users>().Where(a=>a.IsDel==0 && a.CompanyId==_Users.CompanyId).ToList();
+                    if (sys_UsersList.Count==1)
+                    {
+                        return Ok(JsonView(false, "该人员为公司最后一位,不可删除!"));
+                    }
+                }
+                
                 bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
                 {
                     IsDel = 1,

+ 1 - 1
OASystem/OASystem.Domain/Dtos/Groups/AirTicketResDto.cs

@@ -215,7 +215,7 @@ namespace OASystem.Domain.Dtos.Groups
         /// <summary>
         /// 财务操作人 用户Id
         /// </summary>
-        public string MFOperator { get; set; }
+        public int MFOperator { get; set; }
         /// <summary>
         /// 财务操作时间
         /// </summary>

+ 1 - 2
OASystem/OASystem.Infrastructure/Repositories/Resource/TicketBlackCodeRepository.cs

@@ -34,8 +34,7 @@ namespace OASystem.Infrastructure.Repositories.Resource
             {
                 if (dto.Status == 1)//添加
                 {
-                   
-                    Air_TicketBlackCode _TicketBlackCode = await _sqlSugar.Queryable<Air_TicketBlackCode>().FirstAsync(a=>a.IsDel==0 && a.BlackCode==dto.BlackCode);//查询是否存在
+                    Air_TicketBlackCode _TicketBlackCode = await _sqlSugar.Queryable<Air_TicketBlackCode>().FirstAsync(a=>a.IsDel==0 && a.BlackCode==dto.BlackCode && a.DiId==dto.DiId);//查询是否存在
                     if (_TicketBlackCode != null)
                     {
                         return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };

+ 143 - 1
OASystem/OASystem.Infrastructure/Repositories/System/CompanyRepository.cs

@@ -1,5 +1,10 @@
-using OASystem.Domain;
+using MathNet.Numerics.Distributions;
+using NPOI.POIFS.Crypt.Dsig;
+using NPOI.SS.Formula.Functions;
+using OASystem.Domain;
+using OASystem.Domain.Entities.Groups;
 using OASystem.Domain.Entities.System;
+using OASystem.Domain.ViewModels.QiYeWeChat;
 
 namespace OASystem.Infrastructure.Repositories.System
 {
@@ -10,6 +15,143 @@ namespace OASystem.Infrastructure.Repositories.System
 
         }
 
+        public async  Task<Result> AddCompany(Sys_Company company)
+        {
+            Result result = new Result() { Code = -2, Msg = "未知错误" };
+            try
+            {
+                BeginTran();
+                Sys_Company Company = _sqlSugar.Queryable<Sys_Company>().First(a => a.CompanyName == company.CompanyName && a.IsDel == 0);
+                if (Company != null)
+                {
+                    return result = new Result() { Code = -1, Msg = "该公司已存在,请勿重复添加!"};
+                }
+                else
+                {
+                    int CompanyId = 0;
+                    int DepartmentId = 0;
+                    int JobPostId = 0;
+                    int UsersId = 0;
+                    CompanyId = await AddAsyncReturnId(company);
+                    if (CompanyId > 0)
+                    {
+                        #region 添加默认部门
+                        Sys_Department _Department = new Sys_Department();
+                        _Department.CompanyId = CompanyId;
+                        _Department.DepName = "默认部门";
+                        _Department.DepCode = "00";
+                        _Department.ParentDepId = 0;
+                        _Department.CreateUserId = company.CreateUserId;
+                        _Department.Remark = "添加公司时默认生成部门,可修改!";
+                        _Department.IsDel = 0;
+                        DepartmentId = await _sqlSugar.Insertable(_Department).ExecuteReturnIdentityAsync();
+                        #endregion
+
+                        if (DepartmentId>0)
+                        {
+                            #region 添加默认岗位
+                            Sys_JobPost _JobPost = new Sys_JobPost();
+                            _JobPost.CompanyId = CompanyId;
+                            _JobPost.DepId = DepartmentId;
+                            _JobPost.JobName = "默认岗位";
+                            _JobPost.CreateUserId = company.CreateUserId;
+                            _JobPost.Remark = "添加公司时默认生成岗位,可修改!";
+                            _JobPost.IsDel = 0;
+                            JobPostId = await _sqlSugar.Insertable(_JobPost).ExecuteReturnIdentityAsync();
+                            #endregion
+                            if (JobPostId>0)
+                            {
+                                #region 添加默认管理员
+                                Sys_Users _Users = new Sys_Users();
+                                _Users.CnName = "管理员";
+                                _Users.EnName = "Guan LiYuan";
+                                _Users.Number = CompanyId.ToString() + DepartmentId.ToString() + JobPostId.ToString()+"01";
+                                _Users.CompanyId = CompanyId;
+                                _Users.DepId = DepartmentId;
+                                _Users.JobPostId = JobPostId;
+                                _Users.Password = "123456";
+                                _Users.Sex = 0;
+                                _Users.HrAudit = 1;
+                                _Users.CreateUserId = company.CreateUserId;
+                                _Users.Remark = "添加公司时默认生成管理员,Number可修改!";
+                                _Users.IsDel = 0;
+                                UsersId = await _sqlSugar.Insertable(_Users).ExecuteReturnIdentityAsync();
+                                if (UsersId>0)
+                                {
+                                    List<int> fid = new List<int>();//功能权限
+                                    List<int> SmId=new List<int>();//页面权限
+                                    List<Sys_UserAuthority> adds = new List<Sys_UserAuthority>();
+                                    List<Sys_PageFunctionPermission> sys_PageFunctionPermissions = _sqlSugar.Queryable<Sys_PageFunctionPermission>().Where(a=>a.IsDel==0).ToList();
+                                    
+                                    foreach (var item in sys_PageFunctionPermissions)
+                                    {
+                                        fid.Add(item.Id);
+                                    }
+                                    List<Sys_SystemMenuPermission> _SystemMenuPermissions = _sqlSugar.Queryable<Sys_SystemMenuPermission>().Where(a => a.IsDel == 0 && (a.Mid==12 || a.Mid==13 || a.Mid==17) &&
+                                    a.WebUrl!="Null" && a.WebUrl!="/" && a.IsEnable==1).ToList();
+                                    foreach(var item in _SystemMenuPermissions)
+                                    {
+                                        SmId.Add(item.Id);
+                                    }
+
+                                    for (int i = 0;i< SmId.Count; i++)
+                                    {
+                                        for (int j = 0; j < fid.Count; j++)
+                                        {
+                                            adds.Add(new Sys_UserAuthority
+                                            {
+                                                CreateTime = DateTime.Now,
+                                                CreateUserId = company.CreateUserId,
+                                                FId = fid[j],
+                                                UId = UsersId,
+                                                SmId = SmId[i],
+                                                IsTemp = 0
+                                            });
+                                        }
+                                    }
+                                    _sqlSugar.Insertable<Sys_UserAuthority>(adds).ExecuteCommand();
+
+                                }
+                                else
+                                {
+                                    RollbackTran();
+                                    result = new Result() { Code = 0, Msg = "默认管理员添加失败!" };
+                                }
+                                #endregion
+                            }
+                            else
+                            {
+                                RollbackTran();
+                                result = new Result() { Code = 0, Msg = "默认岗位添加失败!" };
+                            }
+                        }
+                        else
+                        {
+                            RollbackTran();
+                            result = new Result() { Code = 0, Msg = "默认部门添加失败!" };
+                        }
+                        CommitTran();
+                        var data = new
+                        {
+                            Number = CompanyId.ToString() + DepartmentId.ToString() + JobPostId.ToString() + "01",
+                            Password = "123456",
+                        };
+                        result = new Result() { Code = 0, Msg = "添加成功!可通过Number和密码登录进去管理!初始密码为:123456", };
+                    }
+                    else
+                    {
+                        result = new Result() { Code = -1, Msg = "添加失败!请稍后重试!" };
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                return result = new Result() { Code = -2, Msg = "未知错误" };
+            }
+            return result;
+        }
+
+        
         /// <summary>
         /// 获取所有公司数据
         /// </summary>