/// <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> /// <returns></returns> public ActionResult login(string password, string account) { using (var db = new DataContext(AppEmr.DbConst.EmrDb)) { var info = FastRead.Query <GI_USERINFO>(a => a.USERCODE.ToLower() == account.ToLower()).ToItem <GI_USERINFO>(db); if (string.IsNullOrEmpty(info.USERCODE)) { return(Json(new { code = 1, msg = "登录失败!该用户信息不存在或已被停用。" })); } if (info.PASSWORD == BaseSymmetric.md5(32, password) || info.PASSWORD == null) { var token = Common.Encrypt.MD5Encrypt(string.Format("{0}{1}", Guid.NewGuid().ToString("D"), DateTime.Now.Ticks)); var cache = RedisCacheManager.CreateInstance(); var tokenlist = new List <UserToken>(); if (cache.IsSet("tokenlist")) { tokenlist = cache.Get <List <UserToken> >("tokenlist"); var usertoken = tokenlist.Find(f => f.UserId == info.USERID); if (usertoken != null) { tokenlist.Remove(usertoken); cache.Remove("tokenlist"); } } var _userToken = new UserToken() { UserId = info.USERID, ORGANID = info.ORGANID, USERCODE = info.USERCODE, USERNAME = info.USERNAME, InpatientID = info.INPATIENTID, UserPhoto = info.USERPHOTO, Permission = "", Timeout = DateTime.Now.AddMinutes(600), Token = token }; if (_userToken.UserPhoto == null || System.IO.File.Exists(Server.MapPath("../../../" + _userToken.UserPhoto)) == false) { _userToken.UserPhoto = "Content/Images/face.png"; } tokenlist.Add(_userToken); cache.Update("tokenlist", tokenlist, 600); return(Json(new { code = 0, data = _userToken })); } else { return(Json(new { code = 1, msg = "登录失败!用户名或密码错误" })); } } }
public IActionResult Login(LoginModel item) { var isSuccess = false; using (var db = new DataContext(App.DbKey.Api)) { var info = FastRead.Query <ApiGatewayLogin>(a => a.UserName.ToLower() == item.Code.ToLower()).ToDic(db); isSuccess = BaseSymmetric.Generate(item.Pwd).ToLower() == info.GetValue("UserPwd").ToStr().ToLower(); info.Add("ip", App.Ip.Get(HttpContext)); if (isSuccess) { BaseCache.Set <Dictionary <string, object> >(App.Cache.UserInfo, info); return(Json(new { success = isSuccess, url = "/home/index" })); } else { return(Json(new { success = isSuccess, msg = "密码不正确" })); } } }
/// <summary> /// 返回字符串列表 /// </summary> /// <param name="path">文件名</param> /// <param name="xmlNode">结点</param> /// <returns></returns> public static bool GetXmlList(string path, string xmlNode, ref List <string> key, ref List <string> sql, ref Dictionary <string, object> db, ref Dictionary <string, object> type, ref Dictionary <string, object> check, ref Dictionary <string, object> param, ref Dictionary <string, object> name, ref Dictionary <string, object> parameName, ConfigModel config, string xml = null) { try { var result = true; var tempKey = ""; //变量 var xmlDoc = new XmlDocument(); //载入xml if (config.IsEncrypt) { var temp = BaseSymmetric.DecodeGB2312(File.ReadAllText(path)); if (temp != "") { xmlDoc.LoadXml(temp); } else { xmlDoc.Load(path); } } else if (!string.IsNullOrEmpty(xml)) { xmlDoc.LoadXml(xml); } else { xmlDoc.Load(path); } //结点 var nodelList = xmlDoc.SelectNodes(xmlNode); var list = new List <string>(); foreach (XmlNode item in nodelList) { foreach (XmlNode temp in item.ChildNodes) { var foreachCount = 1; var i = 0; if (temp is XmlElement) { var tempParam = new List <string>(); #region XmlElement tempKey = temp.Attributes["id"].Value.ToLower(); //节点数 if (Array.Exists(key.ToArray(), element => element == tempKey)) { result = false; Task.Run(() => { BaseLog.SaveLog(string.Format("xml文件:{0},存在相同键:{1}", path, tempKey), "MapKeyExists"); }); } key.Add(tempKey); sql.Add(temp.ChildNodes.Count.ToString()); //name if (temp.Attributes["name"] != null) { name.Add(string.Format("{0}.remark", tempKey), temp.Attributes["name"].Value); } foreach (XmlNode node in temp.ChildNodes) { #region XmlText if (node is XmlText) { key.Add(string.Format("{0}.{1}", tempKey, i)); sql.Add(node.InnerText.Replace("<", "<").Replace(">", ">")); } #endregion #region XmlElement 动态条件 if (node is XmlElement) { if (node.Attributes["prepend"] != null) { key.Add(string.Format("{0}.format.{1}", tempKey, i)); sql.Add(node.Attributes["prepend"].Value.ToLower()); } //foreach if (node.Name.ToLower() == "foreach") { //type if (node.Attributes["type"] != null) { key.Add(string.Format("{0}.foreach.type.{1}", tempKey, foreachCount)); sql.Add(node.Attributes["type"].Value); } //result name key.Add(string.Format("{0}.foreach.name.{1}", tempKey, foreachCount)); if (node.Attributes["name"] != null) { sql.Add(node.Attributes["name"].Value.ToLower()); } else { sql.Add("data"); } //field if (node.Attributes["field"] != null) { key.Add(string.Format("{0}.foreach.field.{1}", tempKey, foreachCount)); sql.Add(node.Attributes["field"].Value.ToLower()); } //sql if (node.ChildNodes[0] is XmlText) { key.Add(string.Format("{0}.foreach.sql.{1}", tempKey, foreachCount)); sql.Add(node.ChildNodes[0].InnerText.Replace("<", "<").Replace(">", ">")); } foreachCount++; } foreach (XmlNode dyn in node.ChildNodes) { if (dyn is XmlText) { continue; } //check required if (dyn.Attributes["required"] != null) { check.Add(string.Format("{0}.{1}.required", tempKey, dyn.Attributes["property"].Value.ToLower()), dyn.Attributes["required"].Value.ToStr()); } //check maxlength if (dyn.Attributes["maxlength"] != null) { check.Add(string.Format("{0}.{1}.maxlength", tempKey, dyn.Attributes["property"].Value.ToLower()), dyn.Attributes["maxlength"].Value.ToStr()); } //check existsmap if (dyn.Attributes["existsmap"] != null) { check.Add(string.Format("{0}.{1}.existsmap", tempKey, dyn.Attributes["property"].Value.ToLower()), dyn.Attributes["existsmap"].Value.ToStr()); } //check checkmap if (dyn.Attributes["checkmap"] != null) { check.Add(string.Format("{0}.{1}.checkmap", tempKey, dyn.Attributes["property"].Value.ToLower()), dyn.Attributes["checkmap"].Value.ToStr()); } //check date if (dyn.Attributes["date"] != null) { check.Add(string.Format("{0}.{1}.date", tempKey, dyn.Attributes["property"].Value.ToLower()), dyn.Attributes["date"].Value.ToStr()); } //参数 tempParam.Add(dyn.Attributes["property"].Value); //param name if (dyn.Attributes["name"] != null) { parameName.Add(string.Format("{0}.{1}.remark", tempKey, dyn.Attributes["property"].Value.ToLower()), dyn.Attributes["name"].Value); } if (dyn.Name.ToLower() == "ispropertyavailable") { //属性和值 key.Add(string.Format("{0}.{1}.{2}", tempKey, dyn.Attributes["property"].Value.ToLower(), i)); sql.Add(string.Format("{0}{1}", dyn.Attributes["prepend"].Value.ToLower(), dyn.InnerText)); } else if (dyn.Name.ToLower() != "choose") { //属性和值 key.Add(string.Format("{0}.{1}.{2}", tempKey, dyn.Attributes["property"].Value.ToLower(), i)); sql.Add(string.Format("{0}{1}", dyn.Attributes["prepend"].Value.ToLower(), dyn.InnerText)); //条件类型 key.Add(string.Format("{0}.{1}.condition.{2}", tempKey, dyn.Attributes["property"].Value.ToLower(), i)); sql.Add(dyn.Name); //判断条件内容 if (dyn.Attributes["condition"] != null) { key.Add(string.Format("{0}.{1}.condition.value.{2}", tempKey, dyn.Attributes["property"].Value.ToLower(), i)); sql.Add(dyn.Attributes["condition"].Value); } //比较条件值 if (dyn.Attributes["compareValue"] != null) { key.Add(string.Format("{0}.{1}.condition.value.{2}", tempKey, dyn.Attributes["property"].Value.ToLower(), i)); sql.Add(dyn.Attributes["compareValue"].Value.ToLower()); } } else { //条件类型 key.Add(string.Format("{0}.{1}.condition.{2}", tempKey, dyn.Attributes["property"].Value.ToLower(), i)); sql.Add(dyn.Name); if (dyn is XmlElement) { var count = 0; key.Add(string.Format("{0}.{1}.{2}", tempKey, dyn.Attributes["property"].Value.ToLower(), i)); sql.Add(dyn.ChildNodes.Count.ToStr()); foreach (XmlNode child in dyn.ChildNodes) { //条件 key.Add(string.Format("{0}.{1}.{2}.choose.condition.{3}", tempKey, dyn.Attributes["property"].Value.ToLower(), i, count)); sql.Add(child.Attributes["property"].Value); //内容 key.Add(string.Format("{0}.{1}.{2}.choose.{3}", tempKey, dyn.Attributes["property"].Value.ToLower(), i, count)); sql.Add(string.Format("{0}{1}", child.Attributes["prepend"].Value.ToLower(), child.InnerText)); count++; } } } } } #endregion i++; } //db if (temp.Attributes["db"] != null) { db.Add(tempKey, temp.Attributes["db"].Value.ToStr()); } //type if (temp.Attributes["type"] != null) { type.Add(tempKey, temp.Attributes["type"].Value.ToStr()); } //foreach count key.Add(string.Format("{0}.foreach", tempKey)); sql.Add((foreachCount - 1).ToStr()); param.Add(tempKey, tempParam); #endregion } else if (temp is XmlText) { #region XmlText key.Add(string.Format("{0}.{1}", item.Attributes["id"].Value.ToLower(), i)); sql.Add(temp.InnerText.Replace("<", "<").Replace(">", ">")); key.Add(item.Attributes["id"].Value.ToLower()); sql.Add("0"); #endregion } } } return(result); } catch (Exception ex) { Task.Run(() => { if (config.SqlErrorType == SqlErrorType.Db) { DbLogTable.LogException(config, ex, "InstanceMap", "GetXmlList"); } else { DbLog.LogException(true, "InstanceMap", ex, "GetXmlList", ""); } }); return(false); } }
/// <summary> /// map xml 存数据库 /// </summary> /// <param name="dbKey"></param> /// <param name="key"></param> /// <param name="info"></param> public static bool SaveXml(string dbKey, string key, FileInfo info, ConfigModel config, DataContext db) { if (config.IsMapSave) { //加密 var enContent = File.ReadAllText(info.FullName); //明文 var deContent = ""; if (config.IsEncrypt) { deContent = BaseSymmetric.DecodeGB2312(deContent); if (deContent == "") { deContent = enContent; } } else { deContent = enContent; } if (config.DbType == DataDbType.MySql) { var model = new DataModel.MySql.Data_MapFile(); model.MapId = key; var query = FastRead.Query <DataModel.MySql.Data_MapFile>(a => a.MapId == key, null, dbKey); if (query.ToCount() == 0) { model.FileName = info.Name; model.FilePath = info.FullName; model.LastTime = info.LastWriteTime; model.EnFileContent = enContent; model.DeFileContent = deContent; return(db.Add(model).writeReturn.IsSuccess); } else { return(db.Update <DataModel.MySql.Data_MapFile>(model, a => a.MapId == model.MapId, a => new { a.LastTime, a.EnFileContent, a.DeFileContent }).writeReturn.IsSuccess); } } if (config.DbType == DataDbType.Oracle) { var model = new DataModel.Oracle.Data_MapFile(); model.MapId = key; var query = FastRead.Query <DataModel.Oracle.Data_MapFile>(a => a.MapId == key, null, dbKey); if (query.ToCount() == 0) { model.FileName = info.Name; model.FilePath = info.FullName; model.LastTime = info.LastWriteTime; model.EnFileContent = enContent; model.DeFileContent = deContent; return(db.Add(model).writeReturn.IsSuccess); } else { return(db.Update <DataModel.Oracle.Data_MapFile>(model, a => a.MapId == model.MapId, a => new { a.LastTime, a.EnFileContent, a.DeFileContent }).writeReturn.IsSuccess); } } if (config.DbType == DataDbType.SqlServer) { var model = new DataModel.SqlServer.Data_MapFile(); model.MapId = key; var query = FastRead.Query <DataModel.SqlServer.Data_MapFile>(a => a.MapId == key, null, dbKey); if (query.ToCount() == 0) { model.FileName = info.Name; model.FilePath = info.FullName; model.LastTime = info.LastWriteTime; model.EnFileContent = enContent; model.DeFileContent = deContent; return(db.Add(model).writeReturn.IsSuccess); } else { return(db.Update <DataModel.SqlServer.Data_MapFile>(model, a => a.MapId == model.MapId, a => new { a.LastTime, a.EnFileContent, a.DeFileContent }).writeReturn.IsSuccess); } } } return(true); }
/// <summary> /// 初始化map 3 /// </summary> /// <returns></returns> private void InstanceMap(string dbKey = null, string dbFile = "db.json", string mapFile = "map.json") { var list = BaseConfig.GetValue <MapConfigModel>(AppSettingKey.Map, mapFile); var config = DataConfig.Get(dbKey, null, dbFile); var db = new DataContext(dbKey); var query = new DataQuery { Config = config, Key = dbKey }; list.Path.ForEach(p => { var info = new FileInfo(p); var key = BaseSymmetric.Generate(info.FullName); if (!DbCache.Exists(config.CacheType, key)) { var temp = new MapXmlModel(); temp.LastWrite = info.LastWriteTime; temp.FileKey = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", "")); temp.FileName = info.FullName; if (MapXml.SaveXml(dbKey, key, info, config, db)) { DbCache.Set <MapXmlModel>(config.CacheType, key, temp); } } else if ((DbCache.Get <MapXmlModel>(config.CacheType, key).LastWrite - info.LastWriteTime).Milliseconds != 0) { DbCache.Get <MapXmlModel>(config.CacheType, key).FileKey.ForEach(a => { DbCache.Remove(config.CacheType, a); }); var model = new MapXmlModel(); model.LastWrite = info.LastWriteTime; model.FileKey = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", "")); model.FileName = info.FullName; if (MapXml.SaveXml(dbKey, key, info, config, db)) { DbCache.Set <MapXmlModel>(config.CacheType, key, model); } } }); if (config.IsMapSave) { query.Config.DesignModel = FastData.Core.Base.Config.CodeFirst; if (query.Config.DbType == DataDbType.Oracle) { var listInfo = typeof(FastData.Core.DataModel.Oracle.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList(); var listAttribute = typeof(FastData.Core.DataModel.Oracle.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList(); BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute); } if (query.Config.DbType == DataDbType.MySql) { var listInfo = typeof(FastData.Core.DataModel.MySql.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList(); var listAttribute = typeof(FastData.Core.DataModel.MySql.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList(); BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute); } if (query.Config.DbType == DataDbType.SqlServer) { var listInfo = typeof(FastData.Core.DataModel.SqlServer.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList(); var listAttribute = typeof(FastData.Core.DataModel.SqlServer.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList(); BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute); } } db.Dispose(); }
public static void InstanceMapResource(string dbKey = null, string dbFile = "db.json", string mapFile = "map.json") { var projectName = Assembly.GetCallingAssembly().GetName().Name; var config = DataConfig.Get(dbKey, projectName, dbFile); var db = new DataContext(dbKey); var assembly = Assembly.Load(projectName); var map = new MapConfigModel(); using (var resource = assembly.GetManifestResourceStream(string.Format("{0}.{1}", projectName, mapFile))) { if (resource != null) { using (var reader = new StreamReader(resource)) { var content = reader.ReadToEnd(); map.Path = BaseJson.JsonToModel <List <string> >(BaseJson.JsonToDic(BaseJson.ModelToJson(BaseJson.JsonToDic(content).GetValue(AppSettingKey.Map))).GetValue("Path").ToStr()); } } else { map = BaseConfig.GetValue <MapConfigModel>(AppSettingKey.Map, mapFile); } } if (map.Path == null) { return; } map.Path.ForEach(a => { using (var resource = assembly.GetManifestResourceStream(string.Format("{0}.{1}", projectName, a.Replace("/", ".")))) { var xml = ""; if (resource != null) { using (var reader = new StreamReader(resource)) { xml = reader.ReadToEnd(); } } var info = new FileInfo(a); var key = BaseSymmetric.Generate(info.FullName); if (!DbCache.Exists(config.CacheType, key)) { var temp = new MapXmlModel(); temp.LastWrite = info.LastWriteTime; temp.FileKey = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""), xml); temp.FileName = info.FullName; if (MapXml.SaveXml(dbKey, key, info, config, db)) { DbCache.Set <MapXmlModel>(config.CacheType, key, temp); } } else if ((DbCache.Get <MapXmlModel>(config.CacheType, key).LastWrite - info.LastWriteTime).Milliseconds != 0) { DbCache.Get <MapXmlModel>(config.CacheType, key).FileKey.ForEach(f => { DbCache.Remove(config.CacheType, f); }); var model = new MapXmlModel(); model.LastWrite = info.LastWriteTime; model.FileKey = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""), xml); model.FileName = info.FullName; if (MapXml.SaveXml(dbKey, key, info, config, db)) { DbCache.Set <MapXmlModel>(config.CacheType, key, model); } } } }); }