using System; using System.Data; using System.Linq; using System.Threading.Tasks; using Yitter.IdGenerator; using Znyc.Recruitment.Admin.Commons; using Znyc.Recruitment.Admin.Commons.Entitys; using Znyc.Recruitment.Admin.Commons.Enums; using Znyc.Recruitment.Admin.Commons.Extensions; using Znyc.Recruitment.Admin.Commons.Helpers; using Znyc.Recruitment.Admin.Commons.Mapping; using Znyc.Recruitment.Admin.Commons.Pages; using Znyc.Recruitment.Admin.Commons.Services; using Znyc.Recruitment.Admin.Security.Dtos; using Znyc.Recruitment.Admin.Security.Entitys; using Znyc.Recruitment.Admin.Security.IRepositories; using Znyc.Recruitment.Admin.Security.IServices; namespace Znyc.Recruitment.Admin.Security.Services { /// /// ��ְ���� /// public class ApplyJobService : BaseService, IApplyJobService { private readonly IApplyJobRepository _applyJobRepository; private readonly IAuditRepository _auditRepository; public readonly IDictionaryService _dictionaryService; private readonly IIndustryJobsService _industryJobsService; private readonly IRegionRepository _regionRepository; private readonly IUserRepository _userRepository; private readonly IWxUnifyUserRepository _wxUnifyUserRepository; private readonly ICallFeedbackRepository _callFeedbackRepository; public ApplyJobService(IApplyJobRepository repository, IDictionaryService dictionaryService, IRegionRepository regionRepository, IIndustryJobsService industryJobsService, IAuditRepository auditRepository, IUserRepository userRepository, ICallFeedbackRepository callFeedbackRepository, IWxUnifyUserRepository wxUnifyUserRepository ) : base(repository) { _applyJobRepository = repository; _dictionaryService = dictionaryService; _regionRepository = regionRepository; _industryJobsService = industryJobsService; _auditRepository = auditRepository; _userRepository = userRepository; _wxUnifyUserRepository = wxUnifyUserRepository; _callFeedbackRepository = callFeedbackRepository; } /// /// ͬ������ʵ�塣 /// /// ʵ�� /// ������� /// public override long Insert(ApplyJobEntity entity, IDbTransaction trans = null) { long result = repository.Insert(entity, trans); return result; } /// /// �첽����ʵ�塣 /// /// ʵ�� /// ����ID /// ������� /// public override async Task UpdateAsync(ApplyJobEntity entity, long id, IDbTransaction trans = null) { bool result = await repository.UpdateAsync(entity, id, trans); return result; } /// /// 异步新增数据 /// /// ʵ�� /// public async Task InsertAsync(ApplyJobEntity input) { CommonResult result = new CommonResult(); input.Id = YitIdHelper.NextId(); input.Status = (int)ProductStatusEnum.Finding; input.UserId = 1001; input.IsPublic = true; input.SerialNumber = StringHelper.GetSerialNumber(ProductTypeEnum.ApplyJob, input.IndustryId, input.JobId); input.ModifiedTime = DateTime.Now; input.RefreshDate = DateTime.Now; input.AreaId = ""; input.Address = input.Address.TrimEnd(','); input.IsRealAuthentication = true; input.IsTop = false; if (input.BirthDate != null) { input.Age = StringHelper.GetAgeByBirthDate(input.BirthDate); } result.Success = await repository.InsertAsync(input) > 0 ? true : false; return result; } public async Task UpdateAsync(ApplyJobEntity tinfo) { CommonResult result = new CommonResult(); ApplyJobEntity info = await repository.GetAsync(tinfo.Id); if (!(info?.Id > 0)) { result.Success = false; result.ErrMsg = "求职信息不存在"; return result; } // info.Title = tinfo.Title; info.Content = tinfo.Content; // info.Name = tinfo.Name; info.Phone = tinfo.Phone; info.IndustryId = tinfo.IndustryId; info.JobId = tinfo.JobId; info.ProvinceId = tinfo.ProvinceId; info.CityId = tinfo.CityId; info.Status = tinfo.Status; info.IsTop = tinfo.IsTop; info.IsHaveDriverLicense = tinfo.IsHaveDriverLicense; info.IsPublic = tinfo.IsPublic; // info.TopExpireTime = tinfo.TopExpireTime; info.ExperienceId = tinfo.ExperienceId; info.ModifiedUserId = tinfo.ModifiedUserId; info.ModifiedTime = tinfo.ModifiedTime; info.BirthDate = tinfo.BirthDate; if (info.BirthDate != null) { info.Age = StringHelper.GetAgeByBirthDate(info.BirthDate); } info.Gender = tinfo.Gender; info.Address = tinfo.Address; await repository.UpdateAsync(info, tinfo.Id).ConfigureAwait(false); result.Success = true; return result; } /// /// 求职分页查询 /// /// 查询条件 /// public async Task> FindWithPagerSearchAsync(SearchRecruitmentModel search) { bool order = search.Order == "asc" ? false : true; string where = GetDataPrivilege(false); if (!string.IsNullOrEmpty(search.Keywords)) { @where += $" and (Content like '%{search.Keywords}%' or Phone like '%{search.Keywords}%' or SerialNumber like '%{search.Keywords}%' or Address like '%{search.Keywords}%')"; } if (search.Status == (int)ProductStatusEnum.Pass) { @where += " and (Status=1 or Status=2 )"; } if (search.Status >= 0 && search.Status != (int)ProductStatusEnum.Pass) { @where += $" and Status={search.Status}"; } if (!string.IsNullOrEmpty(search.StartTime)) { @where += $" and ModifiedTime >='{search.StartTime} 00:00:00'"; } if (!string.IsNullOrEmpty(search.EndTime)) { @where += $" and ModifiedTime <='{search.EndTime} 23:59:59'"; } if (search.industryId > 0) { @where += $" and IndustryId={search.industryId}"; } if (search.jobId > 0) { @where += $" and JobId={search.jobId}"; } System.Collections.Generic.List users = (await _userRepository.GetListWhereAsync(" `Status`=1")).MapTo(); if (!string.IsNullOrEmpty(search.UserName)) { System.Collections.Generic.List uIds = users.Where(x => x.UserName.Contains(search.UserName)).Select(x => x.Id).ToList(); @where += $" and UserId in ({string.Join(",", uIds.ToArray())})"; } //行业岗位 System.Collections.Generic.List industryJobs = await _industryJobsService.GetAllListAsync(); //工作经验 System.Collections.Generic.List experiences = await _dictionaryService.GetListByPidAsync(CommonConst.Dictionary_Experience); //云平台统一用户信息 System.Collections.Generic.List uninIds = users.Select(x => x.UnionId).ToList(); System.Collections.Generic.List wxUnifyUsers = (await _wxUnifyUserRepository.GetListWhereAsync($" IsDeleted=0 AND UnionId IN ('{string.Join("','", uninIds.ToArray())}')")) .MapTo(); PagerInfo pagerInfo = new PagerInfo { CurrenetPageIndex = search.CurrenetPageIndex, PageSize = search.PageSize }; System.Collections.Generic.List list = await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order); System.Collections.Generic.List listDto = list.MapTo(); foreach (ApplyJobOutputDto item in listDto) { item.ExperienceName = experiences.Find(x => x.Id == item.ExperienceId)?.Value; item.IndustryName = industryJobs.Find(x => x.Id == item.IndustryId)?.Name; item.JobName = industryJobs.Find(x => x.Id == item.JobId)?.Name; item.DriverLicense = ""; if (item.IsHaveDriverLicense != null) { item.DriverLicense = item.IsHaveDriverLicense == true ? "有驾驶证" : "无驾驶证"; } item.Top = item.IsTop ? "已置顶" : "未置顶"; item.TopExpireDate = item.IsTop ? item.TopExpireDate : null; item.Public = item.IsPublic ? "已公开" : "未公开"; item.StatusName = EnumExtensions .ParseEnum(typeof(ProductStatusEnum), item.Status.ToString()).ToDescription(); UserOutputDto user = users.Find(x => x.Id == item.UserId); item.UserName = user?.UserName ?? CommonConst.Default_UserName; item.AvatarUrl = CommonConst.Default_Image_Prefix + (user?.AvatarUrl ?? CommonConst.Default_AvataUrl); if (item.Status == (int)ProductStatusEnum.Fail) { string key = $" ProductId={ item.Id} AND ProductType=1 AND HandleStatus={item.Status} ORDER BY CreatedTime DESC LIMIT 1"; item.Note = (await _auditRepository.GetWhereAsync(key))?.Note ?? ""; } item.NickName = wxUnifyUsers.Find(x => x.UnionId == user.UnionId)?.NickName ?? CommonConst.Default_UserName; item.WxAvatarUrl = wxUnifyUsers.Find(x => x.UnionId == user.UnionId)?.AvatarUrl ?? (CommonConst.Default_Image_Prefix + CommonConst.Default_AvataUrl); //通话评价 item.CallFeedbacks = (await _callFeedbackRepository.GetListWhereAsync($" ProductId={item.Id} AND ProductType=1")).MapTo(); foreach (var callFeedback in item.CallFeedbacks) { var callUser = users.Find(x => x.Id == callFeedback.UserId); callFeedback.Phone = callUser.Phone; callFeedback.NickName = wxUnifyUsers.Find(x => x.UnionId == callUser.UnionId)?.NickName ?? CommonConst.Default_UserName; callFeedback.WxAvatarUrl = wxUnifyUsers.Find(x => x.UnionId == callUser.UnionId)?.AvatarUrl ?? (CommonConst.Default_Image_Prefix + CommonConst.Default_AvataUrl); callFeedback.Content = EnumExtensions .ParseEnum(typeof(CallFeedbackStatusEnum), callFeedback.Status.ToString()).ToDescription(); if (callFeedback.IsRead == false && item.IsReadForCallFeedback == false) { item.IsReadForCallFeedback = true; } } } PageResult pageResult = new PageResult { CurrentPage = pagerInfo.CurrenetPageIndex, Items = listDto, ItemsPerPage = pagerInfo.PageSize, TotalItems = pagerInfo.RecordCount }; return pageResult; } /// /// 单条查询 /// /// /// public async Task GetById(long id) { ApplyJobOutputDto applyDto = await GetOutDtoAsync(id); //行业岗位 System.Collections.Generic.List industryJobs = await _industryJobsService.GetAllListAsync(); //工作经验 System.Collections.Generic.List experiences = await _dictionaryService.GetListByPidAsync(CommonConst.Dictionary_Experience); // System.Collections.Generic.List users = (await _userRepository.GetListWhereAsync(" `Status`=1")).MapTo(); applyDto.ExperienceName = experiences.Find(x => x.Id == applyDto.ExperienceId)?.Value; applyDto.IndustryName = industryJobs.Find(x => x.Id == applyDto.IndustryId)?.Name; applyDto.JobName = industryJobs.Find(x => x.Id == applyDto.JobId)?.Name; applyDto.DriverLicense = ""; if (applyDto.IsHaveDriverLicense != null) { applyDto.DriverLicense = applyDto.IsHaveDriverLicense == true ? "有驾驶证" : "无驾驶证"; } applyDto.Top = applyDto.IsTop ? "已置顶" : "未置顶"; applyDto.TopExpireDate = applyDto.IsTop ? applyDto.TopExpireDate : null; applyDto.Public = applyDto.IsPublic ? "已公开" : "未公开"; applyDto.StatusName = EnumExtensions .ParseEnum(typeof(ProductStatusEnum), applyDto.Status.ToString()).ToDescription(); UserOutputDto user = users.Find(x => x.Id == applyDto.UserId); applyDto.UserName = user?.UserName ?? CommonConst.Default_UserName; applyDto.AvatarUrl = CommonConst.Default_Image_Prefix + (user?.AvatarUrl ?? CommonConst.Default_AvataUrl); return applyDto; } /// /// 下架求职信息 /// /// /// /// public async Task RevocationAsync(long id, long userId) { CommonResult result = new CommonResult(); ApplyJobEntity info = await repository.GetAsync(id); if (!(info?.Id > 0)) { result.Success = false; result.ErrMsg = "求职信息不存在"; return result; } info.Status = (int)ProductStatusEnum.Revocation; info.ModifiedUserId = userId; info.ModifiedTime = DateTime.Now; await repository.UpdateAsync(info, info.Id).ConfigureAwait(false); result.Success = true; return result; } } }