You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.5 KiB

  1. package v1
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global/response"
  5. "gin-vue-admin/model"
  6. "gin-vue-admin/model/request"
  7. resp "gin-vue-admin/model/response"
  8. "gin-vue-admin/service"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // @Tags SysApi
  12. // @Summary 创建客户
  13. // @Security ApiKeyAuth
  14. // @accept application/json
  15. // @Produce application/json
  16. // @Param data body model.ExaCustomer true "创建客户"
  17. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  18. // @Router /customer/customer [post]
  19. func CreateExaCustomer(c *gin.Context) {
  20. var cu model.ExaCustomer
  21. _ = c.ShouldBindJSON(&cu)
  22. claims, _ := c.Get("claims")
  23. waitUse := claims.(*request.CustomClaims)
  24. cu.SysUserID = waitUse.ID
  25. cu.SysUserAuthorityID = waitUse.AuthorityId
  26. err := service.CreateExaCustomer(cu)
  27. if err != nil {
  28. response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
  29. } else {
  30. response.OkWithMessage("创建成功", c)
  31. }
  32. }
  33. // @Tags SysApi
  34. // @Summary 删除客户
  35. // @Security ApiKeyAuth
  36. // @accept application/json
  37. // @Produce application/json
  38. // @Param data body model.ExaCustomer true "删除客户"
  39. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  40. // @Router /customer/customer [delete]
  41. func DeleteExaCustomer(c *gin.Context) {
  42. var cu model.ExaCustomer
  43. _ = c.ShouldBindJSON(&cu)
  44. err := service.DeleteExaCustomer(cu)
  45. if err != nil {
  46. response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
  47. } else {
  48. response.OkWithMessage("删除成功", c)
  49. }
  50. }
  51. // @Tags SysApi
  52. // @Summary 更新客户信息
  53. // @Security ApiKeyAuth
  54. // @accept application/json
  55. // @Produce application/json
  56. // @Param data body model.ExaCustomer true "创建客户"
  57. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  58. // @Router /customer/customer [put]
  59. func UpdateExaCustomer(c *gin.Context) {
  60. var cu model.ExaCustomer
  61. _ = c.ShouldBindJSON(&cu)
  62. err := service.UpdateExaCustomer(&cu)
  63. if err != nil {
  64. response.FailWithMessage(fmt.Sprintf("更新失败:%v", err), c)
  65. } else {
  66. response.OkWithMessage("更新成功", c)
  67. }
  68. }
  69. // @Tags SysApi
  70. // @Summary 获取单一客户信息
  71. // @Security ApiKeyAuth
  72. // @accept application/json
  73. // @Produce application/json
  74. // @Param data body model.ExaCustomer true "获取单一客户信息"
  75. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  76. // @Router /customer/customer [get]
  77. func GetExaCustomer(c *gin.Context) {
  78. var cu model.ExaCustomer
  79. _ = c.ShouldBindQuery(&cu)
  80. err, customer := service.GetExaCustomer(cu.ID)
  81. if err != nil {
  82. response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
  83. } else {
  84. response.OkWithData(resp.ExaCustomerResponse{Customer: customer}, c)
  85. }
  86. }
  87. // @Tags SysApi
  88. // @Summary 获取权限客户列表
  89. // @Security ApiKeyAuth
  90. // @accept application/json
  91. // @Produce application/json
  92. // @Param data body request.PageInfo true "获取权限客户列表"
  93. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  94. // @Router /customer/customerList [get]
  95. func GetExaCustomerList(c *gin.Context) {
  96. claims, _ := c.Get("claims")
  97. waitUse := claims.(*request.CustomClaims)
  98. var pageInfo request.PageInfo
  99. _ = c.ShouldBindQuery(&pageInfo)
  100. err, customerList, total := service.GetCustomerInfoList(waitUse.AuthorityId, pageInfo)
  101. if err != nil {
  102. response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
  103. } else {
  104. response.OkWithData(resp.PageResult{
  105. List: customerList,
  106. Total: total,
  107. Page: pageInfo.Page,
  108. PageSize: pageInfo.PageSize,
  109. }, c)
  110. }
  111. }