Browse Source

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

yeshijie 3 years ago
parent
commit
2a6374e339

+ 6 - 0
business/base-service/src/main/java/com/yihu/jw/patient/dao/BasePatientDao.java

@ -34,6 +34,12 @@ public interface BasePatientDao extends PagingAndSortingRepository<BasePatientDO
    @Query("from BasePatientDO where mobile = ?1")
    List<BasePatientDO> findByMobile(String mobile);
    @Query("from BasePatientDO where del = 1")
    List<BasePatientDO> findAllByDel();
    @Query("from BasePatientDO where del = 1 and id = ?1")
    List<BasePatientDO> findAllByDelAndId(String user);
    @Query("from BasePatientDO p where p.mobile = ?1 and p.del=?2")
    List<BasePatientDO> findByMobileAndDel(String mobile,String del);
    

+ 26 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/DevicePatientDevice.java

@ -80,6 +80,16 @@ public class DevicePatientDevice extends IdEntity {
    private Integer deviceType;//设备种类 0健康设备 1安防设备
    /**
     * wifi对应的设备
     */
    private String iotDeviceSn;
    /**
     * 智能拐杖对应的围栏
     */
    private String safeAreaGz;
    @Column(name = "device_id")
    public Long getDeviceId() {
        return deviceId;
@ -338,4 +348,20 @@ public class DevicePatientDevice extends IdEntity {
    public void setDeviceType(Integer deviceType) {
        this.deviceType = deviceType;
    }
    public String getIotDeviceSn() {
        return iotDeviceSn;
    }
    public void setIotDeviceSn(String iotDeviceSn) {
        this.iotDeviceSn = iotDeviceSn;
    }
    public String getSafeAreaGz() {
        return safeAreaGz;
    }
    public void setSafeAreaGz(String safeAreaGz) {
        this.safeAreaGz = safeAreaGz;
    }
}

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

@ -1,5 +1,6 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@ -54,6 +55,9 @@ public interface PatientDeviceDao extends PagingAndSortingRepository<DevicePatie
    @Query("select a from DevicePatientDevice a")
    List<DevicePatientDevice> findAll();
    @Query("select a from DevicePatientDevice a where a.categoryCode = ?1")
    List<DevicePatientDevice> findAllByCategoryCode(String categoryCode);
    @Modifying
    @Query("delete DevicePatientDevice a where a.deviceSn = ?1")
    int deleteByDeviceSn(String deviceSN);

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

@ -117,7 +117,9 @@ public class PadDeviceController extends BaseController {
                             @RequestParam(value = "json", required = true) String json,
                             @ApiParam(name = "patient", value = "居民code") @RequestParam(value = "patient", required = false) String patientCode,
                             @ApiParam(name = "doctorCode", value = "管理员code") @RequestParam(value = "doctorCode", required = false) String doctorCode,
                             @ApiParam(name = "sleepPlanJson", value = "睡眠计划json") @RequestParam(value = "sleepPlanJson", required = false) String sleepPlanJson
                             @ApiParam(name = "sleepPlanJson", value = "睡眠计划json") @RequestParam(value = "sleepPlanJson", required = false) String sleepPlanJson,
                             @ApiParam(name = "iotDeviceSn", value = "iotDeviceSn") @RequestParam(value = "iotDeviceSn", required = false) String iotDeviceSn,
                             @ApiParam(name = "safeAreaGz", value = "safeAreaGz") @RequestParam(value = "safeAreaGz", required = false) String safeAreaGz
                             //{"deviceSn": "7052169111","getUpTime": "07:00","napTime": "13:00","nightRestTime": "21:30"}
                             ) {
        try {
@ -142,7 +144,7 @@ public class PadDeviceController extends BaseController {
            device.setAgentName(doctor.getName());
            String sn = device.getDeviceSn();
            synchronized (sn.intern()){
                Boolean flagDevice = patientDeviceService.saveDevice(device,sleepPlan);
                Boolean flagDevice = patientDeviceService.saveDevice(device,sleepPlan,iotDeviceSn,safeAreaGz);
                if (flagDevice == false){
                    return write(-1,"请填写投放地址");
                }

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

@ -100,7 +100,9 @@ public class PatientDeviceController extends BaseController {
    @RequestMapping(value = "SavePatientDevice", method = RequestMethod.POST)
    public String saveDevice(@ApiParam(name = "json", value = "设备数据json", defaultValue = "{\"deviceId\": \"3\",\"deviceName\": \"血压计-优瑞恩\",\"deviceSn\": \"7052169111\",\"categoryCode\": \"1\",\"userType\": \"-1\"}")
                             @RequestParam(value = "json", required = true) String json,
                             @ApiParam(name = "sleepPlanJson", value = "睡眠计划json") @RequestParam(value = "sleepPlanJson", required = false) String sleepPlanJson){
                             @ApiParam(name = "sleepPlanJson", value = "睡眠计划json") @RequestParam(value = "sleepPlanJson", required = false) String sleepPlanJson,
                             @ApiParam(name = "iotDeviceSn", value = "iotDeviceSn") @RequestParam(value = "iotDeviceSn", required = false) String iotDeviceSn,
                             @ApiParam(name = "safeAreaGz", value = "safeAreaGz") @RequestParam(value = "safeAreaGz", required = false) String safeAreaGz){
        //{"deviceSn": "7052169111","getUpTime": "07:00","napTime": "13:00","nightRestTime": "21:30"})
        try {
            DevicePatientDevice device = objectMapper.readValue(json, DevicePatientDevice.class);
@ -127,7 +129,7 @@ public class PatientDeviceController extends BaseController {
            String sn = device.getDeviceSn();
            synchronized (sn.intern()){
//                patientDeviceService.saveDevice(device);
                Boolean flagDevice = patientDeviceService.saveDevice(device,sleepPlan);
                Boolean flagDevice = patientDeviceService.saveDevice(device,sleepPlan,iotDeviceSn,safeAreaGz);
                if (flagDevice == false){
                    return write(-1,"请填写投放地址");
                }

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

@ -1,7 +1,9 @@
package com.yihu.jw.care.endpoint.statistics;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.service.statistics.DetectionPlatformService;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
@ -16,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
/***
 * @ClassName: DetectionPlatformEndpoint
 * @Description: 社区云照护平台--物联网健康监测展示平台
 * @Description: 社区云照护平台--物联网健康监测展示平台 v1.0.0
 * @Auther: shi kejing
 * @Date: 2021/8/20 9:28
 */
@ -29,9 +31,9 @@ public class DetectionPlatformEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private DetectionPlatformService platformService;
    @GetMapping(value = "security")
    @GetMapping(value = "getHealthMonitoringListNew")
    @ApiOperation(value = "体征监测/安防监护")
    public PageEnvelop security(
    public PageEnvelop getHealthMonitoringListNew(
            @ApiParam(name="page",value = "page") @RequestParam(required = true) int page,
            @ApiParam(name="size",value = "size") @RequestParam(required = true) int size,
            @ApiParam(name="type",value = "type=1(健康监测)   type=2(安防检测)") @RequestParam(required = true) int type) {
@ -42,7 +44,7 @@ public class DetectionPlatformEndpoint extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value = "company")
    @GetMapping(value = "getDeviceCompany")
    @ApiOperation(value = "设备入驻")
    public ObjEnvelop getDeviceCompany(){
        try {
@ -53,4 +55,38 @@ public class DetectionPlatformEndpoint extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value = "getDeviceType")
    @ApiOperation(value = "设备类型")
    public ListEnvelop getDeviceType(){
        try {
            return success("查询成功",200,platformService.getDeviceType());
        }catch (Exception e){
            return failedListEnvelopException(e);
        }
    }
    @GetMapping(value = "getDeviceByCondition")
    @ApiOperation(value = "地图展示,根据不同的条件展示不同的数据")
    public ListEnvelop<Object> getDeviceByCondition(            @ApiParam(name="categoryCode",value = "categoryCode") @RequestParam(required = false) String categoryCode,
                                                                @ApiParam(name="patient",value = "patient") @RequestParam(required = false) String patient){
        try {
            JSONArray object = platformService.getDeviceByCondition(categoryCode,patient);
            return success("查询成功",200,object);
        }catch (Exception e){
            return failedListEnvelopException(e);
        }
    }
    @GetMapping(value = "getDeviceInfo")
    @ApiOperation(value = "地图展示,根据设备sn码查询详情")
    public ObjEnvelop getDeviceInfo(            @ApiParam(name="deviceSn",value = "deviceSn") @RequestParam(required = true) String deviceSn){
        try {
            JSONObject object = platformService.getDeviceInfo(deviceSn);
            return success("查询成功",200,object);
        }catch (Exception e){
            return failedObjEnvelopException(e);
        }
    }
}

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

@ -196,7 +196,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
    /**
     * 保存患者设备
     */
    public boolean saveDevice(DevicePatientDevice devicePatientDevice, BaseSleepPlan sleepPlan) throws Exception {
    public boolean saveDevice(DevicePatientDevice devicePatientDevice, BaseSleepPlan sleepPlan, String iotDeviceSn, String safeAreaGz) throws Exception {
        //判断sn码是否被使用
        String sn = devicePatientDevice.getDeviceSn();
        String type = devicePatientDevice.getCategoryCode();
@ -263,6 +263,12 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                }
                sleepPlanDao.save(sleepPlan);
            }
            if ("17".equals(type)) {    //判断设备是不是随身wifi,如果是,则添加对应的设备sn
                devicePatientDevice.setIotDeviceSn(iotDeviceSn);
            }
            if ("16".equals(type)) {   //判断设备是不是拐杖,如果是拐杖,需要保存围栏地址
                devicePatientDevice.setSafeAreaGz(safeAreaGz);
            }
            patientDeviceDao.save(devicePatientDevice);
        }else {

+ 156 - 10
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/statistics/DetectionPlatformService.java

@ -1,8 +1,17 @@
package com.yihu.jw.care.service.statistics;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sun.org.apache.xerces.internal.xs.datatypes.ByteList;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.service.device.PatientDeviceService;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.web.PageEnvelop;
import io.swagger.models.auth.In;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.utils.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -10,8 +19,10 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/***
 * @ClassName: DetectionPlatformService
@ -26,14 +37,23 @@ public class DetectionPlatformService  {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private BasePatientDao patientDao;
    /**
     * 体征监测 安防监护
     * @param page
     * @param pageSize
     * @param type
     * @return
     */
    public PageEnvelop getHealthMonitoringListNew(Integer page, Integer pageSize, Integer type){
        page = page>0?page-1:0;
        if (type == 1) {
            String sql = " SELECT id,user,`name`,'健康监测' as serve_desc,czrq,value1,value2,value3,value4,value5,value6,value7,type \n" +
                    "FROM wlyy_patient_health_index WHERE del = 1 AND type < 3 ORDER BY czrq ";
                    "FROM wlyy_patient_health_index WHERE del = 1 AND type < 3 ORDER BY czrq desc ";
            String countSql = "select count(id) from ("+sql+")A ";
            long count = jdbcTemplate.queryForObject(countSql,long.class);
            sql +=" limit "+page*pageSize+","+pageSize;
@ -68,7 +88,7 @@ public class DetectionPlatformService  {
        }
        String securitySql = "SELECT allCount,isUse,(allCount - isUse) inventory FROM \n" +
                "(SELECT COUNT(1) allCount FROM wlyy_devices WHERE device_type = 1) allCount,\n" +
                "(SELECT COUNT(1) isUse FROM wlyy_devices WHERE device_type = 1 AND is_binding = 1) isUse";
                "(SELECT COUNT(pd.id) isUse FROM wlyy_devices d,wlyy_patient_device pd WHERE d.device_type = 1 AND d.device_code = pd.device_sn AND pd.del = 0) isUse";
        List<Map<String , Object>> securityList = jdbcTemplate.queryForList(securitySql);
        if (securityList.size() > 0) {
            object.put("securityAllCount",securityList.get(0).get("allCount")); //安防设备总量
@ -81,7 +101,7 @@ public class DetectionPlatformService  {
        }
        String healthSql = "SELECT allCount,isUse,(allCount - isUse) inventory FROM \n" +
                "(SELECT COUNT(1) allCount FROM wlyy_devices WHERE device_type = 0) allCount,\n" +
                "(SELECT COUNT(1) isUse FROM wlyy_devices WHERE device_type = 0 AND is_binding = 1) isUse";
                "(SELECT COUNT(pd.id) isUse FROM wlyy_devices d,wlyy_patient_device pd WHERE d.device_type = 0 AND d.device_code = pd.device_sn AND pd.del = 0) isUse";
        List<Map<String , Object>> healthList = jdbcTemplate.queryForList(healthSql);
        if (healthList.size() > 0) {
            object.put("healthAllCount",securityList.get(0).get("allCount"));//健康设备总量
@ -92,10 +112,21 @@ public class DetectionPlatformService  {
            object.put("healthIsUseCount",0);//健康设备使用中数量
            object.put("healthInventoryCount",0);//健康设备库存量
        }
        //物联率
        object.put("lawOfIOT",getRange( ((Integer)securityList.get(0).get("isUse") + (Integer) healthList.get(0).get("isUser")),( (Integer) securityList.get(0).get("allCount") + (Integer) healthList.get(0).get("allCount") ) ));
        object.put("isUseAllIot",((Integer)securityList.get(0).get("isUse") + (Integer) healthList.get(0).get("isUser")));//已发放设备
        object.put("allIot",(Integer) securityList.get(0).get("allCount") + (Integer) healthList.get(0).get("allCount"));//总设备
        Long securityIsUser = (Long) securityList.get(0).get("isUse");
        Long healthIsUser = (Long) healthList.get(0).get("isUse");
        Long securityAllCount = (Long) securityList.get(0).get("allCount");
        Long healthAllCount = (Long) healthList.get(0).get("allCount");
        object.put("lawOfIOT",getRange( (securityIsUser.intValue() + healthIsUser.intValue() ),( securityAllCount.intValue() + healthAllCount.intValue()  ) ));//物联率
        object.put("isUseAllIot",(securityIsUser.intValue() + healthIsUser.intValue()));//已发放设备
        object.put("allIot",securityAllCount.intValue() + healthAllCount.intValue());//总设备
//        String unUseSql = "";//连续一周为上传数据
//        List<Map<String , Object>> unUseList = jdbcTemplate.queryForList(unUseSql);
//        Long unUseCount = (Long) securityList.get(0).get("allCount");
////        if (unUseList.size() > 0){
////            unUseCount = (Long) securityList.get(0).get("allCount");
////        }
//        object.put("lostLaw",getRange(unUseCount.intValue(),securityIsUser.intValue() + healthIsUser.intValue()));//设备失联率
        object.put("lostLaw","0%");//设备失联率
        return object;
    }
@ -114,4 +145,119 @@ public class DetectionPlatformService  {
        return filesize + "%";
    }
    public List<Map<String , Object>> getDeviceType(){
        String sql = "SELECT category_code,device_name FROM wlyy_patient_device GROUP BY category_code";
        return jdbcTemplate.queryForList(sql);
    }
    public JSONArray getDeviceByCondition(String categoryCode , String user){
        JSONArray jsonArray = new JSONArray();
        List<DevicePatientDevice> patientDevices = patientDeviceDao.findAll();
        if (StringUtils.isNotBlank(categoryCode)) {  //categoryCode != null   根据设备类型查询
            patientDevices = patientDeviceDao.findAllByCategoryCode(categoryCode);
        }
        Map<String, List<DevicePatientDevice>> byUser = patientDevices.stream().collect(Collectors.groupingBy(DevicePatientDevice::getUser));
        List<BasePatientDO> patientDOS = patientDao.findAllByDel();
        if (StringUtils.isNotBlank(user)) {
            patientDOS = patientDao.findAllByDelAndId(user);  //user != null   根据居民查询
        }
        Map<String, List<BasePatientDO>> byId = patientDOS.stream().collect(Collectors.groupingBy(BasePatientDO::getId));
        //首页默认根据居民展示  绑定设备的居民
        String userSql = "SELECT `user` FROM wlyy_patient_device WHERE del = 0 GROUP BY `user`";
        List<Map<String , Object>> userList = jdbcTemplate.queryForList(userSql);
        if (userList.size() > 0) {
            JSONObject userObj = new JSONObject();
            for (int i=0;i<userList.size();i++) {
                JSONArray arrayAll = new JSONArray();
                JSONArray array = new JSONArray();
                userObj.put("patient",userList.get(i).get("user"));
                userObj.put("patientName",byId.get(userList.get(i).get("user")).get(0).getName());
                userObj.put("patientType",byId.get(userList.get(i).get("user")).get(0).getArchiveType());
                userObj.put("latLon",byId.get(userList.get(i).get("user")).get(0).getLatLon());
                List<DevicePatientDevice> deviceList = byUser.get(userList.get(i).get("user"));
                if (deviceList.size() > 1) {    //居民绑定多台设备
                    for (int j=0;j<deviceList.size();j++) {
                        JSONObject obj = new JSONObject();
                        obj.put("deviceSn",deviceList.get(j).getDeviceSn());
                        obj.put("deviceName",deviceList.get(j).getDeviceName());
                        obj.put("categoryCode",deviceList.get(j).getCategoryCode());
                        array.add(obj);
                    }
                    userObj.put("deviceCount",deviceList.size());
                    userObj.put("deviceInfo",array);
                    arrayAll.add(userObj);
                } else {    //居民只绑定一台设备
                    for (int j=0;j<deviceList.size();j++) {
                        JSONObject obj = new JSONObject();
                        obj.put("deviceSn",deviceList.get(j).getDeviceSn());
                        obj.put("deviceName",deviceList.get(j).getDeviceName());
                        obj.put("categoryCode",deviceList.get(j).getCategoryCode());
                        array.add(obj);
                    }
                    userObj.put("deviceCount",deviceList.size());
                    userObj.put("deviceInfo",array);
                    arrayAll.add(userObj);
                }
                jsonArray.add(arrayAll);
            }
        } else {
            return jsonArray;
        }
        return jsonArray;
    }
    public JSONObject getDeviceInfo(String deviceSn) throws Exception{
        String categoryCode = "";
        JSONObject object = new JSONObject();
        String deviceInfoSql = "SELECT device_name deviceName,device_type deviceType,device_code deviceSn,manufacturer FROM wlyy_devices WHERE  device_code = '"+deviceSn+"' ";
        List<Map<String , Object>> deviceInfoList = jdbcTemplate.queryForList(deviceInfoSql);
        if (deviceInfoList.size() > 0){
            object.put("deviceName",deviceInfoList.get(0).get("deviceName"));
            object.put("deviceType",deviceInfoList.get(0).get("deviceType"));
            object.put("deviceSn",deviceInfoList.get(0).get("deviceSn"));
            object.put("manufacturer",deviceInfoList.get(0).get("manufacturer"));
            String patientInfoSql = "SELECT p.`name` patientName,p.id patient,p.mobile,p.idcard,p.address,pd.category_code categoryCode " +
                    "FROM wlyy_patient_device pd,base_patient p WHERE p.id = pd.`user` AND p.del = 1 AND pd.del = 0 AND pd.device_sn = '"+deviceSn+"'";
            List<Map<String , Object>> patientInfoList = jdbcTemplate.queryForList(patientInfoSql);
            if (patientInfoList.size() > 0) {
                categoryCode = patientInfoList.get(0).get("categoryCode").toString();
                object.put("patientName",patientInfoList.get(0).get("patientName"));
                object.put("patient",patientInfoList.get(0).get("patient"));
                object.put("mobile",patientInfoList.get(0).get("mobile"));
                object.put("idcard",patientInfoList.get(0).get("idcard"));
                object.put("address",patientInfoList.get(0).get("address"));
                String dataSql= "";
                List<Map<String , Object>> dataList = new ArrayList<>();
                switch (categoryCode) {
                    // 1=血糖仪  2=血压计  4=智能手表  13=智能床带/睡眠带  14=燃气报警器  15=烟雾报警器
                    case "1" :
                        dataSql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '"+deviceSn+"' AND del = 1 ORDER BY sort_date DESC LIMIT 10";
                        dataList = jdbcTemplate.queryForList(dataSql);
                        object.put("data",dataList);
                        break;
                    case "2" :
                        dataSql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '"+deviceSn+"' AND del = 1 ORDER BY sort_date DESC LIMIT 10";
                        dataList = jdbcTemplate.queryForList(dataSql);
                        object.put("data",dataList);
                        break;
                    case "14" :
                        dataSql = "SELECT record_time recordDate,`value`,unit,device_type FROM base_device_health_index WHERE device_sn = '"+deviceSn+"' ORDER BY record_time DESC LIMIT 10 ";
                        dataList = jdbcTemplate.queryForList(dataSql);
                        object.put("data",dataList);
                        break;
                    case "15" :
                        dataSql = "SELECT record_time recordDate,`value`,unit,device_type FROM base_device_health_index WHERE device_sn = '"+deviceSn+"' ORDER BY record_time DESC LIMIT 10 ";
                        dataList = jdbcTemplate.queryForList(dataSql);
                        object.put("data",dataList);
                        break;
                }
            } else {
                throw new Exception("无法找到该设备对应使用人");
            }
        }else {
            throw new Exception("设备SN码对应的设备不存在!");
        }
        return object;
    }
}