wms_serve_m_jinwangbancai/WmsMobileServe/ApiServe/Mobile/Service/StockInService.cs

189 lines
9.4 KiB
C#
Raw Normal View History

using WmsMobileServe.Annotation;
using WmsMobileServe.ApiClient.Mes;
using WmsMobileServe.ApiClient.Mes.Dto;
using WmsMobileServe.ApiServe.Mobile.Dto;
using WmsMobileServe.ApiServe.Mobile.Vo;
using WmsMobileServe.DataBase.Base.Dao;
using WmsMobileServe.DataBase.Base.Po;
using WmsMobileServe.Utils;
namespace WmsMobileServe.ApiServe.Mobile.Service;
[Component]
public class StockInService(MesApiClient mesApiClient, TOnGoodsShelfDao onGoodsShelfDao, TMiStockDao miStockDao)
{
/// <summary>
/// 空载具入库
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public MobileApiResponse EmptyVehicleIn(EmptyVehicleInReq request)
{
if (string.IsNullOrEmpty(request.VehicleNo)) return MobileApiResponse.Fail("传入的载具号为空");
/* 检验载具是否有入库任务 */
var stackInRasks = onGoodsShelfDao.SelectWithVehicleNo(request.VehicleNo);
if(stackInRasks == default) return MobileApiResponse.Fail("数据服务异常,请稍后再试");
if(stackInRasks.Count > 0) return MobileApiResponse.Fail(string.Format("该载具号:{0} 存在入库任务,请核实后再试", request.VehicleNo));
/* 检验载具是否在库存中 */
var stocks = miStockDao.SelectWithVehicleNo(request.VehicleNo);
if (stocks == default) return MobileApiResponse.Fail("数据服务异常,请稍后再试");
if (stocks.Count > 0) return MobileApiResponse.Fail(string.Format("该载具号:{0} 仍在库中,请核实后再试", request.VehicleNo));
/* 构建空载具信息插入数据库 */
TOnGoodsShelf onGoodsShelf = new()
{
LotId = UUIDUtils.GetNewUUID2(),
GoodsId = "000000",
ProviderId = "景旺",
LocationId = "",
StoNum = 1,
AccNum = 1,
ShelfNum = 1,
StockNum = 0,
OnDate = DateTime.Now,
OnShelfUserId = "Mobile_Android",
StorageId = "-",
StorageAreaId = "-",
UpGoodsId = UUIDUtils.GetNewUUID2(),
GoodsTypeId = "0",
StorageMode = "空托入库",
ProdictionDate = DateTime.Now,
Ctl = request.VehicleNo,
BarCode = "-",
CustomerId = "景旺",
GoodsName = "空载具",
Status = "0",
Unit = "-",
TaskType = "1",
GoodsMeasureId = UUIDUtils.GetNewUUID2(),
PackingNum = 1,
DamageNum = 1,
Remark = ""
};
var insertResult = onGoodsShelfDao.Insert(onGoodsShelf);
if (insertResult > 0) return MobileApiResponse.Success(string.Format("空载具:{0} 产生入库任务成功", request.VehicleNo));
return MobileApiResponse.Fail(string.Format("空载具:{0} 产生入库任务失败,数据无法插入", request.VehicleNo));
}
/// <summary>
/// 获取箱子号对应的信息
/// </summary>
/// <param name="boxNo"></param>
/// <returns></returns>
public MobileApiResponse<GetGoodsDetailResp> GetGoodsDetail(string? boxNo)
{
if (string.IsNullOrEmpty(boxNo)) return MobileApiResponse<GetGoodsDetailResp>.Fail("无法识别的箱子号");
/* -------------- 测试 --------------------------- */
GetGoodsDetailResp mesGoodsDetailTest = new()
{
BoxNo = boxNo,
NumPerBox = 1,
GoodsNum = 23,
PacketNum = 44,
OtherNum = 12,
GoodsId = "000",
SaleOrderNo = "sa123",
PacketLevel = "1",
Cycle = "20天",
CustomSaleOrderNo = "Csale1122",
MinorWarehouseId = "99",
GoodsDesc = "测试物料",
};
return MobileApiResponse<GetGoodsDetailResp>.Success(data: mesGoodsDetailTest);
/* -------------- 测试结束 --------------------------- */
var response = mesApiClient.GetOutBoxInfo(boxNo);
if (!response.IsSend) return MobileApiResponse<GetGoodsDetailResp>.Fail(string.Format("请求MES货物物料信息失败异常信息{0}", response.Exception?.Message));
string? responseData = response.ResponseMsg;
if (string.IsNullOrEmpty(responseData)) return MobileApiResponse<GetGoodsDetailResp>.Fail(string.Format("MES返回的信息无法识别信息{0}", responseData));
var responseDto = XmlUtils.Deserialize<GetOutBoxInfoResp>(responseData);
if (responseDto == null) return MobileApiResponse<GetGoodsDetailResp>.Fail(string.Format("MES返回的信息无法解析信息{0}", responseData));
string mesData = responseDto.Data ?? "";
string[] dataDetail = mesData.Split(':');
if (dataDetail.Length < 2) return MobileApiResponse<GetGoodsDetailResp>.Fail(string.Format("MES返回的信息格式不正确信息{0}", responseData));
if (dataDetail[0] != "Succ") return MobileApiResponse<GetGoodsDetailResp>.Fail(string.Format("MES返回箱子错误信息{0}", responseData));
string goodsInfo = dataDetail[1];
string[] goodsDetails = goodsInfo.Split("|");
if (goodsDetails.Length < 12) return MobileApiResponse<GetGoodsDetailResp>.Fail(string.Format("MES返回的箱子信息参数数量不足信息{0}", goodsDetails));
if(goodsDetails[0] != boxNo) return MobileApiResponse<GetGoodsDetailResp>.Fail(string.Format("MES返回的箱子号和扫描的箱子号不一致返回的箱号{0}", goodsDetails[0]));
string numPerBox = goodsDetails[1]; // 每包数量
string goodsNum = goodsDetails[2]; // 包装数量
string packetNum = goodsDetails[3]; // 包数量
string otherNum = goodsDetails[4]; // 零包数量
if(numPerBox.IsNotDecimal() || goodsNum.IsNotDecimal() || packetNum.IsNotDecimal() || otherNum.IsNotDecimal())
return MobileApiResponse<GetGoodsDetailResp>.Fail(string.Format("MES返回的箱子信息内的数量存在不是数字情况信息{0}", goodsDetails));
GetGoodsDetailResp mesGoodsDetail = new()
{
BoxNo = dataDetail[0],
NumPerBox = numPerBox.ToDecimal(),
GoodsNum = goodsNum.ToDecimal(),
PacketNum = packetNum.ToDecimal(),
OtherNum = otherNum.ToDecimal(),
GoodsId = dataDetail[5],
SaleOrderNo = dataDetail[6],
PacketLevel = dataDetail[7],
Cycle = dataDetail[8],
CustomSaleOrderNo = dataDetail[9],
MinorWarehouseId = dataDetail[10],
GoodsDesc = dataDetail[11],
};
return MobileApiResponse<GetGoodsDetailResp>.Success(data: mesGoodsDetail);
}
public MobileApiResponse BindingVehicleIn(BindingVehicleInReq request)
{
if (string.IsNullOrEmpty(request.VehicleNo) || request.BindingGoodsDetails == default) return MobileApiResponse.Fail("传入的数据无法识别");
if (request.BindingGoodsDetails.Count < 1) return MobileApiResponse.Fail("传入的数据为空");
/* 检验载具是否有入库任务 */
var stackInRasks = onGoodsShelfDao.SelectWithVehicleNo(request.VehicleNo);
if (stackInRasks == default) return MobileApiResponse.Fail("数据服务异常,请稍后再试");
if (stackInRasks.Count > 0) return MobileApiResponse.Fail(string.Format("该载具号:{0} 存在入库任务,请核实后再试", request.VehicleNo));
/* 检验载具是否在库存中 */
var stocks = miStockDao.SelectWithVehicleNo(request.VehicleNo);
if (stocks == default) return MobileApiResponse.Fail("数据服务异常,请稍后再试");
if (stocks.Count > 0) return MobileApiResponse.Fail(string.Format("该载具号:{0} 仍在库中,请核实后再试", request.VehicleNo));
/* 构建入库任务 */
List<TOnGoodsShelf> onGoodsShelves = []; // 需要入库的任务
foreach (var item in request.BindingGoodsDetails)
{
onGoodsShelves.Add(new()
{
LotId = UUIDUtils.GetNewUUID2(),
GoodsId = item.GoodsId,
ProviderId = item.SaleOrderNo,
LocationId = "",
StoNum = item.OtherNum,
AccNum = item.NumPerBox,
ShelfNum = item.GoodsNum,
StockNum = item.PacketNum,
OnDate = DateTime.Now,
OnShelfUserId = "Mobile_Android",
StorageId = "-",
StorageAreaId = item.MinorWarehouseId,
UpGoodsId = UUIDUtils.GetNewUUID2(),
GoodsTypeId = item.PacketLevel,
StorageMode = "码盘入库",
ProdictionDate = DateTime.Now,
Ctl = request.VehicleNo,
BarCode = item.BoxNo,
CustomerId = item.CustomSaleOrderNo,
GoodsName = item.GoodsDesc,
Status = "0",
Unit = "-",
TaskType = request.TaskType.ToString(),
GoodsMeasureId = item.SaleOrderNo,
PackingNum = 1,
DamageNum = 1,
ScaleUnit = item.Cycle,
Remark = ""
});
}
var insertResult = onGoodsShelfDao.Insert([.. onGoodsShelves]);
if (insertResult > 0) return MobileApiResponse.Success(string.Format("载具:{0} 产生入库任务成功", request.VehicleNo));
return MobileApiResponse.Fail(string.Format("载具:{0} 产生入库任务失败,数据无法插入", request.VehicleNo));
}
}