cnf
2025-11-29 e57987bff5891297af9ecbbec5ed6dc9e84bdad2
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
using Gs.Entity.BaseInfo;
using Gs.Toolbox;
using Gs.Toolbox.ApiCore.Abstract.Mvc;
using Gs.Toolbox.ApiCore.Common.Mvc;
using Gs.Toolbox.ApiCore.Group;
using Microsoft.AspNetCore.Http;
using System.Data;
using System.Text;
 
namespace Gs.Warehouse.Services;
 
[ApiGroup(ApiGroupNames.PerMission)]
public class MesDepotSectionsManager : Repository<MesDepotSections>,
    IRomteService
{
    private readonly IHttpContextAccessor _http;
 
    private readonly string _userCode, _userGuid, _orgFids;
 
    public MesDepotSectionsManager()
    {
        //_http = httpContextAccessor;
        //(_userCode, _userGuid, _orgFids) =
        //    UtilityHelper.GetUserGuidAndOrgGuid(_http);
    }
 
      /// <summary>
    ///     查询列表,支持分页
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<PageList<MesDepotSections>> GetListPage(PageQuery query)
    {
        var pageList = new PageList<MesDepotSections>();
        try
        {
            var _sbWhere = new StringBuilder(" 1=1" + query.keyWhere);
            var _sbBy = new StringBuilder(query.sortName + " " + query.sortOrder);
            var totalCount = 0;
            // 先构建基础查询
            var queryBase = Db.Queryable<MesDepots>()
                .LeftJoin<MesDepotSections>((a, b) => a.Guid == b.DepotGuid);
                //.LeftJoin<SysOrganization>((a, b, c) => a.FSubsidiary == c.Fid)
                //.LeftJoin<MesStaff>((a, b, c, d) => a.CreateBy == d.Id.ToString())
                //.LeftJoin<MesCustomer>((a, b, c, d, e) => e.Id.ToString() == a.ClientId)
                //.LeftJoin<MesSupplier>((a, b, c, d, e, f) => f.Id.ToString() == a.SuppLierId)
                //.LeftJoin<SysDepartment>((a, b, c, d, e, f, g) => g.Id.ToString() == a.department);
            // 然后进行选择和分页
            var itemsList = queryBase.Select((a, b) => new MesDepotSections
            {
                Guid = b.Guid,
                DepotSectionCode = b.DepotSectionCode,
                DepotSectionName = b.DepotSectionName
            })
            .Where(_sbWhere.ToString())
            .OrderBy(_sbBy.ToString())
            .ToPageList(query.currentPage, query.everyPageSize, ref totalCount);
 
            pageList = new PageList<MesDepotSections>(itemsList, totalCount,
                query.everyPageSize);
            return ReturnDto<PageList<MesDepotSections>>.QuickReturn(pageList,
                ReturnCode.Success, "读取成功");
        }
        catch (Exception ex)
        {
            return ReturnDto<PageList<MesDepotSections>>.QuickReturn(pageList,
                ReturnCode.Default, ex.Message);
        }
    }
 
 
    /// <summary>
    ///     查询列表,支持分页,用于各种绑定
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<PageList<dynamic>> GetListPage2(PageQuery model)
    {
        var currentPage = model.currentPage;
        var everyPageSize = model.everyPageSize;
        var sortName = string.IsNullOrEmpty(model.sortName) ? "a.USER_NAME" : model.sortName;
        var keyWhere = model.keyWhere;
        string keyType = model.keyType;
        System.Text.StringBuilder sbJoin = new StringBuilder();
        sbJoin.Append(" from [dbo].[MES_DEPOT_SECTIONS] a ");
        sbJoin.Append(" left join [dbo].[MES_DEPOTS] d on a.depot_guid=d.depot_id");
        sbJoin.Append(" left join SYS_ORGANIZATION org on d.FSubsidiary=org.FID");
        sbJoin.Append(keyWhere);
        var sbSql = new StringBuilder();
        sbSql.Append("  SELECT * FROM ");
        sbSql.Append(" (SELECT N'(' +[Org].[FNumber] + N')'  +[Org].[NAME]  AS [FSubsidiary2]");
        sbSql.Append(", a.depot_section_code as cwCode,a.depot_section_name as cwName,d.depot_name as ckName,d.depot_id as ckId,d.depot_code as ckCode ,ROW_NUMBER() OVER(ORDER BY a.depot_section_code asc) AS RowIndex ");
        //如果无关键字,无需找查绑定
        if (string.IsNullOrEmpty(keyType))
        {
            sbSql.Append(",cast(0 as bit) as chkInt");
        }
        else
            sbSql.Append(",cast( (select count(1)  from SYS_USER_BIND bind where bind.userGuid='" + keyType + "' and bind.aboutGuid=a.depot_section_code  and bind.fType='库位')  as bit) as chkInt ");
        sbSql.Append(sbJoin);
        sbSql.Append(") T");
        sbSql.Append(" where T.rowindex>(" + currentPage + "-1)*" + everyPageSize + " and  T.rowindex<=" + currentPage + "*" + everyPageSize);
        sbSql.Append(" select count(1) as intTotal ");
        sbSql.Append(sbJoin);
        var dset = new DataSet();
        try
        {
            dset = DbHelperSQL.Query(sbSql.ToString());
        }
        catch (Exception ex)
        {
            LogHelper.Debug(ToString(), "GetListPage error:" + ex.Message);
            return ReturnDto<PageList<dynamic>>.QuickReturn(default(PageList<dynamic>), ReturnCode.Exception, "读取失败");
        }
        var _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) //有数据
        {
            var intTotal = int.Parse(dset.Tables[1].Rows[0]["intTotal"].ToString());
            var pages = intTotal % everyPageSize != 0
                ? intTotal / everyPageSize + 1
                : intTotal / everyPageSize;
            _pglist.total = intTotal;
            _pglist.everyPageSize = everyPageSize;
            _pglist.pages = pages;
            var _dy = dset.Tables[0].TableToDynamicList();
            _pglist.list = _dy;
        }
        return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist,
            ReturnCode.Success, "读取成功");
    }
 
 
 
}