/// <summary> /// 获取特定数据段中数据源规则ID对应的值 /// </summary> /// yaoy 16.09.20 /// <param name="messageInfo"></param> /// <param name="dataSegmentCode"></param> /// <param name="segmentRulesId"></param> /// <returns></returns> public string GetValues(MessageInfo messageInfo, string dataSegmentCode, string segmentRulesId) { PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { if (pi.Name == dataSegmentCode) { List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); if (list != null) { foreach (Dictionary <string, string> dic in list) { foreach (var info in dic) { if (info.Key == dataSegmentCode + segmentRulesId) { return(info.Value); } } } } } } return(string.Empty); }
/// <summary> /// 查询该信息记录中的某个值 /// </summary> /// yand 16.09.27 /// <param name="message">json信息</param> /// <param name="groupId">组合ID(数据段标识+数据段规则ID)</param> /// <returns></returns> public string GetValue(string message, string groupId) { string result = string.Empty; MessageInfo messageInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageInfo>(message); PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { var list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); if (list != null) { foreach (var item in list) { foreach (var va in item) { if (va.Key == groupId) { result = va.Value; } } } } } return(result); }
/// <summary> /// 根据查询条件获取该记录中是否存在满足条件的信息 /// </summary> /// yand 16.09.27 /// <param name="message">json保存的信息记录值</param> /// <param name="value">筛选条件</param> /// <param name="dic"></param> /// <returns></returns> public bool FindInfo(string message, string value) { bool result = false; MessageInfo messageInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageInfo>(message); PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { var list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); if (list != null) { foreach (var item in list) { foreach (var va in item) { if (va.Value == value) { result = true; } } } } } return(result); }
/// <summary> /// 数据和规则校验 /// </summary> /// yaoy 16.06.01 /// <param name="infoType"></param> /// <param name="messageInfo"></param> /// <param name="message"></param> /// <returns></returns> public bool DataAndRuleCompare(InfoTypeInfo infoType, MessageInfo messageInfo, int recordID, int reportID, ref string message) { message = string.Empty; PropertyInfo[] ps = messageInfo.GetType().GetProperties(); //数据校验 foreach (PropertyInfo pi in ps) { List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); if (pi.Name == "C" && list.Count > 0) { ParagraphCode = pi.Name; } List <DataSegmentInfo> dataSegmentList = infoType.DataSegmentList; if (dataSegmentList != null) { foreach (DataSegmentInfo dataSegmentInfo in dataSegmentList) { List <SegmentRulesInfo> segmentRulesList = dataSegmentInfo.SegmnetRulesList; foreach (SegmentRulesInfo segmentRulesInfo in segmentRulesList) { MetaInfo metaInfo = segmentRulesInfo.MetaInfo; if (list != null) { foreach (Dictionary <string, string> dic in list) { foreach (var info in dic) { if (info.Key == dataSegmentInfo.ParagraphCode + segmentRulesInfo.SegmentRulesId.ToString()) { if (info.Value != "") { bool result = DataValidate(infoType, metaInfo, info, dataSegmentInfo.ParagraphCode, recordID, reportID, ref message); if (result == false) { return(false); } } else { if (segmentRulesInfo.IsRequired == "M") { throw new ApplicationException(metaInfo.Name + "为必填项!"); } } } } } } } } } } Validates.ValidatesFactoryModel.Create(infoType.InfoTypeId, messageInfo); return(true); }
/// <summary> /// 一次性获取数据段中所有Value /// </summary> /// yaoy 16.09.26 /// <param name="messageInfo"></param> /// <param name="dataSegmentCode"></param> /// <param name="dic"></param> /// <returns></returns> public Dictionary <string, string> GetAllValues(MessageInfo messageInfo, string dataSegmentCode, Dictionary <string, string> dic) { var lists = new List <string>(); foreach (var item in dic) { lists.Add(item.Key); } PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { if (pi.Name == dataSegmentCode) { var list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); foreach (var item in list) { foreach (var temp in item) { if (lists.Contains(temp.Key)) { dic[temp.Key] = temp.Value; } } } } } return(dic); }
/// <summary> /// 获取特定数据段中数据源规则ID对应的值 /// </summary> /// yaoy 16.09.20 /// <param name="message"></param> /// <param name="dataSegmentCode"></param> /// <param name="segmentRulesId"></param> public string GetValues(string message, string dataSegmentCode, string segmentRulesId) { MessageInfo messageInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageInfo>(message); PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { if (pi.Name == dataSegmentCode) { List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); if (list != null) { foreach (Dictionary <string, string> dic in list) { foreach (var info in dic) { if (info.Key == dataSegmentCode + segmentRulesId) { return(info.Value); } } } } } } return(string.Empty); }
/// <summary> /// 封装信息类型报文 /// </summary> /// yaoy 16.06.01 /// yand 16.07.15(修改) /// <returns></returns> public string EncapsulateData(InfoTypeInfo infoTypeInfo, string content) { string result = string.Empty; StringBuilder sb = new StringBuilder(); MessageInfo messageInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageInfo>(content); PropertyInfo[] ps = messageInfo.GetType().GetProperties(); // 获取数据段列表 List <DataSegmentInfo> dataSegmentList = infoTypeInfo.DataSegmentList; foreach (PropertyInfo pi in ps) { foreach (DataSegmentInfo dataSegment in dataSegmentList) { // 获取数据段规则集合 List <SegmentRulesInfo> segmentRulesList = dataSegment.SegmnetRulesList; // 获取段 List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); if (list != null) { foreach (Dictionary <string, string> dic in list) { foreach (SegmentRulesInfo segmentRules in segmentRulesList) { foreach (var info in dic) { if (segmentRules != null) { // 获取数据元实体 MetaInfo metaInfo = segmentRules.MetaInfo; // 判断前端传的Key值与数据段Code值和该数据段下的数据段规则Id值是否相等 if (info.Key == dataSegment.ParagraphCode + segmentRules.SegmentRulesId.ToString()) { // 判断前端传的Value值长度小于或等于元数据长度 if (System.Text.Encoding.GetEncoding("GB2312").GetByteCount(info.Value) <= metaInfo.DatasLength) { sb.Append(ComplementBits(metaInfo, info.Value)); } } } } } } } } } return(sb.ToString()); }
/// <summary> /// 判断所有数据规则段出现的次数 /// </summary> /// yaoy 16.09.20 /// <param name="infoTypeId"></param> /// <param name="messageInfo"></param> /// <returns></returns> public bool TimesValidate(int infoTypeId, MessageInfo messageInfo) { bool result = true; // 根据信息类型ID获取所有数据段 List <DataSegmentInfo> dataSegmentList = new DataSegment().GetByInfoTypeId(infoTypeId); PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); // list集合不为空且段名称包含在数据段集合中 if (list != null && dataSegmentList.Select(m => m.ParagraphCode).Contains(pi.Name)) { // 异常情况描述 var temp = string.Empty; //根据信息类型ID和段编码获取实体 DataSegmentInfo dataSegmentInfo = new DataSegment().GetByInfoTypeIdAndCode(infoTypeId, pi.Name); switch (dataSegmentInfo.times) { case "1:1": temp = "次数为一"; result &= list.Count() == 1; break; case "1:n": temp = "次数大于等于一"; result &= list.Count() >= 1; break; case "0:1": temp = "次数小于等于一"; result &= list.Count() <= 1; break; default: break; } if (!result) { throw new ApplicationException(dataSegmentInfo.ParagraphName + "必须满足" + temp); } } } return(result); }
/// <summary> /// 获取信息记录字段中数据段数据 /// </summary> /// yaoy 16.09.23 /// <param name="messageInfo"></param> /// <param name="code"></param> /// <returns></returns> public List <Dictionary <string, string> > GetList(MessageInfo messageInfo, string code) { var list = new List <Dictionary <string, string> >(); PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { if (pi.Name == code) { return((List <Dictionary <string, string> >)pi.GetValue(messageInfo)); } } return(list); }
/// <summary> /// 获取信息记录特定段出现的次数 /// </summary> /// yaoy 16.09.23 /// <param name="messageInfo"></param> /// <param name="code"></param> /// <returns></returns> public int GetTimes(MessageInfo messageInfo, string code) { var times = 0; PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { if (pi.Name == code) { List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); times = list == null ? 0 : list.Count(); } } return(times); }
/// <summary> /// 获取信息记录字段中数据段数据 /// </summary> /// yaoy 16.09.23 /// <param name="informationInfo"></param> /// <returns></returns> public List <Dictionary <string, string> > GetList(string content, string code) { var list = new List <Dictionary <string, string> >(); MessageInfo messageInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageInfo>(content); PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { if (pi.Name == code) { list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); } } return(list); }
/// <summary> /// 判断所有数据规则段出现的次数 /// </summary> /// yaoy 16.09.20 /// <param name="infoTypeId"></param> /// <param name="message"></param> /// <returns></returns> public bool ValidateTimes(int infoTypeId, string message) { bool result = true; MessageInfo messageInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageInfo>(message); PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); if (list != null) { //根据信息类型ID和段编码获取实体 DataSegmentInfo dataSegmentInfo = new DataSegment().GetByInfoTypeIdAndCode(infoTypeId, pi.Name); switch (dataSegmentInfo.times) { case "1:1": result &= list.Count() == 1; break; case "1:n": result &= list.Count() >= 1; break; case "0:1": result &= list.Count() <= 1; break; default: break; } } if (!result) { return(false); } } return(result); }
/// <summary> /// 获取信息记录特定段出现的次数 /// </summary> /// yaoy 16.09.23 /// <param name="content">信息记录字符串</param> /// <param name="code">数据段名称</param> /// <returns></returns> public int GetTimes(string content, string code) { var times = 0; MessageInfo messageInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageInfo>(content); PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { if (pi.Name == code) { List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); times = list == null ? 0 : list.Count(); } } return(times); }
/// <summary> /// /// </summary> /// <param name="segments">需要的段标识</param> /// <param name="segmentRules">段规则ID</param> /// <param name="mates">数据元标识</param> protected void Find(string[] segments, string[] segmentRules, string[] mates, MessageInfo data) { SegmentRulesInfo Rules = new SegmentRulesInfo(); // 段 var segs = new Dictionary <string, bool>(); // 段规则 var segsRule = new Dictionary <string, string>(); // 数据元 var meta = new Dictionary <string, string>(); //将数据段转换成字典类型并且都设置为False segments.ToList().ForEach(m => segs.Add(m, false)); //修改段属性 foreach (var item in data.GetType().GetProperties()) { if (segments.Contains(item.Name)) { segs[item.Name] = true; } } //将数据段规则转换成字典类型并且都设置为False segmentRules.ToList().ForEach(m => segsRule.Add(m, null)); //修改段规则属性 foreach (var item in data.GetType().GetProperties()) { List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)item.GetValue(data); if (list != null) { foreach (Dictionary <string, string> dic in list) { foreach (var info in dic) { if (segmentRules.Contains(info.Key)) { segsRule[info.Key] = info.Value; } } } } } //将数据元转换成字典类型并且都设置为False mates.ToList().ForEach(m => meta.Add(m, null)); //修改数据元属性 foreach (var item in data.GetType().GetProperties()) { List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)item.GetValue(data); if (list != null) { foreach (Dictionary <string, string> dic in list) { foreach (var info in dic) { Rules = new DAL.BankCredit.SegmentRulesMapper().Find(Convert.ToInt32(info.Key.Substring(1, info.Key.Length - 1))); if (mates.Contains(Rules.MetaCode.ToString())) { meta[Rules.MetaCode.ToString()] = info.Value; } } } } } PData = new Parameters { Segments = segs, SegmentRules = segsRule, Mates = meta, }; }
/// <summary> /// 验证两个数据段之间关系 /// </summary> /// yaoy 16.09.22 /// <param name="infoTypeId"></param> /// <param name="messageInfo"></param> /// <returns></returns> public bool RelationValidate(int infoTypeId, MessageInfo messageInfo) { bool result = true; Dictionary <string, string> dictionary = new Dictionary <string, string>(); // 根据信息类型ID获取所有需要校验的规则 List <SegmentRuleRelationInfo> segmentRuleRelationList = new SegmentRuleRelation().GetByInfoTypeId(infoTypeId); if (segmentRuleRelationList.Count > 0) { // 将所以需要校验的数据全部添加到字典类型中 foreach (var segmentRuleRelationInfo in segmentRuleRelationList) { if (!dictionary.ContainsKey(segmentRuleRelationInfo.FirstSegmentRuleId.ToString())) { dictionary.Add(segmentRuleRelationInfo.FirstSegmentRuleId.ToString(), string.Empty); } if (!dictionary.ContainsKey(segmentRuleRelationInfo.SecondSegmentRuleId.ToString())) { dictionary.Add(segmentRuleRelationInfo.SecondSegmentRuleId.ToString(), string.Empty); } } PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { List <Dictionary <string, string> > listDic = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); if (listDic != null) { foreach (Dictionary <string, string> dic in listDic) { foreach (var info in dic) { if (dictionary.ContainsKey(info.Key.ToString().Substring(1, info.Key.Length - 1))) { dictionary[info.Key.ToString().Substring(1, info.Key.Length - 1)] = info.Value; } } } } } } // 将取出的数据进行规则校验 foreach (var item in segmentRuleRelationList) { string relation = string.Empty; var dataSegmentInfo1 = new DataSegment().GetByInfoTypeIdAndSegmentRulesId(infoTypeId, item.FirstSegmentRuleId); var metaInfo1 = new Meta().GetByInfoTypeIdAndSegmentRulesId(infoTypeId, item.FirstSegmentRuleId); var dataSegmentInfo2 = new DataSegment().GetByInfoTypeIdAndSegmentRulesId(infoTypeId, item.SecondSegmentRuleId); var metaInfo2 = new Meta().GetByInfoTypeIdAndSegmentRulesId(infoTypeId, item.SecondSegmentRuleId); switch (item.SegmentRelation) { case ">=": relation = "大于或等于"; result &= Convert.ToDouble(dictionary[item.FirstSegmentRuleId.ToString()] == "" ? "0" : dictionary[item.FirstSegmentRuleId.ToString()]) >= Convert.ToDouble(dictionary[item.SecondSegmentRuleId.ToString()] == "" ? "0" : dictionary[item.SecondSegmentRuleId.ToString()]); break; case "<=": relation = "小于或等于"; result &= Convert.ToDouble(dictionary[item.FirstSegmentRuleId.ToString()] == "" ? "0" : dictionary[item.FirstSegmentRuleId.ToString()]) <= Convert.ToDouble(dictionary[item.SecondSegmentRuleId.ToString()] == "" ? "0" : dictionary[item.SecondSegmentRuleId.ToString()]); break; case "!=": relation = "不等于"; if (dictionary[item.FirstSegmentRuleId.ToString()] != "" && dictionary[item.SecondSegmentRuleId.ToString()] != "") { result &= dictionary[item.FirstSegmentRuleId.ToString()] != dictionary[item.SecondSegmentRuleId.ToString()]; } break; case "!=!": if (!(dictionary[item.FirstSegmentRuleId.ToString()] == string.Empty && dictionary[item.SecondSegmentRuleId.ToString()] == string.Empty) || (dictionary[item.FirstSegmentRuleId.ToString()] != string.Empty && dictionary[item.SecondSegmentRuleId.ToString()] != string.Empty) ) { throw new ApplicationException(dataSegmentInfo1.ParagraphName + metaInfo1.Name + "和" + dataSegmentInfo2.ParagraphName + metaInfo2.Name + "必须同时为空或者同时不为空!"); } break; default: break; } if (!result) { throw new ApplicationException(dataSegmentInfo1.ParagraphName + metaInfo1.Name + relation + dataSegmentInfo2.ParagraphName + metaInfo2.Name); } } return(result); }
/// <summary> /// 验证两个数据段之间关系 /// </summary> /// yaoy 16.09.22 /// <param name="infoTypeId"></param> /// <param name="message"></param> /// <returns></returns> public bool ValidateRelation(int infoTypeId, string message) { bool result = true; Dictionary <string, string> dictionary = new Dictionary <string, string>(); // 根据信息类型ID获取所有需要校验的规则 List <SegmentRuleRelationInfo> segmentRuleRelationList = new SegmentRuleRelation().GetByInfoTypeId(infoTypeId); if (segmentRuleRelationList.Count > 0) { // 将所以需要校验的数据全部添加到字典类型中 foreach (var segmentRuleRelationInfo in segmentRuleRelationList) { if (!dictionary.ContainsKey(segmentRuleRelationInfo.FirstSegmentRuleId.ToString())) { dictionary.Add(segmentRuleRelationInfo.FirstSegmentRuleId.ToString(), string.Empty); } if (!dictionary.ContainsKey(segmentRuleRelationInfo.SecondSegmentRuleId.ToString())) { dictionary.Add(segmentRuleRelationInfo.SecondSegmentRuleId.ToString(), string.Empty); } } MessageInfo messageInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageInfo>(message); PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { List <Dictionary <string, string> > listDic = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); if (listDic != null) { foreach (Dictionary <string, string> dic in listDic) { foreach (var info in dic) { if (dictionary.ContainsKey(info.Key.ToString().Substring(1, info.Key.Length - 1))) { dictionary[info.Key.ToString().Substring(1, info.Key.Length - 1)] = info.Value; } } } } } } // 将取出的数据进行规则校验 foreach (var item in segmentRuleRelationList) { switch (item.SegmentRelation) { case ">=": result &= Convert.ToInt32(dictionary[item.FirstSegmentRuleId.ToString()]) >= Convert.ToInt32(dictionary[item.SecondSegmentRuleId.ToString()]); break; case "<=": result &= Convert.ToInt32(dictionary[item.FirstSegmentRuleId.ToString()]) <= Convert.ToInt32(dictionary[item.SecondSegmentRuleId.ToString()]); break; case "!=": result &= dictionary[item.FirstSegmentRuleId.ToString()] != dictionary[item.SecondSegmentRuleId.ToString()]; break; case "!=!": if (dictionary[item.FirstSegmentRuleId.ToString()] == string.Empty && dictionary[item.SecondSegmentRuleId.ToString()] == string.Empty) { } if (dictionary[item.FirstSegmentRuleId.ToString()] != string.Empty && dictionary[item.SecondSegmentRuleId.ToString()] != string.Empty) { } else { return(false); } break; default: break; } } return(result); }
/// <summary> /// 用于补位 /// </summary> /// yand 16.07.15 测试补充没有的字段 /// <param name="infoType"></param> /// <param name="messageInfo"></param> /// <param name="message"></param> /// <returns></returns> public MessageInfo DataAndRuleCompare1(InfoTypeInfo infoType, MessageInfo messageInfo, ref string message) { message = string.Empty; PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); List <DataSegmentInfo> dataSegmentList = infoType.DataSegmentList; if (dataSegmentList != null) { foreach (DataSegmentInfo dataSegmentInfo in dataSegmentList) { List <SegmentRulesInfo> segmentRulesList = dataSegmentInfo.SegmnetRulesList; foreach (SegmentRulesInfo segmentRulesInfo in segmentRulesList) { MetaInfo metaInfo = segmentRulesInfo.MetaInfo; if (list != null) { foreach (Dictionary <string, string> dic in list) { if (pi.Name == dataSegmentInfo.ParagraphCode) { // 段标识 if (metaInfo.MetaCode == 8105 || metaInfo.MetaCode == 7543) { dic.Add(dataSegmentInfo.ParagraphCode + segmentRulesInfo.SegmentRulesId, dataSegmentInfo.ParagraphCode); } // 信息记录长度 else if (metaInfo.MetaCode == 8103 || metaInfo.MetaCode == 4501) { dic.Add(dataSegmentInfo.ParagraphCode + segmentRulesInfo.SegmentRulesId, "0"); } //// 个人金融机构代码 //else if (metaInfo.MetaCode == 6101) //{ // dic.Add(dataSegmentInfo.ParagraphCode + segmentRulesInfo.SegmentRulesId, "B10211000H0001"); //} // 企业金融机构代码 else if (metaInfo.MetaCode == 6501) { dic.Add(dataSegmentInfo.ParagraphCode + segmentRulesInfo.SegmentRulesId, "33207991216"); } // 企业审计时间 else if (metaInfo.MetaCode == 2589) { dic.Add(dataSegmentInfo.ParagraphCode + segmentRulesInfo.SegmentRulesId, DateTime.Now.ToString("yyyyMMdd")); } // 业务号 //else if (metaInfo.MetaCode == 7101) //{ // dic.Add(dataSegmentInfo.ParagraphCode + segmentRulesInfo.SegmentRulesId, "999123123123999"); //} // 信息记录跟踪编号 else if (metaInfo.MetaCode == 7641) { dic.Add(dataSegmentInfo.ParagraphCode + segmentRulesInfo.SegmentRulesId, "00000000000000000000"); } } } } } } } } return(messageInfo); }