作者 yangfu

init godevp

正在显示 80 个修改的文件 包含 4753 行增加0 行删除

要显示太多修改。

为保证性能只显示 80 of 80+ 个文件。

# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
*.vscode
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
*.log
*debug
*wasm
*.idea
*.tmp
*.sum
opp
/vendor
/*.exe~
... ...
appname = godevp
runmode = "${RUN_MODE||dev}"
httpport = "${HTTP_PORT||8080}"
#开启监控
EnableAdmin = false
#开启JSON请求
copyrequestbody = true
#防止跨站请求伪造 未启用
enablexsrf = false
xsrfkey = asdfioerjlasdfmFADFOEJF2323SDFF
xsrfexpire = 3600
[lang]
types = en-US|zh-CN
names = English|简体中文
\ No newline at end of file
... ...
module gitlab.fjmaimaimai.com/mmm-go/godevp
go 1.15
require (
github.com/astaxie/beego v1.12.2
github.com/go-pg/pg/v10 v10.0.0-beta.2
github.com/tiptok/gocomm v1.0.2
)
replace github.com/tiptok/gocomm v1.0.2 => F:\go\src\learn_project\gocomm
... ...
package main
import (
"github.com/astaxie/beego"
_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego"
)
func main() {
defer func() {
}()
beego.BConfig.CopyRequestBody = true
beego.Run()
}
... ...
package access
import (
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/access"
)
type AccessService struct {
}
func (svr *AccessService) CreateAccess(header *protocol.RequestHeader, request *protocolx.CreateAccessRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.CreateAccessResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
newAccess := &domain.Access{
AccessName: request.AccessName,
AccessCode: request.AccessCode,
AccessType: request.AccessType,
Sort: request.Sort,
Object: request.Object,
Action: request.Action,
Module: request.Module,
}
var AccessRepository, _ = factory.CreateAccessRepository(transactionContext)
if m, err := AccessRepository.Save(newAccess); err != nil {
return nil, err
} else {
rsp = m
}
err = transactionContext.CommitTransaction()
return
}
func (svr *AccessService) UpdateAccess(header *protocol.RequestHeader, request *protocolx.UpdateAccessRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.UpdateAccessResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var AccessRepository, _ = factory.CreateAccessRepository(transactionContext)
var access *domain.Access
if access, err = AccessRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if err = access.Update(common.ObjectToMap(request)); err != nil {
return
}
if access, err = AccessRepository.Save(access); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
func (svr *AccessService) GetAccess(header *protocol.RequestHeader, request *protocolx.GetAccessRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.GetAccessResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var AccessRepository, _ = factory.CreateAccessRepository(transactionContext)
var access *domain.Access
if access, err = AccessRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
rsp = access
err = transactionContext.CommitTransaction()
return
}
func (svr *AccessService) DeleteAccess(header *protocol.RequestHeader, request *protocolx.DeleteAccessRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.DeleteAccessResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var AccessRepository, _ = factory.CreateAccessRepository(transactionContext)
var access *domain.Access
if access, err = AccessRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if access, err = AccessRepository.Remove(access); err != nil {
return
}
rsp = access
err = transactionContext.CommitTransaction()
return
}
func (svr *AccessService) ListAccess(header *protocol.RequestHeader, request *protocolx.ListAccessRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.ListAccessResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var AccessRepository, _ = factory.CreateAccessRepository(transactionContext)
var access []*domain.Access
var total int64
if total, access, err = AccessRepository.Find(common.ObjectToMap(request)); err != nil {
return
}
rsp = map[string]interface{}{
"total": total,
"list": access,
}
err = transactionContext.CommitTransaction()
return
}
func NewAccessService(options map[string]interface{}) *AccessService {
svr := &AccessService{}
return svr
}
... ...
package auth
import (
"fmt"
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/auth"
)
type AuthService struct {
}
func (svr *AuthService) Login(header *protocol.RequestHeader, request *protocolx.LoginRequest) (rsp *protocolx.LoginResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
UserRepository, _ = factory.CreateUserRepository(transactionContext)
)
rsp = &protocolx.LoginResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var user *domain.User
if user, err = UserRepository.FindOne(map[string]interface{}{"phone": request.UserName}); err != nil || user == nil {
err = protocol.NewCustomMessage(1, "用户不存在!")
return
}
if user.Passwd != request.Password {
err = protocol.NewCustomMessage(1, "密码有误!")
return
}
token, _ := common.GenerateToken(fmt.Sprintf("%v", user.Id), user.Passwd)
rsp.Access = map[string]interface{}{
"accessToken": "Bearer " + token,
"expiresIn": domain.TokenExpire,
}
err = transactionContext.CommitTransaction()
return
}
func (svr *AuthService) Logout(header *protocol.RequestHeader, request *protocolx.LogoutRequest) (rsp *protocolx.LogoutResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.LogoutResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
err = transactionContext.CommitTransaction()
return
}
func (svr *AuthService) Profile(header *protocol.RequestHeader, request *protocolx.ProfileRequest) (rsp *protocolx.ProfileResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.ProfileResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
err = transactionContext.CommitTransaction()
return
}
func (svr *AuthService) CaptchaInit(header *protocol.RequestHeader, request *protocolx.CaptchaInitRequest) (rsp *protocolx.CaptchaInitResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.CaptchaInitResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
err = transactionContext.CommitTransaction()
return
}
func (svr *AuthService) ChangePassword(header *protocol.RequestHeader, request *protocolx.ChangePasswordRequest) (rsp *protocolx.ChangePasswordResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.ChangePasswordResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
err = transactionContext.CommitTransaction()
return
}
func NewAuthService(options map[string]interface{}) *AuthService {
svr := &AuthService{}
return svr
}
... ...
package factory
import (
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/repository"
)
func CreateAccessRepository(transactionContext *transaction.TransactionContext) (domain.AccessRepository, error) {
return repository.NewAccessRepository(transactionContext)
}
func CreateMenuRepository(transactionContext *transaction.TransactionContext) (domain.MenuRepository, error) {
return repository.NewMenuRepository(transactionContext)
}
func CreateProjectModuleRepository(transactionContext *transaction.TransactionContext) (domain.ProjectModuleRepository, error) {
return repository.NewProjectModuleRepository(transactionContext)
}
func CreateProjectModuleVersionRepository(transactionContext *transaction.TransactionContext) (domain.ProjectModuleVersionRepository, error) {
return repository.NewProjectModuleVersionRepository(transactionContext)
}
func CreateProjectModuleFilesRepository(transactionContext *transaction.TransactionContext) (domain.ProjectModuleFilesRepository, error) {
return repository.NewProjectModuleFilesRepository(transactionContext)
}
func CreateRoleRepository(transactionContext *transaction.TransactionContext) (domain.RoleRepository, error) {
return repository.NewRoleRepository(transactionContext)
}
func CreateUserRepository(transactionContext *transaction.TransactionContext) (domain.UserRepository, error) {
return repository.NewUserRepository(transactionContext)
}
... ...
package factory
import (
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
)
func CreateTransactionContext(options map[string]interface{}) (*transaction.TransactionContext, error) {
return &transaction.TransactionContext{
PgDd: pg.DB,
}, nil
}
... ...
package menu
import (
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/menu"
"time"
)
type MenuService struct {
}
func (svr *MenuService) CreateMenu(header *protocol.RequestHeader, request *protocolx.CreateMenuRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.CreateMenuResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
newMenu := &domain.Menu{
MenuName: request.MenuName,
MenuCode: request.MenuCode,
Icon: request.Icon,
Sort: request.Sort,
Hidden: request.Hidden,
CreatedTime: time.Now(),
UpdateTime: time.Now(),
}
var MenuRepository, _ = factory.CreateMenuRepository(transactionContext)
if m, err := MenuRepository.Save(newMenu); err != nil {
return nil, err
} else {
rsp = m
}
err = transactionContext.CommitTransaction()
return
}
func (svr *MenuService) UpdateMenu(header *protocol.RequestHeader, request *protocolx.UpdateMenuRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.UpdateMenuResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var MenuRepository, _ = factory.CreateMenuRepository(transactionContext)
var menu *domain.Menu
if menu, err = MenuRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if err = menu.Update(common.ObjectToMap(request)); err != nil {
return
}
if menu, err = MenuRepository.Save(menu); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
func (svr *MenuService) GetMenu(header *protocol.RequestHeader, request *protocolx.GetMenuRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.GetMenuResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var MenuRepository, _ = factory.CreateMenuRepository(transactionContext)
var menu *domain.Menu
if menu, err = MenuRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
rsp = menu
err = transactionContext.CommitTransaction()
return
}
func (svr *MenuService) DeleteMenu(header *protocol.RequestHeader, request *protocolx.DeleteMenuRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.DeleteMenuResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var MenuRepository, _ = factory.CreateMenuRepository(transactionContext)
var menu *domain.Menu
if menu, err = MenuRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if menu, err = MenuRepository.Remove(menu); err != nil {
return
}
rsp = menu
err = transactionContext.CommitTransaction()
return
}
func (svr *MenuService) ListMenu(header *protocol.RequestHeader, request *protocolx.ListMenuRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.ListMenuResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var MenuRepository, _ = factory.CreateMenuRepository(transactionContext)
var menu []*domain.Menu
var total int64
if total, menu, err = MenuRepository.Find(common.ObjectToMap(request)); err != nil {
return
}
rsp = map[string]interface{}{
"total": total,
"list": menu,
}
err = transactionContext.CommitTransaction()
return
}
func NewMenuService(options map[string]interface{}) *MenuService {
svr := &MenuService{}
return svr
}
... ...
package project_module
import (
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module"
"time"
)
type ProjectModuleService struct {
}
func (svr *ProjectModuleService) CreateProjectModule(header *protocol.RequestHeader, request *protocolx.CreateProjectModuleRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext)
)
rsp = &protocolx.CreateProjectModuleResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
newProjectModule := &domain.ProjectModule{
ProjectName: request.ProjectName,
ProjectKey: request.ProjectKey,
Description: request.Description,
Status: 0,
CreateTime: time.Now(),
UpdateTime: time.Now(),
}
var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext)
if _, err = ProjectModuleRepository.FindOne(map[string]interface{}{"projectKey": request.ProjectKey}); err == nil {
err = protocol.NewCustomMessage(1, "项目键值已存在:"+request.ProjectKey)
return
}
if m, err := ProjectModuleRepository.Save(newProjectModule); err != nil {
return nil, err
} else {
rsp = m
}
if _, err = ProjectModuleVersionRepository.Save(&domain.ProjectModuleVersion{
ProjectModuleId: newProjectModule.Id,
Version: "latest",
Description: "latest version",
Status: 0,
CreateTime: time.Now(),
UpdateTime: time.Now(),
}); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleService) UpdateProjectModule(header *protocol.RequestHeader, request *protocolx.UpdateProjectModuleRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.UpdateProjectModuleResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext)
var projectModule *domain.ProjectModule
if projectModule, err = ProjectModuleRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if err = projectModule.Update(common.ObjectToMap(request)); err != nil {
return
}
if projectModule, err = ProjectModuleRepository.Save(projectModule); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleService) GetProjectModule(header *protocol.RequestHeader, request *protocolx.GetProjectModuleRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.GetProjectModuleResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext)
var projectModule *domain.ProjectModule
if projectModule, err = ProjectModuleRepository.FindOne(common.ObjectToMap(request)); err != nil {
err = protocol.NewCustomMessage(1, "模板项目不存在")
return
}
rsp = projectModule
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleService) DeleteProjectModule(header *protocol.RequestHeader, request *protocolx.DeleteProjectModuleRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.DeleteProjectModuleResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext)
var projectModule *domain.ProjectModule
if projectModule, err = ProjectModuleRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if projectModule, err = ProjectModuleRepository.Remove(projectModule); err != nil {
return
}
rsp = projectModule
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleService) ListProjectModule(header *protocol.RequestHeader, request *protocolx.ListProjectModuleRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.ListProjectModuleResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext)
var projectModule []*domain.ProjectModule
var total int64
if total, projectModule, err = ProjectModuleRepository.Find(common.ObjectToMap(request)); err != nil {
return
}
rsp = map[string]interface{}{
"total": total,
"list": projectModule,
}
err = transactionContext.CommitTransaction()
return
}
func NewProjectModuleService(options map[string]interface{}) *ProjectModuleService {
svr := &ProjectModuleService{}
return svr
}
... ...
package project_module_files
import (
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_files"
"time"
)
type ProjectModuleFilesService struct {
}
func (svr *ProjectModuleFilesService) CreateProjectModuleFiles(header *protocol.RequestHeader, request *protocolx.CreateProjectModuleFilesRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.CreateProjectModuleFilesResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
newProjectModuleFiles := &domain.ProjectModuleFiles{
ProjectModuleId: request.ProjectModuleId,
ProjectModuleVersionId: request.ProjectModuleVersionId,
ParentId: request.ProjectModuleVersionId,
FileType: request.FileType,
FileName: request.FileName,
FileKey: request.FileKey,
CodeBlock: request.CodeBlock,
Remark: request.Remark,
CreateTime: time.Now(),
UpdateTime: time.Now(),
}
var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
if m, e := ProjectModuleFilesRepository.FindOne(map[string]interface{}{"fileKey": request.FileKey, "projectModuleId": request.ProjectModuleId, "projectModuleVersionId": request.ProjectModuleVersionId}); e == nil && m != nil {
err = protocol.NewCustomMessage(1, "已存在 filekey:"+request.FileKey)
return
}
if m, err := ProjectModuleFilesRepository.Save(newProjectModuleFiles); err != nil {
return nil, err
} else {
rsp = m
}
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleFilesService) UpdateProjectModuleFiles(header *protocol.RequestHeader, request *protocolx.UpdateProjectModuleFilesRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.UpdateProjectModuleFilesResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
var projectModuleFiles *domain.ProjectModuleFiles
if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if err = projectModuleFiles.Update(common.ObjectToMap(request)); err != nil {
return
}
if projectModuleFiles, err = ProjectModuleFilesRepository.Save(projectModuleFiles); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleFilesService) GetProjectModuleFiles(header *protocol.RequestHeader, request *protocolx.GetProjectModuleFilesRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.GetProjectModuleFilesResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
var projectModuleFiles *domain.ProjectModuleFiles
if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
rsp = projectModuleFiles
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleFilesService) DeleteProjectModuleFiles(header *protocol.RequestHeader, request *protocolx.DeleteProjectModuleFilesRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.DeleteProjectModuleFilesResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
var projectModuleFiles *domain.ProjectModuleFiles
if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if projectModuleFiles, err = ProjectModuleFilesRepository.Remove(projectModuleFiles); err != nil {
return
}
rsp = projectModuleFiles
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleFilesService) ListProjectModuleFiles(header *protocol.RequestHeader, request *protocolx.ListProjectModuleFilesRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.ListProjectModuleFilesResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
var projectModuleFiles []*domain.ProjectModuleFiles
var total int64
if total, projectModuleFiles, err = ProjectModuleFilesRepository.Find(common.ObjectToMap(request)); err != nil {
return
}
rsp = map[string]interface{}{
"total": total,
"list": projectModuleFiles,
}
err = transactionContext.CommitTransaction()
return
}
func NewProjectModuleFilesService(options map[string]interface{}) *ProjectModuleFilesService {
svr := &ProjectModuleFilesService{}
return svr
}
... ...
package project_module_version
import (
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_version"
"time"
)
type ProjectModuleVersionService struct {
}
func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *protocol.RequestHeader, request *protocolx.CreateProjectModuleVersionRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.CreateProjectModuleVersionResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
newProjectModuleVersion := &domain.ProjectModuleVersion{
Version: request.Version,
Description: request.Description,
Status: request.Status,
CreateTime: time.Now(),
UpdateTime: time.Now(),
}
var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext)
if m, err := ProjectModuleVersionRepository.Save(newProjectModuleVersion); err != nil {
return nil, err
} else {
rsp = m
}
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleVersionService) UpdateProjectModuleVersion(header *protocol.RequestHeader, request *protocolx.UpdateProjectModuleVersionRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.UpdateProjectModuleVersionResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext)
var projectModuleVersion *domain.ProjectModuleVersion
if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if err = projectModuleVersion.Update(common.ObjectToMap(request)); err != nil {
return
}
if projectModuleVersion, err = ProjectModuleVersionRepository.Save(projectModuleVersion); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleVersionService) GetProjectModuleVersion(header *protocol.RequestHeader, request *protocolx.GetProjectModuleVersionRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.GetProjectModuleVersionResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext)
var projectModuleVersion *domain.ProjectModuleVersion
if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
rsp = projectModuleVersion
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleVersionService) DeleteProjectModuleVersion(header *protocol.RequestHeader, request *protocolx.DeleteProjectModuleVersionRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.DeleteProjectModuleVersionResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext)
var projectModuleVersion *domain.ProjectModuleVersion
if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if projectModuleVersion, err = ProjectModuleVersionRepository.Remove(projectModuleVersion); err != nil {
return
}
rsp = projectModuleVersion
err = transactionContext.CommitTransaction()
return
}
func (svr *ProjectModuleVersionService) ListProjectModuleVersion(header *protocol.RequestHeader, request *protocolx.ListProjectModuleVersionRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.ListProjectModuleVersionResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext)
var projectModuleVersion []*domain.ProjectModuleVersion
var total int64
if total, projectModuleVersion, err = ProjectModuleVersionRepository.Find(common.ObjectToMap(request)); err != nil {
return
}
rsp = map[string]interface{}{
"total": total,
"list": projectModuleVersion,
}
err = transactionContext.CommitTransaction()
return
}
func NewProjectModuleVersionService(options map[string]interface{}) *ProjectModuleVersionService {
svr := &ProjectModuleVersionService{}
return svr
}
... ...
package role
import (
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/role"
"time"
)
type RoleService struct {
}
func (svr *RoleService) CreateRole(header *protocol.RequestHeader, request *protocolx.CreateRoleRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.CreateRoleResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
newRole := &domain.Role{
RoleName: request.RoleName,
ParentId: request.ParentId,
CreateTime: time.Now(),
UpdateTime: time.Now(),
}
var RoleRepository, _ = factory.CreateRoleRepository(transactionContext)
if request.ParentId > 0 {
if role, e := RoleRepository.FindOne(map[string]interface{}{"id": request.ParentId}); e != nil || role == nil {
err = protocol.NewCustomMessage(1, "父角色不存在")
return
}
}
if m, err := RoleRepository.Save(newRole); err != nil {
return nil, err
} else {
rsp = m
}
err = transactionContext.CommitTransaction()
return
}
func (svr *RoleService) UpdateRole(header *protocol.RequestHeader, request *protocolx.UpdateRoleRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.UpdateRoleResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var RoleRepository, _ = factory.CreateRoleRepository(transactionContext)
var role *domain.Role
if role, err = RoleRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if request.ParentId > 0 {
if role, e := RoleRepository.FindOne(map[string]interface{}{"id": request.ParentId}); e != nil || role == nil {
err = protocol.NewCustomMessage(1, "父角色不存在")
return
}
}
if err = role.Update(common.ObjectToMap(request)); err != nil {
return
}
if role, err = RoleRepository.Save(role); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
func (svr *RoleService) GetRole(header *protocol.RequestHeader, request *protocolx.GetRoleRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.GetRoleResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var RoleRepository, _ = factory.CreateRoleRepository(transactionContext)
var role *domain.Role
if role, err = RoleRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
rsp = map[string]interface{}{"role": role, "permission": ""}
err = transactionContext.CommitTransaction()
return
}
func (svr *RoleService) DeleteRole(header *protocol.RequestHeader, request *protocolx.DeleteRoleRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.DeleteRoleResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var RoleRepository, _ = factory.CreateRoleRepository(transactionContext)
var role *domain.Role
if role, err = RoleRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if count, _, e := RoleRepository.Find(map[string]interface{}{"parentId": role.Id}); e == nil && count > 0 {
err = protocol.NewCustomMessage(2, "存在子角色,不可删除")
return
}
if role, err = RoleRepository.Remove(role); err != nil {
return
}
rsp = role
err = transactionContext.CommitTransaction()
return
}
func (svr *RoleService) ListRole(header *protocol.RequestHeader, request *protocolx.ListRoleRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.ListRoleResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var RoleRepository, _ = factory.CreateRoleRepository(transactionContext)
var role []*domain.Role
var total int64
if total, role, err = RoleRepository.Find(common.ObjectToMap(request)); err != nil {
return
}
rsp = map[string]interface{}{
"total": total,
"list": role,
}
err = transactionContext.CommitTransaction()
return
}
func NewRoleService(options map[string]interface{}) *RoleService {
svr := &RoleService{}
return svr
}
... ...
package user
import (
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/user"
)
type UserService struct {
}
func (svr *UserService) CreateUser(header *protocol.RequestHeader, request *protocolx.CreateUserRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.CreateUserResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
newUser := &domain.User{
Name: request.Name,
Address: request.Address,
Phone: request.Phone,
Passwd: request.Passwd,
Roles: request.Roles,
IsAdmin: request.IsAdmin,
}
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
if m, err := UserRepository.Save(newUser); err != nil {
return nil, err
} else {
rsp = m
}
err = transactionContext.CommitTransaction()
return
}
func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *protocolx.UpdateUserRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.UpdateUserResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
var user *domain.User
if user, err = UserRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if err = user.Update(common.ObjectToMap(request)); err != nil {
return
}
if user, err = UserRepository.Save(user); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
func (svr *UserService) GetUser(header *protocol.RequestHeader, request *protocolx.GetUserRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.GetUserResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
var user *domain.User
if user, err = UserRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
rsp = user
err = transactionContext.CommitTransaction()
return
}
func (svr *UserService) DeleteUser(header *protocol.RequestHeader, request *protocolx.DeleteUserRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.DeleteUserResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
var user *domain.User
if user, err = UserRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if user, err = UserRepository.Remove(user); err != nil {
return
}
rsp = user
err = transactionContext.CommitTransaction()
return
}
func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protocolx.ListUserRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.ListUserResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
var user []*domain.User
var total int64
if total, user, err = UserRepository.Find(common.ObjectToMap(request)); err != nil {
return
}
rsp = map[string]interface{}{
"total": total,
"list": user,
}
err = transactionContext.CommitTransaction()
return
}
func NewUserService(options map[string]interface{}) *UserService {
svr := &UserService{}
return svr
}
... ...
package constant
import "os"
var POSTGRESQL_DB_NAME = "godevp"
var POSTGRESQL_USER = "postgres"
var POSTGRESQL_PASSWORD = "123456"
var POSTGRESQL_HOST = "127.0.0.1"
var POSTGRESQL_PORT = "5432"
var DISABLE_CREATE_TABLE = false
var DISABLE_SQL_GENERATE_PRINT = false
func init() {
if os.Getenv("POSTGRESQL_DB_NAME") != "" {
POSTGRESQL_DB_NAME = os.Getenv("POSTGRESQL_DB_NAME")
}
if os.Getenv("POSTGRESQL_USER") != "" {
POSTGRESQL_USER = os.Getenv("POSTGRESQL_USER")
}
if os.Getenv("POSTGRESQL_PASSWORD") != "" {
POSTGRESQL_PASSWORD = os.Getenv("POSTGRESQL_PASSWORD")
}
if os.Getenv("POSTGRESQL_HOST") != "" {
POSTGRESQL_HOST = os.Getenv("POSTGRESQL_HOST")
}
if os.Getenv("POSTGRESQL_PORT") != "" {
POSTGRESQL_PORT = os.Getenv("POSTGRESQL_PORT")
}
if os.Getenv("DISABLE_CREATE_TABLE") != "" {
DISABLE_CREATE_TABLE = true
}
if os.Getenv("DISABLE_SQL_GENERATE_PRINT") != "" {
DISABLE_SQL_GENERATE_PRINT = true
}
}
... ...
package domain
// Access
type Access struct {
// 唯一标识
Id int64 `json:"id"`
// 父级id
ParentId int64 `json:"parentId"`
// 权限名称
AccessName string `json:"accessName"`
// 权限编码
AccessCode string `json:"accessCode"`
// 权限类型 menu button data
AccessType string `json:"accessType"`
// 排序
Sort int `json:"sort"`
// 请求对象 接口地址/对象
Object string `json:"object"`
// 操作方法 httpMethod/read/write
Action string `json:"action"`
// 所属功能模块
Module string `json:"module"`
}
type AccessRepository interface {
Save(dm *Access) (*Access, error)
Remove(dm *Access) (*Access, error)
FindOne(queryOptions map[string]interface{}) (*Access, error)
Find(queryOptions map[string]interface{}) (int64, []*Access, error)
}
func (m *Access) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *Access) Update(data map[string]interface{}) error {
return nil
}
... ...
package domain
const TokenExpire = 3 * 3600
... ...
package domain
// CasbinRule
type CasbinRule struct {
// 唯一标识
Id int64 `json:"id"`
// 规则类型:p g
PType string `json:"pType"`
// 值0 sub:role_id
V0 string `json:"v0"`
// 值1 object:请求对象 接口地址/对象
V1 string `json:"v1"`
// 值2 action:操作方法 httpMethod/read/write
V2 string `json:"v2"`
// 值3 扩展字段 access_id
V3 string `json:"v3"`
// 值4 扩展字段
V4 string `json:"v4"`
// 值5 扩展字段
V5 string `json:"v5"`
}
type CasbinRuleRepository interface {
Save(dm *CasbinRule) (*CasbinRule, error)
Remove(dm *CasbinRule) (*CasbinRule, error)
FindOne(queryOptions map[string]interface{}) (*CasbinRule, error)
Find(queryOptions map[string]interface{}) (int64, []*CasbinRule, error)
}
func (m *CasbinRule) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *CasbinRule) Update(data map[string]interface{}) error {
return nil
}
... ...
package domain
import "time"
// Menu
type Menu struct {
// 唯一标识
Id int64 `json:"id"`
// 父级id
ParentId int64 `json:"parentId"`
// 菜单名称
MenuName string `json:"menuName"`
// 菜单编码
MenuCode string `json:"menuCode"`
// 图标
Icon string `json:"icon"`
// 排序
Sort int `json:"sort"`
// 是否隐藏: 1:隐藏 0:显示
Hidden bool `json:"hidden"`
// 创建时间
CreatedTime time.Time `json:"createdTime"`
// 更新时间
UpdateTime time.Time `json:"updateTime"`
}
type MenuRepository interface {
Save(dm *Menu) (*Menu, error)
Remove(dm *Menu) (*Menu, error)
FindOne(queryOptions map[string]interface{}) (*Menu, error)
Find(queryOptions map[string]interface{}) (int64, []*Menu, error)
}
func (m *Menu) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *Menu) Update(data map[string]interface{}) error {
return nil
}
... ...
package domain
import "time"
// ProjectModule
type ProjectModule struct {
// 唯一标识
Id int64 `json:"id"`
// 项目名称
ProjectName string `json:"projectName"`
// 项目唯一键值
ProjectKey string `json:"projectKey"`
// 项目描述信息
Description string `json:"description"`
// 状态 0:正常 1:删除
Status int `json:"status"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 更新时间
UpdateTime time.Time `json:"updateTime"`
ProjectModuleVersion []*ProjectModuleVersion `json:"versions"`
}
type ProjectModuleRepository interface {
Save(dm *ProjectModule) (*ProjectModule, error)
Remove(dm *ProjectModule) (*ProjectModule, error)
FindOne(queryOptions map[string]interface{}) (*ProjectModule, error)
Find(queryOptions map[string]interface{}) (int64, []*ProjectModule, error)
}
func (m *ProjectModule) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *ProjectModule) Update(data map[string]interface{}) error {
return nil
}
... ...
package domain
import "time"
// ProjectModuleFiles
type ProjectModuleFiles struct {
// 唯一标识
Id int64 `json:"id"`
// 项目编号
ProjectModuleId int64 `json:"projectModuleId"`
// 项目版本编号
ProjectModuleVersionId int64 `json:"projectModuleVersionId"`
// 文件类型 1:文件夹 2:文件
FileType int `json:"fileType"`
// 文件名称
FileName string `json:"fileName"`
// 文件键值
FileKey string `json:"fileKey"`
// 代码块
CodeBlock string `json:"codeBlock"`
// 父级编号
ParentId int64 `json:"parentId"`
// 排序
Sort int `json:"sort"`
// 备注信息
Remark string `json:"remark"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 更新时间
UpdateTime time.Time `json:"updateTime"`
}
type ProjectModuleFilesRepository interface {
Save(dm *ProjectModuleFiles) (*ProjectModuleFiles, error)
Remove(dm *ProjectModuleFiles) (*ProjectModuleFiles, error)
FindOne(queryOptions map[string]interface{}) (*ProjectModuleFiles, error)
Find(queryOptions map[string]interface{}) (int64, []*ProjectModuleFiles, error)
}
func (m *ProjectModuleFiles) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *ProjectModuleFiles) Update(data map[string]interface{}) error {
return nil
}
... ...
package domain
import "time"
// ProjectModuleVersion
type ProjectModuleVersion struct {
// 唯一标识
Id int64 `json:"id"`
// 项目编号
ProjectModuleId int64 `json:"projectModuleId"`
// 版本号
Version string `json:"version"`
// 项目描述信息
Description string `json:"description"`
// 状态 0:正常 1:删除
Status int `json:"status"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 更新时间
UpdateTime time.Time `json:"updateTime"`
}
type ProjectModuleVersionRepository interface {
Save(dm *ProjectModuleVersion) (*ProjectModuleVersion, error)
Remove(dm *ProjectModuleVersion) (*ProjectModuleVersion, error)
FindOne(queryOptions map[string]interface{}) (*ProjectModuleVersion, error)
Find(queryOptions map[string]interface{}) (int64, []*ProjectModuleVersion, error)
}
func (m *ProjectModuleVersion) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *ProjectModuleVersion) Update(data map[string]interface{}) error {
return nil
}
... ...
package domain
import "time"
// Role
type Role struct {
// 唯一标识
Id int64 `json:"id"`
// 角色名称
RoleName string `json:"roleName"`
// 父级Id
ParentId int64 `json:"parentId"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 更新时间
UpdateTime time.Time `json:"updateTime"`
}
type RoleRepository interface {
Save(dm *Role) (*Role, error)
Remove(dm *Role) (*Role, error)
FindOne(queryOptions map[string]interface{}) (*Role, error)
Find(queryOptions map[string]interface{}) (int64, []*Role, error)
}
func (m *Role) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *Role) Update(data map[string]interface{}) error {
if roleName, ok := data["roleName"]; ok {
m.RoleName = roleName.(string)
}
if parentId, ok := data["parentId"]; ok {
m.ParentId = parentId.(int64)
}
return nil
}
... ...
package domain
// RoleAccess
type RoleAccess struct {
// 唯一标识
Id int64 `json:"id"`
// 角色id
RoleId int64 `json:"roleId"`
// 权限编号
AccessId int64 `json:"accessId"`
// 请求对象 接口地址/对象
Object string `json:"object"`
// 操作方法 httpMethod/read/write
Action string `json:"action"`
// 可选对象
Option string `json:"option"`
}
type RoleAccessRepository interface {
Save(dm *RoleAccess) (*RoleAccess, error)
Remove(dm *RoleAccess) (*RoleAccess, error)
FindOne(queryOptions map[string]interface{}) (*RoleAccess, error)
Find(queryOptions map[string]interface{}) (int64, []*RoleAccess, error)
}
func (m *RoleAccess) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *RoleAccess) Update(data map[string]interface{}) error {
return nil
}
... ...
package domain
// User
type User struct {
// 唯一标识
Id int64 `json:"id"`
// 名称
Name string `json:"name"`
// 地址
Address string `json:"address"`
// 手机号
Phone string `json:"phone"`
// 密码
Passwd string `json:"passwd"`
// 用户角色
Roles []int64 `json:"roles"`
// 是否是超级管理员 true:是 false:否
IsAdmin bool `json:"isAdmin"`
}
type UserRepository interface {
Save(dm *User) (*User, error)
Remove(dm *User) (*User, error)
FindOne(queryOptions map[string]interface{}) (*User, error)
Find(queryOptions map[string]interface{}) (int64, []*User, error)
}
func (m *User) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *User) Update(data map[string]interface{}) error {
return nil
}
... ...
package pg
import (
"context"
"fmt"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"log"
)
var DB *pg.DB
func init() {
DB = pg.Connect(&pg.Options{
User: constant.POSTGRESQL_USER,
Password: constant.POSTGRESQL_PASSWORD,
Database: constant.POSTGRESQL_DB_NAME,
Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT),
})
if !constant.DISABLE_SQL_GENERATE_PRINT {
DB.AddQueryHook(SqlGeneratePrintHook{})
}
//orm.RegisterTable((*models.OrderGood)(nil))
if !constant.DISABLE_CREATE_TABLE {
for _, model := range []interface{}{
(*models.Access)(nil),
(*models.CasbinRule)(nil),
(*models.Menu)(nil),
(*models.ProjectModule)(nil),
(*models.ProjectModuleFiles)(nil),
(*models.ProjectModuleVersion)(nil),
(*models.Role)(nil),
(*models.RoleAccess)(nil),
(*models.User)(nil),
} {
err := DB.CreateTable(model, &orm.CreateTableOptions{
Temp: false,
IfNotExists: true,
FKConstraints: true,
})
if err != nil {
panic(err)
}
}
}
}
type SqlGeneratePrintHook struct{}
func (hook SqlGeneratePrintHook) BeforeQuery(c context.Context, q *pg.QueryEvent) (context.Context, error) {
return c, nil
}
func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) error {
data, err := q.FormattedQuery()
//if len(string(data)) > 8 { //BEGIN COMMIT
log.Println(string(data))
//}
return err
}
... ...
package models
// Access
type Access struct {
tableName struct{} `pg:"access"`
// 唯一标识
Id int64
// 父级id
ParentId int64
// 权限名称
AccessName string
// 权限编码
AccessCode string
// 权限类型 menu button data
AccessType string
// 排序
Sort int
// 请求对象 接口地址/对象
Object string
// 操作方法 httpMethod/read/write
Action string
// 所属功能模块
Module string
}
... ...
package models
// CasbinRule
type CasbinRule struct {
tableName struct{} `pg:"casbin_rule"`
// 唯一标识
Id int64
// 规则类型:p g
PType string
// 值0 sub:role_id
V0 string
// 值1 object:请求对象 接口地址/对象
V1 string
// 值2 action:操作方法 httpMethod/read/write
V2 string
// 值3 扩展字段 access_id
V3 string
// 值4 扩展字段
V4 string
// 值5 扩展字段
V5 string
}
... ...
package models
import "time"
// Menu
type Menu struct {
tableName struct{} `pg:"menu"`
// 唯一标识
Id int64
// 父级id
ParentId int64
// 菜单名称
MenuName string
// 菜单编码
MenuCode string
// 图标
Icon string
// 排序
Sort int
// 是否隐藏: 1:隐藏 0:显示
Hidden bool
// 创建时间
CreatedTime time.Time
// 更新时间
UpdateTime time.Time
}
... ...
package models
import "time"
// ProjectModule
type ProjectModule struct {
tableName struct{} `pg:"project_module"`
// 唯一标识
Id int64
// 项目名称
ProjectName string
// 项目唯一键值
ProjectKey string
// 项目描述信息
Description string
// 状态 0:正常 1:删除
Status int
// 创建时间
CreateTime time.Time
// 更新时间
UpdateTime time.Time
// 外键
ProjectModuleVersion []*ProjectModuleVersion `pg:"fk:project_module_id"`
}
... ...
package models
import "time"
// ProjectModuleFiles
type ProjectModuleFiles struct {
tableName struct{} `pg:"project_module_files"`
// 唯一标识
Id int64
// 项目编号
ProjectModuleId int64
// 项目版本编号
ProjectModuleVersionId int64
// 文件类型 1:文件夹 2:文件
FileType int
// 文件名称
FileName string
// 文件键值
FileKey string
// 代码块
CodeBlock string
// 父级编号
ParentId int64
// 排序
Sort int
// 备注信息
Remark string
// 创建时间
CreateTime time.Time
// 更新时间
UpdateTime time.Time
}
... ...
package models
import "time"
// ProjectModuleVersion
type ProjectModuleVersion struct {
tableName struct{} `pg:"project_module_version"`
// 唯一标识
Id int64
// 项目编号
ProjectModuleId int64
// 版本号
Version string
// 项目描述信息
Description string
// 状态 0:正常 1:删除
Status int
// 创建时间
CreateTime time.Time
// 更新时间
UpdateTime time.Time
}
... ...
package models
import "time"
// Role
type Role struct {
tableName struct{} `pg:"role"`
// 唯一标识
Id int64
// 角色名称
RoleName string
// 父级Id
ParentId int64
// 创建时间
CreateTime time.Time
// 更新时间
UpdateTime time.Time
}
... ...
package models
// RoleAccess
type RoleAccess struct {
tableName struct{} `pg:"role_access"`
// 唯一标识
Id int64
// 角色id
RoleId int64
// 权限编号
AccessId int64
// 请求对象 接口地址/对象
Object string
// 操作方法 httpMethod/read/write
Action string
// 可选对象
Option string
}
... ...
package models
// User
type User struct {
tableName struct{} `pg:"user"`
// 唯一标识
Id int64
// 名称
Name string
// 地址
Address string
// 手机号
Phone string
// 密码
Passwd string
// 用户角色
Roles []int64
// 是否是超级管理员 true:是 false:否
IsAdmin bool
}
... ...
package transaction
import "github.com/go-pg/pg/v10"
type TransactionContext struct {
PgDd *pg.DB
PgTx *pg.Tx
}
func (transactionContext *TransactionContext) StartTransaction() error {
tx, err := transactionContext.PgDd.Begin()
if err != nil {
return err
}
transactionContext.PgTx = tx
return nil
}
func (transactionContext *TransactionContext) CommitTransaction() error {
err := transactionContext.PgTx.Commit()
return err
}
func (transactionContext *TransactionContext) RollbackTransaction() error {
err := transactionContext.PgTx.Rollback()
return err
}
func NewPGTransactionContext(pgDd *pg.DB) *TransactionContext {
return &TransactionContext{
PgDd: pgDd,
}
}
... ...
package repository
import (
"fmt"
"github.com/tiptok/gocomm/common"
. "github.com/tiptok/gocomm/pkg/orm/pgx"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
)
type AccessRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *AccessRepository) Save(dm *domain.Access) (*domain.Access, error) {
var (
err error
m = &models.Access{}
tx = repository.transactionContext.PgTx
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if err = tx.Insert(m); err != nil {
return nil, err
}
return dm, nil
}
if err = tx.Update(m); err != nil {
return nil, err
}
return dm, nil
}
func (repository *AccessRepository) Remove(Access *domain.Access) (*domain.Access, error) {
var (
tx = repository.transactionContext.PgTx
AccessModel = &models.Access{Id: Access.Identify().(int64)}
)
if _, err := tx.Model(AccessModel).Where("id = ?", Access.Id).Delete(); err != nil {
return Access, err
}
return Access, nil
}
func (repository *AccessRepository) FindOne(queryOptions map[string]interface{}) (*domain.Access, error) {
tx := repository.transactionContext.PgTx
AccessModel := new(models.Access)
query := NewQuery(tx.Model(AccessModel), queryOptions)
query.SetWhere("id = ?", "id")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
if AccessModel.Id == 0 {
return nil, fmt.Errorf("query row not found")
}
return repository.transformPgModelToDomainModel(AccessModel)
}
func (repository *AccessRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Access, error) {
tx := repository.transactionContext.PgTx
var AccessModels []*models.Access
Accesss := make([]*domain.Access, 0)
query := NewQuery(tx.Model(&AccessModels), queryOptions).
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, Accesss, err
}
for _, AccessModel := range AccessModels {
if Access, err := repository.transformPgModelToDomainModel(AccessModel); err != nil {
return 0, Accesss, err
} else {
Accesss = append(Accesss, Access)
}
}
return int64(query.AffectRow), Accesss, nil
}
func (repository *AccessRepository) transformPgModelToDomainModel(AccessModel *models.Access) (*domain.Access, error) {
m := &domain.Access{}
err := common.GobModelTransform(m, AccessModel)
return m, err
}
func NewAccessRepository(transactionContext *transaction.TransactionContext) (*AccessRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &AccessRepository{transactionContext: transactionContext}, nil
}
... ...
package repository
import (
"fmt"
"github.com/tiptok/gocomm/common"
. "github.com/tiptok/gocomm/pkg/orm/pgx"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
)
type CasbinRuleRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *CasbinRuleRepository) Save(dm *domain.CasbinRule) (*domain.CasbinRule, error) {
var (
err error
m = &models.CasbinRule{}
tx = repository.transactionContext.PgTx
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if err = tx.Insert(m); err != nil {
return nil, err
}
return dm, nil
}
if err = tx.Update(m); err != nil {
return nil, err
}
return dm, nil
}
func (repository *CasbinRuleRepository) Remove(CasbinRule *domain.CasbinRule) (*domain.CasbinRule, error) {
var (
tx = repository.transactionContext.PgTx
CasbinRuleModel = &models.CasbinRule{Id: CasbinRule.Identify().(int64)}
)
if _, err := tx.Model(CasbinRuleModel).Where("id = ?", CasbinRule.Id).Delete(); err != nil {
return CasbinRule, err
}
return CasbinRule, nil
}
func (repository *CasbinRuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.CasbinRule, error) {
tx := repository.transactionContext.PgTx
CasbinRuleModel := new(models.CasbinRule)
query := NewQuery(tx.Model(CasbinRuleModel), queryOptions)
query.SetWhere("id = ?", "id")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
if CasbinRuleModel.Id == 0 {
return nil, fmt.Errorf("query row not found")
}
return repository.transformPgModelToDomainModel(CasbinRuleModel)
}
func (repository *CasbinRuleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CasbinRule, error) {
tx := repository.transactionContext.PgTx
var CasbinRuleModels []*models.CasbinRule
CasbinRules := make([]*domain.CasbinRule, 0)
query := NewQuery(tx.Model(&CasbinRuleModels), queryOptions).
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, CasbinRules, err
}
for _, CasbinRuleModel := range CasbinRuleModels {
if CasbinRule, err := repository.transformPgModelToDomainModel(CasbinRuleModel); err != nil {
return 0, CasbinRules, err
} else {
CasbinRules = append(CasbinRules, CasbinRule)
}
}
return int64(query.AffectRow), CasbinRules, nil
}
func (repository *CasbinRuleRepository) transformPgModelToDomainModel(CasbinRuleModel *models.CasbinRule) (*domain.CasbinRule, error) {
m := &domain.CasbinRule{}
err := common.GobModelTransform(m, CasbinRuleModel)
return m, err
}
func NewCasbinRuleRepository(transactionContext *transaction.TransactionContext) (*CasbinRuleRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &CasbinRuleRepository{transactionContext: transactionContext}, nil
}
... ...
package repository
import (
"fmt"
"github.com/tiptok/gocomm/common"
. "github.com/tiptok/gocomm/pkg/orm/pgx"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
)
type MenuRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *MenuRepository) Save(dm *domain.Menu) (*domain.Menu, error) {
var (
err error
m = &models.Menu{}
tx = repository.transactionContext.PgTx
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if err = tx.Insert(m); err != nil {
return nil, err
}
return dm, nil
}
if err = tx.Update(m); err != nil {
return nil, err
}
return dm, nil
}
func (repository *MenuRepository) Remove(Menu *domain.Menu) (*domain.Menu, error) {
var (
tx = repository.transactionContext.PgTx
MenuModel = &models.Menu{Id: Menu.Identify().(int64)}
)
if _, err := tx.Model(MenuModel).Where("id = ?", Menu.Id).Delete(); err != nil {
return Menu, err
}
return Menu, nil
}
func (repository *MenuRepository) FindOne(queryOptions map[string]interface{}) (*domain.Menu, error) {
tx := repository.transactionContext.PgTx
MenuModel := new(models.Menu)
query := NewQuery(tx.Model(MenuModel), queryOptions)
query.SetWhere("id = ?", "id")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
if MenuModel.Id == 0 {
return nil, fmt.Errorf("query row not found")
}
return repository.transformPgModelToDomainModel(MenuModel)
}
func (repository *MenuRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Menu, error) {
tx := repository.transactionContext.PgTx
var MenuModels []*models.Menu
Menus := make([]*domain.Menu, 0)
query := NewQuery(tx.Model(&MenuModels), queryOptions).
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, Menus, err
}
for _, MenuModel := range MenuModels {
if Menu, err := repository.transformPgModelToDomainModel(MenuModel); err != nil {
return 0, Menus, err
} else {
Menus = append(Menus, Menu)
}
}
return int64(query.AffectRow), Menus, nil
}
func (repository *MenuRepository) transformPgModelToDomainModel(MenuModel *models.Menu) (*domain.Menu, error) {
m := &domain.Menu{}
err := common.GobModelTransform(m, MenuModel)
return m, err
}
func NewMenuRepository(transactionContext *transaction.TransactionContext) (*MenuRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &MenuRepository{transactionContext: transactionContext}, nil
}
... ...
package repository
import (
"fmt"
"github.com/tiptok/gocomm/common"
. "github.com/tiptok/gocomm/pkg/orm/pgx"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
)
type ProjectModuleFilesRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *ProjectModuleFilesRepository) Save(dm *domain.ProjectModuleFiles) (*domain.ProjectModuleFiles, error) {
var (
err error
m = &models.ProjectModuleFiles{}
tx = repository.transactionContext.PgTx
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if err = tx.Insert(m); err != nil {
return nil, err
}
dm.Id = m.Id
return dm, nil
}
if err = tx.Update(m); err != nil {
return nil, err
}
return dm, nil
}
func (repository *ProjectModuleFilesRepository) Remove(ProjectModuleFiles *domain.ProjectModuleFiles) (*domain.ProjectModuleFiles, error) {
var (
tx = repository.transactionContext.PgTx
ProjectModuleFilesModel = &models.ProjectModuleFiles{Id: ProjectModuleFiles.Identify().(int64)}
)
if _, err := tx.Model(ProjectModuleFilesModel).Where("id = ?", ProjectModuleFiles.Id).Delete(); err != nil {
return ProjectModuleFiles, err
}
return ProjectModuleFiles, nil
}
func (repository *ProjectModuleFilesRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModuleFiles, error) {
tx := repository.transactionContext.PgTx
ProjectModuleFilesModel := new(models.ProjectModuleFiles)
query := NewQuery(tx.Model(ProjectModuleFilesModel), queryOptions)
query.SetWhere("id = ?", "id")
query.SetWhere("project_module_id = ?", "projectModuleId")
query.SetWhere("project_module_version_id = ?", "projectModuleVersionId")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
if ProjectModuleFilesModel.Id == 0 {
return nil, fmt.Errorf("query row not found")
}
return repository.transformPgModelToDomainModel(ProjectModuleFilesModel)
}
func (repository *ProjectModuleFilesRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModuleFiles, error) {
tx := repository.transactionContext.PgTx
var ProjectModuleFilesModels []*models.ProjectModuleFiles
ProjectModuleFiless := make([]*domain.ProjectModuleFiles, 0)
query := NewQuery(tx.Model(&ProjectModuleFilesModels), queryOptions).
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, ProjectModuleFiless, err
}
for _, ProjectModuleFilesModel := range ProjectModuleFilesModels {
if ProjectModuleFiles, err := repository.transformPgModelToDomainModel(ProjectModuleFilesModel); err != nil {
return 0, ProjectModuleFiless, err
} else {
ProjectModuleFiless = append(ProjectModuleFiless, ProjectModuleFiles)
}
}
return int64(query.AffectRow), ProjectModuleFiless, nil
}
func (repository *ProjectModuleFilesRepository) transformPgModelToDomainModel(ProjectModuleFilesModel *models.ProjectModuleFiles) (*domain.ProjectModuleFiles, error) {
m := &domain.ProjectModuleFiles{}
err := common.GobModelTransform(m, ProjectModuleFilesModel)
return m, err
}
func NewProjectModuleFilesRepository(transactionContext *transaction.TransactionContext) (*ProjectModuleFilesRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &ProjectModuleFilesRepository{transactionContext: transactionContext}, nil
}
... ...
package repository
import (
"fmt"
"github.com/tiptok/gocomm/common"
. "github.com/tiptok/gocomm/pkg/orm/pgx"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
)
type ProjectModuleRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *ProjectModuleRepository) Save(dm *domain.ProjectModule) (*domain.ProjectModule, error) {
var (
err error
m = &models.ProjectModule{}
tx = repository.transactionContext.PgTx
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if err = tx.Insert(m); err != nil {
return nil, err
}
dm.Id = m.Id
return dm, nil
}
if err = tx.Update(m); err != nil {
return nil, err
}
return dm, nil
}
func (repository *ProjectModuleRepository) Remove(ProjectModule *domain.ProjectModule) (*domain.ProjectModule, error) {
var (
tx = repository.transactionContext.PgTx
ProjectModuleModel = &models.ProjectModule{Id: ProjectModule.Identify().(int64)}
)
if _, err := tx.Model(ProjectModuleModel).Where("id = ?", ProjectModule.Id).Delete(); err != nil {
return ProjectModule, err
}
return ProjectModule, nil
}
func (repository *ProjectModuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModule, error) {
tx := repository.transactionContext.PgTx
ProjectModuleModel := new(models.ProjectModule)
query := NewQuery(tx.Model(ProjectModuleModel), queryOptions)
query.SetWhere("id = ?", "id")
query.SetWhere("project_key = ?", "projectKey")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
if ProjectModuleModel.Id == 0 {
return nil, fmt.Errorf("query row not found")
}
return repository.transformPgModelToDomainModel(ProjectModuleModel)
}
func (repository *ProjectModuleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModule, error) {
tx := repository.transactionContext.PgTx
var ProjectModuleModels []*models.ProjectModule
ProjectModules := make([]*domain.ProjectModule, 0)
query := NewQuery(tx.Model(&ProjectModuleModels), queryOptions).
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, ProjectModules, err
}
for _, ProjectModuleModel := range ProjectModuleModels {
if ProjectModule, err := repository.transformPgModelToDomainModel(ProjectModuleModel); err != nil {
return 0, ProjectModules, err
} else {
ProjectModules = append(ProjectModules, ProjectModule)
}
}
return int64(query.AffectRow), ProjectModules, nil
}
func (repository *ProjectModuleRepository) transformPgModelToDomainModel(ProjectModuleModel *models.ProjectModule) (*domain.ProjectModule, error) {
m := &domain.ProjectModule{}
err := common.GobModelTransform(m, ProjectModuleModel)
return m, err
}
func NewProjectModuleRepository(transactionContext *transaction.TransactionContext) (*ProjectModuleRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &ProjectModuleRepository{transactionContext: transactionContext}, nil
}
... ...
package repository
import (
"fmt"
"github.com/tiptok/gocomm/common"
. "github.com/tiptok/gocomm/pkg/orm/pgx"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
)
type ProjectModuleVersionRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *ProjectModuleVersionRepository) Save(dm *domain.ProjectModuleVersion) (*domain.ProjectModuleVersion, error) {
var (
err error
m = &models.ProjectModuleVersion{}
tx = repository.transactionContext.PgTx
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if err = tx.Insert(m); err != nil {
return nil, err
}
dm.Id = m.Id
return dm, nil
}
if err = tx.Update(m); err != nil {
return nil, err
}
return dm, nil
}
func (repository *ProjectModuleVersionRepository) Remove(ProjectModuleVersion *domain.ProjectModuleVersion) (*domain.ProjectModuleVersion, error) {
var (
tx = repository.transactionContext.PgTx
ProjectModuleVersionModel = &models.ProjectModuleVersion{Id: ProjectModuleVersion.Identify().(int64)}
)
if _, err := tx.Model(ProjectModuleVersionModel).Where("id = ?", ProjectModuleVersion.Id).Delete(); err != nil {
return ProjectModuleVersion, err
}
return ProjectModuleVersion, nil
}
func (repository *ProjectModuleVersionRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModuleVersion, error) {
tx := repository.transactionContext.PgTx
ProjectModuleVersionModel := new(models.ProjectModuleVersion)
query := NewQuery(tx.Model(ProjectModuleVersionModel), queryOptions)
query.SetWhere("id = ?", "id")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
if ProjectModuleVersionModel.Id == 0 {
return nil, fmt.Errorf("query row not found")
}
return repository.transformPgModelToDomainModel(ProjectModuleVersionModel)
}
func (repository *ProjectModuleVersionRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModuleVersion, error) {
tx := repository.transactionContext.PgTx
var ProjectModuleVersionModels []*models.ProjectModuleVersion
ProjectModuleVersions := make([]*domain.ProjectModuleVersion, 0)
query := NewQuery(tx.Model(&ProjectModuleVersionModels), queryOptions).
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, ProjectModuleVersions, err
}
for _, ProjectModuleVersionModel := range ProjectModuleVersionModels {
if ProjectModuleVersion, err := repository.transformPgModelToDomainModel(ProjectModuleVersionModel); err != nil {
return 0, ProjectModuleVersions, err
} else {
ProjectModuleVersions = append(ProjectModuleVersions, ProjectModuleVersion)
}
}
return int64(query.AffectRow), ProjectModuleVersions, nil
}
func (repository *ProjectModuleVersionRepository) transformPgModelToDomainModel(ProjectModuleVersionModel *models.ProjectModuleVersion) (*domain.ProjectModuleVersion, error) {
m := &domain.ProjectModuleVersion{}
err := common.GobModelTransform(m, ProjectModuleVersionModel)
return m, err
}
func NewProjectModuleVersionRepository(transactionContext *transaction.TransactionContext) (*ProjectModuleVersionRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &ProjectModuleVersionRepository{transactionContext: transactionContext}, nil
}
... ...
package repository
import (
"fmt"
"github.com/tiptok/gocomm/common"
. "github.com/tiptok/gocomm/pkg/orm/pgx"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
)
type RoleAccessRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *RoleAccessRepository) Save(dm *domain.RoleAccess) (*domain.RoleAccess, error) {
var (
err error
m = &models.RoleAccess{}
tx = repository.transactionContext.PgTx
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if err = tx.Insert(m); err != nil {
return nil, err
}
return dm, nil
}
if err = tx.Update(m); err != nil {
return nil, err
}
return dm, nil
}
func (repository *RoleAccessRepository) Remove(RoleAccess *domain.RoleAccess) (*domain.RoleAccess, error) {
var (
tx = repository.transactionContext.PgTx
RoleAccessModel = &models.RoleAccess{Id: RoleAccess.Identify().(int64)}
)
if _, err := tx.Model(RoleAccessModel).Where("id = ?", RoleAccess.Id).Delete(); err != nil {
return RoleAccess, err
}
return RoleAccess, nil
}
func (repository *RoleAccessRepository) FindOne(queryOptions map[string]interface{}) (*domain.RoleAccess, error) {
tx := repository.transactionContext.PgTx
RoleAccessModel := new(models.RoleAccess)
query := NewQuery(tx.Model(RoleAccessModel), queryOptions)
query.SetWhere("id = ?", "id")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
if RoleAccessModel.Id == 0 {
return nil, fmt.Errorf("query row not found")
}
return repository.transformPgModelToDomainModel(RoleAccessModel)
}
func (repository *RoleAccessRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.RoleAccess, error) {
tx := repository.transactionContext.PgTx
var RoleAccessModels []*models.RoleAccess
RoleAccesss := make([]*domain.RoleAccess, 0)
query := NewQuery(tx.Model(&RoleAccessModels), queryOptions).
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, RoleAccesss, err
}
for _, RoleAccessModel := range RoleAccessModels {
if RoleAccess, err := repository.transformPgModelToDomainModel(RoleAccessModel); err != nil {
return 0, RoleAccesss, err
} else {
RoleAccesss = append(RoleAccesss, RoleAccess)
}
}
return int64(query.AffectRow), RoleAccesss, nil
}
func (repository *RoleAccessRepository) transformPgModelToDomainModel(RoleAccessModel *models.RoleAccess) (*domain.RoleAccess, error) {
m := &domain.RoleAccess{}
err := common.GobModelTransform(m, RoleAccessModel)
return m, err
}
func NewRoleAccessRepository(transactionContext *transaction.TransactionContext) (*RoleAccessRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &RoleAccessRepository{transactionContext: transactionContext}, nil
}
... ...
package repository
import (
"fmt"
"github.com/tiptok/gocomm/common"
. "github.com/tiptok/gocomm/pkg/orm/pgx"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
)
type RoleRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *RoleRepository) Save(dm *domain.Role) (*domain.Role, error) {
var (
err error
m = &models.Role{}
tx = repository.transactionContext.PgTx
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if err = tx.Insert(m); err != nil {
return nil, err
}
return dm, nil
}
if err = tx.Update(m); err != nil {
return nil, err
}
return dm, nil
}
func (repository *RoleRepository) Remove(Role *domain.Role) (*domain.Role, error) {
var (
tx = repository.transactionContext.PgTx
RoleModel = &models.Role{Id: Role.Identify().(int64)}
)
if _, err := tx.Model(RoleModel).Where("id = ?", Role.Id).Delete(); err != nil {
return Role, err
}
return Role, nil
}
func (repository *RoleRepository) FindOne(queryOptions map[string]interface{}) (*domain.Role, error) {
tx := repository.transactionContext.PgTx
RoleModel := new(models.Role)
query := NewQuery(tx.Model(RoleModel), queryOptions)
query.SetWhere("id = ?", "id")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
if RoleModel.Id == 0 {
return nil, fmt.Errorf("query row not found")
}
return repository.transformPgModelToDomainModel(RoleModel)
}
func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Role, error) {
tx := repository.transactionContext.PgTx
var RoleModels []*models.Role
Roles := make([]*domain.Role, 0)
query := NewQuery(tx.Model(&RoleModels), queryOptions).
SetWhere("parent_id=?", "parentId").
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, Roles, err
}
for _, RoleModel := range RoleModels {
if Role, err := repository.transformPgModelToDomainModel(RoleModel); err != nil {
return 0, Roles, err
} else {
Roles = append(Roles, Role)
}
}
return int64(query.AffectRow), Roles, nil
}
func (repository *RoleRepository) transformPgModelToDomainModel(RoleModel *models.Role) (*domain.Role, error) {
m := &domain.Role{}
err := common.GobModelTransform(m, RoleModel)
return m, err
}
func NewRoleRepository(transactionContext *transaction.TransactionContext) (*RoleRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &RoleRepository{transactionContext: transactionContext}, nil
}
... ...
package repository
import (
"fmt"
"github.com/tiptok/gocomm/common"
. "github.com/tiptok/gocomm/pkg/orm/pgx"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
)
type UserRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *UserRepository) Save(dm *domain.User) (*domain.User, error) {
var (
err error
m = &models.User{}
tx = repository.transactionContext.PgTx
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if err = tx.Insert(m); err != nil {
return nil, err
}
return dm, nil
}
if err = tx.Update(m); err != nil {
return nil, err
}
return dm, nil
}
func (repository *UserRepository) Remove(User *domain.User) (*domain.User, error) {
var (
tx = repository.transactionContext.PgTx
UserModel = &models.User{Id: User.Identify().(int64)}
)
if _, err := tx.Model(UserModel).Where("id = ?", User.Id).Delete(); err != nil {
return User, err
}
return User, nil
}
func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) (*domain.User, error) {
tx := repository.transactionContext.PgTx
UserModel := new(models.User)
query := NewQuery(tx.Model(UserModel), queryOptions)
query.SetWhere("id = ?", "id")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
if UserModel.Id == 0 {
return nil, fmt.Errorf("query row not found")
}
return repository.transformPgModelToDomainModel(UserModel)
}
func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.User, error) {
tx := repository.transactionContext.PgTx
var UserModels []*models.User
Users := make([]*domain.User, 0)
query := NewQuery(tx.Model(&UserModels), queryOptions).
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, Users, err
}
for _, UserModel := range UserModels {
if User, err := repository.transformPgModelToDomainModel(UserModel); err != nil {
return 0, Users, err
} else {
Users = append(Users, User)
}
}
return int64(query.AffectRow), Users, nil
}
func (repository *UserRepository) transformPgModelToDomainModel(UserModel *models.User) (*domain.User, error) {
m := &domain.User{}
err := common.GobModelTransform(m, UserModel)
return m, err
}
func NewUserRepository(transactionContext *transaction.TransactionContext) (*UserRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &UserRepository{transactionContext: transactionContext}, nil
}
... ...
package utils
import (
"github.com/dgrijalva/jwt-go"
"time"
)
type UserTokenClaims struct {
UserId int64 `json:"userId"`
CompanyId int64 `json:"companyId"`
AdminType int `json:"adminType"` //用户类型 1:合伙人 2:高管
Phone string `json:"phone"`
jwt.StandardClaims
}
var jwtSecret = []byte("123456")
//解析 UserTokenClaims
func ParseJWTToken(token string) (*UserTokenClaims, error) {
tokenClaims, err := jwt.ParseWithClaims(token, &UserTokenClaims{}, func(token *jwt.Token) (interface{}, error) {
return jwtSecret, nil
})
if err != nil {
return nil, err
}
if tokenClaims != nil {
if claim, ok := tokenClaims.Claims.(*UserTokenClaims); ok && tokenClaims.Valid {
// TODO:版本兼容
//if claim.CompanyId==0{
// claim.CompanyId = 1
// claim.AdminType = 1
//}
return claim, nil
}
}
return nil, err
}
//生成token
//@uid 用户变化
//@password 密码
//@expire 过期时长
func GenerateToken(uid int64, phone string, expire time.Duration) (string, error) {
now := time.Now()
expireTime := now.Add(expire)
claims := UserTokenClaims{
UserId: uid,
Phone: phone,
StandardClaims: jwt.StandardClaims{
ExpiresAt: expireTime.Unix(),
Issuer: "jwt",
},
}
tokenClaims := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
token, err := tokenClaims.SignedString(jwtSecret)
return token, err
}
func GenerateTokenWithAdminType(uid int64, phone string, adminType int, expire time.Duration) (string, error) {
now := time.Now()
expireTime := now.Add(expire)
claims := UserTokenClaims{
UserId: uid,
Phone: phone,
AdminType: adminType,
StandardClaims: jwt.StandardClaims{
ExpiresAt: expireTime.Unix(),
Issuer: "jwt",
},
}
tokenClaims := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
token, err := tokenClaims.SignedString(jwtSecret)
return token, err
}
func GenerateTokenWithClaim(claim UserTokenClaims, expire time.Duration) (string, error) {
now := time.Now()
expireTime := now.Add(expire)
claims := UserTokenClaims{
UserId: claim.UserId,
Phone: claim.Phone,
CompanyId: claim.CompanyId,
AdminType: claim.AdminType,
StandardClaims: jwt.StandardClaims{
ExpiresAt: expireTime.Unix(),
Issuer: "jwt",
},
}
tokenClaims := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
token, err := tokenClaims.SignedString(jwtSecret)
return token, err
}
... ...
package beego
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/plugins/cors"
_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/routers"
)
func init() {
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin"},
ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin"},
AllowCredentials: true,
}))
}
... ...
package controllers
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/access"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/access"
)
type AccessController struct {
BaseController
}
// CreateAccess
// CreateAccess execute command create Access
func (this *AccessController) CreateAccess() {
var (
msg *protocol.ResponseMessage
svr = access.NewAccessService(nil)
request *protocolx.CreateAccessRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.CreateAccess(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// UpdateAccess
// UpdateAccess execute command update Access
func (this *AccessController) UpdateAccess() {
var (
msg *protocol.ResponseMessage
svr = access.NewAccessService(nil)
request *protocolx.UpdateAccessRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.UpdateAccess(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// GetAccess
// GetAccess execute query get Access
func (this *AccessController) GetAccess() {
var (
msg *protocol.ResponseMessage
svr = access.NewAccessService(nil)
request *protocolx.GetAccessRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.GetAccess(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// DeleteAccess
// DeleteAccess execute command delete Access
func (this *AccessController) DeleteAccess() {
var (
msg *protocol.ResponseMessage
svr = access.NewAccessService(nil)
request *protocolx.DeleteAccessRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.DeleteAccess(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// ListAccess
// ListAccess execute query list Access
func (this *AccessController) ListAccess() {
var (
msg *protocol.ResponseMessage
svr = access.NewAccessService(nil)
request *protocolx.ListAccessRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.ListAccess(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
... ...
package controllers
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/auth"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/auth"
)
type AuthController struct {
BaseController
}
// Login
// 登录
func (this *AuthController) Login() {
var (
msg *protocol.ResponseMessage
svr = auth.NewAuthService(nil)
request *protocolx.LoginRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.Login(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// Logout
// 测试
func (this *AuthController) Logout() {
var (
msg *protocol.ResponseMessage
svr = auth.NewAuthService(nil)
request *protocolx.LogoutRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.Logout(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// Profile
// 获取当前用户数据
func (this *AuthController) Profile() {
var (
msg *protocol.ResponseMessage
svr = auth.NewAuthService(nil)
request *protocolx.ProfileRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.Profile(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// CaptchaInit
// 图形验证码初始化
func (this *AuthController) CaptchaInit() {
var (
msg *protocol.ResponseMessage
svr = auth.NewAuthService(nil)
request *protocolx.CaptchaInitRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.CaptchaInit(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// ChangePassword
// 修改密码
func (this *AuthController) ChangePassword() {
var (
msg *protocol.ResponseMessage
svr = auth.NewAuthService(nil)
request *protocolx.ChangePasswordRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.ChangePassword(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
... ...
package controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/validation"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
"strconv"
)
type BaseController struct {
beego.Controller
}
func (controller BaseController) JsonUnmarshal(v interface{}) error {
body := controller.Ctx.Input.RequestBody
if len(body) == 0 {
body = []byte("{}")
}
return json.Unmarshal(body, v)
}
func (controller BaseController) GetLimitInfo() (offset int, limit int) {
offset, _ = controller.GetInt("offset")
limit, _ = controller.GetInt("limit")
return
}
//Valid valid struct
func (controller *BaseController) Valid(obj interface{}) (result bool, msg *protocol.ResponseMessage) {
/*校验*/
var err error
valid := validation.Validation{}
result, err = valid.Valid(obj)
if err != nil {
}
if !result {
msg = protocol.BadRequestParam(2)
return
}
return
}
func (this *BaseController) Resp(msg *protocol.ResponseMessage) {
this.Data["json"] = msg
this.Ctx.Input.SetData("outputData", msg)
this.ServeJSON()
}
func (this *BaseController) RespH5(msg *protocol.ResponseMessage) {
if msg.Errno != 0 {
msg.Errno = -1
}
this.Data["json"] = msg
this.Ctx.Input.SetData("outputData", msg)
this.ServeJSON()
}
//获取请求头信息
func (this *BaseController) GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
h := &protocol.RequestHeader{}
h.UserId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-id"), 10, 64)
return h
}
... ...
package controllers
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/menu"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/menu"
)
type MenuController struct {
BaseController
}
// CreateMenu
// CreateMenu execute command create Menu
func (this *MenuController) CreateMenu() {
var (
msg *protocol.ResponseMessage
svr = menu.NewMenuService(nil)
request *protocolx.CreateMenuRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.CreateMenu(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// UpdateMenu
// UpdateMenu execute command update Menu
func (this *MenuController) UpdateMenu() {
var (
msg *protocol.ResponseMessage
svr = menu.NewMenuService(nil)
request *protocolx.UpdateMenuRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.UpdateMenu(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// GetMenu
// GetMenu execute query get Menu
func (this *MenuController) GetMenu() {
var (
msg *protocol.ResponseMessage
svr = menu.NewMenuService(nil)
request *protocolx.GetMenuRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.GetMenu(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// DeleteMenu
// DeleteMenu execute command delete Menu
func (this *MenuController) DeleteMenu() {
var (
msg *protocol.ResponseMessage
svr = menu.NewMenuService(nil)
request *protocolx.DeleteMenuRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.DeleteMenu(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// ListMenu
// ListMenu execute query list Menu
func (this *MenuController) ListMenu() {
var (
msg *protocol.ResponseMessage
svr = menu.NewMenuService(nil)
request *protocolx.ListMenuRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.ListMenu(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
... ...
package controllers
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/project_module"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module"
)
type ProjectModuleController struct {
BaseController
}
// CreateProjectModule
// CreateProjectModule execute command create ProjectModule
func (this *ProjectModuleController) CreateProjectModule() {
var (
msg *protocol.ResponseMessage
svr = project_module.NewProjectModuleService(nil)
request *protocolx.CreateProjectModuleRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.CreateProjectModule(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// UpdateProjectModule
// UpdateProjectModule execute command update ProjectModule
func (this *ProjectModuleController) UpdateProjectModule() {
var (
msg *protocol.ResponseMessage
svr = project_module.NewProjectModuleService(nil)
request *protocolx.UpdateProjectModuleRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.UpdateProjectModule(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// GetProjectModule
// GetProjectModule execute query get ProjectModule
func (this *ProjectModuleController) GetProjectModule() {
var (
msg *protocol.ResponseMessage
svr = project_module.NewProjectModuleService(nil)
request = &protocolx.GetProjectModuleRequest{}
)
defer func() {
this.Resp(msg)
}()
request.Id, _ = this.GetInt64(":projectModuleId")
header := this.GetRequestHeader(this.Ctx)
data, err := svr.GetProjectModule(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// DeleteProjectModule
// DeleteProjectModule execute command delete ProjectModule
func (this *ProjectModuleController) DeleteProjectModule() {
var (
msg *protocol.ResponseMessage
svr = project_module.NewProjectModuleService(nil)
request *protocolx.DeleteProjectModuleRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.DeleteProjectModule(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// ListProjectModule
// ListProjectModule execute query list ProjectModule
func (this *ProjectModuleController) ListProjectModule() {
var (
msg *protocol.ResponseMessage
svr = project_module.NewProjectModuleService(nil)
request *protocolx.ListProjectModuleRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.ListProjectModule(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
... ...
package controllers
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/project_module_files"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_files"
)
type ProjectModuleFilesController struct {
BaseController
}
// CreateProjectModuleFiles
// CreateProjectModuleFiles execute command create ProjectModuleFiles
func (this *ProjectModuleFilesController) CreateProjectModuleFiles() {
var (
msg *protocol.ResponseMessage
svr = project_module_files.NewProjectModuleFilesService(nil)
request *protocolx.CreateProjectModuleFilesRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.CreateProjectModuleFiles(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// UpdateProjectModuleFiles
// UpdateProjectModuleFiles execute command update ProjectModuleFiles
func (this *ProjectModuleFilesController) UpdateProjectModuleFiles() {
var (
msg *protocol.ResponseMessage
svr = project_module_files.NewProjectModuleFilesService(nil)
request *protocolx.UpdateProjectModuleFilesRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.UpdateProjectModuleFiles(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// GetProjectModuleFiles
// GetProjectModuleFiles execute query get ProjectModuleFiles
func (this *ProjectModuleFilesController) GetProjectModuleFiles() {
var (
msg *protocol.ResponseMessage
svr = project_module_files.NewProjectModuleFilesService(nil)
request *protocolx.GetProjectModuleFilesRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.GetProjectModuleFiles(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// DeleteProjectModuleFiles
// DeleteProjectModuleFiles execute command delete ProjectModuleFiles
func (this *ProjectModuleFilesController) DeleteProjectModuleFiles() {
var (
msg *protocol.ResponseMessage
svr = project_module_files.NewProjectModuleFilesService(nil)
request *protocolx.DeleteProjectModuleFilesRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.DeleteProjectModuleFiles(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// ListProjectModuleFiles
// ListProjectModuleFiles execute query list ProjectModuleFiles
func (this *ProjectModuleFilesController) ListProjectModuleFiles() {
var (
msg *protocol.ResponseMessage
svr = project_module_files.NewProjectModuleFilesService(nil)
request *protocolx.ListProjectModuleFilesRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.ListProjectModuleFiles(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
... ...
package controllers
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/project_module_version"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_version"
)
type ProjectModuleVersionController struct {
BaseController
}
// CreateProjectModuleVersion
// CreateProjectModuleVersion execute command create ProjectModuleVersion
func (this *ProjectModuleVersionController) CreateProjectModuleVersion() {
var (
msg *protocol.ResponseMessage
svr = project_module_version.NewProjectModuleVersionService(nil)
request *protocolx.CreateProjectModuleVersionRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.CreateProjectModuleVersion(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// UpdateProjectModuleVersion
// UpdateProjectModuleVersion execute command update ProjectModuleVersion
func (this *ProjectModuleVersionController) UpdateProjectModuleVersion() {
var (
msg *protocol.ResponseMessage
svr = project_module_version.NewProjectModuleVersionService(nil)
request *protocolx.UpdateProjectModuleVersionRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.UpdateProjectModuleVersion(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// GetProjectModuleVersion
// GetProjectModuleVersion execute query get ProjectModuleVersion
func (this *ProjectModuleVersionController) GetProjectModuleVersion() {
var (
msg *protocol.ResponseMessage
svr = project_module_version.NewProjectModuleVersionService(nil)
request *protocolx.GetProjectModuleVersionRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.GetProjectModuleVersion(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// DeleteProjectModuleVersion
// DeleteProjectModuleVersion execute command delete ProjectModuleVersion
func (this *ProjectModuleVersionController) DeleteProjectModuleVersion() {
var (
msg *protocol.ResponseMessage
svr = project_module_version.NewProjectModuleVersionService(nil)
request *protocolx.DeleteProjectModuleVersionRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.DeleteProjectModuleVersion(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// ListProjectModuleVersion
// ListProjectModuleVersion execute query list ProjectModuleVersion
func (this *ProjectModuleVersionController) ListProjectModuleVersion() {
var (
msg *protocol.ResponseMessage
svr = project_module_version.NewProjectModuleVersionService(nil)
request *protocolx.ListProjectModuleVersionRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.ListProjectModuleVersion(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
... ...
package controllers
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/role"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/role"
)
type RoleController struct {
BaseController
}
// CreateRole
// CreateRole execute command create Role
func (this *RoleController) CreateRole() {
var (
msg *protocol.ResponseMessage
svr = role.NewRoleService(nil)
request *protocolx.CreateRoleRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.CreateRole(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// UpdateRole
// UpdateRole execute command update Role
func (this *RoleController) UpdateRole() {
var (
msg *protocol.ResponseMessage
svr = role.NewRoleService(nil)
request *protocolx.UpdateRoleRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
request.Id, _ = this.GetInt64(":roleId")
header := this.GetRequestHeader(this.Ctx)
data, err := svr.UpdateRole(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// GetRole
// GetRole execute query get Role
func (this *RoleController) GetRole() {
var (
msg *protocol.ResponseMessage
svr = role.NewRoleService(nil)
request = &protocolx.GetRoleRequest{}
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
request.Id, _ = this.GetInt64(":roleId")
header := this.GetRequestHeader(this.Ctx)
data, err := svr.GetRole(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// DeleteRole
// DeleteRole execute command delete Role
func (this *RoleController) DeleteRole() {
var (
msg *protocol.ResponseMessage
svr = role.NewRoleService(nil)
request = &protocolx.DeleteRoleRequest{}
)
defer func() {
this.Resp(msg)
}()
request.Id, _ = this.GetInt64(":roleId")
header := this.GetRequestHeader(this.Ctx)
data, err := svr.DeleteRole(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// ListRole
// ListRole execute query list Role
func (this *RoleController) ListRole() {
var (
msg *protocol.ResponseMessage
svr = role.NewRoleService(nil)
request *protocolx.ListRoleRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.ListRole(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
... ...
package controllers
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/user"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/user"
)
type UserController struct {
BaseController
}
// CreateUser
// CreateUser execute command create User
func (this *UserController) CreateUser() {
var (
msg *protocol.ResponseMessage
svr = user.NewUserService(nil)
request *protocolx.CreateUserRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.CreateUser(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// UpdateUser
// UpdateUser execute command update User
func (this *UserController) UpdateUser() {
var (
msg *protocol.ResponseMessage
svr = user.NewUserService(nil)
request *protocolx.UpdateUserRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.UpdateUser(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// GetUser
// GetUser execute query get User
func (this *UserController) GetUser() {
var (
msg *protocol.ResponseMessage
svr = user.NewUserService(nil)
request *protocolx.GetUserRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.GetUser(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// DeleteUser
// DeleteUser execute command delete User
func (this *UserController) DeleteUser() {
var (
msg *protocol.ResponseMessage
svr = user.NewUserService(nil)
request *protocolx.DeleteUserRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.DeleteUser(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// ListUser
// ListUser execute query list User
func (this *UserController) ListUser() {
var (
msg *protocol.ResponseMessage
svr = user.NewUserService(nil)
request *protocolx.ListUserRequest
)
defer func() {
this.Resp(msg)
}()
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := svr.ListUser(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
... ...
package middleware
import (
"errors"
"github.com/astaxie/beego/context"
"github.com/tiptok/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
"strconv"
"strings"
)
var (
errAuthorization = errors.New("无访问权限")
errAuthorizationExpire = errors.New("权限已过期,请重新登录")
)
func CheckAuthorization(ctx *context.Context) {
var (
msg *protocol.ResponseMessage
)
defer func() {
if msg != nil {
ctx.Output.JSON(msg, false, false)
}
}()
authorization := ctx.Input.Header("Authorization")
if len(authorization) == 0 {
msg = protocol.NewResponseMessage(1, errAuthorization.Error())
return
}
token := strings.Split(authorization, " ")[1]
claim, err := common.ParseJWTToken(token)
if err != nil {
msg = protocol.NewResponseMessage(1, errAuthorizationExpire.Error())
return
}
userId, _ := strconv.Atoi(claim.Username)
ctx.Input.SetData("x-mmm-id", userId)
//TODO:check redis cache
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/access/", &controllers.AccessController{}, "POST:CreateAccess")
beego.Router("/access/:accessId", &controllers.AccessController{}, "PUT:UpdateAccess")
beego.Router("/access/:accessId", &controllers.AccessController{}, "GET:GetAccess")
beego.Router("/access/:accessId", &controllers.AccessController{}, "DELETE:DeleteAccess")
beego.Router("/access/", &controllers.AccessController{}, "GET:ListAccess")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/auth/login", &controllers.AuthController{}, "post:Login")
beego.Router("/auth/logout", &controllers.AuthController{}, "post:Logout")
beego.Router("/auth/profile", &controllers.AuthController{}, "post:Profile")
beego.Router("/auth/captchaInit", &controllers.AuthController{}, "get:CaptchaInit")
beego.Router("/auth/changePassword", &controllers.AuthController{}, "post:ChangePassword")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/menu/", &controllers.MenuController{}, "POST:CreateMenu")
beego.Router("/menu/:menuId", &controllers.MenuController{}, "PUT:UpdateMenu")
beego.Router("/menu/:menuId", &controllers.MenuController{}, "GET:GetMenu")
beego.Router("/menu/:menuId", &controllers.MenuController{}, "DELETE:DeleteMenu")
beego.Router("/menu/", &controllers.MenuController{}, "GET:ListMenu")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/project_module_files/", &controllers.ProjectModuleFilesController{}, "POST:CreateProjectModuleFiles")
beego.Router("/project_module_files/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "PUT:UpdateProjectModuleFiles")
beego.Router("/project_module_files/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "GET:GetProjectModuleFiles")
beego.Router("/project_module_files/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "DELETE:DeleteProjectModuleFiles")
beego.Router("/project_module_files/", &controllers.ProjectModuleFilesController{}, "GET:ListProjectModuleFiles")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/project_module/", &controllers.ProjectModuleController{}, "POST:CreateProjectModule")
beego.Router("/project_module/:projectModuleId", &controllers.ProjectModuleController{}, "PUT:UpdateProjectModule")
beego.Router("/project_module/:projectModuleId", &controllers.ProjectModuleController{}, "GET:GetProjectModule")
beego.Router("/project_module/:projectModuleId", &controllers.ProjectModuleController{}, "DELETE:DeleteProjectModule")
beego.Router("/project_module/", &controllers.ProjectModuleController{}, "GET:ListProjectModule")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/project_module_version/", &controllers.ProjectModuleVersionController{}, "POST:CreateProjectModuleVersion")
beego.Router("/project_module_version/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "PUT:UpdateProjectModuleVersion")
beego.Router("/project_module_version/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "GET:GetProjectModuleVersion")
beego.Router("/project_module_version/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "DELETE:DeleteProjectModuleVersion")
beego.Router("/project_module_version/", &controllers.ProjectModuleVersionController{}, "GET:ListProjectModuleVersion")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/role/", &controllers.RoleController{}, "POST:CreateRole")
beego.Router("/role/:roleId", &controllers.RoleController{}, "PUT:UpdateRole")
beego.Router("/role/:roleId", &controllers.RoleController{}, "GET:GetRole")
beego.Router("/role/:roleId", &controllers.RoleController{}, "DELETE:DeleteRole")
beego.Router("/role/", &controllers.RoleController{}, "GET:ListRole")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/user/", &controllers.UserController{}, "POST:CreateUser")
beego.Router("/user/:userId", &controllers.UserController{}, "PUT:UpdateUser")
beego.Router("/user/:userId", &controllers.UserController{}, "GET:GetUser")
beego.Router("/user/:userId", &controllers.UserController{}, "DELETE:DeleteUser")
beego.Router("/user/", &controllers.UserController{}, "GET:ListUser")
}
... ...
package access
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type CreateAccessRequest struct {
// 权限名称
AccessName string `json:"accessName,omitempty"`
// 权限编码
AccessCode string `json:"accessCode,omitempty"`
// 权限类型 menu button data
AccessType string `json:"accessType,omitempty"`
// 排序
Sort int `json:"sort,omitempty"`
// 请求对象 接口地址/对象
Object string `json:"object,omitempty"`
// 操作方法 httpMethod/read/write
Action string `json:"action,omitempty"`
// 所属功能模块
Module string `json:"module,omitempty"`
}
func (CreateAccessRequest *CreateAccessRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(CreateAccessRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package access
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type CreateAccessResponse struct {
}
func (CreateAccessResponse *CreateAccessResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(CreateAccessResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package access
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type DeleteAccessRequest struct {
// 唯一标识
Id int64 `json:"id,omitempty"`
}
func (DeleteAccessRequest *DeleteAccessRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(DeleteAccessRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package access
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type DeleteAccessResponse struct {
}
func (DeleteAccessResponse *DeleteAccessResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(DeleteAccessResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package access
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type UpdateAccessRequest struct {
// 权限名称
AccessName string `json:"accessName,omitempty"`
// 权限编码
AccessCode string `json:"accessCode,omitempty"`
// 权限类型 menu button data
AccessType string `json:"accessType,omitempty"`
// 排序
Sort int `json:"sort,omitempty"`
// 请求对象 接口地址/对象
Object string `json:"object,omitempty"`
// 操作方法 httpMethod/read/write
Action string `json:"action,omitempty"`
// 所属功能模块
Module string `json:"module,omitempty"`
}
func (UpdateAccessRequest *UpdateAccessRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(UpdateAccessRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package access
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type UpdateAccessResponse struct {
}
func (UpdateAccessResponse *UpdateAccessResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(UpdateAccessResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package access
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetAccessRequest struct {
// 唯一标识
Id int64 `json:"id,omitempty"`
}
func (GetAccessRequest *GetAccessRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(GetAccessRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package access
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetAccessResponse struct {
}
func (GetAccessResponse *GetAccessResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(GetAccessResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package access
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListAccessRequest struct {
}
func (ListAccessRequest *ListAccessRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(ListAccessRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package access
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListAccessResponse struct {
}
func (ListAccessResponse *ListAccessResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(ListAccessResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package auth
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ChangePasswordRequest struct {
}
func (ChangePasswordRequest *ChangePasswordRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(ChangePasswordRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package auth
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ChangePasswordResponse struct {
}
func (ChangePasswordResponse *ChangePasswordResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(ChangePasswordResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package auth
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type LoginRequest struct {
UserName string `json:"username,required"`
Password string `json:"password,required"`
}
func (LoginRequest *LoginRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(LoginRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package auth
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type LoginResponse struct {
Access interface{} `json:"access"`
}
func (LoginResponse *LoginResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(LoginResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package auth
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type LogoutRequest struct {
}
func (LogoutRequest *LogoutRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(LogoutRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...