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() { } /// /// 查询所有前置参数 /// /// public static ISugarQueryable QueryAheadParas() { try { return DBHelper.sqlSugarDb.Queryable(); } catch (Exception ex) { var msg = ex == null ? "执行QueryAheadParas方法时异常" : ex.Message; LogHelper.WriteLog($"执行QueryAheadParas方法时异常:{msg}"); return null; } } /// /// 查询前置参数 /// /// /// /// public static ISugarQueryable QueryAheadVM(string statonCode, string category) { try { return DBHelper.sqlSugarDb.Queryable() .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 QueryAheadParaVM(string keyWord = "", int id = 0) { try { return DBHelper.sqlSugarDb.Queryable() .InnerJoin((a, b) => a.LineCode == b.LineCode && a.LastStationCode == b.StationCode && a.Category == b.Category && !a.IsDeleted && !b.IsDeleted) .InnerJoin((a, b, c) => a.LineCode == c.LineCode && a.MachineTypeCode == c.ProductSfcCode) .InnerJoin((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; } } /// /// 查询未删除的前置参数 /// /// public static ISugarQueryable QueryActiveAheadParas() { try { return DBHelper.sqlSugarDb.Queryable().Where(m => !m.IsDeleted); } catch (Exception ex) { var msg = ex == null ? "执行QueryActiveAheadParas方法时异常" : ex.Message; LogHelper.WriteLog($"执行QueryActiveAheadParas方法时异常:{msg}"); return null; } } /// /// 根据Ids删除前置参数 /// 逻辑删除 /// /// /// public static int DelAheadParaByIds(List ids) { try { return DBHelper.sqlSugarDb.Updateable() .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; } } /// /// 根据Ids物理删除前置参数 /// /// /// public static int DoDelAheadParaByIds(List ids) { try { return DBHelper.sqlSugarDb.Deleteable().Where(m => ids.Contains(m.Id)).ExecuteCommand(); } catch (Exception ex) { var msg = ex == null ? "执行DoDelAheadParaByIds方法时异常" : ex.Message; LogHelper.WriteLog($"执行DoDelAheadParaByIds方法时异常:{msg}"); return -1; } } /// /// 新增前置参数 /// /// /// 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; } } /// /// 修改前置参数 /// /// /// 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; } } /// /// 上工位参数(资源、工序)查询 /// /// /// public static string Query_Ahead(string stationcode_1, string productsfccode_1) { try { return DBHelper.sqlSugarDb.Queryable().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 ""; } } } }