|
|
using DSWeb.Areas.MvcShipping.DAL.Message.vgm;
|
|
|
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
|
|
|
using DSWeb.MvcShipping.DAL.MsCodeFtpSet;
|
|
|
using DSWeb.MvcShipping.DAL.MsOpSeaeDAL;
|
|
|
using DSWeb.MvcShipping.DAL.MsOpSeaeEdiDAL;
|
|
|
using DSWeb.MvcShipping.Helper;
|
|
|
using DSWeb.MvcShipping.Models.MsOpSeae;
|
|
|
using DSWeb.MvcShipping.Models.MsOpSeaeEdi;
|
|
|
using HcUtility.Comm;
|
|
|
using HcUtility.Core;
|
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Web;
|
|
|
using System.Web.Mvc;
|
|
|
using System.Web.Caching;
|
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
|
using DSWeb.Common.DB;
|
|
|
using log4net;
|
|
|
|
|
|
namespace DSWeb.Interface
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// CustVGM 的摘要说明
|
|
|
/// </summary>
|
|
|
public class CustEDI : IHttpHandler
|
|
|
{
|
|
|
private ILog log = LogManager.GetLogger("CustEDI");
|
|
|
|
|
|
private const int DURATION = 1;
|
|
|
private const int TIMES = 10;
|
|
|
public void ProcessRequest(HttpContext context)
|
|
|
{
|
|
|
context.Response.ContentType = "text/plain";
|
|
|
|
|
|
string rst = "1";
|
|
|
if (!IsValid())
|
|
|
{
|
|
|
rst = "操作太频繁!";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (context.Request["ac"] == "emf")
|
|
|
{
|
|
|
rst = SendCustEDI(context);
|
|
|
|
|
|
}
|
|
|
else if (context.Request["ac"] == "emfstatus")
|
|
|
{
|
|
|
rst = GetEDISTATUS(context);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
rst = "参数有误";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
context.Response.Write(rst);
|
|
|
}
|
|
|
|
|
|
public bool IsReusable
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 接口发送舱单
|
|
|
/// </summary>
|
|
|
/// <param name="context"></param>
|
|
|
/// <returns></returns>
|
|
|
public string SendCustEDI(HttpContext context)
|
|
|
{
|
|
|
string uid = context.Request["uid"];
|
|
|
string skey = context.Request["skey"];
|
|
|
string optype = context.Request["optype"];
|
|
|
string mdata = context.Request["data"];
|
|
|
if (uid == null || optype == null || mdata == null)
|
|
|
{
|
|
|
return "参数有误!";
|
|
|
}
|
|
|
|
|
|
if (!MsOpSeaeEdiDAL.CheckAuth(uid, skey))
|
|
|
{
|
|
|
return "身份验证错误!";
|
|
|
}
|
|
|
|
|
|
log.Debug($"收到舱单发送请求({context.Request.UserHostAddress}):{uid} {skey} {optype} \r\n{mdata}");
|
|
|
|
|
|
OPTYPE OPTYPE = new OPTYPE(optype);
|
|
|
|
|
|
//作废,单独处理,不需要验证、保存数据
|
|
|
if (OPTYPE.SHOWNAME == "作废")
|
|
|
{
|
|
|
var resp = new JsonResponse();
|
|
|
EdiDataContext edc = new EdiDataContext();
|
|
|
var user = edc.Users.AsNoTracking().First(u => u.GID == uid);
|
|
|
List<iEDIModel> iEDIDataList = JsonConvert.Deserialize<List<iEDIModel>>(mdata);
|
|
|
var listMFNO = new List<string>();
|
|
|
foreach (var item in iEDIDataList)
|
|
|
{
|
|
|
var ediData = edc.Edis.AsNoTracking().FirstOrDefault(x => x.MBLNO == item.MDATA.MBLNO && x.HBLNO == item.MDATA.HBLNO);
|
|
|
if (ediData == null)
|
|
|
{
|
|
|
resp.Success = false;
|
|
|
resp.Message = $"找不到数据,主单号:{item.MDATA.MBLNO} 分单号:{item.MDATA.HBLNO}";
|
|
|
return JsonConvert.Serialize(resp);
|
|
|
}
|
|
|
|
|
|
var userEdi = edc.Users.AsNoTracking().FirstOrDefault(x => x.GID == ediData.INPUTBYID);
|
|
|
if (user.CompId != userEdi.CompId)
|
|
|
{
|
|
|
resp.Success = false;
|
|
|
resp.Message = $"主单号:{item.MDATA.MBLNO} 分单号:{item.MDATA.HBLNO} 非本公司业务";
|
|
|
return JsonConvert.Serialize(resp);
|
|
|
}
|
|
|
|
|
|
listMFNO.Add(ediData.MFNO);
|
|
|
}
|
|
|
|
|
|
resp.Success = EdiHelper.CancelEdi(listMFNO, user.SHOWNAME, out string cancelMsg);
|
|
|
resp.Message = cancelMsg;
|
|
|
return JsonConvert.Serialize(resp);
|
|
|
}
|
|
|
|
|
|
string msg = "";
|
|
|
string mfno = "";
|
|
|
#region 保存数据
|
|
|
string comid = GetCOMIDWithUserid(uid);
|
|
|
bool saveRst = false;
|
|
|
saveRst = SaveEDI(mdata, uid, comid, optype, out msg, out mfno);
|
|
|
//此处mfno的内容为形如:'aaaa','bbbb' 的mfno列表
|
|
|
#endregion
|
|
|
bool rst = false;
|
|
|
bool isMotify = optype == "0" ? false : true;
|
|
|
|
|
|
|
|
|
if (saveRst && OPTYPE.SHOWNAME != "保存")
|
|
|
{
|
|
|
#region 发送报文
|
|
|
|
|
|
rst = SendEDI(mdata, mfno, uid, comid, "", OPTYPE.SHOWNAME, out msg, isMotify);
|
|
|
//var result = MsOpSeaeEdiDAL.CreateCustomList(headList, uid,"",comid, path,comname, dcarrier, type, ftpset, remarks,"");
|
|
|
|
|
|
|
|
|
var relativeXmlPath = "~/EDIFiles/ExportXmlManifest";
|
|
|
var xmlPath = context.Server.MapPath(relativeXmlPath);
|
|
|
if (!Directory.Exists(xmlPath))
|
|
|
{
|
|
|
Directory.CreateDirectory(xmlPath);
|
|
|
}
|
|
|
|
|
|
//华港船代,生成xml并发送ftp
|
|
|
MsOpSeaeEdiDAL.SendEdiXmlHuaGangFtp(mfno, uid, relativeXmlPath, xmlPath);
|
|
|
#endregion
|
|
|
}
|
|
|
else rst = saveRst;
|
|
|
if (!rst && OPTYPE.SHOWNAME == "新增")
|
|
|
{
|
|
|
//发送失败,删除数据
|
|
|
deleteFaildData(mfno);
|
|
|
}
|
|
|
var jsonRespose = new JsonResponse
|
|
|
{
|
|
|
Success = rst,
|
|
|
Message = msg
|
|
|
};
|
|
|
log.Debug($"舱单接口返回({context.Request.UserHostAddress}):{uid} {skey} {optype}");
|
|
|
return JsonConvert.Serialize(jsonRespose);
|
|
|
|
|
|
}
|
|
|
|
|
|
public string GetEDISTATUS(HttpContext context)
|
|
|
{
|
|
|
string uid = context.Request["uid"];
|
|
|
string skey = context.Request["skey"];
|
|
|
string mblnos = context.Request["blno"];
|
|
|
if (uid == null)
|
|
|
{
|
|
|
return "参数有误!";
|
|
|
}
|
|
|
if (!MsOpSeaeEdiDAL.CheckAuth(uid, skey))
|
|
|
{
|
|
|
return "身份验证错误!";
|
|
|
}
|
|
|
if (string.IsNullOrWhiteSpace(mblnos))
|
|
|
{
|
|
|
return "查询提单号不能为空";
|
|
|
}
|
|
|
List<EDIStatusModeli> list = GetEMFSTATUSList(mblnos);
|
|
|
var jsonRespose = new JSONRSB { Success = true, Data = list };
|
|
|
return JsonConvert.Serialize(jsonRespose);
|
|
|
|
|
|
}
|
|
|
//public ActionResult Test()
|
|
|
//{
|
|
|
// string key = "test";
|
|
|
// HttpRuntime.Cache.Add(key, DateTime.Now, null, DateTime.Now.AddSeconds(10), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
|
|
|
// var val = HttpRuntime.Cache[key] ?? "not exist";
|
|
|
// return Content(val.ToString());
|
|
|
//}
|
|
|
|
|
|
public static bool IsValid()
|
|
|
{
|
|
|
////return true;
|
|
|
//HttpContext context = HttpContext.Current;
|
|
|
//if (context.Request.Browser.Crawler) return false;
|
|
|
//string key = context.Request.UserHostAddress;
|
|
|
////IP,10次,30秒;
|
|
|
//return BasicDataRefDAL.IsValid(key, TIMES, 30);
|
|
|
|
|
|
HttpContext context = HttpContext.Current;
|
|
|
string key = context.Request.UserHostAddress;
|
|
|
|
|
|
|
|
|
return IPRecord.canhit(key);
|
|
|
}
|
|
|
|
|
|
private bool SaveEDI(string data, string uid, string comid, string optype, out string msg, out string mfno)
|
|
|
{
|
|
|
msg = "";
|
|
|
string mfnos = "";
|
|
|
BasicDataRefDAL.SaveLog_str(data, uid, "舱单接口", "保存");
|
|
|
List<iEDIModel> iEDIDataList = new List<iEDIModel>();
|
|
|
try
|
|
|
{
|
|
|
iEDIDataList = JsonConvert.Deserialize<List<iEDIModel>>(data);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
mfno = "";
|
|
|
msg = "报文格式错误:" + e.Message;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
OPTYPE OPTYPE = new OPTYPE(optype);
|
|
|
|
|
|
//if ( OPTYPE.SHOWNAME != "保存") {
|
|
|
|
|
|
//}
|
|
|
|
|
|
bool rst = false;
|
|
|
|
|
|
EdiDataContext edc = new EdiDataContext();
|
|
|
|
|
|
//进行校验
|
|
|
foreach (var iEDI in iEDIDataList)
|
|
|
{
|
|
|
var headData = iEDI.MDATA;
|
|
|
OPTYPE _optype = new OPTYPE(optype);
|
|
|
|
|
|
var ftpset = MsCodeFtpSetDAL.GetData("EDINAME=''", comid);
|
|
|
List<MsOpSeaeEdi> headList = new List<MsOpSeaeEdi>();
|
|
|
headList.Add(headData);
|
|
|
|
|
|
List<MsOpSeaeEdiCtn> bodyList = iEDI.CTNDATA;
|
|
|
|
|
|
List<MsOpSeaeEdiCtn> listTemp = iEDI.CTNDATA;
|
|
|
|
|
|
|
|
|
var cargoList = iEDI.CTNDATA;
|
|
|
|
|
|
|
|
|
var errorstr = "";
|
|
|
|
|
|
//分单号主单号不能重复
|
|
|
if (headData.HBLNO.Equals(headData.MBLNO))
|
|
|
{
|
|
|
msg = "主单号与分单号不能一致!";
|
|
|
mfno = "";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
var BSNO = headData.MFNO;
|
|
|
headData.SHIPPER = headData.SHIPPERNAME;
|
|
|
headData.CONSIGNEE = headData.CONSIGNEENAME;
|
|
|
headData.NOTIFYPARTY = headData.NOTIFYPARTYNAME;
|
|
|
var error = "";
|
|
|
|
|
|
//20210719 YARDID用于接收接口发送的场站ID --select EDICODE3, * from info_client where ISYARD=1
|
|
|
//如果YARDID不为空 则判断该ID与info_client.EDICODE3是否对应
|
|
|
//如有 则YARD内容改为该info_client.shortname
|
|
|
//如无 则返回错误
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(headData.YARDID))
|
|
|
{
|
|
|
var cdc = new CommonDataContext();
|
|
|
var 对应场站List = cdc.InfoClients.Where(x => x.EDICODE3 == headData.YARDID.Trim()).ToList();
|
|
|
|
|
|
if (对应场站List.Count > 0)
|
|
|
{
|
|
|
headData.YARD = 对应场站List[0].SHORTNAME;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
error += "<br />场站ID【" + headData.YARDID + "】未能识别,请确认场站的ID";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//如果保存的是分单 且没有同时发送的对应主单,而且目前系统中也没有可对应的主单
|
|
|
//则返回错误
|
|
|
if (_optype.SHOWNAME == "保存" && !string.IsNullOrWhiteSpace(iEDI.MDATA.HBLNO))
|
|
|
{
|
|
|
if (!iEDIDataList.Exists(x => x.MDATA.MBLNO == iEDI.MDATA.MBLNO && string.IsNullOrWhiteSpace(x.MDATA.HBLNO)))
|
|
|
{
|
|
|
|
|
|
var 当前业务 = edc.Edis.Where(x => x.MBLNO == iEDI.MDATA.MBLNO && (x.HBLNO == null || x.HBLNO.Trim() == "") && x.CORPID == comid).ToList();
|
|
|
if (当前业务 != null && 当前业务.Count > 0)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
error += "<br />分提单号“" + iEDI.MDATA.HBLNO + "”的业务需要提单号“" + iEDI.MDATA.MBLNO + "”的主单业务";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (_optype.SHOWNAME != "保存")
|
|
|
error += MsOpSeaeEdiDAL.IsCreateExportManifestForInterface(headList, bodyList, ftpset, false, uid, optype);
|
|
|
|
|
|
|
|
|
if (_optype.SHOWNAME == "删除" && string.IsNullOrEmpty(headData.SENDREMARK))
|
|
|
{
|
|
|
error += "<br />删除的业务需要填写【发送备注】";
|
|
|
}
|
|
|
|
|
|
if (error != "")
|
|
|
{
|
|
|
var jsonRespose3 = new JsonResponse { Success = false, Message = error };
|
|
|
msg = error;
|
|
|
mfno = "";
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//接口用的新的防止为空算法 新接口 防止为空
|
|
|
//编译区分 分支 合川 DS6
|
|
|
var canSend = headData.CheckSendVoid();
|
|
|
|
|
|
var ctncheckresult = MsOpSeaeEdiCtn.CheckCtn_CanSend(bodyList);
|
|
|
if (!ctncheckresult.Success) canSend.SetErrorInfo(ctncheckresult.Message);
|
|
|
|
|
|
if (!canSend.Success)
|
|
|
{
|
|
|
var jsonRespose3 = new JsonResponse { Success = false, Message = canSend.Message };
|
|
|
msg = jsonRespose3.Message;
|
|
|
mfno = "";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//保存
|
|
|
|
|
|
var codectnlist = BasicDataRefDAL.GetCodeCtnListAll();
|
|
|
|
|
|
iEDIDataList = iEDIDataList.OrderBy(o => o.MDATA.HBLNO.Trim()).ToList();
|
|
|
|
|
|
|
|
|
foreach (var iEDI in iEDIDataList)
|
|
|
{
|
|
|
var headData = iEDI.MDATA;
|
|
|
|
|
|
var ftpset = MsCodeFtpSetDAL.GetData("EDINAME=''", comid);
|
|
|
List<MsOpSeaeEdi> headList = new List<MsOpSeaeEdi>();
|
|
|
headList.Add(headData);
|
|
|
List<MsOpSeaeEdiCtn> bodyList = iEDI.CTNDATA;
|
|
|
|
|
|
foreach (var ctn in bodyList)
|
|
|
{
|
|
|
if (codectnlist.Exists(o => o.CTN == ctn.SIZE + ctn.CTN))
|
|
|
{
|
|
|
var _ctncode = codectnlist.Find(o => o.CTN == ctn.SIZE + ctn.CTN);
|
|
|
ctn.CTNALL = _ctncode.CTN;
|
|
|
ctn.TEU = (int)Convert.ToDecimal(_ctncode.TEU);
|
|
|
ctn.CTNCODE = _ctncode.CTNID;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
msg = $"箱型代码[{ctn.SIZE + ctn.CTN}]没有找到匹配的箱型";
|
|
|
BasicDataRefDAL.SaveLog_str(msg, uid, "舱单接口", "保存");
|
|
|
|
|
|
mfno = "";
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List<MsOpSeaeEdiCtn> listTemp = new List<MsOpSeaeEdiCtn>(iEDI.CTNDATA);
|
|
|
var cargoList = iEDI.CTNDATA;
|
|
|
decimal KGS = 0;
|
|
|
decimal CBM = 0;
|
|
|
decimal PKGS = 0;
|
|
|
string ctnStr = "";
|
|
|
if (headData.REEFERF == null || headData.REEFERF == "")
|
|
|
{
|
|
|
headData.REEFERF = "0";
|
|
|
}
|
|
|
if (bodyList != null)
|
|
|
{
|
|
|
if (bodyList.Count > 0)
|
|
|
{
|
|
|
// bool IsDongGui = false;
|
|
|
int i = 0;
|
|
|
string ctnTemp = "";
|
|
|
foreach (var item in bodyList)
|
|
|
{
|
|
|
//获取并更新包装EDI代码
|
|
|
item.KINDPKGS = GetPKGWithEIDCODE(item.KINDPKGS);
|
|
|
KGS += item.KGS;
|
|
|
CBM += item.CBM;
|
|
|
PKGS += item.PKGS;
|
|
|
item.MFNO = "*";
|
|
|
item.CTN_ID = Guid.NewGuid().ToString();
|
|
|
ctnTemp = item.CTNALL;
|
|
|
|
|
|
List<MsOpSeaeEdiCtn> list = listTemp.FindAll(b => b.CTNALL == ctnTemp).ToList();
|
|
|
if (list.Count != 0)
|
|
|
{
|
|
|
ctnStr += ctnTemp + "*" + list.Count.ToString() + ",";
|
|
|
listTemp.RemoveAll(a => a.CTNALL == ctnTemp);
|
|
|
}
|
|
|
|
|
|
//if (IsDongGui == false)
|
|
|
//{
|
|
|
// if (item.CTNALL.Contains("RH") || item.CTNALL.Contains("RF") || item.CTNALL.Contains("RQ"))
|
|
|
// {
|
|
|
// IsDongGui = true;
|
|
|
// }
|
|
|
//}
|
|
|
if (i == 0)
|
|
|
{
|
|
|
headData.KINDPKGS = item.KINDPKGS;
|
|
|
}
|
|
|
i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
//if (IsDongGui)
|
|
|
//{
|
|
|
// headData.CARGOID = "R";
|
|
|
//}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (ctnStr.Length > 0)
|
|
|
{
|
|
|
ctnStr = ctnStr.Substring(0, ctnStr.Length - 1);
|
|
|
}
|
|
|
if (headData.CORPID == "" || headData.CORPID == null)
|
|
|
{
|
|
|
headData.CORPID = comid;
|
|
|
}
|
|
|
headData.CBM = CBM;
|
|
|
headData.KGS = KGS;
|
|
|
headData.PKGS = Convert.ToInt32(PKGS);
|
|
|
headData.JiZhuangXiang = ctnStr;
|
|
|
headData.SHIPPER = headData.SHIPPERNAME;
|
|
|
headData.CONSIGNEE = headData.CONSIGNEENAME;
|
|
|
headData.NOTIFYPARTY = headData.NOTIFYPARTYNAME;
|
|
|
headData.MFNO = Guid.NewGuid().ToString();
|
|
|
iEDI.MDATA.MFNO = headData.MFNO;
|
|
|
|
|
|
//20210927 如果这是一个主单 BSNO设为''
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(headData.HBLNO))
|
|
|
{
|
|
|
headData.BSNO = "";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//如果是分单 首先看此次发送的内容有没有它的主单 如果有 分单BSNO使用主单MFNO
|
|
|
//如果没有 看当前数据库中是否有这个公司的这个MBLNO的主单 如果有 分单BSNO使用主单MFNO
|
|
|
if (iEDIDataList.Exists(x => x.MDATA.MBLNO == iEDI.MDATA.MBLNO && string.IsNullOrWhiteSpace(x.MDATA.HBLNO)))
|
|
|
{
|
|
|
var _sendhead = iEDIDataList.First(x => x.MDATA.MBLNO == iEDI.MDATA.MBLNO && (x.MDATA.HBLNO == null || x.MDATA.HBLNO.Trim() == "") && string.IsNullOrWhiteSpace(x.MDATA.HBLNO)).MDATA;
|
|
|
headData.BSNO = _sendhead.MFNO;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
var 当前业务 = edc.Edis.Where(x => x.MBLNO == iEDI.MDATA.MBLNO && (x.HBLNO == null || x.HBLNO.Trim() == "") && x.CORPID == comid).ToList();
|
|
|
if (当前业务 != null && 当前业务.Count > 0)
|
|
|
{
|
|
|
headData.BSNO = 当前业务[0].MFNO;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
headData.INPUTDATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
headData.INPUTBYID = uid;
|
|
|
headData.INPUTBY = GetSHOWNAMEWithUid(uid);
|
|
|
|
|
|
string MFNO = "";
|
|
|
string status = "";
|
|
|
string zhifatext = "";
|
|
|
//判断主提单号,分提单号是否重复,获取操作类型(主单)
|
|
|
if (HasSameMBLNOWithUserIdForInterface(headData.MBLNO, headData.HBLNO, uid, OPTYPE, out MFNO, out status, out zhifatext))
|
|
|
{
|
|
|
//20210726 只有当"保存"时防止 当修改和删除时可以做下列操作
|
|
|
if (MFNO == "")
|
|
|
{
|
|
|
mfno = "";
|
|
|
if (OPTYPE.SHOWNAME == "保存" || OPTYPE.SHOWNAME == "新增")
|
|
|
{
|
|
|
msg = "提单号已存在";
|
|
|
}
|
|
|
if (OPTYPE.SHOWNAME == "修改" || OPTYPE.SHOWNAME == "删除")
|
|
|
{
|
|
|
msg = "业务状态非已直发,不允许" + OPTYPE.SHOWNAME;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
headData.MFNO = MFNO;
|
|
|
headData.EDISTATUS = status;
|
|
|
headData.DbOperationType = DbOperationType.DbotUpd;
|
|
|
headData.ZhiFaText = zhifatext;
|
|
|
MsOpSeaeEdiDAL.ClearCtn(MFNO);
|
|
|
foreach (var item in bodyList)
|
|
|
{
|
|
|
item.MFNO = "*";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
headData.EDISTATUS = "已录入";
|
|
|
headData.DbOperationType = DbOperationType.DbotIns;
|
|
|
|
|
|
foreach (var item in bodyList)
|
|
|
{
|
|
|
item.MFNO = "*";
|
|
|
item.DbOperationType = DbOperationType.DbotIns;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
headData.INPUTBYID = uid;
|
|
|
if (headData.ETA == "")
|
|
|
{
|
|
|
headData.ETA = null;
|
|
|
}
|
|
|
else if (headData.ETA != null)
|
|
|
{
|
|
|
headData.ETA = DateTime.Parse(headData.ETA).ToString("yyyy-MM-dd");
|
|
|
}
|
|
|
if (headData.ETD == "")
|
|
|
{
|
|
|
headData.ETD = null;
|
|
|
}
|
|
|
else if (headData.ETD != null)
|
|
|
{
|
|
|
headData.ETD = DateTime.Parse(headData.ETD).ToString("yyyy-MM-dd");
|
|
|
}
|
|
|
if (headData.LASTPORTOFCALLDATE == "") headData.LASTPORTOFCALLDATE = null;
|
|
|
if (headData.FIRSTPORTOFCALLDATE == "") headData.FIRSTPORTOFCALLDATE = null;
|
|
|
|
|
|
headData.PORTLOAD = MsBaseInfoDAL.DelPortCn(headData.PORTLOAD);
|
|
|
headData.PORTDISCHARGE = MsBaseInfoDAL.DelPortCn(headData.PORTDISCHARGE);
|
|
|
headData.DESTINATION = MsBaseInfoDAL.DelPortCn(headData.PORTDISCHARGE);
|
|
|
headData.DESTINATIONID = headData.PORTDISCHARGEID;
|
|
|
headData.PLACEDELIVERYID = headData.PORTLOADID;
|
|
|
headData.PLACEDELIVERY = headData.PORTLOAD;
|
|
|
var modb = new ModelObjectDB();
|
|
|
|
|
|
|
|
|
DBResult result = headData.CheckSaveVoid();
|
|
|
|
|
|
if (result.Success == true) result = modb.Save(headData);
|
|
|
|
|
|
if (result.Success == true)
|
|
|
{
|
|
|
result = MsOpSeaeEdiDAL.SaveDetail(headData, bodyList, null);
|
|
|
if (result.Success == true)
|
|
|
{
|
|
|
headData.EDISTATUS = "已直发";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var jsonRespose = new JsonResponse
|
|
|
{
|
|
|
Success = result.Success,
|
|
|
Message = result.Message
|
|
|
};
|
|
|
|
|
|
mfnos += "'" + headData.MFNO + "',";
|
|
|
msg = result.Message;
|
|
|
rst = result.Success;
|
|
|
}
|
|
|
if (mfnos.Length > 0)
|
|
|
{
|
|
|
mfno = mfnos.Substring(0, mfnos.Length - 1);
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
mfno = "";
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
}
|
|
|
|
|
|
private bool SendEDI(string data, string mfno, string uid, string comid, string showname, string optypename, out string msg, bool isMotify = false)
|
|
|
{
|
|
|
List<iEDIModel> iEDIDataList = JsonConvert.Deserialize<List<iEDIModel>>(data);
|
|
|
|
|
|
int cnt = 0;
|
|
|
var headList = MsOpSeaeEdiDAL.GetDataList("MFNO IN (" + mfno + ")", uid, showname, comid, 0, 100, out cnt);
|
|
|
string userid = uid;
|
|
|
|
|
|
var result = new DBResult();
|
|
|
var ftpset = MsCodeFtpSetDAL.GetData("EDINAME=''", comid);
|
|
|
var error = MsOpSeaeEdiDAL.IsCreateExportManifest(headList, false, optypename, checkCtnNum: false);
|
|
|
if (error != "")
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = error;
|
|
|
}
|
|
|
headList = headList.OrderBy(o => o.MBLNO).ToList();
|
|
|
|
|
|
//检查相同主提单号下的主单与分单是否是相同的船代
|
|
|
string mblnoTemp = "";
|
|
|
string forwarderTemp = "";
|
|
|
foreach (var item in headList)
|
|
|
{
|
|
|
if (mblnoTemp != item.MBLNO)
|
|
|
{
|
|
|
mblnoTemp = item.MBLNO;
|
|
|
forwarderTemp = item.FORWARDER;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (forwarderTemp != item.FORWARDER)
|
|
|
{
|
|
|
string blnoStr = item.HBLNO == "" ? item.MBLNO : item.HBLNO;
|
|
|
error += "<br/>" + blnoStr + "主单与分单船代不同!";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var path = HttpContext.Current.Server.MapPath("../EDIFiles/CustomEdi");
|
|
|
if (!Directory.Exists(path))
|
|
|
{
|
|
|
Directory.CreateDirectory(path);
|
|
|
}
|
|
|
|
|
|
var SENDREMARK = "";
|
|
|
//if (!isMotify)
|
|
|
//{
|
|
|
foreach (var item in headList)
|
|
|
{
|
|
|
List<MsOpSeaeManifest> billmsum = MsOpSeaeDAL.GetManifestBsNoSumList(item.MBLNO); ;
|
|
|
List<MsOpSeaeManifest> headmsum = MsOpSeaeDAL.GetZhuDanJianZhongChiZongShuList(item.MBLNO);
|
|
|
string blnoStr = item.HBLNO == "" ? item.MBLNO : item.HBLNO;
|
|
|
|
|
|
if (billmsum[0].PKGS != 0 || billmsum[0].KGS != 0 || billmsum[0].CBM != 0)
|
|
|
{
|
|
|
if (Convert.ToDecimal(headmsum[0].PKGS) != billmsum[0].PKGS)
|
|
|
{
|
|
|
|
|
|
error = error + "<br/>" + blnoStr + "<br /> 分票件数合计:" + billmsum[0].PKGS + " 与总票件数:" + headmsum[0].PKGS + " 不一致。";
|
|
|
}
|
|
|
if (Convert.ToDecimal(headmsum[0].KGS) != billmsum[0].KGS)
|
|
|
{
|
|
|
|
|
|
error = error + "<br/>" + blnoStr + " <br />分票毛重合计:" + billmsum[0].KGS.ToString("0.####") + " 与总票毛重:" + headmsum[0].KGS.ToString("0.####") + " 不一致。";
|
|
|
}
|
|
|
if (Convert.ToDecimal(headmsum[0].CBM) != billmsum[0].CBM)
|
|
|
{
|
|
|
error = error + "<br/>" + blnoStr + " <br />分票体积合计:" + billmsum[0].CBM.ToString("0.###") + " 与总票体积:" + headmsum[0].CBM.ToString("0.###") + " 不一致。";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (optypename == "删除")
|
|
|
{
|
|
|
foreach (var item in iEDIDataList)
|
|
|
{
|
|
|
var headData = item.MDATA;
|
|
|
if (SENDREMARK != "") SENDREMARK += "\r\n";
|
|
|
SENDREMARK += headData.SENDREMARK;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
if (error == "")
|
|
|
{
|
|
|
//result = MsOpSeaeEdiDAL.CreateCustomList(headList, uid, showname, comid, path, "", headList[0].FORWARDER, optype, ftpset, "此处应该填写备注", showname);
|
|
|
result = MsOpSeaeEdiDAL.CreateCustomList(headList, uid, showname, comid, path, "", headList[0].FORWARDER, optypename, ftpset, SENDREMARK, showname);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = error;
|
|
|
}
|
|
|
|
|
|
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data };
|
|
|
//return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
msg = result.Message;
|
|
|
return result.Success;
|
|
|
}
|
|
|
|
|
|
private string GetCOMIDWithUserid(string userid)
|
|
|
{
|
|
|
|
|
|
string comid = "";
|
|
|
|
|
|
string sql = "select companyid from user_company where userid = '" + userid + "'";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
var rst = db.ExecuteScalar(CommandType.Text, sql);
|
|
|
if (rst == DBNull.Value || rst == null)
|
|
|
{
|
|
|
return "";
|
|
|
}
|
|
|
comid = rst.ToString();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
comid = "";
|
|
|
}
|
|
|
|
|
|
|
|
|
return comid;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
/// <param name="mblno"></param>
|
|
|
/// <param name="uid"></param>
|
|
|
/// <param name="mfno"></param>
|
|
|
/// <returns>0新增1修改</returns>
|
|
|
private int GetOptype(string mblno, string uid, out string mfno)
|
|
|
{
|
|
|
string sql = "select mfno from op_seae_edi where mblno = '" + mblno + "' and INPUTBYID = '" + uid + "'";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
var rst = db.ExecuteScalar(CommandType.Text, sql);
|
|
|
if (rst == DBNull.Value || rst == null)
|
|
|
{
|
|
|
|
|
|
mfno = "";
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
mfno = rst.ToString();
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
mfno = "";
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
/// <param name="mblno"></param>
|
|
|
/// <param name="userid"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
/// <param name="mblno"></param>
|
|
|
/// <param name="userid"></param>
|
|
|
/// <returns></returns>
|
|
|
public static bool HasSameMBLNOWithUserIdForInterface(string mblno, string hblno, string userid, OPTYPE _optype, out string mfno, out string status, out string zhifatext)
|
|
|
{
|
|
|
mfno = "";
|
|
|
status = "";
|
|
|
zhifatext = "";
|
|
|
string sql = "select count(*) from op_seae_edi where mblno = '" + mblno + "' and hblno = '" + hblno + "' ";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
bool rst = Convert.ToInt32(db.ExecuteScalar(CommandType.Text, sql)) > 0;
|
|
|
if (rst)
|
|
|
{
|
|
|
string sql1 = "select top 1 mfno,edistatus,zhifatext from op_seae_edi where hblno='" + hblno + "' and mblno = '" + mblno + "' and inputbyid = '" + userid + "' ";//and EDISTATUS = '已录入' ";
|
|
|
|
|
|
if (_optype.SHOWNAME == "保存") sql1 += " and EDISTATUS = '已录入' ";
|
|
|
|
|
|
if (_optype.SHOWNAME == "修改") sql1 += " and EDISTATUS = '已直发' ";
|
|
|
if (_optype.SHOWNAME == "删除") sql1 += " and EDISTATUS = '已直发' ";
|
|
|
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql1))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
mfno = reader["mfno"].ToString();
|
|
|
status = reader["edistatus"].ToString();
|
|
|
zhifatext = reader["zhifatext"].ToString();
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
//mfno = db.ExecuteScalar(CommandType.Text, sql1).ToString();
|
|
|
}
|
|
|
return rst;
|
|
|
}
|
|
|
|
|
|
|
|
|
private bool deleteFaildData(string mfnos)
|
|
|
{
|
|
|
string sql1 = "delete from op_seae_edi where mfno in (" + mfnos + ")" +
|
|
|
"delete from op_seae_edi_ctn where mfno in (" + mfnos + ")";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
bool rst = false;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
rst = db.ExecuteNonQuery(CommandType.Text, sql1) > 0;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
rst = false;
|
|
|
}
|
|
|
|
|
|
return rst;
|
|
|
}
|
|
|
|
|
|
private string GetPKGWithEIDCODE(string edicode)
|
|
|
{
|
|
|
string sql = "select top 1 pkgs from code_package where edicode = '" + edicode + "'";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
string pkgs = "";
|
|
|
try
|
|
|
{
|
|
|
pkgs = db.ExecuteScalar(CommandType.Text, sql).ToString();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
pkgs = "";
|
|
|
}
|
|
|
return pkgs;
|
|
|
}
|
|
|
|
|
|
private string GetSHOWNAMEWithUid(string uid)
|
|
|
{
|
|
|
string sql = "select top 1 showname from [user] where gid = '" + uid + "'";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
string showname = "";
|
|
|
try
|
|
|
{
|
|
|
showname = db.ExecuteScalar(CommandType.Text, sql).ToString();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
showname = "";
|
|
|
}
|
|
|
return showname;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询状态
|
|
|
/// </summary>
|
|
|
/// <param name="mblno"></param>
|
|
|
/// <param name="userid"></param>
|
|
|
/// <returns></returns>
|
|
|
public static List<EDIStatusModeli> GetEMFSTATUSList(string mblnos)
|
|
|
{
|
|
|
string[] mblnoArr = mblnos.Split(',');
|
|
|
string mblnoStr = "";
|
|
|
foreach (string mblno in mblnoArr)
|
|
|
{
|
|
|
mblnoStr += "'" + mblno + "',";
|
|
|
}
|
|
|
mblnoStr = mblnoStr.Substring(0, mblnoStr.Length - 1);
|
|
|
string sql = $"select * from (select t1.mblno, t0.statustext,t0.statustime,t0.shenbaoxiangshu from op_seae_edi_status t0 join op_seae_edi t1 on t0.mfno = t1.MFNO where t1.mblno in ({mblnoStr}) and isnull( t1.HBLNO,'')='' union all select t1.HBLNO mblno, t0.statustext,t0.statustime,t0.shenbaoxiangshu from op_seae_edi_status t0 join op_seae_edi t1 on t0.mfno = t1.MFNO where t1.hblno in ({mblnoStr}) )t order by t.statustime";
|
|
|
List<EDIStatusModeli> list = new List<EDIStatusModeli>();
|
|
|
List<EDIStatusModeli> listRtn = new List<EDIStatusModeli>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
EDIStatusModeli v = new EDIStatusModeli();
|
|
|
v.status = reader["statustext"].ToString();
|
|
|
v.statustime = ((DateTime)reader["statustime"]).ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
v.shenbaoxiangshu = Convert.ToInt32(reader["shenbaoxiangshu"].ToString());
|
|
|
v.blno = reader["mblno"].ToString();
|
|
|
list.Add(v);
|
|
|
}
|
|
|
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
list = list.OrderByDescending(o => o.statustime).OrderBy(o => o.blno).ToList();
|
|
|
string blnoTemp = "";
|
|
|
foreach (var item in list)
|
|
|
{
|
|
|
if (blnoTemp != item.blno)
|
|
|
{
|
|
|
|
|
|
listRtn.Add(item);
|
|
|
blnoTemp = item.blno;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
return listRtn;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public class IPRecord
|
|
|
{
|
|
|
|
|
|
//const int maxhit = 5;
|
|
|
const int maxhit = 20;//2022-4-12,衣国豪:修改为30秒20次
|
|
|
const double overtimenum = 30;
|
|
|
|
|
|
public static List<IPRecord> List;
|
|
|
public static bool isnull
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return (List == null);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private string IP { get; set; }
|
|
|
private int hit { get; set; }
|
|
|
private DateTime st { get; set; }
|
|
|
|
|
|
public bool overtime
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
TimeSpan span = DateTime.Now - st;
|
|
|
if (span.TotalSeconds > overtimenum)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void clear()
|
|
|
{
|
|
|
if (!isnull)
|
|
|
{
|
|
|
for (int i = List.Count - 1; i >= 0; i--)
|
|
|
{
|
|
|
if (List[i].overtime)
|
|
|
List.Remove(List[i]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public IPRecord(string ip, int hit)
|
|
|
{
|
|
|
if (List == null) List = new List<IPRecord>();
|
|
|
|
|
|
this.IP = ip;
|
|
|
this.hit = hit;
|
|
|
st = DateTime.Now;
|
|
|
|
|
|
List.Add(this);
|
|
|
}
|
|
|
|
|
|
public static bool canhit(string ip)
|
|
|
{
|
|
|
|
|
|
IPRecord.clear();
|
|
|
if (gethit(ip) > 0)
|
|
|
{
|
|
|
foreach (var item in List)
|
|
|
{
|
|
|
if (item.IP == ip)
|
|
|
{
|
|
|
if (item.hit > maxhit)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
item.hit++;
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static int gethit(string ip)
|
|
|
{
|
|
|
if (List == null || List.Count == 0)
|
|
|
{
|
|
|
var _t = new IPRecord(ip, 1);
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
foreach (var item in List)
|
|
|
{
|
|
|
if (item.IP == ip)
|
|
|
{
|
|
|
return item.hit;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
public static void reset(string ip)
|
|
|
{
|
|
|
if (List == null || List.Count == 0)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
foreach (var item in List)
|
|
|
{
|
|
|
if (item.IP == ip)
|
|
|
{
|
|
|
List.Remove(item);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |