winform+dev的前后台分离标准项目
lg
2024-08-29 f9f3b38bf70e71f8181df4a064d1e210e2b53545
用户管理
已修改3个文件
350 ■■■■■ 文件已修改
WebApi/Gs.User/Service/MenuActionController.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebApi/Gs.User/Service/OrganizationController.cs 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebApi/Gs.User/Service/UserController.cs 332 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebApi/Gs.User/Service/MenuActionController.cs
@@ -127,7 +127,6 @@
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<int?> EditModel([FromBody] MenuAction model)
        {
            string dddd = model.guid.ToString();
            Guid? guid = model.guid;
            Guid? upGuid = model.upGuid;
            string name = model.name;
WebApi/Gs.User/Service/OrganizationController.cs
@@ -60,13 +60,13 @@
                foreach (DataRow dr in dset.Tables[0].Rows)
                {
                    _pglist.list.Add(
                        new
                        new
                        {
                            guid = Guid.Parse(dr["guid"].ToString()),
                            upGuid = dr["upGuid"].ToString(),
                            name = dr["name"].ToString(),
                            conPeople = dr["conPeople"].ToString(),
                            conTel = int.Parse(dr["conTel"].ToString()),
                            conTel = dr["conTel"].ToString(),
                            status = int.Parse(dr["status"].ToString()),
                        }
                    );
@@ -115,13 +115,22 @@
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<int?> EditModel([FromBody] dynamic model)
        {
            Guid? guid = model.guid;
            Guid? upGuid = model.upGuid;
            Guid? guid = UtilityHelper.GetGuid(model.guid.ToString());
            Guid? upGuid = UtilityHelper.GetGuid(model.upGuid.ToString());
            string name = model.name;
            string conPeople = model.conPeople;
            string conTel = model.conTel;
            int status = model.status;
            int? rtnInt = (int)ReturnCode.Default;
            if (upGuid == null)//只能有一个根组织
            {
                int cont = 0;
                cont = int.Parse(DbHelperSQL.GetSingle("select count(1) from sys_Organization where upguid is null").ToString());
                if (cont > 0)
                {
                    return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "增加失败,请选择上级组织!");
                }
            }
            StringBuilder strSql = new StringBuilder();
            if (guid != null)
            {
WebApi/Gs.User/Service/UserController.cs
@@ -9,6 +9,9 @@
using System.Text;
using Gs.User.Modes;
using System.Diagnostics;
using System.Diagnostics.Metrics;
using System.Security.Principal;
using System.Net;
namespace Gs.User.Service
{
@@ -78,7 +81,7 @@
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<System.Dynamic.ExpandoObject> GetUserInfo([FromBody] UserLogin model)
        public ReturnDto<System.Dynamic.ExpandoObject> GetUserLoginInfo([FromBody] UserLogin model)
        {
            Guid userGuid = model.userGuid;
            DataSet dset = new DataSet();
@@ -140,5 +143,332 @@
            }
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Exception, "登录失败!");
        }
        #region
        /// <summary>
        /// 读取列表,支持分页
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<PageList<dynamic>> GetListPage([FromBody] PageQuery model)
        {
            int currentPage = model.currentPage;
            int everyPageSize = model.everyPageSize;
            string sortName = string.IsNullOrEmpty(model.sortName) ? "a.name" : model.sortName;
            System.Text.StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select * from ");
            sbSql.Append("( ");
            sbSql.Append("select top 100000 ROW_NUMBER() over(order by " + sortName + " " + model.sortOrder + ") as rowIndex,* from sys_User a where 1=1" + model.keyWhere);
            sbSql.Append(") as T ");
            sbSql.Append(" where T.rowindex>(" + currentPage + "-1)*" + everyPageSize + " and  T.rowindex<=" + currentPage + "*" + everyPageSize + "");
            sbSql.Append(" select count(1) as intTotal  from sys_User a where 1=1 " + model.keyWhere).ToString();
            DataSet dset = new DataSet();
            try
            {
                dset = Gs.Toolbox.DbHelperSQL.Query(sbSql.ToString());
            }
            catch (Exception ex)
            {
                Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetListPage error:" + ex.Message);
                return ReturnDto<PageList<dynamic>>.QuickReturn(default(PageList<dynamic>), ReturnCode.Exception, "读取失败");
            }
            PageList<dynamic> _pglist = new PageList<dynamic>
            {
                total = 0,
                everyPageSize = 0,
                pages = 0,
                list = new List<dynamic>()
            };
            if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)//有数据
            {
                int intTotal = int.Parse(dset.Tables[1].Rows[0]["intTotal"].ToString());
                int pages = (intTotal % everyPageSize != 0) ? (intTotal / everyPageSize + 1) : (intTotal / everyPageSize);
                _pglist.total = intTotal;
                _pglist.everyPageSize = everyPageSize;
                _pglist.pages = pages;
                foreach (DataRow row in dset.Tables[0].Rows)
                {
                    Sys_User _model = new Sys_User();
                    if (row["guid"] != null && row["guid"].ToString() != "")
                    {
                        _model.guid = new Guid(row["guid"].ToString());
                    }
                    if (row["account"] != null)
                    {
                        _model.account = row["account"].ToString();
                    }
                    if (row["password"] != null && row["password"].ToString() != "")
                    {
                        _model.password = new Guid(row["password"].ToString());
                    }
                    if (row["userName"] != null)
                    {
                        _model.userName = row["userName"].ToString();
                    }
                    if (row["address"] != null)
                    {
                        _model.address = row["address"].ToString();
                    }
                    if (row["tel"] != null)
                    {
                        _model.tel = row["tel"].ToString();
                    }
                    if (row["email"] != null)
                    {
                        _model.email = row["email"].ToString();
                    }
                    if (row["lastLoginTime"] != null && row["lastLoginTime"].ToString() != "")
                    {
                        _model.lastLoginTime = DateTime.Parse(row["lastLoginTime"].ToString());
                    }
                    if (row["lastLogoutTime"] != null && row["lastLogoutTime"].ToString() != "")
                    {
                        _model.lastLogoutTime = DateTime.Parse(row["lastLogoutTime"].ToString());
                    }
                    if (row["isLocked"] != null && row["isLocked"].ToString() != "")
                    {
                        _model.isLocked = int.Parse(row["isLocked"].ToString());
                    }
                    if (row["createTime"] != null && row["createTime"].ToString() != "")
                    {
                        _model.createTime = DateTime.Parse(row["createTime"].ToString());
                    }
                    if (row["flagAdmin"] != null && row["flagAdmin"].ToString() != "")
                    {
                        _model.flagAdmin = int.Parse(row["flagAdmin"].ToString());
                    }
                    if (row["flagOnline"] != null && row["flagOnline"].ToString() != "")
                    {
                        _model.flagOnline = int.Parse(row["flagOnline"].ToString());
                    }
                    if (row["loginCounter"] != null && row["loginCounter"].ToString() != "")
                    {
                        _model.loginCounter = int.Parse(row["loginCounter"].ToString());
                    }
                    if (row["workerID"] != null)
                    {
                        _model.workerID = row["workerID"].ToString();
                    }
                    if (row["remark"] != null)
                    {
                        _model.remark = row["remark"].ToString();
                    }
                    if (row["departGuid"] != null && row["departGuid"].ToString() != "")
                    {
                        _model.departGuid = new Guid(row["departGuid"].ToString());
                    }
                    if (row["isSys"] != null && row["isSys"].ToString() != "")
                    {
                        _model.isSys = int.Parse(row["isSys"].ToString());
                    }
                    _pglist.list.Add(_model);
                }
            }
            return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist, ReturnCode.Success, "读取成功");
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<int?> DeleteModel([FromBody] string guidList)
        {
            int rtnInt = (int)ReturnCode.Default;
            int cont = 0;
            try
            {
                //是否内置
                cont = int.Parse(DbHelperSQL.GetSingle("select count(1) from sys_User where   [isSys]=1 and guid in split('" + guidList + "',',')").ToString());
                if (cont > 0)
                {
                    return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "删除失败,该条目为系统内置,不可删除!");
                }
                StringBuilder strSql = new StringBuilder();
                strSql.Append("delete from sys_User ");
                strSql.Append(" where guid in (" + guidList + ")  ");
                int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
                rtnInt = rows;
            }
            catch (Exception ex)
            {
                LogHelper.Debug(this.ToString(), "DeleteModel error:" + ex.Message);
                rtnInt = (int)ReturnCode.Exception;
            }
            if (rtnInt > 0)
                return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Success, "操作成功,共删除" + rtnInt.ToString() + "条数据!");
            else
                return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "删除失败,请重试!");
        }
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<int?> EditModel([FromBody] Sys_User model)
        {
            Guid? guid = model.guid;
            string strPass = Guid.NewGuid().ToString();
            int? rtnInt = (int)ReturnCode.Default;
            if (guid == null)
            {
                int cont = 0;
                cont = int.Parse(DbHelperSQL.GetSingle("select count(1) from sys_User where account='" + guid.ToString() + "'").ToString());
                if (cont > 0)
                {
                    return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "增加失败,该账号已存在!");
                }
            }
            StringBuilder strSql = new StringBuilder();
            if (guid != null)
            {
                strSql.Append(" UPDATE [dbo].[sys_User]");
                strSql.Append(" SET [userName] = @userName ,[address] =@address ,[tel] = @tel,[email] = @email ,[isLocked] =@isLocked,[createTime] = getdate() ,[flagAdmin] =@flagAdmin,[workerID] =@workerID ,[remark] = @remark,[departGuid] = @departGuid ");
                strSql.Append(" where guid='" + guid + "'");
            }
            else
            {
                guid = Guid.NewGuid();
                strSql.Append("insert into sys_User");
                strSql.Append(" ([guid],[account],[password],[userName],[address],[tel],[email],[isLocked],[createTime],[flagAdmin],[flagOnline],[loginCounter],[workerID],[remark],[departGuid])");
                strSql.Append(" values (");
                strSql.Append("'" + guid + "',@account,'" + strPass + "',@userName,@address,@tel,@email,@isLocked,getdate(),@flagAdmin,0,0 ,@workerID,@remark,@departGuid)");
            }
            SqlParameter[] parameters = {
             new SqlParameter("@account", model.account),
             new SqlParameter("@userName",model.userName),
             new SqlParameter("@address",model.address),
             new SqlParameter("@tel",model.tel),
             new SqlParameter("@email",model.email),
             new SqlParameter("@isLocked",model.isLocked),
             new SqlParameter("@flagAdmin",model.flagAdmin),
             new SqlParameter("@workerID",model.workerID),
             new SqlParameter("@remark",model.remark),
             new SqlParameter("@departGuid",model.departGuid),
         };
            try
            {
                rtnInt = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            }
            catch (Exception ex)
            {
                LogHelper.Debug(this.ToString(), "EditModel error:" + ex.Message);
                rtnInt = (int)ReturnCode.Exception;
            }
            if (rtnInt > 0)
                return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success, "操作成功!");
            else
                return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception, "增加失败,请重试!");
        }
        /// <summary>
        /// 读取
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        [AllowAnonymous]
        public ReturnDto<Sys_User> GetModel([FromBody] Sys_User model)
        {
            Sys_User _model = new Sys_User();
            System.Text.StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select top 1 * from sys_Organization where 1=1 and guid='" + model.guid.ToString() + "' ");
            try
            {
                DataSet dset = new DataSet();
                dset = DbHelperSQL.Query(sbSql.ToString());
                if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)
                {
                    System.Data.DataRow row = dset.Tables[0].Rows[0];
                    if (row["guid"] != null && row["guid"].ToString() != "")
                    {
                        _model.guid = new Guid(row["guid"].ToString());
                    }
                    if (row["account"] != null)
                    {
                        _model.account = row["account"].ToString();
                    }
                    if (row["password"] != null && row["password"].ToString() != "")
                    {
                        _model.password = new Guid(row["password"].ToString());
                    }
                    if (row["userName"] != null)
                    {
                        _model.userName = row["userName"].ToString();
                    }
                    if (row["address"] != null)
                    {
                        _model.address = row["address"].ToString();
                    }
                    if (row["tel"] != null)
                    {
                        _model.tel = row["tel"].ToString();
                    }
                    if (row["email"] != null)
                    {
                        _model.email = row["email"].ToString();
                    }
                    if (row["lastLoginTime"] != null && row["lastLoginTime"].ToString() != "")
                    {
                        _model.lastLoginTime = DateTime.Parse(row["lastLoginTime"].ToString());
                    }
                    if (row["lastLogoutTime"] != null && row["lastLogoutTime"].ToString() != "")
                    {
                        _model.lastLogoutTime = DateTime.Parse(row["lastLogoutTime"].ToString());
                    }
                    if (row["isLocked"] != null && row["isLocked"].ToString() != "")
                    {
                        _model.isLocked = int.Parse(row["isLocked"].ToString());
                    }
                    if (row["createTime"] != null && row["createTime"].ToString() != "")
                    {
                        _model.createTime = DateTime.Parse(row["createTime"].ToString());
                    }
                    if (row["flagAdmin"] != null && row["flagAdmin"].ToString() != "")
                    {
                        _model.flagAdmin = int.Parse(row["flagAdmin"].ToString());
                    }
                    if (row["flagOnline"] != null && row["flagOnline"].ToString() != "")
                    {
                        _model.flagOnline = int.Parse(row["flagOnline"].ToString());
                    }
                    if (row["loginCounter"] != null && row["loginCounter"].ToString() != "")
                    {
                        _model.loginCounter = int.Parse(row["loginCounter"].ToString());
                    }
                    if (row["workerID"] != null)
                    {
                        _model.workerID = row["workerID"].ToString();
                    }
                    if (row["remark"] != null)
                    {
                        _model.remark = row["remark"].ToString();
                    }
                    if (row["departGuid"] != null && row["departGuid"].ToString() != "")
                    {
                        _model.departGuid = new Guid(row["departGuid"].ToString());
                    }
                    if (row["isSys"] != null && row["isSys"].ToString() != "")
                    {
                        _model.isSys = int.Parse(row["isSys"].ToString());
                    }
                    return ReturnDto<Sys_User>.QuickReturn(_model, ReturnCode.Success, "读取成功!");
                }
                else
                    return ReturnDto<Sys_User>.QuickReturn(_model, ReturnCode.Default, "读取失败!");
            }
            catch (Exception ex)
            {
                LogHelper.Debug(this.ToString(), "GetModel error:" + ex.Message);
                return ReturnDto<Sys_User>.QuickReturn(_model, ReturnCode.Default, "读取失败!");
            }
        }
        #endregion
    }
}