using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Model.ModelDto.SysDto;
using SqlSugar;
using WMS.DAL;
using WMS.Entity.SysEntity;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
namespace WMS.BLL.SysServer
{
public class ExceptionServer : IExceptionServer
{
public IExceptionRepository ExceptionRst { get; set; }
private readonly IMapper _mapper;
public ExceptionServer(IExceptionRepository exceptionRst, IMapper mapper)
{
ExceptionRst = exceptionRst;
_mapper = mapper;
}
///
/// 查询异常处理表信息
///
/// 托盘号
/// 储位号
/// 单据号 入库单 出库单 移库单
/// 任务号
/// 状态 0:未处理 1:已处理
/// 处理描述
/// 异常类型 0:空取 1:满入 2:双工位异常
///
///
///
public async Task> GetExceptionList(string palletNo, string excLocatNo, string orderNo,
string taskNo, string status, string text, string type, int page = 0, int limit = 10)
{
try
{
Expression> item = Expressionable.Create()
.AndIF(!string.IsNullOrWhiteSpace(palletNo), it => it.PalletNo.Contains(palletNo.Trim()))
.AndIF(!string.IsNullOrWhiteSpace(excLocatNo), it => it.ExcLocatNo.Contains(excLocatNo.Trim()))
.AndIF(!string.IsNullOrWhiteSpace(orderNo), it => it.OrderNo.Contains(orderNo.Trim()))
.AndIF(!string.IsNullOrWhiteSpace(taskNo), it => it.TaskNo.Contains(taskNo.Trim()))
.AndIF(!string.IsNullOrWhiteSpace(text), it => it.Text.Contains(text.Trim()))
.AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == type)
.AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
.ToExpression();//注意 这一句 不能少
var data = await ExceptionRst.GetAllByOrderPageAsync(item, limit, page, out int counts).ToListAsync();
return data;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
///
/// 添加异常处理信息
///
/// 异常类型 0:空取 1:满入 2:双工位异常
/// 托盘号
/// 储位号
/// 单据号 入库单 出库单 移库单
/// 任务号
/// 处理描述
/// 操作人
///
public async Task AddException(string type, string palletNo, string excLocatNo, string orderNo, string taskNo, string text, int userId)
{
try
{
var exNo = new Common().GetMaxNo("EX");
var num = await ExceptionRst.AddAsync(new SysException()
{
Type = type,
ExceptionNo = exNo,
PalletNo = palletNo,
ExcLocatNo = excLocatNo,
OrderNo = orderNo,
TaskNo = taskNo,
Text = text,
CreateUser = userId
});
if (num > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
///
/// 获取异常处理信息列表
///
/// 异常号
/// 托盘号
/// 异常储位
/// 关联单号
/// 关联任务号
/// 异常类型
/// 状态
///
public List GetTableList(string exceptionNo, string palletNo, string excLocatNo, string orderNo, string taskNo, string type, string status)
{
List tablelist = ExceptionRst.GetExceptionList(exceptionNo, palletNo, excLocatNo, orderNo, taskNo, type, status);
return tablelist;
}
///
/// 根据id获取异常信息
///
/// 异常id
///
public SysException GetTableById(int id)
{
SysException table = ExceptionRst.GetExceptionById(id);
return table;
}
///
/// 新增异常处理
///
/// 异常类型
/// 托盘号
/// 异常储位
/// 关联单号
/// 关联任务号
/// 备注
/// 创建人
///
/// 捕获异常
public async Task InsertTableName(string type, string palletNo, string excLocatNo, string orderNo, string taskNo, string demo, int uid)
{
//捕获异常
try
{
//获取最大异常号
string ExceptionNo = ExceptionRst.GetMaxExceptionNo().ExceptionNo;
//判断获取到的异常号是否为空
if (!string.IsNullOrEmpty(ExceptionNo))
{
ExceptionNo = "1000";
}
else
{
ExceptionNo = (int.Parse(ExceptionNo) + 1).ToString();
}
int i = await ExceptionRst.InsertException(ExceptionNo, type, palletNo, excLocatNo, orderNo, taskNo, demo, uid);
return i;
}
catch (Exception ex)
{
//抛出异常
throw new Exception("新增异常处理", ex);
}
}
///
/// 处理异常状态
///
/// 异常处理dto
///
/// 捕获异常
public async Task EditStatus(ExceptionDto tabledto)
{
//捕获异常
try
{
SysException table = _mapper.Map(tabledto);
int i = await ExceptionRst.EditStatus(table);
return i;
}
catch (Exception ex)
{
//抛出异常
throw new Exception("处理状态异常", ex);
}
}
}
}