|
|
@@ -504,98 +504,34 @@ func SetCentralKitchenForSchoolWithSpecByMealLabel(c *gin.Context) { |
|
|
|
now := time.Now() |
|
|
|
mealLabelDb := db.MealLabelDb{} |
|
|
|
mealLabelDb.Set(req.EnterpriseId) |
|
|
|
for _, v := range req.List { |
|
|
|
for _, vv := range v.MealLabelListForBreakfast { |
|
|
|
if vv.Id != 0 { |
|
|
|
mealLabel, err := mealLabelDb.GetMealLabel(vv.Id) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
mealLabel.Name = vv.Name |
|
|
|
mealLabel.Price = vv.Price |
|
|
|
_, err = mealLabelDb.MealLabelUpdate(mealLabel, "name", "price") |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
} else { |
|
|
|
mealLabel := &model.MealLabel{ |
|
|
|
Name: vv.Name, |
|
|
|
EnterpriseId: req.EnterpriseId, |
|
|
|
PeriodId: v.PeriodId, |
|
|
|
Kind: 1, |
|
|
|
Price: vv.Price, |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
} |
|
|
|
_, err = mealLabelDb.MealLabelInsert(mealLabel) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
for _, v := range req.MealLabelList { |
|
|
|
if v.Id != 0 { |
|
|
|
mealLabel, err := mealLabelDb.GetMealLabel(v.Id) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
for _, vv := range v.MealLabelListForLunch { |
|
|
|
if vv.Id != 0 { |
|
|
|
mealLabel, err := mealLabelDb.GetMealLabel(vv.Id) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
mealLabel.Name = vv.Name |
|
|
|
mealLabel.Price = vv.Price |
|
|
|
_, err = mealLabelDb.MealLabelUpdate(mealLabel, "name", "price") |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
} else { |
|
|
|
mealLabel := &model.MealLabel{ |
|
|
|
Name: vv.Name, |
|
|
|
EnterpriseId: req.EnterpriseId, |
|
|
|
PeriodId: v.PeriodId, |
|
|
|
Kind: 2, |
|
|
|
Price: vv.Price, |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
} |
|
|
|
_, err = mealLabelDb.MealLabelInsert(mealLabel) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
mealLabel.Name = v.Name |
|
|
|
mealLabel.Price = v.Price |
|
|
|
_, err = mealLabelDb.MealLabelUpdate(mealLabel, "name", "price") |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
for _, vv := range v.MealLabelListForDinner { |
|
|
|
if vv.Id != 0 { |
|
|
|
mealLabel, err := mealLabelDb.GetMealLabel(vv.Id) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
mealLabel.Name = vv.Name |
|
|
|
mealLabel.Price = vv.Price |
|
|
|
_, err = mealLabelDb.MealLabelUpdate(mealLabel, "name", "price") |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
} else { |
|
|
|
mealLabel := &model.MealLabel{ |
|
|
|
Name: vv.Name, |
|
|
|
EnterpriseId: req.EnterpriseId, |
|
|
|
PeriodId: v.PeriodId, |
|
|
|
Kind: 3, |
|
|
|
Price: vv.Price, |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
} |
|
|
|
_, err = mealLabelDb.MealLabelInsert(mealLabel) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
} else { |
|
|
|
mealLabel := &model.MealLabel{ |
|
|
|
Name: v.Name, |
|
|
|
EnterpriseId: req.EnterpriseId, |
|
|
|
GradeId: req.GradeId, |
|
|
|
Kind: req.Kind, |
|
|
|
Price: v.Price, |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
} |
|
|
|
_, err = mealLabelDb.MealLabelInsert(mealLabel) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -605,66 +541,65 @@ func SetCentralKitchenForSchoolWithSpecByMealLabel(c *gin.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
func GetCentralKitchenForSchoolWithSpecByMealLabel(c *gin.Context) { |
|
|
|
enterpriseId := c.DefaultQuery("enterprise_id", "") |
|
|
|
periodDb := db.PeriodDb{} |
|
|
|
periodDb.Set(utils.StrToInt(enterpriseId)) |
|
|
|
periodList, err := periodDb.FindPeriod() |
|
|
|
var req md.GetCentralKitchenForSchoolWithSpecByMealLabelReq |
|
|
|
if req.Kind == 0 { |
|
|
|
req.Kind = 1 //TODO::默认查询早餐 |
|
|
|
} |
|
|
|
err := c.ShouldBindJSON(&req) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
err = validate.HandleValidateErr(err) |
|
|
|
err1 := err.(e.E) |
|
|
|
e.OutErr(c, err1.Code, err1.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var resp = md.GetCentralKitchenForSchoolWithSpecByMealLabelResp{} |
|
|
|
resp.EnterpriseId = req.EnterpriseId |
|
|
|
resp.Kind = req.Kind |
|
|
|
|
|
|
|
gradeList, total, err := svc2.SelfSupportForSchoolGradeList(md.SelfSupportForSchoolGradeListReq{ |
|
|
|
EnterpriseId: req.EnterpriseId, |
|
|
|
Limit: req.Limit, |
|
|
|
Page: req.Page, |
|
|
|
Name: "", |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var resp = md.SetCentralKitchenForSchoolWithSpecByMealLabel{} |
|
|
|
resp.EnterpriseId = utils.StrToInt(enterpriseId) |
|
|
|
mealLabelDb := db.MealLabelDb{} |
|
|
|
mealLabelDb.Set(resp.EnterpriseId) |
|
|
|
for _, v := range *periodList { |
|
|
|
mealLabels, err := mealLabelDb.FindMealLabel(v.Id) |
|
|
|
for _, v := range gradeList { |
|
|
|
mealLabels, err := mealLabelDb.FindMealLabel(v.Id, req.Kind) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var mealLabelListForBreakfast, mealLabelListForLunch, mealLabelListForDinner []md.MealLabelList |
|
|
|
var mealLabelList []md.MealLabelList |
|
|
|
for _, vv := range *mealLabels { |
|
|
|
if vv.Kind == 1 { |
|
|
|
mealLabelListForBreakfast = append(mealLabelListForBreakfast, md.MealLabelList{ |
|
|
|
Id: vv.Id, |
|
|
|
Name: vv.Name, |
|
|
|
Price: vv.Price, |
|
|
|
}) |
|
|
|
} |
|
|
|
if vv.Kind == 2 { |
|
|
|
mealLabelListForLunch = append(mealLabelListForLunch, md.MealLabelList{ |
|
|
|
Id: vv.Id, |
|
|
|
Name: vv.Name, |
|
|
|
Price: vv.Price, |
|
|
|
}) |
|
|
|
} |
|
|
|
if vv.Kind == 3 { |
|
|
|
mealLabelListForDinner = append(mealLabelListForDinner, md.MealLabelList{ |
|
|
|
Id: vv.Id, |
|
|
|
Name: vv.Name, |
|
|
|
Price: vv.Price, |
|
|
|
}) |
|
|
|
} |
|
|
|
mealLabelList = append(mealLabelList, md.MealLabelList{ |
|
|
|
Id: vv.Id, |
|
|
|
Name: vv.Name, |
|
|
|
Price: vv.Price, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
resp.List = append(resp.List, struct { |
|
|
|
PeriodId int `json:"period_id" binding:"required" label:"学段id"` |
|
|
|
Name string `json:"name" label:"学段名称"` |
|
|
|
MealLabelListForBreakfast []md.MealLabelList `json:"meal_label_list_for_breakfast" label:"早餐集合"` |
|
|
|
MealLabelListForLunch []md.MealLabelList `json:"meal_label_list_for_lunch" label:"午餐集合"` |
|
|
|
MealLabelListForDinner []md.MealLabelList `json:"meal_label_list_for_dinner" label:"晚餐集合"` |
|
|
|
GradeId int `json:"grade_id" binding:"required" label:"年级id"` |
|
|
|
Name string `json:"name" label:"年级名称"` |
|
|
|
MealLabelList []md.MealLabelList `json:"meal_label_list" label:"餐标集合"` |
|
|
|
}{ |
|
|
|
PeriodId: v.Id, |
|
|
|
Name: v.Name, |
|
|
|
MealLabelListForBreakfast: mealLabelListForBreakfast, |
|
|
|
MealLabelListForLunch: mealLabelListForLunch, |
|
|
|
MealLabelListForDinner: mealLabelListForDinner, |
|
|
|
GradeId: v.Id, |
|
|
|
Name: v.Name, |
|
|
|
MealLabelList: mealLabelList, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
e.OutSuc(c, resp, nil) |
|
|
|
e.OutSuc(c, map[string]interface{}{ |
|
|
|
"list": resp, |
|
|
|
"total": total, |
|
|
|
}, nil) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|