Commit 39d09828 by huangjy

Merge remote-tracking branch 'origin/dev' into dev

parents 90ec7ecf 59b44526
Showing with 142 additions and 68 deletions
......@@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.Map;
@Data
@ApiModel("excel导入错误信息VO")
......@@ -52,9 +52,17 @@ public class ExcelErrorVo implements Serializable {
}
}
public static void notExists(Object object,List<ExcelErrorVo> errorVoList,int i,String title){
if(Objects.isNull(object)){
public static void notExists(String value,List<ExcelErrorVo> errorVoList,int i,String title){
if(StringUtils.isBlank(value)){
errorVoList.add(new ExcelErrorVo(i,title,"数据库数据不存在"));
}
}
public static void exists(Map<String, String> emailMap,String value, List<ExcelErrorVo> errorVoList, int i, String title){
if(StringUtils.isNotBlank(value)){
errorVoList.add(new ExcelErrorVo(i,title,"数据重复"));
}else {
emailMap.put(value,"system");
}
}
}
package com.makeit.module.iot.vo;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
/**
......@@ -17,7 +18,7 @@ public class DeviceInfo {
private HeaderInfo headers;
private String properties;
private JSONObject properties;
/**
......
......@@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
@Api(tags = "子女端小程序-告警记录")
@RestController
@RequestMapping("/children/alarm-record")
public class ChildrenAlarmRecordController {
public class PlatAlarmRecordChildrenController {
@Autowired
private PlatAlarmRecordService platAlarmRecordService;
......
......@@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
@Api(tags = "小程序-告警记录")
@RestController
@RequestMapping("/wechat/plat/alarm-record")
public class WechatPlatAlarmRecordController {
public class PlatAlarmRecordWechatController {
@Autowired
private PlatAlarmRecordService platAlarmRecordService;
......
......@@ -23,15 +23,15 @@ public class PlatUserImportDTO {
private String mobile;
@ExcelProperty(value = "邮箱")
private String email;
@ExcelProperty(value = "所属组织*")
@ExcelProperty(value = "*所属组织")
private String orgName;
@ExcelProperty(value = "角色*")
@ExcelProperty(value = "*角色")
private String roleName;
@ExcelProperty(value = "备注")
private String remark;
@ExcelIgnore
private String password = "888888";
private String password = "abc888888";
}
......@@ -63,4 +63,6 @@ public class PlatOrg extends BaseBusEntity {
@TableField(exist = false)
private PlatOrg parent;
private String remark;
}
\ No newline at end of file
......@@ -55,4 +55,6 @@ public interface PlatAlarmRecordService extends IService<PlatAlarmRecord> {
void noticeDeviceAlarm(PlatAlarmConfig alarmConfig, PlatAlarmRecord alarmRecord);
PlatAlarmRecord createPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO);
PlatAlarmCheckDTO getElderListByDeviceId(PlatAlarmCheckDTO platAlarmCheckDTO);
}
......@@ -13,6 +13,7 @@ import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.redis.RedisUtil;
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.Arrays;
......@@ -31,8 +32,12 @@ public class BehaviorAlarm implements IAlarm{
return StringUtils.equals(alarmType,alarmTypeEnum.getValue());
}
/**
* 3.行为异常:若长者当在某个空间停留的时间高于长者最近7天在每个空间区域停留时间的平均值+区间(区间在行为异常告警处配置)
* @param platAlarmCheckDTO
*/
@Override
public void createPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO) {
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
String ruleConfigStr = config.getRuleConfig();
JSONObject properties = platAlarmCheckDTO.getProperties();
......@@ -58,9 +63,7 @@ public class BehaviorAlarm implements IAlarm{
return;
}
if (count >= duration) {
platAlarmCheckDTO.getParam().add("房间名");
PlatAlarmRecord platAlarmRecord =platAlarmRecordService.createPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord);
notice(platAlarmCheckDTO);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,startLong);
}
}else {
......@@ -68,4 +71,13 @@ public class BehaviorAlarm implements IAlarm{
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,null);
}
}
@Override
@Async
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
platAlarmCheckDTO.getParam().add("房间名");
PlatAlarmRecord platAlarmRecord =platAlarmRecordService.createPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord);
}
}
......@@ -13,6 +13,7 @@ import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.redis.RedisUtil;
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.Date;
......@@ -29,8 +30,16 @@ public class BreathAlarm implements IAlarm{
return StringUtils.equals(alarmType,alarmTypeEnum.getValue());
}
/**
* 2.呼吸异常/心率异常:长者关联的呼吸心率雷达上报的呼吸和心率不在配置的阈值范围内,且满足持续时间进行告警,
* 若该长者在长者管理处有配置阈值,则以长者个人的阈值为准,若无,则以此处配置的通用规则为准
*
* 心率呼吸率低于阈值且满足持续时间,则对应状态为呼吸过缓/心率过缓,高于阈值且满足持续时间,
* 对应状态为呼吸过速/心率过速,呼吸心率为0且满足持续时间为呼吸暂停
* @param platAlarmCheckDTO
*/
@Override
public void createPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO) {
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
String ruleConfigStr = config.getRuleConfig();
JSONObject properties = platAlarmCheckDTO.getProperties();
......@@ -57,9 +66,7 @@ public class BreathAlarm implements IAlarm{
long count = endLong - startLong;
if (br > end || br < start) {
if (count >= duration) {
platAlarmCheckDTO.getParam().add("呼吸状态111");
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.createPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord);
notice(platAlarmCheckDTO);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
}
} else {
......@@ -67,4 +74,13 @@ public class BreathAlarm implements IAlarm{
}
return;
}
@Override
@Async
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
platAlarmCheckDTO.getParam().add("呼吸状态111");
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.createPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord);
}
}
......@@ -7,6 +7,7 @@ import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
@Component
......@@ -21,14 +22,25 @@ public class FallAlarm implements IAlarm{
return StringUtils.equals(alarmType,alarmTypeEnum.getValue());
}
/**
* 1.长者跌倒:长者所在空间的跌倒监测雷达上报跌倒,若一个空间内有多为长者,则同时告警多条
* @param platAlarmCheckDTO
*/
@Override
public void createPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO) {
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
JSONObject properties = platAlarmCheckDTO.getProperties();
String personState = (String) properties.get("personState");
if (StringUtils.equals(personState, "1")) {
platAlarmCheckDTO.getParam().add("房间名111");
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.createPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord);
notice(platAlarmCheckDTO);
}
}
@Override
@Async
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
platAlarmCheckDTO.getParam().add("房间名111");
PlatAlarmRecord platAlarmRecord = platAlarmRecordService.createPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord);
}
}
......@@ -13,6 +13,7 @@ import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.redis.RedisUtil;
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.Date;
......@@ -30,7 +31,7 @@ public class HeartAlarm implements IAlarm {
}
@Override
public void createPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO) {
public void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO) {
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
String ruleConfigStr = config.getRuleConfig();
JSONObject properties = platAlarmCheckDTO.getProperties();
......@@ -56,13 +57,20 @@ public class HeartAlarm implements IAlarm {
long count = endLong - startLong;
if (hr > end || hr < start) {
if (count >= duration) {
platAlarmCheckDTO.getParam().add("呼吸状态111");
PlatAlarmRecord platAlarmRecord =platAlarmRecordService. createPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord);
notice(platAlarmCheckDTO);
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
}
} else {
RedisUtil.set(RedisConst.ALARM_DEVICE_ID + deviceId,endLong/1000);
}
}
@Override
@Async
public void notice(PlatAlarmCheckDTO platAlarmCheckDTO) {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
platAlarmCheckDTO.getParam().add("呼吸状态111");
PlatAlarmRecord platAlarmRecord =platAlarmRecordService. createPlatAlarmRecord(platAlarmCheckDTO);
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(),platAlarmRecord);
}
}
......@@ -6,5 +6,7 @@ public interface IAlarm {
boolean support(String alarmType);
void createPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO);
void checkConfig(PlatAlarmCheckDTO platAlarmCheckDTO);
void notice(PlatAlarmCheckDTO platAlarmCheckDTO);
}
......@@ -297,7 +297,7 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
@Override
public PlatAlarmRecord createPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO) {
getElderListByDeviceId(platAlarmCheckDTO);
PlatAlarmConfig config = platAlarmCheckDTO.getPlatAlarmConfig();
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
List<String> param = platAlarmCheckDTO.getParam();
......@@ -321,8 +321,8 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
}
private PlatAlarmCheckDTO getElderListByDeviceId(PlatAlarmCheckDTO platAlarmCheckDTO) {
@Override
public PlatAlarmCheckDTO getElderListByDeviceId(PlatAlarmCheckDTO platAlarmCheckDTO) {
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
LambdaQueryWrapper<PlatRoomBedDevice> roomBedDeviceLambdaQueryWrapper = new LambdaQueryWrapper<>();
roomBedDeviceLambdaQueryWrapper.eq(PlatRoomBedDevice::getDeviceId, platDevice.getId());
......
......@@ -1045,33 +1045,37 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
Map<String, String> mobileMap = userList.stream().collect(Collectors.toMap(PlatUser::getMobile, BaseEntity::getId, (a, b) -> a));
Map<String, String> emailMap = userList.stream().collect(Collectors.toMap(PlatUser::getEmail, BaseEntity::getId, (a, b) -> a));
return ExcelValidatorUtil.validate( platUserImportDTOS, list -> {
return ExcelValidatorUtil.validateMain(3, platUserImportDTOS, list -> {
List<ExcelErrorVo> errorVoList = new ArrayList<>();
int start = 3;
for (int i = 0; i < list.size(); i++) {
PlatUserImportDTO dto = list.get(i);
for (int i = 0; i < platUserImportDTOS.size(); i++) {
PlatUserImportDTO dto = platUserImportDTOS.get(i);
ExcelErrorVo.isNotNull(dto.getUsername(),errorVoList, start+i,"姓名*");
ExcelErrorVo.isNotNull(dto.getMobile(),errorVoList,start+i,"手机号*");
ExcelErrorVo.isNotNull(dto.getRoleName(),errorVoList,start+i,"角色*");
ExcelErrorVo.isNotNull(dto.getRoleName(),errorVoList,start+i,"所属组织*");
ExcelErrorVo.isNotNull(dto.getRoleName(),errorVoList,start+i,"*角色");
ExcelErrorVo.isNotNull(dto.getOrgName(),errorVoList,start+i,"*所属组织");
ExcelErrorVo.notExists(orgNameMap.get(dto.getOrgName()),errorVoList,start+i,"所属组织*");
ExcelErrorVo.notExists(roleNameMap.get(dto.getRoleName()),errorVoList,start+i,"角色*");
ExcelErrorVo.notExists(mobileMap.get(dto.getMobile()),errorVoList,start+i,"手机号*");
ExcelErrorVo.notExists(emailMap.get(dto.getEmail()),errorVoList,start+i,"邮箱");
ExcelErrorVo.notExists(orgNameMap.get(dto.getOrgName()),errorVoList,start+i,"*所属组织");
ExcelErrorVo.notExists(roleNameMap.get(dto.getRoleName()),errorVoList,start+i,"*角色");
ExcelErrorVo.exists(mobileMap,mobileMap.get(dto.getMobile()),errorVoList,start+i,"手机号*");
ExcelErrorVo.exists(emailMap,emailMap.get(dto.getEmail()),errorVoList,start+i,"邮箱");
}
if(errorVoList.isEmpty()){
List<PlatUser> platUsers = new ArrayList<>();
list.forEach(vo->{
platUserImportDTOS.forEach(vo->{
PlatUser platUser = BeanDtoVoUtils.convert(vo, PlatUser.class);
setPassword(platUser);
vo.setPassword(PasswordUtils.encryptPassword(vo.getPassword()));
platUser.setStatus(CommonEnum.YES.getValue());
platUser.setTenantId(TenantIdUtil.getTenantId());
platUser.setAccount(platUser.getMobile());
platUser.setIsTenant(CommonEnum.NO.getValue());
platUsers.add(platUser);
});
saveBatch(platUsers);
}
return errorVoList;
},null);
});
}
......
......@@ -2,7 +2,10 @@ package com.makeit.utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.platform.device.PlatDeviceEnum;
import com.makeit.enums.redis.RedisConst;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.alarm.PlatAlarmConfigService;
......@@ -13,6 +16,7 @@ import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Component
......@@ -64,4 +68,21 @@ public class AlarmConfigCacheUtil implements ApplicationRunner {
getAll();
}
public List<PlatAlarmConfig> getDeviceAlarmConfigMap(PlatDevice platDevice) {
if (StringUtils.equals(platDevice.getCategory(), PlatDeviceEnum.CategoryEnum.HEART.getValue())) {
List<PlatAlarmConfig> set = new ArrayList<>();
set.add(this.get(platDevice.getOrgId() + PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE.getValue()));
set.add(this.get(platDevice.getOrgId() + PlatAlarmConfigEnum.AlarmTypeEnum.HEART.getValue()));
}
if (StringUtils.equals(platDevice.getCategory(), PlatDeviceEnum.CategoryEnum.FALL.getValue())) {
List<PlatAlarmConfig> set = new ArrayList<>();
set.add(this.get(platDevice.getOrgId() + PlatAlarmConfigEnum.AlarmTypeEnum.FALL.getValue()));
}
if (StringUtils.equals(platDevice.getCategory(), PlatDeviceEnum.CategoryEnum.SPACE.getValue())) {
List<PlatAlarmConfig> set = new ArrayList<>();
set.add(this.get(platDevice.getOrgId() + PlatAlarmConfigEnum.AlarmTypeEnum.BEHAVIOR.getValue()));
}
return new ArrayList<>();
}
}
......@@ -5,14 +5,12 @@ import com.alibaba.fastjson.JSONObject;
import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO;
import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.platform.device.PlatDeviceEnum;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.iot.vo.DeviceInfo;
import com.makeit.service.platform.alarm.alarmStrategy.IAlarm;
import com.makeit.utils.AlarmConfigCacheUtil;
import com.makeit.utils.DeviceCacheUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
......@@ -22,7 +20,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
......@@ -71,17 +68,20 @@ public class PushCallback implements MqttCallback {
logger.info("deliveryComplete--------------" + token.isComplete());
}
@TenantIdIgnore
public void checkAlarm(DeviceInfo device) {
String deviceId = device.getDeviceId();
String propertiesStr = device.getProperties();
if (StringUtils.isBlank(propertiesStr)) {
return;
}
JSONObject properties = JSON.parseObject(propertiesStr);
//String propertiesStr = device.getProperties();
// if (StringUtils.isBlank(propertiesStr)) {
// return;
// }
// JSONObject properties = JSON.parseObject(propertiesStr);
JSONObject properties = device.getProperties();
//iot设备id
PlatDevice platDevice = deviceCacheUtil.get(deviceId);
List<PlatAlarmConfig> deviceAlarmConfigList = getDeviceAlarmConfigMap(platDevice);
List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice);
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
return;
}
......@@ -94,28 +94,13 @@ public class PushCallback implements MqttCallback {
for (IAlarm alarm : alarmList) {
if (alarm.support(alarmType)) {
alarm.createPlatAlarmRecord(platAlarmCheckDTO);
alarm.checkConfig(platAlarmCheckDTO);
}
}
}
}
public List<PlatAlarmConfig> getDeviceAlarmConfigMap(PlatDevice platDevice) {
if (StringUtils.equals(platDevice.getCategory(), PlatDeviceEnum.CategoryEnum.HEART.getValue())) {
List<PlatAlarmConfig> set = new ArrayList<>();
set.add(alarmConfigCacheUtil.get(platDevice.getOrgId() + PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE.getValue()));
set.add(alarmConfigCacheUtil.get(platDevice.getOrgId() + PlatAlarmConfigEnum.AlarmTypeEnum.HEART.getValue()));
}
if (StringUtils.equals(platDevice.getCategory(), PlatDeviceEnum.CategoryEnum.FALL.getValue())) {
List<PlatAlarmConfig> set = new ArrayList<>();
set.add(alarmConfigCacheUtil.get(platDevice.getOrgId() + PlatAlarmConfigEnum.AlarmTypeEnum.FALL.getValue()));
}
if (StringUtils.equals(platDevice.getCategory(), PlatDeviceEnum.CategoryEnum.SPACE.getValue())) {
List<PlatAlarmConfig> set = new ArrayList<>();
set.add(alarmConfigCacheUtil.get(platDevice.getOrgId() + PlatAlarmConfigEnum.AlarmTypeEnum.BEHAVIOR.getValue()));
}
return new ArrayList<>();
}
}
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