Files
wcs/WCS.WebApi/Controllers/AgvTaskController.cs
2025-02-22 11:33:36 +08:00

86 lines
3.1 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using NPOI.SS.Formula.Functions;
using SqlSugar;
using WCS.BLL;
using WCS.BLL.DbModels;
using WCS.BLL.HardWare;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.BLL.Services.Service;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel.AGV;
using WCS.Model.ApiModel.Home;
using WCS.Model.ApiModel.StoreInfo;
using Mode = WCS.BLL.HardWare.Mode;
namespace WCS.WebApi.Controllers
{
/// <summary>
/// 主页面的接口
/// </summary>
[ApiController]
[Route("[controller]")]
public class AgvTaskController : ControllerBase
{
public AgvTaskController()
{
}
/// <summary>
/// agv任务回调
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("getAGVTasks")]
[HttpPost(Name = "getAGVTasks")]
public async Task<PageQueryResponse<AgvTask>> getAGVTasks(GetAGVTasksRequest request)
{
try
{
var recordsQueryable = DbHelp.db.Queryable<AgvTask>()
.WhereIF(string.IsNullOrEmpty(request.ShelfCode), t => t.ShelfCode.Contains(request.ShelfCode))
.WhereIF(string.IsNullOrEmpty(request.CreateUser), t => t.CreateUser.Contains(request.CreateUser))
.WhereIF(string.IsNullOrEmpty(request.StartLocationCode), t => t.StartLocationCode.Contains(request.StartLocationCode))
.WhereIF(string.IsNullOrEmpty(request.EndLocationCode), t => t.StartLocationCode.Contains(request.EndLocationCode))
.WhereIF(request.TaskStatus !=null, t => t.TaskStatus == request.TaskStatus);
var totalCount = await recordsQueryable.CountAsync();
var records = await recordsQueryable
.Skip((request.PageNumber - 1) * request.PageSize).Take(request.PageSize)
.ToListAsync();
//生成序号
for (int i = 0; i < records.Count; i++)
{
records[i].RowNumber = (request.PageNumber - 1) * request.PageSize + i + 1;
}
return new PageQueryResponse<AgvTask>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<AgvTask>()
{
TotalCount = totalCount,
MaxPage = request.PageSize == 0 ? 0 : (int)Math.Ceiling((decimal)totalCount / request.PageSize),
Count = records.Count,
Lists = records.ToList()
}
};
}
catch (Exception ex)
{
return new PageQueryResponse<AgvTask>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
}
}