Browse Source

푸시 수신을 위한 디바이스 정보 저장, 로그아웃시 디바이스 정보 초기화 api 개발

junekeunsong 4 years ago
parent
commit
f1e9e57bdd

+ 87 - 0
src/main/java/com/lemon/lifecenter/controller/RestApiController.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.lemon.lifecenter.dto.AppVersionDTO;
+import com.lemon.lifecenter.dto.DeviceInfoDTO;
 import com.lemon.lifecenter.service.RestApiService;
 
 @RestController
@@ -46,4 +47,90 @@ public class RestApiController {
         data.put("code", code);
         return data;
     }
+    
+    /**
+     * 디바이스 정보 저장
+     * @param dto
+     * patientIdx : 환자등록 고유번호
+     * deviceType : 안드로이드 : AND, 아이폰 : IOS
+     * deviceToken : 푸시 수신을 위한 토큰
+     * macAddress : 디바이스 맥 어드레스
+     * return code
+     * 00 : 성공
+     * 01 : 파라메터를 모두 받지 못함
+     * 02 : 디바이스 토큰 저장 실패
+     */
+    @RequestMapping(value="/insertDeviceInfo", method=RequestMethod.POST)
+    public Map<String, String> setDeviceInfo(@RequestBody DeviceInfoDTO dto) {
+        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();
+        
+        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 = restApiService.selectDeviceInfoCount(dto);
+        int rCnt = 0;
+        if (cnt == 0) {
+            restApiService.insertDeviceInfo(dto);
+            rCnt = dto.getQueryCount();
+        } else {
+            rCnt = restApiService.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");
+        }
+        
+        logger.error("patientIdx -- > " + dto.getPatientIdx());
+        logger.error("deviceType -- > " + dto.getDeviceType());
+        logger.error("deviceToken -- > " + dto.getDeviceToken());
+        logger.error("macAddress -- > " + dto.getMacAddress());
+        
+        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 = restApiService.deleteDeviceInfo(patientIdx);
+            code = "00";
+            message = "success";
+        }
+        
+        result.put("code", code);
+        result.put("message", message);
+        
+        return result;
+    }
 }

+ 41 - 0
src/main/java/com/lemon/lifecenter/dto/DeviceInfoDTO.java

@@ -0,0 +1,41 @@
+package com.lemon.lifecenter.dto;
+
+public class DeviceInfoDTO {
+    private int patientIdx     = 0;
+    private String deviceType  = "";
+    private String deviceToken = "";
+    private String macAddress  = "";
+    private int queryCount     = 0;
+    
+    public int getPatientIdx() {
+        return patientIdx;
+    }
+    public void setPatientIdx(int patientIdx) {
+        this.patientIdx = patientIdx;
+    }
+    public String getDeviceType() {
+        return deviceType;
+    }
+    public void setDeviceType(String deviceType) {
+        this.deviceType = deviceType;
+    }
+    public String getDeviceToken() {
+        return deviceToken;
+    }
+    public void setDeviceToken(String deviceToken) {
+        this.deviceToken = deviceToken;
+    }
+    public String getMacAddress() {
+        return macAddress;
+    }
+    public void setMacAddress(String macAddress) {
+        this.macAddress = macAddress;
+    }
+    public int getQueryCount() {
+        return queryCount;
+    }
+    
+    public void setQueryCount(int queryCount) {
+        this.queryCount = queryCount;
+    }
+}

+ 5 - 0
src/main/java/com/lemon/lifecenter/mapper/RestApiMapper.java

@@ -4,9 +4,14 @@ import org.apache.ibatis.annotations.Mapper;
 import org.springframework.stereotype.Repository;
 
 import com.lemon.lifecenter.dto.AppVersionDTO;
+import com.lemon.lifecenter.dto.DeviceInfoDTO;
 
 @Repository
 @Mapper
 public interface RestApiMapper {
     public AppVersionDTO selectAppVersion(String deviceType);
+    public int selectDeviceInfoCount(DeviceInfoDTO dto);
+    public void insertDeviceInfo(DeviceInfoDTO dto);
+    public int updatedeviceInfo(DeviceInfoDTO dto);
+    public int deleteDeviceInfo(int patientIdx);
 }

+ 17 - 0
src/main/java/com/lemon/lifecenter/service/RestApiService.java

@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.lemon.lifecenter.dto.AppVersionDTO;
+import com.lemon.lifecenter.dto.DeviceInfoDTO;
 import com.lemon.lifecenter.mapper.RestApiMapper;
 
 @Service
@@ -14,4 +15,20 @@ public class RestApiService {
     public AppVersionDTO selectAppVersion(String deviceType) {
         return mapper.selectAppVersion(deviceType);
     }
+    
+    public int selectDeviceInfoCount(DeviceInfoDTO dto) {
+        return mapper.selectDeviceInfoCount(dto);
+    }
+    
+    public void insertDeviceInfo(DeviceInfoDTO dto) {
+        mapper.insertDeviceInfo(dto);
+    }
+    
+    public int updatedeviceInfo(DeviceInfoDTO dto) {
+        return mapper.updatedeviceInfo(dto);
+    }
+    
+    public int deleteDeviceInfo(int patientIdx) {
+        return mapper.deleteDeviceInfo(patientIdx);
+    }
 }

+ 40 - 0
src/main/resources/mybatis/mapper/api/api.xml

@@ -10,4 +10,44 @@
              WHERE DEVICE_TYPE = #{deviceType}
         ]]>
     </select>
+        <select id="selectDeviceInfoCount" parameterType="DeviceInfoDTO" resultType="int">
+        <![CDATA[
+            SELECT COUNT(*) AS CNT
+              FROM PUSH_DEVICE_INFO
+             WHERE 1 = 1
+               AND PATIENT_IDX = #{patientIdx}
+        ]]>
+    </select>
+    
+    <insert id="insertDeviceInfo" parameterType="DeviceInfoDTO">
+        <selectKey keyProperty="queryCount" resultType="int" order="AFTER">
+            <![CDATA[
+                SELECT COUNT(*) queryCount FROM PUSH_DEVICE_INFO WHERE PATIENT_IDX = #{patientIdx}
+            ]]>
+        </selectKey>
+        <![CDATA[
+            INSERT INTO PUSH_DEVICE_INFO
+                        (PATIENT_IDX,   DEVICE_TYPE,   DEVICE_KEY,     MAC_ADDRESS,   CREATE_DATE)
+                 VALUES (#{patientIdx}, #{deviceType}, #{deviceToken}, #{macAddress}, NOW())
+        ]]>
+    </insert>
+    <update id="updatedeviceInfo" parameterType="DeviceInfoDTO">
+        <![CDATA[
+            UPDATE PUSH_DEVICE_INFO
+               SET UPDATE_DATE  = NOW(),
+                   DEVICE_TYPE  = #{deviceType},
+                   DEVICE_KEY   = #{deviceToken},
+                   MAC_ADDRESS  = #{macAddress}
+             WHERE PATIENT_IDX  = #{patientIdx}
+        ]]>
+    </update>
+    
+    <delete id="deleteDeviceInfo" parameterType="int">
+        <![CDATA[
+            UPDATE PUSH_DEVICE_INFO
+               SET UPDATE_DATE = NOW(),
+                   DEVICE_KEY = ''
+             WHERE PATIENT_IDX = #{patientIdx}
+        ]]>
+    </delete>
 </mapper>