Пример #1
0
        public ResultBase <string> SyncPKPMJCData(string tableName, Dictionary <string, string> cmdData, byte[] cmdAttach)
        {
            if (updateNow)
            {
                return(ResultBase <string> .Failure("服务器在处理数据,暂时不接收数据!"));
            }

            try
            {
                string retStr = string.Empty;
                tableName = GetPlatTableName(tableName);
                UploadMqbaseItem item = GetUploadItemByTableName(tableName, cmdData, cmdAttach);
                if (item == null)
                {
                    string message = string.Format("[{0}]-[{1}]", "无配置的表上传", tableName, cmdData);
                    LoggerHelper.WriteCustomLog(logger, message, "NoTableConfig", false);
                    return(ResultBase <string> .Failure(message));
                }
                else
                {
                    return(item.StartUploadDataItem(logger));
                }
            }
            catch (Exception ex)
            {
                string retStr = ex.Message.ToString() + ex.StackTrace.ToString() + ex.Source.ToString();
                LoggerHelper.WriteErrorLog(logger, ex);
                return(ResultBase <string> .Failure(retStr));
            }
        }
Пример #2
0
        /// <summary>
        /// 单独附件上传接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public UploadAttachmentResponse POST(UploadAttachmentRequest req)
        {
            //如果分段的前几段数据,则先缓存
            //否则调用S1(string d,byte[] b)来存储数据
            //缓存放在数据存放文件夹下面的TempData文件夹
            //如果isEnd的值为"0",则向文件追加数据
            //如果isEnd的值为"1",则向文件追加数据之后调用S1进行数据保存之后删除缓存文件
            //cacheKey需对每台工作站每条数据唯一

            if (updateNow)
            {
                return(new UploadAttachmentResponse {
                    IsSucc = false, ErrMsg = "服务器正在处理数据,暂时不接收数据!"
                });
            }

            try
            {
                string tempDir     = "TempData";
                string tempDirPath = Path.Combine(dataFolder, tempDir);
                string filePath    = Path.Combine(tempDirPath, string.Format("{0}.txt", req.Attachment.CacheKey));

                if (!Directory.Exists(tempDirPath))
                {
                    Directory.CreateDirectory(tempDirPath);
                }

                if (req.Attachment.Status == (int)AttachmentStatus.Begin)
                {
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                }

                CommonUtil.WriteFileBytes(filePath, req.Attachment.Attachment);

                if (req.Attachment.Status == (int)AttachmentStatus.Begin || req.Attachment.Status == (int)AttachmentStatus.Middle) //第一段和中间段二进制数据
                {
                    return(new UploadAttachmentResponse {
                        IsSucc = true, ErrMsg = string.Empty
                    });
                }
                else if (req.Attachment.Status == (int)AttachmentStatus.End) //最后一段二进制数据或附件大小只需要上次一次的
                {
                    byte[] cmdAttach = File.ReadAllBytes(filePath);

                    File.Delete(filePath);

                    UploadMqbaseItem item = GetUploadItemByTableName(req.Attachment.Table, req.Attachment.Data, cmdAttach);

                    var result = item.StartUploadAttachmentItem(logger);

                    //还回附件保存的路径给客户端,客户端在下次上传数据的时候要带上来 校验
                    if (result)
                    {
                        return(new UploadAttachmentResponse {
                            IsSucc = true, FilePath = result.Info, ErrMsg = "上传成功!"
                        });
                    }
                    else
                    {
                        LoggerHelper.WriteCustomLog(logger, string.Format("Table:{0} Data:{1} Status:{2} CacheKey:{3} ErrMsg:{4}", req.Attachment.Table, req.Attachment.Data, req.Attachment.Status, req.Attachment.CacheKey, result.Info), "UploadAttachment", false);
                        return(new UploadAttachmentResponse {
                            IsSucc = false, ErrMsg = result.Info
                        });
                    }
                }
                else
                {
                    return(new UploadAttachmentResponse {
                        IsSucc = false, ErrMsg = "未知状态[Status]"
                    });
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.WriteErrorLog(logger, ex);
                return(new UploadAttachmentResponse {
                    IsSucc = false, ErrMsg = ex.Message
                });;
            }
        }
Пример #3
0
        /// <summary>
        /// 统一数据上传接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public UploadUnifiedDataResponse POST(UploadUnifiedDataRequest req)
        {
            List <ItemUploadResult> results = new List <ItemUploadResult>();

            try
            {
                StringBuilder sb        = new StringBuilder();
                string        cmdData   = string.Empty;
                byte[]        cmdAttach = null;

                if (updateNow)
                {
                    return(new UploadUnifiedDataResponse {
                        AllSucc = false, ErrMsg = "服务器正在处理数据,暂时不接收数据!"
                    });
                }

                if (req.Model != null)
                {
                    UploadMqbaseItem item = null;

                    ResultBase <string> syncResult_Main     = null;
                    ResultBase <string> syncResult_Modify   = null;
                    ResultBase <string> syncResult_Acs      = null;
                    ResultBase <string> syncResult_Pkr      = null;
                    ResultBase <string> syncResult_ItemList = null;
                    ResultBase <string> syncResult_Project  = null;

                    if (req.Model.MainData.IsNullOrEmpty())
                    {
                        return(new UploadUnifiedDataResponse {
                            AllSucc = false, ErrMsg = "主表数据必须上传!"
                        });
                    }

                    if (req.Model.PKRData.IsNullOrEmpty())
                    {
                        return(new UploadUnifiedDataResponse {
                            AllSucc = false, ErrMsg = "PKR数据必须上传!"
                        });
                    }

                    #region 主表记录

                    item            = new TBPItemUpload(req.Model.MainData, cmdAttach);
                    syncResult_Main = item.StartUploadDataItem(logger);
                    results.Add(new ItemUploadResult {
                        IsSuc = syncResult_Main.IsSuc, Table = "Main", msg = syncResult_Main.Info
                    });
                    if (syncResult_Main.IsSuc)
                    {
                        sb.AppendLine(string.Format("isSucc:{0} tableName:{1} cmdData:{2} ErrMsg:{3}", syncResult_Main.IsSuc, "Main", cmdData, syncResult_Main.Info));
                    }

                    #endregion

                    #region PKR记录

                    item           = new TPkpmBinaryReportUpload(req.Model.PKRData, cmdAttach, true);
                    syncResult_Pkr = item.StartUploadDataItem(logger);
                    results.Add(new ItemUploadResult {
                        IsSuc = syncResult_Pkr.IsSuc, Table = "Pkr", msg = syncResult_Pkr.Info
                    });
                    if (!syncResult_Pkr.IsSuc)
                    {
                        sb.AppendLine(string.Format("isSucc:{0} tableName:{1} cmdData:{2} ErrMsg:{3}", syncResult_Pkr.IsSuc, "Pkr", cmdData, syncResult_Pkr.Info));
                    }

                    #endregion

                    #region 修改记录

                    if (!req.Model.ModifyDatas.IsNullOrEmpty())
                    {
                        foreach (var modifyData in req.Model.ModifyDatas)
                        {
                            item = new TBPModifyLogUpload(modifyData, cmdAttach);
                            syncResult_Modify = item.StartUploadDataItem(logger);
                            results.Add(new ItemUploadResult {
                                IsSuc = syncResult_Modify.IsSuc, Table = "Modify", msg = syncResult_Modify.Info
                            });
                            if (!syncResult_Modify.IsSuc)
                            {
                                sb.AppendLine(string.Format("isSucc:{0} tableName:{1} cmdData:{2} ErrMsg:{3}", syncResult_Modify.IsSuc, "Modify", cmdData, syncResult_Modify.Info));
                            }
                        }
                    }

                    #endregion

                    #region 曲线记录

                    if (!req.Model.AcsDatas.IsNullOrEmpty())
                    {
                        foreach (var acsData in req.Model.AcsDatas)
                        {
                            item           = new TBPAcsInterFace(acsData, cmdAttach, true);
                            syncResult_Acs = item.StartUploadDataItem(logger);
                            results.Add(new ItemUploadResult {
                                IsSuc = syncResult_Acs.IsSuc, Table = "Acs", msg = syncResult_Acs.Info
                            });
                            if (!syncResult_Acs.IsSuc)
                            {
                                sb.AppendLine(string.Format("isSucc:{0} tableName:{1} cmdData:{2} ErrMsg:{3}", syncResult_Acs.IsSuc, "Acs", cmdData, syncResult_Acs.Info));
                            }
                        }
                    }

                    #endregion

                    #region 工程项目记录

                    if (!req.Model.ItemListData.IsNullOrEmpty())
                    {
                        item = new TBPItemListUpload(req.Model.ItemListData, cmdAttach);
                        syncResult_ItemList = item.StartUploadDataItem(logger);
                        results.Add(new ItemUploadResult {
                            IsSuc = syncResult_ItemList.IsSuc, Table = "ItemList", msg = syncResult_ItemList.Info
                        });
                        if (!syncResult_Pkr.IsSuc)
                        {
                            sb.AppendLine(string.Format("isSucc:{0} tableName:{1} cmdData:{2} ErrMsg:{3}", syncResult_ItemList.IsSuc, "ItemList", cmdData, syncResult_ItemList.Info));
                        }
                    }

                    #endregion

                    #region 工程记录

                    if (!req.Model.ProjectData.IsNullOrEmpty())
                    {
                        //工程记录不需要传,这里只是要添加到主表的一些字段如 工程名称,工程编号,工程地区,监督机构等等
                        item = new TBPProjectUpload(req.Model.ProjectData, cmdAttach);
                        syncResult_Project = item.StartUploadDataItem(logger);
                        results.Add(new ItemUploadResult {
                            IsSuc = syncResult_Project.IsSuc, Table = "Project", msg = syncResult_Project.Info
                        });
                        if (!syncResult_Pkr.IsSuc)
                        {
                            sb.AppendLine(string.Format("isSucc:{0} tableName:{1} cmdData:{2} ErrMsg:{3}", syncResult_Project.IsSuc, "Project", cmdData, syncResult_Project.Info));
                        }
                    }

                    #endregion

                    if (!string.IsNullOrEmpty(sb.ToString()))
                    {
                        LoggerHelper.WriteCustomLog(logger, sb.ToString(), "UploadUnifiedData", false);
                        return(new UploadUnifiedDataResponse {
                            AllSucc = false, ErrMsg = "存在上传失败的数据!", Result = results
                        });
                    }
                    else
                    {
                        return(new UploadUnifiedDataResponse {
                            AllSucc = true, ErrMsg = "上传成功"
                        });
                    }
                }
                else
                {
                    return(new UploadUnifiedDataResponse {
                        AllSucc = false, ErrMsg = "上传数据为空!"
                    });
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.WriteErrorLog(logger, ex);
                return(new UploadUnifiedDataResponse {
                    AllSucc = false, ErrMsg = ex.Message, Result = results
                });
            }
        }