解决冲突,合并提交
This commit is contained in:
@@ -72,6 +72,8 @@ var (
|
||||
VendorIDXiaoWM: "XiaoWM",
|
||||
VendorIDYiLianYun: "Yilianyun",
|
||||
VendorIDZhongWu: "ZhongWu",
|
||||
|
||||
VendorIDQiNiuCloud: "Qiniu",
|
||||
}
|
||||
|
||||
VendorTypeName = map[int]string{
|
||||
|
||||
@@ -13,19 +13,13 @@ var (
|
||||
type DataResource struct {
|
||||
ModelIDCUL
|
||||
|
||||
HashCode string `orm:"size(48);unique" json:"hash_code"`
|
||||
ResoureType string // 资料的mime type
|
||||
HashCode string `orm:"size(48);unique" json:"hashCode"`
|
||||
|
||||
Name string `orm:"size(48)" json:"name"`
|
||||
ResoureType string `orm:"size(48)" json:"resoureType"` // 资料的mime type
|
||||
Name string `orm:"size(48);index" json:"name"`
|
||||
|
||||
MainURL string
|
||||
QiniuURL string
|
||||
EbaiURL string
|
||||
MtwmURL string
|
||||
}
|
||||
|
||||
func (*DataResource) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"HashCode", "ResoureType"},
|
||||
}
|
||||
MainURL string `orm:"size(1024);column(main_url);index" json:"mainURL"`
|
||||
QiniuURL string `orm:"size(1024);column(qiniu_url);index" json:"qiniuURL"`
|
||||
EbaiURL string `orm:"size(1024);column(ebai_url);index" json:"ebaiURL"`
|
||||
MtwmURL string `orm:"size(1024);column(mtwm_url);index" json:"mtwmURL"`
|
||||
}
|
||||
|
||||
23
business/model/dao/common.go
Normal file
23
business/model/dao/common.go
Normal 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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
40
business/model/dao/food_recipe_test.go
Normal file
40
business/model/dao/food_recipe_test.go
Normal 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")
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -114,7 +114,7 @@ func IsSyncStatusPrice(syncStatus int8) bool {
|
||||
return (syncStatus & SyncFlagPriceMask) != 0
|
||||
}
|
||||
|
||||
func IsSyncStatusSec(syncStatus int8) bool {
|
||||
func IsSyncStatusSeq(syncStatus int8) bool {
|
||||
return (syncStatus & SyncFlagSeqMask) != 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user