Exemplo n.º 1
0
        public AlgorithmRespDTO GetAlgorithmByCode(String code, bool hasMeta)
        {
            // single,如果找不到实体,则抛出异常
            DmeAlgorithm     alg          = base.Repository.GetDbContext().Queryable <DmeAlgorithm>().Single(a => a.SysCode == code);
            AlgorithmRespDTO algorithmDTO = ClassValueCopier <AlgorithmRespDTO> .Copy(alg);

            IList <DmeAlgorithmMeta> metas = base.Repository.GetDbContext().Queryable <DmeAlgorithmMeta>().Where(meta => meta.AlgorithmId == alg.Id).ToList();

            if (metas?.Count > 0)
            {
                foreach (var item in metas)
                {
                    EnumValueMetaType enumValueMetaType = EnumUtil.GetEnumObjByName <EnumValueMetaType>(item.DataType);
                    algorithmDTO.Metas.Add(new AlgorithmMetaDTO()
                    {
                        Name         = item.Name,
                        DataType     = (int)enumValueMetaType,
                        DataTypeCode = item.DataType,
                        DataTypeDesc = EnumUtil.GetEnumDescription(enumValueMetaType),
                        Inout        = item.Inout,
                        AlgorithmId  = item.AlgorithmId,
                        IsVisible    = item.IsVisible,
                        Remark       = item.Remark,
                        Alias        = item.Alias,
                        ReadOnly     = item.ReadOnly,
                        Required     = item.Required
                    });
                }
            }
            return(algorithmDTO);
        }
Exemplo n.º 2
0
        public object ListAlgorithms(bool needMeta)
        {
            var db = base.Repository.GetDbContext();
            List <DmeAlgorithm> algs = db.Queryable <DmeAlgorithm>().OrderBy(alg => alg.CreateTime, OrderByType.Desc).ToList();

            if (null == algs || 0 == algs.Count)
            {
                return(algs);
            }
            if (needMeta)
            {
                IList <AlgorithmRespDTO> algDTOs      = new List <AlgorithmRespDTO>();
                AlgorithmRespDTO         algorithmDTO = null;
                IList <DmeAlgorithmMeta> metas        = null;
                IList <AlgorithmMetaDTO> metasDTO     = null;
                foreach (var alg in algs)
                {
                    algorithmDTO = ClassValueCopier <AlgorithmRespDTO> .Copy(alg);

                    if (alg.Extension != null && !string.IsNullOrEmpty(alg.Extension.ToString()))
                    {
                        algorithmDTO.Extension = alg.Extension;// JsonConvert.DeserializeObject(.ToString());
                    }
                    algDTOs.Add(algorithmDTO);
                    metas = db.Queryable <DmeAlgorithmMeta>().Where(meta => meta.AlgorithmId == alg.Id).ToList();
                    if (null == metas || 0 == metas.Count)
                    {
                        continue;
                    }
                    metasDTO = new List <AlgorithmMetaDTO>();
                    foreach (var item in metas)
                    {
                        EnumValueMetaType enumValueMetaType = EnumUtil.GetEnumObjByName <EnumValueMetaType>(item.DataType);
                        metasDTO.Add(new AlgorithmMetaDTO()
                        {
                            Name         = item.Name,
                            DataType     = (int)enumValueMetaType,
                            DataTypeCode = item.DataType,
                            DataTypeDesc = EnumUtil.GetEnumDescription(enumValueMetaType),
                            Inout        = item.Inout,
                            AlgorithmId  = item.AlgorithmId,
                            IsVisible    = item.IsVisible,
                            Remark       = item.Remark,
                            Alias        = item.Alias,
                            ReadOnly     = item.ReadOnly,
                            Required     = item.Required
                        });
                    }
                    algorithmDTO.Metas = metasDTO;
                }
                return(algDTOs);
            }
            return(algs);
        }
Exemplo n.º 3
0
        public object AddAlgorithm(AlgorithmAddReqDTO dto)
        {
            DbResult <AlgorithmRespDTO> result = base.Repository.GetDbContext().Ado.UseTran <AlgorithmRespDTO>(() =>
            {
                DmeAlgorithm alg = base.Repository.GetDbContext().Queryable <DmeAlgorithm>().Where(a => a.SysCode == dto.SysCode).First();
                if (null == alg)
                {
                    alg            = ClassValueCopier <DmeAlgorithm> .Copy(dto);
                    alg.CreateTime = DateUtil.CurrentTimeMillis;
                    alg.Extension  = JsonConvert.SerializeObject(dto.Extension);
                    alg.Id         = base.Repository.GetDbContext().Insertable <DmeAlgorithm>(alg).ExecuteReturnIdentity();
                }
                else
                {
                    // 进行更新操作
                    alg.Name      = dto.Name;
                    alg.Alias     = dto.Alias;
                    alg.Version   = dto.Version;
                    alg.Remark    = dto.Remark;
                    alg.Type      = dto.Type;
                    alg.Extension = JsonConvert.SerializeObject(dto.Extension);
                    if (!base.Repository.GetDbContext().Updateable <DmeAlgorithm>().ExecuteCommandHasChange())
                    {
                        throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, "更新算法信息失败,无详情信息。");
                    }
                    if (dto.Metas != null && dto.Metas.Count > 0)
                    {
                        // 删除算法的输入输出参数这些元数据信息,必须ExecuteCommand,否则无效
                        base.Repository.GetDbContext().Deleteable <DmeAlgorithmMeta>().Where(am => am.AlgorithmId == alg.Id).ExecuteCommand();
                    }
                }
                // 重新注册算法参数元数据
                AlgorithmRespDTO algorithmRespDTO = ClassValueCopier <AlgorithmRespDTO> .Copy(alg);
                if (dto.Metas != null && dto.Metas.Count > 0)
                {
                    algorithmRespDTO.Metas = new List <AlgorithmMetaDTO>();
                    DmeAlgorithmMeta meta  = null;
                    foreach (var item in dto.Metas)
                    {
                        meta             = ClassValueCopier <DmeAlgorithmMeta> .Copy(item);
                        meta.AlgorithmId = alg.Id;
                        meta.Id          = base.Repository.GetDbContext().Insertable <DmeAlgorithmMeta>(meta).ExecuteReturnIdentity();
                        EnumValueMetaType enumValueMetaType = EnumUtil.GetEnumObjByName <EnumValueMetaType>(item.DataType);
                        algorithmRespDTO.Metas.Add(new AlgorithmMetaDTO()
                        {
                            Name         = item.Name,
                            DataType     = (int)enumValueMetaType,
                            DataTypeCode = item.DataType,
                            DataTypeDesc = EnumUtil.GetEnumDescription(enumValueMetaType),
                            Inout        = item.Inout,
                            AlgorithmId  = alg.Id,
                            IsVisible    = item.IsVisible,
                            Remark       = item.Remark,
                            Alias        = item.Alias,
                            ReadOnly     = item.ReadOnly,
                            Required     = item.Required
                        });
                    }
                }
                return(algorithmRespDTO);
            });

            return(result.Data);
        }
Exemplo n.º 4
0
        public Result ExecuteAlgorithm(string algCode, [FromBody] BaseRequestDTO dto)
        {
            AlgorithmRespDTO algInfo = (AlgorithmRespDTO)base.algorithmService.GetAlgorithmByCode(algCode, true);

            return(base.Success(""));
        }