using Rhea.Common;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tiger.IBusiness;
using Tiger.Model;
namespace Tiger.Business.MengQi
{
///
/// SN操作
///
public partial class MqSNData : IMqSNData
{
///
/// 退回删除条码
///
///
///
public async Task ReturnSN(string barcode)
{
var result = new ApiAction();
try
{
SNData_His data_His = await Biz.Db.Queryable().Where(x => x.OriginalSN == barcode).FirstAsync();
if (data_His == null)
{
result.IsSuccessed = false;
result.Message = $"退回删除条码不存在";
return result;
}
List sndatas = await Biz.Db.Queryable().Where(x => x.SN == barcode || x.SN == data_His.SN).ToListAsync();
if (sndatas == null && sndatas.Count > 0)
{
result.IsSuccessed = false;
result.Message = $"退回删除条码不存在";
return result;
}
result.Data = data_His.DeliveryNo;
var db = Biz.Db;
var dbTran = db.UseTran(() =>
{
db.Deleteable(data_His).ExecuteCommand();
db.Deleteable(sndatas).ExecuteCommand();
});
if (!dbTran.IsSuccess)
{
result.IsSuccessed = false;
result.Message = $"退回删除条码异常";
}
}
catch (Exception ex)
{
result.CatchExceptionWithLog(ex, "退回删除条码异常");
}
return result;
}
///
/// 整单退回
///
///
///
public async Task ReturnWhole(string deliveryNo)
{
var result = new ApiAction();
try
{
List listHis = await Biz.Db.Queryable().Where(x => x.DeliveryNo == deliveryNo).ToListAsync();
if (listHis.Count == 0)
{
result.IsSuccessed = false;
result.Message = $"退回送货单[{deliveryNo}]查不到要删除的条码";
return result;
}
List sndatas = await Biz.Db.Queryable().Where(x => x.DeliveryNo == deliveryNo).ToListAsync();
if (sndatas.Count == 0)
{
result.IsSuccessed = false;
result.Message = $"退回送货单[{deliveryNo}]查不到要删除的条码";
return result;
}
var db = Biz.Db;
var dbTran = db.UseTran(() =>
{
db.Deleteable(listHis).ExecuteCommand();
db.Deleteable(sndatas).ExecuteCommand();
});
if (!dbTran.IsSuccess)
{
result.IsSuccessed = false;
result.Message = $"退回删除条码异常";
}
}
catch (Exception ex)
{
result.CatchExceptionWithLog(ex, "退回删除条码异常");
}
return result;
}
///
/// 分页
///
///
///
public async Task>> GetSNDataHis(PageAble pageList)
{
var res = new ApiAction>();
try
{
string[] strTime = pageList.sqlcmd?.Split(',');
RefAsync total = 0;
pageList.data = await Biz.Db.Queryable()
.WhereIF(!string.IsNullOrEmpty(strTime[0]), x => Convert.ToDateTime(x.ScanTime) > Convert.ToDateTime(strTime[0]))
.WhereIF(!string.IsNullOrEmpty(strTime[1]) && strTime.Length == 2, x => Convert.ToDateTime(x.ScanTime) < Convert.ToDateTime(strTime[1]))
.WhereIF(!string.IsNullOrEmpty(strTime[2]), x => x.ModelCode.Equals(strTime[2]))
.WhereIF(!string.IsNullOrEmpty(strTime[3]), x => x.CustomerCode.Equals(strTime[3]))
.WhereIF(!string.IsNullOrEmpty(strTime[4]), x => x.DeliveryNo.Equals(strTime[4]))
.WhereIF(!string.IsNullOrEmpty(strTime[5]), x => x.CustModel.Equals(strTime[5]))
.ToPageListAsync(pageList.pageIndex, pageList.pageSize, total);
pageList.totals = total;
}
catch (Exception ex)
{
res.CatchExceptionWithLog(ex, "查询异常");
}
res.Data = pageList;
return res;
}
///
/// 获取所有条码,原厂条码和客户条码在同一行,按条件
///
///
///
public async Task>> GetAllSNDataHis(SNDataWhere where)
{
var res = new ApiAction>();
List list = new List();
try
{
DateTime StartTime = DateTime.Now;
DateTime EndTime = DateTime.Now;
string[] strTime = where.strStartEnd?.Split(',');
if (!string.IsNullOrEmpty(where.strStartEnd)) { StartTime = Convert.ToDateTime(strTime[0].ToString()); EndTime = strTime.Length == 2 ? Convert.ToDateTime(strTime[1].ToString()) : DateTime.MinValue; }
RefAsync total = 0;
list = await Biz.Db.Queryable()
.WhereIF(!string.IsNullOrEmpty(where.strStartEnd), x => Convert.ToDateTime(x.ScanTime) > StartTime)
.WhereIF(!string.IsNullOrEmpty(where.strStartEnd) && strTime.Length == 2, x => Convert.ToDateTime(x.ScanTime) < EndTime)
.WhereIF(!string.IsNullOrEmpty(where.model), x => x.ModelCode == where.model)
.WhereIF(!string.IsNullOrEmpty(where.customerCode), x => x.CustomerCode.Equals(where.customerCode))
.WhereIF(!string.IsNullOrEmpty(where.deliveryNo), x => x.DeliveryNo.Equals(where.deliveryNo))
.WhereIF(!string.IsNullOrEmpty(where.custParam1), x => x.CustModel.Equals(where.custParam1))
.ToListAsync();
}
catch (Exception ex)
{
res.CatchExceptionWithLog(ex, "查询异常");
}
res.Data = list;
return res;
}
///
/// 获取所有条码,原厂条码和客户条码分开两行,按条件
///
///
///
public async Task>> GetAllSNData(SNDataWhere where)
{
var res = new ApiAction>();
List list = new List();
try
{
DateTime StartTime = DateTime.Now;
DateTime EndTime = DateTime.Now;
string[] strTime = where.strStartEnd?.Split(',');
if (!string.IsNullOrEmpty(where.strStartEnd)) { StartTime = Convert.ToDateTime(strTime[0].ToString()); EndTime = strTime.Length == 2 ? Convert.ToDateTime(strTime[1].ToString()) : DateTime.MinValue; }
RefAsync total = 0;
list = await Biz.Db.Queryable()
.WhereIF(!string.IsNullOrEmpty(where.strStartEnd), x => Convert.ToDateTime(x.CREATE_TIME) > StartTime)
.WhereIF(!string.IsNullOrEmpty(where.strStartEnd) && strTime.Length == 2, x => Convert.ToDateTime(x.CREATE_TIME) < EndTime)
.WhereIF(!string.IsNullOrEmpty(where.model), x => x.ItemCode == where.model)
.WhereIF(!string.IsNullOrEmpty(where.customerCode), x => x.CustomerCode.Equals(where.customerCode))
.WhereIF(!string.IsNullOrEmpty(where.deliveryNo), x => x.DeliveryNo.Equals(where.deliveryNo))
.WhereIF(!string.IsNullOrEmpty(where.custParam1), x => x.CustModel.Equals(where.custParam1))
.OrderBy(x => x.CREATE_TIME).OrderBy(x => x.Scanner).ToListAsync();
}
catch (Exception ex)
{
res.CatchExceptionWithLog(ex, "查询异常");
}
res.Data = list;
return res;
}
}
}