hpds_jkw_web/internal/handler/manage.go

781 lines
30 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"
"strconv"
)
func (s HandlerService) OwnerList(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.OwnerRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("OwnerList", "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 > 100 {
req.Size = 100
}
if req.Page < 1 {
req.Page = 1
}
data, err = repo.OwnerList(c, req)
go s.SaveLog("获取业主列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) OwnerInfo(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
//var req proto.OwnerItemReq
//err = c.ShouldBindJSON(&req)
id, err := strconv.ParseInt(c.Query("ownerId"), 10, 64)
if err != nil {
go s.SaveLog("OwnerInfo", "Manage", "", "", c.Request.URL.Path, fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.OwnerInfo(c, id)
go s.SaveLog("获取业主信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddOwner(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.OwnerItemReq
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddOwner", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
req.Creator = userInfo.UserId
data, err = repo.AddOwner(c, req)
go s.SaveLog("新增业主", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditOwner(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.OwnerItemReq
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EditOwner", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
req.Creator = userInfo.UserId
data, err = repo.EditOwner(c, req)
go s.SaveLog("修改业主", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DelOwner(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.OwnerItemReq
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("DelOwner", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
req.Creator = userInfo.UserId
data, err = repo.DelOwner(c, req)
go s.SaveLog("删除业主", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) ProjectList(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProjectRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("ProjectList", "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 > 100 {
req.Size = 100
}
if req.Page < 1 {
req.Page = 1
}
data, err = repo.ProjectList(c, req)
go s.SaveLog("获取项目列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) ProjectInfo(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProjectItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("ProjectInfo", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.ProjectInfo(c, req)
go s.SaveLog("获取项目信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddProject(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProjectItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddProject", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
req.Creator = userInfo.UserId
data, err = repo.AddProject(c, req)
go s.SaveLog("新增项目", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditProject(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProjectItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EditProject", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
req.Creator = userInfo.UserId
data, err = repo.EditProject(c, req)
go s.SaveLog("修改项目", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DelProject(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProjectItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("DelProject", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
req.Creator = userInfo.UserId
data, err = repo.DelProject(c, req)
go s.SaveLog("删除项目", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) GetProjectResult(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProjectRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("GetProjectResult", "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 > 100 {
req.Size = 100
}
if req.Page < 1 {
req.Page = 1
}
data, err = repo.GetProjectResult(c, req)
go s.SaveLog("获取项目检测结果", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) GetProjectData(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProjectDataRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("GetProjectData", "Manage", "", "", ToString(req), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
if req.Size < 1 {
req.Size = 20
}
if req.Size > 100 {
req.Size = 100
}
if req.Page < 1 {
req.Page = 1
}
data, err = repo.GetProjectData(c, req)
go s.SaveLog("获取项目数据", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) ProductList(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProductRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("ProductList", "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 > 100 {
req.Size = 100
}
if req.Page < 1 {
req.Page = 1
}
data, err = repo.ProductList(c, req)
go s.SaveLog("产品(物模型)列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) GetProductInfo(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProductItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("GetProductInfo", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.GetProductInfo(c, req)
go s.SaveLog("查看产品(物模型)", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddProduct(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProductItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddProduct", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddProduct(c, req)
go s.SaveLog("新增产品(物模型)", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditProduct(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProductItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EditProduct", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditProduct(c, req)
go s.SaveLog("修改产品(物模型)", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DelProduct(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProductItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("DelProduct", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditProduct(c, req)
go s.SaveLog("删除产品(物模型)", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) CategoryList(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProductCategoryRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("CategoryList", "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.CategoryList(c, req)
go s.SaveLog("产品(物模型)类型列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddCategory(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProductCategoryItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddCategory", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddCategory(c, req)
go s.SaveLog("新增产品(物模型)类型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditCategory(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProductCategoryItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddCategory", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditCategory(c, req)
go s.SaveLog("修改产品(物模型)类型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DelCategory(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ProductCategoryItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("DelCategory", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.DelCategory(c, req)
go s.SaveLog("删除产品(物模型)类型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AttributeList(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.AttributeRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("CategoryList", "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.AttributeList(c, req)
go s.SaveLog("产品(物模型)属性列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddAttribute(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.AttributeItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddAttribute", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddAttribute(c, req)
go s.SaveLog("增加产品(物模型)属性", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditAttribute(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.AttributeItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EditAttribute", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditAttribute(c, req)
go s.SaveLog("修改产品(物模型)属性", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DelAttribute(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.AttributeItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("DelAttribute", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.DelAttribute(c, req)
go s.SaveLog("删除产品(物模型)属性", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EventList(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.AttributeRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EventList", "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.EventList(c, req)
go s.SaveLog("产品(物模型)事件列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddEvent(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.EventItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddEvent", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddEvent(c, req)
go s.SaveLog("增加产品(物模型)事件", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditEvent(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.EventItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EditEvent", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditEvent(c, req)
go s.SaveLog("修改产品(物模型)事件", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DelEvent(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.EventItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("DelEvent", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.DelEvent(c, req)
go s.SaveLog("删除产品(物模型)事件", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EventParamsList(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.EventParamsRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EventList", "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.EventParamsList(c, req)
go s.SaveLog("产品(物模型)事件参数列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddEventParams(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.EventParamItem
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EventList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddEventParams(c, req)
go s.SaveLog("新增产品(物模型)事件参数", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditEventParams(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.EventParamItem
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EventList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditEventParams(c, req)
go s.SaveLog("修改产品(物模型)事件参数", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DelEventParams(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.EventParamItem
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EventList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.DelEventParams(c, req)
go s.SaveLog("删除产品(物模型)事件参数", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) ServiceList(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.AttributeRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("ServiceList", "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.ServiceList(c, req)
go s.SaveLog("产品(物模型)服务列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddService(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ServiceItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddService", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddService(c, req)
go s.SaveLog("增加产品(物模型)服务", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditService(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ServiceItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddService", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditService(c, req)
go s.SaveLog("修改产品(物模型)服务", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DelService(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ServiceItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("DelService", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.DelService(c, req)
go s.SaveLog("删除产品(物模型)服务", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) ServiceParamsList(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ServiceParamsRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("ServiceParamsList", "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.ServiceParamsList(c, req)
go s.SaveLog("产品(物模型)服务参数列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddServiceParams(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ServiceParamItem
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddServiceParams", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddServiceParams(c, req)
go s.SaveLog("增加产品(物模型)服务参数", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditServiceParams(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ServiceParamItem
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddServiceParams", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditServiceParams(c, req)
go s.SaveLog("修改产品(物模型)服务参数", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DelServiceParams(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ServiceParamItem
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddServiceParams", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.DelServiceParams(c, req)
go s.SaveLog("删除产品(物模型)服务参数", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DeviceList(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.DeviceRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("DeviceList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.DeviceList(c, req)
go s.SaveLog("查看设备列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DeviceInfo(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.DeviceItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("DeviceInfo", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.DeviceInfo(c, req)
go s.SaveLog("查看设备列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddDevice(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.DeviceItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddDevice", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddDevice(c, req)
go s.SaveLog("新增设备", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditDevice(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.DeviceItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddDevice", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditDevice(c, req)
go s.SaveLog("修改设备", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DeleteDevice(c *gin.Context) (data interface{}, err error) {
repo := service.NewManageService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.DeviceItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddDevice", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.DeleteDevice(c, req)
go s.SaveLog("删除设备", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}