|
| 1 | +import larkClient, { lark } from './larkClient.js' |
| 2 | + |
| 3 | +// 创建实时解题个数记录 |
| 4 | +const setLeetCodeHistory = async (open_id, easy, medium, hard) => { |
| 5 | + const data = new Map([ |
| 6 | + ['Easy', easy], |
| 7 | + ['Medium', medium], |
| 8 | + ['Hard', hard], |
| 9 | + ['日期', new Date().getTime()], |
| 10 | + ['人员', [{ id: open_id }]], |
| 11 | + ]) |
| 12 | + |
| 13 | + await larkClient.bitable.v1.appTableRecord |
| 14 | + .create({ |
| 15 | + path: { |
| 16 | + app_token: process.env.FEISHU_BITABLE_APP_TOKEN, |
| 17 | + table_id: process.env.FEISHU_BITABLE_RECORD_TABLE_ID, |
| 18 | + }, |
| 19 | + data: { |
| 20 | + fields: Object.fromEntries(data), |
| 21 | + }, |
| 22 | + }) |
| 23 | + .then((res) => { |
| 24 | + // console.log(res) |
| 25 | + }) |
| 26 | + .catch((e) => { |
| 27 | + console.error(JSON.stringify(e.response.data, null, 4)) |
| 28 | + }) |
| 29 | +} |
| 30 | + |
| 31 | +// 获取历史解题个数记录 |
| 32 | +const getLeetCodeHistoryCount = async (open_id) => { |
| 33 | + const res = await larkClient.bitable.v1.appTableRecord |
| 34 | + .search({ |
| 35 | + path: { |
| 36 | + app_token: process.env.FEISHU_BITABLE_APP_TOKEN, |
| 37 | + table_id: process.env.FEISHU_BITABLE_RECORD_TABLE_ID, |
| 38 | + }, |
| 39 | + data: { |
| 40 | + sort: [ |
| 41 | + { |
| 42 | + field_name: '日期', |
| 43 | + desc: true, |
| 44 | + }, |
| 45 | + ], |
| 46 | + filter: { |
| 47 | + conjunction: 'and', |
| 48 | + conditions: [ |
| 49 | + { |
| 50 | + field_name: '人员', |
| 51 | + operator: 'is', |
| 52 | + value: [open_id], |
| 53 | + }, |
| 54 | + { |
| 55 | + field_name: '日期', |
| 56 | + operator: 'is', |
| 57 | + value: ['Yesterday'], |
| 58 | + }, |
| 59 | + ], |
| 60 | + }, |
| 61 | + }, |
| 62 | + }) |
| 63 | + .then((res) => { |
| 64 | + // console.log(res) |
| 65 | + return res |
| 66 | + }) |
| 67 | + .catch((e) => { |
| 68 | + console.error(JSON.stringify(e.response.data, null, 4)) |
| 69 | + }) |
| 70 | + if (res.data.items.length === 0) { |
| 71 | + return -1 |
| 72 | + } |
| 73 | + return res.data.items[0].fields.Total.value[0] |
| 74 | +} |
| 75 | + |
| 76 | +// 创建打卡状态 |
| 77 | +const setLeetCodeStatus = async (open_id, status) => { |
| 78 | + if (status === true) { |
| 79 | + status = '打卡成功' |
| 80 | + } else { |
| 81 | + status = '打卡失败' |
| 82 | + } |
| 83 | + const data = new Map([ |
| 84 | + ['日期', new Date().getTime()], |
| 85 | + ['人员', [{ id: open_id }]], |
| 86 | + ['状态', status], |
| 87 | + ]) |
| 88 | + |
| 89 | + await larkClient.bitable.v1.appTableRecord |
| 90 | + .create({ |
| 91 | + path: { |
| 92 | + app_token: process.env.FEISHU_BITABLE_APP_TOKEN, |
| 93 | + table_id: process.env.FEISHU_BITABLE_STATUS_TABLE_ID, |
| 94 | + }, |
| 95 | + data: { |
| 96 | + fields: Object.fromEntries(data), |
| 97 | + }, |
| 98 | + }) |
| 99 | + .then((res) => { |
| 100 | + // console.log(res) |
| 101 | + }) |
| 102 | + .catch((e) => { |
| 103 | + console.error(JSON.stringify(e.response.data, null, 4)) |
| 104 | + }) |
| 105 | +} |
| 106 | + |
| 107 | +export { setLeetCodeHistory, getLeetCodeHistoryCount, setLeetCodeStatus } |
0 commit comments