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;
|
}
|
|
/// <summary>
|
/// 获取仓库信息
|
/// </summary>
|
/// <param name="wareHouseNo">仓库号</param>
|
/// <param name="wareHouseName">仓库名称</param>
|
/// <param name="type">类型</param>
|
/// <param name="page"></param>
|
/// <param name="limit"></param>
|
/// <param name="count"></param>
|
/// <returns></returns>
|
public List<WareHouseDto> GetWarehouseList(string wareHouseNo, string wareHouseName, string type, int page, int limit,out int count)
|
{
|
try
|
{
|
Expression<Func<SysWareHouse, bool>> item = Expressionable.Create<SysWareHouse>() //创建表达式
|
.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);
|
}
|
|
}
|
|
/// <summary>
|
/// 获取单条仓库信息
|
/// </summary>
|
/// <param name="id">ID</param>
|
/// <returns></returns>
|
public async Task<SysWareHouse> GetWarehouse(int id)
|
{
|
try
|
{
|
var data = await WareHouseRst.GetOneByIdAsync(id);
|
return data;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 修改仓库信息
|
/// </summary>
|
/// <param name="id">ID</param>
|
/// <param name="no">仓库编号</param>
|
/// <param name="name">仓库名称</param>
|
/// <param name="type">类型</param>
|
/// <param name="temp">存储环境</param>
|
/// <param name="row">排</param>
|
/// <param name="col">列</param>
|
/// <param name="layer">层</param>
|
/// <param name="userId">操作人</param>
|
/// <returns>是否成功</returns>
|
public async Task<bool> 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<List<SysWareHouse>> GetWareHouseDic()
|
{
|
try
|
{
|
var list = await WareHouseRst.GetAllAsync().ToListAsync();
|
return list;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
}
|
}
|