org_user.go 7.13 KB
Newer Older
haoyanbin's avatar
haoyanbin committed
1 2 3
package apis

import (
haoyanbin's avatar
haoyanbin committed
4
	"fmt"
haoyanbin's avatar
haoyanbin committed
5
	"github.com/gin-gonic/gin/binding"
haoyanbin's avatar
haoyanbin committed
6 7
	sService "go-admin/app/admin/service"
	sDto "go-admin/app/admin/service/dto"
haoyanbin's avatar
haoyanbin committed
8
	"net/http"
haoyanbin's avatar
haoyanbin committed
9
	"strconv"
haoyanbin's avatar
haoyanbin committed
10 11 12 13 14 15

	"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"

haoyanbin's avatar
1  
haoyanbin committed
16 17
	"go-admin/app/operate/service"
	"go-admin/app/operate/service/dto"
haoyanbin's avatar
haoyanbin committed
18 19 20
	"go-admin/common/actions"
)

haoyanbin's avatar
1  
haoyanbin committed
21
type OrgUser struct {
haoyanbin's avatar
haoyanbin committed
22 23 24
	api.Api
}

haoyanbin's avatar
haoyanbin committed
25 26
// GetPage <赛事>人员管理列表
// @Summary <赛事>人员管理列表
haoyanbin's avatar
haoyanbin committed
27
// @Description 获取JSON
haoyanbin's avatar
haoyanbin committed
28
// @Tags <赛事>人员管理
haoyanbin's avatar
haoyanbin committed
29
// @Param data body dto.OrgUserGetPageReq true "data"
haoyanbin's avatar
haoyanbin committed
30
// @Success 200 {string} {object} response.Response "{"code": 200, "data": [...]}"
haoyanbin's avatar
1  
haoyanbin committed
31
// @Router /api/v1/org-user [get]
haoyanbin's avatar
haoyanbin committed
32
// @Security Bearer
haoyanbin's avatar
1  
haoyanbin committed
33
func (e OrgUser) GetPage(c *gin.Context) {
haoyanbin's avatar
1  
haoyanbin committed
34 35
	s := service.OrgUser{}
	req := dto.OrgUserGetPageReq{}
haoyanbin's avatar
haoyanbin committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49
	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)

haoyanbin's avatar
1  
haoyanbin committed
50
	list := make([]dto.OrgUserGetPageReply, 0)
haoyanbin's avatar
haoyanbin committed
51 52 53 54 55 56 57 58 59 60 61
	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(), "查询成功")
}

haoyanbin's avatar
haoyanbin committed
62 63
// Get <赛事>获取人员详情
// @Summary <赛事>获取人员详情
haoyanbin's avatar
haoyanbin committed
64
// @Description 获取JSON
haoyanbin's avatar
haoyanbin committed
65
// @Tags <赛事>人员管理
haoyanbin's avatar
haoyanbin committed
66 67
// @Param userId path int true "用户编码"
// @Success 200 {string} string   "{"code": 200, "data": [...]}"
haoyanbin's avatar
1  
haoyanbin committed
68
// @Router /api/v1/org-user/{userId} [get]
haoyanbin's avatar
haoyanbin committed
69
// @Security Bearer
haoyanbin's avatar
1  
haoyanbin committed
70
func (e OrgUser) Get(c *gin.Context) {
haoyanbin's avatar
1  
haoyanbin committed
71 72
	s := service.OrgUser{}
	req := dto.OrgUserGetReq{}
haoyanbin's avatar
haoyanbin committed
73 74 75 76 77 78 79 80 81 82
	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
	}
haoyanbin's avatar
1  
haoyanbin committed
83
	var object dto.OrgUserGetReply
haoyanbin's avatar
haoyanbin committed
84 85 86 87 88 89 90 91 92 93
	//数据权限检查
	p := actions.GetPermissionFromContext(c)
	err = s.Get(&req, p, &object)
	if err != nil {
		e.Error(http.StatusUnprocessableEntity, err, "查询失败")
		return
	}
	e.OK(object, "查询成功")
}

haoyanbin's avatar
haoyanbin committed
94 95
// Insert <赛事>创建人员
// @Summary <赛事>创建人员
haoyanbin's avatar
haoyanbin committed
96
// @Description 获取JSON
haoyanbin's avatar
haoyanbin committed
97
// @Tags <赛事>人员管理
haoyanbin's avatar
haoyanbin committed
98 99
// @Accept  application/json
// @Product application/json
haoyanbin's avatar
haoyanbin committed
100
// @Param data body dto.OrgUserInsertReq true "用户数据"
haoyanbin's avatar
haoyanbin committed
101
// @Success 200 {string} string   "{"code": 200, "data": [...]}"
haoyanbin's avatar
1  
haoyanbin committed
102
// @Router /api/v1/org-user [post]
haoyanbin's avatar
haoyanbin committed
103
// @Security Bearer
haoyanbin's avatar
1  
haoyanbin committed
104
func (e OrgUser) Insert(c *gin.Context) {
haoyanbin's avatar
1  
haoyanbin committed
105 106
	s := service.OrgUser{}
	req := dto.OrgUserInsertReq{}
haoyanbin's avatar
haoyanbin committed
107 108 109 110 111 112 113 114 115 116
	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
	}
haoyanbin's avatar
haoyanbin committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

	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"

haoyanbin's avatar
haoyanbin committed
136
	// 设置创建人
haoyanbin's avatar
haoyanbin committed
137 138
	reqSysUser.SetCreateBy(user.GetUserId(c))
	err = sSysUser.Insert(&reqSysUser)
haoyanbin's avatar
haoyanbin committed
139 140 141 142 143 144 145 146 147
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}

	e.OK(req.GetId(), "创建成功")
}

haoyanbin's avatar
haoyanbin committed
148 149
// Update <赛事>修改人员数据
// @Summary <赛事>修改人员数据
haoyanbin's avatar
haoyanbin committed
150
// @Description 获取JSON
haoyanbin's avatar
haoyanbin committed
151
// @Tags <赛事>人员管理
haoyanbin's avatar
haoyanbin committed
152 153
// @Accept  application/json
// @Product application/json
haoyanbin's avatar
haoyanbin committed
154
// @Param data body dto.OrgUserUpdateReq true "body"
haoyanbin's avatar
haoyanbin committed
155
// @Success 200 {string} string   "{"code": 200, "data": [...]}"
haoyanbin's avatar
1  
haoyanbin committed
156
// @Router /api/v1/org-user/{userId} [put]
haoyanbin's avatar
haoyanbin committed
157
// @Security Bearer
haoyanbin's avatar
1  
haoyanbin committed
158
func (e OrgUser) Update(c *gin.Context) {
haoyanbin's avatar
1  
haoyanbin committed
159 160
	s := service.OrgUser{}
	req := dto.OrgUserUpdateReq{}
haoyanbin's avatar
haoyanbin committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
	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
	}

	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(), "更新成功")
}

haoyanbin's avatar
haoyanbin committed
185 186
// Delete <赛事>删除人员数据
// @Summary <赛事>删除人员数据
haoyanbin's avatar
haoyanbin committed
187
// @Description 删除数据
haoyanbin's avatar
haoyanbin committed
188
// @Tags <赛事>人员管理
haoyanbin's avatar
haoyanbin committed
189 190
// @Param userId path int true "userId"
// @Success 200 {string} string   "{"code": 200, "data": [...]}"
haoyanbin's avatar
1  
haoyanbin committed
191
// @Router /api/v1/org-user/{userId} [delete]
haoyanbin's avatar
haoyanbin committed
192
// @Security Bearer
haoyanbin's avatar
1  
haoyanbin committed
193
func (e OrgUser) Delete(c *gin.Context) {
haoyanbin's avatar
1  
haoyanbin committed
194 195
	s := service.OrgUser{}
	req := dto.OrgUserDeleteReq{}
haoyanbin's avatar
haoyanbin committed
196 197 198 199 200 201 202 203 204 205 206 207
	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
	}

	// 设置编辑人
haoyanbin's avatar
haoyanbin committed
208
	//req. = user.GetUserId(c))
haoyanbin's avatar
haoyanbin committed
209 210 211 212 213 214 215 216 217 218 219 220

	// 数据权限检查
	p := actions.GetPermissionFromContext(c)

	err = s.Remove(&req, p)
	if err != nil {
		e.Logger.Error(err)
		return
	}
	e.OK(req.GetId(), "删除成功")
}

haoyanbin's avatar
haoyanbin committed
221 222
// UpdateStatus <赛事>修改人员状态
// @Summary <赛事>修改人员状态
haoyanbin's avatar
haoyanbin committed
223
// @Description 获取JSON
haoyanbin's avatar
haoyanbin committed
224
// @Tags <赛事>人员管理
haoyanbin's avatar
haoyanbin committed
225 226
// @Accept  application/json
// @Product application/json
haoyanbin's avatar
haoyanbin committed
227
// @Param data body dto.OrgUserUpdateStatusReq true "body"
haoyanbin's avatar
haoyanbin committed
228
// @Success 200 {string} string   "{"code": 200, "data": [...]}"
haoyanbin's avatar
1  
haoyanbin committed
229
// @Router /api/v1/org-user/status [put]
haoyanbin's avatar
haoyanbin committed
230
// @Security Bearer
haoyanbin's avatar
1  
haoyanbin committed
231
func (e OrgUser) UpdateStatus(c *gin.Context) {
haoyanbin's avatar
haoyanbin committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
	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{}
haoyanbin's avatar
haoyanbin committed
249
	reqUpdate.UserId = req.UserId
haoyanbin's avatar
haoyanbin committed
250
	reqUpdate.Status = req.Status
haoyanbin's avatar
haoyanbin committed
251 252
	reqUpdate.UpdateBy = user.GetUserId(c)

haoyanbin's avatar
haoyanbin committed
253 254 255 256 257 258
	err = s.Update(&reqUpdate, p)
	if err != nil {
		e.Logger.Error(err)
		return
	}
	e.OK(1, "更新成功")
haoyanbin's avatar
haoyanbin committed
259 260
}

haoyanbin's avatar
haoyanbin committed
261 262
// ResetPwd <赛事>重置用户密码
// @Summary <赛事>重置用户密码
haoyanbin's avatar
haoyanbin committed
263
// @Description 获取JSON
haoyanbin's avatar
haoyanbin committed
264
// @Tags <赛事>人员管理
haoyanbin's avatar
haoyanbin committed
265 266 267 268
// @Accept  application/json
// @Product application/json
// @Param data body dto.ResetSysUserPwdReq true "body"
// @Success 200 {string} string   "{"code": 200, "data": [...]}"
haoyanbin's avatar
1  
haoyanbin committed
269
// @Router /api/v1/org-user/pwd/reset [put]
haoyanbin's avatar
haoyanbin committed
270
// @Security Bearer
haoyanbin's avatar
1  
haoyanbin committed
271
func (e OrgUser) ResetPwd(c *gin.Context) {
haoyanbin's avatar
1  
haoyanbin committed
272
	//	s := service.OrgUser{}
haoyanbin's avatar
haoyanbin committed
273 274
	req := dto.ResetPwdReq{}
	fmt.Println(req)
haoyanbin's avatar
1  
haoyanbin committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
	//	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)
	//
	//	err = s.ResetPwd(&req, p)
	//	if err != nil {
	//		e.Logger.Error(err)
	//		return
	//	}
haoyanbin's avatar
haoyanbin committed
296
	e.OK("", "更新成功")
haoyanbin's avatar
haoyanbin committed
297
}