medicine_img.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package controllers
  2. import (
  3. "Medical_ERP/common/actions"
  4. "Medical_ERP/common/global"
  5. "Medical_ERP/dto"
  6. "Medical_ERP/models"
  7. "Medical_ERP/services"
  8. "errors"
  9. context2 "github.com/beego/beego/v2/adapter/context"
  10. "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser"
  11. "strings"
  12. )
  13. type MedicineImgController struct {
  14. BaseController
  15. }
  16. // List 获取规格列表
  17. // @Summary 获取规格列表
  18. // @Description 获取规格列表
  19. // @Tags 规格
  20. // @Param body body dto.MedicineImgPageReq true "body"
  21. // @Success 200 {object} response.Page{list=[]models.MedicineImg} "{"code": 200, "data": [...]}"
  22. // @Router /spec/list [post]
  23. // @Security Bearer
  24. func (c MedicineImgController) List() {
  25. s := services.MedicineImg{}
  26. reqData := dto.MedicineImgPageReq{}
  27. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  28. err = errors.New("解析表单数据异常")
  29. c.Error(global.ParseFormErr, err, err.Error())
  30. return
  31. }
  32. p := actions.GetPermissionFromContext(c.Ctx)
  33. rootId, err := s.GetRootID((*context2.Context)(c.Ctx), p.DeptId)
  34. if err != nil {
  35. c.Error(global.BadRequest, err, err.Error())
  36. return
  37. }
  38. list := make([]models.MedicineImg, 0)
  39. var count int64
  40. //数据权限检查
  41. err = s.GetPage(&reqData, &list, &count, rootId, p)
  42. if err != nil {
  43. c.Error(global.BadRequest, err, err.Error())
  44. return
  45. }
  46. for i := 0; i < len(list); i++ {
  47. arr := strings.Split(strings.Trim(list[i].Img, ","), ",")
  48. if len(arr) > 0 {
  49. list[i].ImgUrl = arr[0]
  50. }
  51. list[i].SrcList = arr
  52. }
  53. c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
  54. }
  55. // Edit 修改规格
  56. // @Summary 修改规格
  57. // @Description 修改规格
  58. // @Tags 规格
  59. // @Accept application/json
  60. // @MedicineImg application/json
  61. // @Param data body dto.MedicineImgUpdateReq true "body"
  62. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  63. // @Router /spec/edit [post]
  64. // @Security Bearer
  65. func (c MedicineImgController) Edit() {
  66. s := services.MedicineImg{}
  67. reqData := dto.MedicineImgUpdateReq{}
  68. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  69. err = errors.New("解析表单数据异常")
  70. c.Error(global.ParseFormErr, err, err.Error())
  71. return
  72. }
  73. reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
  74. err := s.Update(&reqData)
  75. if err != nil {
  76. c.Error(500, err, err.Error())
  77. return
  78. }
  79. c.OK(reqData.GetId(), "更新成功")
  80. }