using ProductionSystem_Log;
using ProductionSystem_Model.DbModel;
using ProductionSystem_Model.DbModel.System;
using ProductionSystem_Model.ViewModel.Request;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProductionSystem_Service
{
public class TResult2Service : DbContext
{
///
/// 新增
///
///
///
public int AddTResult2(T_Result2 t_Result2)
{
try
{
return db.Insertable(t_Result2).ExecuteCommand();
}catch (Exception ex)
{
LogHelper.Error(ex, "执行TResult2Service下AddTResult2时异常");
return -1;
}
}
/////
///// 根据产品类型和产品条码查询
/////
/////
/////
/////
//public T_Result2 QueryLatestStep(string productType,string productBarcode,string step)
//{
// return db.Queryable().Where(m => m.ProductType == productType && m.ProductBarcode.Contains(productBarcode)
// && m.Step == step && m.Electricity != "0" && m.Electricity != "0,000").OrderByDescending(m => m.CreateTime).First();
//}
///
/// 分页查询
///
///
///
public TestResut2Res Query(TestResut2Vm vm)
{
int totalRecord = 0;
var iq= db.Queryable().
WhereIF(!string.IsNullOrEmpty(vm.ProductType), x => x.ProductType == vm.ProductType)
.WhereIF(!string.IsNullOrEmpty(vm.ProductCode),x=>x.ProductBarcode == vm.ProductCode)
.WhereIF(!string.IsNullOrEmpty(vm.BeginTime),x=>x.CreateTime>=Convert.ToDateTime(vm.BeginTime))
.WhereIF(!string.IsNullOrEmpty(vm.EndTime),xy=> xy.CreateTime <= Convert.ToDateTime(vm.EndTime))
.ToPageList(vm.PageIndex,vm.PageSize, ref totalRecord);
foreach (var item in iq)
{
var stepDic = db.Queryable().Where(z => z.DicCode == item.Step).First();
if (stepDic != null)
{
item.Step = stepDic.DicName;
}
}
int totalPage = (totalRecord + vm.PageSize - 1) / vm.PageSize;
TestResut2Res testResut2Res = new TestResut2Res();
testResut2Res.Total= totalPage;
testResut2Res.Data = iq;
testResut2Res.Next = totalPage > vm.PageIndex;
return testResut2Res;
}
///
/// 列表
///
///
///
public List Query2(TestResut2Vm vm)
{
int totalRecord = 0;
var iq = db.Queryable().
WhereIF(!string.IsNullOrEmpty(vm.ProductType), x => x.ProductType == vm.ProductType)
.WhereIF(!string.IsNullOrEmpty(vm.ProductCode), x => x.ProductBarcode == vm.ProductCode)
.WhereIF(!string.IsNullOrEmpty(vm.BeginTime), x => x.CreateTime >= Convert.ToDateTime(vm.BeginTime))
.WhereIF(!string.IsNullOrEmpty(vm.EndTime), xy => xy.CreateTime <= Convert.ToDateTime(vm.EndTime))
.ToList();
foreach (var item in iq)
{
var stepDic = db.Queryable().Where(z => z.DicCode == item.Step).First();
if (stepDic != null)
{
item.Step = stepDic.DicName;
}
}
return iq;
}
}
public class TestResut2Res
{
public int Total { get; set; }
public bool Next { get; set; }
public List Data
{ get; set; }
}
}