PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/weiganyi/dr-helper
Java | 64 lines | 47 code | 12 blank | 5 comment | 8 complexity | c00e971566911cec1d7d02d742aef582 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.NoticeDetail;
  5. import com.drhelper.android.listener.NoticeServerListener;
  6. import com.drhelper.common.db.DBManager;
  7. import com.drhelper.common.entity.Table;
  8. public class GetNoticeService extends Service {
  9. public String doAction(HttpSession session, String reqBody) {
  10. NoticeDetail reqNoticeDetail = null;
  11. NoticeDetail respNoticeDetail = null;
  12. String respBody = null;
  13. //parse the body
  14. try{
  15. reqNoticeDetail = JSON.parseObject(reqBody, NoticeDetail.class);
  16. }catch (Exception e) {
  17. System.out.println("GetNoticeService.doAction(): json parse body failure: " + e.getMessage());
  18. return respBody;
  19. }
  20. //get the event
  21. String event = reqNoticeDetail.getEvent();
  22. respNoticeDetail = new NoticeDetail();
  23. if (event != null) {
  24. DBManager db= new DBManager();
  25. if (event.equals(NoticeServerListener.worker.emptyTableEvent)) {
  26. //get the empty table
  27. Table table = db.getEmptyTable();
  28. if (table == null) {
  29. respNoticeDetail.setEmptyTable(false);
  30. }else {
  31. respNoticeDetail.setEmptyTable(true);
  32. }
  33. respNoticeDetail.setEvent(event);
  34. }
  35. if (event.equals(NoticeServerListener.worker.finishMenuEvent)) {
  36. //get the finish menu
  37. String user = (String) session.getAttribute("id");
  38. int num = db.getFinishMenu(user);
  39. if (num == 0) {
  40. respNoticeDetail.setFinishMenu(false);
  41. }else {
  42. respNoticeDetail.setFinishMenu(true);
  43. respNoticeDetail.setTable(num);
  44. }
  45. respNoticeDetail.setEvent(event);
  46. }
  47. }
  48. //serialize the object
  49. respBody = JSON.toJSONString(respNoticeDetail);
  50. return respBody;
  51. }
  52. }