YingHang
hanxuntao 9 months ago
parent 75898d3f6e
commit f2f39c8fc5

@ -537,7 +537,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_Payapplication
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.PORTLOAD,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE,b.FORWARDER");
strSql.Append(",b.DOC,b.SALE,(select top 1 INVNO from ch_fee_invoicehexiao where EXISTS (SELECT 1 FROM ch_fee_do_invoice WHERE ch_fee_do_invoice.BILLNO=ch_fee_invoicehexiao.BILLNO AND FEEID=c.FEEID)) INVOICENO ");
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME,0 TTLNODR ");
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME,0 TTLNODR,0 TTLPR ");
strSql.Append(",f.UNIT UNIT,f.ISOPEN ");
strSql.Append(" FROM ch_fee_do c");
strSql.Append(" join v_op_bill b on (b.bsno=c.bsno)");
@ -565,12 +565,56 @@ namespace DSWeb.Areas.Account.DAL.Chfee_Payapplication
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.PORTLOAD,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE,b.FORWARDER");
strSql.Append(",b.DOC,b.SALE,(select top 1 INVNO from ch_fee_invoicehexiao where EXISTS (SELECT 1 FROM ch_fee_do_invoice WHERE ch_fee_do_invoice.BILLNO=ch_fee_invoicehexiao.BILLNO AND FEEID=c.FEEID)) INVOICENO ");
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME,0 TTLNODR ");
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME,0 TTLNODR,0 TTLPR ");
strSql.Append(",f.UNIT UNIT,f.ISOPEN ");
strSql.Append(" FROM ch_fee_do c");
strSql.Append(" join v_op_bill b on (b.bsno=c.bsno)");
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
sortstring = sortstring.Replace("FEEOBJNAME", "f.CUSTOMERNAME");
sortstring = sortstring.Replace("FEENAME", "C.FEENAME");
sortstring = sortstring.Replace("AMOUNT", "C.AMOUNT");
sortstring = sortstring.Replace("MBLNO", "B.MBLNO");
sortstring = sortstring.Replace("CUSTNO", "B.CUSTNO");
sortstring = sortstring.Replace("CUSTOMERNAME", "B.CUSTOMERNAME");
strSql.Append(" order by " + sortstring + ",C.CREATETIME");
}
else
{
strSql.Append(" order by C.CREATETIME,b.ETD,b.MBLNO ");
}
return BodySetData(strSql);
}
static public List<Chfee_do_detail> GetBodyBsAllList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT c.GID,c.BSNO,c.FEEID,c.FEENAME,c.CURRENCY,c.AMOUNT,c.DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,ISNULL(c.ORIGSTLAMOUNT,0) AS ORIGSTLAMOUNT,c.EXCHANGERATE ");
strSql.Append(",c.FEETYPE,f.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,f.EXCHANGERATE ORIGEXCHANGERATE,f.ACCTAXRATE");
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO,b.CUSTOMNO,(CASE b.BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF");
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.PORTLOAD,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE,b.FORWARDER");
strSql.Append(",b.DOC,b.SALE,(select top 1 INVNO from ch_fee_invoicehexiao where EXISTS (SELECT 1 FROM ch_fee_do_invoice WHERE ch_fee_do_invoice.BILLNO=ch_fee_invoicehexiao.BILLNO AND FEEID=c.FEEID)) INVOICENO ");
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME,0 TTLNODR,(g.TTLDR-g.TTLCR) TTLPR ");
strSql.Append(",f.UNIT UNIT,f.ISOPEN ");
strSql.Append(" FROM ch_fee_do c");
strSql.Append(" join v_op_bill b on (b.bsno=c.bsno)");
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
strSql.Append(" join v_op_gain_sum g on (g.bsno=c.bsno)");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
@ -640,7 +684,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_Payapplication
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.PORTLOAD,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE,b.FORWARDER");
strSql.Append(",b.DOC,b.SALE,(select top 1 INVNO from ch_fee_invoicehexiao where EXISTS (SELECT 1 FROM ch_fee_do_invoice WHERE ch_fee_do_invoice.BILLNO=ch_fee_invoicehexiao.BILLNO AND FEEID=c.FEEID)) INVOICENO ");
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME,0 TTLNODR ");
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME,0 TTLNODR,0 TTLPR ");
strSql.Append(",f.UNIT UNIT,f.ISOPEN ");
strSql.Append(" FROM ch_fee_do c");
strSql.Append(" join v_op_bill b on (b.bsno=c.bsno)");
@ -874,7 +918,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_Payapplication
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.PORTLOAD,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE,b.FORWARDER");
strSql.Append(",b.DOC,b.SALE,(select top 1 INVNO from ch_fee_invoicehexiao where EXISTS (SELECT 1 FROM ch_fee_do_invoice WHERE ch_fee_do_invoice.BILLNO=ch_fee_invoicehexiao.BILLNO AND FEEID=c.FEEID)) INVOICENO ");
strSql.Append(",f.Remark Remark,f.INPUTMODE,(g.TTLDR-g.STLTTLDR) TTLNODR ");
strSql.Append(",f.Remark Remark,f.INPUTMODE,(g.TTLDR-g.STLTTLDR) TTLNODR,0 TTLPR ");
strSql.Append(",f.UNIT UNIT,f.ISOPEN ");
strSql.Append(" FROM ch_fee_do c");
strSql.Append(" join v_op_bill b on (b.bsno=c.bsno)");
@ -960,6 +1004,8 @@ namespace DSWeb.Areas.Account.DAL.Chfee_Payapplication
data.ENTERP = Convert.ToString(reader["ENTERP"]);
if (reader["TTLNODR"] != DBNull.Value)
data.TTLNODR = Convert.ToDecimal(reader["TTLNODR"]);
if (reader["TTLPR"] != DBNull.Value)
data.TTLPR = Convert.ToDecimal(reader["TTLPR"]);
data.BSTYPE = Convert.ToString(reader["BSTYPE"]);
data.FORWARDER = Convert.ToString(reader["FORWARDER"]);
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);

@ -307,6 +307,7 @@ namespace DSWeb.Areas.Account.Models.Chfee_do_detail
public string SALEDEPT { get; set; }
public decimal ACCTAXRATE { get; set; }
public decimal TTLNODR { get; set; }
public decimal TTLPR { get; set; }
public string PAYFEEDOID
{
get { return _payfeedoid; }

@ -234,14 +234,14 @@ namespace DSWeb.Areas.Dispatch.Helper
var user = BasicDataRefDAL.GetUserLinkRef("u.DingTalkAccount='" + DingCallBackInfo.staffId + "'");
if (!string.IsNullOrEmpty(user.GID))
{
result = ChpayapplicationDAL.AuditList(Payapplist, user.GID);
result = ChpayapplicationDAL.AuditBackList(Payapplist, user.GID, "钉钉");
}
else
{
var RECEIVER = WorkFlowDAL.GetAuditor(WorkFlowID, "1");
if (RECEIVER != null && RECEIVER.Count != 0)
{
result = ChpayapplicationDAL.AuditBackList(Payapplist, RECEIVER[0].GID, "");
result = ChpayapplicationDAL.AuditBackList(Payapplist, RECEIVER[0].GID,"钉钉");
}
}

@ -914,7 +914,24 @@ namespace DSWeb.MvcShipping.DAL.MsOpSeaeEdiPortDAL
}
return EDICODE;
}
static public string GetVesselFlag(string VESSEL)
{
string EDICODE = "";
var strSql2 = new StringBuilder();
strSql2.Append("select SHIPFLAG from code_vessel where VESSEL='" + VESSEL + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql2.ToString()))
{
while (reader.Read())
{
EDICODE = Convert.ToString(reader["SHIPFLAG"]).Trim();
}
reader.Close();
}
return EDICODE;
}
static public string GetCustEDICode(string CUST, string EDINAME)
{
@ -21996,7 +22013,7 @@ namespace DSWeb.MvcShipping.DAL.MsOpSeaeEdiPortDAL
r.WriteLine("10"
+ ":" + GetVesselEDICode(bill.VESSEL, typeIFCSUM) //2
+ ":" + bill.VESSEL//3
+ ":"//4 舶国籍代码
+ ":"+ GetVesselFlag(bill.VESSEL)
+ ":" + bill.VOYNO//5
+ ":"//6航线代码
+ ":"//7航线
@ -22040,7 +22057,7 @@ namespace DSWeb.MvcShipping.DAL.MsOpSeaeEdiPortDAL
+ ":" + bill.PORTLOAD// 9 LOAD PORT 装货港 X(35) C
+ ":" + bill.SERVICE// 10 B/L CY-CFS ITEM 运输条款 X(9) M
+ ":" + xtype// 11 PREPAID OR COLLECT 付款方式(运费支付方法代码) X(1) "CCollect到付PPrepaid only预付F=免费" M
+ ":" + GetDateStr(bill.ETA, "yyyyMMdd")// 12 Consignment loading date 货物装船时间 9(8) "YYYYMMDD" M
+ ":" + GetDateStr(bill.ETD, "yyyyMMdd")// 12 Consignment loading date 货物装船时间 9(8) "YYYYMMDD" M
+ ":"// 13 QUARANTINE CODING 检疫代码 X(1) C
+ ":"// 14 DATE OF ISSUE 签发日期 9(8) CCYYMMDD C
+ ":"// 15 CURRENCY 币种(金额类型代码) X(3) 填写“托运货物价值”数据项填写的金额数值对应的货币代码参照代码表CN025 C

@ -19,7 +19,7 @@ namespace DSWeb.Areas.MvcShipping.DAL.code_vesselModelDal
//查询code_vessel语句
static public List<code_vesselModel> GetVesselList(string condition)
{
StringBuilder sb = new StringBuilder("select z.vsid,z.vessel,z.cname,z.carrier,z.edicode,z.SHIPAGENCY from code_vessel ");
StringBuilder sb = new StringBuilder("select z.vsid,z.vessel,z.cname,z.carrier,z.edicode,z.SHIPAGENCY,z.SHIPFLAG from code_vessel ");
sb.Append(" as z ");
if (!string.IsNullOrEmpty(condition))
{
@ -31,7 +31,7 @@ namespace DSWeb.Areas.MvcShipping.DAL.code_vesselModelDal
#region 根据ID进行查询
static public List<code_vesselModel> GetVesselByID(object headData)
{
StringBuilder sb = new StringBuilder("select z.vsid,z.vessel,z.cname,z.carrier,z.edicode,z.SHIPAGENCY from code_vessel ");
StringBuilder sb = new StringBuilder("select z.vsid,z.vessel,z.cname,z.carrier,z.edicode,z.SHIPAGENCY,z.SHIPFLAG from code_vessel ");
sb.Append(" as z where z.vsid='"+headData+"'");
return SetData(sb);
}
@ -52,8 +52,9 @@ namespace DSWeb.Areas.MvcShipping.DAL.code_vesselModelDal
data.carrier = Convert.ToString(reader["carrier"]);
data.edicode = Convert.ToString(reader["edicode"]);
data.SHIPAGENCY = Convert.ToString(reader["SHIPAGENCY"]);
data.SHIPFLAG = Convert.ToString(reader["SHIPFLAG"]);
#endregion
headList.Add(data);
}
@ -398,7 +399,7 @@ namespace DSWeb.Areas.MvcShipping.DAL.code_vesselModelDal
{
var cmdDelete = db.GetSqlStringCommand("delete from code_vessel where vsid='" + headData.vsid + "'");
db.ExecuteNonQuery(cmdDelete, tran);
string sql = string.Format("insert into code_vessel values('{0}','{1}','{2}','{3}','{4}','{5}')", headData.DM_ID, headData.vessel, headData.cname, headData.carrier, headData.edicode,headData.SHIPAGENCY);
string sql = string.Format("insert into code_vessel values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", headData.DM_ID, headData.vessel, headData.cname, headData.carrier, headData.edicode,headData.SHIPAGENCY, headData.SHIPFLAG);
var cmd = db.GetSqlStringCommand(sql);
db.ExecuteNonQuery(cmd, tran);
tran.Commit();

@ -23,6 +23,9 @@ namespace DSWeb.Areas.MvcShipping.Models.MsCodeVesselSetModel
[ModelDB]
public string DM_ID { get; set; }//EDI船舶呼号
[ModelDB]
public string SHIPFLAG { get; set; }//船旗
[ModelDB]
public string SHIPAGENCY { get; set; }
}

@ -121,7 +121,17 @@ Ext.extend(Shipping.MsCodeGoodsEdit, Ext.Panel, {
flex:1
}]
}
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '船旗',
name: 'SHIPFLAG',
flex: 1
}]
}
]//end items(fieldset 1)
}//end fieldset 1
]//end root items

@ -123,7 +123,12 @@ Ext.extend(Shipping.MsCodeGoodsIndex, Ext.Panel, {
dataIndex: 'edicode',
header: 'EDI船舶呼号',
width: 140
}
}, {
sortable: true,
dataIndex: 'SHIPFLAG',
header: '船旗',
width: 140
}
],
bbar: Ext.create('Ext.PagingToolbar', {
store: this.storeList,

@ -6,6 +6,7 @@
{ name: 'cname', type: 'string' },
{ name: 'carrier', type: 'string' },
{ name: 'SHIPAGENCY', type: 'string' },
{ name: 'SHIPFLAG', type: 'string' },
{ name: 'edicode', type: 'string' }
]
});

@ -23,6 +23,8 @@ Ext.extend(Shipping.MsOpSeaiIndex, Ext.Panel, {
this.bsno = '';
this.USEDSINTERFACE = 0;
//#region 定义数据集
this.storePLList = Ext.create('Ext.data.Store', {
model: 'MsOpSeaiModel'

@ -3848,8 +3848,17 @@ Ext.extend(Shipping.WMSNewINEdit, Ext.Panel, {
} else {
this.panelFee.StoreUnit.load({ params: { bsno: data.GID, bstype: "WMSIN" } });
}
_thispanefee = this.panelFee;
this.panelFee.storeBodySum.load({
params: { bsno:data.GID, optype: "WMSIN" },
callback: function (r, options, success) {
if (success) {
_thispanefee.setTotalHead();
}
}
});
this.panelFee.storeBodySum.load({ params: { bsno: data.GID } });
this.panelFee.storeChFeeGain.load({ params: { bsno: data.GID, optype: "WMSIN" } });
this.panelFee.DR_condition = "(((WMSOUTBSNO = '" + data.GID + "') and feetype = 1) or ((BSNO = '" + data.GID + "') and feetype = 1)) ";
this.panelFee.CR_condition = "(((WMSOUTBSNO = '" + data.GID + "') and feetype = 2) or ((BSNO = '" + data.GID + "') and feetype = 2)) ";

File diff suppressed because it is too large Load Diff

@ -0,0 +1,303 @@
using log4net;
using Newtonsoft.Json;
using Quartz;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace JobReqWebData
{
public class JobGetMskFtp : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobGetMskFtp));
public void Execute(IJobExecutionContext context)
{
log.Debug($"开始运行ftp");
try
{
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
var FTPADDRESS = context.JobDetail.JobDataMap.GetString("FTPADDRESS");
var FTPPATH = context.JobDetail.JobDataMap.GetString("FTPPATH");
var FTPUSERNAME = context.JobDetail.JobDataMap.GetString("FTPUSERNAME");
var FTPPWD = context.JobDetail.JobDataMap.GetString("FTPPWD");
var FTPPORT = context.JobDetail.JobDataMap.GetString("FTPPORT");
//// 配置会话选项
//SessionOptions sessionOptions = new SessionOptions
//{
// Protocol = Protocol.Ftp,
// HostName = FTPADDRESS,
// UserName = FTPUSERNAME,
// Password= FTPPWD
//};
//try
//{
// log.Debug($"FTP连接:{FTPADDRESS},{FTPPATH},{FTPUSERNAME},{FTPPWD}");
// var m_session = new Session();
// m_session.Open(sessionOptions);
// log.Debug($"FTP已连接:{FTPADDRESS},{FTPPATH},{FTPUSERNAME},{FTPPWD}");
// //this.propUpdateDownloadStatus("已连接");
// var ftpfilelist = m_session.ListDirectory(FTPPATH);
// var filepath = AppDomain.CurrentDomain.BaseDirectory + @"\FTPDOWNLOADFILE\" + DateTime.Now.ToString("yyyy-MM-dd") + @"\";
// if (Directory.Exists(filepath) == false)
// {
// Directory.CreateDirectory(filepath);
// log.Debug($"服务器本地建立文件夹:{filepath}");
// }
// for (var i = 0; i <= ftpfilelist.Files.Count - 1; i++)
// {
// if (!ftpfilelist.Files[i].IsDirectory && Path.GetFileName(ftpfilelist.Files[i].FullName) != "..")
// {
// var finf = new fileprop();
// finf.fdate = ftpfilelist.Files[i].LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
// finf.fname = Path.GetFileName(ftpfilelist.Files[i].FullName);
// finf.fullname = ftpfilelist.Files[i].FullName;
// finf.fsize = ftpfilelist.Files[i].Length.ToString();
// finf.ftype = "文件";
// m_filelist.Add(finf);
// }
// else
// {
// if (ftpfilelist.Files[i].Name != "..")
// {
// var ftpfilelist2 = m_session.ListDirectory(ftpfilelist.Files[i].FullName);
// for (var j = 0; j <= ftpfilelist2.Files.Count - 1; j++)
// {
// if (!ftpfilelist2.Files[j].IsDirectory && ftpfilelist2.Files[j].Name != "..")
// {
// var finf = new fileprop();
// finf.fdate = ftpfilelist2.Files[j].LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
// finf.fname = ftpfilelist2.Files[j].Name;
// finf.fullname = ftpfilelist2.Files[j].FullName;
// finf.fsize = ftpfilelist2.Files[j].Length.ToString();
// finf.ftype = "文件";
// m_filelist.Add(finf);
// }
// }
// }
// }
// }
//}
//catch (Exception e)
//{
//}
FTPDA FTPDA = new FTPDA();
try
{
FTPDA.ErrorMsg = "";
FTPDA.Uri = new Uri("ftp://" + FTPADDRESS + "/");
FTPDA.DirectoryPath = FTPPATH.Replace("/", "//");
FTPDA.UserName = FTPUSERNAME;
FTPDA.Password = FTPPWD;
log.Debug($"FTP连接:{FTPADDRESS},{FTPPATH},{FTPUSERNAME},{FTPPWD}");
var filearray = FTPDA.ListFiles();
var errmsg = FTPDA.ErrorMsg;
log.Debug($"FTP错误日志"+errmsg);
if (filearray == null || filearray.Count() == 0)
{
log.Debug($"没有可读取的文件,进程结束");
return;
}
log.Debug($"发现文件数:{filearray.Count()}");
var filepath = AppDomain.CurrentDomain.BaseDirectory + @"\FTPDOWNLOADFILE\" + DateTime.Now.ToString("yyyy-MM-dd") + @"\";
if (Directory.Exists(filepath) == false)
{
Directory.CreateDirectory(filepath);
log.Debug($"服务器本地建立文件夹:{filepath}");
}
foreach (FileStruct file in filearray)
{
if (!file.IsDirectory)
{
string LocalFullPath = Path.Combine(filepath, file.Name);
if (File.Exists(LocalFullPath))
{
log.Debug($"当前路径下已经存在同名文件:{LocalFullPath}");
FTPDA.DeleteFile(file.Name);
}
else
if (FTPDA.DownloadFile(file.Name, filepath))
{
log.Debug($"下载文件:{LocalFullPath}");
var tmpfile = file.Name;
if (tmpfile.IndexOf(".") > 0)
{
var tmpfilelist = tmpfile.Split('.');
if (tmpfilelist.Length >= 3 && tmpfilelist[2] == "CONTRL")
{
var filename = filepath + file.Name;
var headList = "";
var custno = "";
try
{
FileStream fs = new FileStream(filename, FileMode.Open);
StreamReader sr = new StreamReader(fs, System.Text.Encoding.GetEncoding("gb2312"));
string line;
while ((line = sr.ReadLine()) != null && line != "")
{
headList = headList + line;
}
headList = headList.Replace("?'", "し");
string[] StrList = headList.Split('\'');
for (var i = 0; i <= StrList.Length - 1; i++)
{
line = StrList[i];
if (line.Length > 3)
{
var head = line.Substring(0, 3);
if (head == "UCM")
{
custno = GetPosStringplus(line, 2);
if (!string.IsNullOrEmpty(custno))
{
using (SqlConnection dbcon = new SqlConnection(connStr))
{
dbcon.Open();
string sql = " insert op_status (ST_ID,BSNO,STATUS,ISCOMP,COMPTIME,COMPOP,INPUTTIME,STTYPE) Select NEWID(),BSNO,'订舱已接收',1,GETDATE(),'ADMIN',GETDATE(),'1' FROM OP_SEAE WHERE CUSTNO='" + custno + "'";
SqlCommand cmd = new SqlCommand(sql, dbcon);
cmd.ExecuteNonQuery();
dbcon.Close();
}
}
}
}
}
}
catch
{
}
}
}
FTPDA.DeleteFile(file.Name);
}
}
}
log.Debug($"连接字符串:{connStr}");
}
catch (Exception ex)
{
log.Error(ex.Message);
}
}
catch (Exception ex)
{
log.Error(ex.Message);
log.Error(ex.StackTrace);
}
}
public static string GetPosStringplus(string str, int pos, bool isnum = false)
{
var result = "";
if (isnum) result = "0";
var j = 0;
if (str.IndexOf("+") == -1) return result;
str = str.Replace("??", "?").Replace("?'", "'").Replace("?+", "し");
for (int i = 1; i < pos; i++)
{
if (str.IndexOf("+") == -1) return result;
if (str.IndexOf("+") != -1)
{
j = str.IndexOf("+");
str = str.Substring(j + 1, str.Length - j - 1);
}
}
j = str.IndexOf("+");
if (j != -1)
{
str = str.Substring(0, j);
}
else
{
if (str.Length != 0)
str = str.Substring(0, str.Length);
}
result = str.Replace("し", "+");
if (isnum)
{
if (result == "")
result = "0";
}
return result;
}
static public string GETBSNO(string MBLNO, SqlConnection dbcon)
{
var strSql = new StringBuilder();
strSql.Append("SELECT BSNO from V_OP_BS where MBLNO='" + MBLNO + "'");
SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon);
DataTable table = new DataTable();
adapter.Fill(table);
var BSNO = "";
if (table.Rows.Count > 0)
{
foreach (DataRow row in table.Rows)
{
BSNO = row["BSNO"].ToString();
}
}
return BSNO;
}
}
}

@ -12,6 +12,8 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -57,8 +59,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FTPDA.cs" />
<Compile Include="Helpers.cs" />
<Compile Include="JobDs7ToWeb.cs" />
<Compile Include="JobGetMskFtp.cs" />
<Compile Include="JobGetImpData.cs" />
<Compile Include="JobGetATDData.cs" />
<Compile Include="JobGetCarrierData.cs" />
@ -94,4 +98,11 @@
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Import Project="..\packages\WinSCP.6.3.2\build\WinSCP.targets" Condition="Exists('..\packages\WinSCP.6.3.2\build\WinSCP.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\WinSCP.6.3.2\build\WinSCP.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\WinSCP.6.3.2\build\WinSCP.targets'))" />
</Target>
</Project>

@ -6,4 +6,5 @@
<package id="log4net" version="2.0.8" targetFramework="net40" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net40" />
<package id="Quartz" version="2.6.2" targetFramework="net40" />
<package id="WinSCP" version="6.3.2" targetFramework="net40" />
</packages>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"/>
</configSections>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>

@ -1,210 +0,0 @@
using log4net;
using Quartz;
using System;
using System.Data;
using System.Data.SqlClient;
using RabbitMQ.Client;
using System.IO;
using System.Linq;
using System.Text;
using MailKit.Net.Smtp;
using MimeKit;
using HtmlAgilityPack;
using System.Collections.Generic;
using System.Configuration;
using System.Threading.Tasks;
using System.Threading;
using Newtonsoft.Json;
namespace JobSendAgentMail
{
public class MsOpSeae
{
public string BSNO { get; set; }
public string MBLNO { get; set; }
public string OP { get; set; }
public string MAIL { get; set; }
}
public class SendMail
{
public string OP { get; set; }
public string MAIL { get; set; }
public string MAILDESCRIPTION { get; set; }
}
public class JobDjy2D7Date : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobDjy2D7Date));
private static IConnection mqConn;
public void Execute(IJobExecutionContext context)
{
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
string MQURL = context.JobDetail.JobDataMap.GetString("DJYMQURL");
string virtualhost = context.JobDetail.JobDataMap.GetString("virtualhost");
string ExchangeName = context.JobDetail.JobDataMap.GetString("MQExchangeName");
string QueueName = context.JobDetail.JobDataMap.GetString("MQQueueName");
string BSSQL = context.JobDetail.JobDataMap.GetString("BSSQL");
string MAILSENDACCOUNT = context.JobDetail.JobDataMap.GetString("MAILSENDACCOUNT");
string MAILSENDPASSWORD = context.JobDetail.JobDataMap.GetString("MAILSENDPASSWORD");
string MAILSENDSERVICE = context.JobDetail.JobDataMap.GetString("MAILSENDSERVICE");
string MAILSENDPORT = context.JobDetail.JobDataMap.GetString("MAILSENDPORT");
string MAILISSSL = context.JobDetail.JobDataMap.GetString("MAILISSSL");
log.Debug($"启动接收大简云数据回推");
var CompanyQueueName = QueueName;
ConnectionFactory factory = new ConnectionFactory();
factory.Uri = new Uri(MQURL);
//factory.UserName = "xgs_test";
//factory.Password = "xgs_test123";
factory.VirtualHost = virtualhost;
mqConn = factory.CreateConnection();
IModel model = mqConn.CreateModel();
var task = Task.Run(() =>
{
while (true)
{
var result = model.BasicGet(queue: CompanyQueueName, autoAck: true);
if (result == null) { Thread.Sleep(10); continue; };
var strBody = Encoding.UTF8.GetString(result.Body.ToArray());
log.Debug($"收到简云截单日期数据回推消息:{strBody}");
try
{
//回写数据
var dateback = JsonConvert.DeserializeAnonymousType(strBody, new { vessel = string.Empty, voyage = string.Empty, ship_agency = string.Empty, cut_off_time = string.Empty, etd = string.Empty });
if (!string.IsNullOrEmpty(dateback.vessel) && !string.IsNullOrEmpty(dateback.voyage) && !string.IsNullOrEmpty(dateback.ship_agency) && !string.IsNullOrEmpty(dateback.cut_off_time))
{
using (SqlConnection dbcon = new SqlConnection(connStr))
{
dbcon.Open();
string maildescrption = "";
var FORWARDER = GetCustEdi(dbcon, dateback.ship_agency);
var SendMailList = new List<SendMail>();
if (!string.IsNullOrEmpty(FORWARDER))
{
var opseaelist = GetBs(dbcon, "VESSEL='" + dateback.vessel + "' AND VOYNO='" + dateback.voyage + "' and FORWARDER='" + FORWARDER + "'" + BSSQL);
if (opseaelist != null && opseaelist.Count != 0)
{
var opemail = "";
foreach (var opseae in opseaelist)
{
var tastStr = $" update op_seae set CLOSEDOCDATE='{dateback.cut_off_time}' where BSNO='{opseae.BSNO}' ";
SqlCommand cmdtast = new SqlCommand(tastStr, dbcon);
cmdtast.ExecuteNonQuery();
log.Debug($"已更新截单日期{dateback.cut_off_time},{opseae.MBLNO},{opseae.BSNO}");
var sendmail = SendMailList.Find(x => x.OP == opseae.OP);
if (sendmail != null)
{
sendmail.MAILDESCRIPTION = sendmail.MAILDESCRIPTION + Environment.NewLine + opseae.MBLNO;
}
else
{
var newsendmail = new SendMail();
newsendmail.OP = opseae.OP;
newsendmail.MAIL = opseae.MAIL;
newsendmail.MAILDESCRIPTION = opseae.MBLNO;
SendMailList.Add(newsendmail);
}
}
}
}
else
{
log.Debug($"{dateback.ship_agency}没有找到对应的订舱代理");
}
if (SendMailList != null && SendMailList.Count != 0)
{
foreach (var SendMail in SendMailList)
{
SendEmail se = new SendEmail(SendMail.MAIL, MAILSENDACCOUNT, "", "", "截港日期自动更新", SendMail.MAILDESCRIPTION, false);
se.SetSmtp(MAILSENDACCOUNT, MAILSENDPASSWORD, MAILSENDSERVICE, Convert.ToInt16(MAILSENDPORT), false, System.Net.Mail.MailPriority.Normal); //必须在所有参数设置完后调用此方法
log.Debug($"已给操作{SendMail.OP}发送邮件{SendMail.MAIL}{SendMail.MAILDESCRIPTION}");
}
}
}
}
}
catch (Exception ex)
{
log.Error($"处理大简云数据回推时出错:" + ex.Message);
log.Error(ex.Message);
log.Error(ex.StackTrace);
}
//model.BasicConsume(CompanyQueueName, true, consumer);
//Console.WriteLine(msg);
}
});
task.Wait();
model.Close();
mqConn.Close();
}
static public List<MsOpSeae> GetBs(SqlConnection dbcon, string constr)
{
var opseaeList = new List<MsOpSeae>();
var strSql = new StringBuilder();
strSql.Append("select BSNO,MBLNO,OP,FORWARDER,(SELECT TOP 1 EMAIL1 FROM VW_user WHERE SHOWNAME=op_seae.OP) EMAIL from op_seae where " + constr);
strSql.Append(" ORDER BY OP ");
SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon);
DataTable table = new DataTable();
adapter.Fill(table);
if (table.Rows.Count > 0)
{
foreach (DataRow row in table.Rows)
{
var opseae = new MsOpSeae();
opseae.BSNO = Convert.ToString(row["BSNO"].ToString());
opseae.MBLNO = Convert.ToString(row["MBLNO"].ToString());
opseae.OP = Convert.ToString(row["OP"].ToString());
opseae.MAIL = Convert.ToString(row["EMAIL"].ToString());
opseaeList.Add(opseae);
}
}
return opseaeList;
}
static public string GetCustEdi(SqlConnection dbcon, string constr)
{
string result = "";
var strSql = new StringBuilder();
strSql.Append("select CUST from code_cust_edi where EDINAME='DJY' AND EDICODE='" + constr + "'");
SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon);
DataTable table = new DataTable();
adapter.Fill(table);
if (table.Rows.Count > 0)
{
foreach (DataRow row in table.Rows)
{
result = Convert.ToString(row["CUST"].ToString());
}
}
return result;
}
}
}

@ -0,0 +1,244 @@
using log4net;
using Quartz;
using System;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using MailKit;
using MailKit.Net.Imap;
using MailKit.Search;
using MimeKit;
using System.Data.Entity;
using System.Data.SqlClient;
namespace JobSendAgentMail
{
public class MailDataContext : DbContext
{
public MailDataContext(string nameOrConnectionString)
: base(nameOrConnectionString)
{
}
public DbSet<MailReceiveRecordInfo> ReceiveRecords { get; set; }
public DbSet<MailSend> MailSend { get; set; }
public DbSet<OpMailLog> OpMailLogs { get; set; }
}
public class D7OPSEAEMAIL
{
public string BSNO { get; set; }
public string AGENTMAIL { get; set; }
public string OPEMAIL { get; set; }
}
public class JobReceiveMail : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobReceiveMail));
public void Execute(IJobExecutionContext context)
{
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
string querySql = context.JobDetail.JobDataMap.GetString("QuerySql");
string hblquerySql = context.JobDetail.JobDataMap.GetString("HblQuerySql");
string DocType = context.JobDetail.JobDataMap.GetString("DocType");
string D7FilePath = context.JobDetail.JobDataMap.GetString("D7FilePath");
string MAILSENDACCOUNT = context.JobDetail.JobDataMap.GetString("MAILSENDACCOUNT");
string MAILSENDPASSWORD = context.JobDetail.JobDataMap.GetString("MAILSENDPASSWORD");
string MAILSENDSERVICE = context.JobDetail.JobDataMap.GetString("MAILSENDSERVICE");
string MAILSENDPORT = context.JobDetail.JobDataMap.GetString("MAILSENDPORT");
string MAILISSSL = context.JobDetail.JobDataMap.GetString("MAILISSSL");
string MAILTEMPLATE = context.JobDetail.JobDataMap.GetString("MAILTEMPLATE");
string MAILTITLEJOB = context.JobDetail.JobDataMap.GetString("MAILTITLE");
string basePath = AppDomain.CurrentDomain.BaseDirectory;
string savePath = Path.Combine(basePath, $"{DateTime.Now.ToString("yyyyMMdd")}\\{MAILSENDACCOUNT}");
log.Debug($"开始接收邮件");
using (SqlConnection dbcon = new SqlConnection(connStr))
{
dbcon.Open();
using (var imapClient = new ImapClient())
{
imapClient.ServerCertificateValidationCallback = (s, c, h, e) => true;
imapClient.Connect(MAILSENDSERVICE, Convert.ToInt16(MAILSENDPORT), Convert.ToBoolean(MAILISSSL));
imapClient.Authenticate(MAILSENDACCOUNT, MAILSENDPASSWORD);
log.Debug($"已连接邮件");
var inbox = imapClient.Inbox;
inbox.Open(FolderAccess.ReadOnly);
MailDataContext mailData = new MailDataContext(connStr);
var uids = inbox.Search(SearchQuery.DeliveredAfter(DateTime.Now).And(SearchQuery.DeliveredBefore(DateTime.Now.AddDays(1))));
//MailDataContext dataContext = new MailDataContext(connStr);
for (int i = 0; i < uids.Count; i++)
{
var uid = uids[i];
var c = mailData.ReceiveRecords.Count(r => r.MailAccount == MAILSENDACCOUNT && r.MailId == uid.Id);
if (c > 0)
{
continue; //忽略
}
try
{
var recInfo = new MailReceiveRecordInfo();
recInfo.MailAccount = MAILSENDACCOUNT;
recInfo.MailId = uid.Id;
recInfo.MailDate = DateTime.Now;
string emlSavePath = Path.Combine(savePath, $"{uid}.eml");
var message = inbox.GetMessage(uid);
//message.WriteTo(emlSavePath);
recInfo.Subject = message.Subject;
recInfo.Sender = message.From[0].ToString();
recInfo.RecTime = message.Date.ToLocalTime().DateTime;
if (recInfo.RecTime < DateTime.Parse("1970-01-01"))
{
recInfo.RecTime = DateTime.Now;
}
#region body乱码处理
string body = string.Empty;
//if (message.TextBody != null)
//{
// body = message.TextBody;
//}
//else if (message.HtmlBody != null)
//{
// body = message.HtmlBody;
//}
recInfo.Body = message.HtmlBody;
#endregion
string strAttach = string.Empty;
foreach (var att in message.Attachments)
{
MimePart attPart = att as MimePart;
if (attPart != null)
{
strAttach += attPart.FileName + ";";
}
}
recInfo.Attachments = strAttach;
recInfo.FilePath = emlSavePath;
mailData.ReceiveRecords.Add(recInfo);
mailData.SaveChanges(); //立即保存
log.Debug($"已保存邮件");
if (recInfo.Subject.IndexOf("SZNG HBL") == 0)
{
log.Debug($"分析邮件");
var mailsubject = recInfo.Subject;
var subjectlist = mailsubject.Split(':');
if (subjectlist.Length >=3)
{
var STATUS = "";
var HBLNO = subjectlist[0].Replace("SZNG HBL","").Trim();
log.Debug($"分析邮件:"+HBLNO+" "+STATUS);
var statuslist = subjectlist[2].Split(' ');
if (statuslist.Length >= 0) STATUS = statuslist[2].Trim();
if (!string.IsNullOrEmpty(HBLNO) && !string.IsNullOrEmpty(STATUS))
{
var tastStr = $" update op_seae_edi set MANIFESTSTATUS=MANIFESTSTATUS+' '+'{STATUS}' where HBLNO='{HBLNO}' AND MANIFESTSTATUS not like '%{STATUS}%' ";
SqlCommand cmdtast = new SqlCommand(tastStr, dbcon);
cmdtast.ExecuteNonQuery();
log.Debug($"更新舱单状态:" + HBLNO + " " + STATUS);
var AGENTMAIL = AGENTEMAIL(HBLNO, querySql,dbcon);
if (!string.IsNullOrEmpty(AGENTMAIL.AGENTMAIL))
{
log.Debug($"生成转发:" + HBLNO + " " + STATUS);
var sendmail = new MailSend();
sendmail.GID = Guid.NewGuid().ToString();
sendmail.Title = recInfo.Subject;
sendmail.Body = recInfo.Body;
sendmail.SendTo = AGENTMAIL.AGENTMAIL;
sendmail.CCTo= AGENTMAIL.OPEMAIL;
sendmail.RelativeId = AGENTMAIL.BSNO;
sendmail.SendStatus = "Create";
sendmail.CreateTime = DateTime.Now;
sendmail.TryCount = 0;
mailData.MailSend.Add(sendmail);
mailData.SaveChanges();
log.Debug($"保存转发:" + HBLNO + " " + STATUS);
}
}
}
}
mailData.Dispose();
mailData = null;
}
catch (Exception ex)
{
log.Error($"收取邮件时,发生严重错误:{uid}");
log.Error(ex.Message);
log.Error(ex.StackTrace);
}
}
if (inbox.IsOpen)
{
inbox.Close();
imapClient.Disconnect(true);
}
}
dbcon.Close();
}
}
static public D7OPSEAEMAIL AGENTEMAIL(string HBLNO,string QuerySql,SqlConnection dbcon)
{
var result = new D7OPSEAEMAIL();
QuerySql = QuerySql.Replace("@HBLNO", HBLNO);
SqlDataAdapter adapter = new SqlDataAdapter(QuerySql, dbcon);
DataTable table = new DataTable();
adapter.Fill(table);
if (table.Columns.Contains("BSNO") && table.Columns.Contains("AGENTEMAIL"))
{
if (table.Rows.Count > 0)
{
foreach (DataRow row in table.Rows)
{
result.AGENTMAIL = row["AGENTEMAIL"].ToString();
result.OPEMAIL = row["OPEMAIL"].ToString();
result.BSNO = row["BSNO"].ToString();
}
}
}
return result;
}
}
}

@ -69,9 +69,6 @@
<Reference Include="Quartz, Version=2.6.2.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
<HintPath>..\packages\Quartz.2.6.2\lib\net40\Quartz.dll</HintPath>
</Reference>
<Reference Include="RabbitMQ.Client">
<HintPath>..\D7MqClient\packages\RabbitMQ.Client.6.2.2\lib\net461\RabbitMQ.Client.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
@ -86,13 +83,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DsSendMail.cs" />
<Compile Include="JobDjy2D7Date.cs" />
<Compile Include="JobReceiveMail.cs" />
<Compile Include="JobSendCtn.cs" />
<Compile Include="JobSendBooking.cs" />
<Compile Include="MailReceiveRecordInfo.cs" />
<Compile Include="MailSend.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SendMailJob.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JobSendAgentMail
{
/// <summary>
/// 目前仅用来,通过DJYID判断业务是否存在
/// </summary>
[Table("Mail_Receive_Record")]
public class MailReceiveRecordInfo
{
public MailReceiveRecordInfo()
{
this.GID = Guid.NewGuid().ToString();
this.IsCheck = false;
this.IsProcess = false;
this.IsProcess = false;
this.MailDate = DateTime.Today;
}
[Key]
public string GID { get; set; }
public string MailAccount { get; set; }
public long MailId { get; set; }
public string Subject { get; set; }
public string Sender { get; set; }
public DateTime RecTime { get; set; }
public bool IsCheck { get; set; }
public bool IsParse { get; set; }
public bool IsProcess { get; set; }
public string Body { get; set; }
public string Attachments { get; set; }
public DateTime MailDate { get; set; }
public string FilePath { get; set; }
}
}

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace JobSendAgentMail
{
[Table("Mail_Send")]
public class MailSend
{
public const string MailSendStatusCreate = "Create";
public const string MailSendStatusSending = "Sending";
public const string MailSendStatusSuccess = "Success";
public const string MailSendStatusFail = "Fail";
public MailSend()
{
this.GID = Guid.NewGuid().ToString().Replace("-", "");
SendStatus = MailSendStatusCreate;
CreateTime = DateTime.Now;
TryCount = 0;
}
[Key]
public string GID { get; set; }
public string SendTo { get; set; }
public string CCTo { get; set; }
public string Title { get; set; }
public string Body { get; set; }
public string SendStatus { get; set; }
public DateTime? SendTime { get; set; }
public int TryCount { get; set; }
public DateTime CreateTime { get; set; }
public string RelativeId { get; set; }
public string SmtpConfig { get; set; }
public string ShowName { get; set; }
public string Sender { get; set; }
}
[Table("op_mail_log")]
public class OpMailLog
{
public OpMailLog()
{
this.GID = Guid.NewGuid().ToString().Replace("-", "");
SENDTIME = DateTime.Now;
}
[Key]
public string GID { get; set; }
public string BSNO { get; set; }
public string BLTYPE { get; set; }
public string RECEIVER { get; set; }
public string CCTo { get; set; }
public string SUBJECT { get; set; }
public string DESCRIPTION { get; set; }
public string ATTACHMENT { get; set; }
public DateTime? SENDTIME { get; set; }
public string SENDUSER { get; set; }
}
}

@ -0,0 +1,155 @@
using System.Data.Entity;
using log4net;
using MailKit.Net.Smtp;
using MimeKit;
using Quartz;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
namespace JobSendAgentMail
{
/// <summary>
/// 发送邮件任务
/// </summary>
public class SendMailJob : IJob
{
private const int MailSendTryTimes = 3;
private ILog logger = LogManager.GetLogger(typeof(SendMailJob));
public void Execute(IJobExecutionContext context)
{
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
string MAILSENDACCOUNT = context.JobDetail.JobDataMap.GetString("MAILSENDACCOUNT");
string MAILSENDPASSWORD = context.JobDetail.JobDataMap.GetString("MAILSENDPASSWORD");
string MAILSENDSERVICE = context.JobDetail.JobDataMap.GetString("MAILSENDSERVICE");
string MAILSENDPORT = context.JobDetail.JobDataMap.GetString("MAILSENDPORT");
string MAILISSSL = context.JobDetail.JobDataMap.GetString("MAILISSSL");
MailDataContext commonDataContext = new MailDataContext(connStr);
var sendMailList = commonDataContext.MailSend.Where(sm => sm.SendStatus == MailSend.MailSendStatusCreate).OrderBy(sm => sm.CreateTime).Take(20).ToList();
if (sendMailList.Count > 0)
{
//先更改状态,防止其他线程重复发送
foreach (var sendMail in sendMailList)
{
logger.Debug($"mail ready to send:{sendMail.GID} {sendMail.Title}");
sendMail.SendStatus = MailSend.MailSendStatusSending;
sendMail.SendTime = DateTime.Now;
sendMail.TryCount++;
commonDataContext.SaveChanges();
}
//逐个发送
foreach (var sendMail in sendMailList)
{
try
{
var message = new MimeMessage();
message.From.Add(MailboxAddress.Parse(MAILSENDACCOUNT));
if (sendMail.SendTo.IndexOf(",") > -1)
{
var arrSendTo = sendMail.SendTo.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (var s in arrSendTo)
{
message.To.Add(MailboxAddress.Parse(s));
}
}
else if (sendMail.SendTo.IndexOf(";") > -1)
{
var arrSendTo = sendMail.SendTo.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (var s in arrSendTo)
{
message.To.Add(MailboxAddress.Parse(s));
}
}
else
{
message.To.Add(MailboxAddress.Parse(sendMail.SendTo));
}
if (sendMail.CCTo.IndexOf(",") > -1)
{
var arrSendTo = sendMail.CCTo.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (var s in arrSendTo)
{
message.To.Add(MailboxAddress.Parse(s));
}
}
else if (sendMail.CCTo.IndexOf(";") > -1)
{
var arrSendTo = sendMail.CCTo.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (var s in arrSendTo)
{
message.To.Add(MailboxAddress.Parse(s));
}
}
else
{
message.To.Add(MailboxAddress.Parse(sendMail.CCTo));
}
message.Subject = sendMail.Title;
var html = new TextPart("html")
{
Text = sendMail.Body
};
MimeEntity entity = html;
//if (!string.IsNullOrEmpty(sendMail.Sender))
//{
// message.Sender = MailboxAddress.Parse(sendMail.Sender);
//}
message.Body = entity;
using (var client = new SmtpClient())
{
client.Connect(MAILSENDSERVICE, Convert.ToInt16(MAILSENDPORT), Convert.ToBoolean(MAILISSSL));
client.Authenticate(MAILSENDACCOUNT, MAILSENDPASSWORD);
client.Send(message);
client.Disconnect(true);
}
logger.Debug($"发送成功:{sendMail.GID} {sendMail.Title}");
sendMail.SendStatus = MailSend.MailSendStatusSuccess;
//commonDataContext.SaveChanges();
var OpMailLog = new OpMailLog();
OpMailLog.SUBJECT = sendMail.Title;
OpMailLog.RECEIVER = sendMail.SendTo;
OpMailLog.BSNO = sendMail.RelativeId;
OpMailLog.DESCRIPTION = sendMail.Body;
OpMailLog.SENDUSER = MAILSENDACCOUNT;
OpMailLog.BLTYPE = "舱单回执转发";
commonDataContext.OpMailLogs.Add(OpMailLog);
commonDataContext.SaveChanges();
logger.Debug($"mail send success:{sendMail.GID} {sendMail.Title}");
}
catch (Exception ex)
{
if (sendMail.TryCount < MailSendTryTimes)
{
sendMail.SendStatus = MailSend.MailSendStatusCreate; //会再次尝试发送
}
else
{
sendMail.SendStatus = MailSend.MailSendStatusFail;
}
commonDataContext.SaveChanges();
logger.Error($"mail send fail:{sendMail.GID} {sendMail.Title}times:{sendMail.TryCount}");
logger.Error(ex.Message);
logger.Error(ex.StackTrace);
}
}
}
}
}
}

@ -17,7 +17,7 @@
<!--连接字符串-->
<entry>
<key>ConnectString</key>
<value>Data Source=119.167.78.10,1433;Initial Catalog=DATA;Persist Security Info=True;User ID=sa;Password=yongfa_123</value>
<value>Data Source=ds-hxt;Initial Catalog=DATA;Persist Security Info=True;User ID=sa;Password=yongfa_123</value>
</entry>
<!--查询SQL-->
<entry>

@ -88,16 +88,130 @@
<cron-expression>0 34 14 * * ?</cron-expression>
</cron>
</trigger>
<!--<trigger>
<simple>
<name>TriggerBooking</name>
<!--接收邮件-->
<job>
<name>JobReceiveMail</name>
<group>Job</group>
<description>接收邮件</description>
<job-type>JobSendAgentMail.JobReceiveMail,JobSendAgentMail</job-type>
<durable>true</durable>
<recover>false</recover>
<job-data-map>
<!--连接字符串-->
<entry>
<key>ConnectString</key>
<value>Data Source=www.perways.net,18866;Initial Catalog=ShippingWeb_SZYT;Persist Security Info=True;User ID=sa;Password=Ds20040201</value>
</entry>
<!--查询SQL-->
<entry>
<key>QuerySql</key>
<value>
select BSNO,(SELECT TOP 1 EMAIL FROM info_client WHERE SHORTNAME=op_seae_billmanage.AGENTID) AGENTEMAIL from op_seae_billmanage WHERE AS_ID IN (SELECT BSNO FROM op_seae_edi where HBLNO='@HBLNO')
</value>
</entry>
<!--DS7邮箱发送账号-->
<entry>
<key>MAILSENDACCOUNT</key>
<value>szytcus@perways.com</value>
</entry>
<!--DS7邮箱发送密码-->
<entry>
<key>MAILSENDPASSWORD</key>
<value>PER202100558YT12</value>
</entry>
<!--DS7邮箱发送账号-->
<entry>
<key>MAILSENDSERVICE</key>
<value>smtp.263.net</value>
</entry>
<!--DS7邮箱发送账号-->
<entry>
<key>MAILSENDPORT</key>
<value>25</value>
</entry>
<!--DS7邮箱发送账号-->
<entry>
<key>MAILISSSL</key>
<value>false</value>
</entry>
<entry>
<key>MAILTEMPLATE</key>
<value>MailTemplate.html</value>
</entry>
</job-data-map>
</job>
<!-- 发送请求数据任务触发器-->
<trigger>
<cron>
<name>TriggerReceiveMail</name>
<group>Job</group>
<description>订阅数据触发器</description>
<job-name>JobSendBooking</job-name>
<job-name>JobReceiveMail</job-name>
<job-group>Job</job-group>
<cron-expression>0 0/3 * * * ?</cron-expression>
</cron>
</trigger>
<!--接收邮件-->
<job>
<name>SendMailJob</name>
<group>Job</group>
<description>发送邮件</description>
<job-type>JobSendAgentMail.SendMailJob,JobSendAgentMail</job-type>
<durable>true</durable>
<recover>false</recover>
<job-data-map>
<!--连接字符串-->
<entry>
<key>ConnectString</key>
<value>Data Source=www.perways.net,18866;Initial Catalog=ShippingWeb_SZYT;Persist Security Info=True;User ID=sa;Password=Ds20040201</value>
</entry>
<!--DS7邮箱发送账号-->
<entry>
<key>MAILSENDACCOUNT</key>
<value>szytcus@perways.com</value>
</entry>
<!--DS7邮箱发送密码-->
<entry>
<key>MAILSENDPASSWORD</key>
<value>PER202100558YT12</value>
</entry>
<!--DS7邮箱发送账号-->
<entry>
<key>MAILSENDSERVICE</key>
<value>smtp.263.net</value>
</entry>
<!--DS7邮箱发送账号-->
<entry>
<key>MAILSENDPORT</key>
<value>25</value>
</entry>
<!--DS7邮箱发送账号-->
<entry>
<key>MAILISSSL</key>
<value>false</value>
</entry>
</job-data-map>
</job>
<!-- 发送请求数据任务触发器-->
<trigger>
<cron>
<name>TriggerSendMail</name>
<group>Job</group>
<description>订阅数据触发器</description>
<job-name>SendMailJob</job-name>
<job-group>Job</job-group>
<cron-expression>0 5,10 9 * * ?</cron-expression>
</simple>
</trigger>-->
<cron-expression>0 0/3 * * * ?</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>
Loading…
Cancel
Save