/// <summary> /// 给栏目绑定指标 页面 /// </summary> /// <param name="keyValue">栏目Id</param> /// <param name="indexType">所属平台 0web平台 1安卓平台 2App</param> /// <param name="Templet">所属栏目</param> /// <returns></returns> public ActionResult TerminalBindForm(string keyValue, int indexType, int Templet) { Operator user = OperatorProvider.Provider.Current(); DepartmentEntity userdept = new DepartmentBLL().GetCompany(user.DeptId); TerminalDataSetBLL dataSetBLL = new TerminalDataSetBLL(); List <TerminalDataSetEntity> indexlist = new List <TerminalDataSetEntity>(); indexlist = dataSetBLL.GetList().Where(p => p.IsOpen == 1).ToList(); //if (indexType == 2) //{ // indexlist = dataSetBLL.GetList().Where(p => p.IsOpen == 1 && (p.DataSetType == indexType.ToString() )).ToList(); //所有的手机APP指标 //} //else //{ // indexlist = dataSetBLL.GetList().Where(p => p.IsOpen == 1 && (p.DataSetType == indexType.ToString() || p.DataSetType == null)).ToList(); //所有的终端指标 //} //查询本IndexType的栏目 var titleIds = manageBLL.GetList(userdept.DepartmentId, indexType).Where(x => x.Templet == Templet).Select(x => x.Id); //查找所有的关联关系 IIndexAssocationBLL indexAssocationBLL = new IIndexAssocationBLL(); List <IndexAssocationEntity> indices = indexAssocationBLL.GetListByTitleId(titleIds.ToArray()); //先剔除非本IndexType的关联关系 indices = indices.Where(x => titleIds.Contains(x.TitleId)).ToList(); //查询未被其他标题绑定的指标 var BindIds = indices.Where(x => x.TitleId != keyValue).Select(p => p.DataSetId); //非当前标题 已经的被帮的指标 var thisBindIds = indices.Where(x => x.TitleId == keyValue).Select(p => p.DataSetId); //当前标题绑定的指标 var data = indexlist.Where(x => !BindIds.Contains(x.Id)).ToList(); //当前标题 可显示的指标 ViewBag.ChceckIds = thisBindIds.ToList(); ViewBag.TitleId = keyValue; return(View(data)); }
/// <summary> /// /// </summary> /// <param name="searchDeptId">所查询的指标的部门ID 一般为电厂的Id</param> /// <param name="userId">当前用户的Id 取数据用</param> /// <param name="indexType">指标类型 0管理平台 1安卓终端 2手机APP </param> /// <param name="userDeptId">当前用户的所属的部门Id 取数据用</param> /// <param name="terminalType">查询类型 0月 1季 2年</param> /// <param name="templet">模板 所属的模板 1第一套 2 第二套 以此类推</param> /// <returns></returns> public List <IndexManageModel> GetIndexData(string searchDeptId, string userId, int indexType, string userDeptId, string terminalType, int?templet) { TerminalDataSetBLL terminalDataSetBLL = new TerminalDataSetBLL(); IndexManageBLL indexManageBLL = new IndexManageBLL(); List <TerminalDataSetEntity> entitys = terminalDataSetBLL.GetList().Where(p => p.IsOpen == 1).ToList(); //先取所有的指标 //再取所有的分类 List <IndexManageEntity> manageEntities = indexManageBLL.GetList(searchDeptId, indexType, null, templet).Where(p => p.IsShow == 1).ToList(); //获取分类底下的指标 List <IndexAssocationEntity> indexAssocationEntities = new IIndexAssocationBLL().GetListByTitleId(manageEntities.Select(p => p.Id).ToArray()); //查询并组装指标值的数据 var dataSetIds = indexAssocationEntities.Select(x => x.DataSetId);//所有的指标的Ids Dictionary <string, string> dic = new Dictionary <string, string>(); entitys.Where(x => dataSetIds.Contains(x.Id)).ToList().ForEach(x => { dic.Add(x.Code + "-" + x.Name, terminalType); });//应该要绑定的所有的指标 List <KeyValue> keyValues = FindAllCount(userId, userDeptId, dic); //List<KeyValue> keyValues = FindAllCount(userId, userDeptId, terminalType); List <IndexManageModel> models = new List <IndexManageModel>(); if (manageEntities != null && manageEntities.Count > 0) { manageEntities.ForEach(title => { //生成分类 IndexManageModel model = new IndexManageModel() { TitleId = title.Id, TitleName = title.Title, Srot = title.Sort }; //生成指标 var datasetIds = indexAssocationEntities.Where(p => p.TitleId == title.Id).Select(p => p.DataSetId); List <TerminalDataSetEntity> terminals = entitys.Where(x => datasetIds.Contains(x.Id)).ToList(); List <IndexModel> indexModels = new List <IndexModel>(); terminals.ForEach(terminal => { //组装数据 IndexModel indexModel = new IndexModel() { Key = terminal.Code, Name = terminal.Name, Sort = terminal.Sort, IsBZ = terminal.IsBZ, Unit = terminal.Unint, Icon = string.IsNullOrWhiteSpace(terminal.IconUrl) ? null : Config.GetValue("AppUrl") + terminal.IconUrl, Address = terminal.Address //Value = thisKv == null ? "0" : thisKv.value }; if (terminal.IsBZ == "1" && keyValues != null && keyValues.Count > 0) { var thisKv = keyValues.FirstOrDefault(p => p.key == terminal.Code); indexModel.Value = thisKv == null ? "0" : thisKv.value; } indexModels.Add(indexModel); }); model.AddChilds(indexModels); models.Add(model); }); } return(models); }