hpds_jkw_web/internal/handler/disease.go

138 lines
4.9 KiB
Go
Raw Permalink 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
}
2023-06-17 09:38:26 +08:00
if req.Pid < 0 {
req.Pid = 0
}
data, err = repo.DiseaseListNew(c, req)
2023-03-23 18:03:09 +08:00
go s.SaveLog("获取病害库列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
2023-06-17 09:38:26 +08:00
func (s HandlerService) DiseaseStatistics(c *gin.Context) (data interface{}, err error) {
repo := service.NewDiseaseService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
var (
userInfo *model.SystemUser
ok bool
)
if userInfo, ok = us.(*model.SystemUser); !ok {
go s.SaveLog("DiseaseList", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.DiseaseStatistics(c)
go s.SaveLog("获取标注库统计信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) CreateTrainDatasetByDisease(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.TrainDatasetRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("CreateTrainDatasetByDisease", "Manage", "", "", ToString(req), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
req.UserId = userInfo.UserId
data, err = repo.CreateTrainDatasetByDisease(c, req)
go s.SaveLog("创建训练数据集", "Training", "", "", "", 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
}