feat: import services and standardize Go 1.26.5
This commit is contained in:
132
apps/base/mgt/internal/logic/application/fetch_other.go
Normal file
132
apps/base/mgt/internal/logic/application/fetch_other.go
Normal file
@@ -0,0 +1,132 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-apps/mgt/internal/libs"
|
||||
"git.apinb.com/bsm-apps/mgt/internal/logic/tool"
|
||||
"git.apinb.com/bsm-apps/mgt/internal/models"
|
||||
"git.apinb.com/bsm-apps/mgt/internal/types"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/infra"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 获取应用用户列表
|
||||
func UserFetch(c *gin.Context) {
|
||||
var (
|
||||
request = types.FetchBase{}
|
||||
data = models.MgtApplication{}
|
||||
db = models.DBService.Model(&models.MgtApplication{}).Select("id", "identity", "title")
|
||||
count int64 = 0
|
||||
)
|
||||
err := c.ShouldBindJSON(&request)
|
||||
if err != nil {
|
||||
infra.Response.Error(c, errcode.ErrJsonUnmarshal)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := libs.ValidateStruct(&request); err != nil {
|
||||
infra.Response.Error(c, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
|
||||
if request.Workspace == "" {
|
||||
printer.Error("Workspace不能为空")
|
||||
infra.Response.Error(c, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
if request.Status != 0 {
|
||||
db = db.Where("status = ?", request.Status)
|
||||
}
|
||||
|
||||
page, size := tool.GetSizeAndPage(request.Page, request.Size)
|
||||
if err := db.Where("workspace = ?", request.Workspace).Preload("Users", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("id", "identity", "name", "account", "phone", "email", "avatar").Count(&count).Limit(size).Offset((page - 1) * size)
|
||||
}).Find(&data).Error; err != nil {
|
||||
infra.Response.Error(c, errcode.ErrDB)
|
||||
return
|
||||
}
|
||||
infra.Response.Success(c, types.FetchResp{Data: data, Page: page, Size: size, Total: count})
|
||||
}
|
||||
|
||||
// 获取应用角色列表
|
||||
func RoleFetch(c *gin.Context) {
|
||||
var (
|
||||
request = types.FetchBase{}
|
||||
data = make([]models.MgtApplication, 0)
|
||||
db = models.DBService.Model(&models.MgtApplication{}).Select("id", "identity", "title")
|
||||
count int64 = 0
|
||||
)
|
||||
err := c.ShouldBindJSON(&request)
|
||||
if err != nil {
|
||||
infra.Response.Error(c, errcode.ErrJsonUnmarshal)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := libs.ValidateStruct(&request); err != nil {
|
||||
infra.Response.Error(c, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
|
||||
if request.Workspace == "" {
|
||||
printer.Error("Workspace不能为空")
|
||||
infra.Response.Error(c, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
if request.Status != 0 {
|
||||
db = db.Where("status = ?", request.Status)
|
||||
}
|
||||
if request.ID != 0 {
|
||||
db = db.Where("id = ?", request.ID)
|
||||
}
|
||||
page, size := tool.GetSizeAndPage(request.Page, request.Size)
|
||||
if err := db.Where("workspace = ?", request.Workspace).Preload("Roles", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("id", "identity", "name")
|
||||
}).Count(&count).Limit(size).Offset((page - 1) * size).Find(&data).Error; err != nil {
|
||||
infra.Response.Error(c, errcode.ErrDB)
|
||||
return
|
||||
}
|
||||
infra.Response.Success(c, types.FetchResp{Data: data, Page: page, Size: size, Total: count})
|
||||
}
|
||||
|
||||
// 获取应用权限列表
|
||||
func PermissionFetch(c *gin.Context) {
|
||||
var (
|
||||
request = types.FetchBase{}
|
||||
data = make([]models.MgtApplication, 0)
|
||||
db = models.DBService.Model(&models.MgtApplication{}).Select("id", "identity", "title")
|
||||
count int64 = 0
|
||||
)
|
||||
err := c.ShouldBindJSON(&request)
|
||||
if err != nil {
|
||||
infra.Response.Error(c, errcode.ErrJsonUnmarshal)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := libs.ValidateStruct(&request); err != nil {
|
||||
infra.Response.Error(c, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
|
||||
if request.Workspace == "" {
|
||||
printer.Error("Workspace不能为空")
|
||||
infra.Response.Error(c, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
if request.Status != 0 {
|
||||
db = db.Where("status = ?", request.Status)
|
||||
}
|
||||
if request.ID != 0 {
|
||||
db = db.Where("id = ?", request.ID)
|
||||
}
|
||||
page, size := tool.GetSizeAndPage(request.Page, request.Size)
|
||||
if err := db.Where("workspace = ?", request.Workspace).Preload("Permissions").Count(&count).Limit(size).Offset((page - 1) * size).Find(&data).Error; err != nil {
|
||||
infra.Response.Error(c, errcode.ErrDB)
|
||||
return
|
||||
}
|
||||
infra.Response.Success(c, types.FetchResp{Data: data, Page: page, Size: size, Total: count})
|
||||
}
|
||||
Reference in New Issue
Block a user