|
@@ -4,8 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.zksy.base.domain.EquipmentBase;
|
|
|
|
|
+import com.zksy.base.domain.EquipmentStatus;
|
|
|
|
|
+import com.zksy.base.domain.HazardHiddenAccount;
|
|
|
import com.zksy.base.domain.WorkOrder;
|
|
import com.zksy.base.domain.WorkOrder;
|
|
|
import com.zksy.base.domain.WorkOrderLog;
|
|
import com.zksy.base.domain.WorkOrderLog;
|
|
|
|
|
+import com.zksy.base.mapper.EquipmentBaseMapper;
|
|
|
|
|
+import com.zksy.base.mapper.EquipmentStatusMapper;
|
|
|
|
|
+import com.zksy.base.mapper.HazardHiddenAccountMapper;
|
|
|
import com.zksy.base.mapper.WorkOrderLogMapper;
|
|
import com.zksy.base.mapper.WorkOrderLogMapper;
|
|
|
import com.zksy.base.mapper.WorkOrderMapper;
|
|
import com.zksy.base.mapper.WorkOrderMapper;
|
|
|
import com.zksy.base.service.BusinessWorkOrderService;
|
|
import com.zksy.base.service.BusinessWorkOrderService;
|
|
@@ -19,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -31,6 +38,15 @@ public class BusinessWorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, W
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private WorkOrderLogMapper workOrderLogMapper;
|
|
private WorkOrderLogMapper workOrderLogMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private EquipmentBaseMapper equipmentBaseMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private HazardHiddenAccountMapper hazardHiddenAccountMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private EquipmentStatusMapper equipmentStatusMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public IPage<WorkOrder> selectWorkOrderList(Integer orderType, Integer orderLevel, Integer orderStatus, String deviceCode, String keyword, String equipmentType, Integer pageNum, Integer pageSize) {
|
|
public IPage<WorkOrder> selectWorkOrderList(Integer orderType, Integer orderLevel, Integer orderStatus, String deviceCode, String keyword, String equipmentType, Integer pageNum, Integer pageSize) {
|
|
|
Page<WorkOrder> page = new Page<>(pageNum, pageSize);
|
|
Page<WorkOrder> page = new Page<>(pageNum, pageSize);
|
|
@@ -95,6 +111,7 @@ public class BusinessWorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, W
|
|
|
logEntry.setOperDesc("派单给处理人ID:" + handlerId + ",备注:" + (remarks != null ? remarks : ""));
|
|
logEntry.setOperDesc("派单给处理人ID:" + handlerId + ",备注:" + (remarks != null ? remarks : ""));
|
|
|
logEntry.setOperUserId(operUserId);
|
|
logEntry.setOperUserId(operUserId);
|
|
|
logEntry.setOperUserName(operUserName);
|
|
logEntry.setOperUserName(operUserName);
|
|
|
|
|
+ logEntry.setOperTime(new Date());
|
|
|
workOrderLogMapper.insert(logEntry);
|
|
workOrderLogMapper.insert(logEntry);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -130,6 +147,7 @@ public class BusinessWorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, W
|
|
|
logEntry.setOperDesc("派单给处理人ID:" + handlerId + ",备注:" + (remarks != null ? remarks : ""));
|
|
logEntry.setOperDesc("派单给处理人ID:" + handlerId + ",备注:" + (remarks != null ? remarks : ""));
|
|
|
logEntry.setOperUserId(operUserId);
|
|
logEntry.setOperUserId(operUserId);
|
|
|
logEntry.setOperUserName(operUserName);
|
|
logEntry.setOperUserName(operUserName);
|
|
|
|
|
+ logEntry.setOperTime(new Date());
|
|
|
workOrderLogMapper.insert(logEntry);
|
|
workOrderLogMapper.insert(logEntry);
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
@@ -154,6 +172,7 @@ public class BusinessWorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, W
|
|
|
logEntry.setOperDesc("核查结果:" + handleResult + ",说明:" + solution);
|
|
logEntry.setOperDesc("核查结果:" + handleResult + ",说明:" + solution);
|
|
|
logEntry.setOperUserId(operUserId);
|
|
logEntry.setOperUserId(operUserId);
|
|
|
logEntry.setOperUserName(operUserName);
|
|
logEntry.setOperUserName(operUserName);
|
|
|
|
|
+ logEntry.setOperTime(new Date());
|
|
|
workOrderLogMapper.insert(logEntry);
|
|
workOrderLogMapper.insert(logEntry);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -171,12 +190,16 @@ public class BusinessWorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, W
|
|
|
entity.setRepairResult(solution);
|
|
entity.setRepairResult(solution);
|
|
|
this.updateById(entity);
|
|
this.updateById(entity);
|
|
|
|
|
|
|
|
|
|
+ // 工单处理中 → 同步隐患状态为"整改中"
|
|
|
|
|
+ syncHazardStatus(order, "整改中", solution);
|
|
|
|
|
+
|
|
|
WorkOrderLog logEntry = new WorkOrderLog();
|
|
WorkOrderLog logEntry = new WorkOrderLog();
|
|
|
logEntry.setOrderId(orderId);
|
|
logEntry.setOrderId(orderId);
|
|
|
logEntry.setOperType(4);
|
|
logEntry.setOperType(4);
|
|
|
logEntry.setOperDesc("处理结果:" + handleResult + ",说明:" + solution);
|
|
logEntry.setOperDesc("处理结果:" + handleResult + ",说明:" + solution);
|
|
|
logEntry.setOperUserId(operUserId);
|
|
logEntry.setOperUserId(operUserId);
|
|
|
logEntry.setOperUserName(operUserName);
|
|
logEntry.setOperUserName(operUserName);
|
|
|
|
|
+ logEntry.setOperTime(new Date());
|
|
|
workOrderLogMapper.insert(logEntry);
|
|
workOrderLogMapper.insert(logEntry);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -201,13 +224,14 @@ public class BusinessWorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, W
|
|
|
logEntry.setOperDesc("提交验收,结果:" + result);
|
|
logEntry.setOperDesc("提交验收,结果:" + result);
|
|
|
logEntry.setOperUserId(operUserId);
|
|
logEntry.setOperUserId(operUserId);
|
|
|
logEntry.setOperUserName(operUserName);
|
|
logEntry.setOperUserName(operUserName);
|
|
|
|
|
+ logEntry.setOperTime(new Date());
|
|
|
workOrderLogMapper.insert(logEntry);
|
|
workOrderLogMapper.insert(logEntry);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Long createWorkOrderFromHazard(String hazardId, String hazardDesc, String equipmentId, String hazardLevel, String hazardImages, Date planFinishTime) {
|
|
|
|
|
|
|
+ public Long createWorkOrderFromHazard(String hazardId, String hazardNo, String hazardDesc, String equipmentId, String hazardLevel, String hazardImages, Date planFinishTime) {
|
|
|
// 隐患等级映射到工单优先级:0-重大→紧急(1) 1-较大→一般(2) 2-一般→一般(2) 3-轻微→低(3)
|
|
// 隐患等级映射到工单优先级:0-重大→紧急(1) 1-较大→一般(2) 2-一般→一般(2) 3-轻微→低(3)
|
|
|
Integer orderLevel;
|
|
Integer orderLevel;
|
|
|
if ("0".equals(hazardLevel)) {
|
|
if ("0".equals(hazardLevel)) {
|
|
@@ -220,7 +244,16 @@ public class BusinessWorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, W
|
|
|
|
|
|
|
|
WorkOrder workOrder = new WorkOrder();
|
|
WorkOrder workOrder = new WorkOrder();
|
|
|
workOrder.setOrderNo(generateOrderNo());
|
|
workOrder.setOrderNo(generateOrderNo());
|
|
|
|
|
+ workOrder.setHazardId(hazardId);
|
|
|
|
|
+ workOrder.setHazardNo(hazardNo);
|
|
|
workOrder.setDeviceId(equipmentId);
|
|
workOrder.setDeviceId(equipmentId);
|
|
|
|
|
+ // 查询设备信息,填充设备编码
|
|
|
|
|
+ if (StringUtils.isNotEmpty(equipmentId)) {
|
|
|
|
|
+ EquipmentBase equipment = equipmentBaseMapper.selectById(equipmentId);
|
|
|
|
|
+ if (equipment != null) {
|
|
|
|
|
+ workOrder.setDeviceCode(equipment.getEquipmentCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
workOrder.setOrderType(1); // 默认故障维修
|
|
workOrder.setOrderType(1); // 默认故障维修
|
|
|
workOrder.setOrderLevel(orderLevel);
|
|
workOrder.setOrderLevel(orderLevel);
|
|
|
workOrder.setOrderDesc(hazardDesc);
|
|
workOrder.setOrderDesc(hazardDesc);
|
|
@@ -267,7 +300,105 @@ public class BusinessWorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, W
|
|
|
logEntry.setOperDesc("取消工单");
|
|
logEntry.setOperDesc("取消工单");
|
|
|
logEntry.setOperUserId(operUserId);
|
|
logEntry.setOperUserId(operUserId);
|
|
|
logEntry.setOperUserName(operUserName);
|
|
logEntry.setOperUserName(operUserName);
|
|
|
|
|
+ logEntry.setOperTime(new Date());
|
|
|
|
|
+ workOrderLogMapper.insert(logEntry);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public boolean closeOrder(Long orderId, String result, Long operUserId, String operUserName) {
|
|
|
|
|
+ WorkOrder order = this.getById(orderId);
|
|
|
|
|
+ if (order == null) throw new ServiceException("工单不存在");
|
|
|
|
|
+ if (order.getOrderStatus() != 5) throw new ServiceException("当前工单状态不允许验收通过");
|
|
|
|
|
+
|
|
|
|
|
+ WorkOrder entity = new WorkOrder();
|
|
|
|
|
+ entity.setOrderId(orderId);
|
|
|
|
|
+ entity.setOrderStatus(6);
|
|
|
|
|
+ entity.setRealFinishTime(new Date());
|
|
|
|
|
+ this.updateById(entity);
|
|
|
|
|
+
|
|
|
|
|
+ // 工单已结案 → 同步隐患状态为"已整改"
|
|
|
|
|
+ syncHazardStatus(order, "已整改", result);
|
|
|
|
|
+
|
|
|
|
|
+ // 工单验收通过 → 重置关联设备报警状态为正常
|
|
|
|
|
+ resetEquipmentAlarmStatus(order);
|
|
|
|
|
+
|
|
|
|
|
+ WorkOrderLog logEntry = new WorkOrderLog();
|
|
|
|
|
+ logEntry.setOrderId(orderId);
|
|
|
|
|
+ logEntry.setOperType(6);
|
|
|
|
|
+ logEntry.setOperDesc("验收通过,结果:" + result);
|
|
|
|
|
+ logEntry.setOperUserId(operUserId);
|
|
|
|
|
+ logEntry.setOperUserName(operUserName);
|
|
|
|
|
+ logEntry.setOperTime(new Date());
|
|
|
workOrderLogMapper.insert(logEntry);
|
|
workOrderLogMapper.insert(logEntry);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 同步隐患状态:根据工单处理结果更新关联隐患记录的状态和整改反馈
|
|
|
|
|
+ * @param order 工单对象
|
|
|
|
|
+ * @param hazardStatus 隐患状态:整改中/已整改
|
|
|
|
|
+ * @param rectifyFeedback 整改反馈(说明/方案)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void syncHazardStatus(WorkOrder order, String hazardStatus, String rectifyFeedback) {
|
|
|
|
|
+ if (StringUtils.isEmpty(order.getHazardNo())) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ LambdaQueryWrapper<HazardHiddenAccount> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(HazardHiddenAccount::getHazardNo, order.getHazardNo());
|
|
|
|
|
+ HazardHiddenAccount hazard = hazardHiddenAccountMapper.selectOne(wrapper);
|
|
|
|
|
+ if (hazard != null) {
|
|
|
|
|
+ HazardHiddenAccount update = new HazardHiddenAccount();
|
|
|
|
|
+ update.setHazardId(hazard.getHazardId());
|
|
|
|
|
+ update.setHazardStatus(hazardStatus);
|
|
|
|
|
+ if (StringUtils.isNotEmpty(rectifyFeedback)) {
|
|
|
|
|
+ update.setRectifyFeedback(rectifyFeedback);
|
|
|
|
|
+ }
|
|
|
|
|
+ hazardHiddenAccountMapper.updateById(update);
|
|
|
|
|
+ log.info("工单[{}]关联隐患[{}]状态同步为:{}, 整改反馈:{}",
|
|
|
|
|
+ order.getOrderNo(), order.getHazardNo(), hazardStatus, rectifyFeedback);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("工单[{}]同步隐患状态失败", order.getOrderNo(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 工单验收通过后,重置关联设备的报警状态为正常(0)
|
|
|
|
|
+ * 参考 EquipmentStatusApiServiceImpl.updateAlarmStatus 逻辑
|
|
|
|
|
+ */
|
|
|
|
|
+ private void resetEquipmentAlarmStatus(WorkOrder order) {
|
|
|
|
|
+ if (StringUtils.isEmpty(order.getDeviceId())) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ LambdaQueryWrapper<EquipmentStatus> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(EquipmentStatus::getEquipmentId, order.getDeviceId()).last("LIMIT 1");
|
|
|
|
|
+ EquipmentStatus existingStatus = equipmentStatusMapper.selectOne(wrapper);
|
|
|
|
|
+ if (existingStatus != null) {
|
|
|
|
|
+ // 更新已有记录
|
|
|
|
|
+ existingStatus.setAlarmStatus(0);
|
|
|
|
|
+ existingStatus.setStatusUpdateTime(LocalDateTime.now());
|
|
|
|
|
+ equipmentStatusMapper.updateById(existingStatus);
|
|
|
|
|
+ log.info("工单[{}]验收通过,设备[{}]报警状态已重置为正常",
|
|
|
|
|
+ order.getOrderNo(), order.getDeviceCode());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 不存在则创建新记录
|
|
|
|
|
+ EquipmentStatus newStatus = new EquipmentStatus();
|
|
|
|
|
+ newStatus.setEquipmentId(order.getDeviceId());
|
|
|
|
|
+ newStatus.setAlarmStatus(0);
|
|
|
|
|
+ newStatus.setCurrentStatus(1); // 默认在用
|
|
|
|
|
+ newStatus.setOnlineStatus(1); // 默认在线
|
|
|
|
|
+ newStatus.setStatusUpdateTime(LocalDateTime.now());
|
|
|
|
|
+ newStatus.setCreateTime(LocalDateTime.now());
|
|
|
|
|
+ equipmentStatusMapper.insert(newStatus);
|
|
|
|
|
+ log.info("工单[{}]验收通过,创建设备状态记录,设备[{}]报警状态为正常",
|
|
|
|
|
+ order.getOrderNo(), order.getDeviceCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("工单[{}]重置设备报警状态失败", order.getOrderNo(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|