服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-05-31 d4c326deaa51e7d4897a84afc339684012b8cfbe
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
using Rhea.Common;
using Tiger.Model.Minsun;
using Microsoft.AspNetCore.Http;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tiger.Model;
using Apache.NMS;
using System.Drawing.Drawing2D;
using Tiger.Model.Sharetronic.Shelf;
using Tiger.IBusiness;
 
namespace Tiger.Business.WMS.Transaction
{
    /// <summary>
    /// 生产领料事务
    /// </summary>
    public class ItemQuery : WMSTransactionBase, IItemQuery
    {
        public IItemQuery Init(string id, string userCode, string apiHost, string orgCode)
        {
            TransID = id;
            UserCode = userCode;
            ApiHost = apiHost;
            OrgCode = orgCode;
            Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
            return this;
        }
 
        #region Propertys & Variables
        public string UserCode { get; set; }
        public long UserId { get; set; }
        public string OrgCode { get; set; }
        public List<SuggestItem> Suggests { get; set; } = new();
        public List<V_WMS_ITEM> Vitem { get; set; } = new();
        public List<WMS_ITEM_POOL> CurPoolList => Suggests.Where(q => !q.poolItem.IsNullOrEmpty()).Select(q => q.poolItem).ToList();
        public Inventory CurInv { get; set; }
        public BIZ_ERP_PROD_OUT req { get; set; }
        public ReqType CurReqType { get; set; }
        public List<BIZ_ERP_PROD_OUT_DTL> dtls { get; set; } = new();
        public bool isExceed { get; set; }
        public ProductionPickToMes toMes { get; set; }
        public bool his_isComplete { get; set; }
        public bool isCutting { get; set; }
        public decimal cutQty { get; set; }
 
        public BIZ_WMS_TRANSFER transferH = null;
        public BIZ_WMS_TRANSFER cTransferH = null;
        public BIZ_WMS_TRANSFER_DTL transferDtl = null;
        public BIZ_WMS_TRANSFER_SN transferSn = null;
        #endregion
 
        #region Functions
 
        /// <summary>
        /// 物料汇总查询
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public QueryItemView QueryItemSum(QueryItemInput input)
        {
            var barcode = new Barcode(input.SN);
            var ItemCode = Biz.Db.Queryable<WMS_ITEM_PKG>().ByAuth(input.AuthOption).Where(q => q.SN == barcode.SN).First()?.ITEM_CODE ??
                                     (input.IsK.IsNullOrEmpty() ? input.SN : ((((bool)input.IsK && !barcode.ItemCode.IsNullOrEmpty(input.SN).StartsWith("K")) ? "K" : "") + barcode.ItemCode.IsNullOrEmpty(input.SN)));
            //Suggests[0].Item.ITEM_CODE = ItemCode;
            var itemInfo = Biz.Db.Queryable<BAS_ITEM>().Where(q => q.ITEM_CODE == ItemCode).First();
            if (!itemInfo.IsNullOrEmpty())
            {
                var sumInfo = Biz.Db.Queryable<V_WMS_ITEM>().Where(q => q.ITEM_CODE == ItemCode && q.STATUS == WMS_ITEM.STATUSs.InStore.GetValue())
                                  .ByAuth(input.AuthOption).GroupBy(q => new { q.WH_CODE, q.ITEM_CODE }).Select(q => new { WH_CODE = q.WH_CODE, SumQty = SqlFunc.AggregateSum(q.QTY) }).ToList();
                var items = Biz.Db.Queryable<V_WMS_ITEM>().Where(q => q.ITEM_CODE == ItemCode && q.STATUS == WMS_ITEM.STATUSs.InStore.GetValue())
                                  .ByAuth(input.AuthOption).ToList();
                QueryItemView view = new() {
                    ItemCode = ItemCode,
                    ItemName = itemInfo?.ITEM_NAME, 
                    SumInfo = $"{string.Join("\r\n", sumInfo.Select(q => $"{q.WH_CODE} 总库存: {(double)q.SumQty} 盘数:{items.Count}"))}" 
                };
                Vitem = items;
                return view;
            }
            else
            {
                throw new Exception("物料编码不存在");
            }
        }
        /// <summary>
        /// 物料汇总明细查询
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public ApiAction<PageAble<V_WMS_ITEM>> GetQueryItemSumDtl(BasePageInput input)
        {
            var action = new ApiAction<PageAble<V_WMS_ITEM>>();
            //var query = Biz.Db.Queryable<V_WMS_ITEM>().ByAuth(input.AuthOption).Where(q => q.ITEM_CODE == Vitem.Select(q=>q.ITEM_CODE).FirstOrDefault()&&q.STATUS==WMS_ITEM.STATUSs.InStore.GetValue()).OrderByDescending(o=>o.LOCATION_CODE).ToPage(input.pageIndex, input.pageSize);
            action.Data = new PageAble<V_WMS_ITEM>();
            action.Data.pageSize = input.pageSize;
            action.Data.pageIndex=input.pageIndex;
            action.Data.totals = Vitem.Count;
            action.Data.data = Vitem.Skip((input.pageIndex-1)*input.pageSize).Take(input.pageSize).ToList();
            //action.Data = query;
            return action;
        }
 
        /// <summary>
        /// 领料单推荐所有物料亮灯
        /// </summary>
        /// <param name="light"></param>
        /// <returns></returns>
        public async Task<ApiAction<ProdReqOutput>> LightAll(LightEntityInput light)
        {
            var action = new ApiAction<ProdReqOutput>();
            try
            {
                  light.Color= light.Color == LedColor.NoColor ? LedColor.Blue : light.Color;
                   var  list = Vitem.Where(q => q.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue() || q.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.QRCode.GetValue());
                    if (list.Any())
                    {
                    foreach (var item in Vitem.Select(s=>s.SHELF_CODE).Distinct())
                    {
                        await Share.Shelf.LightMulti(TransID, light.Color,item, list.Where(q=>q.SHELF_CODE==item).Select(x => x.LEDID).ToList());
                        action.LocaleMsg = Biz.L("亮灯成功,亮灯颜色[{0}]", light.Color.GetDesc()); 
                    }
                    }
                    else
                    {
                        action.LocaleMsg = Biz.L($"无需亮灯,推荐的物料不在智能货架上");
                    }
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"亮灯异常");
            }
            return action;
        }
 
 
        /// <summary>
        /// 灭灯
        /// </summary>
        /// <returns></returns>
        public async Task<ApiAction> CloseLight()
        {
            var action = new ApiAction();
            try
            {
                //灭灯
                var list = Vitem.Where(q => q.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue() || q.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.QRCode.GetValue());
                if (list.Any())
                {
                    foreach (var item in Vitem.Select(s => s.SHELF_CODE).Distinct())
                    {
                        await Share.Shelf.DownMulti(TransID, item, list.Where(q => q.SHELF_CODE == item).Select(x => x.LEDID).ToList());
                        action.LocaleMsg = Biz.L("灭灯成功");
                    }
                }
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"亮灯异常");
            }
            return action;
        }
 
        #endregion
 
        public override bool Close(bool needSaveHistoryLog = false)
        {
            needSaveHistoryLog = true;
            CloseLight().Wait();
            if (!(req?.BILLCODE ?? "").IsNullOrEmpty())
            {
                Biz.Db.Deleteable<WMS_ITEM_POOL>().Where(x => x.TRANS_NO == req.BILLCODE).ExecuteCommand();
            }
            Biz.Db.Deleteable<WMS_ITEM_POOL>().Where(q => CurPoolList.Select(q => q.SN).Contains(q.SN)).ExecuteCommand();
            //保存操作日志
 
            this.IsFinished = true;
            return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished;
        }
 
    }//endClass
}