Browse Source

短信、拐杖相关

liubing 3 years ago
parent
commit
d256ceb64c

+ 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();

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

@ -955,7 +955,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);
@ -1059,8 +1059,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;
    }

+ 150 - 50
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();
@ -338,13 +342,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 +384,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 +393,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 +402,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 +1290,153 @@ 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){
        //手表与拐杖同时绑定时优先手表,围栏状态其中一个超出围栏即为超出围栏
        deviceSn="IMEI860314001160450";
        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;
                    }
                }
                //围栏信息
                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);
            }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);
                            }
                            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 (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 ((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]);
                            }
                        }
                    }
                }
                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);
                            }
                        }
                    }
                }
            }
@ -1495,12 +1595,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);

+ 28 - 14
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 {
@ -489,22 +492,23 @@ 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);
                                    }
                                }
                            }
                        }
@ -529,6 +533,16 @@ public class DeviceUploadService {
                        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);

+ 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);
                }