/// <summary> /// 删除字典明细 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Del_DicLeaf_Click(object sender, RoutedEventArgs e) { var count = 0; foreach (var item in Dic.Items) { var box = Common.GetTemplateColumn <CheckBox>(Dic, 0, "dicBox", item); if (box != null && box.IsChecked == true) { var temp = item as Data_Dic_Details; if (temp != null && !string.IsNullOrEmpty(temp.Id)) { FastWrite.Delete <Data_Dic_Details>(a => a.Id == temp.Id); } count++; } } if (count == 0) { CodeBox.Show("请选择字典明细", this); } else { InitDic(); CodeBox.Show("删除成功", this); } }
/// <summary> /// 缓存结果 /// </summary> /// <param name="info"></param> /// <param name="item"></param> private static void CacheResult(ApiGatewayUrl item, DataContext db, ReturnModel info = null, Dictionary <string, object> dic = null) { var model = new ApiGatewayCache(); model.Key = item.Key.ToLower(); model.TimeOut = DateTime.Now.AddDays(item.CacheTimeOut.ToStr().ToDouble(0)).AddHours(8); if (info != null) { model.result = BaseJson.ModelToJson(info.msg); } if (dic != null) { model.result = BaseJson.ModelToJson(dic); } if (FastRead.Query <ApiGatewayCache>(a => a.Key.ToUpper() == model.Key.ToUpper()).ToCount(db) <= 0) { FastWrite.Add(model); } else { FastWrite.Update <ApiGatewayCache>(model, a => a.Key.ToUpper() == model.Key.ToUpper(), a => new { a.result, a.TimeOut }, db); } }
private void WriteData(Block block, FileStream fileStream) { // Create back link to previous spilled block. var lastFilePosition = new[] { _filePosition }; _filePosition = (int)fileStream.Position; FastWrite.WriteInts(fileStream.SafeFileHandle, lastFilePosition, 0, 1); // Write one data block. if (typeof(TData) == typeof(short)) { FastWrite.WriteShorts(fileStream.SafeFileHandle, (short[])(object)block._data, 0, _blockSize); } else if (typeof(TData) == typeof(int)) { FastWrite.WriteInts(fileStream.SafeFileHandle, (int[])(object)block._data, 0, _blockSize); } else if (typeof(TData) == typeof(float)) { FastWrite.WriteFloats(fileStream.SafeFileHandle, (float[])(object)block._data, 0, _blockSize); } else { Assume.Fail(); } }
/// <summary> /// 获取token /// </summary> /// <param name="item"></param> /// <param name="context"></param> private static Task Token(HttpContext context, DataContext db, string urlParam) { var dic = new Dictionary <string, object>(); var AppKey = GetUrlParamKey(urlParam, "AppKey"); var AppSecret = GetUrlParamKey(urlParam, "AppSecret"); if (FastRead.Query <ApiGatewayUser>(a => a.AppKey.ToLower() == AppKey.ToLower() && a.AppSecret.ToLower() == AppSecret.ToLower()).ToCount(db) <= 0) { context.Response.StatusCode = 200; dic.Add("success", false); dic.Add("result", "AppKey和AppSecret参数不存在"); return(context.Response.WriteAsync(JsonConvert.SerializeObject(dic).ToString(), Encoding.UTF8)); } else { var info = FastRead.Query <ApiGatewayUser>(a => a.AppKey.ToLower() == AppKey.ToLower() && a.AppSecret.ToLower() == AppSecret.ToLower()).ToItem <ApiGatewayUser>(db); info.Ip = GetClientIp(context); info.AccessExpires = DateTime.Now.AddHours(24).AddHours(8); info.AccessToken = BaseSymmetric.Generate(string.Format("{0}_{1}_{2}", info.AppKey, info.AppSecret, info.AccessExpires)).ToLower(); //修改信息 FastWrite.Update <ApiGatewayUser>(info, a => a.AppKey.ToLower() == AppKey.ToLower() && a.AppSecret.ToLower() == AppSecret.ToLower() , a => new { a.AccessExpires, a.Ip, a.AccessToken }, db); dic.Add("success", true); dic.Add("AccessToken", info.AccessToken); dic.Add("AccessExpires", info.AccessExpires); context.Response.StatusCode = 200; return(context.Response.WriteAsync(JsonConvert.SerializeObject(dic).ToString(), Encoding.UTF8)); } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_SaveData(object sender, RoutedEventArgs e) { var item = Bussiness.SelectedItem as Data_Business; if (item == null) { CodeBox.Show("请求选择业务", this); } else { item.UpdateDay = (UpdateDay.SelectedItem as BindModel).value; item.UpdateCount = (UpdateCount.SelectedItem as BindModel).value; item.UpdateTime = (UpdateTime.SelectedItem as BindModel).value; item.SaveDataMonth = (DataMonth.SelectedItem as BindModel).value; item.Policy = (IsDel.SelectedItem as BindModel).value.ToStr(); var isSuccess = FastWrite.Update <Data_Business>(item, a => a.Id == item.Id, a => new { a.UpdateCount, a.UpdateTime, a.UpdateDay, a.SaveDataMonth, a.Policy }).IsSuccess; if (isSuccess) { Bussiness.ItemsSource = AppCache.GetAllBusiness; Common.UpdateWindow(); CodeBox.Show("保存成功", this); } else { CodeBox.Show("保存失败", this); } } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Save_Click(object sender, RoutedEventArgs e) { dbConn = BaseLink.GetConnStr(dbType, txtUserName, txtPwd, txtHostName, txtPort, txtServerName); if (!BaseLink.CheckLink(dbType, dbConn)) { CodeBox.Show("连接数据库失败!", this); } else { var buildLink = BaseLink.ControlsToData(dbType, txtHostName, txtUserName, txtPwd, txtPort, txtServerName, labServerName, true, txtLinkName); buildLink.LinkName = buildLink.LinkName == "" ? BaseLink.GetLinkName(buildLink) : buildLink.LinkName; buildLink.Id = Guid.NewGuid().ToString(); AppCache.SetLink(buildLink); if (FastRead.Query <Data_Source>(a => a.LinkName == buildLink.LinkName).ToCount() == 1) { FastWrite.Update <Data_Source>(buildLink, a => a.LinkName == buildLink.LinkName, a => new { a.Host, a.PassWord, a.Port, a.ServerName, a.Type, a.UserName }); } else { FastWrite.Add(buildLink); } CodeBox.Show("连接数据库成功!", this); } }
/// <summary> /// 执行写操作 /// </summary> public WriteReturn Write(string name, DbParameter[] param, DataContext db = null, string key = null, bool isOutSql = false) { key = key == null?MapDb(name) : key; var config = db == null?DataConfig.Get(key) : db.config; if (config.IsUpdateCache) { InstanceMap(key); } if (DbCache.Exists(config.CacheType, name.ToLower())) { var sql = MapXml.GetMapSql(name, ref param, db, key); isOutSql = isOutSql ? isOutSql : IsMapLog(name); BaseAop.AopMapBefore(name, sql, param, config, AopType.Map_Write); var data = FastWrite.ExecuteSql(sql, param, db, key, isOutSql, false); BaseAop.AopMapAfter(name, sql, param, config, AopType.Map_Write, data); return(data); } else { BaseAop.AopMapBefore(name, "", param, config, AopType.Map_Write); var data = new WriteReturn(); BaseAop.AopMapAfter(name, "", param, config, AopType.Map_Write, data); return(data); } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Save_Click(object sender, RoutedEventArgs e) { using (var db = new DataContext()) { var success = false; var main = Dic.SelectedItem as Data_Dic; if (string.IsNullOrEmpty(main.Id)) { main.Id = Guid.NewGuid().ToString(); success = FastWrite.Add(main).IsSuccess; } else { success = FastWrite.Update(main, a => a.Id == main.Id, a => new { a.Name }).IsSuccess; } foreach (var item in DicLeaf.Items) { var temp = item as Data_Dic_Details; if (temp == null) { continue; } temp.DicId = main.Id; if (temp != null) { if (string.IsNullOrEmpty(temp.Value)) { CodeBox.Show("字典值不能为空", this); continue; } if (string.IsNullOrEmpty(temp.ContrastValue)) { CodeBox.Show("字典对照值不能为空", this); continue; } if (string.IsNullOrEmpty(temp.Id)) { temp.Id = Guid.NewGuid().ToString(); if (success) { success = db.Add(temp).writeReturn.IsSuccess; } } else { success = db.Update(temp, a => a.Id == temp.Id, a => new { a.Name, a.Value, a.ContrastValue }).writeReturn.IsSuccess; } } } } CodeBox.Show("保存成功", this); }
/// <summary> /// 删除用户 /// </summary> /// <returns></returns> public ActionResult DeleteUser(string userid) { var isSuccess = FastWrite.Delete <GI_USERINFO>(a => a.USERID == userid, null, AppEmr.DbConst.EmrDb).IsSuccess; if (isSuccess) { return(Json(new { code = 0 })); } else { return(Json(new { code = 1 })); } }
/// <summary> /// 更改用户默认显示的系统模块 /// </summary> /// <param name="InpatientID"></param> /// <param name="UserId"></param> /// <param name="IsDefault"></param> /// <param name="MyOrganId"></param> /// <param name="token"></param> /// <returns></returns> public ActionResult UpdateDefaultBQ(string InpatientID, string UserId, string IsDefault, string MyOrganId, string token) { var info = new GI_USERINFO(); info.USERID = UserId; info.ORGANID = MyOrganId; info.INPATIENTID = InpatientID; info.MODIFYTIME = DateTime.Now; var isSuccess = FastWrite.Update <GI_USERINFO>(info, a => a.USERID == info.USERID, a => new { a.ORGANID, a.INPATIENTID, a.MODIFYTIME }, null, AppEmr.DbConst.EmrDb).IsSuccess; return(Json(new { code = 0 })); }
/// <summary> /// 删除字典类型 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Del_Dic_Click(object sender, RoutedEventArgs e) { var success = false; var item = Dic.SelectedItem as Data_Dic; if (!string.IsNullOrEmpty(item.Id)) { success = FastWrite.Delete <Data_Dic>(a => a.Id == item.Id).IsSuccess; } if (success) { InitDic(); CodeBox.Show("删除成功", this); } else { CodeBox.Show("删除失败", this); } }
/// <summary> /// 删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Del_Click(object sender, RoutedEventArgs e) { var item = dbTypeLink.SelectedItem as Data_Source; if (item != null) { if (FastRead.Query <Data_Business_Details>(a => a.DataSourceId == item.Id).ToCount() == 0) { FastWrite.Delete <Data_Source>(a => a.LinkName == item.LinkName); AppCache.RemoveLink(); dbTypeLink.ItemsSource = AppCache.GetAllLink; InitLinkInfo(); CodeBox.Show("删除成功", this); } else { InitLinkInfo(); CodeBox.Show("删除失败数据源在使用中", this); } } }
/// <summary> /// 执行写操作 /// </summary> public WriteReturn Write(string name, DbParameter[] param, DataContext db = null, string key = null) { key = key == null?MapDb(name) : key; var config = db == null?DataConfig.Get(key) : db.config; if (config.IsUpdateCache) { InstanceMap(key); } if (DbCache.Exists(config.CacheType, name.ToLower())) { var sql = MapXml.GetMapSql(name, ref param, db, key); return(FastWrite.ExecuteSql(sql, param, db, key)); } else { return(new WriteReturn()); } }
/// <summary> /// 处理请求 /// </summary> /// <param name="downparam">下游</param> /// <param name="param">请求参数</param> /// <param name="content">请求参数body</param> /// <returns></returns> private static ReturnModel GetReuslt(ApiGatewayDownParam downparam, string param, string key, int isTextLog, int isDbLog, DataContext db, HttpContext context, string ActionId, int OrderBy, IHttpClientFactory client) { var info = FastRead.Query <ApiGatewayWait>(a => a.Key.ToLower() == key.ToLower() && a.Url.ToLower() == downparam.Url.ToLower()).ToItem <ApiGatewayWait>(db) ?? new ApiGatewayWait(); if (info.Key.ToStr().ToLower() == key.ToLower() && DateTime.Compare(info.NextAction, DateTime.Now) > 0) { //return time out var dic = new Dictionary <string, object>(); dic.Add("success", false); dic.Add("result", "等待恢复"); return(new ReturnModel { msg = BaseJson.ModelToJson(dic), status = 408 }); } else { var result = new ReturnModel(); var stopwatch = new Stopwatch(); stopwatch.Start(); if (downparam.Protocol.ToLower() == "soap") { result = BaseUrl.SoapUrl(downparam.Url, downparam.SoapParamName, downparam.SoapMethod, param, client, key, downparam.SoapNamespace); } else if (downparam.Protocol.ToLower() == "http") { //http if (downparam.Method.ToStr().ToLower() == "post") { if (downparam.IsBody == 1) { result = BaseUrl.PostContent(downparam.Url, param, key, client); } else { result = BaseUrl.PostUrl(downparam.Url, param, key, client); } } else if (downparam.Method.ToStr().ToLower() == "get") { result = BaseUrl.GetUrl(downparam.Url, param, key, client); } } //else if (downparam.Protocol.ToLower() == "mq") // //mq // result = BaseUrl.RabbitUrl(downparam.QueueName, param); else { result.status = 408; } if (result.status == 408) { //time out var wait = new ApiGatewayWait(); wait.Key = key; wait.Url = downparam.Url; wait.WaitHour = downparam.WaitHour.ToInt(0); wait.ErrorMsg = result.msg; wait.NextAction = DateTime.Now.AddHours(wait.WaitHour.ToStr().ToDouble(0)); FastWrite.Add(wait, db); } else if (info.Key.ToStr().ToLower() == key.ToLower()) { FastWrite.Delete <ApiGatewayWait>(a => a.Key.ToLower() == key.ToLower(), db); } stopwatch.Stop(); var logInfo = new ApiGatewayLog(); logInfo.ActionId = ActionId; logInfo.OrderBy = OrderBy; logInfo.Key = key; logInfo.ActionTime = DateTime.Now; logInfo.Url = downparam.Url; logInfo.Protocol = downparam.Protocol; logInfo.Success = result.status == 200 ? 1 : 0; logInfo.Result = result.msg; logInfo.Milliseconds = stopwatch.Elapsed.TotalMilliseconds; logInfo.ActionIp = GetClientIp(context); logInfo.ActionParam = param; if (isDbLog == 1) { FastWrite.Add(logInfo, null, DbApi); } if (isTextLog == 1) { BaseLog.SaveLog(BaseJson.ModelToJson(logInfo), logInfo.Key); } return(result); } }
/// <summary> /// 定时任务同步产品数据 /// </summary> /// <param name="source"></param> /// <param name="e"></param> public void SynData(object source, ElapsedEventArgs e) { try { //防止重复执行 lock (thisLock) { using (var db = new DataContext()) { BaseLog.SaveLog("开始抽取", "FastEtlService"); //不允许停止服务 this.CanStop = false; var list = FastRead.Query <Data_Business>(a => a.Id != null).ToList <Data_Business>(db); foreach (var item in list) { if (DataSchema.IsExistsTable(db, item.TableName) && item.UpdateTime == DateTime.Now.Hour && item.LastUpdateTime.Day + item.UpdateDay >= DateTime.Now.Day) { Parallel.Invoke(() => { var leaf = FastRead.Query <Data_Business_Details>(a => a.Id == item.Id).ToList <Data_Business_Details>(db); if (leaf.Count > 0) { var isAdd = true; var dt = DataSchema.GetTable(db, item.TableName); var columnName = dt.Columns[3].ColumnName.ToLower(); if (leaf.Exists(a => a.FieldName.ToLower() == columnName)) { DataSchema.ExpireData(db, item); //第一列 var link = DataSchema.InitColLink(leaf, db); var tempLeaf = leaf.Find(a => a.FieldName.ToLower() == columnName); var pageInfo = DataSchema.GetTableCount(link[0], tempLeaf, item); for (var i = 1; i <= pageInfo.pageCount; i++) { var log = new Data_Log(); log.Id = Guid.NewGuid().ToStr(); log.TableName = string.Format("{0}_page_{1}", item.TableName, i); log.BeginDateTime = DateTime.Now; pageInfo.pageId = i; var pageData = DataSchema.GetFirstColumnData(link[0], tempLeaf, item, pageInfo); //遍历填充table for (var row = 0; row < pageData.list.Count; row++) { var dtRow = dt.NewRow(); dtRow["Id"] = Guid.NewGuid().ToString(); dtRow["AddTime"] = DateTime.Now; dtRow["Key"] = pageData.list[row].GetValue("key"); dtRow[columnName] = pageData.list[row].GetValue("data"); //字典对照 if (!string.IsNullOrEmpty(tempLeaf.Dic)) { dtRow[columnName] = FastRead.Query <Data_Dic_Details>(a => a.Value.ToLower() == dtRow[columnName].ToStr().ToLower() && a.DicId == tempLeaf.Dic, a => new { a.ContrastValue }).ToDic(db).GetValue("ContrastValue"); } //数据策略 isAdd = DataSchema.DataPolicy(db, item, dtRow["Key"], columnName, dtRow[columnName]); for (var col = 3; col < dt.Columns.Count; col++) { columnName = dt.Columns[col].ColumnName.ToLower(); if (leaf.Exists(a => a.FieldName.ToLower() == columnName)) { tempLeaf = leaf.Find(a => a.FieldName.ToLower() == columnName); dtRow[columnName] = DataSchema.GetColumnData(link[col - 3], tempLeaf, dtRow["Key"]); //字典对照 if (!string.IsNullOrEmpty(tempLeaf.Dic)) { dtRow[columnName] = FastRead.Query <Data_Dic_Details>(a => a.Value.ToLower() == dtRow[columnName].ToStr().ToLower() && a.DicId == tempLeaf.Dic, a => new { a.ContrastValue }).ToDic(db).GetValue("ContrastValue"); } //数据策略 if (item.Policy == "2") { isAdd = DataSchema.DataPolicy(db, item, dtRow["Key"], columnName, dtRow[columnName]); } } } if (isAdd) { dt.Rows.Add(dtRow); } } if (dt.Rows.Count > 0) { DataSchema.AddList(db, dt, ref log); } db.Add(log); dt.Clear(); } DataSchema.CloseLink(link); item.LastUpdateTime = DateTime.Now; FastWrite.Update <Data_Business>(item, a => a.Id == item.Id, a => new { a.LastUpdateTime }, db); } } }); } } //允许停止服务 this.CanStop = true; BaseLog.SaveLog("结束抽取", "FastEtlService"); } } } catch (Exception ex) { BaseLog.SaveLog(ex.ToString(), "FastEtlServiceError"); } }