解决冲突,合并提交

This commit is contained in:
Rosy-zhudan
2019-09-17 16:37:01 +08:00
18 changed files with 733 additions and 74 deletions

View File

@@ -0,0 +1,23 @@
package dao
import (
"git.rosy.net.cn/jx-callback/business/model"
)
func GetDataResource(db *DaoDB, hashCode, fullURL string) (dataRes *model.DataResource, err error) {
sql := `
SELECT t1.*
FROM data_resource t1
WHERE 1 = 1`
sqlParams := []interface{}{}
if hashCode != "" {
sql += " AND t1.hash_code = ?"
sqlParams = append(sqlParams, hashCode)
}
if fullURL != "" {
sql += " AND (t1.main_url = ? OR t1.qiniu_url = ? OR t1.ebai_url = ? OR t1.mtwm_url = ?)"
sqlParams = append(sqlParams, fullURL, fullURL, fullURL, fullURL)
}
err = GetRow(db, &dataRes, sql, sqlParams...)
return dataRes, err
}

View File

@@ -1,2 +1,108 @@
package dao
import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
)
type FoodRecipeWithAction struct {
model.FoodRecipe
ActionType int8 `json:"actionType"`
}
func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID string) (recipeList []*FoodRecipeWithAction, err error) {
var sql string
var sqlParams []interface{}
if userID != "" {
sql = `
SELECT t1.*, t2.action_type
FROM food_recipe t1
LEFT JOIN food_recipe_user t2 ON t2.recipe_id = t1.id AND t2.user_id = ? AND t2.deleted_at = ?
WHERE t1.deleted_at = ?`
sqlParams = []interface{}{
userID,
utils.DefaultTimeValue,
utils.DefaultTimeValue,
}
} else {
sql = `
SELECT t1.*
FROM food_recipe t1
WHERE t1.deleted_at = ?`
sqlParams = []interface{}{
utils.DefaultTimeValue,
}
}
if keyword != "" {
keywordLike := "%" + keyword + "%"
sql += " AND (t1.name LIKE ?"
sqlParams = append(sqlParams, keywordLike)
sql += ")"
}
if recipeID > 0 {
sql += " AND t1.id = ?"
sqlParams = append(sqlParams, recipeID)
}
if authorID != "" {
sql += " AND t1.author_id = ?"
sqlParams = append(sqlParams, authorID)
}
err = GetRows(db, &recipeList, sql, sqlParams...)
return recipeList, err
}
func GetRecommendFoodRecipes(db *DaoDB, keyword, userID string) (recipeList []*model.FoodRecipe, err error) {
if list, err := QueryFoodRecipes(db, keyword, 0, userID, ""); err == nil {
recipeList = FoodRecipeWithActionList2Recipe(list)
}
return recipeList, err
}
func FoodRecipeWithActionList2Recipe(recipeList []*FoodRecipeWithAction) (outRecipeList []*model.FoodRecipe) {
for _, v := range recipeList {
outRecipeList = append(outRecipeList, &v.FoodRecipe)
}
return outRecipeList
}
func QueryFoodRecipesItems(db *DaoDB, recipeID int) (recipeItemList []*model.FoodRecipeItem, err error) {
sql := `
SELECT t1.*
FROM food_recipe_item t1
WHERE t1.deleted_at = ? AND t1.recipe_id = ?`
sqlParams := []interface{}{
utils.DefaultTimeValue,
recipeID,
}
sql += " ORDER BY t1.index"
err = GetRows(db, &recipeItemList, sql, sqlParams...)
return recipeItemList, err
}
func QueryFoodRecipesItemChoices(db *DaoDB, recipeID int) (recipeItemChoiceList []*model.FoodRecipeItemChoice, err error) {
sql := `
SELECT t1.*
FROM food_recipe_item_choice t1
WHERE t1.deleted_at = ? AND t1.recipe_id = ?`
sqlParams := []interface{}{
utils.DefaultTimeValue,
recipeID,
}
sql += " ORDER BY t1.index, t1.choice_index"
err = GetRows(db, &recipeItemChoiceList, sql, sqlParams...)
return recipeItemChoiceList, err
}
func QueryFoodRecipesSteps(db *DaoDB, recipeID int) (recipeStepList []*model.FoodRecipeStep, err error) {
sql := `
SELECT t1.*
FROM food_recipe_step t1
WHERE t1.deleted_at = ? AND t1.recipe_id = ?`
sqlParams := []interface{}{
utils.DefaultTimeValue,
recipeID,
}
sql += " ORDER BY t1.index"
err = GetRows(db, &recipeStepList, sql, sqlParams...)
return recipeStepList, err
}

View File

@@ -0,0 +1,40 @@
package dao
import (
"testing"
)
func TestQueryRecipes(t *testing.T) {
db := GetDB()
recipeList, err := QueryFoodRecipes(db, "", -1, "", "")
if err != nil {
t.Fatal(err)
}
if len(recipeList) > 0 {
t.Fatal("should not return list")
}
recipeItemList, err := QueryFoodRecipesItems(db, -1)
if err != nil {
t.Fatal(err)
}
if len(recipeItemList) > 0 {
t.Fatal("should not return list")
}
choiceList, err := QueryFoodRecipesItemChoices(db, -1)
if err != nil {
t.Fatal(err)
}
if len(choiceList) > 0 {
t.Fatal("should not return list")
}
stepList, err := QueryFoodRecipesSteps(db, -1)
if err != nil {
t.Fatal(err)
}
if len(stepList) > 0 {
t.Fatal("should not return list")
}
}

View File

@@ -32,7 +32,7 @@ func TestFormalizeStoreStatus(t *testing.T) {
}
func TestGetStoreList4Role(t *testing.T) {
storeList, err := GetStoreList(GetDB(), "NiuBi")
storeList, err := GetStoreList(GetDB(), nil, nil, "NiuBi")
t.Log(utils.Format4Output(storeList, false))
if err != nil {
t.Fatal(err)