NceeBaseLineService.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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(IRepository<NceeBaseLine> rep) : INceeBaseLineService, ITransient
  8. {
  9. /// <summary>
  10. /// 添加
  11. /// </summary>
  12. /// <param name="input"></param>
  13. /// <returns></returns>
  14. public async Task Add(AddNceeBaseLineInput input)
  15. {
  16. var e = await rep.AnyAsync(t => t.NceePlanId == input.NceePlanId && t.NceeLineLevel == input.NceeLineLevel);
  17. if (e)
  18. {
  19. throw Oops.Oh(ErrorCode.E2011, "划线等级");
  20. }
  21. var item = input.Adapt<NceeBaseLine>();
  22. await item.InsertNowAsync();
  23. }
  24. /// <summary>
  25. /// 更新
  26. /// </summary>
  27. /// <param name="input"></param>
  28. /// <returns></returns>
  29. public async Task Update(UpdateNceeBaseLineInput input)
  30. {
  31. var item = await rep.FirstOrDefaultAsync(t => t.Id == input.Id) ?? throw Oops.Oh(ErrorCode.E2001);
  32. await item.UpdateNowAsync();
  33. }
  34. /// <summary>
  35. /// 删除
  36. /// </summary>
  37. /// <param name="input"></param>
  38. /// <returns></returns>
  39. public async Task Del(BaseId input)
  40. {
  41. var item = await rep.FirstOrDefaultAsync(t => t.Id == input.Id) ?? throw Oops.Oh(ErrorCode.E2001);
  42. await item.DeleteNowAsync();
  43. }
  44. /// <summary>
  45. /// 根据计划ID获取划线参考列表
  46. /// </summary>
  47. /// <param name="nceePlanId"></param>
  48. /// <returns></returns>
  49. public async Task<List<NceeBaseLineOutput>> GetListByNceePlanId(int nceePlanId)
  50. {
  51. var items = await rep.DetachedEntities.Where(t => t.NceePlanId == nceePlanId).ProjectToType<NceeBaseLineOutput>().OrderBy(t => t.NceeLineLevel).ToListAsync();
  52. return items;
  53. }
  54. }