Bladeren bron

代码修改

liubing 3 jaren geleden
bovenliggende
commit
9c17fc896e
23 gewijzigde bestanden met toevoegingen van 1343 en 296 verwijderingen
  1. 9 0
      common/common-entity/sql记录
  2. 9 0
      common/common-entity/src/main/java/com/yihu/jw/entity/care/contacts/PatientSosContactsDO.java
  3. 9 0
      common/common-entity/src/main/java/com/yihu/jw/entity/care/device/Device.java
  4. 54 5
      common/common-entity/src/main/java/com/yihu/jw/entity/care/device/DeviceDetail.java
  5. 27 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/WlyyPatientDeviceVO.java
  6. 78 0
      svr/svr-base/src/main/java/com/yihu/jw/base/config/YsConfig.java
  7. 33 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/device/DeviceDao.java
  8. 32 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/device/DeviceDetailDao.java
  9. 75 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/device/PatientDeviceDao.java
  10. 408 0
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/device/DeviceManageEndpoint.java
  11. 185 0
      svr/svr-base/src/main/java/com/yihu/jw/base/service/device/DeviceManageService.java
  12. 63 0
      svr/svr-base/src/main/java/com/yihu/jw/base/service/device/DmDeviceService.java
  13. 37 0
      svr/svr-base/src/main/java/com/yihu/jw/base/service/device/WlyyPatientDeviceService.java
  14. 188 0
      svr/svr-base/src/main/java/com/yihu/jw/base/service/device/YsDeviceService.java
  15. 31 31
      svr/svr-base/src/main/java/com/yihu/jw/base/service/equipment/BaseHospitalEquipmentService.java
  16. 2 2
      svr/svr-base/src/main/resources/application.yml
  17. 3 0
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/device/DeviceDao.java
  18. 0 110
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/PadDeviceController.java
  19. 25 10
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/device/PatientDeviceService.java
  20. 1 120
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/DeviceController.java
  21. 70 17
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/OnenetService.java
  22. 3 1
      svr/svr-cloud-job/src/main/java/com/yihu/jw/care/job/device/PatientSosContactsJob.java
  23. 1 0
      svr/svr-cloud-job/src/main/java/com/yihu/jw/care/service/device/NetworkCardService.java

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

@ -1494,3 +1494,12 @@ ALTER table wlyy_job_config_new add COLUMN area_level VARCHAR(1) default null co
-- 2021-09-13
alter table base_admin_service_dynamic add column photo varchar(255) default null COMMENT '用户头像';
alter table base_admin_service_dynamic add column del TINYINT(2) default 1 COMMENT '1有效,0失效';
-- 2021-09-22
alter table base_patient_sos_contacts add column error_info varchar(1000) default null comment '同步错误信息';
ALTER table wlyy_devices add column iccid VARCHAR(20) default null COMMENT '物联网卡iccid';
ALTER table wlyy_devices add column imsi VARCHAR(20) default null COMMENT '物联网卡IMSI';
ALTER table wlyy_devices add column  category_code varchar(50) DEFAULT NULL COMMENT '设备类型 dm_device表定义';
ALTER table dm_device add column device_type tinyint(2) DEFAULT NULL COMMENT '设备种类 0健康设备 1安防设备';

+ 9 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/contacts/PatientSosContactsDO.java

@ -25,6 +25,7 @@ public class PatientSosContactsDO extends IdEntity {
    private Integer del;
    private Integer phoneSeqid;// 联系人序号 1 或2
    private String updateInfo;//同步信息 -1失败 1成功
    private String errorInfo;//同步错误信息
    private String relationName;
@ -109,4 +110,12 @@ public class PatientSosContactsDO extends IdEntity {
    public void setUpdateInfo(String updateInfo) {
        this.updateInfo = updateInfo;
    }
    public String getErrorInfo() {
        return errorInfo;
    }
    public void setErrorInfo(String errorInfo) {
        this.errorInfo = errorInfo;
    }
}

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

@ -28,6 +28,7 @@ public class Device extends IdEntity {
	private String del;
	private String serviceTopic;//设备所属专题 防走失 preventLost
	private String needRegister;//设备是否注册iot(脉搏波血压计)
	private Integer deviceType;//0健康设备 1安防设备
	@Column(name="category_code")
	public String getCategoryCode() {
@ -126,4 +127,12 @@ public class Device extends IdEntity {
	public void setNeedRegister(String needRegister) {
		this.needRegister = needRegister;
	}
	public Integer getDeviceType() {
		return deviceType;
	}
	public void setDeviceType(Integer deviceType) {
		this.deviceType = deviceType;
	}
}

+ 54 - 5
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/DeviceDetail.java

@ -3,11 +3,10 @@ package com.yihu.jw.entity.care.device;
import com.yihu.jw.entity.iot.gateway.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.*;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by ysj on 2018/01/10.
@ -43,7 +42,7 @@ public class DeviceDetail extends IdEntity {
    private Integer isBinding;//是否绑定(0否 1 绑定单端口 2 绑定双端口)
    private String bindingCount;//绑定次数({"1":"0", "2":"0"})
    private Date grantTime;//发放时间
    private Integer deviceType;
    private Integer deviceType;//0健康设备 1安防设备
    //1.5.0版本新增字段
    private String grantDoctor;//发放医生code
@ -51,6 +50,14 @@ public class DeviceDetail extends IdEntity {
    private Integer contactStatus;// 失联状态 1未失联 0失联
    private Date contactStatusTime;//失联状态更新时间
    private String iccid;//设备物联卡iccid
    private String imsi;//设备物联卡imsi
    private String categoryCode; // 设备类型 dm_device表定义
    //导入设备错误信息
    private String errorMsg;
    private Map<String,String> errorMsgMap = new HashMap<>();
    /** default constructor */
    public DeviceDetail() {
    }
@ -344,4 +351,46 @@ public class DeviceDetail extends IdEntity {
    public void setContactStatusTime(Date contactStatusTime) {
        this.contactStatusTime = contactStatusTime;
    }
    public String getIccid() {
        return iccid;
    }
    public void setIccid(String iccid) {
        this.iccid = iccid;
    }
    public String getImsi() {
        return imsi;
    }
    public void setImsi(String imsi) {
        this.imsi = imsi;
    }
    public String getCategoryCode() {
        return categoryCode;
    }
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }
    @Transient
    public String getErrorMsg() {
        return errorMsg;
    }
    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }
    @Transient
    public Map<String, String> getErrorMsgMap() {
        return errorMsgMap;
    }
    public void setErrorMsgMap(Map<String, String> errorMsgMap) {
        this.errorMsgMap = errorMsgMap;
    }
}

+ 27 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/WlyyPatientDeviceVO.java

@ -27,6 +27,9 @@ public class WlyyPatientDeviceVO {
	private String hospitalName;
	private String doctorHealthName;
	private String doctorHealth;
	private String deviceModel;
	private String iccid;//设备物联卡iccid
	private String imsi;//设备物联卡imsi
	
	public Integer getId() {
		return id;
@ -164,4 +167,28 @@ public class WlyyPatientDeviceVO {
	public void setDoctorHealth(String doctorHealth) {
		this.doctorHealth = doctorHealth;
	}
	public String getDeviceModel() {
		return deviceModel;
	}
	public void setDeviceModel(String deviceModel) {
		this.deviceModel = deviceModel;
	}
	public String getIccid() {
		return iccid;
	}
	public void setIccid(String iccid) {
		this.iccid = iccid;
	}
	public String getImsi() {
		return imsi;
	}
	public void setImsi(String imsi) {
		this.imsi = imsi;
	}
}

+ 78 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/config/YsConfig.java

@ -0,0 +1,78 @@
package com.yihu.jw.base.config;
/**
 * Created by Bing on 2021/6/1.
 * 萤石摄像头配置
 */
public class YsConfig {
    //文档地址 https://www.yuque.com/u1400669/kb/lmfp6u
    public static final String AppKey="43e44c2071114743925eda34088045f8";
    public static final String Secret="82051725cf0547208f8bc8ae2bff1323";
    public static final String baseUrl = "https://esopen.ys7.com";
    public static final String iotBaseUrl = "https://open.ys7.com";
   //saas平台 https://www.yuque.com/u1400669/kb/wdvi3b#9ZP70
    public static final String saasAssesToken =baseUrl+ "/api/user/open-app/auth/gettoken";
    //开放平台  https://open.ys7.com/doc/zh/book/index/user.html
    public static final String iotAssesToken =baseUrl+ "/api/user/component-open/sso/oauth2/getEZAccessToken";
    //获取通道列表
    public static final String surveillanceWayList =baseUrl+ "/api/resource/open-app/surveillance/camera/list/page";
    //获取通道信息(通道默认为1)
    public static final String surveillanceWay =baseUrl+ "/api/resource/open-app/surveillance/camera/info";
    //设备抓拍
    public static final String deviceCapture =baseUrl +"/api/resource/device/capture";
    //获取设备有效直播地址
    public static final String getDeviceLiveAddress = iotBaseUrl+ "/api/lapp/live/address/limited";
    //设备视频加解密开关
    public static final String deviceEncrypt = baseUrl+ "/api/resource/device/encrypt/switch";
    //跌倒检测功能查询、设置(立即检测!判断是否有跌倒通过推送消息)
    public static final String deviceFailConfig = iotBaseUrl + "/api/route/device/devconfig/keyValue/{0}/{1}/op";
    //云台控制
    public static final String ptzStart = iotBaseUrl +"/api/lapp/device/ptz/start";
    //云台停止
    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";
    /**
     * 录像相关
     */
    //获取录像accessKey、上传录像地址
    public static final String videoKey = baseUrl +"/seastart/vod/token";
    //上传录像上传地址通过videoKey接口获取
    public static final String videoUpload = "https://seastart.ss.bscstorage.com";
    //录像列表
    public static final String videoList = baseUrl +"/seastart/vod/list";
    //批量获取录像详情
    public static final String videoDetailList = baseUrl +"/seastart/vod";
    //录像详情
    public static final String videoDetail = baseUrl +"/seastart/vod/get";
    public static final String redisKey = "ysAssesToken";
    public static final String iotRedisKey = "iotYsAssesToken";
    public static final String secretKey = "secretKey"; //设备的解密秘钥  通过iotAssesToken接口获取的
    public static final String msgDataKey = "HZADP68PNSNVZ4UW"; //消息解密密钥
}

+ 33 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/device/DeviceDao.java

@ -0,0 +1,33 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.jw.base.dao.device;
import com.yihu.jw.entity.care.device.Device;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface DeviceDao extends PagingAndSortingRepository<Device, Long> {
	@Query("select a from Device a where a.categoryCode = ?1 and a.del = '1'")
	List<Device> findByCategoryCode(String categoryCode);
	@Query("select a from Device a where a.del = '1'")
	List<Device> findAll();
	@Query("select count(1) from Device a where a.del = '1' and a.categoryCode=?1 ")
	Integer findTotalByCategoryCode(String categoryCode);
	@Query("select count(1) from Device a where a.del = '1' and a.name=?1 ")
	Integer findTotalByName(String name);
	@Query("select count(1) from Device a where a.del = '1' and a.model=?1")
	Integer findTotalByModel(String model);
	@Query("select a from Device a where a.del = '1' and a.model=?1")
	Device findByModel(String model);
}

+ 32 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/device/DeviceDetailDao.java

@ -0,0 +1,32 @@
package com.yihu.jw.base.dao.device;
import com.yihu.jw.entity.care.device.DeviceDetail;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author yeshijie on 2018/1/10.
 */
public interface DeviceDetailDao extends PagingAndSortingRepository<DeviceDetail, Long>, JpaSpecificationExecutor<DeviceDetail> {
    @Query(value = "select a.* from wlyy_devices a where a.device_code=?1 limit 0,1",nativeQuery = true)
    DeviceDetail findBySn(String sn);
    List<DeviceDetail> findByDeviceCode(String deviceCode);
    @Query("select a from DeviceDetail a where a.deviceCode = ?1 and a.manufacturerCode = ?2")
    DeviceDetail findByDeviceCodeAndManufacturerCode(String deviceCode,String manufacturerCode);
    @Query("select a from DeviceDetail a where a.sim = ?2")
    List<DeviceDetail> findBySim(String sim);
    @Query("select a from DeviceDetail a where a.iccid = ?2")
    List<DeviceDetail> findByIccid(String iccid);
    @Query("select a from DeviceDetail a where a.imsi = ?2")
    List<DeviceDetail> findByImsi(String sim);
}

+ 75 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/device/PatientDeviceDao.java

@ -0,0 +1,75 @@
package com.yihu.jw.base.dao.device;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface PatientDeviceDao extends PagingAndSortingRepository<DevicePatientDevice, Long>, JpaSpecificationExecutor<DevicePatientDevice> {
    @Query("select a from DevicePatientDevice a where a.user = ?1 ")
    Iterable<DevicePatientDevice> findByUser(String user);
    @Query("select a from DevicePatientDevice a where a.del = 0 ")
    List<DevicePatientDevice> findByAll();
    @Query("select a from DevicePatientDevice a where a.user = ?1 ")
    List<DevicePatientDevice> findByPatient(String user);
    @Query("select a from DevicePatientDevice a where a.user = ?1 and a.del=0 and a.deviceName like '%药盒%'")
    List<DevicePatientDevice> findByPatientAndDel(String user);
    @Query("select a from DevicePatientDevice a where a.user = ?1 and a.deviceSn=?2 ")
    List<DevicePatientDevice> findByPatientAndDeviceSn(String user, String deviceSn);
    List<DevicePatientDevice> findByUser(String user, Pageable pageRequest);
    List<DevicePatientDevice> findByUserAndDoctor(String user, String doctor, Pageable pageRequest);
    List<DevicePatientDevice> findByDeviceSnAndCategoryCode(String deviceSn, String categoryCode);
    DevicePatientDevice findByDeviceSnAndCategoryCodeAndUserType(String deviceSn, String categoryCode, String userType);
    DevicePatientDevice findByDeviceIdAndDeviceSnAndUserType(Long deviceId, String deviceSn, String userType);
    DevicePatientDevice findByDeviceSnAndUserType(String deviceSn, String userType);
    @Query("select pd from DevicePatientDevice pd where pd.deviceSn = ?1 and pd.del=0")
    List<DevicePatientDevice> findByDeviceSn(String deviceSn);
    //更换患者绑定的血糖仪
    @Modifying
    @Query("update DevicePatientDevice t set t.deviceSn = ?3 , t.userType = ?4,t.sim=?5,t.hospital=?6,t.hospitalName=?7,t.checkDoctorName=?8 where t.user = ?1 and t.deviceSn = ?2 ")
    int updatePatientDevice(String user, String deviceSN, String newDeviceSN, String userType, String sim, String hospital, String hospitalName, String checkDoctorName);
    //管理员解绑居民设备
    @Modifying
    @Query("update DevicePatientDevice t set t.del = 1  where t.deviceSn = ?1 and t.del =0  ")
    int updatePatientDevice(String deviceSN);
    @Query("select a from DevicePatientDevice a")
    List<DevicePatientDevice> findAll();
    @Query("select a from DevicePatientDevice a group by a.user")
    List<DevicePatientDevice> findAllGroupUser();
    @Query("select a from DevicePatientDevice a where a.categoryCode = ?1 and a.del=0 group by a.user")
    List<DevicePatientDevice> findAllByCategoryCode(String categoryCode);
    @Modifying
    @Query("delete DevicePatientDevice a where a.deviceSn = ?1")
    int deleteByDeviceSn(String deviceSN);
    @Query("select a from DevicePatientDevice a where a.user=?1 and a.del=0")
    List<DevicePatientDevice> findAllByUser(String user);
    @Query("select a from DevicePatientDevice a where a.user=?1 and a.categoryCode =?2 and a.del=0")
    List<DevicePatientDevice> findAllByUserAndCategoryCode(String user,String categoryCode);
    @Query("select a from DevicePatientDevice a where a.user=?1 and a.categoryCode =?2 and a.del=0")
    List<DevicePatientDevice> findByUserAndCategoryCode(String user,String categoryCode);
}

+ 408 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/device/DeviceManageEndpoint.java

@ -0,0 +1,408 @@
package com.yihu.jw.base.endpoint.device;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.dao.device.DeviceDao;
import com.yihu.jw.base.dao.device.DeviceDetailDao;
import com.yihu.jw.base.service.device.DeviceManageService;
import com.yihu.jw.base.service.device.DmDeviceService;
import com.yihu.jw.base.service.device.WlyyPatientDeviceService;
import com.yihu.jw.base.service.device.YsDeviceService;
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.restmodel.ResponseContant;
import com.yihu.jw.restmodel.iot.device.WlyyPatientDeviceVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.yihu.jw.util.common.BeanUtils.getNullPropertyNames;
/**
 * Created by Bing on 2021/9/22.
 */
@RestController
@RequestMapping(value = "baseDevice",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "设备管理", description = "设备管理", tags = {"设备管理"})
public class DeviceManageEndpoint extends EnvelopRestEndpoint {
    private static Logger logger = LoggerFactory.getLogger(DeviceManageEndpoint.class);
    @Autowired
    private DeviceDetailDao deviceDetailDao;
    @Autowired
    private DeviceDao deviceDao;
    @Autowired
    private DeviceManageService deviceManageService;
    @Autowired
    private WlyyPatientDeviceService patientDeviceService;
    @Autowired
    private DmDeviceService dmDeviceService;
    @Autowired
    private YsDeviceService ysDeviceService;
    @GetMapping("findWlyyDevices")
    @ApiOperation("获取设备列表")
    public PageEnvelop<DeviceDetail> findDevices(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size){
        try {
            List<DeviceDetail> list = deviceManageService.search(fields,filters,sorts,page,size);
            int count = (int) deviceManageService.getCount(filters);
            return success(list, count, page, size, DeviceDetail.class);
        }catch (Exception e){
            return failedPageEnvelopException2(e);
        }
    }
    @PostMapping("delWlyyDevice")
    @ApiOperation("删除设备")
    public Envelop delWlyyDevice(@ApiParam(name = "id")@RequestParam(value = "id")String id){
        try {
            deviceDetailDao.delete(Long.parseLong(id));
            return success(id);
        }catch (Exception e){
            return failedException2(e);
        }
    }
    @PostMapping("saveWlyyDevice")
    @ApiOperation("保存/修改设备")
    public Envelop saveDevice(@ApiParam(name="json")@RequestParam(value = "json")String json){
        try {
            JSONObject response = deviceManageService.saveWlyyDevice(json);
            if (1==response.getInteger(ResponseContant.resultFlag)){
                return success("修改成功") ;
            }
            else {
                return Envelop.getError(response.getString(ResponseContant.resultMsg)) ;
            }
        }catch (Exception e){
            return failedException2(e);
        }
    }
    @GetMapping(value = "getUserDevice")
    @ApiOperation("居民设备查询")
    public PageEnvelop<WlyyPatientDeviceVO> getUserDevice(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size){
        try {
             if (StringUtils.isBlank(filters)){
                 filters="del=0";
             }else {
                 filters+=";del=0";
             }
             List<DevicePatientDevice> list = patientDeviceService.search(fields, filters, sorts,page,size);
             List<WlyyPatientDeviceVO> list2 = new ArrayList<>();
             for (DevicePatientDevice tmp:list){
                 WlyyPatientDeviceVO deviceVO= new WlyyPatientDeviceVO();
                 BeanUtils.copyProperties(tmp, deviceVO, getNullPropertyNames(tmp));
                 deviceVO.setId(tmp.getId().intValue());
                 List<DeviceDetail> deviceDetails = deviceDetailDao.findByDeviceCode(deviceVO.getDeviceSn());
                 if (deviceDetails.size()>0){
                     DeviceDetail deviceDetail = deviceDetails.get(0);
                     deviceVO.setSim(deviceDetail.getSim());
                     deviceVO.setIccid(deviceDetail.getIccid());
                     deviceVO.setImsi(deviceDetail.getImsi());
                 }
                 list2.add(deviceVO);
             }
             int count = (int) patientDeviceService.getCount(filters);
             return success(list2, count, page, size);
        }catch (Exception e){
            return failedPageEnvelopException2(e);
        }
    }
    @PostMapping("delPatientDevice")
    @ApiOperation("删除患者设备-解绑")
    public Envelop delPatientDevice(@ApiParam(name = "id")
                                    @RequestParam(value = "id", required = false) String id){
        try {
            patientDeviceService.delPatientDevice(id);
            return success();
        }catch (Exception e){
            return failedException2(e);
        }
    }
    @GetMapping("findDmDeviceDict")
    @ApiOperation("获取设备字典")
    public PageEnvelop<Device> findDmDeviceDict(@ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
                                    @RequestParam(value = "fields", required = false) String fields,
                                    @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
                                    @RequestParam(value = "filters", required = false) String filters,
                                    @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
                                    @RequestParam(value = "sorts", required = false) String sorts,
                                    @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
                                    @RequestParam(value = "page") int page,
                                    @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
                                    @RequestParam(value = "size") int size){
        try {
            if (StringUtils.isBlank(filters)){
                filters="del=0";
            }else {
                filters+=";del=0";
            }
            List<Device> list = dmDeviceService.search(fields, filters, sorts,page,size);
            int count = (int) dmDeviceService.getCount(filters);
            return success(list, count, page, size);
        }catch (Exception e){
            return failedPageEnvelopException2(e);
        }
    }
    @PostMapping("delDmDevice")
    @ApiOperation("删除设备字典定义")
    public Envelop delDmDevice(@ApiParam(name = "id")
                             @RequestParam(value = "id", required = false) String id){
        try {
            dmDeviceService.delete(Long.parseLong(id));
            return success();
        }catch (Exception e){
            return failedException2(e);
        }
    }
    @PostMapping("saveDmDevice")
    @ApiOperation("保存设备字典定义")
    public Envelop saveDmDevice(@ApiParam(name="json")@RequestParam(value = "json")String json){
        try {
            JSONObject response = dmDeviceService.saveDmDevice(json);
            if (1==response.getInteger(ResponseContant.resultFlag)){
                return success("修改成功") ;
            }
            else {
                return Envelop.getError(response.getString(ResponseContant.resultMsg)) ;
            }
        }catch (Exception e){
            return failedException2(e);
        }
    }
    @PostMapping(value = "/importDeviceFromExcel", produces = "application/json;charset=UTF-8")
    @ApiOperation("设备数据导入")
    public ObjEnvelop importFromExcel(HttpServletRequest request, @ApiParam(value = "文件", required = true)
    @RequestParam(value = "file", required = true) MultipartFile file,HttpServletResponse response) {
        List errorLs = new ArrayList<>();
        List correctLs = new ArrayList<>();
        Map<String, String> errorMsgMapTotal = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<String> deviceCodes = new ArrayList<>();
        try {
            request.setCharacterEncoding("UTF-8");
            InputStream inputStream = file.getInputStream();
            Workbook rwb = Workbook.getWorkbook(inputStream);
            Sheet[] sheets = rwb.getSheets();
            int rows;
            int row;
            String manufacturer=null;//厂商名称
            String deviceName; //设备名称
            String deviceModel; //设备型号
            String deviceCode;  //设备SN
            String sim;  //sim卡号
            String iccid;  //iccid卡号
            String imsi;  //imsi卡号
            Sheet sheet = sheets[0];    //第一张表
            rows = sheet.getRows();
            for (int j = 1; j < rows; j++) {
                if (sheet.getRow(j).length == 0) {
                    continue;
                }
                String errorMsg = "";
                DeviceDetail deviceDetail = new DeviceDetail();
                Map<String, String> errorMsgMap = deviceDetail.getErrorMsgMap();
                row = j;
                manufacturer = sheet.getCell(0, row).getContents().trim();    //0 厂商名称
                deviceName = sheet.getCell(1, row).getContents().trim();  //1 设备名称
                deviceModel = sheet.getCell(2, row).getContents().trim();   //2 设备型号
                deviceCode = sheet.getCell(3, row).getContents().trim(); //3 设备SN
                sim = sheet.getCell(4, row).getContents().trim();  //4 sim卡号
                iccid = sheet.getCell(5, row).getContents().trim();  //4 iccid卡号
                imsi = sheet.getCell(6, row).getContents().trim();  //4 imsi卡号
                if (org.apache.commons.lang.StringUtils.isBlank(deviceCode)){
                    continue;
                }
                if (deviceCodes.contains(deviceCode)){
                    errorMsgMapTotal.put(deviceCode,"设备SN码重复");
                    errorMsgMap.put("deviceCode", "设备SN码重复!;");
                    errorMsg += "设备SN码重复!;";
                }
                deviceCodes.add(deviceCode);
                if (org.apache.commons.lang.StringUtils.isBlank(manufacturer)){
                    errorMsgMapTotal.put(deviceCode,"厂商名称不能为空");
                    errorMsgMap.put("manufacturer", "厂商名称不能为空!;");
                    errorMsg += "厂商名称不能为空!;";
                }
                if (org.apache.commons.lang.StringUtils.isBlank(deviceName)){
                    errorMsgMapTotal.put(deviceCode,"设备名称不能为空");
                    errorMsgMap.put("deviceName", "设备名称不能为空!;");
                    errorMsg += "设备名称不能为空!;";
                }
                if (org.apache.commons.lang.StringUtils.isBlank(deviceModel)){
                    errorMsgMapTotal.put(deviceCode,"设备型号不能为空");
                    errorMsgMap.put("deviceModel", "设备型号不能为空!;");
                    errorMsg += "设备型号不能为空!;";
                }
                //名称、设备类型、设备型号判断
                if (0==deviceDao.findTotalByName(deviceName)){
                    errorMsgMapTotal.put(deviceCode,"设备名称不存在");
                    errorMsgMap.put("deviceName", "设备名称不存在!;");
                    errorMsg += "设备名称不存在!;";
                }
                if (0==deviceDao.findTotalByModel(deviceModel)){
                    errorMsgMapTotal.put(deviceCode,"设备型号不存在");
                    errorMsgMap.put("deviceModel", "设备型号不存在!;");
                    errorMsg += "设备型号不存在!;";
                }
                if (deviceDetailDao.findByDeviceCode(deviceCode).size()>0){
                    errorMsgMapTotal.put(deviceCode,"该设备SN码已存在");
                    errorMsgMap.put("deviceCode", "该设备SN码已存在!;");
                    errorMsg += "该设备SN码已存在!;";
                }
                if (org.apache.commons.lang.StringUtils.isNotBlank(sim) && deviceDetailDao.findBySim(sim).size()>0){
                    errorMsgMapTotal.put(deviceCode,"该sim卡号已存在");
                    errorMsgMap.put("sim", "该sim卡号已存在!;");
                    errorMsg += "该sim卡号已存在!;";
                }
                if (org.apache.commons.lang.StringUtils.isNotBlank(iccid) && deviceDetailDao.findByIccid(iccid).size()>0){
                    errorMsgMapTotal.put(deviceCode,"该iccid卡号已存在");
                    errorMsgMap.put("iccid", "该iccid卡号已存在!;");
                    errorMsg += "该iccid卡号已存在!;";
                }
                if (org.apache.commons.lang.StringUtils.isNotBlank(imsi) && deviceDetailDao.findByImsi(imsi).size()>0){
                    errorMsgMapTotal.put(deviceCode,"该imsi卡号已存在");
                    errorMsgMap.put("imsi", "该imsi卡号已存在!;");
                    errorMsg += "该imsi卡号已存在!;";
                }
                if (!StringUtils.isEmpty(errorMsg.trim())) {
                    deviceDetail.setErrorMsg(errorMsg);
                    errorLs.add(deviceDetail);
                    continue;
                }
                if ("CS-C6Wi-3E4WFR".equals(deviceModel)){//监控器 直播地址开通->关闭视频加密 后续暂时先于APP操作
                    ysDeviceService.videoOpen(deviceCode,null);
                }
                deviceDetail.setApplyDate(sdf.format(new Date()));
                deviceDetail.setManufacturer(manufacturer);
                deviceDetail.setDeviceName(deviceName);
                deviceDetail.setDeviceModel(deviceModel);
                deviceDetail.setDeviceCode(deviceCode);
                deviceDetail.setSim(sim);
                Device device = deviceDao.findByModel(deviceModel);
                if (device!=null){
                    deviceDetail.setDeviceType(device.getDeviceType());
                    deviceDetail.setCategoryCode(device.getCategoryCode());//设备类型判断
                    if ("1".equals(device.getIsMultiUser())){
                        deviceDetail.setBindingCount("{\"1\":\"0\",\"2\":\"0\"}");
                    }else if ("0".equals(device.getIsMultiUser())){
                        deviceDetail.setBindingCount("{\"1\":\"0\"}");
                    }
                }
                correctLs.add(deviceDetail);
            }
            deviceDetailDao.save(correctLs);
            //包装导入结果(导入成功数量、错误对象集合)
            Map<String, Object> map = new HashMap<>();
            map.put("successNum", correctLs.size());
            map.put("failedNum", rows-1 - correctLs.size() );
            map.put("errorData", JSON.toJSONString(errorMsgMapTotal, SerializerFeature.WriteMapNullValue));
            map.put("errorData", errorLs);
            //失败数据下载
            if (errorLs.size()>0){
                response.setContentType("octets/stream");
                response.setHeader("Content-Disposition", "attachment; filename=" + new String("deviceImport.xls"));
                OutputStream os = response.getOutputStream();
                deviceManageService.write(os, errorLs);
            }
            return ObjEnvelop.getSuccess("success",JSON.toJSONString(map,SerializerFeature.WriteMapNullValue));
        } catch (Exception e) {
            failedObjEnvelopException2(e);
        }
        return ObjEnvelop.getSuccess("success",correctLs.size());
    }
    @GetMapping(value = "downLoadDeviceModelExcel", produces = "application/json;charset=UTF-8")
    @ApiOperation(("模板下载"))
    public void downLoadDeviceModelExcel(HttpServletResponse response) {
        try {
            response.setContentType("octets/stream");
            response.setHeader("Content-Disposition", "attachment; filename=" + new String("deviceImport.xls"));
            OutputStream os = response.getOutputStream();
            deviceManageService.write(os, null);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    /***初始化设备表 设备类型字段****/
    @PostMapping("initCategoryCode")
    @ApiOperation("设备库存表新增字段初始化")
    public Envelop initCategoryCode(){
        try {
            deviceManageService.initCategoryCode();
            return success();
        }catch (Exception e){
            return failedException2(e);
        }
    }
}

+ 185 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/device/DeviceManageService.java

@ -0,0 +1,185 @@
package com.yihu.jw.base.service.device;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.dao.device.DeviceDao;
import com.yihu.jw.base.dao.device.DeviceDetailDao;
import com.yihu.jw.entity.care.device.Device;
import com.yihu.jw.entity.care.device.DeviceDetail;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.mysql.query.BaseJpaService;
import jxl.Workbook;
import jxl.write.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
/**
 * Created by Bing on 2021/9/22.
 */
@Service
public class DeviceManageService extends BaseJpaService<DeviceDetail,DeviceDetailDao> {
    @Autowired
    private DeviceDetailDao deviceDetailDao;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private DeviceDao deviceDao;
    public JSONObject saveWlyyDevice(String json)throws Exception{
        JSONObject result = new JSONObject();
        DeviceDetail deviceDetail = objectMapper.readValue(json, DeviceDetail.class);
        String deviceName = deviceDetail.getDeviceName();
        String deviceModel = deviceDetail.getDeviceModel();
        String categoryCode= deviceDetail.getCategoryCode();
        String deviceSn = deviceDetail.getDeviceCode();
        String manufacturer = deviceDetail.getManufacturer();
        if (StringUtils.isBlank(deviceName)||StringUtils.isBlank(deviceModel)||StringUtils.isBlank(categoryCode)||
                StringUtils.isBlank(deviceSn)||StringUtils.isBlank(manufacturer)){
            result.put(ResponseContant.resultFlag,ResponseContant.fail);
            result.put(ResponseContant.resultMsg,"数据数据错误,必填字段为空");
            return result;
        }
        String sim = deviceDetail.getSim();
        String iccid = deviceDetail.getIccid();
        String imsi = deviceDetail.getImsi();
        DeviceDetail tmps1 =  deviceDetailDao.findBySn(deviceSn);
        if (tmps1!=null){
            result.put(ResponseContant.resultFlag,ResponseContant.fail);
            result.put(ResponseContant.resultMsg,"设备SN码重复");
            return result;
        }
        if (StringUtils.isNotBlank(sim)){
            List<DeviceDetail> tmps = deviceDetailDao.findBySim(sim);
            if (tmps.size()>0){
                result.put(ResponseContant.resultFlag,ResponseContant.fail);
                result.put(ResponseContant.resultMsg,"sim卡号重复");
                return result;
            }
        }
        if (StringUtils.isNotBlank(iccid)){
            List<DeviceDetail> tmps =  deviceDetailDao.findByIccid(iccid);
            if (tmps.size()>0){
                result.put(ResponseContant.resultFlag,ResponseContant.fail);
                result.put(ResponseContant.resultMsg,"iccid重复");
                return result;
            }
        }
        if (StringUtils.isNotBlank(imsi)){
            List<DeviceDetail> tmps =  deviceDetailDao.findByImsi(imsi);
            if (tmps.size()>0){
                result.put(ResponseContant.resultFlag,ResponseContant.fail);
                result.put(ResponseContant.resultMsg,"imsi重复");
                return result;
            }
        }
        //名称、设备类型、设备型号判断
        if (0==deviceDao.findTotalByCategoryCode(categoryCode)){
            result.put(ResponseContant.resultFlag,ResponseContant.fail);
            result.put(ResponseContant.resultMsg,"设备类型不存在");
            return result;
        }
        if (0==deviceDao.findTotalByName(deviceName)){
            result.put(ResponseContant.resultFlag,ResponseContant.fail);
            result.put(ResponseContant.resultMsg,"设备名称不存在");
            return result;
        }
        if (0==deviceDao.findTotalByModel(deviceModel)){
            result.put(ResponseContant.resultFlag,ResponseContant.fail);
            result.put(ResponseContant.resultMsg,"设备型号不存在");
            return result;
        }
        Device device = deviceDao.findByModel(deviceModel);
        if (device!=null){
            deviceDetail.setDeviceType(device.getDeviceType());
            if ("1".equals(device.getIsMultiUser())){
                deviceDetail.setBindingCount("{\"1\":\"0\",\"2\":\"0\"}");
            }else if ("0".equals(device.getIsMultiUser())){
                deviceDetail.setBindingCount("{\"1\":\"0\"}");
            }
        }
        if (null==deviceDetail.getId()){
            deviceDetail.setContactStatus(1);
        }
        deviceDetailDao.save(deviceDetail);
        result.put(ResponseContant.resultFlag,ResponseContant.success);
        result.put(ResponseContant.resultMsg,"success");
        return result;
    }
    public void initCategoryCode(){
        String sql = " select GROUP_CONCAT(model) model,category_code from dm_device GROUP BY category_code ";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        for (Map<String,Object> tmp:list){
            String category = tmp.get("category_code").toString();
            String model = tmp.get("model").toString();
            model = "'"+model.replace(",","','")+"'";
            sql = " UPDATE wlyy_devices set category_code='"+category+"' where device_model in ("+model+") ";
            jdbcTemplate.execute(sql);
        }
    }
    public void write(OutputStream os, List ls) throws Exception {
        write(Workbook.createWorkbook(os), ls);
    }
    public void write(WritableWorkbook wwb, List ls) throws Exception {
        try {
            WritableSheet ws;
            ws = wwb.createSheet("sheet", 1);
            addHeader(ws);
            int i = 1;
            for (DeviceDetail tmp : (List<DeviceDetail>) ls) {
                Map<String, String> map = tmp.getErrorMsgMap();
                addCell(ws, i, 0, tmp.getManufacturer(), map.get("manufacturer"));
                addCell(ws, i, 1, tmp.getDeviceName(), map.get("deviceName"));
                addCell(ws, i, 2, tmp.getDeviceModel(), map.get("deviceModel"));
                addCell(ws, i, 3, tmp.getDeviceCode(), map.get("deviceCode"));
                addCell(ws, i, 4, tmp.getSim(), map.get("sim"));
                addCell(ws, i,5,  tmp.getIccid(), map.get("iccid"));
                addCell(ws, i,6,  tmp.getImsi(), map.get("imsi"));
                i++;
            }
            wwb.write();
            wwb.close();
        } catch (IOException e) {
            e.printStackTrace();
            if (wwb != null) wwb.close();
            throw e;
        }
    }
    public void addHeader(WritableSheet ws) throws WriteException {
        String[] header = {"厂商(必填)", "设备名称(必填)", "设备型号(必填)", "设备SN(必填)", "sim卡号",  "iccid卡号", "imsi卡号"};
        int i = 0;
        for (String h : header) {
            addCell(ws, 0, i, h);//表名,行,列,header
            i++;
        }
    }
    //添加单元格内容
    public void addCell(WritableSheet ws, int row, int column, String data) throws WriteException {
        Label label = new Label(column, row, data);
        ws.addCell(label);
    }
    //添加单元格内容
    public void addCell(WritableSheet ws, int row, int column, String data, String memo) throws WriteException {
        Label label = new Label(column, row, data);
        if (!org.springframework.util.StringUtils.isEmpty(memo)) {
            WritableCellFeatures cellFeatures = new WritableCellFeatures();
            cellFeatures.setComment(memo);
            label.setCellFeatures(cellFeatures);
        }
        ws.addCell(label);
    }
}

+ 63 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/device/DmDeviceService.java

@ -0,0 +1,63 @@
package com.yihu.jw.base.service.device;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.dao.device.DeviceDao;
import com.yihu.jw.base.dao.device.DeviceDetailDao;
import com.yihu.jw.entity.care.device.Device;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
/**
 * Created by Bing on 2021/9/23.
 */
@Service
public class DmDeviceService extends BaseJpaService<Device, DeviceDao> {
    @Autowired
    private DeviceDao deviceDao;
    @Autowired
    private ObjectMapper objectMapper;
    public JSONObject saveDmDevice(String json) throws IOException {
        JSONObject result = new JSONObject();
        Device device = objectMapper.readValue(json,Device.class);
        Integer deviceType = device.getDeviceType();
        String categoryCode = device.getCategoryCode();
        String name = device.getName();
        String model = device.getCategoryCode();
        String brands = device.getBrands();
        String photo =device.getPhoto();
        String isMultiUser = device.getIsMultiUser();
        if (null==deviceType||StringUtils.isBlank(categoryCode)||StringUtils.isBlank(name)||StringUtils.isBlank(model)||
                StringUtils.isBlank(brands)||StringUtils.isBlank(photo)||StringUtils.isBlank(isMultiUser)){
            result.put(ResponseContant.resultFlag,ResponseContant.fail);
            result.put(ResponseContant.resultMsg,"数据数据错误,必填字段为空");
            return result;
        }
        //判断型号是否重复
        Device deviceTmp = deviceDao.findByModel(device.getModel());
        if (null!=deviceTmp){
            if (null==device.getId()){
                result.put(ResponseContant.resultFlag,ResponseContant.fail);
                result.put(ResponseContant.resultMsg,"设备型号已存在");
                return result;
            }else if (deviceTmp.getId()!=device.getId()){//
                result.put(ResponseContant.resultFlag,ResponseContant.fail);
                result.put(ResponseContant.resultMsg,"设备型号已存在");
                return result;
            }
        }
        deviceDao.save(device);
        result.put(ResponseContant.resultFlag,ResponseContant.success);
        result.put(ResponseContant.resultMsg,"success");
        return result;
    }
}

+ 37 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/device/WlyyPatientDeviceService.java

@ -0,0 +1,37 @@
package com.yihu.jw.base.service.device;
import com.yihu.jw.base.dao.device.PatientDeviceDao;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * Created by Bing on 2021/9/22.
 */
@Service
public class WlyyPatientDeviceService extends BaseJpaService<DevicePatientDevice, PatientDeviceDao> {
    @Autowired
    private
    PatientDeviceDao patientDeviceDao;
    public void delPatientDevice(String id){
        DevicePatientDevice patientDevice = patientDeviceDao.findOne(Long.parseLong(id));
        String deviceSn = patientDevice.getDeviceSn();
        patientDeviceDao.delete(Long.parseLong(id));
        List<DevicePatientDevice> patientDeviceList = patientDeviceDao.findByDeviceSn(deviceSn);
        String sql = "update device.wlyy_devices dd set dd.is_binding=? where dd.device_code=?";
        if (patientDeviceList.size()==0){
            jdbcTemplate.update(sql,new Object[]{0,deviceSn});
        }
        if (patientDeviceList.size()==1){
            jdbcTemplate.update(sql,new Object[]{1,deviceSn});
        }
        if (patientDeviceList.size()>1){
            jdbcTemplate.update(sql,new Object[]{2,deviceSn});
        }
    }
}

+ 188 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/device/YsDeviceService.java

@ -0,0 +1,188 @@
package com.yihu.jw.base.service.device;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.config.YsConfig;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.utils.encode.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import java.security.Security;
import java.util.concurrent.TimeUnit;
/**
 * Created by Bing on 2021/9/24.
 */
@Service
public class YsDeviceService {
    private static Logger logger = LoggerFactory.getLogger(YsDeviceService.class);
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private HttpClientUtil httpClientUtil;
    /**
     * 获取萤石设备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);
        }
    }
    @Async
    public void videoOpen(String deviceSn, HttpServletRequest request){
        try {
            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());
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 消息解密
     * @param sSrc
     * @param sKey
     * @return
     * @throws Exception
     */
    public static String messageDecrypt(String sSrc, String sKey) throws Exception {
        try {
            byte[] raw = sKey.getBytes("utf-8");
            Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec);
            byte[] encrypted1 = Base64.decode(sSrc);//先用base64解密
            byte[] original = cipher.doFinal(encrypted1);
            return new String(original, "utf-8");
        } catch (Exception ex) {
            logger.error("AES解密异常:Str"+sSrc+"\nkey:"+sKey);
            throw new Exception("解密失败");
        }
    }
}

+ 31 - 31
svr/svr-base/src/main/java/com/yihu/jw/base/service/equipment/BaseHospitalEquipmentService.java

@ -105,35 +105,35 @@ public class BaseHospitalEquipmentService extends BaseJpaService<BaseHospitalEqu
        return map;
    }
    public List<BaseHospitalEquipmentDO> synEquipment(String deviceNo){
        String str[]=deviceNo.split(",");
        for (int i=0;i<str.length;i++){
            String deviceNoString  = str[i];
            //获取第三方设备详情
            String result = juMiAiService.getEquipmentInfo(deviceNoString);
            if (result!=null&&result!=""){
                JSONObject jsonObject = JSONObject.parseObject(result);
                String code = jsonObject.getString("code");
                if (code.equalsIgnoreCase("0")){
                    JSONObject object = jsonObject.getJSONObject("data");
                    String device_no= object.getString("device_no");
                    String device_name = object.getString("device_name");
                    Integer isonline = object.getInteger("isonline");//是否在线 0离线 1在线
                    Integer state= object.getInteger("state");//状态1开启 3关闭(故障) 0已解绑
                    String riss = object.getString("riss");//信号强度 长度限制为1~10个字符
                    String device_category = object.getString("device_category");//设备分类
                    String device_category_name = object.getString("device_category_name");//设备分类名称
                    BaseHospitalEquipmentDO equipmentDO = baseHospitalEquipmentDao.findAllByCode(device_no);
                    if (equipmentDO!=null){
                        equipmentDO.setName(device_name);
                        equipmentDO.
                    }
                }
            }
        }
        return map;
    }
//    public List<BaseHospitalEquipmentDO> synEquipment(String deviceNo){
//        String str[]=deviceNo.split(",");
//        for (int i=0;i<str.length;i++){
//            String deviceNoString  = str[i];
//            //获取第三方设备详情
//            String result = juMiAiService.getEquipmentInfo(deviceNoString);
//            if (result!=null&&result!=""){
//                JSONObject jsonObject = JSONObject.parseObject(result);
//                String code = jsonObject.getString("code");
//                if (code.equalsIgnoreCase("0")){
//                    JSONObject object = jsonObject.getJSONObject("data");
//                    String device_no= object.getString("device_no");
//                    String device_name = object.getString("device_name");
//                    Integer isonline = object.getInteger("isonline");//是否在线 0离线 1在线
//                    Integer state= object.getInteger("state");//状态1开启 3关闭(故障) 0已解绑
//                    String riss = object.getString("riss");//信号强度 长度限制为1~10个字符
//                    String device_category = object.getString("device_category");//设备分类
//                    String device_category_name = object.getString("device_category_name");//设备分类名称
//                    BaseHospitalEquipmentDO equipmentDO = baseHospitalEquipmentDao.findAllByCode(device_no);
//                    if (equipmentDO!=null){
//                        equipmentDO.setName(device_name);
//                        equipmentDO.
//                    }
//
//                }
//            }
//        }
//
//
//        return map;
//    }
}

+ 2 - 2
svr/svr-base/src/main/resources/application.yml

@ -615,8 +615,8 @@ spring:
    user: admin
    password: admin
  redis:
    host: 172.26.0.13 # Redis server host.
    port: 6379  # Redis server port.
    host: 10.18.43.40 # Redis server host.
    port: 6379 # Redis server port.
    password: Kb6wKDQP1W4
fastDFS:
  fastdfs_file_url: http://10.18.43.40:80/

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

@ -18,4 +18,7 @@ public interface DeviceDao extends PagingAndSortingRepository<Device, Long> {
	@Query("select a from Device a where a.del = '1'")
	List<Device> findAll();
	@Query("select a from Device a where a.del = '1' and a.model=?1")
	Device findByModel(String model);
}

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

@ -202,116 +202,6 @@ public class PadDeviceController extends BaseController {
        }
    }
    @RequestMapping(value = "/importDeviceFromExcel", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
    @ResponseBody
    public String importFromExcel(HttpServletRequest request,@ApiParam(value = "文件", required = true)
    @RequestParam(value = "file", required = true) MultipartFile file) {
        List errorLs = new ArrayList<>();
        List correctLs = new ArrayList<>();
        Map<String, String> errorMsgMap = new HashMap<>();
        List<String> deviceCodes = new ArrayList<>();
        try {
            request.setCharacterEncoding("UTF-8");
            InputStream inputStream = file.getInputStream();
            Workbook rwb = Workbook.getWorkbook(inputStream);
            Sheet[] sheets = rwb.getSheets();
            int rows;
            int row;
            String manufacturer=null;//厂商名称
            String deviceName; //设备名称
            String deviceModel; //设备型号
            String deviceCode;  //设备SN
            String sim;  //sim卡号
            String bindingCount; //单人{"1":"0"}  多人{"1":"0", "2":"0"}
            String deviceType; //设备种类  0健康设备 1安防设备
            Sheet sheet = sheets[0];    //第一张表
            rows = sheet.getRows();
            for (int j = 1; j < rows; j++) {
                if (sheet.getRow(j).length == 0) {
                    continue;
                }
                DeviceDetail deviceDetail = new DeviceDetail();
                row = j;
                manufacturer = sheet.getCell(0, row).getContents().trim();    //0 厂商名称
                deviceName = sheet.getCell(1, row).getContents().trim();  //1 设备名称
                deviceModel = sheet.getCell(2, row).getContents().trim();   //2 设备型号
                deviceCode = sheet.getCell(3, row).getContents().trim(); //3 设备SN
                sim = sheet.getCell(4, row).getContents().trim();  //4 sim卡号
                bindingCount = sheet.getCell(5, row).getContents().trim(); //5
                deviceType = sheet.getCell(6, row).getContents().trim(); //6 设备种类
                if (StringUtils.isBlank(deviceCode)){
                    continue;
                }
                if (deviceCodes.contains(deviceCode)){
                    errorMsgMap.put(deviceCode,"设备SN码重复");
                    continue;
                }
                deviceCodes.add(deviceCode);
                if (StringUtils.isBlank(manufacturer)){
                    errorMsgMap.put(deviceCode,"厂商名称不能为空");
                    continue;
                }
                if (StringUtils.isBlank(deviceName)){
                    errorMsgMap.put(deviceCode,"设备名称不能为空");
                    continue;
                }
                if (StringUtils.isBlank(deviceModel)){
                    errorMsgMap.put(deviceCode,"设备型号不能为空");
                    continue;
                }
                if (StringUtils.isBlank(bindingCount)){
                    errorMsgMap.put(deviceCode,"设备类型不能为空");
                    continue;
                }
                if (StringUtils.isBlank(deviceType)){
                    errorMsgMap.put(deviceCode,"设备种类不能为空");
                    continue;
                }else {
                    if ("健康设备".equals(deviceType)){
                        deviceType = "1";
                    }
                    else if ("安防设备".equals(deviceType)){
                        deviceType= "0";
                    }
                    else {
                        errorMsgMap.put(deviceCode,"不支持该设备种类");
                        continue;
                    }
                }
                if (deviceDetailDao.findByDeviceCode(deviceCode).size()>0){
                    errorMsgMap.put(deviceCode,"该设备SN码已存在");
                    continue;
                }
                if (deviceDetailDao.findBySim(sim).size()>0){
                    errorMsgMap.put(deviceCode,"该sim卡号已存在");
                    continue;
                }
                deviceDetail.setManufacturer(manufacturer);
                deviceDetail.setDeviceName(deviceName);
                deviceDetail.setDeviceModel(deviceModel);
                deviceDetail.setDeviceCode(deviceCode);
                deviceDetail.setSim(sim);
                deviceDetail.setBindingCount(bindingCount);
                deviceDetail.setDeviceType(Integer.parseInt(deviceType));
                correctLs.add(deviceDetail);
            }
            deviceDetailDao.save(correctLs);
            //包装导入结果(导入成功数量、错误对象集合)
            Map<String, Object> map = new HashMap<>();
            map.put("successNum", correctLs.size());
            map.put("failedNum", rows-1 - correctLs.size() );
            map.put("errorData", JSON.toJSONString(errorMsgMap, SerializerFeature.WriteMapNullValue));
            return write(200, "操作成功", "data", map);
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
    @RequestMapping(value ="addPatientSosContacts",method = RequestMethod.POST)
    @ApiOperation(value = "设备绑定添加联系人")
    public String addPatientSosContacts(@ApiParam(name = "patient", value = "patient", defaultValue = "patient")

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

@ -258,18 +258,30 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
            DevicePatientDevice device = patientDeviceDao.findByDeviceSnAndUserType(sn, userType);
            if (device != null && !device.getId().equals(devicePatientDevice.getId()) && device.getDel() == 0) {
                //V1.0.0    监控器、报警器、燃气传感器 烟雾传感器支持一个设备绑定多个居民
                //监控器 12   报警器 7  14  15
                if ("12".equals(type) || "14".equals(type) || "15".equals(type)) {
                    if (devicePatientDevice.getUser().equals(device.getUser())) {
                        System.out.println("居民已经绑定此sn码:"+sn);
                        return -5;
                //V1.0.0    监控器、燃气传感器 烟雾传感器支持一个设备绑定多个居民
                //监控器 12     14  15
                DeviceDetail deviceDetail = deviceDetailDao.findBySn(device.getDeviceSn());
                if (null==deviceDetail){
                    return -1;
                }
                Device dmDevice = deviceDao.findByModel(deviceDetail.getDeviceModel());
                if (dmDevice!=null){
                    if ("1".equals(dmDevice.getIsMultiUser())) {//支持多人绑定设备在dm_device表定义
                        if (devicePatientDevice.getUser().equals(device.getUser())) {
                            System.out.println("居民已经绑定此sn码:"+sn);
                            return -5;
                        }
                        System.out.println("此类设备支持多绑定");
                    }
                    System.out.println("此类设备支持多绑定");
                } else {
                    else {
                        System.out.println("sn码" + sn + "已被使用!");
                        return -3;
                    }
                }
               else {
                    System.out.println("sn码" + sn + "已被使用!");
                    return -3;
                }
               }
            }
        }
        devicePatientDevice.setCzrq(new Date());
@ -310,7 +322,10 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
        String sql = "select * from wlyy_patient_device where del = 0 and device_sn = '"+deviceSn+"'";
        List<Map<String , Object>> list = jdbcTemplate.queryForList(sql);
        if (list.size() > 0){
            return patientDeviceDao.deleteByDeviceSn(deviceSn);
            Integer count = patientDeviceDao.deleteByDeviceSn(deviceSn);
            sql = "update device.wlyy_devices dd set dd.is_binding=? where dd.device_code=?";
            jdbcTemplate.update(sql,new Object[]{0,deviceSn});
            return count;
        }else {
            return 0;
        }

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

@ -48,126 +48,7 @@ public class DeviceController {
    @Autowired
    private DeviceDataPushLogUtil dataPushLogUtil;
    @RequestMapping(value = "/importDeviceFromExcel", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
    @ResponseBody
    public String importFromExcel(HttpServletRequest request,@ApiParam(value = "文件", required = true)
    @RequestParam(value = "file", required = true) MultipartFile file) {
        List errorLs = new ArrayList<>();
        List correctLs = new ArrayList<>();
        Map<String, String> errorMsgMap = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<String> deviceCodes = new ArrayList<>();
        try {
            request.setCharacterEncoding("UTF-8");
            InputStream inputStream = file.getInputStream();
            Workbook rwb = Workbook.getWorkbook(inputStream);
            Sheet[] sheets = rwb.getSheets();
            int rows;
            int row;
            String manufacturer=null;//厂商名称
            String deviceName; //设备名称
            String deviceModel; //设备型号
            String deviceCode;  //设备SN
            String sim;  //sim卡号
            String bindingCount; //单人{"1":"0"}  多人{"1":"0", "2":"0"}
            String deviceType; //设备种类  0健康设备 1安防设备
            Sheet sheet = sheets[0];    //第一张表
            rows = sheet.getRows();
            for (int j = 1; j < rows; j++) {
                if (sheet.getRow(j).length == 0) {
                    continue;
                }
                DeviceDetail deviceDetail = new DeviceDetail();
                row = j;
                manufacturer = sheet.getCell(0, row).getContents().trim();    //0 厂商名称
                deviceName = sheet.getCell(1, row).getContents().trim();  //1 设备名称
                deviceModel = sheet.getCell(2, row).getContents().trim();   //2 设备型号
                deviceCode = sheet.getCell(3, row).getContents().trim(); //3 设备SN
                sim = sheet.getCell(4, row).getContents().trim();  //4 sim卡号
                bindingCount = sheet.getCell(5, row).getContents().trim(); //5
                deviceType = sheet.getCell(6, row).getContents().trim(); //6 设备种类
                if (StringUtils.isBlank(deviceCode)){
                    continue;
                }
                if (deviceCodes.contains(deviceCode)){
                    errorMsgMap.put(deviceCode,"设备SN码重复");
                    continue;
                }
                deviceCodes.add(deviceCode);
                if (StringUtils.isBlank(manufacturer)){
                    errorMsgMap.put(deviceCode,"厂商名称不能为空");
                    continue;
                }
                if (StringUtils.isBlank(deviceName)){
                    errorMsgMap.put(deviceCode,"设备名称不能为空");
                    continue;
                }
                if (StringUtils.isBlank(deviceModel)){
                    errorMsgMap.put(deviceCode,"设备型号不能为空");
                    continue;
                }
                if (StringUtils.isBlank(bindingCount)){
                    errorMsgMap.put(deviceCode,"设备类型不能为空");
                    continue;
                }
                if (StringUtils.isBlank(deviceType)){
                    errorMsgMap.put(deviceCode,"设备种类不能为空");
                    continue;
                }else {
                    if ("健康设备".equals(deviceType)){
                        deviceType = "0";
                    }
                    else if ("安防设备".equals(deviceType)){
                        deviceType= "1";
                    }
                    else {
                        errorMsgMap.put(deviceCode,"不支持该设备种类");
                        continue;
                    }
                }
                if (deviceDetailDao.findByDeviceCode(deviceCode).size()>0){
                    errorMsgMap.put(deviceCode,"该设备SN码已存在");
                    continue;
                }
                if (StringUtils.isNotBlank(sim) && deviceDetailDao.findBySim(sim).size()>0){
                    errorMsgMap.put(deviceCode,"该sim卡号已存在");
                    continue;
                }
                if ("CS-C6Wi-3E4WFR".equals(deviceModel)){//监控器 直播地址开通->关闭视频加密 后续暂时先于APP操作
                    ysDeviceService.videoOpen(deviceCode,null);
                }
                deviceDetail.setApplyDate(sdf.format(new Date()));
                deviceDetail.setManufacturer(manufacturer);
                deviceDetail.setDeviceName(deviceName);
                deviceDetail.setDeviceModel(deviceModel);
                deviceDetail.setDeviceCode(deviceCode);
                deviceDetail.setSim(sim);
                if (bindingCount.equals("多人设备")) {
                    bindingCount = "{\"1\":\"0\",\"2\":\"0\"}";
                } else {
                    bindingCount = "{\"1\":\"0\"}";
                }
                deviceDetail.setBindingCount(bindingCount);
                deviceDetail.setDeviceType(Integer.parseInt(deviceType));
                correctLs.add(deviceDetail);
            }
            deviceDetailDao.save(correctLs);
            //包装导入结果(导入成功数量、错误对象集合)
            Map<String, Object> map = new HashMap<>();
            map.put("successNum", correctLs.size());
            map.put("failedNum", rows-1 - correctLs.size() );
            map.put("errorData", JSON.toJSONString(errorMsgMap, SerializerFeature.WriteMapNullValue));
            System.out.println(map);
            return write(200,JSON.toJSONString(map,SerializerFeature.WriteMapNullValue));
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "操作失败!");
        }
    }
    //设备移至导入svr_base
    @GetMapping("test")
    public String test(){

+ 70 - 17
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/OnenetService.java

@ -99,7 +99,12 @@ public class OnenetService {
            Integer type = msg.getInteger("type");
            String value = msg.getString("value");
            if("1".equals(onenetDevice.getDeviceType())){
                wlyDateDel(categoryCode,msg);
                if ("14".equals(categoryCode)){//燃气
                    wlyDateDelGas(categoryCode,msg);
                }
                if ("15".equals(categoryCode)){//烟雾设备
                    wlyDateDelSmoke(msg);
                }
            }else if("2".equals(onenetDevice.getDeviceType())){
                //海康设备
                if("14".equals(onenetDevice.getCategoryCode())){
@ -362,36 +367,84 @@ public class OnenetService {
    }
    /**
     * 未来鹰设备数据处理
     * @param categoryCode
     * 未来鹰设备烟雾数据处理
     * @param msg
     */
    public void wlyDateDel(String categoryCode,JSONObject msg){
    public void wlyDateDelSmoke(JSONObject msg){
        String dsId = msg.getString("ds_id");
        String msgId = dsId.split("_")[2];
        String value = msg.getString("value");
        String deviceSn = msg.getString("imei");
        if ("14".equals(categoryCode)){//燃气设备
        }else if ("15".equals(categoryCode)){//烟雾设备
            if ("5504".equals(msgId)){//烟雾浓度消息 大于0 触发报警
                Integer gasValue = Integer.parseInt(value);
                if (gasValue>0){
        if ("5504".equals(msgId)){//烟雾浓度消息 大于0 触发报警
            Integer gasValue = Integer.parseInt(value);
            if (gasValue>0){
                String sql = "select count(*) from base_device_health_index where device_sn = '"+deviceSn+"'" +
                        " and value>0 and create_time>='"+DateUtil.getNextMinute(-60)+"' ";
                Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
                if(count==0){
                    JSONObject tmp = new JSONObject();
                    tmp.put("smoke",value);
                    orderUtil.createSecurityOrder(deviceSn,null,new JSONObject(),null,7,"10","preventFire",JSON.toJSONString(tmp, SerializerFeature.WriteMapNullValue));
                }
                DeviceHealthIndex index = new DeviceHealthIndex();
                index.setDeviceSn(deviceSn);
            }
            DeviceHealthIndex index = new DeviceHealthIndex();
            index.setDeviceSn(deviceSn);
            index.setUnit("%");
            index.setDeviceType("2");
            index.setValue(value);
            index.setRecordTime(DateUtil.getStringDate());
            deviceHealthIndexDao.save(index);
        }
        if ("5503".equals(msgId)){//各消息类型
            if ("1".equals(value)) {//设备烟雾报警
                String sql = "select count(*) from base_device_health_index where device_sn = '"+deviceSn+"'" +
                        " and value>0 and create_time>='"+DateUtil.getNextMinute(-60)+"' ";
                Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
                if(count==0){
                    JSONObject tmp = new JSONObject();
                    tmp.put("smoke","100");
                    orderUtil.createSecurityOrder(deviceSn,null,new JSONObject(),null,7,"10","preventFire",JSON.toJSONString(tmp, SerializerFeature.WriteMapNullValue));
                }
            }
        }
    }
    public void wlyDateDelGas(String categoryCode,JSONObject msg){
        String deviceSn = msg.getString("imei");
        Integer type = msg.getInteger("type");
        String value = msg.getString("value");
        String order = value.substring(10,14);
        if("1401".equals(order)){
            //自定义命令数据更新(心跳/设备状态上报)
            String gas_Level = value.substring(22,24);
            Integer gas = Integer.parseInt(gas_Level, 16);
            if(gas>0){
                //气体浓度大于0触发报警
                String sql = "select count(*) from base_device_health_index where device_sn = '"+deviceSn+"'" +
                        " and value>0 and create_time>='"+DateUtil.getNextMinute(-60)+"' ";
                Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
                if(count==0){
                    logger.info("气体浓度大于0触发报警,deviceSn:{}",deviceSn);
                    //1小时内不重复发起
                    JSONObject tmp = new JSONObject();
                    tmp.put("gas",gas);
                    orderUtil.createSecurityOrder(deviceSn,null,new JSONObject(),null,6,"11","preventGasLeakage",JSON.toJSONString(tmp, SerializerFeature.WriteMapNullValue));
                }
            }
            DeviceHealthIndex index = new DeviceHealthIndex();
            index.setDeviceSn(deviceSn);
            if("14".equals(categoryCode)){
                index.setUnit("%LEL");
                index.setDeviceType("1");
            }else if("15".equals(categoryCode)){
                index.setUnit("%");
                index.setDeviceType("2");
                index.setValue(value);
                index.setRecordTime(DateUtil.getStringDate());
                deviceHealthIndexDao.save(index);
            }
            if ("5503".equals(msgId)){//各消息类型
            }
            index.setValue(gas+"");
            index.setRecordTime(DateUtil.getStringDate());
            deviceHealthIndexDao.save(index);
        }
    }
}

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

@ -42,7 +42,7 @@ public class PatientSosContactsJob implements Job {
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("PATIENT_SOS_CONTACTS_JOB start");
        String sql = " select pd.device_sn,pd.category_code,wd.sim,sc.* from  wlyy_patient_device pd inner join wlyy_devices wd " +
        String sql = " select pd.device_sn,pd.category_code,wd.iccid as sim,sc.* from  wlyy_patient_device pd inner join wlyy_devices wd " +
                " on pd.device_sn = wd.device_code and pd.del=0 " +
                "INNER JOIN base_patient_sos_contacts sc on sc.patient = pd.user and sc.del=1 " +
                "where  sc.success_flag=0 and pd.category_code in('7','4','16')  group by wd.device_code ";
@ -76,6 +76,7 @@ public class PatientSosContactsJob implements Job {
                        }else {
                            sosContactsDO.setSuccessFlag(-1);
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+-1+"}");
                            sosContactsDO.setErrorInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+response.getString("message")+"}");
                        }
                    }
                    //设备修改
@ -91,6 +92,7 @@ public class PatientSosContactsJob implements Job {
                        }else {
                            sosContactsDO.setSuccessFlag(-1);
                            sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+-1+"}");
                            sosContactsDO.setErrorInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+response2.getString("message")+"}");
                        }
                    }else if ("16".equals(category_code)){
                        sql =" select sos_phone from base_patient_sos_contacts where patient='"+patient+"' and del=1 order by phone_seqid asc ";

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

@ -134,6 +134,7 @@ public class NetworkCardService {
        }
        JSONObject result = new  JSONObject();
        result.put("status",-1);
        result.put("message",responseBody.getString("message"));
        return result;
    }