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 GetLogisticsInfoList(string name, string linkMan, string phone, string licensePlate, string type, int page, int limit, out int 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 = 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 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 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); } } } }