AdoS0MfgPersonSkillAssignmentsController.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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<AdoS0EmpSkills> _rep;
  13. public AdoS0MfgPersonSkillAssignmentsController(SqlSugarRepository<AdoS0EmpSkills> rep)
  14. {
  15. _rep = rep;
  16. }
  17. [HttpGet]
  18. public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0EmpSkillsQueryDto 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(!string.IsNullOrWhiteSpace(q.Domain), x => x.Domain == q.Domain)
  25. .WhereIF(!string.IsNullOrWhiteSpace(q.Employee), x => x.Employee.Contains(q.Employee!))
  26. .WhereIF(!string.IsNullOrWhiteSpace(q.Site), x => x.Site != null && x.Site.Contains(q.Site!))
  27. .WhereIF(!string.IsNullOrWhiteSpace(q.SkillNo), x => x.SkillNo.Contains(q.SkillNo!))
  28. .WhereIF(!string.IsNullOrWhiteSpace(q.Keyword),
  29. x =>
  30. x.Employee.Contains(q.Keyword!) ||
  31. (x.EmployeeName != null && x.EmployeeName.Contains(q.Keyword!)) ||
  32. x.SkillNo.Contains(q.Keyword!) ||
  33. (x.SkillDescription != null && x.SkillDescription.Contains(q.Keyword!)));
  34. var total = await query.CountAsync();
  35. var list = await query
  36. .OrderByDescending(x => x.UpdateTime ?? x.CreateTime)
  37. .Skip((page - 1) * pageSize)
  38. .Take(pageSize)
  39. .ToListAsync();
  40. return Ok(new { total, page, pageSize, list });
  41. }
  42. [HttpGet("{id:long}")]
  43. public async Task<IActionResult> GetAsync(long id)
  44. {
  45. var item = await _rep.GetByIdAsync(id);
  46. return item == null ? NotFound() : Ok(item);
  47. }
  48. [HttpPost]
  49. public async Task<IActionResult> CreateAsync([FromBody] AdoS0EmpSkillsUpsertDto dto)
  50. {
  51. var now = DateTime.Now;
  52. var entity = new AdoS0EmpSkills
  53. {
  54. Employee = dto.Employee.Trim(),
  55. EmployeeId = dto.EmployeeId,
  56. EmployeeName = dto.EmployeeName,
  57. Site = dto.Site,
  58. SkillNo = dto.SkillNo.Trim(),
  59. SkillDescription = dto.SkillDescription,
  60. SkillLevel = dto.SkillLevel,
  61. EfficiencyCoefficient = dto.EfficiencyCoefficient,
  62. DateSkill = dto.DateSkill,
  63. Domain = dto.Domain.Trim(),
  64. CreateUser = dto.CreateUser,
  65. CreateTime = dto.CreateTime ?? now,
  66. UpdateUser = dto.UpdateUser,
  67. UpdateTime = dto.UpdateTime
  68. };
  69. await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  70. return Ok(entity);
  71. }
  72. [HttpPut("{id:long}")]
  73. public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0EmpSkillsUpsertDto dto)
  74. {
  75. var entity = await _rep.GetByIdAsync(id);
  76. if (entity == null) return NotFound();
  77. entity.Employee = dto.Employee.Trim();
  78. entity.EmployeeId = dto.EmployeeId;
  79. entity.EmployeeName = dto.EmployeeName;
  80. entity.Site = dto.Site;
  81. entity.SkillNo = dto.SkillNo.Trim();
  82. entity.SkillDescription = dto.SkillDescription;
  83. entity.SkillLevel = dto.SkillLevel;
  84. entity.EfficiencyCoefficient = dto.EfficiencyCoefficient;
  85. entity.DateSkill = dto.DateSkill;
  86. entity.Domain = dto.Domain.Trim();
  87. entity.UpdateUser = dto.UpdateUser;
  88. entity.UpdateTime = dto.UpdateTime ?? DateTime.Now;
  89. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  90. return Ok(entity);
  91. }
  92. [HttpDelete("{id:long}")]
  93. public async Task<IActionResult> DeleteAsync(long id)
  94. {
  95. var item = await _rep.GetByIdAsync(id);
  96. if (item == null) return NotFound();
  97. await _rep.DeleteAsync(item);
  98. return Ok(new { message = "删除成功" });
  99. }
  100. }