/// <summary> /// 根据主键查找指定的行,返回指定字段 /// </summary> /// <param name="dBase"></param> /// <param name="id">主键值</param> /// <param name="fields">返回字段</param> /// <returns></returns> public static tbl_troneItem GetRowById(Shotgun.Database.IBaseDataClass2 dBase, int id, string[] fields) { tbl_troneItem m = null; lock (cache.SyncRoot) { m = cache.GetDataByIdx(id); if (m != null) { return(m); } } var q = GetQueries(dBase); m = q.GetRowById(id); cache.InsertItem(m); return(m); }
/// <summary> /// 匹对指令 /// </summary> /// <param name="dBase"></param> /// <param name="m"></param> /// <returns></returns> public static LightDataModel.tbl_troneItem FillToneId(Shotgun.Database.IBaseDataClass2 dBase, Logical.ISMS_DataItem m) { var cmds = LightDataModel.tbl_troneItem.QueryTronesByPort(dBase, m.sp_api_url_id, m.ori_trone); if (cmds == null && cmds.Count() == 0) return null;//没有可用通道 var mMsg = m.ori_order; if (mMsg == null) mMsg = string.Empty; m.trone_id = C_TM_NOT_Order; LightDataModel.tbl_troneItem trone = null; int iCount = 0; foreach (var cmd in cmds) { var cMsg = cmd.orders; if (string.IsNullOrEmpty(cMsg) && string.IsNullOrEmpty(mMsg)) { trone = cmd; iCount++; continue; } if (cmd.match_price) {//无规则指令,直接匹配价格 if (cmd.price == (m.price / 100m)) { trone = cmd; iCount++; continue; } } else if (cmd.is_dynamic) {//模糊指令 var rx = Library.GetRegex(cmd.orders); if (rx.IsMatch(mMsg)) { trone = cmd; iCount++; continue; } } else {//精确指令 if (mMsg.Equals(cMsg, StringComparison.OrdinalIgnoreCase)) { trone = cmd; iCount++; continue; } } } if (iCount == 0) return null; if (iCount > 1) { m.trone_id = C_TM_MULTI_TRONE; return null; } if (m.price > 0) {//SP价格校验 防止配置错 if (trone.price != (m.price / 100m)) { m.trone_id = C_TM_PRICE_NOT_EQUQLS; return null; } } m.trone_id = trone.id; var sp_trone = LightDataModel.tbl_sp_troneItem.GetRowById(dBase, trone.sp_trone_id, null); if (sp_trone == null) return null; m.trone_type = sp_trone.trone_type; if (m is LightDataModel.tbl_mrItem) { var mr = (LightDataModel.tbl_mrItem)m; mr.sp_trone_id = sp_trone.id; if (mr.ivr_time > 20) { m.trone_id = C_IVR_TIME_CFG_ERROR; return null; } else if (mr.ivr_time > 0) { if (m.trone_type != C_IVR_TRONE_TYPE) { //通道类型检查 m.trone_id = C_IVR_TRONE_TYPE_ERROR; return null; } } } return trone; }
private void DoPush(LightDataModel.tbl_troneItem trone) { //throw new NotImplementedException(); if (!_MrItem.IsMatch || trone == null) return; var syncFlag = SyncFlag; if (syncFlag == E_CP_SYNC_MODE.Auto) { if (_MrItem.linkid.IndexOf("test", StringComparison.OrdinalIgnoreCase) != -1) syncFlag = E_CP_SYNC_MODE.ForceHide; else if (_MrItem.linkid.IndexOf("ceshi", StringComparison.OrdinalIgnoreCase) != -1) syncFlag = E_CP_SYNC_MODE.ForceHide; } var logFile = Server.MapPath(string.Format("~/PushLog/{0:yyyyMMdd}.log", DateTime.Today)); var sb = new StringBuilder(250); var apiPush = new HTAPIPusher() { dBase = dBase, Trone = trone, LogFile = logFile, PushFlag = syncFlag, TrackLog = sb }; if (apiPush.LoadCPAPI()) { try { apiPush.PushObject = _MrItem; if (apiPush.DoPush()) return; } #if !DEBUG catch (Exception ex) { Shotgun.Library.SimpleLogRecord.WriteLog("api_push_error", ex.ToString()); } #endif finally { } } var cp = new AutoMapPush(); cp.dBase = dBase; cp.Trone = trone; cp.PushFlag = syncFlag; cp.TrackLog = sb; //cp.UnionUserId = -1; cp.LogFile = logFile; if (!cp.LoadCPAPI()) { WriteTrackLog(sb); return; } cp.PushObject = _MrItem; if (cp.DoPush() && _MrItem.cp_id != 34) { if (_MoItem != null && HasMoTroneOrderId) { _MoItem.syn_flag = _MrItem.syn_flag != 0; _MoItem.trone_order_id = _MrItem.trone_order_id; _MoItem.report_flag = true; try { _MoItem.SaveToDatabase(dBase); } catch { } } return; } if (!cp.IsSuccess) sb.AppendLine(cp.ErrorMesage); WriteTrackLog(sb); }
protected virtual void StartPorcess() { WriteDebug("StartPorcess", false); LightDataModel.tbl_troneItem trone = null; var isms = LoadItem(); if (isms == null) { WriteError("linkid not found"); return; } if (!IsNew) {//update 不同步重复数据 WriteExisted(); return; } WriteDebug("ItemNotExisted", false); isms.ip = Shotgun.Library.Static.GetUserHostAddress(); //isms.orgUrl = GetQuery(); isms.recdate = DateTime.Now; isms.sp_api_url_id = API_URL_Config_Id; isms.sp_id = api.sp_id; //isms.API_Config_Id = API_Config_Id; //isms.linkid= //已经在LoadItem中赋值 string err; if (IsMo) {//MO if (!string.IsNullOrEmpty(api.MoPrice)) isms.price = GetFee(api.MoPrice); err = InsertMO(); MoCopyToMr(); } else {//MR if (!string.IsNullOrEmpty(api.MrPrice)) isms.price = GetFee(api.MrPrice); MoCopyToMr(); err = InsertMR(); } if (string.IsNullOrEmpty(isms.ori_trone) && U2DMap.ContainsKey("ori_trone")) {//虚似端口 if (C_VIRTUAL_PORT.Equals(U2DMap["ori_trone"], StringComparison.OrdinalIgnoreCase)) isms.ori_trone = string.Format("3{0:00000}", API_URL_Config_Id); } if (string.IsNullOrEmpty(isms.ori_order) && U2DMap.ContainsKey("ori_order")) {//虚似指令 if (C_VIRTUAL_MSG.Equals(U2DMap["ori_order"], StringComparison.OrdinalIgnoreCase)) isms.ori_order = string.Format("ht_3{0:00000}_{1}", API_URL_Config_Id, isms.price); } if (!U2DMap.ContainsKey("mmc")) isms.mcc = "460";//没有设置mmc动作时,写入默认值 WriteDebug("ValueCollected"); if (isms.trone_id == 0) { if (!IsMo && string.IsNullOrEmpty(api.MrStatus))//MR 安全检查 {//MR 数据,未配置状态检查时,进行“状态”关键字检查,以防万一 if (CheckStatusKeywords()) isms.trone_id = C_TM_STATUS_NOT_CONFIG;//存在“状态”关键字 } try { if (!IsSpServerBack(isms)) {//非正常SP服务的回传 isms.trone_id = C_TM_SERVER_IP_ERROR; } else if (isms.trone_id == 0) { trone = FillToneId(dBase, isms); if (trone != null && IsMo && HasMoTroneOrderId) { var torder = FindTroneOrder(_MoItem); if (torder != null) _MoItem.trone_order_id = torder.id; } } } #if !DEBUG catch (Exception ex) { WriteDebug("TroneMathcFail:" + ex.Message); } #endif finally { } } WriteDebug("TroneIdMatched"); if (!string.IsNullOrEmpty(err)) { WriteError(err); return; } try { if (_MrItem != null) { if (_MoItem != null) { _MrItem.mo_id = _MoItem.id; _MrItem.mo_table = _MoItem.TableName; if (_MrItem.trone_id <= 0) _MrItem.trone_id = _MoItem.trone_id; } _MrItem.IsMatch = _MrItem.trone_id > 0; dBase.SaveData(_MrItem); } if (_MoItem != null) dBase.SaveData(_MoItem); } catch (System.Data.Common.DbException) { WriteError("database busy"); return; } WriteSuccess(); WriteDebug("CoreProcessed", true); var db3 = (Shotgun.Database.IBaseDataPerformance)dBase; db3.EnableRecord = true; if (_MrItem != null) {//同步新的MR记录 if (_MrItem.cp_id == 0 || _MrItem.cp_id == 34) DoPush(trone); } try { if (_MrItem != null) { LightDataModel.tbl_mr_dailyItem daily = null; if (IsMo) { daily = LightDataModel.tbl_mr_dailyItem.GetVRDaily(dBase, _MrItem); } daily = _MrItem.CopyToDailyMr(daily); dBase.SaveData(daily); } } catch { } WriteDebug(db3.PerformanceReport()); WriteDebug("ALL done", true); }