Browse Source

删除不必要的文件

Pchen. 3 months ago
parent
commit
0cf401b905
3 changed files with 0 additions and 299 deletions
  1. 0 116
      apis/Corn/StartPowerCheck.js
  2. 0 72
      apis/Corn/UpdateState.js
  3. 0 111
      apis/Lepao/Face/BeginFaceReco.js

+ 0 - 116
apis/Corn/StartPowerCheck.js

@@ -1,116 +0,0 @@
-const API = require("../../lib/API.js")
-const db = require('../../plugin/DataBase/db.js')
-const axios = require("axios")
-const EmailTemplate = require('../../plugin/Email/emailTemplate')
-const { BaseStdResponse } = require("../../BaseStdResponse.js")
-
-class StartPowerCheck extends API {
-    constructor() {
-        super()
-        this.noEncrypt()
-        this.setPath('/Corn/StartPowerCheck')
-        this.setMethod('GET')
-    }
-
-    async onRequest(req, res) {
-        try {
-            res.json({ ...BaseStdResponse.OK })
-
-            this.logger.info('开始执行电费提醒任务')
-
-            const sql = 'SELECT id, email, balance, lowest, area, building, room, is_notice FROM power_task'
-            const tasks = await db.query(sql)
-
-            if (!tasks) {
-                this.logger.error('获取电费提醒任务失败!')
-                return
-            }
-
-            for (const item of tasks) {
-                const { id, email, balance, lowest, area, building, room, is_notice } = item
-                this.logger.info(`${building}-${room} 开始电费查询余额`)
-
-                try {
-                    const endpoint = `https://hqpay.ctbu.edu.cn/weixin/ashx/frmuser.ashx?test=lastlist&pid=${room}&dyid=${building}`
-                    const response = await axios.get(endpoint, { proxy: false, timeout: 8000 })
-
-                    if (!response || !response.data || !response.data[0]) {
-                        this.logger.error('获取电费信息失败!返回数据:' + (response && response.data ? JSON.stringify(response.data) : 'no-response'))
-                        continue
-                    }
-
-                    const now_balance_raw = response.data[0][1]
-                    const now_change_time = response.data[0][2]
-
-                    this.logger.info(`${building}-${room} 电费余额:${now_balance_raw},扣费时间:${now_change_time}`)
-                    const time = Date.now()
-
-                    const nowBalanceNum = parseFloat(String(now_balance_raw).replace(/[^0-9.-]/g, ''))
-                    const balanceNum = parseFloat(String(balance).replace(/[^0-9.-]/g, '')) || 0
-                    const lowestNum = parseFloat(String(lowest).replace(/[^0-9.-]/g, '')) || 0
-
-                    if (Number.isNaN(nowBalanceNum)) {
-                        this.logger.error(`${building}-${room}:解析当前余额失败,原值:${now_balance_raw}`)
-                        continue
-                    }
-
-                    // 如果余额未变,跳过当前任务
-                    if (nowBalanceNum === balanceNum) {
-                        continue
-                    }
-
-                    // 记录变更并更新任务表余额
-                    const insertSql = 'INSERT INTO power_change_record (time, balance, old_balance, change_time, task_id) VALUES (?, ?, ?, ?, ?)'
-                    const insertRows = await db.query(insertSql, [time, nowBalanceNum, balanceNum, now_change_time, id])
-
-                    const updateSql = 'UPDATE power_task SET update_time = ?, balance = ?, koufei_date = ? WHERE id = ?'
-                    const updateRows = await db.query(updateSql, [time, nowBalanceNum, now_change_time, id])
-
-                    if (!insertRows || insertRows.affectedRows !== 1 || !updateRows || updateRows.affectedRows !== 1) {
-                        this.logger.error(`${building}-${room}:更新电费信息失败! 数据库错误`)
-                        continue
-                    }
-
-                    // 余额低于阈值且尚未通知 -> 发邮件并置 is_notice = 1
-                    if (nowBalanceNum < balanceNum && nowBalanceNum <= lowestNum && Number(is_notice) === 0) {
-                        const data = { now_balance: nowBalanceNum, now_change_time, lowest: lowestNum, area, building, room }
-                        try {
-                            await EmailTemplate.powerCheck(email, data)
-                            const upd = await db.query('UPDATE power_task SET is_notice = 1 WHERE id = ?', [id])
-                            if (!upd || upd.affectedRows !== 1) {
-                                this.logger.error(`${building}-${room}:更新 is_notice=1 失败`)
-                            }
-                        } catch (err) {
-                            this.logger.error(`${building}-${room}:发送邮件失败:${err.stack || err}`)
-                        }
-                    }
-
-                    // 充值后恢复未提醒状态
-                    if (nowBalanceNum > balanceNum && nowBalanceNum > lowestNum) {
-                        const upd = await db.query('UPDATE power_task SET is_notice = 0 WHERE id = ?', [id])
-                        if (!upd || upd.affectedRows !== 1) {
-                            this.logger.error(`${building}-${room}:更新 is_notice=0 失败`)
-                        }
-                    }
-                } catch (error) {
-                    this.logger.error(`获取电费信息失败!${error.stack || error}`)
-                    continue
-                }
-            }
-
-            // 删除180天前的记录
-            const delete_time = new Date().getTime() - 15552000000
-
-            let deleteSql = 'DELETE FROM power_change_record WHERE time < ?'
-            let deleteRows = await db.query(deleteSql, [delete_time])
-            if (!deleteRows) {
-                this.logger.error(`删除电费变更记录失败`)
-                return
-            }
-        } catch (error) {
-            this.logger.error(error)
-        }
-    }
-}
-
-module.exports.StartPowerCheck = StartPowerCheck

+ 0 - 72
apis/Corn/UpdateState.js

@@ -1,72 +0,0 @@
-const API = require("../../lib/API.js")
-const db = require('../../plugin/DataBase/db.js')
-const axios = require('axios')
-const config = require('../../config.json')
-const { BaseStdResponse } = require("../../BaseStdResponse.js")
-
-const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms))
-
-class UpdateState extends API {
-    constructor() {
-        super()
-
-        this.noEncrypt()
-        this.setPath('/Corn/UpdateState')
-        this.setMethod('GET')
-
-        this.runpy = config.runpy
-    }
-
-    async onRequest(req, res) {
-        try {
-            res.json({
-                ...BaseStdResponse.OK
-            })
-
-            this.logger.info('开始更新乐跑账号登录状态')
-
-            const zoneUrl = this.runpy + '/set_zone'
-
-            let sql = `SELECT id, uid, token, school_id, name, student_num FROM lepao_account WHERE state = 0 AND auto_run = 1 AND token IS NOT NULL`
-
-            let r = await db.query(sql)
-            if (!r)
-                return this.logger.error('更新乐跑账号登录状态失败!')
-
-            for (const item of r) {
-                const { name, student_num, token, uid, school_id } = item
-                this.logger.info(`${name}(${student_num})开始更新乐跑登录状态`)
-
-                await sleep(2000)
-
-                try {
-                    const ossData = { uid, token, school_id, student_id: student_num, random_id: 1, run_end_time: 1 }
-                    const zoneRes = await axios.post(zoneUrl, ossData)
-                    const { data } = zoneRes
-
-                    this.logger.info(`${student_num}更新乐跑登录状态返回结果: ${JSON.stringify(data)}`)
-
-                    if (!data || data.status != 1 || !data.data) {
-                        this.logger.info(`${name}(${student_num})数据获取失败,不更新`)
-                        continue
-                    }
-
-                    const sql = 'UPDATE lepao_account SET state = 1 WHERE student_num  = ?'
-                    await db.query(sql, [student_num])
-
-                    this.logger.info(`${name}(${student_num})数据获取成果,状态更新为正常`)
-                } catch (err) {
-                    this.logger.error(`${name}(${student_num})更新乐跑登录状态失败:${err.message || err}`)
-                }
-
-                
-            }
-
-            this.logger.info('更新乐跑账号登录状态完成')
-        } catch (error) {
-            this.logger.error(error)
-        }
-    }
-}
-
-module.exports.UpdateState = UpdateState

+ 0 - 111
apis/Lepao/Face/BeginFaceReco.js

@@ -1,111 +0,0 @@
-const API = require("../../../lib/API.js")
-const db = require("../../../plugin/DataBase/db.js")
-const axios = require('axios')
-const { v4: uuidv4 } = require('uuid')
-const Redis = require('../../../plugin/DataBase/Redis')
-const config = require('../../../config.json')
-const { BaseStdResponse } = require("../../../BaseStdResponse.js")
-
-class BeginFaceReco extends API {
-    constructor() {
-        super()
-
-        this.runpy = config.runpy
-
-        this.setPath('/Face/BeginFaceReco')
-        this.setMethod('POST')
-    }
-
-    /**
-     * 获取图片并转换为Base64
-     * @param {string} url - 图片链接
-     * @returns {Promise<string>} - Base64字符串
-     */
-    async getImageBase64(url) {
-        try {
-            const response = await axios.get(url, {
-                proxy: false,
-                responseType: "arraybuffer"
-            })
-            const base64 = Buffer.from(response.data, "binary").toString("base64")
-
-            // 获取图片MIME类型
-            const contentType = response.headers["content-type"]
-            return `data:${contentType};base64,${base64}`
-        } catch (error) {
-            throw new Error(`获取图片失败: ${error.message}`)
-        }
-    }
-
-    async onRequest(req, res) {
-        let { face_code } = req.body
-
-        if ([face_code].some(value => value === '' || value === null || value === undefined))
-            return res.json({
-                ...BaseStdResponse.MISSING_PARAMETER
-            })
-
-        try {
-            let sql = `
-                SELECT
-                    f.student_num,
-                    l.name,
-                    l.user_avatar,
-                    l.academy_name,
-                    l.state
-                FROM 
-                    lepao_face f
-                JOIN
-                    lepao_account l
-                ON
-                    f.student_num = l.student_num
-                WHERE
-                    f.face_code  = ?
-            `
-            let rows = await db.query(sql, [face_code])
-            if (!rows)
-                return res.json({
-                    ...BaseStdResponse.DATABASE_ERR,
-                    msg: '获取用户人脸信息失败,请重试'
-                })
-            if (rows.length !== 1)
-                return res.json({
-                    ...BaseStdResponse.ERR,
-                    msg: '采集码输入错误'
-                })
-            if(rows[0].state !== 1)
-                return res.json({
-                    ...BaseStdResponse.ERR,
-                    msg: '账号状态为未登录,请用乐跑登录器更新账号状态后再进行人脸识别'
-                })
-
-            const face_img = await this.getImageBase64('https://lepao-cloud.xxoo365.top/view.php/a517e6d3b4cf9834c99ff819b473d58d.jpg')
-            // 此时应该从乐跑获取人脸照片
-
-            const key = uuidv4()
-
-            await Redis.set(`faceReco:${rows[0].student_num}`, key, {
-                EX: 1800
-            })
-
-            let resData = {
-                ...rows[0],
-                key,
-                face_img
-            }
-
-            res.json({
-                ...BaseStdResponse.OK,
-                data: resData
-            })
-        } catch (error) {
-            this.logger.error(`获取用户人脸信息失败。${error.stack}`)
-            return res.json({
-                ...BaseStdResponse.ERR,
-                msg: '获取用户人脸信息失败,请重试'
-            })
-        }
-    }
-}
-
-module.exports.BeginFaceReco = BeginFaceReco