Commit 90a5d123 by 李小龙

saas菜单启用接口

parent ebd707b8
...@@ -244,7 +244,7 @@ CREATE TABLE `plat_device` ...@@ -244,7 +244,7 @@ CREATE TABLE `plat_device`
registration_date datetime NOT NULL COMMENT '注册时间', registration_date datetime NOT NULL COMMENT '注册时间',
last_online_data datetime NOT NULL COMMENT '最后上线时间', last_online_data datetime NOT NULL COMMENT '最后上线时间',
description VARCHAR(1024) DEFAULT NULL COMMENT '说明', description VARCHAR(1024) DEFAULT NULL COMMENT '说明',
status char(1) NOT NULL COMMENT '状态 数据字典 1 在线 0离线', status varchar(36) DEFAULT NULL COMMENT '状态 DeviceState',
org_id varchar(64) NULL COMMENT '组织id', org_id varchar(64) NULL COMMENT '组织id',
city_org_id varchar(64) NULL COMMENT '城市组织id', city_org_id varchar(64) NULL COMMENT '城市组织id',
district_org_id varchar(64) NULL COMMENT '区组织id', district_org_id varchar(64) NULL COMMENT '区组织id',
......
...@@ -2,6 +2,7 @@ package com.makeit.controller.saas; ...@@ -2,6 +2,7 @@ package com.makeit.controller.saas;
import com.makeit.common.dto.BaseIdDTO; import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.dto.StatusDTO;
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.global.annotation.Action; import com.makeit.global.annotation.Action;
...@@ -33,47 +34,47 @@ import java.util.List; ...@@ -33,47 +34,47 @@ import java.util.List;
public class SaasMenuController { public class SaasMenuController {
@Autowired @Autowired
private SaasMenuService platMenuService; private SaasMenuService saasMenuService;
@Action(module = "saas端-菜单", name = "列表", code = "plat:menu:list") @Action(module = "saas端-菜单", name = "列表", code = "saas:menu:list")
@ApiOperation("列表") @ApiOperation("列表")
@PostMapping("list") @PostMapping("list")
public ApiResponseEntity<List<SaasMenuDTOVO>> list(@RequestBody SaasMenuQueryDTO dto) { public ApiResponseEntity<List<SaasMenuDTOVO>> list(@RequestBody SaasMenuQueryDTO dto) {
return ApiResponseUtils.success(platMenuService.list(dto)); return ApiResponseUtils.success(saasMenuService.list(dto));
} }
@Action(module = "saas端-菜单", name = "树形列表", code = "plat:menu:tree") @Action(module = "saas端-菜单", name = "树形列表", code = "saas:menu:tree")
@ApiOperation("树形列表") @ApiOperation("树形列表")
@PostMapping("tree") @PostMapping("tree")
public ApiResponseEntity<List<SaasMenuDTOVO>> tree(@RequestBody SaasMenuQueryDTO dto) { public ApiResponseEntity<List<SaasMenuDTOVO>> tree(@RequestBody SaasMenuQueryDTO dto) {
return ApiResponseUtils.success(platMenuService.tree(dto)); return ApiResponseUtils.success(saasMenuService.tree(dto));
} }
@ApiOperation("列表(AuthIgnore)") @ApiOperation("列表(AuthIgnore)")
@PostMapping("listAuthIgnore") @PostMapping("listAuthIgnore")
public ApiResponseEntity<List<SaasMenuDTOVO>> listAuthIgnore(@RequestBody SaasMenuQueryDTO dto) { public ApiResponseEntity<List<SaasMenuDTOVO>> listAuthIgnore(@RequestBody SaasMenuQueryDTO dto) {
return ApiResponseUtils.success(platMenuService.list(dto)); return ApiResponseUtils.success(saasMenuService.list(dto));
} }
@ApiOperation("树形列表(AuthIgnore)") @ApiOperation("树形列表(AuthIgnore)")
@PostMapping("treeAuthIgnore") @PostMapping("treeAuthIgnore")
public ApiResponseEntity<List<SaasMenuDTOVO>> treeAuthIgnore(@RequestBody SaasMenuQueryDTO dto) { public ApiResponseEntity<List<SaasMenuDTOVO>> treeAuthIgnore(@RequestBody SaasMenuQueryDTO dto) {
return ApiResponseUtils.success(platMenuService.tree(dto)); return ApiResponseUtils.success(saasMenuService.tree(dto));
} }
@Action(module = "saas端-菜单", name = "新增", code = "plat:menu:add") @Action(module = "saas端-菜单", name = "新增", code = "saas:menu:add")
@ApiOperation("新增") @ApiOperation("新增")
@PostMapping("add") @PostMapping("add")
public ApiResponseEntity<String> add(@Validated @RequestBody SaasMenuDTOVO dto) { public ApiResponseEntity<String> add(@Validated @RequestBody SaasMenuDTOVO dto) {
String id = platMenuService.add(dto); String id = saasMenuService.add(dto);
return ApiResponseUtils.success(id); return ApiResponseUtils.success(id);
} }
@Action(module = "saas端-菜单", name = "编辑", code = "plat:menu:edit") @Action(module = "saas端-菜单", name = "编辑", code = "saas:menu:edit")
@ApiOperation("编辑") @ApiOperation("编辑")
@PostMapping("edit") @PostMapping("edit")
public ApiResponseEntity<?> edit(@Validated @RequestBody SaasMenuDTOVO dto) { public ApiResponseEntity<?> edit(@Validated @RequestBody SaasMenuDTOVO dto) {
platMenuService.edit(dto); saasMenuService.edit(dto);
return ApiResponseUtils.success(); return ApiResponseUtils.success();
} }
...@@ -81,21 +82,29 @@ public class SaasMenuController { ...@@ -81,21 +82,29 @@ public class SaasMenuController {
@ApiOperation("详情") @ApiOperation("详情")
@PostMapping("view") @PostMapping("view")
public ApiResponseEntity<SaasMenuDTOVO> view(@RequestBody BaseIdDTO dto) { public ApiResponseEntity<SaasMenuDTOVO> view(@RequestBody BaseIdDTO dto) {
return ApiResponseUtils.success(platMenuService.view(dto.getId())); return ApiResponseUtils.success(saasMenuService.view(dto.getId()));
} }
@Action(module = "saas端-菜单", name = "删除", code = "plat:menu:del") @Action(module = "saas端-菜单", name = "删除", code = "saas:menu:del")
@ApiOperation("删除") @ApiOperation("删除")
@PostMapping("del") @PostMapping("del")
public ApiResponseEntity<?> del(@RequestBody BaseIdDTO dto) { public ApiResponseEntity<?> del(@RequestBody BaseIdDTO dto) {
platMenuService.del(dto.getId()); saasMenuService.del(dto.getId());
return ApiResponseUtils.success();
}
@Action(module = "saas端-菜单", name = "启用禁用", code = "saas:menu:changeStatus")
@ApiOperation("启用禁用")
@PostMapping("changeStatus")
public ApiResponseEntity<Void> changeStatus(@RequestBody StatusDTO dto) {
saasMenuService.changeStatus(dto);
return ApiResponseUtils.success(); return ApiResponseUtils.success();
} }
@ApiOperation("同步") @ApiOperation("同步")
@PostMapping("sync") @PostMapping("sync")
public ApiResponseEntity<?> sync() { public ApiResponseEntity<?> sync() {
platMenuService.sync(); saasMenuService.sync();
return ApiResponseUtils.success(); return ApiResponseUtils.success();
} }
......
...@@ -14,17 +14,13 @@ import com.makeit.enums.id.IdConst; ...@@ -14,17 +14,13 @@ import com.makeit.enums.id.IdConst;
import com.makeit.exception.BusinessException; import com.makeit.exception.BusinessException;
import com.makeit.global.aspect.tenant.TenantIdUtil; import com.makeit.global.aspect.tenant.TenantIdUtil;
import com.makeit.mapper.platform.alarm.PlatAlarmConfigMapper; import com.makeit.mapper.platform.alarm.PlatAlarmConfigMapper;
import com.makeit.module.admin.dto.plat.PlatTenantDTOVO;
import com.makeit.module.system.entity.SysConfig;
import com.makeit.module.system.entity.SysConfigCategory;
import com.makeit.service.platform.alarm.PlatAlarmConfigService; import com.makeit.service.platform.alarm.PlatAlarmConfigService;
import com.makeit.service.platform.auth.PlatUserService; import com.makeit.service.platform.auth.PlatUserService;
import com.makeit.utils.AlarmConfigCacheUtil;
import com.makeit.utils.data.convert.BeanDtoVoUtils; import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.convert.StreamUtil; import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.data.validate.MapUtil;
import com.makeit.utils.old.StringUtils; import com.makeit.utils.old.StringUtils;
import com.makeit.utils.sql.join.JoinUtil; import com.makeit.utils.sql.join.JoinUtil;
import com.makeit.utils.user.plat.PlatUserVO;
import com.makeit.vo.platform.alarm.PlatAlarmConfigListVO; import com.makeit.vo.platform.alarm.PlatAlarmConfigListVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -32,7 +28,6 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -32,7 +28,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
/** /**
...@@ -49,6 +44,9 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe ...@@ -49,6 +44,9 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe
@Autowired @Autowired
private PlatUserService platUserService; private PlatUserService platUserService;
@Autowired
private AlarmConfigCacheUtil alarmConfigUtil;
@Override @Override
public List<PlatAlarmConfigListVO> list(PlatAlarmConfigQueryDTO dto) { public List<PlatAlarmConfigListVO> list(PlatAlarmConfigQueryDTO dto) {
...@@ -76,6 +74,8 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe ...@@ -76,6 +74,8 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe
save(alarmConfig); save(alarmConfig);
alarmConfigUtil.put(alarmConfig);
} }
@Override @Override
...@@ -91,12 +91,19 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe ...@@ -91,12 +91,19 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe
updateById(alarmConfig); updateById(alarmConfig);
alarmConfigUtil.put(alarmConfig);
} }
@Override @Override
@Transactional @Transactional
public void edit(PlatAlarmConfigDTOVO dto) { public void edit(PlatAlarmConfigDTOVO dto) {
updateById(BeanDtoVoUtils.convert(dto, PlatAlarmConfig.class)); PlatAlarmConfig alarmConfig = BeanDtoVoUtils.convert(dto, PlatAlarmConfig.class);
updateById(alarmConfig);
alarmConfigUtil.put(alarmConfig);
} }
@Override @Override
...@@ -144,6 +151,8 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe ...@@ -144,6 +151,8 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe
alarmConfig.setStatus(dto.getStatus()); alarmConfig.setStatus(dto.getStatus());
updateById(alarmConfig); updateById(alarmConfig);
alarmConfigUtil.put(alarmConfig);
} }
@Override @Override
...@@ -162,6 +171,8 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe ...@@ -162,6 +171,8 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe
alarmConfig.setContentAudit(null); alarmConfig.setContentAudit(null);
updateById(alarmConfig); updateById(alarmConfig);
alarmConfigUtil.put(alarmConfig);
} }
@Transactional @Transactional
...@@ -193,6 +204,8 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe ...@@ -193,6 +204,8 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe
}); });
saveBatch(configList); saveBatch(configList);
alarmConfigUtil.putAll(configList);
} }
} }
...@@ -519,6 +519,8 @@ public class PlatOrgServiceImpl extends ServiceImpl<PlatOrgMapper, PlatOrg> ...@@ -519,6 +519,8 @@ public class PlatOrgServiceImpl extends ServiceImpl<PlatOrgMapper, PlatOrg>
private LambdaQueryWrapper<PlatOrg> getLambdaQueryWrapper(PlatOrgQueryDTO dto) { private LambdaQueryWrapper<PlatOrg> getLambdaQueryWrapper(PlatOrgQueryDTO dto) {
LambdaQueryWrapper<PlatOrg> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PlatOrg> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StringUtils.isNotBlank(dto.getParentId()), PlatOrg::getParentId, dto.getParentId()) queryWrapper.eq(StringUtils.isNotBlank(dto.getParentId()), PlatOrg::getParentId, dto.getParentId())
.like(StringUtils.isNotBlank(dto.getName()),PlatOrg::getName,dto.getName())
.eq(StringUtils.isNotBlank(dto.getType()),PlatOrg::getType,dto.getType())
.orderByDesc(BaseEntity::getUpdateDate); .orderByDesc(BaseEntity::getUpdateDate);
return queryWrapper; return queryWrapper;
} }
...@@ -529,15 +531,26 @@ public class PlatOrgServiceImpl extends ServiceImpl<PlatOrgMapper, PlatOrg> ...@@ -529,15 +531,26 @@ public class PlatOrgServiceImpl extends ServiceImpl<PlatOrgMapper, PlatOrg>
LambdaQueryWrapper<PlatOrg> queryWrapper = getLambdaQueryWrapper(platOrgQueryDTO); LambdaQueryWrapper<PlatOrg> queryWrapper = getLambdaQueryWrapper(platOrgQueryDTO);
List<PlatOrg> list = list(queryWrapper); List<PlatOrg> list = list(queryWrapper);
List<PlatOrg> orgTree = createOrgTree2(list); if(CollectionUtils.isEmpty(list)){
return new ArrayList<>();
}
Set<String> filterSet = list.stream().flatMap(vo -> {
String path = vo.getPath()+","+vo.getId();
String[] split = path.split(",");
return Stream.of(split);
}).collect(Collectors.toSet());
List<PlatOrg> total = list();
List<PlatOrg> orgTree = createOrgTree2(total,filterSet);
return orgTree; return orgTree;
} }
private List<PlatOrg> createOrgTree2(List<PlatOrg> orgList){ private List<PlatOrg> createOrgTree2(List<PlatOrg> orgList,Set<String> filterSet){
if(CollectionUtils.isEmpty(orgList)){ if(CollectionUtils.isEmpty(orgList)){
return new ArrayList<>(); return new ArrayList<>();
} }
Map<String, List<PlatOrg>> parentMap = orgList.stream().collect(Collectors.groupingBy(PlatOrg::getParentId)); Map<String, List<PlatOrg>> parentMap = orgList.stream()
.filter(vo->filterSet.contains(vo.getId()))
.collect(Collectors.groupingBy(PlatOrg::getParentId));
orgList.forEach(vo->{ orgList.forEach(vo->{
vo.setChildren(parentMap.get(vo.getId())); vo.setChildren(parentMap.get(vo.getId()));
}); });
......
package com.makeit.service.saas; package com.makeit.service.saas;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.makeit.common.dto.StatusDTO;
import com.makeit.entity.saas.SaasMenu; import com.makeit.entity.saas.SaasMenu;
import com.makeit.module.admin.dto.saas.SaasMenuDTOVO; import com.makeit.module.admin.dto.saas.SaasMenuDTOVO;
import com.makeit.module.admin.dto.saas.SaasMenuQueryDTO; import com.makeit.module.admin.dto.saas.SaasMenuQueryDTO;
...@@ -30,4 +31,6 @@ public interface SaasMenuService extends IService<SaasMenu> { ...@@ -30,4 +31,6 @@ public interface SaasMenuService extends IService<SaasMenu> {
void sync(); void sync();
void changeStatus(StatusDTO dto);
} }
...@@ -2,6 +2,7 @@ package com.makeit.service.saas.impl; ...@@ -2,6 +2,7 @@ package com.makeit.service.saas.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.dto.StatusDTO;
import com.makeit.entity.saas.SaasMenu; import com.makeit.entity.saas.SaasMenu;
import com.makeit.entity.saas.SaasRoleMenu; import com.makeit.entity.saas.SaasRoleMenu;
import com.makeit.enums.CodeMessageEnum; import com.makeit.enums.CodeMessageEnum;
...@@ -332,5 +333,20 @@ public class SaasMenuServiceImpl extends ServiceImpl<SaasMenuMapper, SaasMenu> i ...@@ -332,5 +333,20 @@ public class SaasMenuServiceImpl extends ServiceImpl<SaasMenuMapper, SaasMenu> i
return button; return button;
} }
@Transactional
@Override
public void changeStatus(StatusDTO dto) {
if (Arrays.stream(CommonEnum.values()).noneMatch(e -> e.getValue().equals(dto.getStatus()))) {
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR);
}
SaasMenu saasMenu = getById(dto.getId());
if (saasMenu.getStatus().equals(dto.getStatus())) {
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR);
}
saasMenu.setStatus(dto.getStatus());
updateById(saasMenu);
}
} }
...@@ -47,7 +47,7 @@ public class IotSyncTask { ...@@ -47,7 +47,7 @@ public class IotSyncTask {
* 启用状态的租户才同步 * 启用状态的租户才同步
* 新增和更新平台端设备表 * 新增和更新平台端设备表
*/ */
@Scheduled(cron = "0 0 */1 * * ?") // @Scheduled(cron = "0 0 */1 * * ?")
@TenantIdIgnore @TenantIdIgnore
public void syncEquipmentInfo() { public void syncEquipmentInfo() {
log.info("开始执行同步设备信息接口"); log.info("开始执行同步设备信息接口");
...@@ -131,5 +131,10 @@ public class IotSyncTask { ...@@ -131,5 +131,10 @@ public class IotSyncTask {
}); });
return deviceMap.values(); return deviceMap.values();
} }
/**
* 床位id 绑定的所有设备
* 房间id 绑定的所有设备
*
*/
} }
package com.makeit.utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.enums.CommonEnum;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.alarm.PlatAlarmConfigService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@Component
public class AlarmConfigCacheUtil implements ApplicationRunner {
/**
* key orgId|type
* todo 放redis
*/
private static final ConcurrentHashMap<String, PlatAlarmConfig> CACHE = new ConcurrentHashMap<>(16);
@Autowired
private PlatAlarmConfigService platAlarmConfigService;
public List<PlatAlarmConfig> getAll() {
List<PlatAlarmConfig> list = platAlarmConfigService.list(new LambdaQueryWrapper<PlatAlarmConfig>().eq(PlatAlarmConfig::getStatus, CommonEnum.YES.getValue()));
return list;
}
public void put(PlatAlarmConfig alarmConfig) {
if (StringUtils.equals(CommonEnum.YES.getValue(),alarmConfig.getStatus())) {
CACHE.put(alarmConfig.getOrgId() + "|" + alarmConfig.getAlarmType(),alarmConfig);
} else {
CACHE.remove(alarmConfig.getOrgId() + "|" + alarmConfig.getAlarmType());
}
}
public void putAll(List<PlatAlarmConfig> alarmConfigs) {
alarmConfigs.forEach(vo -> {
put(vo);
});
}
public PlatAlarmConfig get(String orgIdType) {
return CACHE.get(orgIdType);
}
/**
* Callback used to run the bean.
*
* @param args incoming application arguments
* @throws Exception on error
*/
@Override
@TenantIdIgnore
public void run(ApplicationArguments args) throws Exception {
List<PlatAlarmConfig> list = getAll();
list.stream().forEach(vo -> {
put(vo);
});
}
}
package com.makeit.utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.device.PlatDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@Component
public class DeviceCacheUtil implements ApplicationRunner {
/**
* key
* todo 放redis
*/
private static final ConcurrentHashMap<String, PlatDevice> CACHE = new ConcurrentHashMap<>(16);
@Autowired
private PlatDeviceService platDeviceService;
public List<PlatDevice> getAll() {
List<PlatDevice> list = platDeviceService.list(new LambdaQueryWrapper<PlatDevice>());
return list;
}
public void put(PlatDevice platDevice) {
CACHE.put(platDevice.getOriDeviceId(), platDevice);
}
public void putAll(List<PlatDevice> platDevices) {
platDevices.forEach(vo -> {
put(vo);
});
}
public PlatDevice get(String oriDeviceId) {
return CACHE.get(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 {
List<PlatDevice> list = getAll();
list.stream().forEach(vo -> {
put(vo);
});
}
}
...@@ -14,14 +14,16 @@ import com.makeit.entity.platform.device.PlatDevice; ...@@ -14,14 +14,16 @@ 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.entity.platform.space.PlatRoomBedDevice; import com.makeit.entity.platform.space.PlatRoomBedDevice;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.platform.device.PlatDeviceEnum;
import com.makeit.enums.redis.RedisConst; import com.makeit.enums.redis.RedisConst;
import com.makeit.module.iot.vo.DeviceInfo; import com.makeit.module.iot.vo.DeviceInfo;
import com.makeit.service.platform.alarm.PlatAlarmConfigService;
import com.makeit.service.platform.alarm.PlatAlarmRecordService; import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.elder.PlatElderService; import com.makeit.service.platform.elder.PlatElderService;
import com.makeit.service.platform.space.PlatRoomBedDeviceService; import com.makeit.service.platform.space.PlatRoomBedDeviceService;
import com.makeit.service.platform.space.PlatRoomService; import com.makeit.service.platform.space.PlatRoomService;
import com.makeit.utils.AlarmConfigCacheUtil;
import com.makeit.utils.DeviceCacheUtil;
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;
...@@ -37,9 +39,9 @@ import org.slf4j.LoggerFactory; ...@@ -37,9 +39,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -59,9 +61,9 @@ public class PushCallback implements MqttCallback { ...@@ -59,9 +61,9 @@ public class PushCallback implements MqttCallback {
@Autowired @Autowired
private PlatAlarmRecordService platAlarmRecordService; private PlatAlarmRecordService platAlarmRecordService;
@Autowired @Autowired
private PlatDeviceService platDeviceService; private AlarmConfigCacheUtil alarmConfigCacheUtil;
@Autowired @Autowired
private PlatAlarmConfigService platAlarmConfigService; private DeviceCacheUtil deviceCacheUtil;
@Override @Override
...@@ -84,7 +86,7 @@ public class PushCallback implements MqttCallback { ...@@ -84,7 +86,7 @@ public class PushCallback implements MqttCallback {
DeviceInfo device = JSON.parseObject(payload, DeviceInfo.class); DeviceInfo device = JSON.parseObject(payload, DeviceInfo.class);
// todo // todo
// checkAlarm(device); //checkAlarm(device);
} }
@Override @Override
...@@ -92,55 +94,58 @@ public class PushCallback implements MqttCallback { ...@@ -92,55 +94,58 @@ public class PushCallback implements MqttCallback {
logger.info("deliveryComplete--------------" + token.isComplete()); logger.info("deliveryComplete--------------" + token.isComplete());
} }
public void checkAlarm(DeviceInfo device) { public void checkAlarm(DeviceInfo device) {
getDeviceAlarmConfigMap();
String deviceId = device.getDeviceId(); String deviceId = device.getDeviceId();
String propertiesStr = device.getProperties(); String propertiesStr = device.getProperties();
if(StringUtils.isBlank(propertiesStr)){
return;
}
JSONObject properties = JSON.parseObject(propertiesStr); JSONObject properties = JSON.parseObject(propertiesStr);
//呼吸率
int br = (int) properties.get("br"); //iot设备id
//心率 PlatDevice platDevice = deviceCacheUtil.get(deviceId);
int hr = (int) properties.get("hr"); List<PlatAlarmConfig> deviceAlarmConfigList = getDeviceAlarmConfigMap(platDevice);
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
PlatDevice platDevice = platDeviceService.getById(deviceId);
String category = platDevice.getCategory();
LambdaQueryWrapper<PlatAlarmConfig> platAlarmConfigLambdaQueryWrapper = new LambdaQueryWrapper<>();
platAlarmConfigLambdaQueryWrapper.eq(PlatAlarmConfig::getOrgId, platDevice.getOrgId())
.in(PlatAlarmConfig::getAlarmType, deviceAlarmConfigMap.get(category))
;
List<PlatAlarmConfig> configList = platAlarmConfigService.list(platAlarmConfigLambdaQueryWrapper);
if (CollectionUtils.isEmpty(configList)) {
return; return;
} }
RedissonClient redissonClient = RedisUtil.getClient(); RedissonClient redissonClient = RedisUtil.getClient();
for (PlatAlarmConfig config : configList) { for (PlatAlarmConfig config : deviceAlarmConfigList) {
String alarmType = config.getAlarmType(); String alarmType = config.getAlarmType();
String ruleConfigStr = config.getRuleConfig(); String ruleConfigStr = config.getRuleConfig();
//跌倒 //跌倒
if (StringUtils.equals(alarmType, "1")) { if (StringUtils.equals(alarmType, PlatAlarmConfigEnum.AlarmTypeEnum.FALL.getValue())) {
PlatAlarmRecord platAlarmRecord = createFallPlatAlarmRecord(platDevice, config); String personState = (String) properties.get("personState");
platAlarmRecordService.noticeDeviceAlarm(config, platAlarmRecord); if (StringUtils.equals(personState, "1")) {
PlatAlarmRecord platAlarmRecord = createFallPlatAlarmRecord(platDevice, config);
}
} }
if (StringUtils.isBlank(ruleConfigStr)) { if (StringUtils.isBlank(ruleConfigStr)) {
continue; continue;
} }
//呼吸 //呼吸
if (StringUtils.equals(alarmType, "2")) { if (StringUtils.equals(alarmType, PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE.getValue())) {
String personState = (String) properties.get("personState");
//呼吸率
int br = (int) properties.get("br");
PlatAlarmConfigRespiratoryDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigRespiratoryDTOVO.class); PlatAlarmConfigRespiratoryDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigRespiratoryDTOVO.class);
Integer start = ruleConfig.getRespiratoryRateStart(); Integer start = ruleConfig.getRespiratoryRateStart();
Integer end = ruleConfig.getRespiratoryRateEnd(); Integer end = ruleConfig.getRespiratoryRateEnd();
Integer duration = ruleConfig.getDuration(); Integer duration = ruleConfig.getDuration();
//计数 //计数
RAtomicLong atomicLong = redissonClient.getAtomicLong(RedisConst.ALARM_DEVICE_ID + deviceId); RAtomicLong atomicLong = redissonClient.getAtomicLong(RedisConst.ALARM_DEVICE_ID + deviceId);
if (!atomicLong.isExists()) { if (!atomicLong.isExists()) {
atomicLong.set(0); atomicLong.set(0);
} }
if (StringUtils.equals(personState, "0")) {
atomicLong.set(0);
continue;
}
if (br > end || br < start) { if (br > end || br < start) {
long count = atomicLong.incrementAndGet(); long count = atomicLong.incrementAndGet();
if (count >= duration) { if (count >= duration) {
PlatAlarmRecord platAlarmRecord = createRespiratoryPlatAlarmRecord(platDevice, config); PlatAlarmRecord platAlarmRecord = createRespiratoryPlatAlarmRecord(platDevice, config);
platAlarmRecordService.noticeDeviceAlarm(config, platAlarmRecord);
atomicLong.set(0); atomicLong.set(0);
} }
} else { } else {
...@@ -148,7 +153,10 @@ public class PushCallback implements MqttCallback { ...@@ -148,7 +153,10 @@ public class PushCallback implements MqttCallback {
} }
} }
//心率 //心率
if (StringUtils.equals(alarmType, "3")) { if (StringUtils.equals(alarmType, PlatAlarmConfigEnum.AlarmTypeEnum.HEART.getValue())) {
String personState = (String) properties.get("personState");
//心率
int hr = (int) properties.get("hr");
PlatAlarmConfigHeartDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigHeartDTOVO.class); PlatAlarmConfigHeartDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigHeartDTOVO.class);
Integer start = ruleConfig.getHeartRateStart(); Integer start = ruleConfig.getHeartRateStart();
Integer end = ruleConfig.getHeartRateEnd(); Integer end = ruleConfig.getHeartRateEnd();
...@@ -157,43 +165,83 @@ public class PushCallback implements MqttCallback { ...@@ -157,43 +165,83 @@ public class PushCallback implements MqttCallback {
if (!atomicLong.isExists()) { if (!atomicLong.isExists()) {
atomicLong.set(0); atomicLong.set(0);
} }
if (StringUtils.equals(personState, "0")) {
atomicLong.set(0);
continue;
}
if (hr > end || hr < start) { if (hr > end || hr < start) {
long count = atomicLong.incrementAndGet(); long count = atomicLong.incrementAndGet();
if (count >= duration) { if (count >= duration) {
PlatAlarmRecord platAlarmRecord = createHeartPlatAlarmRecord(platDevice, config); PlatAlarmRecord platAlarmRecord = createHeartPlatAlarmRecord(platDevice, config);
platAlarmRecordService.noticeDeviceAlarm(config, platAlarmRecord);
atomicLong.set(0);
} }
} else { } else {
atomicLong.set(0); atomicLong.set(0);
} }
} }
RAtomicLong atomicLong = redissonClient.getAtomicLong(RedisConst.ALARM_DEVICE_ID + deviceId);
//行为 //行为
if (StringUtils.equals(alarmType, "4")) { if (StringUtils.equals(alarmType, PlatAlarmConfigEnum.AlarmTypeEnum.BEHAVIOR.getValue())) {
String personState = (String) 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();
//todo duration = duration*60;
//todo duration+平均停留时长
List<String> personStateList = Arrays.asList("1", "2", "3");
//有人
//计数
if (!atomicLong.isExists()) {
atomicLong.set(0);
}
if (personStateList.contains(personState)) {
long count = atomicLong.incrementAndGet();
if (count >= duration) {
PlatAlarmRecord platAlarmRecord = createBehaviorPlatAlarmRecord(platDevice, config);
atomicLong.set(0);
}
}else {
atomicLong.set(0);
}
} }
// else { //没人 更新停留时长
// long stayLong = atomicLong.get();
// //保存
// /**
// * 老人id
// * 日期
// * 区域名称
// * 当天总时长
// * 当天最后一次进入该区域的开始时间
// * 当天最后一次进入该区域的结束时间
// * 当天最后一次进入该区域的时长
// */
// }
//todo
} }
} }
private PlatAlarmRecord createFallPlatAlarmRecord(PlatDevice platDevice, PlatAlarmConfig config) { private PlatAlarmRecord createFallPlatAlarmRecord(PlatDevice platDevice, PlatAlarmConfig config) {
PlatAlarmRecord platAlarmRecord = createPlatAlarmRecord(platDevice, config, "房间名111");
return createPlatAlarmRecord(platDevice, config, "房间名111"); platAlarmRecordService.noticeDeviceAlarm(config,platAlarmRecord);
return platAlarmRecord;
} }
private PlatAlarmRecord createRespiratoryPlatAlarmRecord(PlatDevice platDevice, PlatAlarmConfig config) { private PlatAlarmRecord createRespiratoryPlatAlarmRecord(PlatDevice platDevice, PlatAlarmConfig config) {
return createPlatAlarmRecord(platDevice, config, "呼吸状态111"); PlatAlarmRecord platAlarmRecord = createPlatAlarmRecord(platDevice, config, "呼吸状态111");
platAlarmRecordService.noticeDeviceAlarm(config,platAlarmRecord);
return platAlarmRecord;
} }
private PlatAlarmRecord createHeartPlatAlarmRecord(PlatDevice platDevice, PlatAlarmConfig config) { private PlatAlarmRecord createHeartPlatAlarmRecord(PlatDevice platDevice, PlatAlarmConfig config) {
return createPlatAlarmRecord(platDevice, config, "心率状态111"); PlatAlarmRecord platAlarmRecord = createPlatAlarmRecord(platDevice, config, "呼吸状态111");
platAlarmRecordService.noticeDeviceAlarm(config,platAlarmRecord);
return platAlarmRecord;
} }
private PlatAlarmRecord createBehaviorPlatAlarmRecord(PlatDevice platDevice, PlatAlarmConfig config) { private PlatAlarmRecord createBehaviorPlatAlarmRecord(PlatDevice platDevice, PlatAlarmConfig config) {
return createPlatAlarmRecord(platDevice, config, "房间名"); PlatAlarmRecord platAlarmRecord = createPlatAlarmRecord(platDevice, config, "房间名");
platAlarmRecordService.noticeDeviceAlarm(config,platAlarmRecord);
return platAlarmRecord;
} }
...@@ -219,18 +267,21 @@ public class PushCallback implements MqttCallback { ...@@ -219,18 +267,21 @@ public class PushCallback implements MqttCallback {
} }
private static HashMap<String, Object> deviceAlarmConfigMap; public List<PlatAlarmConfig> getDeviceAlarmConfigMap(PlatDevice platDevice) {
if (StringUtils.equals(platDevice.getCategory(), PlatDeviceEnum.CategoryEnum.HEART.getValue())) {
public static HashMap<String, Object> getDeviceAlarmConfigMap() { List<PlatAlarmConfig> set = new ArrayList<>();
if (deviceAlarmConfigMap != null) { set.add(alarmConfigCacheUtil.get(platDevice.getOrgId() + PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE.getValue()));
return deviceAlarmConfigMap; 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()));
} }
HashMap<String, Object> map = new HashMap<>(); return new ArrayList<>();
map.put("0", Arrays.asList("2", "3"));
map.put("1", Arrays.asList("4"));
map.put("2", Arrays.asList("1"));
deviceAlarmConfigMap = map;
return deviceAlarmConfigMap;
} }
private String replaceParam(String oriContent, String... param) { private String replaceParam(String oriContent, String... param) {
......
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