修改敏感词过滤代码结构
This commit is contained in:
@@ -1,32 +1,17 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func GetSensitiveWordList() (wordList []*model.SensitiveWords, err error) {
|
||||
sql := `SELECT * FROM sensitive_words`
|
||||
func GetSensitiveWordList() (wordList []*model.SensitiveWord, err error) {
|
||||
sql := `SELECT * FROM sensitive_word`
|
||||
err = GetRows(nil, &wordList, sql)
|
||||
return wordList, err
|
||||
}
|
||||
|
||||
func InsertSensitiveWord(word string) error {
|
||||
return CreateEntity(nil, &model.SensitiveWords{Words: word})
|
||||
}
|
||||
|
||||
func CheckHasSensitiveWord(str string) (bool, string) {
|
||||
wordList, err := GetSensitiveWordList()
|
||||
if err == nil {
|
||||
for _, value := range wordList {
|
||||
keyWord := value.Words
|
||||
checkHas := strings.Contains(str, keyWord)
|
||||
if checkHas {
|
||||
return true, keyWord
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false, ""
|
||||
func InsertSensitiveWord(word string, vendorID int, userName string) error {
|
||||
sensitiveWord := &model.SensitiveWord{Word: word, VendorID: vendorID}
|
||||
WrapAddIDCULDEntity(sensitiveWord, userName)
|
||||
return CreateEntity(nil, sensitiveWord)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
type SensitiveWords struct {
|
||||
ID int `orm:"column(id)" json:"id"`
|
||||
Words string `orm:"size(30);column(words);unique" json:"words"`
|
||||
type SensitiveWord struct {
|
||||
ModelIDCULD
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
Word string `orm:"size(30);unique" json:"word"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user