|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using ZJ_BYD.Common;
|
|
|
|
|
using ZJ_BYD.Model;
|
|
|
|
|
using ZJ_BYD.Untils;
|
|
|
|
|
using ZJ_BYD.ViewModel;
|
|
|
|
|
|
|
|
|
|
namespace ZJ_BYD.DB
|
|
|
|
|
{
|
|
|
|
|
public class AheadParaHelper
|
|
|
|
|
{
|
|
|
|
|
public AheadParaHelper() : base()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询所有前置参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static ISugarQueryable<T_AheadPara> QueryAheadParas()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return DBHelper.sqlSugarDb.Queryable<T_AheadPara>();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
var msg = ex == null ? "执行QueryAheadParas方法时异常" : ex.Message;
|
|
|
|
|
LogHelper.WriteLog($"执行QueryAheadParas方法时异常:{msg}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询前置参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="statonCode"></param>
|
|
|
|
|
/// <param name="category"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static ISugarQueryable<AheadVM> QueryAheadVM(string statonCode, string category)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return DBHelper.sqlSugarDb.Queryable<T_AheadPara>()
|
|
|
|
|
.Where(m=> m.StationCode == statonCode && m.Category == category && !m.IsDeleted)
|
|
|
|
|
.Select(m => new AheadVM
|
|
|
|
|
{
|
|
|
|
|
Id = m.Id,
|
|
|
|
|
StationCode = m.StationCode,
|
|
|
|
|
LastStationCode = m.LastStationCode,
|
|
|
|
|
PointCode = m.PointCode,
|
|
|
|
|
ResultColName = m.ResultColName,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
var msg = ex == null ? "执行QueryAheadVM方法时异常" : ex.Message;
|
|
|
|
|
LogHelper.WriteLog($"执行QueryAheadVM方法时异常:{msg}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ISugarQueryable<AheadParaVM> QueryAheadParaVM(string keyWord = "", int id = 0)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return DBHelper.sqlSugarDb.Queryable<T_AheadPara>()
|
|
|
|
|
.InnerJoin<T_Station>((a, b) => a.LineCode == b.LineCode && a.LastStationCode == b.StationCode && a.Category == b.Category
|
|
|
|
|
&& !a.IsDeleted && !b.IsDeleted)
|
|
|
|
|
.InnerJoin<T_MaskCode>((a, b, c) => a.LineCode == c.LineCode && a.MachineTypeCode == c.ProductSfcCode)
|
|
|
|
|
.InnerJoin<T_Station>((a, b, c, d) => a.LineCode == d.LineCode && a.StationCode == d.StationCode && d.StationCode == Program.ActiveStatinCode)
|
|
|
|
|
.WhereIF(id > 0, (a, b, c, d) => a.Id == id)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(keyWord), (a, b, c) => a.LastStationCode.ToLower().Contains(keyWord.ToLower())
|
|
|
|
|
|| b.StationName.ToLower().Contains(keyWord.ToLower())
|
|
|
|
|
|| a.PointCode.ToLower().Contains(keyWord.ToLower()))
|
|
|
|
|
.Select((a, b, c, d) => new AheadParaVM
|
|
|
|
|
{
|
|
|
|
|
Id = a.Id,
|
|
|
|
|
IpcId = a.IpcId,
|
|
|
|
|
LineCode = a.LineCode,
|
|
|
|
|
MachineTypeCode = a.MachineTypeCode,
|
|
|
|
|
LastStationCode = a.LastStationCode,
|
|
|
|
|
LastStationName = b.StationName,
|
|
|
|
|
Category = b.Category,
|
|
|
|
|
PointCode = a.PointCode,
|
|
|
|
|
ResultColName = a.ResultColName
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var msg = ex == null ? "执行QueryAheadParaVM方法时异常" : ex.Message;
|
|
|
|
|
LogHelper.WriteLog($"执行QueryAheadParaVM方法时异常:{msg}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询未删除的前置参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static ISugarQueryable<T_AheadPara> QueryActiveAheadParas()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return DBHelper.sqlSugarDb.Queryable<T_AheadPara>().Where(m => !m.IsDeleted);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
var msg = ex == null ? "执行QueryActiveAheadParas方法时异常" : ex.Message;
|
|
|
|
|
LogHelper.WriteLog($"执行QueryActiveAheadParas方法时异常:{msg}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据Ids删除前置参数
|
|
|
|
|
/// 逻辑删除
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int DelAheadParaByIds(List<int> ids)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return DBHelper.sqlSugarDb.Updateable<T_AheadPara>()
|
|
|
|
|
.SetColumns(m => m.IsDeleted == true)
|
|
|
|
|
.SetColumns(m => m.UpdatedTime == DateTime.Now)
|
|
|
|
|
.SetColumns(m => m.UpdatedBy == CurrentUser.UserName)
|
|
|
|
|
.Where(m => ids.Contains(m.Id)).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
var msg = ex == null ? "执行DelAheadParaByIds方法时异常" : ex.Message;
|
|
|
|
|
LogHelper.WriteLog($"执行DelAheadParaByIds方法时异常:{msg}");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据Ids物理删除前置参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int DoDelAheadParaByIds(List<int> ids)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return DBHelper.sqlSugarDb.Deleteable<T_AheadPara>().Where(m => ids.Contains(m.Id)).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
var msg = ex == null ? "执行DoDelAheadParaByIds方法时异常" : ex.Message;
|
|
|
|
|
LogHelper.WriteLog($"执行DoDelAheadParaByIds方法时异常:{msg}");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增前置参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="t_AheadPara"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int AddAheadPara(T_AheadPara t_AheadPara)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return DBHelper.sqlSugarDb.Insertable(t_AheadPara).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
var msg = ex == null ? "执行AddAheadPara方法时异常" : ex.Message;
|
|
|
|
|
LogHelper.WriteLog($"执行AddAheadPara方法时异常:{msg}");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 修改前置参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="t_AheadPara"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int UpdateAheadPara(T_AheadPara t_AheadPara)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return DBHelper.sqlSugarDb.Updateable(t_AheadPara).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
var msg = ex == null ? "执行UpdateAheadPara方法时异常" : ex.Message;
|
|
|
|
|
LogHelper.WriteLog($"执行UpdateAheadPara方法时异常:{msg}");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上工位参数(资源、工序)查询
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param ></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string Query_Ahead(string stationcode_1, string productsfccode_1)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return DBHelper.sqlSugarDb.Queryable<T_AheadPara>().First(m => m.StationCode == stationcode_1 && SqlFunc.Replace(m.MachineTypeCode, "*", "") == SqlFunc.Substring(productsfccode_1, 0, SqlFunc.Length(SqlFunc.Replace(m.MachineTypeCode, "*", ""))))?.LastStationCode;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
var msg = ex == null ? "执行Query_Ahead方法时异常" : ex.Message;
|
|
|
|
|
LogHelper.WriteLog($"执行Query_Ahead方法时异常:{msg}");
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|