Browse Source

代码修改

yeshijie 7 năm trước cách đây
mục cha
commit
8087915afa

+ 1 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/SwaggerConfig.java

@ -175,6 +175,7 @@ public class SwaggerConfig {
                        regex("/wechat/.*"),
                        regex("/nofilter/.*"),
                        regex("/idc10/.*"),
                        regex("/iot/.*"),
                        regex("/im_new/.*"),
                        regex("/dataHandling/.*"),
                        regex("/version/.*"),

+ 82 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/iot/IotDeviceService.java

@ -0,0 +1,82 @@
package com.yihu.wlyy.service.third.iot;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.util.HttpClientUtil;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
 * 物联网设备对接
 * @author yeshijie on 2018/1/3.
 */
@Service
public class IotDeviceService {
//    @Value("${}")
    private String baseUrl = "https://iot.xmtyw.cn/";
    private String grantType = "client_credentials&";
    private String clientId = "Va5yQRHlA4Fq4eR3LT0vuXV4&";
    private String clientSecret = "0rDSjzQ20XUj5itV7WRtznPQSzr5pVw2";
    @Autowired
    private HttpClientUtil httpClientUtil;
    private String accessToken = "";
    public String getAccessToken(){
        String url = baseUrl+"/oauth/2.0/token";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("grant_type",grantType));
        params.add(new BasicNameValuePair("client_id",clientId));
        params.add(new BasicNameValuePair("client_secret",clientSecret));
        String response = httpClientUtil.post(url, params, "UTF-8");
        return null;
    }
    /**
     * 设备注册及绑定
     * @return
     */
    public String registedevice(JSONObject json){
        json.put("access_token",accessToken);
        String url = baseUrl+"/registedevice";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("json",json.toString()));
        String response = httpClientUtil.post(url, params, "UTF-8");
        return null;
    }
    /**
     * 数据上传
     * @param json
     * @return
     */
    public String upload(JSONObject json){
        json.put("access_token",accessToken);
        String url = baseUrl+"/upload";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("json",json.toString()));
        String response = httpClientUtil.post(url, params, "UTF-8");
        return null;
    }
    /**
     * 查询
     * @param json
     * @return
     */
    public String search(JSONObject json){
        json.put("access_token",accessToken);
        String url = baseUrl+"/upload";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("json",json.toString()));
        String response = httpClientUtil.post(url, params, "UTF-8");
        return null;
    }
}

+ 112 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/iot/IotDeviceController.java

@ -0,0 +1,112 @@
package com.yihu.wlyy.web.third.iot;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.service.third.iot.IotDeviceService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author yeshijie on 2018/1/3.
 */
@RestController
@RequestMapping(value = "/iot",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "物联网测试类")
public class IotDeviceController extends BaseController{
    @Autowired
    private IotDeviceService iotDeviceService;
    @RequestMapping(value = "/registedevice",method = RequestMethod.POST)
    @ApiOperation("注册设备")
    public String registedevice(){
        try {
            JSONObject json = new JSONObject();
            JSONObject js = new JSONObject();
            js.put("sn","2638234828");
            js.put("ext_code","1");
            js.put("device_name","血压计-康为A206G");
            js.put("device_model","血压计-康为A206G");
            js.put("idcard","350429198905194016");
            js.put("username","邹林");
            js.put("manufacture_code","");
            js.put("manufacture_name","");
            js.put("owner_org_code","");
            js.put("owner_org_name","");
            js.put("sale_org_code","");
            js.put("sale_org_name","");
            js.put("manufacture_tel","");
            JSONArray jsonArray = new JSONArray();
            jsonArray.add(js);
            json.put("data",jsonArray);
            String re = iotDeviceService.registedevice(json);
            return write(200, "注册设备成功!", "data", re);
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "/upload1",method = RequestMethod.POST)
    @ApiOperation("不含居民身份的数据上传协议")
    public String upload1(){
        try {
            JSONObject json = new JSONObject();
            JSONObject js = new JSONObject();
            js.put("measure_time","2018-01-01 01:01:01");
            js.put("systolic","111");
            js.put("diastolic","60");
            js.put("pulse","66");
            JSONArray jsonArray = new JSONArray();
            jsonArray.add(js);
            json.put("data",jsonArray);
            json.put("sn","2638234828");
            json.put("ext_code","1");
            json.put("device_name","血压计-康为A206G");
            json.put("device_model","血压计-康为A206G");
            String re = iotDeviceService.upload(json);
            return write(200, "注册设备成功!", "data", re);
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "/upload2",method = RequestMethod.POST)
    @ApiOperation("不含居民身份的数据上传协议")
    public String upload2(){
        try {
            JSONObject json = new JSONObject();
            JSONObject js = new JSONObject();
            js.put("measure_time","2018-01-01 11:01:01");
            js.put("blood_sugar","6.7");
            JSONArray jsonArray = new JSONArray();
            jsonArray.add(js);
            json.put("data",jsonArray);
            json.put("data",jsonArray);
            json.put("sn","2638234828");
            json.put("ext_code","1");
            json.put("device_name","血压计-康为A206G");
            json.put("device_model","血压计-康为A206G");
            json.put("idcard","350429198905194016");
            json.put("username","邹林");
            String re = iotDeviceService.upload(json);
            return write(200, "注册设备成功!", "data", re);
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
}