| | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | |
| | | 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 |
| | |
| | | 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; |
| | | } |
| | | } |
| | | } |