|
|
@@ -0,0 +1,528 @@
|
|
|
+package com.ygtx.gxt.service.impl;
|
|
|
+
|
|
|
+import com.ygtx.common.constant.Constants;
|
|
|
+import com.ygtx.common.core.domain.entity.SysRole;
|
|
|
+import com.ygtx.common.core.domain.entity.SysUser;
|
|
|
+import com.ygtx.common.core.domain.model.LoginUser;
|
|
|
+import com.ygtx.common.utils.SecurityUtils;
|
|
|
+import com.ygtx.framework.aspectj.DataScopeAspect;
|
|
|
+import com.ygtx.gxt.domain.*;
|
|
|
+import com.ygtx.gxt.mapper.GxtOrderHourMapper;
|
|
|
+import com.ygtx.gxt.mapper.GxtOrderScoreMapper;
|
|
|
+import com.ygtx.gxt.mapper.GxtRepairOrderFlowMapper;
|
|
|
+import com.ygtx.gxt.mapper.GxtWorkOrderFlowMapper;
|
|
|
+import com.ygtx.gxt.service.IGxtOrderHourService;
|
|
|
+import com.ygtx.gxt.service.IGxtOrderScoreService;
|
|
|
+import com.ygtx.gxt.service.IGxtRepairOrderService;
|
|
|
+import com.ygtx.gxt.service.IGxtWorkOrderService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 工单工时Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ouyj
|
|
|
+ * @date 2025-11-12
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class GxtOrderHourServiceImpl implements IGxtOrderHourService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GxtOrderHourMapper gxtOrderHourMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGxtRepairOrderService gxtRepairOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGxtWorkOrderService gxtWorkOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GxtRepairOrderFlowMapper gxtRepairOrderFlowMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GxtWorkOrderFlowMapper gxtWorkOrderFlowMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询合并的工单列表(维修工单和维保工单)
|
|
|
+ *
|
|
|
+ * @param repairOrder 维修工单查询条件
|
|
|
+ * @param workOrder 维保工单查询条件
|
|
|
+ * @return 合并的工单列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<OrderScoreInfo> selectUnionOrderList(GxtRepairOrder repairOrder, GxtWorkOrder workOrder) {
|
|
|
+ // 添加业务特定的数据权限过滤
|
|
|
+ addBusinessDataScopeFilter(repairOrder, workOrder);
|
|
|
+
|
|
|
+ // 设置创建人,用于数据权限过滤
|
|
|
+ if(!Constants.SUPER_ADMIN.equals(SecurityUtils.getUsername())){
|
|
|
+ if (repairOrder.getCreateBy() == null || repairOrder.getCreateBy().isEmpty()) {
|
|
|
+ repairOrder.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (workOrder.getCreateBy() == null || workOrder.getCreateBy().isEmpty()) {
|
|
|
+ workOrder.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 查询工单列表
|
|
|
+ List<OrderScoreInfo> orderList = gxtOrderHourMapper.selectUnionOrderList(repairOrder, workOrder);
|
|
|
+
|
|
|
+ // 计算每个工单的处理时长
|
|
|
+ for (OrderScoreInfo order : orderList) {
|
|
|
+ double processingHours = calculateOrderProcessingHours(order);
|
|
|
+ order.setHandleHour(processingHours);
|
|
|
+ }
|
|
|
+
|
|
|
+ return orderList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加业务特定的数据权限过滤条件
|
|
|
+ * 基于角色的数据范围进行自定义权限控制
|
|
|
+ *
|
|
|
+ * @param repairOrder 维修工单查询条件
|
|
|
+ * @param workOrder 维保工单查询条件
|
|
|
+ */
|
|
|
+ private void addBusinessDataScopeFilter(GxtRepairOrder repairOrder, GxtWorkOrder workOrder) {
|
|
|
+ // 获取当前登录用户
|
|
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
+ if (loginUser == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUser currentUser = loginUser.getUser();
|
|
|
+ if (currentUser == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是超级管理员,不过滤数据
|
|
|
+ if (currentUser.isAdmin()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取用户角色
|
|
|
+ List<SysRole> roles = currentUser.getRoles();
|
|
|
+ if (roles == null || roles.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建业务特定的数据权限SQL
|
|
|
+ StringBuilder orderBusinessSql = new StringBuilder();
|
|
|
+ StringBuilder repairBusinessSql = new StringBuilder();
|
|
|
+
|
|
|
+ // 遍历用户角色,根据角色的数据范围添加业务特定的权限控制
|
|
|
+ for (SysRole role : roles) {
|
|
|
+ String dataScope = role.getDataScope();
|
|
|
+
|
|
|
+ // 如果是全部数据权限,则不过滤
|
|
|
+ if (DataScopeAspect.DATA_SCOPE_ALL.equals(dataScope)) {
|
|
|
+ orderBusinessSql.setLength(0); // 清空之前的条件
|
|
|
+ repairBusinessSql.setLength(0); // 清空之前的条件
|
|
|
+ break; // 全部数据权限,跳出循环
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自定义数据权限 - 根据角色的数据范围值来控制查询条件
|
|
|
+ if (DataScopeAspect.DATA_SCOPE_CUSTOM.equals(dataScope)) {
|
|
|
+ // 获取具有自定义数据权限的角色ID列表
|
|
|
+ List<String> customRoleIds = new ArrayList<>();
|
|
|
+ for (SysRole r : roles) {
|
|
|
+ if (DataScopeAspect.DATA_SCOPE_CUSTOM.equals(r.getDataScope())) {
|
|
|
+ customRoleIds.add(String.valueOf(r.getRoleId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建自定义数据权限查询条件
|
|
|
+ if (orderBusinessSql.length() > 0) {
|
|
|
+ orderBusinessSql.append(" OR ");
|
|
|
+ }
|
|
|
+ // 构建自定义数据权限查询条件
|
|
|
+ if (repairBusinessSql.length() > 0) {
|
|
|
+ repairBusinessSql.append(" OR ");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (customRoleIds.size() > 1) {
|
|
|
+ // 多个自定义数据权限角色使用IN查询
|
|
|
+ orderBusinessSql.append("(t.pcs_station_pid IN (SELECT dept_id FROM sys_role_dept WHERE role_id IN (")
|
|
|
+ .append(String.join(",", customRoleIds))
|
|
|
+ .append("))")
|
|
|
+ .append(" OR t.pcs_station_id IN (SELECT dept_id FROM sys_role_dept WHERE role_id IN (")
|
|
|
+ .append(String.join(",", customRoleIds))
|
|
|
+ .append("))")
|
|
|
+ .append(" OR t.gxt_center_id IN (SELECT dept_id FROM sys_role_dept WHERE role_id IN (")
|
|
|
+ .append(String.join(",", customRoleIds))
|
|
|
+ .append(")))");
|
|
|
+ repairBusinessSql.append("(t.pcs_station_pid IN (SELECT dept_id FROM sys_role_dept WHERE role_id IN (")
|
|
|
+ .append(String.join(",", customRoleIds))
|
|
|
+ .append("))")
|
|
|
+ .append(" OR t.pcs_station_id IN (SELECT dept_id FROM sys_role_dept WHERE role_id IN (")
|
|
|
+ .append(String.join(",", customRoleIds))
|
|
|
+ .append("))")
|
|
|
+ .append(" OR t.gxt_center_id IN (SELECT dept_id FROM sys_role_dept WHERE role_id IN (")
|
|
|
+ .append(String.join(",", customRoleIds))
|
|
|
+ .append(")))");
|
|
|
+ } else {
|
|
|
+ // 单个自定义数据权限角色查询
|
|
|
+ orderBusinessSql.append("(t.pcs_station_pid IN (SELECT dept_id FROM sys_role_dept WHERE role_id = ")
|
|
|
+ .append(role.getRoleId())
|
|
|
+ .append(")")
|
|
|
+ .append(" OR t.pcs_station_id IN (SELECT dept_id FROM sys_role_dept WHERE role_id = ")
|
|
|
+ .append(role.getRoleId())
|
|
|
+ .append(")")
|
|
|
+ .append(" OR t.gxt_center_id IN (SELECT dept_id FROM sys_role_dept WHERE role_id = ")
|
|
|
+ .append(role.getRoleId())
|
|
|
+ .append("))");
|
|
|
+ repairBusinessSql.append("(t.pcs_station_pid IN (SELECT dept_id FROM sys_role_dept WHERE role_id = ")
|
|
|
+ .append(role.getRoleId())
|
|
|
+ .append(")")
|
|
|
+ .append(" OR t.pcs_station_id IN (SELECT dept_id FROM sys_role_dept WHERE role_id = ")
|
|
|
+ .append(role.getRoleId())
|
|
|
+ .append(")")
|
|
|
+ .append(" OR t.gxt_center_id IN (SELECT dept_id FROM sys_role_dept WHERE role_id = ")
|
|
|
+ .append(role.getRoleId())
|
|
|
+ .append("))");
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 部门数据权限 - 适用于部门负责人角色
|
|
|
+ if (DataScopeAspect.DATA_SCOPE_DEPT.equals(dataScope)) {
|
|
|
+ if (orderBusinessSql.length() > 0) {
|
|
|
+ orderBusinessSql.append(" OR ");
|
|
|
+ }
|
|
|
+ if (repairBusinessSql.length() > 0) {
|
|
|
+ repairBusinessSql.append(" OR ");
|
|
|
+ }
|
|
|
+ orderBusinessSql.append("(t.pcs_station_id = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(" OR t.pcs_station_pid = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(" OR t.gxt_center_id = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(")");
|
|
|
+ repairBusinessSql.append("(t.pcs_station_id = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(" OR t.pcs_station_pid = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(" OR t.gxt_center_id = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(")");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 部门及以下数据权限
|
|
|
+ if (DataScopeAspect.DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) {
|
|
|
+ if (orderBusinessSql.length() > 0) {
|
|
|
+ orderBusinessSql.append(" OR ");
|
|
|
+ }
|
|
|
+ if (repairBusinessSql.length() > 0) {
|
|
|
+ repairBusinessSql.append(" OR ");
|
|
|
+ }
|
|
|
+ orderBusinessSql.append("(t.pcs_station_id IN ")
|
|
|
+ .append("(SELECT dept_id FROM sys_dept WHERE dept_id = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(" OR FIND_IN_SET(")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(", ancestors))")
|
|
|
+ .append(" OR t.pcs_station_pid IN ")
|
|
|
+ .append("(SELECT dept_id FROM sys_dept WHERE dept_id = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(" OR FIND_IN_SET(")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(", ancestors))")
|
|
|
+ .append(" OR t.gxt_center_id IN ")
|
|
|
+ .append("(SELECT dept_id FROM sys_dept WHERE dept_id = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(" OR FIND_IN_SET(")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(", ancestors)))");
|
|
|
+ repairBusinessSql.append("(t.pcs_station_id IN ")
|
|
|
+ .append("(SELECT dept_id FROM sys_dept WHERE dept_id = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(" OR FIND_IN_SET(")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(", ancestors))")
|
|
|
+ .append(" OR t.pcs_station_pid IN ")
|
|
|
+ .append("(SELECT dept_id FROM sys_dept WHERE dept_id = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(" OR FIND_IN_SET(")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(", ancestors))")
|
|
|
+ .append(" OR t.gxt_center_id IN ")
|
|
|
+ .append("(SELECT dept_id FROM sys_dept WHERE dept_id = ")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(" OR FIND_IN_SET(")
|
|
|
+ .append(currentUser.getDeptId())
|
|
|
+ .append(", ancestors)))");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 仅本人数据权限 - 适用于主检修员角色
|
|
|
+ if (DataScopeAspect.DATA_SCOPE_SELF.equals(dataScope)) {
|
|
|
+ if (orderBusinessSql.length() > 0) {
|
|
|
+ orderBusinessSql.append(" OR ");
|
|
|
+ }
|
|
|
+ if (repairBusinessSql.length() > 0) {
|
|
|
+ repairBusinessSql.append(" OR ");
|
|
|
+ }
|
|
|
+ orderBusinessSql.append("(t.team_leader_id = ")
|
|
|
+ .append(currentUser.getUserId())
|
|
|
+ .append(" OR t.assign_user_id = ")
|
|
|
+ .append(currentUser.getUserId())
|
|
|
+ .append(" OR t.accept_user_id = ")
|
|
|
+ .append(currentUser.getUserId())
|
|
|
+ .append(" OR t.id IN (SELECT order_id FROM gxt_work_order_person WHERE user_id = ")
|
|
|
+ .append(currentUser.getUserId())
|
|
|
+ .append(") ")
|
|
|
+ .append(" OR t.create_by = '")
|
|
|
+ .append(currentUser.getUserName())
|
|
|
+ .append("')");
|
|
|
+ repairBusinessSql.append("(t.team_leader_id = ")
|
|
|
+ .append(currentUser.getUserId())
|
|
|
+ .append(" OR t.assign_user_id = ")
|
|
|
+ .append(currentUser.getUserId())
|
|
|
+ .append(" OR t.accept_user_id = ")
|
|
|
+ .append(currentUser.getUserId())
|
|
|
+ .append(" OR t.id IN (SELECT order_id FROM gxt_repair_order_person WHERE user_id = ")
|
|
|
+ .append(currentUser.getUserId())
|
|
|
+ .append(") ")
|
|
|
+ .append(" OR t.create_by = '")
|
|
|
+ .append(currentUser.getUserName())
|
|
|
+ .append("')");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果构建了业务特定的过滤条件,则添加到查询参数中
|
|
|
+ if (orderBusinessSql.length() > 0) {
|
|
|
+ String businessDataScopeSql = " AND (" + orderBusinessSql.toString() + ")";
|
|
|
+ workOrder.getParams().put("businessDataScope", businessDataScopeSql);
|
|
|
+ }
|
|
|
+ if (repairBusinessSql.length() > 0) {
|
|
|
+ String businessDataScopeSql = " AND (" + repairBusinessSql.toString() + ")";
|
|
|
+ repairOrder.getParams().put("businessDataScope", businessDataScopeSql);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取工单工时统计信息
|
|
|
+ *
|
|
|
+ * @param repairOrder 维修工单查询条件
|
|
|
+ * @param workOrder 维保工单查询条件
|
|
|
+ * @return 统计信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getOrderHourStatistics(GxtRepairOrder repairOrder, GxtWorkOrder workOrder) {
|
|
|
+ // 添加业务特定的数据权限过滤
|
|
|
+ addBusinessDataScopeFilter(repairOrder, workOrder);
|
|
|
+
|
|
|
+ // 设置创建人,用于数据权限过滤
|
|
|
+ if(!Constants.SUPER_ADMIN.equals(SecurityUtils.getUsername())){
|
|
|
+ if (repairOrder.getCreateBy() == null || repairOrder.getCreateBy().isEmpty()) {
|
|
|
+ repairOrder.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (workOrder.getCreateBy() == null || workOrder.getCreateBy().isEmpty()) {
|
|
|
+ workOrder.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取统计数据
|
|
|
+ List<OrderScoreInfo> orderList = gxtOrderHourMapper.selectUnionOrderList(repairOrder, workOrder);
|
|
|
+
|
|
|
+ // 计算统计信息
|
|
|
+ Map<String, Object> statistics = new HashMap<>();
|
|
|
+
|
|
|
+ double totalHours = 0;
|
|
|
+ double maintenanceHours = 0;
|
|
|
+ double repairHours = 0;
|
|
|
+ int maintenanceCount = 0;
|
|
|
+ int repairCount = 0;
|
|
|
+
|
|
|
+ for (OrderScoreInfo order : orderList) {
|
|
|
+ double hours = calculateOrderProcessingHours(order);
|
|
|
+ totalHours += hours;
|
|
|
+
|
|
|
+ if (order.getOrderType() == 2) { // 维保工单
|
|
|
+ maintenanceHours += hours;
|
|
|
+ maintenanceCount++;
|
|
|
+ } else if (order.getOrderType() == 1) { // 维修工单
|
|
|
+ repairHours += hours;
|
|
|
+ repairCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ statistics.put("totalHours", totalHours);
|
|
|
+ statistics.put("maintenanceHours", maintenanceHours);
|
|
|
+ statistics.put("repairHours", repairHours);
|
|
|
+ statistics.put("maintenanceCount", maintenanceCount);
|
|
|
+ statistics.put("repairCount", repairCount);
|
|
|
+ statistics.put("orderCount", orderList.size());
|
|
|
+
|
|
|
+ return statistics;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算单个工单的处理时长(小时)
|
|
|
+ * 处理时长 = 复运时间restartTime – 故障发生时间(维修工单用occurTime,维保工单用createTime) – 挂起时长
|
|
|
+ * 挂起时长 = 恢复时间 - 挂起时间
|
|
|
+ *
|
|
|
+ * @param order 工单信息
|
|
|
+ * @return 处理时长(小时)
|
|
|
+ */
|
|
|
+ private double calculateOrderProcessingHours(OrderScoreInfo order) {
|
|
|
+ // 只有存在复运时间的工单才进行统计计算
|
|
|
+ if (order.getRestartTime() == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ Date startTime = null;
|
|
|
+ if (order.getOrderType() == 1) { // 维修工单
|
|
|
+ startTime = order.getOccurTime();
|
|
|
+ } else if (order.getOrderType() == 2) { // 维保工单
|
|
|
+ startTime = order.getCreateTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (startTime == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算总挂起时长(毫秒)
|
|
|
+ long suspensionDuration = 0;
|
|
|
+ if (order.getOrderType() == 1) { // 维修工单
|
|
|
+ suspensionDuration = calculateRepairOrderSuspensionTime(order.getId());
|
|
|
+ } else if (order.getOrderType() == 2) { // 维保工单
|
|
|
+ suspensionDuration = calculateWorkOrderSuspensionTime(order.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算处理时长 = (复运时间 - 开始时间 - 挂起时长) / 小时
|
|
|
+ long totalDuration = order.getRestartTime().getTime() - startTime.getTime();
|
|
|
+ long processingDuration = totalDuration - suspensionDuration;
|
|
|
+
|
|
|
+ // 转换为小时
|
|
|
+ return processingDuration / (1000.0 * 60 * 60);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算维修工单的挂起时长
|
|
|
+ * 维修工单挂起对应的actionType是approved,恢复对应的是resume
|
|
|
+ *
|
|
|
+ * @param orderId 工单ID
|
|
|
+ * @return 挂起时长(毫秒)
|
|
|
+ */
|
|
|
+ private long calculateRepairOrderSuspensionTime(Long orderId) {
|
|
|
+ List<GxtRepairOrderFlow> flows = gxtRepairOrderFlowMapper.selectGxtRepairOrderFlowListByOrderId(orderId);
|
|
|
+
|
|
|
+ long totalSuspensionTime = 0;
|
|
|
+ Date suspendTime = null;
|
|
|
+
|
|
|
+ // 按时间顺序处理流转记录
|
|
|
+ flows.sort((f1, f2) -> f1.getActionTime().compareTo(f2.getActionTime()));
|
|
|
+
|
|
|
+ for (GxtRepairOrderFlow flow : flows) {
|
|
|
+ if ("approved".equals(flow.getActionType())) {
|
|
|
+ // 挂起时间
|
|
|
+ suspendTime = flow.getActionTime();
|
|
|
+ } else if ("resume".equals(flow.getActionType()) && suspendTime != null) {
|
|
|
+ // 恢复时间
|
|
|
+ long suspensionDuration = flow.getActionTime().getTime() - suspendTime.getTime();
|
|
|
+ totalSuspensionTime += suspensionDuration;
|
|
|
+ suspendTime = null; // 重置挂起时间
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return totalSuspensionTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算维保工单的挂起时长
|
|
|
+ * 维保工单挂起对应的actionType是approved,恢复对应的是restart
|
|
|
+ *
|
|
|
+ * @param orderId 工单ID
|
|
|
+ * @return 挂起时长(毫秒)
|
|
|
+ */
|
|
|
+ private long calculateWorkOrderSuspensionTime(Long orderId) {
|
|
|
+ List<GxtWorkOrderFlow> flows = gxtWorkOrderFlowMapper.selectGxtWorkOrderFlowByOrderId(orderId);
|
|
|
+
|
|
|
+ long totalSuspensionTime = 0;
|
|
|
+ Date suspendTime = null;
|
|
|
+
|
|
|
+ // 按时间顺序处理流转记录
|
|
|
+ flows.sort((f1, f2) -> f1.getActionTime().compareTo(f2.getActionTime()));
|
|
|
+
|
|
|
+ for (GxtWorkOrderFlow flow : flows) {
|
|
|
+ if ("approved".equals(flow.getActionType())) {
|
|
|
+ // 挂起时间
|
|
|
+ suspendTime = flow.getActionTime();
|
|
|
+ } else if ("restart".equals(flow.getActionType()) && suspendTime != null) {
|
|
|
+ // 恢复时间
|
|
|
+ long suspensionDuration = flow.getActionTime().getTime() - suspendTime.getTime();
|
|
|
+ totalSuspensionTime += suspensionDuration;
|
|
|
+ suspendTime = null; // 重置挂起时间
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return totalSuspensionTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算工单详情中的各个时长(用于前端展示)
|
|
|
+ *
|
|
|
+ * @param order 工单信息
|
|
|
+ */
|
|
|
+ public void calculateOrderTimeDetails(OrderScoreInfo order) {
|
|
|
+ // 下发时长 = 下发时间 - 故障发生时间(维修工单)或创建时间(维保工单)
|
|
|
+ if (order.getAssignTime() != null) {
|
|
|
+ Date startTime = null;
|
|
|
+ if (order.getOrderType() == 1) { // 维修工单
|
|
|
+ startTime = order.getOccurTime();
|
|
|
+ } else if (order.getOrderType() == 2) { // 维保工单
|
|
|
+ startTime = order.getCreateTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (startTime != null) {
|
|
|
+ long diffMillis = order.getAssignTime().getTime() - startTime.getTime();
|
|
|
+ order.setIssueHour(diffMillis / (1000.0 * 60 * 60));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 接单时长 = 接单时间 – 下发时间
|
|
|
+ if (order.getAcceptTime() != null && order.getAssignTime() != null) {
|
|
|
+ long diffMillis = order.getAcceptTime().getTime() - order.getAssignTime().getTime();
|
|
|
+ order.setAcceptHour(diffMillis / (1000.0 * 60 * 60));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 准备时长 = 开始打卡时间 – 接单时间
|
|
|
+ if (order.getRealStartTime() != null && order.getAcceptTime() != null) {
|
|
|
+ long diffMillis = order.getRealStartTime().getTime() - order.getAcceptTime().getTime();
|
|
|
+ order.setPrepareHour(diffMillis / (1000.0 * 60 * 60));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 工作时长 = 结束打卡时间 - 开始打卡时间
|
|
|
+ if (order.getRealEndTime() != null && order.getRealStartTime() != null) {
|
|
|
+ long diffMillis = order.getRealEndTime().getTime() - order.getRealStartTime().getTime();
|
|
|
+ order.setWorkHour(diffMillis / (1000.0 * 60 * 60));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 复运时长 = 复运时间 – 结束打卡时间
|
|
|
+ if (order.getRestartTime() != null && order.getRealEndTime() != null) {
|
|
|
+ long diffMillis = order.getRestartTime().getTime() - order.getRealEndTime().getTime();
|
|
|
+ order.setRestartHour(diffMillis / (1000.0 * 60 * 60));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理时长 = 复运时间 – 故障发生时间(维修工单)或创建时间(维保工单) – 挂起时长
|
|
|
+ double processingHours = calculateOrderProcessingHours(order);
|
|
|
+ order.setHandleHour(processingHours);
|
|
|
+
|
|
|
+ // 挂起时长 = 恢复时间 - 挂起时间
|
|
|
+ long suspensionDuration = 0;
|
|
|
+ if (order.getOrderType() == 1) { // 维修工单
|
|
|
+ suspensionDuration = calculateRepairOrderSuspensionTime(order.getId());
|
|
|
+ } else if (order.getOrderType() == 2) { // 维保工单
|
|
|
+ suspensionDuration = calculateWorkOrderSuspensionTime(order.getId());
|
|
|
+ }
|
|
|
+ order.setSuspendHour(suspensionDuration / (1000.0 * 60 * 60));
|
|
|
+ }
|
|
|
+}
|