Bläddra i källkod

新设备注册的同时,向数据资源云平台注册

yaobo 7 år sedan
förälder
incheckning
777be89bfd

+ 27 - 1
src/main/java/cn/efunbox/audio/controller/DeviceController.java

@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.sql.Timestamp;
 import java.util.*;
 
 /**
@@ -90,6 +91,7 @@ public class DeviceController {
 //        System.out.println(res);
     }
 
+
     @RequestMapping(value = "/token" ,method = RequestMethod.POST)
     public Map Login(@RequestParam long id, @RequestParam String token){
         Map map = new HashMap<>();
@@ -110,7 +112,7 @@ public class DeviceController {
     }
 
     @RequestMapping(value = "/register" ,method = RequestMethod.POST)
-    public Map Register(HttpServletRequest request){
+    public Map Register(HttpServletRequest request, HttpServletResponse response){
         Map map = new HashMap<>();
         String idChannel = request.getParameter("idChannel");
         String idDevice = request.getParameter("idDevice");
@@ -130,8 +132,32 @@ public class DeviceController {
             map.put("msg", ApiCode.PARAMETER_ERROR.getMessage());
             return map;
         }
+        //向云平台注册设备
+        String ip = HttpUtil.getIpAddress(request);
+        System.out.println("start:"+ip);
+        String res = userHttp.Register(UUID.randomUUID().toString().substring(0, 31),
+                idChannel, ip, idDevice, idDevice);
+        System.out.println(res);
+        Map mapRes = JSONObject.parseObject(res);
+        System.out.println(mapRes.toString());
+        if(Integer.valueOf(mapRes.get("code").toString())!=200){
+            map.put("code", ApiCode.OPERATION_FAIL.getCode());
+            map.put("msg", ApiCode.OPERATION_FAIL.getMessage());
+            return map;
+        }
+        mapRes = JSONObject.parseObject(mapRes.get("data").toString());
+
         Device device = deviceService.Register(Long.valueOf(idChannel), Long.valueOf(idDevice));
         if(device!=null){
+            //记录云平台的账号信息
+            device.setIaas_eid(mapRes.get("eid").toString());
+            device.setIaas_uid(mapRes.get("uid").toString());
+            device.setIaas_name(idDevice);
+            device.setIaas_pwd(idDevice);
+            device.setIaas_token(mapRes.get("token").toString());
+            device.setIaas_expiration(new Timestamp(Long.valueOf(mapRes.get("expiration").toString())));
+            device = deviceService.Update(device);
+
             map.put("code", ApiCode.OK.getCode());
             Map data = new HashMap<>();
             data.put("id", device.getId());

+ 24 - 0
src/main/java/cn/efunbox/audio/entity/Device.java

@@ -60,6 +60,30 @@ public class Device implements Serializable, Cloneable{
 //    private Date updated;
     private Timestamp updated;
 
+    //在资源平台的账号信息,学号
+    @Column
+    private String iaas_eid;
+
+    //在资源平台的账号信息,uuid
+    @Column
+    private String iaas_uid;
+
+    //在资源平台的账号信息,设备id
+    @Column
+    private String iaas_name;
+
+    //在资源平台的账号信息,设备密码
+    @Column
+    private String iaas_pwd;
+
+    //在资源平台的账号信息,访问token
+    @Column
+    private String iaas_token;
+
+    //在资源平台的账号信息,访问token过期时间
+    @Column
+    private Timestamp iaas_expiration;
+
     //创建时间
     @Column
 //    @Temporal(TemporalType.TIMESTAMP)

+ 2 - 0
src/main/java/cn/efunbox/audio/utils/ApiCode.java

@@ -31,6 +31,8 @@ public class ApiCode extends AbstractApiCode {
     public static final ApiCode RECORD_EXIST = new ApiCode("记录已存在", 531);
     public static final int _C_PARAMETER_INVALID = 540;
     public static final ApiCode PARAMETER_INVALID = new ApiCode("参数验证不通过", 540);
+    public static final int _C_OPERATION_FAIL = 550;
+    public static final ApiCode OPERATION_FAIL = new ApiCode("操作失败", 550);
 
     protected ApiCode(String message, int code) {
         super(code, message);