using Microsoft.AspNetCore.Mvc;
using WCS.BLL.DbModels;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.PDAMatBind;
using WCS.Model.ApiModel.User;
using WCS.Model.WebSocketModel;
namespace WCS.WebApi.Controllers
{
///
/// PDA物料绑定相关接口
///
[ApiController]
[Route("[controller]")]
public class PDAMatBindController : ControllerBase
{
public IPDAMatBindService _PDAMatBindService { get; set; }
public PDAMatBindController(IPDAMatBindService PDAMatBindService)
{
_PDAMatBindService = PDAMatBindService;
}
[Route("getShelfInfoByLocationCode")]
[HttpPost(Name = "getShelfInfoByLocationCode")]
public async Task getShelfInfoByLocationCode(GetShelfInfoByLocationCodeRequest request)
{
//不含XY就不是工位
if (!request.LocationCode.Contains("XY"))
{
request.LocationCode = string.Empty;
}
//判断参数
if (string.IsNullOrEmpty(request.LocationCode) && string.IsNullOrEmpty(request.ShelfCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "工位码或货架码为空,请重新扫码!",
Data = null,
};
}
//获取是否存在当前工位
//扫的工位码
LocationInfo? location;
ShelfInfo? shelf;
if (!string.IsNullOrEmpty(request.LocationCode))
{
//TO DO 在哪些物料区域才能进行物料绑定
location = await DbHelp.db.Queryable()
.Where(t => t.LocationCode == request.LocationCode)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (location == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"工位[{request.LocationCode}]不存在或已被禁用!\r\n请联系系统管理人员维护工位信息!",
Data = null,
};
}
//获取当前工位的货架
shelf = await DbHelp.db.Queryable()
.Where(t => (t.CurrentLocationId == location.Id && t.TransStatus == TransStatusEnum.静止)
|| (t.DestinationLocationId == location.Id && t.TransStatus == TransStatusEnum.运输中)//解决产线人员 呼叫后货架未到的时候绑定的问题
)
.Where(t => t.IsEnable)
.FirstAsync();
}
//货架到位置了 扫的货架码
else
{
//获取当前工位的货架
shelf = await DbHelp.db.Queryable()
.Where(t => t.ShelfCode == request.ShelfCode)
.Where(t => t.IsEnable)
.FirstAsync();
if (shelf == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"货架[{request.ShelfCode}]不存在或已被禁用!",
Data = null,
};
}
if (shelf.TransStatus != TransStatusEnum.静止)
{
return new ResponseCommon()
{
Code = 201,
Message = $"货架[{request.ShelfCode}]处于运输中状态!\r\n请等待货架运输完成再进行操作",
Data = null,
};
}
if (shelf.CurrentLocationId == 0 || string.IsNullOrEmpty(shelf.CurrentLocaiotnCode))
{
return new ResponseCommon()
{
Code = 201,
Message = $"货架[{request.ShelfCode}]未绑定工位!请尝试将货架与位置绑定后进行操作!",
Data = null,
};
}
location = await DbHelp.db.Queryable()
.Where(t => t.LocationCode == shelf.CurrentLocaiotnCode)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (location == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"工位[{shelf.CurrentLocaiotnCode}]不存在或已被禁用!\r\n请联系系统管理人员维护工位信息!",
Data = null,
};
}
}
if (shelf != null && shelf.TransStatus == TransStatusEnum.运输中)
{
shelf.ShelfCode = shelf.ShelfCode + "(运输中)";
}
return new ResponseBase()
{
Code = 200,
Message = $"success",
Data = new GetShelfInfoByLocationReturnData()
{
LocationId = location.Id,
LocationCode = location.LocationCode,
ShelfId = shelf?.Id,
ShelfCode = shelf?.ShelfCode,
},
};
}
[Route("getShelfInfoByShelfCode")]
[HttpPost(Name = "getShelfInfoByShelfCode")]
public async Task getShelfInfoByShelfCode(GetShelfInfoByShelfCodeRequest request)
{
//判断参数
if (string.IsNullOrEmpty(request.ShelfCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "货架编码为空!",
Data = null,
};
}
//获取是否存在当前工位
var shelf = await DbHelp.db.Queryable()
.Where(t => t.ShelfCode == request.ShelfCode)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (shelf == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"货架[{request.ShelfCode}]不存在或者已被禁用!\r\n请联系系统管理人员维护货架信息!",
Data = null,
};
}
return new ResponseBase