using System;
using SqlSugar;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ZR.Model;
using ZR.Repository;
using ZR.Service.Business.IBusinessService;
using System.Linq;
using ZR.Model.MES.wms;
using ZR.Model.MES.wms.Dto;
using ZR.Service.mes.wms.IService;
using ZR.Model.MES.pro;
using Mapster;
namespace ZR.Service.Business
{
///
/// 盘点记录Service业务层处理
///
[AppService(ServiceType = typeof(IWmAGVService), ServiceLifetime = LifeTime.Transient)]
public class WmAGVService : BaseService, IWmAGVService
{
///
/// 1.获取工单列表
///
///
///
public List GetList(QueryAGVparam param)
{
List aGVWorkorderDtos = new List();
var predicate = Expressionable.Create()
.AndIF(param.year > 0, it => it.Year == param.year)
.AndIF(param.week > 0, it => it.Week == param.week)
.AndIF(param.day > 0, it => it.Date == param.day);
var response = Context.Queryable()
.Where(it=>it.Remark3=="是")
.Where(predicate.ToExpression()).ToList();
foreach (var item in response)
{
aGVWorkorderDtos.Add(item.Adapt());
}
return aGVWorkorderDtos;
}
///
/// 2.获取当前工单下的所有AGV小车任务
///
///
///
///
public List QueryAGVTask(string workorder_id)
{
return Context.Queryable().Where(it => it.FkWorkorderId == workorder_id).OrderByDescending(it=>it.Sort).ToList();
}
///
/// 3.新增AGV小车任务
///
///
///
///
public int AddAGVTask(AgvTask task)
{
int result = 0;
//TODO 1 判断agv小车task是否可以新增
if(string.IsNullOrEmpty(task.FkWorkorderId))
{
return -1;
}
ProWorkorder_v2 workorder = Context.Queryable()
.Where(it => it.Id == task.FkWorkorderId)
.First();
int require_num= workorder.PreviousNumber;
int all_require_num=Context.Queryable().Where(it => it.FkWorkorderId == workorder.Id).Sum(it => it.Number)??0;
if(require_num>all_require_num)
{
task.Id = SnowFlakeSingle.Instance.NextId().ToString();
result= Context.Insertable(task).ExecuteCommand();
}
return result;
}
///
/// 4.删除AGV小车任务
///
///
///
///
public int DeleteTask(string taskId)
{
return Context.Deleteable().Where(it=>it.Id==taskId).ExecuteCommand();
}
///
/// 6 获取agv 起点和终点
///
///
///
///
public List GetAGV_position_list(AgvLocation location)
{
var predicate = Expressionable.Create()
.AndIF(string.IsNullOrEmpty(location.Area), it => it.Area == location.Area)
.AndIF(location.Type > -1, it => it.Type == location.Type)
.AndIF(string.IsNullOrEmpty(location.Coordinate), it => it.Coordinate == location.Coordinate);
return Context.Queryable().Where(predicate.ToExpression()).ToList();
}
}
}