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.

305 lines
14 KiB

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
{
/// <summary>
/// 小程序招聘列表服务
/// </summary>
[ApiDescriptionSettings("Application", Name = "MiniResume", Order = 1)]
public class MiniResumeService : IMiniResumeService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<MiniResume> _rep; //招聘列表仓储
private readonly SqlSugarRepository<BaseUser> baseUser; //基础用户仓储
private readonly SqlSugarRepository<Company> CompanyRep; //公司仓储
private readonly SqlSugarRepository<SysTenant> _sysTenantRep;// 租户表仓储
private readonly SqlSugarRepository<Consume> ComsumeRep; //消费记录仓储
private readonly SqlSugarRepository<Balance> balance; //余额仓储
public MiniResumeService(SqlSugarRepository<MiniResume> rep,
SqlSugarRepository<BaseUser> baseUser,
SqlSugarRepository<SysTenant> _sysTenantRep,
SqlSugarRepository<Consume> ComsumeRep,
SqlSugarRepository<Balance> balance,
SqlSugarRepository<Company> CompanyRep)
{
_rep = rep;
this.balance = balance;
this.ComsumeRep = ComsumeRep;
this._sysTenantRep = _sysTenantRep;
this.baseUser = baseUser;
this.CompanyRep = CompanyRep;
}
#region 求职端
/// <summary>
/// 招聘列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Mini/GetResumeList")]
[AllowAnonymous]
public async Task<dynamic> 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<Company>((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();
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Mini/GetCompanyResumeList")]
[AllowAnonymous]
public async Task<dynamic> GetCompanyResumeList([FromQuery] MiniResumeInput input)
{
var entities = await _rep.AsQueryable()
.LeftJoin<Company>((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;
}
/// <summary>
/// 搜索招聘信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[AllowAnonymous]
[HttpGet("/Mini/SearchRetFun")]
public async Task<dynamic> SearchRetFun(MiniResumeInput input)
{
var entities = await _rep.AsQueryable()
.LeftJoin<Company>((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 招聘端
/// <summary>
/// 发布招聘信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Mini/Resume/add")]
public async Task Add(AddMiniResumeInput input)
{
var entity = input.Adapt<MiniResume>();
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);
}
/// <summary>
/// 获取自己发布的招聘信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Mini/GetSelfResumeList")]
public async Task<dynamic> GetSelfResumeList([FromQuery] MiniResumeInput input)
{
var entities = await _rep.AsQueryable()
.LeftJoin<Company>((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;
}
/// <summary>
/// 招聘下架条数
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Mini/OffResume")]
public async Task<MiniResume[]> OffResume()
{
var entities = await _rep.AsQueryable()
.Where(u => u.Status == ResumeStatusEnum.OffShelf)
.ToArrayAsync();
return entities;
}
/// <summary>
/// 获取发布数量
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Mini/GetSelfResumeListNumber")]
public async Task<dynamic> GetSelfResumeListNumber()
{
var entities = await _rep.AsQueryable()
.LeftJoin<Company>((u, y) => u.CompanyID == y.Id) //关联公司信息
.Where(u => u.CreatedUserId == UserManager.UserId)
.CountAsync();
return entities;
}
/// <summary>
/// 删除招聘信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Mini/Resume/delete")]
public async Task Delete(DeleteMiniResumeInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
/// <summary>
/// 更新招聘信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Mini/Resume/edit")]
public async Task Update(UpdateMiniResumeInput input)
{
var entity = input.Adapt<MiniResume>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
#endregion
}
}