Browse Source

工时工分统计调整

ouyj 4 months ago
parent
commit
dd4860860d

+ 118 - 2
ygtx-gxt/src/main/java/com/ygtx/gxt/service/impl/GxtOrderHourServiceImpl.java

@@ -146,6 +146,40 @@ public class GxtOrderHourServiceImpl implements IGxtOrderHourService {
                 workOrder.setCreateBy(SecurityUtils.getUsername());
             }
         }
+        
+        // 对所有人,只统计个人参与的工单工时
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        if (loginUser != null && loginUser.getUser() != null) {
+            Long userId = loginUser.getUser().getUserId();
+            
+            // 为维修工单添加用户筛选条件
+            if (repairOrder != null) {
+                StringBuilder repairUserFilter = new StringBuilder();
+                repairUserFilter.append("( t.id IN (SELECT order_id FROM gxt_repair_order_person WHERE user_id = ").append(userId).append("))");
+                
+                // 如果已有businessDataScope条件,追加到现有条件中
+                if (repairOrder.getParams().containsKey("businessDataScope")) {
+                    String existingCondition = (String) repairOrder.getParams().get("businessDataScope");
+                    repairOrder.getParams().put("businessDataScope", existingCondition + " AND (" + repairUserFilter.toString() + ")");
+                } else {
+                    repairOrder.getParams().put("businessDataScope", " AND (" + repairUserFilter.toString() + ")");
+                }
+            }
+            
+            // 为维保工单添加用户筛选条件
+            if (workOrder != null) {
+                StringBuilder workUserFilter = new StringBuilder();
+                workUserFilter.append("( t.id IN (SELECT order_id FROM gxt_work_order_person WHERE user_id = ").append(userId).append("))");
+                
+                // 如果已有businessDataScope条件,追加到现有条件中
+                if (workOrder.getParams().containsKey("businessDataScope")) {
+                    String existingCondition = (String) workOrder.getParams().get("businessDataScope");
+                    workOrder.getParams().put("businessDataScope", existingCondition + " AND (" + workUserFilter.toString() + ")");
+                } else {
+                    workOrder.getParams().put("businessDataScope", " AND (" + workUserFilter.toString() + ")");
+                }
+            }
+        }
 
         // 获取统计数据
         List<OrderScoreInfo> orderList = gxtOrderHourMapper.selectUnionOrderList(repairOrder, workOrder, orderType, keyword);
@@ -186,7 +220,7 @@ public class GxtOrderHourServiceImpl implements IGxtOrderHourService {
             statistics.put("rank", rank);
             
             // 计算场站总人数
-            LoginUser loginUser = SecurityUtils.getLoginUser();
+            //LoginUser loginUser = SecurityUtils.getLoginUser();
             if (loginUser != null && loginUser.getUser() != null) {
                 Long deptId = loginUser.getUser().getDeptId();
                 if (deptId != null) {
@@ -198,7 +232,7 @@ public class GxtOrderHourServiceImpl implements IGxtOrderHourService {
         
         return statistics;
     }
-    
+
     /**
      * 判断当前用户的数据权限是否为"仅本人数据"
      * 
@@ -1098,4 +1132,86 @@ public class GxtOrderHourServiceImpl implements IGxtOrderHourService {
         long diffMillis = order.getRealEndTime().getTime() - order.getRealStartTime().getTime() - suspensionTimes[2];
         return diffMillis / (1000.0 * 60 * 60);
     }
+
+    /**
+     * 获取工单工时统计信息
+     *
+     * @param repairOrder 维修工单查询条件
+     * @param workOrder 维保工单查询条件
+     * @param orderType 工单类型筛选条件
+     * @param timeRange 时间范围参数 (week:本周, month:本月, custom:自定义)
+     * @param beginDate 自定义开始时间
+     * @param endDate 自定义结束时间
+     * @param keyword 搜索关键字
+     * @return 统计信息
+     */
+    public Map<String, Object> getOrderHourStatisticsV0(GxtRepairOrder repairOrder, GxtWorkOrder workOrder, String orderType, String timeRange, String beginDate, String endDate, String keyword) {
+        // 处理时间范围参数
+        processTimeRange(repairOrder, workOrder, timeRange, beginDate, endDate);
+
+        // 添加业务特定的数据权限过滤
+        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, orderType, keyword);
+
+        // 计算统计信息
+        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 = calculateWorkHours(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());
+
+        // 如果用户的数据权限是"仅本人数据",则计算排名
+        if (isCurrentUserDataScopeSelf()) {
+            int rank = calculateUserRankInStation(repairOrder, workOrder, orderType, timeRange, beginDate, endDate, keyword);
+            statistics.put("rank", rank);
+
+            // 计算场站总人数
+            LoginUser loginUser = SecurityUtils.getLoginUser();
+            if (loginUser != null && loginUser.getUser() != null) {
+                Long deptId = loginUser.getUser().getDeptId();
+                if (deptId != null) {
+                    int totalUsersInStation = getStationUserIds(deptId).size();
+                    statistics.put("totalRankingUsers", totalUsersInStation);
+                }
+            }
+        }
+
+        return statistics;
+    }
 }

+ 26 - 4
ygtx-gxt/src/main/java/com/ygtx/gxt/service/impl/GxtOrderScoreServiceImpl.java

@@ -189,8 +189,30 @@ public class GxtOrderScoreServiceImpl implements IGxtOrderScoreService {
         }
 
         Map<String, Object> result = new HashMap<>();
+        Long currentUserId = SecurityUtils.getUserId();
+        if(currentUserId != null){
+            // 添加用户ID参数用于Mapper查询
+            repairOrder.getParams().put("currentUserId", currentUserId);
+            workOrder.getParams().put("currentUserId", currentUserId);
+
+            Map<String, Object> statistics = gxtOrderScoreMapper.selectOrderScoreStatistics(repairOrder, workOrder, month);
+
+            // 计算总工分
+            Object maintenanceScoreObj = statistics.get("maintenanceScore");
+            Object repairScoreObj = statistics.get("repairScore");
 
-        // 如果用户的数据权限是"仅本人数据",则只统计本人的工分
+            double maintenanceScore = maintenanceScoreObj != null ? ((Number) maintenanceScoreObj).doubleValue() : 0.0;
+            double repairScore = repairScoreObj != null ? ((Number) repairScoreObj).doubleValue() : 0.0;
+            double totalScore = maintenanceScore + repairScore;
+
+            result.put("totalScore", totalScore);
+            result.put("maintenanceScore", maintenanceScore);
+            result.put("repairScore", repairScore);
+            result.put("maintenanceCount", statistics.get("maintenanceCount"));
+            result.put("repairCount", statistics.get("repairCount"));
+        }
+        return result;
+        /*// 如果用户的数据权限是"仅本人数据",则只统计本人的工分
         if (isCurrentUserDataScopeSelf()) {
             Long currentUserId = SecurityUtils.getUserId();
             if (currentUserId != null) {
@@ -216,7 +238,7 @@ public class GxtOrderScoreServiceImpl implements IGxtOrderScoreService {
                 result.put("repairCount", statistics.get("repairCount"));
 
                 // 计算排名
-               /* int rank = calculateUserRankInStation(repairOrder, workOrder, month);
+                int rank = calculateUserRankInStation(repairOrder, workOrder, month);
                 result.put("rank", rank);
 
                 // 计算场站总人数
@@ -238,7 +260,7 @@ public class GxtOrderScoreServiceImpl implements IGxtOrderScoreService {
                 } else {
                     // 如果无法获取用户信息,至少当前用户参与排名
                     result.put("totalRankingUsers", 1);
-                }*/
+                }
 
                 return result;
             }
@@ -260,7 +282,7 @@ public class GxtOrderScoreServiceImpl implements IGxtOrderScoreService {
         result.put("maintenanceScore", maintenanceScore);
         result.put("repairScore", repairScore);
 
-        return result;
+        return result;*/
     }
 
     /**

+ 2 - 2
ygtx-gxt/src/main/resources/mapper/gxt/GxtOrderScoreMapper.xml

@@ -441,7 +441,7 @@
                     AND wrk.user_id = #{workOrder.params.currentUserId}
                 </if>
             <where>
-                t.scoring_status IS NOT NULL AND (t.scoring_status = 'to_archive' OR t.scoring_status = 'archived') AND t.work_order_status != 'invalid'
+                t.scoring_status IS NOT NULL AND t.work_order_status != 'invalid'
 
                 <if test="month != null and month != ''">
                     AND DATE_FORMAT(t.create_time, '%Y-%m') = #{month}
@@ -464,7 +464,7 @@
                     AND rep.user_id = #{repairOrder.params.currentUserId}
                 </if>
             <where>
-                t.scoring_status IS NOT NULL AND (t.scoring_status = 'to_archive' OR t.scoring_status = 'archived') AND t.work_order_status != 'invalid'
+                t.scoring_status IS NOT NULL AND t.work_order_status != 'invalid'
 
                 <if test="month != null and month != ''">
                     AND DATE_FORMAT(t.occur_time, '%Y-%m') = #{month}