wxw
2025-05-12 c7c2f7aa20427204944ba80a2704232b2f281582
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using Model.ModelDto.SysDto;
using SqlSugar;
using WMS.Entity.SysEntity;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
 
namespace WMS.BLL.SysServer
{
    public class WareHouseServer:IWareHouseServer
    {
        public IWareHouseRepository WareHouseRst { get; set; }
        public WareHouseServer(IWareHouseRepository wareHouseRst)
        {
            WareHouseRst = wareHouseRst;
        }
 
        /// <summary>
        /// 获取仓库信息
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <param name="wareHouseName">仓库名称</param>
        /// <param name="type">类型</param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List<WareHouseDto> GetWarehouseList(string wareHouseNo, string wareHouseName, string type, int page, int limit,out int count)
        {
            try
            {
                Expression<Func<SysWareHouse, bool>> item = Expressionable.Create<SysWareHouse>() //创建表达式
                    .AndIF(!string.IsNullOrWhiteSpace(wareHouseNo), it => it.WareHouseNo.Contains(wareHouseNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(wareHouseName), it => it.WareHouseName.Contains(wareHouseName.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
                    .ToExpression();//注意 这一句 不能少
 
                
                var data = WareHouseRst.GetAllByOrderPageAsync(item, limit, page,out int counts)
                    .Includes(x => x.TypeInfo)
                    .Includes(x => x.TemperatureInfo)
                    .Includes(x => x.CreateUserInfo)
                    .Includes(x => x.UpdateUserInfo).ToList();
                count = counts;
                return data.Select(m => new WareHouseDto()
                {
                    Id = m.Id,
                    WareHouseNo = m.WareHouseNo,
                    WareHouseName = m.WareHouseName,
                    Type = m.TypeInfo == null ? "" : m.TypeInfo.DictName,
                    Temperature = m.TemperatureInfo == null ? "" : m.TemperatureInfo.DictName,
                    Row = m.Row,
                    Column = m.Column,
                    Layer = m.Layer,
 
                    CreateUserName = m.CreateUserInfo == null ? "" : m.CreateUserInfo.RealName,
                    UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.RealName,
                    CreateTime = m.CreateTime,
                    UpdateTime = m.UpdateTime
                }).ToList();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
 
        }
 
        /// <summary>
        /// 获取单条仓库信息
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns></returns>
        public async Task<SysWareHouse> GetWarehouse(int id)
        {
            try
            {
                var data = await WareHouseRst.GetOneByIdAsync(id);
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 修改仓库信息
        /// </summary>
        /// <param name="id">ID</param>
        /// <param name="no">仓库编号</param>
        /// <param name="name">仓库名称</param>
        /// <param name="type">类型</param>
        /// <param name="temp">存储环境</param>
        /// <param name="row">排</param>
        /// <param name="col">列</param>
        /// <param name="layer">层</param>
        /// <param name="userId">操作人</param>
        /// <returns>是否成功</returns>
        public async Task<bool> EditWareHouse(int id,string no, string name, string type, string temp, int? row, int? col, int? layer, int userId)
        {
            try
            {
                //判断除当前id信息以外是否含有编号和名称
                var bol = await WareHouseRst.GetAllAsync()
                    .AnyAsync(m => m.Id != id && (m.WareHouseNo == no.Trim() || m.WareHouseName == name.Trim()));
                if (bol)
                {
                    throw new Exception("当前仓库号或仓库名称已存在");
                }
 
                var wareHouse = await WareHouseRst.GetOneByIdAsync(id);
                if (wareHouse == null)
                {
                    throw new Exception("为查询到当前仓库信息");
                }
 
                var num = await WareHouseRst.EditAsync(new SysWareHouse()
                {
                    Id = id,
                    WareHouseNo = no,
                    WareHouseName = name,
                    Type = type,
                    Temperature = temp,
                    Row = row,
                    Column = col,
                    Layer = layer,
                    UpdateUser = userId,
                    UpdateTime = DateTime.Now
                });
                
                if (num > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
 
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public async Task<List<SysWareHouse>> GetWareHouseDic()
        {
            try
            {
                var list = await WareHouseRst.GetAllAsync().ToListAsync();
                return list;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
    }
}