PageRenderTime 84ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/weiganyi/dr-helper
Java | 52 lines | 38 code | 9 blank | 5 comment | 6 complexity | a7553b9623943a609c7f17a03b06e7e8 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.TwoTableOneOrder;
  5. import com.drhelper.common.db.DBManager;
  6. public class ChangeTableService extends Service {
  7. public String doAction(HttpSession session, String reqBody) {
  8. TwoTableOneOrder reqTable = null;
  9. TwoTableOneOrder respTable = null;
  10. String respBody = null;
  11. //parse the body
  12. try{
  13. reqTable = JSON.parseObject(reqBody, TwoTableOneOrder.class);
  14. }catch (Exception e) {
  15. System.out.println("ChangeTableService.doAction(): json parse body failure: " + e.getMessage());
  16. return respBody;
  17. }
  18. //check the input param
  19. int tableNum1 = reqTable.getTable1();
  20. int tableNum2 = reqTable.getTable2();
  21. if (tableNum1 == 0 || tableNum2 == 0) {
  22. System.out.println("ChangeTableService.doAction(): tableNum is null");
  23. return respBody;
  24. }
  25. respTable = new TwoTableOneOrder();
  26. //create a order and return the number
  27. DBManager db = new DBManager();
  28. int orderNum = db.changeTable(tableNum1, tableNum2);
  29. if (orderNum == 0) {
  30. respTable.setResult(false);
  31. respBody = JSON.toJSONString(respTable);
  32. return respBody;
  33. }
  34. //create the resp object
  35. respTable.setOrder(orderNum);
  36. respTable.setTable1(tableNum1);
  37. respTable.setTable2(tableNum2);
  38. respTable.setResult(true);
  39. //serialize the object
  40. respBody = JSON.toJSONString(respTable);
  41. return respBody;
  42. }
  43. }