操作json 的后台

 int flag = 0;
  HttpSession session = request.getSession();
  UserInfoBean user = (UserInfoBean) session.getAttribute("user");
  if (user != null) {
   String jsonStr = request.getParameter("json");
   System.out.println(jsonStr);
   final JSONObject json = new JSONObject(jsonStr);
   final JSONArray jsonArr = json.getJSONArray("detail");
   int shopid = json.getInt("shopid");
   int accid = json.getInt("accid");
   if (!canAdd(shopid, accid, jsonArr)) {
    flag = 1;
   } else {
    final int credtypeid = json.getInt("credtypeid");
    final Date creddate = Date.valueOf(json.getString("creddate"));
    Map map = getDefaultCredno(shopid, accid, creddate, "");
    final String credid = String.valueOf(map.get("s_newcredid"));
    final int credno = Integer.valueOf(String.valueOf(map.get("i_credno")));
    final int credcode = getDefaultCredCode(shopid, accid, credtypeid, credid);
    
    final int opid = user.getOpid();

    String sql = "INSERT INTO TB_CREDENCE (SHOPID,ACCID,CREDID,CREDCODE,CREDNO,CREDDATE,"
      + "BILLNUMBER,BILLMAKER,CHECKFLAG,POSTFLAG,CREDTYPEID,OPID,OPDATE) "
      + "VALUES(" + shopid + "," + accid + ",?,?,?,?,?,?,?,?,?,?,?)";
    TransactionStatus status = transactionManager.getTransaction(transactionDefinition);
    try {
     jdbc.update(sql, new PreparedStatementSetter() {
      public void setValues(PreparedStatement pstmt)
        throws SQLException {
       try {
        pstmt.setString(1, credid);
        pstmt.setInt(2, credcode);
        pstmt.setInt(3, credno);
        pstmt.setDate(4, creddate);
        pstmt.setInt(5, json.getInt("billnumber"));
        pstmt.setString(6, json.getString("billmaker"));
        pstmt.setString(7, "F");
        pstmt.setString(8, "F");
        pstmt.setInt(9, credtypeid);
        pstmt.setInt(10, opid);
        pstmt.setDate(11, new Date(new java.util.Date().getTime()));
       } catch (JSONException e) {
        e.printStackTrace();
       }
      }
     });

     insertCredenceDetail(jsonArr, shopid, accid, credid, 99);
     transactionManager.commit(status);
     flag = 2;
    } catch (Exception e) {
     transactionManager.rollback(status);
     e.printStackTrace();
     flag = -1;
    }
   }
  }

  net.sf.json.JSONObject json = new net.sf.json.JSONObject();
  json.put("flag", flag);
  response.setContentType("application/json,charset=utf-8");
  response.setCharacterEncoding("utf-8");
  response.setHeader("Cache-Control", "no-cache");
  PrintWriter out = response.getWriter();
  out.print(json.toString());
  out.flush();
  out.close();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值