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.SysEntity; using WMS.IBLL.ISysServer; using WMS.IDAL.ISysInterface; namespace WMS.BLL.SysServer { public class StorageRoadwayServer: IStorageRoadwayServer { public IStorageRoadwayRepository RoadwayRst { get; set; } public StorageRoadwayServer(IStorageRoadwayRepository roadwayRst) { RoadwayRst = roadwayRst; } /// /// 查询巷道信息 /// /// 仓库号 /// 巷道名称 /// 状态 /// 类型 /// /// /// /// public List GetStorageRoadwayList(string houseNo, string roadwayName, string status, string type, int page, int limit,out int count) { try { Expression> item = Expressionable.Create() //创建表达式 .AndIF(!string.IsNullOrWhiteSpace(houseNo), it => it.WareHouseNo.Contains(houseNo.Trim())) .AndIF(!string.IsNullOrWhiteSpace(roadwayName), it => it.RoadwayName.Contains(roadwayName.Trim())) .AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == status) .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type) .ToExpression();//注意 这一句 不能少 var data = RoadwayRst.GetAllByOrderPageAsync(item, limit, page,out int counts) .Includes(x => x.WareHouseInfo) .Includes(x => x.TemperatureInfo) .Includes(x => x.CreateUserInfo) .Includes(x => x.UpdateUserInfo).ToList(); count = counts; return data.Select(m => new RoadwayDto() { Id = m.Id, RoadwayNo = m.RoadwayNo, RoadwayName = m.RoadwayName, WareHouseNo = m.WareHouseNo, WareHouseName = m.WareHouseInfo == null ? "" : m.WareHouseInfo.WareHouseName, AreaNo = m.AreaNo, Priority = m.Priority, Status = m.Status, Type = m.Type, TypeName = GetType(m.Type), TemperatureName = m.TemperatureInfo == null ? "" : m.TemperatureInfo.DictName, CreateTime = m.CreateTime, CreateUserName = m.CreateUserInfo == null ? "" : m.CreateUserInfo.RealName, UpdateTime = m.UpdateTime, UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.RealName }).ToList(); } catch (Exception e) { throw new Exception(e.Message); } } /// /// 查询单条巷道信息 /// /// /// public SysStorageRoadway GetStorageRoadway(int id) { try { var data = RoadwayRst.GetOneById(id); return data; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 获取巷道信息(根据仓库号) /// /// 仓库号 /// public List GetStorageRoadwayByHouseNo(string wareHouseNo) { try { var data = RoadwayRst.GetAllAsync().ToList(); if (!string.IsNullOrWhiteSpace(wareHouseNo)) { data = data.Where(m => m.WareHouseNo == wareHouseNo).ToList(); } return data; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 编辑巷道信息 /// /// /// /// /// /// /// /// /// /// /// /// public bool EditStorageRoadway(int id, string roadwayName, int priority, string type, string temp, int userId) { try { var roadway = RoadwayRst.GetOneById(id); if (roadway == null) { throw new Exception("为查询到当前巷道信息"); } //判断除当前id信息以外是否含有编号和名称 var bol = RoadwayRst.GetAllAsync().Any(m => m.Id != id && m.RoadwayNo== roadway.RoadwayNo && m.RoadwayName == roadwayName.Trim()); if (bol) { throw new Exception("当前巷道号或巷道名称已存在"); } roadway.RoadwayName = roadwayName; roadway.Priority = priority; roadway.Type = type; roadway.Temperature = temp; roadway.UpdateUser = userId; roadway.UpdateTime = DateTime.Now; var num = RoadwayRst.Edit(roadway); if (num > 0) { return true; } else { return false; } } catch (Exception e) { throw new Exception(e.Message); } } /// /// 编辑巷道状态 /// /// /// 状态 /// 操作人 /// public bool EditStorageRoadwayStatus(int id, string status, int userId) { try { var area = RoadwayRst.GetOneById(id); if (area == null) { throw new Exception("为查询到当前区域信息"); } area.Status = status; area.UpdateUser = userId; area.UpdateTime = DateTime.Now; var num = RoadwayRst.EditStorageRoadwayStatus(area); if (num > 0) { return true; } else { return false; } } catch (Exception e) { throw new Exception(e.Message); } } /// /// 查询巷道类别 /// /// /// public string GetType(string code) { if (string.IsNullOrWhiteSpace(code)) { return ""; } else { var str = ""; switch (code) { case "1": str = "成品区"; break; case "2": str = "原料区"; break; case "3": str = "包材区"; break; case "4": str = "空托区"; break; case "5": str = "耗材区"; break; } return str; } } } }