You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ProductionSystem/ProductionSystem_Service/TCurveService.cs

96 lines
3.5 KiB
C#

using ProductionSystem_Log;
using ProductionSystem_Model.DbModel;
using ProductionSystem_Model.ViewModel.Request;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProductionSystem_Service
{
public class TCurveService : DbContext
{
/// <summary>
/// 新增
/// </summary>
/// <param name="t_curve"></param>
/// <returns></returns>
public int AddTResult2(T_Curve t_curve)
{
try
{
return db.Insertable(t_curve).ExecuteCommand();
}
catch (Exception ex)
{
LogHelper.Error(ex, "执行TResult2Service下AddTResult2时异常");
return -1;
}
}
/// <summary>
/// 根据产品类型和产品条码查询
/// </summary>
/// <param name="productType"></param>
/// <param name="productBarcode"></param>
/// <returns></returns>
public T_Curve QueryLatestStep(string productType, string productBarcode, string step)
{
return db.Queryable<T_Curve>().Where(m => m.ProductType == productType && m.ProductBarcode.Contains(productBarcode)
&& m.Step == step && m.Electricity != "0" && m.Electricity != "0,000").OrderByDescending(m => m.CreateTime).First();
}
/// <summary>
/// 分页查询
/// </summary>
/// <param name="vm"></param>
/// <returns></returns>
public TestCurveRes Query(TestCurveVm vm)
{
int totalRecord = 0;
var iq = db.Queryable<T_Curve>().
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))
.OrderByDescending(x => x.CreateTime)
.ToPageList(vm.PageIndex, vm.PageSize, ref totalRecord);
int totalPage = (totalRecord + vm.PageSize - 1) / vm.PageSize;
TestCurveRes testCurveRes = new TestCurveRes();
testCurveRes.Total = totalPage;
testCurveRes.Data = iq;
testCurveRes.Next = totalPage > vm.PageIndex;
return testCurveRes;
}
/// <summary>
/// 列表
/// </summary>
/// <param name="vm"></param>
/// <returns></returns>
public List<T_Curve> Query2(TestCurveVm vm)
{
int totalRecord = 0;
var iq = db.Queryable<T_Curve>().
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))
.OrderByDescending(x => x.CreateTime)
.ToList();
return iq;
}
}
public class TestCurveRes
{
public int Total { get; set; }
public bool Next { get; set; }
public List<T_Curve> Data
{ get; set; }
}
}