| | |
| | | package v1 |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/model/response" |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | ) |
| | | |
| | | type ContractApi struct{} |
| | | |
| | | // Add |
| | | // |
| | | // @Tags Contract |
| | | // @Summary 添加合同 |
| | | // @Produce application/json |
| | | // @Param object body request.AddContract true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/contract/add [post] |
| | | func (s *ContractApi) Add(c *gin.Context) { |
| | | var params request.AddContract |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode, contract := checkContractParams(params.Contract) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | errCode = contractService.AddContract(&contract) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags Contract |
| | | // @Summary 删除合同 |
| | | // @Produce application/json |
| | | // @Param id path int true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/contract/delete/{id} [delete] |
| | | func (s *ContractApi) Delete(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | errCode := contractService.DeleteContract(id) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Update |
| | | // |
| | | // @Tags Contract |
| | | // @Summary 更新合同 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateContract true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/contract/update [put] |
| | | func (s *ContractApi) Update(c *gin.Context) { |
| | | var params request.UpdateContract |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode, contract := checkContractParams(params.Contract) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | errCode = contractService.UpdateContract(&contract) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags Contract |
| | | // @Summary 获取合同列表 |
| | | // @Produce application/json |
| | | // @Success 200 {object} contextx.Response{data=response.ContractResponse} |
| | | // @Router /api/contract/list [get] |
| | | func (s *ContractApi) List(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | contractList, errCode := contractService.GetContractList() |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.ContractResponse{ |
| | | List: contractList, |
| | | }) |
| | | } |
| | | |
| | | func checkContractParams(contract request.Contract) (errCode int, contractModel model.Contract) { |
| | | if contract.Number == "" { |
| | | return ecode.InvalidParams, contractModel |
| | | } |
| | | |
| | | if contract.MemberId == 0 { |
| | | return ecode.InvalidParams, contractModel |
| | | } |
| | | |
| | | contractModel = model.Contract{ |
| | | ClientId: contract.ClientId, |
| | | MemberId: contract.MemberId, |
| | | Number: contract.Number, |
| | | QuotationId: contract.QuotationId, |
| | | StatusId: contract.StatusId, |
| | | File: contract.File, |
| | | } |
| | | |
| | | return ecode.OK, contractModel |
| | | } |