Browse Source

日志改动

xjj 1 năm trước cách đây
mục cha
commit
84847a956b

+ 34 - 12
src/pages/ReportDaily/components/ReportTable.js

@@ -1,8 +1,10 @@
-import React, { useMemo } from 'react';
-import { Button, Table, Tooltip } from 'antd';
+import React, { useMemo, useState } from 'react';
+import { Button, Modal, Table, Tooltip } from 'antd';
 import * as XLSX from 'xlsx';
 
 const ReportTable = ({ data, month }) => {
+  const [visible, setVisible] = useState(false);
+  const [item, setItem] = useState({});
   // 将 data 对象解析为表格的 dataSource
   const dataSource = useMemo(() => {
     if (!data) return [];
@@ -104,22 +106,42 @@ const ReportTable = ({ data, month }) => {
       dataIndex: 'hiredDate',
       key: 'hiredDate',
     },
+
     {
       title: '操作',
-      render: () => <a></a>,
+      render: item => <a onClick={() => showModal(item)}>日志提交时间</a>,
     },
   ];
 
+  const showModal = item => {
+    setItem(item);
+    setVisible(true);
+  };
+
   return (
-    <Table
-      dataSource={dataSource}
-      footer={() => (
-        <Button onClick={exportToExcel} type="primary">
-          导出报表
-        </Button>
-      )}
-      columns={columns}
-    />
+    <>
+      <Table
+        dataSource={dataSource}
+        footer={() => (
+          <Button onClick={exportToExcel} type="primary">
+            导出报表
+          </Button>
+        )}
+        columns={columns}
+      />
+      <Modal
+        title="日志提交记录"
+        visible={visible}
+        onCancel={() => setVisible(false)}
+        footer={null}
+      >
+        {item.dates?.map((item, index) => (
+          <div style={{ margin: '5px 0' }} key={index}>
+            {item.format('YYYY-MM-DD HH:mm:ss')}
+          </div>
+        ))}
+      </Modal>
+    </>
   );
 };
 

+ 28 - 32
src/pages/ReportDaily/utils.js

@@ -6,6 +6,7 @@ import {
   getAllReport,
   getHiredDate,
   getResignationDate,
+  getUserTakingDetail,
 } from '@/services/ReportDaily';
 
 async function getLateSubmissionsAndUnsubmittedReports(option) {
@@ -15,7 +16,7 @@ async function getLateSubmissionsAndUnsubmittedReports(option) {
   // 遍历报表数据,生成以工号为键、提交时间数组为值的数据结构
   reportData.forEach(item => {
     const employeeId = item.creator_id;
-    // if (item.creator_name != '徐俊杰') return;
+    // if (item.creator_name != '张西明') return;
     const reportTime = moment(item.create_time, 'YYYY年MM月DD日 HH:mm');
     if (!employeeSubmissions[employeeId]) {
       employeeSubmissions[employeeId] = {
@@ -25,19 +26,14 @@ async function getLateSubmissionsAndUnsubmittedReports(option) {
     }
     employeeSubmissions[employeeId].dates.push(reportTime);
   });
-
+  // debugger
   // 遍历工号,检查每个工号对应的提交时间
   for (const employeeId in employeeSubmissions) {
     const submissions = employeeSubmissions[employeeId].dates;
     console.log(`请求${employeeSubmissions[employeeId].name}的请假详情`);
     onProcess?.(`请求${employeeSubmissions[employeeId].name}的请假详情`);
     // 查询请假情况
-    const takingLeave = await getUserTakingLeave(startDate, endDate, employeeId);
-    // 判断是否为节假日或者请假
-    const isHoliday = date => {
-      let day = date.format('YYYY-MM-DD');
-      return holiday[day] || takingLeave[day];
-    };
+    const takingLeave = await getUserTakingDetail(startDate, endDate, employeeId);
 
     // 根据日志提交时间、节假日、请假情况,获取未提交以及漏交记录
     const { lateSubmissions, unsubmittedReports, takingLeaveReports } = await analyzeDates(
@@ -50,8 +46,6 @@ async function getLateSubmissionsAndUnsubmittedReports(option) {
     employeeSubmissions[employeeId].lateSubmissions = lateSubmissions;
     employeeSubmissions[employeeId].unsubmittedReports = unsubmittedReports;
     employeeSubmissions[employeeId].takingLeaveReports = takingLeaveReports;
-
-    delete employeeSubmissions[employeeId].dates;
   }
 
   onProcess('请求全部完成', true);
@@ -72,34 +66,36 @@ async function analyzeDates(dateArray, startDate, endDate, holiday, takingLeave)
 
   while (currentDay.isSameOrBefore(endDate, 'day')) {
     let index = -1;
-    // 一日可能有多条记录,通过遍历找到今日最后一次提交记录
-    sortedDates.forEach((time, i) => {
-      let flag = time.isSame(currentDay, 'day');
-      if (flag) index = i;
-    });
-    let date = index == -1 ? null : sortedDates[index];
-
-    // 无提交记录或者没有在9点以后提交都算未提交
-    if (!date || date.hour() < 9) {
-      let dayKey = currentDay.format('YYYY-MM-DD');
-      if (holiday[dayKey]) {
-        // 节假日不做处理
-      } else if (takingLeave[dayKey]) {
-        // 判断是否为请假
-        takingLeaveReports.push(dayKey);
-      } else {
-        // 今日未提交,根据次日提交情况判断是漏交还是迟交
-        let nextDay = sortedDates.find(time => time.diff(currentDay, 'day') == 1);
-        if (nextDay && nextDay.hour() < 9) {
-          lateSubmissions.push(dayKey);
+    let dayKey = currentDay.format('YYYY-MM-DD');
+    if (holiday[dayKey] || currentDay.day() === 0 || currentDay.day() === 6) {
+      // 节假日与周末不做处理
+    } else {
+      // 一日可能有多条记录,通过遍历找到今日最后一次提交记录
+      sortedDates.forEach((time, i) => {
+        let flag = time.isSame(currentDay, 'day');
+        if (flag) index = i;
+      });
+      let date = index == -1 ? null : sortedDates[index];
+
+      // 无提交记录或者没有在9点以后提交都算未提交
+      if (!date || date.hour() < 9) {
+        if (takingLeave[dayKey]) {
+          // 判断是否为请假
+          takingLeaveReports.push(dayKey);
         } else {
-          unsubmittedReports.push(dayKey);
+          // 今日未提交,根据次日提交情况判断是漏交还是迟交
+          let nextDay = sortedDates.find(time => time.diff(currentDay, 'day') == 1);
+          if (nextDay && nextDay.hour() < 9) {
+            lateSubmissions.push(dayKey);
+          } else {
+            unsubmittedReports.push(dayKey);
+          }
         }
       }
     }
 
     // 删除数组内多余数据,提高下次遍历效率
-    if (index != -1) sortedDates.splice(0, index);
+    // if (index != -1) sortedDates.splice(0, index);
 
     currentDay.add(1, 'days');
   }

+ 81 - 2
src/services/ReportDaily.js

@@ -2,7 +2,8 @@ import axios from 'axios';
 const moment = require('moment');
 
 let api = axios.create({
-  baseURL: 'http://47.96.12.136:8123/api',
+  // baseURL: 'http://47.96.12.136:8123/api',
+  baseURL: 'http://192.168.20.168:8123/api',
 });
 
 async function getToken() {
@@ -19,7 +20,7 @@ async function getToken() {
 let access_token = '';
 
 /**
- * 根据用户和时间段查询请假情况
+ * 根据用户和时间段查询下班打卡情况
  * @param {moment} startDate
  * @param {moment} endDate
  * @param {string} userid
@@ -69,6 +70,84 @@ export async function getUserTakingLeave(startDate, endDate, userid) {
 
   return takingLeave;
 }
+/**
+ * 根据用户和时间段查询请假详情
+ * @param {moment} startDate
+ * @param {moment} endDate
+ * @param {string} userid
+ * @returns
+ */
+export async function getUserTakingDetail(startDate, endDate, userid) {
+  if (!access_token) {
+    access_token = await getToken();
+  }
+
+  // 钉钉的接口 URL
+  const url = '/getleavestatus?access_token=' + access_token;
+  const size = 20;
+
+  const requestData = {
+    start_time: startDate.valueOf(),
+    offset: 0,
+    size,
+    end_time: endDate.valueOf(),
+    userid_list: userid,
+  };
+
+  // 设置请求头
+  const headers = {
+    'Content-Type': 'application/json',
+    Authorization: `Bearer ${access_token}`,
+  };
+  function getDaysInRange(startDate, endDate) {
+    const start = new Date(startDate);
+    const end = new Date(endDate);
+    const days = {};
+
+    // 循环遍历每一天,包括开始日期和结束日期
+    for (let date = start; date <= end; date.setDate(date.getDate() + 1)) {
+      const formattedDate = moment(date).format('YYYY-MM-DD');
+      days[formattedDate] = 1;
+    }
+
+    return days;
+  }
+  const getDataByPage = async offset => {
+    let catchKey = `getleavestatus|${userid}|${offset}|${requestData.start_time}`;
+    let res = {};
+    let catchData = localStorage[catchKey];
+    if (catchData) {
+      res = JSON.parse(catchData);
+    } else {
+      // 发送 POST 请求
+      let response = await api.post(url, { ...requestData, offset }, { headers });
+      res = response.data.result;
+      res.leave_status = res.leave_status.map(item => ({
+        userid: item.userid,
+        start_time: item.start_time,
+        end_time: item.end_time,
+      }));
+
+      localStorage[catchKey] = JSON.stringify(res);
+    }
+
+    return res;
+  };
+  let res = null,
+    leave_status = {},
+    count = 1;
+  do {
+    res = await getDataByPage(res ? (count - 1) * size : 0);
+    res.leave_status.forEach(item => {
+      
+      let days = getDaysInRange(item.start_time, item.end_time);
+      Object.assign(leave_status, days);
+    });
+    count++;
+  } while (res.has_more);
+
+  return leave_status;
+}
 
 /**
  * 根据时间段查询日志提交情况