refactor: split backend transport and domain modules
This commit is contained in:
+28
-216
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type AccessService struct{ uc *biz.AccessUsecase }
|
||||
@@ -63,32 +64,32 @@ func (s *AccessService) UpdateAuthority(ctx context.Context, v *biz.Authority) e
|
||||
func (s *AccessService) DeleteAuthority(ctx context.Context, id uint) error {
|
||||
return s.uc.Repo().DeleteAuthority(ctx, id)
|
||||
}
|
||||
func (s *AccessService) SetAuthorityMenus(ctx context.Context, id uint, ids []uint) error {
|
||||
return s.uc.Repo().SetAuthorityMenus(ctx, id, ids)
|
||||
func authorityDomain(req *dto.AuthorityRequest) *biz.Authority {
|
||||
return &biz.Authority{AuthorityID: req.AuthorityID, AuthorityName: req.AuthorityName, ParentID: req.ParentID, DataScope: req.DataScope, DefaultRouter: req.DefaultRouter}
|
||||
}
|
||||
func (s *AccessService) AuthorityMenuIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
return s.uc.Repo().AuthorityMenuIDs(ctx, id)
|
||||
func authorityResponse(value *biz.Authority) *dto.AuthorityResponse {
|
||||
return &dto.AuthorityResponse{AuthorityID: value.AuthorityID, AuthorityName: value.AuthorityName, ParentID: value.ParentID, DataScope: value.DataScope, DefaultRouter: value.DefaultRouter}
|
||||
}
|
||||
func (s *AccessService) AuthorityMenus(ctx context.Context, id uint) ([]map[string]any, error) {
|
||||
ids, err := s.uc.Repo().AuthorityMenuIDs(ctx, id)
|
||||
if err != nil {
|
||||
func (s *AccessService) CreateAuthorityRequest(ctx context.Context, req *dto.AuthorityRequest) (*dto.AuthorityResponse, error) {
|
||||
value := authorityDomain(req)
|
||||
if err := s.CreateAuthority(ctx, value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selected := make(map[uint]bool, len(ids))
|
||||
for _, value := range ids {
|
||||
selected[value] = true
|
||||
}
|
||||
menus, err := s.uc.Repo().ListMenus(ctx)
|
||||
if err != nil {
|
||||
return authorityResponse(value), nil
|
||||
}
|
||||
func (s *AccessService) CopyAuthorityRequest(ctx context.Context, req *dto.CopyAuthorityRequest) (*dto.AuthorityResponse, error) {
|
||||
value := authorityDomain(&req.Authority)
|
||||
if err := s.CopyAuthority(ctx, req.OldAuthorityID, value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(ids))
|
||||
for _, menu := range menus {
|
||||
if selected[menu.ID] {
|
||||
out = append(out, map[string]any{"menuId": menu.ID, "authorityId": id, "sysBaseMenu": convertMenu(menu), "parentId": menu.ParentID})
|
||||
}
|
||||
return authorityResponse(value), nil
|
||||
}
|
||||
func (s *AccessService) UpdateAuthorityRequest(ctx context.Context, req *dto.AuthorityRequest) (*dto.AuthorityResponse, error) {
|
||||
value := authorityDomain(req)
|
||||
if err := s.UpdateAuthority(ctx, value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
return authorityResponse(value), nil
|
||||
}
|
||||
func (s *AccessService) SetAuthorityUsers(ctx context.Context, id uint, ids []uint) error {
|
||||
return s.uc.Repo().SetAuthorityUsers(ctx, id, ids)
|
||||
@@ -106,127 +107,16 @@ func (s *AccessService) ResolveDataScope(ctx context.Context, authorityID, userI
|
||||
return s.uc.Repo().ResolveDataScope(ctx, authorityID, userID)
|
||||
}
|
||||
|
||||
func (s *AccessService) Menus(ctx context.Context) ([]map[string]any, error) {
|
||||
items, err := s.uc.Repo().ListMenus(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
for _, v := range items {
|
||||
v.Buttons, err = s.uc.Repo().Buttons(ctx, v.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, convertMenu(v))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *AccessService) MenuTree(ctx context.Context) ([]map[string]any, error) {
|
||||
items, err := s.uc.Repo().ListMenus(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
byID := make(map[uint]*biz.Menu, len(items))
|
||||
for _, item := range items {
|
||||
item.Buttons, err = s.uc.Repo().Buttons(ctx, item.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
item.Children = []*biz.Menu{}
|
||||
byID[item.ID] = item
|
||||
}
|
||||
roots := make([]*biz.Menu, 0)
|
||||
for _, item := range items {
|
||||
if parent := byID[item.ParentID]; parent != nil {
|
||||
parent.Children = append(parent.Children, item)
|
||||
} else {
|
||||
roots = append(roots, item)
|
||||
}
|
||||
}
|
||||
out := make([]map[string]any, 0, len(roots))
|
||||
for _, item := range roots {
|
||||
out = append(out, convertMenu(item))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *AccessService) CreateMenu(ctx context.Context, v *biz.Menu) error {
|
||||
return s.uc.Repo().CreateMenu(ctx, v)
|
||||
}
|
||||
func (s *AccessService) UpdateMenu(ctx context.Context, v *biz.Menu) error {
|
||||
return s.uc.Repo().UpdateMenu(ctx, v)
|
||||
}
|
||||
func (s *AccessService) DeleteMenu(ctx context.Context, id uint) error {
|
||||
return s.uc.Repo().DeleteMenu(ctx, id)
|
||||
}
|
||||
func (s *AccessService) Menu(ctx context.Context, id uint) (map[string]any, error) {
|
||||
v, err := s.uc.Repo().FindMenu(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v.Buttons, err = s.uc.Repo().Buttons(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return convertMenu(v), nil
|
||||
}
|
||||
func (s *AccessService) MenuRoleIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
return s.uc.Repo().MenuRoleIDs(ctx, id)
|
||||
}
|
||||
func (s *AccessService) SetMenuRoles(ctx context.Context, id uint, ids []uint) error {
|
||||
return s.uc.Repo().SetMenuRoles(ctx, id, ids)
|
||||
}
|
||||
func (s *AccessService) ReplaceMenuButtons(ctx context.Context, menuID uint, buttons []*biz.MenuButton) error {
|
||||
return s.uc.Repo().ReplaceMenuButtons(ctx, menuID, buttons)
|
||||
}
|
||||
|
||||
func (s *AccessService) APIs(ctx context.Context, page, size int, q *biz.API) ([]map[string]any, int64, error) {
|
||||
items, total, err := s.uc.Repo().ListAPIs(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, apiDTO(v))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *AccessService) CreateAPI(ctx context.Context, v *biz.API) error {
|
||||
return s.uc.Repo().CreateAPI(ctx, v)
|
||||
}
|
||||
func (s *AccessService) UpdateAPI(ctx context.Context, v *biz.API) error {
|
||||
return s.uc.Repo().UpdateAPI(ctx, v)
|
||||
}
|
||||
func (s *AccessService) DeleteAPIs(ctx context.Context, ids []uint) error {
|
||||
return s.uc.Repo().DeleteAPIs(ctx, ids)
|
||||
}
|
||||
func (s *AccessService) API(ctx context.Context, id uint) (map[string]any, error) {
|
||||
v, err := s.uc.Repo().FindAPI(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return apiDTO(v), nil
|
||||
}
|
||||
func (s *AccessService) APIRoleIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
return s.uc.Repo().APIRoleIDs(ctx, id)
|
||||
}
|
||||
func (s *AccessService) SetAPIRoles(ctx context.Context, id uint, ids []uint) error {
|
||||
return s.uc.Repo().SetAPIRoles(ctx, id, ids)
|
||||
}
|
||||
func (s *AccessService) PolicyPaths(ctx context.Context, id uint) ([]map[string]any, error) {
|
||||
items, err := s.uc.Repo().PolicyPaths(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, map[string]any{"path": v.Path, "method": v.Method})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *AccessService) SetPolicyPaths(ctx context.Context, id uint, paths []*biz.API) error {
|
||||
return s.uc.Repo().SetPolicyPaths(ctx, id, paths)
|
||||
}
|
||||
func (s *AccessService) SyncAPIs(ctx context.Context, routes []*biz.API) (map[string]any, error) {
|
||||
func (s *AccessService) SyncAPIs(ctx context.Context, routes []*biz.API) (*dto.APISyncResponse, error) {
|
||||
stored, _, err := s.uc.Repo().ListAPIs(ctx, 1, 100000, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -250,31 +140,27 @@ func (s *AccessService) SyncAPIs(ctx context.Context, routes []*biz.API) (map[st
|
||||
for _, item := range stored {
|
||||
storedSet[key(item)] = item
|
||||
}
|
||||
added := make([]map[string]any, 0)
|
||||
deleted := make([]map[string]any, 0)
|
||||
ignoredDTO := make([]map[string]any, 0, len(ignored))
|
||||
added := make([]*dto.APIResponse, 0)
|
||||
deleted := make([]*dto.APIResponse, 0)
|
||||
ignoredDTO := make([]*dto.APIResponse, 0, len(ignored))
|
||||
for k, item := range routeSet {
|
||||
if storedSet[k] == nil {
|
||||
added = append(added, apiDTO(item))
|
||||
added = append(added, apiResponse(item))
|
||||
}
|
||||
}
|
||||
for k, item := range storedSet {
|
||||
if routeSet[k] == nil && !ignoreSet[k] {
|
||||
deleted = append(deleted, apiDTO(item))
|
||||
deleted = append(deleted, apiResponse(item))
|
||||
}
|
||||
}
|
||||
for _, item := range ignored {
|
||||
ignoredDTO = append(ignoredDTO, apiDTO(item))
|
||||
ignoredDTO = append(ignoredDTO, apiResponse(item))
|
||||
}
|
||||
return map[string]any{"newApis": added, "deleteApis": deleted, "ignoreApis": ignoredDTO}, nil
|
||||
return &dto.APISyncResponse{NewAPIs: added, DeleteAPIs: deleted, IgnoreAPIs: ignoredDTO}, nil
|
||||
}
|
||||
func (s *AccessService) SetAPIIgnored(ctx context.Context, path, method string, ignored bool) error {
|
||||
return s.uc.Repo().SetAPIIgnored(ctx, path, method, ignored)
|
||||
}
|
||||
func (s *AccessService) ApplyAPISync(ctx context.Context, added, deleted []*biz.API) error {
|
||||
return s.uc.Repo().ApplyAPISync(ctx, added, deleted)
|
||||
}
|
||||
|
||||
func (s *AccessService) Buttons(ctx context.Context, id uint) ([]map[string]any, error) {
|
||||
items, err := s.uc.Repo().Buttons(ctx, id)
|
||||
if err != nil {
|
||||
@@ -301,77 +187,3 @@ func (s *AccessService) SetSelectedButtons(ctx context.Context, aid, menuID uint
|
||||
func (s *AccessService) CanRemoveButton(ctx context.Context, id uint) (bool, error) {
|
||||
return s.uc.Repo().CanRemoveButton(ctx, id)
|
||||
}
|
||||
|
||||
func (s *AccessService) Departments(ctx context.Context, name string) ([]map[string]any, error) {
|
||||
items, err := s.uc.Repo().ListDepartments(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, departmentDTO(v))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *AccessService) CreateDepartment(ctx context.Context, v *biz.Department) error {
|
||||
return s.uc.Repo().CreateDepartment(ctx, v)
|
||||
}
|
||||
func (s *AccessService) UpdateDepartment(ctx context.Context, v *biz.Department) error {
|
||||
return s.uc.Repo().UpdateDepartment(ctx, v)
|
||||
}
|
||||
func (s *AccessService) DeleteDepartment(ctx context.Context, id uint) error {
|
||||
return s.uc.Repo().DeleteDepartment(ctx, id)
|
||||
}
|
||||
func (s *AccessService) Department(ctx context.Context, id uint) (map[string]any, error) {
|
||||
v, err := s.uc.Repo().FindDepartment(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return departmentDTO(v), nil
|
||||
}
|
||||
func (s *AccessService) DepartmentUserIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
return s.uc.Repo().DepartmentUserIDs(ctx, id)
|
||||
}
|
||||
func (s *AccessService) SetDepartmentUsers(ctx context.Context, id uint, ids []uint) error {
|
||||
return s.uc.Repo().SetDepartmentUsers(ctx, id, ids)
|
||||
}
|
||||
func (s *AccessService) SetUserDepartments(ctx context.Context, id uint, ids []uint, primary uint) error {
|
||||
return s.uc.Repo().SetUserDepartments(ctx, id, ids, primary)
|
||||
}
|
||||
|
||||
func (s *AccessService) Positions(ctx context.Context, page, size int, q *biz.Position) ([]map[string]any, int64, error) {
|
||||
items, total, err := s.uc.Repo().ListPositions(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, positionDTO(v))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *AccessService) CreatePosition(ctx context.Context, v *biz.Position) error {
|
||||
return s.uc.Repo().CreatePosition(ctx, v)
|
||||
}
|
||||
func (s *AccessService) UpdatePosition(ctx context.Context, v *biz.Position) error {
|
||||
return s.uc.Repo().UpdatePosition(ctx, v)
|
||||
}
|
||||
func (s *AccessService) DeletePosition(ctx context.Context, id uint) error {
|
||||
return s.uc.Repo().DeletePosition(ctx, id)
|
||||
}
|
||||
func (s *AccessService) Position(ctx context.Context, id uint) (map[string]any, error) {
|
||||
v, err := s.uc.Repo().FindPosition(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return positionDTO(v), nil
|
||||
}
|
||||
func (s *AccessService) PositionUserIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
return s.uc.Repo().PositionUserIDs(ctx, id)
|
||||
}
|
||||
func (s *AccessService) SetPositionUsers(ctx context.Context, id uint, ids []uint) error {
|
||||
return s.uc.Repo().SetPositionUsers(ctx, id, ids)
|
||||
}
|
||||
func (s *AccessService) SetUserPositions(ctx context.Context, id uint, ids []uint) error {
|
||||
return s.uc.Repo().SetUserPositions(ctx, id, ids)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
func apiDomain(value *dto.APIRequest) *biz.API {
|
||||
return &biz.API{ID: value.ID, Path: value.Path, Description: value.Description, APIGroup: value.APIGroup, Method: value.Method}
|
||||
}
|
||||
|
||||
func apiResponse(value *biz.API) *dto.APIResponse {
|
||||
return &dto.APIResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Path: value.Path, Description: value.Description, APIGroup: value.APIGroup, Method: value.Method}
|
||||
}
|
||||
|
||||
func apiResponses(items []*biz.API) []*dto.APIResponse {
|
||||
out := make([]*dto.APIResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, apiResponse(item))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *AccessService) ListAPI(ctx context.Context, req *dto.APIListRequest) ([]*dto.APIResponse, int64, error) {
|
||||
items, total, err := s.uc.Repo().ListAPIs(ctx, req.Page, req.PageSize, &biz.API{Path: req.Path, Description: req.Description, APIGroup: req.APIGroup, Method: req.Method})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return apiResponses(items), total, nil
|
||||
}
|
||||
|
||||
func (s *AccessService) AllAPI(ctx context.Context) ([]*dto.APIResponse, error) {
|
||||
items, _, err := s.uc.Repo().ListAPIs(ctx, 1, 10000, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return apiResponses(items), nil
|
||||
}
|
||||
|
||||
func (s *AccessService) CreateAPIRequest(ctx context.Context, req *dto.APIRequest) error {
|
||||
return s.uc.Repo().CreateAPI(ctx, apiDomain(req))
|
||||
}
|
||||
func (s *AccessService) UpdateAPIRequest(ctx context.Context, req *dto.APIRequest) error {
|
||||
return s.uc.Repo().UpdateAPI(ctx, apiDomain(req))
|
||||
}
|
||||
func (s *AccessService) FindAPIResponse(ctx context.Context, id uint) (*dto.APIResponse, error) {
|
||||
value, err := s.uc.Repo().FindAPI(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return apiResponse(value), nil
|
||||
}
|
||||
func (s *AccessService) ApplyAPISyncRequest(ctx context.Context, req *dto.ApplyAPISyncRequest) error {
|
||||
added := make([]*biz.API, 0, len(req.NewAPIs))
|
||||
deleted := make([]*biz.API, 0, len(req.DeleteAPIs))
|
||||
for i := range req.NewAPIs {
|
||||
added = append(added, apiDomain(&req.NewAPIs[i]))
|
||||
}
|
||||
for i := range req.DeleteAPIs {
|
||||
deleted = append(deleted, apiDomain(&req.DeleteAPIs[i]))
|
||||
}
|
||||
return s.uc.Repo().ApplyAPISync(ctx, added, deleted)
|
||||
}
|
||||
func (s *AccessService) SetPolicyPathsRequest(ctx context.Context, req *dto.SetPolicyPathsRequest) error {
|
||||
paths := make([]*biz.API, 0, len(req.Infos))
|
||||
for _, value := range req.Infos {
|
||||
paths = append(paths, &biz.API{Path: value.Path, Method: value.Method})
|
||||
}
|
||||
return s.uc.Repo().SetPolicyPaths(ctx, req.AuthorityID, paths)
|
||||
}
|
||||
func (s *AccessService) PolicyPathResponses(ctx context.Context, authorityID uint) ([]dto.PolicyPathRequest, error) {
|
||||
items, err := s.uc.Repo().PolicyPaths(ctx, authorityID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]dto.PolicyPathRequest, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, dto.PolicyPathRequest{Path: item.Path, Method: item.Method})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *AccessService) SyncAPIResponses(ctx context.Context, routes []dto.APIRequest) (*dto.APISyncResponse, error) {
|
||||
items := make([]*biz.API, 0, len(routes))
|
||||
for i := range routes {
|
||||
items = append(items, apiDomain(&routes[i]))
|
||||
}
|
||||
return s.SyncAPIs(ctx, items)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package dto
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type AnnouncementRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
UserID *uint `json:"userID"`
|
||||
Attachments json.RawMessage `json:"attachments"`
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package dto
|
||||
|
||||
import "time"
|
||||
|
||||
type APIRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Path string `json:"path"`
|
||||
Description string `json:"description"`
|
||||
APIGroup string `json:"apiGroup"`
|
||||
Method string `json:"method"`
|
||||
}
|
||||
|
||||
type APIListRequest struct {
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pageSize"`
|
||||
Path string `json:"path"`
|
||||
Description string `json:"description"`
|
||||
APIGroup string `json:"apiGroup"`
|
||||
Method string `json:"method"`
|
||||
}
|
||||
|
||||
type APIResponse struct {
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt any `json:"DeletedAt"`
|
||||
Path string `json:"path"`
|
||||
Description string `json:"description"`
|
||||
APIGroup string `json:"apiGroup"`
|
||||
Method string `json:"method"`
|
||||
}
|
||||
|
||||
type DeleteAPIRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
}
|
||||
type DeleteAPIsRequest struct {
|
||||
IDs []uint `json:"ids"`
|
||||
}
|
||||
type GetAPIRequest struct {
|
||||
ID uint `json:"id"`
|
||||
}
|
||||
type SetAPIRolesRequest struct {
|
||||
APIID uint `json:"apiId"`
|
||||
AuthorityIDs []uint `json:"authorityIds"`
|
||||
}
|
||||
type IgnoreAPIRequest struct {
|
||||
Path string `json:"path"`
|
||||
Method string `json:"method"`
|
||||
Flag bool `json:"flag"`
|
||||
}
|
||||
type ApplyAPISyncRequest struct {
|
||||
NewAPIs []APIRequest `json:"newApis"`
|
||||
DeleteAPIs []APIRequest `json:"deleteApis"`
|
||||
}
|
||||
type PolicyPathRequest struct {
|
||||
Path string `json:"path"`
|
||||
Method string `json:"method"`
|
||||
}
|
||||
type SetPolicyPathsRequest struct {
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
Infos []PolicyPathRequest `json:"casbinInfos"`
|
||||
}
|
||||
type GetPolicyPathsRequest struct {
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
}
|
||||
|
||||
type APISyncResponse struct {
|
||||
NewAPIs []*APIResponse `json:"newApis"`
|
||||
DeleteAPIs []*APIResponse `json:"deleteApis"`
|
||||
IgnoreAPIs []*APIResponse `json:"ignoreApis"`
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package dto
|
||||
|
||||
type AuthorityRequest struct {
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
AuthorityName string `json:"authorityName"`
|
||||
ParentID *uint `json:"parentId"`
|
||||
DataScope int `json:"dataScope"`
|
||||
DefaultRouter string `json:"defaultRouter"`
|
||||
}
|
||||
|
||||
type CopyAuthorityRequest struct {
|
||||
Authority AuthorityRequest `json:"authority"`
|
||||
OldAuthorityID uint `json:"oldAuthorityId"`
|
||||
}
|
||||
|
||||
type DeleteAuthorityRequest struct {
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
}
|
||||
type SetRoleUsersRequest struct {
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
UserIDs []uint `json:"userIds"`
|
||||
}
|
||||
type SetDataScopeRequest struct {
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
DataScope int `json:"dataScope"`
|
||||
DepartmentIDs []uint `json:"deptIds"`
|
||||
}
|
||||
|
||||
type AuthorityResponse struct {
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
AuthorityName string `json:"authorityName"`
|
||||
ParentID *uint `json:"parentId"`
|
||||
DataScope int `json:"dataScope"`
|
||||
DefaultRouter string `json:"defaultRouter"`
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dto
|
||||
|
||||
type SendEmailRequest struct {
|
||||
To string `json:"to"`
|
||||
Subject string `json:"subject"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package dto
|
||||
|
||||
type MenuMetaRequest struct {
|
||||
ActiveName string `json:"activeName"`
|
||||
KeepAlive bool `json:"keepAlive"`
|
||||
DefaultMenu bool `json:"defaultMenu"`
|
||||
Title string `json:"title"`
|
||||
Icon string `json:"icon"`
|
||||
CloseTab bool `json:"closeTab"`
|
||||
TransitionType string `json:"transitionType"`
|
||||
}
|
||||
|
||||
type MenuButtonRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"desc"`
|
||||
}
|
||||
|
||||
type MenuParameterRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Type string `json:"type"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type MenuRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
ParentID uint `json:"parentId"`
|
||||
Path string `json:"path"`
|
||||
Name string `json:"name"`
|
||||
Hidden bool `json:"hidden"`
|
||||
Component string `json:"component"`
|
||||
Sort int `json:"sort"`
|
||||
Meta MenuMetaRequest `json:"meta"`
|
||||
MenuButtons []MenuButtonRequest `json:"menuBtn"`
|
||||
Parameters []MenuParameterRequest `json:"parameters"`
|
||||
}
|
||||
|
||||
type DeleteMenuRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
}
|
||||
|
||||
type GetMenuRequest struct {
|
||||
ID uint `json:"id"`
|
||||
}
|
||||
|
||||
type AuthorityMenuItemRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
}
|
||||
|
||||
type SetAuthorityMenusRequest struct {
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
Menus []AuthorityMenuItemRequest `json:"menus"`
|
||||
}
|
||||
|
||||
type GetAuthorityMenusRequest struct {
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
}
|
||||
|
||||
type SetMenuRolesRequest struct {
|
||||
MenuID uint `json:"menuId"`
|
||||
AuthorityIDs []uint `json:"authorityIds"`
|
||||
}
|
||||
|
||||
type MenuMetaResponse struct {
|
||||
ActiveName string `json:"activeName"`
|
||||
KeepAlive bool `json:"keepAlive"`
|
||||
DefaultMenu bool `json:"defaultMenu"`
|
||||
Title string `json:"title"`
|
||||
Icon string `json:"icon"`
|
||||
CloseTab bool `json:"closeTab"`
|
||||
TransitionType string `json:"transitionType"`
|
||||
}
|
||||
|
||||
type MenuButtonResponse struct {
|
||||
ID uint `json:"ID"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"desc"`
|
||||
SysBaseMenuID uint `json:"sysBaseMenuID"`
|
||||
}
|
||||
|
||||
type MenuParameterResponse struct {
|
||||
ID uint `json:"ID"`
|
||||
SysBaseMenuID uint `json:"SysBaseMenuID"`
|
||||
Type string `json:"type"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type MenuResponse struct {
|
||||
ID uint `json:"ID"`
|
||||
ParentID uint `json:"parentId"`
|
||||
Path string `json:"path"`
|
||||
Name string `json:"name"`
|
||||
Hidden bool `json:"hidden"`
|
||||
Component string `json:"component"`
|
||||
Sort int `json:"sort"`
|
||||
Meta MenuMetaResponse `json:"meta"`
|
||||
Children []*MenuResponse `json:"children"`
|
||||
Parameters []MenuParameterResponse `json:"parameters"`
|
||||
MenuButtons []MenuButtonResponse `json:"menuBtn"`
|
||||
Buttons map[string]uint `json:"btns"`
|
||||
}
|
||||
|
||||
type AuthorityMenuResponse struct {
|
||||
MenuID uint `json:"menuId"`
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
SysBaseMenu *MenuResponse `json:"sysBaseMenu"`
|
||||
ParentID uint `json:"parentId"`
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package dto
|
||||
|
||||
import "time"
|
||||
|
||||
type DepartmentRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Name string `json:"name"`
|
||||
ParentID uint `json:"parentId"`
|
||||
Sort int `json:"sort"`
|
||||
LeaderID uint `json:"leaderId"`
|
||||
Status bool `json:"status"`
|
||||
}
|
||||
|
||||
type DepartmentListRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
type DeleteDepartmentRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
}
|
||||
type SetDepartmentUsersRequest struct {
|
||||
DepartmentID uint `json:"deptId"`
|
||||
UserIDs []uint `json:"userIds"`
|
||||
}
|
||||
type SetUserDepartmentsRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
DepartmentIDs []uint `json:"deptIds"`
|
||||
Primary uint `json:"primaryDeptId"`
|
||||
}
|
||||
|
||||
type DepartmentResponse struct {
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt any `json:"DeletedAt"`
|
||||
Name string `json:"name"`
|
||||
ParentID uint `json:"parentId"`
|
||||
Ancestors string `json:"ancestors"`
|
||||
Sort int `json:"sort"`
|
||||
LeaderID uint `json:"leaderId"`
|
||||
Leader any `json:"leader"`
|
||||
Status bool `json:"status"`
|
||||
Children []*DepartmentResponse `json:"children"`
|
||||
NamePath string `json:"namePath"`
|
||||
}
|
||||
|
||||
type PositionRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Sort int `json:"sort"`
|
||||
Status bool `json:"status"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
type PositionListRequest struct {
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pageSize"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
type DeletePositionRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
}
|
||||
type SetPositionUsersRequest struct {
|
||||
PositionID uint `json:"positionId"`
|
||||
UserIDs []uint `json:"userIds"`
|
||||
}
|
||||
type SetUserPositionsRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
PositionIDs []uint `json:"positionIds"`
|
||||
}
|
||||
|
||||
type PositionResponse struct {
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt any `json:"DeletedAt"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Sort int `json:"sort"`
|
||||
Status bool `json:"status"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package dto
|
||||
|
||||
type GetAuthorityButtonsRequest struct {
|
||||
MenuID uint `json:"menuID"`
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
}
|
||||
|
||||
type SetAuthorityButtonsRequest struct {
|
||||
MenuID uint `json:"menuID"`
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
Selected []uint `json:"selected"`
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package dto
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type TaskRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Spec string `json:"spec"`
|
||||
WithSeconds bool `json:"withSeconds"`
|
||||
ExecutorType string `json:"executorType"`
|
||||
MethodName string `json:"methodName"`
|
||||
Params json.RawMessage `json:"params"`
|
||||
HTTPURL string `json:"httpUrl"`
|
||||
HTTPMethod string `json:"httpMethod"`
|
||||
HTTPHeader json.RawMessage `json:"httpHeader"`
|
||||
HTTPBody string `json:"httpBody"`
|
||||
HTTPAllowPrivate bool `json:"httpAllowPrivate"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type DeleteTaskRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
}
|
||||
type ToggleTaskRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type MenuService struct{ uc *biz.MenuUsecase }
|
||||
|
||||
func NewMenuService(uc *biz.MenuUsecase) *MenuService { return &MenuService{uc: uc} }
|
||||
|
||||
func menuDomain(v *dto.MenuRequest) *biz.Menu {
|
||||
menu := &biz.Menu{ID: v.ID, ParentID: v.ParentID, Path: v.Path, Name: v.Name, Hidden: v.Hidden, Component: v.Component, Sort: v.Sort, ActiveName: v.Meta.ActiveName, KeepAlive: v.Meta.KeepAlive, DefaultMenu: v.Meta.DefaultMenu, Title: v.Meta.Title, Icon: v.Meta.Icon, CloseTab: v.Meta.CloseTab, TransitionType: v.Meta.TransitionType}
|
||||
menu.Buttons = make([]*biz.MenuButton, 0, len(v.MenuButtons))
|
||||
for _, button := range v.MenuButtons {
|
||||
menu.Buttons = append(menu.Buttons, &biz.MenuButton{ID: button.ID, Name: button.Name, Description: button.Description, MenuID: v.ID})
|
||||
}
|
||||
menu.Parameters = make([]*biz.MenuParameter, 0, len(v.Parameters))
|
||||
for _, parameter := range v.Parameters {
|
||||
menu.Parameters = append(menu.Parameters, &biz.MenuParameter{ID: parameter.ID, MenuID: v.ID, Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
|
||||
}
|
||||
return menu
|
||||
}
|
||||
|
||||
func menuResponse(menu *biz.Menu) *dto.MenuResponse {
|
||||
children := make([]*dto.MenuResponse, 0, len(menu.Children))
|
||||
for _, child := range menu.Children {
|
||||
children = append(children, menuResponse(child))
|
||||
}
|
||||
buttons := make([]dto.MenuButtonResponse, 0, len(menu.Buttons))
|
||||
buttonAuthorities := make(map[string]uint, len(menu.Buttons))
|
||||
for _, button := range menu.Buttons {
|
||||
buttons = append(buttons, dto.MenuButtonResponse{ID: button.ID, Name: button.Name, Description: button.Description, SysBaseMenuID: button.MenuID})
|
||||
if button.AuthorityID != 0 {
|
||||
buttonAuthorities[button.Name] = button.AuthorityID
|
||||
}
|
||||
}
|
||||
parameters := make([]dto.MenuParameterResponse, 0, len(menu.Parameters))
|
||||
for _, parameter := range menu.Parameters {
|
||||
parameters = append(parameters, dto.MenuParameterResponse{ID: parameter.ID, SysBaseMenuID: parameter.MenuID, Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
|
||||
}
|
||||
return &dto.MenuResponse{ID: menu.ID, ParentID: menu.ParentID, Path: menu.Path, Name: menu.Name, Hidden: menu.Hidden, Component: menu.Component, Sort: menu.Sort, Meta: dto.MenuMetaResponse{ActiveName: menu.ActiveName, KeepAlive: menu.KeepAlive, DefaultMenu: menu.DefaultMenu, Title: menu.Title, Icon: menu.Icon, CloseTab: menu.CloseTab, TransitionType: menu.TransitionType}, Children: children, Parameters: parameters, MenuButtons: buttons, Buttons: buttonAuthorities}
|
||||
}
|
||||
|
||||
func menuResponses(items []*biz.Menu) []*dto.MenuResponse {
|
||||
out := make([]*dto.MenuResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, menuResponse(item))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *MenuService) List(ctx context.Context) ([]*dto.MenuResponse, error) {
|
||||
items, err := s.uc.List(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return menuResponses(items), nil
|
||||
}
|
||||
|
||||
func (s *MenuService) Tree(ctx context.Context) ([]*dto.MenuResponse, error) {
|
||||
items, err := s.uc.Tree(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return menuResponses(items), nil
|
||||
}
|
||||
|
||||
func (s *MenuService) Create(ctx context.Context, req *dto.MenuRequest) error {
|
||||
return s.uc.Create(ctx, menuDomain(req))
|
||||
}
|
||||
func (s *MenuService) Update(ctx context.Context, req *dto.MenuRequest) error {
|
||||
return s.uc.Update(ctx, menuDomain(req))
|
||||
}
|
||||
func (s *MenuService) Delete(ctx context.Context, id uint) error { return s.uc.Delete(ctx, id) }
|
||||
|
||||
func (s *MenuService) Find(ctx context.Context, id uint) (*dto.MenuResponse, error) {
|
||||
item, err := s.uc.Find(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return menuResponse(item), nil
|
||||
}
|
||||
|
||||
func (s *MenuService) SetAuthorityMenus(ctx context.Context, req *dto.SetAuthorityMenusRequest) error {
|
||||
ids := make([]uint, 0, len(req.Menus))
|
||||
for _, menu := range req.Menus {
|
||||
ids = append(ids, menu.ID)
|
||||
}
|
||||
return s.uc.SetAuthorityMenus(ctx, req.AuthorityID, ids)
|
||||
}
|
||||
|
||||
func (s *MenuService) AuthorityMenus(ctx context.Context, authorityID uint) ([]*dto.AuthorityMenuResponse, error) {
|
||||
items, err := s.uc.AuthorityMenus(ctx, authorityID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*dto.AuthorityMenuResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, &dto.AuthorityMenuResponse{MenuID: item.ID, AuthorityID: authorityID, SysBaseMenu: menuResponse(item), ParentID: item.ParentID})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s *MenuService) RoleIDs(ctx context.Context, menuID uint) ([]uint, error) {
|
||||
return s.uc.RoleIDs(ctx, menuID)
|
||||
}
|
||||
func (s *MenuService) SetRoles(ctx context.Context, req *dto.SetMenuRolesRequest) error {
|
||||
return s.uc.SetRoles(ctx, req.MenuID, req.AuthorityIDs)
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type OrganizationService struct{ uc *biz.OrganizationUsecase }
|
||||
|
||||
func NewOrganizationService(uc *biz.OrganizationUsecase) *OrganizationService {
|
||||
return &OrganizationService{uc: uc}
|
||||
}
|
||||
|
||||
func departmentResponse(value *biz.Department) *dto.DepartmentResponse {
|
||||
children := make([]*dto.DepartmentResponse, 0, len(value.Children))
|
||||
for _, child := range value.Children {
|
||||
children = append(children, departmentResponse(child))
|
||||
}
|
||||
return &dto.DepartmentResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Name: value.Name, ParentID: value.ParentID, Ancestors: value.Ancestors, Sort: value.Sort, LeaderID: value.LeaderID, Leader: nil, Status: value.Status, Children: children, NamePath: ""}
|
||||
}
|
||||
|
||||
func departmentDomain(value *dto.DepartmentRequest) *biz.Department {
|
||||
return &biz.Department{ID: value.ID, Name: value.Name, ParentID: value.ParentID, Sort: value.Sort, LeaderID: value.LeaderID, Status: value.Status}
|
||||
}
|
||||
|
||||
func (s *OrganizationService) Departments(ctx context.Context, name string) ([]*dto.DepartmentResponse, error) {
|
||||
items, err := s.uc.Departments(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*dto.DepartmentResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, departmentResponse(item))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *OrganizationService) CreateDepartment(ctx context.Context, req *dto.DepartmentRequest) error {
|
||||
return s.uc.CreateDepartment(ctx, departmentDomain(req))
|
||||
}
|
||||
func (s *OrganizationService) UpdateDepartment(ctx context.Context, req *dto.DepartmentRequest) error {
|
||||
return s.uc.UpdateDepartment(ctx, departmentDomain(req))
|
||||
}
|
||||
func (s *OrganizationService) DeleteDepartment(ctx context.Context, id uint) error {
|
||||
return s.uc.DeleteDepartment(ctx, id)
|
||||
}
|
||||
func (s *OrganizationService) Department(ctx context.Context, id uint) (*dto.DepartmentResponse, error) {
|
||||
value, err := s.uc.Department(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return departmentResponse(value), nil
|
||||
}
|
||||
func (s *OrganizationService) DepartmentUserIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
return s.uc.DepartmentUserIDs(ctx, id)
|
||||
}
|
||||
func (s *OrganizationService) SetDepartmentUsers(ctx context.Context, req *dto.SetDepartmentUsersRequest) error {
|
||||
return s.uc.SetDepartmentUsers(ctx, req.DepartmentID, req.UserIDs)
|
||||
}
|
||||
func (s *OrganizationService) SetUserDepartments(ctx context.Context, req *dto.SetUserDepartmentsRequest) error {
|
||||
return s.uc.SetUserDepartments(ctx, req.ID, req.DepartmentIDs, req.Primary)
|
||||
}
|
||||
|
||||
func positionDomain(value *dto.PositionRequest) *biz.Position {
|
||||
return &biz.Position{ID: value.ID, Name: value.Name, Code: value.Code, Sort: value.Sort, Status: value.Status, Remark: value.Remark}
|
||||
}
|
||||
func positionResponse(value *biz.Position) *dto.PositionResponse {
|
||||
return &dto.PositionResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Name: value.Name, Code: value.Code, Sort: value.Sort, Status: value.Status, Remark: value.Remark}
|
||||
}
|
||||
func (s *OrganizationService) Positions(ctx context.Context, req *dto.PositionListRequest) ([]*dto.PositionResponse, int64, error) {
|
||||
items, total, err := s.uc.Positions(ctx, req.Page, req.PageSize, &biz.Position{Name: req.Name, Code: req.Code})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*dto.PositionResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, positionResponse(item))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *OrganizationService) CreatePosition(ctx context.Context, req *dto.PositionRequest) error {
|
||||
return s.uc.CreatePosition(ctx, positionDomain(req))
|
||||
}
|
||||
func (s *OrganizationService) UpdatePosition(ctx context.Context, req *dto.PositionRequest) error {
|
||||
return s.uc.UpdatePosition(ctx, positionDomain(req))
|
||||
}
|
||||
func (s *OrganizationService) DeletePosition(ctx context.Context, id uint) error {
|
||||
return s.uc.DeletePosition(ctx, id)
|
||||
}
|
||||
func (s *OrganizationService) Position(ctx context.Context, id uint) (*dto.PositionResponse, error) {
|
||||
value, err := s.uc.Position(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return positionResponse(value), nil
|
||||
}
|
||||
func (s *OrganizationService) PositionUserIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
return s.uc.PositionUserIDs(ctx, id)
|
||||
}
|
||||
func (s *OrganizationService) SetPositionUsers(ctx context.Context, req *dto.SetPositionUsersRequest) error {
|
||||
return s.uc.SetPositionUsers(ctx, req.PositionID, req.UserIDs)
|
||||
}
|
||||
func (s *OrganizationService) SetUserPositions(ctx context.Context, req *dto.SetUserPositionsRequest) error {
|
||||
return s.uc.SetUserPositions(ctx, req.ID, req.PositionIDs)
|
||||
}
|
||||
@@ -3,4 +3,4 @@ package service
|
||||
import "github.com/google/wire"
|
||||
|
||||
// ProviderSet is service providers.
|
||||
var ProviderSet = wire.NewSet(NewSystemService, NewAccessService, NewSettingsService, NewVersionService, NewExportService, NewAuditService, NewTaskService, NewMediaService, NewAnnouncementService, NewEmailService)
|
||||
var ProviderSet = wire.NewSet(NewSystemService, NewAccessService, NewMenuService, NewOrganizationService, NewSettingsService, NewVersionService, NewExportService, NewAuditService, NewTaskService, NewMediaService, NewAnnouncementService, NewEmailService)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"io"
|
||||
"kra/internal/biz"
|
||||
"kra/internal/conf"
|
||||
"kra/internal/service/dto"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -26,6 +27,22 @@ type TaskService struct {
|
||||
func NewTaskService(uc *biz.TaskUsecase, media *biz.MediaUsecase, config *conf.AdminBackend) *TaskService {
|
||||
return &TaskService{uc: uc, media: media, config: config}
|
||||
}
|
||||
func taskDomain(v *dto.TaskRequest) *biz.TimedTask {
|
||||
return &biz.TimedTask{ID: v.ID, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: v.Params, HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: v.HTTPHeader, HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled}
|
||||
}
|
||||
func (s *TaskService) CreateRequest(ctx context.Context, req *dto.TaskRequest) (uint, error) {
|
||||
value := taskDomain(req)
|
||||
if err := s.Create(ctx, value); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return value.ID, nil
|
||||
}
|
||||
func (s *TaskService) UpdateRequest(ctx context.Context, req *dto.TaskRequest) error {
|
||||
return s.Update(ctx, taskDomain(req))
|
||||
}
|
||||
func (s *TaskService) ListRequest(ctx context.Context, page, size int, name, executorType string, enabled *bool, next map[uint]time.Time) ([]map[string]any, int64, error) {
|
||||
return s.Tasks(ctx, page, size, &biz.TimedTask{Name: name, ExecutorType: executorType, EnabledFilter: enabled}, next)
|
||||
}
|
||||
func (s *TaskService) Validate(v *biz.TimedTask) error {
|
||||
if v.Name == "" {
|
||||
return errors.New("任务名不能为空")
|
||||
|
||||
Reference in New Issue
Block a user