package controllers import ( "Medical_ERP/common/actions" "Medical_ERP/common/global" _ "Medical_ERP/common/response" "Medical_ERP/conf" "Medical_ERP/dto" "Medical_ERP/models" "Medical_ERP/services" "encoding/json" "errors" "github.com/go-resty/resty/v2" "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser" ) type ProductCodeController struct { BaseController } // Gen 生成条码 // @Summary 生成条码 // @Description 生成条码 // @Tags 产品条码 // @Param body body dto.BarcodePageReq true "body" // @Success 200 {object} response.Page "{"code": 200, "data": [...]}" // @Router /sales/list [post] // @Security Bearer func (c ProductCodeController) Gen() { s := services.ProductCode{} reqData := dto.GenProductCodePageReq{} if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil { err = errors.New("解析表单数据异常") c.Error(global.ParseFormErr, err, err.Error()) return } deptId := beegouser.GetDeptId(c.Ctx) err := s.CreateProductCode(&reqData, deptId) if err != nil { c.Error(500, err, err.Error()) return } client := resty.New() resp, err := client.R(). SetBody(map[string]interface{}{ "product_name": reqData.Product, "enterprise_name": reqData.Enterprise, "spec_name": reqData.Spec, "batch_number": reqData.BatchNumber, "quantity": reqData.Quantity, }). Post(conf.BZD_pcodeUrl) if err != nil { c.Error(400, err, err.Error()) return } type Resp struct { Code int `json:"Code"` Msg string `json:"Msg"` Data string `json:"Data"` } var res Resp if err = json.Unmarshal(resp.Body(), &res); err != nil { c.Error(400, err, err.Error()) return } if res.Code != 200 { err = errors.New(res.Msg) c.Error(400, err, err.Error()) } c.OK(res.Data, "生成成功") } // List 通过关键字查询条码信息 // @Summary 生成条码 // @Description 生成条码 // @Tags 产品条码 // @Param body body dto.BarcodePageReq true "body" // @Success 200 {object} response.Page "{"code": 200, "data": [...]}" // @Router /sales/list [post] // @Security Bearer func (c ProductCodeController) List() { s := services.ProductCode{} reqData := dto.ProductCodePageReq{} if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil { err = errors.New("解析表单数据异常") c.Error(global.ParseFormErr, err, err.Error()) return } list := make([]models.ProductCode, 0) var count int64 //数据权限检查 p := actions.GetPermissionFromContext(c.Ctx) err := s.GetPage(&reqData, &list, &count, p) if err != nil { c.Error(global.BadRequest, err, err.Error()) return } c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功") }