feat: wecom tag create items

This commit is contained in:
zzw
2026-09-14 18:05:33 +08:00
parent 21b614b062
commit 553e93b16c
22 changed files with 922 additions and 140 deletions
+13
View File
@@ -0,0 +1,13 @@
package dao
import "lone-services/pkg/utils"
type Tags struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
Name string `gorm:"column:name" json:"name"`
TagID int64 `gorm:"column:tag_id" json:"tag_id"`
Remarks string `gorm:"column:remarks" json:"remarks"`
Status uint8 `gorm:"column:status" json:"status"`
CreatedAt utils.CustomTime `gorm:"column:created_at" json:"created_at"`
UpdatedAt utils.CustomTime `gorm:"column:updated_at" json:"updated_at"`
}
@@ -0,0 +1,55 @@
package logic
import (
"context"
"lone-services/pkg/utils"
"lone-services/pkg/wecom/tags"
wecom "lone-services/rpc/wecom/pb"
"lone-services/services/wecom/internal/dao"
"lone-services/services/wecom/internal/model"
"lone-services/services/wecom/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateTagsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateTagsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateTagsLogic {
return &CreateTagsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *CreateTagsLogic) CreateTags(in *wecom.CreateTagsReq) (*wecom.Response, error) {
client := NewTagClient()
data := tags.CreateRequest{
TagName: in.Name,
}
tag, err := client.Create(l.ctx, data)
if err != nil {
l.Logger.Error("create tag error", "error", err)
return failResponse(utils.Fail), nil
}
create := dao.Tags{
Name: in.Name,
Remarks: in.Remarks,
Status: 1,
TagID: tag.TagID,
CreatedAt: utils.Now(),
}
err = model.TagsModel{}.Init().Create(&create)
if err != nil {
l.Logger.Error("create tag error", "error", err)
return failResponse(utils.Fail), nil
}
return okResponse(nil), nil
}
+6
View File
@@ -6,6 +6,8 @@ import (
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/pkg/wecom/auth"
"lone-services/pkg/wecom/tags"
"lone-services/services/wecom/internal/dao"
"lone-services/services/wecom/internal/model"
@@ -128,3 +130,7 @@ func cleanAgentIds(ids []int64) []int64 {
}
return out
}
func NewTagClient() *tags.Client {
return tags.NewClient(auth.NewClient(utils.GetConfigString("wecom.corp_id"), utils.GetConfigString("wecom.corp_secret")))
}
@@ -0,0 +1,47 @@
package logic
import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
wecom "lone-services/rpc/wecom/pb"
"lone-services/services/wecom/internal/dao"
"lone-services/services/wecom/internal/model"
"lone-services/services/wecom/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ItemsTagsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewItemsTagsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsTagsLogic {
return &ItemsTagsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ItemsTagsLogic) ItemsTags(in *wecom.ItemsTagsReq) (*wecom.Response, error) {
w := modelbase.Params{
Page: int(in.Page),
Size: int(in.PageSize),
Order: "id desc",
}
if in.Name != utils.StringEmpty {
w.Like["name"] = "%" + in.Name + "%"
}
var data []dao.Tags
page, err := model.TagsModel{}.Init().Page(w, &data)
if err != nil {
return failResponse(utils.Fail), nil
}
return okResponse(page), nil
}
+18
View File
@@ -0,0 +1,18 @@
package model
import (
"lone-services/pkg/modelbase"
)
type TagsModel struct {
modelbase.Base
}
func (m TagsModel) TableName() string {
return modelbase.Prefix() + "tags"
}
func (m TagsModel) Init() TagsModel {
m.Table = m.TableName()
return m
}
@@ -57,3 +57,13 @@ func (s *WecomServer) Types(ctx context.Context, in *wecom.EmptyReq) (*wecom.Res
l := logic.NewTypesLogic(ctx, s.svcCtx)
return l.Types(in)
}
func (s *WecomServer) CreateTags(ctx context.Context, in *wecom.CreateTagsReq) (*wecom.Response, error) {
l := logic.NewCreateTagsLogic(ctx, s.svcCtx)
return l.CreateTags(in)
}
func (s *WecomServer) ItemsTags(ctx context.Context, in *wecom.ItemsTagsReq) (*wecom.Response, error) {
l := logic.NewItemsTagsLogic(ctx, s.svcCtx)
return l.ItemsTags(in)
}