作者 yangfu

init godevp

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

要显示太多修改。

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

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