using Masuit.Tools; using Newtonsoft.Json; using System.Text.Json.Nodes; using System.Xml.Serialization; using WIDESEA.Common; using WIDESEA_Common; using WIDESEA_Common.ZY; using WIDESEA_Core; using WIDESEA_Core.Enums; using WIDESEA_Core.Helper; using WIDESEA_Model.Models; namespace WIDESEA_StoragIntegrationServices { public partial class ToAPPService { public WebResponseContent SaveCLinfo(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); try { //如当前存在未开始入库的车轮或制动盘数据,则禁止保存新数据 以防数据混乱 var waitInbound = _InWheels_MesRepository.QueryFirst(x => x.Wheels_CurrentStatue == "0"); if (waitInbound != null) throw new Exception("当前存在未开始入库的车轮或制动盘,请先入库后再保存信息!"); //车轮码 string clCode = saveModel.MainData["code"].ToString(); //车轮号 string clh = saveModel.MainData["clh"].ToString(); if (string.IsNullOrEmpty(clCode) || string.IsNullOrEmpty(clh)) throw new Exception($"车轮条码不能为空"); if (!clCode.Contains("/") && !clCode.ToUpper().StartsWith("L")) throw new Exception($"车轮条码错误,请重新核对"); var clinfo = _InWheels_MesRepository.QueryFirst(x => x.Wheels_code == clCode || x.Wheels_Num == clh); if (clinfo != null) throw new Exception("车轮录入信息已存在"); //检测库存是否已存在 _WheelsStockRepository.QueryFirst(x => x.Wheels_code == clCode || x.Wheels_Num == clh); if (clinfo != null) throw new Exception("库内已存在,请检查库存"); //序列号 //string madeUnit = saveModel.MainData["xlh"].ToString(); //轮对条码 string ldtm = saveModel.MainData["ldtm"].ToString(); //车型 string Cartype = saveModel.MainData["chexing"].ToString(); if (string.IsNullOrEmpty(Cartype)) throw new Exception($"车型参数为空,不允许入库"); //配属局 string psj = saveModel.MainData["psj"].ToString(); //车组号 string lcch = saveModel.MainData["lcch"].ToString(); //新旧 (0-新 1-旧) string newOrOld = saveModel.MainData["neworold"].ToString(); if (string.IsNullOrEmpty(newOrOld)) throw new Exception($"新旧参数为空,不允许入库"); //轮对号 string ldh = saveModel.MainData["ldh"].ToString(); //轮型 string ldxh = saveModel.MainData["ldxh"].ToString(); if (string.IsNullOrEmpty(ldxh)) throw new Exception($"轮型参数为空,不允许入库"); //毂孔等级 string gkdj = saveModel.MainData["gkdj"].ToString(); if (string.IsNullOrEmpty(gkdj)) throw new Exception($"毂孔等级参数为空,不允许入库"); //毂孔a界面均值 string gkzja = saveModel.MainData["gkzja"].ToString(); //毂孔b界面均值 string gkzjb = saveModel.MainData["gkzjb"].ToString(); //毂孔c界面均值 string gkzjc = saveModel.MainData["gkzjc"].ToString(); //轮径值 string ljz = saveModel.MainData["ljz"].ToString(); //预估轮径值 string yglj = saveModel.MainData["yglj"].ToString(); //属性 string WheelsProps = saveModel.MainData["clsx"].ToString(); //轮缘 string lyh = saveModel.MainData["lyh"].ToString(); //动拖属性 string mttype = saveModel.MainData["mttype"].ToString(); if (string.IsNullOrEmpty(mttype)) throw new Exception($"动拖属性参数为空,不允许入库"); //毂孔均值 string gkcc = saveModel.MainData["gkcc"].ToString(); if (string.IsNullOrEmpty(gkcc)) throw new Exception($"毂孔均值参数为空,不允许入库"); //入库时间 string rksj = saveModel.MainData["rksj"].ToString(); if (string.IsNullOrEmpty(rksj)) throw new Exception($"入库时间参数为空,不允许入库"); //检测剩余空库位数量是否足够 --todo:内外侧空库位检测 if (_locationRepository.QueryData(x => x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1).Count < 2) throw new Exception($"库位数量不足,不允许入库"); //if (newOrOld == "0") //{ gkdj = LevelChangeHelper.LevelChangeType(gkdj); if (string.IsNullOrEmpty(gkdj)) throw new Exception("等级转换失败,请检查接口等级参数"); //} Dt_InWheels_mes wheels_Mes = new Dt_InWheels_mes { Wheels_code = clCode, Wheels_Type = "1", Wheels_Num = clh, CreateDate = DateTime.Now, Creater = "admin", WheelsProps = WheelsProps, Wheels_CarNo = lcch, Wheels_CarType = Cartype, Wheels_ldxh = ldxh, Wheels_CurrentStatue = "0", Wheels_ldtm = ldtm, Wheels_InDate = rksj, Wheels_level = gkdj, Wheels_NewOrOld = newOrOld == "旧" ? "1" : "0", Wheels_psj = psj, Wheels_gkcc = gkcc, Wheels_gkzja = gkzja, Wheels_gkzjb = gkzjb, Wheels_gkzjc = gkzjc, Wheels_ldh = ldh, Wheels_ljz = ljz, Wheels_mttype = mttype, //Wheels_SequenceNum = "", Wheels_ygljz = yglj, Wheels_LYH = lyh }; if (_InWheels_MesRepository.AddData(wheels_Mes) > 0) { return content.OK("保存成功"); } else { return content.Error("保存失败"); } } catch (Exception ex) { return content.Error($"{ex.Message}"); } } } }