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
using Gs.Toolbox;
using Gs.User.Modes;
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;
 
namespace Gs.User.Service
{
    [ApiGroup(ApiGroupNames.Auth)]
    public class OrganizationController : IRomteService
    {
        /// <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_Organization 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_Organization 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 dr in dset.Tables[0].Rows)
                {
                    _pglist.list.Add(
                        new
                        {
                            guid = Guid.Parse(dr["guid"].ToString()),
                            upGuid = dr["upGuid"].ToString(),
                            name = dr["name"].ToString(),
                            conPeople = dr["conPeople"].ToString(),
                            conTel = dr["conTel"].ToString(),
                            status = int.Parse(dr["status"].ToString()),
                        }
                    );
                }
            }
            return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist, ReturnCode.Success, "读取成功");
        }
 
 
        /// <summary>
        /// 删除机构
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<int?> DeleteModel([FromBody] dynamic model)
        {
            int rtnInt = (int)ReturnCode.Default;
            int cont = 0;
            try
            {
                //是否内置
                cont = int.Parse(DbHelperSQL.GetSingle("select count(1) from sys_Organization where guid='" + model.guid.ToString() + "' and [isSys]=1").ToString());
                if (cont > 0)
                {
                    return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "删除失败,该条目为系统内置,不可删除!");
                }
                rtnInt = DbHelperSQL.ExecuteSql("delete from sys_Organization 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] dynamic model)
        {
            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)
            {
                strSql.Append(" update sys_Organization");
                strSql.Append(" set upGuid=@upGuid,name=@name,conPeople=@conPeople,status=@status,conTel=@conTel");
                strSql.Append(" where guid='" + guid + "'");
            }
            else
            {
                guid = Guid.NewGuid();
                strSql.Append("insert into sys_Organization(");
                strSql.Append(" guid,upGuid,name,conPeople,status,conTel)");
                strSql.Append(" values (");
                strSql.Append("'" + guid + "',@upGuid,@name,@conPeople,@status,@conTel)");
            }
            SqlParameter[] parameters = {
             new SqlParameter("@upGuid", upGuid),
             new SqlParameter("@name", name),
             new SqlParameter("@conPeople",conPeople),
             new SqlParameter("@status",status),
             new SqlParameter("@conTel",conTel),
         };
            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] dynamic model)
        {
            dynamic m = new System.Dynamic.ExpandoObject();
            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 dr = dset.Tables[0].Rows[0];
                    m.guid = Guid.Parse(dr["guid"].ToString());
                    m.upGuid = dr["upGuid"].ToString();
                    m.name = dr["name"].ToString();
                    m.conPeople = dr["conPeople"].ToString();
                    m.status = int.Parse(dr["status"].ToString());
                    m.conTel = dr["conTel"].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, "读取失败!");
            }
        }
    }
}