| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using Admin.NET.Plugin.AiDOP.Dto;
- using Admin.NET.Plugin.AiDOP.Entity;
- using Admin.NET.Plugin.AiDOP.Infrastructure;
- namespace Admin.NET.Plugin.AiDOP.Controllers;
- [ApiController]
- [Route("api/[controller]")]
- [AllowAnonymous]
- [NonUnify]
- public class PlanController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoPlan> _planRep;
- public PlanController(SqlSugarRepository<AdoPlan> planRep)
- {
- _planRep = planRep;
- }
- [HttpGet]
- public async Task<IActionResult> GetPlans([FromQuery] PlanQueryDto query)
- {
- (query.Page, query.PageSize) = PagingGuard.Normalize(query.Page, query.PageSize);
- var q = _planRep.AsQueryable();
- if (!string.IsNullOrWhiteSpace(query.PlanNo))
- q = q.Where(x => x.PlanNo.Contains(query.PlanNo));
- if (!string.IsNullOrWhiteSpace(query.PlanType))
- q = q.Where(x => x.PlanType == query.PlanType);
- if (!string.IsNullOrWhiteSpace(query.Status))
- q = q.Where(x => x.Status == query.Status);
- var total = await q.CountAsync();
- var list = await q
- .OrderByDescending(x => x.CreatedTime)
- .Skip((query.Page - 1) * query.PageSize)
- .Take(query.PageSize)
- .ToListAsync();
- return Ok(new
- {
- total,
- page = query.Page,
- pageSize = query.PageSize,
- list = list.Select(x => new PlanDetailDto
- {
- Id = x.Id,
- PlanNo = x.PlanNo,
- PlanType = x.PlanType,
- ProductName = x.ProductName,
- Quantity = x.Quantity,
- CompletedQuantity = x.CompletedQuantity,
- StartDate = x.StartDate,
- EndDate = x.EndDate,
- Status = x.Status,
- Priority = x.Priority,
- Remark = x.Remark,
- CreatedTime = x.CreatedTime,
- UpdatedTime = x.UpdatedTime,
- CreatedBy = x.CreatedBy
- }).ToList()
- });
- }
- [HttpGet("{id:long}")]
- public async Task<IActionResult> GetPlan(long id)
- {
- var item = await _planRep.GetByIdAsync(id);
- if (item == null)
- return NotFound();
- return Ok(new PlanDetailDto
- {
- Id = item.Id,
- PlanNo = item.PlanNo,
- PlanType = item.PlanType,
- ProductName = item.ProductName,
- Quantity = item.Quantity,
- CompletedQuantity = item.CompletedQuantity,
- StartDate = item.StartDate,
- EndDate = item.EndDate,
- Status = item.Status,
- Priority = item.Priority,
- Remark = item.Remark,
- CreatedTime = item.CreatedTime,
- UpdatedTime = item.UpdatedTime,
- CreatedBy = item.CreatedBy
- });
- }
- [HttpPost]
- public async Task<IActionResult> CreatePlan([FromBody] PlanCreateDto dto)
- {
- var item = new AdoPlan
- {
- PlanNo = $"PL{DateTime.Now:yyyyMMddHHmmss}{Random.Shared.Next(1000, 9999)}",
- PlanType = dto.PlanType,
- ProductName = dto.ProductName,
- Quantity = dto.Quantity,
- StartDate = dto.StartDate,
- EndDate = dto.EndDate,
- Priority = dto.Priority,
- Remark = dto.Remark,
- Status = "未开始",
- CreatedTime = DateTime.Now
- };
- await _planRep.AsInsertable(item).ExecuteReturnEntityAsync();
- return Ok(new { id = item.Id, message = "创建成功" });
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdatePlan(long id, [FromBody] PlanUpdateDto dto)
- {
- var item = await _planRep.GetByIdAsync(id);
- if (item == null)
- return NotFound();
- item.PlanType = dto.PlanType;
- item.ProductName = dto.ProductName;
- item.Quantity = dto.Quantity;
- item.StartDate = dto.StartDate;
- item.EndDate = dto.EndDate;
- item.Priority = dto.Priority;
- item.Remark = dto.Remark;
- item.Status = dto.Status;
- item.UpdatedTime = DateTime.Now;
- await _planRep.AsUpdateable(item).ExecuteCommandAsync();
- return Ok(new { message = "更新成功" });
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeletePlan(long id)
- {
- var item = await _planRep.GetByIdAsync(id);
- if (item == null)
- return NotFound();
- await _planRep.DeleteAsync(item);
- return Ok(new { message = "删除成功" });
- }
- }
|