Merge pull request #415 from dalefengs/fix_group

fix: 渠道多分组,优化分组 like 查询
This commit is contained in:
Calcium-Ion 2024-08-08 20:47:51 +08:00 committed by GitHub
commit 43076c2f33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

@ -106,9 +106,15 @@ func SearchChannels(keyword string, group string, model string) ([]*Channel, err
// 构造WHERE子句 // 构造WHERE子句
var whereClause string var whereClause string
var args []interface{} var args []interface{}
if group != "" { if group != "" && group != "null" {
whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + groupCol + " = ? AND " + modelsCol + " LIKE ?" var groupCondition string
args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, group, "%"+model+"%") if common.UsingPostgreSQL {
groupCondition = `(',' || ` + groupCol + ` || ',') LIKE ?`
} else {
groupCondition = `CONCAT(',', ` + groupCol + `, ',') LIKE ?`
}
whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + ` LIKE ? AND ` + groupCondition
args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, "%"+model+"%", "%,"+group+",%")
} else { } else {
whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + " LIKE ?" whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + " LIKE ?"
args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, "%"+model+"%") args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, "%"+model+"%")

View File

@ -745,7 +745,8 @@ const ChannelsTable = () => {
<Form.Select <Form.Select
field='group' field='group'
label='分组' label='分组'
optionList={groupOptions} optionList={[{ label: '选择分组', value: null}, ...groupOptions]}
initValue={null}
onChange={(v) => { onChange={(v) => {
setSearchGroup(v); setSearchGroup(v);
searchChannels(searchKeyword, v, searchModel); searchChannels(searchKeyword, v, searchModel);