From cb4f0a3831ba25d144ab2802425bfed7c2199f50 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Mon, 26 Aug 2024 11:26:12 +0800 Subject: [PATCH] update --- .../hdl_central_kitchen_for_school.go | 22 +++++++++++++++++++ app/db/db_meal_label.go | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go b/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go index a5b61fe..b8a9ea3 100644 --- a/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go +++ b/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go @@ -504,6 +504,8 @@ func SetCentralKitchenForSchoolWithSpecByMealLabel(c *gin.Context) { now := time.Now() mealLabelDb := db.MealLabelDb{} mealLabelDb.Set(req.EnterpriseId) + + var nowIds map[int]bool for _, v := range req.MealLabelList { if v.Id != 0 { mealLabel, err := mealLabelDb.GetMealLabel(v.Id) @@ -518,6 +520,7 @@ func SetCentralKitchenForSchoolWithSpecByMealLabel(c *gin.Context) { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } + nowIds[v.Id] = true } else { mealLabel := &model.MealLabel{ Name: v.Name, @@ -536,6 +539,25 @@ func SetCentralKitchenForSchoolWithSpecByMealLabel(c *gin.Context) { } } + labels, err := mealLabelDb.FindMealLabel(req.GradeId, req.Kind) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + var needDelIds []int + for _, v := range *labels { + if !nowIds[v.Id] { + needDelIds = append(needDelIds, v.Id) + } + } + if len(needDelIds) > 0 { + _, err = mealLabelDb.MealLabelDelete(needDelIds) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + } + e.OutSuc(c, "success", nil) return } diff --git a/app/db/db_meal_label.go b/app/db/db_meal_label.go index b3b32ca..862f16e 100644 --- a/app/db/db_meal_label.go +++ b/app/db/db_meal_label.go @@ -26,7 +26,7 @@ func (MealLabelDb *MealLabelDb) FindMealLabel(gradeId int, kind int32) (*[]model return &m, nil } -func (MealLabelDb *MealLabelDb) MealLabelDeleteBySession(id interface{}) (int64, error) { +func (MealLabelDb *MealLabelDb) MealLabelDelete(id interface{}) (int64, error) { if reflect.TypeOf(id).Kind() == reflect.Slice { return MealLabelDb.Db.In("id", id).Delete(model.MealLabel{}) } else {