From d48de59b57bce614e17e91f1845789c071930a2f Mon Sep 17 00:00:00 2001
From: ZengTao <2773468879@qq.com>
Date: 星期二, 16 九月 2025 08:01:35 +0800
Subject: [PATCH] 1、大理片进片报表添加连续工作时间统计

---
 UI-Project/src/views/Reportmanage/reportBigFeed.vue |   84 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/UI-Project/src/views/Reportmanage/reportBigFeed.vue b/UI-Project/src/views/Reportmanage/reportBigFeed.vue
index e89cfc8..b196d74 100644
--- a/UI-Project/src/views/Reportmanage/reportBigFeed.vue
+++ b/UI-Project/src/views/Reportmanage/reportBigFeed.vue
@@ -13,7 +13,7 @@
         <el-option :label="$t('reportmanage.go')" value="1"></el-option>
         <el-option :label="$t('reportmanage.nogo')" value="2"></el-option>
       </el-select> -->
-      <el-select v-model="report.taskState" :placeholder="$t('reportmanage.cstate')" style="margin-left: 10px;">
+      <el-select v-model="report.taskState" :placeholder="$t('reportmanage.cstate')" style="margin-left: 10px;width: 100px;">
         <el-option :label="$t('reportmanage.all')" value="-1"></el-option>
         <el-option :label="$t('reportmanage.scan')" value="0"></el-option>
         <el-option :label="$t('reportmanage.feeding')" value="1"></el-option>
@@ -21,11 +21,13 @@
         <el-option :label="$t('reportmanage.car')" value="3"></el-option>
         <el-option :label="$t('reportmanage.cage')" value="4"></el-option>
       </el-select>
-      <el-select v-model="report.line" :placeholder="$t('reportmanage.cprocess')" style="margin-left: 10px;">
+      <el-select v-model="report.line" :placeholder="$t('reportmanage.cprocess')" style="margin-left: 10px;width: 100px;">
         <el-option :label="$t('reportmanage.all')" value="0"></el-option>
         <el-option :label="$t('reportmanage.oneline')" value="2001"></el-option>
         <el-option :label="$t('reportmanage.twoline')" value="2002"></el-option>
       </el-select>
+      
+      <el-input v-model="timeInterval" style="margin-left: 15px;width: 100px" :placeholder="$t('reportmanage.timeInterval')"/>
       <el-button type="primary" style="margin-left: 10px;" @click="selectReportData()">{{ $t('reportmanage.inquire')
         }}</el-button>
     </div>
@@ -57,6 +59,13 @@
             <div id="dt" style="font-size: 15px;">
               <el-form-item :label="$t('reportmanage.totalTakes')" style="width: 14vw">
                 {{ totalTakes }}
+              </el-form-item>
+            </div>
+          </el-col>
+          <el-col :span="3">
+            <div id="dt" style="font-size: 15px;">
+              <el-form-item :label="$t('reportmanage.workMinutes')" style="width: 14vw">
+                {{ totalMinutes }} min
               </el-form-item>
             </div>
           </el-col>
@@ -97,8 +106,9 @@
   taskState: '-1',
   line: '0',
   width: '',
-  height: ''
+  height: '',
 });
+const  timeInterval= ref(120)
 const reportData = ref([])
 const endDate = new Date();
 const startDate = new Date();
@@ -116,6 +126,9 @@
 const totalAreas = ref(0);
 const totalDamages = ref(0);
 const totalTakes = ref(0);
+
+const workHours = ref(0);
+const totalMinutes = ref(0);
 
 // 鏌ヨ鏁版嵁
 const selectReportData = async () => {
@@ -152,10 +165,75 @@
       totalDamages.value = totalDamage;
       totalTakes.value = totalTake;
     ElMessage.success(response.message);
+    const workTime = calculateWorkTime(response.data);
+    console.log(workTime);
+ workHours.value = workTime.totalHours;
+ totalMinutes.value  =workTime.totalMinutes;
   } else {
     ElMessage.error(response.message);
   }
 
 };
 
+const calculateWorkTime = (tasks) =>{
+    // 澶勭悊绌烘暟鎹垨闈炴暟缁勬儏鍐�
+    if (!tasks || !Array.isArray(tasks) || tasks.length === 0) {
+        return {
+            totalSeconds: 0,
+            totalMinutes: 0,
+            totalHours: 0, // 纭繚鍒濆鍖�
+            periods: []
+        };
+    }
+
+    // 鎸夋椂闂存帓搴忎换鍔�
+    const sorted = [...tasks].sort((a, b) => new Date(a.createTime) - new Date(b.createTime));
+    
+    // 鍒濆鍖栧彉閲�
+    const periods = [];
+    let start = new Date(sorted[0].createTime);
+    let end = start;
+
+    // 閬嶅巻璁$畻杩炵画鏃舵
+    for (let i = 1; i < sorted.length; i++) {
+        const prev = new Date(sorted[i - 1].createTime);
+        const curr = new Date(sorted[i].createTime);
+        const gap = (curr - prev) / 1000; // 闂撮殧绉掓暟
+        // alert(timeInterval.value)
+        if (gap <= timeInterval.value) {
+            end = curr;
+        } else {
+            periods.push({
+                start: new Date(start),
+                end: new Date(end),
+                duration: Math.round((end - start) / 1000)
+            });
+            start = curr;
+            end = curr;
+        }
+    }
+
+    // 娣诲姞鏈�鍚庝竴涓椂娈�
+    periods.push({
+        start: new Date(start),
+        end: new Date(end),
+        duration: Math.round((end - start) / 1000)
+    });
+
+    // 璁$畻鎬绘椂闀�
+    const totalSeconds = periods.reduce((sum, p) => sum + (p.duration > 0 ? p.duration : 0), 0);
+    
+    // 纭繚鎵�鏈夋椂闂村瓧娈甸兘琚畾涔�
+    return {
+        totalSeconds: totalSeconds,
+        totalMinutes: Math.floor(totalSeconds / 60),
+        totalHours: (totalSeconds / 3600).toFixed(1), // 淇濈暀1浣嶅皬鏁�
+        periods: periods.map(p => ({
+            start: p.start.toLocaleString(),
+            end: p.end.toLocaleString(),
+            durationSeconds: p.duration,
+            durationMinutes: Math.floor(p.duration / 60)
+        }))
+    };
+}
 </script>
\ No newline at end of file

--
Gitblit v1.8.0