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.
388 lines
19 KiB
C#
388 lines
19 KiB
C#
using djy.Paas.IService;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Dapper;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using Common;
|
|
using djy.Model.Ams;
|
|
using Common.DjyService;
|
|
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;
|
|
|
|
namespace djy.Service.Ams
|
|
{
|
|
/// <summary>
|
|
/// AMS
|
|
/// </summary>
|
|
public class AmsService : ServBase, IAmsService
|
|
{
|
|
public TableData Load(AMSQuery req, string userid)
|
|
{
|
|
var result = new TableData();
|
|
var user = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == userid).ToOne();
|
|
var dto = DbBus.Get(DbList.AMSCenter).Select<AMS_Master>().Where(x => (x.IsDel == false || x.IsDel == null) && x.CompID == user.CompId)
|
|
.WhereIf(req.MBLNO != null, x => x.MBLNO == req.MBLNO).WhereIf(req.ReportState != null, x => x.ReportState == req.ReportState);
|
|
result.count = dto.ToList().Count();
|
|
var list = dto.Page(req.Page, req.Limit).ToList<AMSDto>();
|
|
if (list != null)
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
var historyDto= DbBus.Get(DbList.AMSCenter).Select<AMS_MasterHistory>().Where(x => x.AM_ID == item.GID).ToList();
|
|
item.HistoryDto = historyDto;
|
|
var hodto = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => (x.IsDel == false || x.IsDel == null) && x.PID == item.GID).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 == false || x.IsDel == null) && x.HID == it.GID).ToList();
|
|
it.CntrnoDto = cnt;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
result.data = list;
|
|
return result;
|
|
}
|
|
|
|
public void Delete(string ids,string userid)
|
|
{
|
|
var user = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == userid).ToOne();
|
|
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 = "删除";
|
|
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();
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public void SaveInfo(AMSDto dto, string userid)
|
|
{
|
|
var user = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == userid).ToOne();
|
|
if (dto.GID.IsNull())
|
|
{
|
|
|
|
|
|
DbBus.Get(DbList.AMSCenter).Transaction(() =>
|
|
{
|
|
AMS_Master master = dto.MapTo<AMS_Master>();
|
|
master.CreateTime = DateTime.Now;
|
|
master.LastUpdate = DateTime.Now;
|
|
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.ReportState = "未申报";
|
|
DbBus.Get(DbList.AMSCenter).Insert(master).ExecuteAffrows();
|
|
AMS_MasterHistory history = new AMS_MasterHistory();
|
|
history.GID = Guid.NewGuid().ToString("N");
|
|
history.AM_ID = master.GID;
|
|
history.SendTime = DateTime.Now;///
|
|
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 (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;
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{
|
|
DbBus.Get(DbList.AMSCenter).Transaction(() =>
|
|
{
|
|
AMS_Master master = dto.MapTo<AMS_Master>();
|
|
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();
|
|
AMS_MasterHistory history = new AMS_MasterHistory();
|
|
history.GID = Guid.NewGuid().ToString("N");
|
|
history.AM_ID = master.GID;
|
|
history.SendTime = DateTime.Now;///
|
|
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 (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;
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public List<CommonCodeValue> GetCountry()
|
|
{
|
|
try
|
|
{
|
|
var List = DbBus.Get(DbList.AMSCenter).Select<AMS_SysCountry>().ToList<CommonCodeValue>();
|
|
return List;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
public List<CommonCodeValue> GetCARRIER()
|
|
{
|
|
try
|
|
{
|
|
var List = DbBus.Get(DbList.AMSCenter).Select<AMS_SysCARRIER>().ToList<CommonCodeValue>();
|
|
return List;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public List<CommonCodeValue> GetCTNALL()
|
|
{
|
|
try
|
|
{
|
|
var List = DbBus.Get(DbList.AMSCenter).Select<AMS_SysCTNALL>().ToList<CommonCodeValue>();
|
|
return List;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public List<CommonCodeValue> GetKINDPKGS()
|
|
{
|
|
try
|
|
{
|
|
var List = DbBus.Get(DbList.AMSCenter).Select<AMS_SysKINDPKGS>().ToList<CommonCodeValue>();
|
|
return List;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public List<AMS_SysDangerousGoods> GetDangerousGoods()
|
|
{
|
|
try
|
|
{
|
|
var List = DbBus.Get(DbList.AMSCenter).Select<AMS_SysDangerousGoods>().ToList();
|
|
return List;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async void SendDE(string Gid, string userid)
|
|
{
|
|
var result = new Response();
|
|
try
|
|
{
|
|
string[] id = Gid.Split(',');
|
|
foreach (string oid in id)
|
|
{
|
|
if (oid != "")
|
|
{
|
|
MasterBillInfoDto dto = new MasterBillInfoDto();
|
|
masterBillInfo masterBillInfo = new masterBillInfo();
|
|
var user = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == userid).ToOne();
|
|
var master = DbBus.Get(DbList.AMSCenter).Select<AMS_Master>().Where(x => (x.IsDel == false || x.IsDel == null) && x.CompID == user.CompId && x.GID == oid).ToOne();
|
|
|
|
masterBillInfo.masterBillNo = master.MBLNO;
|
|
masterBillInfo.shipCompany = master.CARRIERID;
|
|
masterBillInfo.vessel = master.VESSEL;
|
|
masterBillInfo.voyage = master.VOYNO;
|
|
masterBillInfo.requesterDea = sysOptionConfig.Webconfig.requesterDea;
|
|
masterBillInfo.consignmentType = master.ConsignmentType;
|
|
masterBillInfo.loadHarbour = master.LoadingPort;
|
|
masterBillInfo.loadHarbourCode = master.LoadingPortCode;
|
|
masterBillInfo.dischargeHarbour = master.PORTDISCHARGE;
|
|
masterBillInfo.dischargeHarbourCode = master.PORTDISCHARGECode;
|
|
masterBillInfo.lastForeignHarbour = master.LastNoUsPort;
|
|
masterBillInfo.lastForeignHarbourCode = master.LastNoUsPortCode;
|
|
masterBillInfo.loadDate = master.ETA.ToString("yyyy-MM-dd hh:mm:ss");
|
|
masterBillInfo.estimatedArrivalTime = master.ETD.ToString("yyyy-MM-dd hh:mm:ss");
|
|
masterBillInfo.filingType = master.ShippingType;
|
|
dto.masterBillInfo = masterBillInfo;
|
|
var hodto = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => (x.IsDel == false || x.IsDel == null) && x.PID == master.GID).ToList<AMS_HouseDto>();
|
|
List<HouseBillInfoListItem> houseBillInfoListItems = new List<HouseBillInfoListItem>();
|
|
foreach (var item in hodto)
|
|
{
|
|
HouseBillInfoListItem houseinfo = new HouseBillInfoListItem();
|
|
houseinfo.businessId = item.GID;
|
|
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.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 = it.KINDPKGS;
|
|
insertList.packingCode = it.KINDPKGSCode;
|
|
insertList.shippingMark = it.MARKS;
|
|
insertList.unCode = it.DUNNO;
|
|
insertList.dangerGrade = it.DangerGrade;
|
|
list.Add(insertList);
|
|
|
|
|
|
|
|
CtnInfo.insertList = list;
|
|
houseinfo.ctnInfo = CtnInfo;
|
|
houseBillInfoListItems.Add(houseinfo);
|
|
}
|
|
}
|
|
dto.houseBillInfoList = houseBillInfoListItems;
|
|
var data = JsonConvert.SerializeObject(dto);
|
|
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();
|
|
//string stringSign = string.Format("format=json&method=cargoedi.demessage.msgrec.post×tamp={0}&user_id={1}&version=2.0&key={2}",
|
|
// DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss").ToUrlEncodeString(), AMSAccount.PARAMVALUE, key.PARAMVALUE);
|
|
|
|
|
|
//string sign = stringSign.ToMd5().ToUpper();
|
|
AMSDocContent aMSDoc = new AMSDocContent();
|
|
aMSDoc.fromdea = "n";
|
|
aMSDoc.todea = "n";
|
|
aMSDoc.editype = "AMSDOC";
|
|
aMSDoc.port = "Ningbo";
|
|
aMSDoc.masterBillInfo = dto;
|
|
var jobj = JsonConvert.SerializeObject(aMSDoc);
|
|
|
|
string stringSign = string.Format("channel=WSTOM&deaId=n&destDeaId=n&docContent={0}&docLength={1}&docName={2}&format=json&method={3}×tamp={4}&user_id={5}&version=2.0&key={6}",
|
|
jobj.ToString(), jobj.ToString().Length, DateTime.Now.ToString("yyyyMMdd") + GenerateRandomNo(), method.PARAMVALUE,
|
|
HttpUtility.UrlEncode(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Encoding.UTF8),
|
|
AMSAccount.PARAMVALUE, key.PARAMVALUE);
|
|
|
|
string sign = stringSign.ToMd5().ToUpper();
|
|
|
|
string json = string.Format("port=Ningbo&docContent={0}&method={1}&channel=WSTOM&docName={2}&user_id={3}&docType=AMSDOC×tamp={4}" +
|
|
"&format=json&destDeaId=n&deaId=n&sign={5}&docLength={6}",
|
|
jobj.ToString().ToBase64(), method.PARAMVALUE, DateTime.Now.ToString("yyyyMMdd") + GenerateRandomNo(),
|
|
AMSAccount.PARAMVALUE, HttpUtility.UrlEncode(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Encoding.UTF8),
|
|
sign, jobj.ToString().Length);
|
|
await HttpHelp.Post(json, url.PARAMVALUE, PsotType.Urlencoded);
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
|
|
}
|
|
|
|
public string GenerateRandomNo()
|
|
{
|
|
int _min = 000000;
|
|
int _max = 999999;
|
|
Random _rdm = new Random();
|
|
return _rdm.Next(_min, _max).ToString();
|
|
}
|
|
}
|
|
}
|