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.
105 lines
3.4 KiB
C#
105 lines
3.4 KiB
C#
using log4net;
|
|
using RabbitMQ.Client;
|
|
using RabbitMQ.Client.Events;
|
|
using System;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.IO;
|
|
using System.Net;
|
|
using MailAnalyzeTools.Common;
|
|
|
|
namespace D7MqClient
|
|
{
|
|
|
|
|
|
|
|
public class JFtoDcStatus
|
|
{
|
|
|
|
|
|
private static string COMPANYID = ConfigurationManager.AppSettings["COMPANYID"];
|
|
private static string MQURL = ConfigurationManager.AppSettings["MQURL"];
|
|
private static string connStr = ConfigurationManager.AppSettings["ConnectionString"];
|
|
private static string connFileStr = ConfigurationManager.AppSettings["ConnectionStringFile"];
|
|
private static string FilePath = ConfigurationManager.AppSettings["FilePath"];
|
|
private static string FileType = ConfigurationManager.AppSettings["FileType"];
|
|
|
|
private const string ExchangeName = "output";
|
|
private const string QueueName = "djy.output.status.so.";
|
|
private static IConnection mqConn;
|
|
private static ILog logger = LogManager.GetLogger("D7MqClient");
|
|
|
|
public static void DoProcess()
|
|
{
|
|
logger.Debug($"启动接收订舱状态消息");
|
|
var CompanyQueueName = QueueName + COMPANYID;
|
|
ConnectionFactory factory = new ConnectionFactory();
|
|
factory.Uri = new Uri(MQURL);
|
|
mqConn = factory.CreateConnection();
|
|
|
|
IModel model = mqConn.CreateModel();
|
|
model.ExchangeDeclare(ExchangeName, ExchangeType.Direct);
|
|
model.QueueDeclare(CompanyQueueName, false, false, false, null);
|
|
|
|
var consumer = new EventingBasicConsumer(model);
|
|
consumer.Received += (ch, ea) =>
|
|
{
|
|
var body = ea.Body;
|
|
var strBody = Encoding.UTF8.GetString(body.ToArray());
|
|
logger.Debug($"收到订舱状态消息:{strBody}");
|
|
|
|
try
|
|
{
|
|
using (SqlConnection dbcon = new SqlConnection(connStr))
|
|
{
|
|
dbcon.Open();
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("update t_op_seae set 订舱状态='已订舱' where 主提单号='" + strBody + "'");
|
|
SqlCommand cmd = new SqlCommand(strSql.ToString(), dbcon);
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error($"处理订舱状态时出错:" +ex.Message);
|
|
logger.Error(ex.Message);
|
|
logger.Error(ex.StackTrace);
|
|
}
|
|
};
|
|
model.BasicConsume(CompanyQueueName, true, consumer);
|
|
}
|
|
|
|
public static string getFileName(string path)
|
|
{
|
|
string str = string.Empty;
|
|
int pos1 = path.LastIndexOf('/');
|
|
int pos2 = path.LastIndexOf('\\');
|
|
int pos = Math.Max(pos1, pos2);
|
|
if (pos < 0)
|
|
str = path;
|
|
else
|
|
str = path.Substring(pos + 1);
|
|
|
|
return str;
|
|
}
|
|
public static void StopProcess()
|
|
{
|
|
if (mqConn != null && mqConn.IsOpen)
|
|
{
|
|
mqConn.Close();
|
|
mqConn = null;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|