bklLiudl
2024-05-25 484e5129e4c9a671c5660a556a24bd306f1fdd9b
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Model.ModelDto.BllSoDto;
using Model.ModelDto.LogDto;
using SqlSugar;
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)
        {
            try
            {
                var task = Db.Queryable<LogTask>().First(m => m.TaskNo == taskNo);
                if (task == null)
                {
                    throw new Exception($"未查询到{taskNo}任务号的任务信息");
                }
 
                return task.OrderType;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
    }
}