Explorar o código

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

Shi Kejing %!s(int64=3) %!d(string=hai) anos
pai
achega
65ea6e20e3

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

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

+ 10 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/patient/BasePatientDO.java

@ -282,6 +282,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
    private String latLon;//定位经纬度
    private String padImei;//绑定平板标志
    private String residentialArea;//居住小区
    private Integer signStatus;// 签约状态【0未签约,1已签约】
    private Integer deviceFlag;//绑定设备标识 大于0为绑定了设备
@ -872,6 +873,15 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.residentialArea = residentialArea;
    }
    @Column(name = "sign_status")
    public Integer getSignStatus() {
        return signStatus;
    }
    public void setSignStatus(Integer signStatus) {
        this.signStatus = signStatus;
    }
    @Transient
    public Integer getDeviceFlag() {
        return deviceFlag;

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

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

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

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

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

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

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

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

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

@ -174,7 +174,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
     * @param patient
     */
    public List<Map<String,Object>> gasConcentration(String patient,String date,String deviceSn){
        String sql = "SELECT r.value,r.create_time from wlyy_patient_device pd,base_device_health_index r " +
        String sql = "SELECT r.value,CAST(DATE_FORMAT(r.create_time,'%Y-%m-%d %H:%i:%S') as char) create_time  from wlyy_patient_device pd,base_device_health_index r " +
                "WHERE pd.device_sn = r.device_sn  ";
        if (StringUtils.isNotBlank(patient)){
            sql +=" and pd.`user` = '"+patient+"' ";

+ 10 - 6
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/patient/CarePatientService.java

@ -469,13 +469,15 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
     * @return
     */
    public List<Map<String,Object>> findChild(String name,String residentialArea,String limit,JSONObject json){
        String sql = "SELECT id,name,photo,idcard,CAST(IFNULL(birthday,'') AS char ) birthday,residential_area residentialArea,sex  from base_patient WHERE archive_type = 2 and del = '1' ";
        String sql = "SELECT id,name,photo,idcard,CAST(IFNULL(birthday,'') AS char ) birthday,residential_area residentialArea" +
                ",sex,IFNULL(on_line,0) online  from base_patient WHERE archive_type = 2 and del = '1' ";
        if(!StringUtil.isBlank(name)){
            sql+= " and name like '%"+name+"%' ";
        }
        if(!StringUtil.isBlank(residentialArea)){
            sql+= " and residential_area = '"+residentialArea+"' ";
        }
        sql += " order by online desc";
        sql+=limit;
        List<Map<String,Object>>  list = jdbcTemplate.queryForList(sql);
        String sqlCount = "SELECT COUNT(*) from base_door_coach_order where `status` = 6";
@ -483,7 +485,7 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
            String paientId = map.get("id").toString();
            String filter = " and patient = '"+paientId+"'";
            Integer count = jdbcTemplate.queryForObject(sqlCount+filter,Integer.class);
            map.put("online",json.containsKey(paientId));
//            map.put("online",json.containsKey(paientId));
            map.put("doorCoach",count);
            String idcardNo = map.get("idcard") + "";
            Date birthday = DateUtil.strToDate(map.get("birthday").toString());
@ -514,7 +516,7 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
     */
    public List<Map<String,Object>> findOld(String name,String residentialArea,String limit,JSONObject json){
        String sql = "SELECT a.id,a.name,a.photo,a.idcard,CAST(IFNULL(a.birthday,'') AS char ) birthday,a.residential_area residentialArea,a.sex " +
                ", GROUP_CONCAT(DISTINCT d.category_code) deviceFlag from base_patient a " +
                ", GROUP_CONCAT(DISTINCT d.category_code) deviceFlag,IFNULL(on_line,0) online,IFNULL(sign_status,0) signStatus from base_patient a " +
                " LEFT JOIN wlyy_patient_device d on d.`user`=a.id  WHERE a.archive_type = 1 and a.del = '1' ";
        if(!StringUtil.isBlank(name)){
            sql+= " and name like '%"+name+"%' ";
@ -522,7 +524,8 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
        if(!StringUtil.isBlank(residentialArea)){
            sql+= " and residential_area = '"+residentialArea+"' ";
        }
        sql += " GROUP BY a.id,a.name,a.photo,a.idcard,a.birthday,a.residential_area,a.sex ";
        sql += " GROUP BY a.id,a.name,a.photo,a.idcard,a.birthday,a.residential_area,a.sex,online,signStatus ";
        sql += " ORDER BY online,signStatus desc";
        sql += limit;
        List<Map<String,Object>>  list = jdbcTemplate.queryForList(sql);
        String sqlLife= "SELECT COUNT(*) from base_life_care_order where `status` = 2";
@ -566,10 +569,11 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
     * @return
     */
    public List<Map<String,Object>> findHelper(String name,String limit,JSONObject json){
        String sql = "SELECT id,name,photo,sex from base_doctor WHERE doctor_level = 2 and del = '1' ";
        String sql = "SELECT id,name,photo,sex,IFNULL(on_line,0) online from base_doctor WHERE doctor_level = 2 and del = '1' ";
        if(!StringUtil.isBlank(name)){
            sql+= " and name like '%"+name+"%' ";
        }
        sql += " ORDER BY online desc";
        sql+=limit;
        List<Map<String,Object>>  list = jdbcTemplate.queryForList(sql);
        String sqlLife= "SELECT COUNT(*) from base_life_care_order where `status` = 2";
@ -590,7 +594,7 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
            Integer lifeCare = jdbcTemplate.queryForObject(sqlLife+filter,Integer.class);
            Integer emergency = jdbcTemplate.queryForObject(sqlEmergency+filter,Integer.class);
            Integer security = jdbcTemplate.queryForObject(sqlSecurity+filter,Integer.class);
            map.put("online",json.containsKey(doctorId));
//            map.put("online",json.containsKey(doctorId));
            map.put("lifeCare",lifeCare);
            map.put("emergency",emergency);
            map.put("security",security);

+ 8 - 25
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/sign/ServicePackageService.java

@ -36,7 +36,6 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@ -149,6 +148,11 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
                    patientLabelDO.setLabelName(dictService.fingByNameAndCode(ConstantUtil.DICT_SERVICE_TYPE,lableCode));
                    patientLabelDao.save(patientLabelDO);
                    //居民签约状态
                    BasePatientDO patientDO = patientDao.findById(patientId);
                    patientDO.setSignStatus(1);
                    patientDao.save(patientDO);
                    //修改base_patient_add里面的del,状态修改成0
                }else {
                    logger.info("居民已签约,patient:"+patientId);
@ -425,37 +429,16 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
        patientLabelDO.setLabelName(dictService.fingByNameAndCode(ConstantUtil.DICT_SERVICE_TYPE,lableCode));
        patientLabelDao.save(patientLabelDO);
        //服务项目 emergencyAssistance 只能签约一个
        String sqlItem = "select item.`code`,item.name from base_service_package_item item INNER JOIN base_service_package_record pr on item.service_package_id = pr.service_package_id\n" +
                "where pr.sign_id='"+signId+"' GROUP BY item.`code`";
        List<Map<String,Object>> itemList = jdbcTemplate.queryForList(sqlItem);
        Map<String,List<Map<String,Object>>> signItem = itemList.stream().collect(Collectors.groupingBy(e->e.get("code").toString()));
        //居民签约状态
        patientDO.setSignStatus(1);
        patientDao.save(patientDO);
        Iterator<ServicePackageRecordDO> iterator = recordDOList.iterator();
        while (iterator.hasNext()) {
            ServicePackageRecordDO recordDO = iterator.next();
            recordDO.setPatient(patientId);
            recordDO.setSignId(signId);
//            if (idList.contains(recordDO.getServicePackageId())) {
//                iterator.remove();//使用迭代器的删除方法删除
//            }
        }
/*        if(recordDOList.size()>0){
            List<String> packages = recordDOList.stream().map(ServicePackageRecordDO::getServicePackageId).collect(Collectors.toList());
            String packagesId = packages.stream().map(String::valueOf).collect(Collectors.joining("','"));
            sqlItem = "select item.`code`,item.name from base_service_package_item item " +
                    "where item.service_package_id in ('"+packagesId+"') GROUP BY item.`code`";
            itemList = jdbcTemplate.queryForList(sqlItem);
           Map<String,List<Map<String,Object>>> newItem = itemList.stream().collect(Collectors.groupingBy(e->e.get("code").toString()));
           if (newItem.containsKey("emergencyAssistance")&&signItem.containsKey("emergencyAssistance")){
               String message = "重复签约服务项目:"+newItem.get("emergencyAssistance").get(0).get("name").toString();
               throw new Exception(message);
           }
        }*/
//        CapacityAssessmentRecordDO capacityAssessmentRecordDO = capacityAssessmentRecordService.findAssessmentByPatientId(patientId);
//        capacityAssessmentRecordDO.setServicePackageStatus(1);
//        capacityAssessmentRecordService.save(capacityAssessmentRecordDO);
        servicePackageRecordDao.save(recordDOList);
        //修改床位生请状态为已完成

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

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

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

@ -55,6 +55,8 @@ public class DeviceUploadService {
    private BaseYxDeviceIndexDao yxDeviceIndexDao;
    @Autowired
    private HvDeviceService hvDeviceService;
    @Autowired
    private YsDeviceService ysDeviceService;
    public Result uploadDevicesData(String dataJson)throws Exception {
        try {
@ -438,6 +440,7 @@ public class DeviceUploadService {
        }
        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]
        //报警[XT*334588000000156*00CD*AL,180916,064153,A,22.570512,N,113.8623267,E,0.00,154.8,0.0,11,10 0,100,0,0,00100018,7,0,460,1,9529,21809,155,9529,21242,132,9529,21405,131,9529,63554,131,9 529,63555,130,9529,63556,118,9529,21869,116,0,12.4]
        String instruct[] = instructions.split("]");
        for (int i=0;i<instruct.length;i++){
            String inst = instruct[i];
@ -446,7 +449,7 @@ public class DeviceUploadService {
            String order = tmp[3];
            if(order.contains(",")){
                String tmp1[] = order.split(",");
                if("UD".equals(tmp1[0])||"CRUD".equals(tmp1[0])){
                if("UD".equals(tmp1[0])||"CRUD".equals(tmp1[0])||"AL".equals(tmp1[0])){
                    //处理位置信息
                    String lat,lon;
                    if("A".equals(tmp1[4])){
@ -456,6 +459,8 @@ public class DeviceUploadService {
                        lat = tmp1[4];
                        lon = tmp1[6];
                    }
                    //判断是否触发防走失工单
                    BaseYxDeviceIndex deviceIndex = new BaseYxDeviceIndex();
                    deviceIndex.setSn(sn);
                    deviceIndex.setLat(lat);
@ -467,4 +472,23 @@ public class DeviceUploadService {
        }
    }
    /**
     * 判断是否触发防走失工单
     */
    public void yxLossPrevention(String sn,String lat,String lon){
        if("0.000000".equals(lat)&&"0.000000".equals(lon)){
            return;
        }
        List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSnAndCategoryCode(sn,"16");
        String safeAreaGz = null;
        if (devices.size()>0){
            safeAreaGz = devices.get(0).getSafeAreaGz();
        }
        if(StringUtil.isBlank(safeAreaGz)){
            return;
        }
    }
}

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

@ -0,0 +1,84 @@
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
    private static double rad(double d) {
        return d * Math.PI / 180.0;
    }
    /**
     * 通过经纬度计算两点之间的距离(单位:千米)
     * @param latone
     * @param lngone
     * @param lattwo
     * @param lngtwo
     * @return
     */
    public  double getDistance(double latone, double lngone, double lattwo, double lngtwo) {
        double radlatone = rad(latone);
        double radlattwo = rad(lattwo);
        double a = radlatone - radlattwo;
        double b = rad(lngone) - rad(lngtwo);
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
                + Math.cos(radlatone) * Math.cos(radlattwo)
                * Math.pow(Math.sin(b / 2), 2)));
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000d) / 10000d;
        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);
    }
}

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

@ -35,54 +35,83 @@ public class PatientSosContactsJob implements Job {
    private NetworkCardService cardService;
    @Autowired
    private PatientDeviceService deviceService;
    @Autowired
    private YunXunDeviceService yunXunDeviceService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("PATIENT_SOS_CONTACTS_JOB start");
        String sql = " select pd.device_sn,wd.sim,sc.* from  wlyy_patient_device pd inner join wlyy_devices wd " +
                " on pd.device_sn = wd.device_code and pd.del=0 and wd.sim is not null and pd.category_code in('7','4') " +
                "INNER JOIN base_patient_sos_contacts sc on sc.patient = pd.user and sc.del=1 and sc.success_flag=0 group by wd.sim";
        String sql = " select pd.device_sn,pd.category_code,wd.sim,sc.* from  wlyy_patient_device pd inner join wlyy_devices wd " +
                " on pd.device_sn = wd.device_code and pd.del=0 " +
                "INNER JOIN base_patient_sos_contacts sc on sc.patient = pd.user and sc.del=1 " +
                "where  sc.success_flag=0 and pd.category_code in('7','4','16')  group by wd.device_code ";
        List<Map<String,Object>> sims = jdbcTemplate.queryForList(sql);
        List<PatientSosContactsDO> modify = new ArrayList<>();
        for(Map<String,Object> tmp:sims){//添加白名单,添加设备联系人
            String sim = tmp.get("sim").toString() ;
            String sim = tmp.get("sim")==null?null:tmp.get("sim").toString() ;
            String patient = tmp.get("patient").toString() ;
            String device_sn = tmp.get("device_sn").toString() ;
            String category_code = tmp.get("category_code").toString() ;
            String id = tmp.get("id").toString() ;
            String sos_name = tmp.get("sos_name").toString() ;
            String sos_phone = tmp.get("sos_phone").toString() ;
            String phone_seqid = tmp.get("phone_seqid").toString() ;
            try {
                PatientSosContactsDO sosContactsDO = sosContactsDao.findOne(Long.parseLong(id));
                if (StringUtils.isBlank(sosContactsDO.getUpdateInfo())){
                    sosContactsDO.setUpdateInfo(" ");
                }
                if(null!=sosContactsDO){
                    JSONObject response = cardService.setPatientContacts(sim, null, null, "1", sos_phone, null);//移动白名单
                    //0成功 12102名单重复
                    if (response.getInteger("status")==0||response.getInteger("status")==12108){
                        sosContactsDO.setSuccessFlag(1);
                    }else {
                        sosContactsDO.setSuccessFlag(-1);
                        modify.add(sosContactsDO);
                    if (StringUtils.isNotBlank(sim)){
                        JSONObject response = cardService.setPatientContacts(sim, null, null, "1", sos_phone, null);//移动白名单
                        //0成功 12102名单重复
                        if (response.getInteger("status")==0||response.getInteger("status")==12108){
                            sosContactsDO.setSuccessFlag(1);
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+1+"}");
                        }else {
                            sosContactsDO.setSuccessFlag(-1);
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+-1+"}");
                        }
                    }
                    //设备修改
                    JSONObject response2 =  deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
                    System.out.println(response2.toString());
                    if (response2.getBoolean("success")){
                        if (1==sosContactsDO.getSuccessFlag()){
                            sosContactsDO.setSuccessFlag(1);
                    if ("4".equals(category_code)||"7".equals(category_code)){
                        JSONObject response2 =  deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
                        System.out.println(response2.toString());
                        if (response2.getBoolean("success")){
                            if (1==sosContactsDO.getSuccessFlag()){
                                sosContactsDO.setSuccessFlag(1);
                            }
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+1+"}");
                        }else {
                            sosContactsDO.setSuccessFlag(-1);
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+-1+"}");
                        }
                    }else if ("16".equals(category_code)){
                        sql =" select sos_phone from base_patient_sos_contacts where patient='"+patient+"' ";
                        List<String> nums = jdbcTemplate.queryForList(sql,String.class);
                        String phone1 = null;
                        String phone2 = null;
                        String phone3 = null;
                        for (int i=0;i<nums.size();i++){
                            if(i==0){
                                phone1 = nums.get(i);
                            }
                            if(i==2){
                                phone2 = nums.get(i);
                            }
                        }
                        sosContactsDO.setSuccessFlag(-1);
                    }else {
                        sosContactsDO.setSuccessFlag(-1);
                        yunXunDeviceService.setSos(device_sn,phone1,phone2,phone3);
                        sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":unknow}");
                    }
                    modify.add(sosContactsDO);
                    sosContactsDao.save(sosContactsDO);
                }
            }catch (Exception e){
                logger.info(sim+"--同步失败--"+sos_phone);
                e.printStackTrace();
            }
        }
        sosContactsDao.save(modify);
//        sosContactsDao.save(modify);
        logger.info("PATIENT_SOS_CONTACTS_JOB end");
    }
}

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

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