From 2f1d2dd3dbe6bd97e1e663cccfd7d4f923dc88e2 Mon Sep 17 00:00:00 2001 From: wet Date: Mon, 4 Jul 2022 22:56:19 +0800 Subject: [PATCH] 1 --- web/djy.Model/IsfDto/IsfInfo.cs | 2 +- web/djy.Service/ISF/IsfService.cs | 427 ++++++++++++++++-------------- 2 files changed, 230 insertions(+), 199 deletions(-) diff --git a/web/djy.Model/IsfDto/IsfInfo.cs b/web/djy.Model/IsfDto/IsfInfo.cs index 8503aa6..3618214 100644 --- a/web/djy.Model/IsfDto/IsfInfo.cs +++ b/web/djy.Model/IsfDto/IsfInfo.cs @@ -110,7 +110,7 @@ namespace djy.Model.IsfDto public class IsfInfo { - public List companyList { get; set; } + public object companyList { get; set; } public string format { get; set; } diff --git a/web/djy.Service/ISF/IsfService.cs b/web/djy.Service/ISF/IsfService.cs index bc7d2a9..050ea10 100644 --- a/web/djy.Service/ISF/IsfService.cs +++ b/web/djy.Service/ISF/IsfService.cs @@ -59,7 +59,7 @@ namespace djy.Service.Isf public string SaveInfo(ISFDto dto, User user) { string guid = ""; - var mlist = DbBus.Get(DbList.AMSCenter).Select().Where(x => x.IsDel != true && x.MBLNO == dto.MBLNO && x.GID != dto.GID&&x.MBLNO!="").ToOne(); + var mlist = DbBus.Get(DbList.AMSCenter).Select().Where(x => x.IsDel != true && x.MBLNO == dto.MBLNO && x.GID != dto.GID && x.MBLNO != "").ToOne(); if (mlist != null) { return "-1"; @@ -218,7 +218,7 @@ namespace djy.Service.Isf { string guid = ""; var list = DbBus.Get(DbList.AMSCenter).Select().Where(w => w.UserID == user.GID && w.TemPlateName == dto.TemPlateName && w.CompanyType == dto.CompanyType && w.InFoType == dto.InFoType && w.GID != dto.GID).ToOne(); - if (list!=null) + if (list != null) { return "-1"; } @@ -267,215 +267,246 @@ namespace djy.Service.Isf var fin = new FinanceService(); var master = DbBus.Get(DbList.AMSCenter).Select().Where(x => (x.IsDel == false || x.IsDel == null) && x.CompID == user.CompId && x.GID == oid).ToOne(); var comlist = DbBus.Get(DbList.AMSCenter).Select().Where(x => (x.IsDel == false || x.IsDel == null) && x.PID == oid).ToList(); - if (msgType != "3") + if (msgType == "3") { + req.Code = 201; + req.Message = "已删除单据不可以再次删除"; + return req; + } - if (msgType == "4" && !(master.ReportState == "已删除" || master.MateState == "匹配失败")) + if (msgType == "4" && !(master.ReportState == "已删除" || master.MateState == "匹配失败")) + { + req.Code = 200; + req.Message = "当前状态不能重发!如有疑问,请联系相关客服!"; + return req; + } + //if (msgType == "1" || msgType == "4") + //{ + // ///扣费接口 + // var getfinrs = fin.Expend(new CustFee + // { + // SENDUSERID = user.GID, + // LURURENID = user.GID, + // CtnrCount = 1, + // CtnrInfo = string.Empty, + // BSTYPE = 16, + // SENDTYPE = 0, + // BSNO = oid.ToString(), + // MBLNO = master.MBLNO.ToString(), + // } + // , 0); + // if (!getfinrs.Status) + // { + // req.Code = 201; + // req.Message = getfinrs.Message; + // return req; + // } + //} + var portList = DbBus.Get(DbList.Common).Select().ToList(); + var CodePortLoadList = DbBus.Get(DbList.Common).Select().ToList(); + Info info = new Info(); + info.masterBillNo = master.MBLNO; + info.infoType = master.InFoType; + info.dischargeHarbourCode = portList.Where(x => x.Code == master.DischargeHarbourCode).Select(x => x.EdiCode).FirstOrDefault(); + info.deliveryHarbourCode = portList.Where(x => x.Code == master.DeliveryHarbourCode).Select(x => x.EdiCode).FirstOrDefault(); + info.shipmentTypeCode = master.ShipmentTypeCode; + info.hstCode = master.HstCode; + info.blTypeCode = master.BlTypeCode; + info.refId = master.GID; + + List companyList = new List(); + JArray arr = new JArray(); + foreach (var item in comlist) + { + JObject obj = new JObject(); + + if (!item.Address.IsNullOrEmpty()) + obj.Add("address", new JValue($"{item.Address}")); + if (!item.City.IsNullOrEmpty()) + obj.Add("city", new JValue($"{item.City}")); + if (!item.CompanyId.IsNullOrEmpty()) + obj.Add("companyId", new JValue($"{item.CompanyId}")); + if (!item.CompanyName.IsNullOrEmpty()) + obj.Add("companyName", new JValue($"{item.CompanyName}")); + if (!item.CompanyType.IsNullOrEmpty()) + obj.Add("companyType", new JValue($"{item.CompanyType}")); + if (!item.CountryCode.IsNullOrEmpty()) + obj.Add("countryCode", new JValue($"{item.CountryCode}")); + if (!item.HstCode.IsNullOrEmpty()) + obj.Add("hstCode", new JValue($"{item.HstCode}")); + if (!item.IdTypeCode.IsNullOrEmpty()) + obj.Add("idTypeCode", new JValue($"{item.IdTypeCode}")); + if (!item.PostCode.IsNullOrEmpty()) + obj.Add("postCode", new JValue($"{item.PostCode}")); + if (!item.Province.IsNullOrEmpty()) + obj.Add("province", new JValue($"{item.Province}")); + if (!item.ProvinceCode.IsNullOrEmpty()) + obj.Add("provinceCode", new JValue($"{item.ProvinceCode}")); + arr.Add(obj); + companyList.Add(new CompanyList { - req.Code = 200; - req.Message = "当前状态不能重发!如有疑问,请联系相关客服!"; - return req; - } - if (msgType == "1" || msgType == "4") + companyType = item.CompanyType, + companyName = item.CompanyName, + idTypeCode = item.IdTypeCode, + companyId = item.CompanyId, + address = item.Address, + city = item.City, + province = item.Province, + provinceCode = item.ProvinceCode, + countryCode = item.CountryCode, + postcode = item.PostCode, + hstCode = item.HstCode, + + }); + } + + var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + var AMSAccount = DbBus.Get(DbList.djydb).Select().Where(x => x.PARAMNAME == "AMSAccount").ToOne(); + var method = DbBus.Get(DbList.djydb).Select().Where(x => x.PARAMNAME == "ISFMethod").ToOne(); + var key = DbBus.Get(DbList.djydb).Select().Where(x => x.PARAMNAME == "AMSKEY").ToOne(); + var url = DbBus.Get(DbList.djydb).Select().Where(x => x.PARAMNAME == "AMSURL").ToOne(); + /////MD5加密 + string stringSign = string.Format("companyList={0}&format=json&info={1}&method={2}&msgType={3}×tamp={4}&user_id={5}&version=2.0&key={6}", + JsonConvert.SerializeObject(arr), JsonConvert.SerializeObject(info), method.PARAMVALUE, Convert.ToInt32(msgType), timestamp, AMSAccount.PARAMVALUE, key.PARAMVALUE); + string sign = stringSign.ToMd5().ToUpper(); + + ///post参数 + IsfInfo isfinfo = new IsfInfo(); + isfinfo.companyList = arr; + isfinfo.format = "json"; + isfinfo.info = info; + isfinfo.method = method.PARAMVALUE; + isfinfo.msgType = Convert.ToInt32(msgType); + isfinfo.user_id = AMSAccount.PARAMVALUE; + isfinfo.sign = sign; + isfinfo.timestamp = timestamp; + isfinfo.version = "2.0"; + isfinfo.format = "json"; + string json = JsonConvert.SerializeObject(isfinfo); + _LogsAdd("SendDE", "post", $"ISF接口调用发送{oid}:{json}"); + string gethtml = await HttpHelp.Post(isfinfo, url.PARAMVALUE, PsotType.Json); + _LogsAdd("SendDE", "post", $"ISF接口调用返回{oid}:{gethtml}"); + if (gethtml != null) + { + JObject rlt = JObject.Parse(gethtml); + var code = rlt.GetValue("code").ToString(); + var msg = rlt.GetValue("msg").ToString(); + var data = rlt.GetValue("data").ToString(); + JObject drlt = JObject.Parse(data); + var result = drlt.GetValue("code").ToString(); + var errorInfo = drlt.GetValue("msg").ToString(); + if (code == "F" || result != "1") { - ///扣费接口 - var getfinrs = fin.Expend(new CustFee + + ISF_MasterHistory history = new ISF_MasterHistory(); + history.GID = Guid.NewGuid().ToString("N"); + history.ISF_ID = oid; + history.SendTime = DateTime.Now; + if (msgType == "1") { - SENDUSERID = user.GID, - LURURENID = user.GID, - CtnrCount = 1, - CtnrInfo = string.Empty, - BSTYPE = 16, - SENDTYPE = 0, - BSNO = oid.ToString(), - MBLNO = master.MBLNO.ToString(), + history.State = "新增发送失败"; + history.Type = "接收失败"; } - , 0); - if (!getfinrs.Status) + else if (msgType == "4") { - req.Code = 201; - req.Message = getfinrs.Message; - return req; + history.State = "重发失败"; + history.Type = "接收失败"; } - } - var portList = DbBus.Get(DbList.Common).Select().ToList(); - var CodePortLoadList = DbBus.Get(DbList.Common).Select().ToList(); - Info info = new Info(); - info.masterBillNo = master.MBLNO; - info.infoType = master.InFoType; - info.dischargeHarbourCode = portList.Where(x => x.Code == master.DischargeHarbourCode).Select(x => x.EdiCode).FirstOrDefault(); - info.deliveryHarbourCode = portList.Where(x => x.Code == master.DeliveryHarbourCode).Select(x => x.EdiCode).FirstOrDefault(); - info.shipmentTypeCode = master.ShipmentTypeCode; - info.hstCode = master.HstCode; - - info.blTypeCode = master.BlTypeCode; - info.refId = master.GID; - List companyList = new List(); - foreach (var item in comlist) - { - companyList.Add(new CompanyList + else if (msgType == "2") + { + history.State = "修改发送失败"; + history.Type = "修改失败"; + } + else { - companyType = item.CompanyType, - companyName = item.CompanyName, - idTypeCode = item.IdTypeCode, - companyId=item.CompanyId, - address = item.Address, - city = item.City, - province = item.Province, - provinceCode = item.ProvinceCode, - countryCode = item.ProvinceCode, - postcode = item.PostCode, - hstCode = item.HstCode, - - }); + history.State = "删除发送失败"; + history.Type = "删单失败"; + } + + history.Operator = user.SHOWNAME; + history.Remark = user.SHOWNAME + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "发送单据失败,失败原因:" + msg; + DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows(); + req.Code = 201; + req.Message = "操作失败," + msg + errorInfo; + return req; } - var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - var AMSAccount = DbBus.Get(DbList.djydb).Select().Where(x => x.PARAMNAME == "AMSAccount").ToOne(); - var method = DbBus.Get(DbList.djydb).Select().Where(x => x.PARAMNAME == "ISFMethod").ToOne(); - var key = DbBus.Get(DbList.djydb).Select().Where(x => x.PARAMNAME == "AMSKEY").ToOne(); - var url = DbBus.Get(DbList.djydb).Select().Where(x => x.PARAMNAME == "AMSURL").ToOne(); - /////MD5加密 - string stringSign = string.Format("companyList={0}&format=json&info={1}&method={2}&msgType={3}×tamp={4}&user_id={5}&version=2.0&key={6}", - JsonConvert.SerializeObject(companyList), JsonConvert.SerializeObject(info), method.PARAMVALUE, Convert.ToInt32(msgType), timestamp, AMSAccount.PARAMVALUE, key.PARAMVALUE); - string sign = stringSign.ToMd5().ToUpper(); - - ///post参数 - IsfInfo isfinfo = new IsfInfo(); - isfinfo.companyList = companyList; - isfinfo.format = "json"; - isfinfo.info = info; - isfinfo.method = method.PARAMVALUE; - isfinfo.msgType = Convert.ToInt32(msgType); - isfinfo.user_id = AMSAccount.PARAMVALUE; - isfinfo.sign = sign; - isfinfo.timestamp = timestamp; - isfinfo.version = "2.0"; - isfinfo.format = "json"; - string json = JsonConvert.SerializeObject(isfinfo); - _LogsAdd("SendDE", "post", $"ISF接口调用发送{oid}:{json}"); - string gethtml = await HttpHelp.Post(isfinfo, url.PARAMVALUE, PsotType.Json); - _LogsAdd("SendDE", "post", $"ISF接口调用返回{oid}:{gethtml}"); - if (gethtml != null) + if (code == "T" && result == "1") { - JObject rlt = JObject.Parse(gethtml); - var code = rlt.GetValue("code").ToString(); - var msg = rlt.GetValue("msg").ToString(); - var data = rlt.GetValue("data").ToString(); - JObject drlt = JObject.Parse(data); - var result = drlt.GetValue("code").ToString(); - var errorInfo = drlt.GetValue("msg").ToString(); - if (code == "F" || result != "1") + ISF_MasterHistory history = new ISF_MasterHistory(); + history.GID = Guid.NewGuid().ToString("N"); + history.ISF_ID = oid; + history.SendTime = DateTime.Now; + if (msgType == "1") { - - ISF_MasterHistory history = new ISF_MasterHistory(); - history.GID = Guid.NewGuid().ToString("N"); - history.ISF_ID = oid; - history.SendTime = DateTime.Now; - if (msgType == "1") - { - history.State = "新增发送失败"; - history.Type = "接收失败"; - } - else if (msgType == "4") - { - history.State = "重发失败"; - history.Type = "接收失败"; - } - else if (msgType == "2") - { - history.State = "修改发送失败"; - history.Type = "修改失败"; - } - else - { - history.State = "删除发送失败"; - history.Type = "删单失败"; - } - - history.Operator = user.SHOWNAME; - history.Remark = user.SHOWNAME + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "发送单据失败,失败原因:" + msg; - DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows(); - req.Code = 201; - req.Message = "操作失败," + msg + errorInfo; - return req; + history.State = "新增发送成功"; + history.Type = "接收成功"; } - if (code == "T" && result == "1") + else if (msgType == "4") { - ISF_MasterHistory history = new ISF_MasterHistory(); - history.GID = Guid.NewGuid().ToString("N"); - history.ISF_ID = oid; - history.SendTime = DateTime.Now; - if (msgType == "1") - { - history.State = "新增发送成功"; - history.Type = "接收成功"; - } - else if (msgType == "4") - { - history.State = "重发成功"; - history.Type = "接收成功"; - } - else if (msgType == "2") - { - history.State = "修改发送成功"; - history.Type = "修改成功"; - } - else - { - history.State = "删除发送成功"; - history.Type = "删单成功"; - } - history.Operator = user.SHOWNAME; - history.Remark = user.SHOWNAME + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "发送了单据"; - DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows(); + history.State = "重发成功"; + history.Type = "接收成功"; + } + else if (msgType == "2") + { + history.State = "修改发送成功"; + history.Type = "修改成功"; + } + else + { + history.State = "删除发送成功"; + history.Type = "删单成功"; + } + history.Operator = user.SHOWNAME; + history.Remark = user.SHOWNAME + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "发送了单据"; + DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows(); - if (msgType == "1") + if (msgType == "1") + { + var getfinrs = fin.Expend(new CustFee { - var getfinrs = fin.Expend(new CustFee - { - SENDUSERID = user.GID, - LURURENID = user.GID, - CtnrCount = 1, - CtnrInfo = string.Empty, - BSTYPE = 16, - SENDTYPE = 0, - BSNO = oid.ToString(), - MBLNO = master.MBLNO.ToString(), - } - , 1); - DbBus.Get(DbList.AMSCenter).Update().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "新增发送成功" }).Where(w => w.GID == oid).ExecuteAffrows(); + SENDUSERID = user.GID, + LURURENID = user.GID, + CtnrCount = 1, + CtnrInfo = string.Empty, + BSTYPE = 16, + SENDTYPE = 0, + BSNO = oid.ToString(), + MBLNO = master.MBLNO.ToString(), } - else if (msgType == "4") + , 1); + DbBus.Get(DbList.AMSCenter).Update().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "新增发送成功" }).Where(w => w.GID == oid).ExecuteAffrows(); + } + else if (msgType == "4") + { + var getfinrs = fin.Expend(new CustFee { - var getfinrs = fin.Expend(new CustFee - { - SENDUSERID = user.GID, - LURURENID = user.GID, - CtnrCount = 1, - CtnrInfo = string.Empty, - BSTYPE = 16, - SENDTYPE = 0, - BSNO = oid.ToString(), - MBLNO = master.MBLNO.ToString(), - } - , 1); - DbBus.Get(DbList.AMSCenter).Update().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "重发发送成功" }).Where(w => w.GID == oid).ExecuteAffrows(); - + SENDUSERID = user.GID, + LURURENID = user.GID, + CtnrCount = 1, + CtnrInfo = string.Empty, + BSTYPE = 16, + SENDTYPE = 0, + BSNO = oid.ToString(), + MBLNO = master.MBLNO.ToString(), } - else if (msgType == "2") - { - DbBus.Get(DbList.AMSCenter).Update().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "修改发送成功" }).Where(w => w.GID == oid).ExecuteAffrows(); + , 1); + DbBus.Get(DbList.AMSCenter).Update().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "重发发送成功" }).Where(w => w.GID == oid).ExecuteAffrows(); + + } + else if (msgType == "2") + { + DbBus.Get(DbList.AMSCenter).Update().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "修改发送成功" }).Where(w => w.GID == oid).ExecuteAffrows(); - } - else - { - DbBus.Get(DbList.AMSCenter).Update().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "删除发送成功" }).Where(w => w.GID == oid).ExecuteAffrows(); - } + } + else + { + DbBus.Get(DbList.AMSCenter).Update().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "删除发送成功" }).Where(w => w.GID == oid).ExecuteAffrows(); } } } } + } return req; } @@ -513,7 +544,7 @@ namespace djy.Service.Isf history.Operator = "系统管理员"; history.Remark = "您的明细单据" + retdto.businessId + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "匹配失败"; DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows(); - + //if (master.NewNotice == "删除发送成功") //{ @@ -531,16 +562,16 @@ namespace djy.Service.Isf } else if (retdto.status == "02") { - ISF_MasterHistory history = new ISF_MasterHistory(); - history.GID = Guid.NewGuid().ToString("N"); - history.ISF_ID = master.GID; - history.SendTime = DateTime.Now; - history.State = "删除成功"; - history.Type = "删除成功"; - history.Operator = "系统管理员"; - history.Remark = "您的单据于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "海关删除成功"; - DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows(); - DbBus.Get(DbList.AMSCenter).Update().Set(w => new AMS_Master { MateState = retdto.status, NewNotice = "ISF和AMS匹配成功", ReportState = "删单失败" }).Where(w => w.GID == master.GID).ExecuteAffrows(); + ISF_MasterHistory history = new ISF_MasterHistory(); + history.GID = Guid.NewGuid().ToString("N"); + history.ISF_ID = master.GID; + history.SendTime = DateTime.Now; + history.State = "删除成功"; + history.Type = "删除成功"; + history.Operator = "系统管理员"; + history.Remark = "您的单据于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "海关删除成功"; + DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows(); + DbBus.Get(DbList.AMSCenter).Update().Set(w => new AMS_Master { MateState = retdto.status, NewNotice = "ISF和AMS匹配成功", ReportState = "删单失败" }).Where(w => w.GID == master.GID).ExecuteAffrows(); } else if (retdto.status == "01") { @@ -555,7 +586,7 @@ namespace djy.Service.Isf DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows(); DbBus.Get(DbList.AMSCenter).Update().Set(w => new AMS_Master { MateState = retdto.status, NewNotice = "海关拒绝", ReportState = "删单失败" }).Where(w => w.GID == master.GID).ExecuteAffrows(); } - else if (retdto.status == "SB"|| retdto.status == "S2" || retdto.status == "S3" || retdto.status == "S4" || retdto.status == "S5" || retdto.status == "S6") + else if (retdto.status == "SB" || retdto.status == "S2" || retdto.status == "S3" || retdto.status == "S4" || retdto.status == "S5" || retdto.status == "S6") { ISF_MasterHistory history = new ISF_MasterHistory(); history.GID = Guid.NewGuid().ToString("N");