package controllers import ( "Medical_ERP/common/actions" "Medical_ERP/common/global" "Medical_ERP/dto" "Medical_ERP/models" "Medical_ERP/services" "errors" context2 "github.com/beego/beego/v2/adapter/context" "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser" "strings" ) type MedicineImgController struct { BaseController } // List 获取规格列表 // @Summary 获取规格列表 // @Description 获取规格列表 // @Tags 规格 // @Param body body dto.MedicineImgPageReq true "body" // @Success 200 {object} response.Page{list=[]models.MedicineImg} "{"code": 200, "data": [...]}" // @Router /spec/list [post] // @Security Bearer func (c MedicineImgController) List() { s := services.MedicineImg{} reqData := dto.MedicineImgPageReq{} if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil { err = errors.New("解析表单数据异常") c.Error(global.ParseFormErr, err, err.Error()) return } p := actions.GetPermissionFromContext(c.Ctx) rootId, err := s.GetRootID((*context2.Context)(c.Ctx), p.DeptId) if err != nil { c.Error(global.BadRequest, err, err.Error()) return } list := make([]models.MedicineImg, 0) var count int64 //数据权限检查 err = s.GetPage(&reqData, &list, &count, rootId, p) if err != nil { c.Error(global.BadRequest, err, err.Error()) return } for i := 0; i < len(list); i++ { arr := strings.Split(strings.Trim(list[i].Img, ","), ",") if len(arr) > 0 { list[i].ImgUrl = arr[0] } list[i].SrcList = arr } c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功") } // Edit 修改规格 // @Summary 修改规格 // @Description 修改规格 // @Tags 规格 // @Accept application/json // @MedicineImg application/json // @Param data body dto.MedicineImgUpdateReq true "body" // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /spec/edit [post] // @Security Bearer func (c MedicineImgController) Edit() { s := services.MedicineImg{} reqData := dto.MedicineImgUpdateReq{} if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil { err = errors.New("解析表单数据异常") c.Error(global.ParseFormErr, err, err.Error()) return } reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx)) err := s.Update(&reqData) if err != nil { c.Error(500, err, err.Error()) return } c.OK(reqData.GetId(), "更新成功") }