239 lines
10 KiB
C#
239 lines
10 KiB
C#
using Admin.NET.Core;
|
|
using Flurl.Http;
|
|
using Furion.DatabaseAccessor;
|
|
|
|
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Furion.FriendlyException;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Dynamic.Core;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Admin.NET.Application
|
|
{
|
|
/// <summary>
|
|
/// 家庭关联学生表服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings("测评服务", Name = "BusFramilyMapStudents", Order = 100)]
|
|
[Route("api/[Controller]")]
|
|
public class BusFramilyMapStudentsService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<BusFramilyMapStudents> _busFramilyMapStudentsRep;
|
|
private readonly SqlSugarRepository<BusStudentsFramily> _studentsfamily;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="busFramilyMapStudentsRep"></param>
|
|
/// <param name="configuration"></param>
|
|
/// <param name="studentsfamily"></param>
|
|
public BusFramilyMapStudentsService(
|
|
SqlSugarRepository<BusFramilyMapStudents> busFramilyMapStudentsRep, IConfiguration configuration, SqlSugarRepository<BusStudentsFramily> studentsfamily
|
|
)
|
|
{
|
|
_busFramilyMapStudentsRep = busFramilyMapStudentsRep;
|
|
_configuration = configuration;
|
|
_studentsfamily = studentsfamily;
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 分页查询家庭关联学生表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("page")]
|
|
public async Task<SqlSugarPagedList<BusFramilyMapStudentsOutput>> Page([FromQuery] BusFramilyMapStudentsInput input)
|
|
{
|
|
var busFramilyMapStudentss = await _busFramilyMapStudentsRep.AsQueryable()
|
|
.Where(u => u.FramilyId == input.FramilyId)
|
|
.Where(u => u.StudentId == input.StudentId)
|
|
.WhereIF(!string.IsNullOrEmpty(input.BarCode), u => u.BarCode == input.BarCode)
|
|
.WhereIF(!string.IsNullOrEmpty(input.StudentName), u => u.StudentName == input.StudentName)
|
|
.WhereIF(!string.IsNullOrEmpty(input.SchoolName), u => u.SchoolName == input.SchoolName)
|
|
.WhereIF(!string.IsNullOrEmpty(input.GradeName), u => u.GradeName == input.GradeName)
|
|
.WhereIF(!string.IsNullOrEmpty(input.ClassName), u => u.ClassName == input.ClassName)
|
|
.Where(u => u.Sort == input.Sort)
|
|
.Where(u => u.TenantId == input.TenantId)
|
|
.OrderBy(u => u.CreateTime, OrderByType.Desc)
|
|
.OrderBuilder(input)
|
|
.Select(s => new BusFramilyMapStudentsOutput()
|
|
{
|
|
BarCode = s.BarCode,
|
|
StudentName = s.StudentName,
|
|
SchoolName = s.SchoolName,
|
|
GradeName = s.GradeName,
|
|
ClassName = s.ClassName,
|
|
Gender = s.Gender,
|
|
Sort = s.Sort,
|
|
TenantId = s.TenantId.Value,
|
|
Id = s.Id,
|
|
IsDefault = s.IsDefault
|
|
})
|
|
.ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
return busFramilyMapStudentss;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取远端用户信息
|
|
/// </summary>
|
|
/// <param name="inputDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<BusSeachStudentResult> SeachStudentInfo([FromQuery] BusSeachStudentInfoInputDto inputDto)
|
|
{
|
|
string key = "3c1cbc3f546eda35168c3aa3cb91780fbe703f0996c6d123ea96dc85c70bbc0a8e70006ae6b35eb3962ad057f41a1690";
|
|
var ulrs = _configuration["WebApi:url"].ToString() + "/UserCenters/GetFramilyMapCenter";
|
|
var flurlResponse = await ulrs.PostJsonAsync(new BusSeachStudentInfoInputDto { Key = key, CardID = inputDto.CardID, UserName = inputDto.UserName });
|
|
var result = await flurlResponse.GetJsonAsync<BusSeachStudentInfoOutDto>();
|
|
if (result.Result == null)
|
|
{
|
|
throw Oops.Oh("未查询到该学生信息");
|
|
}
|
|
return result.Result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 增加家庭关联学生表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("add")]
|
|
public async Task Add(AddBusFramilyMapStudentsInput input)
|
|
{
|
|
var framilyInfo = await _studentsfamily.AsQueryable().FirstAsync(c => c.Uuid == input.UuId);
|
|
var busFramilyMapStudents = input.Adapt<BusFramilyMapStudents>();
|
|
busFramilyMapStudents.IsDefault = true;
|
|
busFramilyMapStudents.FramilyId = framilyInfo.Id;
|
|
var anyinfo = await _busFramilyMapStudentsRep.AsQueryable().AnyAsync(c => c.FramilyId == framilyInfo.Id && c.StudentId == input.StudentId);
|
|
if (!anyinfo)
|
|
{
|
|
var oldlist = await _busFramilyMapStudentsRep.AsQueryable().Where(c => c.FramilyId == framilyInfo.Id).ToListAsync();
|
|
oldlist.ForEach(c =>
|
|
{
|
|
c.IsDefault = false;
|
|
});
|
|
_busFramilyMapStudentsRep.UpdateRange(oldlist);
|
|
await _busFramilyMapStudentsRep.InsertAsync(busFramilyMapStudents);
|
|
framilyInfo.framilyRole = input.FramilyRole;
|
|
await _studentsfamily.UpdateAsync(framilyInfo);
|
|
}
|
|
else
|
|
throw Oops.Oh("绑定关系已存在");
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 切换默认孩子数据
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("changedefault")]
|
|
public async Task ChangeDefault(ChangeDefaultChildrenInput input)
|
|
{
|
|
var framilyInfo = await _studentsfamily.AsQueryable().FirstAsync(c => c.Uuid == input.UuId);
|
|
var oldlist = await _busFramilyMapStudentsRep.AsQueryable().Where(c => c.FramilyId == framilyInfo.Id).ToListAsync();
|
|
oldlist.ForEach(c =>
|
|
{
|
|
c.IsDefault = false;
|
|
});
|
|
_busFramilyMapStudentsRep.UpdateRange(oldlist);
|
|
var defaultmodel = await _busFramilyMapStudentsRep.AsQueryable().FirstAsync(c => c.FramilyId == framilyInfo.Id && c.StudentId == input.StudentId);
|
|
defaultmodel.IsDefault = true;
|
|
await _busFramilyMapStudentsRep.UpdateAsync(defaultmodel);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除家庭关联学生表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("delete")]
|
|
public async Task Delete(DeleteBusFramilyMapStudentsInput input)
|
|
{
|
|
var busFramilyMapStudents = await _busFramilyMapStudentsRep.AsQueryable().FirstAsync(u => u.Id == input.Id);
|
|
await _busFramilyMapStudentsRep.FakeDeleteAsync(busFramilyMapStudents);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新家庭关联学生表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("edit")]
|
|
public async Task Update(UpdateBusFramilyMapStudentsInput input)
|
|
{
|
|
var isExist = await _busFramilyMapStudentsRep.AsQueryable().AnyAsync(u => u.Id == input.Id);
|
|
if (!isExist) throw Oops.Oh(ErrorCodeEnum.D3000);
|
|
|
|
var busFramilyMapStudents = input.Adapt<BusFramilyMapStudents>();
|
|
await _busFramilyMapStudentsRep.UpdateAsync(busFramilyMapStudents);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取家庭关联学生表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("detail")]
|
|
public async Task<BusFramilyMapStudentsOutput> Get([FromQuery] QueryeBusFramilyMapStudentsInput input)
|
|
{
|
|
return (await _busFramilyMapStudentsRep.AsQueryable().FirstAsync(u => u.Id == input.Id)).Adapt<BusFramilyMapStudentsOutput>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取家庭关联学生表列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("list")]
|
|
public async Task<List<BusFramilyMapStudentsOutput>> List([FromQuery] BusFramilyMapStudentsInput input)
|
|
{
|
|
var framilyInfo = await _studentsfamily.AsQueryable().FirstAsync(c => c.Uuid == input.UuId);
|
|
var list = await _busFramilyMapStudentsRep.AsQueryable().Where(c => c.FramilyId == framilyInfo.Id).
|
|
Select(s => new BusFramilyMapStudentsOutput()
|
|
{
|
|
FmailyRole = framilyInfo.framilyRole.GetDescription(),
|
|
StudentId = s.StudentId,
|
|
BarCode = s.BarCode,
|
|
StudentName = s.StudentName,
|
|
SchoolName = s.SchoolName,
|
|
GradeName = s.GradeName,
|
|
ClassName = s.ClassName,
|
|
Gender = s.Gender,
|
|
Sort = s.Sort,
|
|
TenantId = s.TenantId.Value,
|
|
Id = s.Id,
|
|
IsDefault = s.IsDefault
|
|
})
|
|
.ToListAsync();
|
|
//list.ForEach(c =>
|
|
//{
|
|
// c.FmailyRole = EnumUtil.GetDescription(framilyInfo.framilyRole);
|
|
//});
|
|
if (list.Count() <= 0)
|
|
{
|
|
throw Oops.Oh(ErrorCodeEnum.D1002);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
}
|
|
}
|