作者 郑周

1 部门模型

... ... @@ -7,4 +7,5 @@ import "core/article_tag.api"
import "core/user.api"
import "core/company.api"
import "core/article.api"
import "core/role.api"
\ No newline at end of file
import "core/role.api"
import "core/department.api"
\ No newline at end of file
... ...
syntax = "v1"
info(
title: "部门分组"
desc: "部门分组"
author: "zz"
email: "email"
version: "v1"
)
@server(
prefix: v1
group: department
jwt: SystemAuth
)
service Core {
@doc "部门列表"
@handler systemList
post /system/department/list (DepartmentListRequest) returns (DepartmentListResponse)
@doc "部门-新增"
@handler systemAdd
post /system/department/add (DepartmentAddRequest) returns (DepartmentGetResponse)
@doc "部门-详情"
@handler systemGet
get /system/department/:id (DepartmentGetRequest) returns (DepartmentGetResponse)
@doc "部门-更新"
@handler systemUpdate
put /system/department/:id (DepartmentUpdateRequest) returns (DepartmentGetResponse)
}
type (
DepartmentAddRequest {
Name string `json:"name"` // 分组名称
Ids []int64 `json:"ids"` // 用户ID
}
DepartmentGetRequest {
Id int64 `path:"id"`
}
DepartmentGetResponse struct{
Department Department `json:"department"`
}
DepartmentUpdateRequest {
Id int64 `path:"id"`
Name string `json:"name"`
}
DepartmentListRequest {
Page int `json:"page"`
Size int `json:"size"`
}
DepartmentListResponse {
List []Department `json:"list"`
Total int64 `json:"total"`
}
)
... ...
package department
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/department"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DepartmentAddRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := department.NewSystemAddLogic(r.Context(), svcCtx)
resp, err := l.SystemAdd(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package department
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/department"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DepartmentGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := department.NewSystemGetLogic(r.Context(), svcCtx)
resp, err := l.SystemGet(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package department
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/department"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DepartmentListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := department.NewSystemListLogic(r.Context(), svcCtx)
resp, err := l.SystemList(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package department
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/department"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DepartmentUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := department.NewSystemUpdateLogic(r.Context(), svcCtx)
resp, err := l.SystemUpdate(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -7,6 +7,7 @@ import (
article "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/article"
comment "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/comment"
company "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/company"
department "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/department"
message "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/message"
role "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/role"
tags "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/tags"
... ... @@ -310,4 +311,31 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/system/department/list",
Handler: department.SystemListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/system/department/add",
Handler: department.SystemAddHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/system/department/:id",
Handler: department.SystemGetHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/system/department/:id",
Handler: department.SystemUpdateHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
}
... ...
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"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemAddLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemAddLogic {
return &SystemAddLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types.DepartmentGetResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
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"
"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) {
// todo: add your logic here and delete this line
return
}
... ...
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"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemListLogic {
return &SystemListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *types.DepartmentListResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
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"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUpdateLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUpdateLogic {
return &SystemUpdateLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (resp *types.DepartmentGetResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -619,3 +619,31 @@ type Auth struct {
Name string `json:"name"` // 名称
Code string `json:"code"` // 编码
}
type DepartmentAddRequest struct {
Name string `json:"name"` // 分组名称
Ids []int64 `json:"ids"` // 用户ID
}
type DepartmentGetRequest struct {
Id int64 `path:"id"`
}
type DepartmentGetResponse struct {
Department Department `json:"department"`
}
type DepartmentUpdateRequest struct {
Id int64 `path:"id"`
Name string `json:"name"`
}
type DepartmentListRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
type DepartmentListResponse struct {
List []Department `json:"list"`
Total int64 `json:"total"`
}
... ...
... ... @@ -5,14 +5,14 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
)
type Department struct {
Id int64 // 唯一标识
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
ParentId int64 `json:"parentId,omitempty"` // 父级ID
Name string `json:"name,omitempty"` // 部门名称
Id int64 // 唯一标识
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
ParentId int64 `json:"parentId,omitempty"` // 父级ID
Name string `json:"name,omitempty"` // 部门名称
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
... ... @@ -25,13 +25,13 @@ func (m *Department) TableName() string {
}
func (m *Department) BeforeCreate(tx *gorm.DB) (err error) {
// m.CreatedAt = time.Now().Unix()
// m.UpdatedAt = time.Now().Unix()
m.CreatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
func (m *Department) BeforeUpdate(tx *gorm.DB) (err error) {
// m.UpdatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
... ...