From c20b2d72c1f6241213f792dde44e50def6bf3510 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期五, 25 八月 2023 16:42:05 +0800 Subject: [PATCH] fix --- api/v1/test/supplier_type.go | 24 +++++++++++++++++------- 1 files changed, 17 insertions(+), 7 deletions(-) diff --git a/api/v1/test/supplier_type.go b/api/v1/test/supplier_type.go index 9cd5b4d..4733d83 100644 --- a/api/v1/test/supplier_type.go +++ b/api/v1/test/supplier_type.go @@ -94,22 +94,32 @@ // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body test.SupplierType true "鏇存柊SupplierType" +// @Param data body request.SupplierTypeList true "鏇存柊SupplierType" // @Success 200 {string} string "{"success":true,"data":{},"msg":"鏇存柊鎴愬姛"}" // @Router /st/updateSupplierType [put] func (stApi *SupplierTypeApi) UpdateSupplierType(c *gin.Context) { - var st test.SupplierType + var st testReq.SupplierTypeList err := c.ShouldBindJSON(&st) if err != nil { response.FailWithMessage(err.Error(), c) return } - if err := stService.UpdateSupplierType(st); err != nil { - global.GVA_LOG.Error("鏇存柊澶辫触!", zap.Error(err)) - response.FailWithMessage("鏇存柊澶辫触", c) - } else { - response.OkWithMessage("鏇存柊鎴愬姛", c) + + if err := stService.DeleteAll(); err != nil { + global.GVA_LOG.Error("鍒犻櫎澶辫触!", zap.Error(err)) + response.FailWithMessage("鍒犻櫎澶辫触", c) + return } + + for _, v := range st.SupplierTypes { + if err := stService.CreateSupplierType(&v); err != nil { + global.GVA_LOG.Error("鍒涘缓澶辫触!", zap.Error(err)) + response.FailWithMessage("鍒涘缓澶辫触", c) + return + } + } + + response.OkWithMessage("鏇存柊鎴愬姛", c) } // FindSupplierType 鐢╥d鏌ヨSupplierType -- Gitblit v1.8.0