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.

102 lines
3.2 KiB
C#

using CompressorXN_Log;
using CompressorXN_Model;
using SqlSugar;
using System;
using System.Collections.Generic;
namespace CompressorXN_Service
{
public class ParaService : DbContext
{
/// <summary>
/// 根据机型名称查询测试项
/// </summary>
/// <param name="productTypeName"></param>
/// <returns></returns>
public ISugarQueryable<T_Para> QueryParaByProductTypeName(string productTypeName)
{
try
{
return db.Queryable<T_Para>().Where(m => m.ProductTypeName == productTypeName);
}
catch (Exception ex)
{
LogHelper.Error(ex, "执行ParaService下QueryParaByProductTypeName时异常");
return null;
}
}
/// <summary>
/// 根据机型名称校验该机型是否存在测试项
/// </summary>
/// <param name="productTypeName"></param>
/// <returns>true存在 false不存在</returns>
public bool CheckIsExistParaByProductTypeName(string productTypeName)
{
try
{
return db.Queryable<T_Para>().Where(m => m.ProductTypeName == productTypeName).Count() > 0;
}
catch (Exception ex)
{
LogHelper.Error(ex, "执行ParaService下CheckIsExistParaByProductTypeName时异常");
return false;
}
}
/// <summary>
/// 复制参数项
/// </summary>
/// <param name="sourceProductTypeName"></param>
/// <param name="targetProductTypeName"></param>
/// <returns></returns>
public bool CopyPara(string sourceProductTypeName, string targetProductTypeName)
{
try
{
db.Ado.BeginTran();
List<T_Para> paraList = db.Queryable<T_Para>().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;
}
}
/// <summary>
/// 批量保存参数项
/// </summary>
/// <param name="t_ParaList"></param>
/// <param name="productTypeName"></param>
/// <returns></returns>
public bool SavePara(List<T_Para> t_ParaList, string productTypeName)
{
try
{
db.Ado.BeginTran();
db.Deleteable<T_Para>().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;
}
}
}
}