public static void HandlerData() { #region 统计 //分组查询获取昨天的数据值 string sql = ConfigManage.dbConfig.Sql; LogHelper.WriteInfo("查询sql:" + sql); string selectSql = string.Format(sql); DataTable oldData = new DataTable(); try { using (OracleConnection conn = new OracleConnection(ConfigManage.dbConfig.DbConn)) { OracleDataAdapter oda = new OracleDataAdapter(selectSql, conn); oda.Fill(oldData); conn.Dispose(); } } catch (Exception e) { LogHelper.Error(string.Format("查询数据异常,异常信息:{0}", e.ToString())); } DataTable table = oldData.Copy(); if (table.Rows.Count > 0) { LogHelper.WriteInfo(string.Format("获得数据{0}条", oldData.Rows.Count.ToString())); if (ConfigManage.dbConfig.DataType == "1") { //转成对象 // string json=JsonConvert.SerializeObject(table); List <IllegalVehicleReal> list = null; try { list = DataTableListHelper.ToList <IllegalVehicleReal>(table); } catch (Exception e) { } // List<IllegalVehicleReal> list = JsonConvert.DeserializeObject<List<IllegalVehicleReal>>(json); //TableToEntity<IllegalVehicleReal>(table); //发送mq foreach (IllegalVehicleReal item in list) { item.Remark += "CDP流程重走."; item.Status = "0000"; item.ProcessId = Guid.NewGuid().ToString("N"); dynamic obj = new { DataType = "IllegalVehicle", Data = item }; string value = JsonConvert.SerializeObject(obj); string routingkey = ConfigManage.dbConfig.RoutingKey + "." + item.SpottingId + "." + item.DirectionId + "." + item.LaneNo; RabbitMQClient.SendMessage(routingkey, value, false); } } else if (ConfigManage.dbConfig.DataType == "2") { //转成对象 // string json=JsonConvert.SerializeObject(table); List <VehiclePassing> list = null; try { list = DataTableListHelper.ToList <VehiclePassing>(table); } catch (Exception e) { } // List<IllegalVehicleReal> list = JsonConvert.DeserializeObject<List<IllegalVehicleReal>>(json); //TableToEntity<IllegalVehicleReal>(table); //发送mq Parallel.ForEach(list, (item) => { item.Remark += "过车重发."; dynamic obj = new { DataType = "VehiclePassing", Data = item, ErrorCount = 0 }; string value = JsonConvert.SerializeObject(obj); string routingkey = ConfigManage.dbConfig.RoutingKey + "." + item.SpottingId + "." + item.DirectionId + "." + item.LaneNo; RabbitMQClient.SendMessage(routingkey, value, false); }); } } LogHelper.WriteInfo(string.Format("数据转发处理完成")); #endregion }
static void Main(string[] args) { try { Console.Title = "违法数据处理工具"; //if (ConfigManage.dbConfig == null || string.IsNullOrEmpty(ConfigManage.dbConfig.DbConn)) //{ // ConfigForm form = new ConfigForm(); // form.ShowDialog(); //} if (ConfigManage.dbConfig == null || string.IsNullOrEmpty(ConfigManage.dbConfig.DbConn)) { string path = AppDomain.CurrentDomain.BaseDirectory + "\\config.js"; if (!File.Exists(path)) { DbConfig config = new DbConfig() { DbConn = "", Exchange = "", MqAddress = "", Pwd = "", User = "", Sql = "", Port = "" }; string result = JsonConvert.SerializeObject(config, Formatting.Indented); using (FileStream fs = File.Open(path, FileMode.Create)) { char[] charData = result.ToCharArray(); byte[] byData = new byte[charData.Length]; Encoder enc = Encoding.UTF8.GetEncoder(); enc.GetBytes(charData, 0, charData.Length, byData, 0, true); fs.Write(byData, 0, byData.Length); } } System.Diagnostics.Process.Start(@"notepad.exe", AppDomain.CurrentDomain.BaseDirectory + "\\config.js"); //ConfigForm form = new ConfigForm(); //form.ShowDialog(); } log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config")); LogHelper.WriteInfo("启动成功"); LogHelper.WriteInfo(string.Format("可执行命令 config(修改配置文件) reload(应用新的配置文件) start(开始重发)")); Thread thread = new Thread(new ThreadStart(delegate() { IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start(); })); thread.Start(); while (true) { string strCommand = Console.ReadLine(); if (string.IsNullOrEmpty(strCommand)) { continue; } else { strCommand = strCommand.Trim(); if (strCommand.ToUpper() == "CONFIG") { System.Diagnostics.Process.Start(@"notepad.exe", AppDomain.CurrentDomain.BaseDirectory + "\\config.js"); } else if (strCommand.ToUpper() == "RELOAD") { ConfigManage.Reload(); RabbitMQClient.InitMQConnection(); } else if (strCommand.ToUpper() == "START") { Citms.DailyStatistics.DailyStatisticsWork.HandlerData(); } else { LogHelper.Error(string.Format("命令不正确,可执行命令 config(修改配置文件) reload(应用新的配置文件)")); } } } } catch (Exception e) { } }