Exemple #1
0
        /**
         * @return the latest version of the decision definition with the given key (from any tenant)
         *
         * @throws ProcessEngineException if more than one tenant has a decision definition with the given key
         *
         * @see #findLatestDecisionDefinitionByKeyAndTenantId(String, String)
         */
        public DecisionDefinitionEntity FindLatestDecisionDefinitionByKey(string key)
        {
            var keyList = Find(p => p.Key == key).ToList();
            var temp    = keyList
                          .GroupBy(x => new { x.TenantId, x.Key })
                          .Select(group => new
            {
                list       = group,
                MaxVersion = group.Max(o => o.Version)
            });

            var templist = new List <TbGosBpmReDecisionDefDto>();

            foreach (var v in temp)
            {
                foreach (var j in v.list)
                {
                    templist.Add(new TbGosBpmReDecisionDefDto()
                    {
                        TenantId   = j.TenantId,
                        Key        = j.Key,
                        MaxVersion = v.MaxVersion,
                    });
                }
            }

            var query = from a in keyList
                        join b in templist
                        on a.Key equals b.Key
                        where
                        a.Version == b.MaxVersion &&
                        (a.TenantId == b.TenantId || (string.IsNullOrEmpty(a.TenantId) && string.IsNullOrEmpty(a.TenantId)))
                        select a;


            //List<DecisionDefinitionEntity> decisionDefinitions = getDbEntityManager().selectList("selectLatestDecisionDefinitionByKey", configureParameterizedQuery(decisionDefinitionKey));

            //if (decisionDefinitions.isEmpty())
            //{
            //    return null;

            //}
            //else if (decisionDefinitions.size() == 1)
            //{
            //    return decisionDefinitions.iterator().next();

            //}
            //else
            //{
            //    throw LOG.multipleTenantsForDecisionDefinitionKeyException(decisionDefinitionKey);
            //}
            //TODO selectLatestDecisionDefinitionByKey 查询逻辑不匹配
            var decisionDefinitions = Find(m => m.Key == key).OrderByDescending(m => m.Version).ToList();

            if (decisionDefinitions == null || decisionDefinitions.Count == 0)
            {
                return(null);
            }
            else if (decisionDefinitions.Count == 1)
            {
                return(decisionDefinitions[0]);
            }
            else
            {
                throw Log.MultipleTenantsForDecisionDefinitionKeyException(key);
            }
        }