作者 tangxvhui
@@ -8,3 +8,4 @@ import "core/company.api" @@ -8,3 +8,4 @@ import "core/company.api"
8 import "core/article_type.api" 8 import "core/article_type.api"
9 import "core/article.api" 9 import "core/article.api"
10 import "core/role.api" 10 import "core/role.api"
  11 +import "core/department.api"
  1 +syntax = "v1"
  2 +
  3 +info(
  4 + title: "部门分组"
  5 + desc: "部门分组"
  6 + author: "zz"
  7 + email: "email"
  8 + version: "v1"
  9 +)
  10 +
  11 +@server(
  12 + prefix: v1
  13 + group: department
  14 + jwt: SystemAuth
  15 +)
  16 +service Core {
  17 + @doc "部门列表"
  18 + @handler systemList
  19 + post /system/department/list (DepartmentListRequest) returns (DepartmentListResponse)
  20 +
  21 + @doc "部门-新增"
  22 + @handler systemAdd
  23 + post /system/department/add (DepartmentAddRequest) returns (DepartmentGetResponse)
  24 +
  25 + @doc "部门-详情"
  26 + @handler systemGet
  27 + get /system/department/:id (DepartmentGetRequest) returns (DepartmentGetResponse)
  28 +
  29 + @doc "部门-更新"
  30 + @handler systemUpdate
  31 + put /system/department/:id (DepartmentUpdateRequest) returns (DepartmentGetResponse)
  32 +}
  33 +
  34 +type (
  35 + DepartmentAddRequest {
  36 + Name string `json:"name"` // 分组名称
  37 + Ids []int64 `json:"ids"` // 用户ID
  38 + }
  39 +
  40 + DepartmentGetRequest {
  41 + Id int64 `path:"id"`
  42 + }
  43 +
  44 + DepartmentGetResponse struct{
  45 + Department Department `json:"department"`
  46 + }
  47 +
  48 + DepartmentUpdateRequest {
  49 + Id int64 `path:"id"`
  50 + Name string `json:"name"`
  51 + }
  52 +
  53 + DepartmentListRequest {
  54 + Page int `json:"page"`
  55 + Size int `json:"size"`
  56 + }
  57 +
  58 + DepartmentListResponse {
  59 + List []Department `json:"list"`
  60 + Total int64 `json:"total"`
  61 + }
  62 +
  63 +)
  1 +package department
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/department"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 +)
  11 +
  12 +func SystemAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.DepartmentAddRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := department.NewSystemAddLogic(r.Context(), svcCtx)
  21 + resp, err := l.SystemAdd(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package department
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/department"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 +)
  11 +
  12 +func SystemGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.DepartmentGetRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := department.NewSystemGetLogic(r.Context(), svcCtx)
  21 + resp, err := l.SystemGet(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package department
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/department"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 +)
  11 +
  12 +func SystemListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.DepartmentListRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := department.NewSystemListLogic(r.Context(), svcCtx)
  21 + resp, err := l.SystemList(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package department
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/department"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 +)
  11 +
  12 +func SystemUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.DepartmentUpdateRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := department.NewSystemUpdateLogic(r.Context(), svcCtx)
  21 + resp, err := l.SystemUpdate(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 article "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/article" 7 article "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/article"
8 comment "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/comment" 8 comment "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/comment"
9 company "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/company" 9 company "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/company"
  10 + department "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/department"
10 message "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/message" 11 message "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/message"
11 role "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/role" 12 role "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/role"
12 tags "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/tags" 13 tags "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/tags"
@@ -323,4 +324,31 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -323,4 +324,31 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
323 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), 324 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
324 rest.WithPrefix("/v1"), 325 rest.WithPrefix("/v1"),
325 ) 326 )
  327 +
  328 + server.AddRoutes(
  329 + []rest.Route{
  330 + {
  331 + Method: http.MethodPost,
  332 + Path: "/system/department/list",
  333 + Handler: department.SystemListHandler(serverCtx),
  334 + },
  335 + {
  336 + Method: http.MethodPost,
  337 + Path: "/system/department/add",
  338 + Handler: department.SystemAddHandler(serverCtx),
  339 + },
  340 + {
  341 + Method: http.MethodGet,
  342 + Path: "/system/department/:id",
  343 + Handler: department.SystemGetHandler(serverCtx),
  344 + },
  345 + {
  346 + Method: http.MethodPut,
  347 + Path: "/system/department/:id",
  348 + Handler: department.SystemUpdateHandler(serverCtx),
  349 + },
  350 + },
  351 + rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
  352 + rest.WithPrefix("/v1"),
  353 + )
326 } 354 }
  1 +package department
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 +
  9 + "github.com/zeromicro/go-zero/core/logx"
  10 +)
  11 +
  12 +type SystemAddLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewSystemAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemAddLogic {
  19 + return &SystemAddLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types.DepartmentGetResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
  1 +package department
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 +
  9 + "github.com/zeromicro/go-zero/core/logx"
  10 +)
  11 +
  12 +type SystemGetLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewSystemGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemGetLogic {
  19 + return &SystemGetLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *SystemGetLogic) SystemGet(req *types.DepartmentGetRequest) (resp *types.DepartmentGetResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
  1 +package department
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 +
  9 + "github.com/zeromicro/go-zero/core/logx"
  10 +)
  11 +
  12 +type SystemListLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewSystemListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemListLogic {
  19 + return &SystemListLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *SystemListLogic) SystemList(req *types.DepartmentListRequest) (resp *types.DepartmentListResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
  1 +package department
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 +
  9 + "github.com/zeromicro/go-zero/core/logx"
  10 +)
  11 +
  12 +type SystemUpdateLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewSystemUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUpdateLogic {
  19 + return &SystemUpdateLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (resp *types.DepartmentGetResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
@@ -722,3 +722,31 @@ type Auth struct { @@ -722,3 +722,31 @@ type Auth struct {
722 Name string `json:"name"` // 名称 722 Name string `json:"name"` // 名称
723 Code string `json:"code"` // 编码 723 Code string `json:"code"` // 编码
724 } 724 }
  725 +
  726 +type DepartmentAddRequest struct {
  727 + Name string `json:"name"` // 分组名称
  728 + Ids []int64 `json:"ids"` // 用户ID
  729 +}
  730 +
  731 +type DepartmentGetRequest struct {
  732 + Id int64 `path:"id"`
  733 +}
  734 +
  735 +type DepartmentGetResponse struct {
  736 + Department Department `json:"department"`
  737 +}
  738 +
  739 +type DepartmentUpdateRequest struct {
  740 + Id int64 `path:"id"`
  741 + Name string `json:"name"`
  742 +}
  743 +
  744 +type DepartmentListRequest struct {
  745 + Page int `json:"page"`
  746 + Size int `json:"size"`
  747 +}
  748 +
  749 +type DepartmentListResponse struct {
  750 + List []Department `json:"list"`
  751 + Total int64 `json:"total"`
  752 +}
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" 5 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
6 "gorm.io/gorm" 6 "gorm.io/gorm"
7 "gorm.io/plugin/soft_delete" 7 "gorm.io/plugin/soft_delete"
  8 + "time"
8 ) 9 )
9 10
10 type Department struct { 11 type Department struct {
@@ -12,7 +13,6 @@ type Department struct { @@ -12,7 +13,6 @@ type Department struct {
12 CompanyId int64 `json:"companyId,omitempty"` // 公司ID 13 CompanyId int64 `json:"companyId,omitempty"` // 公司ID
13 ParentId int64 `json:"parentId,omitempty"` // 父级ID 14 ParentId int64 `json:"parentId,omitempty"` // 父级ID
14 Name string `json:"name,omitempty"` // 部门名称 15 Name string `json:"name,omitempty"` // 部门名称
15 -  
16 CreatedAt int64 `json:"createdAt,omitempty"` 16 CreatedAt int64 `json:"createdAt,omitempty"`
17 UpdatedAt int64 `json:"updatedAt,omitempty"` 17 UpdatedAt int64 `json:"updatedAt,omitempty"`
18 DeletedAt int64 `json:"deletedAt,omitempty"` 18 DeletedAt int64 `json:"deletedAt,omitempty"`
@@ -25,13 +25,13 @@ func (m *Department) TableName() string { @@ -25,13 +25,13 @@ func (m *Department) TableName() string {
25 } 25 }
26 26
27 func (m *Department) BeforeCreate(tx *gorm.DB) (err error) { 27 func (m *Department) BeforeCreate(tx *gorm.DB) (err error) {
28 - // m.CreatedAt = time.Now().Unix()  
29 - // m.UpdatedAt = time.Now().Unix() 28 + m.CreatedAt = time.Now().Unix()
  29 + m.UpdatedAt = time.Now().Unix()
30 return 30 return
31 } 31 }
32 32
33 func (m *Department) BeforeUpdate(tx *gorm.DB) (err error) { 33 func (m *Department) BeforeUpdate(tx *gorm.DB) (err error) {
34 - // m.UpdatedAt = time.Now().Unix() 34 + m.UpdatedAt = time.Now().Unix()
35 return 35 return
36 } 36 }
37 37