exa_customer.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package example
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "go.uber.org/zap"
  5. "server/global"
  6. "server/model/common/request"
  7. "server/model/common/response"
  8. "server/model/example"
  9. exampleRes "server/model/example/response"
  10. "server/utils"
  11. )
  12. type CustomerApi struct{}
  13. // CreateExaCustomer
  14. // @Tags ExaCustomer
  15. // @Summary 创建客户
  16. // @Security ApiKeyAuth
  17. // @accept application/json
  18. // @Produce application/json
  19. // @Param data body example.ExaCustomer true "客户用户名, 客户手机号码"
  20. // @Success 200 {object} response.Response{msg=string} "创建客户"
  21. // @Router /customer/customer [post]
  22. func (e *CustomerApi) CreateExaCustomer(c *gin.Context) {
  23. var customer example.ExaCustomer
  24. err := c.ShouldBindJSON(&customer)
  25. if err != nil {
  26. response.FailWithMessage(err.Error(), c)
  27. return
  28. }
  29. err = utils.Verify(customer, utils.CustomerVerify)
  30. if err != nil {
  31. response.FailWithMessage(err.Error(), c)
  32. return
  33. }
  34. customer.SysUserID = utils.GetUserID(c)
  35. customer.SysUserAuthorityID = utils.GetUserAuthorityId(c)
  36. err = customerService.CreateExaCustomer(customer)
  37. if err != nil {
  38. global.GVA_LOG.Error("创建失败!", zap.Error(err))
  39. response.FailWithMessage("创建失败", c)
  40. return
  41. }
  42. response.OkWithMessage("创建成功", c)
  43. }
  44. // DeleteExaCustomer
  45. // @Tags ExaCustomer
  46. // @Summary 删除客户
  47. // @Security ApiKeyAuth
  48. // @accept application/json
  49. // @Produce application/json
  50. // @Param data body example.ExaCustomer true "客户ID"
  51. // @Success 200 {object} response.Response{msg=string} "删除客户"
  52. // @Router /customer/customer [delete]
  53. func (e *CustomerApi) DeleteExaCustomer(c *gin.Context) {
  54. var customer example.ExaCustomer
  55. err := c.ShouldBindJSON(&customer)
  56. if err != nil {
  57. response.FailWithMessage(err.Error(), c)
  58. return
  59. }
  60. err = utils.Verify(customer.GVA_MODEL, utils.IdVerify)
  61. if err != nil {
  62. response.FailWithMessage(err.Error(), c)
  63. return
  64. }
  65. err = customerService.DeleteExaCustomer(customer)
  66. if err != nil {
  67. global.GVA_LOG.Error("删除失败!", zap.Error(err))
  68. response.FailWithMessage("删除失败", c)
  69. return
  70. }
  71. response.OkWithMessage("删除成功", c)
  72. }
  73. // UpdateExaCustomer
  74. // @Tags ExaCustomer
  75. // @Summary 更新客户信息
  76. // @Security ApiKeyAuth
  77. // @accept application/json
  78. // @Produce application/json
  79. // @Param data body example.ExaCustomer true "客户ID, 客户信息"
  80. // @Success 200 {object} response.Response{msg=string} "更新客户信息"
  81. // @Router /customer/customer [put]
  82. func (e *CustomerApi) UpdateExaCustomer(c *gin.Context) {
  83. var customer example.ExaCustomer
  84. err := c.ShouldBindJSON(&customer)
  85. if err != nil {
  86. response.FailWithMessage(err.Error(), c)
  87. return
  88. }
  89. err = utils.Verify(customer.GVA_MODEL, utils.IdVerify)
  90. if err != nil {
  91. response.FailWithMessage(err.Error(), c)
  92. return
  93. }
  94. err = utils.Verify(customer, utils.CustomerVerify)
  95. if err != nil {
  96. response.FailWithMessage(err.Error(), c)
  97. return
  98. }
  99. err = customerService.UpdateExaCustomer(&customer)
  100. if err != nil {
  101. global.GVA_LOG.Error("更新失败!", zap.Error(err))
  102. response.FailWithMessage("更新失败", c)
  103. return
  104. }
  105. response.OkWithMessage("更新成功", c)
  106. }
  107. // GetExaCustomer
  108. // @Tags ExaCustomer
  109. // @Summary 获取单一客户信息
  110. // @Security ApiKeyAuth
  111. // @accept application/json
  112. // @Produce application/json
  113. // @Param data query example.ExaCustomer true "客户ID"
  114. // @Success 200 {object} response.Response{data=exampleRes.ExaCustomerResponse,msg=string} "获取单一客户信息,返回包括客户详情"
  115. // @Router /customer/customer [get]
  116. func (e *CustomerApi) GetExaCustomer(c *gin.Context) {
  117. var customer example.ExaCustomer
  118. err := c.ShouldBindQuery(&customer)
  119. if err != nil {
  120. response.FailWithMessage(err.Error(), c)
  121. return
  122. }
  123. err = utils.Verify(customer.GVA_MODEL, utils.IdVerify)
  124. if err != nil {
  125. response.FailWithMessage(err.Error(), c)
  126. return
  127. }
  128. data, err := customerService.GetExaCustomer(customer.ID)
  129. if err != nil {
  130. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  131. response.FailWithMessage("获取失败", c)
  132. return
  133. }
  134. response.OkWithDetailed(exampleRes.ExaCustomerResponse{Customer: data}, "获取成功", c)
  135. }
  136. // GetExaCustomerList
  137. // @Tags ExaCustomer
  138. // @Summary 分页获取权限客户列表
  139. // @Security ApiKeyAuth
  140. // @accept application/json
  141. // @Produce application/json
  142. // @Param data query request.PageInfo true "页码, 每页大小"
  143. // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取权限客户列表,返回包括列表,总数,页码,每页数量"
  144. // @Router /customer/customerList [get]
  145. func (e *CustomerApi) GetExaCustomerList(c *gin.Context) {
  146. var pageInfo request.PageInfo
  147. err := c.ShouldBindQuery(&pageInfo)
  148. if err != nil {
  149. response.FailWithMessage(err.Error(), c)
  150. return
  151. }
  152. err = utils.Verify(pageInfo, utils.PageInfoVerify)
  153. if err != nil {
  154. response.FailWithMessage(err.Error(), c)
  155. return
  156. }
  157. customerList, total, err := customerService.GetCustomerInfoList(utils.GetUserAuthorityId(c), pageInfo)
  158. if err != nil {
  159. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  160. response.FailWithMessage("获取失败"+err.Error(), c)
  161. return
  162. }
  163. response.OkWithDetailed(response.PageResult{
  164. List: customerList,
  165. Total: total,
  166. Page: pageInfo.Page,
  167. PageSize: pageInfo.PageSize,
  168. }, "获取成功", c)
  169. }