Commit ee0642c9 by lzy

Merge branch 'dev' of git.xmmakeit.com:huangjiay/iot-platform-server into dev

parents c1ef5622 e4b83cf0
package com.makeit.module.iot.enums; package com.makeit.module.iot.enums;
import com.makeit.enums.BaseEnum;
import com.makeit.utils.sys.SysDictUtil;
public class DeviceInfoContentFallEnum { public class DeviceInfoContentFallEnum {
public enum PersonStateEnum { public enum PersonStateEnum {
......
package com.makeit.module.iot.enums;
public class DeviceInfoContentSpaceEnum {
public enum PersonStateEnum {
NOBODY(0, "无人"),//0
ANYBODY(1, "有人");//1
private Integer value;
private String name;
PersonStateEnum(Integer value, String name) {
this.value = value;
this.name = name;
}
public Integer getValue() {
return value;
}
public String getName() {
return name;
}
}
}
package com.makeit.utils;
import java.util.List;
public class StandardDeviationUtil {
/**
* 传入一个数列x计算平均值
*
* @param x
* @return 平均值
*/
public static double average(double[] x) {
int n = x.length; //数列元素个数
double sum = 0;
for (double i : x) { //求和
sum += i;
}
return sum / n;
}
public static double average(List<Double> x) {
int n = x.size(); //数列元素个数
double sum = 0;
for (double i : x) { //求和
sum += i;
}
return sum / n;
}
/**
* 传入一个数列x计算方差
* 方差s^2=[(x1-x)^2+(x2-x)^2+......(xn-x)^2]/(n)(x为平均数)
*
* @param x 要计算的数列
* @return 方差
*/
public static double variance(double[] x) {
int n = x.length; //数列元素个数
double avg = average(x); //求平均值
double var = 0;
for (double i : x) {
var += (i - avg) * (i - avg); //(x1-x)^2+(x2-x)^2+......(xn-x)^2
}
return var / n;
}
public static double variance(List<Double> x) {
int n = x.size(); //数列元素个数
double avg = average(x); //求平均值
double var = 0;
for (double i : x) {
var += (i - avg) * (i - avg); //(x1-x)^2+(x2-x)^2+......(xn-x)^2
}
return var / n;
}
/**
* 传入一个数列x计算标准差
* 标准差σ=sqrt(s^2),即标准差=方差的平方根
*
* @param x 要计算的数列
* @return 标准差
*/
public static double standardDeviation(double[] x) {
return Math.sqrt(variance(x));
}
}
...@@ -26,7 +26,7 @@ public class SaasPrivacyConfigDTO implements Serializable { ...@@ -26,7 +26,7 @@ public class SaasPrivacyConfigDTO implements Serializable {
@ApiModelProperty("标题") @ApiModelProperty("标题")
private String title; private String title;
@Size(max = 5000, message = "申请说明最长为5000字符") @Size(max = 5000, message = "内容长度最长为5000字符")
@ApiModelProperty(value="内容") @ApiModelProperty(value="内容")
private String content; private String content;
......
...@@ -3,7 +3,7 @@ package com.makeit.enums.platform.elder; ...@@ -3,7 +3,7 @@ package com.makeit.enums.platform.elder;
import com.makeit.enums.BaseEnum; import com.makeit.enums.BaseEnum;
import com.makeit.utils.sys.SysDictUtil; import com.makeit.utils.sys.SysDictUtil;
public class PlatElderMonitorReportEnum { public class PlatElderRealtimeReportEnum {
public enum NowStatus implements BaseEnum { public enum NowStatus implements BaseEnum {
OUT("elder.realtime.now.status.out"), OUT("elder.realtime.now.status.out"),
RUN("elder.realtime.now.status.run"), RUN("elder.realtime.now.status.run"),
......
...@@ -433,7 +433,11 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -433,7 +433,11 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
m.reset(); m.reset();
int i = 0; int i = 0;
while (m.find()) { while (m.find()) {
m.appendReplacement(sb, param.get(i)); String paramValue = "";
if(param.size()>i) {
paramValue = param.get(i);
}
m.appendReplacement(sb, paramValue);
i++; i++;
} }
m.appendTail(sb); m.appendTail(sb);
......
package com.makeit.service.platform.elder.impl; package com.makeit.service.platform.elder.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.makeit.common.entity.BaseEntity;
import com.makeit.dto.platform.elder.PlatElderIdDTO; import com.makeit.dto.platform.elder.PlatElderIdDTO;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.saas.analysis.SaasSleepAnalysisModel;
import com.makeit.entity.saas.analysis.SaasSleepEvaluateReport;
import com.makeit.enums.platform.elder.PlatElderRealtimeReportEnum;
import com.makeit.module.iot.enums.DeviceInfoContentBreatheEnum;
import com.makeit.module.iot.enums.DeviceInfoContentSpaceEnum;
import com.makeit.module.iot.service.IotProductDeviceService; import com.makeit.module.iot.service.IotProductDeviceService;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe; import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
import com.makeit.module.iot.vo.space.DeviceInfoContentSpace; import com.makeit.module.iot.vo.space.DeviceInfoContentSpace;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.elder.PlatElderDayReportDayService;
import com.makeit.service.platform.elder.PlatElderRealTimeService; import com.makeit.service.platform.elder.PlatElderRealTimeService;
import com.makeit.service.platform.elder.PlatElderService; import com.makeit.service.platform.elder.PlatElderService;
import com.makeit.service.saas.SaasSleepAnalysisModelService;
import com.makeit.utils.StandardDeviationUtil;
import com.makeit.utils.data.convert.StreamUtil; import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.data.validate.CollectionUtils; import com.makeit.utils.data.validate.CollectionUtils;
import com.makeit.utils.old.StringUtils; import com.makeit.utils.old.StringUtils;
...@@ -15,6 +25,7 @@ import com.makeit.vo.platform.elder.realtime.PlatElderCoordinateVO; ...@@ -15,6 +25,7 @@ import com.makeit.vo.platform.elder.realtime.PlatElderCoordinateVO;
import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeBodyVO; import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeBodyVO;
import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeHeartRespiratoryVO; import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeHeartRespiratoryVO;
import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeNowVO; import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeNowVO;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -48,6 +59,12 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -48,6 +59,12 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
@Autowired @Autowired
private IotProductDeviceService iotProductDeviceService; private IotProductDeviceService iotProductDeviceService;
@Autowired
private PlatElderDayReportDayService platElderDayReportDayService;
@Autowired
private SaasSleepAnalysisModelService saasSleepAnalysisModelService;
@Override @Override
public PlatDevice getBreathDevice(String elderId, String deviceId) { public PlatDevice getBreathDevice(String elderId, String deviceId) {
PlatDevice platDevice = null; PlatDevice platDevice = null;
...@@ -121,17 +138,126 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -121,17 +138,126 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
} }
private void nowStatusOut(PlatElderRealTimeNowVO platElderRealTimeNowVO, PlatElderIdDTO platElderIdDTO) {
List<DeviceInfoContentSpace> deviceInfoContentSpaceList = getNowDataSpace(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
if (CollectionUtils.isEmpty(deviceInfoContentSpaceList)) {
return;
}
if (StreamUtil.allMatch(deviceInfoContentSpaceList, e -> DeviceInfoContentSpaceEnum.PersonStateEnum.NOBODY.getValue().equals(e.getProperties().getPersonState()))) {
platElderRealTimeNowVO.setStatus(PlatElderRealtimeReportEnum.NowStatus.OUT.getValue());
}
}
private void nowStatusRun(PlatElderRealTimeNowVO platElderRealTimeNowVO, PlatElderIdDTO platElderIdDTO, DeviceInfoContentBreathe nowDataBreathe, List<PlatElderCoordinateVO> coordinateList) {
if (nowDataBreathe == null) {
return;
}
boolean flag = DeviceInfoContentBreatheEnum.PersonStateEnum.NOBODY.getValue().equals(nowDataBreathe.getProperties().getPersonState());
if (!flag) {
return;
}
if (CollectionUtils.isNotEmpty(coordinateList)) {
double v = StandardDeviationUtil.average(StreamUtil.map(coordinateList, e -> e.getDistance().doubleValue()));
if (new BigDecimal(v + "").compareTo(new BigDecimal(2)) > 0) {
platElderRealTimeNowVO.setStatus((PlatElderRealtimeReportEnum.NowStatus.RUN.getValue()));
}
}
}
private void nowStatusRest(PlatElderRealTimeNowVO platElderRealTimeNowVO, PlatElderIdDTO platElderIdDTO, DeviceInfoContentBreathe nowDataBreathe, List<PlatElderCoordinateVO> coordinateList) {
if (nowDataBreathe == null) {
return;
}
boolean flag = DeviceInfoContentBreatheEnum.PersonStateEnum.NOBODY.getValue().equals(nowDataBreathe.getProperties().getPersonState());
if (!flag) {
return;
}
if (CollectionUtils.isNotEmpty(coordinateList)) {
double v = StandardDeviationUtil.average(StreamUtil.map(coordinateList, e -> e.getDistance().doubleValue()));
if (new BigDecimal(v + "").compareTo(new BigDecimal(2)) <= 0) {
platElderRealTimeNowVO.setStatus((PlatElderRealtimeReportEnum.NowStatus.RUN.getValue()));
}
}
}
private void nowStatusSleepAndBed(PlatElderRealTimeNowVO platElderRealTimeNowVO, PlatElderIdDTO platElderIdDTO, DeviceInfoContentBreathe nowDataBreathe) {
if (nowDataBreathe == null) {
return;
}
boolean flag = !DeviceInfoContentBreatheEnum.PersonStateEnum.NOBODY.getValue().equals(nowDataBreathe.getProperties().getPersonState());
if (!flag) {
return;
}
SaasSleepAnalysisModel analysisModel = saasSleepAnalysisModelService.getOne(new QueryWrapper<SaasSleepAnalysisModel>().lambda()
.orderByDesc(BaseEntity::getCreateBy)
.last("limit 1"));
if (analysisModel == null) {
return;
}
Integer sleepTimeActionDuration = Integer.valueOf(analysisModel.getSleepTimeActionDuration() + "");
Integer sleepTimeActionThreshold = Integer.valueOf(analysisModel.getSleepTimeActionThreshold() + "");
LocalDateTime now = LocalDateTime.now();
LocalDateTime start = now.minusHours(sleepTimeActionDuration);
PlatDevice platDevice = getBreathDevice(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
List<DeviceInfoContentBreathe> breatheList = iotProductDeviceService.getDeviceLogByTimeRangeBreathe(platDevice.getOriDeviceId(), 2 * 24 * 3600, start, now);
if (CollectionUtils.isNotEmpty(breatheList)) {
if (StreamUtil.allMatch(breatheList, e -> e.getProperties().getBodymove() < sleepTimeActionThreshold)) {
platElderRealTimeNowVO.setStatus(PlatElderRealtimeReportEnum.NowStatus.SLEEP.getValue());
}
}
platElderRealTimeNowVO.setStatus(PlatElderRealtimeReportEnum.NowStatus.BED.getValue());
}
@Override @Override
public PlatElderRealTimeNowVO nowStatus(PlatElderIdDTO platElderIdDTO) { public PlatElderRealTimeNowVO nowStatus(PlatElderIdDTO platElderIdDTO) {
// DeviceInfoContentBreathe deviceInfoContentBreathe = getNowDataBreathe(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
//
PlatElderRealTimeNowVO platElderRealTimeNowVO = new PlatElderRealTimeNowVO();
//
// if (deviceInfoContentBreathe == null) {
// return platElderRealTimeNowVO;
// }
//
//platElderRealTimeNowVO.setStatus(deviceInfoContentBreathe.getProperties().getPersonState() + "");
DeviceInfoContentBreathe deviceInfoContentBreathe = getNowDataBreathe(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId()); DeviceInfoContentBreathe deviceInfoContentBreathe = getNowDataBreathe(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
PlatElderRealTimeNowVO platElderRealTimeNowVO = new PlatElderRealTimeNowVO(); nowStatusOut(platElderRealTimeNowVO, platElderIdDTO);
if (deviceInfoContentBreathe == null) { LocalDateTime now = LocalDateTime.now();
return platElderRealTimeNowVO; LocalDateTime start = now.minusSeconds(10);
}
List<PlatElderCoordinateVO> coordinateList = platElderDayReportDayService.coordinateList(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId(), start, now);
nowStatusRun(platElderRealTimeNowVO, platElderIdDTO, deviceInfoContentBreathe, coordinateList);
nowStatusRest(platElderRealTimeNowVO, platElderIdDTO, deviceInfoContentBreathe, coordinateList);
nowStatusSleepAndBed(platElderRealTimeNowVO, platElderIdDTO, deviceInfoContentBreathe);
platElderRealTimeNowVO.setStatus(deviceInfoContentBreathe.getProperties().getPersonState() + "");
platElderRealTimeNowVO.setHeartRate(deviceInfoContentBreathe.getProperties().getHr()); platElderRealTimeNowVO.setHeartRate(deviceInfoContentBreathe.getProperties().getHr());
platElderRealTimeNowVO.setRespiratoryRate(deviceInfoContentBreathe.getProperties().getBr()); platElderRealTimeNowVO.setRespiratoryRate(deviceInfoContentBreathe.getProperties().getBr());
platElderRealTimeNowVO.setBodyMove(deviceInfoContentBreathe.getProperties().getBodymove()); platElderRealTimeNowVO.setBodyMove(deviceInfoContentBreathe.getProperties().getBodymove());
......
...@@ -658,11 +658,16 @@ public class PlatElderServiceImpl extends ServiceImpl<PlatElderMapper, PlatElder ...@@ -658,11 +658,16 @@ public class PlatElderServiceImpl extends ServiceImpl<PlatElderMapper, PlatElder
fillSpace(platElder); fillSpace(platElder);
if (StringUtils.isNotBlank(dto.getBedId())) {
platElder.setCheckInTime(LocalDateTime.now());
}
updateById(platElder); updateById(platElder);
addOrEditExt(dto); addOrEditExt(dto);
if (StringUtils.isNotBlank(dto.getBedId())) { if (StringUtils.isNotBlank(dto.getBedId())) {
db.setCheckInTime(LocalDateTime.now());
checkInInternal(dto.getBedId()); checkInInternal(dto.getBedId());
} }
if (StringUtils.isNotBlank(oldBedId) && !oldBedId.equals(dto.getBedId())) { if (StringUtils.isNotBlank(oldBedId) && !oldBedId.equals(dto.getBedId())) {
......
...@@ -169,10 +169,12 @@ public class PlatMenuServiceImpl extends ServiceImpl<PlatMenuMapper, PlatMenu> ...@@ -169,10 +169,12 @@ public class PlatMenuServiceImpl extends ServiceImpl<PlatMenuMapper, PlatMenu>
* @param dto * @param dto
*/ */
private void checkCode(PlatMenuDTOVO dto) { private void checkCode(PlatMenuDTOVO dto) {
PlatMenu old = getOne(new QueryWrapper<PlatMenu>().lambda() if(StringUtils.isNotBlank(dto.getCode())) {
.eq(PlatMenu::getCode, dto.getCode())); PlatMenu old = getOne(new QueryWrapper<PlatMenu>().lambda()
if (old != null && !old.getId().equals(dto.getId())) { .eq(StringUtils.isNotBlank(dto.getCode()), PlatMenu::getCode, dto.getCode()));
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR_MENU_CODE_DUPLICATE); if (old != null && !old.getId().equals(dto.getId())) {
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR_MENU_CODE_DUPLICATE);
}
} }
} }
......
...@@ -291,7 +291,7 @@ public class PlatTenantServiceImpl extends ServiceImpl<PlatTenantMapper, PlatTen ...@@ -291,7 +291,7 @@ public class PlatTenantServiceImpl extends ServiceImpl<PlatTenantMapper, PlatTen
PlatTenant tntTenant = BeanDtoVoUtils.convert(dto, PlatTenant.class); PlatTenant tntTenant = BeanDtoVoUtils.convert(dto, PlatTenant.class);
PlatTenant platTenant = getById(tntTenant.getId()); PlatTenant platTenant = getById(tntTenant.getId());
//更新同步到iot //更新同步到iot
iotOrgService.updateIotOrgInfo(tntTenant.getIotOrgId(), dto.getName()); iotOrgService.updateIotOrgInfo(platTenant.getIotOrgId(), dto.getName());
updateById(tntTenant); updateById(tntTenant);
......
...@@ -107,7 +107,7 @@ public class IotSyncTask { ...@@ -107,7 +107,7 @@ public class IotSyncTask {
} }
platDevice.setOriDeviceId(iotDevice.getId()); platDevice.setOriDeviceId(iotDevice.getId());
platDevice.setName(iotDevice.getName()); platDevice.setName(iotDevice.getName());
platDevice.setOrgId(tenantId); //platDevice.setOrgId(tenantId);
String productName = iotDevice.getProductName(); String productName = iotDevice.getProductName();
platDevice.setProductName(productName); platDevice.setProductName(productName);
platDevice.setProductId(iotDevice.getProductId()); platDevice.setProductId(iotDevice.getProductId());
......
package com.makeit.vo.platform.elder.report.day; package com.makeit.vo.platform.elder.report.day;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -8,6 +9,7 @@ import java.time.LocalDateTime; ...@@ -8,6 +9,7 @@ import java.time.LocalDateTime;
@Data @Data
public class PlatElderHeartRespiratoryEvaluationRecordVO { public class PlatElderHeartRespiratoryEvaluationRecordVO {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm::ss")
@ApiModelProperty("时间") @ApiModelProperty("时间")
private LocalDateTime time; private LocalDateTime time;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment