Beispiel #1
0
        /// <summary>
        /// 获取分页的数据
        /// </summary>
        /// <param name="gkey">查询Key名称</param>
        /// <param name="parameters">查询参数</param>
        /// <returns>{ total: 总数, data:DataTable}</returns>
        private async Task <PageResult> GetPageAsync(DataGateKey gkey, object obj)
        {
            if (!(obj is IDictionary <string, object> parameters))
            {
                parameters = CommOp.ToStrObjDict(obj);
            }
            if (gkey.TableJoins.Count > 1)
            {
                return(await GetMasterDetailPageAsync(gkey, parameters));
            }
            var tableMeta = gkey.MainTable;

            CreateFilterStr(gkey, tableMeta, parameters);
            CreateOrderStr(gkey, tableMeta, parameters);
            var    ps    = DB.GetParameter(parameters);
            IPager pager = BuildPager(gkey, parameters);

            using (var dr = await DB.DBComm.ExecPageReaderAsync(pager, ps.ToArray()))
            {
                DataTable dt = new DataTable();
                dt.Load(dr);
                ReNameColumns(tableMeta, dt);
                return(new PageResult
                {
                    Total = pager.RecordCount,
                    Data = dt
                });
            }
        }
Beispiel #2
0
 /// <summary>
 /// 实体类对象参数转换
 /// </summary>
 /// <param name="entity">可以是实体对象/匿名对象/数据库参数数组/字典对象</param>
 /// <param name="suffix">为和查询参数相区别对应的后缀</param>
 /// <returns></returns>
 public IEnumerable <IDataParameter> GetParameter(object entity, string suffix = null)
 {
     if (entity is IEnumerable <IDataParameter> param)
     {
         return(param);
     }
     return(GetParameter(CommOp.ToStrObjDict(entity)));
 }
Beispiel #3
0
        /// <summary>
        /// 获取指定表指定条件的数据列表
        /// </summary>
        /// <param name="key"></param>
        /// <param name="paramObj">字典对象或实体对象</param>
        /// <returns></returns>
        public async Task <object> QueryAsync(string key, object paramObj)
        {
            DataGateKey gkey = GetDataGate(key);

            if (!(paramObj is IDictionary <string, object> param))
            {
                param = CommOp.ToStrObjDict(paramObj);
            }
            object result = gkey.Data;

            if (result != null)
            {
                return(result);
            }

            gkey.DataGate.OnQuery(gkey, param);

            switch (gkey.OpType)
            {
            case DataOpType.GetArray:
                result = await GetArrayAsync(gkey, param);

                break;

            case DataOpType.GetObject:
                result = await GetObjectAsync(gkey, param);

                break;

            case DataOpType.GetPage:
                result = await GetPageAsync(gkey, param);

                break;

            default:
                throw new ArgumentException("key=GetArray, GetObject or GetPage");
            }
            gkey.DataGate.OnResult(gkey, result);
            return(result);
        }
Beispiel #4
0
        /// <summary>生成新文档,如已存在则直接返回已存在文档 wang加</summary>
        private async Task <SysFile> BuildNewCheckExists(ServerUploadRequest request, UploadResult result)
        {
            var doc       = BuildNew(request);
            var uploadMD5 = request.Md5;

            doc.Md5  = BuildMD5(request.ServerFile, uploadMD5);
            doc.Size = new FileInfo(request.ServerFile).Length;
            var existsDoc = await _fileMan.GetByMd5Async(doc.Md5);

            if (existsDoc == null)
            {
                var docFile = _uploadPath + doc.RelativePath;
                File.Move(request.ServerFile, docFile);
            }
            else //服务端去重, wang加
            {
                var docFile = _uploadPath + existsDoc.RelativePath;
                if (!File.Exists(docFile)) //万一找到的旧文件不存在,就复制新传的文件
                {
                    docFile = _uploadPath + doc.RelativePath;
                    File.Move(request.ServerFile, docFile);
                    await this._fileMan.UpdateManyAsync(new { doc.RelativePath, existsDoc.Md5 });
                }
                else //如果相同的文件已存在,则新增一条指向原有文件的记录
                {
                    doc.RelativePath = existsDoc.RelativePath;
                }
                result.Dup = true;
            }

            var dict = CommOp.ToStrObjDict(doc);

            foreach (var kv in request.Metadata)
            {
                dict[kv.Key] = kv.Value;
            }
            doc.Id = await _fileMan.InsertAsync(dict);

            return(doc);
        }
Beispiel #5
0
 /// <summary>
 /// 执行非查询语句,用于内部调用
 /// </summary>
 /// <param name="key">关键字</param>
 /// <param name="param">参数</param>
 /// <returns></returns>
 public async Task <int> NonQueryAsync(string key, object param)
 {
     return(await NonQueryAsync(key, CommOp.ToStrObjDict(param)));
 }