Procházet zdrojové kódy

Merge branch 'dev' of liubing/wlyy2.0 into dev

liubing před 3 roky
rodič
revize
ad754a7b1c
16 změnil soubory, kde provedl 236 přidání a 391 odebrání
  1. 14 0
      common/common-entity/sql记录
  2. 89 0
      common/common-entity/src/main/java/com/yihu/jw/entity/care/device/DeviceDataPushLog.java
  3. 1 4
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/PatientEndpoint.java
  4. 20 8
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/patient/CarePatientService.java
  5. 12 0
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/dao/device/DeviceDataPushLogDao.java
  6. 15 11
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/DeviceController.java
  7. 5 2
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/DeviceUploadController.java
  8. 1 0
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/HvDeviceController.java
  9. 0 84
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/SocketClientTest.java
  10. 0 103
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/SocketServerTest.java
  11. 0 151
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/WebSocketServer.java
  12. 0 25
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/YunXinIotController.java
  13. 9 2
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceUploadService.java
  14. 10 1
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/HvDeviceService.java
  15. 8 0
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/YsDeviceService.java
  16. 52 0
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/util/DeviceDataPushLogUtil.java

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

@ -1417,3 +1417,17 @@ CREATE TABLE `wlyy_patient_safe_area` (
  `success_flag` tinyint(4) DEFAULT NULL COMMENT '是否同步至设备 -1失败 1成功',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='患者设备安全区域';
--2021-09-02
CREATE TABLE `device_data_push_log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `patient` varchar(50) DEFAULT NULL,
  `patient_name` varchar(50) DEFAULT NULL,
  `device_sn` varchar(50) DEFAULT NULL,
  `device_name` varchar(50) DEFAULT NULL,
  `device_category` varchar(50) DEFAULT NULL,
  `api_name` varchar(50) DEFAULT NULL,
  `data` varchar(1000) DEFAULT NULL,
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=449 DEFAULT CHARSET=utf8mb4 COMMENT='设备项目推送数据日志';

+ 89 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/DeviceDataPushLog.java

@ -0,0 +1,89 @@
package com.yihu.jw.entity.care.device;
import com.yihu.jw.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Bing on 2021/9/2.
 */
@Entity
@Table(name="device_data_push_log")
public class DeviceDataPushLog extends IdEntity {
    private String patient;
    private String patientName;
    private String deviceSn;
    private String deviceName;
    private String deviceCategory;
    private String apiName;
    private String data;//上传数据
    private Date createTime;
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getPatientName() {
        return patientName;
    }
    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }
    public String getDeviceSn() {
        return deviceSn;
    }
    public void setDeviceSn(String deviceSn) {
        this.deviceSn = deviceSn;
    }
    public String getDeviceName() {
        return deviceName;
    }
    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }
    public String getDeviceCategory() {
        return deviceCategory;
    }
    public void setDeviceCategory(String deviceCategory) {
        this.deviceCategory = deviceCategory;
    }
    public String getApiName() {
        return apiName;
    }
    public void setApiName(String apiName) {
        this.apiName = apiName;
    }
    public String getData() {
        return data;
    }
    public void setData(String data) {
        this.data = data;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}

+ 1 - 4
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/PatientEndpoint.java

@ -125,10 +125,7 @@ public class PatientEndpoint extends EnvelopRestEndpoint {
            @RequestParam(value = "isCapacity", required = false) String isCapacity) {
        try{
            String agent = getAgentUID();
            if(StringUtils.isNotBlank(agent)){
                id = agent;
            }
            return success("获取成功",patientService.findPatientById(id,isCapacity));
            return success("获取成功",patientService.findPatientById(id,agent,isCapacity));
        }catch (Exception e){
            return failedException2(e);
        }

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

@ -129,24 +129,36 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
    /**
     * 居民id
     * @param patientId
     * @param agent 代理人id
     * @param patientId 查看居民id
     * @return
     */
    public JSONObject findPatientById(String patientId,String isCapacity) throws Exception{
    public JSONObject findPatientById(String patientId,String agent,String isCapacity) throws Exception{
        JSONObject res = new JSONObject();
        BasePatientDO patientDO = patientDao.findById(patientId);
        if(patientDO.getArchiveType()!=null&&patientDO.getArchiveType()==3){
        if(StringUtils.isNotBlank(agent)||(patientDO.getArchiveType()!=null&&patientDO.getArchiveType()==3)){
            if (StringUtils.isNotBlank(agent)){
                patientDO = patientDao.findById(agent);
            }
            //老人亲属
            String sql = "SELECT p.* from base_patient p, base_patient_family_member m " +
                    "WHERE p.id = m.family_member  and m.patient = '"+patientId+"' and p.del = '1' " +
                    "ORDER BY p.login_date desc LIMIT 1";
                    "WHERE p.id = m.family_member  and m.patient = '"+patientDO.getId()+"' and p.del = '1' " ;
            if(StringUtils.isNotBlank(agent)&&!patientId.equals(agent)){
                sql+=" and p.id='"+patientId+"' ";
            }
            sql+= " ORDER BY p.login_date desc ";
            List<BasePatientDO> patientDOs = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BasePatientDO.class));
            res.put("agentPatient",patientDO);
            patientDO = patientDOs.get(0);
            patientId = patientDO.getId();
            if (patientDOs.size()>0){
                res.put("agentPatient",patientDO);
                patientDO = patientDOs.get(0);
                patientId = patientDO.getId();
            }else {
                res.put("agentPatient",null);
            }
        }else{
            res.put("agentPatient",null);
        }
        patientDO = patientDao.findById(patientId);
        if (patientDO.getArchiveStatus()!=null){
            patientDO.setArchiveStatusName(dictService.fingByNameAndCode(ConstantUtil.DICT_ARCHIVESTATUS,String.valueOf(patientDO.getArchiveStatus())));
        }

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

@ -0,0 +1,12 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.DeviceDataPushLog;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Bing on 2021/9/2.
 */
public interface DeviceDataPushLogDao extends PagingAndSortingRepository<DeviceDataPushLog,Long>,
        JpaSpecificationExecutor<DeviceDataPushLog> {
}

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

@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.care.dao.device.DeviceDetailDao;
import com.yihu.jw.care.service.DeviceService;
import com.yihu.jw.care.service.YsDeviceService;
import com.yihu.jw.care.util.DeviceDataPushLogUtil;
import com.yihu.jw.entity.care.device.DeviceDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -44,6 +45,8 @@ public class DeviceController {
    private DeviceDetailDao deviceDetailDao;
    @Autowired
    private YsDeviceService ysDeviceService;
    @Autowired
    private DeviceDataPushLogUtil dataPushLogUtil;
    @RequestMapping(value = "/importDeviceFromExcel", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
    @ResponseBody
@ -182,7 +185,7 @@ public class DeviceController {
            String paraString = JSON.toJSONString(request.getParameterMap());
            deviceService.aqgsos(imei, label_mac, time_begin,request);
            long endTime=System.currentTimeMillis();
            dataPushLogUtil.savePushLog(imei,paraString,"爱牵挂SOS数据接收");
            logger.info("爱牵挂设备sos数据接收,请求参数:\n"+paraString+"\n"+(endTime-startTime)+"ms");
            return success();
        } catch (Exception e) {
@ -206,7 +209,7 @@ public class DeviceController {
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("爱牵挂设备开关机数据接收,请求参数:\n"+paraString);
            dataPushLogUtil.savePushLog(imei,paraString,"爱牵挂开关机数据接收");
            deviceService.aqgSwitch(imei, time_begin, remaining_power, type,request);
            return success();
        } catch (Exception e) {
@ -230,6 +233,7 @@ public class DeviceController {
            String paraString = JSON.toJSONString(request.getParameterMap());
            deviceService.pushdata(type, deviceid, communityid, request);
            long endTime=System.currentTimeMillis();
            dataPushLogUtil.savePushLog(deviceid,paraString,"爱牵挂消息通知接收");
            logger.info("爱牵挂设备消息通知数据接收,请求参数:\n"+paraString+"\n"+(endTime-startTime)+"ms");
            return success();
        } catch (Exception e) {
@ -264,7 +268,7 @@ public class DeviceController {
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("爱牵挂位置接收,请求参数:\n"+paraString);
            dataPushLogUtil.savePushLog(imei,paraString,"爱牵挂位置数据接收");
            deviceService.byLocation(imei,time_begin,is_reply,is_track,city,address,lon,lat,type);
            return success();
        } catch (Exception e) {
@ -291,7 +295,7 @@ public class DeviceController {
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("爱牵挂心率数据接收,请求参数: \n"+paraString);
            dataPushLogUtil.savePushLog(imei,paraString,"爱牵挂心率数据接收");
            deviceService.byHeartRate(imei,time_begin,heartrate,theshold_heartrate_h,theshold_heartrate_l);
            return success();
        } catch (Exception e) {
@ -319,7 +323,7 @@ public class DeviceController {
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("爱牵挂血压数据,接收请求参数:\n"+paraString);
            dataPushLogUtil.savePushLog(imei,paraString,"爱牵挂血压数据接收");
            deviceService.byBloodPressure(imei,time_begin,dbp,dbp_l,sbp,sbp_h);
            return success();
        } catch (Exception e) {
@ -349,7 +353,7 @@ public class DeviceController {
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("爱牵挂跌倒数据接收,请求参数: \n"+paraString);
            dataPushLogUtil.savePushLog(imei,paraString,"爱牵挂跌倒数据接收");
            deviceService.byFall(imei,time_begin,city,address,lon,lat,type);
            return success();
        } catch (Exception e) {
@ -371,7 +375,7 @@ public class DeviceController {
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("爱牵挂步数接收,请求参数:\n"+paraString);
            dataPushLogUtil.savePushLog(imei,paraString,"爱牵挂设备步数数据接收");
            deviceService.bySteps(imei,time_begin,value);
            return success();
        } catch (Exception e) {
@ -405,7 +409,7 @@ public class DeviceController {
            deviceService.bySleep(device,time_begin,heartrate,breath,bed_status,turn_over,is_warn);
            long endTime=System.currentTimeMillis();
            logger.info("爱牵挂-睡眠带接收,请求参数:"+paraString+"\n"+(endTime-startTime)+"ms");
            dataPushLogUtil.savePushLog(device,paraString,"睡眠带数据接收");
            return success();
        } catch (Exception e) {
            e.printStackTrace();
@ -459,8 +463,8 @@ public class DeviceController {
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("爱牵挂-睡眠带睡眠报考,请求参数:"+paraString);
            logger.info("爱牵挂-睡眠带睡眠报告,请求参数:"+paraString);
            dataPushLogUtil.savePushLog(device,paraString,"睡眠带报告数据接收");
            deviceService.bySleepReport(device,date,fallasleep,sleepTime,restTime,awakeTime,lightTime,remTime,deepTime,bucket,
                    avghr,avgbr,awakePer,remPer,lightPer,efficiency,score);
            return success();
@ -485,7 +489,7 @@ public class DeviceController {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("爱牵挂-睡眠带wifi在线状态接收:"+paraString);
            dataPushLogUtil.savePushLog(device,paraString,"睡眠带在线状态数据接收");
            deviceService.byOnlineStatus(device,onlinestatu,time_begin);
            return success();
        } catch (Exception e) {

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

@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/**
 * Created by Bing on 2021/7/7.
 */
@ -37,12 +39,12 @@ public class DeviceUploadController {
                    "{\"button\":\"1\",\"data\":\"1.81\",\"deviceSn\":\"16C000337\",\"deviceType\":2,\"id\":2377," +
                            "\"manufacturerCode\":\"threeNod\",\"manufacturerName\":\"三诺\",\"sendTime\":\"2017-03-13 13:47:42\"," +
                            "\"state\":0,\"unit\":\"mmol/L\",\"uploadTime\":\"2017-03-13 13:46:59\"}")
            @RequestParam(value = "data", required = true)  String data)
            @RequestParam(value = "data", required = true)  String data, HttpServletRequest request)
    {
        try{
            logger.info("typeId="+typeId+";data="+data);
            return deviceUploadService.uploadDevicesData(data);
            return deviceUploadService.uploadDevicesData(data,request);
        }
        catch (Exception ex)
        {
@ -59,6 +61,7 @@ public class DeviceUploadController {
        try{
            logger.info("message="+message);
            return deviceUploadService.caneUpload(message);
        }
        catch (Exception ex)

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

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.care.service.HvDeviceService;
import com.yihu.jw.care.util.DeviceDataPushLogUtil;
import com.yihu.jw.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

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

@ -1,84 +0,0 @@
//package com.yihu.jw.care.endpoint;
//
//import java.io.BufferedReader;
//import java.io.BufferedWriter;
//import java.io.InputStreamReader;
//import java.io.OutputStreamWriter;
//import java.net.Socket;
//
///***
// * @ClassName: SocketTest
// * @Description: scoket客户端
// * @Auther: shi kejing
// * @Date: 2021/8/20 11:00
// */
//public class SocketClientTest {
//
//    public static void main(String[] args) {
//        SocketClientTest client=new SocketClientTest();
//        client.startAction();
//    }
//
//    void readSocketInfo(BufferedReader reader){
//        new Thread(new MyRuns(reader)).start();
//    }
//
//    class MyRuns implements Runnable{
//
//        BufferedReader reader;
//
//        public MyRuns(BufferedReader reader) {
//            super();
//            this.reader = reader;
//        }
//
//        public void run() {
//            try {
//                String lineString="";
//                while( (lineString = reader.readLine())!=null ){
//                    System.out.println(lineString);
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//
//    }
//
//    public void startAction(){
//        Socket socket=null;
//        BufferedReader reader=null;
//        BufferedWriter writer=null;
//        BufferedReader reader2=null;
//        try {
//            socket=new Socket("172.26.0.107", 9112);
//            reader = new BufferedReader(new InputStreamReader(System.in));
//            reader2=new BufferedReader(new InputStreamReader(socket.getInputStream()));
//            writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
//            readSocketInfo(reader2);
//            String lineString="";
//            while(!(lineString=reader.readLine()).equals("exit")){
//                writer.write(lineString+"\n");
//                writer.flush();
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                if (reader!=null) {
//                    reader.close();
//                }
//                if (writer!=null) {
//                    writer.close();
//                }
//                if (socket!=null) {
//                    socket.close();
//                }
//            } catch (Exception e2) {
//                e2.printStackTrace();
//            }
//        }
//    }
//
//
//}

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

@ -1,103 +0,0 @@
//package com.yihu.jw.care.endpoint;
//
//import com.tencentcloudapi.oceanus.v20190422.models.SystemResourceItem;
//import com.yihu.jw.entity.util.SystemConfEntity;
//import jdk.internal.cmm.SystemResourcePressureImpl;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.core.convert.Property;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import java.io.BufferedReader;
//import java.io.BufferedWriter;
//import java.io.InputStreamReader;
//import java.io.OutputStreamWriter;
//import java.net.ServerSocket;
//import java.net.Socket;
//
///***
// * @ClassName: SocketServerTest
// * @Description: socket服务器端
// * @Auther: shi kejing
// * @Date: 2021/8/20 11:04
// */
//@Component
//public class SocketServerTest {
//    private final static Logger logger = LoggerFactory.getLogger(SocketServerTest.class);
//
//    public static void main(String[] args) {
//        SocketServerTest st = new SocketServerTest();
//        st.startAction();
//    }
//
////    @PostConstruct
//    public void startAction(){
//        logger.info("服务端服务启动监听:");
//        ServerSocket serverSocket=null;
//        try {
//            serverSocket=new ServerSocket(9112);  //端口号
//            logger.info("服务端服务启动监听:");
//            //通过死循环开启长连接,开启线程去处理消息
//            while(true){
//                Socket socket=serverSocket.accept();
//                new Thread(new SocketServerTest.MyRuns(socket)).start();
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                if (serverSocket!=null) {
//                    serverSocket.close();
//                }
//            } catch (Exception e2) {
//                e2.printStackTrace();
//            }
//        }
//    }
//
//    class MyRuns implements Runnable{
//
//        Socket socket;
//        BufferedReader reader;
//        BufferedWriter writer;
//
//        public MyRuns(Socket socket) {
//            super();
//            this.socket = socket;
//        }
//
//        public void run() {
//            try {
//                reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));//读取客户端消息
//                writer=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));//向客户端写消息
//                String lineString=""; //服务器接受到的消息
//
//                while(!(lineString=reader.readLine()).equals("bye")){
//                    logger.info("收到来自客户端的发送的消息是:" + lineString);
//                    writer.write("服务器返回:"+lineString+"\n");
//                    writer.flush();
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            } finally {
//                try {
//                    if (reader!=null) {
//                        reader.close();
//                    }
//                    if (writer!=null) {
//                        writer.close();
//                    }
//                    if (socket!=null) {
//                        socket.close();
//                    }
//                } catch (Exception e2) {
//                    e2.printStackTrace();
//                }
//            }
//        }
//
//    }
//
//
//}

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

@ -1,151 +0,0 @@
//package com.yihu.jw.care.endpoint;
//
//import com.alibaba.fastjson.JSONObject;
//import org.apache.commons.lang.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//
//
//import javax.websocket.*;
//import javax.websocket.server.PathParam;
//import javax.websocket.server.ServerEndpoint;
//import java.io.IOException;
//import java.util.concurrent.ConcurrentHashMap;
//import com.alibaba.fastjson.JSON;
//
///***
// * @ClassName: WebSocketServer
// * @Description:
// * @Auther: shi kejing
// * @Date: 2021/8/20 14:20
// */
//@ServerEndpoint("/")
//@Component
//public class WebSocketServer {
//
//
//    private final static Logger log = LoggerFactory.getLogger(WebSocketServer.class);
//    /**静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。*/
//    private static int onlineCount = 0;
//    /**concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。*/
//    private static ConcurrentHashMap<String,WebSocketServer> webSocketMap = new ConcurrentHashMap<>();
//    /**与某个客户端的连接会话,需要通过它来给客户端发送数据*/
//    private Session session;
//    /**接收userId*/
//    private String userId="ijk";
//
//    /**
//     * 连接建立成功调用的方法*/
//    @OnOpen
//    public void onOpen(Session session,@PathParam("userId") String userId) {
//        userId="ijk";
//        log.info("userId = "+userId);
//        this.session = session;
//        this.userId=userId;
//        if(webSocketMap.containsKey(userId)){
//            webSocketMap.remove(userId);
//            webSocketMap.put(userId,this);
//            //加入set中
//        }else{
//            webSocketMap.put(userId,this);
//            //加入set中
//            addOnlineCount();
//            //在线数加1
//        }
//
//        log.info("用户连接:"+userId+",当前在线人数为:" + getOnlineCount());
//
//        try {
//            sendMessage("连接成功");
//        } catch (IOException e) {
//            log.error("用户:"+userId+",网络异常!!!!!!");
//        }
//    }
//
//    /**
//     * 连接关闭调用的方法
//     */
//    @OnClose
//    public void onClose() {
//        if(webSocketMap.containsKey(userId)){
//            webSocketMap.remove(userId);
//            //从set中删除
//            subOnlineCount();
//        }
//        log.info("用户退出:"+userId+",当前在线人数为:" + getOnlineCount());
//    }
//
//    /**
//     * 收到客户端消息后调用的方法
//     *
//     * @param message 客户端发送过来的消息*/
//    @OnMessage
//    public void onMessage(String message, Session session) {
//        log.info("用户消息:"+userId+",报文:"+message);
//        //可以群发消息
//        //消息保存到数据库、redis
//        if(StringUtils.isNotBlank(message)){
//            try {
//                //解析发送的报文
//                JSONObject jsonObject = JSON.parseObject(message);
//                //追加发送人(防止串改)
//                jsonObject.put("fromUserId",this.userId);
//                String toUserId=jsonObject.getString("toUserId");
//                //传送给对应toUserId用户的websocket
//                if(StringUtils.isNotBlank(toUserId)&&webSocketMap.containsKey(toUserId)){
//                    webSocketMap.get(toUserId).sendMessage(jsonObject.toJSONString());
//                }else{
//                    log.error("请求的userId:"+toUserId+"不在该服务器上");
//                    //否则不在这个服务器上,发送到mysql或者redis
//                }
//            }catch (Exception e){
//                e.printStackTrace();
//            }
//        }
//    }
//
//    /**
//     *
//     * @param session
//     * @param error
//     */
//    @OnError
//    public void onError(Session session, Throwable error) {
//        log.error("用户错误:"+this.userId+",原因:"+error.getMessage());
//        error.printStackTrace();
//    }
//    /**
//     * 实现服务器主动推送
//     */
//    public void sendMessage(String message) throws IOException {
//        this.session.getBasicRemote().sendText(message);
//    }
//
//
//    /**
//     * 发送自定义消息
//     * */
//    public static void sendInfo(String message,@PathParam("userId") String userId) throws IOException {
//        log.info("发送消息到:"+userId+",报文:"+message);
//        if(StringUtils.isNotBlank(userId)&&webSocketMap.containsKey(userId)){
//            webSocketMap.get(userId).sendMessage(message);
//        }else{
//            log.error("用户"+userId+",不在线!");
//        }
//    }
//
//    public static synchronized int getOnlineCount() {
//        return onlineCount;
//    }
//
//    public static synchronized void addOnlineCount() {
//        WebSocketServer.onlineCount++;
//    }
//
//    public static synchronized void subOnlineCount() {
//        WebSocketServer.onlineCount--;
//    }
//
//
//}

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

@ -1,25 +0,0 @@
package com.yihu.jw.care.endpoint;
import com.yihu.jw.care.common.BaseController;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
/***
 * @ClassName: YunXinIotController
 * @Description: 云芯 智能拐杖
 * @Auther: shi kejing
 * @Date: 2021/8/20 10:06
 */
@RestController
@RequestMapping(value = "yunxin/device")
@Api(value = "云芯 智能拐杖", description = "云芯 智能拐杖", tags = {"云芯 智能拐杖"})
public class YunXinIotController extends BaseController {
    private final static Logger LOGGER = LoggerFactory.getLogger(YunXinIotController.class);
}

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

@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.care.dao.device.*;
import com.yihu.jw.care.endpoint.Result;
import com.yihu.jw.care.util.CountDistance;
import com.yihu.jw.care.util.DeviceDataPushLogUtil;
import com.yihu.jw.care.util.SecurityOrderUtil;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.*;
@ -27,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@ -72,8 +74,10 @@ public class DeviceUploadService {
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PatientSafeAreaDao safeAreaDao;
    @Autowired
    private DeviceDataPushLogUtil dataPushLogUtil;
    public Result uploadDevicesData(String dataJson)throws Exception {
    public Result uploadDevicesData(String dataJson, HttpServletRequest request)throws Exception {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            Map<String, Object> map = objectMapper.readValue(dataJson, Map.class);
@ -88,6 +92,8 @@ public class DeviceUploadService {
            String sendTime = map.get("sendTime").toString();//发送时间yyyy-MM-dd HH:mm:ss
            String userType = map.get("button").toString();//按键号 即 userType
            String measurementType=null==map.get("measurementType")?"":map.get("measurementType").toString(); //单个设备的测量类型,deviceType=4智能手表:1心率,2血压
            String paraString = JSON.toJSONString(request.getParameterMap());
            dataPushLogUtil.savePushLog(deviceSn,paraString,"体征数据接收");
            JSONObject json = new JSONObject();
            json.put("deviceSn", deviceSn);
@ -462,6 +468,7 @@ public class DeviceUploadService {
                String inst = instruct[i];
                String tmp[] = inst.split("\\*");
                String sn = tmp[1];
                dataPushLogUtil.savePushLog(sn,"{\"message\":\""+instructions+"\"}","拐杖数据接收");
                String order = tmp[3];
                if(order.contains(",")){
                    String tmp1[] = order.split(",");
@ -548,7 +555,7 @@ public class DeviceUploadService {
                            String sql=" SELECT * FROM base_yxdevice_index WHERE sn = '"+sn+"' " +
                                    "AND create_time LIKE '"+DateUtil.getStringDateShort()+"%' AND lon != 0 AND lat != 0 ORDER BY create_time DESC  ";
                            List<Map<String,Object>> result = jdbcTemplate.queryForList(sql);
                            if (result.size()>0);{
                            if (result.size()>0){
                                dulat = Double.parseDouble(result.get(0).get("lat").toString());
                                dulon = Double.parseDouble(result.get(0).get("lon").toString());

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

@ -9,11 +9,14 @@ import com.yihu.jw.care.dao.device.DeviceHealthIndexDao;
import com.yihu.jw.care.dao.device.HvDeviceRecordDao;
import com.yihu.jw.care.dao.device.HvDeviceSosLogDao;
import com.yihu.jw.care.util.ArtemisPostTest;
import com.yihu.jw.care.util.DeviceDataPushLogUtil;
import com.yihu.jw.care.util.SecurityOrderUtil;
import com.yihu.jw.entity.care.device.DeviceDetail;
import com.yihu.jw.entity.care.device.DeviceHealthIndex;
import com.yihu.jw.entity.care.device.HvDeviceRecord;
import com.yihu.jw.entity.care.device.HvDeviceSosLog;
import com.yihu.jw.utils.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -44,6 +47,8 @@ public class HvDeviceService {
    private HvDeviceRecordDao hvdeviceRecordDao;
    @Autowired
    private DeviceDetailDao deviceDetailDao;
    @Autowired
    private DeviceDataPushLogUtil dataPushLogUtil;
    /**
     * 消息通知接收
@ -110,6 +115,7 @@ public class HvDeviceService {
                JSONObject tmp = new JSONObject();
                tmp.put("gas",monitorValue);
                orderUtil.createSecurityOrder(resourceSerial,null,new JSONObject(),null,6,"11","preventGasLeakage",JSON.toJSONString(tmp, SerializerFeature.WriteMapNullValue));
                dataPushLogUtil.savePushLog(resourceSerial,jsonObject.toJSONString(SerializerFeature.WriteMapNullValue),"可燃气体探测器报警信息接收");
            }
            if("600002".equals(deviceType)){
@ -117,9 +123,9 @@ public class HvDeviceService {
                JSONObject tmp = new JSONObject();
                tmp.put("smoke",monitorValue);
                orderUtil.createSecurityOrder(resourceSerial,null,new JSONObject(),null,7,"10","preventFire",JSON.toJSONString(tmp, SerializerFeature.WriteMapNullValue));
                dataPushLogUtil.savePushLog(resourceSerial,jsonObject.toJSONString(SerializerFeature.WriteMapNullValue),"烟感探测器报警信息接收");
            }
        }
        if(list.size()>0){
            hvdeviceSosLogDao.save(list);
        }
@ -148,12 +154,14 @@ public class HvDeviceService {
                //独立式可燃气体探测器(NB)
                index.setDeviceType("1");
                list.add(index);
                dataPushLogUtil.savePushLog(resourceSerial,jsonObject.toJSONString(SerializerFeature.WriteMapNullValue),"可燃气体探测器监测信息接收");
            }
            if("600002".equals(resourceType)&&"400013".equals(monitorType)){
                //独立式光电感烟探测器(NB)
                index.setDeviceType("2");
                list.add(index);
                dataPushLogUtil.savePushLog(resourceSerial,jsonObject.toJSONString(SerializerFeature.WriteMapNullValue),"烟探测器监测信息接收");
            }
            updContactStatus(resourceSerial,1);
        }
@ -172,6 +180,7 @@ public class HvDeviceService {
            String deviceID = jsonObject.getString("deviceID");
            String deviceStatus = jsonObject.getString("deviceStatus");
            List<HvDeviceRecord> list = hvdeviceRecordDao.findByDeviceId(deviceID);
            dataPushLogUtil.savePushLog(deviceID,jsonObject.toJSONString(SerializerFeature.WriteMapNullValue),"气感烟感探测器监测信息接收");
            if(list.size()>0){
                updContactStatus(list.get(0).getDeviceSn(),Integer.valueOf(deviceStatus));
            }

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

@ -2,12 +2,15 @@ package com.yihu.jw.care.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.care.config.YsConfig;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.util.DeviceDataPushLogUtil;
import com.yihu.jw.care.util.SecurityOrderUtil;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.DeviceDetail;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.util.AesEncryptUtils;
import com.yihu.jw.exception.business.file_upload.*;
@ -78,6 +81,8 @@ public class YsDeviceService {
    private SecurityOrderUtil orderUtil;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private DeviceDataPushLogUtil dataPushLogUtil;
    /**
     * 获取萤石设备assesToken
@ -204,11 +209,13 @@ public class YsDeviceService {
                                if ("tumble_detection".equals(alarmType)){//tumble_detection跌倒类型    //有人出现SmartHumanDet
                                    fallFlag = true;
                                    deviceSN = bodyJsonObj2.getString("devSerial");//设备SN
                                    dataPushLogUtil.savePushLog(deviceSN,bodyJsonObj.toJSONString(SerializerFeature.WriteMapNullValue),"萤石监控跌倒数据接收");
                                    if (bodyJsonObj2.containsKey("pictureList")&&bodyJsonObj2.getJSONArray("pictureList")!=null){
                                        JSONArray pictureList = bodyJsonObj2.getJSONArray("pictureList");
                                        if (pictureList.size()>0){
                                            JSONObject tmp = pictureList.getJSONObject(0);
                                            sceneUrl = tmp.getString("url");//现场照片
                                            System.out.println("--"+deviceSN+":跌倒图片--"+sceneUrl);
                                            try {
                                            download(sceneUrl, "sceneImg","/data/apps/temp2/work/Tomcat/localhost/ROOT");
                                            String filePath = "/data/apps/temp2/work/Tomcat/localhost/ROOT/sceneImg.jpg";
@ -218,6 +225,7 @@ public class YsDeviceService {
                                            UploadVO uploadVO = orderUtil.uploadImg(multipartFile);
                                            sceneUrl = uploadVO.getFullUri();
                                            }catch (Exception e){
                                                e.printStackTrace();
                                                sceneUrl = null;
                                            }
                                        }

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

@ -0,0 +1,52 @@
package com.yihu.jw.care.util;
import com.yihu.jw.care.dao.device.DeviceDataPushLogDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.DeviceDataPushLog;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.patient.dao.BasePatientDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
/**
 * Created by Bing on 2021/9/2.
 * 设备数据推送日志保存
 */
@Component
public class DeviceDataPushLogUtil {
    @Autowired
    private DeviceDataPushLogDao deviceDataPushLogDao;
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private BasePatientDao patientDao;
    public void savePushLog(String sn,String data,String apiName){
        try {
            DeviceDataPushLog pushLog = new DeviceDataPushLog();
            pushLog.setDeviceSn(sn);
            pushLog.setData(data);
            pushLog.setApiName(apiName);
            pushLog.setCreateTime(new Date());
            List<DevicePatientDevice> devices= patientDeviceDao.findByDeviceSn(sn);
            if (devices.size()>0){
                DevicePatientDevice tmp = devices.get(0);
                BasePatientDO patientDO = patientDao.findById(tmp.getUser());
                if (null!=patientDO){
                    pushLog.setPatient(tmp.getUser());
                    pushLog.setPatientName(patientDO.getName());
                }
                pushLog.setDeviceName(tmp.getDeviceName());
                pushLog.setDeviceCategory(tmp.getCategoryCode());
            }
            deviceDataPushLogDao.save(pushLog);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}