257 lines
10 KiB
C#
257 lines
10 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using WCS.BLL.DbModels;
|
|
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.MatBaseInfo;
|
|
using WCS.Model.ApiModel.MatDetailCurrentInfo;
|
|
using WCS.Model.ApiModel.PDAProductionLineCallIn;
|
|
using WCS.Model.ApiModel.PDAShelfLocationBindUnbind;
|
|
using WCS.Model.ApiModel.Stocktaking;
|
|
|
|
namespace WCS.WebApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// PDA产线呼叫功能
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class PDAProductionLineCallOutController : ControllerBase
|
|
{
|
|
|
|
public PDAProductionLineCallOutController(IStockTakingService stockTakingService)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取当前货架、当前工位、当前工位可以作为起点可以到的目标区域
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[Route("getMatDetailCurrentInfosForCallOut")]
|
|
[HttpPost(Name = "getMatDetailCurrentInfosForCallOut")]
|
|
public async Task<ResponseCommon> getMatDetailCurrentInfosForCallIn(GetMatDetailCurrentInfosForCallInRequest request)
|
|
{
|
|
try
|
|
{
|
|
#region 校验位置是否可以呼叫货架
|
|
if (request.LocationId == 0)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = $"参数错误:请重新扫描工位码!",
|
|
Data = null,
|
|
};
|
|
}
|
|
//获取位置信息
|
|
var locationInfo = await DbHelp.db.Queryable<LocationInfo>()
|
|
.Where(t => t.Id == request.LocationId)
|
|
.FirstAsync();
|
|
if (locationInfo == null)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = $"获取失败:工位{request.LocationCode}不存在!",
|
|
Data = null,
|
|
};
|
|
}
|
|
if (locationInfo.IsEnable == false)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = $"获取失败:工位{locationInfo.LocationCode}已被禁用!",
|
|
Data = null,
|
|
};
|
|
}
|
|
|
|
var shelfInfo = await DbHelp.db.Queryable<ShelfInfo>()
|
|
.Where(t => t.CurrentLocationId == locationInfo.Id)
|
|
.FirstAsync();
|
|
if (shelfInfo != null)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 301,
|
|
Message = $"获取失败:工位{locationInfo.LocationCode}已被货架{shelfInfo.ShelfCode}占用!",
|
|
Data = null,
|
|
};
|
|
}
|
|
#endregion
|
|
|
|
#region 查询货架当前存量
|
|
var recordsQueryable = DbHelp.db.Queryable<MatDetailCurrentInfo>()
|
|
.LeftJoin<ShelfInfo>((mci, si) => mci.ShelfId == si.Id)
|
|
//货架状态是静止的 代表这个货架没有被呼叫走哦
|
|
.LeftJoin<LocationInfo>((mci, si, li) => (si.TransStatus == TransStatusEnum.静止 && si.CurrentLocationId == li.Id))
|
|
.WhereIF(!string.IsNullOrEmpty(request.MatCodeCondition), (mci, si, li) => mci.MatCode.Contains(request.MatCodeCondition))
|
|
.Select((mci, si, li) => new MatDetailCurrentInfoModel()
|
|
{
|
|
Id = mci.Id,
|
|
ShelfId = mci.ShelfId,
|
|
ShelfCode = mci.ShelfCode,
|
|
ShelfType = mci.ShelfType,
|
|
|
|
LocationArea = li.LocationArea,
|
|
LocationCode = li.LocationCode,
|
|
|
|
MatCode = mci.MatCode,
|
|
MatName = mci.MatName,
|
|
MatSpec = mci.MatSpec,
|
|
MatUnit = mci.MatUnit,
|
|
MatCustomer = mci.MatCustomer,
|
|
MatQty = mci.MatQty,
|
|
MatSupplier = mci.MatSupplier,
|
|
|
|
StationCode = mci.StationCode,
|
|
ModifyUser = mci.ModifyUser,
|
|
ModifyTime = mci.ModifyTime
|
|
});
|
|
|
|
//分页
|
|
var totalCount = await recordsQueryable.CountAsync();
|
|
var records = await recordsQueryable
|
|
.OrderByDescending(mci => mci.Id)
|
|
.Skip((1 - 1) * 300).Take(300)
|
|
.ToListAsync();
|
|
return new PageQueryResponse<MatDetailCurrentInfoModel>()
|
|
{
|
|
Code = 200,
|
|
Message = $"success",
|
|
Data = new PageQueryResponseData<MatDetailCurrentInfoModel>()
|
|
{
|
|
TotalCount = totalCount,
|
|
MaxPage = 1,
|
|
Count = records.Count,
|
|
Lists = records.ToList()
|
|
}
|
|
};
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = ex.Message,
|
|
Data = null,
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 货架送回 通过 货架ID 目标区域 是否为空货架 将货架送回
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[Route("callOut")]
|
|
[HttpPost(Name = "callOut")]
|
|
public async Task<ResponseCommon> callIn(CallOutRequest request)
|
|
{
|
|
try
|
|
{
|
|
#region 校验位置是否可以呼叫货架
|
|
if (request.LocationId == 0)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = $"呼叫失败:请重新扫描工位码!",
|
|
Data = null,
|
|
};
|
|
}
|
|
//获取位置信息
|
|
var locationInfo = await DbHelp.db.Queryable<LocationInfo>()
|
|
.Where(t => t.Id == request.LocationId)
|
|
.FirstAsync();
|
|
if (locationInfo == null)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = $"呼叫失败:工位{request.LocationCode}不存在!",
|
|
Data = null,
|
|
};
|
|
}
|
|
if (locationInfo.IsEnable == false)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = $"呼叫失败:工位{locationInfo.LocationCode}已被禁用!",
|
|
Data = null,
|
|
};
|
|
}
|
|
|
|
var shelfInfo = await DbHelp.db.Queryable<ShelfInfo>()
|
|
.Where(t => t.CurrentLocationId == locationInfo.Id)
|
|
.FirstAsync();
|
|
if (shelfInfo != null)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 301,
|
|
Message = $"呼叫失败:工位{locationInfo.LocationCode}已被货架{shelfInfo.ShelfCode}占用!",
|
|
Data = null,
|
|
};
|
|
}
|
|
#endregion
|
|
|
|
#region 获取货架是否可以被呼叫
|
|
shelfInfo = await DbHelp.db.Queryable<ShelfInfo>()
|
|
.Where(t => t.Id == request.ShelfId)
|
|
.Where(t => t.IsEnable)
|
|
.FirstAsync();
|
|
if (shelfInfo == null)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = $"呼叫失败:货架{shelfInfo.ShelfCode}不存在或已被禁用!",
|
|
Data = null,
|
|
};
|
|
}
|
|
|
|
if (shelfInfo.TransStatus == TransStatusEnum.运输中)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = $"呼叫失败:货架{shelfInfo.ShelfCode}正在运输中!",
|
|
Data = null,
|
|
};
|
|
}
|
|
#endregion
|
|
|
|
#region
|
|
//TO DO 调用AGV接口开始呼叫 呼叫成功更新运输状态和目标库位
|
|
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 200,
|
|
Message = $"呼叫成功!",
|
|
Data = null,
|
|
};
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = ex.Message,
|
|
Data = null,
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|