using iWareCommon.Common.EnumType; using iWareCommon.Common.Service; using iWareCommon.Utils; using iWareDataCore.BASE.Dao; using iWareDataCore.BASE.Entity; using iWareDataCore.BASE.EnumType; using iWareDataCore.ORM; using iWareDataCore.Properties; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace iWareDataCore.BASE.Service { public class PlaceService : CommonService { private static object Lock = new object(); private PlaceService() : base(PlaceDao.GetInstance()) { } private static PlaceService Instance = null; /// /// 获取单例的方法 /// /// 角色服务的单例实体 public static PlaceService GetInstance() { if (Instance == null) { lock (Lock) { if (Instance == null) { Instance = new PlaceService(); } } } return Instance; } /// /// 获取指定字符串开头的库位列表 /// /// 指定字符串 /// 返回的最大条数 /// 异常错误消息 /// 订单号列表 public List GetCodes(string term, int size, out string msg) { using (var dbModel = new DbModelCore()) { try { msg = ""; if (string.IsNullOrEmpty(term)) { return new List(); } var places = dbModel.BASEPlaces.Select(x => new { x.id, x.code }).OrderBy(x => x.code).Where(x => x.code.StartsWith(term)).Skip(0).Take(size).ToList(); return places.Select(x => x.code).Distinct().ToList(); } catch (Exception ex) { msg = ex.Message; LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetCodes", ex.Message); return new List(); } } } /// /// 获取空库位和出入库口 /// /// public List GetEmptyAndInOutGate() { using (var dbModel = new DbModelCore()) { try { List placelst = new List(); var places = dbModel.BASEPlaceViews.Where(x => x.placetypename == "gate11" || x.placetypename == "gate22" || x.placetypename == EPlaceType.普通库位.ToString() && x.status == 0 && x.placetypename != EPlaceType.不合格缓存位.ToString()).ToList(); places.ForEach(x =>{ placelst.Add(new PlaceViewEntity(x)); }); return placelst; } catch (Exception ex) { LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetEmptyAndInOutGate", ex.Message); return new List(); } } } /// /// 库位状态重置 /// /// /// /// public int PlaceReset(List ids, out string msg) { msg = ""; using (var dbModel = new DbModelCore()) { try { var placelst = dbModel.BASEPlaces.Where(x => ids.Contains(x.id)).ToList(); placelst.ForEach(x => { x.status=(int)EPlaceStatus.空库位; x.islock = (int)EYesOrNo.否; x.isexecute = (int)EYesOrNo.否; }); return dbModel.SaveChanges(); } catch (Exception ex) { msg = "更新失败"; LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "PlaceReset", ex.Message); return 0; } } } /// /// 库位解锁 /// /// /// /// public int PlaceUnLock(List ids, out string msg) { msg = ""; using (var dbModel = new DbModelCore()) { try { var placelst = dbModel.BASEPlaces.Where(x => ids.Contains(x.id)).ToList(); placelst.ForEach(x => { x.islock = (int)EYesOrNo.否; x.isexecute = (int)EYesOrNo.否; }); return dbModel.SaveChanges(); } catch (Exception ex) { msg = "更新失败"; LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "PlaceReset", ex.Message); return 0; } } } /// /// 库位锁定 /// /// /// /// public int PlaceLock(List ids, out string msg) { msg = ""; using (var dbModel = new DbModelCore()) { try { var placelst = dbModel.BASEPlaces.Where(x => ids.Contains(x.id)).ToList(); placelst.ForEach(x => { x.islock = (int)EYesOrNo.是; }); return dbModel.SaveChanges(); } catch (Exception ex) { msg = "更新失败"; LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "库位锁定", ex.Message); return 0; } } } } }