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.
307 lines
12 KiB
C#
307 lines
12 KiB
C#
using ProductionSystem_Log;
|
|
using ProductionSystem_Model.DbModel;
|
|
using ProductionSystem_Model.DbModel.Para;
|
|
using ProductionSystem_Model.ViewModel.Request.System;
|
|
using ProductionSystem_Model.ViewModel.Response;
|
|
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 PlcPointService : DbContext
|
|
{
|
|
/// <summary>
|
|
/// 分页查询PLC点位
|
|
/// </summary>
|
|
/// <param name="queryPlcPointVM"></param>
|
|
/// <param name="totalCount"></param>
|
|
/// <returns></returns>
|
|
public List<PlcPointVM> GetPlcPointPageList(QueryPlcPointVM queryPlcPointVM, out int totalCount)
|
|
{
|
|
totalCount = 0;
|
|
try
|
|
{
|
|
return db.Queryable<T_PlcPoint>()
|
|
.WhereIF(!string.IsNullOrEmpty(queryPlcPointVM.PointName), a => a.PointName.Contains(queryPlcPointVM.PointName))
|
|
.WhereIF(!string.IsNullOrEmpty(queryPlcPointVM.PointAddress), a => a.PointStartAddress == queryPlcPointVM.PointAddress)
|
|
.Select((a) => new PlcPointVM
|
|
{
|
|
Id = a.Id,
|
|
SerialNumber = SqlFunc.RowNumber(SqlFunc.Desc(a.CreatedTime)),
|
|
PointCode = a.PointCode,
|
|
PointName = a.PointName,
|
|
PointStartAddress = a.PointStartAddress,
|
|
PointLength = a.PointLength,
|
|
PointDataType = a.PointDataType,
|
|
StrIsSaveDb = a.IsSaveDb ? "是" : "否",
|
|
ResultField = a.ResultField,
|
|
StrIsShowMain = a.IsShowMain ? "是" : "否",
|
|
StrIsTestItem = a.IsTestItem ? "是" : "否",
|
|
StrIsRealTimeCollect = a.IsRealTimeCollect ? "是" : "否",
|
|
IsActive = a.IsActive,
|
|
StrIsActive = a.IsActive ? "是" : "否",
|
|
SortIndex = a.SortIndex,
|
|
Remark = a.Remark,
|
|
CreatedTime = a.CreatedTime,
|
|
CreatedBy = a.CreatedBy,
|
|
UpdatedTime = a.UpdatedTime,
|
|
UpdatedBy = a.UpdatedBy
|
|
}).ToPageList(queryPlcPointVM.PageIndex, queryPlcPointVM.PageSize, ref totalCount);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex, "执行PlcPointService下GetPlcPointPageList时异常");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询所有PLC点位
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ISugarQueryable<T_PlcPoint> QueryPlcPoints()
|
|
{
|
|
try
|
|
{
|
|
return db.Queryable<T_PlcPoint>();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex, "执行PlcPointService下QueryPlcPoints时异常");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询所有有效PLC点位
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ISugarQueryable<T_PlcPoint> QueryActivePlcPoints()
|
|
{
|
|
try
|
|
{
|
|
return db.Queryable<T_PlcPoint>().Where(m => m.IsActive).OrderBy(m => m.SortIndex);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex, "执行PlcPointService下QueryActivePlcPoints时异常");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据Id查询PLC点位
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public T_PlcPoint QueryPlcPointById(string id)
|
|
{
|
|
try
|
|
{
|
|
return db.Queryable<T_PlcPoint>().First(m => m.Id == id);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex, "执行PlcPointService下QueryPlcPointById时异常");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询所有有效需要存数据库的PLC点位
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<SaveDbPointVM> QueryActiveSaveDbPlcPoints()
|
|
{
|
|
try
|
|
{
|
|
//采集数据点位
|
|
var collectDataPoints = db.Queryable<T_PlcPoint>()
|
|
.InnerJoin<T_ParaColumnConfig>((a, b) => a.PointCode == b.CollectPointAddress)
|
|
.Where((a, b) => a.IsActive && a.IsSaveDb && b.IsActive)
|
|
.Select((a, b) => new SaveDbPointVM
|
|
{
|
|
PointCode = a.PointCode,
|
|
PointAddress = a.PointStartAddress,
|
|
PointName = a.PointName,
|
|
ResultField = a.ResultField,
|
|
SortIndex = a.SortIndex
|
|
});
|
|
//采集结果数据点位
|
|
var testResultDataPoints = db.Queryable<T_PlcPoint>()
|
|
.InnerJoin<T_ParaColumnConfig>((a, b) => a.PointCode == b.TestResultPointAddress)
|
|
.Where((a, b) => a.IsActive && a.IsSaveDb && b.IsActive)
|
|
.Select((a, b) => new SaveDbPointVM
|
|
{
|
|
PointCode = a.PointCode,
|
|
PointAddress = a.PointStartAddress,
|
|
PointName = a.PointName,
|
|
ResultField = a.ResultField,
|
|
SortIndex = a.SortIndex
|
|
});
|
|
//主界面顶部的那些点位
|
|
var topDataPoints = db.Queryable<T_PlcPoint>().Where(a => a.IsActive && a.IsSaveDb && !a.IsTestItem)
|
|
.Select(a => new SaveDbPointVM
|
|
{
|
|
PointCode = a.PointCode,
|
|
PointAddress = a.PointStartAddress,
|
|
PointName = a.PointName,
|
|
ResultField = a.ResultField,
|
|
SortIndex = a.SortIndex
|
|
});
|
|
return db.UnionAll(collectDataPoints, testResultDataPoints, topDataPoints).OrderBy(m => m.SortIndex).ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex, "执行PlcPointService下QueryActiveSaveDbPlcPoints时异常");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询首页中间部分的PLC点位
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ISugarQueryable<PointKeyValue> QueryHomeMiddlePlcPoints()
|
|
{
|
|
try
|
|
{
|
|
var resultPoints = db.Queryable<T_PlcPoint>()
|
|
.InnerJoin<T_ParaColumnConfig>((a, b) => a.PointCode == b.TestResultPointAddress && b.IsActive)
|
|
.Where(a => a.IsActive)
|
|
.Select((a, b) => new PointKeyValue
|
|
{
|
|
Key = a.PointCode,
|
|
KeyDesc = a.PointName,
|
|
Address = a.PointStartAddress,
|
|
Length = a.PointLength,
|
|
DataType = a.PointDataType,
|
|
IsShowMain = a.IsShowMain,
|
|
IsTestItem = a.IsTestItem,
|
|
IsSaveDb = a.IsSaveDb,
|
|
IsRealTimeCollect = a.IsRealTimeCollect,
|
|
ResultFieldName = a.ResultField,
|
|
ParaCategory = b.ParaCategory,
|
|
SortIndex = a.SortIndex
|
|
});
|
|
var valPoints = db.Queryable<T_PlcPoint>()
|
|
.InnerJoin<T_ParaColumnConfig>((a, b) => a.PointCode == b.CollectPointAddress && b.IsActive)
|
|
.Where(a => a.IsActive)
|
|
.Select((a, b) => new PointKeyValue
|
|
{
|
|
Key = a.PointCode,
|
|
KeyDesc = a.PointName,
|
|
Address = a.PointStartAddress,
|
|
Length = a.PointLength,
|
|
DataType = a.PointDataType,
|
|
IsShowMain = a.IsShowMain,
|
|
IsTestItem = a.IsTestItem,
|
|
IsSaveDb = a.IsSaveDb,
|
|
IsRealTimeCollect = a.IsRealTimeCollect,
|
|
ResultFieldName = a.ResultField,
|
|
ParaCategory = b.ParaCategory,
|
|
SortIndex = a.SortIndex
|
|
});
|
|
;
|
|
return db.UnionAll(resultPoints, valPoints);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex, "执行PlcPointService下QueryHomeMiddlePlcPoints时异常");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增PLC点位
|
|
/// </summary>
|
|
/// <param name="t_PlcPoint"></param>
|
|
/// <returns></returns>
|
|
public int AddPlcPoint(T_PlcPoint t_PlcPoint)
|
|
{
|
|
try
|
|
{
|
|
return db.Insertable(t_PlcPoint).ExecuteCommand();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex, "执行PlcPointService下AddPlcPoint时异常");
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量新增PLC点位
|
|
/// </summary>
|
|
/// <param name="t_PlcPoints"></param>
|
|
/// <returns></returns>
|
|
public bool AddPlcPoints(List<T_PlcPoint> t_PlcPoints)
|
|
{
|
|
var result = db.UseTran(() =>
|
|
{
|
|
foreach (var item in t_PlcPoints)
|
|
{
|
|
AddPlcPoint(item);
|
|
}
|
|
});
|
|
return result.IsSuccess;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改PLC点位
|
|
/// </summary>
|
|
/// <param name="t_PlcPoint"></param>
|
|
/// <returns></returns>
|
|
public int UpdatePlcPoint(T_PlcPoint t_PlcPoint)
|
|
{
|
|
try
|
|
{
|
|
return db.Updateable(t_PlcPoint).ExecuteCommand();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex, "执行PlcPointService下UpdatePlcPoint时异常");
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据Id集合物理删除PLC点位
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public int DoDelPlcPointsById(string id)
|
|
{
|
|
try
|
|
{
|
|
return db.Deleteable<T_PlcPoint>().Where(m => m.Id == id).ExecuteCommand();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex, "执行PlcPointService下DoDelPlcPointsById时异常");
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询PLC点位中已使用的列
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<string> GetUsedCol()
|
|
{
|
|
try
|
|
{
|
|
return db.Queryable<T_PlcPoint>().Where(m => m.IsActive)
|
|
.Select(m => m.ResultField).ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex, "执行PlcPointService下GetUsedCol时异常");
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|