From 4f69f07912ea3da9770983c9d4bacbcebbb366e4 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 09 八月 2023 15:22:54 +0800 Subject: [PATCH] 服务合同签约日期验证 --- model/serviceContract.go | 6 api/v1/serviceContract.go | 42 ---- model/request/serviceContract.go | 90 +++++----- docs/swagger.yaml | 24 +- docs/docs.go | 36 ++-- pkg/contextx/contextx.go | 203 ++++++++++++------------ docs/swagger.json | 36 ++-- 7 files changed, 204 insertions(+), 233 deletions(-) diff --git a/api/v1/serviceContract.go b/api/v1/serviceContract.go index 7ab6147..d354aa2 100644 --- a/api/v1/serviceContract.go +++ b/api/v1/serviceContract.go @@ -46,11 +46,11 @@ // @Tags ServiceContract // @Summary 鍒犻櫎鏈嶅姟鍚堝悓 // @Produce application/json -// @Param object body request.DeleteserviceContract true "鏌ヨ鍙傛暟" +// @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 + var params request.DeleteServiceContract ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return @@ -99,44 +99,11 @@ // check params func checkServiceContractParams(serviceContract request.ServiceContract) (errCode int, result model.ServiceContract) { - //if serviceContract.SignTime == "" { - // return ecode.InvalidParams, result - //} - // - //if serviceContract.Number == "" { - // return ecode.InvalidParams, result - //} - // - //if serviceContract.MemberId <= 0 { - // return ecode.InvalidParams, result - //} - - t, err := checkTimeFormat(serviceContract.SignTime) - if err != nil { - return ecode.InvalidParams, result - } - - result.SignTime = t - - t, err = checkTimeFormat(serviceContract.StartTime) - if err != nil { - return ecode.InvalidParams, result - } - - result.StartTime = t - - t, err = checkTimeFormat(serviceContract.EndTime) - if err != nil { - return ecode.InvalidParams, result - } - - result.EndTime = t - result.Number = serviceContract.Number result.MemberId = serviceContract.MemberId result.Remark = serviceContract.Remark result.ClientId = serviceContract.ClientId - result.ContactId = serviceContract.ContactId + result.SalesDetailsId = serviceContract.SalesDetailsId result.SaleChanceId = serviceContract.SaleChanceId result.QuotationId = serviceContract.QuotationId result.ServiceContractTypeId = serviceContract.TypeId @@ -144,6 +111,9 @@ result.ServiceTimes = serviceContract.ServiceTimes result.Terms = serviceContract.Terms result.Products = serviceContract.Products + result.SignTime = serviceContract.SignTime + result.StartTime = serviceContract.StartTime + result.EndTime = serviceContract.EndTime return ecode.OK, result } diff --git a/docs/docs.go b/docs/docs.go index cce75ae..6e89fdc 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -7620,7 +7620,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/request.DeleteserviceContract" + "$ref": "#/definitions/request.DeleteServiceContract" } } ], @@ -12904,9 +12904,6 @@ "contactId": { "type": "integer" }, - "contractId": { - "type": "integer" - }, "endTime": { "type": "string" }, @@ -12929,6 +12926,9 @@ "type": "string" }, "saleChanceId": { + "type": "integer" + }, + "salesDetailsId": { "type": "integer" }, "serviceTimes": { @@ -13550,6 +13550,17 @@ } } }, + "request.DeleteServiceContract": { + "type": "object", + "properties": { + "ids": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, "request.DeleteServiceFeeManage": { "type": "object", "properties": { @@ -13578,17 +13589,6 @@ "userId": { "description": "鐢ㄦ埛ID", "type": "string" - } - } - }, - "request.DeleteserviceContract": { - "type": "object", - "properties": { - "ids": { - "type": "array", - "items": { - "type": "integer" - } } } }, @@ -15898,9 +15898,6 @@ "contactId": { "type": "integer" }, - "contractId": { - "type": "integer" - }, "endTime": { "type": "string" }, @@ -15928,6 +15925,9 @@ "saleChanceId": { "type": "integer" }, + "salesDetailsId": { + "type": "integer" + }, "serviceTimes": { "type": "integer" }, diff --git a/docs/swagger.json b/docs/swagger.json index fc4f0c6..99935e0 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -7608,7 +7608,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/request.DeleteserviceContract" + "$ref": "#/definitions/request.DeleteServiceContract" } } ], @@ -12892,9 +12892,6 @@ "contactId": { "type": "integer" }, - "contractId": { - "type": "integer" - }, "endTime": { "type": "string" }, @@ -12917,6 +12914,9 @@ "type": "string" }, "saleChanceId": { + "type": "integer" + }, + "salesDetailsId": { "type": "integer" }, "serviceTimes": { @@ -13538,6 +13538,17 @@ } } }, + "request.DeleteServiceContract": { + "type": "object", + "properties": { + "ids": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, "request.DeleteServiceFeeManage": { "type": "object", "properties": { @@ -13566,17 +13577,6 @@ "userId": { "description": "鐢ㄦ埛ID", "type": "string" - } - } - }, - "request.DeleteserviceContract": { - "type": "object", - "properties": { - "ids": { - "type": "array", - "items": { - "type": "integer" - } } } }, @@ -15886,9 +15886,6 @@ "contactId": { "type": "integer" }, - "contractId": { - "type": "integer" - }, "endTime": { "type": "string" }, @@ -15916,6 +15913,9 @@ "saleChanceId": { "type": "integer" }, + "salesDetailsId": { + "type": "integer" + }, "serviceTimes": { "type": "integer" }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index fcc473d..8a6a75d 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -2307,8 +2307,6 @@ type: integer contactId: type: integer - contractId: - type: integer endTime: type: string memberId: @@ -2324,6 +2322,8 @@ remark: type: string saleChanceId: + type: integer + salesDetailsId: type: integer serviceTimes: type: integer @@ -2755,6 +2755,13 @@ type: integer type: array type: object + request.DeleteServiceContract: + properties: + ids: + items: + type: integer + type: array + type: object request.DeleteServiceFeeManage: properties: ids: @@ -2774,13 +2781,6 @@ userId: description: 鐢ㄦ埛ID type: string - type: object - request.DeleteserviceContract: - properties: - ids: - items: - type: integer - type: array type: object request.DownloadFile: properties: @@ -4341,8 +4341,6 @@ type: integer contactId: type: integer - contractId: - type: integer endTime: type: string id: @@ -4360,6 +4358,8 @@ remark: type: string saleChanceId: + type: integer + salesDetailsId: type: integer serviceTimes: type: integer @@ -9980,7 +9980,7 @@ name: object required: true schema: - $ref: '#/definitions/request.DeleteserviceContract' + $ref: '#/definitions/request.DeleteServiceContract' produces: - application/json responses: diff --git a/model/request/serviceContract.go b/model/request/serviceContract.go index 2ad8995..1ab30c4 100644 --- a/model/request/serviceContract.go +++ b/model/request/serviceContract.go @@ -1,45 +1,45 @@ -package request - -import ( - "aps_crm/constvar" - "aps_crm/model" -) - -type AddServiceContract struct { - ServiceContract -} - -type ServiceContract struct { - ClientId int `json:"clientId"` - Number string `json:"number"` - MemberId int `json:"memberId"` - ContactId int `json:"contactId"` - SaleChanceId int `json:"saleChanceId"` - ContractId int `json:"contractId"` - QuotationId int `json:"quotationId"` - TypeId int `json:"typeId"` - SignTime string `json:"signTime"` - StartTime string `json:"startTime"` - EndTime string `json:"endTime"` - StatusId int `json:"statusId"` - ServiceTimes int `json:"serviceTimes"` - Terms string `json:"terms"` - Remark string `json:"remark"` - Products []model.Product `json:"products"` -} - -type UpdateServiceContract struct { - Id int `json:"id"` - ServiceContract -} - -type GetServiceContractList struct { - PageInfo - QueryClass constvar.ServiceContractQueryClass `json:"queryClass"` - KeywordType constvar.ServiceContractKeywordType `json:"keywordType"` - Keyword string `json:"keyword"` -} - -type DeleteserviceContract struct { - Ids []int `json:"ids"` -} +package request + +import ( + "aps_crm/constvar" + "aps_crm/model" +) + +type AddServiceContract struct { + ServiceContract +} + +type ServiceContract struct { + ClientId int `json:"clientId"` + Number string `json:"number"` + MemberId int `json:"memberId"` + ContactId int `json:"contactId"` + SaleChanceId int `json:"saleChanceId"` + SalesDetailsId int `json:"salesDetailsId"` + QuotationId int `json:"quotationId"` + TypeId int `json:"typeId"` + SignTime string `json:"signTime" binding:"datetime=2006-01-02"` + StartTime string `json:"startTime" binding:"datetime=2006-01-02"` + EndTime string `json:"endTime" binding:"datetime=2006-01-02"` + StatusId int `json:"statusId"` + ServiceTimes int `json:"serviceTimes"` + Terms string `json:"terms"` + Remark string `json:"remark"` + Products []model.Product `json:"products"` +} + +type UpdateServiceContract struct { + Id int `json:"id"` + ServiceContract +} + +type GetServiceContractList struct { + PageInfo + QueryClass constvar.ServiceContractQueryClass `json:"queryClass"` + KeywordType constvar.ServiceContractKeywordType `json:"keywordType"` + Keyword string `json:"keyword"` +} + +type DeleteServiceContract struct { + Ids []int `json:"ids"` +} diff --git a/model/serviceContract.go b/model/serviceContract.go index ef16fbe..22dac27 100644 --- a/model/serviceContract.go +++ b/model/serviceContract.go @@ -24,9 +24,9 @@ Quotation Quotation `json:"quotation" gorm:"foreignKey:QuotationId"` ServiceContractTypeId int `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:鍚堝悓绫诲瀷id"` ServiceContractType ServiceContractType `json:"serviceContractType" gorm:"foreignKey:ServiceContractTypeId"` - SignTime time.Time `json:"signTime" gorm:"column:sign_time;type:datetime;comment:绛剧害鏃堕棿"` - StartTime time.Time `json:"startTime" gorm:"column:start_time;type:datetime;comment:寮�濮嬫椂闂�"` - EndTime time.Time `json:"endTime" gorm:"column:end_time;type:datetime;comment:缁撴潫鏃堕棿"` + SignTime string `json:"signTime" gorm:"column:sign_time;type:datetime;comment:绛剧害鏃堕棿"` + StartTime string `json:"startTime" gorm:"column:start_time;type:datetime;comment:寮�濮嬫椂闂�"` + EndTime string `json:"endTime" gorm:"column:end_time;type:datetime;comment:缁撴潫鏃堕棿"` ServiceContractStatusId int `json:"serviceContractStatusId" gorm:"column:service_contract_status_id;type:int;comment:鍚堝悓鐘舵�乮d"` ServiceContractStatus ServiceContractStatus `json:"serviceContractStatus" gorm:"foreignKey:ServiceContractStatusId"` ServiceTimes int `json:"serviceTimes" gorm:"column:service_times;type:int;comment:鏈嶅姟娆℃暟"` diff --git a/pkg/contextx/contextx.go b/pkg/contextx/contextx.go index 95a29c6..77a9b64 100644 --- a/pkg/contextx/contextx.go +++ b/pkg/contextx/contextx.go @@ -1,101 +1,102 @@ -package contextx - -import ( - "aps_crm/pkg/ecode" - "aps_crm/pkg/logx" - "github.com/gin-gonic/gin" - "net/http" -) - -type ( - Context struct { - ctx *gin.Context - paramsMap map[string]interface{} - } - - Response struct { - Code int `json:"code"` - Data interface{} `json:"data"` - Msg string `json:"msg"` - } -) - -func NewContext(ctx *gin.Context, params interface{}) (r *Context, isAllow bool) { - r = &Context{ - ctx: ctx, - } - if r.ctx.Request.Method == "OPTIONS" { - r.ctx.String(http.StatusOK, "") - return - } - - defer func() { - query := r.ctx.Request.URL.RawQuery - if query != "" { - query = "?" + query - } - urlPath := r.ctx.Request.URL.Path - logx.Infof("%s | %s %s | uid: %s | %+v", ctx.ClientIP(), r.ctx.Request.Method, urlPath+query, r.GetUserId(), params) - }() - - // validate params - if params != nil { - if err := r.ctx.ShouldBind(params); err != nil { - r.Fail(ecode.ParamsErr) - return - } - } - isAllow = true - return -} - -func (slf *Context) GetRequestPath() (r string) { - r = slf.ctx.Request.URL.Path - return -} - -func (slf *Context) GetUserId() (r string) { - v := slf.paramsMap["userId"] - switch v.(type) { - case string: - r = v.(string) - } - return -} - -func (slf *Context) Result(code int, data interface{}, msg string) { - slf.ctx.JSON(http.StatusOK, Response{ - Code: code, - Data: data, - Msg: msg, - }) -} - -func (slf *Context) Ok() { - slf.Result(ecode.OK, map[string]interface{}{}, "") -} - -func (slf *Context) OkWithDetailed(data interface{}) { - slf.Result(ecode.OK, data, "") -} - -func (slf *Context) Fail(errCode int) { - slf.Result(errCode, map[string]interface{}{}, ecode.GetMsg(errCode)) -} - -func (slf *Context) FailWithMsg(errCode int, msg string) { - slf.Result(errCode, map[string]interface{}{}, msg) -} - -func (slf *Context) FailWithDetailed(errCode int, data interface{}) { - slf.Result(errCode, data, ecode.GetMsg(errCode)) -} - -func (slf *Context) GetCtx() *gin.Context { - return slf.ctx -} - -func (slf *Context) SetCtx(c *gin.Context) *Context { - slf.ctx = c - return slf -} +package contextx + +import ( + "aps_crm/pkg/ecode" + "aps_crm/pkg/logx" + "github.com/gin-gonic/gin" + "net/http" +) + +type ( + Context struct { + ctx *gin.Context + paramsMap map[string]interface{} + } + + Response struct { + Code int `json:"code"` + Data interface{} `json:"data"` + Msg string `json:"msg"` + } +) + +func NewContext(ctx *gin.Context, params interface{}) (r *Context, isAllow bool) { + r = &Context{ + ctx: ctx, + } + if r.ctx.Request.Method == "OPTIONS" { + r.ctx.String(http.StatusOK, "") + return + } + + defer func() { + query := r.ctx.Request.URL.RawQuery + if query != "" { + query = "?" + query + } + urlPath := r.ctx.Request.URL.Path + logx.Infof("%s | %s %s | uid: %s | %+v", ctx.ClientIP(), r.ctx.Request.Method, urlPath+query, r.GetUserId(), params) + }() + + // validate params + if params != nil { + if err := r.ctx.ShouldBind(params); err != nil { + logx.Errorf("bind param error: %v", err.Error()) + r.Fail(ecode.ParamsErr) + return + } + } + isAllow = true + return +} + +func (slf *Context) GetRequestPath() (r string) { + r = slf.ctx.Request.URL.Path + return +} + +func (slf *Context) GetUserId() (r string) { + v := slf.paramsMap["userId"] + switch v.(type) { + case string: + r = v.(string) + } + return +} + +func (slf *Context) Result(code int, data interface{}, msg string) { + slf.ctx.JSON(http.StatusOK, Response{ + Code: code, + Data: data, + Msg: msg, + }) +} + +func (slf *Context) Ok() { + slf.Result(ecode.OK, map[string]interface{}{}, "") +} + +func (slf *Context) OkWithDetailed(data interface{}) { + slf.Result(ecode.OK, data, "") +} + +func (slf *Context) Fail(errCode int) { + slf.Result(errCode, map[string]interface{}{}, ecode.GetMsg(errCode)) +} + +func (slf *Context) FailWithMsg(errCode int, msg string) { + slf.Result(errCode, map[string]interface{}{}, msg) +} + +func (slf *Context) FailWithDetailed(errCode int, data interface{}) { + slf.Result(errCode, data, ecode.GetMsg(errCode)) +} + +func (slf *Context) GetCtx() *gin.Context { + return slf.ctx +} + +func (slf *Context) SetCtx(c *gin.Context) *Context { + slf.ctx = c + return slf +} -- Gitblit v1.8.0