|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Configuration;
|
|
|
using System.Linq;
|
|
|
using System.Web;
|
|
|
using System.Web.Mvc;
|
|
|
using System.Web.Routing;
|
|
|
using log4net;
|
|
|
using DSWeb.Areas;
|
|
|
using System.Threading;
|
|
|
using System.Timers;
|
|
|
using DSWeb.Areas.Mobile.DAL;
|
|
|
using System.Net;
|
|
|
using System.IO;
|
|
|
using AutoMapper;
|
|
|
using DSWeb.Areas.Dispatch.DB;
|
|
|
using DSWeb.Areas.Dispatch.Models;
|
|
|
using DSWeb.Areas.MvcShipping.DB;
|
|
|
using DSWeb.Areas.MvcShipping.Models.MsOpRule;
|
|
|
using DSWeb.Areas.MvcShipping.Models.MsOpSeaeRunBill;
|
|
|
using DSWeb.Areas.MvcShipping.Comm;
|
|
|
using BookingWeb.DB.Model;
|
|
|
using RabbitMQ.Client;
|
|
|
using RabbitMQ.Client.Events;
|
|
|
using System.Text;
|
|
|
|
|
|
namespace DSWeb
|
|
|
{
|
|
|
public class Global : System.Web.HttpApplication
|
|
|
{
|
|
|
public static void RegisterRoutes(RouteCollection routes)
|
|
|
{
|
|
|
string ls = System.Configuration.ConfigurationSettings.AppSettings["isly"].ToString();
|
|
|
if (ls == "1")
|
|
|
{
|
|
|
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
|
|
|
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
|
|
|
routes.MapRoute(
|
|
|
"Default", //适用于虚拟主机,ext可以为ashx,aspx,ascx,asmx
|
|
|
"{controller}.{ext}/{action}/{id}",
|
|
|
new { controller = "Home", action = "Index", id = "" },
|
|
|
new[] { "DSWeb.Controllers" });
|
|
|
routes.MapRoute(
|
|
|
"Default2", //适用可以设置IIS或IIS版本为7.0以上
|
|
|
"{controller}/{action}/{id}",
|
|
|
new { controller = "Home", action = "Index", id = "" },
|
|
|
new[] { "DSWeb.Controllers" });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
protected void Application_Start(object sender, EventArgs e)
|
|
|
{
|
|
|
string ls = System.Configuration.ConfigurationSettings.AppSettings["isly"].ToString();
|
|
|
if (ls == "1")
|
|
|
{
|
|
|
AreaRegistration.RegisterAllAreas();
|
|
|
RegisterRoutes(RouteTable.Routes);
|
|
|
}
|
|
|
|
|
|
System.Timers.Timer evtTimer = new System.Timers.Timer(150000);
|
|
|
evtTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnEvtTimer);
|
|
|
evtTimer.Interval = 150000;
|
|
|
evtTimer.Enabled = true;
|
|
|
|
|
|
//HomeService.HomeService.StoreMemcachedForCount();
|
|
|
|
|
|
//log4j日志记录
|
|
|
log4net.Config.XmlConfigurator.Configure();//读取了配置文件中关于Log4Net配置信息.
|
|
|
//开启一个线程,扫描异常信息队列。
|
|
|
string filePath = Server.MapPath("/Log/");
|
|
|
ThreadPool.QueueUserWorkItem((a) =>
|
|
|
{
|
|
|
while (true)
|
|
|
{
|
|
|
//判断一下队列中是否有数据
|
|
|
if (ExceptionAttribute.ExecptionQueue.Count() > 0)
|
|
|
{
|
|
|
Exception ex = ExceptionAttribute.ExecptionQueue.Dequeue();
|
|
|
if (ex != null)
|
|
|
{
|
|
|
//将异常信息写到日志文件中。
|
|
|
//string fileName = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
//File.AppendAllText(filePath+fileName+".txt",ex.ToString(),System.Text.Encoding.UTF8);
|
|
|
ILog logger = LogManager.GetLogger("errorMsg");
|
|
|
logger.Error(ex.ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//如果队列中没有数据,休息
|
|
|
Thread.Sleep(3000);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//如果队列中没有数据,休息
|
|
|
Thread.Sleep(3000);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}, filePath);
|
|
|
|
|
|
var appid = ConfigurationManager.AppSettings["appid"];
|
|
|
if (appid != null && appid.ToString() != "")
|
|
|
{
|
|
|
//每隔5个小时,刷新微信的AccessToken
|
|
|
System.Timers.Timer myTimer = new System.Timers.Timer(1000 * 60 * 60 * 5);
|
|
|
|
|
|
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
|
|
|
|
|
|
myTimer.Enabled = true;
|
|
|
|
|
|
myTimer.AutoReset = true;
|
|
|
}
|
|
|
|
|
|
|
|
|
var ReceiveDjydc = ConfigurationManager.AppSettings["ReceiveDjydc"];
|
|
|
if (ReceiveDjydc != null && ReceiveDjydc.ToString() != "")
|
|
|
{
|
|
|
DoReceiveDjydc();
|
|
|
}
|
|
|
|
|
|
InitMapper();
|
|
|
|
|
|
JobScheduler.Start();
|
|
|
}
|
|
|
|
|
|
private static void OnEvtTimer(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
{
|
|
|
|
|
|
//定时运行服务
|
|
|
//c#让webservice定时执行
|
|
|
/*HomeService.HomeService.StoreMemcachedForCount("");
|
|
|
HomeService.HomeService.StoreMemcachedForList("");*/
|
|
|
// HomeService.NavigationService.StoreMemcached();
|
|
|
|
|
|
}
|
|
|
protected void Session_Start(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void Application_BeginRequest(object sender, EventArgs e)
|
|
|
{
|
|
|
if (Context.Request.FilePath == "/") Context.RewritePath("Default.aspx");
|
|
|
}
|
|
|
|
|
|
protected void Application_AuthenticateRequest(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void Application_Error(object sender, EventArgs e)
|
|
|
{
|
|
|
Exception lastError = Server.GetLastError();
|
|
|
ExceptionAttribute.AddException(lastError);
|
|
|
//Server.Transfer("~/Error/FriendError.aspx");
|
|
|
}
|
|
|
|
|
|
protected void Session_End(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void Application_End(object sender, EventArgs e)
|
|
|
{
|
|
|
#region 微信刷新AccessToken定时器关联
|
|
|
//下面的代码是关键,可解决IIS应用程序池自动回收的问题
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
//这里设置你的web地址,可以随便指向你的任意一个aspx页面甚至不存在的页面,目的是要激发Application_Start
|
|
|
|
|
|
string url = "http://www.baidu.com";
|
|
|
|
|
|
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
|
|
|
|
|
|
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
|
|
|
|
|
|
Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
void myTimer_Elapsed(object source, ElapsedEventArgs e)
|
|
|
{
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
DBLog.Log(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":AutoTask is Working!");
|
|
|
|
|
|
TokenTask();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
|
|
|
DBLog.Log(ee.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void TokenTask()
|
|
|
{
|
|
|
AccessTokenDAL.RefrashAccessToken();
|
|
|
}
|
|
|
|
|
|
void InitMapper()
|
|
|
{
|
|
|
Mapper.Initialize(cfg =>
|
|
|
{
|
|
|
cfg.CreateMap<Areas.Dispatch.DB.InfoClient, InfoClientLoginViewModel>();
|
|
|
cfg.CreateMap<Areas.Dispatch.DB.InfoClient, InfoClientTruckViewModel>();
|
|
|
cfg.CreateMap<DriverRegistViewModel, DriverInfo>();
|
|
|
cfg.CreateMap<DriverInfo, DriverRegistViewModel>();
|
|
|
cfg.CreateMap<DriverInfo, DriverAuditViewModel>()
|
|
|
.ForMember(x => x.AuditStatsName, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.IsAudit ? "已审核" : "未审核");
|
|
|
});
|
|
|
cfg.CreateMap<OpStatusInfo, OpStatusViewModel>()
|
|
|
.ForMember(x => x.COMPTIME, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.COMPTIME.HasValue ? d.COMPTIME.Value.ToString("yyyy-MM-dd HH:mm:ss") : "");
|
|
|
})
|
|
|
.ForMember(x => x.COMPTIME_DATE, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.COMPTIME.HasValue ? d.COMPTIME.Value.ToString("yyyy-MM-dd") : "");
|
|
|
})
|
|
|
.ForMember(x => x.COMPTIME_TIME, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.COMPTIME.HasValue ? d.COMPTIME.Value.ToString("HH:mm:ss") : "");
|
|
|
});
|
|
|
|
|
|
|
|
|
cfg.CreateMap<OpRule, OpRuleListViewModel>()
|
|
|
.ForMember(x => x.EnableDisableTime, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.EnableDisableTime.HasValue ? d.EnableDisableTime.Value.ToString("yyyy/MM/dd HH:mm:ss") : "");
|
|
|
});
|
|
|
cfg.CreateMap<OpRule, OpRuleEditViewModel>();
|
|
|
cfg.CreateMap<OpRuleEditViewModel, OpRule>();
|
|
|
cfg.CreateMap<OpRuleItemEditViewModel, OpRuleItem>();
|
|
|
cfg.CreateMap<OpRule, OpRuleCheckListViewModel>();
|
|
|
cfg.CreateMap<OpRuleItem, OpRuleItemCheckListViewModel>();
|
|
|
cfg.CreateMap<OpSeaeRunBill, RunBillEditViewModel>()
|
|
|
.ForMember(x => x.RUNTIME, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.RUNTIME.HasValue ? d.RUNTIME.Value.ToString("yyyy-MM-dd HH:mm:ss") : "");
|
|
|
});
|
|
|
cfg.CreateMap<RunBillEditViewModel, OpSeaeRunBill>();
|
|
|
cfg.CreateMap<OpSeaeRunBill, RunBillListViewModel>()
|
|
|
.ForMember(x => x.RUNTIME, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.RUNTIME.HasValue ? d.RUNTIME.Value.ToString("yyyy-MM-dd HH:mm:ss") : "");
|
|
|
})
|
|
|
.ForMember(x => x.STATUS, m =>
|
|
|
{
|
|
|
m.MapFrom(d => EnumExt.GetDescription((OpSeaeRunBillStatus)Enum.Parse(typeof(OpSeaeRunBillStatus), d.STATUS), true));
|
|
|
})
|
|
|
.ForMember(x => x.CREATETIME, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.CREATETIME.HasValue ? d.CREATETIME.Value.ToString("yyyy-MM-dd HH:mm:ss") : "");
|
|
|
});
|
|
|
|
|
|
cfg.CreateMap<DispInfoClient, DispInfoClientRegistViewModel>();
|
|
|
cfg.CreateMap<DispInfoClientRegistViewModel, DispInfoClient>();
|
|
|
cfg.CreateMap<DispInfoClient, DispInfoClientAuditViewModel>()
|
|
|
.ForMember(x => x.AuditStatsName, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.IsAudit ? "已审核" : "未审核");
|
|
|
});
|
|
|
cfg.CreateMap<BookingUser, BookingUserViewModel>()
|
|
|
.ForMember(x => x.IDENTIFICATION_STATE_STR, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.IDENTIFICATION_STATE == "NotIndent" ? "未提交" : (d.IDENTIFICATION_STATE == "Identifying" ? "待审核" : (d.IDENTIFICATION_STATE == "Indentified" ? "已通过" : "已驳回")));
|
|
|
})
|
|
|
.ForMember(x => x.STATUS_STR, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.STATUS == "Active" ? "激活" : "禁用");
|
|
|
})
|
|
|
.ForMember(x => x.REG_TIME, m =>
|
|
|
{
|
|
|
m.MapFrom(d => d.REG_TIME.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
});
|
|
|
cfg.CreateMap<OP_SEAE_ORDER, OrderEditViewModel>()
|
|
|
.ForMember(x => x.ISCONTAINERSOC, map => map.MapFrom(t => t.ISCONTAINERSOC == "1" ? true : false))
|
|
|
.ForMember(x => x.ETD, map => map.MapFrom(t => t.ETD.HasValue ? t.ETD.Value.ToString("yyyy-MM-dd") : ""))
|
|
|
.ForMember(x => x.MODIFYTIME, map => map.MapFrom(t => t.MODIFYTIME.HasValue ? t.MODIFYTIME.Value.Ticks : 0))
|
|
|
;
|
|
|
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private IConnection mqConn;
|
|
|
private const string ExchangeName = "output";
|
|
|
|
|
|
#region 接收大简云订舱业务
|
|
|
private void DoReceiveDjydc() {
|
|
|
|
|
|
var RecMqUri = ConfigurationManager.AppSettings["ReceiveMQUri"];
|
|
|
var 消费队列数据 = true;
|
|
|
|
|
|
ConnectionFactory factory = new ConnectionFactory();
|
|
|
factory.Uri = RecMqUri;
|
|
|
|
|
|
mqConn = factory.CreateConnection();
|
|
|
|
|
|
IModel modelDingCang = mqConn.CreateModel();
|
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(ExchangeName))
|
|
|
modelDingCang.ExchangeDeclare(ExchangeName, ExchangeType.Direct);
|
|
|
|
|
|
var QueuePrefix_DingCang = ConfigurationManager.AppSettings["QueuePrefix_DingCang"];
|
|
|
var DjydcCompanyid = ConfigurationManager.AppSettings["DjydcCompanyid"];
|
|
|
|
|
|
modelDingCang.QueueDeclare($"{QueuePrefix_DingCang}{DjydcCompanyid}", false, false, false, null);
|
|
|
|
|
|
var consumerDingCang = new EventingBasicConsumer(modelDingCang);
|
|
|
consumerDingCang.Received += (ch, ea) =>
|
|
|
{
|
|
|
var body = ea.Body;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
////不压缩
|
|
|
//var strBody = Encoding.UTF8.GetString(body.ToArray());
|
|
|
|
|
|
////压缩
|
|
|
|
|
|
var strBodyZip = Encoding.UTF8.GetString(body.ToArray());
|
|
|
//logger.Debug($"收到大简云订舱输出压缩数据:{strBodyZip}");
|
|
|
|
|
|
//var strBody = Areas.CommMng.DAL.BasicDataRefDAL.Decompress(strBodyZip);
|
|
|
//测试数据不需解压缩
|
|
|
var strBody = strBodyZip;
|
|
|
//logger.Debug($"收到大简云订舱输出数据:{strBody}");
|
|
|
|
|
|
//导出到东胜6
|
|
|
//if(strBody.Contains("TAHT30633700"))
|
|
|
DSWeb.Areas.CommMng.DAL.MqWorkDAL.DingCangToDS7(strBody);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
var excep = ex;
|
|
|
while (excep != null)
|
|
|
{
|
|
|
//logger.Error(excep.Message);
|
|
|
//logger.Error(excep.StackTrace);
|
|
|
|
|
|
excep = excep.InnerException;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
};
|
|
|
//第二个参数控制【是否消费掉队列里的数据】
|
|
|
modelDingCang.BasicConsume($"{QueuePrefix_DingCang}{DjydcCompanyid}", 消费队列数据, consumerDingCang);
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
} |