新框架PC后端代码(祈禧6月初版本)
南骏 池
3 天以前 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
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.Text;
 
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<MesItems>> GetListPage(PageQuery query)
    {
        var _sbWhere = new StringBuilder(" 1=1" + query.keyWhere);
        var _sbBy =new StringBuilder(query.sortName + " " + query.sortOrder);
        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<InitialBarcode> GetModel(
        [FromBody] MesItems model)
    {
        // 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)
            .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;
    }
}