using Senparc.Weixin.Entities.TemplateMessage; using System; using System.Data; using System.Threading.Tasks; using Wx; using Yitter.IdGenerator; using Znyc.Recruitment.Admin.Commons; 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 AuditService : BaseService, IAuditService { private readonly IApplyJobService _applyJobService; private readonly IAuditRepository _auditRepository; private readonly ICurrencyRecordRepository _currencyRecordRepository; private readonly ICurrencyService _currencyService; private readonly IMessageLogsService _messageLogsService; private readonly IRecruitmentService _recruitmentService; private readonly IUserService _userService; public AuditService( IAuditRepository repository, IApplyJobService applyJobService, IRecruitmentService recruitmentService, IUserService userService, IMessageLogsService messageLogsService, ICurrencyRecordRepository currencyRecordRepository, ICurrencyService currencyService ) : base(repository) { _auditRepository = repository; _applyJobService = applyJobService; _recruitmentService = recruitmentService; _userService = userService; _messageLogsService = messageLogsService; _currencyRecordRepository = currencyRecordRepository; _currencyService = currencyService; } /// /// 同步新增实体。 /// /// 实体 /// 事务对象 /// public override long Insert(AuditEntity entity, IDbTransaction trans = null) { long result = repository.Insert(entity, trans); return result; } /// /// 异步更新实体。 /// /// 实体 /// 主键ID /// 事务对象 /// public override async Task UpdateAsync(AuditEntity entity, long id, IDbTransaction trans = null) { bool result = await repository.UpdateAsync(entity, id, trans); return result; } /// /// 异步步新增实体。 /// /// 实体 /// 事务对象 /// public override async Task InsertAsync(AuditEntity entity, IDbTransaction trans = null) { int result = await repository.InsertAsync(entity, trans); return result; } 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 (Title like '%{0}%' or Content like '%{0}%' or Name like '%{0}%' or Phone like '%{0}%')", search.Keywords); }; PagerInfo pagerInfo = new PagerInfo { CurrenetPageIndex = search.CurrenetPageIndex, PageSize = search.PageSize }; System.Collections.Generic.List list = await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order); PageResult pageResult = new PageResult { CurrentPage = pagerInfo.CurrenetPageIndex, Items = list.MapTo(), ItemsPerPage = pagerInfo.PageSize, TotalItems = pagerInfo.RecordCount }; return pageResult; } /// /// 审核通过 /// /// /// /// public async Task AuditSuccessAsync(AuditEntity info) { CommonResult result = new CommonResult(); string messageTitle = ""; string productTitle = ""; long userId = 0; string toUser = ""; string url = ""; AuditEntity audit = new AuditEntity { Id = YitIdHelper.NextId(), ProductId = info.ProductId, ProductType = info.ProductType, AuditUserId = info.CreatedUserId, HandleStatus = (int)HandleStatusEnum.Finding, Note = "", CreatedTime = info.CreatedTime, ModifiedTime = info.CreatedTime, CreatedUserId = info.CreatedUserId }; if (info.ProductType == 1) { ApplyJobEntity apply = await _applyJobService.GetAsync(info.ProductId); if (apply.Status == (int)ProductStatusEnum.InReview) { apply.Status = (int)ProductStatusEnum.Finding; apply.ModifiedTime = DateTime.Now; if (apply.IsTop == true) { apply.TopExpireDate = DateTime.Now.AddDays(1); } apply.Content = EmojiFilterHelper.FilterEmoji(apply.Content); await _applyJobService.UpdateAsync(apply, apply.Id).ConfigureAwait(false); // productTitle = apply.Title; userId = apply.UserId; messageTitle = ReturnConst.Job_Approved; toUser = (await _userService.GetAsync(apply.UserId)).OpenId; url = string.Format("/pages/detail/detail?id={0}&type=apply", info.ProductId); } else { result.ResData = "该信息未在审核中!"; result.Success = false; return result; } } else { RecruitmentEntity recruitment = await _recruitmentService.GetAsync(info.ProductId); if (recruitment.Status == (int)ProductStatusEnum.InReview) { recruitment.Status = (int)ProductStatusEnum.Finding; recruitment.ModifiedTime = DateTime.Now; if (recruitment.IsTop == true) { recruitment.TopExpireDate = DateTime.Now.AddDays(1); } recruitment.Content = EmojiFilterHelper.FilterEmoji(recruitment.Content); recruitment.Title = EmojiFilterHelper.FilterEmoji(recruitment.Title); await _recruitmentService.UpdateAsync(recruitment, recruitment.Id).ConfigureAwait(false); productTitle = recruitment.Title; userId = recruitment.UserId; messageTitle = ReturnConst.Recruit_Approved; toUser = (await _userService.GetAsync(recruitment.UserId)).OpenId; url = string.Format("/pages/detail/detail?id={0}&type=recruitment", info.ProductId); } else { result.ResData = "该信息未在审核中!"; result.Success = false; return result; } } audit.ProductTitle = productTitle; await _auditRepository.InsertAsync(audit); MessageInputDto messageInputDto = new MessageInputDto { MessageTitle = messageTitle, ProductId = info.ProductId, Title = productTitle, UserId = userId, ProductType = info.ProductType, CreatedUserId = info.CreatedUserId, Content = "" }; await _messageLogsService.AddAsync(messageInputDto).ConfigureAwait(false); TemplateMessageData templateMessageData = new TemplateMessageData { ["thing1"] = new(messageTitle), ["time2"] = new(DateTime.Now.ToString($"yyyy{ReturnConst.Year}MM{ReturnConst.Month}dd{ReturnConst.Day} HH:mm")), ["phrase3"] = new(ReturnConst.Approved), ["thing4"] = new(ReturnConst.Approved_Note) }; //Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(templateMessageData)); await CommonHelper.SendProductAsync(templateMessageData, toUser, url).ConfigureAwait(false); result.Success = true; return result; } /// /// 审核失败 /// /// /// public async Task AuditFailAsync(AuditEntity productAuditInput) { CommonResult result = new CommonResult(); string messageTitle = ""; string productTitle = ""; long userId = 0; string toUser = ""; string url = ""; AuditEntity audit = new AuditEntity { Id = YitIdHelper.NextId(), ProductId = productAuditInput.ProductId, ProductType = productAuditInput.ProductType, AuditUserId = productAuditInput.CreatedUserId, HandleStatus = (int)HandleStatusEnum.Fail, Note = productAuditInput.Note, CreatedTime = productAuditInput.CreatedTime, ModifiedTime = productAuditInput.CreatedTime, CreatedUserId = productAuditInput.CreatedUserId }; if (productAuditInput.ProductType == 1) { ApplyJobEntity apply = await _applyJobService.GetAsync(productAuditInput.ProductId); // productTitle = apply.Title; if (apply.Status == (int)ProductStatusEnum.InReview) { apply.Status = (int)ProductStatusEnum.Fail; apply.ModifiedTime = DateTime.Now; if (apply.IsTop == true) { apply.IsTop = false; apply.TopExpireDate = Convert.ToDateTime("0001-01-01 00:00:00"); //退云币 await _currencyService.TopReturnForApplyJob(apply.UserId, apply.Id, productAuditInput.CreatedUserId); } apply.Content = EmojiFilterHelper.FilterEmoji(apply.Content); await _applyJobService.UpdateAsync(apply, apply.Id).ConfigureAwait(false); userId = apply.UserId; messageTitle = ReturnConst.Job_Audit_Failed; toUser = (await _userService.GetAsync(apply.UserId)).OpenId; url = string.Format("/pages/detail/detail?id={0}&type=apply", productAuditInput.ProductId); } else { result.ResData = "该信息未在审核中!"; result.Success = false; return result; } } else { RecruitmentEntity recruitment = await _recruitmentService.GetAsync(productAuditInput.ProductId); productTitle = recruitment.Title; if (recruitment.Status == (int)ProductStatusEnum.InReview) { recruitment.Status = (int)ProductStatusEnum.Fail; recruitment.ModifiedTime = DateTime.Now; if (recruitment.IsTop == true) { recruitment.IsTop = false; recruitment.TopExpireDate = Convert.ToDateTime("0001-01-01 00:00:00"); //退云币 await _currencyService.TopReturnForRecruitment(recruitment.UserId, recruitment.Id, productAuditInput.CreatedUserId); } recruitment.Content = EmojiFilterHelper.FilterEmoji(recruitment.Content); recruitment.Title = EmojiFilterHelper.FilterEmoji(recruitment.Title); await _recruitmentService.UpdateAsync(recruitment, recruitment.Id).ConfigureAwait(false); userId = recruitment.UserId; messageTitle = ReturnConst.Recruit_Audit_Failed; ; toUser = (await _userService.GetAsync(recruitment.UserId)).OpenId; url = string.Format("/pages/detail/detail?id={0}&type=recruitment", productAuditInput.ProductId); } else { result.ResData = "该信息未在审核中!"; result.Success = false; return result; } } audit.ProductTitle = productTitle; await _auditRepository.InsertAsync(audit); MessageInputDto messageInputDto = new MessageInputDto { MessageTitle = messageTitle, ProductId = productAuditInput.ProductId, Title = productTitle, UserId = userId, ProductType = productAuditInput.ProductType, CreatedUserId = productAuditInput.CreatedUserId, Content = "" }; await _messageLogsService.AddAsync(messageInputDto).ConfigureAwait(false); TemplateMessageData templateMessageData = new TemplateMessageData { ["thing1"] = new(messageTitle), ["time2"] = new(DateTime.Now.ToString($"yyyy{ReturnConst.Year}MM{ReturnConst.Month}dd{ReturnConst.Day} HH:mm")), ["phrase3"] = new(ReturnConst.Audit_Failed), ["thing4"] = new(productAuditInput.Note) }; await CommonHelper.SendProductAsync(templateMessageData, toUser, url).ConfigureAwait(false); result.Success = true; return result; } } }