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 GetCustomerList(string name, int? type, string linkMan, string phone, int page, int limit, out int count) { try { Expression> item = Expressionable.Create() .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 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, int userId) { try { //缺少判断是否重复 var num = CustomerRst.Add(new SysCustomer() { CustomerNo = no, CustomerName = name, Type = type, Address = address, LinkMan = linkMan, Phone = phone, BankAccount = bankAccount, CreditRating = creditRating, 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, 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.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 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); } } } }