liubing před 3 roky
rodič
revize
79f413d148

+ 5 - 5
common/common-entity/src/main/java/com/yihu/jw/entity/care/contacts/PatientSosContactsDO.java

@ -21,7 +21,7 @@ public class PatientSosContactsDO extends IdEntity {
    private String sosPhone; //联系电话
    private String relation; //与联系人关系 同base_patient_family_member
    private Date updateTime; //修改日期
    private Integer success_flag;//联系人是否同步成功-1失败 0待同步 1成功
    private Integer successFlag;//联系人是否同步成功-1失败 0待同步 1成功
    private Integer del;
    private String relationName;
@ -67,12 +67,12 @@ public class PatientSosContactsDO extends IdEntity {
        this.updateTime = updateTime;
    }
    public Integer getSuccess_flag() {
        return success_flag;
    public Integer getSuccessFlag() {
        return successFlag;
    }
    public void setSuccess_flag(Integer success_flag) {
        this.success_flag = success_flag;
    public void setSuccessFlag(Integer successFlag) {
        this.successFlag = successFlag;
    }
    public Integer getDel() {

+ 2 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/contacts/PatientSosContactsDao.java

@ -15,4 +15,6 @@ public interface PatientSosContactsDao extends PagingAndSortingRepository<Patien
    List<PatientSosContactsDO> findByPatientAndDel(String patient,Integer del);
    List<PatientSosContactsDO> findByPatientOrderByUpdateTimeDesc(String patient);
    PatientSosContactsDO findByPatientAndSosPhone(String patient,String sosPhone);
}

+ 35 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/DoctorDeviceController.java

@ -1,14 +1,17 @@
package com.yihu.jw.care.endpoint.device;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.endpoint.BaseController;
import com.yihu.jw.care.service.contacts.ContactsService;
import com.yihu.jw.care.service.device.DeviceDetailService;
import com.yihu.jw.care.service.device.PatientDeviceService;
import com.yihu.jw.care.util.CommonUtil;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
@ -52,6 +55,8 @@ public class DoctorDeviceController extends BaseController {
	@Autowired
	private JmsTemplate jmsTemplate;
	@Autowired
	private ContactsService contactsService;
	private ObjectMapper  objectMapper=new ObjectMapper();
@ -116,4 +121,34 @@ public class DoctorDeviceController extends BaseController {
			return write(200, "获取设备成功!", "data",objects);
	}
	@RequestMapping(value ="updatePatientSosContacts",method = RequestMethod.POST)
	@ApiOperation(value = "设置居民紧急联系人")
	public String updatePatientSosContacts(@ApiParam(name = "patient", value = "patient", defaultValue = "patient")
										   @RequestParam(value = "patient", required = true) String patient,
										   @ApiParam(name="num",value = "成员配置的语音白名单号码 新增时只能传一个,删除时最多两个,用下划线隔开")
										   @RequestParam(value = "num")String num,
										   @ApiParam(name="operType",value = "1新增 4删除")
										   @RequestParam(value ="operType",required = true)Integer operType,
										   @ApiParam(name = "name", value = "联系人姓名")
										   @RequestParam(value = "name", required = false) String name,
										   @ApiParam(name = "relation", value = "与联系人关系,同base_patient_family_member")
										   @RequestParam(value = "relation", required = false) String relation){
		try {
			if (1!=operType&&4!=operType){
				return error(-1,"参数错误");
			}
			JSONObject result = contactsService.updatePatientSosContacts(patient,num,operType,name,relation);
			if (ResponseContant.success == result.getInteger(ResponseContant.resultFlag)){
				return success("修改成功");
			}
			else {
				return error(-1,result.getString(ResponseContant.resultMsg));
			}
		}catch (Exception e){
			return errorResult(e);
		}
	}
}

+ 3 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/DoctorHealthController.java

@ -100,6 +100,9 @@ public class DoctorHealthController extends BaseController {
											  @RequestParam(value="pagesize",required = true) int pagesize) {
		try {
			JSONObject jsonObject = new JSONObject();
			if(StringUtils.isBlank(begin)){
				begin="2016-07-23 00:00:00";
			}
			if (type == 1) {
				List<Object> list = healthIndexService.findIndexByPatient2(patient, type, begin, end, page, pagesize);
				jsonObject.put("data",list);

+ 0 - 28
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/PadDeviceController.java

@ -167,33 +167,5 @@ public class PadDeviceController extends BaseController {
        }
    }
    @RequestMapping(value ="updatePatientSosContacts",method = RequestMethod.POST)
    @ApiOperation(value = "设置居民紧急联系人")
    public String updatePatientSosContacts(@ApiParam(name = "patient", value = "patient", defaultValue = "patient")
                                           @RequestParam(value = "patient", required = true) String patient,
                                           @ApiParam(name="num",value = "成员配置的语音白名单号码 新增时只能传一个,删除时最多两个,用下划线隔开")
                                           @RequestParam(value = "num")String num,
                                           @ApiParam(name="operType",value = "1新增 4删除")
                                           @RequestParam(value ="operType",required = true)Integer operType,
                                           @ApiParam(name = "name", value = "联系人姓名")
                                           @RequestParam(value = "name", required = false) String name,
                                           @ApiParam(name = "relation", value = "与联系人关系,同base_patient_family_member")
                                           @RequestParam(value = "relation", required = false) String relation){
        try {
            if (1!=operType||4!=operType){
                return error(-1,"参数错误");
            }
            JSONObject result = contactsService.updatePatientSosContacts(patient,num,operType,name,relation);
            if (ResponseContant.success == result.getInteger(ResponseContant.resultFlag)){
                return success("修改成功");
            }
            else {
                return error(-1,result.getString(ResponseContant.resultMsg));
            }
        }catch (Exception e){
            return errorResult(e);
        }
    }
}

+ 3 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/PatientHealthController.java

@ -410,6 +410,9 @@ public class PatientHealthController extends BaseController {
        try {
            JSONObject jsonObject = new JSONObject();
            if (StringUtils.isBlank(start)){
                start="2016-07-23 00:00:00";
            }
            if (type == 1) {
                List<Object> list = healthIndexService.findIndexByPatient2(getUID(), type, start, end, page, pagesize);
                jsonObject.put("data",list);

+ 103 - 27
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/contacts/ContactsService.java

@ -1,5 +1,6 @@
package com.yihu.jw.care.service.contacts;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.dao.contacts.BasePatientContactsOrgDao;
@ -30,10 +31,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.xml.crypto.Data;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
 * Created with IntelliJ IDEA.
@ -228,7 +227,7 @@ public class ContactsService {
    /**
     *设置居民紧急联系人
     */
    public JSONObject updatePatientSosContacts(String patient,String num,Integer operType,String name,String relation){
    public JSONObject updatePatientSosContacts(String patient,String num,Integer operType,String name,String relation) throws Exception {
        JSONObject result = new JSONObject();
        List<PatientSosContactsDO> list = sosContactsDao.findByPatientOrderByUpdateTimeDesc(patient);
        if (4==operType){//一个月只能删除一次
@ -239,44 +238,121 @@ public class ContactsService {
                   Long day = timeDiffer/(1000L*3600*24)+1;
                   result.put(ResponseContant.resultFlag,ResponseContant.fail);
                   result.put(ResponseContant.resultMsg,"您本月删除紧急联系人次数已使用,请"+day+"天后再试");
                    return result;
                }
                String[] numTmp = num.split("_");
                String sql = " select wd.sim from  wlyy_patient_device pd inner join wlyy_devices wd  " +
                        "on pd.device_sn = wd.device_code and pd.del=0 and wd.sim is not null " +
                String sql = " select pd.device_sn,wd.sim from  wlyy_patient_device pd inner join wlyy_devices wd  " +
                        "on pd.device_sn = wd.device_code and pd.del=0 and wd.sim is not null and pd.category_code in('7','4')  " +
                        "where pd.user='"+patient+"' ";
                List<String> sims = jdbcTemplate.queryForList(sql,String.class);
                for (String sim:sims){
                    try {
                        JSONArray respons = networkCardService.getPatientContacts(sim,null,null,null);
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
                //接口实时删除
                List<Map<String,Object>> sims = jdbcTemplate.queryForList(sql);
                //修改
                delSosNumber(sims,patient,numTmp);
            }else {
                result.put(ResponseContant.resultFlag,ResponseContant.fail);
                result.put(ResponseContant.resultMsg,"改用户已无紧急联系人");
                result.put(ResponseContant.resultMsg,"该用户已无紧急联系人");
                return result;
            }
        }
        if (1==operType){//新增联系人
            if (list.size()<2){
            list = sosContactsDao.findByPatientAndDel(patient,1);
            if (list.size()>=2){
                result.put(ResponseContant.resultFlag,ResponseContant.fail);
                result.put(ResponseContant.resultMsg,"该用户紧急联系人已上线");
                return result;
            }
            else {
                PatientSosContactsDO contactsDO = new PatientSosContactsDO();
                list = sosContactsDao.findByPatientAndDel(patient,0);
                if (list.size()>0) {
                    contactsDO =list.get(0);
                }
                contactsDO.setPatient(patient);
                contactsDO.setSosName(name);
                contactsDO.setSosPhone(num);
                contactsDO.setRelation(relation);
                contactsDO.setSuccess_flag(0);
                contactsDO.setSuccessFlag(0);
                sosContactsDao.save(contactsDO);
            }
            String sql = " select wd.sim from  wlyy_patient_device pd inner join wlyy_devices wd  " +
                    "on pd.device_sn = wd.device_code and pd.del=0 and wd.sim is not null " +
                    "where pd.user='"+patient+"' ";
            List<String> sims = jdbcTemplate.queryForList(sql,String.class);
        }
        result.put(ResponseContant.resultFlag,ResponseContant.success);
        result.put(ResponseContant.resultMsg,"修改成功");
        return result;
    }
    public void delSosNumber(List<Map<String,Object>> sims,String patient,String[] numTmp) {
        String delSuccess = "";//白名单删除号码
        for (Map<String,Object> simTmp : sims) {
            String sim = simTmp.get("sim").toString();
            try {
                JSONArray respons = networkCardService.getPatientContacts(sim, null, null, null);
                List<Map<String, Object>> memberArr = null;
                if (respons.size() > 0) {
                    respons.getJSONObject(0).getJSONArray("memVoiceWhiteList");
                    memberArr = (List<Map<String, Object>>) JSONArray.parse(respons.getJSONObject(0).getJSONArray("memVoiceWhiteList").toJSONString());
                    List<String> WhiteList = memberArr.stream().map(e -> e.get("whiteNumber").toString()).collect(Collectors.toList());
                    String del_num = "";
                    if (WhiteList.contains(numTmp[0])) {
                        del_num = numTmp[0];
                    }
                    if (numTmp.length == 2) {
                        if (WhiteList.contains(numTmp[1])) {
                            if (StringUtils.isNotBlank(del_num)) {
                                del_num += "_" + numTmp[1];
                            } else {
                                del_num = numTmp[1];
                            }
                        }
                    }
                    if (StringUtils.isNotBlank(del_num)) {
                        String response = networkCardService.setPatientContacts(sim, null, null, "4", null, null);
                        if (StringUtils.isNotBlank(response)) {
                            String[] DelNums = del_num.split("_");
                            for (String tmp:DelNums){
                                if (!delSuccess.contains(tmp)){//本次已删除过 不再作删除操作
                                    String deviceCode = simTmp.get("device_sn").toString();
                                    JSONObject aqgDeviceInfo = patientDeviceService.getAqgDeviceInfo(deviceCode);
                                    JSONArray aqgDeviceSosNum = aqgDeviceInfo.getJSONArray("sos_numbers");
                                    Integer numIndex=0;
                                    for (int i=0;i<aqgDeviceSosNum.size();i++){
                                        JSONObject aqgTmp = aqgDeviceSosNum.getJSONObject(i);
                                        String aqgNum = aqgTmp.getString("num");
                                        if (aqgNum.equals("tmp")){
                                            numIndex = aqgTmp.getInteger("seqid");
                                            break;
                                        }
                                    }
                                    if (numIndex!=0){
                                      JSONObject response2 =  patientDeviceService.updAqgDeviceSosInfo(deviceCode,numIndex+"",null,null,null,"1");
                                      if (response2.getBoolean("success")){
                                          delSuccess += "_"+tmp;
                                      }
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //保存修改记录
        List<PatientSosContactsDO> modify = new ArrayList<>();
        for (String num:numTmp){
            if (StringUtils.isNotBlank(num)){
                PatientSosContactsDO patientSosContactsDO = sosContactsDao.findByPatientAndSosPhone(patient,num);
                patientSosContactsDO.setUpdateTime(new Date());
                patientSosContactsDO.setDel(0);
                if (delSuccess.contains(num)){
                    patientSosContactsDO.setSuccessFlag(1);
                }
                else {
                    patientSosContactsDO.setSuccessFlag(-1);
                }
                modify.add(patientSosContactsDO);
            }
        }
        sosContactsDao.save(modify);
    }
}

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

@ -0,0 +1,49 @@
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 X1sos_numbers = baseUrl +"/api/device/{0}/4g/sos_numbers/{1}";
    /**
     * 获取设备最新位置数据
     */
    public static final String device_last_locationData = baseUrl +"/api/device/{0}/data/locationdata/";
    /**
     * 设置智能手环安全区域
     */
    public static final String S3fence_area = baseUrl +"/api/device/{0}/fences/{1}";
    public static final String X1fence_area = baseUrl +"/api/device/{0}/4g/fences/{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;
}

+ 34 - 0
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/config/NetworkCardConfig.java

@ -0,0 +1,34 @@
package com.yihu.jw.care.config;
import com.yihu.jw.util.date.DateUtil;
/**
 * Created by Bing on 2021/8/6.
 * 电信物联网卡
 */
public class NetworkCardConfig {
    //平台地址 https://ct.cmonelink.com/zh/#/infoPanel/index
    //user:BE5714630405 password:Zjxl2008@
    //文档地址https://ec.iot.10086.cn/ecology/supportService/documents
    public static final String appid="571AIOT2021072910102922281";
    public static final String password="OnXE@QFlwt9R";
    public static final String redisKey="dianXinAssesToken";
    public static final String groupId="9911000019160041";//所有卡号均在同一分组下方便维护
    //APPID+YYYYMMDDHHMISS+8位数字序列
    public static String getTransid() {
        return appid+ DateUtil.getNo(8);
    }
    public static final String getToken="https://api.iot.10086.cn/v5/ec/get/token";
    //获取语音白名单
    public static final String getPatientContacts="https://api.iot.10086.cn/v5/ec/query/member-voice-whitelist";
    //设置语音白名单 //同一卡号一分钟只能调用该接口一次 一个月仅能删除一次(一次最多删除2个号码)
    public static final String setPatientContacts="https://api.iot.10086.cn/v5/ec/config/member-voice-whitelist";
}

+ 21 - 0
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/dao/device/DeviceDao.java

@ -0,0 +1,21 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.Device;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface DeviceDao extends PagingAndSortingRepository<Device, Long> {
	@Query("select a from Device a where a.categoryCode = ?1 and a.del = '1'")
	List<Device> findByCategoryCode(String categoryCode);
	@Query("select a from Device a where a.del = '1'")
	List<Device> findAll();
}

+ 66 - 0
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/dao/device/PatientDeviceDao.java

@ -0,0 +1,66 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface PatientDeviceDao extends PagingAndSortingRepository<DevicePatientDevice, Long>, JpaSpecificationExecutor<DevicePatientDevice> {
    @Query("select a from DevicePatientDevice a where a.user = ?1 ")
    Iterable<DevicePatientDevice> findByUser(String user);
    @Query("select a from DevicePatientDevice a where a.del = 0 ")
    List<DevicePatientDevice> findByAll();
    @Query("select a from DevicePatientDevice a where a.user = ?1 ")
    List<DevicePatientDevice> findByPatient(String user);
    @Query("select a from DevicePatientDevice a where a.user = ?1 and a.del=0 and a.deviceName like '%药盒%'")
    List<DevicePatientDevice> findByPatientAndDel(String user);
    @Query("select a from DevicePatientDevice a where a.user = ?1 and a.deviceSn=?2 ")
    List<DevicePatientDevice> findByPatientAndDeviceSn(String user, String deviceSn);
    List<DevicePatientDevice> findByUser(String user, Pageable pageRequest);
    List<DevicePatientDevice> findByUserAndDoctor(String user, String doctor, Pageable pageRequest);
    List<DevicePatientDevice> findByDeviceSnAndCategoryCode(String deviceSn, String categoryCode);
    DevicePatientDevice findByDeviceSnAndCategoryCodeAndUserType(String deviceSn, String categoryCode, String userType);
    DevicePatientDevice findByDeviceIdAndDeviceSnAndUserType(Long deviceId, String deviceSn, String userType);
    DevicePatientDevice findByDeviceSnAndUserType(String deviceSn, String userType);
    @Query("select pd from DevicePatientDevice pd where pd.deviceSn = ?1 and pd.del=0")
    List<DevicePatientDevice> findByDeviceSn(String deviceSn);
    //更换患者绑定的血糖仪
    @Modifying
    @Query("update DevicePatientDevice t set t.deviceSn = ?3 , t.userType = ?4,t.sim=?5,t.hospital=?6,t.hospitalName=?7,t.checkDoctorName=?8 where t.user = ?1 and t.deviceSn = ?2 ")
    int updatePatientDevice(String user, String deviceSN, String newDeviceSN, String userType, String sim, String hospital, String hospitalName, String checkDoctorName);
    //管理员解绑居民设备
    @Modifying
    @Query("update DevicePatientDevice t set t.del = 1  where t.deviceSn = ?1 and t.del =0  ")
    int updatePatientDevice(String deviceSN);
    @Query("select a from DevicePatientDevice a")
    List<DevicePatientDevice> findAll();
    @Modifying
    @Query("delete DevicePatientDevice a where a.deviceSn = ?1")
    int deleteByDeviceSn(String deviceSN);
    @Query("select a from DevicePatientDevice a where a.user=?1 and a.del=0")
    List<DevicePatientDevice> findAllByUser(String user);
    @Query("select a from DevicePatientDevice a where a.user=?1 and a.categoryCode =?2 and a.del=0")
    List<DevicePatientDevice> findByUserAndCategoryCode(String user,String categoryCode);
}

+ 114 - 0
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/service/device/NetworkCardService.java

@ -0,0 +1,114 @@
package com.yihu.jw.care.service.device;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.config.NetworkCardConfig;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
 * Created by Bing on 2021/8/6.
 */
@Service
public class NetworkCardService {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private HttpClientUtil httpClientUtil;
    /**
     * 获取电信物联网卡assesToken
     */
    public String getAccessToken() throws Exception {
        if(redisTemplate.hasKey(NetworkCardConfig.redisKey)){
            return redisTemplate.opsForValue().get(NetworkCardConfig.redisKey);
        }
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("appid", NetworkCardConfig.appid));
        params.add(new BasicNameValuePair("password",NetworkCardConfig.password));
        params.add(new BasicNameValuePair("transid", NetworkCardConfig.getTransid()));
        String response = httpClientUtil.get(NetworkCardConfig.getToken,params,"UTF-8");
        JSONObject responseBody = JSONObject.parseObject(response);
        String assToken = null;
        if (responseBody.getInteger("status")==0){
            JSONObject tmp = responseBody.getJSONArray("result").getJSONObject(0);
            assToken = tmp.getString("token");
            Long expireTime =Long.parseLong(tmp.getString("ttl"));//token有效期
            redisTemplate.opsForValue().set(NetworkCardConfig.redisKey,assToken,expireTime, TimeUnit.SECONDS);
        }else {
            throw new Exception(response);
        }
        return assToken;
    }
    public JSONArray getPatientContacts(String msisdn, String iccid, String imsi, String groupId) throws Exception {
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("transid", NetworkCardConfig.getTransid()));
        boolean flag = false;
        if (!flag&&StringUtils.isNotBlank(msisdn)){
            params.add(new BasicNameValuePair("msisdn", msisdn));
            flag=true;
        }
        if (!flag&&StringUtils.isNotBlank(iccid)){
            params.add(new BasicNameValuePair("iccid", iccid));
        }
        if (!flag&&StringUtils.isNotBlank(imsi)){
            params.add(new BasicNameValuePair("imsi", imsi));
        }
        params.add(new BasicNameValuePair("groupId", NetworkCardConfig.groupId));
        params.add(new BasicNameValuePair("token", getAccessToken()));
        String response = httpClientUtil.get(NetworkCardConfig.getPatientContacts,params,"UTF-8");
        JSONObject responseBody = JSONObject.parseObject(response);
        if (responseBody.getInteger("status")==0){
            JSONArray tmp = responseBody.getJSONArray("result");
            return tmp;
        }else if (responseBody.getInteger("status")==14008){//未查询到数据白名单列表为空
            return new JSONArray();
        }else{
            throw new Exception(response);
        }
    }
    public String setPatientContacts(String msisdn, String iccid, String imsi,String operType,String  whiteNumber,String groupId) throws Exception {
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("transid", NetworkCardConfig.getTransid()));
        boolean flag = false;
        if (!flag&&StringUtils.isNotBlank(msisdn)){
            params.add(new BasicNameValuePair("msisdn", msisdn));
            flag=true;
        }
        if (!flag&&StringUtils.isNotBlank(iccid)){
            params.add(new BasicNameValuePair("iccid", iccid));
        }
        if (!flag&&StringUtils.isNotBlank(imsi)){
            params.add(new BasicNameValuePair("imsi", imsi));
        }
        params.add(new BasicNameValuePair("groupId", NetworkCardConfig.groupId));
        params.add(new BasicNameValuePair("token", getAccessToken()));
        params.add(new BasicNameValuePair("operType", operType));
        params.add(new BasicNameValuePair("whiteNumber", whiteNumber));
        String response = httpClientUtil.get(NetworkCardConfig.setPatientContacts,params,"UTF-8");
        JSONObject responseBody = JSONObject.parseObject(response);
        if (responseBody.getInteger("status")==0){
            JSONObject tmp = responseBody.getJSONArray("result").getJSONObject(0);
            return tmp.getString("orderNum");
        }else {
            throw new Exception(response);
        }
    }
}

+ 221 - 0
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/service/device/PatientDeviceService.java

@ -0,0 +1,221 @@
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.PatientDeviceDao;
import com.yihu.jw.entity.care.device.Device;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.util.common.GpsUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import javax.annotation.PostConstruct;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Component
@Transactional(rollbackFor = Exception.class)
public class PatientDeviceService {
    private static Logger logger = LoggerFactory.getLogger(PatientDeviceService.class);
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private GpsUtil gpsUtil;
    @Autowired
    private DeviceDao deviceDao;
    Map<Integer, String> relations = new HashMap<>();
    @PostConstruct
    public void init() {
        relations.put(0, "其他");
        relations.put(1, "父亲");
        relations.put(2, "母亲");
        relations.put(3, "老公");
        relations.put(4, "老婆");
        relations.put(5, "儿子");
        relations.put(6, "女儿");
        relations.put(7, "未知");
        relations.put(8, "免疫关联");
    }
     /******************************************* 爱牵挂设备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){
        //先对移动接口限制做判断。
        List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
        String url ="";
        if ("4".equals(devices.get(0).getCategoryCode())){//手表
            Device device = deviceDao.findOne(devices.get(0).getDeviceId());
            if (device!=null){
                if ("X1".equals(device.getModel())){
                    url = MessageFormat.format(AqgConfig.X1sos_numbers, deviceSn,seqid);
                }
            }
        }else {
            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();
    }
    /**
     * 获取设备最新位置数据
     * @param deviceSn
     * @param type  0:Gps定位; 1:基站定位 (非必填)
     * @return
     * @throws Exception
     */
    public com.alibaba.fastjson.JSONObject getDeviceLastLocation(String deviceSn,String type) throws Exception{
        String url = MessageFormat.format(AqgConfig.device_last_locationData, deviceSn);
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        param.add("type", type);
        HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.aqgCookieHttp(url, param, HttpMethod.GET, getCookie());
        com.alibaba.fastjson.JSONObject responseJSON =  response.getBody();
        if (responseJSON.getBooleanValue("success")){
            if (responseJSON.containsKey("obj")&&responseJSON.getJSONObject("obj")!=null){
                com.alibaba.fastjson.JSONObject tmp= responseJSON.getJSONObject("obj");
                if (tmp.containsKey("locationdata")&&tmp.getJSONObject("locationdata")!=null){
                    com.alibaba.fastjson.JSONObject locationdataJson= tmp.getJSONObject("locationdata");
                    if (locationdataJson.containsKey("point")&&locationdataJson.getJSONObject("point")!=null){
                        com.alibaba.fastjson.JSONObject tmpPoint = locationdataJson.getJSONObject("point");
                        if (tmpPoint.containsKey("coordinates")&&tmpPoint.getJSONArray("coordinates")!=null){
                            com.alibaba.fastjson.JSONArray pointArr = tmpPoint.getJSONArray("coordinates");
                            Double lon = pointArr.getDouble(0);
                            Double lat = pointArr.getDouble(1);
                            com.alibaba.fastjson.JSONObject pointJson = gpsUtil.gcj02_To_Bd09(lat,lon);
                            locationdataJson.put("point",pointJson);
                        }
                    }
                }
            }
        }
        return responseJSON;
    }
    /**
     *
     *    | enable       |  否  | Int          |  0,1 是否启用                        |
     *    | name         |  否  | String       |   安全区名称                           |
     *    | freq         |  否  | Boolean      |  0,触发一天;1,每日触发        |
     *    | time_begin   |  否  | Int          |  目标时间与当日0点之间相差的秒数。如8 a.m 8*60*60=28800 |n
     *    | time_end     |  否  | Int          |  同上                        |
     *    | safe_area    |  否  | String       | x1,y1;x2,y2;xn,yn  一组由';'分隔的坐标,坐标用','分隔。且需要呈闭环,如A,B,C,D4个点,则应该上传的数据为 A;B;C;D;A  |
     *    | clear        |  否  | any          | 如果指定clear参数,则上述参数全部无意义,全部重设为缺省值    |
     * @return
     * @throws Exception
     */
    public com.alibaba.fastjson.JSONObject updateDeviceFenceArea(String deviceSn,Integer fenceNO,String enable,String name,String freq,
                                                                 String time_begin,String time_end,String safe_area ,String clear) throws Exception{
        List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
        String url ="";
        if ("4".equals(devices.get(0).getCategoryCode())){//手表
            Device device = deviceDao.findOne(devices.get(0).getDeviceId());
            if (device!=null){
                if ("X1".equals(device.getModel())){
                    url = MessageFormat.format(AqgConfig.X1fence_area, deviceSn,fenceNO);
                }
            }
        }else {
            url = MessageFormat.format(AqgConfig.S3fence_area, deviceSn,fenceNO);
        }
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        if(StringUtils.isBlank(clear)){
            if (StringUtils.isNotBlank(safe_area)){
                String[] position = safe_area.split(";");
                safe_area = "";
                for (String tmp:position){
                    String[] point = tmp.split(",");
                    safe_area+= gpsUtil.bd09_To_Gcj02_str(Double.parseDouble(point[1]),Double.parseDouble(point[0]))+";";
                }
            }
            param.add("name", name);
            param.add("freq", freq);
            param.add("enable",enable);
            param.add("time_begin", time_begin);
            param.add("time_end", time_end);
            param.add("safe_area", safe_area);
        }else {
            param.add("clear",clear);
        }
        HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.aqgCookieHttp(url, param, HttpMethod.POST, getCookie());
        return response.getBody();
    }
    /******************************************* 爱牵挂设备end *****************************************************/
}