using Admin.NET.Core.Service;
using Microsoft.AspNetCore.Http;
namespace Admin.NET.Application;
///
/// 专家预约服务
///
[ApiDescriptionSettings(ApplicationConst.ZYGroupName, Order = 100)]
public class SpecialistReservationService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
private readonly SqlSugarRepository _specialgroup;
public SpecialistReservationService(SqlSugarRepository rep, SqlSugarRepository specialgroup)
{
_rep = rep;
_specialgroup = specialgroup;
}
///
/// 分页查询专家预约
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task> Page(SpecialistReservationInput input)
{
var query = _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
u.AppointmentTime.Contains(input.SearchKey.Trim())
)
.WhereIF(!string.IsNullOrWhiteSpace(input.OpenId), u => u.OpenId == input.OpenId)
.WhereIF(!string.IsNullOrWhiteSpace(input.AppointmentTime), u => u.AppointmentTime.Contains(input.AppointmentTime.Trim()))
.WhereIF(input.SId > 0, u => u.SId == input.SId)
//处理外键和TreeSelector相关字段的连接
.LeftJoin((u, wechat) => u.OpenId == wechat.OpenId)
.LeftJoin((u, wechat, sid) => u.SId == sid.Id)
.Where(e => e.IsDelete == false)
.OrderBy(u => u.CreateTime)
.Select((u, wechat, sid) => new SpecialistReservationOutput
{
Id = u.Id,
OpenId = u.OpenId,
WechatOpenId = wechat.OpenId,
WechatPhone = wechat.Mobile,
AppointmentTime = u.AppointmentTime,
SId = u.SId,
SIdName = sid.Name,
CreateTime = u.CreateTime,
UpdateTime = u.UpdateTime,
CreateUserId = u.CreateUserId,
CreateUserName = u.CreateUserName,
UpdateUserId = u.UpdateUserId,
UpdateUserName = u.UpdateUserName,
IsDelete = u.IsDelete,
});
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
}
///
/// 增加专家预约(目前还未衔接短信)
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Add")]
public async Task Add(AddSpecialistReservationInput input)
{
var entity = input.Adapt();
await _rep.InsertAsync(entity);
return entity.Id;
}
///
/// 用户我的预约
///
///
///
[HttpGet]
public async Task> Reservation([FromQuery] string OpenId)
{
var result = new List();
var query = await _rep.AsQueryable().Where(e => e.OpenId == OpenId && e.IsDelete == false).ToListAsync();
var user = await _rep.Context.Queryable().Where(u => u.OpenId == OpenId).ToListAsync();
var splist = await _specialgroup.GetListAsync();
query.ForEach(a =>
{
result.Add(new MyReservationOutput()
{
AppointmentTime = a.AppointmentTime,
CreateTime = a.CreateTime,
OpenId = a.OpenId,
Id = a.Id,
SId = a.SId,
SIdName = splist.FirstOrDefault(e => e.Id == a.SId).Name,
});
});
return result;
}
///
/// 删除专家预约
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Delete")]
public async Task Delete(DeleteSpecialistReservationInput input)
{
var entity = await _rep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
await _rep.FakeDeleteAsync(entity); //假删除
//await _rep.DeleteAsync(entity); //真删除
}
///
/// 更新专家预约
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Update")]
public async Task Update(UpdateSpecialistReservationInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
///
/// 获取专家预约
///
///
///
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task Detail([FromQuery] QueryByIdSpecialistReservationInput input)
{
return await _rep.GetFirstAsync(u => u.Id == input.Id);
}
///
/// 获取专家预约列表
///
///
///
[HttpGet]
[ApiDescriptionSettings(Name = "List")]
public async Task> List([FromQuery] SpecialistReservationInput input)
{
return await _rep.AsQueryable().Select().ToListAsync();
}
///
/// 获取用户openid列表
///
///
///
[ApiDescriptionSettings(Name = "SysWechatUserOpenIdDropdown"), HttpGet]
public async Task SysWechatUserOpenIdDropdown()
{
return await _rep.Context.Queryable()
.Select(u => new
{
Label = u.OpenId,
Value = u.Id
}
).ToListAsync();
}
///
/// 获取专家id列表
///
///
///
[ApiDescriptionSettings(Name = "BusSpecialistGroupSIdDropdown"), HttpGet]
public async Task BusSpecialistGroupSIdDropdown()
{
return await _rep.Context.Queryable()
.Select(u => new
{
Label = u.Name,
Value = u.Id
}
).ToListAsync();
}
}