WMS-双伸货位初始化功能实现

代码

[HttpPost("/LocationInit/SingleLocationInitials")]
        public async Task SingleLocationInitials(LocationInitInputs locationInitInput)
        {
            try
            {
                string lie, ceng;
                //开启事务
                _locationRepository.Ado.BeginTran();

                if (string.IsNullOrEmpty(locationInitInput.RackCode))
                {
                    throw new Exception("货架编码不能为空!");
                }
                if (_locationRepository.Context.Queryable<Location>().Where(x => x.Rack.RackCode == locationInitInput.RackCode).Count() > 0)
                {
                    throw new Exception("已经存在货位的基础数据,请先删除!");
                }
                if (locationInitInput.Columns > 0 && locationInitInput.Levels > 0)
                {
                    #region 添加货架信息
                    Rack rack = new Rack();
                    rack.RackCode = locationInitInput.RackCode;
                    rack.Columns = locationInitInput.Columns;
                    rack.Levels = locationInitInput.Levels;
                    rack.Side = 0;
                    int deep = locationInitInput.RackDeep;
                    rack.Deep = (RackDeep)locationInitInput.RackDeep;
                    rack.LanewayId = locationInitInput.LaneId;
                    await _locationRepository.Context.Insertable(rack).ExecuteReturnEntityAsync();

                    int CCount = 0;//初始值
                    #endregion
                    for (int i = 1; i <= rack.Levels; i++)
                    {
                        for (int j = 1; j <= rack.Columns; j++)
                        {
                            Cell cell = new Cell();
                            string cellCode = string.Format("{0:00}-{1:000}-{2:00}", rack.RackCode, j, i);

                            cell.CellCode = cellCode;
                            cell.Column = j;
                            cell.Level = i;
                            cell.LanewayId = rack.LanewayId;
                            cell.Side = rack.Side;
                            cell.Shape = "Single";
                            cell.Status = CellStatusConst.None;
                            await _locationRepository.Context.Insertable(cell).ExecuteReturnEntityAsync();


                            for (int k = 1; k <= deep; k++)
                            {
                                int column = j;
                                int layer = i;
                                string locCode = string.Format("{0:00}-{1:000}-{2:00}", rack.RackCode, column, layer);

                                lie = locCode.Substring(3, 3);
                                ceng = locCode.Substring(7, 2);

                                #region 添加货位信息
                                Location location = new Location();
                                location.LocationCode = locCode;
                                location.WcsLocationCode = locCode;
                                location.InboundLimit = 1;
                                location.OutboundLimit = 1;
                                location.StorageGroup = WmsConst.DefaultLocationGroup;
                                location.Specification = WmsConst.NA;
                                location.Sequence = locationInitInput.Sequence;//手动输入是里侧还是外侧
                                location.Level = layer;
                                location.Column = column;
                                location.LocationType = LocationTypes.Rack;

                                //如果是偶数,配置双伸货位的cellid一致
                                if (locationInitInput.ColumnsCount % 2 == 0)
                                {
                                    CCount = locationInitInput.ColumnsCount - 1;
                                    //string av = "0" + CCount.ToString() + "-" + lie + "-" + ceng;调试bug
                                    var userInfo = _locationRepository.Context.Queryable<Location>()
                                                   .Where(x => x.LocationCode == "0" + CCount.ToString() + "-" + lie + "-" + ceng)
                                                   .Select(it => it.CellId)
                                                   .First();
                                    location.CellId = userInfo;
                                }
                                else
                                {
                                    location.CellId = cell.CellId;
                                }
                                
                                location.RackId = rack.RackId;
                                location.WarehouseId = locationInitInput.WarehouseId;
                                location.PosiX = Convert.ToInt32(rack.RackCode);
                                location.PosiY = column;
                                location.PosiZ = layer;
                                await _locationRepository.Context.Insertable(location).ExecuteReturnEntityAsync();
                                #endregion
                            }
                        }
                    }
                }
                _locationRepository.Ado.CommitTran();
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                _locationRepository.Ado.RollbackTran();
                throw;
            }
        }

前言

因为我们公司做单伸比较多,所以单伸货位初始化是有模板的,拿来即用。正巧我目前手头上的项目是个双伸货位,而且公司里的同事都没怎么涉及过,他们一般做法是使用单伸模板先把所有货位生成,然后去数据库里修改部分熟悉使之成为双伸货位。我这里是根据公司原有的单伸货位模板优化出的双伸货位模板。

参数类

/// 
    /// 双伸货位初始化
    /// 
    public class LocationInitInputs
    {
        //仓库ID,不需要的话直接默认为0
        public int WarehouseId { get; set; }
        /// 
        /// 巷道ID
        /// 
        public int LaneId { get; set; }
        /// 
        /// 货架编码/排
        /// 
        public string RackCode { get; set; }
        /// 
        /// 深度  默认为1 
        /// 
        public int RackDeep { get; set; }
        /// 
        /// 列
        /// 
        public int Columns { get; set; }
        /// 
        /// 层
        /// 
        public int Levels { get; set; }

        /// 
        ///里面1 外面2  这样好区分货位是里侧还是外侧,方便做出入库分配货位策略
        /// 
        public int Sequence { get; set; }

        /// 
        /// 总列数
        /// 
        public int ColumnsCount { get; set; }
    }

实现流程

1.如果输入的列和层大于0的话,添加货架信息。
2.嵌套for循环,外层循环层,里层循环列。
3.添加货位单元格表信息
4.再循环深度,这里默认为1,每次生成一次属于正常
5.添加货架表

实现思路

单伸货位和双伸货位的区别在于Sequence字段属于里面为1,外面为2。其次一个通道两个Location 的cellID 相同,例如在货架表中01-001-01这个货位属于里侧,02-001-01这个货位属于外侧,在Cells表中ID是独一无二的,每个货位单元格都会有不同的ID,单是在货位表中,两个货位需要绑定同一个CellId来使两个货位绑定在一起。
这里我的想法是既然是这样,我干脆用奇数和偶数把两个货位做区分。如果是奇数,货架表中正常使用货位单元格的CellId,如果是偶数的话,需要配置双伸货位的cellid一致,这样的话我们就可以拆分货位编码,然后根据货位编码去查询cellid,然后赋值给我们这个货位。

实现

//如果是偶数,配置双伸货位的cellid一致
                                if (locationInitInput.ColumnsCount % 2 == 0)
                                {
                                    CCount = locationInitInput.ColumnsCount - 1;
                                    //string av = "0" + CCount.ToString() + "-" + lie + "-" + ceng;调试bug
                                    var userInfo = _locationRepository.Context.Queryable<Location>()
                                                   .Where(x => x.LocationCode == "0" + CCount.ToString() + "-" + lie + "-" + ceng)
                                                   .Select(it => it.CellId)
                                                   .First();
                                    location.CellId = userInfo;
                                }
                                else
                                {
                                    location.CellId = cell.CellId;
                                }

你可能感兴趣的:(WMS,.net,core,wms)