Beispiel #1
0
        public JsonResult GetUserChat(int chatId, int lastId, int count, bool unknown)
        {
            List <BotMessage> data = new List <BotMessage>();
            BotUserData       user = null;
            var MessageCount       = 0;

            using (KiaGalleryContext db = new KiaGalleryContext())
            {
                user = db.BotUserData.SingleOrDefault(x => x.ChatId == chatId);
                var query = db.BotMessage.Include("Replay").Where(x => x.ChatId == chatId);
                if (lastId > 0)
                {
                    query = query.Where(x => x.Id < lastId);
                }

                data         = query.OrderByDescending(x => x.Id).Take(count).ToList();
                MessageCount = query.Count();
            }

            var ResponseData = data.Select(x => new MessageView()
            {
                Id         = x.Id,
                ChatId     = x.ChatId,
                MessageId  = x.MessageId,
                Text       = x.Text,
                Date       = Common.DateUtility.GetPersianDateTime(x.CreatedDate.GetValueOrDefault()),
                Unknown    = x.Unknown.GetValueOrDefault(),
                ReplayId   = x.ReplayId,
                ReplayText = x.ReplayId == null ? null : x.Replay.Text,
                ReplayDate = x.ReplayId == null ? null : Common.DateUtility.GetPersianDateTime(x.Replay.CreatedDate.GetValueOrDefault())
            }).ToList();


            var response = new Response()
            {
                status = 200,
                data   = new
                {
                    list         = ResponseData,
                    user         = user,
                    messageCount = MessageCount
                }
            };

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        //Custom Code Start | Replaced Code Block
        //Replaced Code Block Start
        //public CreatePutAwayHandlingUnitsDialog(string id, IPutAwayHandlingUnitsService putawayhandlingunitsService, PutAwayHandlingUnitsPost putawayhandlingunitsPost, BotSpielUserStateAccessors statePropertyAccessor)
        //Replaced Code Block End
        public CreatePutAwayHandlingUnitsDialog(string id
                                                , IPutAwayHandlingUnitsService putawayhandlingunitsService
                                                , PutAwayHandlingUnitsPost putawayhandlingunitsPost
                                                , BotSpielUserStateAccessors statePropertyAccessor
                                                , IHandlingUnitsService handlingunitsService
                                                , PutAway putAway
                                                , BotUserData botUserData
                                                , IInventoryLocationsService inventorylocationsService
                                                , IMoveQueueTypesService movequeuetypesService
                                                , IMoveQueueContextsService movequeuecontextsService
                                                , IInventoryUnitsService inventoryunitsService
                                                , IStatusesService statusesService
                                                , IMoveQueuesService movequeuesService
                                                )

        //Custom Code End
            : base(id)
        {
            InitialDialogId             = Id;
            _botSpielUserStateAccessors = statePropertyAccessor ?? throw new System.ArgumentNullException("state accessor can't be null");

            _putawayhandlingunitsService = putawayhandlingunitsService;
            _putawayhandlingunitsPost    = putawayhandlingunitsPost;

            //Custom Code Start | Added Code Block
            _handlingunitsService = handlingunitsService;
            _putAway     = putAway;
            _botUserData = botUserData;
            _inventorylocationsService = inventorylocationsService;
            _movequeuetypesService     = movequeuetypesService;
            _movequeuecontextsService  = movequeuecontextsService;
            _inventoryunitsService     = inventoryunitsService;
            _statusesService           = statusesService;
            _movequeuesService         = movequeuesService;

            PromptValidator <string> putAwayHandlingUnitValidator = async(promptContext, cancellationToken) =>
            {
                var value = promptContext.Recognized.Value.Trim().ToLower();
                if (!_handlingunitsService.IndexDb().Where(x => x.sHandlingUnit.Trim().ToLower() == value).Any())
                {
                    await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The handling unit {value} does not exist. Please enter a different value or exit."), cancellationToken);

                    return(false);
                }
                else
                {
                    return(true);
                }
            };

            PromptValidator <string> inventoryDropLocationValidator = async(promptContext, cancellationToken) =>
            {
                var value = promptContext.Recognized.Value.Trim().ToLower();
                var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(promptContext.Context, () => _botUserData);

                if (!_inventorylocationsService.IndexDb().Where(x => x.sInventoryLocation.Trim().ToLower() == value && x.ixFacility == currentBotUserData.ixFacility).Any() && currentBotUserData.sPutAwaySuggestion == "No Suggestion")
                {
                    await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The inventory location {value} does not exist in the facility. Please enter a different value or exit."), cancellationToken);

                    return(false);
                }
                else
                {
                    if (currentBotUserData.sPutAwaySuggestion.Trim().ToLower() != value)
                    {
                        await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The inventory location {value} does not match the suggested location {currentBotUserData.sPutAwaySuggestion}. Please enter a different value or exit."), cancellationToken);

                        return(false);
                    }
                    return(true);
                }
            };

            //Custom Code End


            // Define the prompts used in the Dialog.
            //Custom Code Start | Replaced Code Block
            //Replaced Code Block Start
            //AddDialog(new TextPrompt(PutAwayHandlingUnitPromptId));
            //Replaced Code Block End
            AddDialog(new TextPrompt(PutAwayHandlingUnitPromptId, putAwayHandlingUnitValidator));
            //Custom Code End

            AddDialog(new TextPrompt(InventoryDropLocationPromptId, inventoryDropLocationValidator));


            // Define the conversation flow for the Dialog.
            WaterfallStep[] steps = new WaterfallStep[]
            {
                PutAwayHandlingUnitPrompt,
                InventoryDropLocationPrompt,
                donePrompt,
            };
            AddDialog(new WaterfallDialog(Id, steps));
        }
Beispiel #3
0
        public Tuple <Int64, double> getPickSuggestion(Int64 ixPickBatch, BotUserData _botUserData)
        {
            Tuple <Int64, double> pickSuggestion = new Tuple <long, double>(0, 0);
            var pickBatch = _pickbatchesService.Get(ixPickBatch);

            if (pickBatch.PickBatchTypes.sPickBatchType.Contains("Discrete order picking")) //Order based picking
            {
                //We pick order by order
                var ordersInBatch = _outboundordersService.IndexDb().Where(x => x.ixPickBatch == ixPickBatch).OrderBy(x => x.ixOutboundOrder).Select(x => new { ixFacility = x.ixFacility, ixCompany = x.ixCompany, ixOutboundOrder = x.ixOutboundOrder }).ToList();

                var orderLinesInBatch = _outboundorderlinesService.IndexDb().Select(x => new { ixOutboundOrder = x.ixOutboundOrder, ixOutboundOrderLine = x.ixOutboundOrderLine, ixMaterial = x.ixMaterial })
                                        //.Where(x => ordersInBatch.Contains(x.ixOutboundOrder)).OrderBy(x => x.ixOutboundOrder).ThenBy(x => x.ixOutboundOrderLine)
                                        .Join(ordersInBatch, ol => ol.ixOutboundOrder, ob => ob.ixOutboundOrder, (ol, ob) => new { Ob = ob, Ol = ol })
                                        .Select(lib => new { ixFacility = lib.Ob.ixFacility, ixCompany = lib.Ob.ixCompany, ixOutboundOrder = lib.Ol.ixOutboundOrder, ixOutboundOrderLine = lib.Ol.ixOutboundOrderLine, ixMaterial = lib.Ol.ixMaterial })
                                        .ToList();

                ordersInBatch.ForEach(o =>
                {
                    var orderLinesInOrder = orderLinesInBatch.Where(x => x.ixOutboundOrder == o.ixOutboundOrder).Select(x => x.ixOutboundOrderLine).ToList();

                    var openLinesToPick = _outboundorderlinesinventoryallocationService.IndexDb()
                                          .Where(x => orderLinesInOrder.Contains(x.ixOutboundOrderLine) && x.nBaseUnitQuantityAllocated > x.nBaseUnitQuantityPicked)
                                          .Join(orderLinesInBatch, op => op.ixOutboundOrderLine, ol => ol.ixOutboundOrderLine, (op, ol) => new { Op = op, Ol = ol })
                                          .Select(x => new { ixOutboundOrder = x.Ol.ixOutboundOrder, ixOutboundOrderLine = x.Ol.ixOutboundOrderLine, ixMaterial = x.Ol.ixMaterial, nBaseUnitQuantityOpen = x.Op.nBaseUnitQuantityAllocated - x.Op.nBaseUnitQuantityPicked }).Distinct().ToList();

                    var inventoryUnitCandidates = _inventoryunitsService.IndexDb().Where(x =>
                                                                                         x.ixFacility == o.ixFacility &&
                                                                                         x.ixCompany == o.ixCompany &&
                                                                                         _commonLookUps.getPickAndPlaceLocationFunctions().Select(lf => lf.ixLocationFunction).Contains(x.InventoryLocations.ixLocationFunction) &&
                                                                                         _commonLookUps.getAvailableInventoryStates().Select(s => s.ixInventoryState).Contains(x.ixInventoryState)
                                                                                         )
                                                  .Join(openLinesToPick, iu => iu.ixMaterial, ol => ol.ixMaterial, (iu, ol) => new { Iu = iu, Ol = ol })
                                                  .Where(x => (x.Iu.nBaseUnitQuantity - x.Iu.nBaseUnitQuantityQueued) >= 0)
                                                  .ToList();

                    pickSuggestion = inventoryUnitCandidates.Select(x =>
                                                                    new
                    {
                        ixInventoryUnit         = x.Iu.ixInventoryUnit,
                        bQtyMatch               = x.Ol.nBaseUnitQuantityOpen == x.Iu.nBaseUnitQuantity - x.Iu.nBaseUnitQuantityQueued ? true : false,
                        bIsSingleIuHU           = _inventoryunitsService.IndexDbPost().Where(iu => iu.ixHandlingUnit == x.Iu.ixHandlingUnit).Count() == 1 ? true : false,
                        nLocationTypePreference =
                            (
                                x.Iu.InventoryLocations.ixLocationFunction == _commonLookUps.getLocationFunctions().Where(f => f.sLocationFunctionCode == "FP").Select(f => f.ixLocationFunction).FirstOrDefault() ? 1 :
                                x.Iu.InventoryLocations.ixLocationFunction == _commonLookUps.getLocationFunctions().Where(f => f.sLocationFunctionCode == "LD").Select(f => f.ixLocationFunction).FirstOrDefault() ? 2 :
                                x.Iu.InventoryLocations.ixLocationFunction == _commonLookUps.getLocationFunctions().Where(f => f.sLocationFunctionCode == "LD").Select(f => f.ixLocationFunction).FirstOrDefault() ? 3 : 1000
                            ),
                        nDistance    = Math.Abs(x.Iu.InventoryLocations.nSequence - _inventorylocationsService.GetPost(_botUserData.ixInventoryLocation).nSequence),
                        nPickQtyDiff = (x.Iu.nBaseUnitQuantity - x.Iu.nBaseUnitQuantityQueued) - x.Ol.nBaseUnitQuantityOpen,
                        nPickQty     = (x.Iu.nBaseUnitQuantity - x.Iu.nBaseUnitQuantityQueued) - x.Ol.nBaseUnitQuantityOpen >= 0 ? x.Ol.nBaseUnitQuantityOpen : (x.Iu.nBaseUnitQuantity - x.Iu.nBaseUnitQuantityQueued)
                    }
                                                                    )
                                     .OrderByDescending(i => i.bQtyMatch)
                                     .ThenByDescending(i => i.bIsSingleIuHU)
                                     .ThenBy(i => i.nLocationTypePreference)
                                     .ThenByDescending(i => i.nPickQtyDiff)
                                     .ThenBy(i => i.nDistance)
                                     .Select(ps => Tuple.Create(ps.ixInventoryUnit, ps.nPickQty)).FirstOrDefault();

                    if (pickSuggestion.Item1 > 0 && pickSuggestion.Item2 > 0)
                    {
                        return;
                    }
                }
                                      );
            }
            else
            {
                //We implement this later
            }

            return(pickSuggestion);
        }
        //Custom Code Start | Replaced Code Block
        //Replaced Code Block Start
        // public BotSpielBot(ILoggerFactory loggerFactory, BotSpielUserStateAccessors statePropertyAccessor, BotUserData botUserData, BotUserEntityContext botUserEntityContext, NavigationEntityData navigationEntityData
        //, PutAwayHandlingUnitsPost putawayhandlingunitsPost
        //    , IPutAwayHandlingUnitsService putawayhandlingunitsService
        // )
        //Replaced Code Block End
        public BotSpielBot(ILoggerFactory loggerFactory, BotSpielUserStateAccessors statePropertyAccessor, BotUserData botUserData, BotUserEntityContext botUserEntityContext, NavigationEntityData navigationEntityData
                           , DropInventoryUnitsPost dropinventoryunitsPost
                           , PickBatchPickingPost pickbatchpickingPost
                           , PutAwayHandlingUnitsPost putawayhandlingunitsPost
                           , SetUpExecutionParametersPost setupexecutionparametersPost
                           , IPutAwayHandlingUnitsService putawayhandlingunitsService
                           , ISetUpExecutionParametersService setupexecutionparametersService
                           , IHandlingUnitsService handlingunitsService
                           , UserManager <ApplicationUser> userManager
                           , IFacilitiesService facilitiesService
                           , PutAway putAway
                           , IInventoryLocationsService inventorylocationsService
                           , ILocationFunctionsService locationfunctionsService
                           , IMoveQueueTypesService movequeuetypesService
                           , IMoveQueueContextsService movequeuecontextsService
                           , IInventoryUnitsService inventoryunitsService
                           , IStatusesService statusesService
                           , IMoveQueuesService movequeuesService
                           , IPickBatchesService pickbatchesService
                           , CommonLookUps commonLookUps
                           , Picking picking
                           , Shipping shipping
                           , IPickBatchPickingService pickbatchpickingService
                           , IOutboundOrderLinesInventoryAllocationService outboundorderlinesinventoryallocationService
                           , IOutboundOrderLinePackingService outboundorderlinepackingService
                           )
        //Custom Code End

        {
            if (loggerFactory == null)
            {
                throw new System.ArgumentNullException(nameof(loggerFactory));
            }

            _logger = loggerFactory.CreateLogger <BotSpielBot>();

            _botUserData          = botUserData;
            _botUserEntityContext = botUserEntityContext;
            _navigationEntityData = navigationEntityData;

            _botSpielUserStateAccessors = statePropertyAccessor ?? throw new System.ArgumentNullException("state accessor can't be null");

            _dropinventoryunitsPost          = dropinventoryunitsPost;
            _pickbatchpickingPost            = pickbatchpickingPost;
            _putawayhandlingunitsPost        = putawayhandlingunitsPost;
            _setupexecutionparametersPost    = setupexecutionparametersPost;
            _putawayhandlingunitsService     = putawayhandlingunitsService;
            _setupexecutionparametersService = setupexecutionparametersService;
            //Custom Code Start | Added Code Block
            _handlingunitsService = handlingunitsService;
            _userManager          = userManager;
            _facilitiesService    = facilitiesService;
            _putAway = putAway;
            _inventorylocationsService = inventorylocationsService;
            _locationfunctionsService  = locationfunctionsService;
            _movequeuetypesService     = movequeuetypesService;
            _movequeuecontextsService  = movequeuecontextsService;
            _inventoryunitsService     = inventoryunitsService;
            _statusesService           = statusesService;
            _movequeuesService         = movequeuesService;
            _pickbatchesService        = pickbatchesService;
            _commonLookUps             = commonLookUps;
            _picking  = picking;
            _shipping = shipping;
            _pickbatchpickingService = pickbatchpickingService;
            _outboundorderlinesinventoryallocationService = outboundorderlinesinventoryallocationService;
            _outboundorderlinepackingService = outboundorderlinepackingService;
            //Custom Code End

            // The DialogSet needs a DialogState accessor, it will call it when it has a turn context.
            _dialogs = new DialogSet(statePropertyAccessor.DialogStateAccessor)
                       .Add(new RootDialog(RootDialogId, _botUserEntityContext, _navigationEntityData))
                       .Add(new CreatePickBatchPickingDialog(CreatePickBatchPickingDialogId, _pickbatchpickingService, _pickbatchpickingPost, _botSpielUserStateAccessors, _pickbatchesService, _commonLookUps, _picking, _inventoryunitsService, _movequeuesService, _handlingunitsService, _outboundorderlinesinventoryallocationService, _outboundorderlinepackingService))
                       //Custom Code Start | Replaced Code Block
                       //Replaced Code Block Start
                       //.Add(new CreatePutAwayHandlingUnitsDialog(CreatePutAwayHandlingUnitsDialogId, _putawayhandlingunitsService, _putawayhandlingunitsPost, _botSpielUserStateAccessors))
                       //Replaced Code Block End
                       .Add(new CreatePutAwayHandlingUnitsDialog(
                                CreatePutAwayHandlingUnitsDialogId
                                , _putawayhandlingunitsService
                                , _putawayhandlingunitsPost
                                , _botSpielUserStateAccessors
                                , _handlingunitsService
                                , _putAway
                                , _botUserData
                                , _inventorylocationsService
                                , _movequeuetypesService
                                , _movequeuecontextsService
                                , _inventoryunitsService
                                , _statusesService
                                , _movequeuesService
                                ))
                       //Custom Code End
                       .Add(new CreateSetUpExecutionParametersDialog(CreateSetUpExecutionParametersDialogId, _setupexecutionparametersService, _setupexecutionparametersPost, _botSpielUserStateAccessors))
                       .Add(new CreateDropInventoryUnitsDialog(CreateDropInventoryUnitsDialogId, _dropinventoryunitsService, _dropinventoryunitsPost, _botSpielUserStateAccessors, _shipping, _inventorylocationsService, _commonLookUps, _movequeuesService))
                       .Add(new ConfirmPrompt(ConfirmPromptId, defaultLocale: Culture.English))
                       //Custom Code Start | Added Code Block
                       .Add(new ChoicePrompt(ChoicesPromptId, defaultLocale: Culture.English))
                       .Add(new CreateGetPickBatchesDialog(CreateGetPickBatchesDialogId, new GetPickBatchesPost(), _botSpielUserStateAccessors, _pickbatchesService, _commonLookUps));
            //Custom Code End
        }