NceeBaseLineService.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Furion.DatabaseAccessor.Extensions;
  2. using YBEE.EQM.Core;
  3. namespace YBEE.EQM.Application.Ncee;
  4. /// <summary>
  5. /// 高中划线参照划线管理服务
  6. /// </summary>
  7. public class NceeBaseLineService : INceeBaseLineService, ITransient
  8. {
  9. private readonly IRepository<NceeBaseLine> _rep;
  10. public NceeBaseLineService(IRepository<NceeBaseLine> rep)
  11. {
  12. _rep = rep;
  13. }
  14. /// <summary>
  15. /// 添加
  16. /// </summary>
  17. /// <param name="input"></param>
  18. /// <returns></returns>
  19. public async Task Add(AddNceeBaseLineInput input)
  20. {
  21. var e = await _rep.AnyAsync(t => t.NceePlanId == input.NceePlanId && t.NceeLineLevel == input.NceeLineLevel);
  22. if (e)
  23. {
  24. throw Oops.Oh(ErrorCode.E2011, "划线等级");
  25. }
  26. var item = input.Adapt<NceeBaseLine>();
  27. await item.InsertNowAsync();
  28. }
  29. /// <summary>
  30. /// 更新
  31. /// </summary>
  32. /// <param name="input"></param>
  33. /// <returns></returns>
  34. public async Task Update(UpdateNceeBaseLineInput input)
  35. {
  36. var item = await _rep.FirstOrDefaultAsync(t => t.Id == input.Id) ?? throw Oops.Oh(ErrorCode.E2001);
  37. await item.UpdateNowAsync();
  38. }
  39. /// <summary>
  40. /// 删除
  41. /// </summary>
  42. /// <param name="input"></param>
  43. /// <returns></returns>
  44. public async Task Del(BaseId input)
  45. {
  46. var item = await _rep.FirstOrDefaultAsync(t => t.Id == input.Id) ?? throw Oops.Oh(ErrorCode.E2001);
  47. await item.DeleteNowAsync();
  48. }
  49. /// <summary>
  50. /// 根据计划ID获取划线参考列表
  51. /// </summary>
  52. /// <param name="nceePlanId"></param>
  53. /// <returns></returns>
  54. public async Task<List<NceeBaseLineOutput>> GetListByNceePlanId(int nceePlanId)
  55. {
  56. var items = await _rep.DetachedEntities.Where(t => t.NceePlanId == nceePlanId).ProjectToType<NceeBaseLineOutput>().OrderBy(t => t.NceeLineLevel).ToListAsync();
  57. return items;
  58. }
  59. }