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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Model.ModelDto.SysDto;
using Model.ModelVm.SysVm;
using SqlSugar;
using WMS.Entity.SysEntity;
using WMS.IBLL.ILogServer;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
 
namespace WMS.BLL.SysServer
{
    public class LogisticsInfoServer : ILogisticsInfoServer
    {
        public ILogisticsInfoRepository LogisticsInfoRst { get; set; }
        private readonly IOperationSysServer _operation; //操作日志
        public LogisticsInfoServer(ILogisticsInfoRepository logisticsInfoRst, IOperationSysServer operation)
        {
            LogisticsInfoRst = logisticsInfoRst;
            _operation = operation;
        }
 
        public List<LogisticsInfoDto> GetLogisticsInfoList(string name, string linkMan, string phone, string licensePlate, string type, int page, int limit, out int count)
        {
            try
            {
                Expression<Func<SysLogisticsInfo, bool>> item = Expressionable.Create<SysLogisticsInfo>()
                    .AndIF(!string.IsNullOrWhiteSpace(name), it => it.CarrierName.Contains(name.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(linkMan), it => it.LinkMan.Contains(linkMan.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(phone), it => it.Phone.Contains(phone.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(licensePlate), it => it.LicensePlate.Contains(licensePlate.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
                    .ToExpression();//注意 这一句 不能少
 
                var data = LogisticsInfoRst.GetAllByOrderPageAsync(item, limit, page, out int counts)
                    .Includes(x => x.CreateUserInfo)
                    .Includes(x => x.UpdateUserInfo).ToList();
                count = counts;
                return data.Select(m => new LogisticsInfoDto()
                {
                    Id = m.Id,
                    CarrierName = m.CarrierName,
                    Address = m.Address,
                    LinkMan = m.LinkMan,
                    Phone = m.Phone,
                    BankAccount = m.BankAccount,
                    CreditRating = m.CreditRating,
                    LicensePlate = m.LicensePlate,
                    Type = m.Type,
                    Demo = m.Demo,
                    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);
            }
        }
 
        public SysLogisticsInfo GetLogisticsInfo(int id)
        {
            try
            {
                var data = LogisticsInfoRst.GetOneById(id);
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public List<SysLogisticsInfo> GetLogisticsInfoSelect()
        {
            try
            {
                var data = LogisticsInfoRst.GetAllAsync().ToList();
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public bool AddLogisticsInfo(AddLogisticsInfoVm model, int userId)
        {
            try
            {
 
                var num = LogisticsInfoRst.Add(new SysLogisticsInfo()
                {
                    CarrierName = model.CarrierName,
                    Address = model.Address,
                    LinkMan = model.LinkMan,
                    Phone = model.Phone,
                    BankAccount = model.BankAccount,
                    CreditRating = model.CreditRating,
                    LicensePlate = model.LicensePlate,
                    Type = model.Type,
                    Demo = model.Demo,
                    CreateUser = userId
                });
                return num > 0;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public bool EditLogisticsInfo(EditLogisticsInfoVm model, int userId)
        {
            try
            {
                var logistics = LogisticsInfoRst.GetOneById(model.Id);
                if (logistics == null)
                {
                    throw new Exception("未查询到物流信息");
                }
 
                logistics.CarrierName = model.CarrierName;
                logistics.Address = model.Address;
                logistics.LinkMan = model.LinkMan;
                logistics.Phone = model.Phone;
                logistics.BankAccount = model.BankAccount;
                logistics.CreditRating = model.CreditRating;
                logistics.LicensePlate = model.LicensePlate;
                logistics.Type = model.Type;
                logistics.Demo = model.Demo;
                logistics.UpdateUser = userId;
                logistics.UpdateTime = DateTime.Now;
                var num = LogisticsInfoRst.Edit(logistics);
                return num > 0;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public bool DelLogisticsInfo(int id, int userId)
        {
            try
            {
                var num = LogisticsInfoRst.Remove(id, userId);
                return num > 0;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public bool DelsLogisticsInfo(List<int> ids, int userId)
        {
            try
            {
                var list = LogisticsInfoRst.GetAllWhereAsync(m => ids.Contains(m.Id)).ToList();
                for (int i = 0; i < list.Count; i++)
                {
                    _operation.InsertOperation("基础信息", "物流管理", list[i].CarrierName, "删除", "删除物流信息 公司名称:" + list[i].CarrierName, Convert.ToInt32(userId));
                }
                var num = LogisticsInfoRst.RemoveAll(list, userId);
                return num > 0;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
    }
}