From c914975bffe90f808a05dba2c53d4a750e8403c0 Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期三, 06 八月 2025 18:17:08 +0800 Subject: [PATCH] feat:企业开发 --- FlexJobApi.User.Application/Enterprises/Commands/EnterpriseCommandHandler.cs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 48 insertions(+), 6 deletions(-) diff --git a/FlexJobApi.User.Application/Enterprises/Commands/EnterpriseCommandHandler.cs b/FlexJobApi.User.Application/Enterprises/Commands/EnterpriseCommandHandler.cs index f30c36b..a151896 100644 --- a/FlexJobApi.User.Application/Enterprises/Commands/EnterpriseCommandHandler.cs +++ b/FlexJobApi.User.Application/Enterprises/Commands/EnterpriseCommandHandler.cs @@ -19,8 +19,11 @@ public class EnterpriseCommandHandler( IRepository<Enterprise> rep, IRepository<UserInfo> repUserInfo - ) - : IRequestHandler<SaveEnterpriseCommand, Guid> + ) : + IRequestHandler<SaveEnterpriseCommand, Guid>, + IRequestHandler<SetEnterpriseElectronSignSettingCommand, Guid>, + IRequestHandler<SetEnterpriseSmsSettingCommand, Guid> + { private readonly IRepository<Enterprise> rep = rep; private readonly IRepository<UserInfo> repUserInfo = repUserInfo; @@ -34,10 +37,12 @@ public async Task<Guid> Handle(SaveEnterpriseCommand request, CancellationToken cancellationToken) { var entity = await rep.AsQueryable() - .FirstOrDefaultAsync(it => it.SocietyCreditCode == request.SocietyCreditCode); + .Include(it => it.EnterpriseAuth) + .FirstOrDefaultAsync(it => it.EnterpriseAuth.SocietyCreditCode == request.EnterpriseAuth.SocietyCreditCode); if (entity == null) { entity = new Enterprise(); + entity.EnterpriseAuth = new EnterpriseAuth(); request.Adapt(entity); await rep.InsertAsync(entity); } @@ -47,11 +52,18 @@ await rep.UpdateAsync(entity); } + var checkExist = await repUserInfo.AsQueryable() + .AnyAsync(it => + it.Type == EnumUserType.Enterprise + && it.EnterpriseId != entity.Id + && it.UserAuth.UserName == request.UserName); + if (checkExist) throw Oops.Oh(EnumErrorCodeType.s405, "璇ヨ处鍙�"); + var userInfo = await repUserInfo.AsQueryable() .Include(it => it.UserAuth) .FirstOrDefaultAsync(it => it.Type == EnumUserType.Enterprise - && it.UserAuth.UserName == request.UserName); + && it.EnterpriseId == entity.Id); if (userInfo == null) { userInfo = new UserInfo @@ -61,21 +73,51 @@ Status = EnumUserInfoStatus.Normal, UserAuth = new UserAuth { + Name = request.Contacts, UserName = request.UserName, PhoneNumber = request.ContactPhoneNumber, - Password = PBKDF2Encryption.Encrypt(request.Password) + Password = PBKDF2Encryption.Encrypt(MD5Encryption.Encrypt(request.Password)) } }; await repUserInfo.InsertAsync(userInfo); } else { - if (userInfo.EnterpriseId != entity.Id) throw Oops.Oh(EnumErrorCodeType.s405, "璇ヨ处鍙�"); userInfo.UserAuth.PhoneNumber = request.ContactPhoneNumber; await repUserInfo.UpdateAsync(userInfo); } return entity.Id; } + + /// <summary> + /// 璁剧疆浼佷笟鐢靛瓙绛鹃厤缃� + /// </summary> + /// <param name="request"></param> + /// <param name="cancellationToken"></param> + /// <returns></returns> + public async Task<Guid> Handle(SetEnterpriseElectronSignSettingCommand request, CancellationToken cancellationToken) + { + var entity = await rep.AsQueryable().FirstOrDefaultAsync(it => it.Id == request.Id, cancellationToken); + if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "璇ヤ紒涓�"); + request.Adapt(entity); + await rep.UpdateAsync(entity); + return entity.Id; + } + + /// <summary> + /// 璁剧疆浼佷笟鐭俊閰嶇疆 + /// </summary> + /// <param name="request"></param> + /// <param name="cancellationToken"></param> + /// <returns></returns> + public async Task<Guid> Handle(SetEnterpriseSmsSettingCommand request, CancellationToken cancellationToken) + { + var entity = await rep.AsQueryable().FirstOrDefaultAsync(it => it.Id == request.Id, cancellationToken); + if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "璇ヤ紒涓�"); + request.Adapt(entity); + await rep.UpdateAsync(entity); + return entity.Id; + } } } -- Gitblit v1.9.1