修改敏感词过滤代码结构
This commit is contained in:
@@ -509,13 +509,28 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params ma
|
||||
}
|
||||
|
||||
func CheckHasSensitiveWord(word string) (bool, error) {
|
||||
if hasSensitiveWord, sensitiveWord := dao.CheckHasSensitiveWord(word); hasSensitiveWord {
|
||||
if hasSensitiveWord, sensitiveWord := IsSensitiveWordInList(word); hasSensitiveWord {
|
||||
return true, errors.New(fmt.Sprintf("不能包含敏感词:[%s]", sensitiveWord))
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func IsSensitiveWordInList(str string) (bool, string) {
|
||||
wordList, err := dao.GetSensitiveWordList()
|
||||
if err == nil {
|
||||
for _, value := range wordList {
|
||||
keyWord := value.Word
|
||||
checkHas := strings.Contains(str, keyWord)
|
||||
if checkHas {
|
||||
return true, keyWord
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false, ""
|
||||
}
|
||||
|
||||
func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName string) (outSkuNameExt *model.SkuNameExt, err error) {
|
||||
if skuNameExt.CategoryID == 0 {
|
||||
return nil, errors.New("CategoryID不能为空")
|
||||
@@ -1027,4 +1042,4 @@ func UploadImg2Platforms(ctx *jxcontext.Context, parentTask tasksch.ITask, imgUR
|
||||
}
|
||||
}
|
||||
return imgHintMap, err
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user