예제 #1
0
        /// <summary>
        /// 入库数据批量校验
        /// </summary>
        /// <param name="pre"></param>
        private void BatchInputStorageCheck(Dictionary <string, string> pre, bool isclear = false)
        {
            var           scanValidKey   = "ScanValid";
            var           scanInvalidKey = "ScanInvalid";
            List <string> errli          = new List <string>();

            List <Product_Model> validModels   = new List <Product_Model>();
            List <Product_Model> inValidModels = new List <Product_Model>();

            if (!isclear)
            {
                validModels   = SessionAccess.Get(scanValidKey) as List <Product_Model>;
                inValidModels = SessionAccess.Get(scanInvalidKey) as List <Product_Model>;
                if (validModels == null)
                {
                    validModels = new List <Product_Model>();
                }
                if (inValidModels == null)
                {
                    inValidModels = new List <Product_Model>();
                }
            }

            List <string> numbs  = pre.Select(c => c.Value).ToList();
            List <string> valied = new List <string>();

            //是否与已校验通过的结果重复
            var exisVali = validModels.Where(c => numbs.Contains(c.ProductBarcode)).ToList();
            //是否与校验不通过的结果重复
            var exisInvali = inValidModels.Where(c => numbs.Contains(c.ProductBarcode)).ToList();
            int cuind      = inValidModels.Count + validModels.Count + 1;

            if (exisVali.Any())
            {
                valied.AddRange(exisVali.Select(c => c.ProductBarcode));
                for (int i = 0; i < exisVali.Count(); i++)
                {
                    var ite = exisVali[0];
                    var t   = CacheAccess.Clone <Product_Model>(ite);
                    t.Id    = cuind;
                    t.Notes = "已进入缓存队列";
                    inValidModels.Add(t);
                }
                var exiscodes = exisVali.Select(c => c.ProductBarcode).ToList();
                numbs.RemoveAll(c => exiscodes.Contains(c));
            }
            else if (exisInvali.Any())
            {
                valied.AddRange(exisInvali.Select(c => c.ProductBarcode));
                for (int i = 0; i < exisInvali.Count(); i++)
                {
                    var ite = exisInvali[i];
                    var t   = CacheAccess.Clone <Product_Model>(ite);
                    t.Id     = cuind;
                    t.Notes += ",且已经重复";
                    inValidModels.Add(t);
                }

                var exiscodes = exisVali.Select(c => c.ProductBarcode).ToList();
                numbs.RemoveAll(c => exiscodes.Contains(c));
            }

            var plbarcode = numbs.Where(c => !valied.Contains(c)).ToList();//没有经过校验的条码

            if (plbarcode.Any())
            {
                //商品的打印记录
                var vadali = _productBarcodeDetailContract.productBarcodeDetails.Where(c => plbarcode.Contains(c.ProductNumber + c.OnlyFlag));
                //根据条码得到编号
                var pnums = numbs.Where(c => c.Length == 14).Select(c => c.Substring(0, 11)).ToList();
                //存在商品檔案的库存
                var exisnum = _productContract.Products.Where(c => pnums.Contains(c.ProductNumber))
                              .Select(c => c.ProductNumber)
                              .ToList();
                //入库校验
                foreach (var inda in plbarcode)
                {
                    //序列号
                    var ind = inValidModels.Count + validModels.Count + 1;
                    if (validModels.Any(c => c.ProductBarcode == inda))
                    {
                        var exc = validModels.FirstOrDefault(c => c.ProductBarcode == inda);
                        if (exc != null)
                        {
                            var t = CacheAccess.Clone <Product_Model>(exc);
                            t.Id    = ind;
                            t.Notes = "已进入缓存队列";
                            inValidModels.Add(t);
                        }
                    }
                    else if (inValidModels.Any(c => c.ProductBarcode == inda))
                    {
                        var exc = inValidModels.FirstOrDefault(c => c.ProductBarcode == inda);
                        if (exc != null)
                        {
                            var te = CacheAccess.Clone <Product_Model>(exc);
                            te.Id     = ind;
                            te.Notes += ",且已经重复";
                            inValidModels.Add(te);
                        }
                        var exiscodes = exisVali.Select(c => c.ProductBarcode).ToList();
                        numbs.RemoveAll(c => exiscodes.Contains(c));
                    }
                    else
                    {
                        //带校验对象
                        var di = pre.FirstOrDefault(c => c.Value == inda);
                        if (inda.Length == 14)
                        {
                            var prnum = inda.Substring(0, 11);
                            //打印记录
                            var barcode = vadali.FirstOrDefault(c => c.ProductNumber + c.OnlyFlag == inda);
                            //商品档案
                            var detai = exisnum.FirstOrDefault(c => c == prnum);

                            if (detai != null)
                            {
                                if (barcode != null)
                                {
                                    if (barcode.IsDeleted)
                                    {
                                        inValidModels.Add(new Product_Model
                                        {
                                            Id             = ind,
                                            UUID           = di.Key,
                                            ProductBarcode = di.Value,
                                            Notes          = "商品档案存在,且有打印记录,但已经被移除到回收站"
                                        });
                                    }
                                    else
                                    {
                                        if (barcode.Status == 0)
                                        {
                                            validModels.Add(new Product_Model
                                            {
                                                Id             = ind,
                                                UUID           = di.Key,
                                                ProductBarcode = di.Value,
                                                Notes          = "商品档案存在,且有打印记录,可以入库"
                                            });
                                        }
                                        else
                                        {
                                            string err = barcode.Status == 1 ? "已入库" : "已删除或禁用";
                                            inValidModels.Add(new Product_Model
                                            {
                                                Id             = ind,
                                                UUID           = di.Key,
                                                ProductBarcode = di.Value,
                                                Notes          = err
                                            });
                                        }
                                    }
                                }
                                else
                                {
                                    inValidModels.Add(new Product_Model
                                    {
                                        Id             = ind,
                                        UUID           = di.Key,
                                        ProductBarcode = di.Value,
                                        Notes          = "商品档案存在,但是没有打印记录"
                                    });
                                }
                            }
                            else
                            {
                                inValidModels.Add(new Product_Model
                                {
                                    Id             = ind,
                                    UUID           = di.Key,
                                    ProductBarcode = di.Value,
                                    Notes          = "商品档案不存在"
                                });
                            }
                        }
                        else
                        {
                            inValidModels.Add(new Product_Model
                            {
                                Id             = ind,
                                UUID           = di.Key,
                                ProductBarcode = di.Value,
                                Notes          = "录入的条码不符合14位数"
                            });
                        }
                    }
                }
            }

            SessionAccess.Set(scanValidKey, validModels, true);
            SessionAccess.Set(scanInvalidKey, inValidModels, true);
        }