| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- using Admin.NET.Plugin.AiDOP.Dto.S0.Quality;
- using Admin.NET.Plugin.AiDOP.Entity.S0.Quality;
- using Admin.NET.Plugin.AiDOP.Infrastructure;
- using System.Linq.Expressions;
- using static Admin.NET.Plugin.AiDOP.Controllers.S0.Quality.AdoS0QmsControllerHelpers;
- namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Quality;
- [ApiController]
- [Route("api/s0/quality/raw-whitelists")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsRawWhitelistsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsRawWhitelist> _rep;
- public AdoS0QmsRawWhitelistsController(SqlSugarRepository<AdoS0QmsRawWhitelist> rep)
- {
- _rep = rep;
- }
- [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.SupplierCode != null && x.SupplierCode.Contains(q.Keyword!)) ||
- (x.SupplierName != null && x.SupplierName.Contains(q.Keyword!)));
- var total = await query.CountAsync();
- var list = await query.OrderBy(x => x.SupplierCode).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> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
- [HttpGet("options")]
- public async Task<IActionResult> GetOptionsAsync()
- {
- var list = await _rep.AsQueryable()
- .OrderBy(x => x.SupplierCode)
- .Select(x => new AdoS0QualitySimpleOptionDto { Value = x.Id, Label = (x.SupplierCode ?? "") + " / " + (x.SupplierName ?? "") })
- .ToListAsync();
- return Ok(list);
- }
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsRawWhitelistUpsertDto dto)
- {
- var entity = new AdoS0QmsRawWhitelist
- {
- SupplierCode = dto.SupplierCode.Trim(),
- SupplierName = dto.SupplierName.Trim()
- };
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsRawWhitelistUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- entity.SupplierCode = dto.SupplierCode.Trim();
- entity.SupplierName = dto.SupplierName.Trim();
- await _rep.AsUpdateable(entity).ExecuteCommandAsync();
- return Ok(entity);
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
- }
- [ApiController]
- [Route("api/s0/quality/sampling-schemes")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsSamplingSchemesController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsSamplingScheme> _rep;
- public AdoS0QmsSamplingSchemesController(SqlSugarRepository<AdoS0QmsSamplingScheme> rep)
- {
- _rep = rep;
- }
- [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> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
- [HttpGet("options")]
- public async Task<IActionResult> GetOptionsAsync() => Ok(await BuildOptionsAsync(_rep.AsQueryable(), x => x.Id, x => $"{x.Number} / {x.Name}"));
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsSamplingSchemeUpsertDto dto)
- {
- var entity = new AdoS0QmsSamplingScheme();
- ApplySamplingScheme(entity, dto, true);
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsSamplingSchemeUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- ApplySamplingScheme(entity, dto, false);
- await _rep.AsUpdateable(entity).ExecuteCommandAsync();
- return Ok(entity);
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
- private static void ApplySamplingScheme(AdoS0QmsSamplingScheme entity, AdoS0QmsSamplingSchemeUpsertDto dto, bool isCreate)
- {
- entity.Number = dto.Number.Trim();
- entity.Name = dto.Name.Trim();
- entity.SamplingType = NullIfWhiteSpace(dto.SamplingType);
- entity.InspectionLevel = NullIfWhiteSpace(dto.InspectionLevel);
- entity.Strictness = NullIfWhiteSpace(dto.Strictness);
- entity.AqlValue = NullIfWhiteSpace(dto.AqlValue);
- entity.InspectionType = NullIfWhiteSpace(dto.InspectionType);
- entity.InspectOrgId = dto.InspectOrgId;
- entity.InspectUserId = NullIfWhiteSpace(dto.InspectUserId);
- entity.Status = NullIfWhiteSpace(dto.Status);
- entity.EnableStatus = NullIfWhiteSpace(dto.EnableStatus);
- entity.Comment = NullIfWhiteSpace(dto.Comment);
- if (isCreate) entity.CreateTime = DateTime.Now;
- entity.ModifyTime = DateTime.Now;
- }
- }
- [ApiController]
- [Route("api/s0/quality/instruments")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsInspectionInstrumentsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsInspectionInstrument> _rep;
- public AdoS0QmsInspectionInstrumentsController(SqlSugarRepository<AdoS0QmsInspectionInstrument> rep)
- {
- _rep = rep;
- }
- [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!)) ||
- (x.Model != null && x.Model.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> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
- [HttpGet("options")]
- public async Task<IActionResult> GetOptionsAsync() => Ok(await BuildOptionsAsync(_rep.AsQueryable(), x => x.Id, x => $"{x.Number} / {x.Name}"));
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsInspectionInstrumentUpsertDto dto)
- {
- var entity = new AdoS0QmsInspectionInstrument();
- ApplyInspectionInstrument(entity, dto, true);
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsInspectionInstrumentUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- ApplyInspectionInstrument(entity, dto, false);
- await _rep.AsUpdateable(entity).ExecuteCommandAsync();
- return Ok(entity);
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
- private static void ApplyInspectionInstrument(AdoS0QmsInspectionInstrument entity, AdoS0QmsInspectionInstrumentUpsertDto dto, bool isCreate)
- {
- entity.Number = dto.Number.Trim();
- entity.Name = dto.Name.Trim();
- entity.Model = NullIfWhiteSpace(dto.Model);
- entity.Specification = NullIfWhiteSpace(dto.Specification);
- entity.Manufacturer = NullIfWhiteSpace(dto.Manufacturer);
- entity.Status = NullIfWhiteSpace(dto.Status);
- entity.EnableStatus = NullIfWhiteSpace(dto.EnableStatus);
- entity.Comment = NullIfWhiteSpace(dto.Comment);
- if (isCreate) entity.CreateTime = DateTime.Now;
- entity.ModifyTime = DateTime.Now;
- }
- }
- [ApiController]
- [Route("api/s0/quality/inspection-methods")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsInspectionMethodsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsInspectionMethod> _rep;
- public AdoS0QmsInspectionMethodsController(SqlSugarRepository<AdoS0QmsInspectionMethod> rep)
- {
- _rep = rep;
- }
- [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> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
- [HttpGet("options")]
- public async Task<IActionResult> GetOptionsAsync() => Ok(await BuildOptionsAsync(_rep.AsQueryable(), x => x.Id, x => $"{x.Number} / {x.Name}"));
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsInspectionMethodUpsertDto dto)
- {
- var entity = new AdoS0QmsInspectionMethod();
- ApplyInspectionMethod(entity, dto, true);
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsInspectionMethodUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- ApplyInspectionMethod(entity, dto, false);
- await _rep.AsUpdateable(entity).ExecuteCommandAsync();
- return Ok(entity);
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
- private static void ApplyInspectionMethod(AdoS0QmsInspectionMethod entity, AdoS0QmsInspectionMethodUpsertDto dto, bool isCreate)
- {
- entity.Number = dto.Number.Trim();
- entity.Name = dto.Name.Trim();
- entity.ControlStrategy = NullIfWhiteSpace(dto.ControlStrategy);
- entity.Status = NullIfWhiteSpace(dto.Status);
- entity.EnableStatus = NullIfWhiteSpace(dto.EnableStatus);
- entity.Comment = NullIfWhiteSpace(dto.Comment);
- if (isCreate) entity.CreateTime = DateTime.Now;
- entity.ModifyTime = DateTime.Now;
- }
- }
- [ApiController]
- [Route("api/s0/quality/inspection-items")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsInspectionItemsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsInspectionItem> _rep;
- public AdoS0QmsInspectionItemsController(SqlSugarRepository<AdoS0QmsInspectionItem> rep)
- {
- _rep = rep;
- }
- [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> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
- [HttpGet("options")]
- public async Task<IActionResult> GetOptionsAsync() => Ok(await BuildOptionsAsync(_rep.AsQueryable(), x => x.Id, x => $"{x.Number} / {x.Name}"));
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsInspectionItemUpsertDto dto)
- {
- var entity = new AdoS0QmsInspectionItem();
- ApplyInspectionItem(entity, dto, true);
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsInspectionItemUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- ApplyInspectionItem(entity, dto, false);
- await _rep.AsUpdateable(entity).ExecuteCommandAsync();
- return Ok(entity);
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
- private static void ApplyInspectionItem(AdoS0QmsInspectionItem entity, AdoS0QmsInspectionItemUpsertDto dto, bool isCreate)
- {
- entity.Number = dto.Number.Trim();
- entity.Name = dto.Name.Trim();
- entity.CheckMethodId = dto.CheckMethodId;
- entity.CheckBasisId = dto.CheckBasisId;
- entity.CheckInstructId = dto.CheckInstructId;
- entity.RadioGroupField = NullIfWhiteSpace(dto.RadioGroupField);
- entity.RadioGroupField1 = NullIfWhiteSpace(dto.RadioGroupField1);
- entity.MetricType = dto.MetricType;
- entity.Status = NullIfWhiteSpace(dto.Status);
- entity.EnableStatus = NullIfWhiteSpace(dto.EnableStatus);
- entity.Comment = NullIfWhiteSpace(dto.Comment);
- if (isCreate) entity.CreateTime = DateTime.Now;
- entity.ModifyTime = DateTime.Now;
- }
- }
- [ApiController]
- [Route("api/s0/quality/inspection-frequencies")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0QmsInspectionFrequenciesController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0QmsInspectionFrequency> _rep;
- public AdoS0QmsInspectionFrequenciesController(SqlSugarRepository<AdoS0QmsInspectionFrequency> rep)
- {
- _rep = rep;
- }
- [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> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
- [HttpGet("options")]
- public async Task<IActionResult> GetOptionsAsync() => Ok(await BuildOptionsAsync(_rep.AsQueryable(), x => x.Id, x => $"{x.Number} / {x.Name}"));
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsInspectionFrequencyUpsertDto dto)
- {
- var entity = new AdoS0QmsInspectionFrequency();
- ApplyInspectionFrequency(entity, dto, true);
- await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- return Ok(entity);
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsInspectionFrequencyUpsertDto dto)
- {
- var entity = await _rep.GetByIdAsync(id);
- if (entity == null) return NotFound();
- ApplyInspectionFrequency(entity, dto, false);
- await _rep.AsUpdateable(entity).ExecuteCommandAsync();
- return Ok(entity);
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
- private static void ApplyInspectionFrequency(AdoS0QmsInspectionFrequency entity, AdoS0QmsInspectionFrequencyUpsertDto dto, bool isCreate)
- {
- entity.Number = dto.Number.Trim();
- entity.Name = dto.Name.Trim();
- entity.Remark = NullIfWhiteSpace(dto.Remark);
- entity.Status = NullIfWhiteSpace(dto.Status);
- entity.EnableStatus = NullIfWhiteSpace(dto.EnableStatus);
- if (isCreate) entity.CreateTime = DateTime.Now;
- entity.ModifyTime = DateTime.Now;
- }
- }
- internal static partial class AdoS0QmsControllerHelpers
- {
- internal static async Task<IActionResult> DeleteByIdAsync<TEntity>(SqlSugarRepository<TEntity> rep, long id) where TEntity : class, new()
- {
- var item = await rep.GetByIdAsync(id);
- if (item == null) return new NotFoundResult();
- await rep.DeleteAsync(item);
- return new OkObjectResult(new { message = "删除成功" });
- }
- internal static IActionResult OkOrNotFound<TEntity>(TEntity? entity) where TEntity : class => entity == null ? new NotFoundResult() : new OkObjectResult(entity);
- internal static string? NullIfWhiteSpace(string? value) => string.IsNullOrWhiteSpace(value) ? null : value.Trim();
- internal static async Task<List<AdoS0QualitySimpleOptionDto>> BuildOptionsAsync<TEntity>(
- ISugarQueryable<TEntity> query,
- Expression<Func<TEntity, long>> valueExp,
- Expression<Func<TEntity, string>> labelExp) where TEntity : class, new()
- {
- var rows = await query.ToListAsync();
- var valueGetter = valueExp.Compile();
- var labelGetter = labelExp.Compile();
- return rows.Select(x => new AdoS0QualitySimpleOptionDto
- {
- Value = valueGetter(x),
- Label = labelGetter(x)
- }).OrderBy(x => x.Label).ToList();
- }
- }
|