public void ProcessOutbound(DssOutboundControl dssOutboundControl) { log.Info("Start process outbound."); this.Initital_DBCache(); #region Initailize this._dssObjectMapping = this.dssObjectMappingMgr.GetAllDssObjectMapping(); #endregion string outFolder = dssOutboundControl.OutFolder; //string serviceName = dssOutboundControl.ServiceName; string archiveFolder = dssOutboundControl.ArchiveFolder; string tempFolder = dssOutboundControl.TempFolder; //string encoding = dssOutboundControl.FileEncoding; string encoding = Encoding.Default.WebName; string filePrefix = this.GetFilePrefix(dssOutboundControl); #region 初始化本地目录 outFolder = outFolder.Replace("\\", "/"); if (!outFolder.EndsWith("/")) { outFolder += "/"; } if (!Directory.Exists(outFolder)) { Directory.CreateDirectory(outFolder); } archiveFolder = archiveFolder.Replace("\\", "/"); if (!archiveFolder.EndsWith("/")) { archiveFolder += "/"; } if (!Directory.Exists(archiveFolder)) { Directory.CreateDirectory(archiveFolder); } tempFolder = tempFolder.Replace("\\", "/"); if (!tempFolder.EndsWith("/")) { tempFolder += "/"; } if (Directory.Exists(tempFolder)) { Directory.Delete(tempFolder, true); } Directory.CreateDirectory(tempFolder); #endregion #region 抽取数据 log.Info("Begin to extract data:extsyscode:" + dssOutboundControl.ExternalSystem.Code + ",extobjcode:" + dssOutboundControl.ExternalObjectCode + ",service:" + dssOutboundControl.ServiceName); IList<DssExportHistory> dataList = this.GetHisList(dssOutboundControl.Id); #region 缓存数据 IList<DssExportHistory> dssExportHistoryList = ExtractOutboundData(dssOutboundControl); this.ObjectMapping(dssExportHistoryList); dssExportHistoryList = this.FilterList(dssExportHistoryList); if (dssExportHistoryList != null && dssExportHistoryList.Count > 0) { this.CreateDssExportHistory(dssExportHistoryList, dssOutboundControl); dataList = dataList.Concat(dssExportHistoryList).ToList(); log.Info("DssExportHistory count:" + dataList.Count + ",update new mark:" + dssOutboundControl.Mark); } #endregion #endregion #region 循环处理抽取数据 if (dataList != null && dataList.Count > 0) { //if (dssOutboundControl.Id != 7) //{ #region 非iss-so foreach (DssExportHistory dssExportHistory in dataList) { try { object obj = null; try { obj = GetOutboundData(dssExportHistory); } catch (BusinessErrorException ex) { log.Warn("Get no outbound data:", ex); continue; } if (obj == null) continue; #region 对象转换为数组 object o = Serialize(obj); DateTime effDate = (DateTime)((object[])o)[0]; string[][] data = (string[][])((object[])o)[1]; #endregion #region 抽取数据导入文件 string transNo = this.GetTransNumber(dssOutboundControl, filePrefix, effDate); //modified by [email protected] //2012/5 string location = dssExportHistory.Location; bool partyfrom = dssExportHistory.PartyFrom == "1001" ? true : false; bool partyto = dssExportHistory.PartyTo == "1001" ? true : false; //string region = locationMgr.LoadLocation(location).Region.Code; string bj_region = partyfrom || partyto == true ? "BJ" : ""; string fileName = this.GetFileName(dssOutboundControl, filePrefix, transNo, bj_region); //modified end StreamWriter streamWriter = new StreamWriter(tempFolder + fileName, false, Encoding.GetEncoding(encoding)); FlatFileWriter flatFileWriter = new FlatFileWriter(streamWriter, Environment.NewLine, "|"); flatFileWriter.Write(data); flatFileWriter.Dispose(); #endregion #region 文件移至目录 try { File.Copy(tempFolder + fileName, archiveFolder + fileName); //备份目录 File.Move(tempFolder + fileName, outFolder + fileName); //导出目录 #region 更新导出标记 dssExportHistory.IsActive = false; dssExportHistory.TransNo = transNo; dssExportHistoryMgr.UpdateDssExportHistory(dssExportHistory); #endregion } catch (Exception ex) { log.Error("Create export file error.", ex); if (File.Exists(archiveFolder + fileName)) { File.Delete(archiveFolder + fileName); } if (File.Exists(outFolder + fileName)) { File.Delete(outFolder + fileName); } } #endregion } catch (Exception ex) { log.Error("Export data error.", ex); break;//2012-10-24 发生错误执行下一任务 djin } } #endregion //} //else //{ // var dataListGroup = (from i in dataList select i.DefinedString1).Distinct().ToList(); // foreach (var i in dataListGroup) // { // IList<string[][]> outString = new List<string[][]>(); // var result = (from x in dataList where x.DefinedString1 == i select x).ToList(); // #region iss-so // if (result != null && result.Count > 0) // { // foreach (DssExportHistory dssExportHistory in result) // { // try // { // object obj = null; // try // { // obj = GetOutboundData(dssExportHistory); // } // catch (BusinessErrorException ex) // { // log.Warn("Get no outbound data:", ex); // continue; // } // if (obj == null) // continue; // #region 对象转换为数组 // object o = Serialize(obj); // string[][] data = (string[][])((object[])o)[1]; // outString.Add(data); // #endregion // } // catch (Exception ex) // { // log.Error("Export data error.", ex); // break;//2012-10-24 发生错误执行下一任务 djin // } // } // #region 抽取数据导入文件 // try // { // DateTime effDate = (DateTime)((object[])Serialize(GetOutboundData(result[0])))[0]; // string transNo = this.GetTransNumber(dssOutboundControl, filePrefix, effDate); // //modified by [email protected] // //2012/5 // string location = result[0].Location; // bool partyfrom = result[0].PartyFrom == "1001" ? true : false; // bool partyto = result[0].PartyTo == "1001" ? true : false; // //string region = locationMgr.LoadLocation(location).Region.Code; // string bj_region = partyfrom || partyto == true ? "BJ" : ""; // string fileName = this.GetFileName(dssOutboundControl, filePrefix, transNo, bj_region); // fileName = fileName.Split(new char[] { '.' })[0].TrimEnd(new char[] { '1' }) +"."+ fileName.Split(new char[] { '.' })[1]; // //modified end // StreamWriter streamWriter = new StreamWriter(tempFolder + fileName, false, Encoding.GetEncoding(encoding)); // FlatFileWriter flatFileWriter = new FlatFileWriter(streamWriter, Environment.NewLine, "|"); // flatFileWriter.WriteWithNewLine(((string[][])(outString[0]))[0]); // foreach (string[][] str in outString) // { // flatFileWriter.WriteWithNewLine(str[1]); // } // flatFileWriter.Dispose(); // #endregion // #region 文件移至目录 // try // { // File.Copy(tempFolder + fileName, archiveFolder + fileName); //备份目录 // File.Move(tempFolder + fileName, outFolder + fileName); //导出目录 // #region 更新导出标记 // foreach (DssExportHistory dssExportHistory in dataList) // { // dssExportHistory.IsActive = false; // dssExportHistory.TransNo = transNo; // dssExportHistoryMgr.UpdateDssExportHistory(dssExportHistory); // } // #endregion // } // catch (Exception ex) // { // log.Error("Create export file error.", ex); // if (File.Exists(archiveFolder + fileName)) // { // File.Delete(archiveFolder + fileName); // } // if (File.Exists(outFolder + fileName)) // { // File.Delete(outFolder + fileName); // } // } // #endregion // } // catch (Exception ex) // { // continue; // } // #endregion // } // } //} } else { log.Info("No data export."); } #endregion this.Initital_DBCache(); log.Info("Start process outbound successful."); }
private void CreateFile(KPOrder kpOrder) { //随便写写,谁叫他们不给钱的 #region 抽取数据导入文件 string fileFolder = "D:\\Dss\\out\\"; string fileName = "SCONIT_QAD_" + DateTime.Now.ToString("yyyyMMddhhmmss") + "_KPCONF.REQ"; string[] line1 = new string[] { "1", kpOrder.QAD_ORDER_ID, DateTime.Now.ToShortDateString() }; string[][] data = new string[][] { line1 }; StreamWriter streamWriter = new StreamWriter(fileFolder + fileName, false, Encoding.GetEncoding(Encoding.Default.WebName)); FlatFileWriter flatFileWriter = new FlatFileWriter(streamWriter, Environment.NewLine, "|"); flatFileWriter.Write(data); flatFileWriter.Dispose(); #endregion }