finclip-app-manager/application/app.go

3138 lines
98 KiB
Go
Raw Permalink Normal View History

2023-10-31 14:07:26 +08:00
package application
import (
"bytes"
"context"
"finclip-app-manager/domain/entity"
"finclip-app-manager/domain/entity/proto"
"finclip-app-manager/domain/entity/proto/apiproto"
"finclip-app-manager/domain/service"
"finclip-app-manager/infrastructure/config"
"finclip-app-manager/infrastructure/utility"
"fmt"
"net/http"
"strconv"
"time"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"github.com/tealeg/xlsx"
"gitlab.finogeeks.club/finclip-backend/apm"
)
const (
MAX_EXPIRE_DATA = 9999999999999
)
/**
* @api {POST} /api/v1/mop/finstore/dev/apps/creation [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestBody) {string} appClass //小程序分类
* @apiParam (RequestBody) {[]string} appTag //小程序标签
* @apiParam (RequestBody) {string} appType //小程序类型
* @apiParam (RequestBody) {string} coreDescription //小程序描述
* @apiParam (RequestBody) {string} logo //小程序logo
* @apiParam (RequestBody) {string} name //小程序名称
* @apiParam (RequestBody) {int} projectType //项目类型,默认 0代表小程序1 小游戏2 H5
* @apiParamExample {json} Request-Example:
* {
* "appClass": "jinrong",
* "appTag":["a","b"],
* "appType":"c",
* "coreDescription":"详情",
* "logo":"/api/v1/netdisk/download/243454567",
* "name":"开户"
* "projectType":0
* }
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": {},
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevCreateApp(c *gin.Context) {
var (
traceCtx = apm.ApmClient().TraceContextFromGin(c)
req = proto.CreateAppReq{}
)
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("createApp bind json err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("createApp get req:%+v", req)
accountId := utility.GetUserId(c)
if accountId == "" {
log.Errorf("DevCreateApp user id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("createApp get user id:%+v", accountId)
svr := service.NewAppService()
rspData, rsp := svr.CreateApp(traceCtx, c, req, accountId)
if rspData != nil {
go autoBindingAppByCreate(rspData, accountId)
rsp.MakeRsp(c, rspData)
} else {
rsp.MakeRsp(c, gin.H{})
}
return
}
func autoBindingAppByCreate(app *entity.App, accountId string) {
svr := service.NewBindingService()
svr.AutoBindingAppByCreate(app, accountId)
}
/**
* @api {POST} /api/v1/mop/finstore/dev/apps/update [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestBody) {string} appId //小程序id
* @apiParam (RequestBody) {string} appClass //小程序分类
* @apiParam (RequestBody) {[]string} appTag //小程序标签
* @apiParam (RequestBody) {string} appType //小程序类型
* @apiParam (RequestBody) {string} coreDescription //小程序描述
* @apiParam (RequestBody) {string} logo //小程序logo
* @apiParam (RequestBody) {string} name //小程序名称
* @apiParam (RequestBody) {object} customData //小程序自定义内容
* @apiParamExample {json} Request-Example:
* {
* "appId":"61b32654659d2b00016264a8",
* "appClass": "jinrong",
* "appTag":["a","b"],
* "appType":"c",
* "coreDescription":"详情",
* "logo":"/api/v1/netdisk/download/243454567",
* "name":"开户",
* "customData":{
* "detailDescription":"详细信息"
* }
* }
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": {},
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevUpdateApp(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := proto.AppUpdateReq{}
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("updateApp bind error:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("updateApp get req:%+v", req)
if req.AppId == "" || req.Name == "" || req.CoreDescription == "" {
log.Errorf("update app req err:%+v", req)
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
userId := utility.GetUserId(c)
if userId == "" {
log.Errorf("update app user id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_USER_ID, gin.H{})
return
}
rsp := service.NewAppService().UpdateApp(traceCtx, c, req, userId)
rsp.MakeRsp(c, gin.H{})
return
}
/**
* @api {POST} /api/v1/mop/finstore/dev/apps/is_forbidden/update [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestBody) {string} appId //小程序id
* @apiParam (RequestBody) {int} isForbidden //0:解禁1:禁用
* @apiParamExample {json} Request-Example:
* {
* "appId":"61b32654659d2b00016264a8",
* "isForbidden": 1
* }
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": {},
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevUpdateAppIsForbidden(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := proto.AppIsForbiddenUpdateReq{}
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("updateAppIsForbidden bind error:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("updateAppIsForbidden get req:%+v", req)
userId := utility.GetUserId(c)
if userId == "" {
log.Errorf("update app isForbidden user id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_USER_ID, gin.H{})
return
}
rsp := service.NewAppService().UpdateAppIsForbidden(traceCtx, req, userId)
rsp.MakeRsp(c, gin.H{})
return
}
/**
* @api {POST} /api/v1/mop/finstore/dev/apps/publish-request [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestBody) {string} id //编译id
* @apiParam (RequestBody) {string} appId //小程序id
* @apiParam (RequestBody) {string} developerId //开发者id
* @apiParam (RequestBody) {bool} needAutoPub //是否自动发布
* @apiParam (RequestBody) {object} testInfo //测试内容
* @apiParamExample {json} Request-Example:
* {
* "id":"61b32654659d2b00016264a9",
* "appId":"61b32654659d2b00016264a8",
* "developerId": "61b32654659d2b00016264a7",
* "needAutoPub":true,
* "testInfo":{
* "account":"zhangsan",
* "password":"123456",
* "description":"测试使用",
* "images":[
* "logo1地址",
* "logo2地址"
* ]
* }
* }
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": {},
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevSubmitPublishRequest(c *gin.Context) {
var (
traceCtx = apm.ApmClient().TraceContextFromGin(c)
req = apiproto.SubmitPublishReqest{}
)
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("submitPublishRequest bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("submitPublishRequest req:%+v", req)
userId := utility.GetUserId(c)
if userId == "" {
log.Errorf("DevSubmitPublishRequest user id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
service.NewAppService().SubmitApp(traceCtx, c, req, userId).MakeRsp(c, gin.H{})
}
/**
* @api {POST} /api/v1/mop/finstore/dev/apps/publish-request-withdrawal [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestBody) {string} appId //小程序id
* @apiParam (RequestBody) {string} developerId //开发者id
* @apiParam (RequestBody) {int} sequence //小程序序列号
* @apiParam (RequestBody) {string} reason //原因
* @apiParamExample {json} Request-Example:
* {
* "appId":"61b32654659d2b00016264a8",
* "developerId":"61b32654659d2b00016264a7",
* "sequence": 1,
* "reason":"非法小程序"
* }
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": {},
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
type developerRequest struct {
AppID string `json:"appId" bson:"appId"`
Sequence int `json:"sequence" bson:"sequence"`
DeveloperID string `json:"developerId" bson:"developerId"`
Reason string `json:"reason" bson:"reason"`
}
func DevWithdrawPublishRequest(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := developerRequest{}
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("withdrawPublishRequest bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("withdrawPublishRequest get req:%+v", req)
userId := utility.GetUserId(c)
if userId == "" {
log.Errorf("withdrawPublishRequest get user id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
rsp := service.NewAppService().WithdrawPublishRequest(traceCtx, c, req.AppID, req.Sequence, userId)
rsp.MakeRsp(c, gin.H{})
//c.JSON(http.StatusOK, gin.H{})
}
/**
* @api {POST} /api/v1/mop/finstore/dev/apps/publish [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestBody) {string} appId //小程序id
* @apiParam (RequestBody) {string} developerId //开发者id
* @apiParam (RequestBody) {int} sequence //小程序序列号
* @apiParam (RequestBody) {string} reason //原因
* @apiParamExample {json} Request-Example:
* {
* "appId":"61b32654659d2b00016264a8",
* "developerId":"61b32654659d2b00016264a7",
* "sequence": 1,
* "reason":"非法小程序"
* }
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": {},
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevPublishApp(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := developerRequest{}
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("DevPublishApp bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("DevPublishApp get req:%+v", req)
userId := utility.GetUserId(c)
if userId == "" {
log.Errorf("DevPublishApp user id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
rsp := service.NewAppService().PubApp(traceCtx, req.AppID, req.Sequence, userId)
rsp.MakeRsp(c, gin.H{})
}
/**
* @api {POST} /api/v1/mop/finstore/dev/apps/unpublish [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestBody) {string} appId //小程序id
* @apiParam (RequestBody) {int} sequence //小程序序列号
* @apiParam (RequestBody) {string} reason //原因
* @apiParamExample {json} Request-Example:
* {
* "appId":"61b32654659d2b00016264a8",
* "sequence": 1,
* "reason":"非法小程序"
* }
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": {},
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevUnpublishApp(c *gin.Context) {
unpublishAppHelp(c, true)
}
/**
* @api {POST} /api/v1/mop/finstore/admin/apps/unpublish [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestBody) {string} appId //小程序id
* @apiParam (RequestBody) {int} sequence //小程序序列号
* @apiParam (RequestBody) {string} reason //原因
* @apiParamExample {json} Request-Example:
* {
* "appId":"61b32654659d2b00016264a8",
* "sequence": 1,
* "reason":"非法小程序"
* }
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": {},
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func AdminUnpublishApp(c *gin.Context) {
unpublishAppHelp(c, false)
}
type unpublishRequest struct {
AppID string `json:"appId" bson:"appId"`
Sequence int `json:"sequence" bson:"sequence"`
Reason string `json:"reason" bson:"reason"`
}
func unpublishAppHelp(c *gin.Context, isDev bool) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := unpublishRequest{}
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("unpublishAppHelp bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
userId := utility.GetUserId(c)
svr := service.NewAppService()
rsp := svr.UnpubApp(traceCtx, c, req.AppID, req.Sequence, userId, isDev, req.Reason)
rsp.MakeRsp(c, gin.H{})
}
type approveRequest struct {
AppID string `json:"appId"`
Sequence int `json:"sequence"`
//AdministratorID string `json:"administratorId" bson:"administratorId"`
Status string `json:"status"`
Reason string `json:"reason"`
}
func AdminApproveApp(c *gin.Context) {
approveApp(c, true)
}
/**
* @api {POST} /api/v1/mop/finstore/dev/apps/approval [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestBody) {string} appId //小程序id
* @apiParam (RequestBody) {int} sequence //小程序序列号
* @apiParam (RequestBody) {string} status //状态
* @apiParam (RequestBody) {string} reason //审核原因
* @apiParamExample {json} Request-Example:
* {
* "appId":"61b32654659d2b00016264a8",
* "sequence": 1,
* "status":"PublishApproved", //PublishRejected:拒绝PublishApproved:通过
* "reason":"通过"
* }
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": {},
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevApproveApp(c *gin.Context) {
approveApp(c, false)
}
func approveApp(c *gin.Context, isAdmin bool) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := apiproto.ApproveAppReq{}
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("approveApp bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
req.RequestFrom = c.GetHeader("C-Open-Api")
log.Infof("approveApp get req:%+v,isAdmin:%t requestFrom:%s", req, isAdmin, req.RequestFrom)
userId := utility.GetUserId(c)
svr := service.NewAppService()
rsp := svr.ApproveApp(traceCtx, req, isAdmin, userId)
rsp.MakeRsp(c, gin.H{})
}
/**
* @api {GET} /api/v1/mop/finstore/dev/appInfo/rollbackList?appId=62986e87277a0d00017b782e [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestParam) {string} appId //小程序id
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": [
* {
* "appId": "62986e87277a0d00017b782e",
* "name": "1",
* "appClass": "jinrong",
* "appTag": [
* "zhengquankaihu"
* ],
* "appType": "Applet",
* "status": {
* "value": "Published",
* "reason": "",
* "lastUpdated": 1654157465456,
* "modifiedBy": "自动上架"
* },
* "publishingStatus": {
* "reason": "",
* "lastUpdated": 1654156994088,
* "modifiedBy": "15377373355"
* },
* "unpublishingStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": ""
* },
* "publishingApprovalStatus": {
* "reason": "",
* "lastUpdated": 1654157465436,
* "modifiedBy": "15377373355"
* },
* "unpublishingApprovalStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": ""
* },
* "publishedStatus": {
* "reason": "",
* "lastUpdated": 1654157465456,
* "modifiedBy": "自动上架"
* },
* "unpublishedStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": "",
* "type": ""
* },
* "requestStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": ""
* },
* "approvalStatus": {
* "reason": "",
* "lastUpdated": 1654157465436,
* "modifiedBy": "15377373355"
* },
* "actionStatus": {
* "reason": "",
* "lastUpdated": 1654157465456,
* "modifiedBy": "自动上架"
* },
* "developerId": "628b2215062d300001e36285",
* "groupId": "628b2215062d300001e36286",
* "created": 1654156994088,
* "createdBy": "15377373355",
* "customData": {
* "detailDescription": "",
* "sourceFile": [
* {
* "fileMd5": "159eed6c06432b1a4f68ced6c19a1bfe",
* "name": "app.zip",
* "sourceFileUrl": "/api/v1/mop/netdisk/download/62986eaa1f1afd0001c3698c",
* "uploadDate": 1654156973289,
* "url": "/api/v1/mop/netdisk/download/62986ead1f1afd0001c3698d",
* "encryptedUrl": "/api/v1/mop/netdisk/download/62986ead1f1afd0001c3698e",
* "encryptedFileMd5": "fad7bd98dbcabb560ca30f4c99121a42",
* "encryptedFileSha256": "c9e9db06725f95a4418c83d54dda3499946b8e1c894583b6477a36cc1d796668",
* "basicPackVer": "",
* "Packages": [],
* "EncryptPackages": []
* }
* ],
* "versionDescription": "1.0.0",
* "developer": "15377373355"
* },
* "version": "1.0.0",
* "sequence": 1,
* "corporationId": "",
* "coreDescription": "123",
* "logo": "https://www-cdn.finclip.com/images/ic-default.png",
* "isRollback": false,
* "testInfo": {
* "account": "",
* "password": "",
* "description": "",
* "images": []
* },
* "needAutoPub": true,
* "inGrayRelease": false,
* "expire": 0,
* "appBuildID": "62986ead277a0d00017b782f"
* },
* {...}
* ]
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func RollbackListApps(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
appId := c.Query("appId")
userId := utility.GetUserId(c)
if userId == "" {
log.Errorf("RollbackListApps user id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
svr := service.NewAppService()
appVerList, err := svr.RollbackAppList(traceCtx, appId, userId)
if err != nil {
log.Errorf("RollbackListApps svr err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, appVerList)
return
}
/**
* @api {GET} /api/v1/mop/finstore/dev/apps?bindingId=6298937b277a0d00017b7860&searchText=&searchFields=name&pageSize=10000&pageNo=0 [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestParam) {string} bindingId //应用id
* @apiParam (RequestParam) {string} searchText //模糊匹配内容
* @apiParam (RequestParam) {string} searchFields //小程序id
* @apiParam (RequestParam) {string} pageNo //页码
* @apiParam (RequestParam) {string} pageSize //页大小
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "list": [
* {
* "appId": "62986e87277a0d00017b782e",
* "name": "开户",
* "appClass":"小程序类别",
* "status":{
* "value":"小程序状态"
* },
* {...}
* ]
* "total":100 //总数
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevListApps(c *gin.Context) {
bindingID := c.Query("bindingId")
if bindingID == "" {
listApps(c, true, false, false)
} else {
// MOP
listAppsToBind(c, bindingID)
}
}
func DevGetApp(c *gin.Context) {
appID := c.Param("path1")
getApp(c, appID)
}
func AdminGetApp(c *gin.Context) {
appID := c.Param("path1")
getApp(c, appID)
}
type InternalGetAppReq struct {
AppId string `form:"appId"`
}
func InternalGetApp(c *gin.Context) {
req := InternalGetAppReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("InternalGetApp err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
getApp(c, req.AppId)
}
func getApp(c *gin.Context, appId string) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
if appId == "" {
log.Errorf("getApp appid empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
svr := service.NewAppService()
appVerInfo, err := svr.GetLatestPubAppVer(traceCtx, appId)
if err != nil {
log.Debugf("getApp GetLatestPubAppVer err:%s", err.Error())
if !service.NotFound(err) {
log.Errorf("getApp err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
} else {
utility.MakeLocRsp(c, http.StatusOK, utility.OK, appVerInfo)
return
}
appInfo, err := service.NewAppService().GetAppInfo(traceCtx, appId)
if err != nil {
log.Errorf("getApp db err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_BAD_JSON, gin.H{})
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, appInfo)
}
/**
* @api {GET} /api/v1/mop/finstore/dev/apps/62986e87277a0d00017b782e/inDevelopment [C/S]
* @apiGroup Finclip App Manager
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
{
"data": {
"appId": "62986e87277a0d00017b782e",
"name": "1",
"sequence": 0,
"appClass": "jinrong",
"appTag": [
"zhengquankaihu"
],
"appType": "Applet",
"status": {
"value": "Published",
"reason": "",
"lastUpdated": 1654157465456,
"modifiedBy": "自动上架"
},
"publishedStatus": {
"reason": "",
"lastUpdated": 1654157465456,
"modifiedBy": "自动上架"
},
"unpublishedStatus": {
"reason": "",
"lastUpdated": 0,
"modifiedBy": ""
},
"actionStatus": {
"reason": "",
"lastUpdated": 1654157465456,
"modifiedBy": "自动上架"
},
"developerId": "628b2215062d300001e36285",
"groupId": "628b2215062d300001e36286",
"created": 1654156935640,
"createdBy": "15377373355",
"customData": {
"detailDescription": "",
"sourceFile": [
{
"fileMd5": "159eed6c06432b1a4f68ced6c19a1bfe",
"name": "app.zip",
"sourceFileUrl": "/api/v1/mop/netdisk/download/62986eaa1f1afd0001c3698c",
"uploadDate": 1654156973289,
"url": "/api/v1/mop/netdisk/download/62986ead1f1afd0001c3698d",
"encryptedUrl": "/api/v1/mop/netdisk/download/62986ead1f1afd0001c3698e",
"encryptedFileMd5": "fad7bd98dbcabb560ca30f4c99121a42",
"encryptedFileSha256": "c9e9db06725f95a4418c83d54dda3499946b8e1c894583b6477a36cc1d796668",
"basicPackVer": "",
"Packages": [],
"EncryptPackages": []
}
],
"versionDescription": "1.0.0",
"developer": "15377373355"
},
"version": "1.0.0",
"coreDescription": "123",
"logo": "https://www-cdn.finclip.com/images/ic-default.png",
"testInfo": {
"account": "",
"password": "",
"description": "",
"images": null
},
"expire": 9999999999999,
"isRollback": false,
"applyStatus": "",
"isForbidden": 1,
"privacySettingType": 0
},
"errcode": "OK",
"error": ""
}
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevGetAppInDevelopment(c *gin.Context) {
getAppInDevelopment(c)
}
func AdminGetAppInDevelopment(c *gin.Context) {
getAppInDevelopment(c)
}
func ClientGetAppInDevelopment(c *gin.Context) {
getAppInDevelopment(c)
}
func GetAppInDevelopment(c *gin.Context) {
getAppInDevelopment(c)
}
func getAppInDevelopment(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
appID := c.Param("path1")
if appID == "" {
log.Errorf("getAppInDevelopment appid empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_APPID, gin.H{})
return
}
log.Infof("getAppInDevelopment appId:%s", appID)
appInfo, err := service.NewAppService().GetAppInfoByAppId(traceCtx, appID)
if err != nil {
log.Errorf("getAppInDevelopment err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
latestBuildInfo, err := service.NewAppAppletInfoService().GetLatestInfoByAppId(traceCtx, appID)
if err != nil && !service.NotFound(err) {
log.Errorf("GetLatestInfoByAppId err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
if !service.NotFound(err) && latestBuildInfo != nil {
appInfo.Version = latestBuildInfo.Version
appInfo.CustomData.Developer = latestBuildInfo.CustomData.Developer
appInfo.CustomData.VersionDescription = latestBuildInfo.CustomData.VersionDescription
//appInfo.CustomData.DetailDescription = ""
if len(latestBuildInfo.CustomData.SourceFile) > 0 {
info := latestBuildInfo.CustomData.SourceFile[0]
appInfo.CustomData.SourceFile = append(appInfo.CustomData.SourceFile, entity.CustomDataSourceFile{
FileMd5: info.FileMd5,
Name: info.Name,
SourceFileUrl: info.SourceFileUrl,
UploadDate: info.UploadDate,
Url: info.Url,
EncryptedUrl: info.EncryptedUrl,
EncryptedFileMd5: info.EncryptedFileMd5,
EncryptedFileSha256: info.EncryptedFileSha256,
BasicPackVer: info.BasicPackVer,
Packages: info.Packages,
EncryptPackages: info.EncryptPackages,
})
}
}
//c.JSON(http.StatusOK, appInfo)
utility.MakeLocRsp(c, http.StatusOK, utility.OK, appInfo)
}
type AdminListAppsReq struct {
PageNo int `form:"pageNo"`
PageSize int `form:"pageSize"`
SearchFields string `form:"searchFields"`
SearchText string `form:"searchText"`
PullType string `form:"pullType"`
}
func AdminListApps(c *gin.Context) {
utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{})
}
func AdminListAppsV2(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := AdminListAppsReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("AdminListApps bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
req.PageNo += 1
if req.PageSize == 0 || req.PageSize > 200 {
req.PageSize = 200
}
svr := service.NewAppService()
svrReq := service.ListAppsReq{
PageNo: req.PageNo,
PageSize: req.PageSize,
SearchText: req.SearchText,
PullType: req.PullType,
}
log.Infof("AdminListAppsV2 svr req:%+v", svrReq)
total, apps, err := svr.AdminListApps(traceCtx, &svrReq)
if err != nil {
log.Errorf("AdminListAppsV2 list apps err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
c.JSON(http.StatusOK, gin.H{
"total": total,
"list": apps,
})
}
func AdminListPubApps(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := AdminListAppsReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("AdminListPubApps bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
req.PageNo += 1
if req.PageSize == 0 || req.PageSize > 200 {
req.PageSize = 200
}
svr := service.NewAppService()
svrReq := service.ListAppsReq{
PageNo: req.PageNo,
PageSize: req.PageSize,
SearchText: req.SearchText,
PullType: req.PullType,
}
log.Infof("AdminListPubApps svr req:%+v", svrReq)
total, apps, err := svr.AdminListPubApps(traceCtx, &svrReq)
if err != nil {
log.Errorf("AdminListPubApps list apps err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
c.JSON(http.StatusOK, gin.H{
"total": total,
"list": apps,
})
}
func listApps(c *gin.Context, isDev, isAdmin, isClient bool) {
return
}
func listAppsV2(c *gin.Context, isDev, isAdmin, isClient bool) {
return
}
type listAppsToBindStatus struct {
Value string `json:"value"`
}
type ListAppsToBindRspItem struct {
AppId string `json:"appId"`
Name string `json:"name"`
AppClass string `json:"appClass"`
ApplyStatus string `json:"applyStatus"`
Status listAppsToBindStatus `json:"status"`
}
//获取应用未关联的所有小程序
func listAppsToBind(c *gin.Context, bindingID string) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := apiproto.ListAppsToBindReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("listAppsToBind bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_PARAM_ERR, gin.H{})
return
}
req.PageNo += 1
log.Infof("listAppsToBind req:%+v", req)
svr := service.NewAppService()
total, apps, err := svr.GetAppsToBinding(traceCtx, req)
if err != nil {
log.Errorf("GetAppsToBinding err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_SYSTEM_CALL, gin.H{})
return
}
rspDataList := make([]ListAppsToBindRspItem, 0)
for _, v := range apps {
rspDataList = append(rspDataList, ListAppsToBindRspItem{
AppId: v.AppID,
Name: v.Name,
AppClass: v.AppClass,
ApplyStatus: v.ApplyStatus,
Status: listAppsToBindStatus{v.Status.Value},
})
}
//if config.Cfg.PublishEnv == ENV_FDEP {
// rspData, err = fillApplyStatus(traceCtx, rspData, bindingID)
// if err != nil {
// MakeRsp(c, http.StatusInternalServerError, FS_DB_ERR, gin.H{})
// return
// }
//}
c.JSON(http.StatusOK, gin.H{"total": total, "list": rspDataList})
// utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{})
return
}
type AdminGetAppReviewsRsp struct {
Total int `json:"total"`
List []entity.AppVersion `json:"list"`
}
func AdminGetAppReviews(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := apiproto.AdminGetAppReviewsReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("AdminGetAppReviews bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_PARAM_ERR, gin.H{})
return
}
log.Infof("AdminGetAppReviews req:%+v", req)
rsp := AdminGetAppReviewsRsp{
Total: 0,
List: make([]entity.AppVersion, 0),
}
total, appVers, err := service.NewAppService().AdminGetAppReviews(traceCtx, req)
if err != nil {
if service.NotFound(err) {
utility.MakeLocRsp(c, http.StatusOK, utility.OK, rsp)
return
}
log.Errorf("AdminGetAppReviews db err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
rsp.Total = total
rsp.List = appVers
utility.MakeLocRsp(c, http.StatusOK, utility.OK, rsp)
}
/**
* @api {GET} /api/v1/mop/finstore/dev/statistics/apps?distinct=true&startTime=1&endTime=2&isForbidden=1 [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestParam) {bool} distinct //是否获取分布
* @apiParam (RequestParam) {int} startTime //开始时间
* @apiParam (RequestParam) {int} endTime //结束时间
* @apiParam (RequestParam) {int} isForbidden //是否包含禁用
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "created": 1,
* "submited":2,
* "approved":3,
* "published":4
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevGetStatistics(c *gin.Context) {
getStatistics(c, true)
}
func AdminGetStatistics(c *gin.Context) {
getStatistics(c, false)
}
type getStatisticsReq struct {
Distinct bool `form:"distinct"`
StartTime int64 `form:"startTime"`
EndTime int64 `form:"endTime"`
IsForbidden int `form:"isForbidden,default=2"`
}
type getStatisticsResponse struct {
Created int `json:"created"`
Submited int `json:"submited"`
Approved int `json:"approved"`
Published int `json:"published"`
}
func getStatistics(c *gin.Context, isDev bool) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := getStatisticsReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("getStatistics bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
svr := service.NewAppService()
var groupId string
if isDev {
userId := utility.GetUserId(c)
if userId == "" {
log.Errorf("getStatistics is dev but user id empty")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
accountInfo, err := hCaller.GetAccountInfo(traceCtx, userId)
if err != nil {
log.Errorf("GetAccountInfo err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_SYSTEM_CALL, gin.H{})
return
}
groupId = accountInfo.OrganId
}
rsp, err := svr.AppStatistics(traceCtx, req.StartTime, req.EndTime, groupId, req.Distinct, req.IsForbidden)
if err != nil {
log.Errorf("AppStatistics svr err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
c.JSON(http.StatusOK, rsp)
//utility.MakeLocRsp(c, http.StatusOK, utility.OK, rsp)
}
type DevListAppsAndReviewsReq struct {
ListType string `form:"listType"`
GroupId string `form:"groupId"`
AppId string `form:"appId"`
Query string `form:"query"`
Sort string `form:"sort"`
SearchFields string `form:"searchFields"`
SearchText string `form:"searchText"`
PageSize int `form:"pageSize"`
PageNo int `form:"pageNo"`
ReviewsPageSize int `form:"reviewsPageSize"`
ReviewsPageNo int `form:"reviewsPageNo"`
}
type DevListAppsAndReviewsRsp struct {
Total int `json:"total"`
List []AppsAndReviewRspItem `json:"list"`
}
type ReviewsRsp struct {
Total int `json:"total"`
List []ReviewsRspItem `json:"list"`
}
type AppsAndReviewRspItem struct {
AppId string `json:"appId"`
Name string `json:"name"`
Logo string `json:"logo"`
Version string `json:"version"`
Status string `json:"status"`
ReviewTotal int `json:"reviewTotal"`
ReviewList []ReviewsRspItem `json:"reviewList"`
}
type ReviewsRspItem struct {
Sequence int `json:"sequence"`
Status string `json:"status"`
Version string `json:"version"`
}
func DevListAppsAndReviews(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := DevListAppsAndReviewsReq{}
if err := c.ShouldBindQuery(&req); err != nil {
log.Errorf("DevListAppsAndReviews bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("DevListAppsAndReviews req:%+v", req)
if req.ListType == "" || (req.ListType != "appsAndReviews" && req.ListType != "reviews") {
log.Errorf("DevListAppsAndReviews list type err,type:%s", req.ListType)
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
if req.PageSize == 0 || req.PageSize > 50 {
req.PageSize = 10
}
req.PageNo += 1
if req.ReviewsPageSize == 0 || req.ReviewsPageSize > 50 {
req.ReviewsPageSize = 50
}
data, rsp := service.NewAppService().ListAppAndReviews(traceCtx, req.AppId, req.PageNo, req.PageSize)
rsp.MakeRsp(c, data)
return
}
func AdminGetAppVersion(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
lang := c.Request.Header.Get("lang")
appID := c.Param("path1")
seqStr := c.Param("path3")
if appID == "" {
log.Errorf("AdminGetAppVersion appid empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_APPID, gin.H{})
return
}
sequence, err := strconv.Atoi(seqStr)
if err != nil {
log.Errorf("AdminGetAppVersion sequence err,sequence:%v", seqStr)
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
userId := utility.GetUserId(c)
_, err = hCaller.GetAdminAccountInfo(traceCtx, userId)
if err != nil {
log.Errorf("DevGetAppVersion user id account info err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
appVer, err := service.NewAppService().GetAppVerInfo(traceCtx, appID, sequence)
if err != nil {
log.Errorf("AdminGetAppVersion db err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
if lang == "en" {
if appVer.ActionStatus.ModifiedBy == "自动上架" {
appVer.ActionStatus.ModifiedBy = "system"
}
if appVer.ActionStatus.ModifiedBy == "管理员" {
appVer.ActionStatus.ModifiedBy = "admin"
}
if appVer.PublishedStatus.ModifiedBy == "自动上架" {
appVer.PublishedStatus.ModifiedBy = "system"
}
if appVer.PublishedStatus.ModifiedBy == "管理员" {
appVer.PublishedStatus.ModifiedBy = "admin"
}
if appVer.Status.ModifiedBy == "自动上架" {
appVer.Status.ModifiedBy = "system"
}
if appVer.Status.ModifiedBy == "管理员" {
appVer.Status.ModifiedBy = "admin"
}
if appVer.UnpublishedStatus.ModifiedBy == "自动上架" {
appVer.UnpublishedStatus.ModifiedBy = "system"
}
if appVer.UnpublishedStatus.ModifiedBy == "管理员" {
appVer.UnpublishedStatus.ModifiedBy = "admin"
}
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, appVer)
}
/**
* @api {GET} /api/v1/mop/finstore/dev/apps/62986e87277a0d00017b782e/sequences/9 [C/S]
* @apiGroup Finclip App Manager
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
{
"data": {
"appId": "62986e87277a0d00017b782e",
"name": "1",
"appClass": "jinrong",
"appTag": [
"zhengquankaihu"
],
"appType": "Applet",
"status": {
"value": "PublishApproved",
"reason": "",
"lastUpdated": 1654165268630,
"modifiedBy": "15377373355"
},
"publishingStatus": {
"reason": "",
"lastUpdated": 1654165260773,
"modifiedBy": "15377373355"
},
"unpublishingStatus": {
"reason": "",
"lastUpdated": 0,
"modifiedBy": ""
},
"publishingApprovalStatus": {
"reason": "",
"lastUpdated": 1654165268630,
"modifiedBy": "15377373355"
},
"unpublishingApprovalStatus": {
"reason": "",
"lastUpdated": 0,
"modifiedBy": ""
},
"publishedStatus": {
"reason": "",
"lastUpdated": 0,
"modifiedBy": ""
},
"unpublishedStatus": {
"reason": "",
"lastUpdated": 0,
"modifiedBy": "",
"type": ""
},
"requestStatus": {
"reason": "",
"lastUpdated": 0,
"modifiedBy": ""
},
"approvalStatus": {
"reason": "",
"lastUpdated": 1654165268630,
"modifiedBy": "15377373355"
},
"actionStatus": {
"reason": "",
"lastUpdated": 1654165260773,
"modifiedBy": "15377373355"
},
"developerId": "628b2215062d300001e36285",
"groupId": "628b2215062d300001e36286",
"created": 1654165260773,
"createdBy": "15377373355",
"customData": {
"detailDescription": "",
"sourceFile": [
{
"fileMd5": "159eed6c06432b1a4f68ced6c19a1bfe",
"name": "app.zip",
"sourceFileUrl": "/api/v1/mop/netdisk/download/62986eaa1f1afd0001c3698c",
"uploadDate": 1654156973289,
"url": "/api/v1/mop/netdisk/download/62986ead1f1afd0001c3698d",
"encryptedUrl": "/api/v1/mop/netdisk/download/62986ead1f1afd0001c3698e",
"encryptedFileMd5": "fad7bd98dbcabb560ca30f4c99121a42",
"encryptedFileSha256": "c9e9db06725f95a4418c83d54dda3499946b8e1c894583b6477a36cc1d796668",
"basicPackVer": "",
"Packages": [],
"EncryptPackages": []
}
],
"versionDescription": "1.0.0",
"developer": "15377373355"
},
"version": "1.0.0",
"sequence": 9,
"corporationId": "",
"coreDescription": "123",
"logo": "https://www-cdn.finclip.com/images/ic-default.png",
"isRollback": false,
"testInfo": {
"account": "",
"password": "",
"description": "",
"images": []
},
"needAutoPub": false,
"inGrayRelease": false,
"expire": 0,
"appBuildID": "62986ead277a0d00017b782f"
},
"errcode": "OK",
"error": ""
}
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevGetAppVersion(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
appID := c.Param("path1")
seqStr := c.Param("path3")
lang := c.Request.Header.Get("lang")
if appID == "" {
log.Errorf("DevGetAppVersion appid empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_APPID, gin.H{})
return
}
sequence, err := strconv.Atoi(seqStr)
if err != nil {
log.Errorf("DevGetAppVersion sequence err,sequence:%v", seqStr)
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
userId := utility.GetUserId(c)
accountInfo, err := hCaller.GetAccountInfo(traceCtx, userId)
if err != nil {
log.Errorf("DevGetAppVersion user id account info err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
appVer, err := service.NewAppService().GetAppVerInfo(traceCtx, appID, sequence)
if err != nil {
log.Errorf("DevGetAppVersion db err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
if appVer.GroupID != accountInfo.OrganId {
log.Errorf("DevGetAppVersion organ id not match!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
if lang == "en" {
if appVer.ActionStatus.ModifiedBy == "自动上架" {
appVer.ActionStatus.ModifiedBy = "system"
}
if appVer.ActionStatus.ModifiedBy == "管理员" {
appVer.ActionStatus.ModifiedBy = "admin"
}
if appVer.PublishedStatus.ModifiedBy == "自动上架" {
appVer.PublishedStatus.ModifiedBy = "system"
}
if appVer.PublishedStatus.ModifiedBy == "管理员" {
appVer.PublishedStatus.ModifiedBy = "admin"
}
if appVer.Status.ModifiedBy == "自动上架" {
appVer.Status.ModifiedBy = "system"
}
if appVer.Status.ModifiedBy == "管理员" {
appVer.Status.ModifiedBy = "admin"
}
if appVer.UnpublishedStatus.ModifiedBy == "自动上架" {
appVer.UnpublishedStatus.ModifiedBy = "system"
}
if appVer.UnpublishedStatus.ModifiedBy == "管理员" {
appVer.UnpublishedStatus.ModifiedBy = "admin"
}
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, appVer)
}
type AdminGetAppVerDetailReq struct {
AppId string `uri:"appId"`
Sequence int `uri:"sequence"`
}
type GetAppVerDeTailRsp struct {
AppID string `json:"appId"`
Name string `json:"name"`
GroupName string `json:"groupName"`
}
/**
* @api {GET} /api/v1/mop/finstore/dev/app-ver/62986e87277a0d00017b782e/9 [C/S]
* @apiGroup Finclip App Manager
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": {
* "appId":"62986e87277a0d00017b782e",
* "name":"开户",
* "groupName":"test"
* },
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func AdminGetAppVerDetail(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := AdminGetAppVerDetailReq{}
errRsp := make(map[string]interface{})
if err := c.BindUri(&req); err != nil {
log.Errorf("AdminGetAppVerDetail bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, errRsp)
return
}
appVer, err := service.NewAppService().GetAppVerInfo(traceCtx, req.AppId, req.Sequence)
if err != nil {
log.Errorf("AdminGetAppVerDetail err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, errRsp)
return
}
rspData := GetAppVerDeTailRsp{
AppID: appVer.AppID,
Name: appVer.Name,
GroupName: "",
}
groupInfo, err := hCaller.GetGroupInfoByGroupId(traceCtx, appVer.GroupID)
if err != nil {
log.Errorf("AdminGetAppVerDetail GetGroupInfoByGroupId err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, errRsp)
return
}
rspData.GroupName = groupInfo.GroupName
utility.MakeLocRsp(c, http.StatusOK, utility.OK, rspData)
return
}
//获取小程序关联管理列表
type AdminGetLinkAppletsRspItem struct {
BindingInfo entity.Binding `json:"bindingInfo"`
AppIdInfo entity.AppInfo `json:"appIdInfo"`
}
type AdminGetLinkAppletsReq struct {
PageNo int `form:"pageNo"`
PageSize int `form:"pageSize"`
SearchText string `form:"searchText"`
}
func AdminGetLinkApplets(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := AdminGetLinkAppletsReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("AdminGetLinkApplets bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("AdminGetLinkApplets req:%+v", req)
svr := service.NewAppService()
total, rspData, err := svr.AdminGetLinkApps(traceCtx, req.SearchText, req.PageNo, req.PageSize)
if err != nil {
log.Errorf("AdminGetLinkApplets err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
c.JSON(http.StatusOK, gin.H{
"total": total,
"list": rspData,
})
//utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{})
}
type AdminLinkAppletAuditsReq struct {
PageNo int `form:"pageNo"`
PageSize int `form:"pageSize"`
SearchText string `form:"searchText"`
}
func AdminLinkAppletAudits(c *gin.Context) {
//traceCtx := apm.ApmClient().TraceContextFromGin(c)
//serachTxt := c.Query("searchText")
//
//pageNo, err := strconv.Atoi(c.Query("pageNo"))
//if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_BAD_JSON, err, "param pageNo error", nil)
// return
//}
//pageSize, err := strconv.Atoi(c.Query("pageSize"))
//if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_BAD_JSON, err, "param pageSize error", nil)
// return
//}
//
//applyStatusStr := c.Query("applyStatus")
//var applyStatus []string
//if applyStatusStr != "" {
// applyStatus = strings.Split(applyStatusStr, ",")
//}
//
//models, total, err := service.LinkAppletAudits(traceCtx, serachTxt, pageNo, pageSize, applyStatus)
//if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_DB_ERR, err, "", nil)
// return
//}
//
//MakeRsp(c, http.StatusOK, OK, gin.H{
// "total": total,
// "list": models,
//})
}
type AdminLinkAppletAuditDetailReq struct {
AuditId string `form:"auditId"`
}
func AdminLinkAppletAuditDetail(c *gin.Context) {
//traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := AdminLinkAppletAuditDetailReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("AdminLinkAppletAuditDetail bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("AdminLinkAppletAuditDetail req:%+v", req)
//auditId := c.Query("auditId")
//if auditId == "" {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_PARAM_ERR, nil, "auditId can not be null", nil)
// return
//}
//
//audit, err := service.LinkAppletAudit(traceCtx, auditId)
//if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_DB_ERR, err, "", nil)
// return
//}
//
//appTable := db.NewTable(db.TableApp)
//apps := make([]model.App, 0)
//if _, err := appTable.GetSome(traceCtx, bson.M{"appId": audit.AppId}, []string{"-Sequence"}, 1, 0, &apps); err != nil || len(apps) == 0 {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_DB_ERR, err, "", nil)
// return
//}
//app := apps[0]
//
//t := db.NewTable(db.TableAppVersion)
//appVerInfo := model.AppVersion{}
//if err := t.GetOne(traceCtx, bson.M{"appId": app.AppID, "sequence": app.Sequence}, &appVerInfo); err != nil {
// return
//}
//if t.NotFound() {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_APP_SEQUENCE_NOT_FOUND, err, "RuntimeGetAppVersionInfo get appVer not found!", nil)
// return
//}
//
//bindingTable := db.NewTable(db.TableBinding)
//bindingInfo := model.Binding{}
//err = bindingTable.GetOne(traceCtx, bson.M{"bindingId": audit.BindingId}, &bindingInfo)
//if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_DB_ERR, err, "", nil)
// return
//}
//
//appDetail := model.AppDetail{}
//appDetail.AppId = app.AppID
//appDetail.Name = app.Name
//appDetail.Logo = app.Logo
//appDetail.AppClass = app.AppClass
//appDetail.AppTag = app.AppTag
//appDetail.CoreDescription = app.CoreDescription
//appDetail.Version = app.Version
//appDetail.CustomData = app.CustomData
//appDetail.TestInfo = app.TestInfo
//appDetail.Created = appVerInfo.Created
//appDetail.Sequence = app.Sequence
//
//bindingDetail := model.BindingDetail{}
//bindingDetail.Name = bindingInfo.Name
//bindingDetail.BindingId = bindingInfo.BindingID
//bindingDetail.GroupID = bindingInfo.GroupID
//bindingDetail.CreatedAt = bindingInfo.CreatedInfo.CreatedAt
//bindingDetail.GroupName = bindingInfo.GroupName
//bindingDetail.BundleInfos = bindingInfo.BundleInfos
//
//audit.AppDetail = &appDetail
//audit.BindingDetail = &bindingDetail
//
//MakeRsp(c, http.StatusOK, OK, audit)
}
type auditOperateReq struct {
Operate string `json:"operate"`
AuditId string `json:"auditId"`
Reason string `json:"reason"`
}
func AdminLinkAppletAuditOperate(c *gin.Context) {
//traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := auditOperateReq{}
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("AdminLinkAppletAuditOperate bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("AdminLinkAppletAuditOperate req:%+v", req)
//if req.AuditId == "" {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_PARAM_ERR, nil, "auditId can not be null", nil)
// return
//}
//
//if req.Operate != StLinkAuditRejected && req.Operate != StLinkAuditApplied {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_PARAM_ERR, nil, "operate invalid with:"+req.Operate, nil)
// return
//}
//
//developerID := c.Request.Header.Get("X-Consumer-Custom-ID")
//accountInfo, err := provider.GetAdminAccountInfo(traceCtx, c, developerID)
//if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_GET_ACCOUNTINFO_ERROR, err, "", nil)
// return
//}
//
//err = service.LinkAppletAuditUpdateOperateStatus(traceCtx, req.AuditId, req.Operate, accountInfo.Account, req.Reason)
//if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_DB_ERR, err, "", nil)
// return
//}
//
//audit, err := service.LinkAppletAudit(traceCtx, req.AuditId)
//if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_DB_ERR, err, "", nil)
// return
//}
//
//if req.Operate == StLinkAuditApplied {
// bindingTable := db.NewTable(db.TableBinding)
// bindingInfo := model.Binding{}
// err := bindingTable.GetOne(traceCtx, bson.M{"bindingId": audit.BindingId}, &bindingInfo)
// if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_DB_ERR, err, "", nil)
// return
// }
//
// err = associate(c, []string{audit.AppId}, &bindingInfo, audit.GroupID, audit.AuditBy)
// if err != nil {
// return
// }
//}
//linkAuditNotify(traceCtx, &audit, req.Operate, req.Reason)
//linkAuditSmsNotify(traceCtx, c, &audit, req.Operate)
//
//MakeRsp(c, http.StatusOK, OK, nil)
//return
}
type associateOperateReq struct {
Operate string `json:"operate"`
AppId string `json:"appId"`
BindingId string `json:"bindingId"`
GroupId string `json:"groupId"`
Account string `json:"account"`
}
func AdminAssociateOperate(c *gin.Context) {
//traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := associateOperateReq{}
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("AdminAssociateOperate bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
if req.Operate != entity.StLinkAuditAssociate && req.Operate != entity.StLinkAuditUnAssociate {
log.Errorf("AdminAssociateOperate operate invalid !")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
if req.AppId == "" || req.BindingId == "" {
log.Errorf("appId&bindingId can not be null!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_PARAM_ERR, gin.H{})
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{})
//bindingTable := db.NewTable(db.TableBinding)
//bindingInfo := model.Binding{}
//err := bindingTable.GetOne(traceCtx, bson.M{"bindingId": req.BindingId}, &bindingInfo)
//if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_DB_ERR, err, "", nil)
// return
//}
//
//if req.Operate == StLinkAuditAssociate {
// err = associate(c, []string{req.AppId}, &bindingInfo, req.GroupId, req.Account)
//} else {
// err = disassociate(c, []string{req.AppId}, &bindingInfo, req.GroupId, req.Account)
//}
//
//if err != nil {
// return
//}
//
//MakeRsp(c, http.StatusOK, OK, nil)
//return
}
func AdminGetAppClassPer(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
status := c.Param("status")
tp := c.DefaultQuery("tp", "query")
log.Infof("AdminGetAppClassPer get status:%s,tp:%s", status, tp)
svr := service.NewAppService()
rspData, err := svr.GetAppClassPer(traceCtx, status)
if err != nil {
log.Errorf("AdminGetAppClassPer err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
log.Infof("AdminGetAppClassPer rsp:%+v", rspData)
if tp == "export" {
content, err := Export(traceCtx, *rspData, status)
if err != nil {
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_EXPORT_APP_CLASS_ERR, gin.H{})
return
} else {
fileName := fmt.Sprintf("app.class.%s.xlsx", time.Now().Format("20060102"))
c.Header("Content-Disposition", `attachment; filename=`+fileName)
contentType := "application/vnd.ms-excel"
c.Data(http.StatusOK, contentType, content)
}
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, rspData)
return
}
func GetLatestAppVerInfo(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
appId := c.Query("appId")
if appId == "" {
log.Errorf("GetLatestAppVerInfo app id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
svr := service.NewAppService()
appVerInfo, err := svr.GetMaxSeqAppVer(traceCtx, appId)
if err != nil {
log.Errorf("GetLatestAppVerInfo db err:%s", err.Error())
if service.NotFound(err) {
utility.MakeLocRsp(c, http.StatusOK, utility.FS_NOT_FOUND, gin.H{})
} else {
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
}
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, appVerInfo)
}
//获取最新上下架小程序版本详情
func GetLatestPubAppVerInfo(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
appId := c.Query("appId")
lang := c.Request.Header.Get("lang")
if appId == "" {
log.Errorf("GetLatestPubAppVerInfo app id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("GetLatestPubAppVerInfo appId:%s", appId)
svr := service.NewAppService()
appVerInfo, err := svr.GetLatestPubAppVer(traceCtx, appId)
if err != nil {
log.Errorf("GetLatestAppVerInfo db err:%s", err.Error())
if service.NotFound(err) {
utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{})
} else {
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
}
return
}
if lang == "en" {
if appVerInfo.ActionStatus.ModifiedBy == "自动上架" {
appVerInfo.ActionStatus.ModifiedBy = "system"
}
if appVerInfo.ActionStatus.ModifiedBy == "管理员" {
appVerInfo.ActionStatus.ModifiedBy = "admin"
}
if appVerInfo.PublishedStatus.ModifiedBy == "自动上架" {
appVerInfo.PublishedStatus.ModifiedBy = "system"
}
if appVerInfo.PublishedStatus.ModifiedBy == "管理员" {
appVerInfo.PublishedStatus.ModifiedBy = "admin"
}
if appVerInfo.Status.ModifiedBy == "自动上架" {
appVerInfo.Status.ModifiedBy = "system"
}
if appVerInfo.Status.ModifiedBy == "管理员" {
appVerInfo.Status.ModifiedBy = "admin"
}
if appVerInfo.UnpublishedStatus.ModifiedBy == "自动上架" {
appVerInfo.UnpublishedStatus.ModifiedBy = "system"
}
if appVerInfo.UnpublishedStatus.ModifiedBy == "管理员" {
appVerInfo.UnpublishedStatus.ModifiedBy = "admin"
}
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, appVerInfo)
}
type TitleClass struct {
Name string
Type string
}
type ExportAppClass struct {
}
func Export(ctx context.Context, data service.GetAppClassPerRsp, status string) ([]byte, error) {
return fillData(ctx, data, status)
}
func export(titlesClass []TitleClass, matrix [][]string) ([]byte, error) {
file := xlsx.NewFile()
titles := []string{}
for _, t := range titlesClass {
titles = append(titles, t.Name)
}
sheet, err := addSheet(file, "Sheet1", titles)
if err != nil {
return nil, err
}
for _, cells := range matrix {
row := sheet.AddRow()
for idx, value := range cells {
cell := row.AddCell()
if titlesClass[idx].Type == "int" {
intVal, _ := strconv.Atoi(value)
cell.SetInt(intVal)
} else if titlesClass[idx].Type == "percent" {
float64Val, _ := strconv.ParseFloat(value, 64)
cell.SetFloatWithFormat(float64Val, "0.00%")
} else {
cell.Value = value
}
}
}
buf := new(bytes.Buffer)
file.Write(buf)
return buf.Bytes(), nil
}
func addSheet(file *xlsx.File, name string, titles []string) (*xlsx.Sheet, error) {
if file == nil {
return nil, errors.New("xlsx file is nil")
}
sheet, err := file.AddSheet(name)
if err != nil {
return nil, err
}
row := sheet.AddRow()
var cell *xlsx.Cell
for _, title := range titles {
cell = row.AddCell()
cell.Value = title
}
return sheet, nil
}
func fillData(ctx context.Context, data service.GetAppClassPerRsp, status string) ([]byte, error) {
if status == "published" {
status = "是"
} else {
status = "否"
}
titles := []TitleClass{{"小程序类型", "string"}, {"是否只看上架中的小程序", "string"}, {"数量", "int"}, {"占比", "percent"}}
total := 0
matrix := [][]string{}
for _, item := range data.List {
total += item.Count
}
for _, item := range data.List {
cells := []string{}
if item.AppClassName == "" {
cells = append(cells, item.AppClass)
} else {
cells = append(cells, item.AppClassName)
}
cells = append(cells, status)
cells = append(cells, strconv.Itoa(item.Count))
cells = append(cells, fmt.Sprintf("%.4f", float64(item.Count)/float64(total)))
matrix = append(matrix, cells)
}
return export(titles, matrix)
}
type DevGetappReviewTrendDataReq struct {
StartTime int64 `form:"startTime"`
EndTime int64 `form:"endTime"`
}
type DevGetappReviewTrendDataResultItem struct {
Date string `bson:"_id" json:"date"`
Num int `bson:"num" json:"num"`
}
type DevGetappReviewTrendDataRsp struct {
ErrCode string `json:"errcode"`
Error string `json:"error"`
Data map[string]interface{} `json:"data"`
}
func DevGetappReviewTrendData(c *gin.Context) {
//traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := DevGetappReviewTrendDataReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("DevGetappReviewTrendData bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_PARAM_ERR, gin.H{})
return
}
if req.StartTime >= req.EndTime || req.EndTime <= 0 {
log.Errorf("DevGetappReviewTrendData time value err!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_PARAM_ERR, gin.H{})
return
}
//rspData := make(map[string]interface{})
//daysArry := GetTimeRangeDays(req.StartTime, req.EndTime)
//fmt.Println("days arry", daysArry)
////首先拉取start之前的累计数据
//t := db.NewTable(db.TableAppVersion)
//beforeMatchGrand := bson.M{
// "status.value": bson.M{"$nin": []string{StInDevelopment, StPublishing, StPublishWithdrawed}},
// //"approvalStatus.lastUpdated": bson.M{"$lte": req.StartTime - (24 * 60 * 60 * 1000)}, //获取前一天的时间
// "approvalStatus.lastUpdated": bson.M{"$lte": req.StartTime}, //获取前一天的时间
// "sequence": bson.M{"$ne": 0},
//}
//beforeGroup := bson.M{
// "_id": nil,
// "total": bson.M{"$sum": 1},
//}
//beforeResultList := make([]db.TotalInfo, 0)
//beforePipe := []bson.M{
// {"$match": beforeMatchGrand},
// {"$group": beforeGroup},
//}
//err := t.AggregateOnly(traceCtx, beforePipe, &beforeResultList)
//if err != nil {
// LogAndSetErrResp(c, http.StatusInternalServerError, FS_DB_ERR, err, "Failed to get appVersion before total", nil)
// return
//}
//fmt.Println("before total:", beforeResultList)
//beforeResult := db.TotalInfo{}
//if len(beforeResultList) > 0 {
// beforeResult = beforeResultList[0]
//}
////拉取累计审核的每天的数据
//matchGrand := bson.M{
// "status.value": bson.M{"$nin": []string{StInDevelopment, StPublishing, StPublishWithdrawed}},
// //如果开始时间=结束时间实际取得是这一天0:0:0 -- 23:59:59
// "approvalStatus.lastUpdated": bson.M{"$gte": req.StartTime, "$lte": req.EndTime},
// "sequence": bson.M{"$ne": 0},
//}
//projectGrand := bson.M{
// "statusValue": "$status.value",
// "formatTime": bson.M{
// "$dateToString": bson.M{
// "format": "%Y-%m-%d",
// "date": bson.M{"$add": []interface{}{time.Date(1970, 1, 1, 8, 0, 0, 0, time.Local), "$approvalStatus.lastUpdated"}},
// },
// },
//}
//groupGrand := bson.M{
// "_id": "$formatTime",
// "num": bson.M{"$sum": 1},
//}
//countFilter := []bson.M{
// {"$match": matchGrand},
//}
//countFilter = append(countFilter, bson.M{
// "$group": bson.M{
// "_id": nil,
// "total": bson.M{
// "$sum": 1,
// },
// },
//})
//pipeFilter := []bson.M{
// {"$match": matchGrand},
// {"$project": projectGrand},
// {"$group": groupGrand},
// {"$sort": bson.M{"_id": 1}},
//}
//result := make([]DevGetappReviewTrendDataResultItem, 0)
//total, err := t.Aggregate(traceCtx, countFilter, pipeFilter, &result)
//if err != nil && !t.NotFound() {
// LogAndSetErrResp(c, http.StatusInternalServerError, FS_DB_ERR, err, "Failed to get appVersion", nil)
// return
//}
//rspData["trendTotal"] = total
//fmt.Printf("get data,count:%d,result:%+v\n", total, result)
////所有的日期+数据需要都返回给前端
//trendRspItemsTemp := make([]DevGetappReviewTrendDataResultItem, 0)
//for _, v := range daysArry {
// foundV := false
// var foundItem DevGetappReviewTrendDataResultItem
// for _, item := range result {
// if item.Date == v {
// foundV = true
// foundItem = item
// }
// }
// if !foundV {
// foundItem = DevGetappReviewTrendDataResultItem{
// Date: v,
// Num: 0,
// }
// }
// trendRspItemsTemp = append(trendRspItemsTemp, foundItem)
//}
////第一天需要加上之前的所有
//if len(trendRspItemsTemp) > 0 {
// trendRspItemsTemp[0].Num += beforeResult.Total
//}
////累计审核
//var preResultTotal int
//var foundItem DevGetappReviewTrendDataResultItem
//trendRspItems := make([]DevGetappReviewTrendDataResultItem, 0)
//isFirst := true
//for _, v := range trendRspItemsTemp {
// if isFirst {
// foundItem = DevGetappReviewTrendDataResultItem{Date: v.Date, Num: v.Num}
// preResultTotal = v.Num
// isFirst = false
// } else {
// foundItem = DevGetappReviewTrendDataResultItem{Date: v.Date, Num: preResultTotal + v.Num}
// preResultTotal = foundItem.Num
// }
// trendRspItems = append(trendRspItems, foundItem)
//}
////新增审核
//var preItem DevGetappReviewTrendDataResultItem
//AddNewRspItems := make([]DevGetappReviewTrendDataResultItem, 0)
//isFirst = true
//for _, item := range trendRspItems {
// if isFirst {
// foundItem = DevGetappReviewTrendDataResultItem{Num: 0, Date: item.Date}
// isFirst = false
// } else {
// foundItem = DevGetappReviewTrendDataResultItem{Num: item.Num - preItem.Num, Date: item.Date}
// }
// preItem = item
// AddNewRspItems = append(AddNewRspItems, foundItem)
//}
//
//rspData["trend"] = trendRspItems
//rspData["addNew"] = AddNewRspItems
//
////rsp := DevGetappReviewTrendDataRsp{}
////rsp.ErrCode = "OK"
////rsp.Error = ""
////rsp.Data = rspData
//c.JSON(http.StatusOK, rspData)
}
type AdminListInDevAppHandReq struct {
PullType string `form:"pullType"`
PageNo int `form:"pageNo"`
PageSize int `form:"pageSize"`
SearchTxt string `form:"searchTxt"`
SortType string `form:"sortType"`
}
type AdminListInDevAppHandRspItem struct {
AppId string `json:"appId"`
Name string `json:"name"`
}
/**
* @api {GET} /api/v1/mop/finstore/admin//apps-v2/in-development?pageNo=1&pageSize=10&searchTxt=&sortType=created&pullType=dev-list [C/S]获取小程序开发列表【运营端】
* @apiGroup Finclip App Manager
* @apiParam (RequestParam) {string} pageNo //页码
* @apiParam (RequestParam) {string} pageSize //页大小
* @apiParam (RequestParam) {string} sortType //排序类型
* @apiParam (RequestParam) {string} pullType //指定类别条件
* @apiParam (RequestParam) {string} searchTxt //搜索内容
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
{
"data": {
"total": 1,
"list": [
{
"appId": "62986e87277a0d00017b782e",
"name":"开户"
}
]
},
"errcode": "OK",
"error": ""
}
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func AdminListInDevAppHand(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := AdminListInDevAppHandReq{}
if err := c.Bind(&req); err != nil {
log.Errorf("AdminListInDevAppHand bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
if req.PageSize == 0 {
req.PageSize = 50
}
if req.SortType == "" {
req.SortType = "-created"
}
req.PageNo += 1
svrReq := service.ListAppsReq{
PullType: req.PullType,
SortType: req.SortType,
PageNo: req.PageNo,
PageSize: req.PageSize,
SearchText: req.SearchTxt,
UserId: "",
IsDev: false,
}
log.Infof("AdminListInDevAppHand req:%+v", svrReq)
svr := service.NewAppService()
total, apps, err := svr.AdminListApps(traceCtx, &svrReq)
if err != nil {
log.Errorf("AdminListInDevAppHand err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
rspData := make(map[string]interface{})
rspData["total"] = total
list := make([]AdminListInDevAppHandRspItem, 0)
for _, v := range apps {
list = append(list, AdminListInDevAppHandRspItem{
Name: v.Name,
AppId: v.AppID,
})
}
rspData["list"] = list
utility.MakeLocRsp(c, http.StatusOK, utility.OK, rspData)
return
}
type GetAppGroupIdRsp struct {
GroupID string `json:"groupId"`
Name string `json:"name"`
Logo string `json:"logo"`
CoreDescription string `json:"coreDescription"`
Version string `json:"version" bson:"version"`
Sequence int `json:"sequence" bson:"sequence"`
}
func GetAppGroupIdByAppId(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
appId := c.Param("appId")
if appId == "" {
log.Errorf("GetAppInFoByAppId appId id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
appInfo, err := service.NewAppService().GetAppInfo(traceCtx, appId)
if err != nil {
log.Errorf("getApp db err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_BAD_JSON, gin.H{})
return
}
rsp := GetAppGroupIdRsp{}
rsp.GroupID = appInfo.GroupID
rsp.Name = appInfo.Name
rsp.Logo = appInfo.Logo
rsp.CoreDescription = appInfo.CoreDescription
rsp.Sequence = appInfo.Sequence
rsp.Version = appInfo.Version
//log.Debugln("GetAppInFoByAppIdRsp", rsp)
utility.MakeLocRsp(c, http.StatusOK, utility.OK, rsp)
return
}
func UpdateHistoryAppMsg(c *gin.Context) {
//traceCtx := apm.ApmClient().TraceContextFromGin(c)
//err := client.NotifySpider{}.UpdateHistoryAppMsg(traceCtx)
//if err != nil {
// log.Errorf("UpdateHistoryAppMsg err:%s", err.Error())
//}
//MakeRsp(c, http.StatusOK, common.OK, nil)
return
}
func UpdateAppInfo(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := apiproto.UpdateAppInfoReq{}
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("UpdateAppInfo bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("UpdateAppInfo get req:%+v", req)
if req.AppId == "" {
log.Errorf("UpdateAppInfo appId empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_APPID, gin.H{})
return
}
userId := utility.GetUserId(c)
if userId == "" {
log.Errorf("UpdateAppInfo user id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_PARAM_ERR, gin.H{})
return
}
if len(req.UpInfo.CustomData.SourceFile) == 0 {
log.Errorf("UpdateAppInfo SourceFile empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_PARAM_ERR, gin.H{})
return
}
err := service.NewAppService().UpdateBuildInfo(traceCtx, c, userId, req)
if err != nil {
log.Errorf("UpdateBuildInfo err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{})
return
}
type listAppVersionsReq struct {
PageNo int `form:"pageNo"`
PageSize int `form:"pageSize"`
SearchText string `form:"searchText"`
DeveloperId string `form:"developerId"`
}
/*
?appId=&status=Deleted,InDevelopment&isIncludeStatus=false&pageNo=0&pageSize=10&sort=-publishingStatusLastUpdated&searchFields=&searchText=
*/
func DevListAppVersions(c *gin.Context) {
//listAppVersions(c, true, false)
return
}
/**
* @api {GET} /api/v1/mop/finstore/dev/apps/sequences-v2?appId=62986e87277a0d00017b782e&pageNo=0&pageSize=100&sort=-sequence&searchFields=&searchText= [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestParam) {string} appId //小程序id
* @apiParam (RequestParam) {string} pageNo //页码
* @apiParam (RequestParam) {string} pageSize //页大小
* @apiParam (RequestParam) {string} sort //排序类型
* @apiParam (RequestParam) {string} searchFields //搜索域
* @apiParam (RequestParam) {string} searchText //搜索内容
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "list": [
* {
* "appId": "62986e87277a0d00017b782e",
* "name": "1",
* "appClass": "jinrong",
* "appTag": [
* "zhengquankaihu"
* ],
* "appType": "Applet",
* "status": {
* "value": "Published",
* "reason": "",
* "lastUpdated": 1654157465456,
* "modifiedBy": "自动上架"
* },
* "publishingStatus": {
* "reason": "",
* "lastUpdated": 1654156994088,
* "modifiedBy": "15377373355"
* },
* "unpublishingStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": ""
* },
* "publishingApprovalStatus": {
* "reason": "",
* "lastUpdated": 1654157465436,
* "modifiedBy": "15377373355"
* },
* "unpublishingApprovalStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": ""
* },
* "publishedStatus": {
* "reason": "",
* "lastUpdated": 1654157465456,
* "modifiedBy": "自动上架"
* },
* "unpublishedStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": "",
* "type": ""
* },
* "requestStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": ""
* },
* "approvalStatus": {
* "reason": "",
* "lastUpdated": 1654157465436,
* "modifiedBy": "15377373355"
* },
* "actionStatus": {
* "reason": "",
* "lastUpdated": 1654157465456,
* "modifiedBy": "自动上架"
* },
* "developerId": "628b2215062d300001e36285",
* "groupId": "628b2215062d300001e36286",
* "created": 1654156994088,
* "createdBy": "15377373355",
* "customData": {
* "detailDescription": "",
* "sourceFile": [
* {
* "fileMd5": "159eed6c06432b1a4f68ced6c19a1bfe",
* "name": "app.zip",
* "sourceFileUrl": "/api/v1/mop/netdisk/download/62986eaa1f1afd0001c3698c",
* "uploadDate": 1654156973289,
* "url": "/api/v1/mop/netdisk/download/62986ead1f1afd0001c3698d",
* "encryptedUrl": "/api/v1/mop/netdisk/download/62986ead1f1afd0001c3698e",
* "encryptedFileMd5": "fad7bd98dbcabb560ca30f4c99121a42",
* "encryptedFileSha256": "c9e9db06725f95a4418c83d54dda3499946b8e1c894583b6477a36cc1d796668",
* "basicPackVer": "",
* "Packages": [],
* "EncryptPackages": []
* }
* ],
* "versionDescription": "1.0.0",
* "developer": "15377373355"
* },
* "version": "1.0.0",
* "sequence": 1,
* "corporationId": "",
* "coreDescription": "123",
* "logo": "https://www-cdn.finclip.com/images/ic-default.png",
* "isRollback": false,
* "testInfo": {
* "account": "",
* "password": "",
* "description": "",
* "images": []
* },
* "needAutoPub": true,
* "inGrayRelease": false,
* "expire": 0,
* "appBuildID": "62986ead277a0d00017b782f"
* },
* {...}
* ]
* "total": 100
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func NewDevListAppSeqList(c *gin.Context) {
newGetAppVerList(c, "dev")
}
type AdminListAppSeqListReq struct {
PageNo int `form:"pageNo"`
PageSize int `form:"pageSize"`
SearchText string `form:"searchText"`
Type string `form:"type"`
OrganTraceId string `form:"organTraceId"`
}
/**
* @api {GET} /api/v1/mop/finstore/dev/apps/audit/list?pageNo=0&pageSize=100&type=pendingReview&organTraceId=24234&searchText= [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestParam) {string} pageNo //页码
* @apiParam (RequestParam) {string} pageSize //页大小
* @apiParam (RequestParam) {string} type //类型pendingReview待审核reviewed已审核revoked已撤销
* @apiParam (RequestParam) {string} organTraceId //企业id
* @apiParam (RequestParam) {string} searchText //搜索内容
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "list": [
* {
* "appId": "62986e87277a0d00017b782e",
* "name": "1",
* "appClass": "jinrong",
* "appTag": [
* "zhengquankaihu"
* ],
* "appType": "Applet",
* "status": {
* "value": "Published",
* "reason": "",
* "lastUpdated": 1654157465456,
* "modifiedBy": "自动上架"
* },
* "publishingStatus": {
* "reason": "",
* "lastUpdated": 1654156994088,
* "modifiedBy": "15377373355"
* },
* "unpublishingStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": ""
* },
* "publishingApprovalStatus": {
* "reason": "",
* "lastUpdated": 1654157465436,
* "modifiedBy": "15377373355"
* },
* "unpublishingApprovalStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": ""
* },
* "publishedStatus": {
* "reason": "",
* "lastUpdated": 1654157465456,
* "modifiedBy": "自动上架"
* },
* "unpublishedStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": "",
* "type": ""
* },
* "requestStatus": {
* "reason": "",
* "lastUpdated": 0,
* "modifiedBy": ""
* },
* "approvalStatus": {
* "reason": "",
* "lastUpdated": 1654157465436,
* "modifiedBy": "15377373355"
* },
* "actionStatus": {
* "reason": "",
* "lastUpdated": 1654157465456,
* "modifiedBy": "自动上架"
* },
* "developerId": "628b2215062d300001e36285",
* "groupId": "628b2215062d300001e36286",
* "created": 1654156994088,
* "createdBy": "15377373355",
* "customData": {
* "detailDescription": "",
* "sourceFile": [
* {
* "fileMd5": "159eed6c06432b1a4f68ced6c19a1bfe",
* "name": "app.zip",
* "sourceFileUrl": "/api/v1/mop/netdisk/download/62986eaa1f1afd0001c3698c",
* "uploadDate": 1654156973289,
* "url": "/api/v1/mop/netdisk/download/62986ead1f1afd0001c3698d",
* "encryptedUrl": "/api/v1/mop/netdisk/download/62986ead1f1afd0001c3698e",
* "encryptedFileMd5": "fad7bd98dbcabb560ca30f4c99121a42",
* "encryptedFileSha256": "c9e9db06725f95a4418c83d54dda3499946b8e1c894583b6477a36cc1d796668",
* "basicPackVer": "",
* "Packages": [],
* "EncryptPackages": []
* }
* ],
* "versionDescription": "1.0.0",
* "developer": "15377373355"
* },
* "version": "1.0.0",
* "sequence": 1,
* "corporationId": "",
* "coreDescription": "123",
* "logo": "https://www-cdn.finclip.com/images/ic-default.png",
* "isRollback": false,
* "testInfo": {
* "account": "",
* "password": "",
* "description": "",
* "images": []
* },
* "needAutoPub": true,
* "inGrayRelease": false,
* "expire": 0,
* "appBuildID": "62986ead277a0d00017b782f"
* },
* {...}
* ]
* "total": 100
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func AdminListAppSeqList(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := AdminListAppSeqListReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("listAppVersions bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("AdminListAppSeqList req:%+v", req)
req.PageNo += 1
total, list, err := service.NewAppService().AdminListAppVer(traceCtx, req.PageNo, req.PageSize, req.SearchText, req.Type, req.OrganTraceId)
if err != nil {
log.Errorf("AdminListAppSeqList err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
c.JSON(http.StatusOK, gin.H{"list": list, "total": total})
}
func AdminListAppVersions(c *gin.Context) {
listAppVersions(c, false, true)
}
func listAppVersions(c *gin.Context, isDev, isAdmin bool) {
//traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := apiproto.ListAppsToBindReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("listAppVersions bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
//queryFilter, sortFilter, searchFilter, pageSize, pageNo, err := GetCommonParam(c)
//if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_BAD_JSON, err, "Failed to get params", nil)
// return
//}
//if len(sortFilter) == 0 {
// sortFilter = []string{"-created"}
//}
//baseFilter := bson.M{}
//calledByDev := isDev
//operatorID := ""
//if isDev || isAdmin || isClient {
// operatorID = c.Request.Header.Get("x-consumer-custom-id")
//} else if developerID != "" {
// operatorID = developerID
// calledByDev = true
//}
//if calledByDev {
// groupID, err := provider.GetGroupID(traceCtx, c, operatorID)
// if err != nil {
// LogAndSetErrResp(c, http.StatusInternalServerError, FS_GET_GROUP_FAILED, err, operatorID, nil)
// return
// }
// baseFilter = bson.M{
// "groupId": groupID,
// "sequence": bson.M{"$ne": 0},
// "status.value": bson.M{"$ne": StDeleted},
// }
//} else {
// baseFilter = bson.M{
// "sequence": bson.M{"$ne": 0},
// "status.value": bson.M{"$ne": StDeleted},
// }
//}
//
//filter := baseFilter
//if len(searchFilter) > 0 {
// filter = bson.M{"$and": []bson.M{filter, searchFilter}}
//}
//if len(queryFilter) > 0 {
// filter = bson.M{"$and": []bson.M{filter, queryFilter}}
//}
//appVers := make([]model.AppVersion, 0)
//t := db.NewTable(db.TableAppVersion)
//total, err := t.GetSome(traceCtx, filter, sortFilter, pageSize, pageNo, &appVers)
//if err != nil {
// LogAndSetErrResp(c, http.StatusInternalServerError, FS_DB_ERR, err, "Failed to get appVersion", nil)
// return
//}
//c.JSON(http.StatusOK, gin.H{
// "total": total,
// "list": appVers,
//})
}
func newGetAppVerList(c *gin.Context, t string) {
var (
traceCtx = apm.ApmClient().TraceContextFromGin(c)
req = apiproto.ListAppVerReq{}
)
if err := c.BindQuery(&req); err != nil {
log.Errorf("list app ver bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("get app seq req:%+v", req)
if req.PageSize == 0 {
req.PageSize = 100
}
req.PageNo += 1
svr := service.NewAppService()
total, appVers, err := svr.ListAppVer(traceCtx, req.AppId, req.PageNo, req.PageSize)
if err != nil {
log.Errorf("ListAppVer err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
rsp := make(map[string]interface{})
rsp["total"] = total
rsp["list"] = appVers
c.JSON(http.StatusOK, rsp)
//utility.MakeLocRsp(c, http.StatusOK, utility.OK, rsp)
}
type ListAppsInDevelopmentReq struct {
GroupId string `form:"groupId"`
}
func DevListAppsInDevelopment(c *gin.Context) {
listAppsInDevelopment(c, true, false, false)
}
func AdminListAppsInDevelopment(c *gin.Context) {
listAppsInDevelopment(c, false, true, false)
}
func ClientListAppsInDevelopment(c *gin.Context) {
listAppsInDevelopment(c, false, false, true)
}
func ListAppsInDevelopment(c *gin.Context) {
listAppsInDevelopment(c, false, false, false)
}
func listAppsInDevelopment(c *gin.Context, isDev, isAdmin, isClient bool) {
//traceCtx := apm.ApmClient().TraceContextFromGin(c)
//developerID := c.Query("developerId")
//queryFilter, sortFilter, searchFilter, pageSize, pageNo, err := GetCommonParam(c)
//if err != nil {
// LogAndSetErrResp(c, http.StatusBadRequest, FS_BAD_JSON, err, "Failed to get param", nil)
// return
//}
//if len(sortFilter) == 0 {
// sortFilter = []string{"-created"}
//}
//baseFilter := bson.M{}
//calledByDev := isDev
//operatorID := ""
//if isDev || isAdmin || isClient {
// operatorID = c.GetHeader("X-Consumer-Custom-Id")
//} else if developerID != "" {
// operatorID = developerID
// calledByDev = true
//}
//if calledByDev {
// groupID, err := provider.GetGroupID(traceCtx, c, operatorID)
// if err != nil {
// LogAndSetErrResp(c, http.StatusInternalServerError, FS_GET_GROUP_FAILED, err, developerID, nil)
// return
// }
// baseFilter = bson.M{
// "sequence": 0,
// "groupId": groupID,
// "status.value": bson.M{"$ne": StDeleted},
// }
//} else {
// baseFilter = bson.M{
// "sequence": 0,
// "status.value": bson.M{"$ne": StDeleted},
// }
//}
//filter := baseFilter
//if len(searchFilter) > 0 {
// filter = bson.M{"$and": []bson.M{filter, searchFilter}}
//}
//if len(queryFilter) > 0 {
// filter = bson.M{"$and": []bson.M{filter, queryFilter}}
//}
//appVers := make([]model.AppVersion, 0)
//t := db.NewTable(db.TableAppVersion)
//total, err := t.GetSome(traceCtx, filter, sortFilter, pageSize, pageNo, &appVers)
//if err != nil {
// LogAndSetErrResp(c, http.StatusInternalServerError, FS_DB_ERR, err, "Failed to get appVersion", nil)
// return
//}
//c.JSON(http.StatusOK, gin.H{
// "total": total,
// "list": appVers,
//})
utility.MakeLocRsp(c, http.StatusOK, utility.OK, gin.H{})
}
type AdminListIndevlopmentAppsReq struct {
GroupId string `form:"groupId"`
PageNo int `form:"pageNo"`
PageSize int `form:"pageSize"`
}
func AdminListIndevlopmentApps(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := AdminListIndevlopmentAppsReq{}
if err := c.BindQuery(&req); err != nil {
log.Errorf("AdminListApps err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
req.PageNo += 1
svr := service.NewAppService()
svrReq := service.ListAppsReq{
GroupId: req.GroupId,
PageNo: req.PageNo,
PageSize: req.PageSize,
}
total, list, err := svr.AdminListApps(traceCtx, &svrReq)
if err != nil {
log.Errorf("AdminListApps err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
rspList := []entity.App{}
for _, v := range list {
if v.Expire == MAX_EXPIRE_DATA {
v.Expire = 0
}
rspList = append(rspList, v)
}
rspData := make(map[string]interface{})
rspData["total"] = total
rspData["list"] = rspList
c.JSON(http.StatusOK, rspData)
return
}
type DevListAppHandReq struct {
PullType string `form:"pullType"`
PageNo int `form:"pageNo"`
PageSize int `form:"pageSize"`
SearchText string `form:"searchTxt"`
SortType string `form:"sortType"`
}
type DevListAppsRspItem struct {
AppId string `json:"appId"`
GroupId string `json:"groupId"`
GroupName string `json:"groupName"`
AppClass string `json:"appClass"`
AppTag []string `json:"appTag"`
Name string `json:"name"`
Created int64 `json:"created"`
Updated int64 `json:"updated"`
Logo string `json:"logo"`
Desc string `json:"desc"`
Status string `json:"status"`
IsForbidden int `json:"isForbidden"` //是否禁用 0:未禁用 1:禁用
}
type DevListAppsRsp struct {
Total int `json:"total"`
List []DevListAppsRspItem `json:"list"`
}
/**
* @api {GET} /api/v1/mop/finstore/dev/apps/inDevelopment-v2?pageNo=1&pageSize=10&searchTxt=&sortType=created&pullType=dev-list [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestParam) {string} pageNo //页码
* @apiParam (RequestParam) {string} pageSize //页大小
* @apiParam (RequestParam) {string} sortType //排序类型
* @apiParam (RequestParam) {string} pullType //指定类别条件
* @apiParam (RequestParam) {string} searchTxt //搜索内容
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
{
"data": {
"total": 1,
"list": [
{
"appId": "62986e87277a0d00017b782e",
"groupId": "628b2215062d300001e36286",
"groupName": "个人-15377373355",
"appClass": "jinrong",
"appTag": [
"zhengquankaihu"
],
"name": "1",
"created": 1654156935640,
"expire": 0,
"logo": "https://www-cdn.finclip.com/images/ic-default.png",
"desc": "123",
"status": "Published",
"isForbidden": 1
}
]
},
"errcode": "OK",
"error": ""
}
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevListAppHand(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := DevListAppHandReq{}
if err := c.Bind(&req); err != nil {
log.Errorf("DevListAppHand bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("DevListAppHand req:%+v", req)
userId := utility.GetUserId(c)
if userId == "" {
log.Errorf("DevListAppHand bind err:%s", "user id empty")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
accountInfo, err := hCaller.GetGroupInfoByUserId(traceCtx, userId)
if err != nil {
log.Errorf("DevListAppHand GetGroupInfoByUserId err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
if req.PageNo == 0 {
req.PageNo = 1
}
if req.PageSize == 0 {
req.PageSize = 10
}
svrReq := service.ListAppsReq{
PullType: req.PullType,
SortType: req.SortType,
PageNo: req.PageNo,
PageSize: req.PageSize,
SearchText: req.SearchText,
UserId: userId,
IsDev: true,
}
log.Infof("DevListAppHand req:%+v", svrReq)
svr := service.NewAppService()
total, appList, err := svr.DevListApps(traceCtx, &svrReq)
if err != nil {
log.Errorf("DevListAppHand err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
/*licenseInfo, err := hCaller.GetLicense(traceCtx)
if err != nil {
log.Errorf("DevListAppHand GetLicense err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_SYSTEM_CALL, gin.H{})
return
}*/
succRspData := DevListAppsRsp{Total: total, List: make([]DevListAppsRspItem, 0)}
for _, v := range appList {
item := DevListAppsRspItem{
AppId: v.AppID,
GroupId: v.GroupID,
GroupName: accountInfo.GroupName,
AppClass: v.AppClass,
AppTag: v.AppTag,
Name: v.Name,
Created: v.Created,
Updated: v.Status.LastUpdated,
Logo: v.Logo,
Desc: v.CoreDescription,
Status: v.Status.Value,
IsForbidden: v.IsForbidden,
}
//item.Expire = getExpire(item.Expire, licenseInfo.ExpireTime)
succRspData.List = append(succRspData.List, item)
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, succRspData)
return
}
/**
* @api {POST} /api/v1/mop/finstore/dev/apps/privacy/setting [C/S],
* @apiGroup Finclip App Manager
* @apiParam (RequestBody) {string} appId //小程序id
* @apiParam (RequestBody) {int} commitType //提交类型 1:本小程序开发者承诺并保证,未以任何方式处理用户的任何信息。如后续有处理用户信息,会及时更新《小程序隐私保护指引》 2:本小程序处理了用户信息,将如实填写并及时更新用户信息处理情况
* @apiParam (RequestBody) {userMessageType} userMessageType //用户使用类型
* @apiParam (RequestBody) {[]SdkMessageInfoObj} sdkMessage //sdk信息
* @apiParam (RequestBody) {contactInfo} contactInfo //联系方式
* @apiParam (RequestBody) {int} fixedStorageTime //固定存储时间
* @apiParam (RequestBody) {bool} isShortestTime //是否是最短时间
* @apiParam (RequestBody) {string} additionalDocName //补充文档名称
* @apiParam (RequestBody) {string} additionalDocNetDiskId //补充文档网盘id
* @apiParam (RequestBody) {string} additionalDocContent //补充文档内容
* @apiParamExample {json} Request-Example:
* {
* "appId": "61f4f3ce5d3ef200013d9240",
* "commitType":1,
* "userMessageType": {
* "userMes":"", //用户信息
* "locationMes":"", //位置信息
* "microphone":"", //麦克风
* "camera":"", //摄像头
* "equipmentMes":"", //设备信息
* "addressBook":"", //通讯录
* "photoAlbum":"", //相册
* "calendar":"", //日历
* "operationLog":"", //操作日志
* "bluetooth":"", //蓝牙
* "others":"", //其他
* "othersExt":"", //其他
* },
* "sdkMessage":[{
* "name":"SDK名称", //SDK名称
* "provider":"提供方" //提供方
* },
* {
* "name":"名称2", //SDK名称
* "provider":"提供方2" //提供方
* },
* {...}
* ],
* "contactInfo":{
* "phone":"13033333333", //电话
* "email":"133@qq.com", //邮箱
* "other":"其他" //其他
* },
* "fixedStorageTime":1,
* "isShortestTime":false,
* "additionalDocName":"文件.txt",
* "additionalDocNetDiskId":"61f4f3ce5d3ef200013d9240" //网盘Id
* "additionalDocContent":"补充内容" //网盘Id
* }
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "data": {},
* "errcode": "OK",
* "error": ""
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DevPrivacySetting(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
req := apiproto.PrivacySettingReq{}
if err := c.ShouldBindJSON(&req); err != nil {
log.Errorf("UpdateAppInfo bind err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
log.Infof("DevPrivacySetting get req:%+v", req)
if req.AppId == "" {
log.Errorf("DevPrivacySetting appId empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_LACK_OF_APPID, gin.H{})
return
}
err := service.NewAppService().SavePrivacySetting(traceCtx, req)
if err != nil {
log.Errorf("DevGetAppVersion db err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, nil)
return
}
/**
* @api {GET} /api/v1/mop/finstore/dev/app/privacy/get/61f4f3ce5d3ef200013d9240 [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestParam) {string} appId id
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "errcode": "OK",
* "error": "",
* "data":{
* "appId": "61f4f3ce5d3ef200013d9240",
* "commitType":1,
* "userMessageType": {
* "userMes":"", //用户信息
* "locationMes":"", //位置信息
* "microphone":"", //麦克风
* "camera":"", //摄像头
* "equipmentMes":"", //设备信息
* "addressBook":"", //通讯录
* "photoAlbum":"", //相册
* "calendar":"", //日历
* "operationLog":"", //操作日志
* "bluetooth":"", //蓝牙
* "others":"", //其他
* "othersExt":"",
* },
* "sdkMessage":[{
* "name":"SDK名称", //SDK名称
* "provider":"提供方" //提供方
* },
* {
* "name":"名称2", //SDK名称
* "provider":"提供方2" //提供方
* },
* {...}
* ],
* "contactInfo":{
* "phone":"13033333333", //电话
* "email":"133@qq.com", //邮箱
* "other":"其他" //其他
* },
* "fixedStorageTime":1,
* "isShortestTime":false,
* "additionalDocName":"文件.txt",
* "additionalDocContent":"111111",
* "additionalDocNetDiskId":"61f4f3ce5d3ef200013d9240" //网盘Id
* "isFirstSave":false,
* "effectiveTime":1657003167000 //生效时间
* "updateTime":1657003167000 //更新时间
* }
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func GetPrivacySettingInfo(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
appId := c.Param("appId")
if appId == "" {
log.Errorf("GetAppInFoByAppId appId id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
result, err := service.NewAppService().GetPrivacySettingInfo(traceCtx, appId)
if err != nil {
log.Errorf("DevGetAppVersion db err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, result)
return
}
/**
* @api {DELETE} /api/v1/mop/finstore/dev/app/privacy/del/61f4f3ce5d3ef200013d9240 [C/S]
* @apiGroup Finclip App Manager
* @apiParam (RequestParam) {string} appId id
* @apiSuccessExample {json} Success Status:
* HTTP/1.1 200 OK
* {
* "errcode": "OK",
* "error": "",
* "data":{}
* }
* @apiErrorExample Error Status:
* HTTP/1.1 !=200
*/
func DelPrivacySettingInfo(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
appId := c.Param("appId")
if appId == "" {
log.Errorf("GetAppInFoByAppId appId id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
err := service.NewAppService().DelPrivacySettingInfo(traceCtx, appId)
if err != nil {
log.Errorf("DelPrivacySettingInfo db err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, nil)
return
}
func InternalGetPrivacySettingInfo(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
appId := c.Param("appId")
if appId == "" {
log.Errorf("GetAppInFoByAppId appId id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
result, err := service.NewAppService().InternalGetPrivacySettingInfo(traceCtx, appId)
if err != nil {
if service.NotFound(err) {
utility.MakeLocRsp(c, http.StatusNotFound, utility.FS_NOT_FOUND, gin.H{})
return
}
log.Errorf("DevGetAppVersion db err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, result)
return
}
func InternalGetAppSearchDataInfo(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
appId := c.Param("appId")
if appId == "" {
log.Errorf("GetAppInFoByAppId appId id empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
result, err := service.NewAppService().InternalGetAppSearchDataInfo(traceCtx, appId)
if err != nil {
if service.NotFound(err) {
utility.MakeLocRsp(c, http.StatusNotFound, utility.FS_NOT_FOUND, gin.H{})
return
}
log.Errorf("DevGetAppVersion db err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, result)
return
}
func InternalGetAppInfoBySearchText(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
searchText := c.Query("searchText")
if searchText == "" {
log.Errorf("InternalGetAppInfoBySearchText empty!")
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
result, err := service.NewAppService().InternalGetAppInfoBySearchText(traceCtx, searchText)
if err != nil {
log.Errorf("DevGetAppVersion db err:%s", err.Error())
utility.MakeLocRsp(c, http.StatusInternalServerError, utility.FS_DB_ERR, gin.H{})
return
}
utility.MakeLocRsp(c, http.StatusOK, utility.OK, result)
return
}
func getExpire(ms int64, licenseExp int64) int64 {
if ms == MAX_EXPIRE_DATA {
return 0
}
//非uat环境取license过期时间
if !config.Cfg.IsUatEnv() {
return licenseExp
}
return ms
}