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
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 SqlSugar;
using WMS.Entity.LogEntity;
using WMS.Entity.SysEntity;
using WMS.IBLL.ILogServer;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
 
namespace WMS.BLL.SysServer
{
    public class CustomerServer : ICustomerServer
    {
        public ICustomerRepository CustomerRst { get; set; }
        private readonly IOperationSysServer _operation; //操作日志
        public CustomerServer(ICustomerRepository customerRst, IOperationSysServer operation)
        {
            CustomerRst = customerRst;
            _operation = operation;
        }
 
 
        public List<CustomerDto> GetCustomerList(string no,string name, int? type, string linkMan, string phone, int page, int limit, out int count)
        {
            try
            {
                Expression<Func<SysCustomer, bool>> item = Expressionable.Create<SysCustomer>()
                    .AndIF(!string.IsNullOrWhiteSpace(no), it => it.CustomerNo.Contains(no.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(name), it => it.CustomerName.Contains(name.Trim()))
                    .AndIF(type >= 0, it => it.Type == type)
                    .AndIF(!string.IsNullOrWhiteSpace(linkMan), it => it.LinkMan.Contains(linkMan.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(phone), it => it.Phone.Contains(phone.Trim()))
                    .ToExpression();//注意 这一句 不能少
 
                var data = CustomerRst.GetAllByOrderPageAsync(item, limit, page, out int counts)
                    .Includes(x => x.CreateUserInfo)
                    .Includes(x => x.UpdateUserInfo)
                    .ToList();
                count = counts;
 
                return data.Select(m => new CustomerDto()
                {
                    Id = m.Id,
                    CustomerNo = m.CustomerNo,
                    CustomerName = m.CustomerName,
                    Type = m.Type,
                    Address = m.Address,
                    LinkMan = m.LinkMan,
                    Phone = m.Phone,
                    BankAccount = m.BankAccount,
                    CreditRating = m.CreditRating,
                    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 SysCustomer GetCustomer(int id)
        {
            try
            {
                var data = CustomerRst.GetOneById(id);
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public List<SysCustomer> GetCustomerSelect()
        {
            try
            {
                var data = CustomerRst.GetAllAsync().ToList();
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public bool AddCustomer(string no, string name, int type, string address, string linkMan, string phone, string bankAccount, string creditRating, string demo, int userId)
        {
            try
            {
                //判断是否重复
                var customer = CustomerRst.GetAllWhereAsync(m => m.CustomerNo == no && m.IsDel == "0").First();
                if (customer != null)
                {
                    throw new Exception("相同编码的客户已存在,请勿重复添加");
                }
                var num = CustomerRst.Add(new SysCustomer()
                {
                    CustomerNo = no,
                    CustomerName = name,
                    Type = type,
                    Address = address,
                    LinkMan = linkMan,
                    Phone = phone,
                    BankAccount = bankAccount,
                    CreditRating = creditRating,
                    Demo = demo,
                    CreateUser = userId
                });
                return num > 0;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public bool EditCustomer(int id, string no, string name, int type, string address, string linkMan, string phone,
            string bankAccount, string creditRating, string demo, int userId)
        {
            try
            {
                var customer = CustomerRst.GetOneById(id);
                if (customer == null)
                {
                    throw new Exception("未查询到客户信息");
                }
 
                customer.CustomerNo = no;
                customer.CustomerName = name;
                customer.Type = type;
                customer.Address = address;
                customer.LinkMan = linkMan;
                customer.Phone = phone;
                customer.BankAccount = bankAccount;
                customer.CreditRating = creditRating;
                customer.Demo = demo;
                customer.UpdateUser = userId;
                customer.UpdateTime = DateTime.Now;
                var num = CustomerRst.Edit(customer);
                return num > 0;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public bool DelCustomer(int id, int userId)
        {
            try
            {
                var num = CustomerRst.Remove(id, userId);
                return num > 0;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public bool DelsCustomer(List<int> ids, int userId)
        {
            try
            {
                var list = CustomerRst.GetAllWhereAsync(m => ids.Contains(m.Id)).ToList();
                for (int i = 0; i < list.Count; i++)
                {
                    _operation.InsertOperation("基础信息", "客户管理", list[i].CustomerNo, "删除", "删除客户信息 客户号:" + list[i].CustomerNo, userId);
                }
                var num = CustomerRst.RemoveAll(list, userId);
                return num > 0;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
    }
}