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.

814 lines
40 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 Common.DJYModel;
using Common.Extensions;
using Common.Tools;
using Common.Utilities;
using djy.IService.Isf;
using djy.Model.Ams;
using djy.Model.Isf;
using djy.Model.IsfDto;
using djy.Service.DjyService;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace djy.Service.Isf
{
public class IsfService : ServBase, IIsfService
{
private readonly IWebHostEnvironment env;
string[] ISF10CompanyTypeCode = new string[] { "CS", "BY", "LG", "MF", "CN", "SE", "ST", "IM" };
string[] ISF5CompanyTypeCode = new string[] { "ST", "BKP" };
public IsfService(IWebHostEnvironment env)
{
this.env = env;
}
#region 查询接口
public TableData Load(ISFQuery req, User user, UserAuthorityDto aut)
{
var result = new TableData();
string[] ReportStates = null;
if (req.ReportState != null)
{
ReportStates = req.ReportState.Split(',');
}
var dto = DbBus.Get(DbList.AMSCenter).Select<ISF_Master>().
Where(x => x.IsDel != true).
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)).
WhereIf(req.InFoType != null, x => x.InFoType == req.InFoType).
WhereIf(req.ReportState != null && req.ReportState != "0" && req.ReportState != "1", x => ReportStates.Contains(x.ReportState)).
WhereIf(req.ReportState == "0", x => x.ReportState == "未申报").
WhereIf(req.ReportState == "1", x => x.ReportState != "未申报").
WhereIf(req.UserName != null, x => x.UserName.Contains(req.UserName.Trim())).
WhereIf(req.BDate != null, x => x.CreateTime >= req.BDate).
WhereIf(req.EDate != null, x => x.CreateTime <= req.EDate).OrderByDescending(x => x.CreateTime);
result.count = dto.ToList().Count();
var list = dto.Page(req.Page, req.Limit).ToList<ISFDto>();
if (list != null)
{
foreach (var item in list)
{
var historyDto = DbBus.Get(DbList.AMSCenter).Select<ISF_MasterHistory>().Where(x => x.ISF_ID == item.GID).OrderByDescending(x => x.SendTime).ToList();
item.HistoryDto = historyDto;
var companylist = DbBus.Get(DbList.AMSCenter).Select<ISF_Company>().Where(x => (x.IsDel == false || x.IsDel == null) && x.PID == item.GID).ToList();
item.companyList = companylist;
}
}
result.data = list;
return result;
}
/// <summary>
/// 获取计费规则
/// </summary>
/// <param name="bstype">业务类型</param>
/// <param name="user">登录人信息</param>
/// <returns>计费规则</returns>
public async Task<Response<CustPriceDto>> GetPrice(string bstype, User user)
{
try
{
if (!int.TryParse(bstype, out int _bstype))
{
return CreateResponse<CustPriceDto>(400, "参数[bstype:业务类型]为空或格式错误");
}
CustPrice custPrice = await DbBus.Get(DbList.djydb).Select<CustPrice>().Where(w => w.BSTYPE == _bstype && w.SENDTYPE == 0 && w.COMNAME == user.COMNAME).ToOneAsync();
if (custPrice == null)
{
return CreateResponse<CustPriceDto>(201, "没有找到此业务的计费规则");
}
CustPriceDto custPriceDto = custPrice.MapTo<CustPriceDto>();
return new Response<CustPriceDto>() { Code = 200, Message = "查询成功", Result = custPriceDto };
}
catch (Exception ex)
{
_LogsAdd("GetPrice", "post", $"ISF_GetPrice接口{ex.Message}");
return CreateResponse<CustPriceDto>(500, ex.Message);
}
}
#endregion
#region 新增编辑
public string SaveInfo(ISFDto dto, User user)
{
string guid = "";
var mlist = DbBus.Get(DbList.AMSCenter).Select<ISF_Master>().Where(x => x.IsDel != true && x.MBLNO == dto.MBLNO && x.GID != dto.GID && x.MBLNO != "").ToOne();
if (mlist != null)
{
return "-1";
}
if (dto.GID.IsNull())
{
DbBus.Get(DbList.AMSCenter).Transaction(() =>
{
ISF_Master master = dto.MapTo<ISF_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 = "未申报";
master.NewNotice = "新增";
DbBus.Get(DbList.AMSCenter).Insert(master).ExecuteAffrows();
ISF_MasterHistory history = new ISF_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.ISF_ID = master.GID;
history.SendTime = DateTime.Now;///
history.State = "新增";
history.Type = "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();
if (dto.companyList != null && dto.companyList.Count() > 0)
{
foreach (var item in dto.companyList)
{
ISF_Company company = item.MapTo<ISF_Company>();
company.GID = Guid.NewGuid().ToString("N");
company.PID = master.GID;
company.IsDel = false;
company.State = "0";
DbBus.Get(DbList.AMSCenter).Insert(company).ExecuteAffrows();
}
}
guid = master.GID;
});
return guid;
}
else
{
DbBus.Get(DbList.AMSCenter).Transaction(() =>
{
ISF_Master master = DbBus.Get(DbList.AMSCenter).Select<ISF_Master>().Where(x => x.GID == dto.GID).ToOne();
master.MBLNO = dto.MBLNO;
master.ShipMasterBillNo = dto.ShipMasterBillNo;
master.InFoType = dto.InFoType;
master.DischargeHarbourCode = dto.DischargeHarbourCode;
master.DischargeHarbourName = dto.DischargeHarbourName;
master.DeliveryHarbourCode = dto.DeliveryHarbourCode;
master.DeliveryHarbourName = dto.DeliveryHarbourName;
master.ShipmentTypeCode = dto.ShipmentTypeCode;
master.ShipmentTypeName = dto.ShipmentTypeName;
master.HstCode = dto.HstCode;
master.BlTypeCode = dto.BlTypeCode;
master.BlTypeName = dto.BlTypeName;
master.NewNotice = "修改";
master.LastUpdate = DateTime.Now;
master.BondOwnCode = dto.BondOwnCode;
DbBus.Get(DbList.AMSCenter).Update<ISF_Master>().SetSource(master).ExecuteAffrows();
DbBus.Get(DbList.AMSCenter).Delete<ISF_Company>().Where(w => w.PID == master.GID).ExecuteAffrows();
//ISF_MasterHistory history = new ISF_MasterHistory();
//history.GID = Guid.NewGuid().ToString("N");
//history.ISF_ID = master.GID;
//history.SendTime = DateTime.Now;
//history.State = "修改";
//history.Type = "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();
if (dto.companyList != null && dto.companyList.Count() > 0)
{
if (dto.InFoType == "1")
{
dto.companyList = dto.companyList.Where(x => ISF5CompanyTypeCode.Contains(x.CompanyType)).ToList();
}
else if (dto.InFoType == "2")
{
dto.companyList = dto.companyList.Where(x => ISF10CompanyTypeCode.Contains(x.CompanyType)).ToList();
}
foreach (var item in dto.companyList)
{
ISF_Company companylist = item.MapTo<ISF_Company>();
companylist.GID = Guid.NewGuid().ToString("N");
companylist.PID = master.GID;
companylist.IsDel = false;
companylist.State = "0";
DbBus.Get(DbList.AMSCenter).Insert(companylist).ExecuteAffrows();
}
}
guid = master.GID;
});
return guid;
}
}
#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(() =>
{
ISF_MasterHistory history = new ISF_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.ISF_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<ISF_Master>().Set(w => w.IsDel, true).Where(w => w.GID == oid).ExecuteAffrows();
DbBus.Get(DbList.AMSCenter).Update<ISF_Company>().Set(w => w.IsDel, true).Where(w => w.PID == oid).ExecuteAffrows();
});
}
}
});
}
#endregion
#region 获取模板
public List<ISF_CompanyTemplate> GetTemplate(User user, string CompanyType, string InFoType, string TemPlateName)
{
try
{
var List = DbBus.Get(DbList.AMSCenter).Select<ISF_CompanyTemplate>().
Where(x => x.IsDel == false || x.IsDel == null).
Where(x => x.UserID == user.GID).
WhereIf(CompanyType != null, x => x.CompanyType == CompanyType).
WhereIf(InFoType != null, x => x.InFoType == InFoType).
WhereIf(TemPlateName != null, x => x.TemPlateName.Contains(TemPlateName)).
ToList();
return List;
}
catch (Exception e)
{
throw;
}
}
#endregion
#region 保存模板
public string SaveTemplate(ISF_CompanyTemplate dto, User user)
{
string guid = "";
var list = DbBus.Get(DbList.AMSCenter).Select<ISF_CompanyTemplate>().Where(w => w.UserID == user.GID && w.TemPlateName == dto.TemPlateName && w.CompanyType == dto.CompanyType && w.InFoType == dto.InFoType && w.GID != dto.GID).ToOne();
if (list != null)
{
return "-1";
}
if (dto.GID.IsNull())
{
ISF_CompanyTemplate template = dto.MapTo<ISF_CompanyTemplate>();
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;
return guid;
}
else
{
ISF_CompanyTemplate template = dto.MapTo<ISF_CompanyTemplate>();
var i = DbBus.Get(DbList.AMSCenter).Update<ISF_CompanyTemplate>().SetSource(template).ExecuteAffrows();
return i.ToString();
}
}
#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<ISF_CompanyTemplate>().Where(w => w.GID == oid).ExecuteAffrows();
});
}
}
});
}
#endregion
#region 第三方接口
/// <param name="msgType">类型(1.原始 2.修改 3.删除 4.重发)</param>
public async Task<Response> SendDE(string Gid, User user, string msgType)
{
Response req = new Response();
try
{
string[] id = Gid.Split(',');
foreach (string oid in id)
{
if (oid != "")
{
var fin = new FinanceService();
var master = DbBus.Get(DbList.AMSCenter).Select<ISF_Master>().Where(x => (x.IsDel == false || x.IsDel == null) && x.CompID == user.CompId && x.GID == oid).ToOne();
if (master == null)
{
req.Code = 201;
req.Message = "未检索到此单据,可能没有发送权限,请切换相关账号后重试";
return req;
}
var comlist = DbBus.Get(DbList.AMSCenter).Select<ISF_Company>().Where(x => (x.IsDel == false || x.IsDel == null) && x.PID == oid).ToList();
//if (msgType == "4" && (master.MateState == "海关删除" || master.MateState != "S1" || master.MateState != "02" || master.MateState != "01"))
//{
// req.Code = 201;
// req.Message = "当前状态不能重发!如有疑问,请联系相关客服!";
// return req;
//}
if (msgType == "4" && (master.NewNotice is not ("删除发送" or "01" or "SB" or "S2" or "S3" or "S4" or "S5" or "S6")))
{
req.Code = 201;
req.Message = "当前状态不能重发!如有疑问,请联系相关客服!";
return req;
}
if (master.ReportState == "删单成功" && msgType == "3")
{
req.Code = 201;
req.Message = "已删除单据不可以再次删除";
return req;
}
var gethtml = "";
if (msgType != "3")
{
if (msgType == "1" && master.NewNotice == "新增发送")
{
req.Code = 201;
req.Message = "当前单据已经发送,不能再次发送!如有疑问,请联系相关客服!";
return req;
}
BondOwnTypeEnum? bondOwnType = master.BondOwnCode switch
{
"1" => BondOwnTypeEnum.OWN,
"2" => BondOwnTypeEnum.CargoEDI,
_ => null
};
if (msgType == "1" || msgType == "4")
{
///扣费接口
var getfinrs = fin.Expend(new CustFee
{
SENDUSERID = user.GID,
LURURENID = user.GID,
CtnrCount = 1,
CtnrInfo = string.Empty,
BSTYPE = 16,
SENDTYPE = 0,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}
, 0, bondOwnType);
if (!getfinrs.Status)
{
req.Code = 201;
req.Message = getfinrs.Message;
return req;
}
}
var portList = DbBus.Get(DbList.Common).Select<CodePort>().ToList();
var CodePortLoadList = DbBus.Get(DbList.Common).Select<CodePortLoad>().ToList();
Info info = new Info();
info.masterBillNo = master.MBLNO;
info.shipMasterBillNo = master.ShipMasterBillNo;
info.infoType = master.InFoType;
info.dischargeHarbourCode = portList.Where(x => x.Code == master.DischargeHarbourCode).Select(x => x.EdiCode).FirstOrDefault();
info.deliveryHarbourCode = portList.Where(x => x.Code == master.DeliveryHarbourCode).Select(x => x.EdiCode).FirstOrDefault();
info.shipmentTypeCode = master.ShipmentTypeCode;
info.hstCode = master.HstCode;
info.blTypeCode = master.BlTypeCode;
info.refId = master.GID;
// 只在ISF-10且使用CargoEDI的BOND时才传bondOwnCode、bondTypeCode
if (master.InFoType == "2" && bondOwnType == BondOwnTypeEnum.CargoEDI)
{
info.bondOwnCode = "2";
info.bondTypeCode = "03";
}
List<CompanyList> companyList = new List<CompanyList>();
foreach (var item in comlist)
{
companyList.Add(new CompanyList
{
companyType = item.CompanyType,
companyName = item.CompanyName,
idTypeCode = item.IdTypeCode,
companyId = item.CompanyId,
address = item.Address,
city = item.City.Trim(),
province = item.Province,
provinceCode = item.ProvinceCode,
countryCode = item.CountryCode,
postcode = item.PostCode,
hstCode = item.CompanyType != "MF" ? item.HstCode : master.HstCode,
});
}
var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var Account = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "ISFAccount").ToOne();
var method = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "ISFMethod").ToOne();
var key = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "ISFKEY").ToOne();
var url = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "AMSURL").ToOne();
/////MD5加密
string stringSign = string.Format("{0}{1}{2}", Account.PARAMVALUE, key.PARAMVALUE, timestamp);
string sign = stringSign.ToMd5();
///post参数
IsfInfo isfinfo = new IsfInfo();
isfinfo.companyList = companyList;
isfinfo.format = "json";
isfinfo.info = info;
isfinfo.method = method.PARAMVALUE;
isfinfo.msgType = Convert.ToInt32(msgType);
isfinfo.user_id = Account.PARAMVALUE;
isfinfo.sign = sign;
isfinfo.timestamp = timestamp;
isfinfo.version = "1.0";
string json = JsonConvert.SerializeObject(isfinfo);
_LogsAdd("SendDE", "post", $"ISF接口调用发送{oid}{json}");
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("user_id", Account.PARAMVALUE);
dic.Add("method", method.PARAMVALUE);
dic.Add("format", "json");
dic.Add("sign", sign);
dic.Add("timestamp", timestamp);
dic.Add("version", "1.0");
dic.Add("data", json.ToUrlEncodeString());
//测试用
//if (env.IsDevelopment() || env.IsStaging())
//{
// var gethtmlTestObj = new { code = "T", msg = "成功", data = new { code = "1", msg = "成功" } };
// gethtml = JsonConvert.SerializeObject(gethtmlTestObj);
// _LogsAdd("SendDE", "post", $"ISF接口调用返回{oid}{gethtml}(当前所处环境为开发或测试环境,直接返回成功)");
//}
//else
//{
// gethtml = await HttpHelp.Post(dic, url.PARAMVALUE, PsotType.Urlencoded);
// _LogsAdd("SendDE", "post", $"ISF接口调用返回{oid}{gethtml}");
//}
gethtml = await HttpHelp.Post(dic, url.PARAMVALUE, PsotType.Urlencoded);
//gethtml = "";
_LogsAdd("SendDE", "post", $"ISF接口调用返回{oid}{gethtml}");
}
else
{
var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var Account = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "ISFAccount").ToOne();
var method = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "ISFDeleteMethod").ToOne();
var key = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "ISFKEY").ToOne();
var url = DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "AMSURL").ToOne();
/////MD5加密
string stringSign = string.Format("{0}{1}{2}", Account.PARAMVALUE, key.PARAMVALUE, timestamp);
string sign = stringSign.ToMd5();
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("user_id", Account.PARAMVALUE);
dic.Add("method", method.PARAMVALUE);
dic.Add("format", "json");
dic.Add("sign", sign);
dic.Add("timestamp", timestamp);
dic.Add("version", "1.0");
dic.Add("refId", oid);
//测试用
//if (env.IsDevelopment() || env.IsStaging())
//{
// var gethtmlTestObj = new { code = "T", msg = "成功", data = new { code = "1", msg = "成功" } };
// gethtml = JsonConvert.SerializeObject(gethtmlTestObj);
// _LogsAdd("SendDE", "post", $"ISF接口调用返回{oid}{gethtml}(当前所处环境为开发或测试环境,直接返回成功)");
//}
//else
//{
// gethtml = await HttpHelp.Post(dic, url.PARAMVALUE, PsotType.Urlencoded);
// _LogsAdd("SendDE", "post", $"ISF接口调用返回{oid}{gethtml}");
//}
gethtml = await HttpHelp.Post(dic, url.PARAMVALUE, PsotType.Urlencoded);
//gethtml = "";
_LogsAdd("SendDE", "post", $"ISF接口调用返回{oid}{gethtml}");
}
if (gethtml != null)
{
JObject rlt = JObject.Parse(gethtml);
var code = rlt.GetValue("code").ToString();
var msg = rlt.GetValue("msg").ToString();
if (code == "F")
{
ISF_MasterHistory history = new ISF_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.ISF_ID = oid;
history.SendTime = DateTime.Now;
history.Type = "0";
if (msgType == "1")
{
history.State = "新增发送失败";
}
else if (msgType == "4")
{
history.State = "重发失败";
}
else if (msgType == "2")
{
history.State = "修改发送失败";
}
else
{
history.State = "删除发送失败";
}
history.Operator = user.SHOWNAME;
history.Remark = $"{user.SHOWNAME}于{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}{history.State}失败,失败原因:{msg} ";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
req.Code = 201;
req.Message = "操作失败," + msg;
return req;
}
if (code == "T")
{
ISF_MasterHistory history = new ISF_MasterHistory();
var data = rlt.GetValue("data").ToString();
JObject drlt = JObject.Parse(data);
var result = drlt.GetValue("code").ToString();
if (result != "1")
{
var errorInfo = drlt.GetValue("msg").ToString();
history.GID = Guid.NewGuid().ToString("N");
history.ISF_ID = oid;
history.SendTime = DateTime.Now;
history.Type = "0";
if (msgType == "1")
{
history.State = "新增发送失败";
}
else if (msgType == "4")
{
history.State = "重发失败";
}
else if (msgType == "2")
{
history.State = "修改发送失败";
}
else
{
history.State = "删除发送失败";
}
history.Operator = user.SHOWNAME;
history.Remark = $"{user.SHOWNAME}于{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}{history.State}失败,失败原因:{errorInfo} ";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
req.Code = 201;
req.Message = "操作失败," + msg + errorInfo;
return req;
}
history.GID = Guid.NewGuid().ToString("N");
history.ISF_ID = oid;
history.SendTime = DateTime.Now;
history.Type = "0";
if (msgType == "1")
{
history.State = "新增发送成功";
}
else if (msgType == "4")
{
history.State = "重发成功";
}
else if (msgType == "2")
{
history.State = "修改发送成功";
}
else
{
history.State = "删除发送成功";
}
history.Operator = user.SHOWNAME;
history.Remark = $"{user.SHOWNAME}于{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}{history.State}";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
if (msgType == "1")
{
BondOwnTypeEnum? bondOwnType = master.BondOwnCode switch
{
"1" => BondOwnTypeEnum.OWN,
"2" => BondOwnTypeEnum.CargoEDI,
_ => null
};
var getfinrs = fin.Expend(new CustFee
{
SENDUSERID = user.GID,
LURURENID = user.GID,
CtnrCount = 1,
CtnrInfo = string.Empty,
BSTYPE = 16,
SENDTYPE = 0,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}
, 1, bondOwnType);
DbBus.Get(DbList.AMSCenter).Update<ISF_Master>().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "新增发送" }).Where(w => w.GID == oid).ExecuteAffrows();
}
else if (msgType == "4")
{
var getfinrs = fin.Expend(new CustFee
{
SENDUSERID = user.GID,
LURURENID = user.GID,
CtnrCount = 1,
CtnrInfo = string.Empty,
BSTYPE = 16,
SENDTYPE = 0,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}
, 1);
DbBus.Get(DbList.AMSCenter).Update<ISF_Master>().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "重发发送" }).Where(w => w.GID == oid).ExecuteAffrows();
}
else if (msgType == "2")
{
DbBus.Get(DbList.AMSCenter).Update<ISF_Master>().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "修改发送" }).Where(w => w.GID == oid).ExecuteAffrows();
}
else
{
DbBus.Get(DbList.AMSCenter).Update<ISF_Master>().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "删除发送" }).Where(w => w.GID == oid).ExecuteAffrows();
}
}
}
}
}
return req;
}
catch (Exception ex)
{
req.Code = 500;
req.Message = ex.InnerException?.Message ?? ex.Message;
_LogsAdd("SendDE", "post", $"ISF_SendDE接口{req.Message}");
return req;
}
}
public Response SaveReceipt(string msg)
{
_LogsAdd("ISFReceipt", "post", $"ISF接口推送{msg}");
Response req = new Response();
try
{
if (msg != null)
{
ISFReceipt retdto = Json.JsonToObject<ISFReceipt>(msg);
var master = DbBus.Get(DbList.AMSCenter).Select<ISF_Master>().Where(x => x.GID == retdto.businessId).ToOne();
if (retdto.status == "S1")
{
ISF_MasterHistory history = new ISF_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.ISF_ID = master.GID;
history.SendTime = DateTime.Now;
history.State = "ISF和AMS匹配";
history.Type = "1";
history.Operator = "系统管理员";
history.Remark = "您的明细单据" + retdto.businessId + "于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "ISF和AMS匹配";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
DbBus.Get(DbList.AMSCenter).Update<ISF_Master>().Set(w => new ISF_Master { MateState = retdto.status }).Where(w => w.GID == master.GID).ExecuteAffrows();
}
else if (retdto.status == "02")
{
ISF_MasterHistory history = new ISF_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.ISF_ID = master.GID;
history.SendTime = DateTime.Now;
history.State = "海关已接受";
history.Type = "1";
history.Operator = "系统管理员";
history.Remark = "您的单据于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "海关已接受";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
if (retdto.content.IndexOf("DELETED") != -1)
{
DbBus.Get(DbList.AMSCenter).Update<ISF_Master>().Set(w => new ISF_Master { MateState = "海关删除" }).Where(w => w.GID == master.GID).ExecuteAffrows();
}
else
{
DbBus.Get(DbList.AMSCenter).Update<ISF_Master>().Set(w => new ISF_Master { MateState = retdto.status }).Where(w => w.GID == master.GID).ExecuteAffrows();
}
}
else if (retdto.status == "01")
{
ISF_MasterHistory history = new ISF_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.ISF_ID = master.GID;
history.SendTime = DateTime.Now;
history.State = "海关拒绝";
history.Type = "1";
history.Operator = "系统管理员";
history.Remark = "您的单据于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "海关拒绝";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
DbBus.Get(DbList.AMSCenter).Update<ISF_Master>().Set(w => new ISF_Master { MateState = retdto.status }).Where(w => w.GID == master.GID).ExecuteAffrows();
}
else if (retdto.status == "SB" || retdto.status == "S2" || retdto.status == "S3" || retdto.status == "S4" || retdto.status == "S5" || retdto.status == "S6")
{
ISF_MasterHistory history = new ISF_MasterHistory();
history.GID = Guid.NewGuid().ToString("N");
history.ISF_ID = master.GID;
history.SendTime = DateTime.Now;
history.State = "未匹配AMS";
history.Type = "1";
history.Operator = "系统管理员";
history.Remark = "您的单据于" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "未匹配AMS";
DbBus.Get(DbList.AMSCenter).Insert(history).ExecuteAffrows();
DbBus.Get(DbList.AMSCenter).Update<ISF_Master>().Set(w => new ISF_Master { MateState = retdto.status }).Where(w => w.GID == master.GID).ExecuteAffrows();
}
}
else
{
req.Code = 200;
req.Message = "未收到参数";
return req;
}
}
catch (Exception ex)
{
req.Code = 500;
req.Message = ex.InnerException?.Message ?? ex.Message;
_LogsAdd("SendDE", "post", $"AMS_SaveReceipt接口{req.Message}");
return req;
}
req.Code = 200;
req.Message = "请求成功";
return req;
}
#endregion
}
}