bklLiudl
2025-04-07 4e8f58cb41c7b6d570fd1979d80f74ab8a4d00c2
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Model.InterFaceModel;
using Model.ModelDto.BllSoDto;
using Model.ModelDto.LogDto;
using Newtonsoft.Json;
using SqlSugar;
using Utility.Tools;
using WMS.DAL; 
using WMS.Entity.Context;
using WMS.Entity.LogEntity;
using WMS.Entity.SysEntity;
using WMS.IBLL.ILogServer;
 
namespace WMS.BLL.LogServer
{
    public class TaskServer:DbHelper<LogTask>,ITaskServer
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        public TaskServer():base(Db)
        {
        }
 
 
        public List<TaskDto> GetTaskList(List<string> orderType, string type, string status, string taskNo, int isSuccess, string palletNo, string msg, int page, int limit, out int count)
        {
            try
            {
                Expression<Func<LogTask, bool>> item = Expressionable.Create<LogTask>()
                    .AndIF( orderType.Count>0, it => orderType.Contains(it.OrderType))
                    .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
                    .AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == status)
                    .AndIF(!string.IsNullOrWhiteSpace(taskNo), it => it.TaskNo.Contains(taskNo.Trim())) 
                    .AndIF(isSuccess != -1, it => it.IsSuccess == isSuccess)
                    .AndIF(!string.IsNullOrWhiteSpace(palletNo), it => it.PalletNo.Contains(palletNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(msg), it => it.Msg.Contains(msg.Trim())) 
                    .ToExpression();//注意 这一句 不能少
                var total = 0;
                var data = GetAllWhereAsync(item)
                    .LeftJoin<SysUserInfor>((a,b)=>a.CreateUser == b.Id).
                    Select((a,b) => new TaskDto()
                    {
                        Id = a.Id,
                        TaskNo = a.TaskNo,
                        Sender = a.Sender,
                        Receiver = a.Receiver,
                        IsSuccess = a.IsSuccess,
                        Information = a.Information,
                        SendDate = a.SendDate,
                        BackDate = a.BackDate,
                        StartLocat = a.StartLocat,
                        EndLocat = a.EndLocat,
                        MessageDate = a.MessageDate,
                        PalletNo = a.PalletNo,
                        Msg = a.Msg,
                        IsSend = a.IsSend,
                        IsCancel = a.IsCancel,
                        IsFinish = a.IsFinish,
                        Status = a.Status,
                        Type = a.Type,
                        OrderType = a.OrderType,
 
                        CancelDate = a.CancelDate,
                        FinishDate = a.FinishDate,
 
                        CreateUserName =b.RealName,
                        CreateTime = a.CreateTime
                    })
                    .OrderByDescending(a => a.TaskNo)
                    .ToOffsetPage(page,limit,ref total);
                count = total;
 
                return data.OrderByDescending(m=>m.TaskNo).ToList();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        //修改任务下发状态为成功
        public void EditTaskIssueOk(List<string> taskNo, DateTime sendTime, DateTime backTime)
        {
            try
            {
                var list = GetAllWhereAsync(m => taskNo.Contains(m.TaskNo)).ToList();
                foreach (var item in list)
                {
                    item.IsSuccess = 1;
                    item.Status = "1";
                    item.SendDate = sendTime;
                    item.BackDate = backTime;
                }
 
                Db.Updateable(list).ExecuteCommand();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        //修改任务下发状态为失败异常信息
        public void EditTaskIssueNo(List<string> taskNo, DateTime sendTime, DateTime backTime, string information)
        {
            try
            {
                var list = GetAllWhereAsync(m => taskNo.Contains(m.TaskNo)).ToList();
                foreach (var item in list)
                {
                    item.SendDate = sendTime;
                    item.BackDate = backTime;
                    item.Information = information;
                }
 
                Db.Updateable(list).ExecuteCommand();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public string GetTaskOrderType(string taskNo,string tasktype)
        {
            try
            {
                if (tasktype == "1")
                {
                     taskNo = taskNo.Substring(0, taskNo.Length - 3);
                }
                var task = Db.Queryable<LogTask>().OrderByDescending(m=>m.Id).First(m => m.TaskNo == taskNo);
                if (task == null)
                {
                    throw new Exception($"未查询到{taskNo}任务号的任务信息");
                }
 
                return task.OrderType;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public string GetTaskType(string taskNo)
        {
            try
            {
                var task = Db.Queryable<LogTask>().First(m => m.TaskNo == taskNo);
                if (task == null)
                {
                    throw new Exception($"未查询到{taskNo}任务号的任务信息");
                }
 
                return task.Type;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// AGV入库放货请求下发至WCS
        /// </summary>
        /// <param name="port"></param> 入库口
        /// <param name="url"></param>  请求地址
        /// <returns></returns>
        public string  GetWcsPuttype(string taskno,string url)
        {
            try
            {
                var port = Db.Queryable<LogTask>().First(m => m.TaskNo == taskno).EndLocat;
                var data = new
                {
                    Port = port,
                    TaskNo = taskno
                };
                var jsonData = JsonConvert.SerializeObject(data);   
                var res = HttpHelper.DoPost(url, jsonData, "请求WCS"+ port+"入库口放货", "WCS");
 
                //////解析返回数据 
                var ret = JsonConvert.DeserializeObject<WcsModel>(res);
                return ret.StatusCode.ToString();
            }                                                                                                 
            catch (Exception ex)
            {
 
                throw ex;
            }
        } 
    }
}