using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Znyc.Recruitment.Admin.Commons; using Znyc.Recruitment.Admin.Commons.Entitys; 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 FeedbackService : BaseService, IFeedbackService { private readonly IFeedbackRepository _feedbackRepository; private readonly IFeedbackPicRepository _feedbackPicRepository; private readonly IUserRepository _userRepository; public FeedbackService(IFeedbackRepository repository, IFeedbackPicRepository feedbackPicRepository, IUserRepository userRepository ) : base(repository) { _feedbackRepository = repository; _feedbackPicRepository = feedbackPicRepository; _userRepository = userRepository; } /// /// 意见反馈分页查询 /// /// 查询条件 /// public async Task> FindWithPagerSearchAsync(SearchFeedbackModel search) { bool order = search.Order == "asc" ? false : true; string where = GetDataPrivilege(false); if (search.Status >= 0) { @where += $" and Status={search.Status}"; } if (!string.IsNullOrEmpty(search.StartTime)) { @where += $" and CreatedTime >='{search.StartTime} 00:00:00'"; } if (!string.IsNullOrEmpty(search.EndTime)) { @where += $" and CreatedTime <='{search.EndTime} 23:59:59'"; } PagerInfo pagerInfo = new PagerInfo { CurrenetPageIndex = search.CurrenetPageIndex, PageSize = search.PageSize }; List list = (await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order)).MapTo(); List usersList = (await _userRepository.GetListWhereAsync(" `Status`=1")).MapTo(); List picList = (await _feedbackPicRepository.GetListWhereAsync(" IsEnabled=true order by Sort")).MapTo(); foreach (var item in list) { var user = usersList.Find(x => x.Id == item.UserId); item.UserName = user.UserName; item.Phone = user.Phone; item.AvatarUrl = CommonConst.Default_Image_Prefix + user.AvatarUrl; item.FeedbackPic = picList.FindAll(x => x.FeedbackId == item.Id).Select(x => CommonConst.Default_FeedbackPic_Prefix + x.PicUrl).ToList(); } PageResult pageResult = new PageResult { CurrentPage = pagerInfo.CurrenetPageIndex, Items = list, ItemsPerPage = pagerInfo.PageSize, TotalItems = pagerInfo.RecordCount }; return pageResult; } /// /// 编辑意见反馈 /// /// /// public async Task UpdateAsync(FeedbackEntity input) { CommonResult result = new CommonResult(); FeedbackEntity info = await repository.GetAsync(input.Id); if (!(info?.Id > 0)) { result.Success = false; result.ErrMsg = "信息不存在"; return result; } info.Status = input.Status; await repository.UpdateAsync(info, input.Id).ConfigureAwait(false); result.Success = true; return result; } } }