zhangzengfei
2023-11-28 3a706d3378aa3626501370352963883fd2783558
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package controllers
 
import (
    "strconv"
    "time"
    "vamicro/appcenter-service/models"
    "vamicro/appcenter-service/service"
 
    "basic.com/valib/bhomeclient.git"
    "basic.com/valib/logger.git"
)
 
type AppController struct {
    bk bhomeclient.Broker
}
 
// @Security ApiKeyAuth
// @Summary 查找已安装和未安装的应用列表
// @Description 查找已安装和未安装的应用列表
// @Produce json
// @Tags 应用
// @Param appName query string true "应用名称"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/app/findAllApp [get]
func (ac AppController) FindAll(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    appName := c.Query("appName")
    logger.Debug("FindAllApp appName:", appName)
    list := service.GetAppList(appName)
    if list == nil {
        list = make([]service.AppWithShop, 0)
    }
    return &bhomeclient.Reply{Success: true, Data: list}
}
 
type DelApp struct {
    AppId string `json:"appId" binding:"required"`
}
 
// @Security ApiKeyAuth
// @Summary 根据id获取app信息
// @Description 根据id获取app信息
// @Produce json
// @Tags 应用
// @Param id query string true "应用id"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/app/getAppInfo [get]
func (ac AppController) GetAppInfo(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    id := c.Query("id")
    logger.Debug("GetAppInfo id:", id)
    if id == "" {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    var app models.App
    rows, err := app.SelectById(id)
    if err == nil && rows > 0 {
        return &bhomeclient.Reply{Success: true, Data: app}
    } else {
        return &bhomeclient.Reply{Msg: "获取失败"}
    }
}
 
// @Security ApiKeyAuth
// @Summary 应用卸载
// @Description 应用卸载
// @Produce json
// @Tags 应用
// @Param arg body controllers.DelApp true "卸载参数"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/app/unInstall [post]
func (ac AppController) UnInstall(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var req DelApp
    err := c.BindJSON(&req)
    if err != nil {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
 
    var sv service.SdkInstallService
    if err := sv.PackUninstall(req.AppId); err != nil {
        logger.Error("执行uninstall.sh 失败", err.Error())
        return &bhomeclient.Reply{Success: false, Msg: "卸载失败"}
    }
 
    var appE models.App
    if appE.DeleteById(req.AppId) {
        return &bhomeclient.Reply{Success: true, Msg: "卸载成功"}
    } else {
        return &bhomeclient.Reply{Success: false, Msg: "卸载失败"}
    }
}
 
// @Security ApiKeyAuth
// @Summary 获取未购买的应用列表
// @Description 获取未购买的应用列表
// @Produce json
// @Tags 应用
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/app/buyList [get]
func (ac AppController) BuyList(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    appName := c.Query("appName")
    logger.Debug("BuyList appName:", appName)
    list := service.GetAppBuyList(appName)
    if list == nil {
        list = make([]models.App, 0)
    }
 
    return &bhomeclient.Reply{Success: true, Data: list}
}
 
// @Security ApiKeyAuth
// @Summary 使用激活码激活安装应用
// @Description 使用激活码激活安装应用
// @Produce json
// @Tags 应用
// @Param code query string true "激活码"
// @Param appId query string true "应用id"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/app/active [get]
func (ac AppController) Active(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    cod := c.Query("code")
    appId := c.Query("appId")
    if appId == "" { //code可以为空,为0元购
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    d, err := service.ActiveApp(cod, appId)
    if err == nil {
        // 激活成功
        var app models.App
        if err := app.UpdateCode(appId, cod); err != nil {
            return &bhomeclient.Reply{Msg: err.Error()}
        }
        return &bhomeclient.Reply{Success: true, Data: d}
    } else {
        return &bhomeclient.Reply{Msg: err.Error()}
    }
}
 
func (ac AppController) Save(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var reqBody models.App
    c.BindJSON(&reqBody)
    if reqBody.Id == "" {
        return &bhomeclient.Reply{Success: false, Msg: "参数有误"}
    }
    reqBody.CreateTime = time.Now().Format("2006-01-02 15:04:05")
    reqBody.CreateBy = "basic"
    reqBody.UpdateBy = ""
    reqBody.UpdateTime = ""
    if err := reqBody.Save(); err == nil {
        return &bhomeclient.Reply{Success: true, Msg: "保存成功"}
    } else {
        return &bhomeclient.Reply{Success: false, Msg: "保存失败"}
    }
}
 
// @Security ApiKeyAuth
// @Summary 显示算法或应用的产品信息详情
// @Description 显示算法或应用的产品信息详情
// @Produce json
// @Tags 应用
// @Param id query string true "算法或应用的id"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/app/detail [get]
func (ac AppController) Detail(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    id := c.Query("id")
    if id == "" {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    d, err := service.DetailByAppOrSdkId(id)
    if err == nil {
        return &bhomeclient.Reply{Success: true, Data: d}
    } else {
        return &bhomeclient.Reply{Msg: err.Error()}
    }
}
 
// @Security ApiKeyAuth
// @Summary 获取更新提醒
// @Description 获取更新提醒
// @Produce json
// @Tags 应用
// @Param id query string true "算法或应用的id"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/app/upgrade/notice [get]
func (ac AppController) UpgradeNotice(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    userId := c.Header("Login_user_id")
    notice := service.GetUpdateNotice()
    LastNoticeTime, ok := notice.NoticeUser[userId]
    if ok {
        notice.LastNoticeTime = LastNoticeTime
    }
    return &bhomeclient.Reply{Success: true, Data: notice}
}
 
// @Security ApiKeyAuth
// @Summary 延迟更新提醒
// @Description 延迟更新提醒
// @Produce json
// @Tags 应用
// @Param delay query string true "延迟提醒的秒数"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/app/upgrade/notice [get]
func (ac AppController) DelayNotice(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    userId := c.Header("Login_user_id")
    delay := c.PostForm("delay")
    delaySecond, err := strconv.Atoi(delay)
    if nil != err {
        return &bhomeclient.Reply{Msg: err.Error()}
    }
    service.DelayNotice(userId, delaySecond)
    return &bhomeclient.Reply{Success: true, Msg: "操作成功", Data: delaySecond}
}