Files
wcs/WCS.WebApi/Controllers/PDAMatBindController.cs
hehaibing-1996 8112e697e6 1.PDA物料绑定限制同一货架只能绑定一种物料
2.提交版本履历表
2025-03-18 08:46:55 +08:00

485 lines
19 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 NPOI.SS.Formula.Functions;
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.Home;
using WCS.Model.ApiModel.LocationInfo;
using WCS.Model.ApiModel.MatDetailHistoryInfo;
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 IPDAMatBindService _PDAMatBindService { get; set; }
public PDAMatBindController(IPDAMatBindService PDAMatBindService)
{
_PDAMatBindService = PDAMatBindService;
}
[Route("getShelfInfoByLocationCode")]
[HttpPost(Name = "getShelfInfoByLocationCode")]
public async Task<ResponseBase> getShelfInfoByLocationCode(GetShelfInfoByLocationCodeRequest request)
{
//不含XY就不是工位
if (!request.LocationCode.Contains("XY"))
{
request.LocationCode = string.Empty;
}
//判断参数
//if (string.IsNullOrEmpty(request.LocationCode) && string.IsNullOrEmpty(request.ShelfCode))
if (string.IsNullOrEmpty(request.ShelfCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "工位码或货架码为空,请重新扫码!",
Data = null,
};
}
//获取是否存在当前工位
//扫的工位码
LocationInfo? location = null;
ShelfInfo? shelf;
if (!string.IsNullOrEmpty(request.LocationCode))
{
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,
};
}
//获取当前工位的货架
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();
}
//货架到位置了 扫的货架码
else
{
//获取当前工位的货架
shelf = await DbHelp.db.Queryable<ShelfInfo>()
.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<LocationInfo>()
.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 + "(运输中)";
}
//允许放置的货架类型
var shelfTypes = new List<ShelfTypeModel>();
if (location != null)
{
shelfTypes.Add(new ShelfTypeModel()
{
Id = 0,
ShelfTypeName = "请选择"
});
var shelfTypeInDb = await DbHelp.db.Queryable<ShelfTypeInfo>()
.WhereIF(location.AllowShelfTypes != null && location.AllowShelfTypes.Count > 0, t => location.AllowShelfTypes.Contains(t.Id))
.ToListAsync();
shelfTypeInDb.ForEach(t =>
{
shelfTypes.Add(new ShelfTypeModel() { Id = t.Id, ShelfTypeName = t.ShelfTypeName });
});
}
else
{
shelfTypes.Add(new ShelfTypeModel()
{
Id = 0,
ShelfTypeName = "请先获取工位码"
});
}
var locationAreas = new List<LocationAreaInfoModel>();
if (location != null)
{
//货架送回的区域
locationAreas.Add(new LocationAreaInfoModel
{
Id = 0,
LocationAreaName = "请选择"
});
var locationAreaInDb = await DbHelp.db.Queryable<LocationAreaInfo>()
.WhereIF(location.AllowDestinationLocationArea != null && location.AllowDestinationLocationArea.Count > 0, t => location.AllowDestinationLocationArea.Contains(t.Id))
.ToListAsync();
locationAreaInDb.ForEach(t =>
{
locationAreas.Add(new LocationAreaInfoModel() { Id = t.Id, LocationAreaName = t.LocationAreaName });
});
}
else
{
locationAreas.Add(new LocationAreaInfoModel() { Id = 0, LocationAreaName = "请先获取工位码" });
}
return new ResponseBase<GetShelfInfoByLocationReturnData>()
{
Code = 200,
Message = $"success",
Data = new GetShelfInfoByLocationReturnData()
{
LocationId = location == null ? 0 : location.Id,
LocationCode = location?.LocationCode,
ShelfId = shelf?.Id,
ShelfCode = shelf?.ShelfCode,
ShelfTypes = shelfTypes,
LocationArea = locationAreas
},
};
}
[Route("getShelfInfoByShelfCode")]
[HttpPost(Name = "getShelfInfoByShelfCode")]
public async Task<ResponseBase> getShelfInfoByShelfCode(GetShelfInfoByShelfCodeRequest request)
{
//判断参数
if (string.IsNullOrEmpty(request.ShelfCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "货架编码为空!",
Data = null,
};
}
//获取是否存在当前工位
var shelf = await DbHelp.db.Queryable<ShelfInfo>()
.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<object>()
{
Code = 200,
Message = $"success",
Data = new
{
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.ShelfCode.Contains("运输中"))
{
return new ResponseCommon()
{
Code = 201,
Message = "货架运输中!\r\n请等待运输完成后扫货架码或点查询后再进行绑定",
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
//获取当前工位的货架
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}]已被禁用!",
Data = null,
};
}
if (shelf.TransStatus == TransStatusEnum.)
{
return new ResponseCommon()
{
Code = 201,
Message = "货架运输中!\r\n请等待运输完成后扫货架码或点查询后再进行绑定",
Data = null,
};
}
//获取货架是否已绑定物料
var matCurrentInfo = await DbHelp.db.Queryable<MatDetailCurrentInfo>()
.Where(t => t.ShelfId == shelf.Id)
.OrderBy(t => t.Id)
.FirstAsync();
//货架已绑定物料
if (matCurrentInfo != null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"当前货架已绑定物料:\r\n{matCurrentInfo.MatCode}\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
try
{
DbHelp.db.BeginTran();
//校验合格 进行保存
var matDetailCurrentInfo = new MatDetailCurrentInfo()
{
ShelfId = shelf.Id,
ShelfCode = shelf.ShelfCode,
ShelfType = shelf.ShelfTypeName,
//ShelfArea = shelf.ShelfArea,
MatCode = matBaseInfo.MatCode,
MatName = matBaseInfo.MatName,
MatBatch = request.MatBatch,
MatSupplier = matBaseInfo.MatSupplier,
MatCustomer = matBaseInfo.MatCustomer,
MatSpec = matBaseInfo.MatSpec,
MatUnit = matBaseInfo.MatUnit,
MatQty = request.Qty,
ModifyUser = request.UserName,
};
//新增数据修改记录表
var historyInfo = new MatDetailHistoryInfo()
{
ShlefId = matDetailCurrentInfo.ShelfId,
ShelfType = matDetailCurrentInfo.ShelfType,
ShelfCode = matDetailCurrentInfo.ShelfCode,
MatCode = matDetailCurrentInfo.MatCode,
MatName = matDetailCurrentInfo.MatName,
MatBatch = matDetailCurrentInfo.MatBatch,
MatSpec = matDetailCurrentInfo.MatSpec,
MatCustomer = matDetailCurrentInfo?.MatCustomer,
MatSupplier = matDetailCurrentInfo?.MatSupplier,
BeforeQty = 0,
AfterQty = matDetailCurrentInfo.MatQty,
ModifyTime = DateTime.Now,
ModifyUser = request.UserName,
RecordType = RecordTypeEnum.,
FunctionType = FunctionTypeEnum.PDA物料绑定,
};
DbHelp.db.Insertable(matDetailCurrentInfo).ExecuteCommand();
DbHelp.db.Insertable(historyInfo).ExecuteCommand();
DbHelp.db.CommitTran();
DataProcessManager.UpdateShelfStatus();
return new ResponseCommon()
{
Code = 200,
Message = "success",
Data = null,
};
}
catch (Exception ex)
{
DbHelp.db.RollbackTran();
throw ex;
}
}
catch (Exception ex)
{
return new ResponseCommon()
{
Code = 201,
Message = ex.Message,
Data = null,
};
}
}
[Route("callEmptyShelf")]
[HttpPost(Name = "callEmptyShelf")]
public async Task<ResponseCommon> callEmptyShelf(BindMatDetailRequest request)
{
try
{
return await _PDAMatBindService.callEmptyShelf(request);
}
catch (Exception ex)
{
return new ResponseCommon()
{
Code = 201,
Message = ex.Message,
Data = null,
};
}
}
[Route("bindSendBackShelf")]
[HttpPost(Name = "bindSendBackShelf")]
public async Task<ResponseCommon> bindSendBackShelf(BindMatDetailRequest request)
{
try
{
return await _PDAMatBindService.bindSendBackShelf(request);
}
catch (Exception ex)
{
return new ResponseCommon()
{
Code = 201,
Message = ex.Message,
Data = null,
};
}
}
}
}