/// <summary> /// 当试验次数重复时候,是更新逻辑这里为true,那么注意一下表名,用临时表名 /// </summary> /// <returns></returns> private bool checkTestTimes() { // 判断本次试验,有没有解析器执行过 if (DataLogDAL.getList(this.taskInfo.id).Count(it => Convert.ToInt32(it.Version) == this.times) > 0) { Structure st = structList.FirstOrDefault(it => it.Comments == System.Configuration.ConfigurationManager.AppSettings["pk"]); if (st != null) { this.dataScriptRule.DesBusinessPk = st.ColumnName; tableName += "_" + DateTime.Now.Millisecond.ToString(); if (tableName.Length > 30) { tableName = tableName.Remove(0, tableName.Length - 29); } TableDAL.createtempTable(this.dataScriptRule.DesTable, tableName); TableDAL.AddIndex(tableName, string.Format("{0},TASKTIMES,PROJECTID", st.ColumnName)); } return(true); } return(false); }
public void run() { SendMessageEvent(string.Format("开始处理数据文件:{0}", sourceFile)); DateTime begin = DateTime.Now, end = DateTime.Now; this.tableName = this.dataScriptRule.DesTable; this.isUpdate = checkTestTimes(); // 判断源表是否存在 if (TableDAL.getTableStructure(this.dataScriptRule.DesTable).Count == 0) { // 源表不存在 log.Error(string.Format("BetchLogic > run > 目标表 [ {0} ] 不存在", this.dataScriptRule.DesTable)); SendMessageEvent(false, string.Format("目标表 [ {0} ] 不存在", this.dataScriptRule.DesTable)); SendCompleteEvent("导入失败"); return; } // 写入导入数据日志 DataLog dataLog = createLog(0, System.IO.Path.GetFileName(sourceFile)); // 上传文件 //WebHelper.uploadFile(sourceFile, dataLog.FID, TaskCenter.TaskID); // 一个处理半物力试验数据的逻辑 uploadFile(); end = DateTime.Now; SendMessageEvent(string.Format("上传数据文件,耗时:{0}秒", (end - begin).TotalSeconds)); begin = DateTime.Now; string fileType = System.IO.Path.GetExtension(this.sourceFile); // 判断本次试验,有没有解析器执行过, 创建临时表 if (isUpdate) { Structure st = structList.FirstOrDefault(it => it.Comments == System.Configuration.ConfigurationManager.AppSettings["pk"]); if (st != null) { tableName += "_" + DateTime.Now.Millisecond.ToString(); if (tableName.Length > 30) { tableName = tableName.Remove(0, tableName.Length - 29); } TableDAL.createtempTable(dataScriptRule.DesTable, tableName); log.Info(string.Format("BetchLogic > run > 本次为更新操作,创建临时表:{0}", tableName)); TableDAL.AddIndex(tableName, string.Format("{0},TASKTIMES,PROJECTID", st.ColumnName)); } } bool inputOk = false; string result = "导入成功!"; switch (fileType) { case ".xls": case ".xlsx": inputOk = xls2db(); break; case ".txt": case ".dat": inputOk = txt2db(); break; case ".mdb": inputOk = acc2db(); break; } if (inputOk) { if (isUpdate) { result = updateDbByID(); } SendCompleteEvent(result); } else { if (isUpdate) { TableDAL.DropTable(tableName); } } end = DateTime.Now; SendMessageEvent(string.Format("数据导入,耗时:{0}秒", (end - begin).TotalSeconds)); }