feat: import services and standardize Go 1.26.5
This commit is contained in:
54
apps/base/mgt/internal/logic/department/detail.go
Normal file
54
apps/base/mgt/internal/logic/department/detail.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package department
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.apinb.com/bsm-apps/mgt/internal/libs"
|
||||
"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 Detail(c *gin.Context) {
|
||||
var (
|
||||
request = types.DptReq{}
|
||||
data = models.MgtDepartment{}
|
||||
)
|
||||
|
||||
// 解析JSON请求
|
||||
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.ID == 0 {
|
||||
printer.Error("部门ID不能为空")
|
||||
infra.Response.Error(c, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
|
||||
if err = models.DBService.Model(&models.MgtDepartment{}).
|
||||
Select("id", "identity", "name", "app_id", "parent_id", "leader_id").Preload("Leader", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("id", "identity", "name")
|
||||
}).Where("id = ?", request.ID).First(&data).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
infra.Response.Error(c, errcode.ErrRecordNotFound)
|
||||
return
|
||||
}
|
||||
infra.Response.Error(c, errcode.ErrDB)
|
||||
return
|
||||
}
|
||||
|
||||
infra.Response.Success(c, data)
|
||||
}
|
||||
Reference in New Issue
Block a user