finclip-app-manager/infrastructure/client/httpcall/appletBuildManage.go

147 lines
6.7 KiB
Go

package httpcall
import (
"context"
"encoding/json"
"errors"
"finclip-app-manager/infrastructure/config"
)
type GetSdkVerIsEncryptedRspData struct {
Encrypted bool `json:"encrypted"`
}
type GetSdkVerIsEncryptedRsp struct {
Errcode string `json:"errcode"`
Error string `json:"error"`
Data GetSdkVerIsEncryptedRspData `json:"data"`
}
func (c *Client) GetSdkVerIsEncrypted(ctx context.Context, sdkVer string) (bool, error) {
url := config.GetConfig().AppletBuildManageHost + config.GetConfig().SdkVerJudgeUrl + "?sdkVersion=" + sdkVer
var headers = map[string]string{
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"url-call": "internal",
}
rsp, err := c.Request(ctx).SetHeaders(headers).Get(url)
if err != nil {
log.Errorf("GetSdkVerIsEncrypted client req err:%s", err.Error())
return false, err
}
if rsp.StatusCode() != 200 {
log.Errorf("GetSdkVerIsEncrypted rsp code err:%s", rsp.String())
return false, errors.New("GetSdkVerIsEncrypted rsp code no 200")
}
log.Infof("GetSdkVerIsEncrypted info:%s", rsp.String())
resp := GetSdkVerIsEncryptedRsp{}
err = json.Unmarshal(rsp.Body(), &resp)
if err != nil {
log.Errorf("Failed to unmarshal DomainResponse: %v\n", err)
return false, err
}
return resp.Data.Encrypted, nil
}
type BuildInfo struct {
Id string `json:"id" gorm:"primary_key;column:id" sql:"primary_key;unique" bson:"id"`
AppId string `json:"appId" gorm:"column:app_id;type:varchar(64);comment:'App id'" bson:"appId"`
UserId string `json:"userId" gorm:"column:user_id;type:varchar(64);default:0;comment:'用户id'" bson:"userId"` //用户id
Filename string `json:"filename" gorm:"column:file_name;type:varchar(64);default:'';comment:'文件名'" bson:"filename"` //文件名
FileUrl string `json:"fileUrl" gorm:"column:file_url;type:varchar(128);default:'';comment:'文件地址'" bson:"fileUrl"` //文件地址
Content string `json:"content" gorm:"column:content;type:varchar(10240);default:'';comment:''" bson:"content"` //content
Version string `json:"version" gorm:"column:version;type:varchar(64);default:'';comment:'版本'" bson:"version"` //版本
VersionRemark string `json:"versionRemark" gorm:"column:version_remark;type:varchar(256);default:'';comment:'VersionRemark'" bson:"versionRemark"` //VersionRemark
OrganId string `json:"organId" gorm:"column:organ_id;type:varchar(64);default:'';comment:'机构id'" bson:"organId"` //机构id
Username string `json:"username" gorm:"column:user_name;type:varchar(64);default:'';comment:'用户名'" bson:"username"` //用户名
CreateTime int64 `json:"createTime" gorm:"column:create_time;type:BIGINT(16);default:0;comment:'创建时间'" bson:"createTime"` //创建时间
UpdateTime int64 `json:"updateTime" gorm:"column:update_time;type:BIGINT(16);default:0;comment:'更新时间'" bson:"updateTime"` //更新时间
EncryptedUrl string `json:"encryptedUrl" gorm:"column:encrypted_url;type:varchar(128);default:'';comment:'文件加密地址'" bson:"encryptedUrl"`
Status bool `json:"status" gorm:"column:encrypted_url;type:varchar(128);default:'';comment:'文件加密地址'" bson:"status"`
Packages []Package `json:"packages" bson:"packages"`
EncryptPackage []Package `json:"encryptPackage" bson:"encryptPackage"`
Cmd string `json:"cmd" gorm:"column:cmd;type:varchar(64);default:'';comment:'编译上传类型'" bson:"cmd"` //cmd:为空默认编译上传 create:不编译直接上传 directUploadSource: 直接上传源文件
}
type Package struct {
Root string `json:"root" bson:"root"`
Name string `json:"name" bson:"name"`
Pages []string `json:"pages" bson:"pages"`
Independent bool `json:"independent" bson:"independent"`
Filename string `json:"filename" bson:"filename"`
FileUrl string `json:"fileUrl" bson:"fileUrl"`
FileMd5 string `json:"fileMd5" bson:"fileMd5"`
}
type GetAppletInfoByIdRsp struct {
Errcode string `json:"errcode"`
Error string `json:"error"`
InfoData GetAppletInfoData `json:"data"`
}
type GetAppletInfoData struct {
Data []BuildInfo `json:"datas`
TotalElement int `json:"totalElement"`
TotalPage int `json:"totalPage"`
Size int `json:"size"`
Page int `json:"page"`
}
func (c *Client) GetAppletInfo(ctx context.Context, appId, organId string) (*[]BuildInfo, error) {
url := config.GetConfig().AppletBuildManageHost + config.GetConfig().GetAppletInfoUrl + "?appId=" + appId + "&organId=" + organId + "&userId=&page=0&size=0"
log.Infof("GetAppletInfo url:%s", url)
var headers = map[string]string{
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"url-call": "internal",
}
rsp, err := c.Request(ctx).SetHeaders(headers).Get(url)
if err != nil {
log.Errorf("GetAppletInfo client req err:%s", err.Error())
return nil, err
}
if rsp.StatusCode() != 200 {
log.Errorf("GetAppletInfo rsp code err:%s", rsp.String())
return nil, errors.New("GetAppletInfo rsp code no 200")
}
log.Infof("GetAppletInfoById info:%s", rsp.String())
resp := GetAppletInfoByIdRsp{}
err = json.Unmarshal(rsp.Body(), &resp)
if err != nil {
log.Errorf("Failed to unmarshal : %v\n", err)
return nil, err
}
return &resp.InfoData.Data, nil
}
type GetAppletByIdRsp struct {
Errcode string `json:"errcode"`
Error string `json:"error"`
InfoData BuildInfo `json:"data"`
}
func (c *Client) GetAppletInfoById(ctx context.Context, Id string) (*BuildInfo, error) {
url := config.GetConfig().AppletBuildManageHost + config.GetConfig().GetAppletInfoByIdUrl + "?appletInfoId=" + Id
log.Infof("GetAppletInfoById url:%s", url)
var headers = map[string]string{
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"url-call": "internal",
}
rsp, err := c.Request(ctx).SetHeaders(headers).Get(url)
if err != nil {
log.Errorf("GetAppletInfo client req err:%s", err.Error())
return nil, err
}
if rsp.StatusCode() != 200 {
log.Errorf("GetAppletInfo rsp code err:%s", rsp.String())
return nil, errors.New("GetAppletInfo rsp code no 200")
}
log.Infof("GetAppletInfoById info:%s", rsp.String())
resp := GetAppletByIdRsp{}
err = json.Unmarshal(rsp.Body(), &resp)
if err != nil {
log.Errorf("Failed to unmarshal : %v\n", err)
return nil, err
}
return &resp.InfoData, nil
}