Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
nizhengjia888
gin-vue-admin
提交
23535cf4
G
gin-vue-admin
项目概览
nizhengjia888
/
gin-vue-admin
与 Fork 源项目一致
Fork自
FLIPPED-AURORA / gin-vue-admin
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
23535cf4
编写于
11月 07, 2020
作者:
m0_50812349
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化server/api/v1/exa_customer.go的代码及备注错误
上级
eaedb37f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
37 addition
and
60 deletion
+37
-60
server/api/v1/exa_customer.go
server/api/v1/exa_customer.go
+27
-49
server/api/v1/sys_user.go
server/api/v1/sys_user.go
+10
-11
未找到文件。
server/api/v1/exa_customer.go
浏览文件 @
23535cf4
...
...
@@ -11,13 +11,13 @@ import (
"github.com/gin-gonic/gin"
)
// @Tags
SysApi
// @Tags
ExaCustomer
// @Summary 创建客户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "
创建客户
"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"
获取
成功"}"
// @Param data body model.ExaCustomer true "
客户用户名, 客户手机号码
"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"
创建
成功"}"
// @Router /customer/customer [post]
func
CreateExaCustomer
(
c
*
gin
.
Context
)
{
var
cu
model
.
ExaCustomer
...
...
@@ -26,66 +26,53 @@ func CreateExaCustomer(c *gin.Context) {
"CustomerName"
:
{
utils
.
NotEmpty
()},
"CustomerPhoneData"
:
{
utils
.
NotEmpty
()},
}
CustomerVerifyErr
:=
utils
.
Verify
(
cu
,
CustomerVerify
)
if
CustomerVerifyErr
!=
nil
{
if
CustomerVerifyErr
:=
utils
.
Verify
(
cu
,
CustomerVerify
);
CustomerVerifyErr
!=
nil
{
response
.
FailWithMessage
(
CustomerVerifyErr
.
Error
(),
c
)
return
}
claims
,
_
:=
c
.
Get
(
"claims"
)
waitUse
:=
claims
.
(
*
request
.
CustomClaims
)
cu
.
SysUserID
=
waitUse
.
ID
cu
.
SysUserAuthorityID
=
waitUse
.
AuthorityId
err
:=
service
.
CreateExaCustomer
(
cu
)
if
err
!=
nil
{
cu
.
SysUserID
=
getUserID
(
c
)
cu
.
SysUserAuthorityID
=
getUserAuthorityId
(
c
)
if
err
:=
service
.
CreateExaCustomer
(
cu
);
err
!=
nil
{
response
.
FailWithMessage
(
fmt
.
Sprintf
(
"删除失败:%v"
,
err
),
c
)
}
else
{
response
.
OkWithMessage
(
"创建成功"
,
c
)
}
}
// @Tags
SysApi
// @Tags
ExaCustomer
// @Summary 删除客户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "
删除客户
"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"
获取
成功"}"
// @Param data body model.ExaCustomer true "
客户ID
"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"
删除
成功"}"
// @Router /customer/customer [delete]
func
DeleteExaCustomer
(
c
*
gin
.
Context
)
{
var
cu
model
.
ExaCustomer
_
=
c
.
ShouldBindJSON
(
&
cu
)
CustomerVerify
:=
utils
.
Rules
{
"ID"
:
{
utils
.
NotEmpty
()},
}
CustomerVerifyErr
:=
utils
.
Verify
(
cu
.
GVA_MODEL
,
CustomerVerify
)
if
CustomerVerifyErr
!=
nil
{
if
CustomerVerifyErr
:=
utils
.
Verify
(
cu
.
GVA_MODEL
,
utils
.
Rules
{
"ID"
:
{
utils
.
NotEmpty
()}});
CustomerVerifyErr
!=
nil
{
response
.
FailWithMessage
(
CustomerVerifyErr
.
Error
(),
c
)
return
}
err
:=
service
.
DeleteExaCustomer
(
cu
)
if
err
!=
nil
{
if
err
:=
service
.
DeleteExaCustomer
(
cu
);
err
!=
nil
{
response
.
FailWithMessage
(
fmt
.
Sprintf
(
"删除失败:%v"
,
err
),
c
)
}
else
{
response
.
OkWithMessage
(
"删除成功"
,
c
)
}
}
// @Tags
SysApi
// @Tags
ExaCustomer
// @Summary 更新客户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "
创建客户
"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"
获取
成功"}"
// @Param data body model.ExaCustomer true "
客户ID, 客户信息
"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"
更新
成功"}"
// @Router /customer/customer [put]
func
UpdateExaCustomer
(
c
*
gin
.
Context
)
{
var
cu
model
.
ExaCustomer
_
=
c
.
ShouldBindJSON
(
&
cu
)
IdCustomerVerify
:=
utils
.
Rules
{
"ID"
:
{
utils
.
NotEmpty
()},
}
IdCustomerVerifyErr
:=
utils
.
Verify
(
cu
.
GVA_MODEL
,
IdCustomerVerify
)
if
IdCustomerVerifyErr
!=
nil
{
if
IdCustomerVerifyErr
:=
utils
.
Verify
(
cu
.
GVA_MODEL
,
utils
.
Rules
{
"ID"
:
{
utils
.
NotEmpty
()}});
IdCustomerVerifyErr
!=
nil
{
response
.
FailWithMessage
(
IdCustomerVerifyErr
.
Error
(),
c
)
return
}
...
...
@@ -93,35 +80,29 @@ func UpdateExaCustomer(c *gin.Context) {
"CustomerName"
:
{
utils
.
NotEmpty
()},
"CustomerPhoneData"
:
{
utils
.
NotEmpty
()},
}
CustomerVerifyErr
:=
utils
.
Verify
(
cu
,
CustomerVerify
)
if
CustomerVerifyErr
!=
nil
{
if
CustomerVerifyErr
:=
utils
.
Verify
(
cu
,
CustomerVerify
);
CustomerVerifyErr
!=
nil
{
response
.
FailWithMessage
(
CustomerVerifyErr
.
Error
(),
c
)
return
}
err
:=
service
.
UpdateExaCustomer
(
&
cu
)
if
err
!=
nil
{
if
err
:=
service
.
UpdateExaCustomer
(
&
cu
);
err
!=
nil
{
response
.
FailWithMessage
(
fmt
.
Sprintf
(
"更新失败:%v"
,
err
),
c
)
}
else
{
response
.
OkWithMessage
(
"更新成功"
,
c
)
}
}
// @Tags
SysApi
// @Tags
ExaCustomer
// @Summary 获取单一客户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "
获取单一客户信息
"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"
获取
成功"}"
// @Param data body model.ExaCustomer true "
客户ID
"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"
操作
成功"}"
// @Router /customer/customer [get]
func
GetExaCustomer
(
c
*
gin
.
Context
)
{
var
cu
model
.
ExaCustomer
_
=
c
.
ShouldBindQuery
(
&
cu
)
IdCustomerVerify
:=
utils
.
Rules
{
"ID"
:
{
utils
.
NotEmpty
()},
}
IdCustomerVerifyErr
:=
utils
.
Verify
(
cu
.
GVA_MODEL
,
IdCustomerVerify
)
if
IdCustomerVerifyErr
!=
nil
{
if
IdCustomerVerifyErr
:=
utils
.
Verify
(
cu
.
GVA_MODEL
,
utils
.
Rules
{
"ID"
:
{
utils
.
NotEmpty
()}});
IdCustomerVerifyErr
!=
nil
{
response
.
FailWithMessage
(
IdCustomerVerifyErr
.
Error
(),
c
)
return
}
...
...
@@ -133,25 +114,22 @@ func GetExaCustomer(c *gin.Context) {
}
}
// @Tags
SysApi
// @Tags
ExaCustomer
// @Summary 获取权限客户列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "
获取权限客户列表
"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"
获取
成功"}"
// @Param data body request.PageInfo true "
页码, 每页大小
"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"
操作
成功"}"
// @Router /customer/customerList [get]
func
GetExaCustomerList
(
c
*
gin
.
Context
)
{
claims
,
_
:=
c
.
Get
(
"claims"
)
waitUse
:=
claims
.
(
*
request
.
CustomClaims
)
var
pageInfo
request
.
PageInfo
_
=
c
.
ShouldBindQuery
(
&
pageInfo
)
PageVerifyErr
:=
utils
.
Verify
(
pageInfo
,
utils
.
CustomizeMap
[
"PageVerify"
])
if
PageVerifyErr
!=
nil
{
if
PageVerifyErr
:=
utils
.
Verify
(
pageInfo
,
utils
.
CustomizeMap
[
"PageVerify"
]);
PageVerifyErr
!=
nil
{
response
.
FailWithMessage
(
PageVerifyErr
.
Error
(),
c
)
return
}
err
,
customerList
,
total
:=
service
.
GetCustomerInfoList
(
waitUse
.
AuthorityId
,
pageInfo
)
err
,
customerList
,
total
:=
service
.
GetCustomerInfoList
(
getUserAuthorityId
(
c
)
,
pageInfo
)
if
err
!=
nil
{
response
.
FailWithMessage
(
fmt
.
Sprintf
(
"获取失败:%v"
,
err
),
c
)
}
else
{
...
...
server/api/v1/sys_user.go
浏览文件 @
23535cf4
package
v1
import
(
"errors"
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/global/response"
...
...
@@ -169,7 +168,7 @@ func ChangePassword(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "页码, 页大小"
// @Param data body request.PageInfo true "页码,
每
页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /user/getUserList [post]
func
GetUserList
(
c
*
gin
.
Context
)
{
...
...
@@ -274,34 +273,34 @@ func SetUserInfo(c *gin.Context) {
}
// 从Gin的Context中获取从jwt解析出来的用户ID
func
getUserID
(
c
*
gin
.
Context
)
(
uint
,
error
)
{
func
getUserID
(
c
*
gin
.
Context
)
uint
{
if
claims
,
exists
:=
c
.
Get
(
"claims"
);
!
exists
{
global
.
GVA_LOG
.
Error
(
"从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件"
)
return
0
,
errors
.
New
(
"解析失败"
)
return
0
}
else
{
waitUse
:=
claims
.
(
*
request
.
CustomClaims
)
return
waitUse
.
ID
,
nil
return
waitUse
.
ID
}
}
// 从Gin的Context中获取从jwt解析出来的用户UUID
func
getUserUuid
(
c
*
gin
.
Context
)
(
string
,
error
)
{
func
getUserUuid
(
c
*
gin
.
Context
)
string
{
if
claims
,
exists
:=
c
.
Get
(
"claims"
);
!
exists
{
global
.
GVA_LOG
.
Error
(
"从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件"
)
return
""
,
errors
.
New
(
"解析失败"
)
return
""
}
else
{
waitUse
:=
claims
.
(
*
request
.
CustomClaims
)
return
waitUse
.
UUID
.
String
()
,
nil
return
waitUse
.
UUID
.
String
()
}
}
// 从Gin的Context中获取从jwt解析出来的用户角色id
func
getUserAuthorityId
(
c
*
gin
.
Context
)
(
string
,
error
)
{
func
getUserAuthorityId
(
c
*
gin
.
Context
)
string
{
if
claims
,
exists
:=
c
.
Get
(
"claims"
);
!
exists
{
global
.
GVA_LOG
.
Error
(
"从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件"
)
return
""
,
errors
.
New
(
"解析失败"
)
return
""
}
else
{
waitUse
:=
claims
.
(
*
request
.
CustomClaims
)
return
waitUse
.
AuthorityId
,
nil
return
waitUse
.
AuthorityId
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录