|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增测试步骤
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="test_Step"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新测试步骤
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="test_Step"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询所有测试步骤
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public ISugarQueryable<Test_Step> QueryTestStep()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return db.Queryable<Test_Step>();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Error(ex, "执行TestStepService下QueryTestStep时异常");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据Id查询测试步骤
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Test_Step QueryTestById(string id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return db.Queryable<Test_Step>().First(m => m.Id == id);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Error(ex, "执行TestStepService下QueryTestStepById时异常");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据Id删除测试步骤
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public (bool isOk, string msg) DelTestStepById(string id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var row = db.Deleteable<Test_Step>()
|
|
|
|
|
.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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询测试步骤字段已存在的最大排序索引
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="productType"></param>
|
|
|
|
|
/// <param name="testStepCategory"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int? QueryTestStepColumnMaxSortIndex(string productType, string testStepCategory)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return db.Queryable<Test_Step>()
|
|
|
|
|
.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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|