Files
wcs/WCS.WebApi/Controllers/PDAMatBindController.cs
hehaibing-1996 a4c02a9173 1.PDA绑定相关接口
2.货架存量 后端接口
2025-01-13 20:08:03 +08:00

229 lines
8.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc;
using WCS.BLL.DbModels;
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
{
/// <summary>
/// PDA物料绑定相关接口
/// </summary>
[ApiController]
[Route("[controller]")]
public class PDAMatBindController : ControllerBase
{
public IWarningService _warningService { get; set; }
public PDAMatBindController(IWarningService warningService)
{
_warningService = warningService;
}
[Route("getShelfInfoByLocationCode")]
[HttpPost(Name = "getShelfInfoByLocationCode")]
public async Task<ResponseBase> getShelfInfoByLocationCode(GetShelfInfoByLocationCodeRequest request)
{
//判断参数
if (string.IsNullOrEmpty(request.LocationCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "工位编码为空!",
Data = null,
};
}
//获取是否存在当前工位
var location = await DbHelp.db.Queryable<LocationInfo>()
.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,
};
}
//获取当前工位的货架
var shelf = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.CurrentLocationId == location.Id && t.TransStatus == TransStatusEnum.
|| t.DestinationLocationId == location.Id && t.TransStatus == TransStatusEnum.)//解决产线人员 呼叫后货架未到的时候绑定的问题
.Where(t => t.IsEnable)
.FirstAsync();
return new ResponseBase<GetShelfInfoByLocationReturnData>()
{
Code = 200,
Message = $"success",
Data = new GetShelfInfoByLocationReturnData()
{
LocationId = location.Id,
LocationCode = request.LocationCode,
ShelfId = shelf?.Id,
ShelfCode = shelf?.ShelfCode,
},
};
}
[Route("bindMatDetail")]
[HttpPost(Name = "bindMatDetail")]
public async Task<ResponseCommon> bindMatDetail(BindMatDetailRequest request)
{
try
{
#region
//判断参数
if (request.LocationId == 0 || string.IsNullOrEmpty(request.LocationCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "工位或工位编码为空!",
Data = null,
};
}
if (request.ShelfId == 0 || string.IsNullOrEmpty(request.ShelfCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "货架或货架编码为空!",
Data = null,
};
}
if (request.MatBaseInfoId == 0 || string.IsNullOrEmpty(request.MatCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "未选择物料!",
Data = null,
};
}
if (request.Qty <= 0)
{
return new ResponseCommon()
{
Code = 201,
Message = "数量应大于等于1",
Data = null,
};
}
#endregion
#region
//判断参数
if (string.IsNullOrEmpty(request.LocationCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "工位编码为空!",
Data = null,
};
}
//获取是否存在当前工位
var location = await DbHelp.db.Queryable<LocationInfo>()
.Where(t => t.Id == request.LocationId)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (location == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"工位[{request.LocationCode}]不存在或已被禁用!\r\n请联系系统管理人员维护工位信息",
Data = null,
};
}
//获取当前工位的货架
var shelf = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.Id == request.ShelfId)
.Where(t => t.CurrentLocationId == location.Id && t.TransStatus == TransStatusEnum.
|| t.DestinationLocationId == location.Id && t.TransStatus == TransStatusEnum.)//解决产线人员 呼叫后货架未到的时候绑定的问题
.Where(t => t.IsEnable == true)
.FirstAsync();
if (shelf == null)
{
return new ResponseCommon()
{
Code = 205,
Message = $"货架[{request.ShelfCode}],已不在工位上!\r\n请进行【货架呼叫】",
Data = null,
};
}
//获取物料基础信息
var matBaseInfo = await DbHelp.db.Queryable<MatBaseInfo>()
.Where(t => t.Id == request.MatBaseInfoId)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (matBaseInfo == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"不存在物料[{request.MatCode}]或已被禁用!",
Data = null,
};
}
#endregion
//校验合格 进行保存
var matDetailCurrentInfo = new MatDetailCurrentInfo()
{
ShlefId = shelf.Id,
ShelfCode = shelf.ShelfCode,
ShelfType = shelf.ShelfTypeName,
ShelfArea = shelf.ShelfArea,
MatCode = matBaseInfo.MatCode,
MatName = matBaseInfo.MatName,
MatSupplier = matBaseInfo.MatSupplier,
MatCustomer = matBaseInfo.MatCustomer,
MatSpec = matBaseInfo.MatSpec,
MatUnit = matBaseInfo.MatUnit,
MatQty = request.Qty,
ModifyUser = request.UserName,
};
DbHelp.db.Insertable(matDetailCurrentInfo).ExecuteCommand();
return new ResponseCommon()
{
Code = 200,
Message = "success",
Data = null,
};
}
catch (Exception ex)
{
return new ResponseCommon()
{
Code = 201,
Message = ex.Message,
Data = null,
};
}
}
}
}