Browse Source

增加扫码回调接口

guozhaoshun 6 years ago
parent
commit
e77b72262c

+ 85 - 0
rankin-api-web/src/main/java/cn/rankin/apiweb/controller/QRcodeController.java

@@ -3,12 +3,17 @@ package cn.rankin.apiweb.controller;
 import cn.rankin.apiweb.assist.resolver.NeedUser;
 import cn.rankin.apiweb.service.user.UserService;
 import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.common.utils.util.FastJsonUtils;
 import cn.rankin.data.api.app.vo.DeviceUserVo;
 import cn.rankin.data.api.user.vo.QRCodeVo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
 
 @Slf4j
 @RestController
@@ -37,5 +42,85 @@ public class QRcodeController {
         return userService.queryLastQRCode(eid);
     }
 
+    @RequestMapping(value = "/callback", method = RequestMethod.POST)
+    public APIResult callback(@RequestParam("data") String data)
+    {
+
+        return userService.qrcodeCallback(data);
+    }
+
+
+    public static String getJson (){
+
+        //二维码信息
+        Map<String,Object> qrcode = new HashMap<>();
+        qrcode.put("user","100166661101001");
+        qrcode.put("time",new Date().getTime());
+
+        //扫码定位信息
+        Map<String,Object> position = new HashMap<>();
+        position.put("lat","27.10444444");
+        position.put("lng","101.5688746");
+        position.put("precise","位置精确度低");
+        position.put("address","湖南省长沙市五一大道壹号公馆");
+
+        //扫码人老师信息
+        Map<String,Object> teacher_info = new HashMap<>();
+        teacher_info.put("real_name","方老师");
+        teacher_info.put("mobile","17319266010");
+        teacher_info.put("position","校长");
+        teacher_info.put("en_code","10056");
+
+
+        //扫码人校区信息
+        Map<String,Object> campus_info = new HashMap<>();
+        campus_info.put("campus_name","芙蓉校区");
+        campus_info.put("en_code","10056");
+        campus_info.put("lat","27.10444444");
+        campus_info.put("lng","101.5688746");
+
+        //其他附加消息
+        Map<String,Object> attach = new HashMap<>();
+
+
+
+        Map<String,Object> data = new HashMap<>();
+        data.put("qrcode",qrcode);
+        data.put("position",position);
+        data.put("teacher_info",teacher_info);
+        data.put("campus_info",campus_info);
+        data.put("attach",attach);
+
+
+
+        Map<String,Object> result = new HashMap<>();
+        result.put("code","0");
+        result.put("status",true);
+        result.put("msg","扫码成功");
+        result.put("data",data);
+        result.put("user","100166661101001");
+
+
+        String json = FastJsonUtils.toJSONNoFeatures(result);
+        System.out.println(json);
+        return json;
+
+    }
+
+
+    public static void main(String[] args){
+        String json = getJson();
+
+        Map<Object, Object> objectMap = FastJsonUtils.stringToCollect(json);
+
+        Object code = objectMap.get("code");
+        Object status = objectMap.get("status");
+        Object msg = objectMap.get("msg");
+        Object data = objectMap.get("data");
+
+        System.out.println("=============");
+
+    }
+
 }
 

+ 1 - 0
rankin-api-web/src/main/java/cn/rankin/apiweb/intercepter/RequestSignatureInterceptor.java

@@ -44,6 +44,7 @@ public class RequestSignatureInterceptor implements HandlerInterceptor {
 
     static {
         ignorePaths.add("/token");
+        ignorePaths.add("/qrcode/callback");
     }
 
     @Autowired

+ 8 - 0
rankin-api-web/src/main/java/cn/rankin/apiweb/service/user/UserClient.java

@@ -79,6 +79,9 @@ public interface UserClient
     @RequestMapping(value = "/qrcode/last", method = RequestMethod.GET)
     QRCodeVo queryLastQRCode(@RequestParam("eid") String eid);
 
+    @RequestMapping(value = "/qrcode/callback", method = RequestMethod.POST)
+    APIResult qrcodeCallback(@RequestParam("data")String data);
+
 
     @Component
     class UserServiceHystrix implements UserClient
@@ -181,6 +184,11 @@ public interface UserClient
             return null;
         }
 
+        @Override
+        public APIResult qrcodeCallback(String data) {
+            return null;
+        }
+
 
     }
 }

+ 4 - 0
rankin-api-web/src/main/java/cn/rankin/apiweb/service/user/UserService.java

@@ -523,4 +523,8 @@ public class UserService
         }
         return APIResult.ok(vo);
     }
+
+    public APIResult qrcodeCallback(String data) {
+        return userClient.qrcodeCallback(data);
+    }
 }

+ 93 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/controller/QRCodeController.java

@@ -1,11 +1,18 @@
 package cn.rankin.userservice.controller;
 
+import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.common.utils.util.FastJsonUtils;
 import cn.rankin.data.api.user.dto.QRCodeDTO;
+import cn.rankin.data.api.user.entity.LocationInfo;
 import cn.rankin.data.api.user.entity.QRCode;
+import cn.rankin.userservice.service.LocationInfoService;
 import cn.rankin.userservice.service.QRCodeService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Date;
+import java.util.Map;
+
 @RestController
 @RequestMapping(value = "/qrcode")
 public class QRCodeController {
@@ -13,6 +20,9 @@ public class QRCodeController {
     @Autowired
     private QRCodeService qrcodeService;
 
+    @Autowired
+    private LocationInfoService locationInfoService;
+
     @RequestMapping(method = RequestMethod.POST)
     public QRCode add(@RequestBody QRCodeDTO dto) {
         return qrcodeService.add(dto);
@@ -23,4 +33,87 @@ public class QRCodeController {
         return qrcodeService.findLastOne(eid);
     }
 
+    @RequestMapping(value = "/callback", method = RequestMethod.POST)
+    public APIResult callback(@RequestParam("data") String data)
+    {
+
+        Map<String, Object> requestMap = FastJsonUtils.stringToCollect(data);
+
+        boolean status = (boolean) requestMap.get("status");
+        Map<String, Object> dataMap = (Map<String, Object>) requestMap.get("data");
+
+
+        Map<String, Object> qrcodeMap = (Map<String, Object>) dataMap.get("qrcode");
+        String eid = (String) qrcodeMap.get("user");
+        long time = (long) qrcodeMap.get("time");
+
+        QRCode qrcode = new QRCode();
+        qrcode.setEid(eid);
+        //qrcode.setTime(new Date(time));
+
+        QRCode entity = qrcodeService.findFirst(qrcode);
+
+        if(status){
+            qrcodeCallback(eid, qrcode.getSimple(), dataMap);
+            entity.setStatus(2);
+            qrcodeService.update(entity);
+            return APIResult.ok("扫码成功");
+        }else{
+            entity.setStatus(1);
+            qrcodeService.update(entity);
+            return APIResult.ok("扫码失败");
+        }
+
+    }
+
+    /**
+     * 处理位置信息
+     * @param dataMap
+     */
+    private void qrcodeCallback(String eid,String simple ,Map<String,Object> dataMap) {
+
+        Map<String,Object> position = (Map<String, Object>) dataMap.get("position");
+        String lat = (String) position.get("lat");
+        String lng = (String) position.get("lng");
+        String precise = (String) position.get("precise");
+        String address = (String) position.get("address");
+
+        Map<String,Object> teacher_info = (Map<String, Object>) dataMap.get("teacher_info");
+        String tRealName = (String) teacher_info.get("real_name");
+        String tMobile = (String) teacher_info.get("mobile");
+        String tPosition = (String) teacher_info.get("position");
+        String tEnCode = (String) teacher_info.get("en_code");
+
+
+        Map<String,Object> campus_info = (Map<String, Object>) dataMap.get("campus_info");
+        String campusName = (String) campus_info.get("campus_name");
+        String cEnCode = (String) campus_info.get("en_code");
+        String cLat = (String) campus_info.get("lat");
+        String cLng = (String) campus_info.get("lng");
+        Map<String,Object> attach = (Map<String, Object>) dataMap.get("attach");
+
+
+        LocationInfo locationInfo = new LocationInfo();
+        locationInfo.setEid(eid);
+        locationInfo.setSimple(simple);
+        locationInfo.setAddress(address);
+        locationInfo.setLat(lat);
+        locationInfo.setLng(lng);
+        locationInfo.setPrecise(precise);
+
+
+        locationInfo.setTRealName(tRealName);
+        locationInfo.setTEnCode(tEnCode);
+        locationInfo.setTMobile(tMobile);
+        locationInfo.setTPosition(tPosition);
+
+        locationInfo.setCampusName(campusName);
+        locationInfo.setCEnCode(cEnCode);
+        locationInfo.setCLat(cLat);
+        locationInfo.setCLng(cLng);
+
+        locationInfoService.add(locationInfo);
+
+    }
+
 }

+ 8 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/repository/LocationInfoRepository.java

@@ -0,0 +1,8 @@
+package cn.rankin.userservice.repository;
+
+import cn.rankin.common.utils.jpa.BasicJpaRepository;
+import cn.rankin.data.api.user.entity.LocationInfo;
+
+public interface LocationInfoRepository extends BasicJpaRepository<LocationInfo, String> {
+
+}

+ 17 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/service/LocationInfoService.java

@@ -0,0 +1,17 @@
+package cn.rankin.userservice.service;
+
+import cn.rankin.data.api.user.entity.LocationInfo;
+import cn.rankin.userservice.repository.LocationInfoRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class LocationInfoService {
+
+    @Autowired
+    private LocationInfoRepository locationInfoRepository;
+
+    public void add(LocationInfo locationInfo) {
+        locationInfoRepository.save(locationInfo);
+    }
+}

+ 8 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/service/QRCodeService.java

@@ -35,4 +35,12 @@ public class QRCodeService {
         }
         return qrCode;
     }
+
+    public QRCode findFirst(QRCode simple) {
+        return qrcodeRepository.findFirst(simple);
+    }
+
+    public void update(QRCode qrcode) {
+        qrcodeRepository.update(qrcode);
+    }
 }