|
|
@@ -337,7 +337,6 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
String permission = assignmentPermission(type);
|
|
|
WorkOrder order = getOrderById(requireOrderId(orderId));
|
|
|
requireStatus(order, WorkOrderStatusEnum.PENDING_DISPATCH, "仅待派单工单允许选择人员");
|
|
|
- requireDispatchScope(order);
|
|
|
if (deptId != null && deptId <= 0) throw new ServiceException("请选择有效部门");
|
|
|
return assignmentUserMapper.selectAssignmentCandidates(assignmentCompanyDeptId(order), deptId).stream()
|
|
|
.filter(this::isNormalUser)
|
|
|
@@ -532,7 +531,6 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
if (!Objects.equals(WorkOrderStatusEnum.PENDING_DISPATCH.getCode(), order.getOrderStatus())) {
|
|
|
throw new ServiceException("仅待派单工单允许派单");
|
|
|
}
|
|
|
- requireDispatchScope(order);
|
|
|
SysUser handler = sysUserService.selectUserById(handlerId);
|
|
|
if (handler == null || !UserConstants.NORMAL.equals(String.valueOf(handler.getStatus())) || !UserConstants.NORMAL.equals(String.valueOf(handler.getDelFlag()))) {
|
|
|
throw new ServiceException("处置人不存在或已停用");
|
|
|
@@ -875,82 +873,10 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
|
|
|
private boolean isDeviceInCurrentCompany(String deviceId) {
|
|
|
if (StringUtils.isEmpty(deviceId)) return true;
|
|
|
- // 超级管理员按部门路径推断会落到某个具体公司(如 admin 挂在研发部门下),
|
|
|
- // 只有该公司设备能派单,其余子系统全部报「无权操作其他公司范围」,与实际授权不符。
|
|
|
- if (assignScopeSupport.isAdmin()) return true;
|
|
|
EquipmentBase equipment = equipmentBaseMapper.selectById(deviceId);
|
|
|
if (equipment == null || equipment.getEquipmentTypeId() == null) return false;
|
|
|
- Integer rootTypeId = rootEquipmentTypeId(equipment.getEquipmentTypeId());
|
|
|
- if (rootTypeId == null) return false;
|
|
|
- Set<Integer> scope = currentCompanyParentTypeIds();
|
|
|
- // 当前部门不属于任何一家公司(集团/管理端账号)时公司边界不适用:
|
|
|
- // 这类账号能看到全部子系统的设备,若按空范围判定会导致排水页面完全无法派单。
|
|
|
- if (scope.isEmpty()) {
|
|
|
- log.warn("当前部门不在供水/排水/燃气公司范围内,跳过设备公司范围校验,设备ID={}", deviceId);
|
|
|
- return true;
|
|
|
- }
|
|
|
- return scope.contains(rootTypeId);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 沿设备类型的 parent_id 向上追溯到一级根类型。
|
|
|
- *
|
|
|
- * 设备类型表允许三级扩展(如 排水设备 → 液位计 → 平升液位流量终端),
|
|
|
- * 直接取 parent_id 判断公司范围会把三级类型误判成其他公司。
|
|
|
- */
|
|
|
- private Integer rootEquipmentTypeId(Integer typeId) {
|
|
|
- Integer current = typeId;
|
|
|
- Set<Integer> visited = new HashSet<>();
|
|
|
- while (current != null && visited.add(current)) {
|
|
|
- EquipmentType type = equipmentTypeMapper.selectById(current);
|
|
|
- if (type == null) return null;
|
|
|
- Integer parentId = type.getParentId();
|
|
|
- if (parentId == null || parentId == 0) return type.getId();
|
|
|
- current = parentId;
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- private void requireDeviceCompanyScope(WorkOrder order) {
|
|
|
- if (order == null || StringUtils.isEmpty(order.getDeviceId())) return;
|
|
|
- if (isDeviceInCurrentCompany(order.getDeviceId())) return;
|
|
|
- throw new ServiceException("无权操作其他公司范围的工单(设备属于" + deviceCompanyName(order.getDeviceId())
|
|
|
- + ",当前账号属于" + currentCompanyName() + ")");
|
|
|
- }
|
|
|
-
|
|
|
- /** 设备所属公司名称(按设备类型一级根节点推断),仅用于错误提示。 */
|
|
|
- private String deviceCompanyName(String deviceId) {
|
|
|
- EquipmentBase equipment = equipmentBaseMapper.selectById(deviceId);
|
|
|
- Integer rootTypeId = equipment == null || equipment.getEquipmentTypeId() == null
|
|
|
- ? null : rootEquipmentTypeId(equipment.getEquipmentTypeId());
|
|
|
- return companyNameOf(rootTypeId);
|
|
|
- }
|
|
|
-
|
|
|
- /** 当前账号所属公司名称,仅用于错误提示。 */
|
|
|
- private String currentCompanyName() {
|
|
|
- Set<Integer> scope = currentCompanyParentTypeIds();
|
|
|
- if (scope.isEmpty()) return "未归属任一子公司";
|
|
|
- return scope.stream().filter(id -> id != 4).sorted().findFirst()
|
|
|
- .map(this::companyNameOf).orElse("未归属任一子公司");
|
|
|
- }
|
|
|
-
|
|
|
- private String companyNameOf(Integer rootTypeId) {
|
|
|
- if (rootTypeId == null) return "未知设备类型";
|
|
|
- switch (rootTypeId) {
|
|
|
- case 1: return "供水公司";
|
|
|
- case 2: return "排水公司";
|
|
|
- case 3: return "燃气公司";
|
|
|
- case 4: return "窨井共享设备";
|
|
|
- default: return "未知设备类型";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void requireDispatchScope(WorkOrder order) {
|
|
|
- if (StringUtils.isEmpty(order.getDeviceId())) {
|
|
|
- // 派单接口已由 Controller 校验 ops:workOrder:dispatch 权限;无设备工单不再限制创建人。
|
|
|
- return;
|
|
|
- }
|
|
|
- requireDeviceCompanyScope(order);
|
|
|
+ EquipmentType type = equipmentTypeMapper.selectById(equipment.getEquipmentTypeId());
|
|
|
+ return type != null && type.getParentId() != null && currentCompanyParentTypeIds().contains(type.getParentId());
|
|
|
}
|
|
|
|
|
|
private String assignmentPermission(String type) {
|
|
|
@@ -962,24 +888,13 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
/** 无设备及共享类型不按候选人的部门限制;关联损坏不可当作无设备放宽。 */
|
|
|
private Long assignmentCompanyDeptId(WorkOrder order) {
|
|
|
if (StringUtils.isEmpty(order.getDeviceId())) return null;
|
|
|
- if (assignScopeSupport.isAdmin()) return null;
|
|
|
EquipmentBase device = equipmentBaseMapper.selectById(order.getDeviceId());
|
|
|
- if (device == null || device.getEquipmentTypeId() == null) {
|
|
|
- throw new ServiceException("工单关联设备或设备类型无效,无法选择人员");
|
|
|
- }
|
|
|
- Integer rootTypeId = rootEquipmentTypeId(device.getEquipmentTypeId());
|
|
|
- if (rootTypeId == null) {
|
|
|
- throw new ServiceException("工单关联设备或设备类型无效,无法选择人员");
|
|
|
- }
|
|
|
- // 窨井为三家公司共享类型
|
|
|
- if (Objects.equals(rootTypeId, 4)) return null;
|
|
|
- if (rootTypeId < 1 || rootTypeId > 3) {
|
|
|
- throw new ServiceException("工单关联设备或设备类型无效,无法选择人员");
|
|
|
- }
|
|
|
- long companyDeptId = 100L + rootTypeId;
|
|
|
- // 公司部门未按 101/102/103 建账时,按部门过滤只会得到空候选人;
|
|
|
- // 此时退化为不限部门,由角色权限与可指派范围继续约束。
|
|
|
- return assignmentDeptMapper.selectDeptById(companyDeptId) == null ? null : companyDeptId;
|
|
|
+ EquipmentType type = device == null || device.getEquipmentTypeId() == null ? null
|
|
|
+ : equipmentTypeMapper.selectById(device.getEquipmentTypeId());
|
|
|
+ Integer parent = type == null ? null : type.getParentId();
|
|
|
+ if (Objects.equals(parent, 4)) return null;
|
|
|
+ if (parent != null && parent >= 1 && parent <= 3) return 100L + parent;
|
|
|
+ throw new ServiceException("工单关联设备或设备类型无效,无法选择人员");
|
|
|
}
|
|
|
|
|
|
private void requireAssignmentCompany(WorkOrder order, Long userId, String label) {
|
|
|
@@ -1211,9 +1126,11 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
}
|
|
|
|
|
|
/** 报警等级映射工单优先级:1级最高为紧急,4级最低为低,其余为一般。 */
|
|
|
- private Integer mapAlarmLevelToOrderLevel(Integer alarmLevel) {
|
|
|
- if (alarmLevel == null || alarmLevel == 1) return 0;
|
|
|
- if (alarmLevel == 4) return 2;
|
|
|
+ private Integer mapAlarmLevelToOrderLevel(String alarmLevel) {
|
|
|
+ if (alarmLevel == null || alarmLevel.trim().isEmpty()) return 0;
|
|
|
+ String level = alarmLevel.trim();
|
|
|
+ if ("1".equals(level)) return 0;
|
|
|
+ if ("4".equals(level)) return 2;
|
|
|
return 1;
|
|
|
}
|
|
|
|