From 48145f787eda81815f653ad21161a60e89b6a303 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 13 十一月 2024 16:41:32 +0800
Subject: [PATCH] 2024.11.13

---
 model/ledger.js |  138 +++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 117 insertions(+), 21 deletions(-)

diff --git a/model/ledger.js b/model/ledger.js
index a4cb035..8686e6c 100644
--- a/model/ledger.js
+++ b/model/ledger.js
@@ -1,7 +1,6 @@
 const moment = require('../utils/moment.min');
 
-// 缁熻鍙拌处涓婁紶鎯呭喌
-function parseLedgerStat(subtypes, lastMonth) {
+function name(params) {
   const DEADLINEDAY = 10;
   let monthInfo = {
     totalMust: 0,
@@ -85,6 +84,8 @@
   //閫夐」鍗�
   var t = [];
   var p = [];
+  var tSelf = [];
+  var pSelf = [];
   for (let item of map) {
     let notUpload = 0;
     item[1].forEach(l => {
@@ -100,35 +101,130 @@
     p.push(item[1]);
   }
 
-  return [t, p, monthInfo];
+  return { types: t, items: p, monthInfo };
+}
+
+/**
+ * 瀵瑰彴璐︽垨鑷贰鏌ヨ繘琛岀粺璁★紝绫诲瀷ledgerTypeId涓�-1鐨勬槸鑷贰鏌ワ紝鍏朵綑涓哄彴璐�
+ * @param {Array} subtypes 鍙拌处璁板綍
+ * @param {Boolean} isSelfPatrol 鏄惁缁熻鑷贰鏌ョ被鍨�
+ */
+function _parse(subtypes, isSelfPatrol) {
+  const DEADLINEDAY = 10;
+  // 鏈堝害缁熻
+  let monthInfo = {
+    // 鍏ㄩ儴蹇呭~鏁�
+    totalMust: 0,
+    // 瀹屾垚蹇呭~鏁�
+    finishedMust: 0,
+    // 蹇呭~瀹屾垚鐧惧垎姣�
+    percent: 0,
+    // 鍏ㄩ儴閫夊~鏁�
+    totalSelect: 0,
+    // 瀹屾垚閫夊~鏁�
+    finishedSelect: 0,
+    // 鎻愪氦鐘舵�侊細鏈彁浜� | 閮ㄥ垎鎻愪氦 | 宸叉彁浜�
+    status: '',
+    // 閫炬湡澶╂暟
+    overtime: '',
+    // 寤鸿
+    suggestion: '',
+  };
+  let map = new Map();
+  for (let i = 0; i < subtypes.length; i++) {
+    const s = subtypes[i];
+    // 缁熻鑷贰鏌ユ椂锛岃繃婊ゆ櫘閫氬彴璐�
+    if (isSelfPatrol && s.ledgerTypeId != -1) continue;
+    // 缁熻鍙拌处鏃讹紝杩囨护鑷贰鏌�
+    if (!isSelfPatrol && s.ledgerTypeId == -1) continue;
+    // 鍒嗗埆缁熻蹇呭~鍜岄�夊~鐨勫畬鎴愭儏鍐�
+    if (s.needUpdate) {
+      monthInfo.totalMust++;
+      if (s.upLoad) monthInfo.finishedMust++;
+    } else {
+      monthInfo.totalSelect++;
+      if (s.upLoad) monthInfo.finishedSelect++;
+    }
+    refreshLedgerStatus(s);
+    if (!map.has(s.ledgerType)) map.set(s.ledgerType, []);
+    map.get(s.ledgerType).push(s);
+  }
+
+  //
+  if (monthInfo.finishedMust + monthInfo.finishedSelf == 0) {
+    monthInfo.status = '鏈彁浜�';
+    monthInfo.suggestion = '鍙拌处瀹屽叏鏈彁浜わ紝灏嗕弗閲嶅奖鍝嶈瘎浼扮粨鏋�';
+  } else if (monthInfo.finishedMust < monthInfo.totalMust) {
+    monthInfo.status = '閮ㄥ垎鎻愪氦';
+    monthInfo.suggestion = '鍙拌处閮ㄥ垎鏈彁浜わ紝浼氬奖鍝嶈瘎浼扮粨鏋�';
+  } else {
+    monthInfo.status = '宸叉彁浜�';
+    monthInfo.suggestion = '鍙拌处宸插叏閮ㄦ彁浜�';
+  }
+  monthInfo.overtime = moment().date() - DEADLINEDAY;
+  monthInfo.percent =
+    monthInfo.totalMust == 0
+      ? 0
+      : Math.round((monthInfo.finishedMust / monthInfo.totalMust) * 100);
+
+  //閫夐」鍗�
+  var t = [];
+  var p = [];
+  for (let item of map) {
+    let notUpload = 0;
+    item[1].forEach(l => {
+      if (l.needUpdate && !l.upLoad) {
+        notUpload++;
+      }
+    });
+    t.push({
+      name: item[0],
+      tag: notUpload,
+      total: item[1].length,
+    });
+    p.push(item[1]);
+  }
+
+  return { types: t, items: p, monthInfo };
+}
+// 缁熻鍙拌处涓婁紶鎯呭喌
+function parseLedgerStat(subtypes) {
+  return _parse(subtypes);
+}
+
+// 缁熻鑷贰鏌ヤ笂浼犳儏鍐�
+function parseSelfPatrol(subtypes) {
+  return _parse(subtypes, true);
 }
 
 function refreshLedgerStatus(s) {
-  if (s.upLoad) {
+  // if (s.ledgerFinished) {
+  //   s.badge = {
+  //     color: 'yellow',
+  //     count: '!',
+  //   };
+  //   s.opacity = 1;
+  // }
+  if (!s.needUpdate) {
     s.badge = {
-      color: 'green',
-      count: '鉁�',
-    };
-    s.opacity = 0.7;
-  } else if (s.ledgerFinished) {
-    s.badge = {
-      color: 'yellow',
-      count: '!',
+      color: '#00500079',
+      count: '閫夊~',
+      shape: 'bubble',
     };
     s.opacity = 1;
-  } else if (!s.needUpdate) {
-    s.badge = {
-      color: 'green',
-      count: '閫夊~',
-    };
-    s.opacity = 0.8;
   } else {
     s.badge = {
-      color: 'red',
-      count: '!',
+      color: 'ff00005d',
+      count: '蹇呭~',
+      shape: 'bubble',
     };
     s.opacity = 1;
   }
+  if (s.upLoad) {
+    s.badge.color = 'gray';
+    // s.badge.count += '鉁�';
+    s.opacity = 0.4;
+  }
 }
 
-export { parseLedgerStat, refreshLedgerStatus };
+export { parseLedgerStat, parseSelfPatrol, refreshLedgerStatus };

--
Gitblit v1.9.3