Commit 50ba56ed by 杨伟程
parents 09af6a32 ece9d396
Showing with 690 additions and 141 deletions
package com.makeit.controller.analysis;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.makeit.common.dto.BaseNameDTO;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.entity.saas.analysis.SaasModelManage;
import com.makeit.global.annotation.Action;
import com.makeit.service.saas.SaasModelManageService;
import com.makeit.utils.old.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -35,8 +39,9 @@ public class SaasModelManageController {
@Action(module = "数据分析-模型管理", name = "分页列表", code = "saas:modelManage:page")
@ApiOperation("分页列表")
@PostMapping("list")
public ApiResponseEntity<List<SaasModelManage>> list() {
return ApiResponseUtils.success(saasModelManageService.list());
public ApiResponseEntity<List<SaasModelManage>> list(@RequestBody BaseNameDTO dto) {
return ApiResponseUtils.success(saasModelManageService.list(new QueryWrapper<SaasModelManage>().lambda()
.like(StringUtils.isNotEmpty(dto.getName()),SaasModelManage::getName,dto.getName())));
}
}
package com.makeit.controller.analysis;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.makeit.common.dto.BaseNameDTO;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.entity.saas.analysis.SaasModelManage;
......@@ -8,8 +10,10 @@ import com.makeit.entity.saas.analysis.SaasReportManage;
import com.makeit.global.annotation.Action;
import com.makeit.service.saas.SaasModelManageService;
import com.makeit.service.saas.SaasReportManageService;
import com.makeit.utils.old.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -37,8 +41,9 @@ public class SaasReportManageController {
@Action(module = "数据分析-报告管理", name = "分页列表", code = "saas:reportManage:page")
@ApiOperation("分页列表")
@PostMapping("list")
public ApiResponseEntity<List<SaasReportManage>> list(){
return ApiResponseUtils.success(saasReportManageService.list());
public ApiResponseEntity<List<SaasReportManage>> list(@RequestBody BaseNameDTO dto){
return ApiResponseUtils.success(saasReportManageService.list(new QueryWrapper<SaasReportManage>().lambda()
.like(StringUtils.isNotEmpty(dto.getName()),SaasReportManage::getName,dto.getName())));
}
}
......
......@@ -92,11 +92,16 @@ public class RedisConst {
public static final String TENANT_PREFIX = "tenant:";
public static final String ALARM_DEVICE_ID = "alarm:device:id:";
public static final String ALARM_DEVICE_BR_ID = "alarm:device:br:id:";
public static final String ALARM_DEVICE_HR_ID = "alarm:device:hr:id:";
public static final String ALARM_DEVICE_FALL_ID = "alarm:device:fall:id:";
public static final String ALARM_DEVICE_BEHAVIOR_ID = "alarm:device:behavior:id:";
public static final String ALARM_CONFIG_ORG_ID = "alarm:config:org:id:";
public static final String PLAT_IOT_DEVICE_PREFIX = "plat:iot:device:";
public static final String ELDER_DAY_DURATION_PREFIX = "plat:day:duration:device:";
......
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.google.common.collect.Lists;
import com.makeit.module.iot.dto.IotQueryParam;
import com.makeit.module.iot.dto.IotSort;
import com.makeit.module.iot.dto.Term;
import com.makeit.module.iot.util.HttpRequest;
import com.makeit.module.iot.vo.DeviceInstanceEntity;
......@@ -193,7 +194,15 @@ public class IotProductDeviceService extends IotCommonService {
return getDeviceLog(deviceId, 10, typeValue);
}
/**
*
* @param deviceId
* @param typeValue
* @param pageSize
* @param startTime
* @param endTime
* @return
*/
public List<DeviceOperationLogEntity> getDeviceLogByTimeRange(String deviceId, String typeValue, int pageSize, String startTime, String endTime) {
IotQueryParam iotQueryParam = buildQueryParam(pageSize);
List<Term> terms = Lists.newArrayList();
......@@ -226,6 +235,14 @@ public class IotProductDeviceService extends IotCommonService {
terms.add(term1);
terms.add(term2);
iotQueryParam.setTerms(terms);
List<IotSort> iotSortList = Lists.newArrayList();
IotSort iotSort = new IotSort();
iotSort.setOrder("asc");
iotSort.setName("timestamp");
iotSortList.add(iotSort);
iotQueryParam.setSorts(iotSortList);
String body = JsonUtil.toJson(iotQueryParam);
String url = iotUrl + DEVICE_PREFIX_URL + deviceId + "/logs";
HttpRequest request = buildRequest(url, body);
......
......@@ -19,6 +19,7 @@ public class DeviceInfo {
private HeaderInfo headers;
private JSONObject properties;
// private String properties;
/**
......
package com.makeit.module.iot.vo.analysis;
import lombok.Data;
@Data
public class SleepTimeAnalysisVO {
private String startSleepTime; // 入睡时间开始
private String endSleepTime; // 入睡时间结束
}
......@@ -160,4 +160,8 @@ public class StreamUtil {
return list.stream().filter(predicate).map(function).collect(Collectors.joining(","));
}
public static <T> String join(List<T> list, Predicate<T> predicate, Function<T, String> function, String split) {
return list.stream().filter(predicate).map(function).collect(Collectors.joining(split));
}
}
......@@ -20,6 +20,8 @@ public class MsgSendDTO {
private Collection<String> receiverList;
private Collection<String> emailSet;
private String oriContent;
/**
......
package com.makeit.utils.msg.sender;
import com.makeit.exception.BusinessException;
import com.makeit.utils.msg.SendTypeEnum;
import com.makeit.utils.msg.dto.MsgSendDTO;
import lombok.extern.slf4j.Slf4j;
......@@ -36,12 +35,12 @@ public class MailMsgSender implements IMsgSender {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(from);
helper.setTo(msgDTO.getReceiverList().toArray(new String[msgDTO.getReceiverList().size()]));
helper.setTo(msgDTO.getEmailSet().toArray(new String[msgDTO.getReceiverList().size()]));
helper.setSubject(msgDTO.getSubject());
helper.setText(msgDTO.getOriContent(), false);
mailSender.send(message);
} catch (Exception e) {
throw new BusinessException(e.getMessage());
log.error("发送邮箱异常:",e);
}
}
......
......@@ -8,6 +8,8 @@ import com.makeit.utils.msg.config.SmsConfig;
import com.makeit.utils.msg.dto.MsgSendDTO;
import com.makeit.utils.old.encode.CryptoUtil;
import com.makeit.utils.third.HttpClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
......@@ -20,6 +22,7 @@ import java.util.HashMap;
import java.util.stream.Collectors;
@Component
@Slf4j
public class SmsMsgSender implements IMsgSender{
@Autowired
......@@ -40,6 +43,9 @@ public class SmsMsgSender implements IMsgSender{
@Override
public void send(MsgSendDTO msgDTO) {
try {
if(CollectionUtils.isEmpty(msgDTO.getReceiverList())){
log.info("发送短信时,没有接收人,短信内容:"+msgDTO.getOriContent());
}
Date now = new Date();
String time = String.valueOf(now.getTime());
Collection<String> receiverList = msgDTO.getReceiverList();
......@@ -57,10 +63,13 @@ public class SmsMsgSender implements IMsgSender{
JSONObject jsonObject = JSON.parseObject(resStr);
String status = String.valueOf(jsonObject.get("status"));
if (!StringUtils.equals(status, "0")) {
log.error("发送短信失败:"+jsonObject.get("status_code"));
throw new BusinessException((String) jsonObject.get("status_code"));
}else {
log.info("发送短信成功");
}
}catch (Exception e){
throw new BusinessException(e.getMessage());
log.error("发送短信异常:",e);
}
}
......
......@@ -8,6 +8,8 @@ import com.makeit.utils.msg.config.SmsVoiceConfig;
import com.makeit.utils.msg.dto.MsgSendDTO;
import com.makeit.utils.old.encode.CryptoUtil;
import com.makeit.utils.third.HttpClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
......@@ -22,6 +24,7 @@ import java.util.function.BiConsumer;
import java.util.stream.Collectors;
@Component
@Slf4j
public class SmsVoiceSender implements IMsgSender{
@Autowired
......@@ -42,6 +45,9 @@ public class SmsVoiceSender implements IMsgSender{
@Override
public void send(MsgSendDTO msgDTO) {
try {
if(CollectionUtils.isEmpty(msgDTO.getReceiverList())){
log.info("发送语音短信时,没有接收人,短信内容:"+msgDTO.getOriContent());
}
Date now = new Date();
String time = String.valueOf(now.getTime());
Collection<String> receiverList = msgDTO.getReceiverList();
......@@ -67,10 +73,11 @@ public class SmsVoiceSender implements IMsgSender{
JSONObject jsonObject = JSON.parseObject(resStr);
String status = String.valueOf(jsonObject.get("status"));
if (!StringUtils.equals(status, "0")) {
log.error("发送语音短信失败:"+jsonObject.get("status_code"));
throw new BusinessException((String) jsonObject.get("status_code"));
}
}catch (Exception e){
throw new BusinessException(e.getMessage().toString());
log.error("发送语音异常:",e);
}
}
}
......@@ -169,4 +169,22 @@ public class LocalDateTimeUtils {
Long until = start.until(end, ChronoUnit.HOURS);
return until.intValue();
}
public static Integer getDaySub(LocalDateTime start, LocalDateTime end) {
if(start==null || end == null ){
return 0;
}
Long until = start.until(end, ChronoUnit.DAYS);
return until.intValue();
}
/**
* 修改为一天的开始时间,例如:2020-02-02 00:00:00,000
*
* @param time 日期时间
* @return 一天的开始时间
*/
public static LocalDateTime beginOfDay(LocalDateTime time) {
return time.with(LocalTime.MIN);
}
}
package com.makeit.module.controller.children.config;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.dto.saas.SaasPrivacyConfigDTO;
import com.makeit.service.saas.SaasPrivacyConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
* @author lzy
* @date 2022年5月28日
* @description
*/
@Api(tags = "子女端小程序-隐私政策-关于我们")
@RestController
@RequestMapping("/children/sys/privacyConfig")
public class SaasPrivacyConfigChildrenController {
@Autowired
private SaasPrivacyConfigService saasPrivacyConfigService;
@ApiOperation(value = "获取隐私政策-关于我们", notes = "")
@PostMapping("/view")
public ApiResponseEntity<SaasPrivacyConfigDTO> view(@RequestBody SaasPrivacyConfigDTO saasPrivacyConfigDTO){
return ApiResponseUtils.success(saasPrivacyConfigService.view(saasPrivacyConfigDTO.getCategory()));
}
@ApiOperation(value = "获取关于我们", notes = "")
@PostMapping("/viewAbout")
public ApiResponseEntity<SaasPrivacyConfigDTO> viewAbout(@RequestBody SaasPrivacyConfigDTO saasPrivacyConfigDTO){
return ApiResponseUtils.success(saasPrivacyConfigService.view(saasPrivacyConfigDTO.getCategory()));
}
}
......@@ -8,6 +8,7 @@ import com.makeit.dto.platform.space.PlatRoomPanoramaDTO;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.service.platform.space.PlatRoomDynamicService;
import com.makeit.vo.platform.space.PlatBedPanoramaVO;
import com.makeit.vo.platform.space.PlatDeviceElderVO;
import com.makeit.vo.platform.space.PlatRoomPanoramaVO;
import com.makeit.vo.platform.space.PlatSpaceAndRoomVO;
import io.swagger.annotations.Api;
......@@ -64,8 +65,8 @@ public class PlatRoomDynamicController {
@ApiOperation("房间详细-下拉长者")
@PostMapping("elderList")
public ApiResponseEntity<List<PlatElder>> elderList(@RequestBody PlatElderQueryDTO dto) {
List<PlatElder> data = platRoomDynamicService.elderList(dto);
public ApiResponseEntity<List<PlatDeviceElderVO>> elderList(@RequestBody PlatElderQueryDTO dto) {
List<PlatDeviceElderVO> data = platRoomDynamicService.elderList(dto);
return ApiResponseUtils.success(data);
}
......
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRegionSetting;
import com.makeit.entity.platform.space.PlatRoom;
import lombok.Data;
......@@ -27,4 +28,6 @@ public class PlatAlarmCheckDTO {
//PlatAlarmRecord.remark
private String remark;
private PlatRegionSetting platRegionSetting;
}
package com.makeit.dto.platform.alarm;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class PlatDayDurationRecordDTO {
private LocalDateTime start;
private LocalDateTime end;
private List<String> dayStrList;
}
package com.makeit.entity.platform.alarm;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.makeit.common.entity.BaseBusEntity;
import io.swagger.annotations.ApiModelProperty;
......@@ -70,12 +71,15 @@ public class PlatAlarmRecord extends BaseBusEntity {
private String deviceId;
/**
* 老人id,逗号拼接
* 老人id,一个老人一条记录
*/
private String elderIds;
private String remark;
@TableField(exist = false)
private String elderName;
}
......
......@@ -2,6 +2,7 @@ package com.makeit.entity.platform.alarm;
import com.baomidou.mybatisplus.annotation.TableName;
import com.makeit.common.entity.BaseBusEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
......@@ -42,4 +43,14 @@ public class PlatDayDurationRecord extends BaseBusEntity {
* 本次离开时间
*/
private Date endDate;
@ApiModelProperty("区域名称")
private String regionName;
@ApiModelProperty("设备ID")
private String deviceId;
@ApiModelProperty("房间ID")
private String roomId;
}
\ No newline at end of file
......@@ -52,7 +52,9 @@ public class PlatDevice extends BaseBusEntity {
/**
* @see DeviceState
*/
@ApiModelProperty(value = "状态 数据字典 1 在线 0离线 ")
@ApiModelProperty(value = "状态 notActive(\"notActive\",\"禁用\"),\n" +
" offline(\"offline\",\"离线\"),\n" +
" online(\"online\",\"在线\"); ")
private String status;
@ApiModelProperty(value = "组织id")
......
......@@ -2,7 +2,11 @@ package com.makeit.mapper.platform.alarm;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.makeit.dto.platform.alarm.PlatDayDurationRecordDTO;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author lixl
......@@ -13,4 +17,5 @@ import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
public interface PlatDayDurationRecordMapper extends BaseMapper<PlatDayDurationRecord> {
List<PlatDayDurationRecord> getDayMaxDurationList(@Param("param") PlatDayDurationRecordDTO param);
}
......@@ -2,8 +2,11 @@ package com.makeit.service.platform.alarm;
import com.baomidou.mybatisplus.extension.service.IService;
import com.makeit.dto.platform.alarm.PlatDayDurationRecordDTO;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
import java.util.List;
/**
* @author lixl
* @description 针对表【plat_day_duration_record(每天停留时长记录)】的数据库操作Service
......@@ -11,4 +14,5 @@ import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
*/
public interface PlatDayDurationRecordService extends IService<PlatDayDurationRecord> {
List<PlatDayDurationRecord> getDayMaxDurationList(PlatDayDurationRecordDTO param);
}
......@@ -8,16 +8,17 @@ import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.redis.RedisConst;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.utils.AlarmRedisDTO;
import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.redis.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
......@@ -25,33 +26,37 @@ import java.util.Date;
import java.util.List;
@Component
public class BreathAlarm implements IAlarm{
@Slf4j
public class BreathAlarm implements IAlarm {
@Autowired
private PlatAlarmRecordService platAlarmRecordService;
private PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE;
private final PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE;
@Override
public boolean support(String alarmType) {
return StringUtils.equals(alarmType,alarmTypeEnum.getValue());
return StringUtils.equals(alarmType, alarmTypeEnum.getValue());
}
/**
* 2.呼吸异常/心率异常:长者关联的呼吸心率雷达上报的呼吸和心率不在配置的阈值范围内,且满足持续时间进行告警,
* 若该长者在长者管理处有配置阈值,则以长者个人的阈值为准,若无,则以此处配置的通用规则为准
*
* <p>
* 心率呼吸率低于阈值且满足持续时间,则对应状态为呼吸过缓/心率过缓,高于阈值且满足持续时间,
* 对应状态为呼吸过速/心率过速,呼吸心率为0且满足持续时间为呼吸暂停
*
* @param platAlarmCheckDTO
*/
@Override
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
//todo 获取老人健康的阈值
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
String ruleConfigStr = config.getRuleConfig();
JSONObject properties = platAlarmCheckDTO.getProperties();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getOriDeviceId();
if (StringUtils.isBlank(ruleConfigStr)) {
log.info("呼吸告警配置未配置,告警配置id:" + config.getId());
return;
}
String personState = Convert.toStr(properties.get("personState"));
......@@ -62,52 +67,80 @@ public class BreathAlarm implements IAlarm{
Integer start = ruleConfig.getRespiratoryRateStart();
Integer end = ruleConfig.getRespiratoryRateEnd();
Integer duration = ruleConfig.getDuration();
long endLong = new Date().getTime();
Date now = new Date();
long endLong = now.getTime();
//计数
Long startLong = RedisUtil.get(RedisConst.ALARM_DEVICE_ID + deviceId);
if (StringUtils.equals(personState, "0")|| startLong == null) {
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_BR_ID + deviceId);
if (StringUtils.equals(personState, CommonEnum.NO.getValue())) {
RedisUtil.delete(RedisConst.ALARM_DEVICE_BR_ID + deviceId);
return;
}
long count = endLong - startLong;
if (br > end || br < start) {
if (count >= duration) {
if(br>end){
platAlarmCheckDTO.setRemark("呼吸过速");
}
if(br < start){
platAlarmCheckDTO.setRemark("呼吸过缓");
if ((br > end || br < start)) {
if(alarmRedisDTO==null){
alarmRedisDTO = new AlarmRedisDTO();
alarmRedisDTO.setAlarm(CommonEnum.NO.getValue());
alarmRedisDTO.setStart(now);
alarmRedisDTO.setStartLong(endLong);
RedisUtil.set(RedisConst.ALARM_DEVICE_BR_ID + deviceId,alarmRedisDTO);
log.info("发现长者呼吸异常,设备id:"+deviceId);
return;
}
Long startLong = alarmRedisDTO.getStartLong();
long count = endLong - startLong;
if (count/1000 >= duration) {
if (StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) {
log.info("呼吸已告警,设备id:" + platDevice.getId());
return;
}
fillRemark(platAlarmCheckDTO, br, start, end);
notice(platAlarmCheckDTO);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
alarmRedisDTO.setStartLong(endLong);
alarmRedisDTO.setStart(now);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_BR_ID + deviceId, alarmRedisDTO);
}
} else {
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
RedisUtil.delete(RedisConst.ALARM_DEVICE_BR_ID + deviceId);
}
}
private void fillRemark(PlatAlarmCheckDTO platAlarmCheckDTO, int br, Integer start, Integer end) {
if (br > end) {
platAlarmCheckDTO.setRemark("呼吸过速");
}
if (br < start) {
platAlarmCheckDTO.setRemark("呼吸过缓");
}
if (br == 0) {
platAlarmCheckDTO.setRemark("呼吸暂停");
}
return;
}
/**
* [#长者姓名][#呼吸状态],请及时处理!
*
* @param platAlarmCheckDTO
*/
@Override
@Async
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if(CollectionUtils.isEmpty(platElderList)){
if (CollectionUtils.isEmpty(platElderList)) {
log.info("未关联长者,设备id:"+platAlarmCheckDTO.getPlatDevice().getId());
return;
}
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
for (PlatElder platElder : platElderList) {
List<String> param = new ArrayList<>();
param.add(platElder.getName());
param.add(platAlarmCheckDTO.getRemark());
platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord);
platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
}
}
}
......@@ -4,10 +4,16 @@ import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSONObject;
import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO;
import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.redis.RedisConst;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.utils.AlarmRedisDTO;
import com.makeit.utils.redis.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -17,35 +23,47 @@ import java.util.ArrayList;
import java.util.List;
@Component
public class FallAlarm implements IAlarm{
@Slf4j
public class FallAlarm implements IAlarm {
@Autowired
private PlatAlarmRecordService platAlarmRecordService;
private PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.FALL;
private final PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.FALL;
@Override
public boolean support(String alarmType) {
return StringUtils.equals(alarmType,alarmTypeEnum.getValue());
return StringUtils.equals(alarmType, alarmTypeEnum.getValue());
}
/**
* 1.长者跌倒:长者所在空间的跌倒监测雷达上报跌倒,若一个空间内有多为长者,则同时告警多条
*
* @param platAlarmCheckDTO
*/
@Override
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
JSONObject properties = platAlarmCheckDTO.getProperties();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getOriDeviceId();
String personState = Convert.toStr(properties.get("personState"));
if (StringUtils.equals(personState, "1")) {
notice(platAlarmCheckDTO);
AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_FALL_ID + deviceId);
if (StringUtils.equals(personState, CommonEnum.YES.getValue())) {
notice(platAlarmCheckDTO);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_FALL_ID, alarmRedisDTO);
} else {
alarmRedisDTO.setAlarm(CommonEnum.NO.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_FALL_ID, alarmRedisDTO);
}
}
@Override
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if(CollectionUtils.isEmpty(platElderList)){
if (CollectionUtils.isEmpty(platElderList)) {
log.info("跌倒设备未关联长者,设备id:" + platDevice.getId());
return;
}
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
......@@ -55,7 +73,9 @@ public class FallAlarm implements IAlarm{
param.add(platRoom.getName());
platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord);
platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
}
}
}
......@@ -8,16 +8,17 @@ import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.redis.RedisConst;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.utils.AlarmRedisDTO;
import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.redis.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
......@@ -25,25 +26,28 @@ import java.util.Date;
import java.util.List;
@Component
@Slf4j
public class HeartAlarm implements IAlarm {
@Autowired
private PlatAlarmRecordService platAlarmRecordService;
private PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.HEART;
private final PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.HEART;
@Override
public boolean support(String alarmType) {
return StringUtils.equals(alarmType,alarmTypeEnum.getValue());
return StringUtils.equals(alarmType, alarmTypeEnum.getValue());
}
@Override
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
//todo 获取老人健康的阈值
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
String ruleConfigStr = config.getRuleConfig();
JSONObject properties = platAlarmCheckDTO.getProperties();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
String deviceId = platDevice.getOriDeviceId();
if (StringUtils.isBlank(ruleConfigStr)) {
log.info("心率告警配置未配置,告警配置id:" + config.getId());
return;
}
String personState = Convert.toStr(properties.get("personState"));
......@@ -53,47 +57,73 @@ public class HeartAlarm implements IAlarm {
Integer start = ruleConfig.getHeartRateStart();
Integer end = ruleConfig.getHeartRateEnd();
Integer duration = ruleConfig.getDuration();
long endLong = new Date().getTime();
Date now = new Date();
long endLong = now.getTime();
//计数
Long startLong = RedisUtil.get(RedisConst.ALARM_DEVICE_ID + deviceId);
if (StringUtils.equals(personState, "0")|| startLong == null) {
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_HR_ID + deviceId);
if (StringUtils.equals(personState, CommonEnum.NO.getValue())) {
RedisUtil.delete(RedisConst.ALARM_DEVICE_HR_ID + deviceId);
return;
}
long count = endLong - startLong;
if (hr > end || hr < start) {
if (count >= duration) {
if(hr>end){
platAlarmCheckDTO.setRemark("心率过速");
}
if(hr < start){
platAlarmCheckDTO.setRemark("心率过缓");
if ((hr > end || hr < start)) {
if(alarmRedisDTO==null){
alarmRedisDTO = new AlarmRedisDTO();
alarmRedisDTO.setAlarm(CommonEnum.NO.getValue());
alarmRedisDTO.setStart(now);
alarmRedisDTO.setStartLong(endLong);
RedisUtil.set(RedisConst.ALARM_DEVICE_HR_ID + deviceId,alarmRedisDTO);
log.info("发现长者心率异常,设备id:"+deviceId);
return;
}
Long startLong = alarmRedisDTO.getStartLong();
long count = endLong - startLong;
if (count/1000 >= duration) {
if (StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) {
log.info("心率已告警,设备id:" + platDevice.getId());
return;
}
fillRemark(platAlarmCheckDTO, hr, start, end);
notice(platAlarmCheckDTO);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
alarmRedisDTO.setStartLong(endLong);
alarmRedisDTO.setStart(now);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_HR_ID + deviceId, alarmRedisDTO);
}
} else {
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
RedisUtil.delete(RedisConst.ALARM_DEVICE_HR_ID + deviceId);
}
}
private void fillRemark(PlatAlarmCheckDTO platAlarmCheckDTO, int hr, Integer start, Integer end) {
if (hr > end) {
platAlarmCheckDTO.setRemark("心率过快");
}
if (hr < start) {
platAlarmCheckDTO.setRemark("心率过缓");
}
}
@Override
@Async
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if(CollectionUtils.isEmpty(platElderList)){
if (CollectionUtils.isEmpty(platElderList)) {
log.info("跌倒设备未关联长者,设备id:" + platAlarmCheckDTO.getPlatDevice().getId());
return;
}
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
for (PlatElder platElder : platElderList) {
List<String> param = new ArrayList<>();
param.add(platElder.getName());
param.add(platAlarmCheckDTO.getRemark());
platAlarmCheckDTO.setParam(param);
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.convertToPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord);
platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
}
}
}
......@@ -2,11 +2,14 @@ package com.makeit.service.platform.alarm.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.dto.platform.alarm.PlatDayDurationRecordDTO;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
import com.makeit.mapper.platform.alarm.PlatDayDurationRecordMapper;
import com.makeit.service.platform.alarm.PlatDayDurationRecordService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author lixl
* @description 针对表【plat_day_duration_record(每天停留时长记录)】的数据库操作Service实现
......@@ -16,4 +19,8 @@ import org.springframework.stereotype.Service;
public class PlatDayDurationRecordServiceImpl extends ServiceImpl<PlatDayDurationRecordMapper, PlatDayDurationRecord>
implements PlatDayDurationRecordService {
@Override
public List<PlatDayDurationRecord> getDayMaxDurationList(PlatDayDurationRecordDTO param){
return baseMapper.getDayMaxDurationList(param);
}
}
......@@ -7,6 +7,7 @@ import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.auth.PlatUser;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatBed;
import com.makeit.entity.platform.space.PlatSpace;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
......@@ -25,12 +26,17 @@ import com.makeit.service.platform.space.PlatSpaceService;
import com.makeit.utils.area.AreaUtil;
import com.makeit.utils.area.ChinaAreaVO;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.sql.join.JoinUtil;
import com.makeit.vo.platform.dataScreen.*;
import com.makeit.vo.platform.elder.PlatElderListVO;
import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -176,26 +182,46 @@ public class DataScreenServiceImpl implements DataScreenService {
.in(PlatAlarmRecord::getOrgId, dto.getOrgIds()));
List<PlatElder> platElders = platElderService.list();
Map<String,String> elderNameMap = platElders.stream().collect(Collectors.toMap(PlatElder::getId,PlatElder::getName));
Map<String, PlatElderListVO> elderBedPathMap = mapElderBedPath(platElders);
List<PlatAlarmStatisticsListVo> list = new ArrayList<>();
long total = 0;
long handledNumber = 0;
long unhandledNumber = 0;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
DateFormat dft = new SimpleDateFormat("HH:mm:ss");
for (PlatAlarmRecord record : alarmRecords){
if(StringUtil.isNotEmpty(record.getElderIds())){
List<String> elderIds = Arrays.asList(record.getElderIds().split(","));
PlatAlarmStatisticsListVo listVo = new PlatAlarmStatisticsListVo();
String elderName = "";
String pathName = "";
for (String elderId : elderIds){
if(elderNameMap.get(elderId)!=null){
elderName = "".equals(elderName) ? elderNameMap.get(elderId) : elderName + "," + elderNameMap.get(elderId);
}
if(PlatAlarmConfigEnum.AlarmTypeEnum.HEART.getValue().equals(record.getAlarmType()) ||
PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE.getValue().equals(record.getAlarmType()) ){
if(elderBedPathMap.get(elderId)!= null){
pathName = elderBedPathMap.get(elderId).getSpacePathName();
}
}else {
if(elderBedPathMap.get(elderId)!= null){
pathName = "".equals(pathName) ? elderBedPathMap.get(elderId).getSpacePathName()
: pathName + "," + elderBedPathMap.get(elderId).getRoomName();
}
}
}
if(PlatAlarmConfigEnum.AlarmTypeEnum.HEART.getValue().equals(record.getAlarmType()) ||
PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE.getValue().equals(record.getAlarmType()) ){
listVo.setStatus(record.getRemark());
}
listVo.setPath(pathName);
listVo.setElderName(elderName);
listVo.setType(record.getAlarmType());
listVo.setAlarmDate(df.format(record.getAlarmDate()));
listVo.setAlarmTime(dft.format(record.getAlarmDate()));
total ++;
if(PlatAlarmRecordEnum.AlarmRecordStatusEnum.HANDLED.getValue().equals(record.getStatus())){
handledNumber ++;
......@@ -213,6 +239,18 @@ public class DataScreenServiceImpl implements DataScreenService {
return vo;
}
private Map<String, PlatElderListVO> mapElderBedPath(List<PlatElder> platElders) {
List<PlatElderListVO> list = BeanDtoVoUtils.listVo(platElders, PlatElderListVO.class);
JoinUtil.joinSplit(list, platSpaceService, PlatElderListVO::getSpacePath, PlatSpace::getId, (e, l) -> {
e.setSpacePathName(StreamUtil.join(l, Objects::nonNull, PlatSpace::getName, "-"));
});
JoinUtil.join(list, platBedService, PlatElderListVO::getBedId, PlatBed::getId, (e, l) -> {
e.setBedName(l.getName());
});
Map<String, PlatElderListVO> map = list.stream().collect(Collectors.toMap(PlatElderListVO::getBedId, Function.identity()));
return map;
}
@Override
public PlatBaseInfoStatisticsVO baseInfoStatistics(PlatDataScreenQueryDTO dto) {
PlatBaseInfoStatisticsVO vo = new PlatBaseInfoStatisticsVO();
......
......@@ -214,7 +214,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
BeanUtils.copyProperties(dto, db);
db.setId(id);
BeanUtils.copyProperties(dto, other);
BeanUtils.copyProperties(dto, other,BaseEntity.Fields.id);
other.setDeviceId(id);
updateById(db);
......
......@@ -5,6 +5,7 @@ import com.makeit.dto.platform.space.PlatBedPanoramaDTO;
import com.makeit.dto.platform.space.PlatRoomPanoramaDTO;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.vo.platform.space.PlatBedPanoramaVO;
import com.makeit.vo.platform.space.PlatDeviceElderVO;
import com.makeit.vo.platform.space.PlatRoomPanoramaVO;
import com.makeit.vo.platform.space.PlatSpaceAndRoomVO;
......@@ -25,5 +26,5 @@ public interface PlatRoomDynamicService {
List<PlatSpaceAndRoomVO> bedPanoramaTree();
List<PlatElder> elderList(PlatElderQueryDTO dto);
List<PlatDeviceElderVO> elderList(PlatElderQueryDTO dto);
}
......@@ -7,26 +7,22 @@ import com.makeit.dto.platform.space.PlatRoomPanoramaDTO;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatBed;
import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.entity.platform.space.PlatRoomBedDevice;
import com.makeit.entity.platform.space.PlatSpace;
import com.makeit.enums.platform.space.PlatBedPanoramaSpaceType;
import com.makeit.enums.platform.space.PlatRoomStatusEnum;
import com.makeit.service.platform.elder.PlatElderService;
import com.makeit.service.platform.space.PlatBedService;
import com.makeit.service.platform.space.PlatRoomDynamicService;
import com.makeit.service.platform.space.PlatRoomService;
import com.makeit.service.platform.space.PlatSpaceService;
import com.makeit.vo.platform.space.PlatBedPanoramaVO;
import com.makeit.vo.platform.space.PlatRoomPanoramaVO;
import com.makeit.vo.platform.space.PlatRoomVO;
import com.makeit.vo.platform.space.PlatSpaceAndRoomVO;
import com.makeit.service.platform.space.*;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.sql.join.JoinUtil;
import com.makeit.vo.platform.elder.PlatElderListVO;
import com.makeit.vo.platform.space.*;
import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -45,6 +41,8 @@ public class PlatRoomDynamicServiceImpl implements PlatRoomDynamicService {
private PlatBedService platBedService;
@Autowired
private PlatElderService platElderService;
@Autowired
private PlatRoomBedDeviceService platRoomBedDeviceService;
@Override
......@@ -107,19 +105,11 @@ public class PlatRoomDynamicServiceImpl implements PlatRoomDynamicService {
}else if(PlatBedPanoramaSpaceType.BedPanoramaSpaceType.ROOM.getValue().equals(dto.getType())){
list = platBedService.selectByRoomIdAndStatus(dto);
}
List<PlatSpace> spaces = platSpaceService.list();
Map<String,String> spaceNameMap = spaces.stream().collect(Collectors.toMap(PlatSpace::getId,PlatSpace::getName));
JoinUtil.joinSplit(list, platSpaceService, PlatBedPanoramaVO::getSpacePath, PlatSpace::getId, (e, l) -> {
e.setSpacePathName(StreamUtil.join(l, Objects::nonNull, PlatSpace::getName, "-"));
});
list.forEach(vo->{
String spacePathName = "";
if(StringUtil.isNotEmpty(vo.getSpacePath())){
List<String> spaceIds = Arrays.asList(vo.getSpacePath().split(","));
for(String spaceId : spaceIds){
if(spaceNameMap.get(spaceId)!=null && StringUtil.isNotEmpty(spaceNameMap.get(spaceId))){
spacePathName = "".equals(spacePathName) ? spaceNameMap.get(spaceId) : spacePathName + "-" + spaceNameMap.get(spaceId);
}
}
}
String spacePathName = vo.getSpacePathName();
if(StringUtil.isNotEmpty(vo.getRoomName())){
spacePathName = "".equals(spacePathName) ? vo.getRoomName() : spacePathName + "-" + vo.getRoomName();
}
......@@ -171,10 +161,23 @@ public class PlatRoomDynamicServiceImpl implements PlatRoomDynamicService {
}
@Override
public List<PlatElder> elderList(PlatElderQueryDTO dto) {
public List<PlatDeviceElderVO> elderList(PlatElderQueryDTO dto) {
List<PlatElder> list = platElderService.list(new QueryWrapper<PlatElder>().lambda()
.eq(PlatElder::getRoomId, dto.getRoomId()));
return list;
List<String> bedIds = list.stream().map(PlatElder::getBedId).collect(Collectors.toList());
List<PlatDeviceElderVO> voList = BeanDtoVoUtils.listVo(list, PlatDeviceElderVO.class);
if(bedIds.isEmpty()){
List<PlatRoomBedDevice> roomBedDevices = platRoomBedDeviceService.list(new QueryWrapper<PlatRoomBedDevice>()
.lambda()
.in(PlatRoomBedDevice::getBedId, bedIds));
Map<String, String> map = roomBedDevices.stream().collect(Collectors.toMap(PlatRoomBedDevice::getBedId, PlatRoomBedDevice::getDeviceId));
voList.forEach(t->{
if(map.containsKey(t.getBedId())){
t.setDeviceId(map.get(t.getBedId()));
}
});
}
return voList;
}
private PlatSpaceAndRoomVO child(PlatSpaceAndRoomVO vo,Map<String,List<PlatSpaceAndRoomVO>> map){
......
......@@ -20,7 +20,10 @@ import com.makeit.service.platform.space.PlatBedService;
import com.makeit.service.platform.space.PlatRoomService;
import com.makeit.service.platform.space.PlatSpaceService;
import com.makeit.service.platform.workstation.WorkStationService;
import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.sql.join.JoinUtil;
import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeNowVO;
import com.makeit.vo.platform.space.PlatBedPanoramaVO;
import com.makeit.vo.platform.workstation.*;
import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -135,7 +138,6 @@ public class WorkStationServiceImpl implements WorkStationService {
//获取父级的所有子级空间
spaces = platSpaceService.listChild(dto.getSpaceIds());
}
Map<String, String> platSpaceMap = spaces.stream().collect(Collectors.toMap(PlatSpace::getId, PlatSpace::getName));
List<String> elderIdList = new ArrayList<>();
List<PlatAlarmRecord> alarmRecords = platAlarmRecordService.list(
......@@ -165,17 +167,14 @@ public class WorkStationServiceImpl implements WorkStationService {
List<WorkStationInstitutionBedVO> bedVos = platBedService.selectByRoomIds(roomIds);
Map<String, List<WorkStationInstitutionBedVO>> bedMap = bedVos.stream().collect(Collectors.groupingBy(WorkStationInstitutionBedVO::getRoomId));
JoinUtil.joinSplit(roomVOList, platSpaceService, WorkStationInstitutionRoomVO::getSpacePath, PlatSpace::getId, (e, l) -> {
e.setPathName(StreamUtil.join(l, Objects::nonNull, PlatSpace::getName, "-"));
});
for (WorkStationInstitutionRoomVO roomVo : roomVOList) {
WorkStationInstitutionRoomVO vo = new WorkStationInstitutionRoomVO();
String pathName = "";
for (String spaceId : Arrays.asList(roomVo.getSpacePath().split(","))) {
if (platSpaceMap.get(spaceId) != null) {
pathName = "".equals(pathName) ? platSpaceMap.get(spaceId) : pathName + "-" + platSpaceMap.get(spaceId);
}
}
pathName = pathName + "-" + roomVo.getRoomName();
vo.setRoomId(roomVo.getRoomId());
vo.setPathName(pathName);
vo.setPathName(vo.getPathName() + "-" + vo.getRoomName());
if (bedMap.get(roomVo.getRoomId()) != null) {
List<WorkStationInstitutionBedVO> roomBedVos = bedMap.get(roomVo.getRoomId());
//获取告警类型及老人状态
......@@ -308,7 +307,6 @@ public class WorkStationServiceImpl implements WorkStationService {
//获取父级的所有子级空间
spaces = platSpaceService.listChild(dto.getSpaceIds());
}
Map<String, String> platSpaceMap = spaces.stream().collect(Collectors.toMap(PlatSpace::getId, PlatSpace::getName));
List<String> elderIdList = new ArrayList<>();
List<PlatAlarmRecord> alarmRecords = platAlarmRecordService.list(
......@@ -333,15 +331,12 @@ public class WorkStationServiceImpl implements WorkStationService {
List<WorkStationHomeBedVO> list = platBedService.selectByCondition(dto);
JoinUtil.joinSplit(list, platSpaceService, WorkStationHomeBedVO::getSpacePath, PlatSpace::getId, (e, l) -> {
e.setPathName(StreamUtil.join(l, Objects::nonNull, PlatSpace::getName, "-"));
});
for(WorkStationHomeBedVO vo : list){
String pathName = "";
for (String spaceId : Arrays.asList(vo.getSpacePath().split(","))) {
if (platSpaceMap.get(spaceId) != null) {
pathName = "".equals(pathName) ? platSpaceMap.get(spaceId) : pathName + "-" + platSpaceMap.get(spaceId);
}
}
pathName = pathName + "-" + vo.getRoomName();
vo.setPathName(pathName);
vo.setPathName(vo.getPathName() + "-" + vo.getRoomName());
if (StringUtil.isNotEmpty(vo.getElderId()) ) {
if(elderAlarmTypeMap.containsKey(vo.getElderId())){
vo.setAlarmTypeMap(elderAlarmTypeMap.get(vo.getElderId()));
......
package com.makeit.task;
import com.makeit.utils.DayDurationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class DayDurationTask {
@Autowired
private DayDurationUtil dayDurationUtil;
@Scheduled(cron = "0 */1 * * * ?")
public void updateDayDuration() {
dayDurationUtil.getAll();
}
}
......@@ -20,5 +20,8 @@ public class AlarmRedisDTO implements Serializable {
*/
private String alarm = "0";
/**
* 雷达开始上报
*/
private Date start;
}
package com.makeit.utils;
import com.makeit.dto.platform.alarm.PlatDayDurationRecordDTO;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
import com.makeit.enums.redis.RedisConst;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.alarm.PlatDayDurationRecordService;
import com.makeit.utils.redis.RedisUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class DayDurationUtil implements ApplicationRunner {
@Autowired
private PlatDayDurationRecordService platDayDurationRecordService;
public void getAll() {
DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDateTime now = LocalDateTime.now();
List<String> dateStrList = new ArrayList<>();
for (int i = 1; i <= 7 ; i++) {
LocalDateTime dateTime = now.plusDays(-i);
dateStrList.add(yyyyMMdd.format(dateTime));
}
PlatDayDurationRecordDTO platDayDurationRecordDTO = new PlatDayDurationRecordDTO();
platDayDurationRecordDTO.setDayStrList(dateStrList);
List<PlatDayDurationRecord> platDayDurationRecords = platDayDurationRecordService.getDayMaxDurationList(platDayDurationRecordDTO);
if(CollectionUtils.isEmpty(platDayDurationRecords)){
return;
}
Map<String, List<PlatDayDurationRecord>> deviceIdMap = platDayDurationRecords.stream().collect(Collectors.groupingBy(PlatDayDurationRecord::getOriDeviceId));
deviceIdMap.entrySet().stream().map(vo -> {
List<PlatDayDurationRecord> value = vo.getValue();
int size = value.size();
int mid = size / 2;
return value.get(mid);
}).forEach(vo->{
put(vo);
});
return;
}
public void put(PlatDayDurationRecord platDayDurationRecord) {
RedisUtil.set(RedisConst.ELDER_DAY_DURATION_PREFIX + platDayDurationRecord.getOriDeviceId(), platDayDurationRecord);
}
public PlatDayDurationRecord get(String oriDeviceId) {
PlatDayDurationRecord platDayDurationRecord = RedisUtil.get(RedisConst.ELDER_DAY_DURATION_PREFIX + oriDeviceId);
if(platDayDurationRecord==null){
getAll();
}
return RedisUtil.get(RedisConst.ELDER_DAY_DURATION_PREFIX + oriDeviceId);
}
/**
* Callback used to run the bean.
*
* @param args incoming application arguments
* @throws Exception on error
*/
@Override
@TenantIdIgnore
public void run(ApplicationArguments args) throws Exception {
getAll();
}
}
package com.makeit.vo.platform.space;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* Controller
*
* @author zm
* @version 2023/9/8
*/
@Data
@ApiModel("PlatDeviceElderVO参数")
public class PlatDeviceElderVO {
@ApiModelProperty("长者id")
private String id;
@ApiModelProperty("长者姓名")
private String name;
@ApiModelProperty("设备id")
private String deviceId;
@ApiModelProperty("床位id")
private String bedId;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.makeit.mapper.platform.alarm.PlatDayDurationRecordMapper">
<resultMap id="BaseResultMap" type="com.makeit.entity.platform.alarm.PlatDayDurationRecord">
<id property="id" column="id" jdbcType="VARCHAR"/>
<result property="elderIds" column="elder_ids" jdbcType="VARCHAR"/>
<result property="duration" column="duration" jdbcType="VARCHAR"/>
<result property="oriDeviceId" column="ori_device_id" jdbcType="VARCHAR"/>
<result property="day" column="day" jdbcType="VARCHAR"/>
<result property="startDate" column="start_date" jdbcType="TIMESTAMP"/>
<result property="endDate" column="end_date" jdbcType="TIMESTAMP"/>
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
<result property="createDate" column="create_date" jdbcType="TIMESTAMP"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
<result property="updateDate" column="update_date" jdbcType="TIMESTAMP"/>
<result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
<result property="tenantId" column="tenant_id" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id,elder_ids,duration,
ori_device_id,day,start_date,
end_date,create_by,create_date,
update_by,update_date,del_flag,
tenant_id
</sql>
<select id="getDayMaxDurationList" resultType="com.makeit.entity.platform.alarm.PlatDayDurationRecord">
select
pddr.ori_device_id,
pddr.day,
max(pddr.duration) as duration
from plat_day_duration_record pddr
<where>
<if test="param.start != null ">
and pddr.create_date >= #{param.start}
</if>
<if test="param.end != null ">
and pddr.create_date <![CDATA[<= #{param.end}]]>
</if>
<if test="param.dayStrList != null and param.dayStrList.size()>0">
AND pddr.day IN
<foreach collection="param.dayStrList" item="item" separator="," open="(" close=")" index="">
#{item}
</foreach>
</if>
</where>
group by pddr.ori_device_id, pddr.day
order by duration
</select>
</mapper>
......@@ -19,8 +19,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;
import java.util.List;
import java.util.Objects;
@Component
......@@ -68,10 +70,17 @@ public class PushCallback implements MqttCallback {
logger.info("deliveryComplete--------------" + token.isComplete());
}
/**
* 触发告警耗时 3.07s
* 未触发告警耗时 0.08s
* @param device
*/
@TenantIdIgnore
public void checkAlarm(DeviceInfo device) {
StopWatch stopWatch = new StopWatch();
stopWatch.start("checkAlarm-1");
String deviceId = device.getDeviceId();
//String propertiesStr = device.getProperties();
// String propertiesStr = device.getProperties();
// if (StringUtils.isBlank(propertiesStr)) {
// return;
// }
......@@ -81,7 +90,12 @@ public class PushCallback implements MqttCallback {
//iot设备id
PlatDevice platDevice = deviceCacheUtil.get(deviceId);
if(platDevice==null){
logger.info("设备信息异常,设备iot-id:"+deviceId);
return;
}
List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice);
deviceAlarmConfigList.removeIf(Objects::isNull);
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
logger.info("该设备没有告警配置:"+deviceId);
return;
......@@ -103,6 +117,8 @@ public class PushCallback implements MqttCallback {
}
}
}
stopWatch.stop();
logger.info(stopWatch.prettyPrint());
}
......
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