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();