/// <summary>
        /// 种植 角色菜单 缓存
        /// </summary>
        public void AutoSetRoleMenuCache()
        {
            _CustomerIDList = CustomerBLL.Instance.GetCustomerList();
            foreach (var customer in _CustomerIDList)
            {
                //
                _T_loggingSessionInfo.ClientID = customer.Key;
                _T_loggingSessionInfo.CurrentLoggingManager.Connection_String = customer.Value;

                //
                _AppSysService = new JIT.CPOS.BS.DataAccess.AppSysService(_T_loggingSessionInfo);
                _T_RoleBLL     = new T_RoleBLL(_T_loggingSessionInfo);

                //
                var roleList = new List <string>();
                try
                {
                    var roleEntities = _T_RoleBLL.QueryByEntity(new T_RoleEntity
                    {
                        customer_id = customer.Key
                    }, null);
                    if (roleEntities == null || roleEntities.Count() <= 0)
                    {
                        continue;
                    }

                    //
                    roleList = roleEntities.Select(it => it.role_id).ToList();
                }
                catch
                {
                    continue;
                }
                foreach (var roleID in roleList)
                {
                    var menuList = _AppSysService.GetRoleMenus(customer.Key, roleID);
                    if (menuList == null && menuList.Count <= 0)
                    {
                        continue;
                    }
                    new RedisRoleBLL().SetRole(customer.Key, roleID, menuList);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 保存角色
        /// </summary>
        public string SaveRoleData()
        {
            var       roleService  = new RoleService(CurrentUserInfo);
            RoleModel obj          = new RoleModel();
            string    content      = string.Empty;
            string    error        = "";
            var       responseData = new ResponseData();

            string key     = string.Empty;
            string role_id = string.Empty;

            if (Request("role") != null && Request("role") != string.Empty)
            {
                key = Request("role").ToString().Trim();
            }
            if (Request("role_id") != null && Request("role_id") != string.Empty)
            {
                role_id = Request("role_id").ToString().Trim();
            }

            obj = key.DeserializeJSONTo <RoleModel>();

            //obj.Def_App_Id = "";
            //if (Request["app_sys_id"] != null && Request["app_sys_id"] != string.Empty)
            //{
            //    obj.Def_App_Id = Request["app_sys_id"].ToString().Trim();
            //}

            if (role_id.Trim().Length == 0 || role_id == "null" || role_id == "undefined")
            {
                obj.Role_Id = Utils.NewGuid();
            }
            else
            {
                obj.Role_Id = role_id;
            }


            if (obj.type_id == null || obj.type_id.Trim().Length == 0)
            {
                //responseData.success = false;
                //responseData.msg = "所属组织层级不能为空";
                //return responseData.ToJSON();
                obj.type_id   = "";
                obj.org_level = 99;
            }
            else
            {
                T_TypeBLL    typeBll = new T_TypeBLL(CurrentUserInfo);
                T_TypeEntity en      = typeBll.GetByID(obj.type_id);
                if (en != null)
                {
                    obj.org_level = (int)en.type_Level;
                }
            }

            if (obj.Def_App_Id == null || obj.Def_App_Id.Trim().Length == 0)
            {
                responseData.success = false;
                responseData.msg     = "应用系统不能为空";
                return(responseData.ToJSON());
            }

            if (obj.Role_Name == null || obj.Role_Name.Trim().Length == 0)
            {
                responseData.success = false;
                responseData.msg     = "角色名称不能为空";
                return(responseData.ToJSON());
            }

            //根据role_id 获取角色信息,系统保留角色的编码不允许修改,主要是admin、administrator等默认角色
            RoleModel roleOld = new AppSysService(CurrentUserInfo).GetRoleById(CurrentUserInfo, role_id);

            if (roleOld != null && roleOld.Is_Sys == 1)
            {
                //throw (new System.Exception("不能删除系统保留的角色"));
                obj.Role_Code = roleOld.Role_Code;//还用原来的,不用role_name
                obj.Is_Sys    = 1;
            }
            //if (obj.Is_Sys == null)
            //{
            //    responseData.success = false;
            //    responseData.msg = "是否系统保留不能为空";
            //    return responseData.ToJSON();
            //}
            if (obj.Role_Code == null || obj.Role_Code.Trim().Length == 0)
            {
                //responseData.success = false;
                //responseData.msg = "角色编码不能为空";
                //return responseData.ToJSON();
                obj.Role_Code = obj.Role_Name;
            }


            if (obj.RoleMenuInfoList != null)
            {
                foreach (var tmpRoleMenuObj in obj.RoleMenuInfoList)
                {
                    tmpRoleMenuObj.Role_Id = obj.Role_Id;
                }
            }

            obj.Create_Time    = Utils.GetNow();
            obj.Create_User_Id = CurrentUserInfo.CurrentUser.User_Id;
            obj.Modify_Time    = Utils.GetNow();
            obj.Modify_User_id = CurrentUserInfo.CurrentUser.User_Id;
            string strError = "";

            //
            roleService.SetRoleInfo(obj, out strError);
            //
            var menuList = new JIT.CPOS.BS.DataAccess.AppSysService(CurrentUserInfo).GetRoleMenus(CurrentUserInfo.ClientID, obj.Role_Id);

            if (menuList != null && menuList.Count > 0)
            {
                new RedisRoleBLL().SetRole(CurrentUserInfo.ClientID, obj.Role_Id, menuList);
            }
            //roleService.SetRoleInfo(obj, out strError);

            if (strError != "" && strError != "成功")
            {
                responseData.success = false;
                responseData.msg     = strError;
                return(responseData.ToJSON());
            }

            responseData.success = true;
            responseData.msg     = error;

            content = responseData.ToJSON();
            return(content);
        }
Exemple #3
0
        protected override SetSignInRD ProcessRequest(DTO.Base.APIRequest <SetSignInRP> pRequest)
        {
            SetSignInRD rd = new SetSignInRD();

            string customerCode = pRequest.Parameters.CustomerCode;

            string phone = pRequest.Parameters.LoginName;

            string password = pRequest.Parameters.Password;

            if (string.IsNullOrEmpty(customerCode))
            {
                throw new APIException("客户代码不能为空")
                      {
                          ErrorCode = Error_CustomerCode_NotNull
                      };
            }

            WMenuBLL menuServer = new WMenuBLL(Default.GetAPLoggingSession(""));
            string   customerId = menuServer.GetCustomerIDByCustomerCode(customerCode);

            if (string.IsNullOrEmpty(customerId))
            {
                throw new APIException("客户代码对应的客户不存在")
                      {
                          ErrorCode = Error_CustomerCode_NotExist
                      };
            }
            var currentUserInfo = Default.GetBSLoggingSession(customerId, "1");

            VipBLL vipBll = new VipBLL(currentUserInfo);

            #region 判断用户是否存在
            if (!vipBll.JudgeUserExist(phone, customerId))
            {
                throw new APIException("用户名无效")
                      {
                          ErrorCode = Error_UserName_InValid
                      };
            }

            #endregion

            #region 判断密码是否正确
            if (!vipBll.JudgeUserPasswordExist(phone, customerId, password))
            {
                throw new APIException("登录密码错误")
                      {
                          ErrorCode = Error_Password_InValid
                      };
            }

            #endregion
            #region 判断是否有登录连锁掌柜App权限
            var  userRolesDs = vipBll.GetUserRoles(phone, customerId, password);
            bool flag        = false;
            foreach (DataRow row in userRolesDs.Tables[0].Rows)
            {
                if (row["Def_App_Code"].ToString().ToUpper() == "APP")
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                throw new APIException("该账号无权登录本系统")
                      {
                          ErrorCode = Error_Password_InValid
                      };
            }
            #endregion
            #region 判断该客服人员是否有客服或操作订单的权限
            //if (!vipBll.JudgeUserRoleExist(phone, customerId, password))
            //{
            //    throw new APIException("该账号无权登录本系统") { ErrorCode = Error_Password_InValid };
            //}
            #endregion

            #region 获取UserId
            var ds = vipBll.GetUserIdByUserNameAndPassword(phone, customerId, password);
            rd.UserId     = ds.Tables[0].Rows[0]["user_id"].ToString();
            rd.UserName   = ds.Tables[0].Rows[0]["user_name"].ToString();
            rd.Status     = int.Parse(ds.Tables[0].Rows[0]["user_status"].ToString());
            rd.CustomerId = customerId;
            var T_SuperRetailTraderbll  = new T_SuperRetailTraderBLL(currentUserInfo);
            var T_SuperRetailTraderInfo = T_SuperRetailTraderbll.QueryByEntity(new T_SuperRetailTraderEntity()
            {
                CustomerId = customerId, SuperRetailTraderFromId = rd.UserId, SuperRetailTraderFrom = "User"
            }, new OrderBy[] { new OrderBy()
                               {
                                   FieldName = "CreateTime", Direction = OrderByDirections.Desc
                               } }).FirstOrDefault();
            if (T_SuperRetailTraderInfo != null)
            {
                rd.SuperRetailTraderID = T_SuperRetailTraderInfo.SuperRetailTraderID.ToString();
            }
            #endregion
            //如果状态不等于1,就说明已经停用,
            if (rd.Status != 1)
            {
                throw new APIException("该员工已经被停用,请联系管理员")
                      {
                          ErrorCode = Error_Password_InValid
                      };
            }


            #region 获取角色列表
            var roleCodeDs = vipBll.GetRoleCodeByUserId(rd.UserId, customerId);

            var tmp = roleCodeDs.Tables[0].AsEnumerable().Select(t => new RoleCodeInfo()
            {
                RoleCode = t["role_code"].ToString()
            });

            #endregion
            rd.UnitId = vipBll.GetUnitByUserId(rd.UserId);//获取会集店
            TUnitBLL tUnitBLL = new TUnitBLL(currentUserInfo);
            if (!string.IsNullOrEmpty(rd.UnitId))
            {
                rd.UnitName = tUnitBLL.GetByID(rd.UnitId).UnitName;
            }
            else
            {
                rd.UnitName = "";
            }


            //app登陆用户权限 add by henry 2015-3-26
            var roleCodeList = vipBll.GetAppMenuByUserId(rd.UserId);


            //app登陆用户权限 add by henry 2015-3-26
            List <string> lst = new List <string>();
            if (roleCodeDs.Tables[0] != null && roleCodeDs.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow item in roleCodeDs.Tables[0].Rows)
                {
                    var menuList = new JIT.CPOS.BS.DataAccess.AppSysService(currentUserInfo).GetRoleMenus(currentUserInfo.ClientID, item["role_id"] + "");
                    if (menuList != null)
                    {
                        lst.AddRange(menuList.Select(m => m.Menu_Code).Distinct().ToList());
                    }
                }
            }

            rd.MenuCodeList = new List <Menu>();
            foreach (var item in lst.Distinct().ToList())
            {
                rd.MenuCodeList.Add(new Menu()
                {
                    MenuCode = item
                });
            }

            //if (roleCodeList != null)
            //{
            //    rd.MenuCodeList = DataTableToObject.ConvertToList<Menu>(roleCodeList.Tables[0]);
            //}

            rd.RoleCodeList = tmp.ToArray();
            rd.CustomerName = currentUserInfo.ClientName;


            //销售员头像
            ObjectImagesBLL    _ObjectImagesBLL = new ObjectImagesBLL(currentUserInfo);
            ObjectImagesEntity en = new ObjectImagesEntity();
            en.ObjectId = rd.UserId;//根据获取的用户ID
            List <ObjectImagesEntity> ImgList = _ObjectImagesBLL.QueryByEntity(en, null).OrderByDescending(p => p.CreateTime).ToList();
            if (ImgList != null && ImgList.Count != 0)
            {
                // string fileDNS = customerBasicSettingBll.GetSettingValueByCode("FileDNS"); ;//http://182.254.156.57:811
                rd.HeadImg = ImgList[0].ImageURL;
            }


            #region 获取appLogo
            //基础数据初始化
            CustomerBasicSettingBLL      customerBasicSettingBLL = new CustomerBasicSettingBLL(currentUserInfo);
            List <CustomerBasicCodeInfo> customerBasicCodeList   = new List <CustomerBasicCodeInfo>();
            //查询条件
            CustomerBasicSettingEntity customerBasicSettingEntity = new CustomerBasicSettingEntity()
            {
                CustomerID  = currentUserInfo.ClientID,
                SettingCode = "WebLogo"
            };
            //执行查询
            List <CustomerBasicSettingEntity> customerBasicSettingEntityList = customerBasicSettingBLL.QueryByEntity(customerBasicSettingEntity, null).ToList();

            foreach (var a in customerBasicSettingEntityList)
            {
                CustomerBasicCodeInfo customerBasicCodeInfo = new CustomerBasicCodeInfo();

                if (a.SettingCode.Equals("WebLogo"))
                {
                    customerBasicCodeInfo.WebLogo = a.SettingValue.ToString();
                }
                customerBasicCodeList.Add(customerBasicCodeInfo);
            }

            rd.CustomerBasicCodeList = customerBasicCodeList;


            #endregion
            return(rd);
        }