Example #1
0
        public IEnumerable <SmlouvyForIndex> GetSmlouvy(string query)
        {
            Func <int, int, Nest.ISearchResponse <Lib.Data.Smlouva> > searchFunc = (size, page) =>
            {
                return(Lib.ES.Manager.GetESClient().Search <Lib.Data.Smlouva>(a => a
                                                                              .Size(size)
                                                                              .Source(ss => ss.Excludes(sml => sml.Field(ff => ff.Prilohy)))
                                                                              .From(page * size)
                                                                              .Query(q => Lib.Data.Smlouva.Search.GetSimpleQuery(query))
                                                                              .Scroll("1m")
                                                                              ));
            };

            List <smlouvaStat> smlStat = new List <smlouvaStat>();

            Searching.Tools.DoActionForQuery <Lib.Data.Smlouva>(Lib.ES.Manager.GetESClient(),
                                                                searchFunc,
                                                                (h, o) =>
            {
                Smlouva s = h.Source;
                if (s != null)
                {
                    foreach (var prij in s.Prijemce)
                    {
                        if (prij.ico == s.Platce.ico)
                        {
                            continue;
                        }
                        Firma f = Firmy.Get(prij.ico);
                        if (f.Valid && f.PatrimStatuAlespon25procent())
                        {
                            continue;
                        }

                        string dodavatel = prij.ico;
                        if (string.IsNullOrWhiteSpace(dodavatel))
                        {
                            dodavatel = prij.nazev;
                        }
                        if (string.IsNullOrWhiteSpace(dodavatel))
                        {
                            dodavatel = "neznamy";
                        }

                        smlStat.Add(new smlouvaStat()
                        {
                            Id            = s.Id,
                            IcoDodavatele = dodavatel,
                            CastkaSDPH    = Math.Abs((decimal)s.CalculatedPriceWithVATinCZK / (decimal)s.Prijemce.Length),
                            Podepsano     = s.datumUzavreni,
                            Rok           = s.datumUzavreni.Year,
                            ULimitu       = s.Hint?.SmlouvaULimitu ?? 0,
                            Obory         = s.GetRelevantClassification()
                                            .OrderByDescending(oo => oo.ClassifProbability)
                                            .Select(m => m.TypeValue).ToArray()
                        });;
                    }
                }

                return(new Devmasters.Batch.ActionOutputData());
            }, null,
                                                                null, null,
                                                                false, blockSize: 100);

            IEnumerable <SmlouvyForIndex> smlouvy = smlStat
                                                    .Select(m => new SmlouvyForIndex(m.IcoDodavatele, m.CastkaSDPH, m.ULimitu, m.Obory))
                                                    .OrderByDescending(m => m.HodnotaSmlouvy) //just better debug
                                                    .ToArray();                               //just better debug

            return(smlouvy);
        }