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
|
{
|
/// <summary>
|
/// 依赖注入
|
/// </summary>
|
public IMaterialsRepository _mate { get; set; }
|
private readonly IMapper _mapper;
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="mate">物料编码</param>
|
/// <param name="mapper">automapper</param>
|
public MaterialsServer(IMaterialsRepository mate, IMapper mapper)
|
{
|
_mate = mate; //物料编码
|
_mapper = mapper; //automapper
|
}
|
|
#region wms
|
|
//public List<MaterialsDto> GetMaterialsList(string skuNo, string skuName, string type, string isInspect, int page, int limit, out int count)
|
//{
|
// try
|
// {
|
// Expression<Func<SysMaterials, bool>> item = Expressionable.Create<SysMaterials>()
|
// .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);
|
// }
|
//}
|
|
|
/// <summary>
|
/// 获取物料信息列表
|
/// </summary>
|
/// <param name="skuNo">物料编码</param>
|
/// <param name="skuName">物料名称</param>
|
/// <param name="auditStatusNo">审核状态</param>
|
/// <param name="type">类型</param>
|
/// <param name="isControlled">是否受控</param>
|
/// <param name="isInspect">是否免检</param>
|
/// <param name="environment">存储环境</param>
|
/// <returns></returns>
|
public List<MaterialsDto> GetMateList(string skuNo, string skuName, string auditStatusNo, string type, string isControlled, string isInspect, string environment)
|
{
|
List<MaterialsDto> matedto = _mate.GetMateList(skuNo, skuName, auditStatusNo, type, isControlled, isInspect, environment);
|
return matedto;
|
}
|
|
/// <summary>
|
/// 根据id查询物料信息
|
/// </summary>
|
/// <param name="id">物料id</param>
|
/// <returns></returns>
|
public SysMaterials GetMateById(int id)
|
{
|
SysMaterials mate = _mate.GetMateById(id);
|
return mate;
|
}
|
|
/// <summary>
|
/// 根据编号查询物料信息
|
/// </summary>
|
/// <param name="SkuNo">物料编号</param>
|
/// <returns></returns>
|
public int GetMateByNo(string SkuNo)
|
{
|
List<SysMaterials> mate = _mate.GetMateByNo(SkuNo);
|
return mate.Count;
|
}
|
|
/// <summary>
|
/// 新增物料信息
|
/// </summary>
|
/// <param name="matedto">物料dto</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> AddMate(MaterialsDto matedto)
|
{
|
//捕获异常
|
try
|
{
|
//映射模型
|
SysMaterials mate = _mapper.Map<SysMaterials>(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);
|
}
|
}
|
|
/// <summary>
|
/// 删除物料信息
|
/// </summary>
|
/// <param name="mate">物料实体模型</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> DelMate(SysMaterials mate)
|
{
|
//捕获异常
|
try
|
{
|
//删除
|
int i = await _mate.DelMate(mate);
|
return i;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("删除物料异常", ex);
|
}
|
}
|
|
/// <summary>
|
/// 编辑物料信息
|
/// </summary>
|
/// <param name="matedto">物料dto</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> 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<SysMaterials>(matedto);
|
//编辑
|
int i = await _mate.ExitMate(mate);
|
return i;
|
}
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("编辑物料异常", ex);
|
}
|
}
|
|
#region 包装 单位
|
|
/// <summary>
|
/// 获取计量单位信息列表
|
/// </summary>
|
/// <returns></returns>
|
public List<SysUnit> GetUnitList()
|
{
|
List<SysUnit> unitlist = _mate.GetUnitList();
|
return unitlist;
|
}
|
|
/// <summary>
|
/// 获取包装信息列表
|
/// </summary>
|
/// <returns></returns>
|
public List<SysPackag> GetPackagList()
|
{
|
List<SysPackag> packlist = _mate.GetPackagList();
|
return packlist;
|
}
|
|
#endregion
|
|
#endregion
|
|
#region erp
|
|
/// <summary>
|
/// 获取erp数据
|
/// </summary>
|
/// <returns></returns>
|
public List<ERPTestDto> GetERPList()
|
{
|
List<ERPTestDto> list = _mate.GetERPList();
|
return list;
|
}
|
|
/// <summary>
|
/// 根据id获取erp数据
|
/// </summary>
|
/// <param name="id">id</param>
|
/// <returns></returns>
|
public SysERPTest GetERPListById(int id)
|
{
|
SysERPTest erp = _mate.GetERPListById(id);
|
return erp;
|
}
|
|
/// <summary>
|
/// 新增erp数据
|
/// </summary>
|
/// <param name="erpdto">erp测试dto</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> AddERP(ERPTestDto erpdto)
|
{
|
//捕获异常
|
try
|
{
|
//模型映射
|
SysERPTest erp = _mapper.Map<SysERPTest>(erpdto);
|
//判断是否唯一
|
//新增
|
int i = await _mate.AddERP(erp);
|
return i;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("新增erp数据异常", ex);
|
}
|
}
|
|
/// <summary>
|
/// 删除erp信息
|
/// </summary>
|
/// <param name="erp">erp测试实体</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> DelERP(SysERPTest erp)
|
{
|
//捕获异常
|
try
|
{
|
//删除
|
int i = await _mate.DelERP(erp);
|
return i;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("删除erp异常", ex);
|
}
|
}
|
|
/// <summary>
|
/// 编辑erp数据
|
/// </summary>
|
/// <param name="erpdto">erp测试dto</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> EditERP(ERPTestDto erpdto)
|
{
|
//捕获异常
|
try
|
{
|
//模型映射
|
SysERPTest erp = _mapper.Map<SysERPTest>(erpdto);
|
//编辑
|
int i = await _mate.EditERP(erp);
|
return i;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("编辑erp数据异常", ex);
|
}
|
}
|
|
#endregion
|
|
}
|
}
|