79 lines
2.8 KiB
Go
79 lines
2.8 KiB
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"hpds-iot-web/internal/proto"
|
|
"hpds-iot-web/internal/service"
|
|
"hpds-iot-web/model"
|
|
e "hpds-iot-web/pkg/err"
|
|
)
|
|
|
|
func (s HandlerService) DiseaseTypeList(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewDiseaseService(s.AppConfig, s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.DiseaseTypeRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("DiseaseTypeList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
if req.Size < 1 {
|
|
req.Size = 20
|
|
}
|
|
if req.Size > 1000 {
|
|
req.Size = 1000
|
|
}
|
|
if req.Page < 1 {
|
|
req.Page = 1
|
|
}
|
|
data, err = repo.DiseaseTypeList(c, req)
|
|
go s.SaveLog("获取病害类型列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) AddDiseaseType(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewDiseaseService(s.AppConfig, s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.DiseaseTypeItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("AddDiseaseType", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.AddDiseaseType(c, req)
|
|
go s.SaveLog("新增病害类型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
func (s HandlerService) EditDiseaseType(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewDiseaseService(s.AppConfig, s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.DiseaseTypeItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("AddDiseaseType", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.EditDiseaseType(c, req)
|
|
go s.SaveLog("修改病害类型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) DeleteDiseaseType(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewDiseaseService(s.AppConfig, s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.DiseaseTypeItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("AddDiseaseType", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.DeleteDiseaseType(c, req)
|
|
go s.SaveLog("删除病害类型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|