wxw
2025-05-12 c2dc3bd2569f8398e2710aca2685bb3115c77eb0
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Commom.Utility;
using Common;
using Model;
 
namespace BLL.DAL
{
    public class DAL_TaskMonitor
    {
        /// <summary>
        /// 获取任务控制信息
        /// </summary>
        /// <param name="Json"></param>
        /// <param name="pageInfo"></param>
        /// <returns></returns>
        public IList<WCSTasks> GetList(AjaxGetTaskList Json, ref PageInfo pageInfo)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                List<SqlParam> para = new List<SqlParam>();
 
                // 0 未下发 1 已下发 2 ? 3已完成
                strSql.Append("select Id,TaskNo,CASE Type when '0' then '入库' when '1' then '出库' when '2' then '移库' else Type end as Type,");
                strSql.Append("Status,IsSuccess,Information,Origin,StartLocat,EndLocat,PalletNo,CancelDate,Levels,FinishDate,CreateTime ");
                strSql.Append(" from WCSTasks where IsDel = '0' ");
 
 
                if (!string.IsNullOrWhiteSpace(Json.TaskNo))
                {
                    strSql.Append(" and TaskNo like '%" + Json.TaskNo + "%'  ");
                }
                if (!string.IsNullOrWhiteSpace(Json.TaskType))
                {
                    strSql.Append(" and Type = '" + Json.TaskType + "'  ");
                }
                if (!string.IsNullOrWhiteSpace(Json.Status))
                {
                    strSql.Append(" and Status = '" + Json.Status + "'  ");
                }
                if (!string.IsNullOrWhiteSpace(Json.StartLocat))
                {
                    strSql.Append(" and StartLocat like '%" + Json.StartLocat + "%'  ");
                }
                if (!string.IsNullOrWhiteSpace(Json.PalletNo))
                {
                    strSql.Append(" and PalletNo like '%" + Json.PalletNo + "%'  ");
                }
                if (!string.IsNullOrWhiteSpace(Json.EndLocat))
                {
                    strSql.Append(" and EndLocat like '%" + Json.EndLocat + "%'  ");
                }
                // strSql.Append(" order by state ,TaskNo1 ");
 
                SqlParam[] param = null;
                if (para != null)
                {
                    param = para.ToArray();
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "TaskNo", "desc", ref pageInfo);
                return ModelConvertHelper<WCSTasks>.DataTableToModel(dt);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 获取任务控制信息明细
        /// </summary>
        /// <param name="Json"></param>
        /// <param name="pageInfo"></param>
        /// <returns></returns>
        public IList<WCSTasksMonitor> GetDetailList(AjaxGetTaskDetailList Json, ref PageInfo pageInfo)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                List<SqlParam> para = new List<SqlParam>();
 
                //  
                strSql.Append("select Id,TaskNo,PlcId,PlcName,StartLocat,EndLocat,InteractiveMsg,ErrorMsg,IsDel,CreateTime,CreateUser,UpdateTime,UpdateUser from WCSTasksMonitor where IsDel = '0' ");
                if (!string.IsNullOrWhiteSpace(Json.TaskNo))
                {
                    strSql.Append(" and TaskNo like '%" + Json.TaskNo + "%' ");
                }
                if (!string.IsNullOrWhiteSpace(Json.StartLocat))
                {
                    strSql.Append(" and StartLocat like '%" + Json.StartLocat + "%'  ");
                }
                if (!string.IsNullOrWhiteSpace(Json.EndLocat))
                {
                    strSql.Append(" and EndLocat like '%" + Json.EndLocat + "%'  ");
                }
                DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), null, "CreateTime", "desc", ref pageInfo);
                return ModelConvertHelper<WCSTasksMonitor>.DataTableToModel(dt);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
 
        /// <summary>
        /// 手动添加任务
        /// </summary>
        /// <param name="model"></param>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        public bool Add(TaskMonitorModel model, string loginUser)
        {
            bool result = false;
            try
            {
                Hashtable ht = new Hashtable();
 
                ht["TaskType"] = model.TaskType.AddQuotes();
                ht["InitialAddre"] = "'" + model.InitialAddre + "'";
                ht["Palno"] = "'" + model.Palno + "'";
                ht["TargetAddre"] = "'" + model.TargetAddre + "'";
                ht["State"] = "'0'";
                ht["IsSucceed"] = "'" + model.IsSucceed + "'";
                ht["ErrorStr"] = "'" + model.ErrorStr + "'";
                ht["PriorityLevel"] = model.PriorityLevel;
                ht["Source"] = "'手动'";
                ht["Demo"] = "'" + model.Demo + "'";
 
                ht["CreateUser"] = "'" + loginUser + "'";
                ht["CreateTime"] = "Getdate()";
 
 
                int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("TaskMonitor", ht);
 
                if (_ret == 1) result = true;
 
                return result;
 
            }
            catch
            {
                return result;
            }
        }
 
 
        /// <summary>
        /// 手动完成任务
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool TaskMonitorComplete(string[] ID)
        {
            bool result = false;
            try
            {
                int dt = DataFactory.SqlDataBase().IsExist("TaskMonitor", "Guid", ID);
                if (dt >= ID.Length)
                {
                    int i = 0;
                    while (i < ID.Length)
                    {
                        StringBuilder sql = new StringBuilder();
                        // 获取当前任务详细信息
                        sql.Append("select * from TaskMonitor where guid = '" + ID[i] + "' and State != '3';");
                        DataTable monitorDt = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
                        if (monitorDt != null && monitorDt.Rows.Count > 0)
                        {
                            // 完成上架任务
                            DALWcsMessage wcsSql = new DALWcsMessage();
                            if (monitorDt.Rows[0]["TaskType"].ToString() == "out")          // 出库任务
                            {
                                wcsSql.WcsinWms(monitorDt.Rows[0]["Palno"].ToString(), monitorDt.Rows[0]["InitialAddre"].ToString(), "2");
                                // 更改储位状态
                                //StringBuilder hql = new StringBuilder();
                                //hql.Append("update DepotsLocation set TurnoverDemand ='01' where LocationCode = '" + monitorDt.Rows[0]["InitialAddre"].ToString() + "'");
                                //DataFactory.SqlDataBase().ExecuteBySql(hql);
                            }
                            else    // 入库任务
                            {
 
                                wcsSql.WcsinWms(monitorDt.Rows[0]["Palno"].ToString(), monitorDt.Rows[0]["TargetAddre"].ToString(), "1");
 
                                //// 更改储位状态
                                //StringBuilder hql = new StringBuilder();
                                //hql.Append("update DepotsLocation set TurnoverDemand ='03' where LocationCode = '" + monitorDt.Rows[0]["TargetAddre"].ToString() + "'");
                                //DataFactory.SqlDataBase().ExecuteBySql(hql);
                            }
 
                            // 修改任务状态
                            sql.Append("update TaskMonitor set State=3 where Guid='" + ID[i] + "'");
                            int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
                            if (_ret >= ID.Length) result = true;
                        }
                        i++;
                    }
 
                }
                return result;
            }
            catch
            {
                return result;
            }
        }
 
        /// <summary>
        ///  取消任务
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool TaskMonitorCancel(string[] ID)
        {
            bool result = false;
            try
            {
                int dt = DataFactory.SqlDataBase().IsExist("TaskMonitor", "Guid", ID);
                if (dt >= ID.Length)
                {
                    int i = 0;
                    while (i < ID.Length)
                    {
                        StringBuilder sql = new StringBuilder();
                        sql.Append("update TaskMonitor set IsDel=1 where Guid='" + ID[i] + "'");
                        int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
                        if (_ret >= ID.Length) result = true;
                        i++;
 
                        //// 更改储位状态
                        //sql.Clear();
                        //sql.Append("select * from TaskMonitor where Guid='" + ID[i] + "';");
                        //DataTable dtt = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
                        //if (dtt.Rows[0][""].ToString() == "in") 
                        //{
                        //    // 将目标储位更改为
                        //}
                    }
 
                }
                return result;
 
            }
            catch
            {
                return result;
            }
        }
    }
}