Browse Source

爱牵挂

yeshijie 3 years ago
parent
commit
e4fd00cde7

+ 16 - 9
common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientUtil.java

@ -506,15 +506,22 @@ public class HttpClientUtil {
        return response;
    }
    public org.springframework.http.HttpEntity<JSONObject> aqgCookieHttp(String url, MultiValueMap<String, String> params,HttpMethod method,String cookie) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/x-www-form-urlencoded");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        headers.add("Cookie",cookie);
        org.springframework.http.HttpEntity<MultiValueMap<String, String>> request = new org.springframework.http.HttpEntity<>(params, headers);
        org.springframework.http.HttpEntity<JSONObject> response = restTemplate.exchange(url, method, request, JSONObject.class);
        return response;
    }
//    public static void main(String[] args) {
//        JSONObject param = new JSONObject();
//        param.put("username","13559485270");
//        param.put("password","zjxl@2021");
//        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
//        map.add("username","13559485270");
//        map.add("password","zjxl@2021");
//        org.springframework.http.HttpEntity<JSONObject> response = cookiePostHttp("http://api.aiqiangua.com:8888/api/auth/login",map);
//        org.springframework.http.HttpHeaders responseHeaders = response.getHeaders();
//        System.out.println("11111");
//        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
//        org.springframework.http.HttpEntity<JSONObject> response = aqgCookieHttp("http://api.aiqiangua.com:8888/api/device/868219010321351",null,HttpMethod.GET,
//                "user=2|1:0|10:1620279813|4:user|16:MTM1NTk0ODUyNzA=|9d8d1403e854d37b551b57c9e53581b2ba7c491ba394a2b3a1b83f4ebc3c2d34");
//        System.out.println(response.getBody().toString());
//    }
}

+ 37 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/config/AqgConfig.java

@ -0,0 +1,37 @@
package com.yihu.jw.care.config;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yeshijie
 * @Date: 2021/4/29
 * @Description: 爱牵挂配置
 */
public class AqgConfig {
    /**
     * 基础url
     */
//    public static final String baseUrl = "http://120.24.56.48:8889";//测试环境
    public static final String baseUrl = "http://api.aiqiangua.com:8888";// 正式环境
    /**
     * 登录
     */
    public static final String login = baseUrl +"/api/auth/login";
    /**
     * 获取设备信息
     */
    public static final String deviceInfo = baseUrl +"/api/device/{0}";
    /**
     * 修改亲情号码
     */
    public static final String sos_numbers = baseUrl +"/api/device/{0}/sos_numbers/{1}";
    public static final String username = "13559485270";
    public static final String password = "zjxl@2021";
    public static final String redisKey = "aqgCooker";
    /**
     * cookie时效24小时,吧过期时间设置为23 小时
     */
    public static final Long overTime = 23L;
}

+ 39 - 10
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/PatientDeviceController.java

@ -18,11 +18,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.HashMap;
@ -34,7 +33,7 @@ import java.util.Map;
 *
 * @author George
 */
@Controller
@RestController
@RequestMapping(value = "patient/device")
@Api(value = "患者设备管理", description = "患者设备管理")
public class PatientDeviceController extends BaseController {
@ -57,7 +56,6 @@ public class PatientDeviceController extends BaseController {
    @ApiOperation("获取居民标准体征预警值")
    @RequestMapping(value = "getDeviceStandard", method = RequestMethod.GET)
    @ResponseBody
    public String getDeviceStandard(@ApiParam(name = "type", value = "类型1血糖,2血压", defaultValue = "1")
                                    @RequestParam(value = "type", required = true) Integer type){
        try {
@ -75,7 +73,6 @@ public class PatientDeviceController extends BaseController {
     */
    @ApiOperation("设备保存接口")
    @RequestMapping(value = "SavePatientDevice", method = RequestMethod.POST)
    @ResponseBody
    public String saveDevice(@ApiParam(name = "json", value = "设备数据json", defaultValue = "{\"deviceId\": \"3\",\"deviceName\": \"血压计-优瑞恩\",\"deviceSn\": \"7052169111\",\"categoryCode\": \"1\",\"userType\": \"-1\"}")
                             @RequestParam(value = "json", required = true) String json) {
        try {
@ -116,7 +113,6 @@ public class PatientDeviceController extends BaseController {
     */
    @ApiOperation("患者设备列表获取")
    @RequestMapping(value = "PatientDeviceList", method = RequestMethod.GET)
    @ResponseBody
    public String getDeviceByPatient(@ApiParam(name = "id", value = "分页起始id", defaultValue = "0")
                                     @RequestParam(value = "id", required = true) long id,
                                     @ApiParam(name = "pagesize", value = "每页条数", defaultValue = "10")
@ -134,7 +130,6 @@ public class PatientDeviceController extends BaseController {
    //要增加时间段信息展示
    @ApiOperation("获取患者设备信息")
    @RequestMapping(value = "PatientDeviceInfo", method = RequestMethod.GET)
    @ResponseBody
    public String getPatientDeviceInfo(@ApiParam(name = "id", value = "患者设备ID", defaultValue = "146")
                                       @RequestParam(value = "id", required = true) String id) {
        try {
@ -153,7 +148,6 @@ public class PatientDeviceController extends BaseController {
     */
    @ApiOperation("通过sn码获取设备绑定情况")
    @RequestMapping(value = "PatientDeviceIdcard", method = RequestMethod.GET)
    @ResponseBody
    public String getDeviceUser(@ApiParam(name = "type", value = "设备类型", defaultValue = "1")
                                @RequestParam(value = "type", required = true) String type,
                                @ApiParam(name = "device_sn", value = "设备SN码", defaultValue = "15L000002")
@ -176,7 +170,6 @@ public class PatientDeviceController extends BaseController {
     */
    @ApiOperation("设备删除")
    @RequestMapping(value = "DeletePatientDevice",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String delete(@ApiParam(name = "id", value = "删除设备关联ID")
                         @RequestParam(value = "id", required = true) String id) {
        try {
@ -201,7 +194,6 @@ public class PatientDeviceController extends BaseController {
    @ApiOperation("获取居民的设备任务信息")
    @RequestMapping(value = "getPatientDeviceTaskInfo",method = RequestMethod.POST)
    @ResponseBody
    public String getPatientDeviceTaskInfo(@ApiParam(name = "patientCode",value = "患者code")@RequestParam(value = "patientCode",required = true)String patientCode){
        try {
            return write(200,"执行成功","data",patientDeviceService.getPatientDeviceTaskInfo(patientCode));
@ -210,5 +202,42 @@ public class PatientDeviceController extends BaseController {
        }
    }
    @ApiOperation("获取居民的爱牵挂设备亲情号码")
    @RequestMapping(value = "getAqgDeviceInfo",method = RequestMethod.GET)
    public String getAqgDeviceInfo(@ApiParam(name = "deviceSn",value = "设备sn码")
                                               @RequestParam(value = "deviceSn",required = true)String deviceSn){
        try {
            return write(200,"获取成功","data",patientDeviceService.getAqgDeviceInfo(deviceSn));
        }catch (Exception e){
            e.printStackTrace();
            return write(-1,"获取失败!");
        }
    }
    @ApiOperation("修改删除 爱牵挂亲情号码")
    @RequestMapping(value = "updAqgDeviceSosInfo",method = RequestMethod.POST)
    public String updAqgDeviceSosInfo(@ApiParam(name = "deviceSn",value = "设备id")
                                   @RequestParam(value = "deviceSn",required = true)String deviceSn,
                                   @ApiParam(name = "seqid",value = "亲情号码id")
                                   @RequestParam(value = "seqid",required = false)String seqid,
                                   @ApiParam(name = "name",value = "亲情号码昵称",required = false)
                                   @RequestParam(value = "name",required = false)String name,
                                   @ApiParam(name = "num",value = "号码",required = false)
                                   @RequestParam(value = "num",required = false)String num,
                                   @ApiParam(name = "dial_flag",value = "0不设置为紧急呼叫号码,1设置为紧急呼叫号码",required = false)
                                   @RequestParam(value = "dial_flag",required = false)String dial_flag,
                                   @ApiParam(name = "clear",value = "删除标志,删除传1",required = false)
                                   @RequestParam(value = "clear",required = false)String clear){
        try {
            com.alibaba.fastjson.JSONObject json = patientDeviceService.updAqgDeviceSosInfo(deviceSn, seqid, name, num, dial_flag, clear);
            if(json.getBoolean("success")){
                return success("操作成功");
            }
            return error(-1,json.getString("error_desc"));
        }catch (Exception e){
            e.printStackTrace();
            return write(-1,"操作失败!");
        }
    }
}

+ 80 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/device/PatientDeviceService.java

@ -1,6 +1,7 @@
package com.yihu.jw.care.service.device;
import com.yihu.jw.care.config.AqgConfig;
import com.yihu.jw.care.dao.device.DeviceDao;
import com.yihu.jw.care.dao.device.DeviceDetailDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
@ -16,11 +17,14 @@ import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
@ -28,20 +32,29 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;
import org.springside.modules.persistence.SearchFilter.Operator;
import javax.annotation.PostConstruct;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Component
@Transactional(rollbackFor = Exception.class)
public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, PatientDeviceDao> {
    private static Logger logger = LoggerFactory.getLogger(PatientDeviceService.class);
    @Autowired
    private BaseDoctorDao doctorDao;
@ -61,7 +74,10 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
    private MyJdbcTemplate myJdbcTemplate;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    WeiXinAccessTokenUtils tokenUtils;
@ -653,4 +669,67 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
       return  patientDeviceDao.findByDeviceSn(deviceSn);
    }
     /******************************************* 爱牵挂设备start *****************************************************/
    /**
     * 获取爱牵挂管理员cookie
     */
    public synchronized String getCookie(){
        if(redisTemplate.hasKey(AqgConfig.redisKey)){
            return redisTemplate.opsForValue().get(AqgConfig.redisKey);
        }
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        param.add("username",AqgConfig.username);
        param.add("password",AqgConfig.password);
        HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.cookiePostHttp(AqgConfig.login,param);
        HttpHeaders responseHeaders = response.getHeaders();
        String cookie =  responseHeaders.get("Set-Cookie").get(0);
        logger.info("cookie="+cookie);
        redisTemplate.opsForValue().set(AqgConfig.redisKey,cookie,AqgConfig.overTime, TimeUnit.HOURS);
        return cookie;
    }
    /**
     * 获取爱牵挂设备信息
     * @param imei
     */
    public com.alibaba.fastjson.JSONObject getAqgDeviceInfo(String imei) throws Exception{
        String url = MessageFormat.format(AqgConfig.deviceInfo, imei);
        HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.aqgCookieHttp(url, null, HttpMethod.GET, getCookie());
        com.alibaba.fastjson.JSONObject json = response.getBody();
        if(!json.getBoolean("success")){
             throw new Exception(json.getString("error_desc")) ;
        }
        return json.getJSONObject("obj");
    }
    /**
     * 修改删除 爱牵挂亲情号码
     * @param deviceSn
     * | name  |  否  | String       | 号码昵称                        |
    | num          |  否  | String       | 亲情号码,可以是手机或固话        |
    | dial_flag    |  否  | Int          | 0不设置为紧急呼叫号码,1设置为紧急呼叫号码       |
    | clear        |  否  | any          | 清空设置,[例如id值为2,如果发送的url带clear,系统只处理clear命令,则上述设置的亲情号2的参数无效,
    若该设备以前已设置亲情号码2,则以前设置的亲情号码2也会被清空]
    |
     */
    public com.alibaba.fastjson.JSONObject updAqgDeviceSosInfo(String deviceSn,String seqid,String name,String num,String dial_flag,String clear) throws Exception{
        String url = MessageFormat.format(AqgConfig.sos_numbers, deviceSn,seqid);
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        if(StringUtils.isBlank(clear)){
            param.add("name", name);
            param.add("num", num);
            param.add("dial_flag", dial_flag);
        }else {
            param.add("clear",clear);
        }
        HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.aqgCookieHttp(url, param, HttpMethod.POST, getCookie());
        return response.getBody();
    }
    /******************************************* 爱牵挂设备end *****************************************************/
}

+ 28 - 1
svr/svr-cloud-device/readme.MD

@ -1,3 +1,30 @@
医养项目设备对接工程
为了设备接收稳定,防止主程序重启导致设备数据没接收到,故独立项目
目前正在对接爱牵挂设备
目前正在对接爱牵挂设备
柏颐设备位置接收
http://ehr.yihu.com/wlyy/aqg/device/byLocation
柏颐心率数据接手
http://ehr.yihu.com/wlyy/aqg/device/byHeartRate
柏颐血压数据接收
http://ehr.yihu.com/wlyy/aqg/device/byBloodPressure
柏颐跌倒数据接收
http://ehr.yihu.com/wlyy/aqg/device/byFall
柏颐设备sos数据接收
http://ehr.yihu.com/wlyy/aqg/device/aqgsos
柏颐设备步数接收
http://ehr.yihu.com/wlyy/aqg/device/bySteps
柏颐设备睡眠数据接收
http://ehr.yihu.com/wlyy/aqg/device/bySleep
柏颐设备开关机数据接收
http://ehr.yihu.com/wlyy/aqg/device/aqgSwitch
柏颐设备消息通知数据接收
http://ehr.yihu.com/wlyy/aqg/device/pushdata

+ 1 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/config/AqgConfig.java

@ -19,6 +19,7 @@ public class AqgConfig {
     */
    public static final String login = baseUrl +"/api/auth/login";
    public static final String username = "13559485270";
    public static final String password = "zjxl@2021";
    public static final String redisKey = "aqgCooker";