222
schangxiang@126.com
2024-11-29 dd53f4d569ed4e48bba9b0912353d54112876342
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
using Admin.NET.Core.Service;
using Admin.NET.Application.Entity;
using Microsoft.AspNetCore.Http;
using System.Data;
using System.Web;
using System.Text;
using DocumentFormat.OpenXml.Office.CustomUI;
using Microsoft.CodeAnalysis.Operations;
using Admin.NET.Application.Service.WmsTask.WmsRbLineTask.Dto;
 
namespace Admin.NET.Application;
/// <summary>
/// 操作任务服务
/// </summary>
[ApiDescriptionSettings(ApplicationConst.WmsTaskGroupName, Order = 100)]
public class WmsOperationTaskService : IDynamicApiController, ITransient
{
    private readonly SqlSugarRepository<WmsRbLineTask> _rep;
    private readonly SqlSugarRepository<WmsStockQuan> _wmsStockQuanRep;
    private readonly SqlSugarRepository<Mes_Package_Gather> _mesPackageGatherRep;
    private readonly SqlSugarRepository<SysConfig> _sysConfigRep;
    private readonly SqlSugarRepository<Mes_BatchOrderUPI_New> _mesBatchOrderUpiRep;
    private readonly SqlSugarRepository<Mes_Order_Gather> _mesOrderGatherRep;
 
    public WmsOperationTaskService(SqlSugarRepository<WmsRbLineTask> rep, SqlSugarRepository<WmsStockQuan> wmsStockQuanRep
        , SqlSugarRepository<Mes_Package_Gather> mesPackageGatherRep
        , SqlSugarRepository<SysConfig> sysConfigRep
        , SqlSugarRepository<Mes_BatchOrderUPI_New> mesBatchOrderUpiRep
        , SqlSugarRepository<Mes_Order_Gather> mesOrderGatherRep
        )
    {
        _sysConfigRep = sysConfigRep;
        _mesPackageGatherRep = mesPackageGatherRep;
        _rep = rep;
        _wmsStockQuanRep = wmsStockQuanRep;
        _mesBatchOrderUpiRep = mesBatchOrderUpiRep;
        _mesOrderGatherRep = mesOrderGatherRep;
    }
 
 
 
    /// <summary>
    /// 强制出库
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "ForceOutbound")]
    [Description("WmsOperationTask/ForceOutbound")]
    public async Task ForceOutbound(ForceOutboundInput input)
    {
        if (input == null || input.PackageCodeList?.Count == 0)
        {
            throw Oops.Oh("参数不能为空");
        }
        List<WmsStockQuan> updateQuanList = new List<WmsStockQuan>();
        foreach (var item in input.PackageCodeList)
        {
            var quanList = await _wmsStockQuanRep.AsQueryable().Where(x => x.PackageCode == item).ToListAsync();
            var isExist = quanList.Where(x => x.StockStatus == StockStatusEnum.齐包待出库).Count();
            if (isExist > 0)
            {
                throw Oops.Oh($"包{item}中其中有板状态是'{StockStatusEnum.齐包待出库.ToString()}',不允许强制出库");
            }
 
            //更新状态 
            foreach (var quan in quanList)
            {
                quan.StockStatus = StockStatusEnum.人工强制待出库;
                quan.UpdateTime = DateTime.Now;
                quan.OperReason = "人工强制待出库";
            }
            updateQuanList.AddRange(quanList);
        }
 
        await _wmsStockQuanRep.UpdateRangeAsync(updateQuanList);
 
    }
 
    /// <summary>
    /// 判断齐套
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "ValdateQiTao")]
    [Description("WmsOperationTask/ValdateQiTao")]
    public async Task<ValidateQiTaoOutput> ValdateQiTao(ValidateQiTaoInput input)
    {
        ValidateQiTaoOutput output = new ValidateQiTaoOutput();
        if (input == null || input.PackageCode == null)
        {
            throw Oops.Oh("参数不能为空");
        }
        var singlePackage = await _mesPackageGatherRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
        if (singlePackage == null)
        {
            throw Oops.Oh($"没有找到包号{input.PackageCode}的汇总数据");
        }
 
        var setValue = "";
        var _QiTaoReuslt = "";
        var other_orderList = await _mesPackageGatherRep.AsQueryable().Where(x => x.Info5 == singlePackage.Info5 && x.PackageCode != input.PackageCode).ToListAsync();
        var num = other_orderList.Where(x => x.UpiStatus == UpiStatusEnum.初始 || x.UpiStatus == UpiStatusEnum.不齐包).Count();
        if (num > 0)
        {
            //不齐套
            setValue = $"{input.PackageCode}|不齐套";
            _QiTaoReuslt = "不齐套";
        }
        else
        {
            setValue = $"{input.PackageCode}|齐套";
            _QiTaoReuslt = "齐套";
        }
 
        var sysConfig = await _sysConfigRep.GetFirstAsync(x => x.Code == CommonConst.WmsBZ30_QiTao);
        if (sysConfig == null)
        {
            throw Oops.Oh($"没有配置 判断齐套 值");
        }
        if (!string.IsNullOrEmpty(sysConfig.Value) && sysConfig.Value != "无")
        {
            throw Oops.Oh($"判断齐套值已经存在值{sysConfig.Value},不允许操作");
        }
        sysConfig.Value = setValue;
        await _sysConfigRep.UpdateAsync(sysConfig);
 
        output = singlePackage.Adapt<ValidateQiTaoOutput>();
        output.QiTaoReuslt = _QiTaoReuslt;
        return output;
    }
 
 
    /// <summary>
    /// 核对标签
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "ValdateLabel")]
    [Description("WmsOperationTask/ValdateLabel")]
    public async Task<Mes_Package_Gather> ValdateLabel(ValidateLabelInput input)
    {
        if (input == null || input.PackageCode == null || input.Upi == null)
        {
            throw Oops.Oh("参数不能为空");
        }
 
        var singleUpi = await _mesBatchOrderUpiRep.AsQueryable().Where(x => x.UPI == input.Upi).FirstAsync();
        if (singleUpi == null)
        {
            throw Oops.Oh($"没有找到部件条码{input.Upi}的数据");
        }
        if (singleUpi.PackageCode != input.PackageCode)
        {
            throw Oops.Oh($"部件条码{input.Upi}所属包是{singleUpi.PackageCode},跟扫描的包号{input.PackageCode}不符");
        }
 
        var singlePackage = await _mesPackageGatherRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
        if (singlePackage == null)
        {
            throw Oops.Oh($"没有找到包号{input.PackageCode}的汇总数据");
        }
        return singlePackage;
    }
 
 
    /// <summary>
    /// 查询不齐套单据
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "QueryNoKittingList")]
    [Description("WmsOperationTask/QueryNoKittingList")]
    public async Task<List<Mes_Order_Gather>> QueryNoKittingList([FromQuery] KittingListInput input)
    {
        var list = await _mesOrderGatherRep.AsQueryable()
            .WhereIF(!string.IsNullOrWhiteSpace(input.Info5), u => u.Info5.Contains(input.Info5.Trim()))
            .WhereIF(!string.IsNullOrWhiteSpace(input.Info5), u => u.Info5.Contains(input.Info5.Trim()))
            .Where(x=>((DateTime)x.CreateTime).ToString("yyyyMMdd")==DateTime.Now.ToString("yyyyMMdd"))
            .Where(x => x.IsKitting == false)
            .OrderBy(g => g.Id)
            .ToListAsync(); // 确保获取结果为 List
 
        return list; // 结果
    }
}