AdoS0MfgProductionLinesController.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using Admin.NET.Plugin.AiDOP.Dto.S0.Manufacturing;
  2. using Admin.NET.Plugin.AiDOP.Dto.S0.Sales;
  3. using Admin.NET.Plugin.AiDOP.Entity.S0.Manufacturing;
  4. using Admin.NET.Plugin.AiDOP.Infrastructure;
  5. namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Manufacturing;
  6. /// <summary>
  7. /// 生产线维护(LineMaster 语义,表 ado_s0_mfg_line_master)。
  8. /// </summary>
  9. [ApiController]
  10. [Route("api/s0/manufacturing/production-lines")]
  11. [AllowAnonymous]
  12. [NonUnify]
  13. public class AdoS0MfgProductionLinesController : ControllerBase
  14. {
  15. private readonly SqlSugarRepository<AdoS0LineMaster> _rep;
  16. public AdoS0MfgProductionLinesController(SqlSugarRepository<AdoS0LineMaster> rep)
  17. {
  18. _rep = rep;
  19. }
  20. [HttpGet]
  21. public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0LineMasterQueryDto q)
  22. {
  23. var page = q.EffectivePage;
  24. var pageSize = q.PageSize;
  25. (page, pageSize) = PagingGuard.Normalize(page, pageSize);
  26. var query = _rep.AsQueryable()
  27. .WhereIF(q.CompanyRefId.HasValue, x => x.CompanyRefId == q.CompanyRefId!.Value)
  28. .WhereIF(q.FactoryRefId.HasValue, x => x.FactoryRefId == q.FactoryRefId!.Value)
  29. .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword),
  30. x => x.Line.Contains(q.Keyword!) || (x.Describe != null && x.Describe.Contains(q.Keyword!)))
  31. .WhereIF(!string.IsNullOrWhiteSpace(q.Line), x => x.Line.Contains(q.Line!))
  32. .WhereIF(!string.IsNullOrWhiteSpace(q.Workshop),
  33. x => x.Workshop != null && x.Workshop.Contains(q.Workshop!))
  34. .WhereIF(q.IsEnabled.HasValue, x => x.IsActive == q.IsEnabled!.Value);
  35. var total = await query.CountAsync();
  36. var entities = await query
  37. .OrderByDescending(x => x.Id)
  38. .Skip((page - 1) * pageSize)
  39. .Take(pageSize)
  40. .ToListAsync();
  41. // GeneralizedCodeMaster 中文说明:当前库无码表实体,占位供列表展示;后续可 JOIN 补全。
  42. var list = entities.Select(x => new
  43. {
  44. x.Id,
  45. x.CompanyRefId,
  46. x.FactoryRefId,
  47. x.Domain,
  48. x.Line,
  49. describe = x.Describe,
  50. x.LineType,
  51. x.LineCategory,
  52. x.Location,
  53. x.Workshop,
  54. vLocation = x.VLocation,
  55. x.Location2,
  56. x.Location3,
  57. pickingLocation = x.PickingLocation,
  58. midLocation = x.MidLocation,
  59. isActive = x.IsActive,
  60. x.CreateUser,
  61. x.CreateTime,
  62. x.UpdateUser,
  63. x.UpdateTime,
  64. lineCategoryComments = (string?)null,
  65. workshopComments = (string?)null
  66. }).ToList();
  67. return Ok(new { total, page, pageSize, list });
  68. }
  69. [HttpGet("{id:long}")]
  70. public async Task<IActionResult> GetAsync(long id)
  71. {
  72. var item = await _rep.GetByIdAsync(id);
  73. return item == null ? NotFound() : Ok(item);
  74. }
  75. [HttpPost]
  76. public async Task<IActionResult> CreateAsync([FromBody] AdoS0LineMasterUpsertDto dto)
  77. {
  78. var now = DateTime.Now;
  79. var entity = new AdoS0LineMaster
  80. {
  81. CompanyRefId = dto.CompanyRefId,
  82. FactoryRefId = dto.FactoryRefId,
  83. Domain = dto.Domain.Trim(),
  84. Line = dto.Line.Trim(),
  85. Describe = string.IsNullOrWhiteSpace(dto.Describe) ? null : dto.Describe.Trim(),
  86. LineType = string.IsNullOrWhiteSpace(dto.LineType) ? null : dto.LineType.Trim(),
  87. LineCategory = string.IsNullOrWhiteSpace(dto.LineCategory) ? null : dto.LineCategory.Trim(),
  88. Location = string.IsNullOrWhiteSpace(dto.Location) ? null : dto.Location.Trim(),
  89. Workshop = string.IsNullOrWhiteSpace(dto.Workshop) ? null : dto.Workshop.Trim(),
  90. VLocation = string.IsNullOrWhiteSpace(dto.VLocation) ? null : dto.VLocation.Trim(),
  91. Location2 = string.IsNullOrWhiteSpace(dto.Location2) ? null : dto.Location2.Trim(),
  92. Location3 = string.IsNullOrWhiteSpace(dto.Location3) ? null : dto.Location3.Trim(),
  93. PickingLocation = string.IsNullOrWhiteSpace(dto.PickingLocation) ? null : dto.PickingLocation.Trim(),
  94. MidLocation = string.IsNullOrWhiteSpace(dto.MidLocation) ? null : dto.MidLocation.Trim(),
  95. IsActive = dto.IsActive,
  96. CreateUser = dto.CreateUser,
  97. CreateTime = now,
  98. UpdateUser = null,
  99. UpdateTime = null
  100. };
  101. await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  102. return Ok(entity);
  103. }
  104. [HttpPut("{id:long}")]
  105. public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0LineMasterUpsertDto dto)
  106. {
  107. var entity = await _rep.GetByIdAsync(id);
  108. if (entity == null) return NotFound();
  109. entity.CompanyRefId = dto.CompanyRefId;
  110. entity.FactoryRefId = dto.FactoryRefId;
  111. entity.Domain = dto.Domain.Trim();
  112. entity.Line = dto.Line.Trim();
  113. entity.Describe = string.IsNullOrWhiteSpace(dto.Describe) ? null : dto.Describe.Trim();
  114. entity.LineType = string.IsNullOrWhiteSpace(dto.LineType) ? null : dto.LineType.Trim();
  115. entity.LineCategory = string.IsNullOrWhiteSpace(dto.LineCategory) ? null : dto.LineCategory.Trim();
  116. entity.Location = string.IsNullOrWhiteSpace(dto.Location) ? null : dto.Location.Trim();
  117. entity.Workshop = string.IsNullOrWhiteSpace(dto.Workshop) ? null : dto.Workshop.Trim();
  118. entity.VLocation = string.IsNullOrWhiteSpace(dto.VLocation) ? null : dto.VLocation.Trim();
  119. entity.Location2 = string.IsNullOrWhiteSpace(dto.Location2) ? null : dto.Location2.Trim();
  120. entity.Location3 = string.IsNullOrWhiteSpace(dto.Location3) ? null : dto.Location3.Trim();
  121. entity.PickingLocation = string.IsNullOrWhiteSpace(dto.PickingLocation) ? null : dto.PickingLocation.Trim();
  122. entity.MidLocation = string.IsNullOrWhiteSpace(dto.MidLocation) ? null : dto.MidLocation.Trim();
  123. entity.IsActive = dto.IsActive;
  124. entity.UpdateUser = dto.UpdateUser;
  125. entity.UpdateTime = DateTime.Now;
  126. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  127. return Ok(entity);
  128. }
  129. [HttpPatch("{id:long}/toggle-enabled")]
  130. public async Task<IActionResult> ToggleEnabledAsync(long id, [FromBody] AdoS0ToggleEnabledDto dto)
  131. {
  132. var entity = await _rep.GetByIdAsync(id);
  133. if (entity == null) return NotFound();
  134. entity.IsActive = dto.IsEnabled;
  135. entity.UpdateTime = DateTime.Now;
  136. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  137. return Ok(new { entity.Id, isActive = entity.IsActive, entity.UpdateTime });
  138. }
  139. [HttpDelete("{id:long}")]
  140. public async Task<IActionResult> DeleteAsync(long id)
  141. {
  142. var item = await _rep.GetByIdAsync(id);
  143. if (item == null) return NotFound();
  144. await _rep.DeleteAsync(item);
  145. return Ok(new { message = "删除成功" });
  146. }
  147. }