Browse Source

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

# Conflicts:
#	common/common-entity/sql记录
yeshijie 3 years ago
parent
commit
c4b9f64a97

+ 2 - 0
common/common-entity/sql记录

@ -1387,6 +1387,8 @@ CREATE TABLE `base_yxdevice_index` (
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='云芯拐杖设备上传记录';
-- 20210828
ALTER table base_patient_sos_contacts add column update_info VARCHAR(1000) default null comment '同步信息 1成功,-1失败'
-- 20210828
alter table base_patient add `sign_status` tinyint(1) DEFAULT NULL COMMENT '签约状态 1已签约 0未签约';

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

@ -21,9 +21,10 @@ public class PatientSosContactsDO extends IdEntity {
    private String sosPhone; //联系电话
    private Integer relation; //与联系人关系 同base_patient_family_member
    private Date updateTime; //修改日期
    private Integer successFlag;//联系人是否同步成功 -2删除失败 -1添加失败 0待同步 1添加成功 2删除成功
    private Integer successFlag;//联系人是否同步成功 -1失败 0待同步 1成功
    private Integer del;
    private Integer phoneSeqid;// 联系人序号 1 或2
    private String updateInfo;//同步信息 -1失败 1成功
    private String relationName;
@ -100,4 +101,12 @@ public class PatientSosContactsDO extends IdEntity {
    public void setPhoneSeqid(Integer phoneSeqid) {
        this.phoneSeqid = phoneSeqid;
    }
    public String getUpdateInfo() {
        return updateInfo;
    }
    public void setUpdateInfo(String updateInfo) {
        this.updateInfo = updateInfo;
    }
}

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

@ -2,6 +2,8 @@ package com.yihu.jw.care.dao.contacts;
import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
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;
@ -17,4 +19,8 @@ public interface PatientSosContactsDao extends PagingAndSortingRepository<Patien
    List<PatientSosContactsDO> findByPatientOrderByUpdateTimeDesc(String patient);
    PatientSosContactsDO findByPatientAndSosPhone(String patient,String sosPhone);
    @Modifying
    @Query(" update PatientSosContactsDO a set a.successFlag = 0,a.updateInfo=null where a.patient=?1")
    void updateByPatient(String patient);
}

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

@ -313,11 +313,13 @@ public class PadDeviceController extends BaseController {
    public String addPatientSosContacts(@ApiParam(name = "patient", value = "patient", defaultValue = "patient")
                                           @RequestParam(value = "patient", required = true) String patient,
                                        @ApiParam(name = "jsonStr", value = "patient", defaultValue = "patient")
                                        @RequestParam(value = "jsonStr", required = true) String jsonStr){
                                        @RequestParam(value = "jsonStr", required = true) String jsonStr,
                                        @ApiParam(name = "isUpdate", value = "是否有更新联系人 1是 0否", defaultValue = "isUpdate")
                                        @RequestParam(value = "isUpdate", defaultValue = "1") Integer isUpdate){
        try {
            JSONObject result = contactsService.addPatientSosContacts(patient,jsonStr);
            JSONObject result = contactsService.addPatientSosContacts(patient,jsonStr,isUpdate);
            if (ResponseContant.success == result.getInteger(ResponseContant.resultFlag)){
                return success("添加成功");
            }

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

@ -276,6 +276,7 @@ public class ContactsService {
                contactsDO = new PatientSosContactsDO();
                contactsDO.setPhoneSeqid(1==seqid?2:1);
            }
            contactsDO.setUpdateInfo(null);
            contactsDO.setDel(1);
            contactsDO.setPatient(patient);
            contactsDO.setSosName(name);
@ -293,41 +294,47 @@ public class ContactsService {
    /**
     *设备绑定添加居民紧急联系人
     */
    public JSONObject addPatientSosContacts(String patient,String jsonStr) throws Exception {
    @Transactional(rollbackFor = Exception.class)
    public JSONObject addPatientSosContacts(String patient,String jsonStr,Integer isUpdate) throws Exception {
        JSONObject result = new JSONObject();
        List<PatientSosContactsDO> list = sosContactsDao.findByPatientOrderByUpdateTimeDesc(patient);
        JSONArray jsonArray = JSONArray.parseArray(jsonStr);
        for (int i=0;i<jsonArray.size();i++){
            list = sosContactsDao.findByPatientAndDel(patient,1);
            JSONObject obj = jsonArray.getJSONObject(i);
            String num = obj.getString("num");
            String name = obj.getString("name");
            String relation = obj.getString("relation");
            Integer seqid=0;
            if (list.size()>=2){
                List<String> sosContacts =list.stream().map(PatientSosContactsDO::getSosPhone).collect(Collectors.toList());
                if (!sosContacts.contains(num)){
                    result.put(ResponseContant.resultFlag,ResponseContant.fail);
                    result.put(ResponseContant.resultMsg,"该用户紧急联系人已上限");
                    return result;
        if (0==isUpdate){
            sosContactsDao.updateByPatient("updateByPatient");
        }else {
            for (int i=0;i<jsonArray.size();i++){
                list = sosContactsDao.findByPatientAndDel(patient,1);
                JSONObject obj = jsonArray.getJSONObject(i);
                String num = obj.getString("num");
                String name = obj.getString("name");
                String relation = obj.getString("relation");
                Integer seqid=0;
                if (list.size()>=2){
                    List<String> sosContacts =list.stream().map(PatientSosContactsDO::getSosPhone).collect(Collectors.toList());
                    if (!sosContacts.contains(num)){
                        result.put(ResponseContant.resultFlag,ResponseContant.fail);
                        result.put(ResponseContant.resultMsg,"该用户紧急联系人已上限");
                        return result;
                    }
                }
            }
            if (list.size()>0){
                seqid = list.get(0).getPhoneSeqid();
            }
            PatientSosContactsDO contactsDO = sosContactsDao.findByPatientAndSosPhone(patient,num);
            if(null==contactsDO){
                contactsDO = new PatientSosContactsDO();
                contactsDO.setPhoneSeqid(1==seqid?2:1);
            }
            contactsDO.setDel(1);
            contactsDO.setPatient(patient);
            contactsDO.setSosName(name);
            contactsDO.setSosPhone(num);
            contactsDO.setRelation(Integer.parseInt(relation));
            contactsDO.setSuccessFlag(0);
            sosContactsDao.save(contactsDO);
                if (list.size()>0){
                    seqid = list.get(0).getPhoneSeqid();
                }
                PatientSosContactsDO contactsDO = sosContactsDao.findByPatientAndSosPhone(patient,num);
                if(null==contactsDO){
                    contactsDO = new PatientSosContactsDO();
                    contactsDO.setPhoneSeqid(1==seqid?2:1);
                }
                contactsDO.setUpdateInfo(null);
                contactsDO.setDel(1);
                contactsDO.setPatient(patient);
                contactsDO.setSosName(name);
                contactsDO.setSosPhone(num);
                contactsDO.setRelation(Integer.parseInt(relation));
                contactsDO.setSuccessFlag(0);
                sosContactsDao.save(contactsDO);
            }
        }
        result.put(ResponseContant.resultFlag,ResponseContant.success);
        result.put(ResponseContant.resultMsg,"修改成功");

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

@ -174,7 +174,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
     * @param patient
     */
    public List<Map<String,Object>> gasConcentration(String patient,String date,String deviceSn){
        String sql = "SELECT r.value,r.create_time from wlyy_patient_device pd,base_device_health_index r " +
        String sql = "SELECT r.value,CAST(DATE_FORMAT(r.create_time,'%Y-%m-%d %H:%i:%S') as char) create_time  from wlyy_patient_device pd,base_device_health_index r " +
                "WHERE pd.device_sn = r.device_sn  ";
        if (StringUtils.isNotBlank(patient)){
            sql +=" and pd.`user` = '"+patient+"' ";
@ -915,7 +915,8 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                result.put(ResponseContant.resultMsg,"居民未绑定该设备");
            }else {
                String sql = "select dd.photo,GROUP_CONCAT( p.name) as patientName,pd.device_sn,dd.brands,dd.category_code,dd.model,pd.device_name,date_format(pd.czrq,'%Y-%m-%d %H:%i:%S' ) deviceTime " +
                        "from dm_device dd INNER JOIN wlyy_patient_device pd on dd.category_code = pd.category_code INNER JOIN base_patient p on p.id = pd.user \n" +
                        "from dm_device dd INNER JOIN wlyy_patient_device pd on dd.category_code = pd.category_code INNER JOIN base_patient p on p.id = pd.user " +
                        " INNER JOIN wlyy_devices wd on dd.model = wd.device_model and pd.device_sn = wd.device_code " +
                        "where 1=1 and  pd.del=0 and pd.device_sn ='"+deviceSn+"' group by pd.device_sn";
                Map<String,Object> devInfo = jdbcTemplate.queryForMap(sql);
                devInfo.put("patient",patient);
@ -1261,6 +1262,15 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                                                                 String time_begin,String time_end,String safe_area ,String clear) throws Exception{
        List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
        String url ="";
        if ("16".equals(devices.get(0).getCategoryCode())) {
            DevicePatientDevice patientDevice = devices.get(0);
            if (StringUtils.isNotBlank(safe_area)){
                patientDevice.setSafeAreaGz(safe_area);
                patientDeviceDao.save(patientDevice);
            }
        }
        if ("4".equals(devices.get(0).getCategoryCode())){//手表
            Device device = deviceDao.findOne(devices.get(0).getDeviceId());
            if (device!=null){

+ 13 - 6
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/statistics/DetectionPlatformService.java

@ -61,7 +61,7 @@ public class DetectionPlatformService  {
            List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
            return PageEnvelop.getSuccessListWithPage("查询成功",list,page,pageSize,count);
        }else {
            String sql = " select  '22' as 'OrderType',ord.id,ord.patient,p.name,ord.serve_desc,DATE_FORMAT(ord.create_time,'%Y-%m-%d %H:%i:%S') create_time,ord.`status` \n" +
            String sql = " select  '22' as 'OrderType',ord.id,ord.patient,p.name,ord.serve_desc,DATE_FORMAT(ord.create_time,'%Y-%m-%d %H:%i:%S') create_time,ord.`status`,ord.doctor,ord.doctor_name \n" +
                    "from base_security_monitoring_order ord INNER JOIN base_patient p on ord.patient = p.id order by create_time desc ";
            String countSql = "select count(id) from ("+sql+")A ";
            long count = jdbcTemplate.queryForObject(countSql,long.class);
@ -169,6 +169,7 @@ public class DetectionPlatformService  {
    public JSONArray getDeviceByCondition(String categoryCode , String user){
        JSONArray jsonArray = new JSONArray();
        JSONArray arrayAll = new JSONArray();
        List<DevicePatientDevice> patientDevices = patientDeviceDao.findAllGroupUser();
        if (StringUtils.isNotBlank(categoryCode)) {  //categoryCode != null   根据设备类型查询
            patientDevices = patientDeviceDao.findAllByCategoryCode(categoryCode);
@ -187,7 +188,6 @@ public class DetectionPlatformService  {
//        List<Map<String , Object>> userList = jdbcTemplate.queryForList(userSql);
        if (patientDevices.size() > 0) {
            for (int i=0;i<patientDevices.size();i++) {
                JSONArray arrayAll = new JSONArray();
                JSONArray array = new JSONArray();
                JSONObject userObj = new JSONObject();
                userObj.put("patient",patientDevices.get(i).getUser());
@ -222,13 +222,12 @@ public class DetectionPlatformService  {
                        userObj.put("deviceInfo",array);
                        arrayAll.add(userObj);
                    }
                    jsonArray.add(arrayAll);
                }
            }
        } else {
            return jsonArray;
            return arrayAll;
        }
        return jsonArray;
        return arrayAll;
    }
    public JSONObject getDeviceInfo(String deviceSn) throws Exception{
@ -252,8 +251,10 @@ public class DetectionPlatformService  {
                object.put("idcard",patientInfoList.get(0).get("idcard"));
                object.put("address",patientInfoList.get(0).get("address"));
                String dataSql= "";
                String recordSql = "";
                List<Map<String , Object>> dataList = new ArrayList<>();
                switch (categoryCode) {
                List<Map<String , Object>> recordList = new ArrayList<>();
                switch (categoryCode) {     //设备数据
                    // 1=血糖仪  2=血压计 14=燃气报警器  15=烟雾报警器
                    // 4=智能手表  7=居家安全报警器  16=智能拐杖  13=智能床带/睡眠带
                    case "1" :
@ -270,11 +271,17 @@ public class DetectionPlatformService  {
                        dataSql = "SELECT record_time recordDate,`value`,unit,device_type FROM base_device_health_index WHERE device_sn = '"+deviceSn+"' ORDER BY record_time DESC LIMIT 10 ";
                        dataList = jdbcTemplate.queryForList(dataSql);
                        object.put("data",dataList);
                        recordSql = "SELECT * FROM base_device_health_index WHERE device_sn = '"+deviceSn+"' order by record_time desc ";
                        recordList = jdbcTemplate.queryForList(recordSql);
                        object.put("record",recordList);
                        break;
                    case "15" :
                        dataSql = "SELECT record_time recordDate,`value`,unit,device_type FROM base_device_health_index WHERE device_sn = '"+deviceSn+"' ORDER BY record_time DESC LIMIT 10 ";
                        dataList = jdbcTemplate.queryForList(dataSql);
                        object.put("data",dataList);
                        recordSql = "SELECT * FROM base_device_health_index WHERE device_sn = '"+deviceSn+"' order by record_time desc ";
                        recordList = jdbcTemplate.queryForList(recordSql);
                        object.put("record",recordList);
                        break;
                }
            } else {

+ 15 - 9
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/statistics/StatisticsService.java

@ -27,6 +27,7 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
@ -676,16 +677,21 @@ public class StatisticsService {
    public JSONArray capacityAssessment(String endDate, String area, int level) throws Exception{
        //评估类型
        JSONArray jsonArray = new JSONArray();
        List<SaveModel> list = statisticsUtilService.findDateAllQuotaLevel1Sort(endDate,endDate,area,level,"37",SaveModel.timeLevel_DDL,null,null);
        for(int i=0;i<list.size();i++){
            SaveModel saveModel = list.get(i);
        String sql = " select dict.dict_code,dict_value,count(DISTINCT lab.patient) total from wlyy_hospital_sys_dict dict \n" +
                "LEFT JOIN wlyy_patient_label lab  on  dict.dict_code = lab.label_code\n" +
                "where  dict.dict_name='service_type' and  dict.dict_code is not null and dict_code<>5  \n" +
                " GROUP BY dict.dict_code; ";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        String older = "  select count(id) from base_patient where archive_type=1 ";
        Integer count = jdbcTemplate.queryForObject(older,Integer.class);
        for(Map<String,Object> map:list){
            JSONObject json = new JSONObject();
            if (saveModel.getResult2().longValue()==0&&StringUtils.isBlank(saveModel.getSlaveKey1())){
                continue;
            }
            json.put("num",saveModel.getResult2().longValue());
            json.put("code",saveModel.getSlaveKey1());
            json.put("name",saveModel.getSlaveKey1Name());
            DecimalFormat df = new DecimalFormat("0.00");
            json.put("num", df.format((Integer.parseInt(map.get("total").toString())*1.00) / count * 100));
            json.put("code",map.get("dict_code").toString());
            json.put("name",map.get("dict_value").toString());
            jsonArray.add(json);
        }
        return jsonArray;

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

@ -170,7 +170,7 @@ public class DeviceService {
                String sql =" select Distinct pack.org_code,pack.org_name\n" +
                        "from base_service_package_sign_record sr INNER JOIN base_service_package_record pr\n" +
                        "on sr.id = pr.sign_id and sr.status=1 INNER JOIN base_service_package_item item on pr.service_package_id = item.service_package_id and item.del=1 \n" +
                        "INNER JOIN base_service_package pack pack on pr.service_package_id = pack.id where item.code='emergencyAssistance' and sr.patient='"+patientDO.getId()+"'";
                        "INNER JOIN base_service_package pack on pr.service_package_id = pack.id where item.code='emergencyAssistance' and sr.patient='"+patientDO.getId()+"'";
                List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql);
                if (sqlResult.size()>0){
                    JSONObject jsonObject = new JSONObject();

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

@ -35,54 +35,83 @@ public class PatientSosContactsJob implements Job {
    private NetworkCardService cardService;
    @Autowired
    private PatientDeviceService deviceService;
    @Autowired
    private YunXunDeviceService yunXunDeviceService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("PATIENT_SOS_CONTACTS_JOB start");
        String sql = " select pd.device_sn,wd.sim,sc.* 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') " +
                "INNER JOIN base_patient_sos_contacts sc on sc.patient = pd.user and sc.del=1 and sc.success_flag=0 group by wd.sim";
        String sql = " select pd.device_sn,pd.category_code,wd.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").toString() ;
            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){
                    JSONObject response = cardService.setPatientContacts(sim, null, null, "1", sos_phone, null);//移动白名单
                    //0成功 12102名单重复
                    if (response.getInteger("status")==0||response.getInteger("status")==12108){
                        sosContactsDO.setSuccessFlag(1);
                    }else {
                        sosContactsDO.setSuccessFlag(-1);
                        modify.add(sosContactsDO);
                    if (StringUtils.isNotBlank(sim)){
                        JSONObject response = cardService.setPatientContacts(sim, null, null, "1", sos_phone, null);//移动白名单
                        //0成功 12102名单重复
                        if (response.getInteger("status")==0||response.getInteger("status")==12108){
                            sosContactsDO.setSuccessFlag(1);
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+1+"}");
                        }else {
                            sosContactsDO.setSuccessFlag(-1);
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+-1+"}");
                        }
                    }
                    //设备修改
                    JSONObject response2 =  deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
                    System.out.println(response2.toString());
                    if (response2.getBoolean("success")){
                        if (1==sosContactsDO.getSuccessFlag()){
                            sosContactsDO.setSuccessFlag(1);
                    if ("4".equals(category_code)||"7".equals(category_code)){
                        JSONObject response2 =  deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
                        System.out.println(response2.toString());
                        if (response2.getBoolean("success")){
                            if (1==sosContactsDO.getSuccessFlag()){
                                sosContactsDO.setSuccessFlag(1);
                            }
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+1+"}");
                        }else {
                            sosContactsDO.setSuccessFlag(-1);
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+-1+"}");
                        }
                    }else if ("16".equals(category_code)){
                        sql =" select sos_phone from base_patient_sos_contacts where patient='"+patient+"' ";
                        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.setSuccessFlag(-1);
                    }else {
                        sosContactsDO.setSuccessFlag(-1);
                        yunXunDeviceService.setSos(device_sn,phone1,phone2,phone3);
                        sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":unknow}");
                    }
                    modify.add(sosContactsDO);
                    sosContactsDao.save(sosContactsDO);
                }
            }catch (Exception e){
                logger.info(sim+"--同步失败--"+sos_phone);
                e.printStackTrace();
            }
        }
        sosContactsDao.save(modify);
//        sosContactsDao.save(modify);
        logger.info("PATIENT_SOS_CONTACTS_JOB end");
    }
}

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

@ -0,0 +1,71 @@
package com.yihu.jw.care.job.device;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * Created with IntelliJ IDEA.
 * 云芯拐杖设备对接
 * @Author: yeshijie
 * @Date: 2021/8/27
 * @Description:
 */
@Service
public class YunXunDeviceService {
    private static Logger logger = LoggerFactory.getLogger(YunXunDeviceService.class);
    @Autowired
    private HttpClientUtil httpClientUtil;
    /**
     * 设置紧急联系人
     * @param sn
     * @param phone1
     * @param phone2
     * @param phone3
     */
    public void setSos(String sn,String phone1,String phone2,String phone3){
        if(StringUtil.isBlank(phone1)){
            return;
        }
        //[IC*334588000000156*0027*SOS,00000000000,00000000000]
        String order = "SOS,"+phone1;
        if(!StringUtil.isBlank(phone2)){
            order += ","+phone2;
        }
        if(!StringUtil.isBlank(phone3)){
            order += ","+phone3;
        }
        String instruction = "[IC*"+sn+"*"+hex10To16(order.length())+"]";
        sendInstruction(sn,instruction);
    }
    /**
     * 发送指令接口
     * @param instruction
     */
    public void sendInstruction(String sn,String instruction){
        try {
            String url = "http://117.24.13.79:43210/yunxin/sendMessage?deviceSN="+sn+"&message="+instruction;
            String response = httpClientUtil.get(url,"UTF-8");
            logger.info("sendInstruction="+response);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 保留4位 十进制转十六进制
     * @param ten
     * @return
     */
    public String hex10To16(int ten){
        return String.format("%04x",ten);
    }
}