winform+dev的前后台分离标准项目
lg
2024-08-27 3aa008c8ce56cbd4cc981ba10a8b4c143208ad48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using Gs.Toolbox;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using Gs.User.Modes;
using System.Diagnostics;
 
namespace Gs.User.Service
{
 
    [ApiGroup(ApiGroupNames.Auth)]
    public class UserController : IRomteService
    {
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<System.Dynamic.ExpandoObject> UserLogin([FromBody] UserLogin model)
        {
            string accountPwd = model.accountPwd;
            string accountNo = model.accountNo;
            Guid orgGuid = model.orgGuid;
            string strPass = "";
            DataSet dset = new DataSet();
            dynamic m = new System.Dynamic.ExpandoObject();
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.strConn))
            {
                using (SqlCommand cmd = new SqlCommand("[prc_user_login]", conn))
                {
                    try
                    {
                        conn.Open();
                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter[] parameters = new SqlParameter[] {
                                new SqlParameter("@accountNo",accountNo),
                                new SqlParameter("@accountPwd",strPass),
                                new SqlParameter("@orgGuid",orgGuid),
                            };
                        foreach (SqlParameter parameter in parameters)
                        {
                            cmd.Parameters.Add(parameter);
                        }
                        using (SqlDataAdapter dt = new SqlDataAdapter(cmd))
                        {
                            dt.Fill(dset, "0");
                        }
                        if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)
                        {
                            System.Data.DataRow row = dset.Tables[0].Rows[0];
                            m.loginGuid = Guid.Parse(row["loginGuid"].ToString());
                            m.loginOrgGuid = row["loginOrgGuid"].ToString();
                            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "登录成功!");
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Debug(this.ToString(), "UserLogin error:" + ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Exception, "登录失败!");
        }
 
        /// <summary>
        /// 读取用户登录信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<System.Dynamic.ExpandoObject> GetUserInfo([FromBody] UserLogin model)
        {
            Guid userGuid = model.userGuid;
            DataSet dset = new DataSet();
            dynamic m = new System.Dynamic.ExpandoObject();
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.strConn))
            {
                using (SqlCommand cmd = new SqlCommand("[prc_user_info]", conn))
                {
                    try
                    {
                        conn.Open();
                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter[] parameters = new SqlParameter[] {
                                new SqlParameter("@userGuid",userGuid),
                            };
                        foreach (SqlParameter parameter in parameters)
                        {
                            cmd.Parameters.Add(parameter);
                        }
                        using (SqlDataAdapter dt = new SqlDataAdapter(cmd))
                        {
                            dt.Fill(dset, "0");
                        }
                        if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)
                        {
                            System.Data.DataRow row = dset.Tables[0].Rows[0];
                            m.loginGuid = Guid.Parse(row["loginGuid"].ToString());
                            m.loginOrgGuid = row["loginOrgGuid"].ToString();
                            m.list = new List<MenuAction>();
                            if (dset.Tables.Count > 1 && dset.Tables[1].Rows.Count > 1)
                            {
                                foreach (DataRow dr in dset.Tables[1].Rows)
                                {
                                    m.list.Add(
                                        new MenuAction()
                                        {
                                            guid = Guid.Parse(dr["rightGuid"].ToString()),
                                            upGuid = dr["upGuid"].ToString().Length > 0 ? Guid.Parse(dr["upGuid"].ToString()) : null,
                                            name = dr["name"].ToString(),
                                            icon = dr["icon"].ToString(),
                                            fromPath = dr["fromPath"].ToString(),
                                            category = int.Parse(dr["category"].ToString()),
                                        }
                                    );
                                }
                                return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "登录成功!");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Debug(this.ToString(), "GetUserInfo error:" + ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Exception, "登录失败!");
        }
    }
}