wxw
3 天以前 d5d794d4e456132b8b07e224e29211998292a728
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
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 async Task<List<LogisticsInfoDto>> GetLogisticsInfoList(string name, string linkMan, string phone, string licensePlate, string type, int page, int limit, RefAsync<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 = await LogisticsInfoRst.GetAllByOrderPage(item, limit, page, out int counts)
                    .Includes(x => x.CreateUserInfo)
                    .Includes(x => x.UpdateUserInfo).ToListAsync();
                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 async Task<SysLogisticsInfo> GetLogisticsInfo(int id)
        {
            var data = await LogisticsInfoRst.GetOneByIdAsync(id);
            return data;
        }
 
        public async Task<SysLogisticsInfo> GetLogisticsDelInfo(int id)
        {
            var data = await LogisticsInfoRst.GetOneByIdAsync1(id);
            return data;
        }
 
        public async Task<List<SysLogisticsInfo>> GetLogisticsInfoSelect()
        {
            var data = await LogisticsInfoRst.GetAllAsync();
            return data;
        }
 
        public async Task<bool> AddLogisticsInfo(AddLogisticsInfoVm model, int userId)
        {
            var num = await LogisticsInfoRst.AddAsync(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;
        }
 
        public async Task<bool> EditLogisticsInfo(EditLogisticsInfoVm model, int userId)
        {
            var logistics = await LogisticsInfoRst.GetOneByIdAsync(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 = await LogisticsInfoRst.EditAsync(logistics);
            return num > 0;
        }
 
        public async Task<bool> DelLogisticsInfo(int id, int userId)
        {
            var num = await LogisticsInfoRst.RemoveAsync(id, userId);
            return num > 0;
        }
 
        public async Task<bool> DelsLogisticsInfo(List<int> ids, int userId)
        {
            var list = await LogisticsInfoRst.GetAllWhere(m => ids.Contains(m.Id)).ToListAsync();
            for (int i = 0; i < list.Count; i++)
            {
                await _operation.InsertOperation("基础信息", "物流管理", list[i].CarrierName, "删除", "删除物流信息 公司名称:" + list[i].CarrierName, Convert.ToInt32(userId));
            }
            var num = LogisticsInfoRst.RemoveAll(list, userId);
            return num > 0;
        }
    }
}