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}
|
}
|