using CompressorXN_Log;
using CompressorXN_Model;
using SqlSugar;
using System;
using System.Collections.Generic;
namespace CompressorXN_Service
{
public class ParaService : DbContext
{
///
/// 根据机型名称查询测试项
///
///
///
public ISugarQueryable QueryParaByProductTypeName(string productTypeName)
{
try
{
return db.Queryable().Where(m => m.ProductTypeName == productTypeName);
}
catch (Exception ex)
{
LogHelper.Error(ex, "执行ParaService下QueryParaByProductTypeName时异常");
return null;
}
}
///
/// 根据机型名称校验该机型是否存在测试项
///
///
/// true:存在 false:不存在
public bool CheckIsExistParaByProductTypeName(string productTypeName)
{
try
{
return db.Queryable().Where(m => m.ProductTypeName == productTypeName).Count() > 0;
}
catch (Exception ex)
{
LogHelper.Error(ex, "执行ParaService下CheckIsExistParaByProductTypeName时异常");
return false;
}
}
///
/// 复制参数项
///
///
///
///
public bool CopyPara(string sourceProductTypeName, string targetProductTypeName)
{
try
{
db.Ado.BeginTran();
List paraList = db.Queryable().Where(m => m.ProductTypeName == sourceProductTypeName).ToList();
paraList.ForEach(m => { m.Id = Guid.NewGuid().ToString(); m.ProductTypeName = targetProductTypeName; });
db.Insertable(paraList).ExecuteCommand();
db.Ado.CommitTran();
return true;
}
catch (Exception ex)
{
db.Ado.RollbackTran();
LogHelper.Error(ex, "执行ParaService下CopyPara时异常");
return false;
}
}
///
/// 批量保存参数项
///
///
///
///
public bool SavePara(List t_ParaList, string productTypeName)
{
try
{
db.Ado.BeginTran();
db.Deleteable().Where(m => m.ProductTypeName == productTypeName).ExecuteCommand();
db.Insertable(t_ParaList).ExecuteCommand();
db.Ado.CommitTran();
return true;
}
catch (Exception ex)
{
db.Ado.RollbackTran();
LogHelper.Error(ex, "执行ParaService中SavePara异常");
return false;
}
}
}
}