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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Model.ModelDto.SysDto;
using SqlSugar;
using WMS.DAL;
using WMS.Entity.SysEntity;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
 
namespace WMS.BLL.SysServer
{
    public class ExceptionServer : IExceptionServer
    {
        public IExceptionRepository ExceptionRst { get; set; }
        private readonly IMapper _mapper;
        public ExceptionServer(IExceptionRepository exceptionRst, IMapper mapper)
        {
            ExceptionRst = exceptionRst;
            _mapper = mapper;
        }
        /// <summary>
        /// 查询异常处理表信息
        /// </summary>
        /// <param name="palletNo">托盘号</param>
        /// <param name="excLocatNo">储位号</param>
        /// <param name="orderNo">单据号 入库单 出库单 移库单</param>
        /// <param name="taskNo">任务号</param>
        /// <param name="status">状态 0:未处理 1:已处理</param>
        /// <param name="text">处理描述</param>
        /// <param name="type">异常类型 0:空取 1:满入 2:双工位异常</param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<List<SysException>> GetExceptionList(string palletNo, string excLocatNo, string orderNo,
            string taskNo, string status, string text, string type, int page = 0, int limit = 10)
        {
            try
            {
                Expression<Func<SysException, bool>> item = Expressionable.Create<SysException>()
                    .AndIF(!string.IsNullOrWhiteSpace(palletNo), it => it.PalletNo.Contains(palletNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(excLocatNo), it => it.ExcLocatNo.Contains(excLocatNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(orderNo), it => it.OrderNo.Contains(orderNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(taskNo), it => it.TaskNo.Contains(taskNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(text), it => it.Text.Contains(text.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == type)
                    .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
                    .ToExpression();//注意 这一句 不能少
 
                var data = await ExceptionRst.GetAllByOrderPageAsync(item, limit, page, out int counts).ToListAsync();
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 添加异常处理信息
        /// </summary>
        /// <param name="type">异常类型 0:空取 1:满入 2:双工位异常</param>
        /// <param name="palletNo">托盘号</param>
        /// <param name="excLocatNo">储位号</param>
        /// <param name="orderNo">单据号 入库单 出库单 移库单</param>
        /// <param name="taskNo">任务号</param>
        /// <param name="text">处理描述</param> 
        /// <param name="userId">操作人</param>
        /// <returns></returns>
        public async Task<bool> AddException(string type, string palletNo, string excLocatNo, string orderNo, string taskNo, string text, int userId)
        {
            try
            {
                var exNo = new Common().GetMaxNo("EX");
                var num = await ExceptionRst.AddAsync(new SysException()
                {
                    Type = type,
                    ExceptionNo = exNo,
                    PalletNo = palletNo,
                    ExcLocatNo = excLocatNo,
                    OrderNo = orderNo,
                    TaskNo = taskNo,
                    Text = text,
                    CreateUser = userId
                });
                if (num > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
 
        /// <summary>
        /// 获取异常处理信息列表
        /// </summary>
        /// <param name="exceptionNo">异常号</param>
        /// <param name="palletNo">托盘号</param>
        /// <param name="excLocatNo">异常储位</param>
        /// <param name="orderNo">关联单号</param>
        /// <param name="taskNo">关联任务号</param>
        /// <param name="type">异常类型</param>
        /// <param name="status">状态</param>
        /// <returns></returns>
        public List<ExceptionDto> GetTableList(string exceptionNo, string palletNo, string excLocatNo, string orderNo, string taskNo, string type, string status)
        {
            List<ExceptionDto> tablelist = ExceptionRst.GetExceptionList(exceptionNo, palletNo, excLocatNo, orderNo, taskNo, type, status);
            return tablelist;
        }
 
        /// <summary>
        /// 根据id获取异常信息
        /// </summary>
        /// <param name="id">异常id</param>
        /// <returns></returns>
        public SysException GetTableById(int id)
        {
            SysException table = ExceptionRst.GetExceptionById(id);
            return table;
        }
 
        /// <summary>
        /// 新增异常处理
        /// </summary>
        /// <param name="type">异常类型</param>
        /// <param name="palletNo">托盘号</param>
        /// <param name="excLocatNo">异常储位</param>
        /// <param name="orderNo">关联单号</param>
        /// <param name="taskNo">关联任务号</param>
        /// <param name="demo">备注</param>
        /// <param name="uid">创建人</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        public async Task<int> InsertTableName(string type, string palletNo, string excLocatNo, string orderNo, string taskNo, string demo, int uid)
        {
            //捕获异常
            try
            {
                //获取最大异常号
                string ExceptionNo = ExceptionRst.GetMaxExceptionNo().ExceptionNo;
                //判断获取到的异常号是否为空
                if (!string.IsNullOrEmpty(ExceptionNo))
                {
                    ExceptionNo = "1000";
                }
                else
                {
                    ExceptionNo = (int.Parse(ExceptionNo) + 1).ToString();
                }
                int i = await ExceptionRst.InsertException(ExceptionNo, type, palletNo, excLocatNo, orderNo, taskNo, demo, uid);
                return i;
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("新增异常处理", ex);
            }
        }
 
        /// <summary>
        /// 处理异常状态
        /// </summary>
        /// <param name="tabledto">异常处理dto</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        public async Task<int> EditStatus(ExceptionDto tabledto)
        {
            //捕获异常
            try
            {
                SysException table = _mapper.Map<SysException>(tabledto);
                int i = await ExceptionRst.EditStatus(table);
                return i;
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("处理状态异常", ex);
            }
        }
    }
}