新框架PC后端代码(祈禧6月初版本)
南骏 池
6 天以前 72449a1b8699b65712e57fba8abce5a8240e9465
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
using System.Data;
using System.Text;
using Gs.Entity.Sys;
using Gs.Sys.Models;
using Gs.Toolbox;
using Gs.Toolbox.ApiCore.Abstract.Mvc;
using Gs.Toolbox.ApiCore.Common.Mvc;
using Gs.Toolbox.ApiCore.Group;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using static Gs.Toolbox.UtilityHelper;
 
 
namespace Gs.Sys.Services;
 
/// <summary>
/// </summary>
[ApiGroup(ApiGroupNames.Sys)]
public class OrganizationController : Repository<SysOrganization>, IRomteService
{
    private readonly IHttpContextAccessor _http;
 
    private readonly string _userCode, _userGuid, _orgFids;
 
    public OrganizationController(IHttpContextAccessor httpContextAccessor)
    {
        _http = httpContextAccessor;
        (_userCode, _userGuid, _orgFids) =
            GetUserGuidAndOrgGuid(_http);
    }
 
    /// <summary>
    ///     查询列表,支持分页
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<PageList<SysOrganization>> GetListPage(PageQuery query)
    {
        string keyWord = query.keyWord;
        var pageList = new PageList<SysOrganization>();
        try
        {
            var _sbWhere = new StringBuilder(" 1=1" + query.keyWhere);
            var _sbBy =
                new StringBuilder(query.sortName + " " + query.sortOrder);
            var totalCount = 0;
            var itemsList = Db.Queryable<SysOrganization>()
                .Where(_sbWhere.ToString())
                .OrderBy(_sbBy.ToString())
                .ToPageList(query.currentPage, query.everyPageSize,
                    ref totalCount);
            pageList = new PageList<SysOrganization>(itemsList, totalCount,
                query.everyPageSize);
            if (!string.IsNullOrEmpty(keyWord))
            {
                System.Text.StringBuilder sbOrg = new StringBuilder();
                System.Data.DataSet dataSet = new System.Data.DataSet();
                dataSet = Gs.Toolbox.DbHelperSQL.Query(" select org_fid from  [dbo].[SYS_USER_ORG] where user_guid='" + keyWord + "' order by  org_fid asc");
                if (dataSet != null && dataSet.Tables.Count > 0)
                {
                    foreach (DataRow _row in dataSet.Tables[0].Rows)
                    {
                        if (sbOrg.Length > 0)
                            sbOrg.Append(", ");
                        sbOrg.Append(_row["org_fid"].ToString());
                    }
                }
                pageList.extendText = sbOrg.ToString();
            }
            return ReturnDto<PageList<SysOrganization>>.QuickReturn(pageList,
                ReturnCode.Success, "读取成功");
        }
        catch (Exception ex)
        {
            return ReturnDto<PageList<SysOrganization>>.QuickReturn(pageList,
                ReturnCode.Default, ex.Message);
        }
    }
 
    ///// <summary>
    ///// 删除机构
    ///// </summary>
    ///// <param name="model"></param>
    ///// <returns></returns>
    //[RequestMethod(RequestMethods.POST)]
    //public ReturnDto<int?> DeleteModel([FromBody] JArray guidList)
    //{
    //    string[] intArray = guidList.ToObject<string[]>();
    //    string guid = intArray[0];
 
    //    int cont = 0;
    //    cont = IsChkOrUnChk(intArray[0], true);
    //    if (cont > 0)
    //        return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "删除失败,该信息已被审核!");
 
 
    //    int? rtnInt = (int)ReturnCode.Default;
 
    //    int it1 = 0;
    //    int it2 = 0;
    //    cont = Db.Queryable<SysOrganization>().Where(c => c.Guid == Guid.Parse(guid) && c.IsSys == 1).Count();
    //    if (cont > 0)
    //    {
    //        return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "删除失败,该条目为系统内置,不可删除!");
    //    }
    //    try
    //    {
    //        Db.Ado.BeginTran();
    //        it1 = Db.Deleteable<SysOrganization>().In(guid).ExecuteCommand();
    //        it2 = Db.Deleteable<SysRoleMenuAction>().Where(it => it.OrgGuid == Guid.Parse(guid)).ExecuteCommand();
    //        Db.Ado.CommitTran();
    //    }
    //    catch (Exception ex)
    //    {
    //        LogHelper.Debug(this.ToString(), "DeleteModel error:" + ex.Message);
    //        Db.Ado.RollbackTran();
    //        return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception, "删除失败,请重试!");
    //    }
    //    rtnInt = (it2 + it1);
    //    return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success, "操作成功,共删除" + rtnInt.ToString() + "条数据!");
    //}
 
    ///// <summary>
    ///// 增加机构
    ///// </summary>
    ///// <param name="model"></param>
    ///// <returns></returns>
    //[RequestMethod(RequestMethods.POST)]
    //public ReturnDto<string?> EditModel([FromBody] SysOrganization model)
    //{
    //    if (UtilityHelper.CheckGuid(model.Guid))
    //    {
    //        int cont = 0;
    //        cont = IsChkOrUnChk(model.Guid.ToString(), true);
    //        if (cont > 0)
    //            return ReturnDto<string>.QuickReturn("", ReturnCode.Exception, "修改失败,该信息已被审核!");
    //    }
    //    if (!UtilityHelper.CheckGuid(model.UpGuid))//只能有一个根组织
    //    {
    //        int cont = 0;
    //        cont = Db.Queryable<SysOrganization>().Where(c => c.UpGuid == null).Count();
    //        if (cont > 0)
    //        {
    //            return ReturnDto<int>.QuickReturn(default(string?), ReturnCode.Exception, "增加失败,请选择上级组织!");
    //        }
    //    }
    //    bool _bl = false;
    //    try
    //    {
    //        if (!UtilityHelper.CheckGuid(model.Guid))
    //        {
    //            model.Guid = Guid.NewGuid();
    //            _bl = base.Insert(model);
    //        }
    //        else
    //        {
    //           // _bl = base.Update(model);
    //            _bl = Db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand() > 0 ? true : false;
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        LogHelper.Debug(this.ToString(), "EditModel error:" + ex.Message);
    //        return ReturnDto<string>.QuickReturn("", ReturnCode.Exception, ex.Message);
    //    }
    //    if (_bl)
    //        return ReturnDto<string>.QuickReturn(model.Guid.ToString(), ReturnCode.Success, "操作成功!");
    //    return ReturnDto<string>.QuickReturn("", ReturnCode.Exception, "增加失败,请重试!");
    //}
 
    /// <summary>
    ///     读取机构
    /// </summary>
    /// <param name="guid"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    [AllowAnonymous]
    public ReturnDto<SysOrganization> GetModel([FromBody] SysOrganization model)
    {
        var m = base.GetById(model.Guid);
        if (m != null)
            return ReturnDto<SysDocRule>.QuickReturn(m, ReturnCode.Success,
                "读取成功!");
        return ReturnDto<SysDocRule>.QuickReturn(m, ReturnCode.Default,
            "读取失败!");
    }
 
    private int IsChkOrUnChk(string guidList, bool status)
    {
        var cont = 0;
        cont = base.GetList(it =>
            it.Guid == Guid.Parse(guidList) && it.CheckStatus == status).Count;
        return cont;
    }
}