AdoS0MfgPersonSkillsController.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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-skills")]
  8. [AllowAnonymous]
  9. [NonUnify]
  10. public class AdoS0MfgPersonSkillsController : ControllerBase
  11. {
  12. private readonly SqlSugarRepository<AdoS0MfgPersonSkill> _rep;
  13. public AdoS0MfgPersonSkillsController(SqlSugarRepository<AdoS0MfgPersonSkill> rep)
  14. {
  15. _rep = rep;
  16. }
  17. [HttpGet]
  18. public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0MfgPersonSkillQueryDto 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.Code.Contains(q.Keyword!) || x.Name.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] AdoS0MfgPersonSkillUpsertDto dto)
  41. {
  42. var entity = new AdoS0MfgPersonSkill
  43. {
  44. CompanyRefId = dto.CompanyRefId,
  45. FactoryRefId = dto.FactoryRefId,
  46. Code = dto.Code,
  47. Name = dto.Name,
  48. SkillLevel = dto.SkillLevel,
  49. Remark = dto.Remark,
  50. IsEnabled = dto.IsEnabled,
  51. CreatedAt = DateTime.Now
  52. };
  53. await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  54. return Ok(entity);
  55. }
  56. [HttpPut("{id:long}")]
  57. public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0MfgPersonSkillUpsertDto dto)
  58. {
  59. var entity = await _rep.GetByIdAsync(id);
  60. if (entity == null) return NotFound();
  61. entity.CompanyRefId = dto.CompanyRefId;
  62. entity.FactoryRefId = dto.FactoryRefId;
  63. entity.Code = dto.Code;
  64. entity.Name = dto.Name;
  65. entity.SkillLevel = dto.SkillLevel;
  66. entity.Remark = dto.Remark;
  67. entity.IsEnabled = dto.IsEnabled;
  68. entity.UpdatedAt = DateTime.Now;
  69. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  70. return Ok(entity);
  71. }
  72. [HttpPatch("{id:long}/toggle-enabled")]
  73. public async Task<IActionResult> ToggleEnabledAsync(long id, [FromBody] AdoS0ToggleEnabledDto dto)
  74. {
  75. var entity = await _rep.GetByIdAsync(id);
  76. if (entity == null) return NotFound();
  77. entity.IsEnabled = dto.IsEnabled;
  78. entity.UpdatedAt = DateTime.Now;
  79. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  80. return Ok(entity);
  81. }
  82. [HttpDelete("{id:long}")]
  83. public async Task<IActionResult> DeleteAsync(long id)
  84. {
  85. var item = await _rep.GetByIdAsync(id);
  86. if (item == null) return NotFound();
  87. await _rep.DeleteAsync(item);
  88. return Ok(new { message = "删除成功" });
  89. }
  90. }