修改敏感词过滤代码结构

This commit is contained in:
Rosy-zhudan
2019-08-19 10:27:04 +08:00
parent 9425f3c07a
commit dee9eea64a
9 changed files with 39 additions and 38 deletions

View File

@@ -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
}
}