package controllers
|
|
import (
|
"basic.com/valib/bhomeclient.git"
|
"basic.com/valib/logger.git"
|
"github.com/satori/go.uuid"
|
|
"os"
|
"path"
|
"vamicro/extend/util"
|
"vamicro/projection-service/zconf"
|
)
|
|
type ReportServiceController struct {
|
bk bhomeclient.Broker
|
}
|
|
func (ac ReportServiceController) GetConfigInfo(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
|
// 加载配置文件
|
zconf.LoadConfig()
|
|
if zconf.Options == nil {
|
return &bhomeclient.Reply{Success: false, Data: nil}
|
}
|
|
return &bhomeclient.Reply{Success: true, Data: zconf.Options}
|
}
|
|
func (ac ReportServiceController) SetConfigInfo(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
|
var config zconf.ZConfig
|
if err := c.BindJSON(&config); err != nil {
|
return &bhomeclient.Reply{Success: false, Msg: "参数格式错误,非法的json格式"}
|
}
|
|
zconf.SaveConfig(&config)
|
|
return &bhomeclient.Reply{Success: true, Data: nil}
|
}
|
|
func (ac ReportServiceController) UploadFile(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
|
file := c.File
|
|
if file.Name == "" || file.Bytes == nil || len(file.Bytes) == 0 {
|
logger.Debug("upload panorama file is nil")
|
return &bhomeclient.Reply{Msg: "参数有误"}
|
}
|
|
ext := path.Ext(file.Name)
|
|
fileName := "/opt/vasystem/files/" + uuid.NewV4().String() + ext
|
if util.Exists(fileName) {
|
os.Remove(fileName)
|
}
|
|
f, err := os.Create(fileName)
|
if err != nil {
|
return &bhomeclient.Reply{Msg: err.Error()}
|
}
|
|
defer f.Close()
|
n, err := f.Write(file.Bytes)
|
logger.Debug("write panorama file n:", n)
|
if err != nil {
|
return &bhomeclient.Reply{Msg: err.Error()}
|
}
|
|
return &bhomeclient.Reply{Success: true, Data: map[string]string{
|
"filePath": fileName,
|
}}
|
}
|