spec.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package controllers
  2. import (
  3. "Medical_ERP/common/actions"
  4. "Medical_ERP/common/global"
  5. _ "Medical_ERP/common/response"
  6. "Medical_ERP/dto"
  7. "Medical_ERP/models"
  8. "Medical_ERP/services"
  9. "errors"
  10. "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser"
  11. )
  12. type SpecController struct {
  13. BaseController
  14. }
  15. // List 获取规格列表
  16. // @Summary 获取规格列表
  17. // @Description 获取规格列表
  18. // @Tags 规格
  19. // @Param body body dto.SpecPageReq true "body"
  20. // @Success 200 {object} response.Page{list=[]models.Spec} "{"code": 200, "data": [...]}"
  21. // @Router /spec/list [post]
  22. // @Security Bearer
  23. func (c SpecController) List() {
  24. s := services.Spec{}
  25. reqData := dto.SpecPageReq{}
  26. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  27. err = errors.New("解析表单数据异常")
  28. c.Error(global.ParseFormErr, err, err.Error())
  29. return
  30. }
  31. list := make([]models.Spec, 0)
  32. var count int64
  33. //数据权限检查
  34. p := actions.GetPermissionFromContext(c.Ctx)
  35. err := s.GetPage(&reqData, &list, &count, p)
  36. if err != nil {
  37. c.Error(global.BadRequest, err, err.Error())
  38. return
  39. }
  40. c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
  41. }
  42. // Detail 通过id获取规格
  43. // @Summary 通过id获取规格
  44. // @Description 通过id获取规格
  45. // @Tags 规格
  46. // @Param body body dto.SpecGetReq true "body"
  47. // @Success 200 {object} response.Response{data=models.Spec} "{"code": 200, "data": [...]}"
  48. // @Router /spec/detail [post]
  49. // @Security Bearer
  50. func (c SpecController) Detail() {
  51. s := services.Spec{}
  52. reqData := dto.SpecGetReq{}
  53. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  54. err = errors.New("解析表单数据异常")
  55. c.Error(global.ParseFormErr, err, err.Error())
  56. return
  57. }
  58. var object models.Spec
  59. //数据权限检查
  60. p := actions.GetPermissionFromContext(c.Ctx)
  61. err := s.Get(&reqData, &object, p)
  62. if err != nil {
  63. c.Error(500, err, err.Error())
  64. return
  65. }
  66. c.OK(object, "查询成功")
  67. }
  68. // Add 添加规格
  69. // @Summary 添加规格
  70. // @Description 添加规格
  71. // @Tags 规格
  72. // @Accept application/json
  73. // @Spec application/json
  74. // @Param data body dto.SpecInsertReq true "data"
  75. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  76. // @Router /spec/add [post]
  77. // @Security Bearer
  78. func (c SpecController) Add() {
  79. s := services.Spec{}
  80. reqData := dto.SpecInsertReq{}
  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. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  87. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  88. err := s.Insert(&reqData)
  89. if err != nil {
  90. c.Error(500, err, err.Error())
  91. return
  92. }
  93. c.OK(reqData.GetId(), "创建成功")
  94. }
  95. // Edit 修改规格
  96. // @Summary 修改规格
  97. // @Description 修改规格
  98. // @Tags 规格
  99. // @Accept application/json
  100. // @Spec application/json
  101. // @Param data body dto.SpecUpdateReq true "body"
  102. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  103. // @Router /spec/edit [post]
  104. // @Security Bearer
  105. func (c SpecController) Edit() {
  106. s := services.Spec{}
  107. reqData := dto.SpecUpdateReq{}
  108. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  109. err = errors.New("解析表单数据异常")
  110. c.Error(global.ParseFormErr, err, err.Error())
  111. return
  112. }
  113. reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
  114. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  115. err := s.Update(&reqData)
  116. if err != nil {
  117. c.Error(500, err, err.Error())
  118. return
  119. }
  120. c.OK(reqData.GetId(), "更新成功")
  121. }
  122. // Delete 删除规格
  123. // @Summary 删除规格
  124. // @Description 删除规格
  125. // @Tags 规格
  126. // @Accept application/json
  127. // @Spec application/json
  128. // @Param id body dto.SpecDeleteReq true "请求参数"
  129. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  130. // @Router /spec/delete [post]
  131. // @Security Bearer
  132. func (c SpecController) Delete() {
  133. s := services.Spec{}
  134. reqData := dto.SpecDeleteReq{}
  135. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  136. err = errors.New("解析表单数据异常")
  137. c.Error(global.ParseFormErr, err, err.Error())
  138. return
  139. }
  140. reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
  141. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  142. err := s.Remove(&reqData)
  143. if err != nil {
  144. c.Error(500, err, err.Error())
  145. return
  146. }
  147. c.OK(reqData.GetId(), "删除成功")
  148. }