| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732 |
- using Admin.NET.Plugin.AiDOP.Dto.S0.Quality;
- using Admin.NET.Plugin.AiDOP.Entity.S0.Quality;
- using Admin.NET.Plugin.AiDOP.Infrastructure;
- using static Admin.NET.Plugin.AiDOP.Controllers.S0.Quality.AdoS0QmsControllerHelpers;
- namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Quality;
- [ApiController]
- [Route("api/s0/quality/inspection-bases")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsInspectionBasesController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsInspectionBasis> _rep;
- private readonly SqlSugarRepository<AdoS0QmsInspectionBasisEntry> _entryRep;
- public AdoS0QmsInspectionBasesController(
- SqlSugarRepository<AdoS0QmsInspectionBasis> rep,
- SqlSugarRepository<AdoS0QmsInspectionBasisEntry> entryRep)
- {
- _rep = rep;
- _entryRep = entryRep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
- {
- (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
- var query = _rep.AsQueryable()
- .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
- (x.Number != null && x.Number.Contains(q.Keyword!)) ||
- (x.Name != null && x.Name.Contains(q.Keyword!)));
- var total = await query.CountAsync();
- var list = await query.OrderBy(x => x.Number).Skip((q.Page - 1) * q.PageSize).Take(q.PageSize).ToListAsync();
- return Ok(new { total, page = q.Page, pageSize = q.PageSize, list });
- }
- [HttpGet("{id:long}")]
- public async Task<IActionResult> GetDetailAsync(long id)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var items = await _entryRep.AsQueryable().Where(x => x.MasterId == id).OrderBy(x => x.Seq).OrderBy(x => x.Id).ToListAsync();
- return Ok(new { master, items });
- }
- [HttpGet("options")]
- public async Task<IActionResult> GetOptionsAsync() => Ok(await _rep.AsQueryable()
- .OrderBy(x => x.Number)
- .Select(x => new AdoS0QualitySimpleOptionDto { Value = x.Id, Label = (x.Number ?? "") + " / " + (x.Name ?? "") })
- .ToListAsync());
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsInspectionBasisUpsertDto dto)
- {
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- var master = new AdoS0QmsInspectionBasis();
- ApplyInspectionBasis(master, dto, true);
- await _rep.AsInsertable(master).ExecuteReturnEntityAsync();
- await SyncInspectionBasisEntriesAsync(master.Id, dto.Items);
- await db.Ado.CommitTranAsync();
- return await GetDetailAsync(master.Id);
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsInspectionBasisUpsertDto dto)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- ApplyInspectionBasis(master, dto, false);
- await _rep.AsUpdateable(master).ExecuteCommandAsync();
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await SyncInspectionBasisEntriesAsync(id, dto.Items);
- await db.Ado.CommitTranAsync();
- return await GetDetailAsync(id);
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await _rep.DeleteAsync(master);
- await db.Ado.CommitTranAsync();
- return Ok(new { message = "删除成功" });
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- private static void ApplyInspectionBasis(AdoS0QmsInspectionBasis entity, AdoS0QmsInspectionBasisUpsertDto dto, bool isCreate)
- {
- entity.Number = dto.Number.Trim();
- entity.Name = dto.Name.Trim();
- entity.ControlStrategy = NullIfWhiteSpace(dto.ControlStrategy);
- entity.CreateOrgId = dto.CreateOrgId;
- entity.UseOrgId = dto.UseOrgId;
- entity.Comment = NullIfWhiteSpace(dto.Comment);
- entity.Status = NullIfWhiteSpace(dto.Status);
- entity.EnableStatus = NullIfWhiteSpace(dto.EnableStatus);
- if (isCreate) entity.CreateTime = DateTime.Now;
- entity.ModifyTime = DateTime.Now;
- }
- private async Task SyncInspectionBasisEntriesAsync(long masterId, IEnumerable<AdoS0QmsInspectionBasisEntryDto> items)
- {
- var seq = 1L;
- foreach (var item in items)
- {
- var entity = new AdoS0QmsInspectionBasisEntry
- {
- MasterId = masterId,
- Seq = item.Seq ?? seq++,
- DocumentNumber = NullIfWhiteSpace(item.DocumentNumber),
- DocumentName = NullIfWhiteSpace(item.DocumentName),
- Attachment = NullIfWhiteSpace(item.Attachment)
- };
- await _entryRep.AsInsertable(entity).ExecuteCommandAsync();
- }
- }
- }
- [ApiController]
- [Route("api/s0/quality/inspection-standards")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsInspectionStandardsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsInspectionStandard> _rep;
- private readonly SqlSugarRepository<AdoS0QmsInspectionStandardEntry> _entryRep;
- public AdoS0QmsInspectionStandardsController(
- SqlSugarRepository<AdoS0QmsInspectionStandard> rep,
- SqlSugarRepository<AdoS0QmsInspectionStandardEntry> entryRep)
- {
- _rep = rep;
- _entryRep = entryRep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
- {
- (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
- var query = _rep.AsQueryable()
- .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
- (x.Number != null && x.Number.Contains(q.Keyword!)) ||
- (x.Name != null && x.Name.Contains(q.Keyword!)));
- var total = await query.CountAsync();
- var list = await query.OrderBy(x => x.Number).Skip((q.Page - 1) * q.PageSize).Take(q.PageSize).ToListAsync();
- return Ok(new { total, page = q.Page, pageSize = q.PageSize, list });
- }
- [HttpGet("{id:long}")]
- public async Task<IActionResult> GetDetailAsync(long id)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var items = await _entryRep.AsQueryable().Where(x => x.MasterId == id).OrderBy(x => x.Seq).OrderBy(x => x.Id).ToListAsync();
- return Ok(new { master, items });
- }
- [HttpGet("options")]
- public async Task<IActionResult> GetOptionsAsync() => Ok(await _rep.AsQueryable()
- .OrderBy(x => x.Number)
- .Select(x => new AdoS0QualitySimpleOptionDto { Value = x.Id, Label = (x.Number ?? "") + " / " + (x.Name ?? "") })
- .ToListAsync());
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsInspectionStandardUpsertDto dto)
- {
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- var master = new AdoS0QmsInspectionStandard();
- ApplyInspectionStandard(master, dto);
- await _rep.AsInsertable(master).ExecuteReturnEntityAsync();
- await SyncInspectionStandardEntriesAsync(master.Id, dto.Items);
- await db.Ado.CommitTranAsync();
- return await GetDetailAsync(master.Id);
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsInspectionStandardUpsertDto dto)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- ApplyInspectionStandard(master, dto);
- await _rep.AsUpdateable(master).ExecuteCommandAsync();
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await SyncInspectionStandardEntriesAsync(id, dto.Items);
- await db.Ado.CommitTranAsync();
- return await GetDetailAsync(id);
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await _rep.DeleteAsync(master);
- await db.Ado.CommitTranAsync();
- return Ok(new { message = "删除成功" });
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- private static void ApplyInspectionStandard(AdoS0QmsInspectionStandard entity, AdoS0QmsInspectionStandardUpsertDto dto)
- {
- entity.Number = dto.Number.Trim();
- entity.Name = dto.Name.Trim();
- entity.Comment = NullIfWhiteSpace(dto.Comment);
- entity.ControlStrategy = NullIfWhiteSpace(dto.ControlStrategy);
- entity.CreateOrgId = dto.CreateOrgId;
- entity.UseOrgId = dto.UseOrgId;
- entity.Status = NullIfWhiteSpace(dto.Status);
- entity.EnableStatus = NullIfWhiteSpace(dto.EnableStatus);
- }
- private async Task SyncInspectionStandardEntriesAsync(long masterId, IEnumerable<AdoS0QmsInspectionStandardEntryDto> items)
- {
- var seq = 1L;
- foreach (var item in items)
- {
- var entity = new AdoS0QmsInspectionStandardEntry
- {
- MasterId = masterId,
- Seq = item.Seq ?? seq++,
- CheckItems = NullIfWhiteSpace(item.CheckItems),
- CheckContent = NullIfWhiteSpace(item.CheckContent),
- NormType = NullIfWhiteSpace(item.NormType),
- SpecValue = NullIfWhiteSpace(item.SpecValue),
- TopValue = item.TopValue,
- DownValue = item.DownValue,
- CheckBasisId = item.CheckBasisId,
- CheckMethodId = item.CheckMethodId,
- CheckFrequencyId = item.CheckFrequencyId,
- CheckInstructId = item.CheckInstructId,
- Unit = NullIfWhiteSpace(item.Unit),
- KeyQuality = item.KeyQuality
- };
- await _entryRep.AsInsertable(entity).ExecuteCommandAsync();
- }
- }
- }
- [ApiController]
- [Route("api/s0/quality/inspection-plans")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsInspectionPlansController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsInspectionPlan> _rep;
- private readonly SqlSugarRepository<AdoS0QmsInspectionPlanEntry> _entryRep;
- public AdoS0QmsInspectionPlansController(
- SqlSugarRepository<AdoS0QmsInspectionPlan> rep,
- SqlSugarRepository<AdoS0QmsInspectionPlanEntry> entryRep)
- {
- _rep = rep;
- _entryRep = entryRep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
- {
- (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
- var query = _rep.AsQueryable()
- .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
- (x.Number != null && x.Number.Contains(q.Keyword!)) ||
- (x.Name != null && x.Name.Contains(q.Keyword!)));
- var total = await query.CountAsync();
- var list = await query.OrderBy(x => x.Number).Skip((q.Page - 1) * q.PageSize).Take(q.PageSize).ToListAsync();
- return Ok(new { total, page = q.Page, pageSize = q.PageSize, list });
- }
- [HttpGet("{id:long}")]
- public async Task<IActionResult> GetDetailAsync(long id)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var items = await _entryRep.AsQueryable().Where(x => x.MasterId == id).OrderBy(x => x.Seq).OrderBy(x => x.Id).ToListAsync();
- return Ok(new { master, items });
- }
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsInspectionPlanUpsertDto dto)
- {
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- var master = new AdoS0QmsInspectionPlan();
- ApplyInspectionPlan(master, dto, true);
- await _rep.AsInsertable(master).ExecuteReturnEntityAsync();
- await SyncInspectionPlanEntriesAsync(master.Id, dto.Items);
- await db.Ado.CommitTranAsync();
- return await GetDetailAsync(master.Id);
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsInspectionPlanUpsertDto dto)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- ApplyInspectionPlan(master, dto, false);
- await _rep.AsUpdateable(master).ExecuteCommandAsync();
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await SyncInspectionPlanEntriesAsync(id, dto.Items);
- await db.Ado.CommitTranAsync();
- return await GetDetailAsync(id);
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await _rep.DeleteAsync(master);
- await db.Ado.CommitTranAsync();
- return Ok(new { message = "删除成功" });
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- private static void ApplyInspectionPlan(AdoS0QmsInspectionPlan entity, AdoS0QmsInspectionPlanUpsertDto dto, bool isCreate)
- {
- entity.Number = dto.Number.Trim();
- entity.Name = dto.Name.Trim();
- entity.BizTypeId = NullIfWhiteSpace(dto.BizTypeId);
- entity.Comment = NullIfWhiteSpace(dto.Comment);
- entity.ControlStrategy = NullIfWhiteSpace(dto.ControlStrategy);
- entity.CreateOrgId = dto.CreateOrgId;
- entity.UseOrgId = dto.UseOrgId;
- entity.Status = NullIfWhiteSpace(dto.Status);
- entity.EnableStatus = NullIfWhiteSpace(dto.EnableStatus);
- if (isCreate) entity.CreateTime = DateTime.Now;
- entity.ModifyTime = DateTime.Now;
- }
- private async Task SyncInspectionPlanEntriesAsync(long masterId, IEnumerable<AdoS0QmsInspectionPlanEntryDto> items)
- {
- var seq = 1;
- foreach (var item in items)
- {
- var entity = new AdoS0QmsInspectionPlanEntry
- {
- MasterId = masterId,
- Seq = item.Seq ?? seq++,
- SetupType = NullIfWhiteSpace(item.SetupType),
- MaterialCode = NullIfWhiteSpace(item.MaterialCode),
- MaterialName = NullIfWhiteSpace(item.MaterialName),
- MaterialTypeId = item.MaterialTypeId,
- SupplierId = NullIfWhiteSpace(item.SupplierId),
- SamplingSchemeId = item.SamplingSchemeId,
- InspectionStandardId = item.InspectionStandardId,
- InspectOrgId = item.InspectOrgId,
- InspectUserId = item.InspectUserId,
- QRouteId = item.QRouteId,
- OperationNo = NullIfWhiteSpace(item.OperationNo),
- OperationId = item.OperationId,
- InspectionFrequencyId = item.InspectionFrequencyId,
- ProcessSeq = NullIfWhiteSpace(item.ProcessSeq),
- InspectionType = item.InspectionType
- };
- await _entryRep.AsInsertable(entity).ExecuteCommandAsync();
- }
- }
- }
- [ApiController]
- [Route("api/s0/quality/raw-inspection-specs")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsRawInspectionSpecsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsRawInspectionSpec> _rep;
- private readonly SqlSugarRepository<AdoS0QmsRawInspectionSpecEntry> _entryRep;
- public AdoS0QmsRawInspectionSpecsController(
- SqlSugarRepository<AdoS0QmsRawInspectionSpec> rep,
- SqlSugarRepository<AdoS0QmsRawInspectionSpecEntry> entryRep)
- {
- _rep = rep;
- _entryRep = entryRep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
- {
- (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
- var query = _rep.AsQueryable()
- .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
- (x.FileNumber != null && x.FileNumber.Contains(q.Keyword!)) ||
- (x.RawMaterialName != null && x.RawMaterialName.Contains(q.Keyword!)) ||
- (x.MaterialCode != null && x.MaterialCode.Contains(q.Keyword!)));
- var total = await query.CountAsync();
- var list = await query.OrderByDescending(x => x.Id).Skip((q.Page - 1) * q.PageSize).Take(q.PageSize).ToListAsync();
- return Ok(new { total, page = q.Page, pageSize = q.PageSize, list });
- }
- [HttpGet("{id:long}")]
- public async Task<IActionResult> GetDetailAsync(long id)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var items = await _entryRep.AsQueryable().Where(x => x.MasterId == id).OrderBy(x => x.Seq).OrderBy(x => x.Id).ToListAsync();
- return Ok(new { master, items });
- }
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsRawInspectionSpecUpsertDto dto)
- {
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- var master = new AdoS0QmsRawInspectionSpec();
- ApplyRawInspectionSpec(master, dto);
- await _rep.AsInsertable(master).ExecuteReturnEntityAsync();
- await SyncRawInspectionSpecEntriesAsync(master.Id, dto.Items);
- await db.Ado.CommitTranAsync();
- return await GetDetailAsync(master.Id);
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsRawInspectionSpecUpsertDto dto)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- ApplyRawInspectionSpec(master, dto);
- await _rep.AsUpdateable(master).ExecuteCommandAsync();
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await SyncRawInspectionSpecEntriesAsync(id, dto.Items);
- await db.Ado.CommitTranAsync();
- return await GetDetailAsync(id);
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await _rep.DeleteAsync(master);
- await db.Ado.CommitTranAsync();
- return Ok(new { message = "删除成功" });
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- private static void ApplyRawInspectionSpec(AdoS0QmsRawInspectionSpec entity, AdoS0QmsRawInspectionSpecUpsertDto dto)
- {
- entity.FileNumber = dto.FileNumber.Trim();
- entity.VersionNo = NullIfWhiteSpace(dto.VersionNo);
- entity.DrawingNo = NullIfWhiteSpace(dto.DrawingNo);
- entity.RawMaterialName = NullIfWhiteSpace(dto.RawMaterialName);
- entity.MaterialCode = NullIfWhiteSpace(dto.MaterialCode);
- entity.EffectiveDate = NullIfWhiteSpace(dto.EffectiveDate);
- entity.DrawingVersion = NullIfWhiteSpace(dto.DrawingVersion);
- entity.MaterialGrade = NullIfWhiteSpace(dto.MaterialGrade);
- entity.CavityOrMold = NullIfWhiteSpace(dto.CavityOrMold);
- entity.Attachment = NullIfWhiteSpace(dto.Attachment);
- entity.FileName = NullIfWhiteSpace(dto.FileName);
- entity.Title = NullIfWhiteSpace(dto.Title);
- }
- private async Task SyncRawInspectionSpecEntriesAsync(long masterId, IEnumerable<AdoS0QmsRawInspectionSpecEntryDto> items)
- {
- var seq = 1;
- foreach (var item in items)
- {
- var entity = new AdoS0QmsRawInspectionSpecEntry
- {
- MasterId = masterId,
- Seq = item.Seq ?? seq++,
- InspectionItem = NullIfWhiteSpace(item.InspectionItem),
- InspectionStandard = NullIfWhiteSpace(item.InspectionStandard),
- InspectionMethod = NullIfWhiteSpace(item.InspectionMethod),
- ImageCategory = NullIfWhiteSpace(item.ImageCategory),
- SamplingScheme = NullIfWhiteSpace(item.SamplingScheme),
- Remark = NullIfWhiteSpace(item.Remark),
- Attachment = NullIfWhiteSpace(item.Attachment),
- UpperLimit = NullIfWhiteSpace(item.UpperLimit),
- LowerLimit = NullIfWhiteSpace(item.LowerLimit)
- };
- await _entryRep.AsInsertable(entity).ExecuteCommandAsync();
- }
- }
- }
- [ApiController]
- [Route("api/s0/quality/process-inspection-specs")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsProcessInspectionSpecsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsProcessInspectionSpec> _rep;
- private readonly SqlSugarRepository<AdoS0QmsProcessInspectionSpecEntry> _entryRep;
- public AdoS0QmsProcessInspectionSpecsController(
- SqlSugarRepository<AdoS0QmsProcessInspectionSpec> rep,
- SqlSugarRepository<AdoS0QmsProcessInspectionSpecEntry> entryRep)
- {
- _rep = rep;
- _entryRep = entryRep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
- {
- (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
- var query = _rep.AsQueryable()
- .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
- (x.FileNumber != null && x.FileNumber.Contains(q.Keyword!)) ||
- (x.ApplicableModel != null && x.ApplicableModel.Contains(q.Keyword!)) ||
- (x.MaterialCode != null && x.MaterialCode.Contains(q.Keyword!)));
- var total = await query.CountAsync();
- var list = await query.OrderByDescending(x => x.Id).Skip((q.Page - 1) * q.PageSize).Take(q.PageSize).ToListAsync();
- return Ok(new { total, page = q.Page, pageSize = q.PageSize, list });
- }
- [HttpGet("{id:long}")]
- public async Task<IActionResult> GetDetailAsync(long id)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var items = await _entryRep.AsQueryable().Where(x => x.MasterId == id).OrderBy(x => x.Id).ToListAsync();
- return Ok(new { master, items });
- }
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsProcessInspectionSpecUpsertDto dto)
- {
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- var master = new AdoS0QmsProcessInspectionSpec();
- ApplyProcessInspectionSpec(master, dto);
- await _rep.AsInsertable(master).ExecuteReturnEntityAsync();
- await SyncProcessInspectionSpecEntriesAsync(master.Id, dto.Items);
- await db.Ado.CommitTranAsync();
- return await GetDetailAsync(master.Id);
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsProcessInspectionSpecUpsertDto dto)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- ApplyProcessInspectionSpec(master, dto);
- await _rep.AsUpdateable(master).ExecuteCommandAsync();
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await SyncProcessInspectionSpecEntriesAsync(id, dto.Items);
- await db.Ado.CommitTranAsync();
- return await GetDetailAsync(id);
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await _rep.DeleteAsync(master);
- await db.Ado.CommitTranAsync();
- return Ok(new { message = "删除成功" });
- }
- catch
- {
- await db.Ado.RollbackTranAsync();
- throw;
- }
- }
- private static void ApplyProcessInspectionSpec(AdoS0QmsProcessInspectionSpec entity, AdoS0QmsProcessInspectionSpecUpsertDto dto)
- {
- entity.ApplicableModel = NullIfWhiteSpace(dto.ApplicableModel);
- entity.FileNumber = dto.FileNumber.Trim();
- entity.VersionNo = NullIfWhiteSpace(dto.VersionNo);
- entity.EffectiveDate = NullIfWhiteSpace(dto.EffectiveDate);
- entity.Attachment = NullIfWhiteSpace(dto.Attachment);
- entity.MaterialCode = NullIfWhiteSpace(dto.MaterialCode);
- entity.Attachment2 = NullIfWhiteSpace(dto.Attachment2);
- entity.Version = dto.Version;
- }
- private async Task SyncProcessInspectionSpecEntriesAsync(long masterId, IEnumerable<AdoS0QmsProcessInspectionSpecEntryDto> items)
- {
- foreach (var item in items)
- {
- var entity = new AdoS0QmsProcessInspectionSpecEntry
- {
- MasterId = masterId,
- OperationCode = NullIfWhiteSpace(item.OperationCode),
- OperationName = NullIfWhiteSpace(item.OperationName),
- InspectionItem = NullIfWhiteSpace(item.InspectionItem),
- InspectionMethod = NullIfWhiteSpace(item.InspectionMethod),
- InspectionSpec = NullIfWhiteSpace(item.InspectionSpec),
- ImageCategory = NullIfWhiteSpace(item.ImageCategory),
- InspectionFrequency = NullIfWhiteSpace(item.InspectionFrequency),
- TechnicalStandard = NullIfWhiteSpace(item.TechnicalStandard),
- PeelingForce = item.PeelingForce,
- UpperLimit = NullIfWhiteSpace(item.UpperLimit),
- LowerLimit = NullIfWhiteSpace(item.LowerLimit)
- };
- await _entryRep.AsInsertable(entity).ExecuteCommandAsync();
- }
- }
- }
|