using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Cryptography.X509Certificates;
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 WareHouseServer:IWareHouseServer
{
public IWareHouseRepository WareHouseRst { get; set; }
public WareHouseServer(IWareHouseRepository wareHouseRst)
{
WareHouseRst = wareHouseRst;
}
///
/// 获取仓库信息
///
/// 仓库号
/// 仓库名称
/// 类型
///
///
///
///
public List GetWarehouseList(string wareHouseNo, string wareHouseName, string type, int page, int limit,out int count)
{
try
{
Expression> item = Expressionable.Create() //创建表达式
.AndIF(!string.IsNullOrWhiteSpace(wareHouseNo), it => it.WareHouseNo.Contains(wareHouseNo.Trim()))
.AndIF(!string.IsNullOrWhiteSpace(wareHouseName), it => it.WareHouseName.Contains(wareHouseName.Trim()))
.AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
.ToExpression();//注意 这一句 不能少
var data = WareHouseRst.GetAllByOrderPageAsync(item, limit, page,out int counts)
.Includes(x => x.TypeInfo)
.Includes(x => x.TemperatureInfo)
.Includes(x => x.CreateUserInfo)
.Includes(x => x.UpdateUserInfo).ToList();
count = counts;
return data.Select(m => new WareHouseDto()
{
Id = m.Id,
WareHouseNo = m.WareHouseNo,
WareHouseName = m.WareHouseName,
Type = m.TypeInfo == null ? "" : m.TypeInfo.DictName,
Temperature = m.TemperatureInfo == null ? "" : m.TemperatureInfo.DictName,
Row = m.Row,
Column = m.Column,
Layer = m.Layer,
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);
}
}
///
/// 获取单条仓库信息
///
/// ID
///
public async Task GetWarehouse(int id)
{
try
{
var data = await WareHouseRst.GetOneByIdAsync(id);
return data;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
///
/// 修改仓库信息
///
/// ID
/// 仓库编号
/// 仓库名称
/// 类型
/// 存储环境
/// 排
/// 列
/// 层
/// 操作人
/// 是否成功
public async Task EditWareHouse(int id,string no, string name, string type, string temp, int? row, int? col, int? layer, int userId)
{
try
{
//判断除当前id信息以外是否含有编号和名称
var bol = await WareHouseRst.GetAllAsync()
.AnyAsync(m => m.Id != id && (m.WareHouseNo == no.Trim() || m.WareHouseName == name.Trim()));
if (bol)
{
throw new Exception("当前仓库号或仓库名称已存在");
}
var wareHouse = await WareHouseRst.GetOneByIdAsync(id);
if (wareHouse == null)
{
throw new Exception("为查询到当前仓库信息");
}
var num = await WareHouseRst.EditAsync(new SysWareHouse()
{
Id = id,
WareHouseNo = no,
WareHouseName = name,
Type = type,
Temperature = temp,
Row = row,
Column = col,
Layer = layer,
UpdateUser = userId,
UpdateTime = DateTime.Now
});
if (num > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
public async Task> GetWareHouseDic()
{
try
{
var list = await WareHouseRst.GetAllAsync().ToListAsync();
return list;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
}
}