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 StationHelper { public StationHelper() : base() { } /// /// 查询所有工位 /// /// public static ISugarQueryable QueryStations() { return DBHelper.sqlSugarDb.Queryable(); } /// /// 根据工位编码查询工位 /// /// /// public static T_Station QueryStationByStationCode(string stationCode) { return DBHelper.sqlSugarDb.Queryable().First(m => m.StationCode == stationCode && !m.IsDeleted); } /// /// 查询未删除的工位 /// /// public static ISugarQueryable QueryActiveStations() { return DBHelper.sqlSugarDb.Queryable().Where(m => !m.IsDeleted); } /// /// 根据IPCID和机型查询未删除的工位 /// /// public static List QueryActiveStationsByIpcIdandCategory(string ipcId, string category) { return DBHelper.sqlSugarDb.Queryable().Where(m => m.IpcId == ipcId && m.Category == category && !m.IsDeleted).ToList(); } /// /// 查询未删除的工位 /// /// public static ISugarQueryable QueryActiveStationVMs() { return DBHelper.sqlSugarDb.Queryable().Where(m => !m.IsDeleted) .Select(m => new QueryStationVM { Id = m.Id, IpcId = m.IpcId, LineCode = m.LineCode, Category = m.Category, StationCode = m.StationCode, StationName = m.StationName, StrIsBindAssembleCode = m.IsBindAssembleCode ? "是" : "否", StrIsShowOrderBtn = m.IsShowOrderBtn ? "是" : "否", StrIsShowPrintBtn = m.IsShowPrintBtn ? "是" : "否", StrIsSearchAssemble = m.IsSearchAssemble ? "是" : "否", StrIsSearchLastStation = m.IsSearchLastStation ? "是" : "否", DatabaseIp = m.DatabaseIp, SortIndex = m.SortIndex, IsBranch = m.IsBranch, StrIsBranch = m.IsBranch ? "是" : "否", IsSfcCodeRepeat = m.IsSfcCodeRepeat, StrIsSfcCodeRepeat= m.IsSfcCodeRepeat ? "是" : "否" }); } /// /// 校验工位编码是否有效 /// true:存在 /// /// /// public static bool CheckStationCode(string stationCode) { return DBHelper.sqlSugarDb.Queryable().Where(m => !m.IsDeleted && m.StationCode == stationCode).ToList().Count > 0; } /// /// 根据Ids删除工位 /// 逻辑删除 /// /// /// public static int DelStationByIds(List ids) { 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(); } /// /// 根据Ids物理删除工位 /// /// /// public static int DoDelStationByIds(List ids) { return DBHelper.sqlSugarDb.Deleteable().Where(m => ids.Contains(m.Id)).ExecuteCommand(); } /// /// 新增工位 /// /// /// public static int AddStation(T_Station t_Station) { return DBHelper.sqlSugarDb.Insertable(t_Station).ExecuteCommand(); } /// /// 批量新增工位 /// /// /// public static bool AddStations(List t_Stations) { var result = DBHelper.sqlSugarDb.UseTran(() => { foreach (var item in t_Stations) { AddStation(item); } }); return result.IsSuccess; } /// /// 修改工位 /// /// /// public static int UpdateStation(T_Station t_Station) { return DBHelper.sqlSugarDb.Updateable(t_Station).ExecuteCommand(); } /// /// 查询表中最大索引 /// /// public static int GetMaxSortIndex() { return DBHelper.sqlSugarDb.Queryable().Max(m => m.SortIndex); } } }