// 格式化筛选条件
function formatCondition() {
    if (Object.keys(params).length > 0) {
        const placeholders = [];
        const tempParams = [];

        var cols = []
        let mapCols = {}
        TABLE_STRUCT.forEach(item => {
            if (item.is_query == 1) {
                cols.push(item.column_name)
                if (item.field_name) {
                    mapCols[`${item.field_name}`] = item.column_name
                }
            }
        })


        // 将存在别名的params转换
        let coverParams = {}
        Object.keys(params).forEach(item => {
            if (mapCols[item]) {
                coverParams[mapCols[item]] = params[item]
            } else {
                coverParams[item] = params[item]
            }
        })

        Object.keys(coverParams).forEach(key => {
            let col_name = camelToUnderscore(key)
            if (cols.includes(col_name)) {
                var row = {}
                TABLE_STRUCT.find(item => {
                    if (item.column_name == col_name) {
                        row = item
                    }
                })

                if (coverParams[key]) {
                    // if (row.query_type == "NaN" || row.query_type == "VAL") {
                    //     placeholders.push(`${col_name} ${sql_operator[row.query_type]}`);
                    // }
                    // if (row.query_type == "LIKE") {
                    //     tempParams.push('%' + coverParams[key] + '%');
                    // } else {
                    //     tempParams.push(coverParams[key]);
                    // }
                    switch (row.query_type) {
                        case "NAN":
                        case "VAL":
                            placeholders.push(`${col_name} ${sql_operator[row.query_type]}`);
                            break;
                        case "LIKE":
                            placeholders.push(`${col_name} ${sql_operator[row.query_type]} ?`);
                            tempParams.push('%' + coverParams[key] + '%');
                            break;
                        case "BT":
                            if (coverParams[key].includes(',')) {
                                placeholders.push(`${col_name} BETWEEN ? AND ?`);
                                let rangValue = coverParams[key].split(',')
                                tempParams.push(rangValue[0]);
                                tempParams.push(rangValue[1]);
                            }
                            break;
                        default:
                            placeholders.push(`${col_name} ${sql_operator[row.query_type]} ?`);
                            tempParams.push(coverParams[key]);
                            break;
                    }
                }
            }
        })

        return {
            placeholders: placeholders.join(' AND '),
            tempParams: tempParams,
        }
    }
}