winform+dev的前后台分离标准项目
lg
2024-08-30 01656f0ff2bf7b62ef0fb039e24be888849ad728
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
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 System.Threading.Tasks;
using Gs.User.Modes;
using Microsoft.Extensions.Primitives;
 
namespace Gs.User.Service
{
    [ApiGroup(ApiGroupNames.Auth)]
    public class MenuActionController : IRomteService
    {
 
        /// <summary>
        /// 读取功能菜单列表,支持分页
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<PageList<MenuAction>> GetListPage([FromBody] PageQuery model)
        {
            int currentPage = model.currentPage;
            int everyPageSize = model.everyPageSize;
            string sortName = string.IsNullOrEmpty(model.sortName) ? "a.idx" : 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_MenuAction 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 dbo.sys_MenuAction 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<MenuAction>>.QuickReturn(default(PageList<MenuAction>), ReturnCode.Exception, "读取失败");
            }
            PageList<MenuAction> _pglist = new PageList<MenuAction>
            {
                total = 0,
                everyPageSize = 0,
                pages = 0,
                list = new List<MenuAction>()
            };
            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 dr in dset.Tables[0].Rows)
                {
                    _pglist.list.Add(
                        new MenuAction()
                        {
                            guid = Guid.Parse(dr["guid"].ToString()),
                            upGuid = dr["upGuid"].ToString().Length > 0 ? Guid.Parse(dr["upGuid"].ToString()) : null,
                            name = dr["name"].ToString(),
                            icon = dr["icon"].ToString(),
                            status = int.Parse(dr["status"].ToString()),
                            formPath = dr["formPath"].ToString(),
                            idx = int.Parse(dr["idx"].ToString()),
                            category = int.Parse(dr["category"].ToString()),
                            statusTxt = (dr["status"].ToString() == "1" ? "正常" : "禁用"),
                            categoryTxt = (dr["category"].ToString() == "1" ? "窗体类型" : "按钮类型"),
                        }
                    );
                }
            }
            return ReturnDto<PageList<MenuAction>>.QuickReturn(_pglist, ReturnCode.Success, "读取成功");
        }
 
 
        /// <summary>
        /// 删除功能菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<int?> DeleteModel([FromBody] MenuAction model)
        {
            int rtnInt = (int)ReturnCode.Default;
            int cont = 0;
            try
            {
                //是否内置
                cont = int.Parse(DbHelperSQL.GetSingle("select count(1) from sys_MenuAction where guid='" + model.guid.ToString() + "' and [isSys]=1").ToString());
                if (cont > 0)
                {
                    return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "删除失败,该条目为系统内置,不可删除!");
                }
                cont = 0;
                //是否有子菜单 
                cont = int.Parse(DbHelperSQL.GetSingle("select count(1) from sys_MenuAction where upguid='" + model.guid.ToString() + "'").ToString());
                if (cont > 0)
                {
                    return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "删除失败,该条目下面有子菜单,不可删除!");
                }
                rtnInt = DbHelperSQL.ExecuteSql("delete from dbo.sys_MenuAction where guid='" + model.guid.ToString() + "'");
            }
            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] MenuAction model)
        {
            Guid? guid = model.guid;
            Guid? upGuid = model.upGuid;
            string name = model.name;
            string icon = model.icon;
            int status = model.status;
            string formPath = model.formPath;
            int category = model.category;
            int idx = model.idx;
            int? rtnInt = (int)ReturnCode.Default;
            StringBuilder strSql = new StringBuilder();
            if (guid != null)
            {
                strSql.Append(" update dbo.sys_MenuAction");
                strSql.Append(" set upGuid=@upGuid,name=@name,icon=@icon,status=@status,formPath=@formPath,category=@category,idx=@idx");
                strSql.Append(" where guid='" + guid + "'");
            }
            else
            {
                guid = Guid.NewGuid();
                strSql.Append("insert into dbo.sys_MenuAction(");
                strSql.Append(" guid,upGuid,name,icon,status,formPath,category,idx)");
                strSql.Append(" values (");
                strSql.Append("'" + guid + "',@upGuid,@name,@icon,@status,@formPath,@category,@idx)");
            }
            SqlParameter[] parameters = {
             new SqlParameter("@upGuid", upGuid),
             new SqlParameter("@name", name),
             new SqlParameter("@icon",icon),
             new SqlParameter("@status",status),
             new SqlParameter("@formPath",formPath),
             new SqlParameter("@category",category),
             new SqlParameter("@idx",idx),
         };
            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<MenuAction> GetModel([FromBody] MenuAction model)
        {
            MenuAction m = new MenuAction();
            System.Text.StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select top 1 * from dbo.sys_MenuAction  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 dr = dset.Tables[0].Rows[0];
                    m.guid = Guid.Parse(dr["guid"].ToString());
                    m.upGuid = dr["upGuid"].ToString().Length > 0 ? Guid.Parse(dr["upGuid"].ToString()) : null;
                    m.name = dr["name"].ToString();
                    m.icon = dr["icon"].ToString();
                    m.status = int.Parse(dr["status"].ToString());
                    m.formPath = dr["formPath"].ToString();
                    m.idx = int.Parse(dr["idx"].ToString());
                    m.category = int.Parse(dr["category"].ToString());
                    return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "读取成功!");
                }
                else
                    return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
            }
            catch (Exception ex)
            {
                LogHelper.Debug(this.ToString(), "GetModel error:" + ex.Message);
                return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
            }
        }
 
 
        /// <summary>
        /// 读取功能菜单列表,分组织展现权限菜单
        /// </summary>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<PageList<MenuAction>> GetListPageByOrg()
        {
            System.Text.StringBuilder _orgSql = new StringBuilder();
            _orgSql.Append("select org.guid,null as upGuid,org.name,org.status from [dbo].[sys_Organization] org   where upGuid is not null ");
            DataSet _orgDset = new DataSet();
            System.Text.StringBuilder sbSql = new StringBuilder();
            try
            {
                _orgDset = Gs.Toolbox.DbHelperSQL.Query(_orgSql.ToString());
                foreach (DataRow row in _orgDset.Tables[0].Rows)
                {
                    if (sbSql.Length > 0)
                        sbSql.Append(" union all");
                    sbSql.Append(" select org.guid,null as upGuid,org.name,org.status,'"+ row["guid"].ToString() + "' as orgGuid from [dbo].[sys_Organization] org where org.guid ='" + row["guid"].ToString() + "'");
                    sbSql.Append(" union all");
                    sbSql.Append(" select ma.guid,isnull(ma.upGuid,'" + row["guid"].ToString() + "') as upGuid,ma.name,ma.status,'"+ row["guid"].ToString() + "' as orgGuid from sys_MenuAction ma");
                }
            }
            catch (Exception ex)
            {
                Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetListPage error:" + ex.Message);
                return ReturnDto<PageList<MenuAction>>.QuickReturn(default(PageList<MenuAction>), ReturnCode.Exception, "读取失败");
            }
            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<MenuAction>>.QuickReturn(default(PageList<MenuAction>), ReturnCode.Exception, "读取失败");
            }
            PageList<MenuAction> _pglist = new PageList<MenuAction>
            {
                total = 0,
                everyPageSize = 0,
                pages = 0,
                list = new List<MenuAction>()
            };
            if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)//有数据
            {
                int intTotal = 999;
                int pages = 1;
                _pglist.total = intTotal;
                _pglist.everyPageSize = 1;
                _pglist.pages = pages;
                foreach (DataRow dr in dset.Tables[0].Rows)
                {
                    _pglist.list.Add(
                        new MenuAction()
                        {
                            guid = Guid.Parse(dr["guid"].ToString()),
                            upGuid = dr["upGuid"].ToString().Length > 0 ? Guid.Parse(dr["upGuid"].ToString()) : null,
                            name = dr["name"].ToString(),
                            status = int.Parse(dr["status"].ToString()),
                            orgGuid = dr["orgGuid"].ToString(),
                        }
                    );
                }
            }
            return ReturnDto<PageList<MenuAction>>.QuickReturn(_pglist, ReturnCode.Success, "读取成功");
        }
 
    }
}