Exemple #1
0
        /// <summary>
        /// 获取用户权限
        /// </summary>
        /// <param name="userCheckList"></param>
        /// <returns></returns>
        public dynamic GetWeChatUserPermissions(object userCheckList)
        {
            List <MED_WECHAT_PERMISSIONS> permissionList = new List <MED_WECHAT_PERMISSIONS>();

            try
            {
                string objUserValue = JsonConvert.SerializeObject(GetWeChatUsers(""));

                List <MED_WECHAT_USERS> weChatUsers = JsonConvert.DeserializeObject <List <MED_WECHAT_USERS> >(objUserValue);

                string objPermissionValue = JsonConvert.SerializeObject(GetWeChatPermissions(""));

                List <MED_WECHAT_PERMISSIONS> weChatUserPermissions = JsonConvert.DeserializeObject <List <MED_WECHAT_PERMISSIONS> >(objPermissionValue);

                if (userCheckList != null)
                {
                    string[] userList = JsonConvert.DeserializeObject <string[]>(userCheckList.ToString());


                    foreach (var item in userList)
                    {
                        MED_WECHAT_USERS weChatUser = weChatUsers.Find(t => t.USER_JOB_ID == item);

                        if (weChatUser != null)
                        {
                            MED_WECHAT_PERMISSIONS weChatUserPermission = weChatUserPermissions.Find(t => t.PERMISSION_ID == weChatUser.PERMISSION_ID);

                            permissionList.Add(weChatUserPermission);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("获取用户权限GetWeChatUserPermissions:", ex);
            }
            return(permissionList);
        }
Exemple #2
0
        /// <summary>
        /// 保存用户数据
        /// </summary>
        /// <param name="userCheckList"></param>
        /// <param name="roleCheckList"></param>
        /// <param name="menuCheckList"></param>
        /// <returns></returns>
        public int SaveWeChatUsersPermission(object userCheckList, object roleCheckList, object menuCheckList)
        {
            int result = 0;

            try
            {
                string objValue = JsonConvert.SerializeObject(GetWeChatUsers(""));

                List <MED_WECHAT_USERS> weChatUsersList = JsonConvert.DeserializeObject <List <MED_WECHAT_USERS> >(objValue);

                string[] userList = JsonConvert.DeserializeObject <string[]>(userCheckList.ToString());

                string[] roleList = JsonConvert.DeserializeObject <string[]>(roleCheckList.ToString());

                string[] menuList = JsonConvert.DeserializeObject <string[]>(menuCheckList.ToString());



                string objPermissionValue = JsonConvert.SerializeObject(GetWeChatPermissions(""));

                List <MED_WECHAT_PERMISSIONS> weChatPermissionsList = JsonConvert.DeserializeObject <List <MED_WECHAT_PERMISSIONS> >(objPermissionValue);


                foreach (string userStr in userList)
                {
                    MED_WECHAT_USERS weChatUser = weChatUsersList.Find(t => t.USER_JOB_ID == userStr);

                    if (weChatUser != null)
                    {
                        MED_WECHAT_PERMISSIONS weChatPermission = weChatPermissionsList.Find(t => t.PERMISSION_ID == weChatUser.PERMISSION_ID);

                        if (weChatPermission != null)
                        {
                            // 已有权限

                            weChatPermission.ROLE_NAME = JsonConvert.SerializeObject(roleList);

                            weChatPermission.PLAT_NAME = "麻醉微信公众号";

                            weChatPermission.PERMISSION_NAME = JsonConvert.SerializeObject(menuList);

                            result = dapper.Set <MED_WECHAT_PERMISSIONS>().Update(weChatPermission) > 0 ? 1 : 0;
                        }
                        else
                        {
                            // 还没有建立权限

                            MED_WECHAT_PERMISSIONS weChatPermissionInsert = new MED_WECHAT_PERMISSIONS();

                            //保证GUID 唯一
                            do//先执行一次,再判断。
                            {
                                weChatPermissionInsert.PERMISSION_ID = Guid.NewGuid().ToString();
                            }while (dapper.Set <MED_WECHAT_PERMISSIONS>().Single(d => d.PERMISSION_ID == weChatPermissionInsert.PERMISSION_ID) != null);

                            weChatPermissionInsert.ROLE_NAME = JsonConvert.SerializeObject(roleList);

                            weChatPermissionInsert.PLAT_NAME = "麻醉微信公众号";

                            weChatPermissionInsert.PERMISSION_NAME = JsonConvert.SerializeObject(menuList);

                            int count = dapper.Set <MED_WECHAT_PERMISSIONS>().Insert(weChatPermissionInsert) ? 1 : 0;

                            if (count == 1)
                            {
                                //更新用户表 权限ID
                                weChatUser.PERMISSION_ID = weChatPermissionInsert.PERMISSION_ID;

                                result = dapper.Set <MED_WECHAT_USERS>().Update(weChatUser) > 0 ? 1 : 0;
                            }
                        }
                    }
                }

                dapper.SaveChanges();
            }
            catch (Exception ex)
            {
                Logger.Error("保存用户数据SaveWeChatUsersPermission:", ex);
            }
            return(result);
        }