DeviceController.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package com.lemon.lifecenter.controller;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import javax.servlet.http.HttpServletRequest;
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.web.bind.annotation.RequestBody;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.RestController;
  12. import com.lemon.lifecenter.common.LifeCenterSessionController;
  13. import com.lemon.lifecenter.dto.AppVersionDTO;
  14. import com.lemon.lifecenter.dto.DeviceInfoDTO;
  15. import com.lemon.lifecenter.service.DeviceService;
  16. @RestController
  17. public class DeviceController {
  18. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  19. @Autowired
  20. private DeviceService deviceService;
  21. @RequestMapping(value="/mobile/getAppVersion", method = RequestMethod.POST)
  22. public HashMap<String, String> appVersion(@RequestBody AppVersionDTO dto) {
  23. HashMap<String, String> data = new HashMap<String, String>();
  24. String code = "99";
  25. String deviceType = dto.getDeviceType();
  26. if (deviceType.equals("")) {
  27. code = "01";
  28. } else {
  29. dto = deviceService.selectAppVersion(deviceType);
  30. if (dto == null) {
  31. code = "02";
  32. } else {
  33. code = "00";
  34. data.put("version", dto.getVersion());
  35. data.put("downloadUrl", dto.getDownloadUrl());
  36. }
  37. }
  38. data.put("code", code);
  39. return data;
  40. }
  41. /**
  42. * 디바이스 정보 저장
  43. * @param dto
  44. * patientIdx : 환자등록 고유번호
  45. * deviceType : 안드로이드 : AND, 아이폰 : IOS
  46. * deviceToken : 푸시 수신을 위한 토큰
  47. * macAddress : 디바이스 맥 어드레스
  48. * return code
  49. * 00 : 성공
  50. * 01 : 파라메터를 모두 받지 못함
  51. * 02 : 디바이스 토큰 저장 실패
  52. */
  53. @RequestMapping(value="/mobile/insertDeviceInfo", method=RequestMethod.POST)
  54. public Map<String, String> setDeviceInfo(@RequestBody DeviceInfoDTO dto, HttpServletRequest request) {
  55. HashMap<String, String> result = new HashMap<>();
  56. String code = "99";
  57. int patientIdx = dto.getPatientIdx();
  58. String deviceType = dto.getDeviceType();
  59. String deviceToken = dto.getDeviceToken();
  60. String macAddress = dto.getMacAddress();
  61. // macAddress는 현재 앱사용자의 앱버전을 받음
  62. // DB에 Insert 시키지 말고 세션에 저장후 menu.jsp 페이지에서 현재 앱버전 표시
  63. dto.setMacAddress( "" );
  64. LifeCenterSessionController.setSessionMobile(request, "sesMDeviceVersion", macAddress );
  65. if (patientIdx == 0 || deviceType.equals("") || deviceToken.equals("") || macAddress.equals("")) {
  66. code = "01";
  67. result.put("code", code);
  68. result.put("message", "Lack of parameters");
  69. return result;
  70. }
  71. int cnt = deviceService.selectDeviceInfoCount(dto);
  72. int rCnt = 0;
  73. if (cnt == 0) {
  74. deviceService.insertDeviceInfo(dto);
  75. rCnt = dto.getQueryCount();
  76. } else {
  77. rCnt = deviceService.updatedeviceInfo(dto);
  78. }
  79. if (rCnt == 0) {
  80. code = "02";
  81. result.put("code", code);
  82. result.put("message", "Token storage failure");
  83. } else {
  84. code = "00";
  85. result.put("code", code);
  86. result.put("message", "success");
  87. }
  88. return result;
  89. }
  90. /**
  91. * 디바이스 정보 제거
  92. * @param dto
  93. * patientIdx : 환자등록 고유번호
  94. * @return
  95. * code
  96. * 00 : 성공
  97. * 01 : 파라메터가 없음
  98. */
  99. @RequestMapping(value="/deleteDeviceInfo", method=RequestMethod.POST, produces = "application/json; charset=utf-8")
  100. public Map<String, String> deleteDeviceInfo(@RequestBody DeviceInfoDTO dto) {
  101. int patientIdx = dto.getPatientIdx();
  102. HashMap<String, String> result = new HashMap<String, String>();
  103. String code = "99";
  104. String message = "";
  105. if (patientIdx == 0) {
  106. code = "01";
  107. message = "Lack of parameters";
  108. } else {
  109. int cnt = deviceService.deleteDeviceInfo(patientIdx);
  110. code = "00";
  111. message = "success";
  112. }
  113. result.put("code", code);
  114. result.put("message", message);
  115. return result;
  116. }
  117. }