123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- package controller
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "iot_manager_service/app/middleware"
- "iot_manager_service/app/warn/model"
- "iot_manager_service/app/warn/service"
- "iot_manager_service/util/common"
- "math"
- "net/http"
- "strconv"
- )
- var NoticeSet = new(noticeSetCtl)
- type noticeSetCtl struct {
- }
- func (c noticeSetCtl) List(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- current, _ := strconv.Atoi(ctx.Query("current"))
- size, _ := strconv.Atoi(ctx.Query("size"))
- searchValue := ctx.Query("searchValue")
- if current == 0 {
- current = 1
- }
- if size <= 0 || size > 100 {
- size = 10
- }
- records, err := service.NoticeSetService.GetList(claims.TenantId, searchValue)
- if err != nil {
- ctx.JSON(http.StatusBadRequest, err)
- return
- }
- pages := math.Ceil(float64(len(records)) / float64(size))
- rsp := model.ResposeNoticeSetRecords{
- Current: current,
- Size: size,
- Total: len(records),
- Pages: int(pages),
- Records: records,
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
- }
- func (c noticeSetCtl) GetUserList(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.NoticeSetService.UserList(account, realName, current, size)
- if err != nil {
- ctx.JSON(http.StatusBadRequest, err)
- return
- }
- fmt.Printf("users = %v", users)
- userN := `
- {"code":200,"success":true,"msg":"操作成功","data":[{"id":"10","tenantId":100000,"code":"13","account":"huangxz","password":"4b51712f9748dbba080ed1d8dac9a7d24abb24c2","name":"huang","realName":"黄小柱","avatar":"","email":"38612744@qq.com","phone":"13787020473","birthday":"1981-04-24T12:00:00+08:00","sex":1,"roleId":1,"createUser":1432148790919352321,"createDept":1263036048201457666,"createTime":"2022-03-14T08:52:27+08:00","updateUser":1123598821738675201,"updateTime":"2022-04-28T11:24:30+08:00","status":1,"isDeleted":0,"groupId":1,"bigScreenIndexCameraIds":"","securitySixScreen":"85,-1,-1,-1,86,-1","tenantName":"平江县智慧路灯","roleName":"超级管理员","sexName":"男"},{"id":"11","tenantId":100000,"code":"13","account":"test","password":"4b51712f9748dbba080ed1d8dac9a7d24abb24c2","name":"test","realName":"测试","avatar":"","email":"38612744@qq.com","phone":"13787020473","birthday":"","sex":0,"roleId":1,"createUser":1432148790919352321,"createDept":1263036048201457666,"createTime":"2022-03-14T08:52:27+08:00","updateUser":0,"updateTime":"2022-04-28T11:24:30+08:00","status":1,"isDeleted":0,"groupId":1,"bigScreenIndexCameraIds":"","securitySixScreen":"","tenantName":"平江县智慧路灯","roleName":"超级管理员","sexName":""}]}
- `
- ctx.String(200, userN)
- //ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, users))
- }
- func (c noticeSetCtl) Detail(ctx *gin.Context) {
- id := ctx.Query("id")
- data, err := service.NoticeSetService.GetById(id)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, data))
- }
- func (c noticeSetCtl) Update(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- post := model.NoticeUpdateData{}
- err := ctx.ShouldBindJSON(&post)
- if err != nil {
- ctx.JSON(http.StatusBadRequest, err)
- return
- }
- //fmt.Printf("post = %v", post)
- err = service.NoticeSetService.Update(post, claims.TenantId)
- if err != nil {
- ctx.JSON(http.StatusBadRequest, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
- }
- func (c noticeSetCtl) Remove(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- id := ctx.Query("ids")
- err := service.NoticeSetService.Remove(id, claims.TenantId)
- if err != nil {
- ctx.JSON(http.StatusBadRequest, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
- }
|