You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

adddictitemlogic.go 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dictionary
  2. import (
  3. "context"
  4. "github.com/pkg/errors"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
  6. "gorm.io/gorm"
  7. "time"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type AddDictItemLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewAddDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddDictItemLogic {
  18. return &AddDictItemLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. func (l *AddDictItemLogic) AddDictItem(req *types.DictItemEditReq) (resp *types.DictItemResp, err error) {
  25. dict := &types.DictInfo{}
  26. result := l.svcCtx.DbEngin.Table("t_dict").First(&dict, req.DictId)
  27. if errors.Is(result.Error, gorm.ErrRecordNotFound) {
  28. return nil, errors.New("Dictionary does not exist")
  29. }
  30. var dictItem types.DictItemInfo
  31. dictItem.DictId = req.DictId
  32. dictItem.ItemText = req.ItemText
  33. dictItem.ItemValue = req.ItemValue
  34. dictItem.Description = req.Description
  35. dictItem.SortOrder = req.SortOrder
  36. dictItem.ParentId = "0"
  37. if req.ParentId != "" {
  38. dictItem.ParentId = req.ParentId
  39. }
  40. dictItem.Status = req.Status
  41. dictItem.Id = utils.GenSnowflakeIDStr()
  42. dictItem.CreateTime = time.Now().Format("2006-01-02 15:04:05")
  43. result = l.svcCtx.DbEngin.Table("t_dict_item").Create(&dictItem)
  44. if result.Error != nil {
  45. logx.Errorf("Failed to create dictionary item , errors: %s", result.Error)
  46. return nil, result.Error
  47. }
  48. return
  49. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.