using EntityFrameworkCore.Triggered; using System.Linq.Dynamic.Core; namespace IRaCIS.Core.Application.Triggers { //病灶编号维护 public class TableQuestionRowTrigger( IRepository _readingQuestionTrialRepository) : IBeforeSaveTrigger { public async Task BeforeSave(ITriggerContext context, CancellationToken cancellationToken) { Dictionary splitLesionDic = new Dictionary() { {1, "a" }, {2, "b" }, {3, "c" }, {4, "d" }, {5, "e" }, {6, "f" }, {7, "g" }, {8, "h" }, {9, "i" }, {10, "j" }, {11, "k" }, {12, "l" }, {13, "m" }, {14, "n" }, {15, "o" }, {16, "p" }, {17, "q" }, {18, "r" }, {19, "s" }, {20, "t" }, {21, "u" }, {22, "v" }, {23, "w" }, {24, "x" }, {25, "y" }, {26, "z" }, }; if (context.Entity.OrderMark == string.Empty) { context.Entity.OrderMark = await _readingQuestionTrialRepository.Where(x => x.Id == context.Entity.QuestionId).Select(x => x.OrderMark).FirstOrDefaultAsync(); } if (context.Entity.RowIndex % 1 == 0) { context.Entity.RowMark = context.Entity.OrderMark + decimal.ToInt32(context.Entity.RowIndex).ToString().PadLeft(2, '0'); } else { context.Entity.RowMark = context.Entity.OrderMark + Math.Floor(context.Entity.RowIndex).ToString().PadLeft(2, '0') + splitLesionDic[decimal.ToInt32((context.Entity.RowIndex % 1) * 100)]; } //return Task.CompletedTask; } } }