schangxiang@126.com
2025-09-17 ff43ddf18764629ff875478e4e47a7281cbd230a
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
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
 
using Admin.NET.Application.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Admin.NET.Application.CommonHelper;
public class BaseInfoHelper
{
 
 
    private readonly SqlSugarRepository<WmsBaseContainer> _wmsContainerRep;
    private readonly SqlSugarRepository<WmsBaseArea> _wmsAreaRep;
    private readonly SqlSugarRepository<WmsBasePlace> _wmsPlaceRep;
 
    /// <summary>
    ///  根据库区号获取库区信息
    /// </summary>
    /// <param name="wmsPlace"></param>
    /// <param name="_wmsAreaRep"></param>
    /// <returns></returns>
    public static async Task<WmsBaseArea> GetAreaByPlace(WmsBasePlace wmsPlace, SqlSugarRepository<WmsBaseArea> _wmsAreaRep)
    {
        var wmsArea = await _wmsAreaRep.GetFirstAsync(x => x.Id == wmsPlace.AreaId && x.IsDelete == false);
        //判断库区信息是否为空
        if (wmsArea == null)
        {
            //抛出异常库区不存在
            throw Oops.Oh($"库区{wmsPlace.AreaCode}不存在");
        }
        if (wmsArea.IsDisabled)
        {
            //抛出异常库区已禁用
            throw Oops.Oh($"库区{wmsArea.AreaCode}已禁用");
        }
 
        return wmsArea;
    }
 
 
    /// <summary>
    /// 根据库位号获取库位信息
    /// </summary>
    /// <param name="toPlaceCode"></param>
    /// <param name="_wmsPlaceRep"></param>
    /// <returns></returns>
    public static async Task<WmsBasePlace> GetPlace(string toPlaceCode, SqlSugarRepository<WmsBasePlace> _wmsPlaceRep)
    {
        var wmsPlace = await _wmsPlaceRep.GetFirstAsync(x => x.PlaceCode == toPlaceCode && x.IsDelete == false);
        //判断库位信息是否为空
        if (wmsPlace == null)
        {
            //抛出异常库位不存在
            throw Oops.Oh($"库位:{toPlaceCode}不存在");
        }
        if (wmsPlace.IsDisabled)
        {
            //抛出异常库位已禁用
            throw Oops.Oh($"库位:{toPlaceCode}已禁用");
        }
 
        return wmsPlace;
    }
 
    /// <summary>
    /// 根据库位号获取库位信息
    /// </summary>
    /// <param name="toPlaceCode"></param>
    /// <param name="wmsBasePlaceList"></param>
    /// <returns></returns>
    public static WmsBasePlace GetPlace(string toPlaceCode, List<WmsBasePlace> wmsBasePlaceList)
    {
        var wmsPlace = wmsBasePlaceList.FirstOrDefault(x => x.PlaceCode == toPlaceCode && x.IsDelete == false);
        //判断库位信息是否为空
        if (wmsPlace == null)
        {
            //抛出异常库位不存在
            throw Oops.Oh($"库位:{toPlaceCode}不存在");
        }
        if (wmsPlace.IsDisabled)
        {
            //抛出异常库位已禁用
            throw Oops.Oh($"库位:{toPlaceCode}已禁用");
        }
 
        return wmsPlace;
    }
 
    /// <summary>
    /// 根据容器号获取库位信息
    /// </summary>
    /// <param name="containerCode"></param>
    /// <param name="_wmsBasePlaceRep"></param>
    /// <param name="_wmsContainerPlaceRep"></param>
    /// <returns></returns>
    public static async Task<WmsBasePlace> GetPlaceByContinerCode(string containerCode, SqlSugarRepository<WmsBasePlace> _wmsBasePlaceRep, SqlSugarRepository<WmsContainerPlace> _wmsContainerPlaceRep)
    {
        var containerPlace = await _wmsContainerPlaceRep.GetFirstAsync(u => u.ContainerCode == containerCode);
        if (containerPlace == null)
        {
            throw Oops.Oh($"根据容器号{containerCode}没有找到容器库位绑定关系");
        }
        var place = await _wmsBasePlaceRep.GetFirstAsync(u => u.PlaceCode == containerPlace.PlaceCode);
        if (place == null)
        {
            throw Oops.Oh($"根据库位号{containerPlace.PlaceCode}没有找到库位信息");
        }
        return place;
    }
 
 
    /// <summary>
    /// 根据容器号获取容器信息
    /// </summary>
    /// <param name="toContainer"></param>
    /// <param name="_wmsContainerRep"></param>
    /// <returns></returns>
    public static async Task<WmsBaseContainer> GetContainer(string toContainer, SqlSugarRepository<WmsBaseContainer> _wmsContainerRep)
    {
        var wmsContainer = await _wmsContainerRep.GetFirstAsync(x => x.ContainerCode == toContainer && x.IsDelete == false);
        //判断容器信息是否为空
        if (wmsContainer == null)
        {
            //抛出异常容器不存在
            throw Oops.Oh($"容器{toContainer}不存在");
        }
        if (wmsContainer.IsDisabled)
        {
            //抛出异常容器已禁用
            throw Oops.Oh($"容器{toContainer}已禁用");
        }
 
        return wmsContainer;
    }
 
    /// <summary>
    /// 根据仓库号获取容器信息
    /// </summary>
    /// <param name="toWarehouse"></param>
    /// <param name="_wmsWmsWarehouseRep"></param>
    /// <returns></returns>
    public static async Task<WmsBaseWarehouse> GetWarehouse(string toWarehouse, SqlSugarRepository<WmsBaseWarehouse> _wmsWmsWarehouseRep)
    {
        var wmsContainer = await _wmsWmsWarehouseRep.GetFirstAsync(x => x.Code == toWarehouse && x.IsDelete == false);
        //判断容器信息是否为空
        if (wmsContainer == null)
        {
            //抛出异常容器不存在
            throw Oops.Oh($"仓库{toWarehouse}不存在");
        }
        if (wmsContainer.IsDisabled)
        {
            //抛出异常容器已禁用
            throw Oops.Oh($"仓库{toWarehouse}已禁用");
        }
 
        return wmsContainer;
    }
}