package test import ( "github.com/gin-gonic/gin" "github.com/spf13/cast" "srm/constvar" "srm/model/common/response" "srm/model/test/request" "srm/pkg/contextx" "srm/pkg/logx" "srm/proto/code" "srm/service" purchaseService "srm/service/purchase" "srm/utils" ) type CodeApi struct { } var ( supplierService = service.ServiceGroupApp.TestServiceGroup.SupplierService ) // GetCodeList // // @Tags 编码 // @Summary 获取编码列表 // @Produce application/json // @Param object query request.GetCodeList true "参数" // @Success 200 {object} response.Response{data=[]code.CodeStandard} // // @Router /code/getCodeList [get] func (ca *CodeApi) GetCodeList(c *gin.Context) { var params request.GetCodeList ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } params.CodeStandID = c.Query("codeStandID") params.Name = c.Query("name") params.Type = c.Query("type") client := code.NewCodeServiceClient(productServiceConn) list, err := client.GetCodeList(ctx.GetCtx(), &code.GetCodeListRequest{ Page: cast.ToInt32(params.Page), PageSize: cast.ToInt32(params.PageSize), CodeStandID: params.CodeStandID, Name: params.Name, Type: params.Type, }) if err != nil { logx.Errorf("GetCodeList err: %v", err.Error()) response.FailWithMessage("产品名称不能为空", c) return } response.OkWithDetailed(response.PageResult{ List: list.List, Total: list.Total, Page: params.Page, PageSize: params.PageSize, }, "获取成功", c) } // GetAutoCode // // @Tags 编码 // @Summary 获取自动编码 // @Produce application/json // @Param object body code.CodeStandard true "参数" // @Success 200 {object} response.Response{data=map[string]interface{}} // // @Router /code/getAutoCode [post] func (ca *CodeApi) GetAutoCode(c *gin.Context) { var params code.CodeStandard ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } var ( id = 0 err error ) switch constvar.CodeStandardType(params.Type) { case constvar.CodeStandardType_PurchaseOrder: id, err = purchaseService.NewPurchaseService().MaxAutoIncr() case constvar.CodeStandardType_Supplier: id, err = supplierService.MaxAutoIncr() default: response.FailWithMessage("编码规则不存在", c) return } if err != nil { response.FailWithMessage("获取最大值失败", c) return } m := make(map[string]interface{}) autoCode := utils.GetAutoCode(id, ¶ms) m["id"] = autoCode m["codeStandardID"] = params.ID m["maxAutoIncr"] = id + 1 ctx.OkWithDetailed(m) }