Sfoglia il codice sorgente

眼科医院处方物流

ysj 5 anni fa
parent
commit
10ae16a155

+ 25 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/monitorPlatform/MonitorPlatformController.java

@ -0,0 +1,25 @@
package com.yihu.iot.controller.monitorPlatform;
import com.yihu.iot.service.monitorPlatform.MonitorPlatformService;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by yeshijie on 2020/5/11.
 */
@RestController
@RequestMapping(IotRequestMapping.Common.monitorPlatform)
@Api(tags = "健康监测平台相关操作", description = "大屏数据相关操作")
public class MonitorPlatformController extends EnvelopRestEndpoint {
    @Autowired
    private MonitorPlatformService monitorPlatformService;
}

+ 67 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/monitorPlatform/MonitorPlatformService.java

@ -0,0 +1,67 @@
package com.yihu.iot.service.monitorPlatform;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by yeshijie on 2020/5/11.
 */
@Service
public class MonitorPlatformService  {
    @Value("${spring.wlyy.url}")
    private String wlyyUrl;
    @Value("${spring.wlyy.appid}")
    private String appid;
    @Value("${spring.wlyy.appsecret}")
    private String appSecret;
    public static Map<String,String> tokenMap = new HashMap<>();
    @Autowired
    private HttpClientUtil httpClientUtil;
    /**
     * 返回accessToken
     * @return
     * @throws IOException
     */
    private synchronized String getAccessToken(){
        String token = "";
        if(tokenMap.get("token")!=null){
            token = tokenMap.get("token");
            String time = tokenMap.get("time");
            Date start = DateUtil.strToDate(time);
            long m = (System.currentTimeMillis()-start.getTime())/1000;
            long overTime = 15*6*60;//1.5小时
            if(m<overTime){
                return token;
            }
        }
        JSONObject params = new JSONObject();
        params.put("appid", appid);
        params.put("appSecret", appSecret);
        String url = "/gc/accesstoken";
        String response = httpClientUtil.sendPost(wlyyUrl + url, params.toString());
        JSONObject jsonObject = JSON.parseObject(response);
        if(jsonObject.getInteger("status")==10000){
            String accesstoken = jsonObject.getJSONObject("result").getString("accesstoken");
            tokenMap.put("token",accesstoken);
            tokenMap.put("time", DateUtil.dateToStrLong(new Date()));
            return accesstoken;
        }
        return null;
    }
}