Beispiel #1
0
        public async Task <RouteData <Wms_StockInDto> > Get(long storeId, string no)
        {
            Wms_stockin model = await _client.Queryable <Wms_stockin>().FirstAsync(c => c.StockInNo == no && c.WarehouseId == storeId && c.IsDel == 1);

            if (model == null)
            {
                RouteData <Wms_stockin> .From(PubMessages.E2013_STOCKIN_NOTFOUND);
            }
            Wms_StockInDto dto = JsonConvert.DeserializeObject <Wms_StockInDto>(JsonConvert.SerializeObject(model));
            List <Wms_StockMaterialDetailDto> details = await _client.Queryable <Wms_stockindetail, Wms_material>
                                                            ((sid, m) => new object[] {
                JoinType.Left, sid.MaterialId == m.MaterialId,
            })
                                                        .Where((sid, m) => sid.StockInId == model.StockInId)
                                                        .Select((sid, m) => new Wms_StockMaterialDetailDto()
            {
                StockId            = sid.StockInId.ToString(),
                StockDetailId      = sid.StockInDetailId.ToString(),
                StockInUniqueIndex = sid.UniqueIndex,
                MaterialId         = m.MaterialId.ToString(),
                MaterialNo         = m.MaterialNo,
                MaterialName       = m.MaterialName,
                PlanQty            = (int)sid.PlanInQty,
                ActQty             = (int)sid.ActInQty,
                Qty = 0
            })
                                                        .MergeTable()
                                                        .ToListAsync();

            dto.Details = details.ToArray();
            return(RouteData <Wms_StockInDto> .From(dto));
        }
Beispiel #2
0
        public IActionResult Add(string id)
        {
            var model = new Wms_stockin();

            if (id.IsEmpty())
            {
                return(View(model));
            }
            else
            {
                model = _stockinServices.QueryableToEntity(c => c.StockInId == SqlFunc.ToInt64(id) && c.IsDel == 1);
                return(View(model));
            }
        }
Beispiel #3
0
        public IActionResult Add(long id, long storeId)
        {
            var model = new Wms_stockin();

            if (id == 0)
            {
                model.WarehouseId = storeId;
                return(View(model));
            }
            else
            {
                model = _stockinServices.QueryableToEntity(c => c.StockInId == id && c.IsDel == 1);
                return(View(model));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> Preview(long storeId, long pid, long?detailId, long?taskId)
        {
            long id = pid;

            if (id == 0 && detailId != null)
            {
                Wms_stockindetail detail = await _client.Queryable <Wms_stockindetail>().FirstAsync(x => x.StockInDetailId == detailId);

                id = detail.StockInId.Value;
            }
            Wms_stockin model = _stockinServices.QueryableToEntity(
                c => c.WarehouseId == storeId && c.StockInId == id && c.IsDel == 1);

            ViewBag.StockInId       = id;
            ViewBag.StockInDetailId = detailId;
            ViewBag.StoreId         = storeId;
            ViewBag.TaskId          = taskId;
            return(View(model));
        }
Beispiel #5
0
        public IActionResult AddOrUpdate([FromForm] Wms_stockin model, [FromForm] string id)
        {
            var validator = new StockInFluent();
            var results   = validator.Validate(model);
            var success   = results.IsValid;

            if (!success)
            {
                string msg = results.Errors.Aggregate("", (current, item) => (current + item.ErrorMessage + "</br>"));
                return(BootJsonH((PubEnum.Failed.ToInt32(), msg)));
            }
            if (id.IsEmptyZero())
            {
                if (!model.OrderNo.IsEmpty())
                {
                    if (_stockinServices.IsAny(c => c.OrderNo == model.OrderNo))
                    {
                        return(BootJsonH((false, PubConst.StockIn1)));
                    }
                }
                model.StockInNo     = _serialnumServices.GetSerialnum(UserDtoCache.UserId, "Wms_stockin");
                model.StockInId     = PubId.SnowflakeId;
                model.StockInStatus = StockInStatus.initial.ToByte();
                model.CreateBy      = UserDtoCache.UserId;
                bool flag = _stockinServices.Insert(model);
                return(BootJsonH(flag ? (flag, PubConst.Add1) : (flag, PubConst.Add2)));
            }
            else
            {
                model.StockInId    = id.ToInt64();
                model.ModifiedBy   = UserDtoCache.UserId;
                model.ModifiedDate = DateTimeExt.DateTime;
                var flag = _stockinServices.Update(model);
                return(BootJsonH(flag ? (flag, PubConst.Update1) : (flag, PubConst.Update2)));
            }
        }
        public async Task <RouteData> StockInReport(long stockInId, [FromBody] OutsideStockInReportDto result)
        {
            try
            {
                _logger.LogInformation($"[入库任务状态变化通知]收到通知,StockInId={stockInId},data={JsonConvert.SerializeObject(result)}");
                result.StockInId = stockInId;
                Wms_stockin stockIn = await _client.Queryable <Wms_stockin>()
                                      .FirstAsync(x => x.StockInId == result.StockInId);

                if (stockIn == null)
                {
                    _logger.LogError($"[入库任务状态变化通知]E2013-没有找到入库单,StockInId={stockInId}");
                    return(YL.Core.Dto.RouteData.From(PubMessages.E2013_STOCKIN_NOTFOUND));
                }
                if (stockIn.StockInStatus == StockInStatus.task_finish.ToInt32())
                {
                    _logger.LogError($"[入库任务状态变化通知]E2014-入库单状态已标记为完成,本次操作中断,StockInId={stockInId}, StockInNo={stockIn.StockInNo}");
                    //return YL.Core.Dto.RouteData.From(PubMessages.E2014_STOCKIN_ALLOW_FINISHED);
                    return(new RouteData());
                }

                Wms_mestask mesTask = await _client.Queryable <Wms_mestask>()
                                      .FirstAsync(x => x.MesTaskId == stockIn.MesTaskId);

                if (mesTask == null)
                {
                    _logger.LogError($"[入库任务状态变化通知]E3000-没有找到相应的Mes任务,StockInId={stockInId}, StockInNo={stockIn.StockInNo}, MesTaskId={stockIn.MesTaskId}");
                    return(YL.Core.Dto.RouteData.From(PubMessages.E3000_MES_STOCKINTASK_NOTFOUND));
                }

                Wms_stockindetail[] details = _client.Queryable <Wms_stockindetail>()
                                              .Where(x => x.StockInId == result.StockInId).ToArray();

                _client.BeginTran();
                foreach (OutsideStockInReportDetail detail in result.Details)
                {
                    Wms_stockindetail localDetail = details.FirstOrDefault(
                        x => x.UniqueIndex == detail.UniqueIndex);
                    if (localDetail == null)
                    {
                        _client.RollbackTran();
                        _logger.LogError($"[入库任务状态变化通知]E2015-没有找到相应的物料,StockInId={stockInId}, StockInNo={stockIn.StockInNo} ,UniqueIndex ={ detail.UniqueIndex}");
                        return(YL.Core.Dto.RouteData.From(PubMessages.E2015_STOCKIN_HASNOT_MATERIAL, $"MaterialId={detail.MaterialId}"));
                    }
                    localDetail.PlanInQty    = detail.PlanInQty;
                    localDetail.ActInQty     = detail.ActInQty;
                    localDetail.Status       = detail.Status.ToInt32();
                    localDetail.ModifiedBy   = PubConst.InterfaceUserId;
                    localDetail.ModifiedUser = detail.ModifiedBy;
                    localDetail.ModifiedDate = Convert.ToDateTime(detail.ModifiedDate);
                    localDetail.Remark       = detail.Remark;
                    localDetail.ErrorId      = detail.ErrorId;
                    localDetail.ErrorInfo    = detail.ErrorInfo;
                }

                if (_client.Updateable(details).ExecuteCommand() == 0)
                {
                    _client.RollbackTran();
                    _logger.LogError($"[入库任务状态变化通知]E0002-任务明细更新失败,StockInId={stockInId}, StockInNo={stockIn.StockInNo}");
                    return(YL.Core.Dto.RouteData.From(PubMessages.E0002_UPDATE_COUNT_FAIL));
                }

                stockIn.StockInStatus = result.StockInStatus.ToInt32();
                stockIn.ModifiedBy    = PubConst.InterfaceUserId;
                stockIn.ModifiedUser  = PubConst.InterfaceUserName;

                if (_client.Updateable(stockIn).ExecuteCommand() == 0)
                {
                    _client.RollbackTran();
                    _logger.LogError($"[入库任务状态变化通知]E0002-任务更新失败,StockInId={stockInId}, StockInNo={stockIn.StockInNo}");
                    return(YL.Core.Dto.RouteData.From(PubMessages.E0002_UPDATE_COUNT_FAIL));
                }

                var anyWorking = await _client.Queryable <Wms_stockin>()
                                 .AnyAsync(x => x.MesTaskId == stockIn.MesTaskId &&
                                           x.StockInStatus != (int)StockInStatus.task_finish &&
                                           x.StockInStatus != (int)StockInStatus.task_canceled);

                if (!anyWorking)
                {
                    _logger.LogInformation($"[入库任务状态变化通知]所有相关任务已完成,尝试通知MES MesTaskId={stockIn.MesTaskId}");
                    await _client.NofityStockIn(mesTask);
                }
                else
                {
                    _logger.LogInformation($"[入库任务状态变化通知]尚有未完成任务,等待其余任务完成通知 MesTaskId={stockIn.MesTaskId}");
                }

                _logger.LogInformation($"[入库任务状态变化通知]通知处理正常完成,StockInId={stockInId}");
                _client.CommitTran();
                return(new RouteData());
            }
            catch (Exception ex)
            {
                _client.RollbackTran();
                _logger.LogError($"[入库任务状态变化通知]E-1-发生异常,处理结束 ex={ex.ToString()}");
                return(new RouteData()
                {
                    Code = -1, Message = ex.Message
                });
            }
        }
        /// <summary>
        /// 更改料箱相关的入库任务的状态
        /// </summary>
        /// <param name="client"></param>
        /// <param name="inventoryBoxTaskId"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static async Task <RouteData> ConfirmRelationStockIn(
            this ISqlSugarClient client, long inventoryBoxTaskId, SysUserDto user)
        {
            List <Wms_stockindetail_box> stockInDeltailBoxs =
                await client.Queryable <Wms_stockindetail_box>().Where(x => x.InventoryBoxTaskId == inventoryBoxTaskId).ToListAsync();

            if (stockInDeltailBoxs.Count == 0)
            {
                return(new RouteData()); //如果没有相关任务则不做处理
            }
            List <long> confiredStockInIds = new List <long>();

            foreach (Wms_stockindetail_box detailbox in stockInDeltailBoxs)
            {
                Wms_stockindetail stockInDetail =
                    await client.Queryable <Wms_stockindetail>().Where(x => x.StockInDetailId == detailbox.StockinDetailId).FirstAsync();

                if (stockInDetail == null)
                {
                    continue;
                }
                if (stockInDetail.Status == (int)StockInStatus.task_finish)
                {
                    continue;
                }
                if (stockInDetail.ActInQty < stockInDetail.PlanInQty)
                {
                    continue;
                }
                stockInDetail.Status       = (int)StockInStatus.task_finish;
                stockInDetail.ModifiedBy   = user.UserId;
                stockInDetail.ModifiedUser = user.UserName;
                stockInDetail.ModifiedDate = DateTime.Now;
                if (client.Updateable(stockInDetail).ExecuteCommand() == 0)
                {
                    continue;
                }

                if (!confiredStockInIds.Contains(stockInDetail.StockInId.Value))
                {
                    confiredStockInIds.Add(stockInDetail.StockInId.Value);
                }
            }

            foreach (long stockInId in confiredStockInIds)
            {
                bool hasWorking = await client.Queryable <Wms_stockindetail>().AnyAsync(x => x.StockInId == stockInId && x.Status != (int)StockInStatus.task_finish);

                if (!hasWorking)
                {
                    Wms_stockin stockin = await client.Queryable <Wms_stockin>().FirstAsync(x => x.StockInId == stockInId);

                    if (stockin == null)
                    {
                        continue;
                    }
                    stockin.StockInStatus = (int)StockInStatus.task_finish;
                    stockin.ModifiedBy    = user.UserId;
                    stockin.ModifiedUser  = user.UserName;
                    stockin.ModifiedDate  = DateTime.Now;
                    if (client.Updateable(stockin).ExecuteCommand() == 0)
                    {
                        //LOG
                    }
                    var anyWorking = await client.Queryable <Wms_stockin>()
                                     .AnyAsync(x => x.MesTaskId == stockin.MesTaskId &&
                                               x.StockInStatus != (int)StockInStatus.task_finish &&
                                               x.StockInStatus != (int)StockInStatus.task_canceled);

                    if (!anyWorking)
                    {
                        Wms_mestask mesTask = await client.Queryable <Wms_mestask>()
                                              .FirstAsync(x => x.MesTaskId == stockin.MesTaskId);

                        if (mesTask == null)
                        {
                            //正常不可能
                            return(YL.Core.Dto.RouteData.From(PubMessages.E3000_MES_STOCKINTASK_NOTFOUND));
                        }
                        try
                        {
                            //通知处理无论成功失败不影响后续处理
                            await client.NofityStockIn(mesTask);
                        }
                        catch { }
                    }
                }
            }
            return(new RouteData());
        }