|
|
@@ -0,0 +1,134 @@
|
|
|
+const API = require("../../../../lib/API.js")
|
|
|
+const db = require("../../../../plugin/DataBase/db.js")
|
|
|
+const { BaseStdResponse } = require("../../../../BaseStdResponse.js")
|
|
|
+const AccessControl = require("../../../../lib/AccessControl.js")
|
|
|
+
|
|
|
+function parseDetail(value) {
|
|
|
+ if (value === null || value === undefined || value === '') return null
|
|
|
+ if (typeof value === 'object') return value
|
|
|
+ try {
|
|
|
+ return JSON.parse(value)
|
|
|
+ } catch {
|
|
|
+ return null
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class AdminBindAuditList extends API {
|
|
|
+ constructor() {
|
|
|
+ super()
|
|
|
+ this.setPath('/Admin/Lepao/BindAudit/List')
|
|
|
+ this.setMethod('GET')
|
|
|
+ }
|
|
|
+
|
|
|
+ async onRequest(req, res) {
|
|
|
+ let {
|
|
|
+ uuid,
|
|
|
+ session,
|
|
|
+ student_num,
|
|
|
+ owner_uuid,
|
|
|
+ operator_uuid,
|
|
|
+ action,
|
|
|
+ source,
|
|
|
+ queryTime,
|
|
|
+ pagesize,
|
|
|
+ current
|
|
|
+ } = req.query
|
|
|
+
|
|
|
+ if ([uuid, session, pagesize, current].some(v => v === '' || v === null || v === undefined))
|
|
|
+ return res.json({ ...BaseStdResponse.MISSING_PARAMETER })
|
|
|
+ if (isNaN(pagesize) || Number(pagesize) <= 0 || isNaN(current) || Number(current) <= 0)
|
|
|
+ return res.json({ ...BaseStdResponse.ERR, msg: '参数错误' })
|
|
|
+
|
|
|
+ if (!await AccessControl.checkSession(uuid, session))
|
|
|
+ return res.status(401).json({ ...BaseStdResponse.ACCESS_DENIED })
|
|
|
+
|
|
|
+ const permission = await AccessControl.getPermission(uuid)
|
|
|
+ if (!permission.includes("admin") && !permission.includes("server") && !permission.includes("service"))
|
|
|
+ return res.json({ ...BaseStdResponse.PERMISSION_DENIED })
|
|
|
+
|
|
|
+ const offset = (Number(current) - 1) * Number(pagesize)
|
|
|
+ const where = ['1 = 1']
|
|
|
+ const params = []
|
|
|
+ const countParams = []
|
|
|
+
|
|
|
+ if (student_num) {
|
|
|
+ where.push('lba.student_num COLLATE utf8mb4_general_ci LIKE (CONVERT(? USING utf8mb4) COLLATE utf8mb4_general_ci)')
|
|
|
+ params.push(`%${student_num}%`)
|
|
|
+ countParams.push(`%${student_num}%`)
|
|
|
+ }
|
|
|
+ if (owner_uuid) {
|
|
|
+ where.push('lba.owner_uuid COLLATE utf8mb4_general_ci = (CONVERT(? USING utf8mb4) COLLATE utf8mb4_general_ci)')
|
|
|
+ params.push(owner_uuid)
|
|
|
+ countParams.push(owner_uuid)
|
|
|
+ }
|
|
|
+ if (operator_uuid) {
|
|
|
+ where.push('lba.operator_uuid COLLATE utf8mb4_general_ci = (CONVERT(? USING utf8mb4) COLLATE utf8mb4_general_ci)')
|
|
|
+ params.push(operator_uuid)
|
|
|
+ countParams.push(operator_uuid)
|
|
|
+ }
|
|
|
+ if (action) {
|
|
|
+ where.push('lba.action COLLATE utf8mb4_general_ci = (CONVERT(? USING utf8mb4) COLLATE utf8mb4_general_ci)')
|
|
|
+ params.push(action)
|
|
|
+ countParams.push(action)
|
|
|
+ }
|
|
|
+ if (source) {
|
|
|
+ where.push('lba.source COLLATE utf8mb4_general_ci = (CONVERT(? USING utf8mb4) COLLATE utf8mb4_general_ci)')
|
|
|
+ params.push(source)
|
|
|
+ countParams.push(source)
|
|
|
+ }
|
|
|
+ if (Array.isArray(queryTime) && queryTime.length === 2) {
|
|
|
+ where.push('lba.created_at >= ? AND lba.created_at < ?')
|
|
|
+ params.push(queryTime[0], queryTime[1])
|
|
|
+ countParams.push(queryTime[0], queryTime[1])
|
|
|
+ }
|
|
|
+
|
|
|
+ const whereSql = where.join(' AND ')
|
|
|
+ const listSql = `
|
|
|
+ SELECT
|
|
|
+ lba.id,
|
|
|
+ lba.student_num,
|
|
|
+ lba.owner_uuid,
|
|
|
+ lba.action,
|
|
|
+ lba.source,
|
|
|
+ lba.operator_uuid,
|
|
|
+ lba.detail_json,
|
|
|
+ lba.created_at,
|
|
|
+ la.name AS lepao_name,
|
|
|
+ la.user_avatar AS lepao_avatar,
|
|
|
+ owner_u.username AS owner_username,
|
|
|
+ owner_u.avatar AS owner_avatar,
|
|
|
+ op_u.username AS operator_username,
|
|
|
+ op_u.avatar AS operator_avatar
|
|
|
+ FROM lepao_bind_audit lba
|
|
|
+ LEFT JOIN lepao_account la ON la.student_num COLLATE utf8mb4_general_ci = lba.student_num COLLATE utf8mb4_general_ci
|
|
|
+ LEFT JOIN users owner_u ON owner_u.uuid COLLATE utf8mb4_general_ci = lba.owner_uuid COLLATE utf8mb4_general_ci
|
|
|
+ LEFT JOIN users op_u ON op_u.uuid COLLATE utf8mb4_general_ci = lba.operator_uuid COLLATE utf8mb4_general_ci
|
|
|
+ WHERE ${whereSql}
|
|
|
+ ORDER BY lba.id DESC
|
|
|
+ LIMIT ? OFFSET ?
|
|
|
+ `
|
|
|
+ const countSql = `SELECT COUNT(*) AS total FROM lepao_bind_audit lba WHERE ${whereSql}`
|
|
|
+ params.push(String(pagesize), String(offset))
|
|
|
+
|
|
|
+ const rows = await db.query(listSql, params)
|
|
|
+ const countRows = await db.query(countSql, countParams)
|
|
|
+ if (!rows || !countRows) return res.json({ ...BaseStdResponse.DATABASE_ERR })
|
|
|
+
|
|
|
+ const data = rows.map(item => ({
|
|
|
+ ...item,
|
|
|
+ detail_json: parseDetail(item.detail_json)
|
|
|
+ }))
|
|
|
+
|
|
|
+ return res.json({
|
|
|
+ ...BaseStdResponse.OK,
|
|
|
+ data,
|
|
|
+ pagination: {
|
|
|
+ current: Number(current),
|
|
|
+ pagesize: Number(pagesize),
|
|
|
+ total: countRows[0]?.total || 0
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+module.exports.AdminBindAuditList = AdminBindAuditList
|