You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
282 lines
13 KiB
282 lines
13 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Yitter.IdGenerator;
|
|
using Znyc.Cloudcar.Admin.Commons;
|
|
using Znyc.Cloudcar.Admin.Commons.Entitys;
|
|
using Znyc.Cloudcar.Admin.Commons.Enums;
|
|
using Znyc.Cloudcar.Admin.Commons.Extensions;
|
|
using Znyc.Cloudcar.Admin.Commons.Helpers;
|
|
using Znyc.Cloudcar.Admin.Commons.Mapping;
|
|
using Znyc.Cloudcar.Admin.Commons.Pages;
|
|
using Znyc.Cloudcar.Admin.Commons.Services;
|
|
using Znyc.Cloudcar.Admin.Security.Dtos;
|
|
using Znyc.Cloudcar.Admin.Security.Entitys;
|
|
using Znyc.Cloudcar.Admin.Security.IRepositories;
|
|
using Znyc.Cloudcar.Admin.Security.IServices;
|
|
|
|
namespace Znyc.Cloudcar.Admin.Security.Services
|
|
{
|
|
/// <summary>
|
|
/// 招聘服务
|
|
/// </summary>
|
|
public class CloudcarService : BaseService<CloudcarEntity, CloudcarOutputDto, long>, ICloudcarService
|
|
{
|
|
private readonly IAuditRepository _auditRepository;
|
|
private readonly IDictionaryService _dictionaryService;
|
|
private readonly IIndustryJobsService _industryJobsService;
|
|
private readonly ICloudcarRepository _CloudcarRepository;
|
|
private readonly IRegionRepository _regionRepository;
|
|
private readonly IUserRepository _userRepository;
|
|
private readonly IWxUnifyUserRepository _wxUnifyUserRepository;
|
|
private readonly ICallFeedbackRepository _callFeedbackRepository;
|
|
|
|
public CloudcarService(
|
|
ICloudcarRepository repository,
|
|
IDictionaryService dictionaryService,
|
|
IIndustryJobsService industryJobsService,
|
|
IRegionRepository regionRepository,
|
|
IAuditRepository auditRepository,
|
|
IUserRepository userRepository,
|
|
IWxUnifyUserRepository wxUnifyUserRepository,
|
|
ICallFeedbackRepository callFeedbackRepository
|
|
) : base(repository)
|
|
{
|
|
_CloudcarRepository = repository;
|
|
_dictionaryService = dictionaryService;
|
|
_industryJobsService = industryJobsService;
|
|
_regionRepository = regionRepository;
|
|
_auditRepository = auditRepository;
|
|
_userRepository = userRepository;
|
|
_wxUnifyUserRepository = wxUnifyUserRepository;
|
|
_callFeedbackRepository = callFeedbackRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 异步新增数据
|
|
/// </summary>
|
|
/// <param name="intput">ʵ��</param>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> InsertAsync(CloudcarEntity intput)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
intput.Id = YitIdHelper.NextId();
|
|
intput.State = (int)ProductStatusEnum.Review;
|
|
intput.UserId = 1;
|
|
intput.IsPublic = true;
|
|
intput.AreaId = 0;
|
|
intput.SerialNumber =
|
|
StringHelper.GetSerialNumber(ProductTypeEnum.Cloudcar, intput.IndustryId, intput.JobId);
|
|
intput.ModifiedTime = DateTime.Now;
|
|
intput.RefreshDate = DateTime.Now;
|
|
result.Success = await repository.InsertAsync(intput) > 0 ? true : false;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 异步修改数据
|
|
/// </summary>
|
|
/// <param name="tinfo"></param>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> UpdateAsync(CloudcarEntity tinfo)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
CloudcarEntity 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.Phone = tinfo.Phone;
|
|
info.IndustryId = tinfo.IndustryId;
|
|
info.JobId = tinfo.JobId;
|
|
info.ProvinceId = tinfo.ProvinceId;
|
|
info.CityId = tinfo.CityId;
|
|
info.State = tinfo.State;
|
|
info.IsTop = tinfo.IsTop;
|
|
info.IsPublic = tinfo.IsPublic;
|
|
info.TopExpireDate = tinfo.TopExpireDate;
|
|
info.Welfare = tinfo.Welfare;
|
|
info.Address = tinfo.Address;
|
|
info.ModifiedTime = tinfo.ModifiedTime;
|
|
info.ModifiedUserId = tinfo.ModifiedUserId;
|
|
await repository.UpdateAsync(info, tinfo.Id).ConfigureAwait(false);
|
|
result.Success = true;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
|
|
/// </summary>
|
|
/// <param name="search">查询的条件</param>
|
|
/// <returns>指定对象的集合</returns>
|
|
public async Task<PageResult<CloudcarOutputDto>> FindWithPagerSearchAsync(SearchCloudcarModel search)
|
|
{
|
|
bool order = search.Order == "asc" ? false : true;
|
|
string where = GetDataPrivilege(false);
|
|
if (!string.IsNullOrEmpty(search.Keywords))
|
|
{
|
|
@where += $" and (Title like '%{search.Keywords}%' or Content like '%{search.Keywords}%' or Phone like '%{search.Keywords}%' " +
|
|
$"or SerialNumber like '%{search.Keywords}%' or Address like '%{search.Keywords}%')";
|
|
}
|
|
|
|
//if (search.State == (int)ProductStatusEnum.Pass)
|
|
//{
|
|
// @where += $" and (State=1 or State=2 )";
|
|
//}
|
|
|
|
//if (search.State >= 0 && search.State != (long)ProductStatusEnum.Pass)
|
|
//{
|
|
// @where += $" and State={search.State}";
|
|
//}
|
|
|
|
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}";
|
|
}
|
|
|
|
List<UserOutputDto> users = (await _userRepository.GetListWhereAsync(" `State`=10")).MapTo<UserOutputDto>();
|
|
if (!string.IsNullOrEmpty(search.UserName))
|
|
{
|
|
List<long> uIds = users.Where(x => x.UserName.Contains(search.UserName)).Select(x => x.Id).ToList();
|
|
@where += $" and UserId in ({string.Join(",", uIds.ToArray())})";
|
|
}
|
|
//行业岗位
|
|
List<IndustryJobsOutputDto> industryJobs = await _industryJobsService.GetAllListAsync();
|
|
//福利待遇
|
|
List<DictionaryListOutput> welfares = await _dictionaryService.GetListByPidAsync(CommonConst.Dictionary_Welfare);
|
|
//云平台统一用户信息
|
|
List<string> uninIds = users.Select(x => x.UnionId).ToList();
|
|
List<WxUnifyUserOutputDto> wxUnifyUsers = (await _wxUnifyUserRepository.GetListWhereAsync($" IsDeleted=0 AND UnionId IN ('{string.Join("','", uninIds.ToArray())}')"))
|
|
.MapTo<WxUnifyUserOutputDto>();
|
|
PagerInfo pagerInfo = new PagerInfo
|
|
{
|
|
CurrenetPageIndex = search.CurrenetPageIndex,
|
|
PageSize = search.PageSize
|
|
};
|
|
List<CloudcarEntity> list = await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order);
|
|
List<CloudcarOutputDto> listDto = list.MapTo<CloudcarOutputDto>();
|
|
foreach (CloudcarOutputDto item in listDto)
|
|
{
|
|
item.IndustryName = industryJobs.Find(x => x.Id == item.IndustryId)?.Name;
|
|
item.JobName = industryJobs.Find(x => x.Id == item.JobId)?.Name;
|
|
string[] welfare = item.Welfare.Split(",");
|
|
item.WelfareList = welfares.FindAll(x => welfare.Contains(x.Id.ToString()));
|
|
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);
|
|
item.Top = item.IsTop ? "已置顶" : "未置顶";
|
|
item.TopExpireDate = item.IsTop ? item.TopExpireDate : null;
|
|
item.Public = item.IsPublic ? "已公开" : "未公开";
|
|
item.StatusName = EnumExtensions
|
|
.ParseEnum(typeof(ProductStatusEnum), item.State.ToString()).ToDescription();
|
|
if (item.State == (int)ProductStatusEnum.Fail)
|
|
{
|
|
string key = $" ProductId={item.Id} AND ProductType=2 AND HandleStatus={item.State} 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=2")).MapTo<CallFeedbackOutputDto>();
|
|
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.State.ToString()).ToDescription();
|
|
if (callFeedback.IsRead == false && item.IsReadForCallFeedback == false)
|
|
{
|
|
item.IsReadForCallFeedback = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
PageResult<CloudcarOutputDto> pageResult = new PageResult<CloudcarOutputDto>
|
|
{
|
|
CurrentPage = pagerInfo.CurrenetPageIndex,
|
|
Items = listDto,
|
|
ItemsPerPage = pagerInfo.PageSize,
|
|
TotalItems = pagerInfo.RecordCount
|
|
};
|
|
return pageResult;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public async Task<CloudcarOutputDto> GetById(long id)
|
|
{
|
|
CloudcarOutputDto CloudcarDto = await GetOutDtoAsync(id);
|
|
//行业岗位
|
|
List<IndustryJobsOutputDto> industryJobs = await _industryJobsService.GetAllListAsync();
|
|
//福利待遇
|
|
List<DictionaryListOutput> welfares = await _dictionaryService.GetListByPidAsync(CommonConst.Dictionary_Welfare);
|
|
|
|
List<UserOutputDto> users = (await _userRepository.GetListWhereAsync(" `State`=10")).MapTo<UserOutputDto>();
|
|
|
|
CloudcarDto.IndustryName = industryJobs.Find(x => x.Id == CloudcarDto.IndustryId)?.Name;
|
|
CloudcarDto.JobName = industryJobs.Find(x => x.Id == CloudcarDto.JobId)?.Name;
|
|
string[] welfare = CloudcarDto.Welfare.Split(",");
|
|
CloudcarDto.WelfareList = welfares.FindAll(x => welfare.Contains(x.Id.ToString()));
|
|
UserOutputDto user = users.Find(x => x.Id == CloudcarDto.UserId);
|
|
CloudcarDto.UserName = user?.UserName ?? CommonConst.Default_UserName;
|
|
CloudcarDto.AvatarUrl = CommonConst.Default_Image_Prefix + (user?.AvatarUrl ?? CommonConst.Default_AvataUrl);
|
|
CloudcarDto.Top = CloudcarDto.IsTop ? "已置顶" : "未置顶";
|
|
CloudcarDto.TopExpireDate = CloudcarDto.IsTop ? CloudcarDto.TopExpireDate : null;
|
|
CloudcarDto.Public = CloudcarDto.IsPublic ? "已公开" : "未公开";
|
|
CloudcarDto.StatusName = EnumExtensions
|
|
.ParseEnum(typeof(ProductStatusEnum), CloudcarDto.State.ToString()).ToDescription();
|
|
return CloudcarDto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 下架招聘信息
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="userId"></param>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> RevocationAsync(long id, long userId)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
CloudcarEntity info = await repository.GetAsync(id);
|
|
if (!(info?.Id > 0))
|
|
{
|
|
result.Success = false;
|
|
result.ErrMsg = "招聘信息不存在";
|
|
return result;
|
|
}
|
|
info.State = (int)ProductStatusEnum.Cancel;
|
|
info.ModifiedUserId = userId;
|
|
info.ModifiedTime = DateTime.Now;
|
|
await repository.UpdateAsync(info, info.Id).ConfigureAwait(false);
|
|
result.Success = true;
|
|
return result;
|
|
}
|
|
}
|
|
}
|