Exemplo n.º 1
0
        public ActionResult ReplyInspection(UInt32 id, string replyContent)
        {
            string msg = PromptInformation.OperationFailure + ":{0}";


            #region 检查数据
            var obj = InspectionBLL.GetInspectionInfoByID(id);
            if (obj.DataResult == null)
            {
                return(Json(new OperationResult()
                {
                    Message = string.Format(msg, obj.Message)
                }));
            }
            var data = obj.DataResult;
            //true代表已被其他人回复
            //这里其实有点问题,因为可能出现查询出以后被人回复的情况,所以实际上如果为了保证不会重复回复,需要做乐观并发
            //但是实际上发生概率实在太低,而且即使重复回复也不会有什么后果,所以不处理
            if (data.Flag)
            {
                return(Json(new OperationResult()
                {
                    Message = string.Format(msg, PromptInformation.InspectionHadBeenRelied)
                }));
            }
            #endregion


            #region 回复查岗
            try
            {
                var    remoteObj = GetRemoteObj();
                string pn        = data.PlatformName;
                string ac        = data.AccessCode;
                string version   = data.Version;
                uint   M1        = (uint)data.M1;
                uint   IA1       = (uint)data.IA1;
                uint   IC1       = (uint)data.IC1;
                string opResult  = string.Empty;
                byte[] sendBytes = BuildReplyContentBytes(id, replyContent, data);
                //进行回复
                if (data.ObjType == "1")//针对平台的查岗
                {
                    opResult = remoteObj.BeginSendPlatFormCheckMsg(sendBytes, pn, ac, version, M1, IA1, IC1);
                }
                else//针对具体业户的查岗
                {
                    opResult = remoteObj.BeginSendPlatFormCheckMsg(sendBytes, pn, data.ObjID, ac, version, M1, IA1, IC1);
                }
                bool   success = opResult == "成功";//remoting那边返回的结果是中文字
                string tempMsg = string.Empty;
                if (success)
                {
                    tempMsg = PromptInformation.OperationSuccess;
                    InspectionBLL.UpdateInspectionState(id, replyContent);//更新物流TMS库的查岗数据,注意这里无所谓更新失败还是成功,大不了重新再回复一次查岗
                }
                else
                {
                    tempMsg = string.Format(msg, PromptInformation.CommunicationError) + "[" + opResult + "]";
                }
                //不论是否成功,只要正常操作了就记录日志
                InspectionBLL.DoReplyLog(id, base.UserIDForLog, tempMsg, success);
                return(Json(new OperationResult()
                {
                    Success = success, Message = tempMsg
                }));
            }
            catch
            {
                return(Json(new OperationResult()
                {
                    Message = string.Format(msg, PromptInformation.RemotingError)
                }));
            }
            #endregion
        }
Exemplo n.º 2
0
        public int ReplyInspectionMessage(UInt32 msgID, string replyContent)
        {
            //TODO: 回复查岗信息 内部逻辑待定
            //根据msgID获取查岗信息
            var result = InspectionBLL.GetInspectionInfoByID(msgID).DataResult;

            if (result == null)//发生错误或未找到记录
            {
                return(-1);
            }
            //true代表已被其他人回复
            //这里其实不对,因为可能出现查询出以后被人回复的情况,所以实际上如果为了保证不会重复回复,需要做乐观并发
            //但是实际上发生概率实在太低,而且即使重复回复也不会有什么后果,所以不处理
            if (result.Flag)
            {
                return(2);
            }

            #region 由于老版本remoting设计问题,导致这里需要编写一次消息体

            if (!GetRemoteObj())
            {
                return(-2);
            }

            //查岗应答内容
            byte[] byteText = Encoding.GetEncoding("GBK").GetBytes(replyContent.Trim());
            //查岗应答消息体
            //子业务类型标识2+后续数据长度4+查岗对象的类型1+查岗对象的ID12+信息ID4+数据长度4+应答内容
            byte[] clientSend = new byte[27 + byteText.Length];


            //子业务类型标识 开始0 结束1
            clientSend[0] = 0x13;
            clientSend[1] = 0x01;

            //后续数据长度 开始2 结束5
            byte[] checkObject = GetBigEndianBytes4(21 + byteText.Length);
            checkObject.CopyTo(clientSend, 2);

            //对象类型 开始6 结束6
            clientSend[6] = Convert.ToByte(result.ObjType);

            //查岗对象的ID 开始7 结束18
            byte[] B12 = new byte[12];
            B12 = Encoding.GetEncoding("GBK").GetBytes(result.ObjID);
            B12.CopyTo(clientSend, 7);

            // 信息ID 开始19 结束22
            byte[] byteSendId = GetBigEndianBytes4(msgID);
            byteSendId.CopyTo(clientSend, 19);

            // 数据长度 开始23 结束26
            byte[] sendTextLen = GetBigEndianBytes4(byteText.Length);
            sendTextLen.CopyTo(clientSend, 23);

            //应答内容 开始27
            byteText.CopyTo(clientSend, 27);
            #endregion



            string pn      = result.PlatformName;
            string ac      = result.AccessCode;
            string version = result.Version;
            uint   M1      = (uint)result.M1;
            uint   IA1     = (uint)result.IA1;
            uint   IC1     = (uint)result.IC1;

            string opResult = string.Empty;
            //进行回复
            if (result.ObjType == "1")//针对平台的查岗
            {
                opResult = remoteObj.BeginSendPlatFormCheckMsg(clientSend, pn, ac, version, M1, IA1, IC1);
            }
            else//针对业户的查岗
            {
                opResult = remoteObj.BeginSendPlatFormCheckMsg(clientSend, pn, result.ObjID, ac, version, M1, IA1, IC1);
            }
            if (opResult != "成功")
            {
                return(0);
            }
            InspectionBLL.UpdateInspectionState(msgID, replyContent);
            return(1);
        }