finclip-app-manager/router/router.go

418 lines
22 KiB
Go
Raw Normal View History

2023-10-31 14:07:26 +08:00
package router
import (
"finclip-app-manager/infrastructure/config"
"net/http"
auth "gitlab.finogeeks.club/finclip-backend/mop-middleware-auth"
authConfig "gitlab.finogeeks.club/finclip-backend/mop-middleware-auth/config"
"finclip-app-manager/application"
"finclip-app-manager/infrastructure/consul"
"finclip-app-manager/infrastructure/logger"
"finclip-app-manager/router/middleware"
"github.com/gin-gonic/gin"
)
func Load(g *gin.Engine) *gin.Engine {
// Middlewares
g.Use(middleware.NoCache)
g.Use(middleware.Options)
g.Use(middleware.Secure)
g.Use(middleware.Transfer)
//g.Use(middleware.AddZipkinTraceSpan)
g.Use(middleware.RequestCount)
g.Use(middleware.RequestDuration())
g.Use(middleware.CheckLicenseUrl) //mop license 校验
g.Use(middleware.CheckEnterpriseIsExpired)
cfg := config.GetConfig()
authCfg := authConfig.Config{
ServerName: cfg.ServerName,
ConsulAddr: cfg.ConsulAddr,
ConsulTag: cfg.ConsulTag,
ExpireInterval: cfg.AuthExpireInterval,
DebugLog: cfg.LogMode == "debug",
}
g.Use(auth.CreateAuthMiddleware(authCfg).CheckPathAuthor)
// 404 Handler
g.NoRoute(func(c *gin.Context) {
c.String(http.StatusNotFound, "The incorrect API route.")
})
appGroup := g.Group("/api/v1/finclip-app-manager")
{
appGroup.GET("/user", application.UserApi)
}
readyGroup := g.Group("/")
readyGroup.GET("/ready", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"ready": "ok"})
})
readyGroup.POST("/down", func(c *gin.Context) {
logger.GetLogger().Debugln("post notify down")
go consul.GetConsulInstance().DisRegisterServer()
c.JSON(http.StatusOK, gin.H{"down": "ok"})
})
//小程序相关
devGroup := g.Group("/api/v1/mop/finstore/dev") //机构端请求
devGroup.Use(middleware.VerifyAppletEcolRole) //机构端开启权限校验
{
devGroup.POST("/apps/creation", application.DevCreateApp) //创建小程序
devGroup.POST("/apps/update", application.DevUpdateApp) //更新小程序
devGroup.POST("/apps/is_forbidden/update", application.DevUpdateAppIsForbidden) //更新是否禁用小程序
devGroup.POST("/apps/publishRequest", application.DevSubmitPublishRequest) //提交上架申请
devGroup.POST("/apps/publishRequestWithdrawal", application.DevWithdrawPublishRequest) //撤销上架申请
devGroup.POST("/apps/publish", application.DevPublishApp) //上架小程序
devGroup.POST("/apps/unpublish", application.DevUnpublishApp) //下架小程序
devGroup.GET("/appInfo/rollbackList", application.RollbackListApps) //回滚列表
devGroup.GET("/appInfo/builds", application.GetAppBuilds)
devGroup.GET("/appInfo/latest", application.GetLatestAppInfo)
devGroup.GET("/apps", application.DevListApps) //获取app列表
devGroup.GET("/appsAndReviews", application.DevListAppsAndReviews) //获取小程序及其审核历史
devGroup.POST("/files", application.UploadFile) //编译模块调用(弃用)
devGroup.GET("/statistics/apps", application.DevGetStatistics)
devGroup.GET("/apps/:path1", devHandleSinglePath)
devGroup.GET("/apps/:path1/:path2", devHandleDoublePath) //这里用来获取小程序二维码信息
devGroup.GET("/apps/:path1/:path2/:path3", devHandleTriplePath)
//标准化
devGroup.POST("/apps/publish-request", application.DevSubmitPublishRequest) //提交上架申请
devGroup.POST("/apps/publish-request-withdrawal", application.DevWithdrawPublishRequest) //撤销上架申请
devGroup.GET("/apps-and-reviews", application.DevListAppsAndReviews) //获取小程序及其审核历史
//体验版
devGroup.POST("/trial/operate", application.UpdateTrialApp) //添加体验版
devGroup.POST("/trial/path-query", application.UpdateTrialAppPathAndQueryHand) //更新体验版path
devGroup.GET("/trial/info", application.GetTrialAppInfo) //获取小程序体验版信息
//devGroup.POST("/red-dot/read", handler.ReadRedDotHand) //读红点
devGroup.POST("/package/offline", application.GenOfflinePackageInfoHand)
devGroup.GET("/apps/audit/list", application.AdminListAppSeqList)
devGroup.POST("/wechat/info", application.UpdateWechatInfo)
if config.Cfg.IsPrivateEnv() || config.Cfg.IsCommunityEnv() {
devGroup.GET("/bundle/list", application.Bundles) //获取bundle列表
}
devGroup.GET("/app-ver/:appId/:sequence", application.AdminGetAppVerDetail) //获取小程序版本详情
devGroup.POST("/apps/approval", application.DevApproveApp) //审核小程序
devGroup.POST("/apps/privacy/setting", application.DevPrivacySetting) //隐私设置
devGroup.GET("/app/privacy/get/:appId", application.GetPrivacySettingInfo)
devGroup.DELETE("/app/privacy/del/:appId", application.DelPrivacySettingInfo)
devGroup.GET("/apps/organ/admin-account/:appId", application.GetAppAdminAccount)
}
adminGroup := g.Group("/api/v1/mop/finstore/admin")
{
adminGroup.POST("/apps/unpublish", application.AdminUnpublishApp) //运营端下架小程序
adminGroup.POST("/apps/approval", application.AdminApproveApp) //审核小程序
adminGroup.GET("/apps", application.AdminListApps)
adminGroup.POST("/files", application.UploadFile)
adminGroup.GET("/app-ver/:appId/:sequence", application.AdminGetAppVerDetail) //获取小程序版本详情
adminGroup.GET("/linkApplets", application.AdminGetLinkApplets) //获取小程序关联列表
if config.Cfg.IsPrivateEnv() || config.Cfg.IsCommunityEnv() {
adminGroup.GET("/bundle/list", application.Bundles) //获取bundle列表
adminGroup.POST("/bundle/create", application.CreateBundles) //创建多个bundle
adminGroup.POST("/bundle/isExist", application.BundleIsExist) //判断bundle是否存在
adminGroup.POST("/bundle/update/is_forbidden", application.UpdateBundlesIsForbidden) //更新bundle 禁用状态
adminGroup.POST("/bundle/update/platform", application.UpdateBundlesPlatform) //更新bundle 平台
}
adminGroup.GET("/statistics/apps", application.AdminGetStatistics)
adminGroup.GET("/statistics/app-class/:status", application.AdminGetAppClassPer) //获取小程序类型分布百分比
adminGroup.GET("/statistics/appReviewTrend", application.DevGetappReviewTrendData)
adminGroup.GET("/apps/:path1", adminHandleSinglePath)
adminGroup.GET("/apps-v2/in-development", application.AdminListInDevAppHand)
adminGroup.GET("/apps/:path1/:path2", adminHandleDoublePath)
adminGroup.GET("/apps/:path1/:path2/:path3", adminHandleTriplePath)
//
adminGroup.GET("/link-applets", application.AdminGetLinkApplets) //获取小程序关联列表
adminGroup.GET("/statistics/app-review-trend", application.DevGetappReviewTrendData)
//todo 开新的接口
adminGroup.GET("/appver/reviews", application.AdminGetAppReviews) //运营端获取小程序审核列表
adminGroup.GET("/app-info/latest-pub", application.GetLatestPubAppVerInfo) //运营端获取最近一次小程序上架信息(上架+下架)
adminGroup.GET("/list/pub-apps", application.AdminListPubApps) //运营端获取当前上架的小程序版本列表
adminGroup.GET("/app-oper-conifg/info", application.QueryAppOperConfig)
adminGroup.POST("/app-oper-conifg/update", application.UpdateAppOperConfig)
}
adminGroupV2 := g.Group("/api/v2/mop/finstore/admin")
{
adminGroupV2.GET("/apps", application.AdminListAppsV2)
adminGroupV2.GET("apps/sdk-key/:appId", application.GetSdkKeyList) //获取小程序sdkkey
adminGroupV2.GET("apps/history-app", application.UpdateHistoryAppMsg)
}
clientGroup := g.Group("/api/v1/mop/finstore/client")
{
//clientGroup.GET("/apps", handler.ClientListApps)
appGroup.POST("/files", application.UploadFile)
//clientGroup.GET("/apps/:path1", clientHandleSinglePath)
clientGroup.GET("/apps/:path1/:path2", clientHandleDoublePath)
clientGroup.GET("/binding/used", application.GetBindingUsedInfo)
//clientGroup.GET("/apps/:path1/:path2/:path3", clientHandleTriplePath)
}
runtimeGroup := g.Group("/api/v1/mop/finstore/runtime")
{
runtimeGroup.GET("/apps/:path1", application.RuntimeGetAppInfo) //运行时获取小程序详情
runtimeGroup.GET("/apps/:path1/sequences/:path3", application.RuntimeGetAppVersionInfo) //运行时获取版本详情
}
internalGroup := g.Group("/api/v1/mop/finstore")
{
internalGroup.GET("/organId/:appId", application.GetGroupIdByAppId) //根据appId获取机构ID
internalGroup.PUT("/app", application.UpdateAppInfo) //更新小程序
//internalGroup.POST("/appBuild", handler.InitAppBuild) //更新小程序
//internalGroup.GET("/app/:appId/pubVer", handler.GetAppPubVer) //获取小程序详情
internalGroup.GET("/ruleEngine/permitPub/:appId", application.GetRuleEngineVerPubList) //获取可进行灰度发布的版本列表
internalGroup.GET("/ruleEngine/app/:appId", application.RuleEngineGetAppInfo) //灰度发布获取小程序详情
internalGroup.GET("/ruleEngine/app/:appId/:version", application.RuleEngineGetAppVerInfo) //获取版本详情
internalGroup.PATCH("/ruleEngine/grayNotify", application.GrayNotifyApp)
internalGroup.GET("/organ-id/:appId", application.GetGroupIdByAppId) //根据appId获取机构ID
//internalGroup.GET("/binding-info", handler.GetBindingInfoByIdHand) //内部调用
//账号系统调用,更新缓存
//internalGroup.PATCH("/organ-info/:organId", handler.AccountSyncInfoHand) //账号系统同步更新消息到应用市场
//internalGroup.PATCH("/domain-info/:organId", handler.DomainSyncInfoHand) //域名系统同步更新消息到应用市场
internalGroup.PATCH("/notify", application.NotifySyncInfoHand) //其他系统更新消
//编译模块调用
//internalGroup.GET("/app/:appId/pub-ver", handler.GetAppPubVer) //获取小程序详情
internalGroup.GET("/app-build/build-info", application.GetAppVerBuildInfos) //获取体验版,线上版小程序信息
internalGroup.GET("/rule-engine/permit-pub/:appId", application.GetRuleEngineVerPubList) //获取可进行灰度发布的版本列表
internalGroup.GET("/rule-engine/statics/ver-list", application.GetGrayStatisticsVerList) //获取小于该版本的所有上架版本
internalGroup.GET("/rule-engine/app/:appId", application.RuleEngineGetAppInfo) //灰度发布获取小程序详情
internalGroup.GET("/rule-engine/app/:appId/:version", application.RuleEngineGetAppVerInfo) //获取版本详情
internalGroup.POST("/rule-engine/batch/app-info", application.RuleEngineBatchGetApp) //批量获取小程序
internalGroup.PATCH("/rule-engine/gray-notify", application.GrayNotifyApp)
// 管理后台调用
internalGroup.GET("/manage/tagAndClassification/use/list", application.GetAppTagAndClassification) //获取小程序使用分类和标签汇总
//internalGroup.GET("/data-report/bindingId/:organId/:bundleId", application.GetBindingIdByBundleId) //根据bundleId获取应用ID
//支付模块调用
internalGroup.PUT("/update-expire/:type/:businessId", application.UpdateExpireInfo)
//ide 创建临时appId和sequence
//internalGroup.PUT("/temp-applet/:appId", handler.UpdateTempApp)
//open-api调用
internalGroup.POST("/identity/batch-apps", application.BatchAppsByIdentity)
internalGroup.POST("/identity/check-apps", application.IdentityAppsCheck)
internalGroup.POST("/build/app-info", application.GetBuildAppInfo) //获取: (1)体验版 (2)临时版 小程序信息
internalGroup.GET("/build/id-info", application.GetBuildInfoById) //根据code id获取build info
internalGroup.GET("/manage/app-list", application.GetManageAppList) //获取管理小程序列表
internalGroup.GET("/manage/ver-list", application.GetManageAppVerList) //获取小程序线上、开发、体验版本
internalGroup.POST("/fix-old/dev-list-status", application.FixDevListStatus) //获取小程序线上、开发、体验版本
internalGroup.GET("/apps/:path1/:path2", handleDoublePath)
//internalGroup.GET("/apps/:path1/:path2/:path3", handleTriplePath)
//internalGroup.GET("/bindings/ids", handler.GetBindingsByIds) //根据应用id列表批量获取应用详情
internalGroup.GET("/bindingId", application.GetBindingIdBySdkKeyHand) //根据sdkkey,organId获取bindingId
internalGroup.POST("/bindingInfo", application.GetBindingInfoBySdkKeyHand) //根据sdkkey,organId获取bindingInfo
//新增
internalGroup.GET("/app-info", application.InternalGetApp)
internalGroup.GET("/latest/app-version", application.GetLatestAppVerInfo)
internalGroup.GET("/app-info/latest-pub", application.GetLatestPubAppVerInfo) //运营端获取最近一次小程序上架信息(上架+下架)
internalGroup.GET("/build/info/by/build-info-id", application.GetInfoByBuildInfoId) //根据buildInfoId获取build info
internalGroup.POST("/bindings/sync/organbind", application.SyncOrganBinding) //新创建企业同步运营端创建的合作应用
internalGroup.GET("/app/search/data/info/:appId", application.InternalGetAppSearchDataInfo) //获取搜索es所需的小程序数据
//关键字匹配app_id,app_name
internalGroup.GET("/app-id/by/search-text", application.InternalGetAppInfoBySearchText) //获取关键字匹配的的小程序id
}
openApiGroup := g.Group("/api/v1/mop/finstore/openapi")
{
openApiGroup.GET("/app/list", application.GetAppListByBindIdHand) //根据应用Id获取它的关联列表
openApiGroup.GET("/apps/info", application.GetAppsInfoByListHand) //根据appId列表获取app信息
openApiGroup.GET("/app/search", application.SearchAppHand) //根据小程序名称搜索小程序
openApiGroup.GET("/appver/:appId/:sequence", application.InternalGetAppVerInfo) //根据小程序版本获取详情
openApiGroup.GET("/secret", application.GetSecretBySdkKeyHand) //获取secret
openApiGroup.GET("/wechat/app", application.GetAppByWechat) // 已读
openApiGroup.GET("/app/getBySDKKey", application.GetAppBySDKKey) //获取当前 App 已经关联的全部小程序清单
}
openApiGroupV2 := g.Group("/api/v1/mop/finstore/open-api")
{
//mop-open-api调用
openApiGroupV2.GET("/app/list", application.GetAppListByBindIdHand) //根据应用Id获取它的关联列表
//openApiGroupV2.GET("/binding-id", handler.GetBindingIdBySdkKeyHand) //根绝sdkKey获取应用Id
openApiGroupV2.GET("/secret", application.GetSecretBySdkKeyHand) //获取secret
//openApiGroupV2.GET("/binding-info", handler.GetBindingInfoByIdHand) //根据应用Id获取应用信息
openApiGroupV2.GET("/apps/info", application.GetAppsInfoByListHand) //根据appId列表获取app信息
openApiGroupV2.GET("/app/search", application.SearchAppHand) //根据小程序名称搜索小程序
openApiGroupV2.GET("/app-ver/:appId/:sequence", application.InternalGetAppVerInfo) //根据小程序版本获取详情
//openApiGroupV2.GET("/qrcode-info/:uuid", handler.GetQrcodeInfo) //获取小程序二维码详情
openApiGroupV2.GET("/app/privacy/get/:appId", application.InternalGetPrivacySettingInfo)
}
//devGroup := g.Group("/api/v1/mop/finstore/dev")
//binding相关
devGroup.POST("/bindings/creation", application.DevCreateBinding) //新增应用
devGroup.GET("/bindings", application.DevListBindings) //获取应用列表
devGroup.GET("/bindings-v2", application.DevListBindingsV2) //获取应用列表
devGroup.GET("/binding/:bindingId", application.GetBindingDetail)
devGroup.GET("/bindings/appIdInfoList", application.DevListAllAppidInfo) //拉取appid的详细信息
devGroup.POST("/bindings/update", application.UpdateBinding) //更新应用
devGroup.GET("/add/bundleId/limit", application.AddBundleIdLimitNumConfig) //获取添加bundle时数量限制
devGroup.GET("/bindings/get/terminal", application.GetLicenseTerminal) //获取license终端情况
devGroup.GET("/bindings/get/byAppId", application.GetBindingsByAppId) //获取license终端情况
adminGroup.POST("/bindings/creation", application.AdminCreateBinding) //新增应用
adminGroup.POST("/bindings/update", application.AdminUpdateBinding) //运营端更新应用
adminGroup.GET("/bindings", application.AdminListBindings) //管理员获取应用列表
adminGroup.GET("/bindings-v2", application.NewAdminListBindings) //管理员获取应用列表
adminGroup.GET("/limit/bindings", application.GetLimitBindingList) //根据机构Id获取应用列表
adminGroup.GET("/binding/:bindingId", application.GetBindingDetail)
adminGroup.GET("/add/bundleId/limit", application.AddBundleIdLimitNumConfig) //获取添加bundle时数量限制
adminGroup.GET("/binding/review-bundle/list", application.AdminReviewBundleList) //获取审核应用列表
adminGroup.POST("/binding/review-bundle/update", application.UpdateReviewBundle) //更改审核应用
adminGroup.GET("/binding/check/review/:sdkkey", application.CheckReviewBySdkKey) //判断sdkkey是否在审核列表用于测试
//devGroup.GET("/bindings/appid-info-list", application.DevListAllAppidInfo) //拉取appid的详细信息
internalGroup.GET("/bindings/ids", application.GetBindingsByIds) //根据应用id列表批量获取应用详情
internalGroup.GET("/organ-id", application.GetOrganIdBySdkKey) //根据sdkKey获取organId
internalGroup.GET("/binding-info", application.GetBindingInfoByIdHand) //内部调用
if config.GetConfig().IsPrivateEnv() || config.GetConfig().IsCommunityEnv() {
devGroup.GET("/limit/bundleId", application.BundlesLimit) //获取bundleId的限制
//devGroup.POST("/bundle/update/is_forbidden", application.OrganUpdateBundlesIsForbidden) //更新bundle 禁用状态
} else {
devGroup.GET("/limit/bundleId", application.GetBundleIdLimitHand) //获取bundleId的限制
}
//菜单管理
// 已测
adminGroup.POST("/menu", application.AddMenuHand)
adminGroup.DELETE("/menu/:traceId", application.DelMenuHand)
adminGroup.PUT("/menu/:traceId", application.UpdateMenuHand)
adminGroup.GET("/menu/all", application.GetAllMenuHand)
adminGroup.POST("/menu/sort", application.SortMenuHand)
//二维码调用
devGroup.POST("/qrcode", application.GenQrcodeHand)
adminGroup.POST("/qrcode", application.GenQrcodeHand)
internalGroup.POST("/qrcode", application.GenQrcodeHand) //内部调用
appGroup.POST("/apps/qrcode/refresh", application.QRCodeRefresh) //小程序扫码登录
openApiGroup.GET("/qrcode/appver", application.InternalGetQRcodeAppVerInfo) //获取二维码小程序版本详情
devGroup.POST("/wechat/qrcode/delete", application.DeleteWechatQrcode) // 删除关连
devGroup.POST("wechat/readHint", application.ReadWechatHint)
openApiGroupV2.GET("/qrcode-info/:uuid", application.GetQrcodeInfo) //获取小程序二维码详情
// URL_PREFIX/apps/:appId/InDevelopment -- 获取开发详情
appGroup.GET("/apps/:path1/:path2", handleDoublePath)
//根据小程序id获取小程序数据
devGroup.GET("/app/:appId", application.GetAppGroupIdByAppId)
// 已测
appGroup.GET("/typeConfig", application.ListTypeConfig) //获取配置类型列表
devGroup.GET("/typeConfig", application.ListTypeConfig)
adminGroup.GET("/typeConfig", application.ListTypeConfig)
adminGroup.POST("/typeConfig", application.AddTypeConfig) //添加小程序类型
adminGroup.DELETE("/typeConfig/:typeConfigId", application.DeleteTypeConfig) //删除小程序类型
//小程序类型配置
appGroup.GET("/type-config", application.ListTypeConfig) //获取配置类型列表
devGroup.GET("/type-config", application.ListTypeConfig)
adminGroup.GET("/type-config", application.ListTypeConfig)
adminGroup.POST("/type-config", application.AddTypeConfig) //添加小程序类型
adminGroup.DELETE("/type-config/:typeConfigId", application.DeleteTypeConfig) //删除小程序类型
//ide 创建临时appId和sequence
internalGroup.PUT("/temp-applet/:appId", application.UpdateTempApp)
ideGroup := g.Group("/api/v1/mop/finstore/ide")
{
ideGroup.POST("/temp-applet", application.GenTempApp)
}
devGroup.POST("/red-dot/read", application.ReadRedDotHand) //读红点
return g
}
func handleDoublePath(c *gin.Context) {
path2 := c.Param("path2")
if path2 == "qrcode" {
application.GetQRCode(c)
} else if path2 == "qrcodeInfo" {
application.GetQRCodeInfo(c)
} else {
application.GetAppInDevelopment(c)
}
}
func adminHandleSinglePath(c *gin.Context) {
path1 := c.Param("path1")
if path1 == "sequences" {
application.AdminListAppVersions(c)
} else if path1 == "sequences-v2" { //获取小程序审核列表
application.AdminListAppSeqList(c)
} else if path1 == "inDevelopment" {
application.AdminListIndevlopmentApps(c)
} else {
application.AdminGetApp(c)
}
}
func adminHandleDoublePath(c *gin.Context) {
path2 := c.Param("path2")
if path2 == "qrcode" {
application.GetQRCode(c)
} else if path2 == "qrcodeInfo" {
application.GetQRCodeInfo(c)
} else {
//application.AdminGetAppInDevelopment(c)
}
}
func adminHandleTriplePath(c *gin.Context) {
application.AdminGetAppVersion(c)
}
//dev
func devHandleSinglePath(c *gin.Context) {
path1 := c.Param("path1")
if path1 == "sequences" {
application.DevListAppVersions(c)
} else if path1 == "sequences-v2" {
application.NewDevListAppSeqList(c)
} else if path1 == "inDevelopment" {
application.DevListAppsInDevelopment(c)
} else if path1 == "inDevelopment-v2" {
//handler.ListAppsInDevelopment(c)
application.DevListAppHand(c)
} else {
application.DevGetApp(c)
}
}
func devHandleDoublePath(c *gin.Context) {
path2 := c.Param("path2")
if path2 == "qrcode" {
application.GetQRCode(c)
} else if path2 == "qrcodeInfo" {
application.GetQRCodeInfo(c)
} else {
application.DevGetAppInDevelopment(c)
}
}
func devHandleTriplePath(c *gin.Context) {
application.DevGetAppVersion(c)
}
//func handleTriplePath(c *gin.Context) {
// application.GetAppVersion(c)
//}
func clientHandleDoublePath(c *gin.Context) {
path2 := c.Param("path2")
if path2 == "qrcode" {
application.GetQRCode(c)
} else if path2 == "qrcodeInfo" {
application.GetQRCodeInfo(c)
} else {
//application.ClientGetAppInDevelopment(c)
}
}