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
|
{
|
/// <summary>
|
/// SN操作
|
/// </summary>
|
public partial class MqSNData : IMqSNData
|
{
|
/// <summary>
|
/// 退回删除条码
|
/// </summary>
|
/// <param name="barcode"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> ReturnSN(string barcode)
|
{
|
var result = new ApiAction();
|
try
|
{
|
SNData_His data_His = await Biz.Db.Queryable<SNData_His>().Where(x => x.OriginalSN == barcode).FirstAsync();
|
if (data_His == null)
|
{
|
result.IsSuccessed = false;
|
result.Message = $"退回删除条码不存在";
|
return result;
|
}
|
List<SNData> sndatas = await Biz.Db.Queryable<SNData>().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;
|
}
|
|
/// <summary>
|
/// 整单退回
|
/// </summary>
|
/// <param name="deliveryNo"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> ReturnWhole(string deliveryNo)
|
{
|
var result = new ApiAction();
|
try
|
{
|
List<SNData_His> listHis = await Biz.Db.Queryable<SNData_His>().Where(x => x.DeliveryNo == deliveryNo).ToListAsync();
|
if (listHis.Count == 0)
|
{
|
result.IsSuccessed = false;
|
result.Message = $"退回送货单[{deliveryNo}]查不到要删除的条码";
|
return result;
|
}
|
List<SNData> sndatas = await Biz.Db.Queryable<SNData>().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;
|
}
|
|
/// <summary>
|
/// 分页
|
/// </summary>
|
/// <param name="pageList"></param>
|
/// <returns></returns>
|
public async Task<ApiAction<PageAble<SNData_His>>> GetSNDataHis(PageAble<SNData_His> pageList)
|
{
|
var res = new ApiAction<PageAble<SNData_His>>();
|
try
|
{
|
string[] strTime = pageList.sqlcmd?.Split(',');
|
RefAsync<int> total = 0;
|
pageList.data = await Biz.Db.Queryable<SNData_His>()
|
.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;
|
}
|
|
/// <summary>
|
/// 获取所有条码,原厂条码和客户条码在同一行,按条件
|
/// </summary>
|
/// <param name="where"></param>
|
/// <returns></returns>
|
public async Task<ApiAction<List<SNData_His>>> GetAllSNDataHis(SNDataWhere where)
|
{
|
var res = new ApiAction<List<SNData_His>>();
|
List<SNData_His> list = new List<SNData_His>();
|
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<int> total = 0;
|
list = await Biz.Db.Queryable<SNData_His>()
|
.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;
|
}
|
|
/// <summary>
|
/// 获取所有条码,原厂条码和客户条码分开两行,按条件
|
/// </summary>
|
/// <param name="where"></param>
|
/// <returns></returns>
|
public async Task<ApiAction<List<SNData>>> GetAllSNData(SNDataWhere where)
|
{
|
var res = new ApiAction<List<SNData>>();
|
List<SNData> list = new List<SNData>();
|
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<int> total = 0;
|
list = await Biz.Db.Queryable<SNData>()
|
.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;
|
}
|
}
|
}
|