123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package com.lemon.lifecenter.controller;
- import java.util.HashMap;
- import java.util.Map;
- import javax.servlet.http.HttpServletRequest;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import com.lemon.lifecenter.common.LifeCenterSessionController;
- import com.lemon.lifecenter.dto.AppVersionDTO;
- import com.lemon.lifecenter.dto.DeviceInfoDTO;
- import com.lemon.lifecenter.service.DeviceService;
- @RestController
- public class DeviceController {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- @Autowired
- private DeviceService deviceService;
-
- @RequestMapping(value="/mobile/getAppVersion", method = RequestMethod.POST)
- public HashMap<String, String> appVersion(@RequestBody AppVersionDTO dto) {
- HashMap<String, String> data = new HashMap<String, String>();
-
- String code = "99";
- String deviceType = dto.getDeviceType();
- if (deviceType.equals("")) {
- code = "01";
- } else {
- dto = deviceService.selectAppVersion(deviceType);
- if (dto == null) {
- code = "02";
- } else {
- code = "00";
- data.put("version", dto.getVersion());
- data.put("downloadUrl", dto.getDownloadUrl());
- }
-
- }
- data.put("code", code);
- return data;
- }
-
- /**
- * 디바이스 정보 저장
- * @param dto
- * patientIdx : 환자등록 고유번호
- * deviceType : 안드로이드 : AND, 아이폰 : IOS
- * deviceToken : 푸시 수신을 위한 토큰
- * macAddress : 디바이스 맥 어드레스
- * return code
- * 00 : 성공
- * 01 : 파라메터를 모두 받지 못함
- * 02 : 디바이스 토큰 저장 실패
- */
- @RequestMapping(value="/mobile/insertDeviceInfo", method=RequestMethod.POST)
- public Map<String, String> setDeviceInfo(@RequestBody DeviceInfoDTO dto, HttpServletRequest request) {
- HashMap<String, String> result = new HashMap<>();
- String code = "99";
-
- int patientIdx = dto.getPatientIdx();
- String deviceType = dto.getDeviceType();
- String deviceToken = dto.getDeviceToken();
- String macAddress = dto.getMacAddress();
-
- // macAddress는 현재 앱사용자의 앱버전을 받음
- // DB에 Insert 시키지 말고 세션에 저장후 menu.jsp 페이지에서 현재 앱버전 표시
- dto.setMacAddress( "" );
- LifeCenterSessionController.setSessionMobile(request, "sesMDeviceVersion", macAddress );
-
-
- if (patientIdx == 0 || deviceType.equals("") || deviceToken.equals("") || macAddress.equals("")) {
- code = "01";
- result.put("code", code);
- result.put("message", "Lack of parameters");
- return result;
- }
-
- int cnt = deviceService.selectDeviceInfoCount(dto);
- int rCnt = 0;
- if (cnt == 0) {
- deviceService.insertDeviceInfo(dto);
- rCnt = dto.getQueryCount();
- } else {
- rCnt = deviceService.updatedeviceInfo(dto);
- }
-
- if (rCnt == 0) {
- code = "02";
- result.put("code", code);
- result.put("message", "Token storage failure");
- } else {
- code = "00";
- result.put("code", code);
- result.put("message", "success");
- }
-
- return result;
- }
-
- /**
- * 디바이스 정보 제거
- * @param dto
- * patientIdx : 환자등록 고유번호
- * @return
- * code
- * 00 : 성공
- * 01 : 파라메터가 없음
- */
- @RequestMapping(value="/deleteDeviceInfo", method=RequestMethod.POST, produces = "application/json; charset=utf-8")
- public Map<String, String> deleteDeviceInfo(@RequestBody DeviceInfoDTO dto) {
- int patientIdx = dto.getPatientIdx();
- HashMap<String, String> result = new HashMap<String, String>();
- String code = "99";
- String message = "";
- if (patientIdx == 0) {
- code = "01";
- message = "Lack of parameters";
- } else {
- int cnt = deviceService.deleteDeviceInfo(patientIdx);
- code = "00";
- message = "success";
- }
-
- result.put("code", code);
- result.put("message", message);
-
- return result;
- }
- }
|