From f9f3b38bf70e71f8181df4a064d1e210e2b53545 Mon Sep 17 00:00:00 2001
From: lg <999544862qq.com>
Date: 星期四, 29 八月 2024 16:23:41 +0800
Subject: [PATCH] 用户管理
---
WebApi/Gs.User/Service/UserController.cs | 332 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
WebApi/Gs.User/Service/OrganizationController.cs | 17 ++
WebApi/Gs.User/Service/MenuActionController.cs | 1
3 files changed, 344 insertions(+), 6 deletions(-)
diff --git a/WebApi/Gs.User/Service/MenuActionController.cs b/WebApi/Gs.User/Service/MenuActionController.cs
index 111766a..ab42aa4 100644
--- a/WebApi/Gs.User/Service/MenuActionController.cs
+++ b/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;
diff --git a/WebApi/Gs.User/Service/OrganizationController.cs b/WebApi/Gs.User/Service/OrganizationController.cs
index 3ada6a5..997cc76 100644
--- a/WebApi/Gs.User/Service/OrganizationController.cs
+++ b/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)
{
diff --git a/WebApi/Gs.User/Service/UserController.cs b/WebApi/Gs.User/Service/UserController.cs
index fb4117d..d404929 100644
--- a/WebApi/Gs.User/Service/UserController.cs
+++ b/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
}
}
--
Gitblit v1.9.3