Signed-off-by: jagger <cossjie@foxmail.com>

Former-commit-id: 53039ebcdb46e353f2dcec112389cad7c3b91432
This commit is contained in:
jagger 2024-06-04 15:23:16 +08:00
parent 378ed17411
commit d8e8370e5b
1 changed files with 17 additions and 0 deletions

View File

@ -2,10 +2,12 @@ package adapters
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gorm.io/gorm"
"time" "time"
) )
@ -26,6 +28,21 @@ func NewCreateAdapterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
func (l *CreateAdapterLogic) CreateAdapter(req *types.AdapterCreateReq) (resp *types.AdapterResp, err error) { func (l *CreateAdapterLogic) CreateAdapter(req *types.AdapterCreateReq) (resp *types.AdapterResp, err error) {
adapter := types.AdapterInfo{} adapter := types.AdapterInfo{}
utils.Convert(req, &adapter) utils.Convert(req, &adapter)
//check name
exist := l.svcCtx.DbEngin.Table("t_adapter").Where("name = ?", req.Name).First(&types.AdapterInfo{}).Error
if !errors.Is(exist, gorm.ErrRecordNotFound) {
return nil, errors.New("name already exists")
}
//check type
sql := `select t_dict_item.item_value
from t_dict
join t_dict_item on t_dict.id = t_dict_item.dict_id
where dict_code = 'adapter_type' and item_value = ?
and t_dict_item.parent_id != 0`
err = l.svcCtx.DbEngin.Raw(sql, req.Type).First(&types.DictItemInfo{}).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errors.New("Type error, please check!")
}
adapter.Id = utils.GenSnowflakeIDStr() adapter.Id = utils.GenSnowflakeIDStr()
adapter.CreateTime = time.Now().Format("2006-01-02 15:04:05") adapter.CreateTime = time.Now().Format("2006-01-02 15:04:05")
result := l.svcCtx.DbEngin.Table("t_adapter").Create(&adapter) result := l.svcCtx.DbEngin.Table("t_adapter").Create(&adapter)