Commit 196e5182 by 杨伟程
parents 5b906468 acb8ffdf
Showing with 429 additions and 45 deletions
...@@ -453,4 +453,21 @@ CREATE TABLE `plafform_setting` ( ...@@ -453,4 +453,21 @@ CREATE TABLE `plafform_setting` (
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COMMENT = '平台设置'; ) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COMMENT = '平台设置';
CREATE TABLE `plat_day_duration_record` (
`id` varchar(64) NOT NULL COMMENT 'id',
`elder_ids` varchar(1024) NOT NULL COMMENT '长者id,逗号拼接',
`duration` bigint(64) NOT NULL COMMENT '当天本次进入该区域的时长',
`ori_device_id` varchar(64) NOT NULL COMMENT 'iot设备id',
`day` varchar(64) NOT NULL COMMENT '日期 yyyyMMdd',
`start_date` datetime DEFAULT NULL COMMENT '本次进入时间',
`end_date` datetime DEFAULT NULL COMMENT '本次离开时间',
`create_by` varchar(64) DEFAULT NULL COMMENT '创建者',
`create_date` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(64) DEFAULT NULL COMMENT '更新者',
`update_date` datetime DEFAULT NULL COMMENT '更新时间',
`del_flag` int(1) DEFAULT '0' COMMENT '删除标记',
`tenant_id` varchar(64) DEFAULT NULL COMMENT ' 租户id ',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='每天停留时长记录';
...@@ -6,7 +6,7 @@ import com.makeit.common.page.PageVO; ...@@ -6,7 +6,7 @@ import com.makeit.common.page.PageVO;
import com.makeit.common.response.ApiResponseEntity; import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils; import com.makeit.common.response.ApiResponseUtils;
import com.makeit.dto.platform.device.PlatDeviceDetailDTO; import com.makeit.dto.platform.device.PlatDeviceDetailDTO;
import com.makeit.dto.platform.device.PlatDeviceEditDTO; import com.makeit.dto.saas.device.PlatDeviceEditSaasDTO;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.global.aspect.tenant.TenantIdIgnore; import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
...@@ -42,8 +42,8 @@ public class SaasDeviceController { ...@@ -42,8 +42,8 @@ public class SaasDeviceController {
@ApiOperation("设备编辑") @ApiOperation("设备编辑")
@PostMapping("edit") @PostMapping("edit")
@TenantIdIgnore @TenantIdIgnore
public ApiResponseEntity<Void> edit(@RequestBody PlatDeviceEditDTO dto) { public ApiResponseEntity<Void> edit(@RequestBody PlatDeviceEditSaasDTO dto) {
platDeviceService.edit(dto); platDeviceService.saasEdit(dto);
return ApiResponseUtils.success(); return ApiResponseUtils.success();
} }
......
package com.makeit.controller.saas; package com.makeit.controller.saas;
import com.alibaba.fastjson.JSONObject;
import com.makeit.common.dto.BaseIdDTO; import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.dto.StatusDTO; import com.makeit.common.dto.StatusDTO;
import com.makeit.common.page.PageReqDTO; import com.makeit.common.page.PageReqDTO;
...@@ -10,8 +11,11 @@ import com.makeit.common.response.ApiResponseUtils; ...@@ -10,8 +11,11 @@ import com.makeit.common.response.ApiResponseUtils;
import com.makeit.global.annotation.Action; import com.makeit.global.annotation.Action;
import com.makeit.module.admin.dto.saas.SaasUserDTOVO; import com.makeit.module.admin.dto.saas.SaasUserDTOVO;
import com.makeit.module.admin.dto.saas.SaasUserQueryDTO; import com.makeit.module.admin.dto.saas.SaasUserQueryDTO;
import com.makeit.service.saas.SaasUserService; import com.makeit.module.admin.vo.plat.PlatUserLoginVO;
import com.makeit.module.admin.vo.saas.SaasUserLoginVO; import com.makeit.module.admin.vo.saas.SaasUserLoginVO;
import com.makeit.service.saas.SaasUserService;
import com.makeit.utils.user.ThreadLocalUserUtil;
import com.makeit.utils.user.wechat.WechatUserInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -130,5 +134,18 @@ public class SaasUserController { ...@@ -130,5 +134,18 @@ public class SaasUserController {
return ApiResponseUtils.success(saasUserService.getUserVO()); return ApiResponseUtils.success(saasUserService.getUserVO());
} }
@ApiOperation("获取当前登录用户的用户信息2")
@PostMapping("getUserVOFromTH")
public ApiResponseEntity<JSONObject> getUserInfo2(){
PlatUserLoginVO sysUserLoginVO = ThreadLocalUserUtil.getTntUser();
WechatUserInfo wechatUserInfo = ThreadLocalUserUtil.getWechatUser();
SaasUserLoginVO saasUser = ThreadLocalUserUtil.getSaasUser();
JSONObject jsonObject = new JSONObject();
jsonObject.put("sysUserLoginVO",sysUserLoginVO);
jsonObject.put("wechatUserInfo",wechatUserInfo);
jsonObject.put("saasUser",sysUserLoginVO);
return ApiResponseUtils.success(jsonObject);
}
} }
...@@ -34,8 +34,9 @@ public class TenantIdUtil { ...@@ -34,8 +34,9 @@ public class TenantIdUtil {
public static String getTenantId() { public static String getTenantId() {
List<Supplier<String>> supplierList = Arrays.asList( List<Supplier<String>> supplierList = Arrays.asList(
//TenantIdUtil::getFromThreadLocal, TenantIdUtil::getFromThreadLocal,
TenantIdUtil::getFromHeader//, TenantIdUtil::getFromHeader
); );
for (Supplier<String> supplier : supplierList) { for (Supplier<String> supplier : supplierList) {
......
...@@ -127,7 +127,7 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -127,7 +127,7 @@ public class IotProductDeviceService extends IotCommonService {
public List<DeviceInfoContentBreathe> getDeviceLogByTimeRangeBreathe(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) { public List<DeviceInfoContentBreathe> getDeviceLogByTimeRangeBreathe(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
List<DeviceOperationLogEntity> deviceOperationLogEntityList = getDeviceLogByTimeRange(deviceId, "reportProperty", pageSize, dateTimeFormatter.format(startTime), dateTimeFormatter.format(endTime)); List<DeviceOperationLogEntity> deviceOperationLogEntityList = getDeviceLogByTimeRange(deviceId, "event", pageSize, dateTimeFormatter.format(startTime), dateTimeFormatter.format(endTime));
List<DeviceInfoContentBreathe> deviceInfoContentBreatheList = StreamUtil.map(deviceOperationLogEntityList, e -> JsonUtil.toObj((String) e.getContent(), DeviceInfoContentBreathe.class)); List<DeviceInfoContentBreathe> deviceInfoContentBreatheList = StreamUtil.map(deviceOperationLogEntityList, e -> JsonUtil.toObj((String) e.getContent(), DeviceInfoContentBreathe.class));
...@@ -137,7 +137,7 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -137,7 +137,7 @@ public class IotProductDeviceService extends IotCommonService {
public List<DeviceInfoContentSpace> getDeviceLogByTimeRangeSpace(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) { public List<DeviceInfoContentSpace> getDeviceLogByTimeRangeSpace(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
List<DeviceOperationLogEntity> deviceOperationLogEntityList = getDeviceLogByTimeRange(deviceId, "reportProperty", pageSize, dateTimeFormatter.format(startTime), dateTimeFormatter.format(endTime)); List<DeviceOperationLogEntity> deviceOperationLogEntityList = getDeviceLogByTimeRange(deviceId, "event", pageSize, dateTimeFormatter.format(startTime), dateTimeFormatter.format(endTime));
List<DeviceInfoContentSpace> deviceInfoContentSpaceList = StreamUtil.map(deviceOperationLogEntityList, e -> JsonUtil.toObj((String) e.getContent(), DeviceInfoContentSpace.class)); List<DeviceInfoContentSpace> deviceInfoContentSpaceList = StreamUtil.map(deviceOperationLogEntityList, e -> JsonUtil.toObj((String) e.getContent(), DeviceInfoContentSpace.class));
...@@ -198,16 +198,6 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -198,16 +198,6 @@ public class IotProductDeviceService extends IotCommonService {
IotQueryParam iotQueryParam = buildQueryParam(pageSize); IotQueryParam iotQueryParam = buildQueryParam(pageSize);
List<Term> terms = Lists.newArrayList(); List<Term> terms = Lists.newArrayList();
Term term = Term.builder()
.column("type")
.termType("btw")
.type(Term.Type.or)
.value(typeValue)
.terms(Lists.newArrayList())
.options(Lists.newArrayList())
.build();
terms.add(term);
Term term1 = Term.builder() Term term1 = Term.builder()
.column("timestamp") .column("timestamp")
.termType("gte") .termType("gte")
...@@ -224,6 +214,15 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -224,6 +214,15 @@ public class IotProductDeviceService extends IotCommonService {
.terms(Lists.newArrayList()) .terms(Lists.newArrayList())
.options(Lists.newArrayList()) .options(Lists.newArrayList())
.build(); .build();
Term term3 = Term.builder()
.column("type")
.termType("eq")
.type(Term.Type.or)
.value(typeValue)
.terms(Lists.newArrayList())
.options(Lists.newArrayList())
.build();
terms.add(term3);
terms.add(term1); terms.add(term1);
terms.add(term2); terms.add(term2);
iotQueryParam.setTerms(terms); iotQueryParam.setTerms(terms);
...@@ -259,7 +258,7 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -259,7 +258,7 @@ public class IotProductDeviceService extends IotCommonService {
List<Term> terms = Lists.newArrayList(); List<Term> terms = Lists.newArrayList();
Term term = Term.builder() Term term = Term.builder()
.column("type") .column("type")
.termType("btw") .termType("eq")
.type(Term.Type.or) .type(Term.Type.or)
.value(typeValue) .value(typeValue)
.terms(Lists.newArrayList()) .terms(Lists.newArrayList())
......
...@@ -61,7 +61,7 @@ public class PlatDeviceController { ...@@ -61,7 +61,7 @@ public class PlatDeviceController {
@Autowired @Autowired
private IotSyncTask iotSyncTask; private IotSyncTask iotSyncTask;
@ApiOperation("详情") @ApiOperation("手动同步")
@PostMapping("iotSyncTask") @PostMapping("iotSyncTask")
@AuthIgnore @AuthIgnore
@TenantIdIgnore @TenantIdIgnore
......
package com.makeit.dto.platform.alarm; package com.makeit.dto.platform.alarm;
import com.makeit.common.dto.BaseTenantDTO; import com.makeit.common.dto.BaseTenantDTO;
import com.makeit.common.entity.BaseBusEntity;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum; import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.global.validator.DictEnum; import com.makeit.global.validator.DictEnum;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -47,13 +46,13 @@ public class PlatAlarmConfigDTOVO extends BaseTenantDTO { ...@@ -47,13 +46,13 @@ public class PlatAlarmConfigDTOVO extends BaseTenantDTO {
@ApiModelProperty(value = "规则配置") @ApiModelProperty(value = "规则配置")
private String ruleConfig; private String ruleConfig;
@ApiModelProperty(value = "心率异常") @ApiModelProperty(value = "呼吸异常")
private PlatAlarmConfigRespiratoryDTOVO respiratory; private PlatAlarmConfigRespiratoryDTOVO respiratory;
@ApiModelProperty(value = "心率异常") @ApiModelProperty(value = "心率异常")
private PlatAlarmConfigHeartDTOVO heart; private PlatAlarmConfigHeartDTOVO heart;
@ApiModelProperty(value = "心率异常") @ApiModelProperty(value = "行为异常")
private PlatAlarmConfigBehaviorDTOVO behavior; private PlatAlarmConfigBehaviorDTOVO behavior;
@ApiModelProperty(value = "内容") @ApiModelProperty(value = "内容")
......
package com.makeit.dto.saas.device;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.makeit.common.dto.BaseTenantDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
/**
* <p>
* 设备
* </p>
*
* @author eugene young
* @since 2023-09-05
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "PlatDevice对象", description = "设备")
public class PlatDeviceEditSaasDTO extends BaseTenantDTO {
@NotBlank(message = "设备名称不能为空")
@Size(max = 50, message = "设备名称最长为50个字符")
@ApiModelProperty(value = "设备名称")
private String name;
@ApiModelProperty(value = "设备安装方式")
private String installation;
@ApiModelProperty(value = "开关指示灯")
private String indicatorLight;
@ApiModelProperty(value = "设备属性json")
private String attribute;
@ApiModelProperty(value = "说明")
private String description;
@ApiModelProperty(value = "有效期-开始")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startDate;
@ApiModelProperty(value = "有效期-结束")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endDate;
}
package com.makeit.entity.platform.alarm;
import com.baomidou.mybatisplus.annotation.TableName;
import com.makeit.common.entity.BaseBusEntity;
import lombok.Data;
import java.util.Date;
/**
* 每天停留时长记录
* @TableName plat_day_duration_record
*/
@TableName(value ="plat_day_duration_record")
@Data
public class PlatDayDurationRecord extends BaseBusEntity {
/**
* 长者id,逗号拼接
*/
private String elderIds;
/**
* 当天本次进入该区域的时长
*/
private Long duration;
/**
* iot设备id
*/
private String oriDeviceId;
/**
* 日期 yyyyMMdd
*/
private String day;
/**
* 本次进入时间
*/
private Date startDate;
/**
* 本次离开时间
*/
private Date endDate;
}
\ No newline at end of file
package com.makeit.entity.platform.device; package com.makeit.entity.platform.device;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.makeit.common.entity.BaseBusEntity; import com.makeit.common.entity.BaseBusEntity;
import com.makeit.module.iot.enums.DeviceState; import com.makeit.module.iot.enums.DeviceState;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -72,7 +73,10 @@ public class PlatDevice extends BaseBusEntity { ...@@ -72,7 +73,10 @@ public class PlatDevice extends BaseBusEntity {
@ApiModelProperty(value = "设备类型 0-呼吸心率雷达 1-空间人体雷达 2-跌倒检测雷达") @ApiModelProperty(value = "设备类型 0-呼吸心率雷达 1-空间人体雷达 2-跌倒检测雷达")
private String category; private String category;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startDate; private LocalDateTime startDate;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endDate; private LocalDateTime endDate;
......
...@@ -3,6 +3,7 @@ package com.makeit.entity.platform.elder; ...@@ -3,6 +3,7 @@ package com.makeit.entity.platform.elder;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.makeit.common.entity.BaseBusEntity; import com.makeit.common.entity.BaseBusEntity;
import com.makeit.common.typehandler.ListStringJsonTypeHandler; import com.makeit.common.typehandler.ListStringJsonTypeHandler;
import com.makeit.typehandler.ElderListStringJsonTypeHandler;
import com.makeit.vo.platform.elder.report.day.PlatSleepRangeVO; import com.makeit.vo.platform.elder.report.day.PlatSleepRangeVO;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
...@@ -40,7 +41,7 @@ public class PlatElderSleep extends BaseBusEntity { ...@@ -40,7 +41,7 @@ public class PlatElderSleep extends BaseBusEntity {
private String currentDate; private String currentDate;
@ApiModelProperty(value = "睡眠记录 区分时间段记录 [{\"sleepType\":\"\",\"startTime\":\"\",\"endTime\":\"\"},{}]") @ApiModelProperty(value = "睡眠记录 区分时间段记录 [{\"sleepType\":\"\",\"startTime\":\"\",\"endTime\":\"\"},{}]")
@TableField(typeHandler = ListStringJsonTypeHandler.class) @TableField(typeHandler = ElderListStringJsonTypeHandler.class)
private List<PlatSleepRangeVO> sleepRecord; private List<PlatSleepRangeVO> sleepRecord;
......
package com.makeit.mapper.platform.alarm;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
/**
* @author lixl
* @description 针对表【plat_day_duration_record(每天停留时长记录)】的数据库操作Mapper
* @createDate 2023-09-14 10:14:20
* @Entity generator.entity.PlatDayDurationRecord
*/
public interface PlatDayDurationRecordMapper extends BaseMapper<PlatDayDurationRecord> {
}
package com.makeit.service.platform.alarm;
import com.baomidou.mybatisplus.extension.service.IService;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
/**
* @author lixl
* @description 针对表【plat_day_duration_record(每天停留时长记录)】的数据库操作Service
* @createDate 2023-09-14 10:14:20
*/
public interface PlatDayDurationRecordService extends IService<PlatDayDurationRecord> {
}
...@@ -2,16 +2,21 @@ package com.makeit.service.platform.alarm.alarmStrategy; ...@@ -2,16 +2,21 @@ package com.makeit.service.platform.alarm.alarmStrategy;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.makeit.common.entity.BaseEntity;
import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO; import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO;
import com.makeit.dto.platform.alarm.PlatAlarmConfigBehaviorDTOVO; import com.makeit.dto.platform.alarm.PlatAlarmConfigBehaviorDTOVO;
import com.makeit.entity.platform.alarm.PlatAlarmConfig; import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.alarm.PlatAlarmRecord; import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.alarm.PlatDayDurationRecord;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder; import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatRoom; import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum; import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.redis.RedisConst; import com.makeit.enums.redis.RedisConst;
import com.makeit.service.platform.alarm.PlatAlarmRecordService; import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.service.platform.alarm.PlatDayDurationRecordService;
import com.makeit.utils.AlarmRedisDTO;
import com.makeit.utils.data.convert.JsonUtil; import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.redis.RedisUtil; import com.makeit.utils.redis.RedisUtil;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
...@@ -20,15 +25,21 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -20,15 +25,21 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Component @Component
public class BehaviorAlarm implements IAlarm{ public class BehaviorAlarm implements IAlarm{
@Autowired @Autowired
private PlatAlarmRecordService platAlarmRecordService; private PlatAlarmRecordService platAlarmRecordService;
@Autowired
private PlatDayDurationRecordService platDayDurationRecordService;
private PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.BEHAVIOR; private PlatAlarmConfigEnum.AlarmTypeEnum alarmTypeEnum = PlatAlarmConfigEnum.AlarmTypeEnum.BEHAVIOR;
...@@ -39,6 +50,9 @@ public class BehaviorAlarm implements IAlarm{ ...@@ -39,6 +50,9 @@ public class BehaviorAlarm implements IAlarm{
/** /**
* 3.行为异常:若长者当在某个空间停留的时间高于长者最近7天在每个空间区域停留时间的平均值+区间(区间在行为异常告警处配置) * 3.行为异常:若长者当在某个空间停留的时间高于长者最近7天在每个空间区域停留时间的平均值+区间(区间在行为异常告警处配置)
* 取前七天的日最长时间,然后取中位数
* 前七天:没有满足七条记录则跳过,如果七条没都包含长者则跳过
* 记录的保存和缓存读取
* @param platAlarmCheckDTO * @param platAlarmCheckDTO
*/ */
@Override @Override
...@@ -53,33 +67,74 @@ public class BehaviorAlarm implements IAlarm{ ...@@ -53,33 +67,74 @@ public class BehaviorAlarm implements IAlarm{
} }
String personState = Convert.toStr(properties.get("personState")); String personState = Convert.toStr(properties.get("personState"));
PlatAlarmConfigBehaviorDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigBehaviorDTOVO.class); PlatAlarmConfigBehaviorDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigBehaviorDTOVO.class);
Integer duration = ruleConfig.getDuration(); Integer duration = ruleConfig.getDuration();//分钟
duration = duration*60; duration = duration*60;
//todo duration+平均停留时长 //todo duration+平均停留时长
List<String> personStateList = Arrays.asList("1", "2", "3"); List<String> personStateList = Arrays.asList("1", "2", "3");
//有人 //有人
//计数 //计数
long endLong = new Date().getTime(); Date now = new Date();
Long startLong = RedisUtil.get(RedisConst.ALARM_DEVICE_ID + deviceId); long endLong = now.getTime();
AlarmRedisDTO alarmRedisDTO = RedisUtil.get(RedisConst.ALARM_DEVICE_ID + deviceId);
if(alarmRedisDTO==null){
alarmRedisDTO= new AlarmRedisDTO();
}
//有人
if (personStateList.contains(personState)) { if (personStateList.contains(personState)) {
long count = endLong - startLong; //第一次进入空间
Long startLong = alarmRedisDTO.getStartLong();
if(startLong == null ){ if(startLong == null ){
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong); alarmRedisDTO.setStartLong(endLong);
alarmRedisDTO.setStart(now);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,alarmRedisDTO);
return; return;
} }
if (count >= duration) { long count = endLong - startLong;
//进入空间时间满足告警时长,判断是否已经告警过了
if (count/1000 >= duration && StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.NO.getValue())) {
notice(platAlarmCheckDTO); notice(platAlarmCheckDTO);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,startLong); alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,alarmRedisDTO);
}
}else {//没人
// 是否有第一次进入记录,有则保存db
Long startLong = alarmRedisDTO.getStartLong();
if(startLong==null){
return;
} }
}else { //保存每次进入空间时长
// saveDayDurationRecord(platAlarmCheckDTO,alarmRedisDTO);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,null); RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,null);
} }
} }
private void saveDayDurationRecord(PlatAlarmCheckDTO platAlarmCheckDTO, AlarmRedisDTO alarmRedisDTO) {
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
Date now = new Date();
long endLong = now.getTime();
Long startLong = alarmRedisDTO.getStartLong();
long count = endLong - alarmRedisDTO.getStartLong();
//save db
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
PlatDayDurationRecord durationRecord = new PlatDayDurationRecord();
durationRecord.setElderIds(platElderList.stream().map(BaseEntity::getId).collect(Collectors.joining(",")));
durationRecord.setDuration(count);
durationRecord.setOriDeviceId(platDevice.getOriDeviceId());
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
durationRecord.setDay(dateTimeFormatter.format( LocalDateTime.ofEpochSecond(startLong /1000, 0, ZoneOffset.ofHours(8))));
durationRecord.setStartDate(alarmRedisDTO.getStart());
durationRecord.setEndDate(now);
durationRecord.setTenantId(config.getTenantId());
platDayDurationRecordService.saveOrUpdate(durationRecord);
}
@Override @Override
@Async @Async
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) { public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
//获取长者 空间信息
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO); platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList(); List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if(CollectionUtils.isEmpty(platElderList)){ if(CollectionUtils.isEmpty(platElderList)){
......
...@@ -177,6 +177,7 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe ...@@ -177,6 +177,7 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe
@Transactional @Transactional
@Override @Override
//@TenantIdIgnore
public void copyForOrg(PlatOrg org) { public void copyForOrg(PlatOrg org) {
List<PlatAlarmConfig> configList = TenantIdUtil.execute(IdConst.DEFAULT_TENANT_ID, () -> list()); List<PlatAlarmConfig> configList = TenantIdUtil.execute(IdConst.DEFAULT_TENANT_ID, () -> list());
...@@ -190,20 +191,23 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe ...@@ -190,20 +191,23 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe
String[] split = orgPath.split(","); String[] split = orgPath.split(",");
configList.forEach(e -> { TenantIdUtil.execute(org.getTenantId(),()->{
e.setId(null); configList.forEach(e -> {
e.setTenantId(org.getTenantId());
e.setId(null);
for (int i = 1; i < split.length; i++) { for (int i = 1; i < split.length; i++) {
BiConsumer<PlatAlarmConfig, String> consumer = list.get(i - 1); BiConsumer<PlatAlarmConfig, String> consumer = list.get(i - 1);
consumer.accept(e, split[i]); consumer.accept(e, split[i]);
} }
e.setOrgId(org.getId()); e.setOrgId(org.getId());
e.setOrgPath(orgPath); e.setOrgPath(orgPath);
}); });
saveBatch(configList); saveBatch(configList);
});
alarmConfigUtil.putAll(configList); alarmConfigUtil.putAll(configList);
} }
......
package com.makeit.service.platform.alarm.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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;
/**
* @author lixl
* @description 针对表【plat_day_duration_record(每天停留时长记录)】的数据库操作Service实现
* @createDate 2023-09-14 10:14:20
*/
@Service
public class PlatDayDurationRecordServiceImpl extends ServiceImpl<PlatDayDurationRecordMapper, PlatDayDurationRecord>
implements PlatDayDurationRecordService {
}
...@@ -6,6 +6,7 @@ import com.makeit.common.page.PageVO; ...@@ -6,6 +6,7 @@ import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.device.PlatDeviceDetailDTO; import com.makeit.dto.platform.device.PlatDeviceDetailDTO;
import com.makeit.dto.platform.device.PlatDeviceEditDTO; import com.makeit.dto.platform.device.PlatDeviceEditDTO;
import com.makeit.dto.platform.device.PlatDeviceQueryDTO; import com.makeit.dto.platform.device.PlatDeviceQueryDTO;
import com.makeit.dto.saas.device.PlatDeviceEditSaasDTO;
import com.makeit.dto.wechat.device.PlatDeviceEditWechatDTO; import com.makeit.dto.wechat.device.PlatDeviceEditWechatDTO;
import com.makeit.dto.wechat.device.PlatDeviceSetupDTO; import com.makeit.dto.wechat.device.PlatDeviceSetupDTO;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
...@@ -49,4 +50,6 @@ public interface PlatDeviceService extends IService<PlatDevice> { ...@@ -49,4 +50,6 @@ public interface PlatDeviceService extends IService<PlatDevice> {
* @return * @return
*/ */
PlatDeviceDetailDTO getDetailDTO(String deviceId); PlatDeviceDetailDTO getDetailDTO(String deviceId);
void saasEdit(PlatDeviceEditSaasDTO dto);
} }
...@@ -11,6 +11,7 @@ import com.makeit.common.page.PageVO; ...@@ -11,6 +11,7 @@ import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.device.PlatDeviceDetailDTO; import com.makeit.dto.platform.device.PlatDeviceDetailDTO;
import com.makeit.dto.platform.device.PlatDeviceEditDTO; import com.makeit.dto.platform.device.PlatDeviceEditDTO;
import com.makeit.dto.platform.device.PlatDeviceQueryDTO; import com.makeit.dto.platform.device.PlatDeviceQueryDTO;
import com.makeit.dto.saas.device.PlatDeviceEditSaasDTO;
import com.makeit.dto.wechat.device.PlatDeviceEditWechatDTO; import com.makeit.dto.wechat.device.PlatDeviceEditWechatDTO;
import com.makeit.dto.wechat.device.PlatDeviceSetupDTO; import com.makeit.dto.wechat.device.PlatDeviceSetupDTO;
import com.makeit.entity.platform.auth.PlatOrg; import com.makeit.entity.platform.auth.PlatOrg;
...@@ -190,6 +191,31 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -190,6 +191,31 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
return PageUtil.toPageVO(devicePage); return PageUtil.toPageVO(devicePage);
} }
@Override
public void saasEdit(PlatDeviceEditSaasDTO dto) {
PlatDevice db = getById(dto.getId());
String id = db.getId();
PlatDeviceOther other = platDeviceOtherService.getOne(new QueryWrapper<PlatDeviceOther>().lambda()
.eq(PlatDeviceOther::getDeviceId, db.getId()));
if (other == null) {
other = new PlatDeviceOther();
}
BeanUtils.copyProperties(dto, db);
db.setId(id);
BeanUtils.copyProperties(dto, other);
other.setDeviceId(id);
updateById(db);
deviceCacheUtil.put(db);
platDeviceOtherService.saveOrUpdate(other);
}
/** /**
* 设备信息 * 设备信息
* *
......
/*
* Copyright (c) 2011-2021, baomidou (jobob@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.makeit.typehandler;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.makeit.vo.platform.elder.report.day.PlatSleepRangeVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import java.io.IOException;
import java.util.List;
/**
* Jackson 实现 JSON 字段类型处理器
*
* @author hubin
* @since 2019-08-25
*/
@Slf4j
@MappedTypes({List.class})
@MappedJdbcTypes(JdbcType.VARCHAR)
public class ElderListStringJsonTypeHandler extends AbstractJsonTypeHandler<List> {
private static ObjectMapper OBJECT_MAPPER;
@Override
protected List<PlatSleepRangeVO> parse(String json) {
try {
return getObjectMapper().readValue(json, new TypeReference<List<PlatSleepRangeVO>>() {
});
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
protected String toJson(List obj) {
try {
return getObjectMapper().writeValueAsString(obj);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
public static ObjectMapper getObjectMapper() {
if (null == OBJECT_MAPPER) {
OBJECT_MAPPER = new ObjectMapper();
}
return OBJECT_MAPPER;
}
public static void setObjectMapper(ObjectMapper objectMapper) {
Assert.notNull(objectMapper, "ObjectMapper should not be null");
ElderListStringJsonTypeHandler.OBJECT_MAPPER = objectMapper;
}
}
package com.makeit.utils;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class AlarmRedisDTO implements Serializable {
private static final long serialVersionUID = -1136022758968665492L;
/**
* 雷达第一次记录时间/进入空间时间
*/
private Long startLong;
/**
* 是否告警过 0-未告警 1-告警了
*/
private String alarm = "0";
private Date start;
}
...@@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.enums.redis.RedisConst; import com.makeit.enums.redis.RedisConst;
import com.makeit.global.aspect.tenant.TenantIdIgnore; import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.iot.enums.DeviceState;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.utils.redis.RedisUtil; import com.makeit.utils.redis.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
...@@ -21,7 +23,7 @@ public class DeviceCacheUtil implements ApplicationRunner { ...@@ -21,7 +23,7 @@ public class DeviceCacheUtil implements ApplicationRunner {
private PlatDeviceService platDeviceService; private PlatDeviceService platDeviceService;
public List<PlatDevice> getAll() { public List<PlatDevice> getAll() {
List<PlatDevice> list = platDeviceService.list(new LambdaQueryWrapper<PlatDevice>()); List<PlatDevice> list = platDeviceService.list(new LambdaQueryWrapper<PlatDevice>().eq(PlatDevice::getStatus,DeviceState.online.getValue()));
list.stream().forEach(vo -> { list.stream().forEach(vo -> {
put(vo); put(vo);
}); });
...@@ -29,7 +31,11 @@ public class DeviceCacheUtil implements ApplicationRunner { ...@@ -29,7 +31,11 @@ public class DeviceCacheUtil implements ApplicationRunner {
} }
public void put(PlatDevice platDevice) { public void put(PlatDevice platDevice) {
RedisUtil.set(RedisConst.PLAT_IOT_DEVICE_PREFIX+platDevice.getOriDeviceId(), platDevice); if(StringUtils.equals(platDevice.getStatus(),DeviceState.online.getValue())) {
RedisUtil.set(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId(), platDevice);
}else {
RedisUtil.delete(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId());
}
} }
public PlatDevice get(String oriDeviceId) { public PlatDevice get(String oriDeviceId) {
......
...@@ -83,6 +83,7 @@ public class PushCallback implements MqttCallback { ...@@ -83,6 +83,7 @@ public class PushCallback implements MqttCallback {
PlatDevice platDevice = deviceCacheUtil.get(deviceId); PlatDevice platDevice = deviceCacheUtil.get(deviceId);
List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice); List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice);
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) { if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
logger.info("该设备没有告警配置:"+deviceId);
return; return;
} }
for (PlatAlarmConfig config : deviceAlarmConfigList) { for (PlatAlarmConfig config : deviceAlarmConfigList) {
......
...@@ -147,6 +147,7 @@ tenant: ...@@ -147,6 +147,7 @@ tenant:
- plat_tenant_menu - plat_tenant_menu
- plat_user - plat_user
- plat_menu - plat_menu
- plat_day_duration_record
rsa: rsa:
......
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