Files
Yi.Admin/Yi.Framework.Net6/test/Yi.Framework.Application/Student/StudentService.cs

106 lines
3.8 KiB
C#
Raw Normal View History

using System;
2023-01-12 14:58:16 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Application.Contracts.Student;
using Yi.Framework.Domain.Student;
using Microsoft.AspNetCore.Mvc;
using NET.AutoWebApi.Setting;
using Microsoft.AspNetCore.Http;
2023-01-15 14:32:43 +08:00
using Yi.Framework.Ddd.Services.Abstract;
using Yi.Framework.Application.Contracts.Student.Dtos;
using Yi.Framework.Domain.Student.Entities;
using Yi.Framework.Ddd.Services;
using Yi.Framework.Core.Attributes;
2023-01-17 23:33:14 +08:00
using Yi.Framework.Uow;
2023-01-18 19:42:13 +08:00
using Microsoft.AspNetCore.Authorization;
2023-01-19 15:35:50 +08:00
using Yi.Framework.Auth.JwtBearer.Authentication;
using Yi.Framework.Core.Const;
using Yi.Framework.Core.CurrentUsers;
using Yi.Framework.Auth.JwtBearer.Authorization;
using Yi.Framework.Domain.Shared.Student.ConstClasses;
2023-01-20 20:03:25 +08:00
using Yi.Framework.Domain.Student.Repositories;
using Yi.Framework.Data.Filters;
using Yi.Framework.Data.Entities;
using Yi.Framework.Ddd.Dtos;
2023-01-12 14:58:16 +08:00
namespace Yi.Framework.Application.Student
{
/// <summary>
/// 服务实现
/// </summary>
[AppService]
2023-01-15 14:32:43 +08:00
public class StudentService : CrudAppService<StudentEntity, StudentGetOutputDto, StudentGetListOutputDto, long, StudentGetListInputVo, StudentCreateInputVo, StudentUpdateInputVo>,
2023-01-17 23:33:14 +08:00
IStudentService, IAutoApiService
2023-01-12 14:58:16 +08:00
{
private readonly IStudentRepository _studentRepository;
private readonly StudentManager _studentManager;
2023-01-19 15:35:50 +08:00
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly JwtTokenManager _jwtTokenManager;
private readonly ICurrentUser _currentUser;
2023-01-20 20:03:25 +08:00
private readonly IDataFilter _dataFilter;
public StudentService(IStudentRepository studentRepository, StudentManager studentManager, IUnitOfWorkManager unitOfWorkManager, JwtTokenManager jwtTokenManager, ICurrentUser currentUser, IDataFilter dataFilter)
2023-01-12 14:58:16 +08:00
{
_studentRepository = studentRepository;
_studentManager = studentManager;
2023-01-17 23:33:14 +08:00
_unitOfWorkManager = unitOfWorkManager;
2023-01-19 15:35:50 +08:00
_jwtTokenManager = jwtTokenManager;
2023-01-19 17:58:46 +08:00
_currentUser = currentUser;
2023-01-20 20:03:25 +08:00
_dataFilter = dataFilter;
}
/// <summary>
/// 数据过滤测试
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<PagedResultDto<StudentGetListOutputDto>> GetDataFiterTestAsync(StudentGetListInputVo input)
{
PagedResultDto<StudentGetListOutputDto> res = new();
using (_dataFilter.Disable<ISoftDelete>())
{
res = await base.GetListAsync(input);
}
var p = await base.GetListAsync(input);
return res;
2023-01-19 15:35:50 +08:00
}
/// <summary>
/// 测试token
/// </summary>
/// <returns></returns>
2023-01-19 17:58:46 +08:00
public string GetToken()
2023-01-19 15:35:50 +08:00
{
var claimDic = new Dictionary<string, object>() { { TokenTypeConst.Id, "123" }, { TokenTypeConst.UserName, "cc" } };
return _jwtTokenManager.CreateToken(claimDic);
2023-01-12 14:58:16 +08:00
}
2023-01-18 00:34:14 +08:00
/// <summary>
2023-01-17 23:33:14 +08:00
/// Uow
/// </summary>
/// <returns></returns>
2023-01-18 19:42:13 +08:00
[Authorize]
2023-01-19 15:35:50 +08:00
[Permission(AuthStudentConst.查询)]
2023-01-17 23:33:14 +08:00
public async Task<StudentGetOutputDto> PostUow()
2023-01-12 14:58:16 +08:00
{
2023-01-19 17:58:46 +08:00
var o = _currentUser;
2023-01-17 23:33:14 +08:00
StudentGetOutputDto res = new();
using (var uow = _unitOfWorkManager.CreateContext())
{
2023-01-18 00:34:14 +08:00
var studentRepository = uow.GetRepository<StudentEntity>();
2023-01-17 23:33:14 +08:00
res = await base.CreateAsync(new StudentCreateInputVo { Name = $"老杰哥{DateTime.Now.ToString("ffff")}", Number = 2023 });
if (new Random().Next(0, 2) == 0) throw new NotImplementedException();
uow.Commit();
}
return res;
2023-01-12 14:58:16 +08:00
}
}
}