• post方法


      /// <summary>
            /// post方法
            /// </summary>
            /// <param name="postUrl">url地址</param>
            /// <param name="paramData">提交的ParamData对象</param>
            /// <returns></returns>
            public static KeyValuePair<bool, string> PostWebRequest<T>(string postUrl, T paramData)
            {
                KeyValuePair<bool, string> res = new KeyValuePair<bool, string>(false, "");
                string ret = string.Empty;
                string md5Key = "L[tUbqSWnMcI#1qjV3bMPIv^pwS83y0b";
                try
                {
                    string str_Tem = JsonConvert.SerializeObject(paramData);//将对象转成json串
                    byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(str_Tem);
                    HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
                    webReq.Method = "POST";
                    webReq.ContentType = "application/json; charset=utf-8";
                    webReq.ContentLength = byteArray.Length;
                    if (BaseInfo.Cur._UserInfo != null)//除登录之外的接口,均需要传用户名,密码,token
                    {
                        webReq.Headers.Add("UserName", BaseInfo.Cur._UserInfo.UserName);
                        webReq.Headers.Add("UserPwd", BaseInfo.Cur._UserInfo.UserPwd);
                        webReq.Headers.Add("ApiToken", BaseInfo.Cur._UserInfo.ApiToken);
                        webReq.Headers.Add("MacAddress", BaseInfo.Cur._UserInfo.MacAddress);
                        webReq.Headers.Add("SchoolId", BaseInfo.Cur._UserInfo.SchoolId);
                    }
                    else
                    {
                        webReq.Headers.Add("WebApiUserName", BaseInfo.Cur.WebApiUserName);
                        webReq.Headers.Add("WebApiPWD", Encryption.GetMd5Hash(BaseInfo.Cur.WebApiPWD));
                    }
                    webReq.Headers.Add("sign", Encryption.GetMd5Hash(str_Tem + md5Key));
                    Stream newStream = webReq.GetRequestStream();
                    newStream.Write(byteArray, 0, byteArray.Length);//写入参数
                    newStream.Close();
                    HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                    StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    ret = sr.ReadToEnd();
                    res = new KeyValuePair<bool, string>(true, ret);
                    sr.Close();
                    response.Close();
                    newStream.Close();
                }
                catch (Exception ex)
                {
                    res = new KeyValuePair<bool, string>(false, ex.Message);
                }
                return res;
            }

     cache

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    
    namespace Wisdom.JPClient.Common
    {
        public class CacheHelper
        {
            /// <summary>
            /// 获取数据缓存
            /// </summary>
            /// <param name="CacheKey"></param>
            public static object GetCache(string CacheKey)
            {
                System.Web.Caching.Cache objCache = HttpRuntime.Cache;
                return objCache[CacheKey];
            }
    
            /// <summary>
            /// 设置数据缓存
            /// </summary>
            public static void SetCache(string CacheKey, object objObject)
            {
                System.Web.Caching.Cache objCache = HttpRuntime.Cache;
                objCache.Insert(CacheKey, objObject);
            }
    
            /// <summary>
            /// 设置数据缓存
            /// </summary>
            public static void SetCache(string CacheKey, object objObject, TimeSpan Timeout)
            {
                System.Web.Caching.Cache objCache = HttpRuntime.Cache;
                objCache.Insert(CacheKey, objObject, null, DateTime.MaxValue, Timeout, System.Web.Caching.CacheItemPriority.NotRemovable, null);
            }
    
            /// <summary>
            /// 设置数据缓存
            /// </summary>
            public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
            {
                System.Web.Caching.Cache objCache = HttpRuntime.Cache;
                objCache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
            }
    
            /// <summary>
            /// 移除指定数据缓存
            /// </summary>
            public static void RemoveAllCache(string CacheKey)
            {
                System.Web.Caching.Cache _cache = HttpRuntime.Cache;
                _cache.Remove(CacheKey);
            }
    
            /// <summary>
            /// 移除全部缓存
            /// </summary>
            public static void RemoveAllCache()
            {
                System.Web.Caching.Cache _cache = HttpRuntime.Cache;
                IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
                while (CacheEnum.MoveNext())
                {
                    _cache.Remove(CacheEnum.Key.ToString());
                }
            }
    
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net.Http;
    using System.Web;
    using Wisdom.JPClient.Common;
    using Wisdom.JPClient.Model;
    using Wisdom.JPClient.BLL.Logic;
    using System.IO;
    using System.Text;
    
    namespace Wisdom.JPClient.WebApi.Controllers
    {
        public class AuthorizeFilter : System.Web.Http.Filters.ActionFilterAttribute
        {
            /// <summary>
            /// 接口认证
            /// </summary>
            /// <param name="filterContext"></param>
            public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
            {
                base.OnActionExecuting(actionContext);
                ApiResult<string> res = new ApiResult<string>();
                var headers = HttpContext.Current.Request.Headers;
                string userName = "";
                string userPwd = "";
                string apiToken = "";
                string macAddress = "";
                string schoolId = "";
                string[] keys = headers.AllKeys;
                string sign = "";
                if (keys.Contains("sign"))
                    sign = headers.GetValues("sign").First();
                if (string.IsNullOrEmpty(sign) || !CheckSign(actionContext, sign))
                {
                    res.ResultFlag = -1;
                    res.ResultMsg = "签名校验失败!";
                    actionContext.Response = HttpHelper.ResponseMessagetoJson(res);
                    return;
                }
                try
                {
                    if (keys.Contains("UserName"))
                        userName = headers.GetValues("UserName").First();
                    if (keys.Contains("UserPwd"))
                        userPwd = headers.GetValues("UserPwd").First();
                    if (keys.Contains("ApiToken"))
                        apiToken = headers.GetValues("ApiToken").First();
                    if (keys.Contains("MacAddress"))
                        macAddress = headers.GetValues("MacAddress").First();
                    if (keys.Contains("SchoolId"))
                        schoolId = headers.GetValues("SchoolId").First();
                    if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(userPwd) && !string.IsNullOrEmpty(apiToken) && !string.IsNullOrEmpty(macAddress) && !string.IsNullOrEmpty(schoolId))
                    {
                        //验证token
                        TokenModel tokenModel = CacheHelper.GetCache(userName.ToUpper() + schoolId.ToUpper()) as TokenModel;
                        if (tokenModel != null)
                        {
                            //if (apiToken == tokenModel.TokenId)
                            //{
                                //验证成功,重置过期时间
                                CacheHelper.SetCache(tokenModel.UserName.ToUpper() + tokenModel.SchoolId.ToUpper(), tokenModel, TimeSpan.FromMinutes(30));
                                return;
                            //}
                            //else//token不相同,说明已经在其他电脑登录
                            //{
                            //    res.ResultFlag = -1;
                            //    res.ResultMsg = "您的账号已经在其他电脑登录,请退出重新登录!";
                            //    actionContext.Response = HttpHelper.ResponseMessagetoJson(res);
                            //    return;
                            //}
                        }
                        else//token不存在,重新登录
                        {
                            LoginParamModel userEntity = new LoginParamModel();
                            userEntity.LoginIP = ApiCommon.GetIP();
                            userEntity.MacAddress = macAddress;
                            userEntity.UserName = userName;
                            userEntity.UserPwd = userPwd;
                            userEntity.SchoolId = schoolId;
                            ApiResult<LoginUserInfo> loginRes = new AdminUserLogic().LogOn(userEntity);
                            if (res.ResultFlag == 1 && res.ResultObj != null)
                            {
                                //重新登录成功
                                return;
                            }
                        }
                    }
                    res.ResultFlag = -1;
                    res.ResultMsg = "授权验证失败!";
                    actionContext.Response = HttpHelper.ResponseMessagetoJson(res);
                }
                catch
                {
                    res.ResultFlag = -1;
                    res.ResultMsg = "授权验证失败!";
                    actionContext.Response = HttpHelper.ResponseMessagetoJson(res);
                }
    
            }
    
            private bool CheckSign(System.Web.Http.Controllers.HttpActionContext actionContext, string sign)
            {
                var content = string.Empty;
                var task = actionContext.Request.Content.ReadAsStreamAsync();
                string md5Key = "L[tUbqSWnMcI#1qjV3bMPIv^pwS83y0b";
                using (System.IO.Stream sm = task.Result)
                {
                    if (sm != null)
                    {
                        sm.Seek(0, SeekOrigin.Begin);
                        int len = (int)sm.Length;
                        byte[] inputByts = new byte[len];
                        sm.Read(inputByts, 0, len);
                        sm.Close();
                        content = Encoding.UTF8.GetString(inputByts);
                    }
                }
                string md5Sign = Encryption.GetMd5Hash(content + md5Key);
                if (md5Sign == sign)
                {
                    return true;
                }
                return false;
            }
        }
    
        //登录时使用,无token
        public class AuthorizeFilterNoToken : System.Web.Http.Filters.ActionFilterAttribute
        {
            /// <summary>
            /// 接口认证
            /// </summary>
            /// <param name="filterContext"></param>
            public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
            {
                base.OnActionExecuting(actionContext);
                ApiResult<string> res = new ApiResult<string>();
                var headers = HttpContext.Current.Request.Headers;
                string userName = "";
                string userPwd = "";
                string[] keys = headers.AllKeys;
                string sign = "";
                if (keys.Contains("sign"))
                    sign = headers.GetValues("sign").First();
                if (string.IsNullOrEmpty(sign) || !CheckSign(actionContext, sign))
                {
                    res.ResultFlag = -1;
                    res.ResultMsg = "签名校验失败!";
                    actionContext.Response = HttpHelper.ResponseMessagetoJson(res);
                    return;
                }
                try
                {
                    if (keys.Contains("WebApiUserName"))
                        userName = headers.GetValues("WebApiUserName").First();
                    if (keys.Contains("WebApiPWD"))
                        userPwd = headers.GetValues("WebApiPWD").First();
                    ClientSysUserEntity sysUser = new ClientSysUserEntity();
                    sysUser.UserName = userName;
                    sysUser = new ClientSysUserLogic().SelectCommand(sysUser);
                    if (userName == "" || sysUser.UserPwd == "" || sysUser == null || sysUser.UserPwd.ToLower() != userPwd.ToLower())
                    {
                        res.ResultFlag = -1;
                        res.ResultMsg = "授权验证失败!";
                        actionContext.Response = HttpHelper.ResponseMessagetoJson(res);
                    }
                    else if (DateTime.Now > (sysUser.ExpTime ?? DateTime.MinValue))
                    {
                        res.ResultFlag = -1;
                        res.ResultMsg = "授权口令已过期,请联系管理员!";
                        actionContext.Response = HttpHelper.ResponseMessagetoJson(res);
                    }
                }
                catch
                {
                    res.ResultFlag = -1;
                    res.ResultMsg = "授权验证失败!";
                    actionContext.Response = HttpHelper.ResponseMessagetoJson(res);
                }
    
            }
    
            private bool CheckSign(System.Web.Http.Controllers.HttpActionContext actionContext, string sign)
            {
                var content = string.Empty;
                var task = actionContext.Request.Content.ReadAsStreamAsync();
                string md5Key = "L[tUbqSWnMcI#1qjV3bMPIv^pwS83y0b";
                using (System.IO.Stream sm = task.Result)
                {
                    if (sm != null)
                    {
                        sm.Seek(0, SeekOrigin.Begin);
                        int len = (int)sm.Length;
                        byte[] inputByts = new byte[len];
                        sm.Read(inputByts, 0, len);
                        sm.Close();
                        content = Encoding.UTF8.GetString(inputByts);
                    }
                }
                string md5Sign = Encryption.GetMd5Hash(content + md5Key);
                if (md5Sign == sign)
                {
                    return true;
                }
                return false;
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Net.Http;
    using System.Text;
    using System.Web;
    using System.Web.Http;
    using Newtonsoft.Json;
    using Wisdom.DAL.Framework.Base.Validator;
    using Wisdom.JPClient.BLL.Logic;
    using Wisdom.JPClient.Common;
    using Wisdom.JPClient.Model;
    
    namespace Wisdom.JPClient.WebApi.Controllers
    {
        public class AccountController : ApiController
        {
            //
            // GET: /Account/
            [HttpPost]
            [AuthorizeFilterNoToken]
            public HttpResponseMessage Login([FromBody] object value)
            {
                ApiResult<LoginUserInfo> res = new ApiResult<LoginUserInfo>();
                try
                {
                    LoginParamModel userEntity = JsonConvert.DeserializeObject<LoginParamModel>(JsonConvert.SerializeObject(value));
                    if (userEntity != null && !string.IsNullOrEmpty(userEntity.UserName.Trim()) && !string.IsNullOrEmpty(userEntity.UserPwd.Trim()))
                    {
                        var headers = HttpContext.Current.Request.Headers;
                        string[] keys = headers.AllKeys;
                        string apiUserName = "";
                        if (keys.Contains("WebApiUserName"))
                            apiUserName = headers.GetValues("WebApiUserName").First();
                        ClientSysUserEntity sysUser = new ClientSysUserEntity();
                        sysUser.UserName = apiUserName;
                        sysUser = new ClientSysUserLogic().SelectCommand(sysUser);
                        userEntity.SchoolId = sysUser.SchoolId;
                        userEntity.LoginIP = ApiCommon.GetIP();
                        res = new AdminUserLogic().LogOn(userEntity);
                    }
                    else
                    {
                        res.ResultFlag = 0;
                        res.ResultMsg = "参数错误";
                        res.ResultObj = null;
                    }
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-Login");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
    
            [HttpGet]
            public HttpResponseMessage Index()
            {
                return HttpHelper.ResponseMessagetoJson("Hello!");
            }
    
            [HttpPost]
            [AuthorizeFilter]
            public HttpResponseMessage GetMenu([FromBody] object value)
            {
                List<SysMenu_BySchoolEntity> result_list = new List<SysMenu_BySchoolEntity>();
                ApiResult<List<SysMenu_BySchoolEntity>> res = new ApiResult<List<SysMenu_BySchoolEntity>>();
                int tem_children = 0;//判断 子菜单下面的操作是否被赋权限
                try
                {
                    LoginUserInfo userEntity = JsonConvert.DeserializeObject<LoginUserInfo>(JsonConvert.SerializeObject(value));
                    //查询功能权限
                    FunRightLogic frLogic = new FunRightLogic();
                    DataTable dtFunRight = frLogic.GetFunRightByRoleid(Convert.ToInt32(userEntity.UserId));
                    //查询所有菜单
                    List<SysMenu_BySchoolEntity> lstMenu = new List<SysMenu_BySchoolEntity>();
                    if (userEntity.IsHeadSchool == 0)
                    {
                        lstMenu = new SysMenu_BySchoolLogic().GetSysMenu_BySchoolList(userEntity.SchoolId, "0");
                    }
                    else {  //如果是分校查出主校的所有菜单
                        lstMenu = new SysMenu_BySchoolLogic().GetSysMenu_BySchoolList(userEntity.HeadSchoolID, "0");
                    }
                    //1系统管理员 3驾校管理员 返回所有菜单
                    if (userEntity.UserType == 1 || userEntity.UserType == 3)
                    {
                        res.ResultFlag = 1;
                        res.ResultObj = lstMenu;
                        return HttpHelper.ResponseMessagetoJson(res);
                    }
    
                    //List<RolesEntity> Role_list = new List<RolesEntity>();
                    //RolesLogic Role_bll = new RolesLogic();
    
                    //Role_list = Role_bll.SelectCommandList(" 1=1 and id in (select RoleId from [dbo].[UserRole] where IsDelete=0 and  UserId=" + userEntity.UserId + ")");
    
    
                    List<SysMenu_BySchoolEntity> pMenu = lstMenu.FindAll(p => p.M_ParentID == 0).OrderBy(p => p.M_Seq).ToList();
                    foreach (SysMenu_BySchoolEntity itemParent in pMenu)//父菜单
                    {
                        List<SysMenu_BySchoolEntity> cMenu = lstMenu.FindAll(p => p.M_ParentID == itemParent.M_Id).OrderBy(p => p.M_Seq).ToList();
                        tem_children = 0;
                        foreach (SysMenu_BySchoolEntity itemChild in cMenu)//子菜单
                        {
                            DataRow[] getUser_dtFunRight = dtFunRight.Select("ParentId=" + itemChild.M_Id.ToString());//看是否有菜单权限相应操作权限
                            if (getUser_dtFunRight != null && getUser_dtFunRight.Length > 0)
                            {
                                result_list.Add(itemChild);//添加到子菜单
                                tem_children++;
                            }
                        }
                        if (tem_children != 0)//当有相应的模块子操作权限时  显示模块
                        {
                            result_list.Add(itemParent);//添加到父菜单
                        }
                    }
    
    
                    //selectEntity.M_IsDel = 0;
                    res.ResultFlag = 1;
                    res.ResultObj = result_list;
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-GetMenu");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
    
            [HttpPost]
            [AuthorizeFilter]
            public HttpResponseMessage GetMenu1([FromBody] object value)
            {
                ApiResult<List<SysMenuEntity>> res = new ApiResult<List<SysMenuEntity>>();
                try
                {
                    RolesEntity userEntity = JsonConvert.DeserializeObject<RolesEntity>(JsonConvert.SerializeObject(value));
                    SysMenuEntity selectEntity = new SysMenuEntity();
                    selectEntity.M_IsDel = 0;
                    res.ResultFlag = 1;
                    res.ResultObj = new SysMenuLogic().SelectCommandList(selectEntity);
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-GetMenu");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
    
            [HttpPost]
            [AuthorizeFilter]
            public HttpResponseMessage GetFunRightByRoleId([FromBody] object value)
            {
                ApiResult<List<TreeNodeItem>> res = new ApiResult<List<TreeNodeItem>>();
                try
                {
                    RolesEntity roleEntity = JsonConvert.DeserializeObject<RolesEntity>(JsonConvert.SerializeObject(value));
                    if (roleEntity.id > 0)
                    {
                        //查询功能权限
                        FunRightLogic frLogic = new FunRightLogic();
                        DataTable dtFunRight = frLogic.GetFunRightByRoleId(roleEntity.id ?? 0);
                        List<TreeNodeItem> treeList = new List<TreeNodeItem>();
                        //查询菜单
                        SysMenu_BySchoolEntity selectEntity = new SysMenu_BySchoolEntity();
                        selectEntity.M_IsDel = 0;
                        selectEntity.SchoolID = roleEntity.SchoolId;
                        res.ResultFlag = 1;
                        List<SysMenu_BySchoolEntity> lstMenu = new SysMenu_BySchoolLogic().SelectCommandList(selectEntity);
                        List<SysMenu_BySchoolEntity> pMenu = lstMenu.FindAll(p => p.M_ParentID == 0).OrderBy(p => p.M_Seq).ToList();
                        foreach (SysMenu_BySchoolEntity itemParent in pMenu)//父菜单
                        {
                            TreeNodeItem treeMenuParent = new TreeNodeItem()
                            {
                                DisplayName = itemParent.M_Name,
                                Name = itemParent.M_Name,
                                id = itemParent.M_Id ?? 0,
                                parentId = itemParent.M_ParentID ?? 0,
                                Type = 0,
                                IsExpanded = false
                            };
                            List<SysMenu_BySchoolEntity> cMenu = lstMenu.FindAll(p => p.M_ParentID == itemParent.M_Id).OrderBy(p => p.M_Seq).ToList();
                            foreach (SysMenu_BySchoolEntity itemChild in cMenu)//子菜单
                            {
                                TreeNodeItem treeMenuChild = new TreeNodeItem()
                                {
                                    DisplayName = itemChild.M_Name,
                                    Name = itemChild.M_Name,
                                    id = itemChild.M_Id ?? 0,
                                    parentId = itemChild.M_ParentID ?? 0,
                                    Type = 0,
                                    IsExpanded = false
                                };
                                //按钮
                                foreach (DataRow dr in dtFunRight.Select("ParentId=" + itemChild.M_Id.ToString()))
                                {
                                    TreeNodeItem btnMenu = new TreeNodeItem()
                                    {
                                        DisplayName = dr["Name"].ToString(),
                                        Name = dr["Name"].ToString(),
                                        id = Convert.ToInt32(dr["ID"]),
                                        parentId = itemChild.M_Id ?? 0,
                                        IsExpanded = false,
                                        Type = 1,
                                        IsChecked = dr["IsChecked"].ToString() == "1"
                                    };
                                    treeMenuChild.Children.Add(btnMenu);//添加到子菜单
                                }
                                treeMenuParent.Children.Add(treeMenuChild);//添加到父菜单
                            }
                            treeList.Add(treeMenuParent);//添加到菜单集合
                        }
                        res.ResultFlag = 1;
                        res.ResultObj = treeList;
                    }
                    else
                    {
                        res.ResultFlag = 0;
                        res.ResultMsg = "参数错误";
                        res.ResultObj = null;
                    }
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-GetFunRightByRoleId");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
    
            [HttpPost]
            [AuthorizeFilter]
            public HttpResponseMessage SaveFunRight([FromBody] object value)
            {
                ApiResult<RoleFunRightEntity> res = new ApiResult<RoleFunRightEntity>();
                try
                {
                    List<RoleFunRightEntity> roleList = JsonConvert.DeserializeObject<List<RoleFunRightEntity>>(JsonConvert.SerializeObject(value));
                    if (roleList.Count > 0)
                    {
                        string rightCodes = "";
                        int roleId = roleList[0].RoleId ?? 0;
                        foreach (RoleFunRightEntity role in roleList)
                        {
                            rightCodes += role.fRightId + ",";
                        }
                        rightCodes = rightCodes.Trim(',');
                        if (new FunRightLogic().SaveFunRight(roleId, rightCodes))
                        {
                            res.ResultFlag = 1;
                            res.ResultObj = null;
                        }
                        else
                        {
                            res.ResultFlag = 0;
                            res.ResultMsg = "数据存储失败";
                            res.ResultObj = null;
                        }
                    }
                    else
                    {
                        res.ResultFlag = 0;
                        res.ResultMsg = "参数错误";
                        res.ResultObj = null;
                    }
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-GetFunRightByRoleId");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
    
            [HttpPost]
            [AuthorizeFilter]
            public HttpResponseMessage GetDataRightByRoleId([FromBody] object value)
            {
                ApiResult<List<TreeNodeItem>> res = new ApiResult<List<TreeNodeItem>>();
                try
                {
                    RolesEntity roleEntity = JsonConvert.DeserializeObject<RolesEntity>(JsonConvert.SerializeObject(value));
                    if (roleEntity.id > 0)
                    {
                        List<TreeNodeItem> treeList = new List<TreeNodeItem>();
                        DataTable dt = new RoleDataRightLogic().GetDataRightByRoleId(roleEntity.id ?? 0);
                        TreeNodeItem node = new TreeNodeItem()
                        {
                            DisplayName = "组织结构",
                            Name = "组织结构",
                            id = 0,
                            parentId = 0,
                            parentPath = "0",
                            IsExpanded = false
                        };
                        ForeachPropertyNode(dt, node, 0);
                        treeList.Add(node);
                        res.ResultFlag = 1;
                        res.ResultObj = treeList;
                    }
                    else
                    {
                        res.ResultFlag = 0;
                        res.ResultMsg = "参数错误";
                        res.ResultObj = null;
                    }
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-GetDataRightByRoleId");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
            //递归绑定子节点
            private void ForeachPropertyNode(DataTable allList, TreeNodeItem node, int pid)
            {
                DataRow[] curList = allList.Select("ParentId=" + pid);
                if (curList.Length > 0)
                {
                    foreach (DataRow dr in curList)
                    {
                        TreeNodeItem childNodeItem = new TreeNodeItem()
                        {
                            DisplayName = dr["Name"].ToString(),
                            Name = dr["Name"].ToString(),
                            id = Convert.ToInt32(dr["ID"]),
                            parentId = pid,
                            IsExpanded = false,
                            Type = 1,
                            IsChecked = dr["IsChecked"].ToString() == "1"
                        };
                        ForeachPropertyNode(allList, childNodeItem, Convert.ToInt32(dr["ID"]));
                        node.Children.Add(childNodeItem);
                    }
                }
            }
            [HttpPost]
            [AuthorizeFilter]
            public HttpResponseMessage SaveDataRight([FromBody] object value)
            {
                ApiResult<RoleDataRightEntity> res = new ApiResult<RoleDataRightEntity>();
                try
                {
                    List<RoleDataRightEntity> roleList = JsonConvert.DeserializeObject<List<RoleDataRightEntity>>(JsonConvert.SerializeObject(value));
                    if (roleList.Count > 0)
                    {
                        string rightCodes = "";
                        int roleId = roleList[0].RoleId ?? 0;
                        foreach (RoleDataRightEntity role in roleList)
                        {
                            rightCodes += role.DepId + ",";
                        }
                        rightCodes = rightCodes.Trim(',');
                        if (new RoleDataRightLogic().SaveDataRight(roleId, rightCodes))
                        {
                            res.ResultFlag = 1;
                            res.ResultObj = null;
                        }
                        else
                        {
                            res.ResultFlag = 0;
                            res.ResultMsg = "数据存储失败";
                            res.ResultObj = null;
                        }
                    }
                    else
                    {
                        res.ResultFlag = 0;
                        res.ResultMsg = "参数错误";
                        res.ResultObj = null;
                    }
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-GetDataRightByRoleId");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
    
            [HttpPost]
            [AuthorizeFilter]
            public HttpResponseMessage UpdatePwd([FromBody] object value)
            {
                ApiResult<AdminUserEntity> res = new ApiResult<AdminUserEntity>();
                try
                {
                    AdminUserEntity userEntity = JsonConvert.DeserializeObject<AdminUserEntity>(JsonConvert.SerializeObject(value));
                    if (userEntity != null && userEntity.id > 0 && !string.IsNullOrEmpty(userEntity.Password.Trim()))
                    {
                        AdminUserLogic uLogic = new AdminUserLogic();
                        AdminUserEntity selectEntity = new AdminUserEntity();
                        selectEntity.id = userEntity.id;
                        selectEntity = uLogic.SelectCommand(selectEntity);
                        //YR_Messages字段用来传旧密码
                        if (selectEntity.Password.ToLower() == userEntity.YR_Message.ToLower())
                        {
                            if (uLogic.UpdateCommand(userEntity) > 0)
                            {
                                res.ResultFlag = 1;
                                res.ResultObj = null;
                                res.ResultMsg = "编辑密码成功。";
                            }
                            else
                            {
                                res.ResultFlag = 3;
                                res.ResultObj = null;
                                res.ResultMsg = "编辑密码失败。";
                            }
                        }
                        else
                        {
                            res.ResultFlag = 2;
                            res.ResultMsg = "旧密码错误。";
                            res.ResultObj = null;
                        }
                    }
                    else
                    {
                        res.ResultFlag = 0;
                        res.ResultMsg = "参数错误。";
                        res.ResultObj = null;
                    }
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-Login");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
            [HttpPost]
            [AuthorizeFilter]
            public HttpResponseMessage UpdateUserInfo([FromBody] object value)
            {
                ApiResult<AdminUserEntity> res = new ApiResult<AdminUserEntity>();
                try
                {
                    AdminUserEntity userEntity = JsonConvert.DeserializeObject<AdminUserEntity>(JsonConvert.SerializeObject(value));
                    if (userEntity != null && userEntity.id > 0)
                    {
                        AdminUserLogic uLogic = new AdminUserLogic();
                        if (uLogic.UpdateCommand(userEntity) > 0)
                        {
                            res.ResultFlag = 1;
                            res.ResultObj = null;
                            res.ResultMsg = "编辑用户信息成功。";
                        }
                        else
                        {
                            res.ResultFlag = 3;
                            res.ResultObj = null;
                            res.ResultMsg = "编辑用户信息失败。";
                        }
                    }
                    else
                    {
                        res.ResultFlag = 0;
                        res.ResultMsg = "参数错误。";
                        res.ResultObj = null;
                    }
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-Login");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
    
            ///// <summary>
            ///// 根据模块id和用户信息 查询 当前模块的用户用户 按钮权限
            ///// </summary>
            ///// <param name="value"></param>
            ///// <returns></returns>
            //[HttpPost]
            //[AuthorizeFilter]
            //public HttpResponseMessage GetOperateRightByRoleId([FromBody] object value)
            //{
            //    ApiResult<DataTable> res = new ApiResult<DataTable>();
            //    try
            //    {
            //        StudentParam_tem studentParam_tem = JsonConvert.DeserializeObject<StudentParam_tem>(JsonConvert.SerializeObject(value));
            //        if (studentParam_tem != null && studentParam_tem.UserID > 0)
            //        {
            //            DataTable dt = new RoleDataRightLogic().GetDataRightByUserID(studentParam_tem.UserID, studentParam_tem.Menu_Code);
            //            res.ResultFlag = 1;
            //            res.ResultObj = dt;
            //        }
            //        else
            //        {
            //            res.ResultFlag = 0;
            //            res.ResultMsg = "参数错误";
            //            res.ResultObj = null;
            //        }
            //    }
            //    catch (Exception ex)
            //    {
            //        res.ResultFlag = 0;
            //        res.ResultMsg = ex.Message;
            //        res.ResultObj = null;
            //        //写错误日志
            //        WebLogTool.WriteLog(ex, "AccountController-GetOperateRightByRoleId");
            //    }
            //    return HttpHelper.ResponseMessagetoJson(res);
            //}
    
            [HttpPost]
            public HttpResponseMessage GetClientUpdate([FromBody] object value)
            {
                ApiResult<ClientSysUpdateEntity> res = new ApiResult<ClientSysUpdateEntity>();
                try
                {
                    ClientSysUpdateEntity model = new ClientSysUpdateEntity();
                    model = new ClientSysUpdateLogic().SelectCommand("");
                    res.ResultFlag = 1;
                    res.ResultObj = model;
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-GetClientUpdate");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
    
            #region 驾校自定义菜单
            [HttpPost]
            [AuthorizeFilter]
            public HttpResponseMessage GetMenuBySchoolId([FromBody] object value)
            {
                ApiResult<List<SysMenu_BySchoolEntity>> res = new ApiResult<List<SysMenu_BySchoolEntity>>();
                try
                {
                    string schoolId = value.ToString();
                    if (!string.IsNullOrEmpty(schoolId))
                    {
                        //查询菜单
                        SysMenu_BySchoolEntity selectEntity = new SysMenu_BySchoolEntity();
                        //selectEntity.M_IsDel = 0; isDel=1为隐藏
                        selectEntity.SchoolID = schoolId;
                        res.ResultFlag = 1;
                        List<SysMenu_BySchoolEntity> lstMenu = new SysMenu_BySchoolLogic().SelectCommandList(selectEntity);
                        res.ResultFlag = 1;
                        res.ResultObj = lstMenu;
                    }
                    else
                    {
                        res.ResultFlag = 0;
                        res.ResultMsg = "参数错误";
                        res.ResultObj = null;
                    }
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-GetMenuBySchoolId");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
    
            [HttpPost]
            [AuthorizeFilter]
            public HttpResponseMessage SaveSchoolMenu([FromBody] object value)
            {
                ApiResult<string> res = new ApiResult<string>();
                try
                {
                    List<SysMenu_BySchoolEntity> lstMenu = JsonConvert.DeserializeObject<List<SysMenu_BySchoolEntity>>(JsonConvert.SerializeObject(value));
                    if (lstMenu != null && lstMenu.Count>0)
                    {
                        int r=new SysMenu_BySchoolLogic().SaveMenu(lstMenu);
                        if (r > 0)
                        {
                            res.ResultFlag = 1;
                            res.ResultObj = null;
                        }
                        else
                        {
                            res.ResultFlag = -1;
                            res.ResultObj = null;
                            res.ResultMsg = "保存失败,系统错误!";
                        }
                    }
                    else
                    {
                        res.ResultFlag = 0;
                        res.ResultMsg = "参数错误";
                        res.ResultObj = null;
                    }
                }
                catch (Exception ex)
                {
                    res.ResultFlag = 0;
                    res.ResultMsg = ex.Message;
                    res.ResultObj = null;
                    //写错误日志
                    WebLogTool.WriteLog(ex, "AccountController-SaveSchoolMenu");
                }
                return HttpHelper.ResponseMessagetoJson(res);
            }
            #endregion
        }
    }
  • 相关阅读:
    Mac OS使用brew安装memcached
    Mac OS使用brew安装memcached
    Mac OS使用brew安装memcached
    JAVA学习之路 (五) 类
    JAVA学习之路 (五) 类
    JAVA学习之路 (五) 类
    JAVA学习之路 (五) 类
    常用的CSS小技巧
    常用的CSS小技巧
    常用的CSS小技巧
  • 原文地址:https://www.cnblogs.com/muxueyuan/p/5591178.html
Copyright © 2020-2023  润新知