qixiaoning
9 天以前 eac932eb827c93e2e998ac1210c3f5e548af0dbf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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,
    }}
}