Parcourir la source

Merge branch 'dev' of liubing/wlyy2.0 into dev

liubing il y a 3 ans
Parent
commit
078b246d28

+ 41 - 0
common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientUtil.java

@ -117,6 +117,47 @@ public class HttpClientUtil {
    }
    }
    public  String postWithTimeOUt(String url, List<NameValuePair> params, String chatSet,int outTime) {
        // 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost(url);
        UrlEncodedFormEntity uefEntity;
        RequestConfig requestConfig = RequestConfig.custom()
                .setConnectTimeout(outTime)
                .setConnectionRequestTimeout(outTime)
                .setStaleConnectionCheckEnabled(true)
                .setSocketTimeout(outTime).build();
        httppost.setConfig(requestConfig);
        try {
            uefEntity = new UrlEncodedFormEntity(params, chatSet);
            httppost.setEntity(uefEntity);
            CloseableHttpResponse response = httpclient.execute(httppost);
            try {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    return EntityUtils.toString(entity, chatSet);
                }
            } finally {
                response.close();
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭连接,释放资源
            try {
                httpclient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
    /**
    /**
     * 发送get请求
     * 发送get请求
     *
     *

+ 27 - 8
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/job/device/PatientSosContactsJob.java

@ -42,7 +42,11 @@ public class PatientSosContactsJob implements Job {
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("PATIENT_SOS_CONTACTS_JOB start");
        logger.info("PATIENT_SOS_CONTACTS_JOB start");
        String sql = " select pd.device_sn,pd.category_code,wd.iccid as sim,sc.* from  wlyy_patient_device pd inner join wlyy_devices wd " +
        String sql = " UPDATE base_patient_sos_contacts set success_flag=0,update_info = null,error_info=null where \n" +
                " `success_flag` <> '1' AND `del` = '1' ";
        jdbcTemplate.execute(sql);
        sql = " select pd.device_sn,pd.category_code,wd.iccid as sim,sc.* from  wlyy_patient_device pd inner join wlyy_devices wd " +
                " on pd.device_sn = wd.device_code and pd.del=0 " +
                " on pd.device_sn = wd.device_code and pd.del=0 " +
                "INNER JOIN base_patient_sos_contacts sc on sc.patient = pd.user and sc.del=1 " +
                "INNER JOIN base_patient_sos_contacts sc on sc.patient = pd.user and sc.del=1 " +
                "where  sc.success_flag=0 and pd.category_code in('7','4','16')  group by wd.device_code ";
                "where  sc.success_flag=0 and pd.category_code in('7','4','16')  group by wd.device_code ";
@ -108,14 +112,29 @@ public class PatientSosContactsJob implements Job {
                                phone2 = nums.get(i);
                                phone2 = nums.get(i);
                            }
                            }
                        }
                        }
                        yunXunDeviceService.setSos(device_sn,phone1,phone2,phone3);
                        if (!sosContactsDO.getUpdateInfo().contains(device_sn)){
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":unknow}");
                        }
                        if (1==sosContactsDO.getSuccessFlag()||0==sosContactsDO.getSuccessFlag()){
                            sosContactsDO.setSuccessFlag(1);
                        }else {
                        String yxResponse =  yunXunDeviceService.setSos(device_sn,phone1,phone2,phone3);
                        if (StringUtils.isBlank(yxResponse)){//请求失败或超时
                            if (!sosContactsDO.getUpdateInfo().contains(device_sn)){
                                sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":error}");
                            }
                            sosContactsDO.setSuccessFlag(-1);
                            sosContactsDO.setSuccessFlag(-1);
                        }else {
                            JSONObject yxResponseObj = JSONObject.parseObject(yxResponse);
                            if (200==yxResponseObj.getInteger("status")){//返回成功
                                if (!sosContactsDO.getUpdateInfo().contains(device_sn)){
                                    sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":success}");
                                }
                                if (1==sosContactsDO.getSuccessFlag()||0==sosContactsDO.getSuccessFlag()){
                                    sosContactsDO.setSuccessFlag(1);
                                }else {
                                    sosContactsDO.setSuccessFlag(-1);
                                }
                            } else { //返回失败
                                if (!sosContactsDO.getUpdateInfo().contains(device_sn)){
                                    sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":error}");
                                }
                                sosContactsDO.setSuccessFlag(-1);
                            }
                        }
                        }
                    }
                    }
                    sosContactsDao.save(sosContactsDO);
                    sosContactsDao.save(sosContactsDO);

+ 7 - 5
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/job/device/YunXunDeviceService.java

@ -34,9 +34,9 @@ public class YunXunDeviceService {
     * @param phone2
     * @param phone2
     * @param phone3
     * @param phone3
     */
     */
    public void setSos(String sn,String phone1,String phone2,String phone3){
    public String setSos(String sn,String phone1,String phone2,String phone3){
        if(StringUtil.isBlank(phone1)){
        if(StringUtil.isBlank(phone1)){
            return;
            return "";
        }
        }
        //[IC*334588000000156*0027*SOS,00000000000,00000000000]
        //[IC*334588000000156*0027*SOS,00000000000,00000000000]
        String order = "SOS,"+phone1;
        String order = "SOS,"+phone1;
@ -47,24 +47,26 @@ public class YunXunDeviceService {
            order += ","+phone3;
            order += ","+phone3;
        }
        }
        String instruction = "[IC*"+sn+"*"+hex10To16(order.length())+"*"+order+"]";
        String instruction = "[IC*"+sn+"*"+hex10To16(order.length())+"*"+order+"]";
        sendInstruction(sn,instruction);
        return sendInstruction(sn,instruction);
    }
    }
    /**
    /**
     * 发送指令接口
     * 发送指令接口
     * @param instruction
     * @param instruction
     */
     */
    public void sendInstruction(String sn,String instruction){
    public String sendInstruction(String sn,String instruction){
        try {
        try {
            String url = "http://www.cityihealth.com:43210/yunxin/sendMessage?deviceSN="+sn+"&message="+instruction;
            String url = "http://www.cityihealth.com:43210/yunxin/sendMessage?deviceSN="+sn+"&message="+instruction;
            List<NameValuePair> params = new ArrayList<>();
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("deviceSN",sn));
            params.add(new BasicNameValuePair("deviceSN",sn));
            params.add(new BasicNameValuePair("message",instruction));
            params.add(new BasicNameValuePair("message",instruction));
            String response = httpClientUtil.post(url,params,"UTF-8");
            String response = httpClientUtil.postWithTimeOUt(url,params,"UTF-8",10000);
            logger.info("sendInstruction="+response);
            logger.info("sendInstruction="+response);
            return response;
        }catch (Exception e){
        }catch (Exception e){
            e.printStackTrace();
            e.printStackTrace();
        }
        }
        return "";
    }
    }
    /**
    /**

+ 2 - 2
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/web/JobController.java

@ -346,8 +346,8 @@ public class JobController extends BaseController {
            @ApiParam(name = "phone3",required = false)
            @ApiParam(name = "phone3",required = false)
            @RequestParam(value = "phone3",required = false)String phone3) {
            @RequestParam(value = "phone3",required = false)String phone3) {
        try {
        try {
            yunXunDeviceService.setSos(device_sn,phone1,phone2,phone3);
            return write(200,"success");
           String response = yunXunDeviceService.setSos(device_sn,phone1,phone2,phone3);
            return write(200,response);
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return error(-1, e.getMessage());
            return error(-1, e.getMessage());