public PolicyRecord GetLastUploadRecored(PurchaserType purchaser, UploadType uType) { PolicyRecord rec = new PolicyRecord(); try { string strSql = "select top 1 LastUpdateTime,LastPolicyId from UpLoadRecord where IsEnabled=1 and NotifyResult=1 and UploadType='" + uType.ToString() + "' and PurchaserType='" + purchaser.ToString() + "' and IsEnabled =1 ORDER BY CreateTime DESC"; SqlDataReader reader = DbHelperSQL.ExecuteReader(strSql); bool flag = false; while (reader.Read()) { flag = true; rec.LastPolicyId = long.Parse(reader["LastPolicyId"].ToString()); rec.LastUpdateTime = Convert.ToDateTime(reader["LastUpdateTime"]); } if (!flag) { rec = new PolicyRecord() { LastUpdateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 0:00:00"), LastPolicyId = 0 }; } reader.Close(); reader = null; } catch (Exception ex) { rec = new PolicyRecord() { LastUpdateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 0:00:00"), LastPolicyId = 0 }; } return(rec); }
public void DeleteModel(PurchaserType purchaser) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from RealTimeUploadRecord where Purchaser = '" + purchaser.ToString() + "' "); DbHelperSQL.ExecuteSql(strSql.ToString()); }
/* * /// <summary> * /// 分页获取数据列表 * /// </summary> * public DataSet GetList(int PageSize,int PageIndex,string strWhere) * { * SqlParameter[] parameters = { * new SqlParameter("@tblName", SqlDbType.VarChar, 255), * new SqlParameter("@fldName", SqlDbType.VarChar, 255), * new SqlParameter("@PageSize", SqlDbType.Int), * new SqlParameter("@PageIndex", SqlDbType.Int), * new SqlParameter("@IsReCount", SqlDbType.Bit), * new SqlParameter("@OrderType", SqlDbType.Bit), * new SqlParameter("@strWhere", SqlDbType.VarChar,1000), * }; * parameters[0].Value = "RealTimeUploadRecord"; * parameters[1].Value = "Id"; * parameters[2].Value = PageSize; * parameters[3].Value = PageIndex; * parameters[4].Value = 0; * parameters[5].Value = 0; * parameters[6].Value = strWhere; * return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds"); * }*/ #endregion Method #region Extention Method /// <summary> /// 得到一个对象实体 /// </summary> public RealTimeUploadRecord GetModel(PurchaserType purchaser) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,LastUpdateTime,IsLock,LockPerson,Remark,CreateTime from RealTimeUploadRecord where Purchaser = '" + purchaser.ToString() + "' order by CreateTime desc "); RealTimeUploadRecord model = new RealTimeUploadRecord(); DataSet ds = DbHelperSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = new Guid(ds.Tables[0].Rows[0]["Id"].ToString()); } model.LastUpdateTime = ds.Tables[0].Rows[0]["LastUpdateTime"].ToString(); if (ds.Tables[0].Rows[0]["IsLock"].ToString() != "") { model.IsLock = int.Parse(ds.Tables[0].Rows[0]["IsLock"].ToString()); } model.LockPerson = ds.Tables[0].Rows[0]["LockPerson"].ToString(); model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString(); if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString()); } return(model); } else { return(null); } }
public SearchPolicyRequest FillSearchPolicyRequest() { try { StringBuilder sqlWhere = new StringBuilder(); sqlWhere.Append(" 1=1 "); if (this.txtDptCode.Text.Length > 0) { sqlWhere.Append(" and pd.DptCity like '%" + this.txtDptCode.Text + "%' ");//DptCity = " + this.txtDptCode.Text } if (this.txtArrCode.Text.Length > 0) { sqlWhere.Append(" and pd.ArrCity like '%" + this.txtArrCode.Text + "%'"); } if (this.txtSeatCode.Text.Length > 0) { sqlWhere.Append(" and pd.Seat like '%" + this.txtSeatCode.Text + "%'"); } if (this.txtCommsionPointMin.Text.Length > 0) { sqlWhere.Append(" and pd.CommisionPoint >= " + this.txtCommsionPointMin.Text); } if (this.txtCommsionPointMax.Text.Length > 0) { sqlWhere.Append(" and pd.CommisionPoint <= " + this.txtCommsionPointMax.Text); } if (this.txtMoneyMin.Text.Length > 0) { sqlWhere.Append(" and pd.CommisionMoney >= " + this.txtMoneyMin.Text); } if (this.txtMoneyMax.Text.Length > 0) { sqlWhere.Append(" and pd.CommisionMoney <= " + this.txtMoneyMax.Text); } if (this.txtPolicyId.Text.Length > 0) { sqlWhere.Append(" and ps.Id = " + this.txtPolicyId.Text); } if (!this.cmbAirCode.SelectedItem.ToString().Contains("全部")) { //if (this.cmbAirCode.SelectedItem.ToString().ToUpper() == "G5") //{ // sqlWhere.Append("id IN(SELECT TOP 1 id from dbo.PolicyDetail WHERE CommisionPoint=( SELECT MAX(CommisionPoint) FROM dbo.PolicyDetail WHERE AirlineCode='G5' )UNIONSELECT TOP 1 id FROM dbo.PolicyDetail where Seat =(SELECT TOP 1 Seat FROM dbo.PolicyDetail WHERE AirlineCode='G5' GROUP BY Seat ORDER BY MAX(LEN(Seat)) desc))"); //} //else //{ sqlWhere.Append(" and pd.AirlineCode = '" + this.cmbAirCode.SelectedItem.ToString() + "'"); //} } UploadType uType = new UploadType(); switch (cmbUploadType.SelectedItem.ToString()) { case "全量上传": uType = UploadType.FullUpload; break; case "增量上传": uType = UploadType.Incremental; break; default: uType = UploadType.FullUpload; break; } PurchaserType pType = new PurchaserType(); switch (cmbPlatform.SelectedItem.ToString()) { case "淘宝": pType = PurchaserType.TaoBao; break; case "去哪儿": pType = PurchaserType.Qunar; break; default: pType = PurchaserType.Qunar; break; } int pageSize = 100; if (this.txtPageSize.Text.Length > 0) { pageSize = int.Parse(this.txtPageSize.Text); } decimal addCommsionPoint = 0; if (this.txtAddCommsionPoint.Text.Length > 0) { addCommsionPoint = decimal.Parse(this.txtAddCommsionPoint.Text); } decimal addMoney = 0; if (this.txtAddMoney.Text.Length > 0) { addMoney = decimal.Parse(this.txtAddMoney.Text); } QunarPolicyType policyType = new QunarPolicyType(); switch (cmbPolicyType.SelectedItem.ToString()) { case "单程普通政策": policyType = QunarPolicyType.COMMON; break; case "单程预付政策": policyType = QunarPolicyType.PREPAY; break; default: break; } if (this.txtUploadName.Text.Length <= 0) { MessageBox.Show("上传和查询人员姓名不能为空!"); return(null); } SearchPolicyRequest request = new SearchPolicyRequest() { PageSize = pageSize, SqlWhere = sqlWhere.ToString(), UType = uType, pType = pType, CommisionMoney = addMoney, CommsionPoint = addCommsionPoint, PolicyType = policyType, OperName = this.txtUploadName.Text }; return(request); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } }
public static List <Policies> SplitPolicy(PurchaserType pType, List <Policies> lstPolicies, List <string> lstQunarCodes, PoliciesType policyType) { SplitPolicyResponse splitResponse = new SplitPolicyResponse(); int maxArrCityCount = 25; int maxDptCityCount = 1; int maxFlightInCount = 25; int splitMaxTaskCount = 10; int splitPerTaskMaxCount = 50; int maxSeatCount = 29; switch (policyType) { case PoliciesType.COMMON: //普通政策 break; case PoliciesType.CUSTOMER: //包机切位政策 break; case PoliciesType.LOWPRICE: //特价政策 break; case PoliciesType.PREPAY: //预付政策 { maxSeatCount = 1; maxArrCityCount = 1; } break; case PoliciesType.ROUNDALL: //往返所有类型政策 break; case PoliciesType.ROUNDPREPAY: //往返预付政策 break; case PoliciesType.ROUNDSPECIAL: //往返特价政策 break; case PoliciesType.SINGLEALL: //单程所有类型政策 break; case PoliciesType.APPLY: //申请政策 break; default: break; } switch (pType) { case PurchaserType.Qunar: { QunarSplitPolicyRequest splitQunarRequst = new QunarSplitPolicyRequest() { MaxArrCityCount = maxArrCityCount, //最大支持出发城市个数 MaxDptCityCount = maxDptCityCount, //最大支持出发城市个数 MaxFlightInCount = maxFlightInCount, //包含航班最大个数 SplitMaxTaskCount = splitMaxTaskCount, //最大可开启任务数量 SplitPerTaskMaxCount = splitPerTaskMaxCount, //每个task处理的数量 StorageMaxTaskCount = 10, //最多可开启存储的线程 StoragePerTaskMaxCount = 1000, //每个存储线程最多可处理的数量 MaxSeatCount = maxSeatCount, Purchaser = PurchaserType.Qunar, //供应商类型 Policies = lstPolicies, //政策数据 LstQunarCodes = lstQunarCodes, PolicyType = policyType }; IPolicySplit policySplit = new QunarPolicySplit(); //去哪儿拆分政策 //拆分政策 splitResponse = policySplit.PolicySplit(splitQunarRequst); if (splitResponse.ErrCode == ResultType.Failed) { // MessageBox.Show("拆分政策失败:" + splitResponse.ErrMsg); return(new List <Policies>()); } } break; case PurchaserType.TaoBao: break; default: break; } return(splitResponse.PoliciesData); }
public EmptyResponse UpdateNotify(UpdateNotifyRequest request) { try { UpLoadRecordLib recLib = new UpLoadRecordLib(); UploadPolicyRecordLib recPolicyLib = new UploadPolicyRecordLib(); PolicySyncRecLib syncLib = new PolicySyncRecLib(); request.UpdateStatusId = request.UpdateStatusId.Replace("\"", "").Replace("\\", ""); UpLoadRecord rec = recLib.GetModel(int.Parse(request.UpdateStatusId)); if (rec == null) { return(new EmptyResponse { ErrCode = PolicyService.Enums.ResultType.Failed, ErrMsg = "未找到此上传的记录!" }); } if (rec.OperName.ToLower() == "system") { if ((SuccessStatus)request.NotifyResult == SuccessStatus.Success) { recPolicyLib.BlukyUpdatePolicy(rec.Id.ToString(), true); recLib.Delete(rec.Id);//删除 } else { recPolicyLib.BlukyUpdatePolicy(rec.Id.ToString(), false); recLib.Delete(rec.Id);//删除 } return(new EmptyResponse { ErrCode = PolicyService.Enums.ResultType.Sucess }); } PurchaserType Purchaser = (PurchaserType)Enum.Parse(typeof(PurchaserType), rec.PurchaserType); UploadType uType = (UploadType)Enum.Parse(typeof(UploadType), rec.UploadType); #region 1.保存文件记录 if (request.IsSucess) { string timeAndId = Convert.ToDateTime(rec.LastUpdateTime).ToString("yyyy-MM-dd HH:mm:ss.fff") + "|" + rec.LastPolicyId.ToString(); // CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\" + System.Guid.NewGuid() + ".txt", "读取最后记录"+timeAndId);//创建文件 // File.WriteAllText("e://1.txt", timeAndId); string name = uType == UploadType.FullUpload ? rec.PurchaserType + "\\" + rec.PurchaserType + "FullPolicyRecLog" : rec.PurchaserType + "\\" + rec.PurchaserType + "IncrementPolicyRecLog"; CoreHelper.SaveLastUpTimeAndId(timeAndId, name); // CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\" + System.Guid.NewGuid() + ".txt", "保存最后记录成功");//创建文件 } #endregion #region 2.更新表中记录 rec.ResponseParams = request.ResponseParams; rec.NotifyResult = (int)request.NotifyResult; rec.FailedCount = request.NotifyResult == SuccessStatus.Failed ? rec.FailedCount + 1 : rec.FailedCount; rec.CompleteTime = DateTime.Now; rec.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd") + " 0:00:00"; rec.LastPolicyId = "0"; bool r = recLib.Update(rec); if (!r) { return(new EmptyResponse { ErrCode = PolicyService.Enums.ResultType.Failed, ErrMsg = "更新记录失败!" }); } bool flag = false; if (request.NotifyResult == SuccessStatus.Failed || request.NotifyResult == SuccessStatus.Other) { flag = false; } else { flag = true; } recPolicyLib.BlukyUpdatePolicy(rec.Id.ToString(), flag); #endregion #region 3.批量更新已经上传完成的政策 if (request.IsSucess) { string selectSql = ""; int totalCount = 0; List <UploadPolicyRecord> lstUploadIds = recPolicyLib.GetModelList(" UId='" + rec.Id + "'"); List <string> lstAddPolicies = new List <string>(); lstUploadIds.ForEach(x => { lstAddPolicies.Add(x.PolicyId); }); //List<string> lstAddPolicies = rec.Remark.Split(',').ToList(); if (lstAddPolicies.Count > 0) { bool r2 = syncLib.BlukyUpdatePolicyUploaded(lstAddPolicies); if (!r) { return(new EmptyResponse { ErrCode = PolicyService.Enums.ResultType.Failed, ErrMsg = "批量把政策置为已上传失败!" }); } } } #endregion return(new EmptyResponse { ErrCode = PolicyService.Enums.ResultType.Sucess }); } catch (Exception ex) { return(new EmptyResponse { ErrCode = PolicyService.Enums.ResultType.Failed, ErrMsg = JsonConvert.SerializeObject(ex) }); } }