//[Authorize]
        //[ValidateModel]
        public async Task <ActionResult <ResModel <JObject> > > getOrderPushMsg([FromForm] ReqPushMsgDto pushMsgDto)
        {
            //ReqPushMsgDto pushmsg = JsonConvert.DeserializeObject<ReqPushMsgDto>(pushMsgDto);
            //ResModel<ResMsgDto> res = new ResModel<ResMsgDto>();
            ResModel <JObject> res = new ResModel <JObject>();

            //未授权
            //未授权
            JObject token = CheckAuthorize(pushMsgDto.token?.ToString());

            if (token == null) //未授权 24小时过期,重新获取
            {
                res.success       = "false";
                res.resultMessage = "无权限访问";
                return(res);
            }
            ;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            HttpContext context = _httpContextAccessor.HttpContext;

            if (pushMsgDto.method?.ToString() == "getOrderPushMsg")
            {
                //string msgInfo = JObject.FromObject(pushMsgDto.msgInfo).ToString();

                if (pushMsgDto.type?.ToString() == "1")
                {
                    try
                    {
                        var obj = JsonConvert.DeserializeObject <AddMsg>(pushMsgDto.msgInfo);

                        res = await _iunion.AddLogiticOrder(obj, context);
                    }
                    catch (Exception ex)
                    {
                        return(res.GetRes(Convert.ToBoolean((int)ErrorEnum.SystemException).ToString(), EnumHelper.GetDescription(ErrorEnum.SystemException)));
                    }
                }
                else if (pushMsgDto.type == "2" || pushMsgDto.type == "3" || pushMsgDto.type == "6" || pushMsgDto.type == "7" || pushMsgDto.type == "8")
                {
                    try
                    {
                        res = await _iunion.getOrderPushMsg(pushMsgDto, context);

                        return(res);
                    }
                    catch (Exception ex)
                    {
                        return(res.GetRes(Convert.ToBoolean((int)ErrorEnum.SystemException).ToString(), EnumHelper.GetDescription(ErrorEnum.SystemException)));
                    }
                }
                else
                {
                    res.success       = "false";
                    res.resultMessage = "请求method、推送消息类型或者消息实体错误";
                }
            }
            else if (pushMsgDto.method?.ToString() == "queryLogisticsOrderInfo")
            {
                try
                {
                    res = await _iunion.GetLogiticOrderByNo(pushMsgDto.logisticsOrderNo?.ToString(), context);

                    return(res);
                }
                catch (Exception ex)
                {
                    res.success = "false";
                    return(res.GetRes(Convert.ToBoolean((int)ErrorEnum.SystemException).ToString(), EnumHelper.GetDescription(ErrorEnum.SystemException)));
                }
            }
            else
            {
                res.success       = "false";
                res.resultMessage = "请求method错误";
            }



            return(res);
        }
Exemple #2
0
 /// <summary>
 /// 推送消息
 /// </summary>
 /// <param name="reqPushMsgDto">消息实体</param>
 /// <param name="httpContext"></param>
 /// <returns></returns>
 public async Task <ResModel <JObject> > getOrderPushMsg(ReqPushMsgDto reqPushMsgDto, HttpContext httpContext)
 {
     return(await _unionDal.getOrderPushMsg(reqPushMsgDto, httpContext));
 }
Exemple #3
0
        /// <summary>
        /// 推送消息
        /// </summary>
        /// <param name="addMsg"></param>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        public async Task <ResModel <JObject> > getOrderPushMsg(ReqPushMsgDto reqPushMsgDto, HttpContext httpContext)
        {
            ResModel <JObject> res = new ResModel <JObject>();

            res.success       = "success";
            res.resultMessage = "推送消息成功!";

            if (string.IsNullOrEmpty(reqPushMsgDto.msgInfo))
            {
                res.success       = "false";
                res.resultMessage = "msgInfo为空";
                res.resultCode    = "";
                return(res);
            }
            if (string.IsNullOrEmpty(reqPushMsgDto.type))
            {
                res.success       = "false";
                res.resultMessage = "type为空";
                res.resultCode    = "";
                return(res);
            }
            string strConn = _unDbConnection.GetDbConnStr();

            using (IDbConnection conn = DapperHelper.GetOpenConnection(strConn, DbProvider.SqlServer))
            {
                IDbTransaction transaction = conn.BeginTransaction();
                if (reqPushMsgDto.type == "2")     //物流订单确认
                {
                    try
                    {
                        var id  = 0;
                        var obj = JsonConvert.DeserializeObject <CfmMsg>(reqPushMsgDto.msgInfo);
                        //记录接口调用
                        string ipStr  = httpContext.Connection.RemoteIpAddress.ToString();
                        string sqlstr = @" insert into INTERFACE_CALL_LOG(FUNCTION_NAME,FUNCTION_PARAM,Ip,CALL_DATE)
                            select 'LogiticOrderConfirm ','ReqPushCfmMsgDto;HttpContext',@ip,getdate()";
                        await conn.ExecuteAsync(sqlstr, new { ip = ipStr }, transaction);

                        //确认消息的情况:记录推送过来的消息
                        if (obj.stype == "1")
                        {
                            //总价格,stype=1时为必填
                            if (string.IsNullOrEmpty(obj.totalPrice))
                            {
                                res.success       = "false";
                                res.resultMessage = "总价格为空!";
                                res.result        = JObject.FromObject(new ResMsgDto()
                                {
                                    msg = "推送消息失败!"
                                });
                                return(res);
                            }
                            else
                            {
                                sqlstr = @"insert into T_PUSHMSG (OrderNO,Types,MsgTime,TotalPrice,AddDate,EleContractNo,MsgType,needReply) 
select @orderNo,2,@msgTime,@totalPrice,getdate(),@eleContractNo,1,@needReply; SELECT CAST(SCOPE_IDENTITY() as int)";

                                id = await conn.QueryFirstAsync <int>(sqlstr, new
                                {
                                    orderNo       = obj.logisticsOrderNo,
                                    msgTime       = obj.time,
                                    totalPrice    = obj.totalPrice,
                                    eleContractNo = obj.eleContractNo,
                                    needReply     = obj.needReply
                                }, transaction);
                            }
                        }
                        else if (obj.stype == "2") //取消
                        {
                            sqlstr = @"insert into T_PUSHMSG (OrderNO,Types,MsgTime,AddDate,MsgType,needReply) 
select @orderNo,2,@msgTime,getdate(),2,@needReply; 
SELECT CAST(SCOPE_IDENTITY() as int)";

                            id = await conn.QueryFirstAsync <int>(sqlstr, new { orderNo = obj.logisticsOrderNo, msgTime = obj.time, needReply = obj.needReply }, transaction);
                        }
                        //插入记录到消息队列中,待调用物流单查询接口推送确认结果给平台
                        sqlstr = @"insert into T_MsgQueue(InterfaceId,InterfaceName,ParamId,ProcessState) select '2.8','物流订单接收确认接口',@id,0";
                        await conn.ExecuteAsync(sqlstr, new { id = obj.logisticsOrderNo }, transaction);

                        res.result = JObject.FromObject(new ResMsgDto()
                        {
                            msg = "推送消息成功!"
                        });

                        transaction.Commit();
                        conn.Close();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        res.success       = "false";
                        res.resultMessage = "推送消息失败:" + ex.Message;
                        res.result        = JObject.FromObject(new ResMsgDto()
                        {
                            msg = "推送消息失败!"
                        });
                    }
                }
                else if (reqPushMsgDto.type == "3")  //新增追加费用
                {
                    try
                    {
                        var id  = 0;
                        var obj = JsonConvert.DeserializeObject <AddExpMsg>(reqPushMsgDto.msgInfo);

                        //记录接口调用
                        string ipStr  = httpContext.Connection.RemoteIpAddress.ToString();
                        string sqlstr = @" insert into INTERFACE_CALL_LOG(FUNCTION_NAME,FUNCTION_PARAM,Ip,CALL_DATE)
                            select 'LogiticOrderAddExpense ','ReqPushAddExpMsgDto;HttpContext',@ip,getdate()";
                        await conn.ExecuteAsync(sqlstr, new { ip = ipStr }, transaction);

                        //记录推送过来的消息
                        sqlstr = @"insert into T_PUSHMSG (OrderNO,Types,MsgTime,AddedExpense,AddDate,Remark) 
select @orderNo,3,@msgTime,@addedExpense,getdate(),@remark; SELECT CAST(SCOPE_IDENTITY() as int)";

                        //消息在平台推送物流单消息表中的标识id
                        id = await conn.QueryFirstAsync <int>(sqlstr, new
                        {
                            orderNo      = obj.logisticsOrderNo,
                            msgTime      = obj.time,
                            addedExpense = obj.addedExpense,
                            remark       = obj.remark,
                        }, transaction);

                        //插入记录到消息队列中,待调用物流单查询接口推送确认结果给平台
                        sqlstr = @"insert into T_MsgQueue(InterfaceId,InterfaceName,ParamId,ProcessState) select '2.13','查看追加费用接口',@id,0";
                        await conn.ExecuteAsync(sqlstr, new { id = obj.logisticsOrderNo }, transaction);

                        res.result = JObject.FromObject(new ResMsgDto()
                        {
                            msg = "推送消息成功!"
                        });

                        transaction.Commit();
                        conn.Close();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        res.success       = "false";
                        res.resultMessage = "推送消息失败:" + ex.Message;
                        res.result        = JObject.FromObject(new ResMsgDto()
                        {
                            msg = "推送消息失败!"
                        });
                    }
                }
                else if (reqPushMsgDto.type == "6")  //妥投驳回
                {
                    try
                    {
                        var id  = 0;
                        var obj = JsonConvert.DeserializeObject <DelivRejMsg>(reqPushMsgDto.msgInfo);

                        //记录接口调用
                        string ipStr  = httpContext.Connection.RemoteIpAddress.ToString();
                        string sqlstr = @" insert into INTERFACE_CALL_LOG(FUNCTION_NAME,FUNCTION_PARAM,Ip,CALL_DATE)
                            select 'LogiticOrderDelivRej ','ReqPushDelivRejMsgDto;HttpContext',@ip,getdate()";
                        await conn.ExecuteAsync(sqlstr, new { ip = ipStr }, transaction);

                        //记录推送过来的消息
                        sqlstr = @"insert into T_PUSHMSG (OrderNO,Types,MsgTime,DeliveredType,DeliveredInfo,DeliveredPerson,AddDate) 
select @orderNo,6,@time,2,@deliveredInfo,@deliveredPerson,getdate(); SELECT CAST(SCOPE_IDENTITY() as int)";

                        //消息在平台推送物流单消息表中的标识id
                        id = await conn.QueryFirstAsync <int>(sqlstr, new
                        {
                            orderNo         = obj.logisticsOrderNo,
                            time            = obj.time,
                            deliveredInfo   = obj.deliveredInfo,
                            deliveredPerson = obj.deliveredPerson,
                        }, transaction);

                        //插入记录到消息队列中,待调用物流单查询接口推送确认结果给平台
                        sqlstr = @"insert into T_MsgQueue(InterfaceId,InterfaceName,ParamId,ProcessState) select '2.16','妥投/拒收信息推送接口',@id,0";
                        await conn.ExecuteAsync(sqlstr, new { id = obj.logisticsOrderNo }, transaction);

                        res.result = JObject.FromObject(new ResMsgDto()
                        {
                            msg = "推送消息成功!"
                        });

                        transaction.Commit();
                        conn.Close();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        res.success       = "false";
                        res.resultMessage = "推送消息失败:" + ex.Message;
                        res.result        = JObject.FromObject(new ResMsgDto()
                        {
                            msg = "推送消息失败!"
                        });
                    }
                }
                else if (reqPushMsgDto.type == "7") //线路价格更新审批结果推送
                {
                    try
                    {
                        var id  = 0;
                        var obj = JsonConvert.DeserializeObject <PriceMsg>(reqPushMsgDto.msgInfo);

                        //记录接口调用
                        string ipStr  = httpContext.Connection.RemoteIpAddress.ToString();
                        string sqlstr = @" insert into INTERFACE_CALL_LOG(FUNCTION_NAME,FUNCTION_PARAM,Ip,CALL_DATE)
                            select 'RoutPriceUpdate','ReqPushRoutPriceMsgDto;HttpContext',@ip,getdate()";
                        await conn.ExecuteAsync(sqlstr, new { ip = ipStr }, transaction);

                        //记录推送过来的消息
                        sqlstr = @"insert into T_PUSHMSG (Types,RouteAgreementNo,ApplyNO,CheckState,MsgTime,remark,AddDate) 
select 7,@routeAgreementNo,@applyNO,@checkState,@time,@remark,getdate(); SELECT CAST(SCOPE_IDENTITY() as int)";

                        //消息在平台推送物流单消息表中的标识id
                        id = await conn.QueryFirstAsync <int>(sqlstr, new
                        {
                            routeAgreementNo = obj.routeAgreementNo,
                            applyNO          = obj.applyNo,
                            checkState       = obj.status,
                            time             = obj.time,
                            remark           = obj.remark
                        }, transaction);

                        DynamicParameters dp = new DynamicParameters();

                        dp.Add("@ApplyNo", obj.applyNo);
                        dp.Add("@Status", obj.status);

                        //审批未通过时,找到申请单号对应的价格表更新的审批状态;审批通过时,不存在则新增,存在则更新
                        var result = await conn.ExecuteScalarAsync <string>("UN_CheckRoutPrice", dp, transaction, commandType : CommandType.StoredProcedure);

                        if (result.ToString() == "1")
                        {
                            res.result = JObject.FromObject(new ResMsgDto()
                            {
                                msg = "推送消息成功!"
                            });
                        }

                        transaction.Commit();
                        conn.Close();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        res.success       = "false";
                        res.resultMessage = "推送消息失败:" + ex.Message;
                        res.result        = JObject.FromObject(new ResMsgDto()
                        {
                            msg = "推送消息失败!"
                        });
                    }
                }
                else if (reqPushMsgDto.type == "8") //追加费用确认
                {
                    try
                    {
                        var id  = 0;
                        var obj = JsonConvert.DeserializeObject <pactMsg>(reqPushMsgDto.msgInfo);

                        //记录接口调用
                        string ipStr  = httpContext.Connection.RemoteIpAddress.ToString();
                        string sqlstr = @" insert into INTERFACE_CALL_LOG(FUNCTION_NAME,FUNCTION_PARAM,Ip,CALL_DATE)
                            select 'LogiticOrderAddExpComf','ReqPushAddExpCofmMsgDto;HttpContext',@ip,getdate()";
                        await conn.ExecuteAsync(sqlstr, new { ip = ipStr }, transaction);

                        //记录推送过来的消息
                        sqlstr = @"insert into T_PUSHMSG (OrderNO,Types,MsgTime,NeedEleContract,EleContractNo,AddDate) 
select @orderNo,8,@time,@needEleContract,@eleContractNo,getdate(); SELECT CAST(SCOPE_IDENTITY() as int)";

                        //消息在平台推送物流单消息表中的标识id
                        id = await conn.QueryFirstAsync <int>(sqlstr, new
                        {
                            orderNo         = obj.logisticsOrderNo,
                            time            = obj.time,
                            needEleContract = obj.needEleContract,
                            eleContractNo   = obj.eleContractNo,
                        }, transaction);

                        //插入记录到消息队列中,待调用物流单查询接口推送确认结果给平台
                        sqlstr = @"insert into T_MsgQueue(InterfaceId,InterfaceName,ParamId,ProcessState) select '2.11','电子合同查询接口',@id,0";
                        await conn.ExecuteAsync(sqlstr, new { id = obj.logisticsOrderNo }, transaction);

                        res.result = JObject.FromObject(new ResMsgDto()
                        {
                            msg = "推送消息成功!"
                        });

                        transaction.Commit();
                        conn.Close();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        res.success       = "false";
                        res.resultMessage = "推送消息失败:" + ex.Message;
                        res.result        = JObject.FromObject(new ResMsgDto()
                        {
                            msg = "推送消息失败!"
                        });
                    }
                }
            }

            return(res);
        }