Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request ThingsPanel#236 from November-12/main
Browse files Browse the repository at this point in the history
add
  • Loading branch information
November-12 authored Oct 18, 2023
2 parents 5af5e41 + b4e07c8 commit 7f53ff0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions controllers/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *ConsoleController) Add() {
}

var ConsoleService services.ConsoleService
err = ConsoleService.AddConsole(input.Name, userID, input.Data, input.Config, input.Template, input.Code, tenantId)
err = ConsoleService.AddConsole(input.Name, userID, input.Data, input.Config, input.Template, tenantId)
if err != nil {
utils.SuccessWithMessage(1000, err.Error(), (*context2.Context)(c.Ctx))
return
Expand Down Expand Up @@ -87,7 +87,7 @@ func (c *ConsoleController) Edit() {

var ConsoleService services.ConsoleService

err = ConsoleService.EditConsole(input.ID, input.Name, input.Data, input.Config, input.Template, input.Code, tenantId)
err = ConsoleService.EditConsole(input.ID, input.Name, input.Data, input.Config, input.Template, tenantId)
if err != nil {
utils.SuccessWithMessage(1000, err.Error(), (*context2.Context)(c.Ctx))
return
Expand Down
28 changes: 21 additions & 7 deletions services/console_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"ThingsPanel-Go/initialize/psql"
"ThingsPanel-Go/models"
uuid "ThingsPanel-Go/utils"
"math/rand"
"strconv"
"time"

"github.com/beego/beego/v2/core/logs"
Expand All @@ -12,8 +14,24 @@ import (
type ConsoleService struct {
}

func (*ConsoleService) AddConsole(name, createdBy, data, config, template, code, tenantId string) error {
func (*ConsoleService) AddConsole(name, createdBy, data, config, template, tenantId string) error {
id := uuid.GetUuid()
if data == "" {
data = "{}"
}

if config == "" {
config = "{}"
}

if template == "" {
template = "{}"
}

rand.Seed(time.Now().UnixNano())
randomNumber := rand.Intn(90000000) + 10000000
randomString := strconv.Itoa(randomNumber)

save := models.Console{
ID: id,
Name: name,
Expand All @@ -23,14 +41,14 @@ func (*ConsoleService) AddConsole(name, createdBy, data, config, template, code,
Data: data,
Config: config,
Template: template,
Code: code,
Code: randomString,
TenantId: tenantId,
}
result := psql.Mydb.Create(&save)
return result.Error
}

func (*ConsoleService) EditConsole(id, name, data, config, template, code, tenant_id string) error {
func (*ConsoleService) EditConsole(id, name, data, config, template, tenant_id string) error {

update := make(map[string]interface{})

Expand All @@ -52,10 +70,6 @@ func (*ConsoleService) EditConsole(id, name, data, config, template, code, tenan
update["template"] = template
}

if code != "" {
update["code"] = code
}

err := psql.Mydb.Model(&models.Console{}).Where("id = ? and tenant_id = ? ", id, tenant_id).Updates(update).Error
return err
}
Expand Down
2 changes: 0 additions & 2 deletions validate/console_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type AddConsole struct {
Data string `json:"data" alias:"看板数据" valid:"MaxSize(255)"`
Config string `json:"config" alias:"看板配置" valid:"MaxSize(500)"`
Template string `json:"templates" alias:"看板模版" valid:"MaxSize(500)"`
Code string `json:"code" alias:"看板编号" valid:"MaxSize(255)"`
}

type EditConsole struct {
Expand All @@ -15,7 +14,6 @@ type EditConsole struct {
Data string `json:"data" alias:"看板数据" valid:"MaxSize(255)"`
Config string `json:"config" alias:"看板配置" valid:"MaxSize(500)"`
Template string `json:"templates" alias:"看板模版" valid:"MaxSize(500)"`
Code string `json:"code" alias:"看板编号" valid:"MaxSize(255)"`
}

type DetailAndDetailConsole struct {
Expand Down

0 comments on commit 7f53ff0

Please sign in to comment.