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.

119 lines
3.7 KiB

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