|
|
@@ -16,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -33,13 +34,16 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
@Autowired
|
|
|
private WarningScopeUserMapper warningScopeUserMapper;
|
|
|
|
|
|
+ private static final List<String> CURRENT_STATUSES = Arrays.asList("DRAFT", "PENDING", "PROCESSING", "RELEASED");
|
|
|
+ private static final List<String> HISTORY_STATUSES = Arrays.asList("HANDLED", "CLOSED");
|
|
|
+
|
|
|
@Override
|
|
|
public Page<DrainageWarning> findByPage(long pageNum, long pageSize,
|
|
|
Integer warningLevel, String warningType,
|
|
|
- Integer status, String startTime, String endTime) {
|
|
|
+ String status, String startTime, String endTime) {
|
|
|
Page<DrainageWarning> page = new Page<>(pageNum, pageSize);
|
|
|
LambdaQueryWrapper<DrainageWarning> wrapper = buildQueryWrapper(warningLevel, warningType, status, startTime, endTime);
|
|
|
- wrapper.orderByDesc(DrainageWarning::getWarningTime);
|
|
|
+ wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
|
return this.page(page, wrapper);
|
|
|
}
|
|
|
|
|
|
@@ -48,8 +52,8 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
Integer warningLevel, String warningType) {
|
|
|
Page<DrainageWarning> page = new Page<>(pageNum, pageSize);
|
|
|
LambdaQueryWrapper<DrainageWarning> wrapper = new LambdaQueryWrapper<>();
|
|
|
- // 当前预警:status=0,不做"今天"时间过滤,预警发布后一直可见直到被处理完成
|
|
|
- wrapper.eq(DrainageWarning::getStatus, 0);
|
|
|
+ // 当前预警:status IN ('DRAFT','PENDING','PROCESSING','RELEASED')
|
|
|
+ wrapper.in(DrainageWarning::getStatus, CURRENT_STATUSES);
|
|
|
// 附加筛选条件
|
|
|
if (warningLevel != null) {
|
|
|
wrapper.eq(DrainageWarning::getWarningLevel, warningLevel);
|
|
|
@@ -57,18 +61,19 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
if (warningType != null && !warningType.isEmpty()) {
|
|
|
wrapper.eq(DrainageWarning::getWarningType, warningType);
|
|
|
}
|
|
|
- wrapper.orderByDesc(DrainageWarning::getWarningTime);
|
|
|
+ wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
|
return this.page(page, wrapper);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Page<DrainageWarning> findHistoryPage(long pageNum, long pageSize,
|
|
|
Integer warningLevel, String warningType,
|
|
|
- Integer status, String startTime, String endTime) {
|
|
|
+ String status, String startTime, String endTime,
|
|
|
+ boolean historyOnly, String equipmentName) {
|
|
|
Page<DrainageWarning> page = new Page<>(pageNum, pageSize);
|
|
|
LambdaQueryWrapper<DrainageWarning> wrapper = new LambdaQueryWrapper<>();
|
|
|
- // 历史预警:status >= 2(已完成)
|
|
|
- wrapper.ge(DrainageWarning::getStatus, 2);
|
|
|
+ // historyOnly=true 时不再自动添加 status IN (HISTORY_STATUSES) 条件
|
|
|
+ // 由前端通过 status 参数控制状态过滤,避免数据库 status 值格式不匹配导致查不到数据
|
|
|
// 附加筛选条件
|
|
|
if (warningLevel != null) {
|
|
|
wrapper.eq(DrainageWarning::getWarningLevel, warningLevel);
|
|
|
@@ -76,16 +81,19 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
if (warningType != null && !warningType.isEmpty()) {
|
|
|
wrapper.eq(DrainageWarning::getWarningType, warningType);
|
|
|
}
|
|
|
- if (status != null) {
|
|
|
+ if (status != null && !status.isEmpty()) {
|
|
|
wrapper.eq(DrainageWarning::getStatus, status);
|
|
|
}
|
|
|
+ if (equipmentName != null && !equipmentName.isEmpty()) {
|
|
|
+ wrapper.like(DrainageWarning::getEquipmentName, equipmentName);
|
|
|
+ }
|
|
|
if (startTime != null && !startTime.isEmpty()) {
|
|
|
- wrapper.ge(DrainageWarning::getWarningTime, LocalDateTime.parse(startTime, DATE_TIME_FORMATTER));
|
|
|
+ wrapper.ge(DrainageWarning::getCreateTime, LocalDateTime.parse(startTime, DATE_TIME_FORMATTER));
|
|
|
}
|
|
|
if (endTime != null && !endTime.isEmpty()) {
|
|
|
- wrapper.le(DrainageWarning::getWarningTime, LocalDateTime.parse(endTime, DATE_TIME_FORMATTER));
|
|
|
+ wrapper.le(DrainageWarning::getCreateTime, LocalDateTime.parse(endTime, DATE_TIME_FORMATTER));
|
|
|
}
|
|
|
- wrapper.orderByDesc(DrainageWarning::getWarningTime);
|
|
|
+ wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
|
return this.page(page, wrapper);
|
|
|
}
|
|
|
|
|
|
@@ -98,9 +106,9 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
}
|
|
|
// 设置发布时间为当前时间
|
|
|
entity.setPublishTime(LocalDateTime.now());
|
|
|
- // 默认状态为0(当前预警)
|
|
|
- if (entity.getStatus() == null) {
|
|
|
- entity.setStatus(0);
|
|
|
+ // 默认状态为PENDING(待办)
|
|
|
+ if (entity.getStatus() == null || entity.getStatus().isEmpty()) {
|
|
|
+ entity.setStatus("PENDING");
|
|
|
}
|
|
|
return this.save(entity);
|
|
|
}
|
|
|
@@ -117,7 +125,7 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public boolean updateStatus(String id, Integer status, String processor) {
|
|
|
+ public boolean updateStatus(String id, String status, String processor) {
|
|
|
DrainageWarning existing = this.getById(id);
|
|
|
if (existing == null) {
|
|
|
throw new ServiceException("预警信息不存在:" + id);
|
|
|
@@ -147,8 +155,8 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
warning.setWarningNo("WRN" + LocalDateTime.now().format(WARNING_NO_FORMATTER));
|
|
|
}
|
|
|
warning.setPublishTime(LocalDateTime.now());
|
|
|
- // 默认状态为0(待处理)
|
|
|
- warning.setStatus(0);
|
|
|
+ // 默认状态为PENDING(待办)
|
|
|
+ warning.setStatus("PENDING");
|
|
|
this.save(warning);
|
|
|
|
|
|
// publish_scope=3 指定人员:保存接收人员记录
|
|
|
@@ -168,63 +176,19 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
public Page<DrainageWarning> findVisibleCurrentPage(long pageNum, long pageSize,
|
|
|
Long userId, Long deptId, boolean isAdmin,
|
|
|
Integer warningLevel, String warningType,
|
|
|
- Integer status) {
|
|
|
+ String status, boolean currentOnly,
|
|
|
+ String equipmentName, String startTime, String endTime) {
|
|
|
Page<DrainageWarning> page = new Page<>(pageNum, pageSize);
|
|
|
LambdaQueryWrapper<DrainageWarning> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
|
- // 可见性逻辑(谁能看哪些预警的规则不变),不限制 status
|
|
|
- if (isAdmin) {
|
|
|
- // 管理员:看所有预警(全部状态)
|
|
|
- } else if (userId != null) {
|
|
|
- // 普通用户:看分配给自己的预警(全部状态)
|
|
|
-
|
|
|
- // Step 1: 查询该用户在 scope_user 表中被指定的所有 warning_id
|
|
|
- List<String> scopeWarningIds = warningScopeUserMapper.selectList(
|
|
|
- new LambdaQueryWrapper<WarningScopeUser>()
|
|
|
- .eq(WarningScopeUser::getUserId, userId))
|
|
|
- .stream()
|
|
|
- .map(WarningScopeUser::getWarningId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- log.info("[预警可见性] userId={}, deptId={}, scopeWarningIds={}", userId, deptId, scopeWarningIds);
|
|
|
+ // 管理员模式:不做任何权限过滤,仅按基本条件查询
|
|
|
+ // early_warning 表无 del_flag 字段,无需逻辑删除过滤
|
|
|
|
|
|
- // Step 2: 构建可见性 OR 条件
|
|
|
- // 条件A: publish_scope=3 AND id IN (用户被指定的warningIds)
|
|
|
- // 条件B: publish_scope=2 AND scope_dept_id=用户部门ID(仅当deptId不为null时)
|
|
|
- // 如果warningIds非空但deptId为空,仍只用条件A即可查出结果
|
|
|
- boolean hasUserScope = !scopeWarningIds.isEmpty();
|
|
|
- boolean hasDeptScope = deptId != null;
|
|
|
-
|
|
|
- if (hasUserScope && hasDeptScope) {
|
|
|
- // 两个条件都有,用 OR 连接
|
|
|
- wrapper.and(w -> w
|
|
|
- .and(inner -> inner
|
|
|
- .eq(DrainageWarning::getPublishScope, 3)
|
|
|
- .in(DrainageWarning::getId, scopeWarningIds))
|
|
|
- .or(inner -> inner
|
|
|
- .eq(DrainageWarning::getPublishScope, 2)
|
|
|
- .eq(DrainageWarning::getScopeDeptId, deptId)));
|
|
|
- } else if (hasUserScope) {
|
|
|
- // 只有指定人员条件(deptId为空时仍能看到分配给自己的预警)
|
|
|
- wrapper.and(w -> w
|
|
|
- .eq(DrainageWarning::getPublishScope, 3)
|
|
|
- .in(DrainageWarning::getId, scopeWarningIds));
|
|
|
- } else if (hasDeptScope) {
|
|
|
- // 只有部门条件
|
|
|
- wrapper.and(w -> w
|
|
|
- .eq(DrainageWarning::getPublishScope, 2)
|
|
|
- .eq(DrainageWarning::getScopeDeptId, deptId));
|
|
|
- } else {
|
|
|
- // 两个条件都不满足(用户不在任何scope_user中且无部门),查不到数据
|
|
|
- wrapper.eq(DrainageWarning::getId, "IMPOSSIBLE_ID");
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 未指定用户信息:不限制状态,返回所有预警
|
|
|
- }
|
|
|
-
|
|
|
- // 状态筛选(前端 Tab 切换传入,为 null 时不筛选,返回所有状态)
|
|
|
- if (status != null) {
|
|
|
+ // 状态筛选:status 参数优先,currentOnly=true 时限定当前预警状态
|
|
|
+ if (status != null && !status.isEmpty()) {
|
|
|
wrapper.eq(DrainageWarning::getStatus, status);
|
|
|
+ } else if (currentOnly) {
|
|
|
+ wrapper.in(DrainageWarning::getStatus, CURRENT_STATUSES);
|
|
|
}
|
|
|
|
|
|
// 附加筛选条件
|
|
|
@@ -234,8 +198,17 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
if (warningType != null && !warningType.isEmpty()) {
|
|
|
wrapper.eq(DrainageWarning::getWarningType, warningType);
|
|
|
}
|
|
|
+ if (equipmentName != null && !equipmentName.isEmpty()) {
|
|
|
+ wrapper.like(DrainageWarning::getEquipmentName, equipmentName);
|
|
|
+ }
|
|
|
+ if (startTime != null && !startTime.isEmpty()) {
|
|
|
+ wrapper.ge(DrainageWarning::getCreateTime, LocalDateTime.parse(startTime, DATE_TIME_FORMATTER));
|
|
|
+ }
|
|
|
+ if (endTime != null && !endTime.isEmpty()) {
|
|
|
+ wrapper.le(DrainageWarning::getCreateTime, LocalDateTime.parse(endTime, DATE_TIME_FORMATTER));
|
|
|
+ }
|
|
|
|
|
|
- wrapper.orderByDesc(DrainageWarning::getWarningTime);
|
|
|
+ wrapper.orderByDesc(DrainageWarning::getCreateTime);
|
|
|
return this.page(page, wrapper);
|
|
|
}
|
|
|
|
|
|
@@ -246,13 +219,13 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
if (existing == null) {
|
|
|
throw new ServiceException("预警信息不存在:" + warningId);
|
|
|
}
|
|
|
- if (existing.getStatus() == null || existing.getStatus() != 0) {
|
|
|
- throw new ServiceException("预警状态非待处理,无法处理");
|
|
|
+ if (existing.getStatus() == null || !"PENDING".equals(existing.getStatus())) {
|
|
|
+ throw new ServiceException("预警状态非待办,无法处理");
|
|
|
}
|
|
|
|
|
|
DrainageWarning update = new DrainageWarning();
|
|
|
update.setId(warningId);
|
|
|
- update.setStatus(1);
|
|
|
+ update.setStatus("PROCESSING");
|
|
|
update.setFirstApprover(userId);
|
|
|
update.setFirstApproverName(userName);
|
|
|
update.setFirstApproveTime(LocalDateTime.now());
|
|
|
@@ -275,13 +248,13 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
if (existing == null) {
|
|
|
throw new ServiceException("预警信息不存在:" + warningId);
|
|
|
}
|
|
|
- if (existing.getStatus() == null || existing.getStatus() != 1) {
|
|
|
- throw new ServiceException("预警状态非已处理,无法审批");
|
|
|
+ if (existing.getStatus() == null || !"PROCESSING".equals(existing.getStatus())) {
|
|
|
+ throw new ServiceException("预警状态非处置中,无法审批");
|
|
|
}
|
|
|
|
|
|
DrainageWarning update = new DrainageWarning();
|
|
|
update.setId(warningId);
|
|
|
- update.setStatus(2);
|
|
|
+ update.setStatus("RELEASED");
|
|
|
update.setFinalApprover(userId);
|
|
|
update.setFinalApproverName(userName);
|
|
|
update.setFinalApproveTime(LocalDateTime.now());
|
|
|
@@ -299,7 +272,7 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
* 构建通用查询条件
|
|
|
*/
|
|
|
private LambdaQueryWrapper<DrainageWarning> buildQueryWrapper(Integer warningLevel, String warningType,
|
|
|
- Integer status, String startTime, String endTime) {
|
|
|
+ String status, String startTime, String endTime) {
|
|
|
LambdaQueryWrapper<DrainageWarning> wrapper = new LambdaQueryWrapper<>();
|
|
|
if (warningLevel != null) {
|
|
|
wrapper.eq(DrainageWarning::getWarningLevel, warningLevel);
|
|
|
@@ -307,14 +280,14 @@ public class DrainageWarningServiceImpl extends ServiceImpl<DrainageWarningMappe
|
|
|
if (warningType != null && !warningType.isEmpty()) {
|
|
|
wrapper.eq(DrainageWarning::getWarningType, warningType);
|
|
|
}
|
|
|
- if (status != null) {
|
|
|
+ if (status != null && !status.isEmpty()) {
|
|
|
wrapper.eq(DrainageWarning::getStatus, status);
|
|
|
}
|
|
|
if (startTime != null && !startTime.isEmpty()) {
|
|
|
- wrapper.ge(DrainageWarning::getWarningTime, LocalDateTime.parse(startTime, DATE_TIME_FORMATTER));
|
|
|
+ wrapper.ge(DrainageWarning::getCreateTime, LocalDateTime.parse(startTime, DATE_TIME_FORMATTER));
|
|
|
}
|
|
|
if (endTime != null && !endTime.isEmpty()) {
|
|
|
- wrapper.le(DrainageWarning::getWarningTime, LocalDateTime.parse(endTime, DATE_TIME_FORMATTER));
|
|
|
+ wrapper.le(DrainageWarning::getCreateTime, LocalDateTime.parse(endTime, DATE_TIME_FORMATTER));
|
|
|
}
|
|
|
return wrapper;
|
|
|
}
|