liubing 3 gadi atpakaļ
vecāks
revīzija
226741ed3b

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

@ -1392,4 +1392,13 @@ ALTER table base_patient_sos_contacts add column update_info VARCHAR(1000) defau
-- 20210828
-- 20210828
alter table base_patient add `sign_status` tinyint(1) DEFAULT NULL COMMENT '签约状态 1已签约 0未签约';
alter table base_patient add `sign_status` tinyint(1) DEFAULT NULL COMMENT '签约状态 1已签约 0未签约';
--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);
}

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

@ -331,4 +331,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,"安全区域设置失败");
        }
        }
    }
    }

+ 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,"安全区域设置失败");
        }
        }
    }
    }
}
}

+ 8 - 0
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;
    /**
    /**
     * 查找居民联系服务站
     * 查找居民联系服务站
@ -418,4 +422,8 @@ public class ContactsService {
        sosContactsDao.save(modify);
        sosContactsDao.save(modify);
    }
    }
    public List<PatientSafeAreaDO> getPatientSafeArea(String patient){
        return safeAreaDao.findByPatient(patient);
    }
}
}

+ 78 - 46
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, "其他");
@ -1351,54 +1348,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";
    }
    }
    /**
    /**

+ 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";
    /**
    /**
     * 录像相关
     * 录像相关
     */
     */

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

+ 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());
    }
    /**
    /**
     * 消息解密
     * 消息解密