using GDZZ.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using GDZZ.Application.Entity;
using Microsoft.AspNetCore.Authorization;
using StackExchange.Profiling.Internal;
using System;
using System.Collections.Generic;
using GDZZ.Core.Entity;
using Furion.FriendlyException;
using Senparc.CO2NET.Extensions;
namespace GDZZ.Application
{
///
/// 小程序招聘列表服务
///
[ApiDescriptionSettings("Application", Name = "MiniResume", Order = 1)]
public class MiniResumeService : IMiniResumeService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep; //招聘列表仓储
private readonly SqlSugarRepository baseUser; //基础用户仓储
private readonly SqlSugarRepository CompanyRep; //公司仓储
private readonly SqlSugarRepository _sysTenantRep;// 租户表仓储
private readonly SqlSugarRepository ComsumeRep; //消费记录仓储
private readonly SqlSugarRepository balance; //余额仓储
public MiniResumeService(SqlSugarRepository rep,
SqlSugarRepository baseUser,
SqlSugarRepository _sysTenantRep,
SqlSugarRepository ComsumeRep,
SqlSugarRepository balance,
SqlSugarRepository CompanyRep)
{
_rep = rep;
this.balance = balance;
this.ComsumeRep = ComsumeRep;
this._sysTenantRep = _sysTenantRep;
this.baseUser = baseUser;
this.CompanyRep = CompanyRep;
}
#region 求职端
///
/// 招聘列表
///
///
///
[HttpGet("/Mini/GetResumeList")]
[AllowAnonymous]
public async Task GetResumeList([FromQuery] MiniResumeInput input)
{
var entities = await _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.RegionName), u => u.RegionName.Contains(input.RegionName.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchValue), u => u.Title.Contains(input.SearchValue))
.WhereIF(!string.IsNullOrWhiteSpace(input.Salary), u => u.Salary.Contains(input.Salary.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Record), u => u.Record.Contains(input.Record.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Level), u => u.Record.Contains(input.Level.Trim()))
.WhereIF(!input.TypeEnum.IsEmpty(), u => u.Types == input.TypeEnum)
.Where(u => u.Status == input.Status)
.LeftJoin((u, y) => u.CompanyID == y.Id) //关联公司信息
.Select((u, y) => new MiniResumeOutput
{
CompanyID = y.Id,
CompanyName = y.Name,
Logo = y.logo,
Id = u.Id,
Info = u.Info,
Sak = u.Sak,
Salary = u.Salary,
Title = u.Title,
Time = u.CreatedTime.Value.ToString("yyyy/MM/dd"),
RegionName = u.RegionName,
Record = u.Record,
Level = u.Level,
Status = u.Status,
TypeEnum = u.Types
}).MergeTable()
.OrderBy(u => u.TypeEnum)
.OrderByDescending(u => u.Time)
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
///
/// 初始化
///
///
///
[HttpGet("/Mini/GetCompanyResumeList")]
[AllowAnonymous]
public async Task GetCompanyResumeList([FromQuery] MiniResumeInput input)
{
var entities = await _rep.AsQueryable()
.LeftJoin((u, y) => u.CompanyID == y.Id) //关联公司信息
.Where(u => u.CompanyID == input.CompanyID)
.Select((u, y) => new MiniResumeOutput
{
CompanyID = y.Id,
CompanyName = y.Name,
Logo = y.logo,
Id = u.Id,
Info = u.Info,
Sak = u.Sak,
Salary = u.Salary,
Title = u.Title,
Time = u.CreatedTime.Value.ToString("yyyy/MM/dd"),
RegionName = u.RegionName,
Record = u.Record,
Level = u.Level,
Status = u.Status
}).MergeTable()
.ToListAsync();
return entities;
}
///
/// 搜索招聘信息
///
///
///
[AllowAnonymous]
[HttpGet("/Mini/SearchRetFun")]
public async Task SearchRetFun(MiniResumeInput input)
{
var entities = await _rep.AsQueryable()
.LeftJoin((u, y) => u.CompanyID == y.Id) //关联公司信息
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchValue), u => u.Title.Contains(input.SearchValue))
.Where(u => u.Status == ResumeStatusEnum.Release)
//.WhereIF(!string.IsNullOrWhiteSpace(input.SearchValue), u => u.CompanyName.Contains(input.SearchValue))
//.WhereIF(!string.IsNullOrWhiteSpace(input.SearchValue), u => u.Level.Contains(input.SearchValue))
//.WhereIF(!string.IsNullOrWhiteSpace(input.SearchValue), u => u.RegionName.Contains(input.SearchValue))
//.WhereIF(!string.IsNullOrWhiteSpace(input.SearchValue), u => u.Sak.Contains(input.SearchValue))
//.WhereIF(!string.IsNullOrWhiteSpace(input.SearchValue), (u, y) => y.Name.Contains(input.SearchValue))
.Select((u, y) => new MiniResumeOutput
{
CompanyID = y.Id,
CompanyName = y.Name,
Logo = y.logo,
Id = u.Id,
Info = u.Info,
Sak = u.Sak,
Salary = u.Salary,
Title = u.Title,
Time = u.CreatedTime.Value.ToString("yyyy/MM/dd"),
RegionName = u.RegionName,
Record = u.Record,
Level = u.Level,
Status = u.Status
}).MergeTable()
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
#endregion
#region 招聘端
///
/// 发布招聘信息
///
///
///
[HttpPost("/Mini/Resume/add")]
public async Task Add(AddMiniResumeInput input)
{
var entity = input.Adapt();
var user = await this.baseUser.AsQueryable().Filter("TenantId", true).SingleAsync(x => x.CreatedUserId == UserManager.UserId);
entity.CompanyID = user.CompanyID;
entity.CompanyName = "";
//查询是否有余额
var banlan = await this.balance.FirstOrDefaultAsync(x => x.UserID == UserManager.UserId);
if (banlan.IsNullOrZero() | banlan.Amount <= 0)
throw Oops.Oh(ErrorCode.B1001);
//查询所属租户收费
var tenantID = await this._sysTenantRep.FirstOrDefaultAsync(s => s.Id == long.Parse(UserManager.TenantID));
if (tenantID.IsNullOrZero())
throw Oops.Oh(ErrorCode.F1001);
if (tenantID.PushFee > banlan.Amount)
throw Oops.Oh(ErrorCode.B1001);
//在余额中减去
banlan.Amount = banlan.Amount - tenantID.PushFee;
await this.balance.UpdateAsync(banlan);
//新增消费记录
await this.ComsumeRep.InsertAsync(new Consume { CAmount = tenantID.PushFee, Surplus = banlan.Amount, UserID = UserManager.UserId, Sort = (int)ConsumeEnum.Push });
await _rep.InsertAsync(entity);
}
///
/// 获取自己发布的招聘信息
///
///
///
[HttpGet("/Mini/GetSelfResumeList")]
public async Task GetSelfResumeList([FromQuery] MiniResumeInput input)
{
var entities = await _rep.AsQueryable()
.LeftJoin((u, y) => u.CompanyID == y.Id) //关联公司信息
.Where(u => u.CreatedUserId == UserManager.UserId)
.Select((u, y) => new MiniResumeOutput
{
CompanyID = y.Id,
CompanyName = y.Name,
Logo = y.logo,
Id = u.Id,
Info = u.Info,
Sak = u.Sak,
Salary = u.Salary,
Title = u.Title,
Time = u.CreatedTime.Value.ToString("yyyy/MM/dd"),
RegionName = u.RegionName,
Record = u.Record,
Level = u.Level,
RegionStrID = u.RegionStrID,
SalaryID = u.SalaryID
}).MergeTable()
.OrderByDescending(u => u.Time)
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities;
}
///
/// 招聘下架条数
///
///
///
[HttpGet("/Mini/OffResume")]
public async Task OffResume()
{
var entities = await _rep.AsQueryable()
.Where(u => u.Status == ResumeStatusEnum.OffShelf)
.ToArrayAsync();
return entities;
}
///
/// 获取发布数量
///
///
///
[HttpGet("/Mini/GetSelfResumeListNumber")]
public async Task GetSelfResumeListNumber()
{
var entities = await _rep.AsQueryable()
.LeftJoin((u, y) => u.CompanyID == y.Id) //关联公司信息
.Where(u => u.CreatedUserId == UserManager.UserId)
.CountAsync();
return entities;
}
///
/// 删除招聘信息
///
///
///
[HttpPost("/Mini/Resume/delete")]
public async Task Delete(DeleteMiniResumeInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
///
/// 更新招聘信息
///
///
///
[HttpPost("/Mini/Resume/edit")]
public async Task Update(UpdateMiniResumeInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
#endregion
}
}