定时任务改为查询7天内的所有审批消息
This commit is contained in:
parent
44c371e4a3
commit
a5b840e0a6
@ -5,6 +5,7 @@ import os from 'os'
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { RedisClient } from 'redis/RedisClient'
|
import { RedisClient } from 'redis/RedisClient'
|
||||||
import { excelToJson } from 'utils/excel.util'
|
import { excelToJson } from 'utils/excel.util'
|
||||||
|
import { timeBeforeDay } from 'utils/time.util'
|
||||||
|
|
||||||
// 1-审批中;2-已通过;3-已驳回;4-已撤销;6-通过后撤销;7-已删除;10-已支付
|
// 1-审批中;2-已通过;3-已驳回;4-已撤销;6-通过后撤销;7-已删除;10-已支付
|
||||||
export enum TaskStatus {
|
export enum TaskStatus {
|
||||||
@ -334,14 +335,14 @@ export class WechatWorkService {
|
|||||||
public async queryTasks() {
|
public async queryTasks() {
|
||||||
const url = `${WX_API_HOST}/cgi-bin/oa/getapprovalinfo`
|
const url = `${WX_API_HOST}/cgi-bin/oa/getapprovalinfo`
|
||||||
const access_token = await this.getAccessToken()
|
const access_token = await this.getAccessToken()
|
||||||
let starttime = this.timePre
|
let starttime = (timeBeforeDay(7) / 1000) | 0
|
||||||
if (!this.timePre) {
|
// if (!this.timePre) {
|
||||||
let timeStr = await new RedisClient().get('qywx_time_cache')
|
// let timeStr = await new RedisClient().get('qywx_time_cache')
|
||||||
if (timeStr) {
|
// if (timeStr) {
|
||||||
starttime = parseInt(timeStr)
|
// starttime = parseInt(timeStr)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
starttime = starttime || 1681401600
|
// starttime = starttime || 1683614900
|
||||||
let endtime = (Date.now() / 1000) | 0
|
let endtime = (Date.now() / 1000) | 0
|
||||||
let config: AxiosRequestConfig = {
|
let config: AxiosRequestConfig = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
|
68
src/utils/time.util.ts
Normal file
68
src/utils/time.util.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
export const ONE_DAY_MILLISECOND = 1000 * 3600 * 24
|
||||||
|
/**
|
||||||
|
* 获取n天前的time
|
||||||
|
* @param {number} day
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
export function timeBeforeDay(day: number): number {
|
||||||
|
let time = Date.now()
|
||||||
|
return time - day * ONE_DAY_MILLISECOND
|
||||||
|
}
|
||||||
|
|
||||||
|
//间隔天数
|
||||||
|
export function calcBetweenDays(time1: number, time2: number) {
|
||||||
|
let v1 = Math.floor(time1 / ONE_DAY_MILLISECOND)
|
||||||
|
let v2 = Math.floor(time2 / ONE_DAY_MILLISECOND)
|
||||||
|
return Math.abs(v1 - v2)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否是今天
|
||||||
|
* @param {number} time
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
export function isToday(time: number) {
|
||||||
|
return new Date().toDateString() === new Date(time).toDateString()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 今天开始的时间
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
export function todayStart() {
|
||||||
|
return new Date(new Date().toLocaleDateString()).getTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 今天结束的时间
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
export function todayEnd() {
|
||||||
|
return todayStart() + ONE_DAY_MILLISECOND - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取本周第一天和最后一天(周一开始)
|
||||||
|
* @return {{startDay: string, endDay: string}}
|
||||||
|
*/
|
||||||
|
export function getThisWeekData() {
|
||||||
|
return weekData(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取前后n周的周一和周日的日期
|
||||||
|
* @param {number} n 0为当前周, 1为下一周, -1为上周
|
||||||
|
* @return {{startDay: string, endDay: string}}
|
||||||
|
*/
|
||||||
|
export function weekData(n: number) {
|
||||||
|
const weekData = { startDay: '', endDay: '' }
|
||||||
|
const date = new Date()
|
||||||
|
// 上周一的日期
|
||||||
|
date.setDate(date.getDate() + 7 * n - date.getDay() + 1)
|
||||||
|
weekData.startDay = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
|
||||||
|
|
||||||
|
// 上周日的日期
|
||||||
|
date.setDate(date.getDate() + 6)
|
||||||
|
weekData.endDay = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
|
||||||
|
return weekData
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user