system_get_logic.go 1.1 KB
package department

import (
	"context"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"

	"github.com/zeromicro/go-zero/core/logx"
)

type SystemGetLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSystemGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemGetLogic {
	return &SystemGetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SystemGetLogic) SystemGet(req *types.DepartmentGetRequest) (resp *types.DepartmentGetResponse, err error) {
	var conn = l.svcCtx.DefaultDBConn()
	department, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, req.Id)
	if err != nil {
		return nil, xerr.NewErrMsg("数据不存在")
	}
	resp = &types.DepartmentGetResponse{
		Department: types.Department{
			Id:        department.Id,
			CompanyId: department.CompanyId,
			ParentId:  department.ParentId,
			Name:      department.Name,
		},
	}
	return resp, nil
}