Merge pull request 'fix bug' (#207) from devad/pcm-coordinator:master into master
Former-commit-id: ee2394c862032881fcb1703ac0a2ab86eaab6f07
This commit is contained in:
commit
a908f671a6
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue