Browse Source

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

Shi Kejing 4 years ago
parent
commit
193b1d5d38
18 changed files with 535 additions and 30 deletions
  1. 18 1
      common/common-entity/sql记录
  2. 9 0
      common/common-entity/src/main/java/com/yihu/jw/entity/care/device/Device.java
  3. 114 0
      common/common-entity/src/main/java/com/yihu/jw/entity/care/device/DeviceSosLogDO.java
  4. 5 0
      common/common-entity/src/main/java/com/yihu/jw/entity/util/AesEncryptUtils.java
  5. 19 1
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/GpsUtil.java
  6. 12 0
      common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientUtil.java
  7. 1 0
      gateway/ag-basic/src/main/java/com/yihu/jw/gateway/filter/BasicZuulFilter.java
  8. 6 0
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/config/AqgConfig.java
  9. 57 1
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/PatientDeviceController.java
  10. 46 0
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/third/assistance/EmeAsEndpoint.java
  11. 55 2
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/device/PatientDeviceService.java
  12. 1 1
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/doctor/CareDoctorService.java
  13. 44 14
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/security/SecurityMonitoringOrderService.java
  14. 2 2
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/sign/ArchiveService.java
  15. 51 0
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/CountDistance.java
  16. 11 0
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/dao/device/DeviceSosLogDao.java
  17. 78 8
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceService.java
  18. 6 0
      svr/svr-cloud-device/src/main/resources/application.yml

+ 18 - 1
common/common-entity/sql记录

@ -470,4 +470,21 @@ CREATE TABLE `base_patient_contacts_org` (
ALTER TABLE base.wlyy_patient_device add COLUMN  `sos_address` varchar(50) DEFAULT NULL COMMENT '设备类型为报警器时,需要填写投放地址 category_code = 7';
-- 2021-05-08 skj
ALTER TABLE base.base_life_care_item_dict add COLUMN  `life_care_img` varchar(255) DEFAULT NULL COMMENT '服务项目图片';
ALTER TABLE base.base_life_care_item_dict add COLUMN  `life_care_img` varchar(255) DEFAULT NULL COMMENT '服务项目图片';
-- 2021-05-08 lb
CREATE TABLE `base_device_sos_log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `patient` varchar(50) DEFAULT NULL COMMENT '居民code',
  `patient_name` varchar(50) DEFAULT NULL COMMENT '姓名',
  `idcard` varchar(32) DEFAULT NULL COMMENT '身份证',
  `category_code` varchar(50) DEFAULT NULL COMMENT '设备类型标识1血糖仪,2.血压计,3药盒,4智能手表',
  `device_sn` varchar(50) NOT NULL COMMENT '设备SN码',
  `sos_address` varchar(100) DEFAULT NULL COMMENT '报警地址',
  `sos_lat` varchar(100) DEFAULT NULL COMMENT '报警地址纬度',
  `sos_lon` varchar(100) DEFAULT NULL COMMENT '报警地址经度',
  `sos_send_status` varchar(255) DEFAULT NULL COMMENT '紧急救助发起状态 200成功, -1 失败',
  `sos_send_message` varchar(500) DEFAULT NULL COMMENT '紧急救助发起返回消息',
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='设备紧急救助日志表';

+ 9 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/Device.java

@ -26,6 +26,7 @@ public class Device extends IdEntity {
	private String name;
	private Date czrq;
	private String del;
	private String serviceTopic;//设备所属专题 防走失 preventLost
	@Column(name="category_code")
	public String getCategoryCode() {
@ -108,4 +109,12 @@ public class Device extends IdEntity {
	public void setDel(String del) {
		this.del = del;
	}
	public String getServiceTopic() {
		return serviceTopic;
	}
	public void setServiceTopic(String serviceTopic) {
		this.serviceTopic = serviceTopic;
	}
}

+ 114 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/DeviceSosLogDO.java

@ -0,0 +1,114 @@
package com.yihu.jw.entity.care.device;
import com.yihu.jw.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Bing on 2021/5/8.
 */
@Entity
@Table(name="base_device_sos_log")
public class DeviceSosLogDO extends IdEntity {
    private String patient; //居民code
    private String patientName; //姓名
    private String idcard;  //身份证
    private String categoryCode;    //设备类型标识1血糖仪,2.血压计,3药盒,4智能手表
    private String deviceSn;    //设备SN码
    private String sosAddress;  //报警地址
    private String sosLat;  //报警地址纬度
    private String sosLon;  //报警地址经度
    private String sosSendStatus;//紧急救助发起状态 200成功 -1失败
    private String sosSendMessage; //紧急救助返回消息
    private Date createTime;//
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getPatientName() {
        return patientName;
    }
    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }
    public String getIdcard() {
        return idcard;
    }
    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }
    public String getCategoryCode() {
        return categoryCode;
    }
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }
    public String getDeviceSn() {
        return deviceSn;
    }
    public void setDeviceSn(String deviceSn) {
        this.deviceSn = deviceSn;
    }
    public String getSosAddress() {
        return sosAddress;
    }
    public void setSosAddress(String sosAddress) {
        this.sosAddress = sosAddress;
    }
    public String getSosLat() {
        return sosLat;
    }
    public void setSosLat(String sosLat) {
        this.sosLat = sosLat;
    }
    public String getSosLon() {
        return sosLon;
    }
    public void setSosLon(String sosLon) {
        this.sosLon = sosLon;
    }
    public String getSosSendStatus() {
        return sosSendStatus;
    }
    public void setSosSendStatus(String sosSendStatus) {
        this.sosSendStatus = sosSendStatus;
    }
    public String getSosSendMessage() {
        return sosSendMessage;
    }
    public void setSosSendMessage(String sosSendMessage) {
        this.sosSendMessage = sosSendMessage;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}

+ 5 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/util/AesEncryptUtils.java

@ -145,6 +145,11 @@ public class AesEncryptUtils {
        }
        return decrypt(encryptStr, AGKEY);
    }
    public static String agEncrypt(String content) throws Exception {
        return encrypt(content, AGKEY);
    }
    private static final String AGKEY = "46A61629A19AE04C";
}

+ 19 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/GpsUtil.java

@ -1,4 +1,4 @@
package com.yihu.jw.care.util;
package com.yihu.jw.util.common;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
@ -67,6 +67,15 @@ public class GpsUtil {
        return getPosition(bd_lat, bd_lon);
    }
    public  String gcj02_To_Bd09_Str(double gg_lat, double gg_lon) {
        double x = gg_lon, y = gg_lat;
        double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * pi);
        double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * pi);
        double bd_lon = z * Math.cos(theta) + 0.0065;
        double bd_lat = z * Math.sin(theta) + 0.006;
        return bd_lon+","+bd_lat;
    }
    /**
     * * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法 * * 将 BD-09 坐标转换成GCJ-02 坐标 * * @param
     * bd_lat * @param bd_lon * @return
@ -80,6 +89,15 @@ public class GpsUtil {
        return getPosition(gg_lat, gg_lon);
    }
    public  String  bd09_To_Gcj02_str(double bd_lat, double bd_lon) {
        double x = bd_lon - 0.0065, y = bd_lat - 0.006;
        double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * pi);
        double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * pi);
        double gg_lon = z * Math.cos(theta);
        double gg_lat = z * Math.sin(theta);
        return bd_lon+","+bd_lat;
    }
    /**
     * (BD-09)-->84
     * @param bd_lat

+ 12 - 0
common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientUtil.java

@ -488,6 +488,18 @@ public class HttpClientUtil {
        return null;
    }
    public String postBodyRawForm(String url, String params) throws IOException {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        List<NameValuePair> pairs = new ArrayList<>(0);
        pairs.add(new BasicNameValuePair("object",params));
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(pairs);
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(formEntity);
        CloseableHttpResponse response = httpclient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        String ret = EntityUtils.toString(entity);
        return ret;
    }
    /**
     * 爱牵挂请求

+ 1 - 0
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/filter/BasicZuulFilter.java

@ -131,6 +131,7 @@ public class BasicZuulFilter extends ZuulFilter {
                || url.contains("/sms_gateway/send")//发送短信
                || url.contains("/accountAppeal/create")
                || url.contains("/open/")//开放接口
                || url.contains("/cloudCare/noLogin/")//医疗云开放接口
                || url.contains("/image/")//获取默认图片
                ||url.contains("/weixin")||
                url.contains("/excelControl")) {

+ 6 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/config/AqgConfig.java

@ -32,6 +32,12 @@ public class AqgConfig {
     */
    public static final String device_last_locationdata = baseUrl +"/api/device/{0}/data/locationdata/";
    /**
     * 设置智能手环安全区域
     */
    public static final String fence_area = baseUrl +"/api/device/{0}/fences/{1}";
    public static final String username = "13559485270";
    public static final String password = "zjxl@2021";
    public static final String redisKey = "aqgCooker";

+ 57 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/PatientDeviceController.java

@ -9,6 +9,7 @@ import com.yihu.jw.care.service.device.PatientHealthIndexService;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.web.ListEnvelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -167,7 +168,20 @@ public class PatientDeviceController extends BaseController {
            return invalidUserException(ex, -1, ex.getMessage());
        }
    }
    
    @ApiOperation("获取患者设备信息")
    @RequestMapping(value = "patientDeviceListByTopic", method = RequestMethod.GET)
    public ListEnvelop patientDeviceListByTopic(@ApiParam(name = "patient", value = "patient", defaultValue = "patient")
                                                @RequestParam(value = "patient", required = true) String patient,
                                                @ApiParam(name = "topic", value = "专题CODE;preventLost防走失", defaultValue = "topic")
                                                @RequestParam(value = "topic", required = true) String topic) {
        try {
            return ListEnvelop.getSuccess("查询成功",  patientDeviceService.patientDeviceListByTopic(patient,topic));
        } catch (Exception ex) {
            error(ex);
            return ListEnvelop.getError("查询失败");
        }
    }
    /**
     * 设备删除
@ -244,4 +258,46 @@ public class PatientDeviceController extends BaseController {
        }
    }
    @ApiOperation("获取设备最新位置数据")
    @RequestMapping(value = "getDeviceLastLocation",method = RequestMethod.GET)
    public String getDeviceLastLocation(@ApiParam(name = "deviceSn",value = "设备sn码")
                                        @RequestParam(value = "deviceSn",required = true)String deviceSn,
                                        @ApiParam(name = "type",value = "type 0:Gps定位; 1:基站定位 (非必填)")
                                        @RequestParam(value = "type",required = false)String type){
        try {
            return write(200,"获取成功","data",patientDeviceService.getDeviceLastLocation(deviceSn,type));
        }catch (Exception e){
            e.printStackTrace();
            return write(-1,"获取失败!");
        }
    }
    @ApiOperation("更新智能手环设备安全区域")
    @RequestMapping(value = "updateDeviceFenceArea",method = RequestMethod.GET)
    public String updateDeviceFenceArea(@ApiParam(name = "deviceSn",value = "设备sn码")
                                        @RequestParam(value = "deviceSn",required = true)String deviceSn,
                                        @ApiParam(name = "fenceNO",value = "安全区编号")
                                        @RequestParam(value = "fenceNO",required = false)Integer fenceNO,
                                        @ApiParam(name = "enable",value = "0,1 是否启用")
                                        @RequestParam(value = "enable",required = false)String enable,
                                        @ApiParam(name = "name",value = "安全区名称")
                                        @RequestParam(value = "name",required = false)String name,
                                        @ApiParam(name = "freq",value = "0,触发一天;1,每日触发 ")
                                        @RequestParam(value = "freq",required = false)String freq,
                                        @ApiParam(name = "time_begin",value = "目标时间与当日0点之间相差的秒数 ")
                                        @RequestParam(value = "time_begin",required = false)String time_begin,
                                        @ApiParam(name = "time_end",value = "同上 ")
                                        @RequestParam(value = "time_end",required = false)String time_end,
                                        @ApiParam(name = "safe_area",value = "lon1,lat1;lon2,lat2; 5个坐标 形成一个封闭区域  A;B;C;D;A ")
                                        @RequestParam(value = "safe_area",required = false)String safe_area,
                                        @ApiParam(name = "clear",value = "删除标志,删除传1")
                                        @RequestParam(value = "clear",required = false)String clear
                                        ){
        try {
            return write(200,"获取成功","data",patientDeviceService.updateDeviceFenceArea(deviceSn, fenceNO, enable, name, freq, time_begin, time_end, safe_area, clear));
        }catch (Exception e){
            e.printStackTrace();
            return write(-1,"获取失败!");
        }
    }
}

+ 46 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/third/assistance/EmeAsEndpoint.java

@ -0,0 +1,46 @@
package com.yihu.jw.care.endpoint.third.assistance;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.aop.ServicesAuth;
import com.yihu.jw.care.service.assistance.EmergencyAssistanceService;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * Created by Bing on 2021/5/10.
 */
@RestController
@RequestMapping(value = "/cloudCare/noLogin/emergency_assistance")
@Api(description = "紧急救助相关")
public class EmeAsEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private EmergencyAssistanceService assistanceService;
    @PostMapping(value = "newOrder")
    @ApiOperation(value = "居民发起新的紧急救助")
    @ServicesAuth(item = "emergencyAssistance")
    public ObjEnvelop newOrder(@ApiParam(name="patientId",value = "居民id")
                               @RequestParam(value = "patientId") String patientId,
                               @ApiParam(name="jsonData",value = "创建工单json")
                               @RequestParam(value = "jsonData") String jsonData
    ){
        try {
            JSONObject result = assistanceService.newOrder(patientId,jsonData,getUID());
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
                return ObjEnvelop.getError(result.getString(ResponseContant.resultMsg));
            }
            return ObjEnvelop.getSuccess("发起成功",result.getJSONObject("resultMsg"));
        }catch (Exception e){
            e.printStackTrace();
            return ObjEnvelop.getError("发起失败"+e.getMessage());
        }
    }
}

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

@ -7,6 +7,7 @@ import com.yihu.jw.care.dao.device.DeviceDetailDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.service.wechat.WeiXinAccessTokenUtils;
import com.yihu.jw.care.util.ConcealUtil;
import com.yihu.jw.util.common.GpsUtil;
import com.yihu.jw.care.util.MyJdbcTemplate;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
@ -18,7 +19,6 @@ import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
@ -89,6 +89,8 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
    Map<Integer, String> relations = new HashMap<>();
    @Value("${es.index.Statistics}")
    private String esIndex;
    @Autowired
    private GpsUtil gpsUtil;
    @PostConstruct
    public void init() {
@ -412,6 +414,19 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
        return re;
    }
    public List<Map<String,Object>> patientDeviceListByTopic(String patient,String serviceTopic){
        String sql = "select dd.photo,dd.brands,dd.category_code,dd.model,pd.device_name,pd.czrq deviceTime from dm_device dd INNER JOIN wlyy_patient_device pd on dd.category_code = pd.category_code\n" +
                "where 1=1 and  pd.del=0 ";
        if (StringUtils.isNotBlank(patient)) {
        sql += " pd.`user`='" + patient + "' ";
        }
        if (StringUtils.isNotBlank(serviceTopic)) {
            sql+= " and dd.service_topic='preventLost' ";
        }
        sql+=" order by pd.czrq asc ";
        return jdbcTemplate.queryForList(sql);
    }
    public JSONArray getDeviceByDeviceSn(String deviceSn, String type) {
        List<DevicePatientDevice> list = patientDeviceDao.findByDeviceSnAndCategoryCode(deviceSn, type);
        JSONArray objects = new JSONArray();
@ -780,11 +795,49 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
        String url = MessageFormat.format(AqgConfig.device_last_locationdata, deviceSn);
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        param.add("type", type);
        HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.aqgCookieHttp(url, param, HttpMethod.GET, getCookie());
        return response.getBody();
    }
    /**
     *
     *    | enable       |  否  | Int          |  0,1 是否启用                        |
     *    | name         |  否  | String       |   安全区名称                           |
     *    | freq         |  否  | Boolean      |  0,触发一天;1,每日触发        |
     *    | time_begin   |  否  | Int          |  目标时间与当日0点之间相差的秒数。如8 a.m 8*60*60=28800 |n
     *    | time_end     |  否  | Int          |  同上                        |
     *    | safe_area    |  否  | String       | x1,y1;x2,y2;xn,yn  一组由';'分隔的坐标,坐标用','分隔。且需要呈闭环,如A,B,C,D4个点,则应该上传的数据为 A;B;C;D;A  |
     *    | clear        |  否  | any          | 如果指定clear参数,则上述参数全部无意义,全部重设为缺省值    |
     * @return
     * @throws Exception
     */
    public com.alibaba.fastjson.JSONObject updateDeviceFenceArea(String deviceSn,Integer fenceNO,String enable,String name,String freq,
                                                                 String time_begin,String time_end,String safe_area ,String clear) throws Exception{
        String url = MessageFormat.format(AqgConfig.fence_area, deviceSn,fenceNO);
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        if(StringUtils.isBlank(clear)){
            if (StringUtils.isNotBlank(safe_area)){
                String[] position = safe_area.split(";");
                safe_area = "";
                for (String tmp:position){
                    String[] point = tmp.split(",");
                    safe_area+= gpsUtil.bd09_To_Gcj02_str(Double.parseDouble(point[1]),Double.parseDouble(point[0]))+";";
                }
            }
            param.add("name", name);
            param.add("freq", freq);
            param.add("enable",enable);
            param.add("time_begin", time_begin);
            param.add("time_end", time_end);
            param.add("safe_area", safe_area);
        }else {
            param.add("clear",clear);
        }
        HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.aqgCookieHttp(url, param, HttpMethod.POST, getCookie());
        return response.getBody();
    }
    /******************************************* 爱牵挂设备end *****************************************************/
}

+ 1 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/doctor/CareDoctorService.java

@ -157,7 +157,7 @@ public class CareDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
                    "and dh.dept_code = dict.`code` and dh.org_code = dict.org_code and dh.del=1 and dh.org_code='"+org.getCode()+"' GROUP BY doc.id" ;
            List<Map<String,Object>> tmpList = jdbcTemplate.queryForList(sql);
            Map<String,List<Map<String,Object>>> docTmp = tmpList.stream().collect(Collectors.groupingBy(e->e.get("deptCode").toString()));
//          Map<String,String> deptList = tmpList.stream().collect(Collectors.toMap(s->s.get("deptCode").toString(),s->s.get("deptName").toString(),(oldVal, currVal) -> currVal));
          Map<String,String> deptList = tmpList.stream().collect(Collectors.toMap(s->s.get("deptCode").toString(),s->s.get("deptName").toString(),(oldVal, currVal) -> currVal));
            Map<String,Object> tmpMap = new HashMap<>();
            tmpMap.put("orgCode",org.getCode());
            tmpMap.put("orgName",org.getName());

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

@ -9,6 +9,8 @@ import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.security.*;
import com.yihu.jw.care.service.device.PatientDeviceService;
import com.yihu.jw.care.service.sign.ServicePackageService;
import com.yihu.jw.care.util.CountDistance;
import com.yihu.jw.util.common.GpsUtil;
import com.yihu.jw.care.util.MessageUtil;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
@ -68,6 +70,10 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
    private BaseDoctorHospitalDao baseDoctorHospitalDao;
    @Autowired
    private PatientDeviceService patientDeviceService;
    @Autowired
    private GpsUtil gpsUtil;
    @Autowired
    private CountDistance countDistance;
    private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
@ -912,39 +918,63 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
    public JSONObject patientMonitoringInfo(String patient){
        JSONObject result = new JSONObject();
        result.put("location",null);
        result.put("enclosureStatus",null);
        result.put("enclosurePosition",null);
        result.put("fences",null);
        result.put("smoke",null);
        result.put("fire",null);
        result.put("deviceSn",null);
        List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
        if (devicePatientDeviceDos.size()==0){
            return result;
        }
        else {
            DevicePatientDevice device = devicePatientDeviceDos.get(0);
            result.put("deviceSn",device.getDeviceSn());
            try {
             JSONObject response= patientDeviceService.getDeviceLastLocation(device.getDeviceSn(),null);
             if (response.getBooleanValue("success")){
                JSONObject tmp = response.getJSONObject("obj");
                if (tmp.containsKey("locationdata")&&tmp.get("locationdata")!=null){
                    JSONObject locationTmp = tmp.getJSONObject("locationdata");
                    Double lon = locationTmp.getJSONObject("point").getJSONArray("coordinates").getDouble(0);
                    Double lat = locationTmp.getJSONObject("point").getJSONArray("coordinates").getDouble(1);
                    tmp = new JSONObject();
             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",locationTmp.getString("city"));
                    tmp.put("address",locationTmp.getString("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);
                     }
                 }
             }
            }catch (Exception e){
                e.printStackTrace();
                result.put("location",null);
            }
            result.put("enclosureStatus",null);
            result.put("enclosurePosition",null);
        }
        return result;
    }

+ 2 - 2
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/sign/ArchiveService.java

@ -83,7 +83,7 @@ public class ArchiveService extends BaseJpaService<ArchiveDO, ArchiveDao> {
    }
    public PageEnvelop<List<Map<String,Object>>> archiveList(String doctorId, int page, int size,Integer signStatus,String name){
        String sql = "SELECT a.create_time,p.idcard,p.mobile,p.name,p.sex,p.id,CAST(a.sign_status AS char) sign_status ";
        String sql = "SELECT a.create_time,p.idcard,p.mobile,p.name,p.sex,p.id,p.photo,CAST(a.sign_status AS char) sign_status ";
        String countSql = "SELECT count(*) from ( ";
        String filters = "from wlyy_archive a,base_patient p " +
@ -99,7 +99,7 @@ public class ArchiveService extends BaseJpaService<ArchiveDO, ArchiveDao> {
        }
        if (signStatus!=null&&signStatus==1){//已签约不按建档查询,是要该居民服务医生就在列表中
            filters+=" UNION " +
                    " SELECT a.create_time,p.idcard,p.mobile,p.name,p.sex,p.id,CAST(a.sign_status AS char) sign_status \n" +
                    " SELECT a.create_time,p.idcard,p.mobile,p.name,p.sex,p.id,p.photo,CAST(a.sign_status AS char) sign_status \n" +
                    "from wlyy_archive a,base_patient p WHERE  a.patient = p.id and a.sign_status = 1 and EXISTS( " +
                    "SELECT DISTINCT sr.patient from base_service_package_sign_record sr,base_service_package_record r, " +
                    "base_service_package_item i,base_team_member m " +

+ 51 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/CountDistance.java

@ -1,7 +1,13 @@
package com.yihu.jw.care.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
@Component
public class CountDistance {
    private static double EARTH_RADIUS = 6378.137;// 6378.137赤道半径6378137
@ -32,4 +38,49 @@ public class CountDistance {
        return s;
    }
    /**
     * 判断坐标是否在多边形区域内
     * @param pointLon
     * @param pointLat
     * @param rangePositions 多边形坐标 [{"lon":118.19302036660137,"lat":24.494515439791996},{"lon":118.19401849369201,"lat":24.49606682685256}]
     * @return
     */
    public boolean isInPolygon(double pointLon, double pointLat, JSONArray rangePositions) {
        // 将要判断的横纵坐标组成一个点
        double[] lon =  rangePositions.stream().mapToDouble(item->((JSONObject)item).getDouble("lon")).toArray();
        double[] lat =  rangePositions.stream().mapToDouble(item->((JSONObject)item).getDouble("lat")).toArray();;
        Point2D.Double point = new Point2D.Double(pointLon, pointLat);
        // 将区域各顶点的横纵坐标放到一个点集合里面
        List<Point2D.Double> pointList = new ArrayList<Point2D.Double>();
        double polygonPoint_x = 0.0, polygonPoint_y = 0.0;
        for (int i = 0; i < lon.length; i++) {
            polygonPoint_x = lon[i];
            polygonPoint_y = lat[i];
            Point2D.Double polygonPoint = new Point2D.Double(polygonPoint_x, polygonPoint_y);
            pointList.add(polygonPoint);
        }
        return check(point, pointList);
    }
    private static boolean check(Point2D.Double point, List<Point2D.Double> polygon) {
        java.awt.geom.GeneralPath peneralPath = new java.awt.geom.GeneralPath();
        Point2D.Double first = polygon.get(0);
        // 通过移动到指定坐标(以双精度指定),将一个点添加到路径中
        peneralPath.moveTo(first.x, first.y);
        polygon.remove(0);
        for (Point2D.Double d : polygon) {
            // 通过绘制一条从当前坐标到新指定坐标(以双精度指定)的直线,将一个点添加到路径中。
            peneralPath.lineTo(d.x, d.y);
        }
        // 将几何多边形封闭
        peneralPath.lineTo(first.x, first.y);
        peneralPath.closePath();
        // 测试指定的 Point2D 是否在 Shape 的边界内。
        return peneralPath.contains(point);
    }
}

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

@ -0,0 +1,11 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.DeviceSosLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Bing on 2021/5/8.
 */
public interface DeviceSosLogDao extends PagingAndSortingRepository<DeviceSosLogDO, Long>, JpaSpecificationExecutor<DeviceSosLogDO> {
}

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

@ -1,30 +1,37 @@
package com.yihu.jw.care.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.config.AqgConfig;
import com.yihu.jw.care.dao.device.DevicePatientHealthIndexDao;
import com.yihu.jw.care.dao.device.DeviceSosLogDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.DevicePatientHealthIndex;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.DeviceSosLogDO;
import com.yihu.jw.entity.util.AesEncryptUtils;
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.http.HttpClientUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
@ -38,6 +45,8 @@ import java.util.concurrent.TimeUnit;
public class DeviceService {
    private static Logger logger = LoggerFactory.getLogger(DeviceService.class);
    @Value("${cloudCare.url}")
    private String cloudCareUrl;
    @Autowired
    private HttpClientUtil httpClientUtil;
@ -49,6 +58,12 @@ public class DeviceService {
    private DevicePatientHealthIndexDao healthIndexDao;
    @Autowired
    private BasePatientDao patientDao;
    @Autowired
    private DeviceSosLogDao sosLogDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private GpsUtil gpsUtil;
    /**
     * 获取爱牵挂管理员cookie
@ -100,12 +115,67 @@ public class DeviceService {
    @Async
    public void aqgsos(String imei,String label_mac,String time_begin, HttpServletRequest request) {
        try {
        } catch (Exception e) {
            e.printStackTrace();
        }
            String address= request.getParameter("address");
            Double lat= Double.parseDouble(request.getParameter("lat"));
            Double lon= Double.parseDouble(request.getParameter("lon"));
            List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(imei);
            DevicePatientDevice deviceDO = devicePatientDeviceDos.get(0);
            BasePatientDO patientDO = patientDao.findById(deviceDO.getUser());
            DeviceSosLogDO logDO = new DeviceSosLogDO();
            logDO.setPatient(patientDO.getIdcard());
            logDO.setPatientName(patientDO.getName());
            logDO.setIdcard(patientDO.getIdcard());
            logDO.setCategoryCode(deviceDO.getCategoryCode());
            logDO.setDeviceSn(deviceDO.getDeviceSn());
            logDO.setCreateTime(new Date());
            if (deviceDO.getCategoryCode().equals("4")) {
                JSONObject position = gpsUtil.gcj02_To_Bd09(lat,lon);
                logDO.setSosAddress(address);
                logDO.setSosLat(position.getDouble("lat")+"");
                logDO.setSosLon(position.getDouble("lon")+"");
            }
            if (deviceDO.getCategoryCode().equals("7")) {
                logDO.setSosAddress(deviceDO.getSosAddress());
                Map<String, String> json = null;
                if (StringUtils.isNotBlank(deviceDO.getSosAddress())) {
                    json = LatitudeUtils.getGeocoderLatitude(deviceDO.getSosAddress().replace("G.", "").replace("(糖友网)", "").replace("(高友网)", ""));
                }
                if (json != null) {
                    logDO.setSosLat(json.get("lat").toString());
                    logDO.setSosLon(json.get("lat").toString());
                }
            }
            //发送紧急救助
            String sql =" select Distinct item.org_code,item.org_name\n" +
                    "from base_service_package_sign_record sr INNER JOIN base_service_package_record pr\n" +
                    "on sr.id = pr.sign_id and sr.status=1 INNER JOIN base_service_package_item item on pr.service_package_id = item.service_package_id and item.del=1 \n" +
                    "where item.code='emergencyAssistance' and sr.patient='"+patientDO.getId()+"'";
            List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql);
            if (sqlResult.size()>0){
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("serveAddress",logDO.getSosAddress());
                jsonObject.put("serveLon",logDO.getSosLon());
                jsonObject.put("serveLat",logDO.getSosLat());
                jsonObject.put("orgCode",sqlResult.get(0).get("org_code").toString());
                jsonObject.put("orgName",sqlResult.get(0).get("org_name").toString());
                jsonObject.put("patient",logDO.getPatient());
                jsonObject.put("patientName",logDO.getPatientName());
                String url = cloudCareUrl+"cloudCare/noLogin/emergency_assistance/newOrder";
                Map map = new HashMap<String, String>();
                map.put("patientId", logDO.getPatient());
                map.put("jsonData", jsonObject.toJSONString());
                String content = com.alibaba.fastjson.JSONObject.toJSONString(map);
                String postParams = AesEncryptUtils.agEncrypt(content);
                String response = httpClientUtil.postBodyRawForm(url,postParams);
                JSONObject result = com.alibaba.fastjson.JSONObject.parseObject(response);
                JSONObject jsonObjectData =JSONObject.parseObject(AesEncryptUtils.agDecrypt(result.getString("data")));
                logDO.setSosSendStatus(jsonObjectData.getInteger("status").toString());
                logDO.setSosSendMessage(jsonObjectData.getString("message"));
            }
            sosLogDao.save(logDO);
        }catch(Exception e){
                e.printStackTrace();
            }
    }
    /**

+ 6 - 0
svr/svr-cloud-device/src/main/resources/application.yml

@ -168,6 +168,9 @@ express:
baiduApi:
  AK: 0vjnCSReegE7A47a941ohjv9a07ONiMC
  url: http://api.map.baidu.com/
cloudCare:
  url: http://ehr.yihu.com/hlwyy/cloudCare/
---
spring:
  profiles: jwtest
@ -264,6 +267,9 @@ express:
baiduApi:
  AK: 0vjnCSReegE7A47a941ohjv9a07ONiMC
  url: http://api.map.baidu.com/
cloudCare:
  url: http://ehr.yihu.com/hlwyy/cloudCare/
---
spring:
  profiles: jwprod