PageRenderTime 2510ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/weiganyi/dr-helper
Java | 63 lines | 49 code | 9 blank | 5 comment | 12 complexity | 95b0131ff7838d7a6957a632d035b1b7 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.android.util.LogicException;
  6. import com.drhelper.common.db.DBManager;
  7. public class CheckOrderService extends Service {
  8. public String doAction(HttpSession session, String reqBody) {
  9. OneTableOneOrder reqOrder = null;
  10. OneTableOneOrder respOrder = null;
  11. String respBody = null;
  12. //parse the body
  13. try{
  14. reqOrder = JSON.parseObject(reqBody, OneTableOneOrder.class);
  15. }catch (Exception e) {
  16. System.out.println("CheckOrderService.doAction(): json parse body failure: " + e.getMessage());
  17. return respBody;
  18. }
  19. //check the input param
  20. int tableNum = reqOrder.getTableNum();
  21. int orderNum = reqOrder.getOrderNum();
  22. if (tableNum == 0 && orderNum == 0) {
  23. System.out.println("CheckOrderService.doAction(): tableNum and orderNum is null");
  24. return respBody;
  25. }
  26. respOrder = new OneTableOneOrder();
  27. DBManager db = new DBManager();
  28. try {
  29. //check if order is exist
  30. if (tableNum != 0) {
  31. orderNum = db.getOrderByTable(tableNum);
  32. if (orderNum == 0) {
  33. throw new LogicException();
  34. }
  35. }else if (orderNum != 0) {
  36. orderNum = db.getOrderByOrder(orderNum);
  37. if (orderNum == 0) {
  38. throw new LogicException();
  39. }
  40. }
  41. respOrder.setResult(true);
  42. }catch (LogicException e) {
  43. System.out.println("CheckOrderService.doAction(): catch LogicException: " + e.getMessage());
  44. respOrder.setResult(false);
  45. }finally {
  46. //create the resp object
  47. respOrder.setOrderNum(orderNum);
  48. respOrder.setTableNum(tableNum);
  49. }
  50. //serialize the object
  51. respBody = JSON.toJSONString(respOrder);
  52. return respBody;
  53. }
  54. }