|  | @ -6,12 +6,16 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
 | 
												
													
														
															|  | import com.fasterxml.jackson.databind.ObjectMapper;
 |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
												
													
														
															|  | import com.yihu.jw.care.dao.device.*;
 |  | import com.yihu.jw.care.dao.device.*;
 | 
												
													
														
															|  | import com.yihu.jw.care.endpoint.Result;
 |  | import com.yihu.jw.care.endpoint.Result;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.care.util.CountDistance;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.care.util.SecurityOrderUtil;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
												
													
														
															|  | import com.yihu.jw.entity.care.device.*;
 |  | import com.yihu.jw.entity.care.device.*;
 | 
												
													
														
															|  | import com.yihu.jw.entity.hospital.message.SystemMessageDO;
 |  | import com.yihu.jw.entity.hospital.message.SystemMessageDO;
 | 
												
													
														
															|  | import com.yihu.jw.hospital.message.dao.SystemMessageDao;
 |  | import com.yihu.jw.hospital.message.dao.SystemMessageDao;
 | 
												
													
														
															|  | import com.yihu.jw.im.util.ImUtil;
 |  | import com.yihu.jw.im.util.ImUtil;
 | 
												
													
														
															|  | import com.yihu.jw.patient.dao.BasePatientDao;
 |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.util.common.GpsUtil;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.util.common.LatitudeUtils;
 | 
												
													
														
															|  | import com.yihu.jw.util.date.DateUtil;
 |  | import com.yihu.jw.util.date.DateUtil;
 | 
												
													
														
															|  | import com.yihu.jw.util.healthIndex.HealthIndexUtil;
 |  | import com.yihu.jw.util.healthIndex.HealthIndexUtil;
 | 
												
													
														
															|  | import com.yihu.jw.utils.StringUtil;
 |  | import com.yihu.jw.utils.StringUtil;
 | 
												
											
												
													
														
															|  | @ -55,6 +59,14 @@ public class DeviceUploadService {
 | 
												
													
														
															|  |     private BaseYxDeviceIndexDao yxDeviceIndexDao;
 |  |     private BaseYxDeviceIndexDao yxDeviceIndexDao;
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private HvDeviceService hvDeviceService;
 |  |     private HvDeviceService hvDeviceService;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private CountDistance countDistance;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private YsDeviceService ysDeviceService;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private SecurityOrderUtil orderUtil;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private GpsUtil gpsUtil;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     public Result uploadDevicesData(String dataJson)throws Exception {
 |  |     public Result uploadDevicesData(String dataJson)throws Exception {
 | 
												
													
														
															|  |         try {
 |  |         try {
 | 
												
											
												
													
														
															|  | @ -433,38 +445,135 @@ public class DeviceUploadService {
 | 
												
													
														
															|  |      * @return
 |  |      * @return
 | 
												
													
														
															|  |      */
 |  |      */
 | 
												
													
														
															|  |     public void parsingInstruction(String instructions){
 |  |     public void parsingInstruction(String instructions){
 | 
												
													
														
															|  |         if(StringUtils.isBlank(instructions)){
 |  | 
 | 
												
													
														
															|  |             return;
 |  | 
 | 
												
													
														
															|  |         }
 |  | 
 | 
												
													
														
															|  |         String res = "";
 |  | 
 | 
												
													
														
															|  |         //位置[434036bb95761faaf8771d10029ae8eaIC*860314001160427*0113*UD,210826,093829,V,0.000000,N,0.000000,E,0.00,0.0,100.0,0,62,31,0,0,00000000,1,1,460,0,22831,259001902,62,6,wifi0,20:6b:e7:67:bf:1f,-63,wifi1,d4:9e:05:a7:60:a6,-65,wifi2,e0:d4:62:2d:67:9c,-71,wifi3,54:75:95:b9:4f:8e,-73,wifi4,e4:72:e2:aa:73:0c,-73,wifi5,e0:d4:62:2d:67:a1,-73]
 |  | 
 | 
												
													
														
															|  |         String instruct[] = instructions.split("]");
 |  | 
 | 
												
													
														
															|  |         for (int i=0;i<instruct.length;i++){
 |  | 
 | 
												
													
														
															|  |             String inst = instruct[i];
 |  | 
 | 
												
													
														
															|  |             String tmp[] = inst.split("\\*");
 |  | 
 | 
												
													
														
															|  |             String sn = tmp[1];
 |  | 
 | 
												
													
														
															|  |             String order = tmp[3];
 |  | 
 | 
												
													
														
															|  |             if(order.contains(",")){
 |  | 
 | 
												
													
														
															|  |                 String tmp1[] = order.split(",");
 |  | 
 | 
												
													
														
															|  |                 if("UD".equals(tmp1[0])||"CRUD".equals(tmp1[0])){
 |  | 
 | 
												
													
														
															|  |                     //处理位置信息
 |  | 
 | 
												
													
														
															|  |                     String lat,lon;
 |  | 
 | 
												
													
														
															|  |                     if("A".equals(tmp1[4])){
 |  | 
 | 
												
													
														
															|  |                         lat = tmp1[5];
 |  | 
 | 
												
													
														
															|  |                         lon = tmp1[7];
 |  | 
 | 
												
													
														
															|  |                     }else{
 |  | 
 | 
												
													
														
															|  |                         lat = tmp1[4];
 |  | 
 | 
												
													
														
															|  |                         lon = tmp1[6];
 |  | 
 | 
												
													
														
															|  | 
 |  |         try {
 | 
												
													
														
															|  | 
 |  |             if(StringUtils.isBlank(instructions)){
 | 
												
													
														
															|  | 
 |  |                 return;
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             String res = "";
 | 
												
													
														
															|  | 
 |  |             //位置[434036bb95761faaf8771d10029ae8eaIC*860314001160427*0113*UD,210826,093829,V,0.000000,N,0.000000,E,0.00,0.0,100.0,0,62,31,0,0,00000000,1,1,460,0,22831,259001902,62,6,wifi0,20:6b:e7:67:bf:1f,-63,wifi1,d4:9e:05:a7:60:a6,-65,wifi2,e0:d4:62:2d:67:9c,-71,wifi3,54:75:95:b9:4f:8e,-73,wifi4,e4:72:e2:aa:73:0c,-73,wifi5,e0:d4:62:2d:67:a1,-73]
 | 
												
													
														
															|  | 
 |  |             String instruct[] = instructions.split("]");
 | 
												
													
														
															|  | 
 |  |             for (int i=0;i<instruct.length;i++){
 | 
												
													
														
															|  | 
 |  |                 String inst = instruct[i];
 | 
												
													
														
															|  | 
 |  |                 String tmp[] = inst.split("\\*");
 | 
												
													
														
															|  | 
 |  |                 String sn = tmp[1];
 | 
												
													
														
															|  | 
 |  |                 String order = tmp[3];
 | 
												
													
														
															|  | 
 |  |                 if(order.contains(",")){
 | 
												
													
														
															|  | 
 |  |                     String tmp1[] = order.split(",");
 | 
												
													
														
															|  | 
 |  |                     if("UD".equals(tmp1[0])||"CRUD".equals(tmp1[0])){
 | 
												
													
														
															|  | 
 |  |                         //处理位置信息
 | 
												
													
														
															|  | 
 |  |                         String lat,lon;
 | 
												
													
														
															|  | 
 |  |                         if("A".equals(tmp1[4])){
 | 
												
													
														
															|  | 
 |  |                             lat = tmp1[5];
 | 
												
													
														
															|  | 
 |  |                             lon = tmp1[7];
 | 
												
													
														
															|  | 
 |  |                             //判断是否超出围栏,
 | 
												
													
														
															|  | 
 |  |                         }else{
 | 
												
													
														
															|  | 
 |  |                             lat = tmp1[4];
 | 
												
													
														
															|  | 
 |  |                             lon = tmp1[6];
 | 
												
													
														
															|  | 
 |  |                         }
 | 
												
													
														
															|  | 
 |  |                         double dulat =Double.parseDouble(lat);
 | 
												
													
														
															|  | 
 |  |                         double dulon = Double.parseDouble(lon);
 | 
												
													
														
															|  | 
 |  |                         if (!(dulat==0.0&&dulon==0.0)){//判断是否触发工单
 | 
												
													
														
															|  | 
 |  |                             List<DevicePatientDevice> patientDeviceList = patientDeviceDao.findByDeviceSn(sn);
 | 
												
													
														
															|  | 
 |  |                             DevicePatientDevice patientDevice = null;
 | 
												
													
														
															|  | 
 |  |                             if (patientDeviceList.size()>0){
 | 
												
													
														
															|  | 
 |  |                                 for (DevicePatientDevice pd2:patientDeviceList){
 | 
												
													
														
															|  | 
 |  |                                     if (StringUtils.isNotBlank(pd2.getSafeAreaGz())){
 | 
												
													
														
															|  | 
 |  |                                         patientDevice = pd2;
 | 
												
													
														
															|  | 
 |  |                                         break;
 | 
												
													
														
															|  | 
 |  |                                     }
 | 
												
													
														
															|  | 
 |  |                                 }
 | 
												
													
														
															|  | 
 |  |                             }
 | 
												
													
														
															|  | 
 |  |                             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]);
 | 
												
													
														
															|  | 
 |  | //                                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);
 | 
												
													
														
															|  | 
 |  |                                 }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |                             }
 | 
												
													
														
															|  | 
 |  |                         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |                         BaseYxDeviceIndex deviceIndex = new BaseYxDeviceIndex();
 | 
												
													
														
															|  | 
 |  |                         deviceIndex.setSn(sn);
 | 
												
													
														
															|  | 
 |  |                         deviceIndex.setLat(lat);
 | 
												
													
														
															|  | 
 |  |                         deviceIndex.setLon(lon);
 | 
												
													
														
															|  | 
 |  |                         yxDeviceIndexDao.save(deviceIndex);
 | 
												
													
														
															|  | 
 |  |                         hvDeviceService.updContactStatus(sn,1);
 | 
												
													
														
															|  | 
 |  |                     }
 | 
												
													
														
															|  | 
 |  |                     if ("AL".equals(equals(tmp1[0]))){//触发报警
 | 
												
													
														
															|  | 
 |  |                         String lat,lon;
 | 
												
													
														
															|  | 
 |  |                         if("A".equals(tmp1[4])){
 | 
												
													
														
															|  | 
 |  |                             lat = tmp1[5];
 | 
												
													
														
															|  | 
 |  |                             lon = tmp1[7];
 | 
												
													
														
															|  | 
 |  |                             //判断是否超出围栏,
 | 
												
													
														
															|  | 
 |  |                         }else{
 | 
												
													
														
															|  | 
 |  |                             lat = tmp1[4];
 | 
												
													
														
															|  | 
 |  |                             lon = tmp1[6];
 | 
												
													
														
															|  | 
 |  |                         }
 | 
												
													
														
															|  | 
 |  |                         double dulat =Double.parseDouble(lat);
 | 
												
													
														
															|  | 
 |  |                         double dulon = Double.parseDouble(lon);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |                         List<DevicePatientDevice> patientDeviceList = patientDeviceDao.findByDeviceSn(sn);
 | 
												
													
														
															|  | 
 |  |                         if (patientDeviceList.size()>0){
 | 
												
													
														
															|  | 
 |  |                             DevicePatientDevice deviceDO = patientDeviceList.get(0);
 | 
												
													
														
															|  | 
 |  |                             BasePatientDO patientDO = patientDao.findById(deviceDO.getUser());
 | 
												
													
														
															|  | 
 |  |                             //发起救助工单
 | 
												
													
														
															|  | 
 |  |                             //获取居民坐标
 | 
												
													
														
															|  | 
 |  |                             //如果没获取取居民坐标
 | 
												
													
														
															|  | 
 |  |                             if ((dulat==0.0&&dulon==0.0)){
 | 
												
													
														
															|  | 
 |  |                                 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]);
 | 
												
													
														
															|  | 
 |  |                                         }
 | 
												
													
														
															|  | 
 |  |                                     }
 | 
												
													
														
															|  | 
 |  |                                 }else {
 | 
												
													
														
															|  | 
 |  |                                     return;
 | 
												
													
														
															|  | 
 |  |                                 }
 | 
												
													
														
															|  | 
 |  |                             }
 | 
												
													
														
															|  | 
 |  |                             if ((dulat==0.0&&dulon==0.0)){
 | 
												
													
														
															|  | 
 |  |                                 return;
 | 
												
													
														
															|  | 
 |  |                             }
 | 
												
													
														
															|  | 
 |  |                             DeviceSosLogDO logDO = new DeviceSosLogDO();
 | 
												
													
														
															|  | 
 |  |                             logDO.setPatient(patientDO.getId());
 | 
												
													
														
															|  | 
 |  |                             logDO.setPatientName(patientDO.getName());
 | 
												
													
														
															|  | 
 |  |                             logDO.setIdcard(patientDO.getIdcard());
 | 
												
													
														
															|  | 
 |  |                             logDO.setCategoryCode(deviceDO.getCategoryCode());
 | 
												
													
														
															|  | 
 |  |                             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")+""));
 | 
												
													
														
															|  | 
 |  |                             orderUtil.createEmeOrder(logDO,"4");
 | 
												
													
														
															|  | 
 |  |                         }
 | 
												
													
														
															|  |                     }
 |  |                     }
 | 
												
													
														
															|  |                     BaseYxDeviceIndex deviceIndex = new BaseYxDeviceIndex();
 |  | 
 | 
												
													
														
															|  |                     deviceIndex.setSn(sn);
 |  | 
 | 
												
													
														
															|  |                     deviceIndex.setLat(lat);
 |  | 
 | 
												
													
														
															|  |                     deviceIndex.setLon(lon);
 |  | 
 | 
												
													
														
															|  |                     yxDeviceIndexDao.save(deviceIndex);
 |  | 
 | 
												
													
														
															|  |                     hvDeviceService.updContactStatus(sn,1);
 |  | 
 | 
												
													
														
															|  |                 }
 |  |                 }
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         }catch (Exception e){
 | 
												
													
														
															|  | 
 |  |             e.printStackTrace();
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | }
 |  | }
 |