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.

120 lines
3.7 KiB

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