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 System.Collections.Generic;
using System;
namespace GDZZ.Application
{
///
/// 职位管理服务
///
[ApiDescriptionSettings("Application", Name = "Position", Order = 1)]
public class PositionService : IPositionService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
public PositionService(SqlSugarRepository rep)
{
_rep = rep;
}
///
/// 分页查询职位管理
///
///
///
[HttpGet("/Position/page")]
public async Task Page([FromQuery] PositionInput input)
{
var entities = await _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.PositionName), u => u.PositionName == input.PositionName)
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
///
/// 增加职位管理
///
///
///
[HttpPost("/Position/add")]
public async Task Add(AddPositionInput input)
{
var entity = input.Adapt();
await _rep.InsertAsync(entity);
}
///
/// 删除职位管理
///
///
///
[HttpPost("/Position/delete")]
public async Task Delete(DeletePositionInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
///
/// 更新职位管理
///
///
///
[HttpPost("/Position/edit")]
public async Task Update(UpdatePositionInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
///
/// 获取职位管理
///
///
///
[HttpGet("/Position/detail")]
public async Task Get([FromQuery] QueryePositionInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
///
/// 获取职位管理列表
///
///
///
[HttpGet("/Position/list")]
public async Task> List([FromQuery] PositionInput input)
{;
var allProvinces = await _rep.AsQueryable().ToListAsync();
//先查询 省级别
var JobList = allProvinces.Where(x => x.PositionLevel == PositionEnum.JobList).ToList().Adapt>();
foreach (var province in JobList)
{
province.Children = allProvinces.Where(r => r.PositionLevel == PositionEnum.Subitem && r.ParentID == province.ID).ToList().Adapt>();
foreach (var city in province.Children)
{
city.Children = allProvinces.Where(r => r.PositionLevel == PositionEnum.Grandson && r.ParentID == city.ID).ToList().Adapt>()??null;
}
}
return JobList;
}
}
}