init: init refactor
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
Auth struct {
|
||||
AccessSecret string
|
||||
AccessExpire int64
|
||||
}
|
||||
SystemRpc zrpc.RpcClientConf
|
||||
DB struct {
|
||||
DataSource string
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/client"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建客户端
|
||||
func CreateClientHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ClientReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := client.NewCreateClientLogic(r.Context(), svcCtx)
|
||||
err := l.CreateClient(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/client"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除客户端
|
||||
func DeleteClientHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := client.NewDeleteClientLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteClient(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/client"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 客户端列表
|
||||
func GetClientListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ClientListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := client.NewGetClientListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetClientList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/client"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新客户端
|
||||
func UpdateClientHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ClientUpdateReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := client.NewUpdateClientLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateClient(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package dict
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/dict"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建字典
|
||||
func CreateDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DictReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := dict.NewCreateDictLogic(r.Context(), svcCtx)
|
||||
err := l.CreateDict(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package dict
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/dict"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除字典
|
||||
func DeleteDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := dict.NewDeleteDictLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteDict(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package dict
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/dict"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 字典列表
|
||||
func GetDictListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DictListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := dict.NewGetDictListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetDictList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package dict
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/dict"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新字典
|
||||
func UpdateDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DictUpdateReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := dict.NewUpdateDictLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateDict(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package menu
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/menu"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建菜单
|
||||
func CreateMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.MenuReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := menu.NewCreateMenuLogic(r.Context(), svcCtx)
|
||||
err := l.CreateMenu(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package menu
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/menu"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除菜单
|
||||
func DeleteMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := menu.NewDeleteMenuLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteMenu(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package menu
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/menu"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 根据角色获取菜单
|
||||
func GetMenuByRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := menu.NewGetMenuByRoleLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetMenuByRole(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package menu
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/logic/menu"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 菜单列表(树形)
|
||||
func GetMenuListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := menu.NewGetMenuListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetMenuList()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package menu
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/menu"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新菜单
|
||||
func UpdateMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.MenuUpdateReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := menu.NewUpdateMenuLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateMenu(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package operationRecord
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/operationRecord"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除操作日志
|
||||
func DeleteOperationRecordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := operationRecord.NewDeleteOperationRecordLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteOperationRecord(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package operationRecord
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
operationrecord "sundynix-micro-go/app/system/api/internal/logic/operationRecord"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 操作日志列表
|
||||
func GetOperationRecordListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.OperationRecordListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := operationrecord.NewGetOperationRecordListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetOperationRecordList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package role
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/role"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建角色
|
||||
func CreateRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.RoleReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := role.NewCreateRoleLogic(r.Context(), svcCtx)
|
||||
err := l.CreateRole(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package role
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/role"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除角色
|
||||
func DeleteRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := role.NewDeleteRoleLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteRole(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package role
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/role"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 角色列表
|
||||
func GetRoleListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.RoleListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := role.NewGetRoleListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetRoleList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package role
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/role"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新角色
|
||||
func UpdateRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.RoleUpdateReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := role.NewUpdateRoleLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateRole(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
client "sundynix-micro-go/app/system/api/internal/handler/client"
|
||||
dict "sundynix-micro-go/app/system/api/internal/handler/dict"
|
||||
menu "sundynix-micro-go/app/system/api/internal/handler/menu"
|
||||
operationRecord "sundynix-micro-go/app/system/api/internal/handler/operationRecord"
|
||||
role "sundynix-micro-go/app/system/api/internal/handler/role"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 创建客户端
|
||||
Method: http.MethodPost,
|
||||
Path: "/client/create",
|
||||
Handler: client.CreateClientHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除客户端
|
||||
Method: http.MethodDelete,
|
||||
Path: "/client/delete",
|
||||
Handler: client.DeleteClientHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 客户端列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/client/list",
|
||||
Handler: client.GetClientListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新客户端
|
||||
Method: http.MethodPut,
|
||||
Path: "/client/update",
|
||||
Handler: client.UpdateClientHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/sys"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 创建字典
|
||||
Method: http.MethodPost,
|
||||
Path: "/dict/create",
|
||||
Handler: dict.CreateDictHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除字典
|
||||
Method: http.MethodDelete,
|
||||
Path: "/dict/delete",
|
||||
Handler: dict.DeleteDictHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 字典列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/dict/list",
|
||||
Handler: dict.GetDictListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新字典
|
||||
Method: http.MethodPut,
|
||||
Path: "/dict/update",
|
||||
Handler: dict.UpdateDictHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/sys"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 根据角色获取菜单
|
||||
Method: http.MethodPost,
|
||||
Path: "/menu/byRole",
|
||||
Handler: menu.GetMenuByRoleHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 创建菜单
|
||||
Method: http.MethodPost,
|
||||
Path: "/menu/create",
|
||||
Handler: menu.CreateMenuHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除菜单
|
||||
Method: http.MethodDelete,
|
||||
Path: "/menu/delete",
|
||||
Handler: menu.DeleteMenuHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 菜单列表(树形)
|
||||
Method: http.MethodGet,
|
||||
Path: "/menu/list",
|
||||
Handler: menu.GetMenuListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新菜单
|
||||
Method: http.MethodPut,
|
||||
Path: "/menu/update",
|
||||
Handler: menu.UpdateMenuHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/sys"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 删除操作日志
|
||||
Method: http.MethodDelete,
|
||||
Path: "/log/delete",
|
||||
Handler: operationRecord.DeleteOperationRecordHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 操作日志列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/log/list",
|
||||
Handler: operationRecord.GetOperationRecordListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/sys"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 创建角色
|
||||
Method: http.MethodPost,
|
||||
Path: "/role/create",
|
||||
Handler: role.CreateRoleHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除角色
|
||||
Method: http.MethodDelete,
|
||||
Path: "/role/delete",
|
||||
Handler: role.DeleteRoleHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 角色列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/role/list",
|
||||
Handler: role.GetRoleListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新角色
|
||||
Method: http.MethodPut,
|
||||
Path: "/role/update",
|
||||
Handler: role.UpdateRoleHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/sys"),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateClientLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateClientLogic {
|
||||
return &CreateClientLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateClientLogic) CreateClient(req *types.ClientReq) error {
|
||||
client := sysModel.SundynixClient{
|
||||
ClientID: req.ClientId,
|
||||
Name: req.Name,
|
||||
GrantType: req.GrantType,
|
||||
AdditionalInfo: req.AdditionalInfo,
|
||||
ActiveTimeout: req.ActiveTimeout,
|
||||
}
|
||||
if err := l.svcCtx.DB.Create(&client).Error; err != nil {
|
||||
l.Errorf("创建客户端失败: %v", err)
|
||||
return fmt.Errorf("创建客户端失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteClientLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteClientLogic {
|
||||
return &DeleteClientLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteClientLogic) DeleteClient(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixClient{}).Error; err != nil {
|
||||
l.Errorf("删除客户端失败: %v", err)
|
||||
return fmt.Errorf("删除客户端失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetClientListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetClientListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClientListLogic {
|
||||
return &GetClientListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetClientListLogic) GetClientList(req *types.ClientListReq) (resp interface{}, err error) {
|
||||
var clients []sysModel.SundynixClient
|
||||
var total int64
|
||||
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixClient{})
|
||||
if req.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+req.Name+"%")
|
||||
}
|
||||
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
l.Errorf("查询客户端总数失败: %v", err)
|
||||
return nil, fmt.Errorf("查询失败")
|
||||
}
|
||||
|
||||
current := req.Current
|
||||
pageSize := req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
offset := (current - 1) * pageSize
|
||||
if err := db.Offset(offset).Limit(pageSize).Find(&clients).Error; err != nil {
|
||||
l.Errorf("查询客户端列表失败: %v", err)
|
||||
return nil, fmt.Errorf("查询失败")
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"list": clients,
|
||||
"total": total,
|
||||
"current": current,
|
||||
"size": pageSize,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateClientLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateClientLogic {
|
||||
return &UpdateClientLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateClientLogic) UpdateClient(req *types.ClientUpdateReq) error {
|
||||
updates := map[string]interface{}{}
|
||||
if req.ClientId != "" {
|
||||
updates["client_id"] = req.ClientId
|
||||
}
|
||||
if req.Name != "" {
|
||||
updates["name"] = req.Name
|
||||
}
|
||||
if req.GrantType != "" {
|
||||
updates["grant_type"] = req.GrantType
|
||||
}
|
||||
if req.AdditionalInfo != "" {
|
||||
updates["additional_info"] = req.AdditionalInfo
|
||||
}
|
||||
if req.ActiveTimeout > 0 {
|
||||
updates["active_timeout"] = req.ActiveTimeout
|
||||
}
|
||||
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixClient{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
|
||||
l.Errorf("更新客户端失败: %v", err)
|
||||
return fmt.Errorf("更新客户端失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package dict
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type CreateDictLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateDictLogic {
|
||||
return &CreateDictLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *CreateDictLogic) CreateDict(req *types.DictReq) error {
|
||||
dict := sysModel.SundynixDict{Type: req.Type, Label: req.Label, Value: req.Value, Sort: req.Sort, Desc: req.Desc}
|
||||
if err := l.svcCtx.DB.Create(&dict).Error; err != nil {
|
||||
return fmt.Errorf("创建字典失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package dict
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type DeleteDictLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictLogic {
|
||||
return &DeleteDictLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *DeleteDictLogic) DeleteDict(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixDict{}).Error; err != nil {
|
||||
return fmt.Errorf("删除字典失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package dict
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type GetDictListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetDictListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDictListLogic {
|
||||
return &GetDictListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetDictListLogic) GetDictList(req *types.DictListReq) (resp interface{}, err error) {
|
||||
var dicts []sysModel.SundynixDict
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixDict{})
|
||||
if req.Type != "" {
|
||||
db = db.Where("type = ?", req.Type)
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := req.Current, req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Offset((current - 1) * pageSize).Limit(pageSize).Order("sort").Find(&dicts).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询字典列表失败")
|
||||
}
|
||||
return map[string]interface{}{"list": dicts, "total": total, "current": current, "size": pageSize}, nil
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package dict
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type UpdateDictLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateDictLogic {
|
||||
return &UpdateDictLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *UpdateDictLogic) UpdateDict(req *types.DictUpdateReq) error {
|
||||
updates := map[string]interface{}{}
|
||||
if req.Type != "" {
|
||||
updates["type"] = req.Type
|
||||
}
|
||||
if req.Label != "" {
|
||||
updates["label"] = req.Label
|
||||
}
|
||||
if req.Value != "" {
|
||||
updates["value"] = req.Value
|
||||
}
|
||||
if req.Sort > 0 {
|
||||
updates["sort"] = req.Sort
|
||||
}
|
||||
if req.Desc != "" {
|
||||
updates["desc"] = req.Desc
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixDict{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
|
||||
return fmt.Errorf("更新字典失败")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type CreateMenuLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateMenuLogic {
|
||||
return &CreateMenuLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *CreateMenuLogic) CreateMenu(req *types.MenuReq) error {
|
||||
menu := sysModel.SundynixMenu{
|
||||
ParentID: req.ParentId, Category: req.Category, Name: req.Name, Title: req.Title,
|
||||
Code: req.Code, Path: req.Path, Permission: req.Permission, Locale: req.Locale,
|
||||
Icon: req.Icon, Sort: req.Sort,
|
||||
}
|
||||
if menu.ParentID == "" {
|
||||
menu.ParentID = "0"
|
||||
}
|
||||
if err := l.svcCtx.DB.Create(&menu).Error; err != nil {
|
||||
return fmt.Errorf("创建菜单失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type DeleteMenuLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMenuLogic {
|
||||
return &DeleteMenuLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *DeleteMenuLogic) DeleteMenu(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixMenu{}).Error; err != nil {
|
||||
return fmt.Errorf("删除菜单失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type GetMenuByRoleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetMenuByRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuByRoleLogic {
|
||||
return &GetMenuByRoleLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetMenuByRoleLogic) GetMenuByRole(req *types.IdReq) (resp interface{}, err error) {
|
||||
var role sysModel.SundynixRole
|
||||
if err := l.svcCtx.DB.Preload("Menus").Where("id = ?", req.Id).First(&role).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询角色菜单失败")
|
||||
}
|
||||
return role.Menus, nil
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type GetMenuListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetMenuListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuListLogic {
|
||||
return &GetMenuListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetMenuListLogic) GetMenuList() (resp interface{}, err error) {
|
||||
var menus []sysModel.SundynixMenu
|
||||
if err := l.svcCtx.DB.Order("sort").Find(&menus).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询菜单列表失败")
|
||||
}
|
||||
// 构建树形结构
|
||||
menuMap := make(map[string]*sysModel.SundynixMenu)
|
||||
for i := range menus {
|
||||
menus[i].Children = []*sysModel.SundynixMenu{}
|
||||
menuMap[menus[i].ID] = &menus[i]
|
||||
}
|
||||
var tree []*sysModel.SundynixMenu
|
||||
for _, m := range menuMap {
|
||||
if m.ParentID == "0" || m.ParentID == "" {
|
||||
tree = append(tree, m)
|
||||
} else if parent, ok := menuMap[m.ParentID]; ok {
|
||||
parent.Children = append(parent.Children, m)
|
||||
} else {
|
||||
tree = append(tree, m)
|
||||
}
|
||||
}
|
||||
return tree, nil
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type UpdateMenuLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateMenuLogic {
|
||||
return &UpdateMenuLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *UpdateMenuLogic) UpdateMenu(req *types.MenuUpdateReq) error {
|
||||
updates := map[string]interface{}{}
|
||||
if req.ParentId != "" {
|
||||
updates["parent_id"] = req.ParentId
|
||||
}
|
||||
if req.Name != "" {
|
||||
updates["name"] = req.Name
|
||||
}
|
||||
if req.Title != "" {
|
||||
updates["title"] = req.Title
|
||||
}
|
||||
if req.Code != "" {
|
||||
updates["code"] = req.Code
|
||||
}
|
||||
if req.Path != "" {
|
||||
updates["path"] = req.Path
|
||||
}
|
||||
if req.Permission != "" {
|
||||
updates["permission"] = req.Permission
|
||||
}
|
||||
if req.Locale != "" {
|
||||
updates["locale"] = req.Locale
|
||||
}
|
||||
if req.Icon != "" {
|
||||
updates["icon"] = req.Icon
|
||||
}
|
||||
if req.Sort > 0 {
|
||||
updates["sort"] = req.Sort
|
||||
}
|
||||
if req.Category > 0 {
|
||||
updates["category"] = req.Category
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixMenu{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
|
||||
return fmt.Errorf("更新菜单失败")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package operationRecord
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type DeleteOperationRecordLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteOperationRecordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteOperationRecordLogic {
|
||||
return &DeleteOperationRecordLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *DeleteOperationRecordLogic) DeleteOperationRecord(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixOperationRecord{}).Error; err != nil {
|
||||
return fmt.Errorf("删除操作日志失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package operationRecord
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type GetOperationRecordListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetOperationRecordListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOperationRecordListLogic {
|
||||
return &GetOperationRecordListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetOperationRecordListLogic) GetOperationRecordList(req *types.OperationRecordListReq) (resp interface{}, err error) {
|
||||
var records []sysModel.SundynixOperationRecord
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixOperationRecord{})
|
||||
if req.Method != "" {
|
||||
db = db.Where("method = ?", req.Method)
|
||||
}
|
||||
if req.Path != "" {
|
||||
db = db.Where("path LIKE ?", "%"+req.Path+"%")
|
||||
}
|
||||
if req.Status > 0 {
|
||||
db = db.Where("status = ?", req.Status)
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := req.Current, req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Offset((current - 1) * pageSize).Limit(pageSize).Order("created_at DESC").Find(&records).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询操作日志失败")
|
||||
}
|
||||
return map[string]interface{}{"list": records, "total": total, "current": current, "size": pageSize}, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateRoleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateRoleLogic {
|
||||
return &CreateRoleLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *CreateRoleLogic) CreateRole(req *types.RoleReq) error {
|
||||
role := sysModel.SundynixRole{Name: req.Name, Code: req.Code, Sort: req.Sort}
|
||||
if err := l.svcCtx.DB.Create(&role).Error; err != nil {
|
||||
return fmt.Errorf("创建角色失败")
|
||||
}
|
||||
// 关联菜单
|
||||
if len(req.MenuIds) > 0 {
|
||||
for _, menuID := range req.MenuIds {
|
||||
l.svcCtx.DB.Create(&sysModel.SundynixRoleMenu{RoleID: role.ID, MenuID: menuID})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type DeleteRoleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteRoleLogic {
|
||||
return &DeleteRoleLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *DeleteRoleLogic) DeleteRole(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixRole{}).Error; err != nil {
|
||||
return fmt.Errorf("删除角色失败")
|
||||
}
|
||||
// 清理角色菜单关联
|
||||
l.svcCtx.DB.Where("role_id IN ?", req.Ids).Delete(&sysModel.SundynixRoleMenu{})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type GetRoleListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetRoleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRoleListLogic {
|
||||
return &GetRoleListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetRoleListLogic) GetRoleList(req *types.RoleListReq) (resp interface{}, err error) {
|
||||
var roles []sysModel.SundynixRole
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixRole{})
|
||||
if req.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+req.Name+"%")
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := req.Current, req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Preload("Menus").Offset((current - 1) * pageSize).Limit(pageSize).Order("sort").Find(&roles).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询角色列表失败")
|
||||
}
|
||||
return map[string]interface{}{"list": roles, "total": total, "current": current, "size": pageSize}, nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
)
|
||||
|
||||
type UpdateRoleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateRoleLogic {
|
||||
return &UpdateRoleLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *UpdateRoleLogic) UpdateRole(req *types.RoleUpdateReq) error {
|
||||
updates := map[string]interface{}{}
|
||||
if req.Name != "" {
|
||||
updates["name"] = req.Name
|
||||
}
|
||||
if req.Code != "" {
|
||||
updates["code"] = req.Code
|
||||
}
|
||||
if req.Sort > 0 {
|
||||
updates["sort"] = req.Sort
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixRole{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
|
||||
return fmt.Errorf("更新角色失败")
|
||||
}
|
||||
}
|
||||
// 更新菜单关联
|
||||
if len(req.MenuIds) > 0 {
|
||||
l.svcCtx.DB.Where("role_id = ?", req.Id).Delete(&sysModel.SundynixRoleMenu{})
|
||||
for _, menuID := range req.MenuIds {
|
||||
l.svcCtx.DB.Create(&sysModel.SundynixRoleMenu{RoleID: req.Id, MenuID: menuID})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package svc
|
||||
|
||||
import (
|
||||
"sundynix-micro-go/app/system/api/internal/config"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
db, err := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{})
|
||||
if err != nil {
|
||||
logx.Errorf("连接数据库失败: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DB: db,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
|
||||
package types
|
||||
|
||||
type ClientListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
}
|
||||
|
||||
type ClientReq struct {
|
||||
ClientId string `json:"clientId"`
|
||||
Name string `json:"name"`
|
||||
GrantType string `json:"grantType,optional"`
|
||||
AdditionalInfo string `json:"additionalInfo,optional"`
|
||||
ActiveTimeout int64 `json:"activeTimeout,optional"`
|
||||
}
|
||||
|
||||
type ClientUpdateReq struct {
|
||||
Id string `json:"id"`
|
||||
ClientId string `json:"clientId,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
GrantType string `json:"grantType,optional"`
|
||||
AdditionalInfo string `json:"additionalInfo,optional"`
|
||||
ActiveTimeout int64 `json:"activeTimeout,optional"`
|
||||
}
|
||||
|
||||
type DictListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Type string `json:"type,optional"`
|
||||
}
|
||||
|
||||
type DictReq struct {
|
||||
Type string `json:"type"`
|
||||
Label string `json:"label"`
|
||||
Value string `json:"value"`
|
||||
Sort int `json:"sort,optional"`
|
||||
Desc string `json:"desc,optional"`
|
||||
}
|
||||
|
||||
type DictUpdateReq struct {
|
||||
Id string `json:"id"`
|
||||
Type string `json:"type,optional"`
|
||||
Label string `json:"label,optional"`
|
||||
Value string `json:"value,optional"`
|
||||
Sort int `json:"sort,optional"`
|
||||
Desc string `json:"desc,optional"`
|
||||
}
|
||||
|
||||
type IdReq struct {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type IdsReq struct {
|
||||
Ids []string `json:"ids"`
|
||||
}
|
||||
|
||||
type MenuReq struct {
|
||||
ParentId string `json:"parentId,optional"`
|
||||
Category int `json:"category,optional"`
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title,optional"`
|
||||
Code string `json:"code,optional"`
|
||||
Path string `json:"path,optional"`
|
||||
Permission string `json:"permission,optional"`
|
||||
Locale string `json:"locale,optional"`
|
||||
Icon string `json:"icon,optional"`
|
||||
Sort int `json:"sort,optional"`
|
||||
}
|
||||
|
||||
type MenuUpdateReq struct {
|
||||
Id string `json:"id"`
|
||||
ParentId string `json:"parentId,optional"`
|
||||
Category int `json:"category,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
Code string `json:"code,optional"`
|
||||
Path string `json:"path,optional"`
|
||||
Permission string `json:"permission,optional"`
|
||||
Locale string `json:"locale,optional"`
|
||||
Icon string `json:"icon,optional"`
|
||||
Sort int `json:"sort,optional"`
|
||||
}
|
||||
|
||||
type OperationRecordListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Method string `json:"method,optional"`
|
||||
Path string `json:"path,optional"`
|
||||
Status int `json:"status,optional"`
|
||||
}
|
||||
|
||||
type PageReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Keyword string `json:"keyword,optional"`
|
||||
}
|
||||
|
||||
type RoleListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
}
|
||||
|
||||
type RoleReq struct {
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Sort int `json:"sort,optional"`
|
||||
MenuIds []string `json:"menuIds,optional"`
|
||||
}
|
||||
|
||||
type RoleUpdateReq struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name,optional"`
|
||||
Code string `json:"code,optional"`
|
||||
Sort int `json:"sort,optional"`
|
||||
MenuIds []string `json:"menuIds,optional"`
|
||||
}
|
||||
Reference in New Issue
Block a user