Commit c009fac6 by 朱淼
parents 0b405676 fc11dd32
Showing with 410 additions and 82 deletions
......@@ -11,6 +11,7 @@ import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.saas.SaasOperationLogService;
import com.makeit.vo.platform.device.PlatDeviceListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -31,7 +32,7 @@ public class SaasDeviceController {
@ApiOperation("列表")
@PostMapping("page")
@TenantIdIgnore
public ApiResponseEntity<PageVO<PlatDevice>> page(@RequestBody PageReqDTO<PlatDevice> pageReqDTO) {
public ApiResponseEntity<PageVO<PlatDeviceListVO>> page(@RequestBody PageReqDTO<PlatDevice> pageReqDTO) {
return ApiResponseUtils.success(platDeviceService.pageSaas(pageReqDTO));
}
......
......@@ -23,7 +23,11 @@
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.makeit</groupId>
<artifactId>server-service</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
......
package com.makeit.api.controller;
public class AlarmController {
}
package com.makeit.api.controller.external;
import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.dto.platform.alarm.PlatAlarmRecordQueryDTO;
import com.makeit.dto.platform.device.PlatDeviceQueryDTO;
import com.makeit.dto.platform.elder.PlatElderQueryDTO;
import com.makeit.global.annotation.AuthIgnore;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.elder.PlatElderService;
import com.makeit.vo.platform.alarm.PlatAlarmRecordVO;
import com.makeit.vo.platform.device.PlatDeviceListVO;
import com.makeit.vo.platform.elder.PlatElderListVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContextAware;
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;
import javax.annotation.PostConstruct;
/**
* iot对外接口
*/
@RestController
@RequestMapping("/iot/external")
public class IotPlatExternalController {
@Autowired
private PlatElderService platElderService;
@Autowired
private PlatDeviceService platDeviceService;
@Autowired
private PlatAlarmRecordService platAlarmRecordService;
@ApiOperation("长者列表")
@PostMapping("elderPage")
@TenantIdIgnore
@AuthIgnore
public ApiResponseEntity<PageVO<PlatElderListVO>> elderPage(@RequestBody PageReqDTO<PlatElderQueryDTO> page) {
return ApiResponseUtils.success(platElderService.page(page));
}
@ApiOperation("设备列表")
@PostMapping("devicePage")
@TenantIdIgnore
@AuthIgnore
public ApiResponseEntity<PageVO<PlatDeviceListVO>> devicePage(@RequestBody PageReqDTO<PlatDeviceQueryDTO> pageReqDTO) {
return ApiResponseUtils.success(platDeviceService.page(pageReqDTO));
}
@ApiOperation("告警记录列表")
@PostMapping("alarmRecordPage")
@TenantIdIgnore
@AuthIgnore
public ApiResponseEntity<PageVO<PlatAlarmRecordVO>> page(@RequestBody PageReqDTO<PlatAlarmRecordQueryDTO> dto) {
return ApiResponseUtils.success(platAlarmRecordService.page(dto));
}
@ApiOperation("处理告警回调")
@PostMapping("dealAlarm")
@TenantIdIgnore
@AuthIgnore
public ApiResponseEntity<String> dealAlarm(@RequestBody BaseIdDTO dto) {
platAlarmRecordService.dealAlarm(dto);
return ApiResponseUtils.success();
}
}
......@@ -50,6 +50,8 @@ public class PlatAuthorizationInterceptor implements HandlerInterceptor {
Set<String> codeSet = new HashSet<>();
if(userLoginVO!= null && CollectionUtils.isNotEmpty(userLoginVO.getButtonCodeList())) {
codeSet = new HashSet<>(userLoginVO.getButtonCodeList());
}else {
return true;
}
for (String e : annotation.code()) {
......
......@@ -5,11 +5,14 @@ import com.makeit.enums.redis.RedisConst;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.user.ThreadLocalUserUtil;
import com.makeit.utils.user.TokenUtil;
import org.apache.poi.ss.formula.functions.T;
public class WechatUserUtil {
public static WechatUserInfo getUserVO() {
TokenUtil.getToken(RedisConst.WECHAT_TOKEN_PREFIX, ThreadLocalUserUtil.getWechatToken());
//TokenUtil.getToken(RedisConst.WECHAT_TOKEN_PREFIX, ThreadLocalUserUtil.getWechatToken());
TokenUtil.getToken(RedisConst.WECHAT_TOKEN_PREFIX, TokenUtil.wechatGetToken());
return BeanDtoVoUtils.convert(ThreadLocalUserUtil.getWechatUser(), WechatUserInfo.class);
}
......
package com.makeit.module.controller.elder;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.global.annotation.AuthIgnore;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.task.IotSyncTask;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 长者每天睡觉记录 前端控制器
* </p>
*
* @author eugene young
* @since 2023-09-13
*/
@Api(tags = "长者睡觉分析")
@RestController
@RequestMapping("/plat/elderSleep")
public class PlatElderSleepController {
@Autowired
private IotSyncTask iotSyncTask;
@ApiOperation("测试")
@PostMapping("test")
@AuthIgnore
@TenantIdIgnore
public ApiResponseEntity<Void> test() {
iotSyncTask.elderSleepSleepAnalysisTask();
return ApiResponseUtils.success();
}
}
......@@ -22,7 +22,7 @@ public class PlatAlarmConfigHeartDTOVO {
private Integer heartRateStart;
@ApiModelProperty("心率正常范围结束")
private Integer heartRateEnd;
private Integer heartRateeEnd;
@ApiModelProperty("异常持续时间")
private Integer duration;
......
package com.makeit.dto.platform.auth;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class PlatOrgSplitDTO {
@ApiModelProperty(value = "部门树id")
private String orgId;
@ApiModelProperty(value = "城市组织id")
private String cityOrgId;
@ApiModelProperty(value = "区组织id")
private String districtOrgId;
@ApiModelProperty(value = "街道组织id")
private String streetOrgId;
@ApiModelProperty(value = "组织路径")
private String orgPath;
}
package com.makeit.enums.report;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum DeviceNameEnum {
heart("呼吸心率","呼吸心率雷达"),
fall("跌倒","跌倒检测雷达"),
space("空间","空间人体雷达");
private String prefix;
private String name;
public static String getNameByPrefix(String productName) {
for (DeviceNameEnum value : DeviceNameEnum.values()) {
if ( productName.startsWith(value.prefix)) {
return value.name;
}
}
return "";
}
}
package com.makeit.service.platform.alarm;
import com.baomidou.mybatisplus.extension.service.IService;
import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO;
......@@ -57,4 +58,6 @@ public interface PlatAlarmRecordService extends IService<PlatAlarmRecord> {
PlatAlarmRecord convertToPlatAlarmRecord(PlatAlarmCheckDTO platAlarmCheckDTO);
void getElderListByDeviceId(PlatAlarmCheckDTO platAlarmCheckDTO);
void dealAlarm(BaseIdDTO dto);
}
......@@ -76,7 +76,7 @@ public class BehaviorAlarm implements IAlarm {
Integer duration = ruleConfig.getDuration();//分钟
PlatDayDurationRecord platDayDurationRecord = dayDurationUtil.get(platDevice.getOriDeviceId());
if (platDayDurationRecord == null) {
log.error("行为告警未找到行为异常平均时长,设备id:" + platDevice.getId());
log.error("行为告警未找到行为异常平均时长,设备plat_id:" + platDevice.getId());
return;
}
Long duration1 = platDayDurationRecord.getDuration();
......@@ -99,13 +99,13 @@ public class BehaviorAlarm implements IAlarm {
alarmRedisDTO.setStartLong(endLong);
alarmRedisDTO.setStart(now);
RedisUtil.set(RedisConst.ALARM_DEVICE_BEHAVIOR_ID + deviceId, alarmRedisDTO);
log.error("空间雷达上报进入房间,设备id:" + platDevice.getId());
log.error("空间雷达上报进入房间,设备plat_id:" + platDevice.getId());
return;
}
long count = endLong - startLong;
//进入空间时间满足告警时长,判断是否已经告警过了
if (count / 1000 >= duration && StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.NO.getValue())) {
log.error("空间雷达发出告警,设备id:" + platDevice.getId());
log.error("空间雷达发出告警,设备plat_id:" + platDevice.getId());
notice(platAlarmCheckDTO);
alarmRedisDTO.setAlarm(CommonEnum.YES.getValue());
RedisUtil.set(RedisConst.ALARM_DEVICE_BEHAVIOR_ID + deviceId, alarmRedisDTO);
......
......@@ -85,14 +85,14 @@ public class BreathAlarm implements IAlarm {
alarmRedisDTO.setStart(now);
alarmRedisDTO.setStartLong(endLong);
RedisUtil.set(RedisConst.ALARM_DEVICE_BR_ID + deviceId,alarmRedisDTO);
log.error("发现长者呼吸异常,设备id:"+deviceId);
log.error("发现长者呼吸异常,设备plat_id:"+deviceId);
return;
}
Long startLong = alarmRedisDTO.getStartLong();
long count = endLong - startLong;
if (count/1000 >= duration) {
if (StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) {
log.error("呼吸已告警,设备id:" + platDevice.getId());
log.error("呼吸已告警,设备plat_id:" + platDevice.getId());
return;
}
fillRemark(platAlarmCheckDTO, br, start, end);
......
......@@ -66,7 +66,7 @@ public class FallAlarm implements IAlarm {
platAlarmRecordService.getElderListByDeviceId(platAlarmCheckDTO);
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if (CollectionUtils.isEmpty(platElderList)) {
log.error("跌倒设备未关联长者,设备id:" + platDevice.getId());
log.error("跌倒设备未关联长者,设备plat_id:" + platDevice.getId());
return;
}
PlatRoom platRoom = platAlarmCheckDTO.getPlatRoom();
......
......@@ -11,6 +11,7 @@ import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.redis.RedisConst;
import com.makeit.exception.BusinessException;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.utils.AlarmRedisDTO;
import com.makeit.utils.data.convert.JsonUtil;
......@@ -55,7 +56,7 @@ public class HeartAlarm implements IAlarm {
int hr = (int) properties.get("hr");
PlatAlarmConfigHeartDTOVO ruleConfig = JsonUtil.toObj(ruleConfigStr, PlatAlarmConfigHeartDTOVO.class);
Integer start = ruleConfig.getHeartRateStart();
Integer end = ruleConfig.getHeartRateEnd();
Integer end = ruleConfig.getHeartRateeEnd();
Integer duration = ruleConfig.getDuration();
Date now = new Date();
long endLong = now.getTime();
......@@ -75,7 +76,7 @@ public class HeartAlarm implements IAlarm {
alarmRedisDTO.setStart(now);
alarmRedisDTO.setStartLong(endLong);
RedisUtil.set(RedisConst.ALARM_DEVICE_HR_ID + deviceId,alarmRedisDTO);
log.error("发现长者心率异常,设备id:"+deviceId);
log.error("发现长者心率异常,设备iot_id:"+deviceId);
return;
}
Long startLong = alarmRedisDTO.getStartLong();
......@@ -84,7 +85,7 @@ public class HeartAlarm implements IAlarm {
//todo 如果每台服务器都能收到上报消息 加redis锁
//RLock lock = RedisLockUtil.lock(RedisConst.LOCK_ALARM + deviceId);
if (StringUtils.equals(alarmRedisDTO.getAlarm(), CommonEnum.YES.getValue())) {
log.error("心率已告警,设备id:" + platDevice.getId());
log.error("心率已告警,设备plat_id:" + platDevice.getId());
return;
}
fillRemark(platAlarmCheckDTO, hr, start, end);
......@@ -116,8 +117,7 @@ public class HeartAlarm implements IAlarm {
PlatDevice platDevice = platAlarmCheckDTO.getPlatDevice();
List<PlatElder> platElderList = platAlarmCheckDTO.getPlatElderList();
if (CollectionUtils.isEmpty(platElderList)) {
log.error("心率设备未关联长者,设备id:" + platAlarmCheckDTO.getPlatDevice().getId());
return;
throw new BusinessException("心率设备未关联长者,设备plat_id:" + platAlarmCheckDTO.getPlatDevice().getId());
}
for (PlatElder platElder : platElderList) {
List<String> param = new ArrayList<>();
......@@ -128,7 +128,7 @@ public class HeartAlarm implements IAlarm {
platAlarmRecord.setElderIds(platElder.getId());
platAlarmRecord.setElderName(platElder.getName());
platAlarmRecordService.noticeDeviceAlarm(platAlarmCheckDTO.getPlatAlarmConfig(), platAlarmRecord);
log.error("长者心率异常,发出告警,设备id:"+platDevice.getId()+", 长者名称:"+platElder.getName());
log.error("长者心率异常,发出告警,设备plat_id:"+platDevice.getId()+", 长者名称:"+platElder.getName());
}
}
}
......@@ -3,6 +3,7 @@ package com.makeit.service.platform.alarm.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.entity.BaseBusEntity;
import com.makeit.common.entity.BaseEntity;
import com.makeit.common.page.PageReqDTO;
......@@ -381,7 +382,11 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
.eq(BaseBusEntity::getTenantId,tenantId)
;
List<PlatElder> list = platElderService.list(elderLambdaQueryWrapper);
platAlarmCheckDTO.setPlatElderList(list);
if(CollectionUtils.isNotEmpty(list)) {
platAlarmCheckDTO.setPlatElderList(list);
return;
}
}
String roomId = platRoomBedDevice.getRoomId();
......@@ -412,4 +417,14 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
return sb.toString();
}
@Override
public void dealAlarm(BaseIdDTO dto) {
if (StringUtils.isEmpty(dto.getId())) {
throw new RuntimeException("id为空");
}
PlatAlarmRecord platAlarmRecord = getById(dto.getId());
platAlarmRecord.setStatus(CommonEnum.YES.getValue());
platAlarmRecord.setDealDate(LocalDateTime.now());
updateById(platAlarmRecord);
}
}
......@@ -4,6 +4,7 @@ package com.makeit.service.platform.auth;
import com.baomidou.mybatisplus.extension.service.IService;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.auth.PlatOrgSplitDTO;
import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.vo.platform.auth.PlatOrgQueryDTO;
......@@ -98,4 +99,11 @@ public interface PlatOrgService extends IService<PlatOrg> {
List<PlatOrg> createOrgTree(List<PlatOrg> orgList);
List<PlatOrg> belongToScopeList(PlatOrg param);
/**
* 获取orgId 的 城市|区|街道 id
* @param orgId
* @return
*/
PlatOrgSplitDTO getOrgSplitVO(String orgId);
}
......@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.entity.BaseEntity;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.auth.PlatOrgSplitDTO;
import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.auth.PlatRoleOrg;
import com.makeit.entity.platform.auth.PlatUserRole;
......@@ -46,6 +47,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -607,4 +609,29 @@ public class PlatOrgServiceImpl extends ServiceImpl<PlatOrgMapper, PlatOrg>
platAlarmConfigService.copyForOrg(platOrg);
}
@Override
public PlatOrgSplitDTO getOrgSplitVO(String orgId) {
PlatOrgSplitDTO platOrgSplitDTO = new PlatOrgSplitDTO();
platOrgSplitDTO.setOrgId(orgId);
PlatOrg platOrg = getById(orgId);
if (platOrg == null) {
return platOrgSplitDTO;
}
String orgPath = platOrg.getPath();
if (StringUtils.isBlank(orgPath)) {
return platOrgSplitDTO;
}
List<BiConsumer<PlatOrgSplitDTO, String>> list = Arrays.asList(
PlatOrgSplitDTO::setCityOrgId,
PlatOrgSplitDTO::setDistrictOrgId,
PlatOrgSplitDTO::setStreetOrgId
);
String[] split = orgPath.split(",");
for (int i = 1; i < split.length; i++) {
BiConsumer<PlatOrgSplitDTO, String> e = list.get(i - 1);
e.accept(platOrgSplitDTO, split[i]);
}
return platOrgSplitDTO;
}
}
......@@ -443,7 +443,7 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
String button = SysEnum.MenuTypeEnum.BUTTON.getValue();
menuList.forEach(e -> {
if (menu.equals(e.getCategory()) || button.equals(e.getCategory())) {
if ( button.equals(e.getCategory())) {
buttonList.add(e);
}
......
......@@ -42,7 +42,7 @@ public interface PlatDeviceService extends IService<PlatDevice> {
* @param pageReqDTO
* @return
*/
PageVO<PlatDevice> pageSaas(PageReqDTO<PlatDevice> pageReqDTO);
PageVO<PlatDeviceListVO> pageSaas(PageReqDTO<PlatDevice> pageReqDTO);
/**
* 设备信息
......
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.dto.BaseTenantDTO;
import com.makeit.common.entity.BaseBusEntity;
import com.makeit.common.entity.BaseEntity;
import com.makeit.common.page.PageReqDTO;
......@@ -25,6 +26,7 @@ import com.makeit.module.iot.service.IotDevicePropertiesOperateService;
import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.device.PlatDeviceOtherService;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.saas.PlatTenantService;
import com.makeit.utils.DeviceCacheUtil;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.convert.PageUtil;
......@@ -60,6 +62,8 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
private DeviceCacheUtil deviceCacheUtil;
@Autowired
private IotDevicePropertiesOperateService devicePropertiesOperateService;
@Autowired
private PlatTenantService platTenantService;
@Override
public PageVO<PlatDeviceListVO> page(PageReqDTO<PlatDeviceQueryDTO> pageReqDTO) {
......@@ -195,12 +199,17 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
}
@Override
public PageVO<PlatDevice> pageSaas(PageReqDTO<PlatDevice> pageReqDTO) {
public PageVO<PlatDeviceListVO> pageSaas(PageReqDTO<PlatDevice> pageReqDTO) {
PlatDevice param = pageReqDTO.getData();
Page<PlatDevice> page = PageUtil.toMpPage(pageReqDTO);
LambdaQueryWrapper<PlatDevice> lambdaQueryWrapper = getLambdaQueryWrapper(param);
Page<PlatDevice> devicePage = page(page, lambdaQueryWrapper);
return PageUtil.toPageVO(devicePage);
List<PlatDevice> records = devicePage.getRecords();
List<PlatDeviceListVO> platDeviceListVOS = BeanDtoVoUtils.listVo(records, PlatDeviceListVO.class);
JoinUtil.join(platDeviceListVOS,platTenantService, BaseTenantDTO::getTenantId,BaseEntity::getId,(d,o)->{
d.setTenantName(o.getName());
});
return PageUtil.toPageVO(platDeviceListVOS,devicePage);
}
@Override
......
......@@ -13,4 +13,5 @@ import com.makeit.entity.platform.elder.PlatElderSleep;
*/
public interface PlatElderSleepService extends IService<PlatElderSleep> {
void elderSleepSleepAnalysisTask();
}
......@@ -41,6 +41,8 @@ public class PlatElderChildrenInfoUserLoginWechatServiceImpl implements PlatElde
childrenInfo.setPhone(userInfo.getPhoneNumber());
childrenInfo.setAvatar(userInfo.getAvatarUrl());
platElderChildrenInfoService.saveOrUpdate(childrenInfo);
WechatUserInfo wechatUserVo = BeanDtoVoUtils.convert(childrenInfo, WechatUserInfo.class);
FileUtil.convert(Arrays.asList(wechatUserVo), WechatUserInfo::getAvatar, (u, f) -> {
......
......@@ -6,6 +6,7 @@ import com.makeit.common.entity.BaseBusEntity;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.saas.PlatTenant;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.report.DeviceNameEnum;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.iot.service.IotOrgService;
import com.makeit.module.iot.vo.DeviceInstanceEntity;
......@@ -13,6 +14,7 @@ import com.makeit.module.iot.vo.DeviceState;
import com.makeit.module.system.service.SysDictionaryCategoryService;
import com.makeit.module.system.vo.DictionaryVo;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.elder.PlatElderSleepService;
import com.makeit.service.saas.PlatTenantService;
import com.makeit.utils.DeviceCacheUtil;
import lombok.extern.slf4j.Slf4j;
......@@ -43,6 +45,8 @@ public class IotSyncTask {
private SysDictionaryCategoryService sysDictionaryCategoryService;
@Autowired
private DeviceCacheUtil deviceCacheUtil;
@Autowired
private PlatElderSleepService platElderSleepService;
/**
* 一小时同步一次
......@@ -108,7 +112,8 @@ public class IotSyncTask {
}
platDevice.setOriDeviceId(iotDevice.getId());
platDevice.setName(iotDevice.getName());
platDevice.setProductName(iotDevice.getProductName());
String productName = iotDevice.getProductName();
platDevice.setProductName(productName);
platDevice.setProductId(iotDevice.getProductId());
if(iotDevice.getRegistryTime()!=null) {
LocalDateTime registryTime = LocalDateTime.ofEpochSecond(iotDevice.getRegistryTime() / 1000, 0, ZoneOffset.ofHours(8));
......@@ -120,7 +125,8 @@ public class IotSyncTask {
platDevice.setStatus(deviceState.getValue());
//todo 根据类型名称来匹配
platDevice.setCategory(dicNameIdMap.get(iotDevice.getProductName()));
String categoryName = DeviceNameEnum.getNameByPrefix(productName);
platDevice.setCategory(dicNameIdMap.get(categoryName));
// platDevice.setFirmwareVersion();
// platDevice.setLastOnlineData();
// platDevice.setOrgId();
......@@ -145,4 +151,15 @@ public class IotSyncTask {
*
*/
/**
* 长者睡眠分析
*/
//@Scheduled(cron = "0 6 * * *")
@TenantIdIgnore
public void elderSleepSleepAnalysisTask() {
log.info("开始定时分析长者睡眠质量");
platElderSleepService.elderSleepSleepAnalysisTask();
log.info("定时分析长者睡眠质量结束");
}
}
......@@ -2,10 +2,13 @@ package com.makeit.utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.saas.PlatTenant;
import com.makeit.enums.redis.RedisConst;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.global.aspect.tenant.TenantIdIgnoreUtil;
import com.makeit.module.iot.enums.DeviceState;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.saas.PlatTenantService;
import com.makeit.utils.redis.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -21,29 +24,35 @@ public class DeviceCacheUtil implements ApplicationRunner {
@Autowired
private PlatDeviceService platDeviceService;
@Autowired
private PlatTenantService platTenantService;
public List<PlatDevice> getAll() {
List<PlatDevice> list = platDeviceService.list(new LambdaQueryWrapper<PlatDevice>().eq(PlatDevice::getStatus,DeviceState.online.getValue()));
list.stream().forEach(vo -> {
put(vo);
return TenantIdIgnoreUtil.execute(()->{
List<PlatDevice> list = platDeviceService.list(new LambdaQueryWrapper<PlatDevice>().eq(PlatDevice::getStatus,DeviceState.online.getValue()));
list.stream().forEach(vo -> {
put(vo);
});
return list;
});
return list;
}
public void put(PlatDevice platDevice) {
PlatTenant platTenant = platTenantService.getById(platDevice.getTenantId());
if(StringUtils.equals(platDevice.getStatus(),DeviceState.online.getValue())) {
RedisUtil.set(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId(), platDevice);
RedisUtil.set(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId()+":"+platTenant.getIotOrgId(), platDevice);
}else {
RedisUtil.delete(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId());
RedisUtil.delete(RedisConst.PLAT_IOT_DEVICE_PREFIX + platDevice.getOriDeviceId()+":"+platTenant.getIotOrgId());
}
}
public PlatDevice get(String oriDeviceId) {
PlatDevice platDevice = RedisUtil.get(RedisConst.PLAT_IOT_DEVICE_PREFIX + oriDeviceId);
public PlatDevice get(String oriDeviceIdAndIotOrgId) {
PlatDevice platDevice = RedisUtil.get(RedisConst.PLAT_IOT_DEVICE_PREFIX + oriDeviceIdAndIotOrgId);
if(platDevice==null){
getAll();
}
return RedisUtil.get(RedisConst.PLAT_IOT_DEVICE_PREFIX + oriDeviceId);
return RedisUtil.get(RedisConst.PLAT_IOT_DEVICE_PREFIX + oriDeviceIdAndIotOrgId);
}
public void putAll(Collection<PlatDevice> platDeviceList) {
platDeviceList.forEach(vo -> {
......
......@@ -74,4 +74,7 @@ public class PlatDeviceListVO extends BaseTenantDTO {
private LocalDateTime endDate;
private String tenantName;
}
......@@ -21,18 +21,19 @@
<dependency>
<groupId>com.makeit</groupId>
<artifactId>server-common</artifactId>
<artifactId>saas-module</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.makeit</groupId>
<artifactId>saas-module</artifactId>
<artifactId>server-module</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.makeit</groupId>
<artifactId>server-module</artifactId>
<artifactId>server-api</artifactId>
<version>1.0.0</version>
</dependency>
......
......@@ -24,6 +24,7 @@ public class MqttConfig {
private String defaultTopic;
private int timeout;
private int keepalive;
private Boolean msgSwitch;
public MqttConfig() {
super();
......@@ -44,6 +45,9 @@ public class MqttConfig {
@Bean
public MqttPushClient getMqttPushClient() {
if (!msgSwitch) {
return null;
}
clientId = StringUtils.isNotEmpty(clientId) ? clientId : iotTokenService.getIotToken();
mqttPushClient.connect(hostUrl, clientId, username, password, timeout, keepalive);
// 订阅主题
......@@ -51,6 +55,14 @@ public class MqttConfig {
return mqttPushClient;
}
public Boolean getMsgSwitch() {
return msgSwitch;
}
public void setMsgSwitch(Boolean msgSwitch) {
this.msgSwitch = msgSwitch;
}
public String getUsername() {
return username;
}
......
package com.makeit.mqtt;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.global.annotation.AuthIgnore;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.iot.service.IotDevicePropertiesOperateService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "发送mqtt消息")
@RestController
@RequestMapping("/mqtt")
public class MqttController {
@Autowired
private MqttPushClient mqttPushClient;
@Autowired
private IotDevicePropertiesOperateService devicePropertiesOperateService;
@ApiOperation("测试")
@PostMapping("testMqtt")
@AuthIgnore
@TenantIdIgnore
public ApiResponseEntity<Void> testMqtt() {
devicePropertiesOperateService.deviceWrite("1701240048151490560", 1,1,1);
return ApiResponseUtils.success();
}
}
......@@ -37,6 +37,7 @@ public class MqttPushClient {
* @param keepalive
*/
public void connect(String host, String clientId, String username, String password, int timeout, int keepalive) {
MqttClient client;
try {
client = new MqttClient(host, clientId, new MemoryPersistence());
......
......@@ -7,6 +7,7 @@ import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.iot.vo.DeviceInfo;
import com.makeit.module.iot.vo.HeaderInfo;
import com.makeit.service.platform.alarm.alarmStrategy.IAlarm;
import com.makeit.utils.AlarmConfigCacheUtil;
import com.makeit.utils.DeviceCacheUtil;
......@@ -79,43 +80,49 @@ public class PushCallback implements MqttCallback {
@TenantIdIgnore
@Async
public void checkAlarm(DeviceInfo device) {
StopWatch stopWatch = new StopWatch();
stopWatch.start("checkAlarm-1");
String deviceId = device.getDeviceId();
JSONObject properties = device.getProperties();
//iot设备id
PlatDevice platDevice = deviceCacheUtil.get(deviceId);
if(platDevice==null){
logger.error("设备信息异常,设备iot-id:"+deviceId);
return;
}
List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice);
deviceAlarmConfigList.removeIf(Objects::isNull);
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
logger.error("该设备没有告警配置:"+deviceId);
return;
}
for (PlatAlarmConfig config : deviceAlarmConfigList) {
String alarmType = config.getAlarmType();
PlatAlarmCheckDTO platAlarmCheckDTO = new PlatAlarmCheckDTO();
//告警配置
platAlarmCheckDTO.setPlatAlarmConfig(config);
//设备信息
platAlarmCheckDTO.setPlatDevice(platDevice);
//iot上报数据
platAlarmCheckDTO.setProperties(properties);
for (IAlarm alarm : alarmList) {
if (alarm.support(alarmType)) {
alarm.checkConfig(platAlarmCheckDTO);
HeaderInfo headers = device.getHeaders();
List<HeaderInfo.Bind> bindings = headers.getBindings();
for (HeaderInfo.Bind binding : bindings) {
String iot_tenantId = binding.getId();
StopWatch stopWatch = new StopWatch();
stopWatch.start("checkAlarm-1");
String deviceId = device.getDeviceId();
JSONObject properties = device.getProperties();
//iot设备id
PlatDevice platDevice = deviceCacheUtil.get(deviceId+":"+iot_tenantId);
if(platDevice==null){
logger.error("获取设备信息异常,设备iot-id:"+deviceId);
return;
}
List<PlatAlarmConfig> deviceAlarmConfigList = alarmConfigCacheUtil.getDeviceAlarmConfigMap(platDevice);
deviceAlarmConfigList.removeIf(Objects::isNull);
if (CollectionUtils.isEmpty(deviceAlarmConfigList)) {
logger.error("该设备没有告警配置,设备iot-id:"+deviceId);
return;
}
for (PlatAlarmConfig config : deviceAlarmConfigList) {
String alarmType = config.getAlarmType();
PlatAlarmCheckDTO platAlarmCheckDTO = new PlatAlarmCheckDTO();
//告警配置
platAlarmCheckDTO.setPlatAlarmConfig(config);
//设备信息
platAlarmCheckDTO.setPlatDevice(platDevice);
//iot上报数据
platAlarmCheckDTO.setProperties(properties);
for (IAlarm alarm : alarmList) {
if (alarm.support(alarmType)) {
alarm.checkConfig(platAlarmCheckDTO);
}
}
}
stopWatch.stop();
logger.info(stopWatch.prettyPrint());
}
stopWatch.stop();
logger.info(stopWatch.prettyPrint());
}
......
......@@ -119,16 +119,17 @@ mqtt:
defaultTopic: /device/*/*/**
timeout: 10
keepalive: 60
msgSwitch: false
wx:
miniapp:
config:
appid: wx48720402e3fdbe0f #微信小程序的appid
secret: 2ebae648f45716e70c75b7d78d0660cc #微信小程序的Secret
# appid: wx48720402e3fdbe0f #微信小程序的appid
# secret: 2ebae648f45716e70c75b7d78d0660cc #微信小程序的Secret
appid: wx454f0dbc28a6529a #微信小程序的appid
secret: fb20da3064d6b7ac90d5c15cf407df46 #微信小程序的Secret
token: #微信小程序消息服务器配置的token
aesKey: #微信小程序消息服务器配置的EncodingAESKey
msgDataFormat: JSON
......
......@@ -116,15 +116,16 @@ mqtt:
defaultTopic: /device/*/*/**
timeout: 10
keepalive: 60
msgSwitch: true
wx:
miniapp:
config:
appid: wx48720402e3fdbe0f #微信小程序的appid
secret: 2ebae648f45716e70c75b7d78d0660cc #微信小程序的Secret
# appid: wx48720402e3fdbe0f #微信小程序的appid
# secret: 2ebae648f45716e70c75b7d78d0660cc #微信小程序的Secret
# appid: wx48720402e3fdbe0f #微信小程序的appid
# secret: 2ebae648f45716e70c75b7d78d0660cc #微信小程序的Secret
appid: wx454f0dbc28a6529a #微信小程序的appid
secret: fb20da3064d6b7ac90d5c15cf407df46 #微信小程序的Secret
token: #微信小程序消息服务器配置的token
aesKey: #微信小程序消息服务器配置的EncodingAESKey
......
......@@ -44,7 +44,7 @@ public class IotDeviceInfoContentFall {
@Test
void getOrgDevice() {
iotOrgService.getOrgDevice("1698939546961244160");
iotOrgService.getOrgDevice("1701223487902642176");
}
@Test
......@@ -64,7 +64,7 @@ public class IotDeviceInfoContentFall {
@Test
void getDeviceLogByTimeRange() {
iotProductDeviceService.getDeviceLogByTimeRange("1701127702523473920", "reportProperty", 100, "2023-09-12 00:00:00", "2023-09-12 23:59:00");
iotProductDeviceService.getDeviceLogByTimeRange("1702604383784333312", "reportProperty", 1000, "2023-09-19 14:23:32", "2023-09-19 15:23:32");
}
@Test
......
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