AdoS0MfgPersonSkillAssignmentsController.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. [ApiController]
  7. [Route("api/s0/manufacturing/person-skill-assignments")]
  8. [AllowAnonymous]
  9. [NonUnify]
  10. public class AdoS0MfgPersonSkillAssignmentsController : ControllerBase
  11. {
  12. private readonly SqlSugarRepository<AdoS0MfgPersonSkillAssignment> _rep;
  13. public AdoS0MfgPersonSkillAssignmentsController(SqlSugarRepository<AdoS0MfgPersonSkillAssignment> rep)
  14. {
  15. _rep = rep;
  16. }
  17. [HttpGet]
  18. public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0MfgPersonSkillAssignmentQueryDto q)
  19. {
  20. var page = q.EffectivePage;
  21. var pageSize = q.PageSize;
  22. (page, pageSize) = PagingGuard.Normalize(page, pageSize);
  23. var query = _rep.AsQueryable()
  24. .WhereIF(q.CompanyRefId.HasValue, x => x.CompanyRefId == q.CompanyRefId!.Value)
  25. .WhereIF(q.FactoryRefId.HasValue, x => x.FactoryRefId == q.FactoryRefId!.Value)
  26. .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword),
  27. x => x.PersonCode.Contains(q.Keyword!))
  28. .WhereIF(q.IsEnabled.HasValue, x => x.IsEnabled == q.IsEnabled!.Value);
  29. var total = await query.CountAsync();
  30. var list = await query.OrderByDescending(x => x.CreatedAt).Skip((page - 1) * pageSize).Take(pageSize).ToListAsync();
  31. return Ok(new { total, page, pageSize, list });
  32. }
  33. [HttpGet("{id:long}")]
  34. public async Task<IActionResult> GetAsync(long id)
  35. {
  36. var item = await _rep.GetByIdAsync(id);
  37. return item == null ? NotFound() : Ok(item);
  38. }
  39. [HttpPost]
  40. public async Task<IActionResult> CreateAsync([FromBody] AdoS0MfgPersonSkillAssignmentUpsertDto dto)
  41. {
  42. var entity = new AdoS0MfgPersonSkillAssignment
  43. {
  44. CompanyRefId = dto.CompanyRefId,
  45. FactoryRefId = dto.FactoryRefId,
  46. PersonCode = dto.PersonCode,
  47. WorkGroup = dto.WorkGroup,
  48. SkillId = dto.SkillId,
  49. SkillLevel = dto.SkillLevel,
  50. ProductionEfficiency = dto.ProductionEfficiency,
  51. Remark = dto.Remark,
  52. IsEnabled = dto.IsEnabled,
  53. CreatedAt = DateTime.Now
  54. };
  55. await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  56. return Ok(entity);
  57. }
  58. [HttpPut("{id:long}")]
  59. public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0MfgPersonSkillAssignmentUpsertDto dto)
  60. {
  61. var entity = await _rep.GetByIdAsync(id);
  62. if (entity == null) return NotFound();
  63. entity.CompanyRefId = dto.CompanyRefId;
  64. entity.FactoryRefId = dto.FactoryRefId;
  65. entity.PersonCode = dto.PersonCode;
  66. entity.WorkGroup = dto.WorkGroup;
  67. entity.SkillId = dto.SkillId;
  68. entity.SkillLevel = dto.SkillLevel;
  69. entity.ProductionEfficiency = dto.ProductionEfficiency;
  70. entity.Remark = dto.Remark;
  71. entity.IsEnabled = dto.IsEnabled;
  72. entity.UpdatedAt = DateTime.Now;
  73. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  74. return Ok(entity);
  75. }
  76. [HttpPatch("{id:long}/toggle-enabled")]
  77. public async Task<IActionResult> ToggleEnabledAsync(long id, [FromBody] AdoS0ToggleEnabledDto dto)
  78. {
  79. var entity = await _rep.GetByIdAsync(id);
  80. if (entity == null) return NotFound();
  81. entity.IsEnabled = dto.IsEnabled;
  82. entity.UpdatedAt = DateTime.Now;
  83. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  84. return Ok(entity);
  85. }
  86. [HttpDelete("{id:long}")]
  87. public async Task<IActionResult> DeleteAsync(long id)
  88. {
  89. var item = await _rep.GetByIdAsync(id);
  90. if (item == null) return NotFound();
  91. await _rep.DeleteAsync(item);
  92. return Ok(new { message = "删除成功" });
  93. }
  94. }