hpds_jkw_web/internal/handler/disease.go

103 lines
3.5 KiB
Go
Raw Normal View History

2023-01-12 10:21:40 +08:00
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"
)
2023-03-23 18:03:09 +08:00
func (s HandlerService) DiseaseList(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.DiseaseRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("DiseaseList", "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.DiseaseList(c, req)
go s.SaveLog("获取病害库列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
2023-01-12 10:21:40 +08:00
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
}