1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "iot_manager_service/app/system/dao"
- "iot_manager_service/app/system/model"
- "iot_manager_service/app/system/service"
- "iot_manager_service/util"
- "math"
- "net/http"
- "strconv"
- )
- var User = new(user)
- type user struct{}
- func (c *user) GetDetail(ctx *gin.Context) {
- id := ctx.Query("id")
- iId, err := strconv.ParseInt(id, 10, 64)
- if err != nil {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- detail, err := service.UserService.Get(iId)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail))
- }
- func (c *user) List(ctx *gin.Context) {
- current, _ := strconv.Atoi(ctx.Query("current"))
- size, _ := strconv.Atoi(ctx.Query("size"))
- account := ctx.Query("account")
- realName := ctx.Query("realName")
- if current == 0 {
- current = 1
- }
- if size <= 0 || size > 100 {
- size = 10
- }
- users, err := service.UserService.List(account, realName, current, size)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- pages := math.Ceil(float64(len(users)) / float64(size))
- rsp := model.RsqUserList{
- Current: current,
- Size: size,
- Total: len(users),
- Pages: int(pages),
- Records: users,
- }
- ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
- }
- func (c *user) Submit(ctx *gin.Context) {
- var req dao.User
- if err := ctx.ShouldBindJSON(&req); err != nil {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- err := service.UserService.Submit(req)
- ctx.JSON(http.StatusOK, err)
- }
- func (c *user) Update(ctx *gin.Context) {
- var req dao.User
- if err := ctx.ShouldBindJSON(&req); err != nil {
- ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- err := service.UserService.Update(req)
- ctx.JSON(http.StatusOK, err)
- }
- func (c *user) Remove(ctx *gin.Context) {
- id, _ := strconv.ParseInt(ctx.Query("id"), 10, 64)
- err := service.UserService.Remove(id)
- ctx.JSON(http.StatusOK, err)
- }
|