/// <summary>
        /// 获得产品的缓存数据
        /// </summary>
        /// <returns></returns>
        public List <ProductEntity> GetList()
        {
            string Key = string.Format(CacheKey.JOOSHOW_PRODUCT_CACHE, this.CompanyID);
            List <ProductEntity> list = CacheHelper.Get(Key) as List <ProductEntity>;

            if (!list.IsNullOrEmpty())
            {
                return(list);
            }
            ProductEntity entity = new ProductEntity();

            entity.IncludeAll();
            entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete)
            .And(a => a.CompanyID == this.CompanyID);
            entity.OrderBy(a => a.ID, EOrderBy.DESC);
            list = this.Product.GetList(entity);

            if (!list.IsNullOrEmpty())
            {
                StorageProvider      storageProvider = new StorageProvider(this.CompanyID);
                List <StorageEntity> listStorage     = storageProvider.GetList();
                listStorage = listStorage.IsNull() ? new List <StorageEntity>() : listStorage;

                LocationProvider      locationProvider = new LocationProvider(this.CompanyID);
                List <LocationEntity> listLocation     = locationProvider.GetList();
                listLocation = listLocation.IsNull() ? new List <LocationEntity>() : listLocation;

                foreach (ProductEntity item in list)
                {
                    if (!item.StorageNum.IsEmpty())
                    {
                        StorageEntity storage = listStorage.FirstOrDefault(a => a.SnNum == item.StorageNum);
                        item.StorageName = storage.IsNull() ? string.Empty : storage.StorageName;
                    }

                    if (!item.DefaultLocal.IsEmpty())
                    {
                        LocationEntity location = listLocation.FirstOrDefault(a => a.LocalNum == item.DefaultLocal);
                        item.LocalName = location.IsNull() ? string.Empty : location.LocalName;
                    }
                }
            }
            if (!list.IsNullOrEmpty())
            {
                CacheHelper.Insert(Key, list);
            }
            return(list);
        }
        /// <summary>
        /// 初始化某个仓库的库位
        /// </summary>
        /// <param name="StorageNum"></param>
        /// <param name="CreateUser"></param>
        /// <returns></returns>
        public int Init(string StorageNum, string CreateUser)
        {
            string Key = string.Format(CacheKey.JOOSHOW_LOCATION_CACHE, this.CompanyID);

            int            line   = 0;
            LocationEntity entity = new LocationEntity();

            entity.Where(item => item.StorageNum == StorageNum)
            .And(item => item.CompanyID == this.CompanyID)
            ;
            if (this.Location.GetCount(entity) == 0)
            {
                StorageProvider storageProvider = new StorageProvider(this.CompanyID);
                StorageEntity   storage         = storageProvider.GetSingleByNum(StorageNum);
                if (storage != null)
                {
                    LocationEntity location = new LocationEntity();
                    location.LocalNum     = ConvertHelper.NewGuid();
                    location.LocalBarCode = new SequenceProvider(this.CompanyID).GetSequence(typeof(LocationEntity));
                    location.LocalName    = "默认待入库位";
                    location.LocalType    = (int)ELocalType.WaitIn;
                    location.StorageNum   = storage.SnNum;
                    location.StorageType  = storage.StorageType;
                    location.CreateUser   = CreateUser;
                    location.CreateTime   = DateTime.Now;
                    location.IsDefault    = (int)EBool.Yes;
                    location.IsDelete     = (int)EIsDelete.NotDelete;
                    location.IsForbid     = (int)EBool.No;
                    location.CompanyID    = this.CompanyID;
                    location.IncludeAll();
                    line += this.Location.Add(location);


                    location              = new LocationEntity();
                    location.LocalNum     = ConvertHelper.NewGuid();
                    location.LocalBarCode = new SequenceProvider(this.CompanyID).GetSequence(typeof(LocationEntity));
                    location.LocalName    = "默认正式库位";
                    location.LocalType    = (int)ELocalType.Normal;
                    location.StorageNum   = storage.SnNum;
                    location.StorageType  = storage.StorageType;
                    location.CreateUser   = CreateUser;
                    location.CreateTime   = DateTime.Now;
                    location.IsDefault    = (int)EBool.Yes;
                    location.IsDelete     = (int)EIsDelete.NotDelete;
                    location.IsForbid     = (int)EBool.No;
                    location.CompanyID    = this.CompanyID;
                    location.IncludeAll();
                    line += this.Location.Add(location);

                    location              = new LocationEntity();
                    location.LocalNum     = ConvertHelper.NewGuid();
                    location.LocalBarCode = new SequenceProvider(this.CompanyID).GetSequence(typeof(LocationEntity));
                    location.LocalName    = "默认待检库位";
                    location.LocalType    = (int)ELocalType.WaitCheck;
                    location.StorageNum   = storage.SnNum;
                    location.StorageType  = storage.StorageType;
                    location.CreateUser   = CreateUser;
                    location.CreateTime   = DateTime.Now;
                    location.IsDefault    = (int)EBool.Yes;
                    location.IsDelete     = (int)EIsDelete.NotDelete;
                    location.IsForbid     = (int)EBool.No;
                    location.CompanyID    = this.CompanyID;
                    location.IncludeAll();
                    line += this.Location.Add(location);

                    location              = new LocationEntity();
                    location.LocalNum     = ConvertHelper.NewGuid();
                    location.LocalBarCode = new SequenceProvider(this.CompanyID).GetSequence(typeof(LocationEntity));
                    location.LocalName    = "默认待出库位";
                    location.LocalType    = (int)ELocalType.WaitOut;
                    location.StorageNum   = storage.SnNum;
                    location.StorageType  = storage.StorageType;
                    location.CreateUser   = CreateUser;
                    location.CreateTime   = DateTime.Now;
                    location.IsDefault    = (int)EBool.Yes;
                    location.IsDelete     = (int)EIsDelete.NotDelete;
                    location.IsForbid     = (int)EBool.No;
                    location.CompanyID    = this.CompanyID;
                    location.IncludeAll();
                    line += this.Location.Add(location);

                    location              = new LocationEntity();
                    location.LocalNum     = ConvertHelper.NewGuid();
                    location.LocalBarCode = new SequenceProvider(this.CompanyID).GetSequence(typeof(LocationEntity));
                    location.LocalName    = "默认报损库位";
                    location.LocalType    = (int)ELocalType.Bad;
                    location.StorageNum   = storage.SnNum;
                    location.StorageType  = storage.StorageType;
                    location.CreateUser   = CreateUser;
                    location.CreateTime   = DateTime.Now;
                    location.IsDefault    = (int)EBool.Yes;
                    location.IsDelete     = (int)EIsDelete.NotDelete;
                    location.IsForbid     = (int)EBool.No;
                    location.CompanyID    = this.CompanyID;
                    location.IncludeAll();
                    line += this.Location.Add(location);
                }
            }

            if (line > 0)
            {
                CacheHelper.Remove(Key);
            }

            return(line);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(LocationEntity entity)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                string Key = string.Format(CacheKey.JOOSHOW_LOCATION_CACHE, this.CompanyID);

                if (entity.IsDefault == (int)EBool.Yes)
                {
                    LocationEntity location = new LocationEntity();
                    location.IsDefault = (int)EBool.No;
                    location.IncludeIsDefault(true);
                    location.Where(a => a.LocalType == entity.LocalType)
                    .And(a => a.CompanyID == this.CompanyID)
                    ;
                    this.Location.Update(location);

                    LocationEntity temp = new LocationEntity();
                    temp.IsDefault = (int)EBool.No;
                    temp.IncludeIsDefault(true);
                    temp.Where(a => a.CompanyID == this.CompanyID);
                    this.Location.Update(temp);
                }

                //绑定仓库信息
                StorageProvider      storageProvider = new StorageProvider(this.CompanyID);
                List <StorageEntity> listStorage     = storageProvider.GetList();
                listStorage = listStorage.IsNull() ? new List <StorageEntity>() : listStorage;
                if (entity.StorageNum.IsEmpty())
                {
                    StorageEntity storage = listStorage.FirstOrDefault(a => a.IsDefault == (int)EBool.Yes);
                    if (storage != null)
                    {
                        entity.StorageNum  = storage.StorageNum;
                        entity.StorageType = storage.StorageType;
                    }
                }
                else
                {
                    StorageEntity storage = listStorage.FirstOrDefault(a => a.StorageNum == entity.StorageNum);
                    if (storage != null)
                    {
                        entity.StorageType = storage.StorageType;
                    }
                }
                if (entity.UnitName.IsEmpty() && !entity.UnitNum.IsEmpty())
                {
                    MeasureProvider      provider    = new MeasureProvider(this.CompanyID);
                    List <MeasureEntity> listMeasure = provider.GetList();
                    listMeasure = listMeasure.IsNull() ? new List <MeasureEntity>() : listMeasure;
                    MeasureEntity measureEntity = listMeasure.FirstOrDefault(a => a.SN == entity.UnitNum);
                    entity.UnitName = measureEntity != null ? measureEntity.MeasureName : entity.UnitName;
                }
                entity.UnitNum  = entity.UnitNum.IsEmpty() ? "" : entity.UnitNum;
                entity.UnitName = entity.UnitName.IsEmpty() ? "" : entity.UnitName;

                entity.Include(a => new { a.LocalBarCode, a.LocalName, a.StorageNum, a.StorageType, a.LocalType, a.Rack, a.Length, a.Width, a.Height, a.X, a.Y, a.Z, a.UnitNum, a.UnitName, a.Remark, a.IsForbid, a.IsDefault });
                entity.Where(a => a.LocalNum == entity.LocalNum)
                .And(a => a.CompanyID == this.CompanyID)
                ;
                int line = this.Location.Update(entity);
                if (line > 0)
                {
                    CacheHelper.Remove(Key);
                }
                ts.Complete();
                return(line);
            }
        }