1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
package apis
import (
"github.com/gin-gonic/gin/binding"
sService "go-admin/app/admin/service"
sDto "go-admin/app/admin/service/dto"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/operate/service"
"go-admin/app/operate/service/dto"
"go-admin/common/actions"
)
type OrgUser struct {
api.Api
}
// GetPage <赛事>人员管理列表
// @Summary <赛事>人员管理列表
// @Description 获取JSON
// @Tags <赛事>人员管理
// @Param data body dto.OrgUserGetPageReq true "data"
// @Success 200 {string} {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/org-user [get]
// @Security Bearer
func (e OrgUser) GetPage(c *gin.Context) {
s := service.OrgUser{}
req := dto.OrgUserGetPageReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
//数据权限检查
p := actions.GetPermissionFromContext(c)
list := make([]dto.OrgUserGetPageReply, 0)
var count int64
err = s.GetPage(&req, p, &list, &count)
if err != nil {
e.Error(500, err, "查询失败")
return
}
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
}
// Get <赛事>获取人员详情
// @Summary <赛事>获取人员详情
// @Description 获取JSON
// @Tags <赛事>人员管理
// @Param userId path int true "用户编码"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /api/v1/org-user/{userId} [get]
// @Security Bearer
func (e OrgUser) Get(c *gin.Context) {
s := service.OrgUser{}
req := dto.OrgUserGetReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req, nil).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
var object dto.OrgUserGetReply
//数据权限检查
p := actions.GetPermissionFromContext(c)
err = s.Get(&req, p, &object)
if err != nil {
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(object, "查询成功")
}
// Insert <赛事>创建人员
// @Summary <赛事>创建人员
// @Description 获取JSON
// @Tags <赛事>人员管理
// @Accept application/json
// @Product application/json
// @Param data body dto.OrgUserInsertReq true "用户数据"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /api/v1/org-user [post]
// @Security Bearer
func (e OrgUser) Insert(c *gin.Context) {
s := service.OrgUser{}
req := dto.OrgUserInsertReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
sSysUser := sService.SysUser{}
reqSysUser := sDto.SysUserInsertReq{}
e.MakeContext(c).MakeOrm().MakeService(&sSysUser.Service)
reqSysUser.Username = req.Username
reqSysUser.Password = "123456"
reqSysUser.NickName = req.NickName
reqSysUser.NickNameEn = req.NickNameEn
reqSysUser.Phone = req.Username
reqSysUser.RoleId, _ = strconv.Atoi(req.RoleId)
reqSysUser.Avatar = ""
reqSysUser.Sex = "0"
reqSysUser.Email = ""
reqSysUser.DeptId = 1
reqSysUser.PostId = 1
reqSysUser.Remark = "赛事"
reqSysUser.Status = "2"
reqSysUser.UserType = "2"
// 设置创建人
reqSysUser.SetCreateBy(user.GetUserId(c))
err = sSysUser.Insert(&reqSysUser)
if err != nil {
e.Logger.Error(err)
e.Error(111, err, err.Error())
return
}
e.OK(req.GetId(), "创建成功")
}
// Update <赛事>修改人员数据
// @Summary <赛事>修改人员数据
// @Description 获取JSON
// @Tags <赛事>人员管理
// @Accept application/json
// @Product application/json
// @Param data body dto.OrgUserUpdateReq true "body"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /api/v1/org-user/{userId} [put]
// @Security Bearer
func (e OrgUser) Update(c *gin.Context) {
s := service.OrgUser{}
req := dto.OrgUserUpdateReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
_, isBing := s.IsBing(strconv.Itoa(req.UserId), req.Username)
if isBing > 0 {
e.Error(111, err, "账户已存在!请更换")
return
}
req.SetUpdateBy(user.GetUserId(c))
//数据权限检查
p := actions.GetPermissionFromContext(c)
err = s.Update(&req, p)
if err != nil {
e.Logger.Error(err)
return
}
e.OK(req.GetId(), "更新成功")
}
// Delete <赛事>删除人员数据
// @Summary <赛事>删除人员数据
// @Description 删除数据
// @Tags <赛事>人员管理
// @Param userId path int true "userId"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /api/v1/org-user/{userId} [delete]
// @Security Bearer
func (e OrgUser) Delete(c *gin.Context) {
s := service.OrgUser{}
req := dto.OrgUserDeleteReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
// 设置编辑人
//req. = user.GetUserId(c))
// 数据权限检查
p := actions.GetPermissionFromContext(c)
err = s.Remove(&req, p)
if err != nil {
e.Logger.Error(err)
return
}
e.OK(req.GetId(), "删除成功")
}
// UpdateStatus <赛事>修改人员状态
// @Summary <赛事>修改人员状态
// @Description 获取JSON
// @Tags <赛事>人员管理
// @Accept application/json
// @Product application/json
// @Param data body dto.OrgUserUpdateStatusReq true "body"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /api/v1/org-user/status [put]
// @Security Bearer
func (e OrgUser) UpdateStatus(c *gin.Context) {
s := service.OrgUser{}
req := dto.OrgUserUpdateStatusReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON, nil).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
//数据权限检查
p := actions.GetPermissionFromContext(c)
reqUpdate := dto.OrgUserUpdateReq{}
reqUpdate.UserId = req.UserId
reqUpdate.Status = req.Status
reqUpdate.UpdateBy = user.GetUserId(c)
err = s.Update(&reqUpdate, p)
if err != nil {
e.Logger.Error(err)
return
}
e.OK(1, "更新成功")
}
// ResetPwd <赛事>重置用户密码
// @Summary <赛事>重置用户密码
// @Description 获取JSON
// @Tags <赛事>人员管理
// @Accept application/json
// @Product application/json
// @Param data body dto.ResetSysUserPwdReq true "body"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /api/v1/org-user/pwd/reset [put]
// @Security Bearer
func (e OrgUser) ResetPwd(c *gin.Context) {
s := service.OrgUser{}
req := dto.ResetPwdReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
req.SetUpdateBy(user.GetUserId(c))
//数据权限检查
p := actions.GetPermissionFromContext(c)
reqUpdate := dto.OrgUserUpdateReq{}
reqUpdate.UserId = req.UserId
reqUpdate.Password = "123456"
reqUpdate.UpdateBy = user.GetUserId(c)
err = s.Update(&reqUpdate, p)
if err != nil {
e.Logger.Error(err)
return
}
e.OK("", "更新成功")
}