using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Model.ModelDto.SysDto;
using SqlSugar;
using WMS.Entity.SysEntity;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
namespace WMS.BLL.SysServer
{
public class MaterialsServer : IMaterialsServer
{
///
/// 依赖注入
///
public IMaterialsRepository _mate { get; set; }
private readonly IMapper _mapper;
///
/// 构造函数
///
/// 物料编码
/// automapper
public MaterialsServer(IMaterialsRepository mate, IMapper mapper)
{
_mate = mate; //物料编码
_mapper = mapper; //automapper
}
#region wms
//public List GetMaterialsList(string skuNo, string skuName, string type, string isInspect, int page, int limit, out int count)
//{
// try
// {
// Expression> item = Expressionable.Create()
// .AndIF(!string.IsNullOrWhiteSpace(skuNo), it => it.SkuNo.Contains(skuNo.Trim()))
// .AndIF(!string.IsNullOrWhiteSpace(skuName), it => it.SkuName.Contains(skuName.Trim()))
// .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
// .AndIF(!string.IsNullOrWhiteSpace(isInspect), it => it.IsInspect == isInspect)
// .ToExpression();//注意 这一句 不能少
// var data = _mate.GetAllByOrderPageAsync(item, limit, page, out int counts)
// .Includes(x => x.TypeInfo)
// .Includes(x => x.EnvironmentInfo)
// .Includes(x => x.UnitInfo)
// .Includes(x => x.PackagInfo)
// .Includes(x => x.CreateUserInfo)
// .Includes(x => x.UpdateUserInfo)
// .ToList();
// count = counts;
// return data.Select(m => new MaterialsDto()
// {
// Id = m.Id,
// SkuNo = m.SkuNo,
// SkuName = m.SkuName,
// Standard = m.Standard,
// AuditStatusNo = m.AuditStatusNo,
// Type = m.Type,
// TypeName = m.TypeInfo == null ? "" : m.TypeInfo.DictName,
// IsControlled = m.IsControlled,
// IsInspect = m.IsInspect,
// Origin = m.Origin,
// UnitNo = m.UnitNo,
// UnitName = m.UnitInfo == null ? "" : m.UnitInfo.UnitName,
// PackagNo = m.PackagNo,
// PackagName = m.PackagInfo == null ? "" : m.PackagInfo.PackagName,
// Environment = m.Environment,
// EnvironmentName = m.EnvironmentInfo == null ? "" : m.EnvironmentInfo.DictName,
// Weight = m.Weight,
// Warranty = m.Warranty,
// Price = m.Price,
// Demo = m.Demo,
// CreateUserName = m.CreateUserInfo == null ? "" : m.CreateUserInfo.UserName,
// UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.UserName,
// CreateTime = m.CreateTime,
// UpdateTime = m.UpdateTime
// }).ToList();
// }
// catch (Exception e)
// {
// throw new Exception(e.Message);
// }
//}
///
/// 获取物料信息列表
///
/// 物料编码
/// 物料名称
/// 审核状态
/// 类型
/// 是否受控
/// 是否免检
/// 存储环境
///
public List GetMateList(string skuNo, string skuName, string auditStatusNo, string type, string isControlled, string isInspect, string environment)
{
List matedto = _mate.GetMateList(skuNo, skuName, auditStatusNo, type, isControlled, isInspect, environment);
return matedto;
}
///
/// 根据id查询物料信息
///
/// 物料id
///
public SysMaterials GetMateById(int id)
{
SysMaterials mate = _mate.GetMateById(id);
return mate;
}
///
/// 根据编号查询物料信息
///
/// 物料编号
///
public int GetMateByNo(string SkuNo)
{
List mate = _mate.GetMateByNo(SkuNo);
return mate.Count;
}
///
/// 新增物料信息
///
/// 物料dto
///
/// 捕获异常
public async Task AddMate(MaterialsDto matedto)
{
//捕获异常
try
{
//映射模型
SysMaterials mate = _mapper.Map(matedto);
//判断物料号是否唯一
int count = GetMateByNo(mate.SkuNo);
int i = 0;
if (matedto.AdventTime > 365 && matedto.AdventTime < 30)
{
return 2;
}
//else if (matedto.LowInventory > 1000)
//{
// return 4;
//}
else
{
if (count > 0)
{
i = 3;
}
else if (count == 0)
{
//新增
i = await _mate.AddMate(mate);
}
return i;
}
}
catch (Exception ex)
{
//抛出异常
throw new Exception("新增物料异常", ex);
}
}
///
/// 删除物料信息
///
/// 物料实体模型
///
/// 捕获异常
public async Task DelMate(SysMaterials mate)
{
//捕获异常
try
{
//删除
int i = await _mate.DelMate(mate);
return i;
}
catch (Exception ex)
{
//抛出异常
throw new Exception("删除物料异常", ex);
}
}
///
/// 编辑物料信息
///
/// 物料dto
///
/// 捕获异常
public async Task ExitMate(MaterialsDto matedto)
{
//捕获异常
try
{
if (matedto.AdventTime > 365 && matedto.AdventTime < 30)
{
return 2;
}
//else if (matedto.LowInventory > 1000)
//{
// return 4;
//}
else
{
//映射模型
SysMaterials mate = _mapper.Map(matedto);
//编辑
int i = await _mate.ExitMate(mate);
return i;
}
}
catch (Exception ex)
{
//抛出异常
throw new Exception("编辑物料异常", ex);
}
}
#region 包装 单位
///
/// 获取计量单位信息列表
///
///
public List GetUnitList()
{
List unitlist = _mate.GetUnitList();
return unitlist;
}
///
/// 获取包装信息列表
///
///
public List GetPackagList()
{
List packlist = _mate.GetPackagList();
return packlist;
}
#endregion
#endregion
#region erp
///
/// 获取erp数据
///
///
public List GetERPList()
{
List list = _mate.GetERPList();
return list;
}
///
/// 根据id获取erp数据
///
/// id
///
public SysERPTest GetERPListById(int id)
{
SysERPTest erp = _mate.GetERPListById(id);
return erp;
}
///
/// 新增erp数据
///
/// erp测试dto
///
/// 捕获异常
public async Task AddERP(ERPTestDto erpdto)
{
//捕获异常
try
{
//模型映射
SysERPTest erp = _mapper.Map(erpdto);
//判断是否唯一
//新增
int i = await _mate.AddERP(erp);
return i;
}
catch (Exception ex)
{
//抛出异常
throw new Exception("新增erp数据异常", ex);
}
}
///
/// 删除erp信息
///
/// erp测试实体
///
/// 捕获异常
public async Task DelERP(SysERPTest erp)
{
//捕获异常
try
{
//删除
int i = await _mate.DelERP(erp);
return i;
}
catch (Exception ex)
{
//抛出异常
throw new Exception("删除erp异常", ex);
}
}
///
/// 编辑erp数据
///
/// erp测试dto
///
/// 捕获异常
public async Task EditERP(ERPTestDto erpdto)
{
//捕获异常
try
{
//模型映射
SysERPTest erp = _mapper.Map(erpdto);
//编辑
int i = await _mate.EditERP(erp);
return i;
}
catch (Exception ex)
{
//抛出异常
throw new Exception("编辑erp数据异常", ex);
}
}
#endregion
}
}