AdoS0OrderReviewCyclesController.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Admin.NET.Plugin.AiDOP.Dto.S0.Sales;
  2. using Admin.NET.Plugin.AiDOP.Entity.S0.Sales;
  3. using Admin.NET.Plugin.AiDOP.Infrastructure;
  4. namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Sales;
  5. [ApiController]
  6. [Route("api/s0/sales/order-review-cycles")]
  7. [AllowAnonymous]
  8. [NonUnify]
  9. public class AdoS0OrderReviewCyclesController : ControllerBase
  10. {
  11. private readonly SqlSugarRepository<AdoS0OrderReviewCycle> _rep;
  12. public AdoS0OrderReviewCyclesController(SqlSugarRepository<AdoS0OrderReviewCycle> rep)
  13. => _rep = rep;
  14. [HttpGet]
  15. public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0OrderReviewCycleQueryDto q)
  16. {
  17. (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
  18. var query = _rep.AsQueryable()
  19. .WhereIF(q.CompanyRefId.HasValue, x => x.CompanyRefId == q.CompanyRefId!.Value)
  20. .WhereIF(q.FactoryRefId.HasValue, x => x.FactoryRefId == q.FactoryRefId!.Value)
  21. .WhereIF(!string.IsNullOrWhiteSpace(q.DomainCode), x => x.DomainCode == q.DomainCode)
  22. .WhereIF(q.IsActive.HasValue, x => x.IsActive == q.IsActive!.Value);
  23. var total = await query.CountAsync();
  24. var list = await query.OrderByDescending(x => x.CreateTime).Skip((q.Page - 1) * q.PageSize).Take(q.PageSize).ToListAsync();
  25. return Ok(new { total, page = q.Page, pageSize = q.PageSize, list });
  26. }
  27. [HttpGet("{id:long}")]
  28. public async Task<IActionResult> GetAsync(long id)
  29. {
  30. var item = await _rep.GetByIdAsync(id);
  31. return item == null ? NotFound() : Ok(item);
  32. }
  33. [HttpPost]
  34. public async Task<IActionResult> CreateAsync([FromBody] AdoS0OrderReviewCycleUpsertDto dto)
  35. {
  36. if (await _rep.IsAnyAsync(x => x.FactoryRefId == dto.FactoryRefId))
  37. return AdoS0ApiErrors.Conflict(AdoS0ErrorCodes.DuplicateCode, "该工厂已存在订单评审周期配置,请使用编辑功能");
  38. var entity = new AdoS0OrderReviewCycle
  39. {
  40. CompanyRefId = dto.CompanyRefId,
  41. FactoryRefId = dto.FactoryRefId,
  42. DomainCode = dto.DomainCode,
  43. StdHours = dto.StdHours,
  44. Remarks = dto.Remarks,
  45. IsActive = dto.IsActive,
  46. CreateUser = dto.CreateUser,
  47. CreateTime = DateTime.Now,
  48. };
  49. await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  50. return Ok(entity);
  51. }
  52. [HttpPut("{id:long}")]
  53. public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0OrderReviewCycleUpsertDto dto)
  54. {
  55. var entity = await _rep.GetByIdAsync(id);
  56. if (entity == null) return NotFound();
  57. entity.CompanyRefId = dto.CompanyRefId;
  58. entity.FactoryRefId = dto.FactoryRefId;
  59. entity.DomainCode = dto.DomainCode;
  60. entity.StdHours = dto.StdHours;
  61. entity.Remarks = dto.Remarks;
  62. entity.IsActive = dto.IsActive;
  63. entity.UpdateUser = dto.UpdateUser;
  64. entity.UpdateTime = DateTime.Now;
  65. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  66. return Ok(entity);
  67. }
  68. [HttpPatch("{id:long}/toggle-enabled")]
  69. public async Task<IActionResult> ToggleActiveAsync(long id, [FromBody] AdoS0OrderReviewCycleToggleActiveDto dto)
  70. {
  71. var entity = await _rep.GetByIdAsync(id);
  72. if (entity == null) return NotFound();
  73. entity.IsActive = dto.IsActive;
  74. entity.UpdateTime = DateTime.Now;
  75. await _rep.AsUpdateable(entity).ExecuteCommandAsync();
  76. return Ok(entity);
  77. }
  78. [HttpDelete("{id:long}")]
  79. public async Task<IActionResult> DeleteAsync(long id)
  80. {
  81. var item = await _rep.GetByIdAsync(id);
  82. if (item == null) return NotFound();
  83. await _rep.DeleteAsync(item);
  84. return Ok(new { message = "删除成功" });
  85. }
  86. }