PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Server/tomcat/WEB-INF/src/com/drhelper/android/service/CreateTableService.java

https://github.com/weiganyi/dr-helper
Java | 51 lines | 37 code | 9 blank | 5 comment | 4 complexity | bc64f78cc827140f0b1add8595ed9e9a MD5 | raw file
  1. package com.drhelper.android.service;
  2. import javax.servlet.http.HttpSession;
  3. import com.alibaba.fastjson.JSON;
  4. import com.drhelper.android.bean.com.OneTableOneOrder;
  5. import com.drhelper.common.db.DBManager;
  6. public class CreateTableService extends Service {
  7. public String doAction(HttpSession session, String reqBody) {
  8. OneTableOneOrder reqTable = null;
  9. OneTableOneOrder respTable = null;
  10. String respBody = null;
  11. //parse the body
  12. try{
  13. reqTable = JSON.parseObject(reqBody, OneTableOneOrder.class);
  14. }catch (Exception e) {
  15. System.out.println("CreateTableService.doAction(): json parse body failure: " + e.getMessage());
  16. return respBody;
  17. }
  18. //check the input param
  19. int tableNum = reqTable.getTableNum();
  20. if (tableNum == 0) {
  21. System.out.println("CreateTableService.doAction(): tableNum is null");
  22. return respBody;
  23. }
  24. respTable = new OneTableOneOrder();
  25. //create a order and return the number
  26. DBManager db = new DBManager();
  27. String user = (String) session.getAttribute("id");
  28. int orderNum = db.createTable(user, tableNum);
  29. if (orderNum == 0) {
  30. respTable.setResult(false);
  31. respBody = JSON.toJSONString(respTable);
  32. return respBody;
  33. }
  34. //create the resp object
  35. respTable.setOrderNum(orderNum);
  36. respTable.setTableNum(tableNum);
  37. respTable.setResult(true);
  38. //serialize the object
  39. respBody = JSON.toJSONString(respTable);
  40. return respBody;
  41. }
  42. }