1、增加模型服务
This commit is contained in:
		
							parent
							
								
									71b21f8a7a
								
							
						
					
					
						commit
						5c8be63b8e
					
				
							
								
								
									
										2
									
								
								go.mod
								
								
								
								
							
							
						
						
									
										2
									
								
								go.mod
								
								
								
								
							|  | @ -1,6 +1,6 @@ | |||
| module hpds-iot-web | ||||
| 
 | ||||
| go 1.19 | ||||
| go 1.18 | ||||
| 
 | ||||
| require ( | ||||
| 	git.hpds.cc/Component/gin_valid v0.0.0-20230104142509-f956bce255b6 | ||||
|  |  | |||
|  | @ -414,6 +414,75 @@ func (s HandlerService) DelEvent(c *gin.Context) (data interface{}, err error) { | |||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (s HandlerService) EventParamsList(c *gin.Context) (data interface{}, err error) { | ||||
| 	repo := service.NewManageService(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.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.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.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.Engine, s.Logger) | ||||
| 	us, _ := c.Get("operatorUser") | ||||
|  | @ -479,3 +548,69 @@ func (s HandlerService) DelService(c *gin.Context) (data interface{}, err error) | |||
| 	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.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.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.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.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 | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,76 @@ | |||
| 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) ModelList(c *gin.Context) (data interface{}, err error) { | ||||
| 	repo := service.NewModelService(s.Engine, s.Logger) | ||||
| 	us, _ := c.Get("operatorUser") | ||||
| 	userInfo := us.(*model.SystemUser) | ||||
| 	var req proto.ModelRequest | ||||
| 	err = c.ShouldBindJSON(&req) | ||||
| 	if err != nil { | ||||
| 		go s.SaveLog("ModelList", "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.ModelList(c, req) | ||||
| 	go s.SaveLog("获取模型列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||
| 	return | ||||
| } | ||||
| func (s HandlerService) AddModel(c *gin.Context) (data interface{}, err error) { | ||||
| 	repo := service.NewModelService(s.Engine, s.Logger) | ||||
| 	us, _ := c.Get("operatorUser") | ||||
| 	userInfo := us.(*model.SystemUser) | ||||
| 	var req proto.ModelItemRequest | ||||
| 	err = c.ShouldBindJSON(&req) | ||||
| 	if err != nil { | ||||
| 		go s.SaveLog("AddModel", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||
| 		return nil, e.NewValidErr(err) | ||||
| 	} | ||||
| 	data, err = repo.AddModel(c, req) | ||||
| 	go s.SaveLog("新增模型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||
| 	return | ||||
| } | ||||
| func (s HandlerService) EditModel(c *gin.Context) (data interface{}, err error) { | ||||
| 	repo := service.NewModelService(s.Engine, s.Logger) | ||||
| 	us, _ := c.Get("operatorUser") | ||||
| 	userInfo := us.(*model.SystemUser) | ||||
| 	var req proto.ModelItemRequest | ||||
| 	err = c.ShouldBindJSON(&req) | ||||
| 	if err != nil { | ||||
| 		go s.SaveLog("EditModel", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||
| 		return nil, e.NewValidErr(err) | ||||
| 	} | ||||
| 	data, err = repo.EditModel(c, req) | ||||
| 	go s.SaveLog("新增模型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||
| 	return | ||||
| } | ||||
| func (s HandlerService) DelModel(c *gin.Context) (data interface{}, err error) { | ||||
| 	repo := service.NewModelService(s.Engine, s.Logger) | ||||
| 	us, _ := c.Get("operatorUser") | ||||
| 	userInfo := us.(*model.SystemUser) | ||||
| 	var req proto.ModelItemRequest | ||||
| 	err = c.ShouldBindJSON(&req) | ||||
| 	if err != nil { | ||||
| 		go s.SaveLog("EditModel", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||
| 		return nil, e.NewValidErr(err) | ||||
| 	} | ||||
| 	data, err = repo.DelModel(c, req) | ||||
| 	go s.SaveLog("删除模型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") | ||||
| 	return | ||||
| } | ||||
|  | @ -217,3 +217,110 @@ func (p ServiceItemRequest) ToString() string { | |||
| 	} | ||||
| 	return string(data) | ||||
| } | ||||
| 
 | ||||
| type EventParamsRequest struct { | ||||
| 	EventId   int64 `json:"eventId"` | ||||
| 	MatterId  int64 `json:"matterId"` | ||||
| 	VersionId int64 `json:"versionId"` | ||||
| 	BasePageList | ||||
| } | ||||
| 
 | ||||
| func (p EventParamsRequest) ToString() string { | ||||
| 	data, err := json.Marshal(p) | ||||
| 	if err != nil { | ||||
| 		return "" | ||||
| 	} | ||||
| 	return string(data) | ||||
| } | ||||
| 
 | ||||
| type EventParamItem struct { | ||||
| 	ParamsId        int64  `json:"paramsId"` | ||||
| 	MatterId        int64  `json:"matterId"` | ||||
| 	VersionId       int64  `json:"versionId"` | ||||
| 	EventId         int64  `json:"eventId"` | ||||
| 	ParamName       string `json:"paramName"` | ||||
| 	ParamIdentifier string `json:"paramIdentifier"` | ||||
| 	DataType        int    `json:"dataType"` | ||||
| 	MaxValue        string `json:"maxValue"` | ||||
| 	MinValue        string `json:"minValue"` | ||||
| 	StepValue       string `json:"stepValue"` | ||||
| 	Unit            string `json:"unit"` | ||||
| } | ||||
| 
 | ||||
| func (p EventParamItem) ToString() string { | ||||
| 	data, err := json.Marshal(p) | ||||
| 	if err != nil { | ||||
| 		return "" | ||||
| 	} | ||||
| 	return string(data) | ||||
| } | ||||
| 
 | ||||
| type ServiceParamsRequest struct { | ||||
| 	MatterId        int64 `json:"matterId"` | ||||
| 	VersionId       int64 `json:"versionId"` | ||||
| 	ServiceId       int64 `json:"serviceId"` | ||||
| 	ParamsOwnerType int   `json:"paramsOwnerType"` | ||||
| 	BasePageList | ||||
| } | ||||
| 
 | ||||
| func (p ServiceParamsRequest) ToString() string { | ||||
| 	data, err := json.Marshal(p) | ||||
| 	if err != nil { | ||||
| 		return "" | ||||
| 	} | ||||
| 	return string(data) | ||||
| } | ||||
| 
 | ||||
| type ServiceParamItem struct { | ||||
| 	ParamsId        int64  `json:"paramsId"` | ||||
| 	MatterId        int64  `json:"matterId"` | ||||
| 	VersionId       int64  `json:"versionId"` | ||||
| 	ServiceId       int64  `json:"serviceId"` | ||||
| 	ParamsOwnerType int    `json:"paramsOwnerType"` | ||||
| 	ParamName       string `json:"paramName"` | ||||
| 	ParamIdentifier string `json:"paramIdentifier"` | ||||
| 	DataType        int    `json:"dataType"` | ||||
| 	MaxValue        string `json:"maxValue"` | ||||
| 	MinValue        string `json:"minValue"` | ||||
| 	StepValue       string `json:"stepValue"` | ||||
| 	Unit            string `json:"unit"` | ||||
| } | ||||
| 
 | ||||
| func (p ServiceParamItem) ToString() string { | ||||
| 	data, err := json.Marshal(p) | ||||
| 	if err != nil { | ||||
| 		return "" | ||||
| 	} | ||||
| 	return string(data) | ||||
| } | ||||
| 
 | ||||
| type ModelRequest struct { | ||||
| 	ModelName string `json:"modelName"` | ||||
| 	BasePageList | ||||
| } | ||||
| 
 | ||||
| func (p ModelRequest) ToString() string { | ||||
| 	data, err := json.Marshal(p) | ||||
| 	if err != nil { | ||||
| 		return "" | ||||
| 	} | ||||
| 	return string(data) | ||||
| } | ||||
| 
 | ||||
| type ModelItemRequest struct { | ||||
| 	ModelId          int    `json:"modelId"` | ||||
| 	ModelName        string `json:"modelName"` | ||||
| 	ModelVersion     string `json:"modelVersion"` | ||||
| 	ModelDesc        string `json:"modelDesc"` | ||||
| 	ModelFiles       string `json:"modelFiles"` | ||||
| 	ModelParamsFiles string `json:"modelParamsFiles"` | ||||
| 	ModelExecScript  string `json:"modelExecScript"` | ||||
| } | ||||
| 
 | ||||
| func (p ModelItemRequest) ToString() string { | ||||
| 	data, err := json.Marshal(p) | ||||
| 	if err != nil { | ||||
| 		return "" | ||||
| 	} | ||||
| 	return string(data) | ||||
| } | ||||
|  |  | |||
|  | @ -26,9 +26,9 @@ func InitRouter(logger *zap.Logger, engine *xorm.Engine) *gin.Engine { | |||
| 	} | ||||
| 	manage := r.Group("/manage") | ||||
| 	{ | ||||
| 		manage.Use(middleware.JwtAuthMiddleware(logger)) | ||||
| 		owner := manage.Group("/owner") | ||||
| 		{ | ||||
| 			owner.Use(middleware.JwtAuthMiddleware(logger)) | ||||
| 			owner.POST("/list", e.ErrorWrapper(hs.OwnerList)) | ||||
| 			owner.POST("/add", e.ErrorWrapper(hs.AddOwner)) | ||||
| 			owner.POST("/edit", e.ErrorWrapper(hs.EditOwner)) | ||||
|  | @ -36,7 +36,6 @@ func InitRouter(logger *zap.Logger, engine *xorm.Engine) *gin.Engine { | |||
| 		} | ||||
| 		project := manage.Group("/project") | ||||
| 		{ | ||||
| 			project.Use(middleware.JwtAuthMiddleware(logger)) | ||||
| 			project.POST("/list", e.ErrorWrapper(hs.ProjectList)) | ||||
| 			project.POST("/add", e.ErrorWrapper(hs.AddProject)) | ||||
| 			project.POST("/edit", e.ErrorWrapper(hs.EditProject)) | ||||
|  | @ -45,7 +44,6 @@ func InitRouter(logger *zap.Logger, engine *xorm.Engine) *gin.Engine { | |||
| 		} | ||||
| 		product := manage.Group("/product") | ||||
| 		{ | ||||
| 			product.Use(middleware.JwtAuthMiddleware(logger)) | ||||
| 			product.POST("/list", e.ErrorWrapper(hs.ProductList)) | ||||
| 			product.POST("/add", e.ErrorWrapper(hs.AddProduct)) | ||||
| 			product.POST("/edit", e.ErrorWrapper(hs.EditProduct)) | ||||
|  | @ -53,7 +51,6 @@ func InitRouter(logger *zap.Logger, engine *xorm.Engine) *gin.Engine { | |||
| 
 | ||||
| 			category := product.Group("/category") | ||||
| 			{ | ||||
| 				category.Use(middleware.JwtAuthMiddleware(logger)) | ||||
| 				category.POST("/list", e.ErrorWrapper(hs.CategoryList)) | ||||
| 				category.POST("/add", e.ErrorWrapper(hs.AddCategory)) | ||||
| 				category.POST("/edit", e.ErrorWrapper(hs.EditCategory)) | ||||
|  | @ -61,7 +58,6 @@ func InitRouter(logger *zap.Logger, engine *xorm.Engine) *gin.Engine { | |||
| 			} | ||||
| 			attribute := product.Group("/attribute") | ||||
| 			{ | ||||
| 				attribute.Use(middleware.JwtAuthMiddleware(logger)) | ||||
| 				attribute.POST("/list", e.ErrorWrapper(hs.AttributeList)) | ||||
| 				attribute.POST("/add", e.ErrorWrapper(hs.AddAttribute)) | ||||
| 				attribute.POST("/edit", e.ErrorWrapper(hs.EditAttribute)) | ||||
|  | @ -69,21 +65,44 @@ func InitRouter(logger *zap.Logger, engine *xorm.Engine) *gin.Engine { | |||
| 			} | ||||
| 			event := product.Group("/event") | ||||
| 			{ | ||||
| 				event.Use(middleware.JwtAuthMiddleware(logger)) | ||||
| 				event.POST("/list", e.ErrorWrapper(hs.EventList)) | ||||
| 				event.POST("/add", e.ErrorWrapper(hs.AddEvent)) | ||||
| 				event.POST("/edit", e.ErrorWrapper(hs.EditEvent)) | ||||
| 				event.POST("/delete", e.ErrorWrapper(hs.DelEvent)) | ||||
| 
 | ||||
| 				params := event.Group("/params") | ||||
| 				{ | ||||
| 					params.POST("/list", e.ErrorWrapper(hs.EventParamsList)) | ||||
| 					params.POST("/add", e.ErrorWrapper(hs.AddEventParams)) | ||||
| 					params.POST("/edit", e.ErrorWrapper(hs.EditEventParams)) | ||||
| 					params.POST("/delete", e.ErrorWrapper(hs.DelEventParams)) | ||||
| 				} | ||||
| 
 | ||||
| 			} | ||||
| 			service := product.Group("/service") | ||||
| 			{ | ||||
| 				service.Use(middleware.JwtAuthMiddleware(logger)) | ||||
| 				service.POST("/list", e.ErrorWrapper(hs.ServiceList)) | ||||
| 				service.POST("/add", e.ErrorWrapper(hs.AddService)) | ||||
| 				service.POST("/edit", e.ErrorWrapper(hs.EditService)) | ||||
| 				service.POST("/delete", e.ErrorWrapper(hs.DelService)) | ||||
| 
 | ||||
| 				params := service.Group("/params") | ||||
| 				{ | ||||
| 					params.POST("/list", e.ErrorWrapper(hs.ServiceParamsList)) | ||||
| 					params.POST("/add", e.ErrorWrapper(hs.AddServiceParams)) | ||||
| 					params.POST("/edit", e.ErrorWrapper(hs.EditServiceParams)) | ||||
| 					params.POST("/delete", e.ErrorWrapper(hs.DelServiceParams)) | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	model := r.Group("/model") | ||||
| 	{ | ||||
| 		model.Use(middleware.JwtAuthMiddleware(logger)) | ||||
| 		model.POST("/list", e.ErrorWrapper(hs.ModelList)) | ||||
| 		model.POST("/add", e.ErrorWrapper(hs.AddModel)) | ||||
| 		model.POST("/edit", e.ErrorWrapper(hs.EditModel)) | ||||
| 		model.POST("/delete", e.ErrorWrapper(hs.DelModel)) | ||||
| 	} | ||||
| 	return r | ||||
| } | ||||
|  |  | |||
|  | @ -45,6 +45,16 @@ type ManageService interface { | |||
| 	AddService(ctx context.Context, req proto.ServiceItemRequest) (rsp *proto.BaseResponse, err error) | ||||
| 	EditService(ctx context.Context, req proto.ServiceItemRequest) (rsp *proto.BaseResponse, err error) | ||||
| 	DelService(ctx context.Context, req proto.ServiceItemRequest) (rsp *proto.BaseResponse, err error) | ||||
| 
 | ||||
| 	EventParamsList(ctx context.Context, req proto.EventParamsRequest) (rsp *proto.BaseResponse, err error) | ||||
| 	AddEventParams(ctx context.Context, req proto.EventParamItem) (rsp *proto.BaseResponse, err error) | ||||
| 	EditEventParams(ctx context.Context, req proto.EventParamItem) (rsp *proto.BaseResponse, err error) | ||||
| 	DelEventParams(ctx context.Context, req proto.EventParamItem) (rsp *proto.BaseResponse, err error) | ||||
| 
 | ||||
| 	ServiceParamsList(ctx context.Context, req proto.ServiceParamsRequest) (rsp *proto.BaseResponse, err error) | ||||
| 	AddServiceParams(ctx context.Context, req proto.ServiceParamItem) (rsp *proto.BaseResponse, err error) | ||||
| 	EditServiceParams(ctx context.Context, req proto.ServiceParamItem) (rsp *proto.BaseResponse, err error) | ||||
| 	DelServiceParams(ctx context.Context, req proto.ServiceParamItem) (rsp *proto.BaseResponse, err error) | ||||
| } | ||||
| 
 | ||||
| func NewManageService(engine *xorm.Engine, logger *zap.Logger) ManageService { | ||||
|  | @ -1129,6 +1139,201 @@ ReturnPoint: | |||
| 	return rsp, err | ||||
| } | ||||
| 
 | ||||
| func (rp *repo) EventParamsList(ctx context.Context, req proto.EventParamsRequest) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		data := make([]model.MatterEventParams, 0) | ||||
| 		count, err := rp.engine.Where("matter_id = ? ", req.MatterId). | ||||
| 			And("version_id = ?", req.VersionId). | ||||
| 			And("event_id = ?", req.EventId). | ||||
| 			Limit(int(req.Size), int(((req.Page)-1)*req.Size)). | ||||
| 			FindAndCount(&data) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "成功" | ||||
| 		rsp = FillPaging(count, req.Page, req.Size, data, rsp) | ||||
| 		rsp.Err = err | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
| func (rp *repo) AddEventParams(ctx context.Context, req proto.EventParamItem) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		item := &model.MatterEventParams{ | ||||
| 			MatterId:        req.MatterId, | ||||
| 			VersionId:       req.VersionId, | ||||
| 			EventId:         req.EventId, | ||||
| 			ParamName:       req.ParamName, | ||||
| 			ParamIdentifier: req.ParamIdentifier, | ||||
| 			DataType:        req.DataType, | ||||
| 			MaxValue:        req.MaxValue, | ||||
| 			MinValue:        req.MinValue, | ||||
| 			StepValue:       req.StepValue, | ||||
| 			Unit:            req.Unit, | ||||
| 			Status:          1, | ||||
| 			CreateAt:        time.Now().Unix(), | ||||
| 			UpdateAt:        time.Now().Unix(), | ||||
| 		} | ||||
| 		_, err = rp.engine.Insert(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "成功" | ||||
| 		rsp.Err = err | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
| func (rp *repo) EditEventParams(ctx context.Context, req proto.EventParamItem) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		var h bool | ||||
| 		item := new(model.MatterEventParams) | ||||
| 		h, err = rp.engine.ID(req.ParamsId).Get(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		if !h { | ||||
| 			err = fmt.Errorf("未能找到对应的参数") | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		if req.MatterId > 0 { | ||||
| 			item.MatterId = req.MatterId | ||||
| 		} | ||||
| 		if req.VersionId > 0 { | ||||
| 			item.VersionId = req.VersionId | ||||
| 		} | ||||
| 		if req.EventId > 0 { | ||||
| 			item.EventId = req.EventId | ||||
| 		} | ||||
| 		if len(req.ParamName) > 0 { | ||||
| 			item.ParamName = req.ParamName | ||||
| 		} | ||||
| 		if len(req.ParamIdentifier) > 0 { | ||||
| 			item.ParamIdentifier = req.ParamIdentifier | ||||
| 		} | ||||
| 		if req.DataType > 0 { | ||||
| 			item.DataType = req.DataType | ||||
| 		} | ||||
| 		if len(req.MaxValue) > 0 { | ||||
| 			item.MaxValue = req.MaxValue | ||||
| 		} | ||||
| 		if len(req.MinValue) > 0 { | ||||
| 			item.MinValue = req.MinValue | ||||
| 		} | ||||
| 		if len(req.StepValue) > 0 { | ||||
| 			item.StepValue = req.StepValue | ||||
| 		} | ||||
| 		if len(req.Unit) > 0 { | ||||
| 			item.Unit = req.Unit | ||||
| 		} | ||||
| 		item.UpdateAt = time.Now().Unix() | ||||
| 		_, err = rp.engine.ID(req.ParamsId).AllCols().Update(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "成功" | ||||
| 		rsp.Err = err | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
| func (rp *repo) DelEventParams(ctx context.Context, req proto.EventParamItem) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		var h bool | ||||
| 		item := new(model.MatterEventParams) | ||||
| 		h, err = rp.engine.ID(req.ParamsId).Get(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		if !h { | ||||
| 			err = fmt.Errorf("未能找到对应的参数") | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		item.Status = 0 | ||||
| 		item.UpdateAt = time.Now().Unix() | ||||
| 		_, err = rp.engine.ID(req.ParamsId).AllCols().Update(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "成功" | ||||
| 		rsp.Err = err | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
| 
 | ||||
| func (rp *repo) ServiceList(ctx context.Context, req proto.AttributeRequest) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
|  | @ -1308,3 +1513,203 @@ ReturnPoint: | |||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
| 
 | ||||
| func (rp *repo) ServiceParamsList(ctx context.Context, req proto.ServiceParamsRequest) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		data := make([]model.MatterServiceParams, 0) | ||||
| 		count, err := rp.engine.Where("matter_id = ? ", req.MatterId). | ||||
| 			And("version_id = ?", req.VersionId). | ||||
| 			And("service_id = ?", req.ServiceId). | ||||
| 			And("params_owner_type = ?", req.ParamsOwnerType). | ||||
| 			Limit(int(req.Size), int(((req.Page)-1)*req.Size)). | ||||
| 			FindAndCount(&data) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "成功" | ||||
| 		rsp = FillPaging(count, req.Page, req.Size, data, rsp) | ||||
| 		rsp.Err = err | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
| func (rp *repo) AddServiceParams(ctx context.Context, req proto.ServiceParamItem) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		item := &model.MatterServiceParams{ | ||||
| 			MatterId:        req.MatterId, | ||||
| 			VersionId:       req.VersionId, | ||||
| 			ServiceId:       req.ServiceId, | ||||
| 			ParamsOwnerType: req.ParamsOwnerType, | ||||
| 			ParamName:       req.ParamName, | ||||
| 			ParamIdentifier: req.ParamIdentifier, | ||||
| 			DataType:        req.DataType, | ||||
| 			MaxValue:        req.MaxValue, | ||||
| 			MinValue:        req.MinValue, | ||||
| 			StepValue:       req.StepValue, | ||||
| 			Unit:            req.Unit, | ||||
| 			Status:          1, | ||||
| 			CreateAt:        time.Now().Unix(), | ||||
| 			UpdateAt:        time.Now().Unix(), | ||||
| 		} | ||||
| 		_, err = rp.engine.Insert(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "成功" | ||||
| 		rsp.Err = err | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
| func (rp *repo) EditServiceParams(ctx context.Context, req proto.ServiceParamItem) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		var h bool | ||||
| 		item := new(model.MatterServiceParams) | ||||
| 		h, err = rp.engine.ID(req.ParamsId).Get(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		if !h { | ||||
| 			err = fmt.Errorf("未能找到对应的参数") | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		if req.MatterId > 0 { | ||||
| 			item.MatterId = req.MatterId | ||||
| 		} | ||||
| 		if req.VersionId > 0 { | ||||
| 			item.VersionId = req.VersionId | ||||
| 		} | ||||
| 		if req.ServiceId > 0 { | ||||
| 			item.ServiceId = req.ServiceId | ||||
| 		} | ||||
| 		if req.ParamsOwnerType > 0 { | ||||
| 			item.ParamsOwnerType = req.ParamsOwnerType | ||||
| 		} | ||||
| 		if len(req.ParamName) > 0 { | ||||
| 			item.ParamName = req.ParamName | ||||
| 		} | ||||
| 		if len(req.ParamIdentifier) > 0 { | ||||
| 			item.ParamIdentifier = req.ParamIdentifier | ||||
| 		} | ||||
| 		if req.DataType > 0 { | ||||
| 			item.DataType = req.DataType | ||||
| 		} | ||||
| 		if len(req.MaxValue) > 0 { | ||||
| 			item.MaxValue = req.MaxValue | ||||
| 		} | ||||
| 		if len(req.MinValue) > 0 { | ||||
| 			item.MinValue = req.MinValue | ||||
| 		} | ||||
| 		if len(req.StepValue) > 0 { | ||||
| 			item.StepValue = req.StepValue | ||||
| 		} | ||||
| 		if len(req.Unit) > 0 { | ||||
| 			item.Unit = req.Unit | ||||
| 		} | ||||
| 		item.UpdateAt = time.Now().Unix() | ||||
| 		_, err = rp.engine.ID(req.ParamsId).AllCols().Update(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "成功" | ||||
| 		rsp.Err = err | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
| func (rp *repo) DelServiceParams(ctx context.Context, req proto.ServiceParamItem) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		var h bool | ||||
| 		item := new(model.MatterServiceParams) | ||||
| 		h, err = rp.engine.ID(req.ParamsId).Get(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		if !h { | ||||
| 			err = fmt.Errorf("未能找到对应的参数") | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		item.Status = 0 | ||||
| 		item.UpdateAt = time.Now().Unix() | ||||
| 		_, err = rp.engine.ID(req.ParamsId).AllCols().Update(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "成功" | ||||
| 		rsp.Err = err | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,208 @@ | |||
| package service | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"go.uber.org/zap" | ||||
| 	"hpds-iot-web/internal/proto" | ||||
| 	"hpds-iot-web/model" | ||||
| 	"net/http" | ||||
| 	"time" | ||||
| 	"xorm.io/xorm" | ||||
| ) | ||||
| 
 | ||||
| type ModelService interface { | ||||
| 	ModelList(ctx context.Context, req proto.ModelRequest) (rsp *proto.BaseResponse, err error) | ||||
| 	AddModel(ctx context.Context, req proto.ModelItemRequest) (rsp *proto.BaseResponse, err error) | ||||
| 	EditModel(ctx context.Context, req proto.ModelItemRequest) (rsp *proto.BaseResponse, err error) | ||||
| 	DelModel(ctx context.Context, req proto.ModelItemRequest) (rsp *proto.BaseResponse, err error) | ||||
| } | ||||
| 
 | ||||
| func NewModelService(engine *xorm.Engine, logger *zap.Logger) ModelService { | ||||
| 	return &repo{ | ||||
| 		engine: engine, | ||||
| 		logger: logger, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (rp *repo) ModelList(ctx context.Context, req proto.ModelRequest) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		data := make([]model.Model, 0) | ||||
| 		count, err := rp.engine.Where("(? = '' or model_name like ?)", req.ModelName, "%"+req.ModelName+"%"). | ||||
| 			And("status = 1").Limit(int(req.Size), int(((req.Page)-1)*req.Size)). | ||||
| 			FindAndCount(&data) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "成功" | ||||
| 		rsp = FillPaging(count, req.Page, req.Size, data, rsp) | ||||
| 		rsp.Err = err | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
| 
 | ||||
| func (rp *repo) AddModel(ctx context.Context, req proto.ModelItemRequest) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		item := &model.Model{ | ||||
| 			ModelName:        req.ModelName, | ||||
| 			ModelVersion:     req.ModelVersion, | ||||
| 			ModelDesc:        req.ModelDesc, | ||||
| 			ModelFiles:       req.ModelFiles, | ||||
| 			ModelParamsFiles: req.ModelParamsFiles, | ||||
| 			ModelExecScript:  req.ModelExecScript, | ||||
| 			Status:           1, | ||||
| 			CreateAt:         time.Now().Unix(), | ||||
| 			UpdateAt:         time.Now().Unix(), | ||||
| 		} | ||||
| 		_, err = rp.engine.Insert(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 
 | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "新增模型成功" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		rsp.Data = item | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
| func (rp *repo) EditModel(ctx context.Context, req proto.ModelItemRequest) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		var h bool | ||||
| 		item := new(model.Model) | ||||
| 		h, err = rp.engine.ID(req.ModelId).Get(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		if !h { | ||||
| 			err = fmt.Errorf("未能找到对应的模型") | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		if len(req.ModelName) > 0 { | ||||
| 			item.ModelName = req.ModelName | ||||
| 		} | ||||
| 		if len(req.ModelVersion) > 0 { | ||||
| 			item.ModelVersion = req.ModelVersion | ||||
| 		} | ||||
| 		if len(req.ModelDesc) > 0 { | ||||
| 			item.ModelDesc = req.ModelDesc | ||||
| 		} | ||||
| 		if len(req.ModelFiles) > 0 { | ||||
| 			item.ModelFiles = req.ModelFiles | ||||
| 		} | ||||
| 		if len(req.ModelParamsFiles) > 0 { | ||||
| 			item.ModelParamsFiles = req.ModelParamsFiles | ||||
| 		} | ||||
| 		if len(req.ModelExecScript) > 0 { | ||||
| 			item.ModelExecScript = req.ModelExecScript | ||||
| 		} | ||||
| 		item.UpdateAt = time.Now().Unix() | ||||
| 		_, err = rp.engine.ID(req.ModelId).AllCols().Update(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "修改模型成功" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		rsp.Data = item | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
| func (rp *repo) DelModel(ctx context.Context, req proto.ModelItemRequest) (rsp *proto.BaseResponse, err error) { | ||||
| 	rsp = new(proto.BaseResponse) | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		err = fmt.Errorf("超时/取消") | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Message = "超时/取消" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		return rsp, ctx.Err() | ||||
| 	default: | ||||
| 		var h bool | ||||
| 		item := new(model.Model) | ||||
| 		h, err = rp.engine.ID(req.ModelId).Get(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		if !h { | ||||
| 			err = fmt.Errorf("未能找到对应的模型") | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		item.Status = 0 | ||||
| 		item.UpdateAt = time.Now().Unix() | ||||
| 		_, err = rp.engine.ID(req.ModelId).AllCols().Update(item) | ||||
| 		if err != nil { | ||||
| 			goto ReturnPoint | ||||
| 		} | ||||
| 		rsp.Code = http.StatusOK | ||||
| 		rsp.Status = http.StatusText(http.StatusOK) | ||||
| 		rsp.Message = "删除模型成功" | ||||
| 		rsp.Err = ctx.Err() | ||||
| 		rsp.Data = item | ||||
| 		return rsp, err | ||||
| 	} | ||||
| ReturnPoint: | ||||
| 	if err != nil { | ||||
| 		rsp.Code = http.StatusInternalServerError | ||||
| 		rsp.Status = http.StatusText(http.StatusInternalServerError) | ||||
| 		rsp.Err = err | ||||
| 		rsp.Message = "失败" | ||||
| 	} | ||||
| 	return rsp, err | ||||
| } | ||||
|  | @ -12,6 +12,7 @@ type MatterEventParams struct { | |||
| 	MinValue        string `xorm:"varchar(200)" json:"minValue"` | ||||
| 	StepValue       string `xorm:"varchar(200) " json:"stepValue"` | ||||
| 	Unit            string `xorm:"varchar(200) " json:"unit"` | ||||
| 	Status          int    `xorm:"not null SMALLINT default 0" json:"status"` | ||||
| 	CreateAt        int64  `xorm:"created" json:"createAt"` | ||||
| 	UpdateAt        int64  `xorm:"updated" json:"updateAt"` | ||||
| } | ||||
|  |  | |||
|  | @ -13,6 +13,7 @@ type MatterServiceParams struct { | |||
| 	MinValue        string `xorm:"varchar(200)" json:"minValue"` | ||||
| 	StepValue       string `xorm:"varchar(200) " json:"stepValue"` | ||||
| 	Unit            string `xorm:"varchar(200) " json:"unit"` | ||||
| 	Status          int    `xorm:"not null SMALLINT default 0" json:"status"` | ||||
| 	CreateAt        int64  `xorm:"created" json:"createAt"` | ||||
| 	UpdateAt        int64  `xorm:"updated" json:"updateAt"` | ||||
| } | ||||
|  |  | |||
|  | @ -5,6 +5,10 @@ type Model struct { | |||
| 	ModelName        string `xorm:"varchar(200) not null" json:"modelName"` | ||||
| 	ModelVersion     string `xorm:"varchar(50) not null" json:"modelVersion"` | ||||
| 	ModelDesc        string `xorm:"varchar(200) not null" json:"modelDesc"` | ||||
| 	ModelFiles       string `xorm:"varchar(200) not null" json:"modelFiles"` | ||||
| 	ModelParamsFiles string `xorm:"varchar(200)" json:"modelParamsFiles"` | ||||
| 	ModelExecScript  string `xorm:"varchar(200)" json:"modelExecScript"` | ||||
| 	Status           int    `xorm:"not null SMALLINT default 0" json:"status"` | ||||
| 	CreateAt         int64  `xorm:"created" json:"createAt"` | ||||
| 	UpdateAt         int64  `xorm:"updated" json:"updateAt"` | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue