kyy
6 天以前 5c45b5f97c1365b6f89da2a0897a7c93fe16cb63
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
using Gs.Entity.BaseInfo;
using Gs.Entity.Sys;
using Gs.Entity.Warehouse;
using Gs.Toolbox;
using Gs.Toolbox.ApiCore.Abstract.Mvc;
using Gs.Toolbox.ApiCore.Common.Mvc;
using Gs.Toolbox.ApiCore.Group;
using Gs.Warehouse.Dto;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Data;
using System.Data.SqlClient;
using System.Dynamic;
using System.Text;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
 
namespace Gs.Warehouse.Services;
 
[ApiGroup(ApiGroupNames.PerMission)]
public class MesInvItemBarcodesManager : Repository<MesInvItemBarcodes>,
    IRomteService
{
    private readonly IHttpContextAccessor _http;
 
    private readonly string _userCode, _userGuid, _orgFids;
 
    public MesInvItemBarcodesManager(IHttpContextAccessor httpContextAccessor)
    {
        _http = httpContextAccessor;
        (_userCode, _userGuid, _orgFids) =
            UtilityHelper.GetUserGuidAndOrgGuid(_http);
    }
 
    /// <summary>
    ///     查询列表,支持分页
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<PageList<dynamic>> GetListPage(PageQuery query)
    {
        var _sbWhere = new StringBuilder(" 1=1" + query.keyWhere);
        var _sbBy =new StringBuilder(query.sortName + " " + query.sortOrder);
 
        int currentPage = query.currentPage;
        int everyPageSize = query.everyPageSize;
        string sortName = query.sortName;
        string keyWhere = query.keyWhere;
        SqlParameter[] parameters =
        {
                new("@inCurrentPage", currentPage),
                new("@inEveryPageSize", everyPageSize),
                new("@inSortName", sortName),
                new("@inSortOrder", query.sortOrder),
                new("@inQueryWhere", keyWhere),
                new("@inFid", ""),
                new("@inP1", ""),
                new("@inP2", ""),
                new("@inP3", ""),
                new("@inP4", _userGuid)//当前登录用户guid,将根据他读取仓管员
            };
        var dset = new DataSet();
        var _pglist = new PageList<dynamic>
        {
            total = 0,
            everyPageSize = 0,
            pages = 0,
            list = new List<dynamic>()
        };
        try
        {
            dset = DbHelperSQL.RunProcedure("prc_qcdy_lst", parameters, "0");
            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;
                //currentId = dset.Tables[1].Rows[0]["mrCgy"].ToString();
            }
        }
        catch (Exception ex)
        {
            LogHelper.Debug(ToString(), ex.Message);
            return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist,
          ReturnCode.Exception, "读取失败!");
        }
 
        return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist,
            ReturnCode.Success, "读取成功");
 
        //var pageList = new PageList<MesItems>();
        //try
        //{
        //    var totalCount = GetPageTotalCount(null, query, out var itemsList, _sbWhere, _sbBy);
        //    pageList = new PageList<MesItems>(itemsList, totalCount,
        //        query.everyPageSize);
        //    return ReturnDto<PageList<MesItems>>.QuickReturn(pageList,
        //        ReturnCode.Success, "读取成功");
        //}
        //catch (Exception ex)
        //{
        //    return ReturnDto<PageList<MesItems>>.QuickReturn(pageList,
        //        ReturnCode.Default, ex.Message);
        //}
    }
 
    private int GetPageTotalCount(Guid? guid, PageQuery query,
        out List<MesItems> itemsList,System.Text.StringBuilder _sbWhere, StringBuilder _sbBy)
    {
        var totalCount = 0;
        itemsList = Db.Queryable<MesItems, MesUnit, SysOrganization>(
                (a, b, org) =>
                    new object[]
                    {
                        JoinType.Left, a.Storeunit == b.Id.ToString(),
                        JoinType.Left, a.FSubsidiary == org.Fid.ToString()
                    })
            .WhereIF(UtilityHelper.CheckGuid(guid),
                (a, b, org) => a.Guid == guid)
            .Select((a, b, org) => new MesItems
            {
                Guid = a.Guid,
                Id = a.Id,
                Fumbrella = a.Fumbrella,
                FSubsidiary = "(" + org.FNumber + ")" + org.Name,
                FSubsidiaryFId = org.Fid,
                ItemNo = a.ItemNo,
                ItemId = a.ItemId,
                ItemName = a.ItemName,
                ItemModel = a.ItemModel,
                ItemUnit = b.Fname,
                PsnQty = 0, // Assuming decimal type
                ICount = 0, // Assuming int type
                WorkNo = "",
                SuppNo = "",
                SuppName = "",
                CreateDate1 = DateTime.Now.ToString("yyyy-MM-dd"),
                Tc = "否"
            }).Where(_sbWhere.ToString())
             .OrderBy(_sbBy.ToString())
            .ToPageList(query.currentPage, query.everyPageSize,
                ref totalCount);
        return totalCount;
    }
 
    /// <summary>
    ///     根据主表id读取主表和子表
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<ExpandoObject> GetModel(
        [FromBody] dynamic model)
    {
 
        string guid = model.guid.ToString();
        dynamic m = new ExpandoObject();
        m.list = new List<dynamic>();
        m.list2 = new List<dynamic>();
        SqlParameter[] parameters =
        {
            new("@inMainGuid", guid),
            new("@inP1", ""),
            new("@inP2", ""),
            new("@inP3", ""),
            new("@inP4", ""),
            new("@userGuid", _userGuid)
        };
        var dset = new DataSet();
        try
        {
            dset = DbHelperSQL.RunProcedure("[prc_qcdy_mx]", parameters,
                "0");
            if (dset != null && dset.Tables.Count > 0 &&
                dset.Tables[0].Rows.Count > 0)
            {
                var dr = dset.Tables[0].Rows[0];
                m = dr.RowToDynamic();
                var _tb = dset.Tables[1].TableToDynamicList();
                m.list = _tb;
                //var _tb2 = dset.Tables[2].TableToDynamicList();
                //m.list2 = _tb2;
    
            }
        }
        catch (Exception ex)
        {
            LogHelper.Debug(ToString(), ex.Message);
        }
 
        if (m != null)
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success,
                "读取成功!");
        return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
 
        //// var m = base.GetById(model.Guid);
        //var query = new PageQuery
        //{
        //    currentPage = 1,
        //    everyPageSize = 1
        //};
        //System.Text.StringBuilder sb = new StringBuilder();
        //System.Text.StringBuilder order = new StringBuilder();
        //order.Append(" org.FNumber asc ,a.item_no asc");
        //var pageTotalCount =  GetPageTotalCount(model.Guid, query, out var itemsList, sb, order);
 
        //var barcode = new InitialBarcode();
 
        //if (pageTotalCount == 0)
        //    return ReturnDto<InitialBarcode>.QuickReturn(barcode,
        //        ReturnCode.Default,
        //        "读取失败!");
 
        //var mesItems = itemsList.FirstOrDefault();
 
 
        //if (mesItems == null)
        //    return ReturnDto<InitialBarcode>.QuickReturn(barcode,
        //        ReturnCode.Default,
        //        "读取失败!");
 
        //barcode.from = mesItems;
 
        //barcode.barcodes = GetMesInvItemBarcodes(mesItems.Id);
 
        //return ReturnDto<InitialBarcode>.QuickReturn(barcode,
        //    ReturnCode.Success, "读取成功!");
    }
 
    private List<MesInvItemBarcodes> GetMesInvItemBarcodes(long? ItemId)
    {
        var result = Db
            .Queryable<MesInvItemBarcodes, MesInvItemStocks, MesDepots, MesSupplier>(
                (b, c, d, e) => new object[]
                {
                    JoinType.Left, b.ItemBarcode == c.ItemBarcode,
                    JoinType.Left, c.DepotId == d.DepotId,
                    JoinType.Left,e.Id.ToString()==b.SuppID
                })
            .Where((b, c, d) => b.ComeFlg == 0 && b.ItemId == ItemId && b.Barcodetype== "初期物料")
            .OrderBy((b) => b.ItemBarcode)//写Select前面用法,正常都这么用
            .Select((b, c, d, e) => new MesInvItemBarcodes
            {
                Guid = b.Guid,
                ItemBarcode = b.ItemBarcode,
                TrLotno = b.TrLotno,
                LotNo = b.LotNo,
                Quantity = b.Quantity,
                LotDate = b.LotDate,
                CreateBy = b.CreateBy,
                SuppID = e.SuppName,
                CreateDate = b.CreateDate,
                DepotSectionsCode = c.DepotSectionsCode,
                DepotsCode = c.DepotsCode,
                DepotName = d.DepotName,
                RkUser = c.IndepUserCode,
                RkDate = c.IndepDate,
                InChk = string.IsNullOrEmpty(c.IndepUserCode) ? false : true
            })
            .ToList();
        return result;
    }
}