Esempio n. 1
0
        public async Task <RouteData <MaterialCode> > QueryStockInMaterial(string no)
        {
            no = no.Split('@')[0];

            Wms_stockindetail targetDetail = await _client.Queryable <Wms_stockindetail>()
                                             .FirstAsync(x => x.UniqueIndex == no);

            if (targetDetail != null)
            {
                return(RouteData <MaterialCode> .From(
                           new MaterialCode()
                {
                    UniqueIndex = no,
                    MaterialId = targetDetail.MaterialId.ToString(),
                    MaterialNo = targetDetail.MaterialNo,
                    MaterialOnlyId = targetDetail.MaterialOnlyId,
                    MaterialName = targetDetail.MaterialName
                }
                           ));
            }
            return(new RouteData <MaterialCode>()
            {
                Code = -1
            });
        }
Esempio n. 2
0
        public IActionResult AddOrUpdateD([FromForm] Wms_stockindetail model, [FromForm] string id)
        {
            var validator = new StockInDetailFluent();
            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())
            {
                model.StockInDetailId = PubId.SnowflakeId;
                model.Status          = StockInStatus.initial.ToByte();
                model.CreateBy        = UserDtoCache.UserId;
                bool flag = _stockindetailServices.Insert(model);
                return(BootJsonH(flag ? (flag, PubConst.Add1) : (flag, PubConst.Add2)));
            }
            else
            {
                model.StockInDetailId = id.ToInt64();
                model.ModifiedBy      = UserDtoCache.UserId;
                model.ModifiedDate    = DateTimeExt.DateTime;
                var flag = _stockindetailServices.Update(model);
                return(BootJsonH(flag ? (flag, PubConst.Update1) : (flag, PubConst.Update2)));
            }
        }
Esempio n. 3
0
        public RouteData <Wms_StockInMaterialDetailDto> SearchMaterial(long storeId, long stockInId, string materialNo)
        {
            Wms_material material = _client.Queryable <Wms_material>().First(x => x.MaterialNo == materialNo);

            if (material == null)
            {
                return(RouteData <Wms_StockInMaterialDetailDto> .From(PubMessages.E1005_MATERIALNO_NOTFOUND));
            }
            Wms_stockindetail detail = _stockindetailServices.QueryableToEntity(x => x.StockInId == stockInId && x.MaterialId == material.MaterialId);

            if (detail == null)
            {
                return(RouteData <Wms_StockInMaterialDetailDto> .From(PubMessages.E2015_STOCKIN_HASNOT_MATERIAL));
            }
            Wms_StockInMaterialDetailDto detailDto = new Wms_StockInMaterialDetailDto()
            {
                StockInId       = detail.StockInId.ToString(),
                StockInDetailId = detail.StockInDetailId.ToString(),
                MaterialId      = material.MaterialId.ToString(),
                MaterialNo      = material.MaterialNo,
                MaterialName    = material.MaterialName,
                PlanInQty       = (int)detail.PlanInQty,
                ActInQty        = (int)detail.ActInQty,
                Qty             = 0
            };

            return(RouteData <Wms_StockInMaterialDetailDto> .From(detailDto));
        }
Esempio n. 4
0
        public IActionResult Detail(string id, string pid)
        {
            var model = new Wms_stockindetail();

            if (id.IsEmptyZero())
            {
                model.StockInId = pid.ToInt64();
                return(View(model));
            }
            else
            {
                model = _stockindetailServices.QueryableToEntity(c => c.StockInDetailId == SqlFunc.ToInt64(id) && c.IsDel == 1);
                return(View(model));
            }
        }
Esempio n. 5
0
        public IActionResult Detail(string id, string pid, long storeId)
        {
            var model = new Wms_stockindetail();

            ViewData["currentStoreId"] = storeId;
            if (id.IsEmptyZero() && !pid.IsEmptyZero())
            {
                model.StockInId = pid.ToInt64();
                return(View(model));
            }
            else
            {
                model = _stockindetailServices.QueryableToEntity(c => c.WarehouseId == storeId && c.StockInDetailId == SqlFunc.ToInt64(id) && c.IsDel == 1);
                return(View(model));
            }
        }
Esempio n. 6
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));
        }
Esempio n. 7
0
        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());
        }