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> GetLogisticsInfoList(string name, string linkMan, string phone, string licensePlate, string type, int page, int limit, RefAsync count) { try { Expression> item = Expressionable.Create() .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 GetLogisticsInfo(int id) { var data = await LogisticsInfoRst.GetOneByIdAsync(id); return data; } public async Task> GetLogisticsInfoSelect() { var data = await LogisticsInfoRst.GetAllAsync(); return data; } public async Task 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 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 DelLogisticsInfo(int id, int userId) { var num = await LogisticsInfoRst.RemoveAsync(id, userId); return num > 0; } public async Task DelsLogisticsInfo(List 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; } } }