AdoS0MfgSopDocumentsController.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using Admin.NET.Plugin.AiDOP.Dto.S0.Manufacturing;
  2. using Admin.NET.Plugin.AiDOP.Entity.S0.Manufacturing;
  3. using Admin.NET.Plugin.AiDOP.Infrastructure;
  4. namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Manufacturing;
  5. [ApiController]
  6. [Route("api/s0/manufacturing/sop-documents")]
  7. [AllowAnonymous]
  8. [NonUnify]
  9. public class AdoS0MfgSopDocumentsController : ControllerBase
  10. {
  11. private readonly SqlSugarRepository<AdoS0QualitySegmentImage> _rep;
  12. public AdoS0MfgSopDocumentsController(SqlSugarRepository<AdoS0QualitySegmentImage> rep)
  13. {
  14. _rep = rep;
  15. }
  16. [HttpGet]
  17. public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0MfgSopDocumentQueryDto q)
  18. {
  19. var page = q.Page;
  20. var pageSize = q.PageSize;
  21. (page, pageSize) = PagingGuard.Normalize(page, pageSize);
  22. var domain = q.Domain.Trim();
  23. var baseQuery = _rep.AsQueryable()
  24. .Where(x => x.Domain == domain)
  25. .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword),
  26. x => (x.Line != null && x.Line.Contains(q.Keyword!))
  27. || (x.ItemNum != null && x.ItemNum.Contains(q.Keyword!))
  28. || (x.Op != null && x.Op.Contains(q.Keyword!))
  29. || (x.Path != null && x.Path.Contains(q.Keyword!))
  30. || (x.Descr != null && x.Descr.Contains(q.Keyword!))
  31. || (x.Rev != null && x.Rev.Contains(q.Keyword!)));
  32. var total = await baseQuery.CountAsync();
  33. // 左联仅用于展示字段(Line/Op/imgType),主表字段仍可 CRUD
  34. var list = await baseQuery
  35. .LeftJoin<AdoS0ImageType>((qsi, it) => qsi.ImageTypeID == it.ImageTypeID && qsi.Domain == it.Domain)
  36. .LeftJoin<AdoS0LineMaster>((qsi, it, lm) => qsi.Line == lm.Line && qsi.Domain == lm.Domain)
  37. .LeftJoin<AdoS0MfgRoutingOpDetail>((qsi, it, lm, rd) => qsi.ItemNum == rd.MaterialCode && qsi.Op == rd.OperationCode)
  38. .OrderByDescending((qsi, it, lm, rd) => qsi.Id)
  39. .Select((qsi, it, lm, rd) => new
  40. {
  41. id = qsi.Id,
  42. line = qsi.Line,
  43. lineDisplay = qsi.Line == null ? "" : (lm.Line + " " + (lm.Describe ?? "")),
  44. itemNum = qsi.ItemNum,
  45. op = qsi.Op,
  46. opDisplay = qsi.Op == null ? "" : (rd.OperationCode + " " + (rd.OperationDescription ?? "")),
  47. imageTypeID = qsi.ImageTypeID,
  48. imgType = it.Descr,
  49. path = qsi.Path,
  50. descr = qsi.Descr,
  51. rev = qsi.Rev,
  52. sortID = qsi.SortID,
  53. domain = qsi.Domain
  54. })
  55. .Skip((page - 1) * pageSize)
  56. .Take(pageSize)
  57. .ToListAsync();
  58. return Ok(new { total, page, pageSize, list });
  59. }
  60. [HttpGet("{id:long}")]
  61. public async Task<IActionResult> GetAsync(long id)
  62. {
  63. var item = await _rep.GetByIdAsync(id);
  64. return item == null ? NotFound() : Ok(item);
  65. }
  66. [HttpPost]
  67. public async Task<IActionResult> CreateAsync([FromBody] AdoS0MfgSopDocumentUpsertDto dto)
  68. {
  69. var entity = new AdoS0QualitySegmentImage
  70. {
  71. Domain = dto.Domain.Trim(),
  72. Line = dto.Line,
  73. ItemNum = dto.ItemNum,
  74. Op = dto.Op,
  75. ImageTypeID = dto.ImageTypeID,
  76. Path = dto.Path,
  77. Descr = dto.Descr,
  78. Rev = dto.Rev,
  79. SortID = dto.SortID
  80. };
  81. await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  82. return Ok(entity);
  83. }
  84. [HttpPut("{id:long}")]
  85. public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0MfgSopDocumentUpsertDto dto)
  86. {
  87. var entity = await _rep.GetByIdAsync(id);
  88. if (entity == null) return NotFound();
  89. entity.Domain = dto.Domain.Trim();
  90. entity.Line = dto.Line;
  91. entity.ItemNum = dto.ItemNum;
  92. entity.Op = dto.Op;
  93. entity.ImageTypeID = dto.ImageTypeID;
  94. entity.Path = dto.Path;
  95. entity.Descr = dto.Descr;
  96. entity.Rev = dto.Rev;
  97. entity.SortID = dto.SortID;
  98. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  99. return Ok(entity);
  100. }
  101. [HttpDelete("{id:long}")]
  102. public async Task<IActionResult> DeleteAsync(long id)
  103. {
  104. var item = await _rep.GetByIdAsync(id);
  105. if (item == null) return NotFound();
  106. await _rep.DeleteAsync(item);
  107. return Ok(new { message = "删除成功" });
  108. }
  109. }