| | |
| | | using Furion; |
| | | using Furion.DatabaseAccessor; |
| | | using Furion.DataValidation; |
| | | using Furion.DistributedIDGenerator; |
| | | using Furion.FriendlyException; |
| | | using Furion.HttpRemote; |
| | | using Mapster; |
| | | using MediatR; |
| | | using Microsoft.AspNetCore.Components.Forms; |
| | | using Microsoft.EntityFrameworkCore; |
| | | using MiniExcelLibs; |
| | | using NetTopologySuite.Index.HPRtree; |
| | |
| | | /// 灵工命令处理器 |
| | | /// </summary> |
| | | public class EnterpriseEmployeesCommandHandler( |
| | | IMediator mediator, |
| | | IRepository<EnterpriseEmployee> rep, |
| | | IRepository<User> repUser |
| | | IRepository<User> repUser, |
| | | IRepository<EnterpriseEmployeeContract> repEnterpriseEmployeeContract |
| | | ) : |
| | | IRequestHandler<ImportEnterpriseEmployeesCommand, ImportEnterpriseEmployeesCommandResult>, |
| | | IRequestHandler<EditEnterpriseEmployeeCommand, Guid> |
| | | IRequestHandler<EditEnterpriseEmployeeCommand, Guid>, |
| | | IRequestHandler<InviteElectronSignCommand, Guid> |
| | | { |
| | | private readonly IMediator mediator = mediator; |
| | | private readonly IRepository<EnterpriseEmployee> rep = rep; |
| | | private readonly IRepository<User> repUser = repUser; |
| | | private readonly IRepository<EnterpriseEmployeeContract> repEnterpriseEmployeeContract = repEnterpriseEmployeeContract; |
| | | |
| | | /// <summary> |
| | | /// 导入灵工信息 |
| | |
| | | cancellationToken); |
| | | return entity.Id; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 邀请灵工签约 |
| | | /// </summary> |
| | | /// <param name="request"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public async Task<Guid> Handle(InviteElectronSignCommand request, CancellationToken cancellationToken) |
| | | { |
| | | var logier = JwtUtils.GetCurrentLogier(); |
| | | var entity = await rep.AsQueryable() |
| | | .Where(it => it.EnterpriseId == logier.EnterpriseId && it.Id == request.Id) |
| | | .FirstOrDefaultAsync(); |
| | | if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "灵工"); |
| | | if (entity.UserSignContractStatus == EnumTaskUserSignContractStatus.Pass) throw Oops.Oh(EnumErrorCodeType.s400, "已签约"); |
| | | if (entity.UserSignContractStatus == EnumTaskUserSignContractStatus.Effect) throw Oops.Oh(EnumErrorCodeType.s400, "已生效"); |
| | | if (entity.UserSignContractStatus == EnumTaskUserSignContractStatus.Wait) throw Oops.Oh(EnumErrorCodeType.s400, "已邀请"); |
| | | await mediator.Send(new CheckContractTemplateCommand |
| | | { |
| | | Id = request.Id |
| | | }, cancellationToken); |
| | | entity.ContractTemplateId = request.Id; |
| | | entity.UserSignContractStatus = EnumTaskUserSignContractStatus.Wait; |
| | | entity.UserSignContractTime = null; |
| | | entity.EnterpriseSignContractStatus = null; |
| | | entity.EnterpriseSignContractTime = null; |
| | | entity.ContractCode = $"{DateTime.Now:yyyyMMddHHmmss}{new Random(IDGen.NextID().GetHashCode()).Next(1000, 9999)}"; |
| | | var contract = new EnterpriseEmployeeContract |
| | | { |
| | | EnterpriseEmployeeId = entity.Id, |
| | | ContractTemplateId = entity.ContractTemplateId, |
| | | ContractCode = entity.ContractCode, |
| | | UserSignContractStatus = entity.UserSignContractStatus, |
| | | }; |
| | | await repEnterpriseEmployeeContract.InsertAsync(contract); |
| | | await rep.UpdateAsync(entity); |
| | | return entity.Id; |
| | | } |
| | | } |
| | | } |