| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- 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/fqc-inspection-specs")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsFqcInspectionSpecsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsFqcInspectionSpec> _rep;
- private readonly SqlSugarRepository<AdoS0QmsFqcInspectionSpecEntry> _entryRep;
- public AdoS0QmsFqcInspectionSpecsController(
- SqlSugarRepository<AdoS0QmsFqcInspectionSpec> rep,
- SqlSugarRepository<AdoS0QmsFqcInspectionSpecEntry> 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] AdoS0QmsFqcInspectionSpecUpsertDto dto)
- {
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- var master = new AdoS0QmsFqcInspectionSpec();
- ApplyFqcSpec(master, dto);
- await _rep.AsInsertable(master).ExecuteReturnEntityAsync();
- await SyncFqcEntriesAsync(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] AdoS0QmsFqcInspectionSpecUpsertDto dto)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- ApplyFqcSpec(master, dto);
- await _rep.AsUpdateable(master).ExecuteCommandAsync();
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await SyncFqcEntriesAsync(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 ApplyFqcSpec(AdoS0QmsFqcInspectionSpec entity, AdoS0QmsFqcInspectionSpecUpsertDto 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 SyncFqcEntriesAsync(long masterId, IEnumerable<AdoS0QmsFqcInspectionSpecEntryDto> items)
- {
- foreach (var item in items)
- {
- var entity = new AdoS0QmsFqcInspectionSpecEntry
- {
- 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();
- }
- }
- }
- [ApiController]
- [Route("api/s0/quality/oqc-inspection-specs")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsOqcInspectionSpecsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsOqcInspectionSpec> _rep;
- private readonly SqlSugarRepository<AdoS0QmsOqcInspectionSpecEntry> _entryRep;
- public AdoS0QmsOqcInspectionSpecsController(
- SqlSugarRepository<AdoS0QmsOqcInspectionSpec> rep,
- SqlSugarRepository<AdoS0QmsOqcInspectionSpecEntry> 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] AdoS0QmsOqcInspectionSpecUpsertDto dto)
- {
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- var master = new AdoS0QmsOqcInspectionSpec();
- ApplyOqcSpec(master, dto);
- await _rep.AsInsertable(master).ExecuteReturnEntityAsync();
- await SyncOqcEntriesAsync(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] AdoS0QmsOqcInspectionSpecUpsertDto dto)
- {
- var master = await _rep.GetByIdAsync(id);
- if (master == null) return NotFound();
- var db = _rep.Context;
- await db.Ado.BeginTranAsync();
- try
- {
- ApplyOqcSpec(master, dto);
- await _rep.AsUpdateable(master).ExecuteCommandAsync();
- await _entryRep.AsDeleteable().Where(x => x.MasterId == id).ExecuteCommandAsync();
- await SyncOqcEntriesAsync(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 ApplyOqcSpec(AdoS0QmsOqcInspectionSpec entity, AdoS0QmsOqcInspectionSpecUpsertDto 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 SyncOqcEntriesAsync(long masterId, IEnumerable<AdoS0QmsOqcInspectionSpecEntryDto> items)
- {
- foreach (var item in items)
- {
- var entity = new AdoS0QmsOqcInspectionSpecEntry
- {
- 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();
- }
- }
- }
|