@@ -2,13 +2,14 @@ package v1
22
33import (
44 "fmt"
5- "gin-vue-admin/global/response "
5+ "gin-vue-admin/global"
66 "gin-vue-admin/model"
77 "gin-vue-admin/model/request"
8- resp "gin-vue-admin/model/response"
8+ "gin-vue-admin/model/response"
99 "gin-vue-admin/service"
1010 "gin-vue-admin/utils"
1111 "github.com/gin-gonic/gin"
12+ "go.uber.org/zap"
1213)
1314
1415// @Tags ExaCustomer
@@ -20,20 +21,17 @@ import (
2021// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
2122// @Router /customer/customer [post]
2223func CreateExaCustomer (c * gin.Context ) {
23- var cu model.ExaCustomer
24- _ = c .ShouldBindJSON (& cu )
25- CustomerVerify := utils.Rules {
26- "CustomerName" : {utils .NotEmpty ()},
27- "CustomerPhoneData" : {utils .NotEmpty ()},
28- }
29- if CustomerVerifyErr := utils .Verify (cu , CustomerVerify ); CustomerVerifyErr != nil {
30- response .FailWithMessage (CustomerVerifyErr .Error (), c )
24+ var customer model.ExaCustomer
25+ _ = c .ShouldBindJSON (& customer )
26+ if err := utils .Verify (customer , utils .CustomerVerify ); err != nil {
27+ response .FailWithMessage (err .Error (), c )
3128 return
3229 }
33- cu .SysUserID = getUserID (c )
34- cu .SysUserAuthorityID = getUserAuthorityId (c )
35- if err := service .CreateExaCustomer (cu ); err != nil {
36- response .FailWithMessage (fmt .Sprintf ("删除失败:%v" , err ), c )
30+ customer .SysUserID = getUserID (c )
31+ customer .SysUserAuthorityID = getUserAuthorityId (c )
32+ if err := service .CreateExaCustomer (customer ); err != nil {
33+ global .GVA_LOG .Error ("创建失败!" , zap .Any ("err" , err ))
34+ response .FailWithMessage ("创建失败" , c )
3735 } else {
3836 response .OkWithMessage ("创建成功" , c )
3937 }
@@ -48,14 +46,15 @@ func CreateExaCustomer(c *gin.Context) {
4846// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
4947// @Router /customer/customer [delete]
5048func DeleteExaCustomer (c * gin.Context ) {
51- var cu model.ExaCustomer
52- _ = c .ShouldBindJSON (& cu )
53- if CustomerVerifyErr := utils .Verify (cu .GVA_MODEL , utils.Rules { "ID" : { utils . NotEmpty ()}}); CustomerVerifyErr != nil {
54- response .FailWithMessage (CustomerVerifyErr .Error (), c )
49+ var customer model.ExaCustomer
50+ _ = c .ShouldBindJSON (& customer )
51+ if err := utils .Verify (customer .GVA_MODEL , utils .IdVerify ); err != nil {
52+ response .FailWithMessage (err .Error (), c )
5553 return
5654 }
57- if err := service .DeleteExaCustomer (cu ); err != nil {
58- response .FailWithMessage (fmt .Sprintf ("删除失败:%v" , err ), c )
55+ if err := service .DeleteExaCustomer (customer ); err != nil {
56+ global .GVA_LOG .Error ("删除失败!" , zap .Any ("err" , err ))
57+ response .FailWithMessage ("删除失败" , c )
5958 } else {
6059 response .OkWithMessage ("删除成功" , c )
6160 }
@@ -70,22 +69,19 @@ func DeleteExaCustomer(c *gin.Context) {
7069// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
7170// @Router /customer/customer [put]
7271func UpdateExaCustomer (c * gin.Context ) {
73- var cu model.ExaCustomer
74- _ = c .ShouldBindJSON (& cu )
75- if IdCustomerVerifyErr := utils .Verify (cu .GVA_MODEL , utils.Rules { "ID" : { utils . NotEmpty ()}}); IdCustomerVerifyErr != nil {
76- response .FailWithMessage (IdCustomerVerifyErr .Error (), c )
72+ var customer model.ExaCustomer
73+ _ = c .ShouldBindJSON (& customer )
74+ if err := utils .Verify (customer .GVA_MODEL , utils .IdVerify ); err != nil {
75+ response .FailWithMessage (err .Error (), c )
7776 return
7877 }
79- CustomerVerify := utils.Rules {
80- "CustomerName" : {utils .NotEmpty ()},
81- "CustomerPhoneData" : {utils .NotEmpty ()},
82- }
83- if CustomerVerifyErr := utils .Verify (cu , CustomerVerify ); CustomerVerifyErr != nil {
84- response .FailWithMessage (CustomerVerifyErr .Error (), c )
78+ if err := utils .Verify (customer , utils .CustomerVerify ); err != nil {
79+ response .FailWithMessage (err .Error (), c )
8580 return
8681 }
87- if err := service .UpdateExaCustomer (& cu ); err != nil {
88- response .FailWithMessage (fmt .Sprintf ("更新失败:%v" , err ), c )
82+ if err := service .UpdateExaCustomer (& customer ); err != nil {
83+ global .GVA_LOG .Error ("更新失败!" , zap .Any ("err" , err ))
84+ response .FailWithMessage ("更新失败!" , c )
8985 } else {
9086 response .OkWithMessage ("更新成功" , c )
9187 }
@@ -97,47 +93,49 @@ func UpdateExaCustomer(c *gin.Context) {
9793// @accept application/json
9894// @Produce application/json
9995// @Param data body model.ExaCustomer true "客户ID"
100- // @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功 "}"
96+ // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功 "}"
10197// @Router /customer/customer [get]
10298func GetExaCustomer (c * gin.Context ) {
103- var cu model.ExaCustomer
104- _ = c .ShouldBindQuery (& cu )
105- if IdCustomerVerifyErr := utils .Verify (cu .GVA_MODEL , utils.Rules { "ID" : { utils . NotEmpty ()}}); IdCustomerVerifyErr != nil {
106- response .FailWithMessage (IdCustomerVerifyErr .Error (), c )
99+ var customer model.ExaCustomer
100+ _ = c .ShouldBindQuery (& customer )
101+ if err := utils .Verify (customer .GVA_MODEL , utils .IdVerify ); err != nil {
102+ response .FailWithMessage (err .Error (), c )
107103 return
108104 }
109- err , customer := service .GetExaCustomer (cu .ID )
105+ err , data := service .GetExaCustomer (customer .ID )
110106 if err != nil {
111- response .FailWithMessage (fmt .Sprintf ("获取失败:%v" , err ), c )
107+ global .GVA_LOG .Error ("获取失败!" , zap .Any ("err" , err ))
108+ response .FailWithMessage ("获取失败" , c )
112109 } else {
113- response .OkWithData (resp .ExaCustomerResponse {Customer : customer } , c )
110+ response .OkWithDetailed (response .ExaCustomerResponse {Customer : data }, "获取成功" , c )
114111 }
115112}
116113
117114// @Tags ExaCustomer
118- // @Summary 获取权限客户列表
115+ // @Summary 分页获取权限客户列表
119116// @Security ApiKeyAuth
120117// @accept application/json
121118// @Produce application/json
122119// @Param data body request.PageInfo true "页码, 每页大小"
123- // @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功 "}"
120+ // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功 "}"
124121// @Router /customer/customerList [get]
125122func GetExaCustomerList (c * gin.Context ) {
126123 var pageInfo request.PageInfo
127124 _ = c .ShouldBindQuery (& pageInfo )
128- if PageVerifyErr := utils .Verify (pageInfo , utils .CustomizeMap [ "PageVerify" ] ); PageVerifyErr != nil {
129- response .FailWithMessage (PageVerifyErr .Error (), c )
125+ if err := utils .Verify (pageInfo , utils .PageInfoVerify ); err != nil {
126+ response .FailWithMessage (err .Error (), c )
130127 return
131128 }
132129 err , customerList , total := service .GetCustomerInfoList (getUserAuthorityId (c ), pageInfo )
133130 if err != nil {
131+ global .GVA_LOG .Error ("获取失败!" , zap .Any ("err" , err ))
134132 response .FailWithMessage (fmt .Sprintf ("获取失败:%v" , err ), c )
135133 } else {
136- response .OkWithData (resp .PageResult {
134+ response .OkWithDetailed (response .PageResult {
137135 List : customerList ,
138136 Total : total ,
139137 Page : pageInfo .Page ,
140138 PageSize : pageInfo .PageSize ,
141- }, c )
139+ }, "获取成功" , c )
142140 }
143141}
0 commit comments