refactor all service dependency injection

This commit is contained in:
2026-08-10 11:35:48 +08:00
parent 007a7ba38a
commit c883cc52a2
152 changed files with 1030 additions and 223 deletions

View File

@@ -3,9 +3,11 @@ package department
import (
"errors"
"bsm/full/module/base/mgt/internal/impl"
"bsm/full/module/base/mgt/internal/libs"
"bsm/full/module/base/mgt/internal/models"
"bsm/full/module/base/mgt/internal/types"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/infra"
"git.apinb.com/bsm-sdk/core/printer"
@@ -38,7 +40,7 @@ func SetPmn(c *gin.Context) {
}
var dpt models.MgtDepartment
if err := models.DBService.Select("id", "app_id").Where("id = ?", request.Id).First(&dpt).Error; err != nil {
if err := impl.DBService.Select("id", "app_id").Where("id = ?", request.Id).First(&dpt).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
infra.Response.Error(c, errcode.ErrRecordNotFound)
return
@@ -61,7 +63,7 @@ func SetPmn(c *gin.Context) {
pmnData = append(pmnData, models.MgtLinkDptPmn{AppId: appId, PmnId: v, DptId: request.Id})
}
if err := models.DBService.Clauses(clause.OnConflict{
if err := impl.DBService.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "dpt_id"}, {Name: "app_id"}, {Name: "pmn_id"}},
DoUpdates: clause.AssignmentColumns([]string{"dpt_id", "app_id", "pmn_id"}),
}).Create(&pmnData).Error; err != nil {
@@ -97,7 +99,7 @@ func ModifyPmn(c *gin.Context) {
}
var dpt models.MgtDepartment
if err := models.DBService.Select("id", "app_id").Where("id = ?", request.Id).First(&dpt).Error; err != nil {
if err := impl.DBService.Select("id", "app_id").Where("id = ?", request.Id).First(&dpt).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
infra.Response.Error(c, errcode.ErrRecordNotFound)
return
@@ -120,7 +122,7 @@ func ModifyPmn(c *gin.Context) {
pmnData = append(pmnData, models.MgtLinkDptPmn{AppId: appId, PmnId: v, DptId: request.Id})
}
if err := models.DBService.Transaction(func(tx *gorm.DB) error {
if err := impl.DBService.Transaction(func(tx *gorm.DB) error {
if err := tx.Where("dpt_id = ? and app_id = ?", request.Id, appId).Delete(&models.MgtLinkDptPmn{}).Error; err != nil {
return err
}
@@ -165,7 +167,7 @@ func DelPmn(c *gin.Context) {
}
var dpt models.MgtDepartment
if err := models.DBService.Select("id", "app_id").Where("id = ?", request.Id).First(&dpt).Error; err != nil {
if err := impl.DBService.Select("id", "app_id").Where("id = ?", request.Id).First(&dpt).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
infra.Response.Error(c, errcode.ErrRecordNotFound)
return
@@ -188,7 +190,7 @@ func DelPmn(c *gin.Context) {
}
pmnIds = append(pmnIds, v)
}
if err := models.DBService.Where("dpt_id = ? AND app_id = ? AND pmn_id in ?", request.Id, appId, pmnIds).
if err := impl.DBService.Where("dpt_id = ? AND app_id = ? AND pmn_id in ?", request.Id, appId, pmnIds).
Delete(&models.MgtLinkDptPmn{}).Error; err != nil {
infra.Response.Error(c, errcode.ErrDB)
return