/// <summary> /// 新增任务日志 /// </summary> /// <param name="data">任务日志实体</param> /// <returns></returns> public ResultData TaskLogAdd(string data) { SysTaskLog sysTaskLog = Utils.Deserialize <SysTaskLog>(data); MSSQLADODAL.SetConnection(Utility.DBFxtLoan); int flag = CAS.DataAccess.DA.BaseDA.InsertFromEntity <SysTaskLog>(sysTaskLog); if (flag > 0) { return(Utility.GetObjJson(1, "Success")); } return(Utility.GetObjJson(0, "")); }
void StartRun(SystemTask systemTask) { bool isSuspend = false; if (systemTask.Status.Equals(2)) { isSuspend = true; } BackgroundWorkerTimer bwTimer = new BackgroundWorkerTimer(); #region BackgroundWorkerTimer 任务 bwTimer.Runing += (s, e) => { CustomEventArgs customEventArgs = ((CustomEventArgs)e); SystemTask doSystemTask = customEventArgs.Argument as SystemTask; int index = -1; index = doSystemTask.RowObject.Index; if (customEventArgs.RunComplete != null && customEventArgs.RunComplete.Cancelled)//取消 { //e.Cancel = true; //break; } else if (customEventArgs.RunComplete != null && customEventArgs.RunComplete.Error != null)//错误 { } else//成功或者继续执行 { string strGet = string.Empty; if (doSystemTask.TaskType.Equals(1)) { #region 估 List <DataCollateral> list = customEventArgs.ListObject as List <DataCollateral>; strGet = GetDownString(doSystemTask.Url2.Replace("{id}", list[customEventArgs.Index].Id.ToString())); if (!Utils.IsNullOrEmpty(strGet) && Utils.GetJObjectValue(strGet, "Type").Equals("1"))//成功 { doSystemTask.SuccessCount = IntNull(doSystemTask.SuccessCount); } else//失败 { doSystemTask.FailureCount = IntNull(doSystemTask.FailureCount); SysTaskLog sysTaskLog = new SysTaskLog() { TaskId = doSystemTask.Id, Message = Utils.GetJObjectValue(strGet, "Message") }; SendString(GetUrl("API/FxtTask.svc/TLC/"), new { data = Utils.Serialize(sysTaskLog) }); } #endregion } else if (doSystemTask.TaskType.Equals(0)) { #region 押品拆分 object[,] arrayItem = customEventArgs.ListObject as object[, ]; ExcelHelper excelHelper = customEventArgs.ExcelHelper as ExcelHelper; object objCollateral = excelHelper.TaskExcelStandardization(arrayItem, customEventArgs.StandardizationHeader, customEventArgs.Index); DataCollateral model = objCollateral as DataCollateral; if (model != null) { model.UploadFileId = doSystemTask.UploadFileId; model.BankId = doSystemTask.BankId; model.BankProjectId = doSystemTask.BankProjectId; model.Status = 0;//默认什么都没有 strGet = SendString(GetUrl("API/FxtTask.svc/CreateCollateral/"), new { data = Utils.Serialize(model) }); } //!model.Id.Equals(0) 是否已存在拆分过的押品 if ((!Utils.IsNullOrEmpty(strGet) && Utils.GetJObjectValue(strGet, "Type").Equals("1")) || (model != null && !model.Id.Equals(0))) { doSystemTask.SuccessCount = IntNull(doSystemTask.SuccessCount); } else if ((!Utils.IsNullOrEmpty(strGet) && Utils.GetJObjectValue(strGet, "Type").Equals("0")) || model == null) { doSystemTask.FailureCount = IntNull(doSystemTask.FailureCount); SysTaskLog sysTaskLog = new SysTaskLog() { TaskId = doSystemTask.Id, Message = objCollateral.ToString() }; //失败了就记录日志 SendString(GetUrl("API/FxtTask.svc/TLC/"), new { data = Utils.Serialize(sysTaskLog) }); } #endregion } //是否下标小于0 if (!index.Equals(-1)) { dgvTack.Rows[index].Cells["SuccessCount"].Value = doSystemTask.SuccessCount; dgvTack.Rows[index].Cells["FailureCount"].Value = doSystemTask.FailureCount; } SendString(GetUrl("API/FxtTask.svc/TUSF/"), new { data = Utils.Serialize(doSystemTask) }); if (customEventArgs.Index == doSystemTask.Count - 1 && doSystemTask != null) { string strSuccess = SendString(doSystemTask.Url3, new { data = Utils.Serialize(doSystemTask) }); if (Utils.GetJObjectValue(strSuccess, "Type").Equals("1")) { if (!doSystemTask.RowObject.Index.Equals(-1)) { doSystemTask.RowObject.Cells["RunStatus"].Value = "成功"; } Thread.Sleep(3000); //因为线程,所以异步操作 this.Invoke(new EventHandler((object sender, EventArgs es) => { if (!index.Equals(-1)) { dgvTack.Rows.Remove(dgvTack.Rows[index]); } })); //if (listExists.Where(ie => ie.Equals(doSystemTask.Id)).Any()) //{ // listExists.Remove(doSystemTask.Id); //} //var taskControl = listTaskControl.Where(item => item.SystemTask.Id.Equals(doSystemTask.Id)); //if (taskControl.Any()) //{ // listTaskControl.Remove(taskControl.FirstOrDefault()); //} } } } }; #endregion bool isAdd = false; if (systemTask.TaskType.Equals(0) && !Utils.IsNullOrEmpty(systemTask.FileUrl))//拆分 { ExcelHelper excelHelper = new ExcelHelper(GetUrl(systemTask.FileUrl, "excelParentUrl")); string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Homologous/ExcelToModel.xml"); Dictionary <int, string> listHeader = excelHelper.TaskExcelColumns(path); //excelHelper.TaskExcelStandardization(excelHelper.TaskReadExcel(), listHeader); object[,] arrayItem = excelHelper.TaskReadExcel(); bwTimer.count = arrayItem.GetLength(0); systemTask.Count = arrayItem.GetLength(0); bwTimer.Set(systemTask, arrayItem, listHeader, excelHelper); isAdd = true; } else if (systemTask.TaskType.Equals(1))//复估 { string strDown = GetDownString(systemTask.Url1.Replace("{id}", systemTask.UploadFileId.ToString())); List <DataCollateral> listData = Utils.Deserialize <List <DataCollateral> >(Utils.GetJObjectValue(strDown, "Data")); if (listData != null) { bwTimer.count = listData.Count; systemTask.Count = bwTimer.count; } bwTimer.Set(systemTask, listData); isAdd = true; } if (isAdd) { systemTask.RowObject.Cells["Count"].Value = systemTask.Count; bwTimer.Start(isSuspend); listTaskControl.Add(new TaskControl() { SystemTask = systemTask, BackgroundWorker = bwTimer }); } }