oracle存储过程

create or replace procedure APP_0200000100(p_in_str  in varchar2,
                                           p_out_str out varchar2) is
  /*******************************************************************************
  -- 函数名称  APP_0200000100 in 入参参数 out 返回结果
  -- 功能描述  消费组包接口
  ********************************************************************************/

  -- Private exception declarations 定义异常信息
  scanner_exception exception;
  pragma exception_init(scanner_exception, -20100);

  parser_exception exception;
  pragma exception_init(parser_exception, -20101);

  -- Private variable declarations 定义变量
  j_param json;

  --v_user_id   number;
  v_query_id  VARCHAR2(32);
  v_swap_date varchar2(32);
  v_ret       varchar2(2); -- 返回值 2位
  v_des       varchar2(32);
  --v_source    varchar2(20);
  --v_logid     varchar2(20);
  v_str           varchar2(1024);
  v_card_no       varchar2(20);
  v_amount        varchar2(12);
  v_track2        varchar2(38);
  v_market_id     varchar2(15);
  v_pos_water_num number;
  v_pos_code      varchar2(8); --edit by ws 160624,  v_pos_code      varchar2(6);
  v_order_id      varchar2(64);
  v_count         number;

begin
  -- 创建json对象
  j_param := json(p_in_str);

  /*  -- 校验param域是否缺少必填参数
  jl_keys := json_list('["userId", "openId", "queryId", "reqSource","swapdate","productid","amount"]');
  if false = json_util_extra.containKeys(j_param, jl_keys) then
    p_out_str := '{"resultCode":"30", "resultMsg":"param域Json缺少必填参数"}';
    return;
  end if;
  */

  -- 获取用户ID := 赋值操作 
  --v_user_id   := json_ext.get_number(j_param, 'userId');
  v_query_id  := json_ext.get_string(j_param, 'queryId');
  v_swap_date := json_ext.get_string(j_param, 'timespan');
  --v_source    := json_ext.get_string(j_param, 'reqSource');
  v_card_no := json_ext.get_string(j_param, 'cardNo');
  --v_logid     := json_ext.get_string(j_param, 'log_id'); --受赠LOG id
  v_amount    := json_ext.get_string(j_param, 'amount');
  v_track2    := json_ext.get_string(j_param, 'track2');
  v_market_id := json_ext.get_string(j_param, 'marketId');
  --需要写进去实际生产的POS
  v_pos_code := '10598501'; --针对充值开的虚拟的商户号 4000105985 POS号 10598501 20160719 该生成的商户号需要给用
  --v_pos_code := '10599602'; --测试和生产混合了,现在用测试的POS号
  --增加订单 现校验数据库中是否有该订单,如果有,则返回错误 20160715
  v_order_id := json_ext.get_string(j_param, 'orderNo');

  select count(*)
    into v_count
    from xshe_app_wb
   where order_id = v_order_id;

  if v_count > 0 then
    v_ret     := '22'; --订单号重复
    v_des     := '订单重复';
    p_out_str := '{"resultCode":"' || v_ret || '", "resultMsg":"' || v_des || '"}';
    return;
  end if;

  --赠送去重表,根据发送来的请求号来做 query_id
  begin
    insert into xshe_query_id (query_id) values (v_query_id);
    commit;
  exception
    when others then
      v_ret     := '20'; --订单号重复
      v_des     := '请求重复';
      p_out_str := '{"resultCode":"' || v_ret || '", "resultMsg":"' ||
                   v_des || '"}';
      return;
  end;

  v_pos_water_num := app_pos_waste_num_seq.nextval;

  --600000000002000001007320023500160411    13D23BC8D41C751A                    000000000001000023030516163121105990014000105990     599001000023                                                                                                             092099                                          AS7320023500160411=9909525724   
  --组包
  v_str := '60000000000200000100';
  v_str := v_str || rpad(v_card_no, 20, ' ');
  v_str := v_str || '                                    ';
  v_str := v_str || lpad(v_amount, 12, '0');
  v_str := v_str || lpad(v_pos_water_num, 6, '0');
  v_str := v_str || substr(v_swap_date, 5); --不需要年份中的2016的20
  v_str := v_str || '  '; --input_type
  v_str := v_str || v_pos_code; --'10599605'; --pos_code  --针对4000105996在测试上的值  
  v_str := v_str || rpad(v_market_id, 15, ' '); --market_id   
  v_str := v_str || substr(v_pos_code, 3) || lpad(v_pos_water_num, 6, '0'); --'trace_code  '; --trace_code   
  v_str := v_str || '  '; --return_code   
  v_str := v_str || '      '; --auth_code
  v_str := v_str ||
           '                                                                                                                                                     '; --auth_code 
  v_str := v_str || 'AP'; --version AS CP         
  v_str := v_str || lpad(v_track2, 38, ' '); --track_2 

  p_out_str := v_str;

  return;

  ----------------------------------------------------------*/
exception
  when scanner_exception then
    p_out_str := '{"resultCode":"94", "resultMsg":"Json扫描器异常"}';
  when parser_exception then
    p_out_str := '{"resultCode":"95", "resultMsg":"Json解析器异常"}';
  when others then
    p_out_str := '{"resultCode":"96", "resultMsg":"运行时异常"}';
end;

 

posted @ 2018-08-16 10:46  748573200000  阅读(194)  评论(0编辑  收藏  举报