/// <summary> /// <see cref="IOpenQueryTemplateService.AddQueryTemplate(QueryTemplateView)"/> /// </summary> /// <param name="item"><see cref="QueryTemplateView"/></param> /// <returns></returns> public long AddQueryTemplate(QueryTemplateView item) { using (var context = UnitOfWork.Get(Unity.ContainerName)) { long templateID = 0; context.UsingTransaction(() => { templateID = new QueryTemplateRepository(context).AddQueryTemplate(item); List <QueryGroup> groups = new List <QueryGroup>(); List <QueryFilter> filters = new List <QueryFilter>(); Recursive(item.FilterGroup, string.Empty, string.Empty, 0, templateID, groups, filters); new QueryGroupRepository(context).BacthAddQueryGroup(groups); new QueryFilterRepository(context).AddBatchQueryFilter(filters); if (item.QueryFields != null && item.QueryFields.Count > 0) { item.QueryFields.ForEach(p => { p.TemplateID = templateID; }); if (item.BaseQueryFields != null && item.BaseQueryFields.Count > 0) { item.BaseQueryFields.ForEach(p => { p.TemplateID = templateID; }); item.QueryFields.AddRange(item.BaseQueryFields); } new QueryFieldRepository(context).AddBatchQueryField(item.QueryFields); } if (item.ColorLevelCfgInfos != null && item.ColorLevelCfgInfos.Count > 0) { var csr = new ColorSettingRepository(context); item.ColorLevelCfgInfos.ForEach(p => { p.ModuleId = 400000000 + item.MenuID * 1000; p.SettingName = string.Format("{0}|{1}|{2}", p.SettingName, templateID, item.TemplateName); }); csr.Add(item.ColorLevelCfgInfos); var list = new List <ColorLevelDynamicInfo>(); item.ColorLevelCfgInfos.ForEach(o => { list.AddRange(o.SectionList); }); csr.Add(list); } if (item.IsHasNe && !item.NeParameter.IsNullOrEmpty()) { new QueryNeRepository(context).AddQueryNe(new QueryNe { TemplateID = templateID, NeValue = item.NeParameter, NeName = item.NeNames }); } //var strWhere = item.NeParameter.ToString(); }); return(templateID); } }
/// <summary> /// 更新模板信息 /// </summary> /// <param name="item"></param> /// <returns></returns> public int UpdateQueryTemplates(QueryTemplateView item) { using (var context = UnitOfWork.Get(Unity.ContainerName)) { var result = 0; context.UsingTransaction(() => { new QueryTemplateRepository(context).UpdateQueryTemplate(item); var r = new QueryGroupRepository(context); var queryGroups = r.GetQueryGroups().Where(p => p.TemplateID == item.TemplateID).Select(p => p.ID).ToList(); if (queryGroups != null && queryGroups.Count > 0) { r.DeleteQueryGroupByTemplateID(item.TemplateID); new QueryFilterRepository(context).DeleteQueryFilterByGroupID(queryGroups); } List <QueryGroup> groups = new List <QueryGroup>(); List <QueryFilter> filters = new List <QueryFilter>(); Recursive(item.FilterGroup, null, null, 0, item.TemplateID, groups, filters); new QueryGroupRepository(context).BacthAddQueryGroup(groups); new QueryFilterRepository(context).AddBatchQueryFilter(filters); if (item.QueryFields != null && item.QueryFields.Count > 0) { var qf = new QueryFieldRepository(context); qf.DeleteQueryFieldByTemplateID(new long[] { item.TemplateID }); item.QueryFields.ForEach(p => { p.TemplateID = item.TemplateID; }); if (item.BaseQueryFields != null && item.BaseQueryFields.Count > 0) { item.BaseQueryFields.ForEach(p => { p.TemplateID = item.TemplateID; }); item.QueryFields.AddRange(item.BaseQueryFields); } qf.AddBatchQueryField(item.QueryFields); } if (item.ColorLevelCfgInfos != null && item.ColorLevelCfgInfos.Count > 0) { //var service = ServiceFactory.GetService<IColorSettingService>(); var csr = new ColorSettingRepository(context); var settings = csr.All().Where(t => t.ModuleId.Equals(400000000 + item.MenuID * 1000) && t.SettingName.Contains(item.TemplateID.ToString() + "|")).ToList(); if (settings.FirstOrDefault() != null) { csr.Delete(settings.Select(p => p.Id)); csr.DeleteDynamic(settings.Select(p => p.Id)); } item.ColorLevelCfgInfos.ForEach(p => { p.ModuleId = 400000000 + item.MenuID * 1000; p.SettingName = string.Format("{0}|{1}|{2}", p.SettingName, item.TemplateID, item.TemplateName); }); csr.Add(item.ColorLevelCfgInfos); var list = new List <ColorLevelDynamicInfo>(); item.ColorLevelCfgInfos.ForEach(o => { list.AddRange(o.SectionList); }); csr.Add(list); } if (item.IsHasNe) { var qne = new QueryNeRepository(context).GetQueryNe(item.TemplateID); if (qne != null) { new QueryNeRepository(context).UpdateQueryNe(new QueryNe { TemplateID = item.TemplateID, NeValue = item.NeParameter, NeName = item.NeNames }); } else { new QueryNeRepository(context).AddQueryNe(new QueryNe { TemplateID = item.TemplateID, NeValue = item.NeParameter, NeName = item.NeNames }); } } result = 1; }); return(result); } }