Jelajahi Sumber

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

wangzhinan 1 tahun lalu
induk
melakukan
9920db35ed

+ 78 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/WlyyTokenGranter.java

@ -125,6 +125,16 @@ public class WlyyTokenGranter implements TokenGranter {
                        requestFactory,
                        userDetailsService
                ));
        tokenGranters.put(PwdAndCaptchaTokenGranter.GRANT_TYPE,
                new PwdAndCaptchaTokenGranter(
                        authenticationManager,
                        tokenServices,
                        clientDetailsService,
                        requestFactory,
                        userDetailsService,
                        wlyyRedisVerifyCodeService
                ));
    }
    public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
@ -644,5 +654,73 @@ public class WlyyTokenGranter implements TokenGranter {
            return new OAuth2Authentication(storedOAuth2Request, userAuth);
        }
    }
    /**
     * 密码+验证码登录
     */
    public static class PwdAndCaptchaTokenGranter extends AbstractTokenGranter {
        private static final String GRANT_TYPE = "pwdAndCaptcha";
        private final AuthenticationManager authenticationManager;
        private final UserDetailsService userDetailsService;
        private final WlyyRedisVerifyCodeService wlyyRedisVerifyCodeService;
        private GrantedAuthoritiesMapper authoritiesMapper = new NullAuthoritiesMapper();
        public PwdAndCaptchaTokenGranter(AuthenticationManager authenticationManager,
                                    AuthorizationServerTokenServices tokenServices,
                                    ClientDetailsService clientDetailsService,
                                    OAuth2RequestFactory requestFactory,
                                    UserDetailsService userDetailsService,
                                    WlyyRedisVerifyCodeService wlyyRedisVerifyCodeService) {
            this(authenticationManager, tokenServices, clientDetailsService, requestFactory, userDetailsService,wlyyRedisVerifyCodeService, GRANT_TYPE);
        }
        protected PwdAndCaptchaTokenGranter(AuthenticationManager authenticationManager,
                                       AuthorizationServerTokenServices tokenServices,
                                       ClientDetailsService clientDetailsService,
                                       OAuth2RequestFactory requestFactory,
                                       UserDetailsService userDetailsService,
                                       WlyyRedisVerifyCodeService wlyyRedisVerifyCodeService,
                                       String grantType) {
            super(tokenServices, clientDetailsService, requestFactory, grantType);
            this.authenticationManager = authenticationManager;
            this.wlyyRedisVerifyCodeService = wlyyRedisVerifyCodeService;
            this.userDetailsService = userDetailsService;
        }
        @Override
        protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) {
            Map<String, String> parameters = new LinkedHashMap<String, String>(tokenRequest.getRequestParameters());
            String client_id = parameters.get("client_id");
            String username = parameters.get("username");
            String captcha = parameters.get("captcha");
            //todo cyx  部署应取消注释(自测试,可注释,不验证短信直接登录)
            if (!wlyyRedisVerifyCodeService.verification(client_id, username, captcha)){
                throw new InvalidGrantException("Invalid captcha");
            }
            String password = parameters.get("password");
            parameters.remove("password");
            Authentication userAuth = new UsernamePasswordAuthenticationToken(username, password);
            ((AbstractAuthenticationToken) userAuth).setDetails(parameters);
            try {
                userAuth = authenticationManager.authenticate(userAuth);
            }
            catch (AccountStatusException ase) {
                throw new InvalidGrantException(ase.getMessage());
            }
            catch (BadCredentialsException e) {
                throw new InvalidGrantException(e.getMessage());
            }
            if (userAuth == null || !userAuth.isAuthenticated()) {
                throw new InvalidGrantException("Could not authenticate user: " + username);
            }
            OAuth2Request storedOAuth2Request = getRequestFactory().createOAuth2Request(client, tokenRequest);
            return new OAuth2Authentication(storedOAuth2Request, userAuth);
        }
    }
}

+ 121 - 113
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyLoginEndpoint.java

@ -404,6 +404,14 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                Oauth2Envelop<WlyyUserSimple> oauth2Envelop = new Oauth2Envelop<>("获取用户手机号失败", -1, null);
                return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
            }
        } else if("1".equals(parameters.get("pwdAndCaptcha"))){
            parameters.put("grant_type", "pwdAndCaptcha");
            KeyPair keyPair = (KeyPair) httpSession.getAttribute("privateKey");
            String password = com.yihu.jw.security.utils.RSAUtils.decryptBase64(parameters.get("password"), keyPair);
            parameters.put("password", password);
            if (!testPwd(parameters.get("password"))) {
                throw new PwdException("密码强度低,请用验证码登录,或者修改密码后在重新登录!");
            }
        }else if (StringUtils.isEmpty(parameters.get("captcha"))) {
            parameters.put("grant_type", "password");
            //解密密码
@ -433,7 +441,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
            throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType());
        }
            //账户密码登录的才验证密码强度
        //账户密码登录的才验证密码强度
        if ("hz_yyyzh_wx".equals(wechatId)||
                "iottest".equals(springProfile)||//物联网
                "iotprod".equals(springProfile)||//物联网
@ -442,7 +450,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
            String grant_type = parameters.get("grant_type");
            if ("password".equals(grant_type)) {
                if (!testPwd(parameters.get("password"))) {
                    throw new PwdException("密码强度低,请用验证码登录,或者修改密码后在从新登录!");
                    throw new PwdException("密码强度低,请用验证码登录,或者修改密码后在重新登录!");
                }
            }
        }
@ -1093,9 +1101,9 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
            }
        }
        if("xm_ykyy_wx".equals(wxId)){
           return sendYKCaptcha(parameters);
            return sendYKCaptcha(parameters);
        }else if("xm_zsyy_wx".equals(wxId)){
           return sendZSCaptcha(parameters);
            return sendZSCaptcha(parameters);
        }else if ("xm_xzzx_wx".equals(wxId)){
            return sendXZCaptcha(parameters);
        }else if ("sd_tnzyy_wx".equals(wxId)){
@ -1554,7 +1562,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
            //固定秘钥解密
            String key = "FEA5049E4CCD16A9";
            String result = AesEncryptUtils.decrypt(data,key);
          /*  String result = AES.decrypt(key,data);*/
            /*  String result = AES.decrypt(key,data);*/
            logger.info("wjwLogin :"+result);
@ -2481,7 +2489,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
    }*/
    @RequestMapping(value = "/oauth/registerPatientAndLogin", method = RequestMethod.POST)
    public ObjEnvelop registerPatientAndLogin(String name, String mobile, String idcard, String ssc, String pw,String client_id,String login_type,String captcha,String openid,String wxId
    ,String geetestChallenge,String geetestValidate,String geetestSeccode )throws Exception{
            ,String geetestChallenge,String geetestValidate,String geetestSeccode )throws Exception{
        if (StringUtils.isEmpty(client_id)) {
            throw new InvalidRequestException("client_id is null");
@ -2658,7 +2666,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
    @RequestMapping(value = "/oauth/findDoctorPw", method = RequestMethod.POST)
    public Envelop findDoctorPw(String mobile,String client_id,String captcha,String pw) throws Exception{
        if("xm_ykyy_wx".equalsIgnoreCase(wechatId)){
           String response =  ykyyService.ResetPwd(mobile,pw,captcha);
            String response =  ykyyService.ResetPwd(mobile,pw,captcha);
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(response)){
                JSONObject object = JSONObject.parseObject(response);
                if (object.getString("code").equalsIgnoreCase("10000")){
@ -2787,10 +2795,10 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
            List<BasePatientDO> patientSize = new ArrayList<>();
            switch (type){
                case "idcard":
                     patientSize = basePatientDao.findByIdcard(id);
                    patientSize = basePatientDao.findByIdcard(id);
                    break;
                case "mobile":
                     patientSize = basePatientDao.findByMobile(id);
                    patientSize = basePatientDao.findByMobile(id);
                    break;
            }
            if (patientSize.size()<0){
@ -3282,108 +3290,108 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                        return getFailedResponse(object.getString("msg"),-1,userSimple);
                    }
                }
                    String response = ykyyService.yktLogin(parameters.get("username"),password);
                    if (!StringUtils.isEmpty(response)){
                        JSONObject object = JSONObject.parseObject(response);
                        if (!object.getString("code").equalsIgnoreCase("200")){
                            throw new Exception(object.getString("msg"));
                        }else {
                            JSONObject jsonObject = object.getJSONObject("data");
                            if (jsonObject!=null){
                                String userId= jsonObject.getString("ID");
                                String tel = jsonObject.getString("LOGINID");
                                List<BasePatientDO> basePatientDOS = basePatientDao.findByMobile(tel);
                                if (basePatientDOS==null||basePatientDOS.size()==0){
                                    BasePatientDO basePatientDO = new BasePatientDO();
                                    String familyList = ykyyService.getFamilyList(null,userId);
                                    JSONObject familyJson = JSONObject.parseObject(familyList);
                                    if (familyJson.getString("code").equalsIgnoreCase("200")){
                                        JSONObject object1 = familyJson.getJSONObject("data");
                                        JSONArray list = object1.getJSONArray("list");
                                        List<String> iliness = new ArrayList<>();
                                        if (list!=null&&list.size()!=0){
                                            for (int i=0;i<list.size();i++){
                                                JSONObject family = list.getJSONObject(i);
                                                iliness.add(family.getString("ILLNESS"));
                                                if (family.getString("ILLNESS").equalsIgnoreCase("本人")&&tel.equalsIgnoreCase(family.getString("TEL"))){
                String response = ykyyService.yktLogin(parameters.get("username"),password);
                if (!StringUtils.isEmpty(response)){
                    JSONObject object = JSONObject.parseObject(response);
                    if (!object.getString("code").equalsIgnoreCase("200")){
                        throw new Exception(object.getString("msg"));
                    }else {
                        JSONObject jsonObject = object.getJSONObject("data");
                        if (jsonObject!=null){
                            String userId= jsonObject.getString("ID");
                            String tel = jsonObject.getString("LOGINID");
                            List<BasePatientDO> basePatientDOS = basePatientDao.findByMobile(tel);
                            if (basePatientDOS==null||basePatientDOS.size()==0){
                                BasePatientDO basePatientDO = new BasePatientDO();
                                String familyList = ykyyService.getFamilyList(null,userId);
                                JSONObject familyJson = JSONObject.parseObject(familyList);
                                if (familyJson.getString("code").equalsIgnoreCase("200")){
                                    JSONObject object1 = familyJson.getJSONObject("data");
                                    JSONArray list = object1.getJSONArray("list");
                                    List<String> iliness = new ArrayList<>();
                                    if (list!=null&&list.size()!=0){
                                        for (int i=0;i<list.size();i++){
                                            JSONObject family = list.getJSONObject(i);
                                            iliness.add(family.getString("ILLNESS"));
                                            if (family.getString("ILLNESS").equalsIgnoreCase("本人")&&tel.equalsIgnoreCase(family.getString("TEL"))){
                                                basePatientDO.setDel("1");
                                                basePatientDO.setName(family.getString("NAME"));
                                                basePatientDO.setCreateTime(new Date());
                                                basePatientDO.setUpdateTime(new Date());
                                                basePatientDO.setYktId(family.getString("ID"));
                                                basePatientDO.setUserId(userId);
                                                basePatientDO.setIdcard(family.getString("IDCARD"));
                                                String idcard = family.getString("IDCARD");
                                                Integer age = IdCardUtil.getAgeForIdcard(idcard);
                                                String sex = IdCardUtil.getSexForIdcard_new(idcard);
                                                Integer sexx = null;
                                                if (org.apache.commons.lang3.StringUtils.isNoneBlank(sex)){
                                                    sexx = Integer.parseInt(sex);
                                                }
                                                String birthDay = family.getString("BIRTHDAY");
                                                Date birthday = null;
                                                if (org.apache.commons.lang3.StringUtils.isNoneBlank(birthDay)){
                                                    birthday = DateUtil.strToDate(birthDay+" 00:00:00");;
                                                }
                                                basePatientDO.setBirthday(birthday);
                                                basePatientDO.setSex(sexx);
                                                basePatientDO.setMobile(tel);
                                                String salt = UUID.randomUUID().toString().substring(0,5);
                                                String pw = idcard.substring(idcard.length()-6,idcard.length());
                                                basePatientDO.setIdcard(idcard);
                                                basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                                                basePatientDO.setSalt(salt);
                                                basePatientDO.setLocked(0);
                                                basePatientDO.setEnabled(1);
                                                basePatientDO.setVerifyCode(jsonObject.getString("TOKEN"));
                                                basePatientDO.setPatientStatus("1");
                                                basePatientDao.save(basePatientDO);
                                            }else {
                                                List<BasePatientDO> basePatientDOList = basePatientDao.findByMobile(tel);
                                                if(basePatientDOList==null||basePatientDOList.size()==0){
                                                    basePatientDO.setDel("1");
                                                    basePatientDO.setName(family.getString("NAME"));
                                                    if (jsonObject.getString("USERNAME").length()>=2){
                                                        basePatientDO.setName(jsonObject.getString("USERNAME"));
                                                    }else {
                                                        basePatientDO.setName(tel);
                                                    }
                                                    basePatientDO.setCreateTime(new Date());
                                                    basePatientDO.setUpdateTime(new Date());
                                                    basePatientDO.setYktId(family.getString("ID"));
                                                    basePatientDO.setYktId(jsonObject.getString("ID"));
                                                    basePatientDO.setUserId(userId);
                                                    basePatientDO.setIdcard(family.getString("IDCARD"));
                                                    String idcard = family.getString("IDCARD");
                                                    Integer age = IdCardUtil.getAgeForIdcard(idcard);
                                                    String sex = IdCardUtil.getSexForIdcard_new(idcard);
                                                    Integer sexx = null;
                                                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(sex)){
                                                        sexx = Integer.parseInt(sex);
                                                    }
                                                    String birthDay = family.getString("BIRTHDAY");
                                                    Date birthday = null;
                                                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(birthDay)){
                                                        birthday = DateUtil.strToDate(birthDay+" 00:00:00");;
                                                    }
                                                    basePatientDO.setBirthday(birthday);
                                                    basePatientDO.setSex(sexx);
                                                    basePatientDO.setMobile(tel);
                                                    String salt = UUID.randomUUID().toString().substring(0,5);
                                                    String pw = idcard.substring(idcard.length()-6,idcard.length());
                                                    basePatientDO.setIdcard(idcard);
                                                    String pw = tel.substring(tel.length()-6,tel.length());
                                                    basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                                                    basePatientDO.setSalt(salt);
                                                    basePatientDO.setLocked(0);
                                                    basePatientDO.setEnabled(1);
                                                    basePatientDO.setVerifyCode(jsonObject.getString("TOKEN"));
                                                    basePatientDO.setPatientStatus("1");
                                                    basePatientDao.save(basePatientDO);
                                                }else {
                                                    List<BasePatientDO> basePatientDOList = basePatientDao.findByMobile(tel);
                                                    if(basePatientDOList==null||basePatientDOList.size()==0){
                                                        basePatientDO.setDel("1");
                                                        if (jsonObject.getString("USERNAME").length()>=2){
                                                            basePatientDO.setName(jsonObject.getString("USERNAME"));
                                                        }else {
                                                            basePatientDO.setName(tel);
                                                        }
                                                        basePatientDO.setCreateTime(new Date());
                                                        basePatientDO.setUpdateTime(new Date());
                                                        basePatientDO.setYktId(jsonObject.getString("ID"));
                                                        basePatientDO.setUserId(userId);
                                                        basePatientDO.setMobile(tel);
                                                        String salt = UUID.randomUUID().toString().substring(0,5);
                                                        String pw = tel.substring(tel.length()-6,tel.length());
                                                        basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                                                        basePatientDO.setSalt(salt);
                                                        basePatientDO.setLocked(0);
                                                        basePatientDO.setEnabled(1);
                                                        basePatientDO.setPatientStatus("1");
                                                        basePatientDao.save(basePatientDO);
                                                    }
                                                }
                                            }
                                        }else {
                                        }
                                    }else {
                                            if (jsonObject.getString("USERNAME").length()>=2){
                                                basePatientDO.setName(jsonObject.getString("USERNAME"));
                                            }else {
                                                basePatientDO.setName(tel);
                                            }
                                            basePatientDO.setDel("1");
                                            basePatientDO.setCreateTime(new Date());
                                            basePatientDO.setUpdateTime(new Date());
                                            basePatientDO.setUserId(userId);
                                            basePatientDO.setMobile(tel);
                                            String salt = UUID.randomUUID().toString().substring(0,5);
                                            String pw = tel.substring(tel.length()-6,tel.length());
                                            basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                                            basePatientDO.setSalt(salt);
                                            basePatientDO.setLocked(0);
                                            basePatientDO.setEnabled(1);
                                            basePatientDO.setPatientStatus("1");
                                            basePatientDao.save(basePatientDO);
                                        if (jsonObject.getString("USERNAME").length()>=2){
                                            basePatientDO.setName(jsonObject.getString("USERNAME"));
                                        }else {
                                            basePatientDO.setName(tel);
                                        }
                                        basePatientDO.setDel("1");
                                        basePatientDO.setCreateTime(new Date());
                                        basePatientDO.setUpdateTime(new Date());
                                        basePatientDO.setUserId(userId);
                                        basePatientDO.setMobile(tel);
                                        String salt = UUID.randomUUID().toString().substring(0,5);
                                        String pw = tel.substring(tel.length()-6,tel.length());
                                        basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                                        basePatientDO.setSalt(salt);
                                        basePatientDO.setLocked(0);
                                        basePatientDO.setEnabled(1);
                                        basePatientDO.setPatientStatus("1");
                                        basePatientDao.save(basePatientDO);
                                    }
                                    /*String birdth = com.yihu.jw.util.idcard.IdCardUtil.getBirthdayForIdcardStr(basePatientDO.getIdcard());
                                    Integer age = com.yihu.jw.util.idcard.IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard());
                                    Integer sex = basePatientDO.getSex()!=null?basePatientDO.getSex():0;
@ -3394,21 +3402,21 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                                    }else {
                                        ykyyService.addFamily(basePatientDO.getUserId(),basePatientDO.getIdcard(),basePatientDO.getName(),sex+"",birdth,age+"",basePatientDO.getMobile());
                                    }*/
                                }
                            }else {
                                logger.info("======"+jsonObject.getString("USERNAME")+"======");
                                logger.info("tel"+jsonObject.getString("USERNAME"));
                                BasePatientDO basePatientDO1 = basePatientDOS.get(0);
                                if (basePatientDO1.getName()==null||basePatientDO1.getName()==""){
                                    if (jsonObject.getString("USERNAME").length()>=2){
                                        basePatientDO1.setName(jsonObject.getString("USERNAME"));
                                    }else {
                                        basePatientDO1.setName(tel);
                                    }
                                }else {
                                    logger.info("======"+jsonObject.getString("USERNAME")+"======");
                                    logger.info("tel"+jsonObject.getString("USERNAME"));
                                    BasePatientDO basePatientDO1 = basePatientDOS.get(0);
                                    if (basePatientDO1.getName()==null||basePatientDO1.getName()==""){
                                        if (jsonObject.getString("USERNAME").length()>=2){
                                            basePatientDO1.setName(jsonObject.getString("USERNAME"));
                                        }else {
                                            basePatientDO1.setName(tel);
                                        }
                                    }
                                    basePatientDO1.setVerifyCode(jsonObject.getString("TOKEN"));
                                    basePatientDO1.setUserId(userId);
                                    basePatientDao.save(basePatientDO1);
                                }
                                basePatientDO1.setVerifyCode(jsonObject.getString("TOKEN"));
                                basePatientDO1.setUserId(userId);
                                basePatientDao.save(basePatientDO1);
                                /*String familyList = ykyyService.getFamilyList(null,userId);
                                JSONObject familyJson = JSONObject.parseObject(familyList);
                                if (familyJson.getString("code").equalsIgnoreCase("200")){
@ -3437,12 +3445,12 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                                    }
                                }*/
                                }
                            }
                        }
                    }
                    parameters.remove("password");
                } else if (!StringUtils.isEmpty(loginType)&&"3".equalsIgnoreCase(loginType)){
                }
                parameters.remove("password");
            } else if (!StringUtils.isEmpty(loginType)&&"3".equalsIgnoreCase(loginType)){
                if (wlyyRedisVerifyCodeService.verification(client_id, username, captcha)) {
                    //验证码正确
                }
@ -3598,7 +3606,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                    return ObjEnvelop.getError("验证码错误!");
                }
            }else if (wlyyRedisVerifyCodeService.verification(client_id, mobile, captcha)) {
                    //验证码正确
                //验证码正确
            } else {
                return ObjEnvelop.getError("验证码错误!");
            }

+ 1 - 0
server/svr-authentication/src/main/resources/application.yml

@ -97,6 +97,7 @@ spring:
  redis:
    host: 172.26.0.253 # Redis server host.
    port: 6379 # Redis server port.
    password: Kb6wKDQP1W4
  ##发现服务
## i健康用户信息接口,开放出来给互联网医院登录同步用户信息用

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

@ -41,110 +41,114 @@ public class PatientSosContactsJob implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("PATIENT_SOS_CONTACTS_JOB start");
        try {
            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);
        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 " +
                "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 ";
        List<Map<String,Object>> sims = jdbcTemplate.queryForList(sql);
        List<PatientSosContactsDO> modify = new ArrayList<>();
        for(Map<String,Object> tmp:sims){//添加白名单,添加设备联系人
            String sim = tmp.get("sim")==null?null:tmp.get("sim").toString() ;
            String patient = tmp.get("patient").toString() ;
            String device_sn = tmp.get("device_sn").toString() ;
            String category_code = tmp.get("category_code").toString() ;
            String id = tmp.get("id").toString() ;
            String sos_name = tmp.get("sos_name").toString() ;
            String sos_phone = tmp.get("sos_phone").toString() ;
            String phone_seqid = tmp.get("phone_seqid").toString() ;
            try {
                PatientSosContactsDO sosContactsDO = sosContactsDao.findOne(Long.parseLong(id));
                if (StringUtils.isBlank(sosContactsDO.getUpdateInfo())){
                    sosContactsDO.setUpdateInfo(" ");
                }
                if(null!=sosContactsDO){
                    if (StringUtils.isNotBlank(sim)){
                        JSONObject response = cardService.setPatientContacts(null, sim, null, "1", sos_phone);//移动白名单
                        //0成功 12102名单重复
                        if (response.getInteger("status")==0||response.getInteger("status")==12108){
                            if (1==sosContactsDO.getSuccessFlag()||0==sosContactsDO.getSuccessFlag()){
                                sosContactsDO.setSuccessFlag(1);
                            }else {
                                sosContactsDO.setSuccessFlag(-1);
                            }
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+1+"}");
                        }else {
                            sosContactsDO.setSuccessFlag(-1);
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+-1+"}");
                            sosContactsDO.setErrorInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+response.getString("message")+"}");
                        }
            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 " +
                    "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 ";
            List<Map<String,Object>> sims = jdbcTemplate.queryForList(sql);
            List<PatientSosContactsDO> modify = new ArrayList<>();
            for(Map<String,Object> tmp:sims){//添加白名单,添加设备联系人
                String sim = tmp.get("sim")==null?null:tmp.get("sim").toString() ;
                String patient = tmp.get("patient").toString() ;
                String device_sn = tmp.get("device_sn").toString() ;
                String category_code = tmp.get("category_code").toString() ;
                String id = tmp.get("id").toString() ;
                String sos_name = tmp.get("sos_name").toString() ;
                String sos_phone = tmp.get("sos_phone").toString() ;
                String phone_seqid = tmp.get("phone_seqid").toString() ;
                try {
                    PatientSosContactsDO sosContactsDO = sosContactsDao.findOne(Long.parseLong(id));
                    if (StringUtils.isBlank(sosContactsDO.getUpdateInfo())){
                        sosContactsDO.setUpdateInfo(" ");
                    }
                    //设备修改
                    if ("4".equals(category_code)||"7".equals(category_code)){
                        JSONObject response2 =  deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
                        if (response2.getBoolean("success")){
                            if (1==sosContactsDO.getSuccessFlag()||0==sosContactsDO.getSuccessFlag()){
                                sosContactsDO.setSuccessFlag(1);
                    if(null!=sosContactsDO){
                        if (StringUtils.isNotBlank(sim)){
                            JSONObject response = cardService.setPatientContacts(null, sim, null, "1", sos_phone);//移动白名单
                            logger.info("setPatientContacts:"+response);
                            //0成功 12102名单重复
                            if (response.getInteger("status")==0||response.getInteger("status")==12108){
                                if (1==sosContactsDO.getSuccessFlag()||0==sosContactsDO.getSuccessFlag()){
                                    sosContactsDO.setSuccessFlag(1);
                                }else {
                                    sosContactsDO.setSuccessFlag(-1);
                                }
                                sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+1+"}");
                            }else {
                                sosContactsDO.setSuccessFlag(-1);
                            }
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+1+"}");
                        }else {
                            sosContactsDO.setSuccessFlag(-1);
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+-1+"}");
                            sosContactsDO.setErrorInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+response2.getString("message")+"}");
                        }
                    }else if ("16".equals(category_code)){
                        sql =" select sos_phone from base_patient_sos_contacts where patient='"+patient+"' and del=1 order by phone_seqid asc ";
                        List<String> nums = jdbcTemplate.queryForList(sql,String.class);
                        String phone1 = null;
                        String phone2 = null;
                        String phone3 = null;
                        for (int i=0;i<nums.size();i++){
                            if(i==0){
                                phone1 = nums.get(i);
                            }
                            if(i==2){
                                phone2 = nums.get(i);
                                sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+-1+"}");
                                sosContactsDO.setErrorInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+response.getString("message")+"}");
                            }
                        }
                        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);
                        }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 ("4".equals(category_code)||"7".equals(category_code)){
                            JSONObject response2 =  deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
                            logger.info("updAqgDeviceSosInfo:"+response2);
                            if (response2.getBoolean("success")){
                                if (1==sosContactsDO.getSuccessFlag()||0==sosContactsDO.getSuccessFlag()){
                                    sosContactsDO.setSuccessFlag(1);
                                }else {
                                    sosContactsDO.setSuccessFlag(-1);
                                }
                            } else { //返回失败
                                sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+1+"}");
                            }else {
                                sosContactsDO.setSuccessFlag(-1);
                                sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+-1+"}");
                                sosContactsDO.setErrorInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+response2.getString("message")+"}");
                            }
                        }else if ("16".equals(category_code)){
                            sql =" select sos_phone from base_patient_sos_contacts where patient='"+patient+"' and del=1 order by phone_seqid asc ";
                            List<String> nums = jdbcTemplate.queryForList(sql,String.class);
                            String phone1 = null;
                            String phone2 = null;
                            String phone3 = null;
                            for (int i=0;i<nums.size();i++){
                                if(i==0){
                                    phone1 = nums.get(i);
                                }
                                if(i==2){
                                    phone2 = nums.get(i);
                                }
                            }
                            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+":"+yxResponseObj.getString("message")+"}");
                                    sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":error}");
                                }
                                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+":"+yxResponseObj.getString("message")+"}");
                                    }
                                    sosContactsDO.setSuccessFlag(-1);
                                }
                            }
                        }
                        sosContactsDao.save(sosContactsDO);
                    }
                    sosContactsDao.save(sosContactsDO);
                }catch (Exception e){
                    logger.info(sim+"--同步失败--"+sos_phone);
                    e.printStackTrace();
                }
            }catch (Exception e){
                logger.info(sim+"--同步失败--"+sos_phone);
                e.printStackTrace();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
//        sosContactsDao.save(modify);
        logger.info("PATIENT_SOS_CONTACTS_JOB end");
    }
}