using System.Threading.Tasks; using Wx; using Znyc.Recruitment.Admin.Commons; using Znyc.Recruitment.Admin.Commons.Cache; using Znyc.Recruitment.Admin.Commons.Const; using Znyc.Recruitment.Admin.Commons.Entitys; using Znyc.Recruitment.Admin.Commons.Enums; 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 CertificationService : BaseService, ICertificationService { private readonly ICacheService _cacheService; private readonly ICertificationRepository _certificationRepository; private readonly ICurrencyRecordRepository _currencyRecordRepository; private readonly ICurrencyService _currencyService; private readonly IMessageLogsService _messageLogsService; private readonly IUserRepository _userRepository; private readonly IApplyJobRepository _applyJobRepository; private readonly IRecruitmentRepository _recruitmentRepository; public CertificationService( ICertificationRepository repository, IMessageLogsService messageLogsService, IUserRepository userRepository, ICurrencyService currencyService, ICurrencyRecordRepository currencyRecordRepository, IApplyJobRepository applyJobRepository, IRecruitmentRepository recruitmentRepository, ICacheService cacheService ) : base(repository) { _certificationRepository = repository; _messageLogsService = messageLogsService; _userRepository = userRepository; _currencyRecordRepository = currencyRecordRepository; _currencyService = currencyService; _cacheService = cacheService; _applyJobRepository = applyJobRepository; _recruitmentRepository = recruitmentRepository; } public async Task> FindWithPagerSearchAsync(SearchUserModel search) { bool order = search.Order == "asc" ? false : true; string where = GetDataPrivilege(false); if (!string.IsNullOrEmpty(search.Keywords)) { @where += string.Format( " and (IdCard like '%{0}%' or IssuedAddress like '%{0}%' or Name like '%{0}%')", search.Keywords); } if (search.Status >= 0) { @where += string.Format(" and Status={0}", 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'"; } 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(); PageResult pageResult = new PageResult { CurrentPage = pagerInfo.CurrenetPageIndex, Items = listDto, ItemsPerPage = pagerInfo.PageSize, TotalItems = pagerInfo.RecordCount }; return pageResult; } /// /// 实名认证审核通过 /// /// /// public async Task AuditSuccessAsync(CertificationEntity info) { string where = string.Format(" Id={0} and IsDeleted=0", info.Id); CertificationEntity certification = await _certificationRepository.GetWhereAsync(where); if (certification == null) { return false; } certification.Status = (int)UserCertificationEnum.Pass; certification.ModifiedUserId = info.ModifiedUserId; bool bl = await _certificationRepository.UpdateAsync(certification, certification.Id) .ConfigureAwait(false); UserEntity user = await _userRepository.GetUserByUnionId(certification.UnionId); string messageTitle = ""; if (bl) { string toUser = user.OpenId; await CommonHelper.SendAuditSuccessAsync(toUser); messageTitle = ReturnConst.RealName_Approved; //审核通过增加积分 //string key = string.Format("UserId = {0} AND CurrencyType = {1} AND IsDeleted = 0", // user.Id, (int)OperatingCreditsTypeEnum.RealName); //CurrencyRecordEntity currencyRecord = await _currencyRecordRepository.GetWhereAsync(key); //if (currencyRecord == null) //{ // await _currencyService.AddCurrencyByCreditsType(user.Id, CurrencyConst.RealName, // (int)OperatingCreditsTypeEnum.RealName, certification.Id, info.ModifiedUserId); //} await RemoveCertificationCacheAsync(user.Id); //更新用户表 user.IsRealAuthentication = true; user.UserName = EmojiFilterHelper.FilterEmoji(user.UserName); await _userRepository.UpdateAsync(user, user.Id); //更新求职表 await _applyJobRepository.UpdateIsRealAuthenticationAsync(user.Id); //更新招聘表 await _recruitmentRepository.UpdateIsRealAuthenticationAsync(user.Id); //删除用户信息缓存 await RemoveUserCacheAsync(user.Id); //删除用户云币列表 //await RemoveCurrencyIntroCacheAsync(user.Id); } MessageInputDto messageInputDto = new MessageInputDto { MessageTitle = messageTitle, ProductId = certification.Id, Title = "", UserId = (await _userRepository.GetUserByUnionId(certification.UnionId)).Id, ProductType = 3, //系统通知 CreatedUserId = info.ModifiedUserId, Content = "" }; await _messageLogsService.AddAsync(messageInputDto); return bl; } /// /// 实名认证审核失败 /// /// /// public async Task AuditFailAsync(CertificationEntity info) { CommonResult result = new CommonResult(); string where = string.Format("Id={0} and IsDeleted=0", info.Id); CertificationEntity certification = await _certificationRepository.GetWhereAsync(where); certification.Status = (int)UserCertificationEnum.Fail; certification.ModifiedUserId = info.ModifiedUserId; UserEntity user = await _userRepository.GetUserByUnionId(certification.UnionId); bool bl = await _certificationRepository.UpdateAsync(certification, certification.Id) .ConfigureAwait(false); string messageTitle = ""; if (bl) { string toUser = user.OpenId; await CommonHelper.SendAuditFailAsync(toUser); messageTitle = ReturnConst.RealName_Audit_Failed; await RemoveCertificationCacheAsync(user.Id); //更新用户表 user.IsRealAuthentication = false; await _userRepository.UpdateAsync(user, user.Id); //删除用户信息缓存 await RemoveUserCacheAsync(user.Id); } MessageInputDto messageInputDto = new MessageInputDto { MessageTitle = messageTitle, ProductId = certification.Id, Title = "", UserId = (await _userRepository.GetUserByUnionId(certification.UnionId)).Id, ProductType = 3, //系统通知 CreatedUserId = info.ModifiedUserId, Content = "" }; await _messageLogsService.AddAsync(messageInputDto); return bl; } /// /// 删除用户缓存 /// /// /// public async Task RemoveUserCacheAsync(long id) { string key = string.Format("user:{0}", id); await _cacheService.RemoveAsync(key); } /// /// 删除用户实名认证缓存 /// /// /// public async Task RemoveCertificationCacheAsync(long id) { string key = string.Format("certification:{0}", id); await _cacheService.RemoveAsync(key); } /// /// 删除云币来源缓存 /// /// /// public async Task RemoveCurrencyIntroCacheAsync(long id) { string key = string.Format("currency:intro:{0}", id); await _cacheService.RemoveAsync(key); } /// /// 新增实名缓存 /// /// /// public async Task SetUserCertificationCacheAsync(long id, CertificationOutput certificationOutput) { string key = string.Format("certification:{0}", id); await _cacheService.AddAsync(key, certificationOutput); } } }