using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Estsh.Core.Base; using Estsh.Core.Wms.IRepositories; using Estsh.Core.Wms.IServices; using Estsh.Core.Model.Result; using Estsh.Core.Services; using Estsh.Core.Repositories; using Estsh.Core.Models; using Newtonsoft.Json.Linq; using static Estsh.Core.Model.EnumUtil.WmsEnumUtil; using Estsh.Core.Model.EnumUtil; namespace Estsh.Core.Wms.Services { public class MaterialService : BaseService, IMaterialService { private readonly IMaterialRepository repository; public MaterialService(IMaterialRepository _repository) : base(_repository) { repository = _repository; } /// /// 获取箱条码信息 /// /// /// public SetObjectDetail GetMaterialInfo(string cartonNo) { SetObjectDetail det = new SetObjectDetail(); List MaterialInfo = repository.GetMaterialInfo(cartonNo); if (MaterialInfo.Count == 0) { det.type = "NO"; det.message = "[" + cartonNo + "]:箱条码不存在,请检查!"; return det; } if (MaterialInfo[0].Enabled.Equals("N")) { det.type = "NO"; det.message = "[" + cartonNo + "]:包装条码已被冻结,请检查!"; return det; } else if (MaterialInfo[0].Status != (int)WmsEnumUtil.StockStatus.INSTOCKED && MaterialInfo[0].Status != (int)WmsEnumUtil.StockStatus.ONLINED && MaterialInfo[0].Status != (int)WmsEnumUtil.StockStatus.NC_INSTOCK) { det.type = "NO"; det.message = "[" + cartonNo + "]:该条码不是已上架/已上线状态,是" + MaterialInfo[0].StockStatus + "状态,请检查!"; return det; } if (MaterialInfo[0].Qty < 1) { det.type = "NO"; det.message = "[" + cartonNo + "]:箱条码数量不足,无法拆分!"; return det; } det.type = "OK"; det.wmsObjectDetail = MaterialInfo.ConvertAll(s => (object)s); return det; } /// /// 扫描条码 /// /// /// public SetObjectDetail ScanCode(string cartonNo) { SetObjectDetail det = new SetObjectDetail(); int MaterialInfo = repository.ScanCode(cartonNo); det.type = "OK"; return det; } public SetObjectDetail SpellCode(string cartonNo) { SetObjectDetail det = new SetObjectDetail(); List MaterialInfo = repository.SpellCode(cartonNo); det.type = "OK"; det.wmsObjectDetail = MaterialInfo.ConvertAll(s => (object)s); return det; } public SetObjectDetail TailBox(string cartonNo) { SetObjectDetail det = new SetObjectDetail(); List MaterialInfo = new List() ; List GetInfo = repository.GetMaterialInfo(cartonNo);//得到条码信息 if (GetInfo.Count > 0) { MaterialInfo = repository.TailBox(GetInfo[0].PartNo); } if (GetInfo.Count == 0) { MaterialInfo = repository.TailBox(cartonNo); } if (MaterialInfo.Count > 0) { det.type = "OK"; } else { det.type = "NO"; } det.wmsObjectDetail = MaterialInfo.ConvertAll(s => (object)s); return det; } /// /// 拆分 箱条码 /// /// /// /// /// /// public SetObjectDetail CheckMaterialSplit(string cartonNo, int splitNum, string loginId, int splitCount) { SetObjectDetail det = new SetObjectDetail(); //需要拆分的箱条码信息 List MaterialInfo = repository.GetMaterialInfo(cartonNo); if (MaterialInfo.Count == 0) { det.type = "NO"; det.message = "[" + cartonNo + "]:箱条码不存在,请检查!"; return det; } if (MaterialInfo[0].Enabled.Equals("N")) { det.type = "NO"; det.message = "[" + cartonNo + "]:包装条码已被冻结,请检查!"; return det; } //else if (MaterialInfo[0].Status != (int)WmsEnumUtil.StockStatus.INSTOCKED && MaterialInfo[0].Status != (int)WmsEnumUtil.StockStatus.ONLINED) //{ // det.type = "NO"; // det.message = "[" + cartonNo + "]:是" + MaterialInfo[0].StockStatus + "状态,请检查!"; // return det; //} if (MaterialInfo[0].Qty < 1) { det.type = "NO"; det.message = "[" + cartonNo + "]:箱条码数量不足,无法拆分!"; return det; } List NewStock = repository.CheckMaterialSplit(MaterialInfo, splitNum, loginId, splitCount); if (NewStock == null || NewStock.Count == 0) { det.type = "NO"; det.message = "执行失败!请重试!"; } else { det.type = "OK"; det.wmsObjectDetail = NewStock.ConvertAll(s => (object)s); } return det; } /// /// 合并 /// /// /// /// /// public SetObjectDetail CheckMaterialConsolidation(string hostCartonNo, string SecondaryCartonNo, string loginId) { SetObjectDetail det = new SetObjectDetail(); //主箱条码信息 List host = repository.GetMaterialInfo(hostCartonNo); if (host.Count == 0) { det.type = "NO"; det.message = "[" + hostCartonNo + "]:主箱条码不存在,请检查!"; return det; } if (host[0].Enabled.Equals("N")) { det.type = "NO"; det.message = "[" + hostCartonNo + "]:主箱条码已被冻结,请检查!"; return det; } else if (host[0].Status != (int)WmsEnumUtil.StockStatus.INSTOCKED) { det.type = "NO"; det.message = "[" + hostCartonNo + "]:是" + host[0].StockStatus + "状态,请检查!"; return det; } //副箱条码信息 List Secondary = repository.GetMaterialInfo(SecondaryCartonNo); if (Secondary.Count == 0) { det.type = "NO"; det.message = "[" + hostCartonNo + "]:副箱条码不存在,请检查!"; return det; } if (Secondary[0].Enabled.Equals("N")) { det.type = "NO"; det.message = "[" + hostCartonNo + "]:副箱条码已被冻结,请检查!"; return det; } else if (Secondary[0].Status != (int)WmsEnumUtil.StockStatus.INSTOCKED) { det.type = "NO"; det.message = "[" + hostCartonNo + "]:是" + Secondary[0].StockStatus + "状态,请检查!"; return det; } //条码匹配检查 if (!host[0].LocateId.Equals(Secondary[0].LocateId) || !host[0].WarehouseId.Equals(Secondary[0].WarehouseId) || !host[0].ZoneId.Equals(Secondary[0].ZoneId)) { det.type = "NO"; det.message = "[" + hostCartonNo + "]:合并条码库位不一致,请检查!"; return det; } if (!host[0].Status.Equals(Secondary[0].Status)) { det.type = "NO"; det.message = "[" + hostCartonNo + "]:合并条码状态不一致,请检查!"; return det; } if (!host[0].LotNo.Equals(Secondary[0].LotNo)) { det.type = "NO"; det.message = "[" + hostCartonNo + "]:合并条码批次不一致,请检查!"; return det; } List NewStock = repository.CheckMaterialConsolidation(host, Secondary, loginId); if (NewStock == null || NewStock.Count == 0) { det.type = "NO"; det.message = "执行失败!请重试!"; } else { det.type = "OK"; det.wmsObjectDetail = NewStock.ConvertAll(s => (object)s); } return det; } } }