sunty
2020-08-20 9d88c7c467f8d93af4aab9ba0b6d6c01c2ffc546
controllers/sdk.go
@@ -47,7 +47,7 @@
// @Description 算法保存
// @Accept json
// @Produce json
// @Tags sdk
// @Tags 算法
// @Param reqMap body controllers.SdkVo true "人脸检测"
// @Success 200 {string} json "{"code":200, msg:"请求处理成功",data:"",success:true}"
// @Failure 500 {string} json "{"code":500, msg:"请求失败",data:"",success:false}"
@@ -73,16 +73,18 @@
// @Summary 查找所有算法
// @Description 查找所有算法
// @Produce json
// @Tags sdk
// @Tags 算法
// @Param sdkName query string false "可选参数"
// @Param installed query bool true "查已安装或者查所有"
// @Success 200 {string} json "{"code":200, msg:"请求处理成功",data:"算法列表",success:true}"
// @Failure 500 {string} json "{"code":500, msg:"请求失败",data:"[]",success:false}"
// @Router /data/api-v/sdk/findAllSdk [GET]
func (sc SdkController) FindAllSdk(c *gin.Context) {
   sdkName := c.Query("sdkName")
   installed, _ := strconv.ParseBool(c.Query("installed"))
   logger.Debug("FindAllSdk sdkName:", sdkName)
   sdks := service.GetSdkList("") //本机已安装的算法
   sdks := service.GetSdkList("", installed) //本机已安装的算法
   util.ResponseFormat(c, code.Success, sdks)
}
@@ -91,7 +93,7 @@
// @Summary 根据id获取算法信息
// @Description 根据id获取算法信息
// @Produce json
// @Tags sdk
// @Tags 算法
// @Param id query string true "算法id,必填"
// @Success 200 {string} json "{"code":200, msg:"请求处理成功",data:"算法信息",success:true}"
// @Failure 500 {string} json "{"code":500, msg:"请求失败",data:"",success:false}"
@@ -134,7 +136,7 @@
// @Summary 根据taskId获取算法信息
// @Description 根据taskId获取算法信息
// @Produce json
// @Tags sdk
// @Tags 算法
// @Param taskId query string true "taskId,必填"
// @Success 200 {string} json "{"code":200, msg:"请求处理成功",data:"算法信息",success:true}"
// @Failure 500 {string} json "{"code":500, msg:"请求失败",data:"",success:false}"
@@ -158,7 +160,7 @@
// @Description 算法安装包上传(分块检查)
// @Accept multipart/form-data
// @Produce json
// @Tags sdk
// @Tags 算法
// @Param chunkNumber formData int true "当前是第几个分块"
// @Param chunkSize formData int true "每一块的大小"
// @Param currentChunkSize formData int true "当前块的大小"
@@ -210,7 +212,7 @@
// @Description 算法安装包上传
// @Accept multipart/form-data
// @Produce json
// @Tags sysset
// @Tags 算法
// @Param chunkNumber formData int true "当前是第几个分块"
// @Param chunkSize formData int true "每一块的大小"
// @Param currentChunkSize formData int true "当前块的大小"
@@ -257,23 +259,78 @@
      Header:           header,
   }
   var sv service.SysService
   if b,isComplete := sv.PatchUpload(&arg); b {
      if isComplete { //上传完毕需要自动触发安装
         var sv service.SdkInstallService
         if b,err := sv.SdkInstall(identifier, filename);b {
            util.ResponseFormat(c,&code.Code{http.StatusOK, true, "算法安装成功"},"算法安装成功")
            return
         } else {
            util.ResponseFormat(c,&code.Code{http.StatusBadRequest, false, "算法安装失败"},err.Error())
            return
         }
      }
      util.ResponseFormat(c, code.Success, "")
   if b,_ := sv.PatchUpload(&arg); b {
      //if isComplete { //上传完毕需要自动触发安装
      //   var sv service.SdkInstallService
      //   if b,err := sv.SdkInstall(identifier, filename);b {
      //      util.ResponseFormat(c,&code.Code{http.StatusOK, true, "算法安装成功"},"算法安装成功")
      //      return
      //   } else {
      //      util.ResponseFormat(c,&code.Code{http.StatusBadRequest, false, "算法安装失败"},err.Error())
      //      return
      //   }
      //}
      util.ResponseFormat(c, code.Success, "上传完成")
   } else {
      util.ResponseFormat(c, code.ComError, "")
   }
}
// @Security ApiKeyAuth
// @Summary 上传完成获取安装信息
// @Description 上传完成获取安装信息
// @Produce json
// @Tags 算法
// @Param identifier formData string true "整个文件的唯一标识,目前是md5"
// @Param filename formData string true "文件名称"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/sdk/showInstallInfo [post]
func (sc SdkController) ShowInstallInfo(c *gin.Context) {
   identifier := c.Request.FormValue("identifier")
   filename := c.Request.FormValue("filename")
   var sv service.SdkInstallService
   b,d, err := sv.ShowInstallInfo(identifier, filename)
   if b {
      util.ResponseFormat(c,code.Success, d)
   } else {
      util.ResponseFormat(c,&code.Code{http.StatusInternalServerError, false, err.Error()}, err.Error())
   }
}
// @Security ApiKeyAuth
// @Summary 上传完成开始安装
// @Description 上传完成开始安装
// @Produce json
// @Tags 算法
// @Param identifier formData string true "整个文件的唯一标识,目前是md5"
// @Param filename formData string true "文件名称"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/sdk/install [post]
func (sc SdkController) Install(c *gin.Context) {
   identifier := c.Request.FormValue("identifier")
   filename := c.Request.FormValue("filename")
   var sv service.SdkInstallService
   if b,err := sv.SdkInstall(identifier, filename);b {
      util.ResponseFormat(c,&code.Code{http.StatusOK, true, "算法安装成功"},"算法安装成功")
      return
   } else {
      util.ResponseFormat(c,&code.Code{http.StatusBadRequest, false, err.Error()},err.Error())
      return
   }
}
// @Security ApiKeyAuth
// @Summary 从商城下载或升级算法
// @Description 从商城下载或升级算法
// @Produce json
// @Tags 算法
// @Param path 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/sdk/sdkDownload [get]
func (sc SdkController) SdkDownLoad(c *gin.Context) {
   sdkId, exist := c.GetQuery("path")
   if !exist {
@@ -287,3 +344,29 @@
      util.ResponseFormat(c, &code.Code{http.StatusBadRequest, false, err.Error()}, err.Error())
   }
}
// @Security ApiKeyAuth
// @Summary 使用激活码激活安装算法
// @Description 使用激活码激活安装算法
// @Produce json
// @Tags 算法
// @Param code query string true "激活码"
// @Param sdkId 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/sdk/active [get]
func (sc SdkController) Active(c *gin.Context) {
   cod := c.GetString("code")
   sdkId := c.GetString("sdkId")
   if cod == "" || sdkId == "" {
      util.ResponseFormat(c, code.RequestParamError, "激活码和算法id不能为空")
      return
   }
   var sv service.SdkInstallService
   d, err := sv.Active(cod, sdkId)
   if err == nil {
      util.ResponseFormat(c,code.Success,  d)
   } else {
      util.ResponseFormat(c,code.ComError, err.Error())
   }
}