You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1830 lines
97 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Common;
using djy.Model.Ams;
using djy.Model.AmsDto;
using Common.Extensions;
using Common.DJYModel;
using System.Transactions;
using Dapper.Contrib.Extensions;
using Common.Utilities;
using Newtonsoft.Json;
using System.Security.Cryptography;
using System.Text.Encodings.Web;
using Common.Tools;
using System.Web;
using Newtonsoft.Json.Linq;
using iTextSharp.text;
using System.IO;
using iTextSharp.text.pdf;
using System.Reflection;
using djy.IService.Ams;
using djy.Service.DjyService;
namespace djy.Service.Ams
{
/// <summary>
/// AMS
/// </summary>
public class AmsService : ServBase, IAmsService
{
#region 查询列表
public TableData Load(AMSQuery req, User user, UserAuthorityDto aut)
{
var result = new TableData();
int count = 0;
string[] ReportStates = null;
if (req.ReportState != null)
{
ReportStates = req.ReportState.Split(',');
}
List<string> hou = null;
if (!req.HBLNo.IsNullOrEmpty())
{
hou = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel != true)
.WhereIf(req.HBLNo != null, x => x.HBLNo.Contains(req.HBLNo)).ToList().Select(x => x.PID).ToList<string>();
}
var dto = DbBus.Get(DbList.AMSCenter).Select<AMS_Master>()
.Where(x => x.IsDel != true)
.WhereIf(!string.IsNullOrEmpty(req.Mid), x => x.GID == req.Mid)
.WhereIf(aut.CompayId != null, x => x.CompID == aut.CompayId.ToString())
.WhereIf(aut.UserId != null, x => x.UserID == aut.UserId.ToString())
.WhereIf(req.MBLNO != null, x => x.MBLNO.Contains(req.MBLNO.Trim()))
.WhereIf(req.PORTDISCHARGECode != null, x => x.PORTDISCHARGECode == req.PORTDISCHARGECode)
.WhereIf(req.LoadingPortCode != null, x => x.LoadingPortCode == req.LoadingPortCode)
.WhereIf(req.UserName != null, x => x.UserName.Contains(req.UserName.Trim()))
.WhereIf(req.CARRIERID != null, x => req.CARRIERID == x.CARRIERID)
.WhereIf(hou != null, x => hou.Contains(x.GID))
.WhereIf(req.BDate != null, x => x.CreateTime >= req.BDate)
.WhereIf(req.EDate != null, x => x.CreateTime <= req.EDate).OrderByDescending(x => x.CreateTime);
if (req.ReportState == "0")
{
result.count = dto.ToList().Count();
var SASCCODEList = DbBus.Get(DbList.djydb).Select<company_new_param_value>().Where(x => x.ParaCode == "AMSSASCCODE").ToList();
var list = dto.Page(req.Page, req.Limit).ToList<AMSDto>();
if (list != null)
{
foreach (var item in list)
{
var SASCCODE = SASCCODEList.Where(x => x.CompId == item.CompID).FirstOrDefault();
if (SASCCODE != null)
{
item.SASCCODE = SASCCODE.ItemCode;
}
else
{
item.SASCCODE = "NIAV";
}
var hodto = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel != true && x.PID == item.GID)
.WhereIf(!string.IsNullOrEmpty(req.Hid), x => x.GID == req.Hid)
.WhereIf(req.HBLNo != null, x => x.HBLNo.Contains(req.HBLNo.Trim()))
.WhereIf(req.ReportState == "0", x => x.ReportState == "未申报")
.WhereIf(req.ReportState == "1", x => x.ReportState != "未申报")
.WhereIf(req.ReportState != null && req.ReportState != "0" && req.ReportState != "1", x => ReportStates.Contains(x.ReportState))
.ToList<AMS_HouseDto>();
item.HouseDto = hodto;
if (hodto != null)
{
foreach (var it in hodto)
{
var cnt = DbBus.Get(DbList.AMSCenter).Select<AMS_Cntrno>().Where(x => x.IsDel != true && x.HID == it.GID).ToList();
it.CntrnoDto = cnt;
var historyDto = DbBus.Get(DbList.AMSCenter).Select<AMS_MasterHistory>().Where(x => x.AM_ID == it.GID).OrderByDescending(x => x.SendTime).ToList();
it.HistoryDto = historyDto;
}
}
count += hodto.Count();
}
}
result.data = list.Where(x => x.HouseDto != null && x.HouseDto.Count() > 0).ToList();
}
else
{
var g = dto.ToList().Select(x => x.GID).ToList();
result.count = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel != true && g.Contains(x.PID))
.WhereIf(!string.IsNullOrEmpty(req.Hid), x => x.GID == req.Hid)
.WhereIf(req.HBLNo != null, x => x.HBLNo.Contains(req.HBLNo.Trim()))
.WhereIf(req.ReportState == "0", x => x.ReportState == "未申报")
.WhereIf(req.ReportState == "1", x => x.ReportState != "未申报")
.WhereIf(req.ReportState != null && req.ReportState != "0" && req.ReportState != "1", x => ReportStates.Contains(x.ReportState)).ToList()
.Count();
var SASCCODEList = DbBus.Get(DbList.djydb).Select<company_new_param_value>().Where(x => x.ParaCode == "AMSSASCCODE").ToList();
var list = dto.ToList<AMSDto>();
if (list != null)
{
foreach (var item in list)
{
var SASCCODE = SASCCODEList.Where(x => x.CompId == item.CompID).FirstOrDefault();
if (SASCCODE != null)
{
item.SASCCODE = SASCCODE.ItemCode;
}
else
{
item.SASCCODE = "NIAV";
}
var hodto = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel != true && x.PID == item.GID)
.WhereIf(!string.IsNullOrEmpty(req.Hid), x => x.GID == req.Hid)
.WhereIf(req.HBLNo != null, x => x.HBLNo.Contains(req.HBLNo.Trim()))
.WhereIf(req.ReportState == "0", x => x.ReportState == "未申报")
.WhereIf(req.ReportState == "1", x => x.ReportState != "未申报")
.WhereIf(req.ReportState != null && req.ReportState != "0" && req.ReportState != "1", x => ReportStates.Contains(x.ReportState))
.ToList<AMS_HouseDto>();
item.HouseDto = hodto.ToList();
if (hodto != null)
{
foreach (var it in hodto)
{
var cnt = DbBus.Get(DbList.AMSCenter).Select<AMS_Cntrno>().Where(x => x.IsDel != true && x.HID == it.GID).ToList();
it.CntrnoDto = cnt;
var historyDto = DbBus.Get(DbList.AMSCenter).Select<AMS_MasterHistory>().Where(x => x.AM_ID == it.GID).OrderByDescending(x => x.SendTime).ToList();
it.HistoryDto = historyDto;
}
}
}
}
result.data = list.Where(x => x.HouseDto != null && x.HouseDto.Count() > 0).Skip((req.Page-1) * req.Limit).Take(req.Limit).ToList();
}
return result;
}
#endregion
#region 删除
public void Delete(string ids, User user)
{
string[] id = ids.Split(',');
DbBus.Get(DbList.AMSCenter).Transaction(() =>
{
foreach (string oid in id)
{
if (oid != "")
{
DbBus.Get(DbList.AMSCenter).Transaction(() =>
{
AMS_MasterHistory history = new AMS_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.AM_ID = oid;
history.SendTime = DateTime.Now;///此处为删除时间
history.State = "删除";
history.Type = "0";
history.Operator = user.SHOWNAME;
history.Remark = user.SHOWNAME + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "删除了单据";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
DbBus.Get(DbList.AMSCenter).Update<AMS_Master>().Set(w => w.IsDel, true).Where(w => w.GID == oid).ExecuteAffrows();
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => w.IsDel, true).Where(w => w.PID == oid).ExecuteAffrows();
DbBus.Get(DbList.AMSCenter).Update<AMS_Cntrno>().Set(w => w.IsDel, true).Where(w => w.PID == oid).ExecuteAffrows();
});
}
}
});
}
#endregion
#region 新增/编辑
public string SaveInfo(AMSDto dto, User user)
{
string guid = "";
List<string> hblist = null;
hblist = dto.HouseDto.Select(x => x.HBLNo.Trim()).ToList();
var mlist = DbBus.Get(DbList.AMSCenter).Select<AMS_Master>().Where(x => x.IsDel != true && x.MBLNO == dto.MBLNO.Trim() && x.GID != dto.GID && x.MBLNO != "").ToOne();
var hlist = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel != true && hblist.Contains(x.HBLNo) && x.PID != dto.GID && x.HBLNo != "").ToOne();
if (mlist != null || hlist != null)
{
return "-1";
}
if (dto.GID.IsNull())
{
DbBus.Get(DbList.AMSCenter).Transaction(() =>
{
AMS_Master master = dto.MapTo<AMS_Master>();
master.GID = Guid.NewGuid().ToString("N");
master.UserID = user.GID;
master.UserName = user.SHOWNAME;
master.CompID = user.CompId;
master.CompName = user.COMNAME;
master.IsDel = false;
master.PORTDISCHARGE = DbBus.Get(DbList.Common).Select<CodePort>().Where(x => x.Code == master.PORTDISCHARGECode).ToList().Select(x => x.EnName).FirstOrDefault();
master.CARRIER = DbBus.Get(DbList.Common).Select<CodeCarrier>().Where(x => x.Code == master.CARRIERID).ToList().Select(x => x.EnName).FirstOrDefault();
master.LoadingPort = DbBus.Get(DbList.Common).Select<CodePortLoad>().Where(x => x.EdiCode == master.LoadingPortCode).ToList().Select(x => x.EnName).FirstOrDefault();
master.LastNoUsPort = DbBus.Get(DbList.Common).Select<CodePort>().Where(x => x.Code == master.LastNoUsPortCode).ToList().Select(x => x.EnName).FirstOrDefault();
master.CreateTime = DateTime.Now;
master.LastUpdate = DateTime.Now;
DbBus.Get(DbList.AMSCenter).Insert(master).ExecuteAffrows();
if (dto.HouseDto != null && dto.HouseDto.Count() > 0)
{
foreach (var item in dto.HouseDto)
{
AMS_House house = item.MapTo<AMS_House>();
house.GID = Guid.NewGuid().ToString("N");
house.PID = master.GID;
house.IsDel = false;
house.State = "0";
house.ReportState = "未申报";
DbBus.Get(DbList.AMSCenter).Insert(house).ExecuteAffrows();
if (item.CntrnoDto != null && item.CntrnoDto.Count() > 0)
{
foreach (var it in item.CntrnoDto)
{
AMS_Cntrno cntrno = it.MapTo<AMS_Cntrno>();
cntrno.GID = Guid.NewGuid().ToString("N");
cntrno.PID = master.GID;
cntrno.HID = house.GID;
cntrno.IsDel = false;
DbBus.Get(DbList.AMSCenter).Insert(cntrno).ExecuteAffrows();
}
}
AMS_MasterHistory history = new AMS_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.AM_ID = house.GID;
history.SendTime = DateTime.Now;
history.State = "新增";
history.Type = "0";
history.Operator = user.SHOWNAME;
history.Remark = user.SHOWNAME + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "创建了单据";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
}
}
guid = master.GID;
});
return guid;
}
else
{
if (DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel != true && x.PID == dto.GID).ToList().Where(x => x.ReportState.Contains("未申报")).Count() > 0)
{
DbBus.Get(DbList.AMSCenter).Transaction(() =>
{
var master = DbBus.Get(DbList.AMSCenter).Select<AMS_Master>().Where(w => w.GID == dto.GID).ToOne();
master.CARRIERID = dto.CARRIERID;
master.MBLNO = dto.MBLNO;
master.VESSEL = dto.VESSEL;
master.VOYNO = dto.VOYNO;
master.ShippingType = dto.ShippingType;
master.SHIPPERADDR = dto.SHIPPERADDR;
master.ETA = dto.ETA;
master.ETD = dto.ETD;
master.LastUpdate = DateTime.Now;
master.ShippingNo = dto.ShippingNo;
master.ConsignmentType = dto.ConsignmentType;
master.LoadingPortCode = dto.LoadingPortCode;
master.PORTDISCHARGECode = dto.PORTDISCHARGECode;
master.LastNoUsPortCode = dto.LastNoUsPortCode;
master.PORTDISCHARGE = DbBus.Get(DbList.Common).Select<CodePort>().Where(x => x.Code == master.PORTDISCHARGECode).ToList().Select(x => x.EnName).FirstOrDefault();
master.CARRIER = DbBus.Get(DbList.Common).Select<CodeCarrier>().Where(x => x.Code == master.CARRIERID).ToList().Select(x => x.EnName).FirstOrDefault();
master.LoadingPort = DbBus.Get(DbList.Common).Select<CodePortLoad>().Where(x => x.EdiCode == master.LoadingPortCode).ToList().Select(x => x.EnName).FirstOrDefault();
master.LastNoUsPort = DbBus.Get(DbList.Common).Select<CodePort>().Where(x => x.Code == master.LastNoUsPortCode).ToList().Select(x => x.EnName).FirstOrDefault();
DbBus.Get(DbList.AMSCenter).Update<AMS_Master>().SetSource(master).ExecuteAffrows();
DbBus.Get(DbList.AMSCenter).Delete<AMS_House>().Where(w => w.PID == master.GID).ExecuteAffrows();
DbBus.Get(DbList.AMSCenter).Delete<AMS_Cntrno>().Where(w => w.PID == master.GID).ExecuteAffrows();
foreach (var item in dto.HouseDto)
{
var house = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(w => w.GID == item.GID).ToOne();
house = item.MapTo<AMS_House>();
house.GID = Guid.NewGuid().ToString("N");
house.PID = master.GID;
house.IsDel = false;
house.State = "0";
house.ReportState = "未申报";
DbBus.Get(DbList.AMSCenter).Insert(house).ExecuteAffrows();
if (item.CntrnoDto != null && item.CntrnoDto.Count() > 0)
{
foreach (var it in item.CntrnoDto)
{
AMS_Cntrno cntrno = it.MapTo<AMS_Cntrno>();
cntrno.GID = Guid.NewGuid().ToString("N");
cntrno.PID = master.GID;
cntrno.HID = house.GID;
cntrno.IsDel = false;
DbBus.Get(DbList.AMSCenter).Insert(cntrno).ExecuteAffrows();
}
}
AMS_MasterHistory history = new AMS_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.AM_ID = house.GID;
history.SendTime = DateTime.Now;
history.State = "新增";
history.Type = "0";
history.Operator = user.SHOWNAME;
history.Remark = user.SHOWNAME + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "创建了单据";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
}
guid = master.GID;
});
}
else
{
DbBus.Get(DbList.AMSCenter).Transaction(() =>
{
var master = DbBus.Get(DbList.AMSCenter).Select<AMS_Master>().Where(w => w.GID == dto.GID).ToOne();
master.CARRIERID = dto.CARRIERID;
master.MBLNO = dto.MBLNO;
master.VESSEL = dto.VESSEL;
master.VOYNO = dto.VOYNO;
master.ShippingType = dto.ShippingType;
master.SHIPPERADDR = dto.SHIPPERADDR;
master.ETA = dto.ETA;
master.ETD = dto.ETD;
master.LastUpdate = DateTime.Now;
master.ShippingNo = dto.ShippingNo;
master.ConsignmentType = dto.ConsignmentType;
master.LoadingPortCode = dto.LoadingPortCode;
master.PORTDISCHARGECode = dto.PORTDISCHARGECode;
master.LastNoUsPortCode = dto.LastNoUsPortCode;
master.PORTDISCHARGE = DbBus.Get(DbList.Common).Select<CodePort>().Where(x => x.Code == master.PORTDISCHARGECode).ToList().Select(x => x.EnName).FirstOrDefault();
master.CARRIER = DbBus.Get(DbList.Common).Select<CodeCarrier>().Where(x => x.Code == master.CARRIERID).ToList().Select(x => x.EnName).FirstOrDefault();
master.LoadingPort = DbBus.Get(DbList.Common).Select<CodePortLoad>().Where(x => x.EdiCode == master.LoadingPortCode).ToList().Select(x => x.EnName).FirstOrDefault();
master.LastNoUsPort = DbBus.Get(DbList.Common).Select<CodePort>().Where(x => x.Code == master.LastNoUsPortCode).ToList().Select(x => x.EnName).FirstOrDefault();
DbBus.Get(DbList.AMSCenter).Update<AMS_Master>().SetSource(master).ExecuteAffrows();
DbBus.Get(DbList.AMSCenter).Delete<AMS_Cntrno>().Where(w => w.PID == master.GID).ExecuteAffrows();
List<string> houseid = dto.HouseDto.Select(x => x.GID).ToList();
foreach (var item in dto.HouseDto)
{
var house = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(w => w.GID == item.GID).ToOne();
if (house != null)
{
house.HBLNo = item.HBLNo;
house.SHIPPERNAME = item.SHIPPERNAME;
house.SHIPPERADDR = item.SHIPPERADDR;
house.SHIPPERTEL = item.SHIPPERTEL;
house.CONSIGNEEName = item.CONSIGNEEName;
house.CONSIGNEEDADDR = item.CONSIGNEEDADDR;
house.CONSIGNEETEL = item.CONSIGNEETEL;
house.NOTIFYPARTYNAME = item.NOTIFYPARTYNAME;
house.NOTIFYPARTYADDR = item.NOTIFYPARTYADDR;
house.NOTIFYPARTYTEL = item.NOTIFYPARTYTEL;
house.SHIPPERCountry = item.SHIPPERCountry;
house.SHIPPERCountryCode = item.SHIPPERCountryCode;
house.SHIPPERCity = item.SHIPPERCity;
house.CONSIGNEECountry = item.CONSIGNEECountry;
house.CONSIGNEECountryCode = item.CONSIGNEECountryCode;
house.CONSIGNEECity = item.CONSIGNEECity;
house.NOTIFYPARTYCountry = item.NOTIFYPARTYCountry;
house.NOTIFYPARTYCountryCode = item.NOTIFYPARTYCountryCode;
house.NOTIFYPARTYCity = item.NOTIFYPARTYCity;
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().SetSource(house).ExecuteAffrows();
if (item.CntrnoDto != null && item.CntrnoDto.Count() > 0)
{
foreach (var it in item.CntrnoDto)
{
var cntrno = new AMS_Cntrno();
cntrno = it.MapTo<AMS_Cntrno>();
cntrno.GID = Guid.NewGuid().ToString("N");
cntrno.PID = master.GID;
cntrno.HID = house.GID;
cntrno.IsDel = false;
DbBus.Get(DbList.AMSCenter).Insert(cntrno).ExecuteAffrows();
}
}
//AMS_MasterHistory history = new AMS_MasterHistory();
//history.GID = Guid.NewGuid().ToString("N");
//history.AM_ID = item.GID;
//history.SendTime = DateTime.Now;
//history.State = "修改";
//history.Type = "0";
//history.Operator = user.SHOWNAME;
//history.Remark = user.SHOWNAME + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "修改了单据";
//DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
}
else
{
house = item.MapTo<AMS_House>();
house.GID = Guid.NewGuid().ToString("N");
house.PID = master.GID;
house.IsDel = false;
house.State = "0";
house.ReportState = "未申报";
DbBus.Get(DbList.AMSCenter).Insert(house).ExecuteAffrows();
if (item.CntrnoDto != null && item.CntrnoDto.Count() > 0)
{
foreach (var it in item.CntrnoDto)
{
AMS_Cntrno cntrno = it.MapTo<AMS_Cntrno>();
cntrno.GID = Guid.NewGuid().ToString("N");
cntrno.PID = master.GID;
cntrno.HID = house.GID;
cntrno.IsDel = false;
DbBus.Get(DbList.AMSCenter).Insert(cntrno).ExecuteAffrows();
}
}
AMS_MasterHistory history = new AMS_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.AM_ID = house.GID;
history.SendTime = DateTime.Now;
history.State = "新增";
history.Type = "0";
history.Operator = user.SHOWNAME;
history.Remark = user.SHOWNAME + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "创建了单据";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
}
}
guid = master.GID;
});
}
return guid;
}
}
#endregion
#region 第三方接口
/// <summary>
/// 发送接口
/// </summary>
/// <param name="Gid"></param>
/// <param name="userid"></param>
/// <param name="docType"></param>
public async Task<Response> SendDE(string Gid, User user, string docType, string hid = null)
{
Response req = new Response();
try
{
string[] id = Gid.Split(',');
string[] House = null;
if (hid != null)
{
House = hid.Split(',');
}
var AMSAccount = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "AMSAccount").ToOne();
var key = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "AMSKEY").ToOne();
var url = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "AMSURL").ToOne();
var method = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "AMSMethod").ToOne();
var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var AMSRequestDEA = DbBus.Get(DbList.djydb).Select<company_new_param_value>().Where(x => x.CompId == user.CompId && x.ParaCode == "AMSRequestDEA").First();
foreach (string oid in id)
{
if (oid != "")
{
var docContent = "";
var fin = new FinanceService();
var master = DbBus.Get(DbList.AMSCenter).Select<AMS_Master>().Where(x => x.IsDel != true && x.CompID == user.CompId && x.GID == oid).ToOne();
var hodto = new List<AMS_HouseDto>();
if (docType == "AMSDOC")
{
hodto = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel != true && x.PID == oid && x.State == "0").ToList<AMS_HouseDto>();
#region docContent 新增
var cARRIERIDList = DbBus.Get(DbList.Common).Select<MappingCarrier>().Where(map => map.Module == "AMS").ToList();
var portList = DbBus.Get(DbList.Common).Select<CodePort>().ToList();
var containerTypeList = DbBus.Get(DbList.Common).Select<MappingCtn>().Where(map => map.Module == "AMS").ToList();
var packageList = DbBus.Get(DbList.Common).Select<MappingPackage>().Where(map => map.Module == "AMS").ToList();
MasterBillInfoDto dto = new MasterBillInfoDto();
masterBillInfo masterBillInfo = new masterBillInfo();
masterBillInfo.masterBillNo = cARRIERIDList.Where(x => x.Code == master.CARRIERID).Select(x => x.MapCode).FirstOrDefault() + master.MBLNO;
masterBillInfo.shippingNo = null;
masterBillInfo.shipCompany = cARRIERIDList.Where(x => x.Code == master.CARRIERID).Select(x => x.MapCode).FirstOrDefault();
masterBillInfo.vessel = master.VESSEL;
if (master.VOYNO.TrimAll().Length > 4)
{
masterBillInfo.voyage = master.VOYNO.TrimAll().Substring(0, 5);
}
else
{
masterBillInfo.voyage = master.VOYNO;
}
if (AMSRequestDEA != null)
{
masterBillInfo.requesterDea = AMSRequestDEA.ItemCode;
}
else {
masterBillInfo.requesterDea = sysOptionConfig.Webconfig.requesterDea;
}
masterBillInfo.consignmentType = master.ConsignmentType;
masterBillInfo.loadHarbour = master.LoadingPort;
masterBillInfo.loadHarbourCode = master.LoadingPortCode;
masterBillInfo.dischargeHarbour = master.PORTDISCHARGE;
masterBillInfo.dischargeHarbourCode = portList.Where(x => x.Code == master.PORTDISCHARGECode).Select(x => x.EdiCode).FirstOrDefault();
masterBillInfo.lastForeignHarbour = master.LastNoUsPort;
masterBillInfo.lastForeignHarbourCode = portList.Where(x => x.Code == master.LastNoUsPortCode).Select(x => x.EdiCode).FirstOrDefault();
masterBillInfo.loadDate = Convert.ToDateTime(master.ETA).ToString("yyyy-MM-dd hh:mm:ss");
masterBillInfo.estimatedArrivalTime = Convert.ToDateTime(master.ETD).ToString("yyyy-MM-dd hh:mm:ss");
masterBillInfo.filingType = master.ShippingType;
dto.masterBillInfo = masterBillInfo;
List<HouseBillInfoListItem> houseBillInfoListItems = new List<HouseBillInfoListItem>();
foreach (var item in hodto)
{
var getfinrs = fin.Expend(new CustFee
{
ETD = master.ETD,
VOYNO = master.VOYNO,
VESSEL = master.VESSEL,
HBLNO = item.HBLNo,
SENDUSERID = user.GID,
LURURENID = user.GID,
CtnrCount = 1,
CtnrInfo = string.Empty,
BSTYPE = 15,
SENDTYPE = 0,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}
, 0);
if (!getfinrs.Status)
{
req.Code = 201;
req.Message = getfinrs.Message;
return req;
}
HouseBillInfoListItem houseinfo = new HouseBillInfoListItem();
houseinfo.businessId = item.GID;
houseinfo.shippingNo = null;
houseinfo.houseBillNo = item.HBLNo;
houseinfo.sendAddress = item.SHIPPERADDR;
houseinfo.sendName = item.SHIPPERNAME;
houseinfo.sendCity = item.SHIPPERCity;
houseinfo.sendCountry = item.SHIPPERCountry;
houseinfo.sendCountryCode = item.SHIPPERCountryCode;
houseinfo.receiveAddress = item.CONSIGNEEDADDR;
houseinfo.receiveName = item.CONSIGNEEName;
houseinfo.receiveCity = item.CONSIGNEECity;
houseinfo.receiveCountry = item.CONSIGNEECountry;
houseinfo.receiveCountryCode = item.CONSIGNEECountryCode;
houseinfo.notifyAddress = item.NOTIFYPARTYADDR;
houseinfo.notifyName = item.NOTIFYPARTYNAME;
houseinfo.notifyCity = item.NOTIFYPARTYCity;
houseinfo.notifyCountry = item.NOTIFYPARTYCountry;
houseinfo.notifyCountryCode = item.NOTIFYPARTYCountryCode;
var cnt = DbBus.Get(DbList.AMSCenter).Select<AMS_Cntrno>().Where(x => (x.IsDel == false || x.IsDel == null) && x.HID == item.GID).ToList();
CtnInfo CtnInfo = new CtnInfo();
List<InsertListItem> list = new List<InsertListItem>();
foreach (var it in cnt)
{
InsertListItem insertList = new InsertListItem();
insertList.containerMark = null;
insertList.containerType = containerTypeList.Where(x => x.Code == it.CTNALL).Select(x => x.MapCode).FirstOrDefault();
insertList.enProductName = it.ProductName;
insertList.containerNo = it.CNTRNO;
insertList.sealNo = it.SEALNO;
insertList.digit = it.PKGS.ToString();
insertList.grossWeight = it.KGS.ToString();
insertList.volume = it.CBM.ToString();
insertList.packing = packageList.Where(x => x.Code == it.KINDPKGSCode).Select(x => x.MapName).FirstOrDefault();
insertList.packingCode = packageList.Where(x => x.Code == it.KINDPKGSCode).Select(x => x.MapCode).FirstOrDefault();
insertList.shippingMark = it.MARKS;
insertList.secondSealNo = null;
insertList.originCountry = "CHINA";
insertList.originCountryCode = "CN";
insertList.unCode = it.DUNNO;
insertList.dangerGrade = it.DangerGrade;
insertList.dangerContact = "";
insertList.dangerContactTel = "";
insertList.dangerMemo = "";
insertList.ignite = "";
list.Add(insertList);
CtnInfo.insertList = list;
}
houseinfo.ctnInfo = CtnInfo;
houseBillInfoListItems.Add(houseinfo);
}
dto.houseBillInfoList = houseBillInfoListItems;
var data = JsonConvert.SerializeObject(dto);
AMSDocContent aMSDoc = new AMSDocContent();
aMSDoc.fromdea = "n";
aMSDoc.todea = "n";
aMSDoc.editype = "AMSDOC";
aMSDoc.port = "Ningbo";
aMSDoc.masterBillInfo = dto;
docContent = JsonConvert.SerializeObject(aMSDoc);
docContent = JsonConvert.SerializeObject(aMSDoc).ToBase64();
#endregion
}
else if (docType == "AMSAR" || docType == "AMSM")
{
hodto = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel != true && x.PID == oid).
WhereIf(hid != null, x => House.Contains(x.GID)).
ToList<AMS_HouseDto>();
#region docContent 修改 重发
if (string.IsNullOrEmpty(hid))
{
req.Code = 201;
req.Message = "没有相关货代提单号id";
return req;
}
var cARRIERIDList = DbBus.Get(DbList.Common).Select<MappingCarrier>().Where(map => map.Module == "AMS").ToList();
var portList = DbBus.Get(DbList.Common).Select<CodePort>().ToList();
var containerTypeList = DbBus.Get(DbList.Common).Select<MappingCtn>().Where(map => map.Module == "AMS").ToList();
var packageList = DbBus.Get(DbList.Common).Select<MappingPackage>().Where(map => map.Module == "AMS").ToList();
MasterBillInfoDto dto = new MasterBillInfoDto();
masterBillInfo masterBillInfo = new masterBillInfo();
masterBillInfo.masterBillNo = cARRIERIDList.Where(x => x.Code == master.CARRIERID).Select(x => x.MapCode).FirstOrDefault() + master.MBLNO;
masterBillInfo.shippingNo = null;
masterBillInfo.shipCompany = cARRIERIDList.Where(x => x.Code == master.CARRIERID).Select(x => x.MapCode).FirstOrDefault();
masterBillInfo.vessel = master.VESSEL;
if (master.VOYNO.TrimAll().Length > 4)
{
masterBillInfo.voyage = master.VOYNO.TrimAll().Substring(0, 5);
}
else
{
masterBillInfo.voyage = master.VOYNO;
}
if (AMSRequestDEA != null)
{
masterBillInfo.requesterDea = AMSRequestDEA.ItemCode;
}
else
{
masterBillInfo.requesterDea = sysOptionConfig.Webconfig.requesterDea;
}
masterBillInfo.consignmentType = master.ConsignmentType;
masterBillInfo.loadHarbour = master.LoadingPort;
masterBillInfo.loadHarbourCode = master.LoadingPortCode;
masterBillInfo.dischargeHarbour = master.PORTDISCHARGE;
masterBillInfo.dischargeHarbourCode = portList.Where(x => x.Code == master.PORTDISCHARGECode).Select(x => x.EdiCode).FirstOrDefault();
masterBillInfo.lastForeignHarbour = master.LastNoUsPort;
masterBillInfo.lastForeignHarbourCode = portList.Where(x => x.Code == master.LastNoUsPortCode).Select(x => x.EdiCode).FirstOrDefault();
masterBillInfo.loadDate = Convert.ToDateTime(master.ETA).ToString("yyyy-MM-dd hh:mm:ss");
masterBillInfo.estimatedArrivalTime = Convert.ToDateTime(master.ETD).ToString("yyyy-MM-dd hh:mm:ss");
masterBillInfo.filingType = master.ShippingType;
dto.masterBillInfo = masterBillInfo;
List<HouseBillInfoListItem> houseBillInfoListItems = new List<HouseBillInfoListItem>();
foreach (var item in hodto)
{
if (docType == "AMSAR" && (item.NewNotice == "删除发送成功" || item.MateState == "匹配失败"))
{
req.Code = 201;
req.Message = "当前状态不能重发!如有疑问,请联系相关客服!";
return req;
}
if (docType == "AMSDOC" && (item.NewNotice == "新增发送成功"))
{
req.Code = 201;
req.Message = "当前单据已经发送,不能再次发送!如有疑问,请联系相关客服!";
return req;
}
if (docType == "AMSAR")
{
var getfinrs = fin.Expend(new CustFee
{
ETD = master.ETD,
VOYNO = master.VOYNO,
VESSEL = master.VESSEL,
HBLNO = item.HBLNo,
SENDUSERID = user.GID,
LURURENID = user.GID,
CtnrCount = 1,
CtnrInfo = string.Empty,
BSTYPE = 15,
SENDTYPE = 0,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}
, 0);
if (!getfinrs.Status)
{
req.Code = 201;
req.Message = getfinrs.Message;
return req;
}
}
if (docType == "AMSM")
{
var getfinrs = fin.Expend(new CustFee
{
ETD = master.ETD,
VOYNO = master.VOYNO,
VESSEL = master.VESSEL,
HBLNO = item.HBLNo,
SENDUSERID = user.GID,
LURURENID = user.GID,
CtnrCount = 1,
CtnrInfo = string.Empty,
BSTYPE = 15,
SENDTYPE = 1,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}
, 0);
if (!getfinrs.Status)
{
req.Code = 201;
req.Message = getfinrs.Message;
return req;
}
}
HouseBillInfoListItem houseinfo = new HouseBillInfoListItem();
houseinfo.businessId = item.GID;
houseinfo.shippingNo = null;
houseinfo.houseBillNo = item.HBLNo;
houseinfo.sendAddress = item.SHIPPERADDR;
houseinfo.sendName = item.SHIPPERNAME;
houseinfo.sendCity = item.SHIPPERCity;
houseinfo.sendCountry = item.SHIPPERCountry;
houseinfo.sendCountryCode = item.SHIPPERCountryCode;
houseinfo.receiveAddress = item.CONSIGNEEDADDR;
houseinfo.receiveName = item.CONSIGNEEName;
houseinfo.receiveCity = item.CONSIGNEECity;
houseinfo.receiveCountry = item.CONSIGNEECountry;
houseinfo.receiveCountryCode = item.CONSIGNEECountryCode;
houseinfo.notifyAddress = item.NOTIFYPARTYADDR;
houseinfo.notifyName = item.NOTIFYPARTYNAME;
houseinfo.notifyCity = item.NOTIFYPARTYCity;
houseinfo.notifyCountry = item.NOTIFYPARTYCountry;
houseinfo.notifyCountryCode = item.NOTIFYPARTYCountryCode;
var cnt = DbBus.Get(DbList.AMSCenter).Select<AMS_Cntrno>().Where(x => x.IsDel != true && x.HID == item.GID).ToList();
CtnInfo CtnInfo = new CtnInfo();
List<InsertListItem> list = new List<InsertListItem>();
foreach (var it in cnt)
{
InsertListItem insertList = new InsertListItem();
insertList.containerMark = null;
insertList.containerType = containerTypeList.Where(x => x.Code == it.CTNALL).Select(x => x.MapCode).FirstOrDefault();
insertList.enProductName = it.ProductName;
insertList.containerNo = it.CNTRNO;
insertList.sealNo = it.SEALNO;
insertList.digit = it.PKGS.ToString();
insertList.grossWeight = it.KGS.ToString();
insertList.volume = it.CBM.ToString();
insertList.packing = packageList.Where(x => x.Code == it.KINDPKGSCode).Select(x => x.MapName).FirstOrDefault();
insertList.packingCode = packageList.Where(x => x.Code == it.KINDPKGSCode).Select(x => x.MapCode).FirstOrDefault();
insertList.shippingMark = it.MARKS;
insertList.secondSealNo = null;
insertList.originCountry = "CHINA";
insertList.originCountryCode = "CN";
insertList.unCode = it.DUNNO;
insertList.dangerGrade = it.DangerGrade;
insertList.dangerContact = "";
insertList.dangerContactTel = "";
insertList.dangerMemo = "";
insertList.ignite = "";
list.Add(insertList);
CtnInfo.insertList = list;
}
houseinfo.ctnInfo = CtnInfo;
houseBillInfoListItems.Add(houseinfo);
}
dto.houseBillInfoList = houseBillInfoListItems;
var data = JsonConvert.SerializeObject(dto);
AMSDocContent aMSDoc = new AMSDocContent();
aMSDoc.fromdea = "n";
aMSDoc.todea = "n";
aMSDoc.editype = "AMSDOC";
aMSDoc.port = "Ningbo";
aMSDoc.masterBillInfo = dto;
docContent = JsonConvert.SerializeObject(aMSDoc);
docContent = JsonConvert.SerializeObject(aMSDoc).ToBase64();
#endregion
}
else
{
hodto = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel != true && x.PID == oid).
WhereIf(hid != null, x => House.Contains(x.GID)).
ToList<AMS_HouseDto>();
foreach (var item in hodto)
{
var getfinrs = fin.Expend(new CustFee
{
ETD = master.ETD,
VOYNO = master.VOYNO,
VESSEL = master.VESSEL,
HBLNO = item.HBLNo,
SENDUSERID = user.GID,
LURURENID = user.GID,
CtnrCount = 1,
CtnrInfo = string.Empty,
BSTYPE = 15,
SENDTYPE = 5,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}
, 0);
if (!getfinrs.Status)
{
req.Code = 201;
req.Message = getfinrs.Message;
return req;
}
if (item.NewNotice == "删除发送成功")
{
req.Code = 201;
req.Message = "已删除单据不可以再次删除";
return req;
}
}
if (string.IsNullOrEmpty(hid))
{
req.Code = 201;
req.Message = "没有相关货代提单号id";
return req;
}
AMSDDto aMSDDto = new AMSDDto();
aMSDDto.fromdea = AMSAccount.PARAMVALUE;
aMSDDto.ids = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel != true && x.PID == oid && House.Contains(x.GID)).ToList().Select(x => x.GID).ToList();
docContent = JsonConvert.SerializeObject(aMSDDto).ToBase64();
}
/////MD5加密
string stringSign = string.Format("{0}{1}{2}", AMSAccount.PARAMVALUE, key.PARAMVALUE, timestamp);
string sign = stringSign.ToMd5();
///post参数
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("port", "Ningbo");
dic.Add("docContent", docContent);
dic.Add("method", method.PARAMVALUE);
dic.Add("channel", "WSTOM");
dic.Add("docName", GenerateRandomNo());
dic.Add("user_id", AMSAccount.PARAMVALUE);
dic.Add("userId", AMSAccount.PARAMVALUE);
dic.Add("docType", docType);
dic.Add("timestamp", timestamp);
dic.Add("format", "json");
dic.Add("destDeaId", "n");
dic.Add("deaId", "n");
dic.Add("sign", sign);
dic.Add("docLength", docContent.ToString().Length.ToString());
#region 接口调用
_LogsAdd("SendDE", "post", $"timestamp{timestamp}");
_LogsAdd("SendDE", "post", $"AMS接口调用发送{oid}{ JsonConvert.SerializeObject(dic)}");
_LogsAdd("SendDE", "post", $"AMS接口调用地址{oid}{url.PARAMVALUE}");
string gethtml = await HttpHelp.Post(dic, url.PARAMVALUE, PsotType.Urlencoded);
_LogsAdd("SendDE", "post", $"AMS接口调用返回{oid}{gethtml}");
if (gethtml != null)
{
JObject rlt = JObject.Parse(gethtml);
var code = rlt.GetValue("code").ToString();
var msg = rlt.GetValue("msg").ToString();
if (msg == "验签失败")
{
req.Code = 200;
req.Message = "验签失败";
return req;
}
var data = rlt.GetValue("data").ToString();
JObject drlt = JObject.Parse(data);
var result = drlt.GetValue("result").ToString();
if (code == "F" || result == "false")
{
var errorInfo = drlt.GetValue("errorInfo").ToString();
foreach (var item in hodto)
{
AMS_MasterHistory history = new AMS_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.AM_ID = item.GID;
history.SendTime = DateTime.Now;
if (docType == "AMSDOC")
{
history.State = "新增发送失败";
history.Type = "0";
}
else if (docType == "AMSAR")
{
history.State = "重发失败";
history.Type = "0";
}
else if (docType == "AMSM")
{
history.State = "修改发送失败";
history.Type = "0";
}
else
{
history.State = "删除发送失败";
history.Type = "0";
}
history.Operator = user.SHOWNAME;
history.Remark = user.SHOWNAME + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "发送单据失败,失败原因:" + msg + errorInfo;
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
}
req.Code = 201;
req.Message = "操作失败," + msg + errorInfo;
return req;
}
if (code == "T" && result == "true")
{
AMS_MasterHistory history = new AMS_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.AM_ID = oid;
history.SendTime = DateTime.Now;
history.Type = "0";
if (docType == "AMSDOC")
{
history.State = "新增发送成功";
}
else if (docType == "AMSAR")
{
history.State = "重发成功";
}
else if (docType == "AMSM")
{
history.State = "修改发送成功";
}
else
{
history.State = "删除发送成功";
}
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 (docType == "AMSDOC")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = "", ReportState = "已提交", NewNotice = "新增发送成功" }).Where(w => w.PID == oid).ExecuteAffrows();
foreach (var item in hodto)
{
var getfinrs = fin.Expend(new CustFee
{
CARRIER = master.CARRIER,
ETD = master.ETA,
VOYNO = master.VOYNO,
VESSEL = master.VESSEL,
HBLNO = item.HBLNo,
SENDUSERID = user.GID,
LURURENID = user.GID,
CtnrCount = DbBus.Get(DbList.AMSCenter).Select<AMS_Cntrno>().Where(x => x.IsDel != true && x.HID == item.GID).ToList().Count(),
CtnrInfo = string.Empty,
BSTYPE = 15,
SENDTYPE = 0,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}, 1);
}
}
else if (docType == "AMSAR")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = "", ReportState = "已提交", NewNotice = "重发发送成功" }).Where(w => House.Contains(w.GID)).ExecuteAffrows();
foreach (var item in hodto)
{
var getfinrs = fin.Expend(new CustFee
{
CARRIER = master.CARRIER,
ETD = master.ETA,
VOYNO = master.VOYNO,
VESSEL = master.VESSEL,
HBLNO = item.HBLNo,
SENDUSERID = user.GID,
LURURENID = user.GID,
CtnrCount = DbBus.Get(DbList.AMSCenter).Select<AMS_Cntrno>().Where(x => x.IsDel != true && x.HID == item.GID).ToList().Count(),
CtnrInfo = string.Empty,
BSTYPE = 15,
SENDTYPE = 0,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}, 1);
}
}
else if (docType == "AMSM")
{
foreach (var item in hodto)
{
var getfinrs = fin.Expend(new CustFee
{
CARRIER = master.CARRIER,
ETD = master.ETA,
VOYNO = master.VOYNO,
VESSEL = master.VESSEL,
HBLNO = item.HBLNo,
SENDUSERID = user.GID,
LURURENID = user.GID,
CtnrCount = DbBus.Get(DbList.AMSCenter).Select<AMS_Cntrno>().Where(x => x.IsDel != true && x.HID == item.GID).ToList().Count(),
CtnrInfo = string.Empty,
BSTYPE = 15,
SENDTYPE = 1,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}, 1);
}
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = "", ReportState = "已提交", NewNotice = "修改发送成功" }).Where(w => House.Contains(w.GID)).ExecuteAffrows();
}
else
{
foreach (var item in hodto)
{
var getfinrs = fin.Expend(new CustFee
{
CARRIER = master.CARRIER,
ETD = master.ETA,
VOYNO = master.VOYNO,
VESSEL = master.VESSEL,
HBLNO = item.HBLNo,
SENDUSERID = user.GID,
LURURENID = user.GID,
CtnrCount = 1,
CtnrInfo = string.Empty,
BSTYPE = 15,
SENDTYPE = 5,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}, 1);
}
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = "", ReportState = "已提交", NewNotice = "删除发送成功" }).Where(w => House.Contains(w.GID)).ExecuteAffrows();
}
}
}
#endregion
}
}
req.Code = 200;
req.Message = "操作成功";
return req;
}
catch (Exception ex)
{
req.Code = 500;
req.Message = ex.InnerException?.Message ?? ex.Message;
_LogsAdd("SendDE", "post", $"AMS_SendDE接口{req.Message }");
return req;
}
}
public Response SaveReceipt(string msg)
{
Response req = new Response();
try
{
AMSReturnDto retdto = Json.JsonToObject<AMSReturnDto>(msg);
_LogsAdd("SaveReceipt", "post", $"AMS接口推送{msg}");
if (retdto != null)
{
DbBus.Get(DbList.AMSCenter).Transaction(() =>
{
var masterid = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel != true && x.GID == retdto.businessId).ToList().Select(x => x.PID).FirstOrDefault();
if (retdto.status == "W2")
{
var house = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.GID == retdto.businessId).ToOne();
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { State = "1" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
if (house != null)
{
AMS_MasterHistory history = new AMS_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.AM_ID = retdto.businessId;
history.SendTime = DateTime.Now;
history.State = "海关接收成功";
history.Type = "1";
history.Operator = "系统管理员";
history.Remark = "您的单据" + house.HBLNo + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "海关接收成功";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
if (house.NewNotice == "删除发送成功")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "海关接收成功" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
else if (house.NewNotice == "修改发送成功")
{
if (house.MateState.Contains("3Z"))
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = "3Z," + retdto.status, NewNotice = "海关接收成功" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
else
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = house.MateState + "," + retdto.status, NewNotice = "海关接收成功" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
}
else
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = house.MateState + "," + retdto.status, NewNotice = "海关接收成功" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
}
}
else if (retdto.status == "1Y")
{
var house = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.GID == retdto.businessId).ToOne();
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { State = "1" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
if (house != null)
{
AMS_MasterHistory history = new AMS_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.AM_ID = retdto.businessId;
history.SendTime = DateTime.Now;
history.State = "船司匹配成功";
history.Type = "1";
history.Operator = "系统管理员";
history.Remark = "您的单据" + house.HBLNo + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "船司匹配成功";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
if (house.NewNotice == "删除发送成功")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "船司匹配成功" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
else if (house.NewNotice == "修改发送成功")
{
if (house.MateState.Contains("3Z"))
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = "3Z," + retdto.status, NewNotice = "船司匹配成功" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
else
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = house.MateState + "," + retdto.status, NewNotice = "船司匹配成功" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
}
else
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = house.MateState + "," + retdto.status, NewNotice = "船司匹配成功" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
}
}
else if (retdto.status == "3Z")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { State = "1" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
var house = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.GID == retdto.businessId).ToOne();
if (house != null)
{
AMS_MasterHistory history = new AMS_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.AM_ID = retdto.businessId;
history.SendTime = DateTime.Now;
history.State = "ISF匹配成功";
history.Type = "1";
history.Operator = "系统管理员";
history.Remark = "您的单据" + house.HBLNo + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "ISF匹配成功";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
if (house.NewNotice == "删除发送成功")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "ISF匹配成功" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
else
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = house.MateState + "," + retdto.status, NewNotice = "ISF匹配成功" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
}
}
else if (retdto.status == "W1")
{
var house = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.GID == retdto.businessId).ToOne();
AMS_MasterHistory history = new AMS_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.AM_ID = retdto.businessId;
history.SendTime = DateTime.Now;
history.State = "海关拒绝";
history.Type = "1";
history.Operator = "系统管理员";
history.Remark = "您的单据" + house.HBLNo + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "海关拒绝";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
if (house.NewNotice == "删除发送成功")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "海关拒绝" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
else
if (house.NewNotice == "修改发送成功")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "海关拒绝" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
else
if (house.NewNotice == "重发发送成功" || house.NewNotice == "新增发送成功")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "海关拒绝" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
else
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "海关拒绝" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
}
else if (retdto.status == "2Z")
{
var house = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.GID == retdto.businessId).ToOne();
AMS_MasterHistory history = new AMS_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.AM_ID = retdto.businessId;
history.SendTime = DateTime.Now;
history.State = "箱货信息不匹配";
history.Type = "1";
history.Operator = "系统管理员";
history.Remark = "您的单据" + house.HBLNo + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "箱货信息不匹配";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
if (house.NewNotice == "删除发送成功")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "箱货信息不匹配" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
else
if (house.NewNotice == "修改发送成功")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "箱货信息不匹配" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
else
if (house.NewNotice == "重发发送成功" || house.NewNotice == "新增发送成功")
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "箱货信息不匹配" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
else
{
DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "箱货信息不匹配" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
}
}
//else
//{
// AMS_MasterHistory history = new AMS_MasterHistory();
// history.GID = Guid.NewGuid().ToString("N");
// history.AM_ID = retdto.businessId;
// history.SendTime = DateTime.Now;
// history.State = "匹配失败";
// history.Type = "1";
// history.Operator = "系统管理员";
// history.Remark = "您的单据" + house.HBLNo + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "匹配失败";
// DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
// if (house.NewNotice == "删除发送成功")
// {
// DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "匹配失败" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
// }
// else
// if (house.NewNotice == "修改发送成功")
// {
// DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "匹配失败" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
// }
// else
// if (house.NewNotice == "重发发送成功" || house.NewNotice == "新增发送成功")
// {
// DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "匹配失败" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
// }
// else
// {
// DbBus.Get(DbList.AMSCenter).Update<AMS_House>().Set(w => new AMS_House { MateState = retdto.status, NewNotice = "匹配失败" }).Where(w => w.GID == retdto.businessId).ExecuteAffrows();
// }
//}
});
}
else
{
req.Code = 201;
req.Message = "未收到参数";
return req;
}
return req;
}
catch (Exception ex)
{
req.Code = 500;
req.Message = ex.InnerException?.Message ?? ex.Message;
_LogsAdd("SendDE", "post", $"AMS_SaveReceipt接口{req.Message }");
return req;
}
}
/// <summary>
/// 根据日期生成14位随机数
/// </summary>
/// <returns></returns>
public string GenerateRandomNo()
{
int _min = 000000;
int _max = 999999;
Random _rdm = new Random();
return DateTime.Now.ToString("yyyyMMdd") + _rdm.Next(_min, _max).ToString();
}
#endregion
#region 下拉接口
public List<CommonCNEN> GetCountry(string strlink, int page, int limit)
{
try
{
if (page == 0 && limit == 0)
{
var List = DbBus.Get(DbList.Common).Select<CodeCountry>().ToList().Select(x => new CommonCNEN
{
Code = x.Code,
ENName = x.EnName,
CNName = x.CnName,
}).Distinct().ToList();
return List;
}
else
{
var List = DbBus.Get(DbList.Common).Select<CodeCountry>().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.EnName.Contains(strlink.Trim()) || x.CnName.Contains(strlink.Trim())).Page(page, limit).ToList().Select(x => new CommonCNEN
{
Code = x.Code,
ENName = x.EnName,
CNName = x.CnName,
}).Distinct().ToList();
return List;
}
}
catch (Exception e)
{
throw;
}
}
public List<CommonMappiCode> GetCARRIER()
{
try
{
var List = DbBus.Get(DbList.Common).Select<CodeCarrier, MappingCarrier>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AMS").ToList((cc, map) => new CommonMappiCode
{
Code = cc.Code,
Value = cc.EnName,
MapCode = map.MapCode
}).Distinct().ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
public List<CommonCodeValue> GetCTNALL()
{
try
{
var List = DbBus.Get(DbList.Common).Select<CodeCtn, MappingCtn>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AMS").ToList((cc, map) => new CommonCodeValue
{
Code = cc.Code,
Value = cc.Name,
}).Distinct().ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
public List<CommonCodeValue> GetPackage()
{
try
{
var List = DbBus.Get(DbList.Common).Select<CodePackage, MappingPackage>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AMS").ToList((cc, map) => new CommonCodeValue
{
Code = cc.Code,
Value = cc.Name,
}).Distinct().ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
public List<CodeDangerGradeDto> GetDangerousGoods(string strlink)
{
try
{
var List = DbBus.Get(DbList.Common).Select<CodeDangerGrade>().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.Grade.Contains(strlink.Trim())).ToList().Select(x => new CodeDangerGradeDto
{
Code = x.Code,
Grade = x.Grade,
}).Distinct().ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
public List<CommonCodeValue> GetPort(string strlink, int page, int limit)
{
try
{
if (page == 0 && limit == 0)
{
var List = DbBus.Get(DbList.Common).Select<CodePort>().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.EnName.Contains(strlink.Trim())).ToList().Select(x => new CommonCodeValue
{
Code = x.Code,
Value = x.EnName,
}).Distinct().ToList();
return List;
}
else
{
var List = DbBus.Get(DbList.Common).Select<CodePort>().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.EnName.Contains(strlink.Trim())).Page(page, limit).ToList().Select(x => new CommonCodeValue
{
Code = x.Code,
Value = x.EnName,
}).Distinct().ToList();
return List;
}
}
catch (Exception e)
{
throw;
}
}
public List<CommonCodeValue> GetCodePortLoad()
{
try
{
var List = DbBus.Get(DbList.Common).Select<CodePortLoad>().ToList().Select(x => new CommonCodeValue
{
Code = x.EdiCode,
Value = x.EnName,
}).Distinct().ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
public List<CommonCodeValue> GetVessel(string strlink, int page, int limit)
{
try
{
if (page == 0 && limit == 0)
{
var List = DbBus.Get(DbList.Common).Select<CodeVessel>().WhereIf(strlink != "", x => x.Name.Contains(strlink.Trim())).ToList().Select(x => new CommonCodeValue
{
Code = x.Name,
Value = x.Name,
}).Distinct().ToList();
return List;
}
else
{
var List = DbBus.Get(DbList.Common).Select<CodeVessel>().WhereIf(strlink != "", x => x.Name.Contains(strlink.Trim())).Page(page, limit).ToList().Select(x => new CommonCodeValue
{
Code = x.Name,
Value = x.Name,
}).Distinct().ToList();
return List;
}
}
catch (Exception e)
{
throw;
}
}
public List<CommonCodeValue> GetCodeProvince(string code)
{
try
{
if (!string.IsNullOrEmpty(code))
{
var List = DbBus.Get(DbList.Common).Select<CodeProvince>().ToList().Where(x => x.Country == code).Select(x => new CommonCodeValue
{
Code = x.Code,
Value = x.ENName,
}).Distinct().ToList();
return List;
}
else
{
var List = DbBus.Get(DbList.Common).Select<CodeProvince>().ToList().Select(x => new CommonCodeValue
{
Code = x.Code,
Value = x.ENName,
}).Distinct().ToList();
return List;
}
}
catch (Exception e)
{
throw;
}
}
public List<CodeCityDto> GetCodeCity(string provinceCode)
{
try
{
var List = DbBus.Get(DbList.Common).Select<CodeCity>().WhereIf(provinceCode != "", x => x.ProvinceCode == provinceCode).ToList().Select(x => new CodeCityDto
{
Code = x.EnName,
PostCode = x.PostCode,
ProvinceCode = x.ProvinceCode,
}).Distinct().ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
#endregion
#region pdf导出
/// <summary>
/// pdf导出
/// </summary>
/// <param name="GID"></param>
/// <returns></returns>
public byte[] PDF(string ids)
{
string[] id = ids.Split(',');
Document document = new Document(PageSize.A4);
//指定字体文件IDENTITY_H支持中文
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "msyh.ttc,0");
_LogsAdd("PDF", "Get", $"PDF字体路径{path }");
BaseFont customfont = BaseFont.CreateFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
var Fonttable = new Font(customfont, 12);
Font font = new Font(customfont, 14);
Font datefont = new Font(customfont, 9);
MemoryStream baos = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(document, baos);
document.Open();
///获取数据源
var houselist = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => id.Contains(x.GID)).ToList();
var cARRIERIDList = DbBus.Get(DbList.Common).Select<MappingCarrier>().Where(map => map.Module == "AMS").ToList();
if (houselist != null)
{
for (int i = 0; i < houselist.Count(); i++)
{
var masterlist = DbBus.Get(DbList.AMSCenter).Select<AMS_Master>().Where(x => x.GID == houselist[i].PID).ToOne();
string heardText = "NIAV" + houselist[i].HBLNo + " ISF INFORMATION";
Paragraph heardTexts = new Paragraph(heardText, font);
heardTexts.IndentationLeft = 150;
heardTexts.IndentationRight = 130;
document.Add(heardTexts);
document.Add(new Paragraph("\r"));//换行
PdfPTable table = new PdfPTable(2); //生成只有2列的行数据
table.DefaultCell.Border = Rectangle.NO_BORDER; //无边框
table.DefaultCell.MinimumHeight = 50f; //高度
float[] widths = new float[] { 100f, 200f }; //宽度
table.SetWidths(widths);
var Row_1 = new PdfPCell(new Paragraph("AMS B/L NO.", Fonttable));
Row_1.HorizontalAlignment = Element.ALIGN_RIGHT;//靠右
table.AddCell(Row_1);
var Row_2 = new PdfPCell(new Paragraph("NIAV" + houselist[i].HBLNo, Fonttable));
Row_2.HorizontalAlignment = Element.ALIGN_LEFT;//靠左
table.AddCell(Row_2);
var Row_3 = new PdfPCell(new Paragraph("HNL.NO.", Fonttable));
Row_3.HorizontalAlignment = Element.ALIGN_RIGHT;//靠右
table.AddCell(Row_3);
var Row_4 = new PdfPCell(new Paragraph(houselist[i].HBLNo, Fonttable));
Row_4.HorizontalAlignment = Element.ALIGN_LEFT;//靠左
table.AddCell(Row_4);
var Row_5 = new PdfPCell(new Paragraph("HNL SCAC CODE.", Fonttable));
Row_5.HorizontalAlignment = Element.ALIGN_RIGHT;//靠右
table.AddCell(Row_5);
var Row_6 = new PdfPCell(new Paragraph("NIAV", Fonttable));
Row_6.HorizontalAlignment = Element.ALIGN_LEFT;//靠左
table.AddCell(Row_6);
var Row_7 = new PdfPCell(new Paragraph("MBL NO.", Fonttable));
Row_7.HorizontalAlignment = Element.ALIGN_RIGHT;//靠右
table.AddCell(Row_7);
var Row_8 = new PdfPCell(new Paragraph(cARRIERIDList.Where(x => x.Code == masterlist.CARRIERID).Select(x => x.MapCode).FirstOrDefault() + masterlist.MBLNO, Fonttable));
Row_8.HorizontalAlignment = Element.ALIGN_LEFT;//靠左
table.AddCell(Row_8);
var Row_9 = new PdfPCell(new Paragraph("MBL SCAC CODE.", Fonttable));
Row_9.HorizontalAlignment = Element.ALIGN_RIGHT;//靠右
table.AddCell(Row_9);
var Row_0 = new PdfPCell(new Paragraph(cARRIERIDList.Where(x => x.Code == masterlist.CARRIERID).Select(x => x.MapCode).FirstOrDefault(), Fonttable));
Row_0.HorizontalAlignment = Element.ALIGN_LEFT;//靠左
table.AddCell(Row_0);
document.Add(table);
string dateText = "DATE PRINTED:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm");
Paragraph dateTexts = new Paragraph(dateText, datefont);
dateTexts.IndentationLeft = 380f;
document.Add(dateTexts);
document.Add(new Paragraph("\r"));//换行
var imgpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logo.png");
Image image = Image.GetInstance(imgpath);
image.ScalePercent(10f);
//设置图片的宽高
image.ScaleAbsolute(180f, 66f);
image.Alignment = Element.ALIGN_CENTER;
//设置图片具体位置 PDF左下角为原点
image.SetAbsolutePosition(400f, 20f);//出现在屏幕左下角 图片左下角做为锚点
document.Add(image);
if ((i + 1) % 4 == 0)
{
document.NewPage();
}
}
}
document.Close();
writer.Close();
return baos.GetBuffer();
}
#endregion
#region 保存模板
public string SaveTemplate(AMS_AddrTemplate dto, User user)
{
string guid = "";
var list = DbBus.Get(DbList.AMSCenter).Select<AMS_AddrTemplate>().Where(w => w.UserID == user.GID && w.TemPlateName == dto.TemPlateName && w.Type == dto.Type && w.GID != dto.GID).ToOne();
if (list != null)
{
return "-1";
}
if (dto.GID.IsNull())
{
AMS_AddrTemplate template = dto.MapTo<AMS_AddrTemplate>();
template.CreateTime = DateTime.Now;
template.LastUpdate = DateTime.Now;
template.GID = Guid.NewGuid().ToString("N");
template.UserID = user.GID;
template.UserName = user.SHOWNAME;
template.CompID = user.CompId;
template.CompName = user.COMNAME;
template.IsDel = false;
DbBus.Get(DbList.AMSCenter).Insert(template).ExecuteAffrows();
guid = template.GID;
}
else
{
AMS_AddrTemplate template = dto.MapTo<AMS_AddrTemplate>();
DbBus.Get(DbList.AMSCenter).Update<AMS_AddrTemplate>().SetSource(template).ExecuteAffrows();
}
return guid;
}
#endregion
#region 获取模板
public List<AMS_AddrTemplate> GetTemplate(User user, string type, string TemPlateName)
{
try
{
var List = DbBus.Get(DbList.AMSCenter).Select<AMS_AddrTemplate>().
Where(x => x.IsDel == false || x.IsDel == null).
Where(x => x.UserID == user.GID).
WhereIf(type != null, x => x.Type == type).
WhereIf(TemPlateName != null, x => TemPlateName.Contains(x.TemPlateName)).
ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
#endregion
#region 删除模板
public void DeleteTemplate(string ids)
{
string[] id = ids.Split(',');
DbBus.Get(DbList.AMSCenter).Transaction(() =>
{
foreach (string oid in id)
{
if (oid != "")
{
DbBus.Get(DbList.AMSCenter).Transaction(() =>
{
DbBus.Get(DbList.AMSCenter).Delete<AMS_AddrTemplate>().Where(w => w.GID == oid).ExecuteAffrows();
});
}
}
});
}
#endregion
public async Task<company_new_param_value> GetSASCCODE(User user)
{
try
{
var List = await DbBus.Get(DbList.djydb).Select<company_new_param_value>().Where(x => x.CompId == user.CompId && x.ParaCode == "AMSSASCCODE").FirstAsync();
return List;
}
catch (Exception e)
{
throw;
}
}
}
}