|
|
using ProductionSystem_Log;
|
|
|
using ProductionSystem_Model.DbModel;
|
|
|
using ProductionSystem_Model.DbModel.Para;
|
|
|
using ProductionSystem_Model.DbModel.System;
|
|
|
using ProductionSystem_Model.DbModel.Test;
|
|
|
using ProductionSystem_Model.ViewModel;
|
|
|
using ProductionSystem_Model.ViewModel.Request.Para;
|
|
|
using ProductionSystem_Model.ViewModel.Response.Para;
|
|
|
using ProductionSystem_Model.ViewModel.Response.System;
|
|
|
using SqlSugar;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace ProductionSystem_Service
|
|
|
{
|
|
|
public class ParaColumnConfigService : DbContext
|
|
|
{
|
|
|
|
|
|
|
|
|
public List<Test_Step> QueryTestStepColumnByProductType(string productType)
|
|
|
{
|
|
|
return db.Queryable<Test_Step>()
|
|
|
.Where(x => x.ProductType == productType).ToList();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 分页查询参数字段配置项
|
|
|
/// </summary>
|
|
|
/// <param name="queryParaVM"></param>
|
|
|
/// <param name="totalCount"></param>
|
|
|
/// <returns></returns>
|
|
|
public List<ParaColVM> GetParaColumnPageList(QueryParaColVM queryParaVM, out int totalCount)
|
|
|
{
|
|
|
totalCount = 0;
|
|
|
try
|
|
|
{
|
|
|
return db.Queryable<T_ParaColumnConfig>()
|
|
|
.InnerJoin<Sys_Dic>((a, b) => a.ParaCategory == b.DicCode && b.DicTypeCode == "para_category")
|
|
|
.LeftJoin<T_PlcPoint>((a, b, c) => a.TargetPointAddress == c.PointCode && c.IsActive)
|
|
|
.LeftJoin<T_PlcPoint>((a, b, c, d) => a.MaxPointAddress == d.PointCode && d.IsActive)
|
|
|
.LeftJoin<T_PlcPoint>((a, b, c, d, e) => a.MinPointAddress == e.PointCode && e.IsActive)
|
|
|
.LeftJoin<T_PlcPoint>((a, b, c, d, e, f) => a.IsMustPointAddress == f.PointCode && f.IsActive)
|
|
|
.LeftJoin<T_PlcPoint>((a, b, c, d, e, f, g) => a.TestResultPointAddress == g.PointCode && g.IsActive)
|
|
|
.LeftJoin<T_PlcPoint>((a, b, c, d, e, f, g, h) => a.CollectPointAddress == h.PointCode && h.IsActive)
|
|
|
.WhereIF(queryParaVM != null && !string.IsNullOrWhiteSpace(queryParaVM.ProductType), a => a.ProductType == queryParaVM.ProductType)
|
|
|
.WhereIF(queryParaVM != null && !string.IsNullOrWhiteSpace(queryParaVM.ParaCategory), a => a.ParaCategory == queryParaVM.ParaCategory)
|
|
|
.WhereIF(queryParaVM != null && !string.IsNullOrWhiteSpace(queryParaVM.ParaName), a => a.ParaName.Contains(queryParaVM.ParaName))
|
|
|
.Select((a, b, c, d, e, f, g, h) => new ParaColVM
|
|
|
{
|
|
|
Id = a.Id,
|
|
|
SerialNumber = SqlFunc.RowNumber($"{a.ProductType} asc ,{a.ParaCategory} asc,{a.SortIndex} asc "),
|
|
|
ProductType = a.ProductType,
|
|
|
ParaCategory = a.ParaCategory,
|
|
|
ParaCategoryName = b.DicName,
|
|
|
ParaCode = a.ParaCode,
|
|
|
ParaName = a.ParaName,
|
|
|
TargetPointAddress = c.PointStartAddress,
|
|
|
TargetReadonly = a.TargetReadonly,
|
|
|
StrTargetReadonly = a.TargetReadonly ? "是" : "否",
|
|
|
MaxPointAddress = d.PointStartAddress,
|
|
|
MaxReadonly = a.MaxReadonly,
|
|
|
StrMaxReadonly = a.MaxReadonly ? "是" : "否",
|
|
|
MinPointAddress = e.PointStartAddress,
|
|
|
MinReadonly = a.MinReadonly,
|
|
|
StrMinReadonly = a.MinReadonly ? "是" : "否",
|
|
|
IsMust = a.IsMust,
|
|
|
StrIsMust = a.IsMust ? "是" : "否",
|
|
|
IsMustPointAddress = f.PointStartAddress,
|
|
|
IsShowMain = a.IsShowMain,
|
|
|
StrIsShowMain = a.IsShowMain ? "是" : "否",
|
|
|
IsShowColConfig = a.IsShowColConfig,
|
|
|
StrIsShowColConfig = a.IsShowColConfig ? "是" : "否",
|
|
|
CollectPointAddress = h.PointStartAddress,
|
|
|
TestResultPointAddress = g.PointStartAddress,
|
|
|
SortIndex = a.SortIndex,
|
|
|
ProtocolType = a.ProtocolType,
|
|
|
TestStep = a.TestStepId,
|
|
|
WaiterTime = a.WaiterTime,
|
|
|
TestTime = a.TestTime,
|
|
|
IsActive = a.IsActive,
|
|
|
StrIsActive = a.IsActive ? "是" : "否",
|
|
|
Remark = a.Remark
|
|
|
}).OrderBy(a => a.ProductType).OrderBy(a => a.ParaCategory).OrderBy(a => a.SortIndex).ToPageList(queryParaVM.PageIndex, queryParaVM.PageSize, ref totalCount);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.Error(ex, "执行ParaColumnConfigService下GetParaColumnPageList时异常");
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询所有参数字段配置项
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ISugarQueryable<T_ParaColumnConfig> QueryParaColumns()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
return db.Queryable<T_ParaColumnConfig>();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.Error(ex, "执行ParaColumnConfigService下QueryParaColumns时异常");
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询有效参数字段配置项
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ISugarQueryable<T_ParaColumnConfig> QueryActiveParaColumns()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
return db.Queryable<T_ParaColumnConfig>().Where(m => m.IsActive);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.Error(ex, "执行ParaColumnConfigService下QueryActiveParaColumns时异常");
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据产品型号查询有效参数字段配置项
|
|
|
/// </summary>
|
|
|
/// <param name="productType"></param>
|
|
|
/// <returns></returns>
|
|
|
public ISugarQueryable<T_ParaColumnConfig> QueryActiveParaColumnsByProductType(string productType)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
return db.Queryable<T_ParaColumnConfig>().Where(m => m.ProductType == productType && m.IsActive).OrderBy(m => m.SortIndex);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.Error(ex, "执行ParaColumnConfigService下QueryActiveParaColumnsByProductType时异常");
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据Id查询参数项字段
|
|
|
/// </summary>
|
|
|
/// <param name="id"></param>
|
|
|
/// <returns></returns>
|
|
|
public T_ParaColumnConfig QueryParaColumnById(string id)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
return db.Queryable<T_ParaColumnConfig>().First(m => m.Id == id);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.Error(ex, "执行ParaColumnConfigService下QueryActiveParaColumnById时异常");
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询参数项字段已存在的最大排序索引
|
|
|
/// </summary>
|
|
|
/// <param name="productType"></param>
|
|
|
/// <param name="paraCategory"></param>
|
|
|
/// <returns></returns>
|
|
|
public int? QueryParaColumnMaxSortIndex(string productType, string paraCategory)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
return db.Queryable<T_ParaColumnConfig>()
|
|
|
.Where(m => m.ProductType == productType)
|
|
|
.WhereIF(!string.IsNullOrEmpty(paraCategory), m => m.ParaCategory == paraCategory)
|
|
|
.Select(m => new
|
|
|
{
|
|
|
sortIndex = SqlFunc.AggregateMax(m.SortIndex)
|
|
|
}).First()?.sortIndex;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.Error(ex, "执行ParaColumnConfigService下QueryParaColumnMaxSortIndex时异常");
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据产品型号查询有效参数字段配置项
|
|
|
/// </summary>
|
|
|
/// <param name="productType"></param>
|
|
|
/// <returns></returns>
|
|
|
public List<T_ParaColumnConfig> GetActiveParaColumns(string productType)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
return db.Queryable<T_ParaColumnConfig>().Where(m => m.ProductType == productType && m.IsActive).OrderBy(m => m.SortIndex).ToList();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.Error(ex, "执行ParaColumnConfigService下GetActiveParaColumns时异常");
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 新增参数字段配置项
|
|
|
/// </summary>
|
|
|
/// <param name="t_ParaColumnConfig"></param>
|
|
|
/// <returns></returns>
|
|
|
public (bool isOk, string msg) AddParaColumn(T_ParaColumnConfig t_ParaColumnConfig)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var row = db.Insertable(t_ParaColumnConfig).ExecuteCommand();
|
|
|
return (row > 0, row > 0 ? "操作成功!" : "操作失败!");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
var errorMsg = $"执行ParaColumnConfigService下AddParaColumn时异常:{ex.Message}";
|
|
|
LogHelper.Error(ex, errorMsg);
|
|
|
return (false, errorMsg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 批量新增参数字段配置项
|
|
|
/// </summary>
|
|
|
/// <param name="t_ParaColumnConfig"></param>
|
|
|
/// <returns></returns>
|
|
|
public (bool isOk, string msg) SaveParaColumn(List<T_ParaColumnConfig> t_ParaColumnConfigs)
|
|
|
{
|
|
|
var result = db.UseTran(() =>
|
|
|
{
|
|
|
var rows = db.Insertable(t_ParaColumnConfigs).ExecuteCommand();
|
|
|
if (rows > 0 && rows == t_ParaColumnConfigs.Count)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!result.Data) //返回值为false
|
|
|
{
|
|
|
return (false, "批量新增参数字段配置项,操作失败!");
|
|
|
}
|
|
|
return (true, "操作成功!");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新参数字段配置项
|
|
|
/// </summary>
|
|
|
/// <param name="t_ParaColumnConfig"></param>
|
|
|
/// <returns></returns>
|
|
|
public (bool isOk, string msg) UpdateParaColumn(T_ParaColumnConfig t_ParaColumnConfig)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var row = db.Updateable(t_ParaColumnConfig).ExecuteCommand();
|
|
|
return (row > 0, row > 0 ? "操作成功!" : "操作失败!");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
var errorMsg = $"执行ParaColumnConfigService下UpdateParaColumn时异常:{ex.Message}";
|
|
|
LogHelper.Error(ex, errorMsg);
|
|
|
return (false, errorMsg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据Id删除参数字段配置项
|
|
|
/// </summary>
|
|
|
/// <param name="id"></param>
|
|
|
/// <returns></returns>
|
|
|
public (bool isOk, string msg) DelParaColumnById(string id)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var row = db.Deleteable<T_ParaColumnConfig>().Where(m => m.Id == id).ExecuteCommand();
|
|
|
return (row > 0, row > 0 ? "操作成功!" : "操作失败!");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
var errorMsg = $"执行ParaColumnConfigService下DelParaColumnById时异常:{ex.Message}";
|
|
|
LogHelper.Error(ex, errorMsg);
|
|
|
return (false, errorMsg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据参数项字段Id集合批量更新参数字段配置项状态
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <param name="isActive"></param>
|
|
|
/// <returns></returns>
|
|
|
public (bool isOk, string msg) UpdateParaColumnStatus(List<string> ids, bool? isActive = true)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var row = db.Updateable<T_ParaColumnConfig>()
|
|
|
.SetColumns(c => c.IsActive == isActive)
|
|
|
.SetColumns(c => c.UpdatedTime == DateTime.Now)
|
|
|
.SetColumns(c => c.UpdatedBy == CurrentUser.UserName)
|
|
|
.Where(m => ids.Contains(m.Id))
|
|
|
.ExecuteCommand();
|
|
|
return (row > 0, row > 0 ? "操作成功!" : "操作失败!");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
var errorMsg = $"执行ParaColumnConfigService下UpdateParaColumnStatus时异常:{ex.Message}";
|
|
|
LogHelper.Error(ex, errorMsg);
|
|
|
return (false, errorMsg);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|