12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "iot_manager_service/app/dao"
- "iot_manager_service/app/model"
- "iot_manager_service/app/service"
- "iot_manager_service/app/utils"
- "math"
- "net/http"
- "strconv"
- )
- // 一键报警终端表管理对象
- var AlarmTerminal = new(alarmTerminalCtl)
- type alarmTerminalCtl struct{}
- func (c *alarmTerminalCtl) Detail(ctx *gin.Context) {
- id, e := strconv.Atoi(ctx.Query("id"))
- if e != nil {
- ctx.JSON(http.StatusOK, utils.ParamsInvalidResponse(e.Error(), nil))
- return
- }
- device, err := service.AlarmTerminalService.Get(id)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, utils.SuccessResponse(utils.Succeeded, device))
- }
- func (c *alarmTerminalCtl) List(ctx *gin.Context) {
- searchValue := ctx.Query("searchValue")
- current, _ := strconv.Atoi(ctx.Query("current"))
- size, _ := strconv.Atoi(ctx.Query("size"))
- if current == 0 {
- current = 1
- }
- if size <= 0 || size > 100 {
- size = 10
- }
- devices, err := service.AlarmTerminalService.List(searchValue, current, size)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- pages := math.Ceil(float64(len(devices)) / float64(size))
- rsp := model.RsqAlarmTerminalList{
- Current: current,
- Size: size,
- Total: len(devices),
- Pages: int(pages),
- }
- for _, device := range devices {
- rsp.Records = append(rsp.Records, device)
- }
- ctx.JSON(http.StatusOK, utils.SuccessResponse(utils.Succeeded, rsp))
- }
- func (c *alarmTerminalCtl) CreateOrUpdate(ctx *gin.Context) {
- var req dao.AlarmTerminal
- if err := ctx.ShouldBindJSON(&req); err != nil {
- ctx.JSON(http.StatusOK, utils.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- err := service.AlarmTerminalService.CreateOrUpdate(req)
- ctx.JSON(http.StatusOK, err)
- }
- func (c *alarmTerminalCtl) Remove(ctx *gin.Context) {
- var req *model.ReqAlarmTerminalRemove
- if err := ctx.ShouldBindJSON(&req); err != nil {
- ctx.JSON(http.StatusOK, utils.ParamsInvalidResponse(err.Error(), nil))
- return
- }
- err := service.AlarmTerminalService.Remove(req.IDs)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, utils.SuccessResponse(utils.Succeeded, nil))
- }
- func (c *alarmTerminalCtl) ImportExcel(ctx *gin.Context) {
- }
- func (c *alarmTerminalCtl) ExportExcel(ctx *gin.Context) {
- }
- func (c *alarmTerminalCtl) ExportTemplate(ctx *gin.Context) {
- }
|