Browse Source

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

yeshijie 3 years ago
parent
commit
3fe2857890

+ 1 - 1
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/DevicePatientDevice.java

@ -21,7 +21,7 @@ public class DevicePatientDevice extends IdEntity {
    private String deviceName;
    // 用户code
    private String user;
    // 设备类型标识 1血糖仪,2.血压计,3药盒,4智能手表,7 = 居家报警器,12 监控器 13 睡眠带 14气感报警器 15烟感报警器
    // 设备类型标识 1血糖仪,2.血压计,3药盒,4智能手表,7 = 居家报警器,12 监控器 13 睡眠带 14气感报警器 15烟感报警器 16拐杖 17随身wifi
    private String categoryCode;
    // 用户类型标准 -1代表单用户
    private String userType;

+ 20 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/device/BaseYxDeviceIndexDao.java

@ -0,0 +1,20 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.BaseYxDeviceIndex;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yeshijie
 * @Date: 2021/8/26
 * @Description:
 */
public interface BaseYxDeviceIndexDao extends PagingAndSortingRepository<BaseYxDeviceIndex, String> {
    @Query(value = "SELECT a.* from base_yxdevice_index a where a.sn=?1 and a.lat!=0 and a.lon!=0 order by a.create_time desc limit 1",nativeQuery = true)
    List<BaseYxDeviceIndex> findBySn(String sn);
}

+ 1 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/security/SecurityMonitoringOrderEndpoint.java

@ -340,7 +340,7 @@ public class SecurityMonitoringOrderEndpoint extends EnvelopRestEndpoint {
                                            @ApiParam(name = "topicItem", value = "专题code,关联security_topic_dict字典", required = false)
                                            @RequestParam(value = "topicItem") String topicItem) {
        try {
            return ObjEnvelop.getSuccess( "查询成功", securityMonitoringOrderService.patientSignTopicInfo(null,patient,topicItem));
            return ObjEnvelop.getSuccess( "查询成功", securityMonitoringOrderService.patientSignTopicInfo(null,patient,topicItem,null));
        } catch (Exception e) {
            return failedObjEnvelopException2(e);
        }

+ 45 - 16
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/assistance/EmergencyAssistanceService.java

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.yihu.jw.care.dao.assistance.EmergencyAssistanceDao;
import com.yihu.jw.care.dao.device.BaseYxDeviceIndexDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.security.BaseEmergencyWarnLogDao;
import com.yihu.jw.care.dao.security.EmergencyWarnConclusionDao;
@ -18,6 +19,7 @@ import com.yihu.jw.care.service.device.PatientDeviceService;
import com.yihu.jw.care.service.family.PatientFamilyMemberService;
import com.yihu.jw.care.util.ConstantUtil;
import com.yihu.jw.care.util.CountDistance;
import com.yihu.jw.care.util.MessageUtil;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.im.ConsultDo;
@ -25,6 +27,7 @@ import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.assistance.EmergencyAssistanceDO;
import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
import com.yihu.jw.entity.care.device.BaseYxDeviceIndex;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.securitymonitoring.BaseEmergencyWarnLogDO;
import com.yihu.jw.entity.care.securitymonitoring.EmergencyWarnConclusionDO;
@ -39,6 +42,7 @@ import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.emergency.EmergencyOrderVO;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.common.LatitudeUtils;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.mysql.query.BaseJpaService;
@ -105,6 +109,10 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
    private BaseEmergencyWarnLogDao logDao;
    @Autowired
    private ContactsService contactsService;
    @Autowired
    private MessageUtil messageUtil;
    @Autowired
    private BaseYxDeviceIndexDao yxDeviceIndexDao;
    /**
     * 获取百度天气
@ -230,6 +238,9 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
        for (BaseDoctorDO doctorDO:doctorDOS){
            try {
                if (StringUtils.isNotBlank(doctorDO.getMobile())){
                    messageUtil.sendTXYSJson("1099807",doctorDO.getMobile(),assistanceDO.getPatientName(),"紧急呼叫");
                }
                imUtill.sendMDTSocketMessageToDoctor(doctorDO.getId(),message.toString());
            }catch (Exception e){
                e.printStackTrace();
@ -255,7 +266,7 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
        }
        emergencyOrderVO.setId(assistanceDO.getId());
        //手环发起时坐标已取
        if (assistanceDO.getOrderSource()==2){//手环发起的紧急救助获取手环坐标
        if (assistanceDO.getOrderSource()==2){//手环发起的紧急救助实时获取手环坐标
            try {
                List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(assistanceDO.getPatient(),"4");
                if (devicePatientDeviceDos.size()>0){
@ -281,6 +292,20 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
            }catch (Exception e){
            }
        }else if (assistanceDO.getOrderSource()==4){//拐杖
            if (StringUtils.isNotBlank(assistanceDO.getDeviceSn())){
                List<BaseYxDeviceIndex> points = yxDeviceIndexDao.findBySn(assistanceDO.getDeviceSn());
                if (points.size()>0){
                    long lat = Long.parseLong(points.get(0).getLat());
                    long lon = Long.parseLong(points.get(0).getLon());
                    if (!(lat==0.0&&lon==0.0)){
                        assistanceDO.setServeAddress(LatitudeUtils.getLocationAddress(lat+"",lon+""));
                        assistanceDO.setServeLat(lat+"");
                        assistanceDO.setServeLon(lon+"");
                        assistanceDO = emergencyAssistanceDao.save(assistanceDO);
                    }
                }
            }
        }
        BasePatientDO patientDO = patientDao.findById(assistanceDO.getPatient());
        Integer statustemp = Integer.valueOf(assistanceDO.getStatus()+"");
@ -343,22 +368,26 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
        JSONArray familyArr =  familyMemberService.getPatientMembers(assistanceDO.getPatient(),null,null,null,null);
        String emeCallPhone = "";
        if (assistanceDO.getOrderSource()!=1){//设备发起工单
            String category = assistanceDO.getOrderSource()==2?"4":"7";
            List<DevicePatientDevice> devices = patientDeviceDao.findByUserAndCategoryCode(assistanceDO.getPatient(),category);
            if (devices.size()>0){
//            String category = assistanceDO.getOrderSource()==2?"4":"7";
            //v1.0紧急联系人设备共用从数据库中获取
            String sql = " select sos_phone from base_patient_sos_contacts where patient='"+assistanceDO.getPatient()+"' order by phone_seqid asc ";
            List<String> nums = jdbcTemplate.queryForList(sql,String.class);
//            List<DevicePatientDevice> devices = patientDeviceDao.findByUserAndCategoryCode(assistanceDO.getPatient(),category);
            if (nums.size()>0){
                try {
                    com.alibaba.fastjson.JSONObject jsonTmp = patientDeviceService.getAqgDeviceInfo(devices.get(0).getDeviceSn());
                    if (jsonTmp.containsKey("sos_numbers")){//取第一个号码
                        JSONArray array = jsonTmp.getJSONArray("sos_numbers");
                        for (int i=0;i<array.size();i++){
                            JSONObject obj = array.getJSONObject(i);
                            if (obj.getBooleanValue("dial_flag")){
                                emeCallPhone = obj.getString("num");
                                break;
                            }
                        }
                    }
                    emeCallPhone = nums.get(0);
//                    com.alibaba.fastjson.JSONObject jsonTmp = patientDeviceService.getAqgDeviceInfo(devices.get(0).getDeviceSn());
//                    if (jsonTmp.containsKey("sos_numbers")){//取第一个号码
//                        JSONArray array = jsonTmp.getJSONArray("sos_numbers");
//                        for (int i=0;i<array.size();i++){
//                            JSONObject obj = array.getJSONObject(i);
//                            if (obj.getBooleanValue("dial_flag")){
//                                emeCallPhone = obj.getString("num");
//                                break;
//                            }
//                        }
//
//                    }
                    System.out.println("1");
                }catch (Exception e){
                    e.printStackTrace();

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

@ -13,6 +13,7 @@ import com.yihu.jw.care.service.contacts.ContactsService;
import com.yihu.jw.care.service.security.SecurityMonitoringOrderService;
import com.yihu.jw.care.service.wechat.WeiXinAccessTokenUtils;
import com.yihu.jw.care.util.ConcealUtil;
import com.yihu.jw.care.util.CountDistance;
import com.yihu.jw.care.util.MyJdbcTemplate;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
@ -25,6 +26,7 @@ import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.util.common.GpsUtil;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.common.LatitudeUtils;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.entity.ServiceException;
import com.yihu.jw.util.healthIndex.HealthIndexUtil;
@ -115,7 +117,8 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
    private EmergencyAssistanceService emergencyAssistanceService;
    @Autowired
    private SecurityMonitoringOrderService securityMonitoringOrderService;
    @Autowired
    private CountDistance countDistance;
    @PostConstruct
    public void init() {
        relations.put(0, "其他");
@ -936,7 +939,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                devInfo.put("orgCode", "");
            }
            if ("4".equals(device.getCategoryCode()) || "7".equals(device.getCategoryCode())) {
            if ("4".equals(device.getCategoryCode()) || "7".equals(device.getCategoryCode())|| "16".equals(device.getCategoryCode())) {
                devInfo.put("sosContactsDOS", contactsService.getPatientSosContacts(patient));
            }
            com.alibaba.fastjson.JSONObject devInfoObj = JSON.parseObject(JSON.toJSONString(devInfo, SerializerFeature.WriteMapNullValue));
@ -965,7 +968,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                    if (StringUtils.isBlank(day)) {
                        day = DateUtil.getStringDateShort();
                    }
                    devInfoObj = securityMonitoringOrderService.patientSignTopicInfo(devInfoObj, patient, "preventLost");
                    devInfoObj = securityMonitoringOrderService.patientSignTopicInfo(devInfoObj, patient, "preventLost",deviceSn);
                    //轨迹动态
                    JSONArray locations = getX1Locations(deviceSn, day.replace("-", ""));
                    devInfoObj.put("routes", locations);
@ -998,10 +1001,59 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                    devInfoObj.put("day", DateUtil.getStringDateShort());
                    break;
                case "16":
                    if (StringUtils.isBlank(day)) {
                        day = DateUtil.getStringDateShort();
                    }
                    // 电子围栏
                    devInfoObj.put("safeAreaGz", securityMonitoringOrderService.getElectronicFence(deviceSn));
                    // 行动轨迹
                    devInfoObj.put("actionTrack", securityMonitoringOrderService.getActionTrack(deviceSn));
                    devInfoObj.put("actionTrack", securityMonitoringOrderService.getActionTrack(deviceSn,day));
                    //当前定位
                    List<Map<String , Object>> newList = securityMonitoringOrderService.getNewList(deviceSn,day);
                    String lat = "";
                    String lon = "";
                    if (newList.size() > 0) {
                        lat = (String) newList.get(0).get("lat");
                        lon = (String) newList.get(0).get("lon");
                        devInfoObj.put("currentPositioning", LatitudeUtils.getLocationAddress(lat,lon));    //当前定位
                    } else {  //当前地址为null,则获取居民坐标
                        newList = securityMonitoringOrderService.getPatientLatLon(deviceSn);
                        String safeArea = (String) newList.get(0).get("lat_lon");
                        String[] safeAreas = safeArea.split(";");
                        com.alibaba.fastjson.JSONArray fenceLocation = new com.alibaba.fastjson.JSONArray();
                        for (String area:safeAreas){
                            String[] areaPoint = area.split(",");
                            lat = areaPoint[0];
                            lon = areaPoint[1];
                        }
                    }
                    devInfoObj.put("currentPositioning",LatitudeUtils.getLocationAddress(lat,lon));       //当前定位
                    devInfoObj.put("currentLat",lat);       //当前定位
                    devInfoObj.put("currentLon",lon);       //当前定位
                    double dulat =Double.parseDouble(lat);
                    double dulon = Double.parseDouble(lon);
                    String safeArea = device.getSafeAreaGz();
                    String[] safeAreas = safeArea.split(";");
                    com.alibaba.fastjson.JSONArray fenceLocation = new com.alibaba.fastjson.JSONArray();
                    for (String area:safeAreas){
                        String[] areaPoint = area.split(",");
                        com.alibaba.fastjson.JSONObject positionTmp = new com.alibaba.fastjson.JSONObject();
                        Double areaLon = Double.parseDouble( areaPoint[0]);
                        Double areaLat = Double.parseDouble( areaPoint[1]);
//                                com.alibaba.fastjson.JSONObject positionTmp = gpsUtil.gcj02_To_Bd09(lat,lon);
                        positionTmp.put("lat",areaLat);
                        positionTmp.put("lon",areaLon);
                        fenceLocation.add(positionTmp);
                    }
                    if (!countDistance.isInPolygon(dulon,dulat,fenceLocation)){
//                        orderUtil.createSecurityOrder(sn,null,null,8,"1","yslkaqqy",null);
                        devInfoObj.put("isTrueFalse","已超出围栏范围");
                        devInfoObj.put("isNotAlarm","已报警");
                    } else {
                        devInfoObj.put("isTrueFalse","未超出围栏范围");
                        devInfoObj.put("isNotAlarm","未报警");
                    }
                    break;
            }
//        }
@ -1071,8 +1123,8 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
        else if (type == 2){
            JSONArray re = new JSONArray();
            // 排序
            String countSql =" select count(distinct user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date ) from wlyy_patient_health_index a where a.user = '"+patient+"' " +
                    " and a.type=2 and a.device_sn='"+deviceSn+"' and a.del = '1'  ";
            String countSql =" select SUM(total) from ( select count(id ) total from wlyy_patient_health_index a where a.user = '"+patient+"' " +
                    " and a.type=2 and a.device_sn='"+deviceSn+"' and a.del = '1' GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date )A  ";
            count = jdbcTemplate.queryForObject(countSql,Long.class);
            String sql = "SELECT " +
                    "MIN(id) id" +

+ 21 - 2
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/lifeCare/LifeCareOrderService.java

@ -6,6 +6,7 @@ import com.yihu.jw.care.dao.lifeCare.LifeCareCancelLogDao;
import com.yihu.jw.care.dao.lifeCare.LifeCareFeeDetailDao;
import com.yihu.jw.care.dao.lifeCare.LifeCareItemDictDao;
import com.yihu.jw.care.dao.lifeCare.LifeCareOrderDao;
import com.yihu.jw.care.dao.team.BaseTeamMemberDao;
import com.yihu.jw.care.service.common.OrderNoService;
import com.yihu.jw.care.service.message.BaseServiceNewsService;
import com.yihu.jw.care.service.pay.PayService;
@ -88,8 +89,8 @@ public class LifeCareOrderService extends BaseJpaService<LifeCareOrderDO, LifeCa
    private PayService payService;
    @Autowired
    private BusinessOrderDao businessOrderDao;
    @Autowired
    private BaseTeamMemberDao baseTeamMemberDao;
    /**
     * 记录完成情况
@ -563,6 +564,24 @@ public class LifeCareOrderService extends BaseJpaService<LifeCareOrderDO, LifeCa
        //发起支付订单
        payService.submitOrder(orderDO.getPatient(),"4",orderDO.getId(),orderDO.getTotalFee().doubleValue());
        //给签约医生发送预约短信
        String sql ="SELECT i.code,r.team_code,pack.org_code,pack.org_name from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i,base_service_package pack  \n" +
                "where  sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id and r.service_package_id = pack.id and i.del = 1 and sr.`status`=1 \n" +
                "and  sr.patient  = '"+orderDO.getPatient()+"' and i.code='lifeCare' ";
        List<Map<String,Object>> items = jdbcTemplate.queryForList(sql);
        Map<String,Object> mapTmp = items.get(0);
        List<BaseDoctorDO> doctorDOS = baseTeamMemberDao.findAllMembers(mapTmp.get("team_code").toString());
        for (BaseDoctorDO doctorDO:doctorDOS){
            try {
                if (StringUtils.isNotBlank(doctorDO.getMobile())){
                    messageUtil.sendTXYSJson("1099805",doctorDO.getMobile(),orderDO.getPatientName());
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return result;
    }

+ 167 - 52
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/security/SecurityMonitoringOrderService.java

@ -38,6 +38,7 @@ import com.yihu.jw.restmodel.emergency.EmergencyOrderVO;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.util.common.GpsUtil;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.common.LatitudeUtils;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.entity.EntityUtils;
import com.yihu.mysql.query.BaseJpaService;
@ -237,6 +238,9 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        message.put("content_type",40);
        for (BaseDoctorDO doctorDO:doctorDOS){
            try {
                if (StringUtils.isNotBlank(doctorDO.getMobile())){
                    messageUtil.sendTXYSJson("1099807",doctorDO.getMobile(),orderDO.getPatientName(),orderDO.getServeDesc());
                }
                imUtil.sendMDTSocketMessageToDoctor(doctorDO.getId(),message.toString());
            }catch (Exception e){
                e.printStackTrace();
@ -255,8 +259,24 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        return jdbcTemplate.queryForList(sql);
    }
    public List<Map<String , Object>> getActionTrack(String deviceSn){
        String sql = "SELECT * FROM base_yxdevice_index WHERE sn = '"+deviceSn+"' AND lon != 0 AND lat != 0 ORDER BY create_time DESC LIMIT 0,20";
    public List<Map<String , Object>> getActionTrack(String deviceSn,String day){
        String sql = "SELECT * FROM base_yxdevice_index WHERE sn = '"+deviceSn+"' AND lon != 0 AND lat != 0  and create_time like '"+day+"%' ORDER BY create_time DESC LIMIT 0,20";
        return jdbcTemplate.queryForList(sql);
    }
    public List<Map<String,Object>>getNewList(String deviceSn,String day){
        SimpleDateFormat sdf = new SimpleDateFormat();
        if (StringUtils.isBlank(day)){
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            day = dateFormat.format(date);
        }
        String sql = "SELECT * FROM base_yxdevice_index WHERE sn = '"+deviceSn+"' AND create_time LIKE '"+day+"%' AND lon != 0 AND lat != 0 ORDER BY create_time DESC limit 1";
        return jdbcTemplate.queryForList(sql);
    }
    public List<Map<String , Object>> getPatientLatLon(String deviceSn){
        String sql = "SELECT p.lat_lon FROM base_patient p,wlyy_patient_device pd WHERE pd.del = 0 AND pd.device_sn = '"+deviceSn+"' AND pd.`user` = p.id AND p.del = 1 limit 1";
        return jdbcTemplate.queryForList(sql);
    }
@ -338,13 +358,13 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
            }
        }
        //附加信息 电子围栏状态
        if (orderDO.getOrderSource()==2){
        if (2==orderDO.getOrderSource()||8==orderDO.getOrderSource()){//手表/拐杖
            Map<String,Object> map = new HashMap<>();
            map.put("inFenceStatus",false);
            map.put("inFenceName","疑似超出安全区域");
            emergencyOrderVO.setInformation(map);
        }
        if(4==orderDO.getOrderSource()){
        if(4==orderDO.getOrderSource()){//报警器
            List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(orderDO.getPatient(),"12");
            if (devicePatientDeviceDos.size()==0){
            }
@ -380,7 +400,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
                }else {
                    monitorInfo.put("sleepPlan",false);
                }
                monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall");
                monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall",null);
                emergencyOrderVO.setInformation(monitorInfo);
            }catch (Exception e){
                e.printStackTrace();
@ -389,7 +409,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        if (6==orderDO.getOrderSource()){//气感工单
            try {
                JSONObject monitorInfo = JSONObject.parseObject(orderDO.getWarnInfo());
                monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall");
                monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall",null);
                emergencyOrderVO.setInformation(monitorInfo);
            }catch (Exception e){
                e.printStackTrace();
@ -398,7 +418,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        if (7==orderDO.getOrderSource()){//烟感工单
            try {
                JSONObject monitorInfo = JSONObject.parseObject(orderDO.getWarnInfo());
                monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall");
                monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall",null);
                emergencyOrderVO.setInformation(monitorInfo);
            }catch (Exception e){
                e.printStackTrace();
@ -1286,57 +1306,152 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
                    break;
            }
        }
        result = patientSignTopicInfo(result,patient,topicItem);
        result = patientSignTopicInfo(result,patient,topicItem,null);
        return result;
    }
    public void preventLost(JSONObject result,String patient){
        List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
        if (devicePatientDeviceDos.size()==0){
            return;
        }
        DevicePatientDevice device = devicePatientDeviceDos.get(0);
        result.put("deviceSn",device.getDeviceSn());
    public void preventLost(JSONObject result,String patient,String deviceSn){
        //手表与拐杖同时绑定时优先手表,围栏状态其中一个超出围栏即为超出围栏
        try {
            JSONObject response= patientDeviceService.getAqgDeviceInfo(device.getDeviceSn());
            if (response!=null){
                //定位信息
                if (response.containsKey("last_location")&&response.get("last_location")!=null){
                    JSONObject locationTmp = response.getJSONObject("last_location");
                    Double lon = locationTmp.getJSONArray("coordinates").getDouble(0);
                    Double lat = locationTmp.getJSONArray("coordinates").getDouble(1);
                    JSONObject tmp = gpsUtil.gcj02_To_Bd09(lat,lon);
                    tmp.put("city",response.getString("last_city"));
                    tmp.put("province",response.getString("last_province"));
                    tmp.put("address",response.getString("last_address"));
                    result.put("location",tmp);
            Integer categoryCode=0;
            List<DevicePatientDevice> devicePatientDeviceDos = new ArrayList<>();
            List<DevicePatientDevice> devicePatientDeviceDos2 = new ArrayList<>();
            if (StringUtils.isNotBlank(deviceSn)){//查看指定设备详情
                List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
                if (devices.size()>0){
                   String categoryCodeTmp = devices.get(0).getCategoryCode();
                    categoryCode = StringUtils.isBlank(categoryCodeTmp)?-1:Integer.parseInt(categoryCodeTmp);
                    if (4==categoryCode){
                        devicePatientDeviceDos = devices;
                    }
                    if (16==categoryCode){
                        devicePatientDeviceDos2 = devices;
                    }
                }
            }else {
                devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
                devicePatientDeviceDos2 = patientDeviceDao.findByUserAndCategoryCode(patient,"16");
            }
            if (devicePatientDeviceDos.size()>0&&(4==categoryCode||0==categoryCode)){
                DevicePatientDevice device = devicePatientDeviceDos.get(0);
                result.put("deviceSn",device.getDeviceSn());
                JSONObject response= patientDeviceService.getAqgDeviceInfo(device.getDeviceSn());
                if (response!=null){
                    //定位信息
                    if (response.containsKey("last_location")&&response.get("last_location")!=null){
                        JSONObject locationTmp = response.getJSONObject("last_location");
                        Double lon = locationTmp.getJSONArray("coordinates").getDouble(0);
                        Double lat = locationTmp.getJSONArray("coordinates").getDouble(1);
                        JSONObject tmp = gpsUtil.gcj02_To_Bd09(lat,lon);
                        tmp.put("city",response.getString("last_city"));
                        tmp.put("province",response.getString("last_province"));
                        tmp.put("address",response.getString("last_address"));
                        result.put("location",tmp);
                    }
                    //围栏信息
                    if (response.containsKey("fences")&&response.get("fences")!=null){
                        JSONArray fencesArr = response.getJSONArray("fences");
                        JSONArray fencesEnables = new JSONArray();
                        for (int i=0;i<fencesArr.size();i++){
                            JSONObject tmp = fencesArr.getJSONObject(i);
                            if (tmp.getBooleanValue("enable")){//围栏生效
                                JSONObject fenceTmp = new JSONObject();
                                fenceTmp.put("fenceNO",tmp.getInteger("seqid").toString());
                                fenceTmp.put("name",tmp.getString("name"));
                                JSONArray fenceLocationTmp = tmp.getJSONObject("safe_area").getJSONArray("coordinates").getJSONArray(0);
                                JSONArray fenceLocation = new JSONArray();
                                for (int j=0;j<fenceLocationTmp.size();j++){
                                    Double lon = fenceLocationTmp.getJSONArray(j).getDouble(0);
                                    Double lat = fenceLocationTmp.getJSONArray(j).getDouble(1);
                                    JSONObject positionTmp = gpsUtil.gcj02_To_Bd09(lat,lon);
                                    fenceLocation.add(positionTmp);
                                }
                                fenceTmp.put("location",fenceLocation);
                                fenceTmp.put("inFenceStatus",countDistance.isInPolygon(result.getJSONObject("location").getDouble("lon"),result.getJSONObject("location").getDouble("lat"),fenceLocation));
                                fencesEnables.add(fenceTmp);
                            }
                        }
                        if (fencesEnables.size()>0){
                            result.put("fences",fencesEnables);
                        }
                    }
                }
            }
            if (devicePatientDeviceDos2.size()>0&&(16==categoryCode||0==categoryCode)) {
                DevicePatientDevice deviceDO = devicePatientDeviceDos2.get(0);
                double dulat = 0l;
                double dulon = 0l;
                //获取当前定位
                String sql = " SELECT * FROM base_yxdevice_index WHERE sn = '" + deviceDO.getDeviceSn() + "' " +
                        "AND create_time LIKE '" + DateUtil.getStringDateShort() + "%' AND lon != 0 AND lat != 0 ORDER BY create_time DESC  ";
                List<Map<String, Object>> pointTmp = jdbcTemplate.queryForList(sql);
                if (pointTmp.size() > 0) {
                    dulat = Double.parseDouble(pointTmp.get(0).get("lat").toString());
                    dulon = Double.parseDouble(pointTmp.get(0).get("lon").toString());
                }
                //围栏信息
                if (response.containsKey("fences")&&response.get("fences")!=null){
                    JSONArray fencesArr = response.getJSONArray("fences");
                    JSONArray fencesEnables = new JSONArray();
                    for (int i=0;i<fencesArr.size();i++){
                        JSONObject tmp = fencesArr.getJSONObject(i);
                        if (tmp.getBooleanValue("enable")){//围栏生效
                            JSONObject fenceTmp = new JSONObject();
                            fenceTmp.put("fenceNO",tmp.getInteger("seqid").toString());
                            fenceTmp.put("name",tmp.getString("name"));
                            JSONArray fenceLocationTmp = tmp.getJSONObject("safe_area").getJSONArray("coordinates").getJSONArray(0);
                            JSONArray fenceLocation = new JSONArray();
                            for (int j=0;j<fenceLocationTmp.size();j++){
                                Double lon = fenceLocationTmp.getJSONArray(j).getDouble(0);
                                Double lat = fenceLocationTmp.getJSONArray(j).getDouble(1);
                                JSONObject positionTmp = gpsUtil.gcj02_To_Bd09(lat,lon);
                                fenceLocation.add(positionTmp);
                if ((dulat == 0.0 && dulon == 0.0)) {
                    BasePatientDO patientDO = basePatientDao.findById(deviceDO.getUser());
                    String points = patientDO.getLatLon();
                    if (StringUtils.isNotBlank(points)) {
                        String[] pointss = points.split(",");
                        if (2 == pointss.length) {
                            if (StringUtils.isNotBlank(pointss[0])) {
                                dulat = Double.parseDouble(pointss[0]);
                            }
                            if (StringUtils.isNotBlank(pointss[1])) {
                                dulat = Double.parseDouble(pointss[1]);
                            }
                            fenceTmp.put("location",fenceLocation);
                            fenceTmp.put("inFenceStatus",countDistance.isInPolygon(result.getJSONObject("location").getDouble("lon"),result.getJSONObject("location").getDouble("lat"),fenceLocation));
                            fencesEnables.add(fenceTmp);
                        }
                    }
                    if (fencesEnables.size()>0){
                        result.put("fences",fencesEnables);
                }
                if (!(dulat == 0.0 && dulon == 0.0)) {
                    String safeArea = deviceDO.getSafeAreaGz();
                    JSONArray fenceLocation = new JSONArray();
                    String address = LatitudeUtils.getLocationAddress(dulat + "", dulon + "");
                    if (StringUtils.isNotBlank(safeArea)) {
                        String[] safeAreas = safeArea.split(";");
                        for (String area : safeAreas) {
                            String[] areaPoint = area.split(",");
                            JSONObject positionTmp = new JSONObject();
                            Double areaLon = Double.parseDouble(areaPoint[0]);
                            Double areaLat = Double.parseDouble(areaPoint[1]);
                            positionTmp.put("lat", areaLat);
                            positionTmp.put("lon", areaLon);
                            fenceLocation.add(positionTmp);
                        }
                        if (devicePatientDeviceDos2.size() > 0 && 0 == categoryCode) {
                            JSONObject obj = result.getJSONArray("fences").getJSONObject(0);
                            if (!obj.getBooleanValue("inFenceStatus")) {
                                if (!countDistance.isInPolygon(dulon, dulat, fenceLocation)) {
                                    obj.put("inFenceStatus", false);
                                    obj = result.getJSONObject("location");
                                    obj.put("address", address);
                                    obj.put("lon", dulon);
                                    obj.put("lat", dulat);
                                }
                            }
                        }
                        if (devicePatientDeviceDos2.size() > 0 && 16 == categoryCode) {
                            if (StringUtils.isNotBlank(safeArea)) {
                                result.put("deviceSn", deviceDO.getDeviceSn());
                                JSONObject location = new JSONObject();
                                location.put("address",address);
                                location.put("province","");
                                location.put("city","");
                                location.put("lon",dulon);
                                location.put("lat",dulat);
                                result.put("location",location);
                                JSONArray fences = new JSONArray();
                                JSONObject fence = new JSONObject();
                                fence.put("fenceNO","1");
                                fence.put("name","安全区域1");
                                fence.put("inFenceStatus", countDistance.isInPolygon(dulon, dulat, fenceLocation));
                                fence.put("location", fenceLocation);
                                fences.add(fence);
                                result.put("fences",fences);
                            }
                        }
                    }
                }
            }
@ -1496,12 +1611,12 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
    }
    public JSONObject patientSignTopicInfo(JSONObject result,String patient,String topicItem){
    public JSONObject patientSignTopicInfo(JSONObject result,String patient,String topicItem,String deviceSn){
        if (null==result){
            result = new JSONObject();
        }
        if ("preventLost".equals(topicItem)||StringUtils.isBlank(topicItem)){
            preventLost(result, patient);
            preventLost(result, patient,deviceSn);
        }
        if ("preventFall".equals(topicItem)||StringUtils.isBlank(topicItem)){
            monitorInfo(result, patient);

+ 13 - 9
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/DeviceController.java

@ -171,10 +171,13 @@ public class DeviceController {
            @RequestParam(value = "time_begin",required = false) String time_begin,
            HttpServletRequest request) {
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("爱牵挂设备sos数据接收,请求参数:\n"+paraString);
            long startTime=System.currentTimeMillis();
            String paraString = JSON.toJSONString(request.getParameterMap());
            deviceService.aqgsos(imei, label_mac, time_begin,request);
            long endTime=System.currentTimeMillis();
            logger.info("爱牵挂设备sos数据接收,请求参数:\n"+paraString+"\n"+(endTime-startTime)+"ms");
            return success();
        } catch (Exception e) {
            e.printStackTrace();
@ -217,11 +220,11 @@ public class DeviceController {
            @RequestParam(value = "communityid",required = false) String communityid,
            HttpServletRequest request) {
        try {
            long startTime=System.currentTimeMillis();
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("爱牵挂设备消息通知数据接收,请求参数:\n"+paraString);
            deviceService.pushdata(type, deviceid, communityid, request);
            long endTime=System.currentTimeMillis();
            logger.info("爱牵挂设备消息通知数据接收,请求参数:\n"+paraString+"\n"+(endTime-startTime)+"ms");
            return success();
        } catch (Exception e) {
            e.printStackTrace();
@ -383,7 +386,7 @@ public class DeviceController {
            @RequestParam(value = "heartrate",required = false) String heartrate,
            @ApiParam(name="breath",required = false,value="呼吸率(离床或翻身测量失败时为0)")
            @RequestParam(value = "breath",required = false) String breath,
            @ApiParam(name="bed_status",required = false,value="在离床状态(0 离床,1 在床) ")
                @ApiParam(name="bed_status",required = false,value="在离床状态(0 离床,1 在床) ")
            @RequestParam(value = "bed_status",required = false) String bed_status,
            @ApiParam(name="turn_over",required = false,value="翻身状态(0 没翻身,1 在翻身)")
            @RequestParam(value = "turn_over",required = false)String turn_over,
@ -391,11 +394,12 @@ public class DeviceController {
            @RequestParam(value = "is_warn",required = false)String is_warn,
            HttpServletRequest request) {
        try {
            long startTime=System.currentTimeMillis();
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("爱牵挂-睡眠带接收,请求参数:"+paraString);
            deviceService.bySleep(device,time_begin,heartrate,breath,bed_status,turn_over,is_warn);
            long endTime=System.currentTimeMillis();
            logger.info("爱牵挂-睡眠带接收,请求参数:"+paraString+"\n"+(endTime-startTime)+"ms");
            return success();
        } catch (Exception e) {
            e.printStackTrace();

+ 47 - 20
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceUploadService.java

@ -24,6 +24,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
@ -67,6 +68,8 @@ public class DeviceUploadService {
    private SecurityOrderUtil orderUtil;
    @Autowired
    private GpsUtil gpsUtil;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    public Result uploadDevicesData(String dataJson)throws Exception {
        try {
@ -474,6 +477,9 @@ public class DeviceUploadService {
                        double dulat =Double.parseDouble(lat);
                        double dulon = Double.parseDouble(lon);
                        if (!(dulat==0.0&&dulon==0.0)){//判断是否触发工单
                            com.alibaba.fastjson.JSONObject position = gpsUtil.Gps84_To_bd09(dulat,dulon);
                            dulat = position.getDouble("lat");
                            dulon = position.getDouble("lon");
                            List<DevicePatientDevice> patientDeviceList = patientDeviceDao.findByDeviceSn(sn);
                            DevicePatientDevice patientDevice = null;
                            if (patientDeviceList.size()>0){
@ -486,29 +492,30 @@ public class DeviceUploadService {
                            }
                            if (null!=patientDevice){//存在围栏地址
                                String safeArea = patientDevice.getSafeAreaGz();
                                String[] safeAreas = safeArea.split(";");
                                JSONArray fenceLocation = new JSONArray();
                                for (String area:safeAreas){
                                    String[] areaPoint = area.split(",");
                                    JSONObject positionTmp = new JSONObject();
                                    Double areaLon = Double.parseDouble( areaPoint[0]);
                                    Double areaLat = Double.parseDouble( areaPoint[1]);
                                if (StringUtils.isNotBlank(safeArea)){
                                    String[] safeAreas = safeArea.split(";");
                                    JSONArray fenceLocation = new JSONArray();
                                    for (String area:safeAreas){
                                        String[] areaPoint = area.split(",");
                                        com.alibaba.fastjson.JSONObject positionTmp = new com.alibaba.fastjson.JSONObject();
                                        Double areaLon = Double.parseDouble( areaPoint[0]);
                                        Double areaLat = Double.parseDouble( areaPoint[1]);
//                                com.alibaba.fastjson.JSONObject positionTmp = gpsUtil.gcj02_To_Bd09(lat,lon);
                                    positionTmp.put("lat",areaLat);
                                    positionTmp.put("lon",areaLon);
                                    fenceLocation.add(positionTmp);
                                }
                                if (!countDistance.isInPolygon(dulon,dulat,fenceLocation)){
                                    orderUtil.createSecurityOrder(sn,null,null,8,"1","yslkaqqy",null);
                                        positionTmp.put("lat",areaLat);
                                        positionTmp.put("lon",areaLon);
                                        fenceLocation.add(positionTmp);
                                    }
                                    if (!countDistance.isInPolygon(dulon,dulat,fenceLocation)){
                                        orderUtil.createSecurityOrder(sn,null,null,8,"1","yslkaqqy",null);
                                    }
                                }
                            }
                        }
                        BaseYxDeviceIndex deviceIndex = new BaseYxDeviceIndex();
                        deviceIndex.setSn(sn);
                        deviceIndex.setLat(lat);
                        deviceIndex.setLon(lon);
                        deviceIndex.setLat(dulat+"");
                        deviceIndex.setLon(dulon+"");
                        yxDeviceIndexDao.save(deviceIndex);
                        hvDeviceService.updContactStatus(sn,1);
                    }
@ -522,9 +529,20 @@ public class DeviceUploadService {
                            lat = tmp1[4];
                            lon = tmp1[6];
                        }
                        double dulat =Double.parseDouble(lat);
                        double dulon = Double.parseDouble(lon);
                        if ((dulat==0.0&&dulon==0.0)){
                            String sql=" SELECT * FROM base_yxdevice_index WHERE sn = '"+sn+"' " +
                                    "AND create_time LIKE '"+DateUtil.getStringDateShort()+"%' AND lon != 0 AND lat != 0 ORDER BY create_time DESC  ";
                            List<Map<String,Object>> result = jdbcTemplate.queryForList(sql);
                            if (result.size()>0);{
                                dulat = Double.parseDouble(result.get(0).get("lat").toString());
                                dulon = Double.parseDouble(result.get(0).get("lon").toString());
                            }
                        }
                        List<DevicePatientDevice> patientDeviceList = patientDeviceDao.findByDeviceSn(sn);
                        if (patientDeviceList.size()>0){
                            DevicePatientDevice deviceDO = patientDeviceList.get(0);
@ -547,6 +565,10 @@ public class DeviceUploadService {
                                }else {
                                    return;
                                }
                            }else {
                                com.alibaba.fastjson.JSONObject position = gpsUtil.Gps84_To_bd09(dulat,dulon);
                                dulat = position.getDouble("lat");
                                dulon = position.getDouble("lon");
                            }
                            if ((dulat==0.0&&dulon==0.0)){
                                return;
@ -559,13 +581,18 @@ public class DeviceUploadService {
                            logDO.setDeviceSn(deviceDO.getDeviceSn());
                            logDO.setCreateTime(new Date());
                            com.alibaba.fastjson.JSONObject position = gpsUtil.Gps84_To_bd09(dulat,dulon);
                            //坐标
                            logDO.setSosLat(position.getDouble("lat")+"");
                            logDO.setSosLon(position.getDouble("lon")+"");
                            logDO.setSosAddress(LatitudeUtils.getLocationAddress(position.getDouble("lat")+"",position.getDouble("lon")+""));
                            logDO.setSosLat(dulat+"");
                            logDO.setSosLon(dulon+"");
                            logDO.setSosAddress(LatitudeUtils.getLocationAddress(dulat+"",dulon+""));
                            orderUtil.createEmeOrder(logDO,"4");
                        }
                        BaseYxDeviceIndex deviceIndex = new BaseYxDeviceIndex();
                        deviceIndex.setSn(sn);
                        deviceIndex.setLat(dulat+"");
                        deviceIndex.setLon(dulon+"");
                        yxDeviceIndexDao.save(deviceIndex);
                        hvDeviceService.updContactStatus(sn,1);
                    }
                }
            }

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

@ -77,10 +77,11 @@ public class PatientSosContactsJob implements Job {
                    //设备修改
                    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);
                            }else {
                                sosContactsDO.setSuccessFlag(-1);
                            }
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+1+"}");
                        }else {
@ -88,7 +89,7 @@ public class PatientSosContactsJob implements Job {
                            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+"' ";
                        sql =" select sos_phone from base_patient_sos_contacts where patient='"+patient+"' order by phone_seqid asc ";
                        List<String> nums = jdbcTemplate.queryForList(sql,String.class);
                        String phone1 = null;
                        String phone2 = null;
@ -102,7 +103,14 @@ public class PatientSosContactsJob implements Job {
                            }
                        }
                        yunXunDeviceService.setSos(device_sn,phone1,phone2,phone3);
                        sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":unknow}");
                        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 {
                            sosContactsDO.setSuccessFlag(-1);
                        }
                    }
                    sosContactsDao.save(sosContactsDO);
                }