Pārlūkot izejas kodu

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

Shi Kejing 3 gadi atpakaļ
vecāks
revīzija
2246cecbb3
21 mainītis faili ar 595 papildinājumiem un 198 dzēšanām
  1. 10 0
      common/common-entity/sql记录
  2. 66 0
      common/common-entity/src/main/java/com/yihu/jw/entity/care/device/PatientSafeAreaDO.java
  3. 21 0
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/device/PatientSafeAreaDao.java
  4. 15 1
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/PadDeviceController.java
  5. 6 4
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/PatientDeviceController.java
  6. 2 2
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/statistics/DetectionPlatformEndpoint.java
  7. 5 3
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/third/device/PDeviceController.java
  8. 33 1
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/contacts/ContactsService.java
  9. 96 54
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/device/PatientDeviceService.java
  10. 9 1
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/message/BaseServiceNewsService.java
  11. 7 7
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/patient/CarePatientService.java
  12. 9 3
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/security/SecurityMonitoringOrderService.java
  13. 81 65
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/statistics/StatisticsService.java
  14. 4 0
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/config/YsConfig.java
  15. 1 0
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/dao/device/BasePatientOutBedDao.java
  16. 21 0
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/dao/device/PatientSafeAreaDao.java
  17. 6 0
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/DeviceController.java
  18. 15 0
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/YsDeviceController.java
  19. 39 50
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceService.java
  20. 14 7
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceUploadService.java
  21. 135 0
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/YsDeviceService.java

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

@ -1407,3 +1407,13 @@ CREATE TABLE `base_admin_service_dynamic` (
  PRIMARY KEY (`id`)
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='调度分析,管理员调度实时动态';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='调度分析,管理员调度实时动态';
--20210831
CREATE TABLE `wlyy_patient_safe_area` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `patient` varchar(50) DEFAULT NULL COMMENT '居民id',
  `safe_area_gz` varchar(255) DEFAULT NULL COMMENT '围栏地址5个坐标组成封闭区域 a>b>c>d>a',
  `create_time` timestamp NULL DEFAULT NULL COMMENT '创建日期',
  `update_time` timestamp NULL DEFAULT NULL COMMENT '更新日期',
  `success_flag` tinyint(4) DEFAULT NULL COMMENT '是否同步至设备 -1失败 1成功',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='患者设备安全区域';

+ 66 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/PatientSafeAreaDO.java

@ -0,0 +1,66 @@
package com.yihu.jw.entity.care.device;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Bing on 2021/8/31.
 */
@Entity
@Table(name="wlyy_patient_safe_area")
public class PatientSafeAreaDO extends IdEntity {
    private String patient;
    private String safeAreaGz;
    private Integer successFlag; //围栏同步至设备 -1失败 1成功
    private Date createTime;
    private Date updateTime;
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    @Column(name="safe_area_gz")
    public String getSafeAreaGz() {
        return safeAreaGz;
    }
    public void setSafeAreaGz(String safeAreaGz) {
        this.safeAreaGz = safeAreaGz;
    }
    public Integer getSuccessFlag() {
        return successFlag;
    }
    public void setSuccessFlag(Integer successFlag) {
        this.successFlag = successFlag;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}

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

@ -0,0 +1,21 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.PatientSafeAreaDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Bing on 2021/8/31.
 */
public interface PatientSafeAreaDao extends PagingAndSortingRepository<PatientSafeAreaDO,Long>,
        JpaSpecificationExecutor<PatientSafeAreaDO> {
    List<PatientSafeAreaDO> findByPatient(String patient);
    @Modifying
    void deleteByPatient(String patient);
}

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

@ -75,12 +75,14 @@ public class PadDeviceController extends BaseController {
    @RequestMapping(value = "PatientDeviceList", method = RequestMethod.GET)
    @RequestMapping(value = "PatientDeviceList", method = RequestMethod.GET)
    public String getDeviceByPatient(@ApiParam(name = "patientName", value = "居民姓名", defaultValue = "张")
    public String getDeviceByPatient(@ApiParam(name = "patientName", value = "居民姓名", defaultValue = "张")
                                     @RequestParam(value = "patientName", required = false) String patientName,
                                     @RequestParam(value = "patientName", required = false) String patientName,
                                     @ApiParam(name = "doctor", value = "doctor")
                                     @RequestParam(value = "doctor", required = false) String doctor,
                                     @ApiParam(name = "page", value = "分页起始id", defaultValue = "1")
                                     @ApiParam(name = "page", value = "分页起始id", defaultValue = "1")
                                     @RequestParam(value = "page", required = true) int page,
                                     @RequestParam(value = "page", required = true) int page,
                                     @ApiParam(name = "pagesize", value = "每页条数", defaultValue = "10")
                                     @ApiParam(name = "pagesize", value = "每页条数", defaultValue = "10")
                                     @RequestParam(value = "pagesize", required = true) int pagesize) {
                                     @RequestParam(value = "pagesize", required = true) int pagesize) {
        try {
        try {
            List<Map<String , Object>> list = patientDeviceService.findDeviceFromAdmin(patientName, page, pagesize);
            List<Map<String , Object>> list = patientDeviceService.findDeviceFromAdmin(doctor,patientName, page, pagesize);
            return write(200, "查询成功", "data", list);
            return write(200, "查询成功", "data", list);
        } catch (Exception ex) {
        } catch (Exception ex) {
@ -331,4 +333,16 @@ public class PadDeviceController extends BaseController {
        }
        }
    }
    }
    @RequestMapping(value ="getPatientSafeArea",method = RequestMethod.GET)
    @ApiOperation(value = "获取患者安全区域")
    public String getPatientSafeArea(@ApiParam(name = "patient", value = "patient", defaultValue = "patient")
                                        @RequestParam(value = "patient", required = true) String patient){
        try {
            return write(200,"获取成功","data",contactsService.getPatientSafeArea(patient));
        }catch (Exception e){
            return errorResult(e);
        }
    }
}
}

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

@ -324,7 +324,9 @@ public class PatientDeviceController extends BaseController {
    @ApiOperation("更新智能手环设备安全区域")
    @ApiOperation("更新智能手环设备安全区域")
    @RequestMapping(value = "updateDeviceFenceArea",method = RequestMethod.GET)
    @RequestMapping(value = "updateDeviceFenceArea",method = RequestMethod.GET)
    public String updateDeviceFenceArea(@ApiParam(name = "deviceSn",value = "设备sn码")
    public String updateDeviceFenceArea(@ApiParam(name = "patient",value = "患者")
                                        @RequestParam(value = "patient",required = false)String patient,
                                        @ApiParam(name = "deviceSn",value = "设备sn码")
                                        @RequestParam(value = "deviceSn",required = true)String deviceSn,
                                        @RequestParam(value = "deviceSn",required = true)String deviceSn,
                                        @ApiParam(name = "fenceNO",value = "安全区编号")
                                        @ApiParam(name = "fenceNO",value = "安全区编号")
                                        @RequestParam(value = "fenceNO",defaultValue = "1",required = false)Integer fenceNO,
                                        @RequestParam(value = "fenceNO",defaultValue = "1",required = false)Integer fenceNO,
@ -340,13 +342,13 @@ public class PatientDeviceController extends BaseController {
                                        @RequestParam(value = "time_end",defaultValue = "86400",required = false)String time_end,
                                        @RequestParam(value = "time_end",defaultValue = "86400",required = false)String time_end,
                                        @ApiParam(name = "safe_area",value = "lon1,lat1;lon2,lat2; 5个坐标 形成一个封闭区域  A;B;C;D;A ")
                                        @ApiParam(name = "safe_area",value = "lon1,lat1;lon2,lat2; 5个坐标 形成一个封闭区域  A;B;C;D;A ")
                                        @RequestParam(value = "safe_area",required = false)String safe_area,
                                        @RequestParam(value = "safe_area",required = false)String safe_area,
                                        @ApiParam(name = "clear",value = "删除标志,删除传1")
                                        @ApiParam(name = "clear",value = "删除标志,删除传1")
                                        @RequestParam(value = "clear",required = false)String clear
                                        @RequestParam(value = "clear",required = false)String clear
                                        ){
                                        ){
        try {
        try {
            return write(200,"获取成功","data",patientDeviceService.updateDeviceFenceArea(deviceSn, fenceNO, enable, name, freq, time_begin, time_end, safe_area, clear));
            return write(200,"设置成功","data",patientDeviceService.updateDeviceFenceArea(patient,deviceSn, fenceNO, enable, name, freq, time_begin, time_end, safe_area, clear));
        }catch (Exception e){
        }catch (Exception e){
            return errorResult(e);
            return error(-1,"安全区域设置失败");
        }
        }
    }
    }

+ 2 - 2
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/statistics/DetectionPlatformEndpoint.java

@ -146,8 +146,8 @@ public class DetectionPlatformEndpoint extends EnvelopRestEndpoint {
                                       @RequestParam(value = "pageSize")Integer pageSize){
                                       @RequestParam(value = "pageSize")Integer pageSize){
        try {
        try {
            com.alibaba.fastjson.JSONObject result = patientDeviceService.getPatientDeviceData(patient,deviceSn,page,pageSize);
            if (result.getInteger(ResponseContant.resultFlag)==ResponseContant.success){
            org.json.JSONObject result = patientDeviceService.getPatientDeviceData(patient,deviceSn,page,pageSize);
            if (result.getInt(ResponseContant.resultFlag)==ResponseContant.success){
                return success(JSON.parseObject(result.getString(ResponseContant.resultMsg)));
                return success(JSON.parseObject(result.getString(ResponseContant.resultMsg)));
            }else {
            }else {
                return success(result.getString(ResponseContant.resultMsg), -1);
                return success(result.getString(ResponseContant.resultMsg), -1);

+ 5 - 3
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/third/device/PDeviceController.java

@ -105,7 +105,9 @@ public class PDeviceController extends BaseController {
    @ApiOperation("更新智能手环设备安全区域")
    @ApiOperation("更新智能手环设备安全区域")
    @RequestMapping(value = "updateDeviceFenceArea",method = RequestMethod.GET)
    @RequestMapping(value = "updateDeviceFenceArea",method = RequestMethod.GET)
    public String updateDeviceFenceArea(@ApiParam(name = "deviceSn",value = "设备sn码")
    public String updateDeviceFenceArea(@ApiParam(name = "patient",value = "患者")
                                        @RequestParam(value = "patient",required = false)String patient,
                                        @ApiParam(name = "deviceSn",value = "设备sn码")
                                        @RequestParam(value = "deviceSn",required = true)String deviceSn,
                                        @RequestParam(value = "deviceSn",required = true)String deviceSn,
                                        @ApiParam(name = "fenceNO",value = "安全区编号")
                                        @ApiParam(name = "fenceNO",value = "安全区编号")
                                        @RequestParam(value = "fenceNO",defaultValue = "1",required = false)Integer fenceNO,
                                        @RequestParam(value = "fenceNO",defaultValue = "1",required = false)Integer fenceNO,
@ -125,9 +127,9 @@ public class PDeviceController extends BaseController {
                                        @RequestParam(value = "clear",required = false)String clear
                                        @RequestParam(value = "clear",required = false)String clear
                                        ){
                                        ){
        try {
        try {
            return write(200,"获取成功","data",patientDeviceService.updateDeviceFenceArea(deviceSn, fenceNO, enable, name, freq, time_begin, time_end, safe_area, clear));
            return write(200,"设置成功","data",patientDeviceService.updateDeviceFenceArea(patient,deviceSn, fenceNO, enable, name, freq, time_begin, time_end, safe_area, clear));
        }catch (Exception e){
        }catch (Exception e){
            return errorResult(e);
            return error(-1,"安全区域设置失败");
        }
        }
    }
    }
}
}

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

@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.dao.contacts.BasePatientContactsOrgDao;
import com.yihu.jw.care.dao.contacts.BasePatientContactsOrgDao;
import com.yihu.jw.care.dao.contacts.PatientSosContactsDao;
import com.yihu.jw.care.dao.contacts.PatientSosContactsDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.device.PatientSafeAreaDao;
import com.yihu.jw.care.dao.family.PatientFamilyMemberDao;
import com.yihu.jw.care.dao.family.PatientFamilyMemberDao;
import com.yihu.jw.care.service.device.NetworkCardService;
import com.yihu.jw.care.service.device.NetworkCardService;
import com.yihu.jw.care.service.device.PatientDeviceService;
import com.yihu.jw.care.service.device.PatientDeviceService;
@ -17,6 +18,7 @@ import com.yihu.jw.entity.base.patient.BasePatientFamilyMemberDO;
import com.yihu.jw.entity.care.contacts.BasePatientContactsOrgDO;
import com.yihu.jw.entity.care.contacts.BasePatientContactsOrgDO;
import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.PatientSafeAreaDO;
import com.yihu.jw.org.dao.BaseOrgDao;
import com.yihu.jw.org.dao.BaseOrgDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.ResponseContant;
@ -66,6 +68,8 @@ public class ContactsService {
    private PatientSosContactsDao sosContactsDao;
    private PatientSosContactsDao sosContactsDao;
    @Autowired
    @Autowired
    private NetworkCardService networkCardService;
    private NetworkCardService networkCardService;
    @Autowired
    private PatientSafeAreaDao safeAreaDao;
    /**
    /**
     * 查找居民联系服务站
     * 查找居民联系服务站
@ -202,7 +206,7 @@ public class ContactsService {
        List<Map<String,Object>> result = new ArrayList<>();
        List<Map<String,Object>> result = new ArrayList<>();
        String sql =  "select * from base_org org  " ;
        String sql =  "select * from base_org org  " ;
        if (StringUtils.isNotBlank(patient)){
        if (StringUtils.isNotBlank(patient)){
            sql +=" LEFT JOIN ( " +
            sql +=" Inner JOIN ( " +
                    "SELECT  DISTINCT pack.org_code,'1' as signFlag FROM  base_service_package_sign_record sr,  base_service_package_record r, " +
                    "SELECT  DISTINCT pack.org_code,'1' as signFlag FROM  base_service_package_sign_record sr,  base_service_package_record r, " +
                    " base_service_package pack  WHERE  sr.id = r.sign_id and sr.status=1 and sr.patient = '"+patient+"'" +
                    " base_service_package pack  WHERE  sr.id = r.sign_id and sr.status=1 and sr.patient = '"+patient+"'" +
                    "  and r.service_package_id = pack.id  " +
                    "  and r.service_package_id = pack.id  " +
@ -418,4 +422,32 @@ public class ContactsService {
        sosContactsDao.save(modify);
        sosContactsDao.save(modify);
    }
    }
    public JSONObject getPatientSafeArea(String patient){
        JSONObject result = new JSONObject();
        result.put("currentPositioning",null);       //当前定位
        result.put("currentLat",null);       //当前定位
        result.put("currentLon",null);
        List<PatientSafeAreaDO> safes =  safeAreaDao.findByPatient(patient);
        result.put("fences",safes);
        Double dulat = null;
        Double dulon = null;
        BasePatientDO patientDO = basePatientDao.findById(patient);
        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])){
                    dulon = Double.parseDouble(pointss[1]);
                }
                result.put("currentPositioning",LatitudeUtils.getLocationAddress(dulat+"",dulon+""));
                result.put("currentLat",dulat);
                result.put("currentLon",dulon);
            }
        }
        return result;
    }
}
}

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

@ -4,10 +4,7 @@ package com.yihu.jw.care.service.device;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.yihu.jw.care.config.AqgConfig;
import com.yihu.jw.care.config.AqgConfig;
import com.yihu.jw.care.dao.device.BaseSleepPlanDao;
import com.yihu.jw.care.dao.device.DeviceDao;
import com.yihu.jw.care.dao.device.DeviceDetailDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.device.*;
import com.yihu.jw.care.service.assistance.EmergencyAssistanceService;
import com.yihu.jw.care.service.assistance.EmergencyAssistanceService;
import com.yihu.jw.care.service.contacts.ContactsService;
import com.yihu.jw.care.service.contacts.ContactsService;
import com.yihu.jw.care.service.security.SecurityMonitoringOrderService;
import com.yihu.jw.care.service.security.SecurityMonitoringOrderService;
@ -18,10 +15,7 @@ import com.yihu.jw.care.util.MyJdbcTemplate;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.BaseSleepPlan;
import com.yihu.jw.entity.care.device.Device;
import com.yihu.jw.entity.care.device.DeviceDetail;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.*;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.util.common.GpsUtil;
import com.yihu.jw.util.common.GpsUtil;
@ -119,6 +113,9 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
    private SecurityMonitoringOrderService securityMonitoringOrderService;
    private SecurityMonitoringOrderService securityMonitoringOrderService;
    @Autowired
    @Autowired
    private CountDistance countDistance;
    private CountDistance countDistance;
    @Autowired
    private PatientSafeAreaDao safeAreaDao;
    @PostConstruct
    @PostConstruct
    public void init() {
    public void init() {
        relations.put(0, "其他");
        relations.put(0, "其他");
@ -391,7 +388,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
        return page;
        return page;
    }
    }
    public List<Map<String , Object>> findDeviceFromAdmin(String patientName, int page, int pageSize) {
    public List<Map<String , Object>> findDeviceFromAdmin(String doctor,String patientName, int page, int pageSize) {
        String sql = "select Distinct p.id,p.`name`,dd.photo,pd.device_id deviceId,pd.category_code categoryCode,pd.device_name deviceName, " +
        String sql = "select Distinct p.id,p.`name`,dd.photo,pd.device_id deviceId,pd.category_code categoryCode,pd.device_name deviceName, " +
                " pd.device_sn deviceSn,pd.czrq,pd.doctor,pd.doctor_name doctorName,pd.agent,pd.agent_name agentName " +
                " pd.device_sn deviceSn,pd.czrq,pd.doctor,pd.doctor_name doctorName,pd.agent,pd.agent_name agentName " +
                " from wlyy_patient_device pd,wlyy_devices wd,base_patient p,dm_device dd where p.id = pd.`user`  and pd.del = 0 " +
                " from wlyy_patient_device pd,wlyy_devices wd,base_patient p,dm_device dd where p.id = pd.`user`  and pd.del = 0 " +
@ -399,6 +396,12 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
        if (StringUtils.isNotBlank(patientName)){
        if (StringUtils.isNotBlank(patientName)){
            sql += " AND (p.`name` LIKE '%" + patientName +"%' or  p.idcard LIKE '%" + patientName + "%') ";
            sql += " AND (p.`name` LIKE '%" + patientName +"%' or  p.idcard LIKE '%" + patientName + "%') ";
        }
        }
        if (StringUtils.isNotBlank(doctor)){//著老远查看时之查看签约居民的绑定
            sql += " and EXISTS (SELECT sr.patient from base_service_package_sign_record sr,base_service_package_record r,base_team_member m " +
                    " WHERE sr.patient = p.id and sr.status=1 and m.team_code = r.team_code and sr.id=r.sign_id " +
                    " and m.doctor_code = '"+doctor+"' and m.del = '1') ";
        }
        sql += " ORDER BY pd.czrq DESC LIMIT "+ (page-1)*pageSize +" , " + pageSize + " ";
        sql += " ORDER BY pd.czrq DESC LIMIT "+ (page-1)*pageSize +" , " + pageSize + " ";
        List<Map<String , Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String , Object>> list = jdbcTemplate.queryForList(sql);
        return list;
        return list;
@ -1005,7 +1008,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                        day = DateUtil.getStringDateShort();
                        day = DateUtil.getStringDateShort();
                    }
                    }
                    // 电子围栏
                    // 电子围栏
                    devInfoObj.put("safeAreaGz", securityMonitoringOrderService.getElectronicFence(deviceSn));
                    devInfoObj.put("safeAreaGz", securityMonitoringOrderService.getElectronicFence(device.getUser()));
                    // 行动轨迹
                    // 行动轨迹
                    devInfoObj.put("actionTrack", securityMonitoringOrderService.getActionTrack(deviceSn,day));
                    devInfoObj.put("actionTrack", securityMonitoringOrderService.getActionTrack(deviceSn,day));
                    //当前定位
                    //当前定位
@ -1032,7 +1035,11 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                    devInfoObj.put("currentLon",lon);       //当前定位
                    devInfoObj.put("currentLon",lon);       //当前定位
                    double dulat =Double.parseDouble(lat);
                    double dulat =Double.parseDouble(lat);
                    double dulon = Double.parseDouble(lon);
                    double dulon = Double.parseDouble(lon);
                    String safeArea = device.getSafeAreaGz();
                    List<PatientSafeAreaDO> safeAreaDOS = safeAreaDao.findByPatient(device.getUser());
                    String safeArea=null;
                    if (safeAreaDOS.size()>0){
                        safeArea = safeAreaDOS.get(0).getSafeAreaGz();
                    }
                    String[] safeAreas = safeArea.split(";");
                    String[] safeAreas = safeArea.split(";");
                    com.alibaba.fastjson.JSONArray fenceLocation = new com.alibaba.fastjson.JSONArray();
                    com.alibaba.fastjson.JSONArray fenceLocation = new com.alibaba.fastjson.JSONArray();
                    for (String area:safeAreas){
                    for (String area:safeAreas){
@ -1068,9 +1075,9 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
     * @param deviceSn 设备sn码
     * @param deviceSn 设备sn码
     * @return
     * @return
     */
     */
    public com.alibaba.fastjson.JSONObject getPatientDeviceData(String patient,String deviceSn,Integer page,Integer pageSize)throws Exception{
    public JSONObject getPatientDeviceData(String patient,String deviceSn,Integer page,Integer pageSize)throws Exception{
        page = page>0?page-1:0;
        page = page>0?page-1:0;
        com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
        JSONObject result = new JSONObject();
        List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
        List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
        if (devices.size()>0){
        if (devices.size()>0){
            DevicePatientDevice device = devices.get(0);
            DevicePatientDevice device = devices.get(0);
@ -1097,7 +1104,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
        return result;
        return result;
    }
    }
    public com.alibaba.fastjson.JSONObject getHealthIndex(com.alibaba.fastjson.JSONObject result,Integer type,String deviceSn,String patient,Integer page,Integer pageSize){
    public JSONObject getHealthIndex(JSONObject result,Integer type,String deviceSn,String patient,Integer page,Integer pageSize){
        page = page>0?page-1:0;
        page = page>0?page-1:0;
        Long count =0l;
        Long count =0l;
        PageRequest pageRequest = new PageRequest(page, pageSize);
        PageRequest pageRequest = new PageRequest(page, pageSize);
@ -1188,7 +1195,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                    }
                    }
                }
                }
                re.put(json);
                    re.put(json);
            }
            }
            result.put("dataList",re);
            result.put("dataList",re);
        }
        }
@ -1199,7 +1206,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
        return result;
        return result;
    }
    }
    public com.alibaba.fastjson.JSONObject getEmeWarn(com.alibaba.fastjson.JSONObject result,String deviceSn,String patient,Integer page,Integer pageSize){
    public JSONObject getEmeWarn(JSONObject result,String deviceSn,String patient,Integer page,Integer pageSize){
        String sqlCount = "select SUM(total) from( \n" +
        String sqlCount = "select SUM(total) from( \n" +
                "select count(ord.id) as total from base_emergency_assistance_order ord  where ord.device_sn='"+deviceSn+"' " +
                "select count(ord.id) as total from base_emergency_assistance_order ord  where ord.device_sn='"+deviceSn+"' " +
@ -1351,54 +1358,89 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
     * @return
     * @return
     * @throws Exception
     * @throws Exception
     */
     */
    public com.alibaba.fastjson.JSONObject updateDeviceFenceArea(String deviceSn,Integer fenceNO,String enable,String name,String freq,
    @Transactional(rollbackFor = Exception.class)
    public String updateDeviceFenceArea(String patient,String deviceSn,Integer fenceNO,String enable,String name,String freq,
                                                                 String time_begin,String time_end,String safe_area ,String clear) throws Exception{
                                                                 String time_begin,String time_end,String safe_area ,String clear) throws Exception{
        List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
        String url ="";
        if ("16".equals(devices.get(0).getCategoryCode())) {
            DevicePatientDevice patientDevice = devices.get(0);
            if (StringUtils.isNotBlank(safe_area)){
                patientDevice.setSafeAreaGz(safe_area);
                patientDeviceDao.save(patientDevice);
                com.alibaba.fastjson.JSONObject object = new com.alibaba.fastjson.JSONObject();
                object.put("success",true);
                return object;
        if(StringUtils.isBlank(patient)){
            List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
            if (devices.size()>0){
                DevicePatientDevice deviceTmp = devices.get(0);
                if ("4".equals(deviceTmp.getCategoryCode())||"16".equals(deviceTmp.getCategoryCode())){
                    patient = deviceTmp.getUser();
                }
            }
            }
        }
        }
        if ("4".equals(devices.get(0).getCategoryCode())){//手表
            Device device = deviceDao.findOne(devices.get(0).getDeviceId());
            if (device!=null){
                if ("X1".equals(device.getModel())){
                    url = MessageFormat.format(AqgConfig.X1fence_area, deviceSn,fenceNO);
                }
        List<DevicePatientDevice> devices = patientDeviceDao.findAllByUserAndCategoryCode(patient,"4");
        PatientSafeAreaDO safeAreaDO = new PatientSafeAreaDO();
        if (StringUtils.isNotBlank(patient)){
            List<PatientSafeAreaDO> safeAreaDOS = safeAreaDao.findByPatient(patient);
            // 1删除 空修改或删除
            if (safeAreaDOS.size()>0){
                safeAreaDO = safeAreaDOS.get(0);
            }else {
                safeAreaDO.setPatient(patient);
                safeAreaDO.setCreateTime(new Date());
                safeAreaDO.setUpdateTime(new Date());
                safeAreaDO.setSuccessFlag(-1);
            }
            if (StringUtils.isNotBlank(clear)) {//删除
                safeAreaDao.deleteByPatient(patient);
            }
            else{//新增或修改
                safeAreaDO.setSafeAreaGz(safe_area);
                safeAreaDO.setUpdateTime(new Date());
                safeAreaDO.setSuccessFlag(-1);
            }
            }
        }else {
            url = MessageFormat.format(AqgConfig.S3fence_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]))+";";
        if (devices.size()>0){
            DevicePatientDevice patientDevice = devices.get(0);
            String deviceSnTmp = patientDevice.getDeviceSn();
            String url ="";
            if ("4".equals(devices.get(0).getCategoryCode())){//手表
                Device device = deviceDao.findOne(devices.get(0).getDeviceId());
                if (device!=null){
                    if ("X1".equals(device.getModel())){
                        url = MessageFormat.format(AqgConfig.X1fence_area, deviceSnTmp,fenceNO);
                    }
                }
                }
            }else {
                url = MessageFormat.format(AqgConfig.S3fence_area, deviceSnTmp,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());
            com.alibaba.fastjson.JSONObject responseObj = response.getBody();
            if (responseObj.getBoolean("success")){
                safeAreaDO.setSuccessFlag(1);
            }
            else {
                throw new Exception("安全区域设置失败!");
            }
            if (StringUtils.isBlank(clear)&&StringUtils.isNotBlank(patient)){
                safeAreaDao.save(safeAreaDO);
            }
            }
            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();
        return "success";
    }
    }
    /**
    /**

+ 9 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/message/BaseServiceNewsService.java

@ -5,7 +5,6 @@ import com.yihu.jw.care.dao.message.BaseServiceNewsDao;
import com.yihu.jw.care.service.device.DeviceService;
import com.yihu.jw.care.service.device.DeviceService;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.message.BaseServiceNews;
import com.yihu.jw.entity.care.message.BaseServiceNews;
import com.yihu.jw.restmodel.iot.device.WlyyPatientDeviceVO;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.common.IdCardUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.PageRequest;
@ -43,7 +42,16 @@ public class BaseServiceNewsService {
     * @return
     * @return
     */
     */
    public List<Map<String,Object>> findOrgLocations(){
    public List<Map<String,Object>> findOrgLocations(){
        String filter = "";
        String sqltmp = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_org' ";
        List<Map<String,Object>> listtmp =  jdbcTemplate.queryForList(sqltmp);
        if(listtmp.size()>0){
            String orgCodes = String.valueOf(listtmp.get(0).get("orgCodes"));
            orgCodes = orgCodes.replaceAll(",","','");
            filter = " and code not in ('"+orgCodes+"')";
        }
        String sql = "SELECT code,name,brief,address,photo,mobile,longitude,latitude,type from base_org WHERE type in ('3','4') and del =1";
        String sql = "SELECT code,name,brief,address,photo,mobile,longitude,latitude,type from base_org WHERE type in ('3','4') and del =1";
        sql += filter;
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return list;
        return list;
    }
    }

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

@ -474,14 +474,13 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
        }
        }
        if("3".equals(type)||StringUtil.isBlank(type)){
        if("3".equals(type)||StringUtil.isBlank(type)){
            filter = "";
            filter = "";
            String sqltmp = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_helper' ";
            String sqltmp = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_org' ";
            List<Map<String,Object>> listtmp =  jdbcTemplate.queryForList(sqltmp);
            List<Map<String,Object>> listtmp =  jdbcTemplate.queryForList(sqltmp);
            if(listtmp.size()>0){
            if(listtmp.size()>0){
                String orgCodes = String.valueOf(listtmp.get(0).get("orgCodes"));
                String orgCodes = String.valueOf(listtmp.get(0).get("orgCodes"));
                orgCodes = orgCodes.replaceAll(",","','");
                orgCodes = orgCodes.replaceAll(",","','");
                filter = " and id not in ('"+orgCodes+"')";
                filter = " and h.org_code not in ('"+orgCodes+"')";
            }
            }
            List<Map<String,Object>> list = findHelper(name,limit,filter);
            List<Map<String,Object>> list = findHelper(name,limit,filter);
            re.put("helper",list);
            re.put("helper",list);
@ -557,7 +556,7 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
        }
        }
        sql += filter1;
        sql += filter1;
        sql += " GROUP BY a.id,a.name,a.photo,a.idcard,a.birthday,a.residential_area,a.sex,online,signStatus ";
        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 += " ORDER BY online desc,signStatus desc";
        sql += limit;
        sql += limit;
        List<Map<String,Object>>  list = jdbcTemplate.queryForList(sql);
        List<Map<String,Object>>  list = jdbcTemplate.queryForList(sql);
        String sqlLife= "SELECT COUNT(*) from base_life_care_order where `status` = 2";
        String sqlLife= "SELECT COUNT(*) from base_life_care_order where `status` = 2";
@ -601,9 +600,10 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
     * @return
     * @return
     */
     */
    public List<Map<String,Object>> findHelper(String name,String limit,String fileter){
    public List<Map<String,Object>> findHelper(String name,String limit,String fileter){
        String sql = "SELECT id,name,photo,sex,IFNULL(on_line,0) online from base_doctor WHERE doctor_level = 2 and del = '1' ";
        String sql = "SELECT a.id,a.name,a.photo,a.sex,IFNULL(a.on_line,0) online from base_doctor a,base_doctor_hospital h" +
                "  WHERE a.id=h.doctor_code and a.doctor_level = 2 and a.del = '1' and h.del = '1' ";
        if(!StringUtil.isBlank(name)){
        if(!StringUtil.isBlank(name)){
            sql+= " and name like '%"+name+"%' ";
            sql+= " a.and name like '%"+name+"%' ";
        }
        }
        sql += fileter;
        sql += fileter;
        sql += " ORDER BY online desc";
        sql += " ORDER BY online desc";
@ -635,7 +635,7 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
    }
    }
    public Integer findHelperTotal(String name,String filter){
    public Integer findHelperTotal(String name,String filter){
        String sql = "SELECT count(id) from base_doctor WHERE doctor_level = 2 and del = '1' ";
        String sql = "SELECT count(a.id) from base_doctor a,base_doctor_hospital h WHERE  a.id=h.doctor_code and a.doctor_level = 2 and a.del = '1' and h.del = '1'  ";
        if(!StringUtil.isBlank(name)){
        if(!StringUtil.isBlank(name)){
            sql+= " and name like '%"+name+"%' ";
            sql+= " and name like '%"+name+"%' ";
        }
        }

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

@ -124,6 +124,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
    private BaseSleepPlanDetailDao sleepPlanDetailDao;
    private BaseSleepPlanDetailDao sleepPlanDetailDao;
    @Autowired
    @Autowired
    private BaseSleepNightRecordDao nightRecordDao;
    private BaseSleepNightRecordDao nightRecordDao;
    @Autowired
    private PatientSafeAreaDao safeAreaDao;
    private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
    private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
@ -254,8 +256,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        return result;
        return result;
    }
    }
    public List<Map<String , Object>> getElectronicFence(String deviceSn){
        String sql = " select safe_area_gz safeAreaGz from wlyy_patient_device where device_sn = '"+deviceSn+"' and del = 0 order by id desc limit 1";
    public List<Map<String , Object>> getElectronicFence(String patient){
        String sql = " select safe_area_gz safeAreaGz from wlyy_patient_safe_area where patient = '"+patient+"' ";
        return jdbcTemplate.queryForList(sql);
        return jdbcTemplate.queryForList(sql);
    }
    }
@ -1402,7 +1404,11 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
                    }
                    }
                }
                }
                if (!(dulat == 0.0 && dulon == 0.0)) {
                if (!(dulat == 0.0 && dulon == 0.0)) {
                    String safeArea = deviceDO.getSafeAreaGz();
                    List<PatientSafeAreaDO> safeAreaDOS = safeAreaDao.findByPatient(deviceDO.getUser());
                    String safeArea=null;
                    if (safeAreaDOS.size()>0){
                        safeArea = safeAreaDOS.get(0).getSafeAreaGz();
                    }
                    JSONArray fenceLocation = new JSONArray();
                    JSONArray fenceLocation = new JSONArray();
                    String address = LatitudeUtils.getLocationAddress(dulat + "", dulon + "");
                    String address = LatitudeUtils.getLocationAddress(dulat + "", dulon + "");
                    if (StringUtils.isNotBlank(safeArea)) {
                    if (StringUtils.isNotBlank(safeArea)) {

+ 81 - 65
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/statistics/StatisticsService.java

@ -88,45 +88,46 @@ public class StatisticsService {
    public JSONObject serviceResources(){
    public JSONObject serviceResources(){
        String orgFilter = "";
        String orgFilter = "";
        String helperFilter = "";
        String teacherFilter = "";
        String sqlOrg = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_org' ";
        String sqlOrg = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_org' ";
        List<Map<String,Object>> listOrg =  jdbcTemplate.queryForList(sqlOrg);
        List<Map<String,Object>> listOrg =  jdbcTemplate.queryForList(sqlOrg);
        if(listOrg.size()>0){
        if(listOrg.size()>0){
            String orgCodes = String.valueOf(listOrg.get(0).get("orgCodes"));
            String orgCodes = String.valueOf(listOrg.get(0).get("orgCodes"));
            orgCodes = orgCodes.replaceAll(",","','");
            orgCodes = orgCodes.replaceAll(",","','");
            orgFilter = " and id not in ('"+orgCodes+"')";
        }
        String sqlHelper = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_helper' ";
        List<Map<String,Object>> listHelper =  jdbcTemplate.queryForList(sqlHelper);
        if(listHelper.size()>0){
            String orgCodes = String.valueOf(listHelper.get(0).get("orgCodes"));
            orgCodes = orgCodes.replaceAll(",","','");
            helperFilter = " and id not in ('"+orgCodes+"')";
        }
        String sqltmp = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_teacher' ";
        List<Map<String,Object>> listtmp =  jdbcTemplate.queryForList(sqltmp);
        if(listtmp.size()>0){
            String orgCodes = String.valueOf(listtmp.get(0).get("orgCodes"));
            orgCodes = orgCodes.replaceAll(",","','");
            teacherFilter = " and id not in ('"+orgCodes+"')";
            orgFilter = " and code not in ('"+orgCodes+"')";
        }
        }
        JSONObject res = new JSONObject();
        JSONObject res = new JSONObject();
        String medicalInstitutionSql = "SELECT COUNT(1) FROM base_org WHERE (type = 1 OR type = 2) AND del = 1 ";
        String medicalInstitutionSql = "SELECT COUNT(1) FROM base_org WHERE (type = 1 OR type = 2) AND del = 1 ";
        String elderlyCarServiceSql = "SELECT COUNT(1) FROM base_org WHERE type = 3 AND del = 1"+orgFilter;
        String elderlyCarServiceSql = "SELECT COUNT(1) FROM base_org WHERE type = 3 AND del = 1"+orgFilter;
        String childcareInstitutionsssSql = "SELECT COUNT(1) FROM base_org WHERE type = 4 AND del = 1"+orgFilter;
        String childcareInstitutionsssSql = "SELECT COUNT(1) FROM base_org WHERE type = 4 AND del = 1"+orgFilter;
        String doctorSql = "SELECT COUNT(1) FROM base_doctor WHERE del = 1 AND doctor_level = 1";
        String helperSql = "SELECT COUNT(1) FROM base_doctor WHERE del = 1 AND doctor_level = 2" +helperFilter;
        String teacherSql = "SELECT COUNT(1) FROM base_doctor WHERE del = 1 AND doctor_level = 3"+teacherFilter;
        //助老员和教师注册人数
        Integer doctorNum = 0;
        Integer helperNum = 0;
        Integer teacherNum = 0;
        String sql2 = "SELECT COUNT(a.id) c,a.doctor_level from base_doctor a,base_doctor_hospital h where a.id=h.doctor_code and a.del = '1' and h.del = '1' " +
                "and a.doctor_level is not null and h.org_code not in ( " +
                "SELECT dict_code from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_org'  " +
                ") GROUP BY a.doctor_level";
        List<Map<String,Object>> list2 = jdbcTemplate.queryForList(sql2);
        for(Map<String,Object> map:list2){
            String archive_type = map.get("doctor_level").toString();
            Integer num = Integer.valueOf(map.get("c").toString());
            if("1".equals(archive_type)){
                doctorNum = num;
                continue;
            }
            if("2".equals(archive_type)){
                helperNum = num;
                continue;
            }
            if("3".equals(archive_type)){
                teacherNum = num;
            }
        }
        Integer medicalInstitutionNum = jdbcTemplate.queryForObject(medicalInstitutionSql,Integer.class);
        Integer medicalInstitutionNum = jdbcTemplate.queryForObject(medicalInstitutionSql,Integer.class);
        Integer elderlyCarServiceNum = jdbcTemplate.queryForObject(elderlyCarServiceSql,Integer.class);
        Integer elderlyCarServiceNum = jdbcTemplate.queryForObject(elderlyCarServiceSql,Integer.class);
        Integer childcareInstitutionsssNum = jdbcTemplate.queryForObject(childcareInstitutionsssSql,Integer.class);
        Integer childcareInstitutionsssNum = jdbcTemplate.queryForObject(childcareInstitutionsssSql,Integer.class);
        Integer doctorNum = jdbcTemplate.queryForObject(doctorSql,Integer.class);
        Integer helperNum = jdbcTemplate.queryForObject(helperSql,Integer.class);
        Integer teacherNum = jdbcTemplate.queryForObject(teacherSql,Integer.class);
        res.put("medicalInstitutionNum",medicalInstitutionNum);             //医疗结构
        res.put("medicalInstitutionNum",medicalInstitutionNum);             //医疗结构
        res.put("elderlyCarServiceNum",elderlyCarServiceNum);               //养老机构
        res.put("elderlyCarServiceNum",elderlyCarServiceNum);               //养老机构
        res.put("childcareInstitutionsssNum",childcareInstitutionsssNum);   //托育机构
        res.put("childcareInstitutionsssNum",childcareInstitutionsssNum);   //托育机构
@ -376,22 +377,54 @@ public class StatisticsService {
        Integer childTotal = 0;
        Integer childTotal = 0;
        Integer helperTotal = 0;
        Integer helperTotal = 0;
        Integer teacherTotal = 0;
        Integer teacherTotal = 0;
        Integer olderOff = 0;
        Integer childOff = 0;
        Integer helperOff = 0;
        Integer teacherOff = 0;
        Integer helperOn = 0;
        Integer teacherOn = 0;
        Integer childOn = 0;
        Integer olderOn = 0;
        Integer olderWxOn = 0;
        Integer olderPadOn = 0;
        //老人 儿童注册人数
        //老人 儿童注册人数
        String sql1 = "SELECT COUNT(*) c,archive_type*1 as archive_type from base_patient WHERE archive_type is  not null and del='1' GROUP BY archive_type";
        String pateintFilter = "";
        String sqltmp = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_child' or dict_name = 'jkzl_older'  ";
        List<Map<String,Object>> listtmp =  jdbcTemplate.queryForList(sqltmp);
        if(listtmp.size()>0){
            String orgCodes = String.valueOf(listtmp.get(0).get("orgCodes"));
            orgCodes = orgCodes.replaceAll(",","','");
            pateintFilter = " and id not in ('"+orgCodes+"')";
        }
        String sql1 = "SELECT COUNT(*) c,archive_type*1 as archive_type,IFNULL(on_line,0) online from base_patient WHERE archive_type is  not null" +
                " and del='1' "+pateintFilter+" GROUP BY archive_type";
        List<Map<String,Object>> list1 = jdbcTemplate.queryForList(sql1);
        List<Map<String,Object>> list1 = jdbcTemplate.queryForList(sql1);
        for(Map<String,Object> map:list1){
        for(Map<String,Object> map:list1){
            String archive_type = map.get("archive_type").toString();
            String archive_type = map.get("archive_type").toString();
            Integer num = Integer.valueOf(map.get("c").toString());
            Integer num = Integer.valueOf(map.get("c").toString());
            Integer online = Integer.valueOf(map.get("online").toString());
            if("1".equals(archive_type)){
            if("1".equals(archive_type)){
                olderTotal = num;
                if(online == 1){
                    olderOn = num;
                }else{
                    olderOff = num;
                }
                continue;
                continue;
            }
            }
            if("2".equals(archive_type)){
            if("2".equals(archive_type)){
                childTotal = num;
                if(online == 1){
                    childOn = num;
                }else{
                    childOff = num;
                }
            }
            }
        }
        }
        olderTotal = olderOff+olderOn;
        childTotal = childOff+childOn;
        //助老员和教师注册人数
        //助老员和教师注册人数
        String sql2 = "SELECT COUNT(a.id) c,a.doctor_level from base_doctor a,base_doctor_hospital h where a.id=h.doctor_code and a.del = '1' and h.del = '1' " +
        String sql2 = "SELECT COUNT(a.id) c,a.doctor_level,IFNULL(a.on_line,0) online from base_doctor a,base_doctor_hospital h where a.id=h.doctor_code and a.del = '1' and h.del = '1' " +
                "and a.doctor_level is not null and h.org_code not in ( " +
                "and a.doctor_level is not null and h.org_code not in ( " +
                "SELECT dict_code from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_org'  " +
                "SELECT dict_code from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_org'  " +
                ") GROUP BY a.doctor_level";
                ") GROUP BY a.doctor_level";
@ -399,50 +432,32 @@ public class StatisticsService {
        for(Map<String,Object> map:list2){
        for(Map<String,Object> map:list2){
            String archive_type = map.get("doctor_level").toString();
            String archive_type = map.get("doctor_level").toString();
            Integer num = Integer.valueOf(map.get("c").toString());
            Integer num = Integer.valueOf(map.get("c").toString());
            Integer online = Integer.valueOf(map.get("online").toString());
            if("2".equals(archive_type)){
            if("2".equals(archive_type)){
                helperTotal = num;
                if(online == 1){
                    helperOn = num;
                }else{
                    helperOff = num;
                }
                continue;
                continue;
            }
            }
            if("3".equals(archive_type)){
            if("3".equals(archive_type)){
                teacherTotal = num;
                if(online == 1){
                    teacherOn = num;
                }else{
                    teacherOff = num;
                }
            }
            }
        }
        }
        helperTotal = helperOff+helperOn;
        teacherTotal = teacherOff+teacherOn;
        //helper 助老员,teacher 教师,child 幼儿,olderWx 老人公众号,olderPad 老人平板
        //helper 助老员,teacher 教师,child 幼儿,olderWx 老人公众号,olderPad 老人平板
        String onlineCount = imUtil.getOnlineCountByType("");
        String onlineCount = imUtil.getOnlineCountByType("");
        JSONObject jsonObject = JSON.parseObject(onlineCount).getJSONObject("data");
        JSONObject jsonObject = JSON.parseObject(onlineCount).getJSONObject("data");
        //olderPad":0,"olderWx":0,"child":0,"teacher":0,"helper":0
        //olderPad":0,"olderWx":0,"child":0,"teacher":0,"helper":0
        Integer helperOn = jsonObject.getInteger("helper");
        Integer teacherOn = jsonObject.getInteger("teacher");
        Integer childOn = jsonObject.getInteger("child");
        Integer olderWxOn = jsonObject.getInteger("olderWx");
        Integer olderPadOn = jsonObject.getInteger("olderPad");
        int repeatNum = 0;
        if(olderWxOn>0&&olderPadOn>0){
            //2个都大于0 要计算重复的人数
            String onlineOlderWx = imUtil.getOnlineListByType("olderWx");
            JSONObject olderWx = JSON.parseObject(onlineOlderWx);
            List<String> list = new ArrayList(olderWx.size());
            olderWx.entrySet().stream().forEach(one->{
                list.add(one.getKey());
            });
            String onlineOlderPad = imUtil.getOnlineListByType("olderPad");
            JSONObject olderPad = JSON.parseObject(onlineOlderPad);
            for (Map.Entry<String,Object> s:olderPad.entrySet()){
                if(list.contains(s.getKey())){
                    repeatNum++;
                }
            }
        }
        Integer olderOff = olderTotal - olderWxOn - olderPadOn + repeatNum;
        olderOff = olderOff>0?olderOff:0;
        Integer childOff = childTotal - childOn;
        Integer helperOff = helperTotal - helperOn;
        Integer teacherOff = teacherTotal - teacherOn;
        olderWxOn = jsonObject.getInteger("olderWx");
        olderPadOn = jsonObject.getInteger("olderPad");
        result.put("olderTotal",olderTotal);
        result.put("olderTotal",olderTotal);
        result.put("childTotal",childTotal);
        result.put("childTotal",childTotal);
@ -715,18 +730,19 @@ public class StatisticsService {
        //评估类型
        //评估类型
        JSONArray jsonArray = new JSONArray();
        JSONArray jsonArray = new JSONArray();
        String sql = " select dict.dict_code,dict_value,count(DISTINCT lab.patient) total from wlyy_hospital_sys_dict dict \n" +
        String sql = " select dict.dict_code,dict_value,count(DISTINCT lab.patient) total from wlyy_hospital_sys_dict dict \n" +
                "LEFT JOIN wlyy_patient_label lab  on  dict.dict_code = lab.label_code\n" +
                "LEFT JOIN wlyy_patient_label lab  on  dict.dict_code = lab.label_code AND  lab.label_type='1' " +
                "where  dict.dict_name='service_type' and  dict.dict_code is not null and dict_code<>5  \n" +
                "where  dict.dict_name='service_type' and  dict.dict_code is not null and dict_code<>5  \n" +
                " GROUP BY dict.dict_code; ";
                " GROUP BY dict.dict_code; ";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        String older = "  select count(id) from base_patient where archive_type=1 ";
        String older = "  select count(DISTINCT patient) from wlyy_patient_label where label_type='1' ";
        Integer count = jdbcTemplate.queryForObject(older,Integer.class);
        Integer count = jdbcTemplate.queryForObject(older,Integer.class);
        for(Map<String,Object> map:list){
        for(Map<String,Object> map:list){
            JSONObject json = new JSONObject();
            JSONObject json = new JSONObject();
            DecimalFormat df = new DecimalFormat("0.00");
            DecimalFormat df = new DecimalFormat("0.00");
            json.put("num", df.format((Integer.parseInt(map.get("total").toString())*1.00) / count * 100));
            json.put("rate", df.format((Integer.parseInt(map.get("total").toString())*1.00) / count * 100));
            json.put("num", map.get("total"));
            json.put("code",map.get("dict_code").toString());
            json.put("code",map.get("dict_code").toString());
            json.put("name",map.get("dict_value").toString());
            json.put("name",map.get("dict_value").toString());
            jsonArray.add(json);
            jsonArray.add(json);

+ 4 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/config/YsConfig.java

@ -46,6 +46,10 @@ public class YsConfig {
    //云台停止
    //云台停止
    public static final String ptzStop = iotBaseUrl +"/api/lapp/device/ptz/stop";
    public static final String ptzStop = iotBaseUrl +"/api/lapp/device/ptz/stop";
    public static final String openChannelNo = iotBaseUrl +"/api/lapp/live/video/open";
    public static final String defenceSet = iotBaseUrl +"/open.ys7.com/api/lapp/device/intelligence/detection/switch/set";
    /**
    /**
     * 录像相关
     * 录像相关
     */
     */

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

@ -11,5 +11,6 @@ public interface BasePatientOutBedDao extends PagingAndSortingRepository<BasePat
        JpaSpecificationExecutor<BasePatientOutBed> {
        JpaSpecificationExecutor<BasePatientOutBed> {
    BasePatientOutBed findByPatientAndDeviceSnAndStatus(String patient,String deviceSn,Integer status);
    BasePatientOutBed findByPatientAndDeviceSnAndStatus(String patient,String deviceSn,Integer status);
    BasePatientOutBed findByPatientAndDeviceSn(String patient,String deviceSn);
}
}

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

@ -0,0 +1,21 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.PatientSafeAreaDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Bing on 2021/8/31.
 */
public interface PatientSafeAreaDao extends PagingAndSortingRepository<PatientSafeAreaDO,Long>,
        JpaSpecificationExecutor<PatientSafeAreaDO> {
    List<PatientSafeAreaDO> findByPatient(String patient);
    @Modifying
    void deleteByPatient(String patient);
}

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

@ -5,6 +5,7 @@ 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.DeviceDetailDao;
import com.yihu.jw.care.dao.device.DeviceDetailDao;
import com.yihu.jw.care.service.DeviceService;
import com.yihu.jw.care.service.DeviceService;
import com.yihu.jw.care.service.YsDeviceService;
import com.yihu.jw.entity.care.device.DeviceDetail;
import com.yihu.jw.entity.care.device.DeviceDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperation;
@ -41,6 +42,8 @@ public class DeviceController {
    private DeviceService deviceService;
    private DeviceService deviceService;
    @Autowired
    @Autowired
    private DeviceDetailDao deviceDetailDao;
    private DeviceDetailDao deviceDetailDao;
    @Autowired
    private YsDeviceService ysDeviceService;
    @RequestMapping(value = "/importDeviceFromExcel", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
    @RequestMapping(value = "/importDeviceFromExcel", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
    @ResponseBody
    @ResponseBody
@ -130,6 +133,9 @@ public class DeviceController {
                    errorMsgMap.put(deviceCode,"该sim卡号已存在");
                    errorMsgMap.put(deviceCode,"该sim卡号已存在");
                    continue;
                    continue;
                }
                }
                if ("CS-C6Wi-3E4WFR".equals(deviceModel)){//监控器 直播地址开通->关闭视频加密 后续暂时先于APP操作
                    ysDeviceService.videoOpen(deviceCode,null);
                }
                deviceDetail.setApplyDate(sdf.format(new Date()));
                deviceDetail.setApplyDate(sdf.format(new Date()));
                deviceDetail.setManufacturer(manufacturer);
                deviceDetail.setManufacturer(manufacturer);
                deviceDetail.setDeviceName(deviceName);
                deviceDetail.setDeviceName(deviceName);

+ 15 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/YsDeviceController.java

@ -4,6 +4,7 @@ import com.yihu.jw.care.common.BaseController;
import com.yihu.jw.care.service.YsDeviceService;
import com.yihu.jw.care.service.YsDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;
@ -45,5 +46,19 @@ public class YsDeviceController  extends BaseController {
        }
        }
    }
    }
    @ApiOperation("萤石摄像机直播地址开通->关闭视频加密")
    @RequestMapping(value = "video/open", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String videoOpen(
            @ApiParam(name="deviceSn",required = true,value="deviceSn")
            @RequestParam(value = "deviceSn",required = true) String deviceSn,
            HttpServletRequest request) {
        try {
            ysDeviceService.videoOpen(deviceSn,request);
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"error");
        }
    }
}
}

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

@ -724,37 +724,37 @@ public class DeviceService {
                    }
                    }
                    //更新患者在床状态
                    //更新患者在床状态
                    updatePatientSleepStatus(device,patient,time_begin,bed_status);
                    updatePatientSleepStatus(device,patient,time_begin,bed_status);
                    if (!orderCreate){
                        if ("1".equals(bed_status)){//呼吸 心率检测
                            Integer theshold_breath_h = 25;
                            Integer theshold_breath_l = 8;
                            Integer theshold_heartrate_h = 100;
                            Integer theshold_heartrate_l = 50;
                            if (StringUtils.isNotBlank(breath)){
                                Integer breath1 = Integer.parseInt(breath);
                                if (breath1>theshold_breath_h||breath1<theshold_breath_l){
                                    planDetail.setBreath(breath);
                                    planDetail.setHeartRate(heartrate);
                                    planDetail.setBedStatus(1);
                                    planDetail.setSleepNightRecordList(nightRecord.findBySnPaTime(device,patient,dayTime));
                                    outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
                                    return null;
                                }
                            }
                            if (StringUtils.isNotBlank(heartrate)){
                                Integer heartrate1 = Integer.parseInt(heartrate);
                                if (heartrate1>theshold_heartrate_h||theshold_heartrate_h<theshold_heartrate_l){
                                    planDetail.setBreath(breath);
                                    planDetail.setHeartRate(heartrate);
                                    planDetail.setBedStatus(1);
                                    planDetail.setSleepNightRecordList(nightRecord.findBySnPaTime(device,patient,dayTime));
                                    outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
                                    return null;
                                }
                            }
                        }
                    }
//                    if (!orderCreate){
//                        if ("1".equals(bed_status)){//呼吸 心率检测
//                            Integer theshold_breath_h = 25;
//                            Integer theshold_breath_l = 8;
//                            Integer theshold_heartrate_h = 100;
//                            Integer theshold_heartrate_l = 50;
//                            if (StringUtils.isNotBlank(breath)){
//                                Integer breath1 = Integer.parseInt(breath);
//                                if (breath1>theshold_breath_h||breath1<theshold_breath_l){
//                                    planDetail.setBreath(breath);
//                                    planDetail.setHeartRate(heartrate);
//                                    planDetail.setBedStatus(1);
//                                    planDetail.setSleepNightRecordList(nightRecord.findBySnPaTime(device,patient,dayTime));
//                                    outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
//                                    return null;
//                                }
//                            }
//                            if (StringUtils.isNotBlank(heartrate)){
//                                Integer heartrate1 = Integer.parseInt(heartrate);
//                                if (heartrate1>theshold_heartrate_h||theshold_heartrate_h<theshold_heartrate_l){
//                                    planDetail.setBreath(breath);
//                                    planDetail.setHeartRate(heartrate);
//                                    planDetail.setBedStatus(1);
//                                    planDetail.setSleepNightRecordList(nightRecord.findBySnPaTime(device,patient,dayTime));
//                                    outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
//                                    return null;
//                                }
//                            }
//
//                        }
//                    }
                }
                }
            }
            }
        } catch (Exception e) {
        } catch (Exception e) {
@ -818,26 +818,15 @@ public class DeviceService {
    public void updatePatientSleepStatus(String device,String patient,String time_begin,String bed_status){
    public void updatePatientSleepStatus(String device,String patient,String time_begin,String bed_status){
        Integer status = Integer.parseInt(bed_status);
        Integer status = Integer.parseInt(bed_status);
        BasePatientOutBed outBed = outBedDao.findByPatientAndDeviceSnAndStatus(patient,device,0);
        switch (status){
            case 0://离床
                if (null==outBed){
                    outBed = new BasePatientOutBed();
                    outBed.setPatient(patient);
                    outBed.setDeviceSn(device);
                    outBed.setStatus(status);
                    outBed.setCreateTime(DateUtil.strToDate(time_begin,DateUtil.YYYY_MM_DD_HH_MM_SS));
                    outBedDao.save(outBed);
                }
                break;
            case 1://在床
                if (null!=outBed){
                   outBed.setStatus(status);
                   outBed.setCreateTime(DateUtil.strToDate(time_begin,DateUtil.YYYY_MM_DD_HH_MM_SS));
                   outBedDao.save(outBed);
                }
                break;
        BasePatientOutBed outBed = outBedDao.findByPatientAndDeviceSn(patient,device);
        if (null==outBed){
            outBed = new BasePatientOutBed();
        }
        }
        outBed.setPatient(patient);
        outBed.setDeviceSn(device);
        outBed.setStatus(status);
        outBed.setCreateTime(DateUtil.strToDate(time_begin,DateUtil.YYYY_MM_DD_HH_MM_SS));
        outBedDao.save(outBed);
    }
    }
    @Async
    @Async

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

@ -70,6 +70,8 @@ public class DeviceUploadService {
    private GpsUtil gpsUtil;
    private GpsUtil gpsUtil;
    @Autowired
    @Autowired
    private JdbcTemplate jdbcTemplate;
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PatientSafeAreaDao safeAreaDao;
    public Result uploadDevicesData(String dataJson)throws Exception {
    public Result uploadDevicesData(String dataJson)throws Exception {
        try {
        try {
@ -483,15 +485,20 @@ public class DeviceUploadService {
                            List<DevicePatientDevice> patientDeviceList = patientDeviceDao.findByDeviceSn(sn);
                            List<DevicePatientDevice> patientDeviceList = patientDeviceDao.findByDeviceSn(sn);
                            DevicePatientDevice patientDevice = null;
                            DevicePatientDevice patientDevice = null;
                            if (patientDeviceList.size()>0){
                            if (patientDeviceList.size()>0){
                                for (DevicePatientDevice pd2:patientDeviceList){
                                    if (StringUtils.isNotBlank(pd2.getSafeAreaGz())){
                                        patientDevice = pd2;
                                        break;
                                    }
                                }
                                patientDevice = patientDeviceList.get(0);
//                                for (DevicePatientDevice pd2:patientDeviceList){
//                                    if (StringUtils.isNotBlank(pd2.getSafeAreaGz())){
//                                        patientDevice = pd2;
//                                        break;
//                                    }
//                                }
                            }
                            }
                            if (null!=patientDevice){//存在围栏地址
                            if (null!=patientDevice){//存在围栏地址
                                String safeArea = patientDevice.getSafeAreaGz();
                                List<PatientSafeAreaDO> safeAreaDOS = safeAreaDao.findByPatient(patientDevice.getUser());
                                String safeArea=null;
                                if (safeAreaDOS.size()>0){
                                    safeArea = safeAreaDOS.get(0).getSafeAreaGz();
                                }
                                if (StringUtils.isNotBlank(safeArea)){
                                if (StringUtils.isNotBlank(safeArea)){
                                    String[] safeAreas = safeArea.split(";");
                                    String[] safeAreas = safeArea.split(";");
                                    JSONArray fenceLocation = new JSONArray();
                                    JSONArray fenceLocation = new JSONArray();

+ 135 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/YsDeviceService.java

@ -12,6 +12,7 @@ import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.util.AesEncryptUtils;
import com.yihu.jw.entity.util.AesEncryptUtils;
import com.yihu.jw.exception.business.file_upload.*;
import com.yihu.jw.exception.business.file_upload.*;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import com.yihu.jw.util.common.LatitudeUtils;
import com.yihu.jw.util.common.LatitudeUtils;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.util.http.HttpClientUtil;
@ -25,9 +26,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartFile;
import javax.crypto.Cipher;
import javax.crypto.Cipher;
@ -43,6 +50,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashMap;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
/**
 * Created by Bing on 2021/6/1.
 * Created by Bing on 2021/6/1.
@ -68,6 +76,84 @@ public class YsDeviceService {
    private String fastdfs_file_url;
    private String fastdfs_file_url;
    @Autowired
    @Autowired
    private SecurityOrderUtil orderUtil;
    private SecurityOrderUtil orderUtil;
    @Autowired
    private StringRedisTemplate redisTemplate;
    /**
     * 获取萤石设备assesToken
     */
    public String getAccessToken() throws Exception {
        if(redisTemplate.hasKey(YsConfig.redisKey)){
            return redisTemplate.opsForValue().get(YsConfig.redisKey);
        }
        JSONObject param = new JSONObject();
        param.put("appKey",YsConfig.AppKey);
        param.put("appSecret",YsConfig.Secret);
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.saasAssesToken,param, HttpMethod.POST);
        JSONObject responseBody = response.getBody();
        String assToken = null;
        if (responseBody.getInteger("code")==200){
            assToken = responseBody.getJSONObject("data").getString("accessToken");
            Long expireTime = responseBody.getJSONObject("data").getLong("expiresIn");//token有效期
            redisTemplate.opsForValue().set(YsConfig.redisKey,assToken,expireTime, TimeUnit.SECONDS);
//            Long ss= redisTemplate.getExpire(YsConfig.redisKey);
//            System.out.println(expireTime+"---"+ss);
        }else {
            throw new Exception("获取token失败");
        }
        return assToken;
    }
    /**
     * 获取IOT开放平台assesToken
     * @return
     * @throws Exception
     */
    public String getIotAccessToken() throws Exception {
        if(redisTemplate.hasKey(YsConfig.iotRedisKey)){
            return redisTemplate.opsForValue().get(YsConfig.iotRedisKey);
        }
        JSONObject param = new JSONObject();
        param.put("accessToken",getAccessToken());
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.iotAssesToken,param, HttpMethod.POST);
        JSONObject responseBody = response.getBody();
        String assToken = null;
        if (responseBody.getInteger("code")==200){
            assToken = responseBody.getJSONObject("data").getString("ezOpenAccessToken");
            Long expireTime = responseBody.getJSONObject("data").getLong("expireTime");//token有效截止日期
            Long nowTime = System.currentTimeMillis();
            expireTime = expireTime-nowTime;
            redisTemplate.opsForValue().set(YsConfig.iotRedisKey,assToken,expireTime, TimeUnit.MILLISECONDS);
            //设备解密密钥
            String secretKey = responseBody.getJSONObject("data").getString("secretKey");
            redisTemplate.opsForValue().set(YsConfig.secretKey,secretKey,expireTime, TimeUnit.MILLISECONDS);
//            Long ss= redisTemplate.getExpire(YsConfig.iotRedisKey);
//            System.out.println(expireTime+"---"+ss);
        }else {
            throw new Exception("获取token失败");
        }
        return assToken;
    }
    /**
     * 获取设备解密密钥
     * @return
     * @throws Exception
     */
    public String getSecretKey() throws Exception {
        if(redisTemplate.hasKey(YsConfig.secretKey)){
            return redisTemplate.opsForValue().get(YsConfig.secretKey);
        }
        else {
            getIotAccessToken();
            return redisTemplate.opsForValue().get(YsConfig.secretKey);
        }
    }
    /**
    /**
     * 消息推送
     * 消息推送
@ -153,6 +239,55 @@ public class YsDeviceService {
        //https://www.yuque.com/u1400669/kb/div5py
        //https://www.yuque.com/u1400669/kb/div5py
    }
    }
    @Async
    public void videoOpen(String deviceSn,HttpServletRequest request) throws Exception {
        StringBuilder responseStr = new StringBuilder("--"+deviceSn+"-- ");
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        param.add("accessToken",getIotAccessToken());
        param.add("source",deviceSn+":"+1);
        HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(YsConfig.openChannelNo,param, HttpMethod.POST);
        JSONObject responseBody = response.getBody();
        responseStr.append("->开通通道:"+responseBody.getInteger("code"));
        JSONObject param2 = new JSONObject();
        param2.put("accessToken",getAccessToken());
        param2.put("deviceSerial",deviceSn);
        param2.put("channelNo","1");
        param2.put("isTrust",0);
        response = httpClientUtil.assesTokenPostHttp(YsConfig.surveillanceWay,param2,HttpMethod.POST);
        responseBody = response.getBody();
        responseStr.append("->获取通道详情:"+responseBody.getInteger("code"));
        if (responseBody.getInteger("code")==200){
            try {
                JSONObject tmp =  responseBody.getJSONObject("data");
                String validateCode = tmp.getString("ipcValidateCode");
                param2 = new JSONObject();
                param2.put("accessToken",getAccessToken());
                param2.put("deviceSerial",deviceSn);
                param2.put("isEncrypt","0");
                validateCode = messageDecrypt(validateCode,getSecretKey());
                param2.put("validateCode",validateCode);
                response = httpClientUtil.assesTokenPostHttp(YsConfig.deviceEncrypt,param2,HttpMethod.POST);
                responseBody = response.getBody();
                responseStr.append("->视频解密:"+responseBody.getInteger("code"));
            }catch (Exception e){
            }
        }
//        //设置编码格式
//
//
//        //设置活动检测
//        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
//        param.add("accessToken",getIotAccessToken());
//        param.add("deviceSerial",deviceSn);
//        param.add("enable","1");
//        param.add("channelNo","1");
//        HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp("https://open.ys7.com/api/lapp/device/intelligence/detection/switch/set",param, HttpMethod.POST);
//        JSONObject responseBody = response.getBody();
//        responseStr.append("->活动检测:"+responseBody.getInteger("code"));
        logger.info(responseStr.toString());
    }
    /**
    /**
     * 消息解密
     * 消息解密