瞪眼法测试通过

This commit is contained in:
Kyaru
2026-06-25 21:18:13 +08:00
parent b9266dfc1f
commit 67c9330659
11 changed files with 919 additions and 49 deletions

View File

@@ -2,6 +2,24 @@
const { pool } = require('../db')
const { getDataScope } = require('../middleware/permissions')
// 格式化日期为 YYYY-MM-DD
function formatDate(dateStr) {
if (!dateStr) return null
if (typeof dateStr === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(dateStr)) {
return dateStr
}
try {
const date = new Date(dateStr)
if (isNaN(date.getTime())) return null
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
} catch {
return null
}
}
function pagination(query) {
const page = Math.max(Number(query.page) || 1, 1)
const pageSize = Math.min(Math.max(Number(query.pageSize) || 10, 1), 100)
@@ -23,7 +41,7 @@ const LIST_SELECT = `
async function list(req, res) {
try {
const { page, pageSize, offset } = pagination(req.query)
const { handle_status, customer_name } = req.query
const { handle_status, customer_name, id, customer_id, feedback } = req.query
let where = 'WHERE 1=1'
const params = []
@@ -35,11 +53,23 @@ async function list(req, res) {
}
if (scope.where) {
// list 查询有 JOIN需要表别名前缀避免列名歧义
const scopeCol = scope.tableAlias ? scope.where.replace('responsible_user_id', `${scope.tableAlias}.responsible_user_id`) : scope.where
const scopeCol = scope.tableAlias ? scope.where.replace(/\bresponsible_user_id\b/g, `${scope.tableAlias}.responsible_user_id`) : scope.where
where += ' AND ' + scopeCol
params.push(...scope.values)
}
if (id) {
where += ' AND a.id = ?'
params.push(id)
}
if (customer_id) {
where += ' AND a.customer_id = ?'
params.push(customer_id)
}
if (feedback) {
where += ' AND a.feedback LIKE ?'
params.push(`%${feedback}%`)
}
if (handle_status) {
where += ' AND a.handle_status = ?'
params.push(handle_status)
@@ -145,7 +175,7 @@ async function create(req, res) {
employee_id || null,
handle_method || null,
handle_status || '待处理',
service_date || null,
formatDate(service_date),
remark || null,
ownerId]
)
@@ -201,7 +231,12 @@ async function update(req, res) {
for (const f of fields) {
if (req.body[f] !== undefined) {
sets.push(`${f} = ?`)
params.push(req.body[f])
// 日期字段需要格式化
if (f === 'service_date') {
params.push(formatDate(req.body[f]))
} else {
params.push(req.body[f])
}
}
}
if (sets.length === 0) {