tuiwucarrer/Admin.NET/Admin.NET.Application/Service/SpecialistReservation/SpecialistReservationServic...

194 lines
6.6 KiB
C#

using Admin.NET.Core.Service;
using Microsoft.AspNetCore.Http;
namespace Admin.NET.Application;
/// <summary>
/// 专家预约服务
/// </summary>
[ApiDescriptionSettings(ApplicationConst.ZYGroupName, Order = 100)]
public class SpecialistReservationService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<SpecialistReservation> _rep;
private readonly SqlSugarRepository<BusSpecialistGroup> _specialgroup;
public SpecialistReservationService(SqlSugarRepository<SpecialistReservation> rep, SqlSugarRepository<BusSpecialistGroup> specialgroup)
{
_rep = rep;
_specialgroup = specialgroup;
}
/// <summary>
/// 分页查询专家预约
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task<SqlSugarPagedList<SpecialistReservationOutput>> 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<SysWechatUser>((u, wechat) => u.OpenId == wechat.OpenId)
.LeftJoin<BusSpecialistGroup>((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);
}
/// <summary>
/// 增加专家预约(目前还未衔接短信)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Add")]
public async Task<long> Add(AddSpecialistReservationInput input)
{
var entity = input.Adapt<SpecialistReservation>();
await _rep.InsertAsync(entity);
return entity.Id;
}
/// <summary>
/// 用户我的预约
/// </summary>
/// <param name="OpenId"></param>
/// <returns></returns>
[HttpGet]
public async Task<List<MyReservationOutput>> Reservation([FromQuery] string OpenId)
{
var result = new List<MyReservationOutput>();
var query = await _rep.AsQueryable().Where(e => e.OpenId == OpenId && e.IsDelete == false).ToListAsync();
var user = await _rep.Context.Queryable<SysWechatUser>().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;
}
/// <summary>
/// 删除专家预约
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[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); //真删除
}
/// <summary>
/// 更新专家预约
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Update")]
public async Task Update(UpdateSpecialistReservationInput input)
{
var entity = input.Adapt<SpecialistReservation>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
/// <summary>
/// 获取专家预约
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task<SpecialistReservation> Detail([FromQuery] QueryByIdSpecialistReservationInput input)
{
return await _rep.GetFirstAsync(u => u.Id == input.Id);
}
/// <summary>
/// 获取专家预约列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "List")]
public async Task<List<SpecialistReservationOutput>> List([FromQuery] SpecialistReservationInput input)
{
return await _rep.AsQueryable().Select<SpecialistReservationOutput>().ToListAsync();
}
/// <summary>
/// 获取用户openid列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[ApiDescriptionSettings(Name = "SysWechatUserOpenIdDropdown"), HttpGet]
public async Task<dynamic> SysWechatUserOpenIdDropdown()
{
return await _rep.Context.Queryable<SysWechatUser>()
.Select(u => new
{
Label = u.OpenId,
Value = u.Id
}
).ToListAsync();
}
/// <summary>
/// 获取专家id列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[ApiDescriptionSettings(Name = "BusSpecialistGroupSIdDropdown"), HttpGet]
public async Task<dynamic> BusSpecialistGroupSIdDropdown()
{
return await _rep.Context.Queryable<BusSpecialistGroup>()
.Select(u => new
{
Label = u.Name,
Value = u.Id
}
).ToListAsync();
}
}