Commit c828848a by 汪志阳

fix:初始化config离床

parent 2107cd3f
ALTER TABLE `plat_device_other`
ALTER TABLE `plat_device_other`
......@@ -4,8 +4,7 @@ ADD COLUMN `secure_key` varchar(255) COMMENT '密钥key' AFTER `secure_id`;
ALTER TABLE `plat_alarm_record`
ADD COLUMN `misinformation_flag` char(1) DEFAULT 0 COMMENT '是否误报 1 误报 0 没有误报' AFTER `read_flag`
ADD COLUMN `wechat_read_flag` char(1) DEFAULT 0 COMMENT '小程序端是否读取 0未读 1已读' AFTER `misinformation_flag`;
ADD COLUMN `misinformation_flag` char(1) DEFAULT 0 COMMENT '是否误报 1 误报 0 没有误报' AFTER `read_flag`;
ALTER TABLE `plat_elder_report_month`
......@@ -62,7 +61,7 @@ CREATE TABLE `plat_device_log` (
ALTER TABLE `plat_alarm_config` modify column alarm_type char(1) comment '告警类型 数据字典 1 长者跌倒 2 呼吸异常 3 心率异常 4 行为异常 5 离床异常';
INSERT INTO `plat_alarm_config`(`id`, `alarm_type`, `status`, `org_id`, `city_org_id`, `district_org_id`, `street_org_id`, `org_path`, `rule_config`, `content`, `notify_channel`, `notify_relation`, `notify_way`, `notify_user`, `description`, `create_by`, `create_date`, `update_by`, `update_date`, `del_flag`, `tenant_id`, `content_audit`)
VALUES ('16996678722776842252', '5', '1', '1701542574740770817', NULL, NULL, NULL, NULL, '{\"offBedStart\":\"0:00\",\"startTimeType\":\"1\",\"offBedEnd\":\"10:00\",\"endTimeType\":\"2\",\"duration\":\"5\"}', '[#长者姓名]离床时间过长,请及时处理!', '', '1', '1', NULL, NULL, 'platAdmin02', NOW(), 'platAdmin02', NOW(), '0', '0', NULL);
VALUES ('16996678722776842252', '5', '1', '1701542574740770817', NULL, NULL, NULL, NULL, '{"offBedStart":"00:00:00","offBedEnd":"05:00:00","duration":"60"}', '[#长者姓名]离床时间过长,请及时处理!', '', '1', '1', NULL, NULL, 'platAdmin02', NOW(), 'platAdmin02', NOW(), '0', '0', NULL);
## 离床异常字典
INSERT INTO `sys_dictionary` VALUES ('204', 'alarm.alarmType.offBed', '离床异常', '5', 5, '', '200', NOW(), NOW(), '0', NULL, NULL, NULL);
## 离床次数月统计
......@@ -83,3 +82,6 @@ CREATE TABLE `saas_pid_manage` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='声网pid管理';
ALTER TABLE `plat_alarm_record`
ADD COLUMN `wechat_read_flag` char(1) DEFAULT 0 COMMENT '小程序端是否读取 0未读 1已读' AFTER `misinformation_flag`;
......@@ -97,5 +97,15 @@ public class PlatAlarmConfigController {
}
@ApiOperation("初始化数据")
@PostMapping("/data/init")
@TenantIdIgnore
@AuthIgnore
public ApiResponseEntity<PlatAlarmConfig> initConfig() {
platAlarmConfigService.initData();
return ApiResponseUtils.success();
}
}
......@@ -41,4 +41,5 @@ public interface PlatAlarmConfigService extends IService<PlatAlarmConfig> {
List<PlatHealthConfigDTO> getHealthConfigList();
void initData();
}
......@@ -151,7 +151,7 @@ public class OffBedAlarm implements IAlarm {
Long firstOffBedLong = alarmRedisDTO.getStartLong();
long currentTimeMillis = System.currentTimeMillis();
LocalDateTime nowTest = LocalDateTime.now().plusHours(7).plusMinutes(20);
LocalDateTime nowTest = LocalDateTime.now().plusHours(6);
currentTimeMillis = nowTest.toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("handleCrossDay,测试当前的时间:{},时间戳:{}", nowTest, currentTimeMillis);
boolean isOverTime = (currentTimeMillis - firstOffBedLong) / 1000 >= duration * 60;
......@@ -174,7 +174,7 @@ public class OffBedAlarm implements IAlarm {
return;
}
// LocalDateTime now = LocalDateTime.now();
LocalDateTime now = LocalDateTime.now().plusHours(7).plusMinutes(20);;
LocalDateTime now = LocalDateTime.now().plusHours(6);;
LocalDateTime startLocalDteTime = LocalDateTime.of(LocalDate.now(), startTime);
if (!isInTime) {
long mills = Duration.between(startLocalDteTime, now).toMillis() / 1000;
......@@ -195,7 +195,7 @@ public class OffBedAlarm implements IAlarm {
}
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now().plusHours(7).plusMinutes(20);
LocalDateTime now = LocalDateTime.now().plusHours(6);
System.out.println(now);
}
......@@ -212,7 +212,7 @@ public class OffBedAlarm implements IAlarm {
Long firstOffBedLong = alarmRedisDTO.getStartLong();
long currentTimeMillis = System.currentTimeMillis();
LocalDateTime nowTest = LocalDateTime.now().plusHours(7).plusMinutes(20);
LocalDateTime nowTest = LocalDateTime.now().plusHours(6);
currentTimeMillis = nowTest.toInstant(ZoneOffset.of("+8")).toEpochMilli();
boolean isOverTime = (currentTimeMillis - firstOffBedLong) / 1000 >= duration * 60;
LocalDateTime firstOffBedTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(firstOffBedLong), ZoneOffset.of("+8"));
......@@ -239,7 +239,7 @@ public class OffBedAlarm implements IAlarm {
return;
}
LocalDateTime now = LocalDateTime.now().plusHours(7).plusMinutes(20);
LocalDateTime now = LocalDateTime.now().plusHours(6);
if (!isInTime && now.isAfter(startLocalDteTime) && now.isBefore(endLocalDteTime)) {
long mills = Duration.between(startLocalDteTime, now).toMillis() / 1000;
boolean noInOverTime = mills >= duration * 60;
......
package com.makeit.service.platform.alarm.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.dto.StatusDTO;
import com.makeit.dto.platform.alarm.PlatAlarmConfigDTOVO;
......@@ -16,6 +19,7 @@ import com.makeit.exception.BusinessException;
import com.makeit.global.aspect.tenant.TenantIdUtil;
import com.makeit.mapper.platform.alarm.PlatAlarmConfigMapper;
import com.makeit.service.platform.alarm.PlatAlarmConfigService;
import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.auth.PlatUserService;
import com.makeit.utils.AlarmConfigCacheUtil;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
......@@ -23,13 +27,17 @@ import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.old.StringUtils;
import com.makeit.utils.sql.join.JoinUtil;
import com.makeit.vo.platform.alarm.PlatAlarmConfigListVO;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
/**
* <p>
......@@ -47,6 +55,8 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe
@Autowired
private AlarmConfigCacheUtil alarmConfigUtil;
@Resource
private PlatOrgService platOrgService;
@Override
public List<PlatAlarmConfigListVO> list(PlatAlarmConfigQueryDTO dto) {
......@@ -221,4 +231,29 @@ public class PlatAlarmConfigServiceImpl extends ServiceImpl<PlatAlarmConfigMappe
public List<PlatHealthConfigDTO> getHealthConfigList() {
return baseMapper.getHealthConfigList();
}
@Override
public void initData() {
List<PlatOrg> orgList = platOrgService.list();
PlatAlarmConfig config = getOne(Wrappers.<PlatAlarmConfig>lambdaQuery().eq(PlatAlarmConfig::getTenantId, 0)
.eq(PlatAlarmConfig::getAlarmType, "5"));
List<String> orgIds = orgList.stream().map(PlatOrg::getId).collect(Collectors.toList());
List<PlatAlarmConfig> existList = list(Wrappers.<PlatAlarmConfig>lambdaQuery().in(PlatAlarmConfig::getOrgId, orgIds)
.eq(PlatAlarmConfig::getAlarmType, "5"));
Map<String, PlatAlarmConfig> configMap = StreamUtil.toMap(existList, PlatAlarmConfig::getOrgId);
List<PlatAlarmConfig> saveList = Lists.newArrayList();
for (PlatOrg o : orgList) {
if (configMap.containsKey(o.getId())) {
continue;
}
PlatAlarmConfig alarmConfig = new PlatAlarmConfig();
BeanUtil.copyProperties(config, alarmConfig, "id");
alarmConfig.setTenantId(o.getTenantId());
alarmConfig.setOrgId(o.getId());
saveList.add(alarmConfig);
}
if (CollUtil.isNotEmpty(saveList)) {
saveBatch(saveList);
}
}
}
......@@ -148,9 +148,8 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
if (parentSpace!=null && parentSpace.getParentPath()!=null && parentSpace.getParentPath().contains(dto.getId())) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_NOT_AUTH_PARENT);
}
// 编辑后层级大于4,不允许编辑
checkMaxLevel(space);
// todo 编辑后层级大于4,不允许编辑 脏数据太多,待校验
// checkAndUpdateSonSpace(space);
this.updateById(space);
List<String> lastSpaceIds = recursionLastSpaceIds(space.getId(), new ArrayList<>());
if (CollUtil.isEmpty(lastSpaceIds)) {
......@@ -218,8 +217,9 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
return result;
}
private void checkMaxLevel(PlatSpace space) {
int level = StrUtil.isBlank(space.getParentPath()) ? 0 : space.getParentPath().split(",").length;
private void checkAndUpdateSonSpace(PlatSpace space) {
String parentPath = space.getParentPath();
int level = StrUtil.isBlank(parentPath) ? 0 : parentPath.split(",").length;
if (level > 3) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_OVER_LEVEL);
}
......@@ -243,17 +243,22 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
if (level + sonLevel > 3) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_OVER_LEVEL);
}
}
private List<String> recursionSpaceId(List<String> result, String spaceId) {
List<PlatSpace> platSpaces = this.list(Wrappers.<PlatSpace>lambdaQuery().eq(PlatSpace::getParentId, spaceId));
if (CollUtil.isNotEmpty(platSpaces)) {
platSpaces.forEach(p -> recursionLastSpaceIds(p.getId(), result));
} else {
result.add(spaceId);
return result;
// 更新下级空间的parentPath
if (CollUtil.isNotEmpty(platSpaceList)) {
platSpaceList.forEach(s -> {
if (StrUtil.isBlank(s.getParentPath())) {
return;
}
int indexOf = s.getParentPath().indexOf(spaceId);
if (indexOf == -1) {
return;
}
String oldSpacePath = s.getParentPath().substring(indexOf);
s.setParentPath(parentPath + "," + oldSpacePath);
updateById(s);
});
}
return result;
}
@Override
......
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