product_code.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package controllers
  2. import (
  3. "Medical_ERP/common/actions"
  4. "Medical_ERP/common/global"
  5. _ "Medical_ERP/common/response"
  6. "Medical_ERP/conf"
  7. "Medical_ERP/dto"
  8. "Medical_ERP/models"
  9. "Medical_ERP/services"
  10. "encoding/json"
  11. "errors"
  12. "github.com/go-resty/resty/v2"
  13. "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser"
  14. )
  15. type ProductCodeController struct {
  16. BaseController
  17. }
  18. // Gen 生成条码
  19. // @Summary 生成条码
  20. // @Description 生成条码
  21. // @Tags 产品条码
  22. // @Param body body dto.BarcodePageReq true "body"
  23. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  24. // @Router /sales/list [post]
  25. // @Security Bearer
  26. func (c ProductCodeController) Gen() {
  27. s := services.ProductCode{}
  28. reqData := dto.GenProductCodePageReq{}
  29. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  30. err = errors.New("解析表单数据异常")
  31. c.Error(global.ParseFormErr, err, err.Error())
  32. return
  33. }
  34. deptId := beegouser.GetDeptId(c.Ctx)
  35. err := s.CreateProductCode(&reqData, deptId)
  36. if err != nil {
  37. c.Error(500, err, err.Error())
  38. return
  39. }
  40. client := resty.New()
  41. resp, err := client.R().
  42. SetBody(map[string]interface{}{
  43. "product_name": reqData.Product,
  44. "enterprise_name": reqData.Enterprise,
  45. "spec_name": reqData.Spec,
  46. "batch_number": reqData.BatchNumber,
  47. "quantity": reqData.Quantity,
  48. }).
  49. Post(conf.BZD_pcodeUrl)
  50. if err != nil {
  51. c.Error(400, err, err.Error())
  52. return
  53. }
  54. type Resp struct {
  55. Code int `json:"Code"`
  56. Msg string `json:"Msg"`
  57. Data string `json:"Data"`
  58. }
  59. var res Resp
  60. if err = json.Unmarshal(resp.Body(), &res); err != nil {
  61. c.Error(400, err, err.Error())
  62. return
  63. }
  64. if res.Code != 200 {
  65. err = errors.New(res.Msg)
  66. c.Error(400, err, err.Error())
  67. }
  68. c.OK(res.Data, "生成成功")
  69. }
  70. // List 通过关键字查询条码信息
  71. // @Summary 生成条码
  72. // @Description 生成条码
  73. // @Tags 产品条码
  74. // @Param body body dto.BarcodePageReq true "body"
  75. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  76. // @Router /sales/list [post]
  77. // @Security Bearer
  78. func (c ProductCodeController) List() {
  79. s := services.ProductCode{}
  80. reqData := dto.ProductCodePageReq{}
  81. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  82. err = errors.New("解析表单数据异常")
  83. c.Error(global.ParseFormErr, err, err.Error())
  84. return
  85. }
  86. list := make([]models.ProductCode, 0)
  87. var count int64
  88. //数据权限检查
  89. p := actions.GetPermissionFromContext(c.Ctx)
  90. err := s.GetPage(&reqData, &list, &count, p)
  91. if err != nil {
  92. c.Error(global.BadRequest, err, err.Error())
  93. return
  94. }
  95. c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
  96. }