| | |
| | | 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; |
| | |
| | | using System.Text; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using static System.Runtime.InteropServices.JavaScript.JSType; |
| | | |
| | | namespace FlexJobApi.UserServer.Application |
| | | { |
| | |
| | | /// 灵工命令处理器 |
| | | /// </summary> |
| | | public class EnterpriseEmployeesCommandHandler( |
| | | IRepository<EnterpriseEmployee> rep |
| | | IMediator mediator, |
| | | IRepository<EnterpriseEmployee> rep, |
| | | 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> |
| | | /// 导入灵工信息 |
| | |
| | | var identities = models.DistinctSelect(it => it.Identity); |
| | | var enterpriseEmployees = await rep.AsQueryable() |
| | | .Where(it => it.EnterpriseId == logier.EnterpriseId && identities.Contains(it.Identity)) |
| | | .ToListAsync(); |
| | | var userIds = enterpriseEmployees.DistinctSelect(it => it.UserId.HasValue, it => it.UserId!.Value); |
| | | var users = await repUser.AsQueryable() |
| | | .Where(it => userIds.Contains(it.Id)) |
| | | .ToListAsync(); |
| | | var successList = new List<ImportEnterpriseEmployeesCommandModel>(); |
| | | foreach (var model in models) |
| | |
| | | } |
| | | else |
| | | { |
| | | var canUpdate = true; |
| | | if (enterpriseEmployee.UserId.HasValue) |
| | | { |
| | | errors.Add("已报名无法修改信息"); |
| | | var user = users.FirstOrDefault(it => it.Id == enterpriseEmployee.UserId.Value)!; |
| | | if (user.IsReal == true) |
| | | { |
| | | canUpdate = false; |
| | | errors.Add("已实名无法修改信息"); |
| | | } |
| | | else |
| | | { |
| | | user.Name = model.Name; |
| | | user.ContactPhoneNumber = model.ContactPhoneNumber; |
| | | user.Identity = model.Identity; |
| | | user.Gender = model.Gender; |
| | | user.Birthday = model.Birthday; |
| | | user.Age = model.Age; |
| | | await repUser.UpdateAsync(user); |
| | | } |
| | | } |
| | | else |
| | | if (canUpdate) |
| | | { |
| | | enterpriseEmployee.Name = model.Name; |
| | | enterpriseEmployee.ContactPhoneNumber = model.ContactPhoneNumber; |
| | |
| | | /// <param name="request"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public Task<Guid> Handle(EditEnterpriseEmployeeCommand request, CancellationToken cancellationToken) |
| | | public async Task<Guid> Handle(EditEnterpriseEmployeeCommand request, CancellationToken cancellationToken) |
| | | { |
| | | var logier = JwtUtils.GetCurrentLogier(); |
| | | return request.SaveData<EnterpriseEmployee, EditEnterpriseEmployeeCommand>( |
| | | var entity = await request.SaveData<EnterpriseEmployee, EditEnterpriseEmployeeCommand>( |
| | | q => q.Where(it => it.EnterpriseId == logier.EnterpriseId), |
| | | it => it.EnterpriseId == logier.EnterpriseId && it.Id != request.Id && it.Identity == request.Identity, |
| | | (entity) => |
| | | (entity) => |
| | | { |
| | | if (request.Id.HasValue && entity.UserId.HasValue) |
| | | { |
| | | throw Oops.Oh(EnumErrorCodeType.s510, "已报名无法修改信息"); |
| | | var user = repUser.AsQueryable().FirstOrDefault(it => it.Id == entity.UserId.Value); |
| | | if (user!.IsReal == true) |
| | | { |
| | | throw Oops.Oh(EnumErrorCodeType.s510, "已实名无法修改信息"); |
| | | } |
| | | else |
| | | { |
| | | user.Name = request.Name; |
| | | user.ContactPhoneNumber = request.ContactPhoneNumber; |
| | | user.Identity = request.Identity; |
| | | user.Birthday = request.Identity.GetBirthday(); |
| | | user.Gender = request.Gender; |
| | | user.Age = request.Age; |
| | | repUser.Update(user); |
| | | } |
| | | } |
| | | request.Adapt(entity); |
| | | }, |
| | | 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; |
| | | } |
| | | } |
| | | } |