20240625 接收大简云订舱 箱信息改为每次都删除全部保存此次接收的

dev
ddlucky 5 months ago
parent 0fd700ef43
commit 68d502cb23

@ -1220,56 +1220,78 @@ namespace DSWeb.Areas.CommMng.DAL
if (ctnInputs != null)
{
var CurrCtnList = new List<op_ctn_md>();
//var CurrCtnList = new List<op_ctn_md>();
if (BSNO != "*") {
//CurrCtnList = DSWeb.MvcShipping.DAL.MsOpSeaeDAL.MsOpSeaeDAL.GetBodyList($" BSNO='{BSNO}'");
CurrCtnList = cdc.OP_CTN.Where(x => x.BSNO == BSNO).ToList();
var djyctnids = ctnInputs.Select(x => x.id).ToList();
var Ctn = CurrCtnList.Where(x => !djyctnids.Contains(x.DJYCTNID)).ToList();
if (Ctn != null && Ctn.Count > 0)
////CurrCtnList = DSWeb.MvcShipping.DAL.MsOpSeaeDAL.MsOpSeaeDAL.GetBodyList($" BSNO='{BSNO}'");
//CurrCtnList = cdc.OP_CTN.Where(x => x.BSNO == BSNO).ToList();
//var djyctnids = ctnInputs.Select(x => x.id).ToList();
//var 需删除Ctn = CurrCtnList.Where(x => !djyctnids.Contains(x.DJYCTNID)).ToList();
//if (需删除Ctn != null && 需删除Ctn.Count > 0)
//{
// cdc.OP_CTN.RemoveRange(需删除Ctn);
// cdc.SaveChanges();
// result.AddRange(需删除Ctn);
// //var 需删除Ctnid = 需删除Ctn.Select(s => s.CTN_ID).ToArray();
// //var delidstr = "'"+string.Join("','", 需删除Ctnid )+ "'";
// //Database db = DatabaseFactory.CreateDatabase();
// //using (var conn = db.CreateConnection())
// //{
// // conn.Open();
// // var tran = conn.BeginTransaction();
// // try
// // {
// // var cmdDeletectn = db.GetSqlStringCommand(" delete from op_ctn where ctn_id in(" + delidstr + ") ");
// // db.ExecuteNonQuery(cmdDeletectn, tran);
// // }
// // catch (Exception e)
// // {
// // tran.Rollback();
// // BasicDataRefDAL.SaveLog(JsonConvert.SerializeObject(e), "删除箱", "接收大简云订舱", "错误");
// // //return result;
// // }
// //}
//}
//20240625 改为删除所有本地集装箱信息 然后重新保存报文里的
var delcondition = $" BSNO='{BSNO}'";
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
cdc.OP_CTN.RemoveRange(Ctn);
result.AddRange(Ctn);
//var 需删除Ctnid = 需删除Ctn.Select(s => s.CTN_ID).ToArray();
//var delidstr = "'"+string.Join("','", 需删除Ctnid )+ "'";
//Database db = DatabaseFactory.CreateDatabase();
//using (var conn = db.CreateConnection())
//{
// conn.Open();
// var tran = conn.BeginTransaction();
// try
// {
// var cmdDeletectn = db.GetSqlStringCommand(" delete from op_ctn where ctn_id in(" + delidstr + ") ");
// db.ExecuteNonQuery(cmdDeletectn, tran);
// }
// catch (Exception e)
// {
// tran.Rollback();
// BasicDataRefDAL.SaveLog(JsonConvert.SerializeObject(e), "删除箱", "接收大简云订舱", "错误");
// //return result;
// }
//}
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDeletectn = db.GetSqlStringCommand(" delete from op_ctn where "+ delcondition);
db.ExecuteNonQuery(cmdDeletectn, tran);
BasicDataRefDAL.SaveLog(cmdDeletectn, "删除箱", "接收大简云订舱", "执行");
}
catch (Exception e)
{
tran.Rollback();
BasicDataRefDAL.SaveLog(JsonConvert.SerializeObject(e), "删除箱", "接收大简云订舱", "错误");
//return result;
}
}
}
foreach (var ctn in ctnInputs)
{
var infoList = cdc.CODE_CTN.Where(x =>
(x.CTNSIZE + "'" + x.CTNTYPE) == ctn.ctnall
|| (x.CTNSIZE + x.CTNTYPE) == ctn.ctnall
|| (x.CTNSIZE + "'" + x.CTNTYPE.Replace("OT", "O/T")) == ctn.ctnall
|| (x.CTNSIZE + x.CTNTYPE.Replace("OT", "O/T")) == ctn.ctnall
(x.CTNSIZE + "'" + x.CTNTYPE) == ctn.ctnall
|| (x.CTNSIZE + x.CTNTYPE) == ctn.ctnall
|| (x.CTNSIZE + "'" + x.CTNTYPE.Replace("OT", "O/T")) == ctn.ctnall
|| (x.CTNSIZE + x.CTNTYPE.Replace("OT", "O/T")) == ctn.ctnall
).ToList();
var info = new CODE_CTN_md();
if (infoList != null && infoList.Count > 0)
@ -1283,37 +1305,37 @@ namespace DSWeb.Areas.CommMng.DAL
var ctnbsno = BSNO;
if ( CurrCtnList.Exists(x => x.DJYCTNID == ctn.id))
{
ctnbsno = BSNO;
var updctn = CurrCtnList.FirstOrDefault(x => x.DJYCTNID == ctn.id);
updctn.CTNCODE = info.CTNID;
updctn.SIZE = info.CTNSIZE;
updctn.CTN = info.CTN;
updctn.BSNO = ctnbsno;
updctn.CTNALL = ctn.ctnall;
updctn.CTNNUM = ctn.ctnnum == null ? 0 : (int)ctn.ctnnum;
updctn.CNTRNO = ctn.cntrno;
updctn.SEALNO = ctn.sealno;
updctn.PKGS = ctn.pkgs == null ? 0 : (int)ctn.pkgs;
updctn.KINDPKGS = ctn.kindpkgs;
updctn.KGS = ctn.kgs == null ? 0 : (decimal)ctn.kgs;
updctn.CBM = ctn.cbm == null ? 0 : (decimal)ctn.cbm;
updctn.TAREWEIGHT = ctn.tareweight == null ? 0 : (decimal)ctn.tareweight;
updctn.TEU = info.TEU == null ? 0 : (int)info.TEU;
updctn.WEIGHKGS = ctn.weighkgs == null ? 0 : (decimal)ctn.weighkgs;
//DJYCTNID = ctn.id;
result.Add(updctn);
cdc.OP_CTN.AddOrUpdate(updctn);
}
else
{
//if ( CurrCtnList.Exists(x => x.DJYCTNID == ctn.id))
//{
// ctnbsno = BSNO;
// var updctn = CurrCtnList.FirstOrDefault(x => x.DJYCTNID == ctn.id);
// updctn.CTNCODE = 箱型info.CTNID;
// updctn.SIZE = 箱型info.CTNSIZE;
// updctn.CTN = 箱型info.CTN;
// updctn.BSNO = ctnbsno;
// updctn.CTNALL = ctn.ctnall;
// updctn.CTNNUM = ctn.ctnnum == null ? 0 : (int)ctn.ctnnum;
// updctn.CNTRNO = ctn.cntrno;
// updctn.SEALNO = ctn.sealno;
// updctn.PKGS = ctn.pkgs == null ? 0 : (int)ctn.pkgs;
// updctn.KINDPKGS = ctn.kindpkgs;
// updctn.KGS = ctn.kgs == null ? 0 : (decimal)ctn.kgs;
// updctn.CBM = ctn.cbm == null ? 0 : (decimal)ctn.cbm;
// updctn.TAREWEIGHT = ctn.tareweight == null ? 0 : (decimal)ctn.tareweight;
// updctn.TEU = 箱型info.TEU == null ? 0 : (int)箱型info.TEU;
// updctn.WEIGHKGS = ctn.weighkgs == null ? 0 : (decimal)ctn.weighkgs;
// //DJYCTNID = ctn.id;
// result.Add(updctn);
// cdc.OP_CTN.AddOrUpdate(updctn);
//}
//else
//{
//如果DS7里面没有这个djyctnid保存时新增依据BSNO = *作为标记(ds7现有逻辑)
var newctn = ctn.GetNewCtn(BSNO, info);
result.Add(newctn);
cdc.OP_CTN.Add(newctn);
}
//}
}

Loading…
Cancel
Save