using ProductionSystem_Log;
using ProductionSystem_Model.DbModel.Para;
using ProductionSystem_Model.DbModel.System;
using ProductionSystem_Model.DbModel.Test;
using ProductionSystem_Model.ViewModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProductionSystem_Service
{
public class TestStepService : DbContext
{
///
/// 新增测试步骤
///
///
///
public (bool isOk, string msg) AddTestStep(Test_Step test_Step)
{
try
{
var row = db.Insertable(test_Step).ExecuteCommand();
return (row > 0, row > 0 ? "操作成功!" : "操作失败!");
}
catch (Exception ex)
{
var errorMsg = $"执行TestStepService下AddTestStep时异常:{ex.Message}";
LogHelper.Error(ex, errorMsg);
return (false, errorMsg);
}
}
///
/// 更新测试步骤
///
///
///
public (bool isOk, string msg) UpdateTestStep(Test_Step test_Step)
{
try
{
var row = db.Updateable(test_Step).ExecuteCommand();
return (row > 0, row > 0 ? "操作成功!" : "操作失败!");
}
catch (Exception ex)
{
var errorMsg = $"执行TestStepService下UpdateTestStep时异常:{ex.Message}";
LogHelper.Error(ex, errorMsg);
return (false, errorMsg);
}
}
///
/// 查询所有测试步骤
///
///
public ISugarQueryable QueryTestStep()
{
try
{
return db.Queryable();
}
catch (Exception ex)
{
LogHelper.Error(ex, "执行TestStepService下QueryTestStep时异常");
return null;
}
}
///
/// 根据Id查询测试步骤
///
///
///
public Test_Step QueryTestById(string id)
{
try
{
return db.Queryable().First(m => m.Id == id);
}
catch (Exception ex)
{
LogHelper.Error(ex, "执行TestStepService下QueryTestStepById时异常");
return null;
}
}
///
/// 根据Id删除测试步骤
///
///
///
public (bool isOk, string msg) DelTestStepById(string id)
{
try
{
var row = db.Deleteable()
.Where(m => m.Id == id)
.ExecuteCommand();
return (row > 0, row > 0 ? "操作成功!" : "操作失败!");
}
catch (Exception ex)
{
var errorMsg = $"执行TestStepService下DelTestStepById时异常:{ex.Message}";
LogHelper.Error(ex, errorMsg);
return (false, errorMsg);
}
}
///
/// 查询测试步骤字段已存在的最大排序索引
///
///
///
///
public int? QueryTestStepColumnMaxSortIndex(string productType, string testStepCategory)
{
try
{
return db.Queryable()
.Where(m => m.ProductType == productType)
.WhereIF(!string.IsNullOrEmpty(testStepCategory), m => m.TestName == testStepCategory)
.Select(m => new
{
sortIndex = SqlFunc.AggregateMax(m.Index)
}).First()?.sortIndex;
}
catch (Exception ex)
{
LogHelper.Error(ex, "执行TestStepService下QueryTestStepColumnMaxSortIndex时异常");
return -1;
}
}
}
}