From e7f3f86e85a46c7962e4701115571a2274631a84 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 15 八月 2023 20:19:44 +0800 Subject: [PATCH] 服务合同批量删除接口 --- model/serviceContract.go | 6 ++ api/v1/serviceContract.go | 43 +++++++++++--- api/v1/serviceOrder.go | 6 +- docs/swagger.yaml | 17 +---- docs/docs.go | 21 +----- service/serviceContract.go | 8 ++ docs/swagger.json | 21 +----- router/serviceContract.go | 38 ++++++------ 8 files changed, 84 insertions(+), 76 deletions(-) diff --git a/api/v1/serviceContract.go b/api/v1/serviceContract.go index bd10717..99bfb1e 100644 --- a/api/v1/serviceContract.go +++ b/api/v1/serviceContract.go @@ -42,22 +42,45 @@ ctx.Ok() } -// Delete +//// Delete +//// +//// @Tags ServiceContract +//// @Summary 鍒犻櫎鏈嶅姟鍚堝悓 +//// @Produce application/json +//// @Param object body request.DeleteServiceContract true "鏌ヨ鍙傛暟" +//// @Success 200 {object} contextx.Response{} +//// @Router /api/serviceContract/delete [delete] +//func (s *ServiceContractApi) Delete(c *gin.Context) { +// var params request.DeleteServiceContract +// ctx, ok := contextx.NewContext(c, ¶ms) +// if !ok { +// return +// } // -// @Tags ServiceContract -// @Summary 鍒犻櫎鏈嶅姟鍚堝悓 -// @Produce application/json -// @Param object body request.DeleteServiceContract true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{} -// @Router /api/serviceContract/delete [delete] -func (s *ServiceContractApi) Delete(c *gin.Context) { - var params request.DeleteServiceContract +// errCode := serviceContractService.DeleteServiceContract(params.Ids) +// if errCode != ecode.OK { +// ctx.Fail(errCode) +// return +// } +// +// ctx.Ok() +//} + +// BatchDelete +// @Tags ServiceContract +// @Summary 鎵归噺鍒犻櫎鏈嶅姟鍚堝悓 +// @Produce application/json +// @Param object body request.CommonIds true "鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/serviceContract/delete [delete] +func (s *ServiceContractApi) BatchDelete(c *gin.Context) { + var params request.CommonIds ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } - errCode := serviceContractService.DeleteServiceContract(params.Ids) + errCode := serviceContractService.BatchDeleteServiceContract(params.Ids) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/api/v1/serviceOrder.go b/api/v1/serviceOrder.go index 6675774..887979d 100644 --- a/api/v1/serviceOrder.go +++ b/api/v1/serviceOrder.go @@ -67,10 +67,10 @@ } // BatchDelete -// @Tags 鏈嶅姟鍗曠鐞� -// @Summary 鎵归噺鍒犻櫎鏈嶅姟鍗� +// @Tags 鏈嶅姟鍗� +// @Summary 鎵归噺鍒犻櫎鏈嶅姟鍗� // @Produce application/json -// @Param object body request.CommonIds true "鍙傛暟" +// @Param object body request.CommonIds true "鍙傛暟" // @Success 200 {object} contextx.Response{} // @Router /api/serviceOrder/delete [delete] func (s *ServiceOrderApi) BatchDelete(c *gin.Context) { diff --git a/docs/docs.go b/docs/docs.go index 5c448f1..51bc4f3 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -7763,15 +7763,15 @@ "tags": [ "ServiceContract" ], - "summary": "鍒犻櫎鏈嶅姟鍚堝悓", + "summary": "鎵归噺鍒犻櫎鏈嶅姟鍚堝悓", "parameters": [ { - "description": "鏌ヨ鍙傛暟", + "description": "鍙傛暟", "name": "object", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/request.DeleteServiceContract" + "$ref": "#/definitions/request.CommonIds" } } ], @@ -8395,12 +8395,12 @@ "application/json" ], "tags": [ - "鏈嶅姟鍗曠鐞�" + "鏈嶅姟鍗�" ], "summary": "鎵归噺鍒犻櫎鏈嶅姟鍗�", "parameters": [ { - "description": "鏌ヨ鍙傛暟", + "description": "鍙傛暟", "name": "object", "in": "body", "required": true, @@ -14676,17 +14676,6 @@ } }, "request.DeleteSalesLeads": { - "type": "object", - "properties": { - "ids": { - "type": "array", - "items": { - "type": "integer" - } - } - } - }, - "request.DeleteServiceContract": { "type": "object", "properties": { "ids": { diff --git a/docs/swagger.json b/docs/swagger.json index 418ac07..094a394 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -7751,15 +7751,15 @@ "tags": [ "ServiceContract" ], - "summary": "鍒犻櫎鏈嶅姟鍚堝悓", + "summary": "鎵归噺鍒犻櫎鏈嶅姟鍚堝悓", "parameters": [ { - "description": "鏌ヨ鍙傛暟", + "description": "鍙傛暟", "name": "object", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/request.DeleteServiceContract" + "$ref": "#/definitions/request.CommonIds" } } ], @@ -8383,12 +8383,12 @@ "application/json" ], "tags": [ - "鏈嶅姟鍗曠鐞�" + "鏈嶅姟鍗�" ], "summary": "鎵归噺鍒犻櫎鏈嶅姟鍗�", "parameters": [ { - "description": "鏌ヨ鍙傛暟", + "description": "鍙傛暟", "name": "object", "in": "body", "required": true, @@ -14664,17 +14664,6 @@ } }, "request.DeleteSalesLeads": { - "type": "object", - "properties": { - "ids": { - "type": "array", - "items": { - "type": "integer" - } - } - } - }, - "request.DeleteServiceContract": { "type": "object", "properties": { "ids": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 9cb687d..825d07d 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -3200,13 +3200,6 @@ type: integer type: array type: object - request.DeleteServiceContract: - properties: - ids: - items: - type: integer - type: array - type: object request.DeleteServiceFeeManage: properties: ids: @@ -10661,12 +10654,12 @@ /api/serviceContract/delete: delete: parameters: - - description: 鏌ヨ鍙傛暟 + - description: 鍙傛暟 in: body name: object required: true schema: - $ref: '#/definitions/request.DeleteServiceContract' + $ref: '#/definitions/request.CommonIds' produces: - application/json responses: @@ -10674,7 +10667,7 @@ description: OK schema: $ref: '#/definitions/contextx.Response' - summary: 鍒犻櫎鏈嶅姟鍚堝悓 + summary: 鎵归噺鍒犻櫎鏈嶅姟鍚堝悓 tags: - ServiceContract /api/serviceContract/list: @@ -11050,7 +11043,7 @@ /api/serviceOrder/delete: delete: parameters: - - description: 鏌ヨ鍙傛暟 + - description: 鍙傛暟 in: body name: object required: true @@ -11065,7 +11058,7 @@ $ref: '#/definitions/contextx.Response' summary: 鎵归噺鍒犻櫎鏈嶅姟鍗� tags: - - 鏈嶅姟鍗曠鐞� + - 鏈嶅姟鍗� /api/serviceOrder/delete/{id}: delete: parameters: diff --git a/model/serviceContract.go b/model/serviceContract.go index 526b545..0850404 100644 --- a/model/serviceContract.go +++ b/model/serviceContract.go @@ -139,6 +139,12 @@ return db.Delete(&ServiceContract{}).Error } +func (slf *ServiceContractSearch) DeleteByIds(ids []int) error { + var db = slf.build() + db = db.Where("id in ?", ids) + return db.Delete(&ServiceContract{}).Error +} + func (slf *ServiceContractSearch) Find() ([]*ServiceContract, int64, error) { var db = slf.build() var records = make([]*ServiceContract, 0) diff --git a/router/serviceContract.go b/router/serviceContract.go index 9b22b38..d18817c 100644 --- a/router/serviceContract.go +++ b/router/serviceContract.go @@ -1,19 +1,19 @@ -package router - -import ( - v1 "aps_crm/api/v1" - "github.com/gin-gonic/gin" -) - -type ServiceContractRouter struct{} - -func (s *ServiceContractRouter) InitServiceContractRouter(router *gin.RouterGroup) { - serviceContractRouter := router.Group("serviceContract") - serviceContractApi := v1.ApiGroup.ServiceContractApi - { - serviceContractRouter.POST("add", serviceContractApi.Add) // 娣诲姞鏈嶅姟鍚堝悓 - serviceContractRouter.DELETE("delete", serviceContractApi.Delete) // 鍒犻櫎鏈嶅姟鍚堝悓 - serviceContractRouter.PUT("update", serviceContractApi.Update) // 鏇存柊鏈嶅姟鍚堝悓 - serviceContractRouter.POST("list", serviceContractApi.List) // 鑾峰彇鏈嶅姟鍚堝悓鍒楄〃 - } -} \ No newline at end of file +package router + +import ( + v1 "aps_crm/api/v1" + "github.com/gin-gonic/gin" +) + +type ServiceContractRouter struct{} + +func (s *ServiceContractRouter) InitServiceContractRouter(router *gin.RouterGroup) { + serviceContractRouter := router.Group("serviceContract") + serviceContractApi := v1.ApiGroup.ServiceContractApi + { + serviceContractRouter.POST("add", serviceContractApi.Add) // 娣诲姞鏈嶅姟鍚堝悓 + serviceContractRouter.DELETE("delete", serviceContractApi.BatchDelete) // 鍒犻櫎鏈嶅姟鍚堝悓 + serviceContractRouter.PUT("update", serviceContractApi.Update) // 鏇存柊鏈嶅姟鍚堝悓 + serviceContractRouter.POST("list", serviceContractApi.List) // 鑾峰彇鏈嶅姟鍚堝悓鍒楄〃 + } +} diff --git a/service/serviceContract.go b/service/serviceContract.go index 6da4367..93b7b3a 100644 --- a/service/serviceContract.go +++ b/service/serviceContract.go @@ -77,6 +77,14 @@ return ecode.OK } +func (SContractService) BatchDeleteServiceContract(ids []int) int { + err := model.NewServiceContractSearch().DeleteByIds(ids) + if err != nil { + return ecode.DBErr + } + return ecode.OK +} + func (SContractService) GetServiceContractList(page, pageSize int, queryClass constvar.ServiceContractQueryClass, keywordType constvar.ServiceContractKeywordType, keyword string) ([]*model.ServiceContract, int64, int) { // get contact list contacts, total, err := model.NewServiceContractSearch(). -- Gitblit v1.8.0