作者 yangfu

修改: 1.路由增加版本标识 v1 2.增加发布文件

正在显示 51 个修改的文件 包含 983 行增加152 行删除
  1 +FROM golang:1.14
  2 +ENV APP_DIR $GOPATH/src/godevp
  3 +RUN mkdir -p $APP_DIR
  4 +WORKDIR $APP_DIR/
  5 +COPY ./pkg pkg
  6 +COPY ./conf conf
  7 +COPY ./go.mod go.mod
  8 +COPY ./main.go main.go
  9 +RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
  10 +ENV GO111MODULE on
  11 +ENV GOPROXY https://goproxy.cn,direct
  12 +RUN ["go","mod","tidy"]
  13 +RUN ["go","build"]
  14 +EXPOSE 8082
  15 +ENTRYPOINT ["./godevp"]
  1 +#!/bin/bash
  2 +export PATH=/root/local/bin:$PATH
  3 +kubectl -n mmm-suplus-dev get pods | grep -q mmmgodevp
  4 +if [ "$?" == "1" ];then
  5 + kubectl create -f /tmp/dev/godevp/godevp.yaml --record
  6 + kubectl -n mmm-suplus-dev get svc | grep -q mmmgodevp
  7 + if [ "$?" == "0" ];then
  8 + echo "mmmgodevp service install success!"
  9 + else
  10 + echo "mmmgodevp service install fail!"
  11 + fi
  12 + kubectl -n mmm-suplus-dev get pods | grep -q mmmgodevp
  13 + if [ "$?" == "0" ];then
  14 + echo "mmmgodevp deployment install success!"
  15 + else
  16 + echo "mmmgodevp deployment install fail!"
  17 + fi
  18 +else
  19 + kubectl delete -f /tmp/dev/godevp/godevp.yaml
  20 + kubectl -n mmm-suplus-dev get svc | grep -q mmmgodevp
  21 + while [ "$?" == "0" ]
  22 + do
  23 + kubectl -n mmm-suplus-dev get svc | grep -q mmmgodevp
  24 + done
  25 + kubectl -n mmm-suplus-dev get pods | grep -q mmmgodevp
  26 + while [ "$?" == "0" ]
  27 + do
  28 + kubectl -n mmm-suplus-dev get pods | grep -q mmmgodevp
  29 + done
  30 + kubectl create -f /tmp/dev/godevp/godevp.yaml --record
  31 + kubectl -n mmm-suplus-dev get svc | grep -q mmmgodevp
  32 + if [ "$?" == "0" ];then
  33 + echo "mmmgodevp service update success!"
  34 + else
  35 + echo "mmmgodevp service update fail!"
  36 + fi
  37 + kubectl -n mmm-suplus-dev get pods | grep -q mmmgodevp
  38 + if [ "$?" == "0" ];then
  39 + echo "mmmgodevp deployment update success!"
  40 + else
  41 + echo "mmmgodevp deployment update fail!"
  42 + fi
  43 +fi
  1 +apiVersion: v1
  2 +kind: Service
  3 +metadata:
  4 + name: mmmgodevp
  5 + namespace: mmm-suplus-dev
  6 + labels:
  7 + k8s-app: mmmgodevp
  8 +spec:
  9 + ports:
  10 + - name: "http"
  11 + port: 80
  12 + targetPort: 8082
  13 + selector:
  14 + k8s-app: mmmgodevp
  15 +---
  16 +apiVersion: extensions/v1beta1
  17 +kind: Deployment
  18 +metadata:
  19 + name: mmmgodevp
  20 + namespace: mmm-suplus-dev
  21 + labels:
  22 + k8s-app: mmmgodevp
  23 +spec:
  24 + replicas: 1
  25 + template:
  26 + metadata:
  27 + labels:
  28 + k8s-app: mmmgodevp
  29 + spec:
  30 + affinity:
  31 + nodeAffinity:
  32 + preferredDuringSchedulingIgnoredDuringExecution:
  33 + - preference: {}
  34 + weight: 100
  35 + requiredDuringSchedulingIgnoredDuringExecution:
  36 + nodeSelectorTerms:
  37 + - matchExpressions:
  38 + - key: kubernetes.io/hostname
  39 + operator: In
  40 + values:
  41 + - cn-hangzhou.i-bp1djh1xn7taumbue1ze
  42 + - cn-hangzhou.i-bp1djh1xn7taumbue1zd
  43 + - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
  44 + - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
  45 + containers:
  46 + - name: mmmgodevp
  47 + image: 192.168.0.243:5000/mmm/godevp:dev
  48 + imagePullPolicy: Always
  49 + ports:
  50 + - containerPort: 8082
  51 + volumeMounts:
  52 + - mountPath: /opt/logs
  53 + name: accesslogs
  54 + env:
  55 + - name: HTTP_PORT
  56 + value: "8082"
  57 + - name: POSTGRESQL_DB_NAME
  58 + value: "godevp_dev"
  59 + - name: POSTGRESQL_USER
  60 + value: "postgres"
  61 + - name: POSTGRESQL_PASSWORD
  62 + value: "eagle1010"
  63 + - name: POSTGRESQL_HOST
  64 + value: "114.55.200.59"
  65 + - name: POSTGRESQL_PORT
  66 + value: "31543"
  67 + - name: LOG_LEVEL
  68 + value: "debug"
  69 + - name: ERROR_BASE_CODE
  70 + value: "1"
  71 + - name: ERROR_BASE_CODE_MULTIPLE
  72 + value: "1000"
  73 + - name: DEFAULT_GUEST_COMPANY
  74 + value: "10011"
  75 + - name: ABILITY_SERVICE_HOST
  76 + value: "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
  77 + - name: MMM_OPEN_API_SERVICE_HOST
  78 + value: "http://mmm-open-api-dev.fjmaimaimai.com"
  79 + - name: UCENTER_SERVICE_HOST
  80 + value: "https://suplus-ucenter-dev.fjmaimaimai.com"
  81 + - name: BUSINESS_ADMIN_SERVICE_HOST
  82 + valueFrom:
  83 + configMapKeyRef:
  84 + name: suplus-config
  85 + key: service.businessadmin
  86 + - name: REDIS_HOST
  87 + valueFrom:
  88 + configMapKeyRef:
  89 + name: suplus-config
  90 + key: redis.ip
  91 + - name: REDIS_PORT
  92 + valueFrom:
  93 + configMapKeyRef:
  94 + name: suplus-config
  95 + key: redis.port
  96 + - name: REDIS_AUTH
  97 + value: ""
  98 + volumes:
  99 + - name: accesslogs
  100 + emptyDir: {}
  1 +#!/bin/bash
  2 +export PATH=/root/local/bin:$PATH
  3 +kubectl -n mmm-suplus-prd get pods | grep -q partner
  4 +if [ "$?" == "1" ];then
  5 + kubectl create -f /tmp/prd/partner/partner.yaml --record
  6 + kubectl -n mmm-suplus-prd get svc | grep -q partner
  7 + if [ "$?" == "0" ];then
  8 + echo "partner service install success!"
  9 + else
  10 + echo "partner service install fail!"
  11 + fi
  12 + kubectl -n mmm-suplus-prd get pods | grep -q partner
  13 + if [ "$?" == "0" ];then
  14 + echo "partner deployment install success!"
  15 + else
  16 + echo "partner deployment install fail!"
  17 + fi
  18 +else
  19 + kubectl delete -f /tmp/prd/partner/partner.yaml
  20 + kubectl -n mmm-suplus-prd get svc | grep -q partner
  21 + while [ "$?" == "0" ]
  22 + do
  23 + kubectl -n mmm-suplus-prd get svc | grep -q partner
  24 + done
  25 + kubectl -n mmm-suplus-prd get pods | grep -q partner
  26 + while [ "$?" == "0" ]
  27 + do
  28 + kubectl -n mmm-suplus-prd get pods | grep -q partner
  29 + done
  30 + kubectl create -f /tmp/prd/partner/partner.yaml --record
  31 + kubectl -n mmm-suplus-prd get svc | grep -q partner
  32 + if [ "$?" == "0" ];then
  33 + echo "partner service update success!"
  34 + else
  35 + echo "partner service update fail!"
  36 + fi
  37 + kubectl -n mmm-suplus-prd get pods | grep -q partner
  38 + if [ "$?" == "0" ];then
  39 + echo "partner deployment update success!"
  40 + else
  41 + echo "partner deployment update fail!"
  42 + fi
  43 +fi
  1 +apiVersion: v1
  2 +kind: Service
  3 +metadata:
  4 + name: partner
  5 + namespace: mmm-suplus-prd
  6 + labels:
  7 + k8s-app: partner
  8 +spec:
  9 + ports:
  10 + - name: "http"
  11 + port: 80
  12 + targetPort: 8082
  13 + selector:
  14 + k8s-app: partner
  15 +---
  16 +apiVersion: extensions/v1beta1
  17 +kind: Deployment
  18 +metadata:
  19 + name: partner
  20 + namespace: mmm-suplus-prd
  21 + labels:
  22 + k8s-app: partner
  23 +spec:
  24 + replicas: 1
  25 + template:
  26 + metadata:
  27 + labels:
  28 + k8s-app: partner
  29 + spec:
  30 + affinity:
  31 + nodeAffinity:
  32 + preferredDuringSchedulingIgnoredDuringExecution:
  33 + - preference: {}
  34 + weight: 100
  35 + requiredDuringSchedulingIgnoredDuringExecution:
  36 + nodeSelectorTerms:
  37 + - matchExpressions:
  38 + - key: kubernetes.io/hostname
  39 + operator: In
  40 + values:
  41 + - cn-hangzhou.i-bp1djh1xn7taumbue1ze
  42 + - cn-hangzhou.i-bp1djh1xn7taumbue1zd
  43 + - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
  44 + - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
  45 + containers:
  46 + - name: partner
  47 + image: 192.168.0.243:5000/mmm/partner:master
  48 + imagePullPolicy: Always
  49 + ports:
  50 + - containerPort: 8082
  51 + volumeMounts:
  52 + - mountPath: /opt/logs
  53 + name: accesslogs
  54 + env:
  55 + - name: HTTP_PORT
  56 + value: "8082"
  57 + - name: POSTGRESQL_DB_NAME
  58 + value: "partner"
  59 + - name: POSTGRESQL_USER
  60 + value: "postgres"
  61 + - name: POSTGRESQL_PASSWORD
  62 + value: "postgres_55_online"
  63 + - name: POSTGRESQL_HOST
  64 + value: "112.124.115.55"
  65 + - name: POSTGRESQL_PORT
  66 + value: "15432"
  67 + - name: LOG_LEVEL
  68 + value: "debug"
  69 + - name: ERROR_BASE_CODE
  70 + value: "1"
  71 + - name: ERROR_BASE_CODE_MULTIPLE
  72 + value: "1000"
  73 + - name: DEFAULT_GUEST_COMPANY
  74 + value: "12"
  75 + - name: ABILITY_SERVICE_HOST
  76 + value: "https://ability.fjmaimaimai.com"
  77 + - name: MMM_OPEN_API_SERVICE_HOST
  78 + value: "https://public-interface.fjmaimaimai.com/openapi"
  79 + - name: UCENTER_SERVICE_HOST
  80 + value: "https://suplus-ucenter-prd.fjmaimaimai.com"
  81 + - name: BUSINESS_ADMIN_SERVICE_HOST
  82 + valueFrom:
  83 + configMapKeyRef:
  84 + name: suplus-config
  85 + key: service.businessadmin
  86 + - name: REDIS_HOST
  87 + valueFrom:
  88 + configMapKeyRef:
  89 + name: suplus-config
  90 + key: redis.ip
  91 + - name: REDIS_PORT
  92 + valueFrom:
  93 + configMapKeyRef:
  94 + name: suplus-config
  95 + key: redis.port
  96 + - name: REDIS_AUTH
  97 + value: ""
  98 + volumes:
  99 + - name: accesslogs
  100 + emptyDir: {}
  1 +#!/bin/bash
  2 +export PATH=/root/local/bin:$PATH
  3 +kubectl -n mmm-suplus-test get pods | grep -q mmmpartner
  4 +if [ "$?" == "1" ];then
  5 + kubectl create -f /tmp/test/partner/partner.yaml --record
  6 + kubectl -n mmm-suplus-test get svc | grep -q mmmpartner
  7 + if [ "$?" == "0" ];then
  8 + echo "mmmpartner service install success!"
  9 + else
  10 + echo "mmmpartner service install fail!"
  11 + fi
  12 + kubectl -n mmm-suplus-test get pods | grep -q mmmpartner
  13 + if [ "$?" == "0" ];then
  14 + echo "mmmpartner deployment install success!"
  15 + else
  16 + echo "mmmpartner deployment install fail!"
  17 + fi
  18 +else
  19 + kubectl delete -f /tmp/test/partner/partner.yaml
  20 + kubectl -n mmm-suplus-test get svc | grep -q mmmpartner
  21 + while [ "$?" == "0" ]
  22 + do
  23 + kubectl -n mmm-suplus-test get svc | grep -q mmmpartner
  24 + done
  25 + kubectl -n mmm-suplus-test get pods | grep -q mmmpartner
  26 + while [ "$?" == "0" ]
  27 + do
  28 + kubectl -n mmm-suplus-test get pods | grep -q mmmpartner
  29 + done
  30 + kubectl create -f /tmp/test/partner/partner.yaml --record
  31 + kubectl -n mmm-suplus-test get svc | grep -q mmmpartner
  32 + if [ "$?" == "0" ];then
  33 + echo "mmmpartner service update success!"
  34 + else
  35 + echo "mmmpartner service update fail!"
  36 + fi
  37 + kubectl -n mmm-suplus-test get pods | grep -q mmmpartner
  38 + if [ "$?" == "0" ];then
  39 + echo "mmmpartner deployment update success!"
  40 + else
  41 + echo "mmmpartner deployment update fail!"
  42 + fi
  43 +fi
  1 +apiVersion: v1
  2 +kind: Service
  3 +metadata:
  4 + name: mmmpartner
  5 + namespace: mmm-suplus-test
  6 + labels:
  7 + k8s-app: mmmpartner
  8 +spec:
  9 + ports:
  10 + - name: "http"
  11 + port: 80
  12 + targetPort: 8082
  13 + selector:
  14 + k8s-app: mmmpartner
  15 +---
  16 +apiVersion: extensions/v1beta1
  17 +kind: Deployment
  18 +metadata:
  19 + name: mmmpartner
  20 + namespace: mmm-suplus-test
  21 + labels:
  22 + k8s-app: mmmpartner
  23 +spec:
  24 + replicas: 1
  25 + template:
  26 + metadata:
  27 + labels:
  28 + k8s-app: mmmpartner
  29 + spec:
  30 + affinity:
  31 + nodeAffinity:
  32 + preferredDuringSchedulingIgnoredDuringExecution:
  33 + - preference: {}
  34 + weight: 100
  35 + requiredDuringSchedulingIgnoredDuringExecution:
  36 + nodeSelectorTerms:
  37 + - matchExpressions:
  38 + - key: kubernetes.io/hostname
  39 + operator: In
  40 + values:
  41 + - cn-hangzhou.i-bp1djh1xn7taumbue1ze
  42 + - cn-hangzhou.i-bp1djh1xn7taumbue1zd
  43 + - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
  44 + - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
  45 + containers:
  46 + - name: mmmpartner
  47 + image: 192.168.0.243:5000/mmm/partner:dev
  48 + imagePullPolicy: Always
  49 + ports:
  50 + - containerPort: 8082
  51 + volumeMounts:
  52 + - mountPath: /opt/logs
  53 + name: accesslogs
  54 + env:
  55 + - name: HTTP_PORT
  56 + value: "8082"
  57 + - name: POSTGRESQL_DB_NAME
  58 + value: "partner_test"
  59 + - name: POSTGRESQL_USER
  60 + value: "postgres"
  61 + - name: POSTGRESQL_PASSWORD
  62 + value: "eagle1010"
  63 + - name: POSTGRESQL_HOST
  64 + value: "114.55.200.59"
  65 + - name: POSTGRESQL_PORT
  66 + value: "31543"
  67 + - name: LOG_LEVEL
  68 + value: "debug"
  69 + - name: ERROR_BASE_CODE
  70 + value: "1"
  71 + - name: ERROR_BASE_CODE_MULTIPLE
  72 + value: "1000"
  73 + - name: DEFAULT_GUEST_COMPANY
  74 + value: "358"
  75 + - name: ABILITY_SERVICE_HOST
  76 + value: "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
  77 + - name: MMM_OPEN_API_SERVICE_HOST
  78 + value: "http://mmm-open-api-dev.fjmaimaimai.com"
  79 + - name: UCENTER_SERVICE_HOST
  80 + value: "https://suplus-ucenter-test.fjmaimaimai.com"
  81 + - name: BUSINESS_ADMIN_SERVICE_HOST
  82 + valueFrom:
  83 + configMapKeyRef:
  84 + name: suplus-config
  85 + key: service.businessadmin
  86 + - name: REDIS_HOST
  87 + valueFrom:
  88 + configMapKeyRef:
  89 + name: suplus-config
  90 + key: redis.ip
  91 + - name: REDIS_PORT
  92 + valueFrom:
  93 + configMapKeyRef:
  94 + name: suplus-config
  95 + key: redis.port
  96 + - name: REDIS_AUTH
  97 + value: ""
  98 + volumes:
  99 + - name: accesslogs
  100 + emptyDir: {}
@@ -7,9 +7,9 @@ require ( @@ -7,9 +7,9 @@ require (
7 github.com/astaxie/beego v1.12.2 7 github.com/astaxie/beego v1.12.2
8 github.com/dgrijalva/jwt-go v3.2.0+incompatible 8 github.com/dgrijalva/jwt-go v3.2.0+incompatible
9 github.com/go-pg/pg/v10 v10.0.0-beta.2 9 github.com/go-pg/pg/v10 v10.0.0-beta.2
10 - github.com/tiptok/gocomm v1.0.2  
11 - github.com/tal-tech/go-zero v1.0.11 10 + github.com/tiptok/gocomm v1.0.3
  11 + //github.com/tal-tech/go-zero v1.0.11
12 github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 12 github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9
13 ) 13 )
14 14
15 -replace github.com/tiptok/gocomm v1.0.2 => F:\go\src\learn_project\gocomm 15 +//replace github.com/tiptok/gocomm v1.0.2 => F:\go\src\learn_project\gocomm
@@ -49,11 +49,43 @@ func (svr *CacheService) CacheUserAccess(userId int64) func() (interface{}, erro @@ -49,11 +49,43 @@ func (svr *CacheService) CacheUserAccess(userId int64) func() (interface{}, erro
49 return accesses, nil 49 return accesses, nil
50 } 50 }
51 } 51 }
  52 +func (svr *CacheService) ValidUser(userId int64) (isAdmin bool, err error) {
  53 + var (
  54 + transactionContext, _ = factory.CreateTransactionContext(nil)
  55 + UserRepository, _ = factory.CreateUserRepository(transactionContext)
  56 + )
  57 + if err = transactionContext.StartTransaction(); err != nil {
  58 + log.Error(err)
  59 + return isAdmin, err
  60 + }
  61 + defer func() {
  62 + transactionContext.RollbackTransaction()
  63 + }()
  64 +
  65 + var user *domain.Users
  66 + if user, err = UserRepository.FindOne(map[string]interface{}{"id": userId}); err != nil {
  67 + return isAdmin, err
  68 + }
  69 + if user.AdminType == domain.UserAdmin {
  70 + isAdmin = true
  71 + }
  72 + err = transactionContext.CommitTransaction()
  73 + return isAdmin, nil
  74 +}
52 func (svr *CacheService) ValidUserAccess(userId int64, object string, method string) (result bool, err error) { 75 func (svr *CacheService) ValidUserAccess(userId int64, object string, method string) (result bool, err error) {
53 var userAccess []*domain.Access 76 var userAccess []*domain.Access
  77 + var isAdmin bool
54 defer func() { 78 defer func() {
55 log.Info(fmt.Sprintf("ValidUserAccess user:%v object:%v method:%v result:%v", userId, object, method, result)) 79 log.Info(fmt.Sprintf("ValidUserAccess user:%v object:%v method:%v result:%v", userId, object, method, result))
56 }() 80 }()
  81 + if isAdmin, err = svr.ValidUser(userId); err != nil {
  82 + return
  83 + }
  84 + //管理员有所有权限
  85 + if isAdmin {
  86 + result = true
  87 + return
  88 + }
57 cache.GetObject(UserRoleAccessCacheKey(userId), &userAccess, 3600, svr.CacheUserAccess(userId)) 89 cache.GetObject(UserRoleAccessCacheKey(userId), &userAccess, 3600, svr.CacheUserAccess(userId))
58 for i := range userAccess { 90 for i := range userAccess {
59 if KeyMatch3(object, userAccess[i].Object) && ActionEqual(userAccess[i].Action, method) { 91 if KeyMatch3(object, userAccess[i].Object) && ActionEqual(userAccess[i].Action, method) {
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "github.com/tiptok/gocomm/pkg/log" 5 "github.com/tiptok/gocomm/pkg/log"
6 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory" 6 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
7 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils"
8 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" 9 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
9 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module" 10 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module"
10 "time" 11 "time"
@@ -82,7 +83,12 @@ func (svr *ProjectModuleService) UpdateProjectModule(header *protocol.RequestHea @@ -82,7 +83,12 @@ func (svr *ProjectModuleService) UpdateProjectModule(header *protocol.RequestHea
82 83
83 var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext) 84 var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext)
84 var projectModule *domain.ProjectModule 85 var projectModule *domain.ProjectModule
85 - if projectModule, err = ProjectModuleRepository.FindOne(common.ObjectToMap(request)); err != nil { 86 + if projectModule, err = ProjectModuleRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
  87 + err = protocol.NewCustomMessage(1, "模板项目不存在")
  88 + return
  89 + }
  90 + if _, err = ProjectModuleRepository.FindOne(map[string]interface{}{"projectKey": request.ProjectKey}); err == nil {
  91 + err = protocol.NewCustomMessage(1, "项目键值已存在:"+request.ProjectKey)
86 return 92 return
87 } 93 }
88 if err = projectModule.Update(common.ObjectToMap(request)); err != nil { 94 if err = projectModule.Update(common.ObjectToMap(request)); err != nil {
@@ -118,7 +124,7 @@ func (svr *ProjectModuleService) GetProjectModule(header *protocol.RequestHeader @@ -118,7 +124,7 @@ func (svr *ProjectModuleService) GetProjectModule(header *protocol.RequestHeader
118 err = protocol.NewCustomMessage(1, "模板项目不存在") 124 err = protocol.NewCustomMessage(1, "模板项目不存在")
119 return 125 return
120 } 126 }
121 - rsp = projectModule 127 + rsp = utils.LoadCustomField(projectModule, "Id", "ProjectName", "ProjectKey", "Description", "Status", "CreateTime", "UpdateTime")
122 err = transactionContext.CommitTransaction() 128 err = transactionContext.CommitTransaction()
123 return 129 return
124 } 130 }
@@ -130,6 +136,7 @@ func (svr *ProjectModuleService) DeleteProjectModule(header *protocol.RequestHea @@ -130,6 +136,7 @@ func (svr *ProjectModuleService) DeleteProjectModule(header *protocol.RequestHea
130 rsp = &protocolx.DeleteProjectModuleResponse{} 136 rsp = &protocolx.DeleteProjectModuleResponse{}
131 if err = request.ValidateCommand(); err != nil { 137 if err = request.ValidateCommand(); err != nil {
132 err = protocol.NewCustomMessage(2, err.Error()) 138 err = protocol.NewCustomMessage(2, err.Error())
  139 + return
133 } 140 }
134 if err = transactionContext.StartTransaction(); err != nil { 141 if err = transactionContext.StartTransaction(); err != nil {
135 log.Error(err) 142 log.Error(err)
@@ -141,10 +148,13 @@ func (svr *ProjectModuleService) DeleteProjectModule(header *protocol.RequestHea @@ -141,10 +148,13 @@ func (svr *ProjectModuleService) DeleteProjectModule(header *protocol.RequestHea
141 148
142 var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext) 149 var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext)
143 var projectModule *domain.ProjectModule 150 var projectModule *domain.ProjectModule
144 - if projectModule, err = ProjectModuleRepository.FindOne(common.ObjectToMap(request)); err != nil { 151 + if projectModule, err = ProjectModuleRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
145 return 152 return
146 } 153 }
147 - if projectModule, err = ProjectModuleRepository.Remove(projectModule); err != nil { 154 + if err = projectModule.Update(map[string]interface{}{"status": 2}); err != nil {
  155 + return
  156 + }
  157 + if projectModule, err = ProjectModuleRepository.Save(projectModule); err != nil {
148 return 158 return
149 } 159 }
150 rsp = projectModule 160 rsp = projectModule
@@ -156,7 +166,7 @@ func (svr *ProjectModuleService) ListProjectModule(header *protocol.RequestHeade @@ -156,7 +166,7 @@ func (svr *ProjectModuleService) ListProjectModule(header *protocol.RequestHeade
156 var ( 166 var (
157 transactionContext, _ = factory.CreateTransactionContext(nil) 167 transactionContext, _ = factory.CreateTransactionContext(nil)
158 ) 168 )
159 - rsp = &protocolx.ListProjectModuleResponse{} 169 + //listProjectModuleResponse := &protocolx.ListProjectModuleResponse{}
160 if err = request.ValidateCommand(); err != nil { 170 if err = request.ValidateCommand(); err != nil {
161 err = protocol.NewCustomMessage(2, err.Error()) 171 err = protocol.NewCustomMessage(2, err.Error())
162 } 172 }
@@ -171,12 +181,13 @@ func (svr *ProjectModuleService) ListProjectModule(header *protocol.RequestHeade @@ -171,12 +181,13 @@ func (svr *ProjectModuleService) ListProjectModule(header *protocol.RequestHeade
171 var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext) 181 var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext)
172 var projectModule []*domain.ProjectModule 182 var projectModule []*domain.ProjectModule
173 var total int64 183 var total int64
174 - if total, projectModule, err = ProjectModuleRepository.Find(common.ObjectToMap(request)); err != nil { 184 + if total, projectModule, err = ProjectModuleRepository.Find(map[string]interface{}{"offset": (request.PageNumber - 1) * request.PageSize, "limit": request.PageSize, "sortByCreateTime": "DESC", "status": domain.StatusNormal}); err != nil {
175 return 185 return
176 } 186 }
177 rsp = map[string]interface{}{ 187 rsp = map[string]interface{}{
178 - "total": total,  
179 - "list": projectModule, 188 + "totalRow": total,
  189 + "pageNumber": request.PageNumber,
  190 + "list": utils.LoadCustomField(projectModule, "Id", "ProjectName", "ProjectKey", "Description", "Status", "CreateTime", "UpdateTime"), //listProjectModuleResponse.LoadDto(projectModule),
180 } 191 }
181 err = transactionContext.CommitTransaction() 192 err = transactionContext.CommitTransaction()
182 return 193 return
@@ -5,6 +5,8 @@ import ( @@ -5,6 +5,8 @@ import (
5 "github.com/tiptok/gocomm/pkg/log" 5 "github.com/tiptok/gocomm/pkg/log"
6 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory" 6 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
7 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/dao"
  9 + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils"
8 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" 10 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
9 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_files" 11 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_files"
10 "path/filepath" 12 "path/filepath"
@@ -37,7 +39,7 @@ func (svr *ProjectModuleFilesService) CreateProjectModuleFiles(header *protocol. @@ -37,7 +39,7 @@ func (svr *ProjectModuleFilesService) CreateProjectModuleFiles(header *protocol.
37 ParentId: request.ParentId, 39 ParentId: request.ParentId,
38 FileType: request.FileType, 40 FileType: request.FileType,
39 FileName: request.FileName, 41 FileName: request.FileName,
40 - FileKey: request.FileKey, 42 + FileKey: request.FileName,
41 CodeBlock: request.CodeBlock, 43 CodeBlock: request.CodeBlock,
42 Remark: request.Remark, 44 Remark: request.Remark,
43 CreateTime: time.Now(), 45 CreateTime: time.Now(),
@@ -49,6 +51,7 @@ func (svr *ProjectModuleFilesService) CreateProjectModuleFiles(header *protocol. @@ -49,6 +51,7 @@ func (svr *ProjectModuleFilesService) CreateProjectModuleFiles(header *protocol.
49 err = protocol.NewCustomMessage(1, "项目版本不存在") 51 err = protocol.NewCustomMessage(1, "项目版本不存在")
50 return 52 return
51 } 53 }
  54 + // TODO:判断是否重名
52 var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext) 55 var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
53 if rsp, err = svr.save(newProjectModuleFiles, ProjectModuleFilesRepository); err != nil { 56 if rsp, err = svr.save(newProjectModuleFiles, ProjectModuleFilesRepository); err != nil {
54 return 57 return
@@ -60,10 +63,12 @@ func (svr *ProjectModuleFilesService) CreateProjectModuleFiles(header *protocol. @@ -60,10 +63,12 @@ func (svr *ProjectModuleFilesService) CreateProjectModuleFiles(header *protocol.
60 func (svr *ProjectModuleFilesService) UpdateProjectModuleFiles(header *protocol.RequestHeader, request *protocolx.UpdateProjectModuleFilesRequest) (rsp interface{}, err error) { 63 func (svr *ProjectModuleFilesService) UpdateProjectModuleFiles(header *protocol.RequestHeader, request *protocolx.UpdateProjectModuleFilesRequest) (rsp interface{}, err error) {
61 var ( 64 var (
62 transactionContext, _ = factory.CreateTransactionContext(nil) 65 transactionContext, _ = factory.CreateTransactionContext(nil)
  66 + ProjectModuleFilesDao, _ = dao.NewProjectModuleFilesDao(transactionContext)
63 ) 67 )
64 rsp = &protocolx.UpdateProjectModuleFilesResponse{} 68 rsp = &protocolx.UpdateProjectModuleFilesResponse{}
65 if err = request.ValidateCommand(); err != nil { 69 if err = request.ValidateCommand(); err != nil {
66 err = protocol.NewCustomMessage(2, err.Error()) 70 err = protocol.NewCustomMessage(2, err.Error())
  71 + return
67 } 72 }
68 if err = transactionContext.StartTransaction(); err != nil { 73 if err = transactionContext.StartTransaction(); err != nil {
69 log.Error(err) 74 log.Error(err)
@@ -75,15 +80,36 @@ func (svr *ProjectModuleFilesService) UpdateProjectModuleFiles(header *protocol. @@ -75,15 +80,36 @@ func (svr *ProjectModuleFilesService) UpdateProjectModuleFiles(header *protocol.
75 80
76 var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext) 81 var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
77 var projectModuleFiles *domain.ProjectModuleFiles 82 var projectModuleFiles *domain.ProjectModuleFiles
78 - if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(common.ObjectToMap(request)); err != nil { 83 + var oldFileName string
  84 + if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
79 return 85 return
80 } 86 }
  87 + oldFileName = projectModuleFiles.FileName
81 if err = projectModuleFiles.Update(common.ObjectToMap(request)); err != nil { 88 if err = projectModuleFiles.Update(common.ObjectToMap(request)); err != nil {
82 return 89 return
83 } 90 }
84 if projectModuleFiles, err = ProjectModuleFilesRepository.Save(projectModuleFiles); err != nil { 91 if projectModuleFiles, err = ProjectModuleFilesRepository.Save(projectModuleFiles); err != nil {
85 return 92 return
86 } 93 }
  94 +
  95 + // 更新文件名称,修改子节点跟本身的路径 1.文件夹 2.文件
  96 + if request.FileName != oldFileName {
  97 + // TODO:判断是否重名
  98 + var oldPath = projectModuleFiles.Path
  99 + var newPath string
  100 + if index := strings.LastIndex(projectModuleFiles.Path, oldFileName); index > 0 {
  101 + newPath = projectModuleFiles.Path[:index] + request.FileName
  102 + projectModuleFiles.Path = newPath
  103 + }
  104 + if projectModuleFiles.FileType == domain.Dir {
  105 + if err = ProjectModuleFilesDao.UpdateFilesPath(projectModuleFiles.ProjectModuleId, projectModuleFiles.ProjectModuleVersionId, oldPath, newPath); err != nil {
  106 + return
  107 + }
  108 + }
  109 + }
  110 + // TODO:移动文件文件夹时pid变更,底下路径需要都变掉
  111 +
  112 + // TODO:变更记录
87 err = transactionContext.CommitTransaction() 113 err = transactionContext.CommitTransaction()
88 return 114 return
89 } 115 }
@@ -132,9 +158,16 @@ func (svr *ProjectModuleFilesService) DeleteProjectModuleFiles(header *protocol. @@ -132,9 +158,16 @@ func (svr *ProjectModuleFilesService) DeleteProjectModuleFiles(header *protocol.
132 158
133 var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext) 159 var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
134 var projectModuleFiles *domain.ProjectModuleFiles 160 var projectModuleFiles *domain.ProjectModuleFiles
135 - if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(common.ObjectToMap(request)); err != nil { 161 + if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
  162 + err = protocol.NewCustomMessage(1, "文件不存在")
  163 + return
  164 + }
  165 + if projectModuleFiles.FileType == domain.Dir {
  166 + if count, _, e := ProjectModuleFilesRepository.Find(map[string]interface{}{"parentId": request.Id}); e == nil && count > 0 {
  167 + err = protocol.NewCustomMessage(1, "文件夹不为空")
136 return 168 return
137 } 169 }
  170 + }
138 if projectModuleFiles, err = ProjectModuleFilesRepository.Remove(projectModuleFiles); err != nil { 171 if projectModuleFiles, err = ProjectModuleFilesRepository.Remove(projectModuleFiles); err != nil {
139 return 172 return
140 } 173 }
@@ -168,7 +201,13 @@ func (svr *ProjectModuleFilesService) ListProjectModuleFiles(header *protocol.Re @@ -168,7 +201,13 @@ func (svr *ProjectModuleFilesService) ListProjectModuleFiles(header *protocol.Re
168 } 201 }
169 rsp = map[string]interface{}{ 202 rsp = map[string]interface{}{
170 "total": total, 203 "total": total,
171 - "list": projectModuleFiles, 204 + "list": utils.LoadCustomField(projectModuleFiles, "Id", "FileType", "FileName", "ParentId", "Path", "CodeBlock"),
  205 + }
  206 + if request.StructType == "tree" {
  207 + rsp = map[string]interface{}{
  208 + "total": total,
  209 + "list": svr.traverseModuleFiles(projectModuleFiles),
  210 + }
172 } 211 }
173 err = transactionContext.CommitTransaction() 212 err = transactionContext.CommitTransaction()
174 return 213 return
@@ -298,6 +337,30 @@ func (svr *ProjectModuleFilesService) mkdirF(fileDir string, mid, vid, pid int64 @@ -298,6 +337,30 @@ func (svr *ProjectModuleFilesService) mkdirF(fileDir string, mid, vid, pid int64
298 return 337 return
299 } 338 }
300 339
  340 +func (svr *ProjectModuleFilesService) traverseModuleFiles(files []*domain.ProjectModuleFiles) interface{} {
  341 +
  342 + retSlice := make([]*protocolx.ModuleFiles, 0)
  343 +
  344 + for i := range files {
  345 + if files[i].ParentId == 0 {
  346 + retSlice = append(retSlice, &protocolx.ModuleFiles{ModuleFile: protocolx.NewModuleFile(files[i]), List: make([]*protocolx.ModuleFiles, 0)})
  347 + continue
  348 + }
  349 + traverse(retSlice, files[i])
  350 + }
  351 + return retSlice
  352 +}
  353 +
  354 +func traverse(list []*protocolx.ModuleFiles, file *domain.ProjectModuleFiles) {
  355 + for i := range list {
  356 + if list[i].Id == file.ParentId {
  357 + list[i].List = append(list[i].List, &protocolx.ModuleFiles{ModuleFile: protocolx.NewModuleFile(file), List: make([]*protocolx.ModuleFiles, 0)})
  358 + return
  359 + }
  360 + traverse(list[i].List, file)
  361 + }
  362 + return
  363 +}
301 func NewProjectModuleFilesService(options map[string]interface{}) *ProjectModuleFilesService { 364 func NewProjectModuleFilesService(options map[string]interface{}) *ProjectModuleFilesService {
302 svr := &ProjectModuleFilesService{} 365 svr := &ProjectModuleFilesService{}
303 return svr 366 return svr
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
8 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" 8 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
9 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/dao" 9 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/dao"
  10 + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils"
10 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" 11 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
11 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_version" 12 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_version"
12 "strings" 13 "strings"
@@ -194,8 +195,8 @@ func (svr *ProjectModuleVersionService) ListProjectModuleVersion(header *protoco @@ -194,8 +195,8 @@ func (svr *ProjectModuleVersionService) ListProjectModuleVersion(header *protoco
194 return 195 return
195 } 196 }
196 rsp = map[string]interface{}{ 197 rsp = map[string]interface{}{
197 - "total": total,  
198 - "list": projectModuleVersion, 198 + "totalRow": total,
  199 + "list": utils.LoadCustomField(projectModuleVersion, "Id", "ProjectModuleId", "Description", "Version", "Status"),
199 } 200 }
200 err = transactionContext.CommitTransaction() 201 err = transactionContext.CommitTransaction()
201 return 202 return
@@ -117,7 +117,7 @@ func (svr *RoleService) GetRole(header *protocol.RequestHeader, request *protoco @@ -117,7 +117,7 @@ func (svr *RoleService) GetRole(header *protocol.RequestHeader, request *protoco
117 if role, err = RoleRepository.FindOne(common.ObjectToMap(request)); err != nil { 117 if role, err = RoleRepository.FindOne(common.ObjectToMap(request)); err != nil {
118 return 118 return
119 } 119 }
120 - rsp = map[string]interface{}{"role": utils.LoadCustomField(role, "Id", "RoleName", "ParentId"), "permission": ""} 120 + rsp = map[string]interface{}{"role": utils.LoadCustomField(role, "Id", "RoleName", "ParentId")}
121 err = transactionContext.CommitTransaction() 121 err = transactionContext.CommitTransaction()
122 return 122 return
123 } 123 }
@@ -11,6 +11,8 @@ import ( @@ -11,6 +11,8 @@ import (
11 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils" 11 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils"
12 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" 12 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
13 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/user" 13 protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/user"
  14 + "strings"
  15 + "time"
14 ) 16 )
15 17
16 type UserService struct { 18 type UserService struct {
@@ -38,6 +40,8 @@ func (svr *UserService) CreateUser(header *protocol.RequestHeader, request *prot @@ -38,6 +40,8 @@ func (svr *UserService) CreateUser(header *protocol.RequestHeader, request *prot
38 Roles: request.Roles, 40 Roles: request.Roles,
39 Status: 1, 41 Status: 1,
40 AdminType: request.AdminType, 42 AdminType: request.AdminType,
  43 + CreateTime: time.Now(),
  44 + UpdateTime: time.Now(),
41 } 45 }
42 46
43 var UserRepository, _ = factory.CreateUserRepository(transactionContext) 47 var UserRepository, _ = factory.CreateUserRepository(transactionContext)
@@ -183,6 +187,7 @@ func (svr *UserService) DeleteUser(header *protocol.RequestHeader, request *prot @@ -183,6 +187,7 @@ func (svr *UserService) DeleteUser(header *protocol.RequestHeader, request *prot
183 func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protocolx.ListUserRequest) (rsp interface{}, err error) { 187 func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protocolx.ListUserRequest) (rsp interface{}, err error) {
184 var ( 188 var (
185 transactionContext, _ = factory.CreateTransactionContext(nil) 189 transactionContext, _ = factory.CreateTransactionContext(nil)
  190 + RoleRepository, _ = factory.CreateRoleRepository(transactionContext)
186 ) 191 )
187 rsp = &protocolx.ListUserResponse{} 192 rsp = &protocolx.ListUserResponse{}
188 if err = request.ValidateCommand(); err != nil { 193 if err = request.ValidateCommand(); err != nil {
@@ -197,17 +202,39 @@ func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protoc @@ -197,17 +202,39 @@ func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protoc
197 transactionContext.RollbackTransaction() 202 transactionContext.RollbackTransaction()
198 }() 203 }()
199 204
  205 + _, roles, _ := RoleRepository.Find(map[string]interface{}{})
  206 + roleMap := domain.Roles(roles).RoleMap()
  207 + getRoles := func(roleIds []int64) string {
  208 + if len(roleIds) == 0 {
  209 + return ""
  210 + }
  211 + var role []string
  212 + for _, id := range roleIds {
  213 + if v, ok := roleMap[id]; ok {
  214 + role = append(role, v.RoleName)
  215 + }
  216 + }
  217 + return strings.Join(role, ",")
  218 + }
  219 +
200 var UserRepository, _ = factory.CreateUserRepository(transactionContext) 220 var UserRepository, _ = factory.CreateUserRepository(transactionContext)
201 var user []*domain.Users 221 var user []*domain.Users
202 var total int64 222 var total int64
203 - if total, user, err = UserRepository.Find(map[string]interface{}{"offset": request.PageNumber * request.PageSize, "limit": request.PageSize, "sortById": "DESC"}); err != nil { 223 + if total, user, err = UserRepository.Find(map[string]interface{}{"offset": (request.PageNumber - 1) * request.PageSize, "limit": request.PageSize, "searchByText": request.SearchByText, "sortById": "DESC"}); err != nil {
204 err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 224 err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
205 return 225 return
206 } 226 }
  227 + userList := make([]map[string]interface{}, 0)
  228 + for _, v := range user {
  229 + item := map[string]interface{}{"id": v.Id, "name": v.Name, "adminType": v.AdminType, "status": v.Status, "createTime": v.CreateTime.Local().Format("2006-01-02 15:04:05")}
  230 + item["roles"] = getRoles(v.Roles)
  231 + userList = append(userList, item)
  232 + }
  233 +
207 rsp = map[string]interface{}{ 234 rsp = map[string]interface{}{
208 "totalRow": total, 235 "totalRow": total,
209 "pageNumber": request.PageNumber, 236 "pageNumber": request.PageNumber,
210 - "list": utils.LoadCustomField(user, "Id", "Name", "Phone", "IsAdmin", "Status"), 237 + "list": userList,
211 } 238 }
212 if err = transactionContext.CommitTransaction(); err != nil { 239 if err = transactionContext.CommitTransaction(); err != nil {
213 err = application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 240 err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -2,11 +2,11 @@ package constant @@ -2,11 +2,11 @@ package constant
2 2
3 import "os" 3 import "os"
4 4
5 -var POSTGRESQL_DB_NAME = "godevp" 5 +var POSTGRESQL_DB_NAME = "godevp_dev"
6 var POSTGRESQL_USER = "postgres" 6 var POSTGRESQL_USER = "postgres"
7 -var POSTGRESQL_PASSWORD = "123456"  
8 -var POSTGRESQL_HOST = "127.0.0.1"  
9 -var POSTGRESQL_PORT = "5432" 7 +var POSTGRESQL_PASSWORD = "eagle1010"
  8 +var POSTGRESQL_HOST = "114.55.200.59"
  9 +var POSTGRESQL_PORT = "31543"
10 var DISABLE_CREATE_TABLE = true 10 var DISABLE_CREATE_TABLE = true
11 var DISABLE_SQL_GENERATE_PRINT = false 11 var DISABLE_SQL_GENERATE_PRINT = false
12 12
@@ -2,6 +2,11 @@ package domain @@ -2,6 +2,11 @@ package domain
2 2
3 import "time" 3 import "time"
4 4
  5 +const (
  6 + StatusNormal = iota + 1
  7 + StatusDelete
  8 +)
  9 +
5 // ProjectModule 10 // ProjectModule
6 type ProjectModule struct { 11 type ProjectModule struct {
7 // 唯一标识 12 // 唯一标识
@@ -12,7 +17,7 @@ type ProjectModule struct { @@ -12,7 +17,7 @@ type ProjectModule struct {
12 ProjectKey string `json:"projectKey"` 17 ProjectKey string `json:"projectKey"`
13 // 项目描述信息 18 // 项目描述信息
14 Description string `json:"description"` 19 Description string `json:"description"`
15 - // 状态 0:正常 1:删除 20 + // 状态 1:正常 2:删除
16 Status int `json:"status"` 21 Status int `json:"status"`
17 // 创建时间 22 // 创建时间
18 CreateTime time.Time `json:"createTime"` 23 CreateTime time.Time `json:"createTime"`
@@ -36,5 +41,18 @@ func (m *ProjectModule) Identify() interface{} { @@ -36,5 +41,18 @@ func (m *ProjectModule) Identify() interface{} {
36 } 41 }
37 42
38 func (m *ProjectModule) Update(data map[string]interface{}) error { 43 func (m *ProjectModule) Update(data map[string]interface{}) error {
  44 + if projectName, ok := data["projectName"]; ok {
  45 + m.ProjectName = projectName.(string)
  46 + }
  47 + if projectKey, ok := data["projectKey"]; ok {
  48 + m.ProjectKey = projectKey.(string)
  49 + }
  50 + if description, ok := data["description"]; ok {
  51 + m.Description = description.(string)
  52 + }
  53 + if status, ok := data["status"]; ok {
  54 + m.Status = status.(int)
  55 + }
  56 + m.UpdateTime = time.Now()
39 return nil 57 return nil
40 } 58 }
@@ -26,13 +26,13 @@ type ProjectModuleFiles struct { @@ -26,13 +26,13 @@ type ProjectModuleFiles struct {
26 // 父级编号 26 // 父级编号
27 ParentId int64 `json:"parentId"` 27 ParentId int64 `json:"parentId"`
28 // 排序 28 // 排序
29 - Sort int `json:"sort"` 29 + Sort int `json:"-"`
30 // 备注信息 30 // 备注信息
31 Remark string `json:"remark"` 31 Remark string `json:"remark"`
32 // 创建时间 32 // 创建时间
33 - CreateTime time.Time `json:"createTime"` 33 + CreateTime time.Time `json:"-"`
34 // 更新时间 34 // 更新时间
35 - UpdateTime time.Time `json:"updateTime"` 35 + UpdateTime time.Time `json:"-"`
36 // 当前文件相对路径 a/b/c 36 // 当前文件相对路径 a/b/c
37 Path string `json:"path"` 37 Path string `json:"path"`
38 } 38 }
@@ -52,5 +52,21 @@ func (m *ProjectModuleFiles) Identify() interface{} { @@ -52,5 +52,21 @@ func (m *ProjectModuleFiles) Identify() interface{} {
52 } 52 }
53 53
54 func (m *ProjectModuleFiles) Update(data map[string]interface{}) error { 54 func (m *ProjectModuleFiles) Update(data map[string]interface{}) error {
  55 + if fileName, ok := data["fileName"]; ok {
  56 + m.FileName = fileName.(string)
  57 + }
  58 + if codeBlock, ok := data["codeBlock"]; ok {
  59 + m.CodeBlock = codeBlock.(string)
  60 + }
  61 + //if parentId, ok := data["parentId"]; ok {
  62 + // m.ParentId = parentId.(int64)
  63 + //}
  64 + if remark, ok := data["remark"]; ok {
  65 + m.Remark = remark.(string)
  66 + }
  67 + if path, ok := data["path"]; ok {
  68 + m.Path = path.(string)
  69 + }
  70 + m.UpdateTime = time.Now()
55 return nil 71 return nil
56 } 72 }
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "time"
  5 +)
4 6
5 // Role 7 // Role
6 type Role struct { 8 type Role struct {
@@ -39,3 +41,23 @@ func (m *Role) Update(data map[string]interface{}) error { @@ -39,3 +41,23 @@ func (m *Role) Update(data map[string]interface{}) error {
39 } 41 }
40 return nil 42 return nil
41 } 43 }
  44 +
  45 +type Roles []*Role
  46 +
  47 +func (roles Roles) RoleMap() map[int64]*Role {
  48 + var retMap = make(map[int64]*Role)
  49 + for _, v := range roles {
  50 + retMap[v.Id] = v
  51 + }
  52 + return retMap
  53 +}
  54 +
  55 +//func(roles Roles)RolesWithMap(roleMap map[int64]*Role,roleIds []int64)string{
  56 +// var role []string
  57 +// for _,id :=range roleIds{
  58 +// if v,ok:=roleMap[id];ok{
  59 +// role = append(role,v.RoleName)
  60 +// }
  61 +// }
  62 +// return strings.Join(role,",")
  63 +//}
1 package domain 1 package domain
2 2
  3 +import "time"
  4 +
  5 +const (
  6 + UserAdmin = iota + 1
  7 + UserNormal
  8 +)
  9 +
3 // Users 10 // Users
4 type Users struct { 11 type Users struct {
5 // 唯一标识 12 // 唯一标识
@@ -16,8 +23,12 @@ type Users struct { @@ -16,8 +23,12 @@ type Users struct {
16 Roles []int64 `json:"roles"` 23 Roles []int64 `json:"roles"`
17 // 1启用 2禁用 24 // 1启用 2禁用
18 Status int `json:"status"` 25 Status int `json:"status"`
19 - // 管理员类型 26 + // 管理员类型 1:管理员 2:普通员工
20 AdminType int `json:"adminType"` 27 AdminType int `json:"adminType"`
  28 + // 创建时间
  29 + CreateTime time.Time `json:"createTime"`
  30 + // 更新时间
  31 + UpdateTime time.Time `json:"updateTime"`
21 } 32 }
22 33
23 type UsersRepository interface { 34 type UsersRepository interface {
@@ -53,5 +64,6 @@ func (m *Users) Update(data map[string]interface{}) error { @@ -53,5 +64,6 @@ func (m *Users) Update(data map[string]interface{}) error {
53 if status, ok := data["status"]; ok { 64 if status, ok := data["status"]; ok {
54 m.Status = status.(int) 65 m.Status = status.(int)
55 } 66 }
  67 + m.UpdateTime = time.Now()
56 return nil 68 return nil
57 } 69 }
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
  6 + "strings"
  7 +)
  8 +
  9 +type ProjectModuleFilesDao struct {
  10 + transactionContext *transaction.TransactionContext
  11 +}
  12 +
  13 +func (dao *ProjectModuleFilesDao) UpdateFilesPath(srcProjectId, srcVersionId int64, oldPath, newPath string) error {
  14 + tx := dao.transactionContext.PgTx
  15 + _, err := tx.Exec(fmt.Sprintf(`update project_module_files set "path"= replace("path",?,?) where project_module_id=? and project_module_version_id=? and "path" like '%%%v%%'`, strings.Replace(oldPath, "\\", "\\\\", -1)),
  16 + oldPath, newPath, srcProjectId, srcVersionId)
  17 + return err
  18 +}
  19 +
  20 +func NewProjectModuleFilesDao(transactionContext *transaction.TransactionContext) (*ProjectModuleFilesDao, error) {
  21 + if transactionContext == nil {
  22 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  23 + } else {
  24 + return &ProjectModuleFilesDao{
  25 + transactionContext: transactionContext,
  26 + }, nil
  27 + }
  28 +}
@@ -13,7 +13,7 @@ type ProjectModule struct { @@ -13,7 +13,7 @@ type ProjectModule struct {
13 ProjectKey string 13 ProjectKey string
14 // 项目描述信息 14 // 项目描述信息
15 Description string 15 Description string
16 - // 状态 0:正常 1:删除 16 + // 状态 1:正常 2:删除
17 Status int 17 Status int
18 // 创建时间 18 // 创建时间
19 CreateTime time.Time 19 CreateTime time.Time
@@ -20,9 +20,9 @@ type ProjectModuleFiles struct { @@ -20,9 +20,9 @@ type ProjectModuleFiles struct {
20 // 代码块 20 // 代码块
21 CodeBlock string 21 CodeBlock string
22 // 父级编号 22 // 父级编号
23 - ParentId int64 23 + ParentId int64 `pg:",use_zero"`
24 // 排序 24 // 排序
25 - Sort int 25 + Sort int `pg:",use_zero"`
26 // 备注信息 26 // 备注信息
27 Remark string 27 Remark string
28 // 创建时间 28 // 创建时间
1 package models 1 package models
2 2
  3 +import "time"
  4 +
3 // Users 5 // Users
4 type Users struct { 6 type Users struct {
5 tableName struct{} `pg:"users"` 7 tableName struct{} `pg:"users"`
@@ -17,4 +19,8 @@ type Users struct { @@ -17,4 +19,8 @@ type Users struct {
17 Status int 19 Status int
18 // 管理员类型 1:超级管理员 2:普通账号 20 // 管理员类型 1:超级管理员 2:普通账号
19 AdminType int 21 AdminType int
  22 + // 创建时间
  23 + CreateTime time.Time
  24 + // 更新时间
  25 + UpdateTime time.Time
20 } 26 }
@@ -73,7 +73,11 @@ func (repository *ProjectModuleFilesRepository) Find(queryOptions map[string]int @@ -73,7 +73,11 @@ func (repository *ProjectModuleFilesRepository) Find(queryOptions map[string]int
73 SetWhere("project_module_id=?", "projectModuleId"). 73 SetWhere("project_module_id=?", "projectModuleId").
74 SetWhere("project_module_version_id=?", "projectModuleVersionId"). 74 SetWhere("project_module_version_id=?", "projectModuleVersionId").
75 SetOrder("create_time", "sortByCreateTime"). 75 SetOrder("create_time", "sortByCreateTime").
76 - SetOrder("update_time", "sortByUpdateTime") 76 + SetOrder("update_time", "sortByUpdateTime").
  77 + SetOrder("parent_id", "sortByParentId").
  78 + SetOrder("id", "sortById")
  79 +
  80 + query.SetWhere("parent_id = ?", "parentId")
77 var err error 81 var err error
78 if query.AffectRow, err = query.SelectAndCount(); err != nil { 82 if query.AffectRow, err = query.SelectAndCount(); err != nil {
79 return 0, ProjectModuleFiless, err 83 return 0, ProjectModuleFiless, err
@@ -30,7 +30,7 @@ func (repository *ProjectModuleRepository) Save(dm *domain.ProjectModule) (*doma @@ -30,7 +30,7 @@ func (repository *ProjectModuleRepository) Save(dm *domain.ProjectModule) (*doma
30 dm.Id = m.Id 30 dm.Id = m.Id
31 return dm, nil 31 return dm, nil
32 } 32 }
33 - if err = tx.Update(m); err != nil { 33 + if _, err = tx.Model(m).WherePK().Update(); err != nil {
34 return nil, err 34 return nil, err
35 } 35 }
36 return dm, nil 36 return dm, nil
@@ -69,12 +69,14 @@ func (repository *ProjectModuleRepository) Find(queryOptions map[string]interfac @@ -69,12 +69,14 @@ func (repository *ProjectModuleRepository) Find(queryOptions map[string]interfac
69 tx := repository.transactionContext.PgTx 69 tx := repository.transactionContext.PgTx
70 var ProjectModuleModels []*models.ProjectModule 70 var ProjectModuleModels []*models.ProjectModule
71 ProjectModules := make([]*domain.ProjectModule, 0) 71 ProjectModules := make([]*domain.ProjectModule, 0)
72 - query := NewQuery(tx.Model(&ProjectModuleModels).Relation("ProjectModuleVersion", func(q *orm.Query) (*orm.Query, error) {  
73 - q.Where("status=0")  
74 - return q, nil  
75 - }), queryOptions). 72 + query := NewQuery(tx.Model(&ProjectModuleModels), queryOptions).
  73 + //Relation("ProjectModuleVersion", func(q *orm.Query) (*orm.Query, error) {
  74 + // q.Where("status=0")
  75 + // return q, nil
  76 + //}), queryOptions).
  77 + SetWhere("status=?", "status").
76 SetOrder("create_time", "sortByCreateTime"). 78 SetOrder("create_time", "sortByCreateTime").
77 - SetOrder("update_time", "sortByUpdateTime") 79 + SetOrder("update_time", "sortByUpdateTime").SetLimit()
78 var err error 80 var err error
79 if query.AffectRow, err = query.SelectAndCount(); err != nil { 81 if query.AffectRow, err = query.SelectAndCount(); err != nil {
80 return 0, ProjectModules, err 82 return 0, ProjectModules, err
@@ -3,14 +3,22 @@ package repository @@ -3,14 +3,22 @@ package repository
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/tiptok/gocomm/common" 5 "github.com/tiptok/gocomm/common"
  6 + "github.com/tiptok/gocomm/pkg/cache"
6 . "github.com/tiptok/gocomm/pkg/orm/pgx" 7 . "github.com/tiptok/gocomm/pkg/orm/pgx"
7 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" 8 "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/models"
9 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction" 10 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
10 ) 11 )
11 12
  13 +var (
  14 + cacheUsersIdKey = func(id int64) string {
  15 + return fmt.Sprintf("%v:cache:Users:id:%v", "godevp", id)
  16 + }
  17 +)
  18 +
12 type UsersRepository struct { 19 type UsersRepository struct {
13 transactionContext *transaction.TransactionContext 20 transactionContext *transaction.TransactionContext
  21 + *cache.CachedRepository
14 } 22 }
15 23
16 func (repository *UsersRepository) Save(dm *domain.Users) (*domain.Users, error) { 24 func (repository *UsersRepository) Save(dm *domain.Users) (*domain.Users, error) {
@@ -29,7 +37,10 @@ func (repository *UsersRepository) Save(dm *domain.Users) (*domain.Users, error) @@ -29,7 +37,10 @@ func (repository *UsersRepository) Save(dm *domain.Users) (*domain.Users, error)
29 dm.Id = m.Id 37 dm.Id = m.Id
30 return dm, nil 38 return dm, nil
31 } 39 }
32 - if err = tx.Update(m); err != nil { 40 + queryFunc := func() (interface{}, error) {
  41 + return nil, tx.Update(m)
  42 + }
  43 + if _, err = repository.Query(queryFunc, cacheUsersIdKey(dm.Id)); err != nil {
33 return nil, err 44 return nil, err
34 } 45 }
35 return dm, nil 46 return dm, nil
@@ -40,21 +51,37 @@ func (repository *UsersRepository) Remove(User *domain.Users) (*domain.Users, er @@ -40,21 +51,37 @@ func (repository *UsersRepository) Remove(User *domain.Users) (*domain.Users, er
40 tx = repository.transactionContext.PgTx 51 tx = repository.transactionContext.PgTx
41 UserModel = &models.Users{Id: User.Identify().(int64)} 52 UserModel = &models.Users{Id: User.Identify().(int64)}
42 ) 53 )
43 - if _, err := tx.Model(UserModel).Where("id = ?", User.Id).Delete(); err != nil { 54 + queryFunc := func() (interface{}, error) {
  55 + return tx.Model(UserModel).Where("id = ?", User.Id).Delete()
  56 + }
  57 + if _, err := repository.Query(queryFunc, cacheUsersIdKey(User.Id)); err != nil {
44 return User, err 58 return User, err
45 } 59 }
46 return User, nil 60 return User, nil
47 } 61 }
48 62
49 func (repository *UsersRepository) FindOne(queryOptions map[string]interface{}) (*domain.Users, error) { 63 func (repository *UsersRepository) FindOne(queryOptions map[string]interface{}) (*domain.Users, error) {
50 - tx := repository.transactionContext.PgTx 64 + tx := repository.transactionContext.PgDd
51 UserModel := new(models.Users) 65 UserModel := new(models.Users)
  66 + queryFunc := func() (interface{}, error) {
52 query := NewQuery(tx.Model(UserModel), queryOptions) 67 query := NewQuery(tx.Model(UserModel), queryOptions)
53 query.SetWhere("id = ?", "id") 68 query.SetWhere("id = ?", "id")
54 query.SetWhere("phone = ?", "phone") 69 query.SetWhere("phone = ?", "phone")
55 if err := query.First(); err != nil { 70 if err := query.First(); err != nil {
56 return nil, fmt.Errorf("query row not found") 71 return nil, fmt.Errorf("query row not found")
57 } 72 }
  73 + return UserModel, nil
  74 + }
  75 + var options []cache.QueryOption
  76 + if _, ok := queryOptions["id"]; !ok {
  77 + options = append(options, cache.WithNoCacheFlag())
  78 + } else {
  79 + UserModel.Id = queryOptions["id"].(int64)
  80 + }
  81 + if err := repository.QueryCache(cacheUsersIdKey(UserModel.Id), UserModel, queryFunc, options...); err != nil {
  82 + return nil, err
  83 + }
  84 +
58 if UserModel.Id == 0 { 85 if UserModel.Id == 0 {
59 return nil, fmt.Errorf("query row not found") 86 return nil, fmt.Errorf("query row not found")
60 } 87 }
@@ -70,6 +97,11 @@ func (repository *UsersRepository) Find(queryOptions map[string]interface{}) (in @@ -70,6 +97,11 @@ func (repository *UsersRepository) Find(queryOptions map[string]interface{}) (in
70 SetOrder("update_time", "sortByUpdateTime"). 97 SetOrder("update_time", "sortByUpdateTime").
71 SetOrder("id", "sortById"). 98 SetOrder("id", "sortById").
72 SetLimit() 99 SetLimit()
  100 +
  101 + if searchByText, ok := queryOptions["searchByText"]; ok && len(searchByText.(string)) > 0 {
  102 + query.Where(fmt.Sprintf(`name like '%%%v%%'`, searchByText))
  103 + }
  104 +
73 var err error 105 var err error
74 if query.AffectRow, err = query.SelectAndCount(); err != nil { 106 if query.AffectRow, err = query.SelectAndCount(); err != nil {
75 return 0, Users, err 107 return 0, Users, err
@@ -94,5 +126,5 @@ func NewUserRepository(transactionContext *transaction.TransactionContext) (*Use @@ -94,5 +126,5 @@ func NewUserRepository(transactionContext *transaction.TransactionContext) (*Use
94 if transactionContext == nil { 126 if transactionContext == nil {
95 return nil, fmt.Errorf("transactionContext参数不能为nil") 127 return nil, fmt.Errorf("transactionContext参数不能为nil")
96 } 128 }
97 - return &UsersRepository{transactionContext: transactionContext}, nil 129 + return &UsersRepository{transactionContext: transactionContext, CachedRepository: cache.NewDefaultCachedRepository()}, nil
98 } 130 }
@@ -3,6 +3,7 @@ package utils @@ -3,6 +3,7 @@ package utils
3 import ( 3 import (
4 "github.com/tiptok/gocomm/common" 4 "github.com/tiptok/gocomm/common"
5 "reflect" 5 "reflect"
  6 + "time"
6 ) 7 )
7 8
8 func LoadCustomField(src interface{}, fields ...string) interface{} { 9 func LoadCustomField(src interface{}, fields ...string) interface{} {
@@ -33,7 +34,14 @@ func LoadCustomField(src interface{}, fields ...string) interface{} { @@ -33,7 +34,14 @@ func LoadCustomField(src interface{}, fields ...string) interface{} {
33 retSliceMap := make(map[string]interface{}) 34 retSliceMap := make(map[string]interface{})
34 for _, filed := range fields { 35 for _, filed := range fields {
35 f := valueSrc.FieldByName(filed) 36 f := valueSrc.FieldByName(filed)
36 - retSliceMap[common.CamelCase(filed, false)] = f.Interface() 37 + if !f.IsValid() {
  38 + continue
  39 + }
  40 + v := f.Interface()
  41 + if t, ok := v.(time.Time); ok {
  42 + v = t.Local().Format("2006-01-02 15:04:05")
  43 + }
  44 + retSliceMap[common.CamelCase(filed, false)] = v
37 } 45 }
38 return retSliceMap 46 return retSliceMap
39 default: 47 default:
@@ -41,3 +49,16 @@ func LoadCustomField(src interface{}, fields ...string) interface{} { @@ -41,3 +49,16 @@ func LoadCustomField(src interface{}, fields ...string) interface{} {
41 } 49 }
42 return src 50 return src
43 } 51 }
  52 +
  53 +func AppendCustomField(src interface{}, options map[string]interface{}) interface{} {
  54 + var mapSrc map[string]interface{}
  55 + var ok bool
  56 + mapSrc, ok = src.(map[string]interface{})
  57 + if !ok {
  58 + common.JsonUnmarshal(common.JsonAssertString(src), &mapSrc)
  59 + }
  60 + for field, value := range options {
  61 + mapSrc[common.CamelCase(field, false)] = value
  62 + }
  63 + return mapSrc
  64 +}
@@ -26,6 +26,23 @@ func TestLoadCustomField(t *testing.T) { @@ -26,6 +26,23 @@ func TestLoadCustomField(t *testing.T) {
26 t.Log(common.JsonAssertString(ret2)) 26 t.Log(common.JsonAssertString(ret2))
27 27
28 v3 := []*User{&User{Name: "c1", Id: 1}, &User{Name: "c2", Id: 2}, &User{Name: "c3", Id: 3}} 28 v3 := []*User{&User{Name: "c1", Id: 1}, &User{Name: "c2", Id: 2}, &User{Name: "c3", Id: 3}}
29 - ret3 := LoadCustomField(&v3, "Name") 29 + ret3 := LoadCustomField(&v3, "Name", "Name2")
30 t.Log(common.JsonAssertString(ret3)) 30 t.Log(common.JsonAssertString(ret3))
31 } 31 }
  32 +
  33 +func TestAppendCustomField(t *testing.T) {
  34 + customMap := map[string]interface{}{"1": "h", "2": "e"}
  35 + t.Log(customMap)
  36 +
  37 + customeFiles := map[string]interface{}{
  38 + "Value": map[string]interface{}{"a": "a", "b": "b"},
  39 + "Value2": "cc",
  40 + "Value3": 9999,
  41 + }
  42 + t.Log(AppendCustomField(customMap, customeFiles))
  43 +
  44 + t.Log(AppendCustomField(struct {
  45 + Name string `json:"name"`
  46 + Age int64 `json:"age"`
  47 + }{Name: "ccc", Age: 20}, customeFiles))
  48 +}
@@ -16,11 +16,11 @@ func init() { @@ -16,11 +16,11 @@ func init() {
16 AllowCredentials: true, 16 AllowCredentials: true,
17 })) 17 }))
18 18
19 - beego.InsertFilter("/auth/profile", beego.BeforeExec, middleware.CheckAuthorization)  
20 - beego.InsertFilter("/user/*", beego.BeforeExec, middleware.InspectRoleAccess(""))  
21 - beego.InsertFilter("/role/*", beego.BeforeExec, middleware.InspectRoleAccess(""))  
22 - beego.InsertFilter("/project_module/*", beego.BeforeExec, middleware.InspectRoleAccess(""))  
23 - beego.InsertFilter("/project_module_version/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*"))  
24 - beego.InsertFilter("/project_module_files/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*"))  
25 - beego.InsertFilter("/rbac/*", beego.BeforeExec, middleware.InspectRoleAccess("/role/*")) 19 + beego.InsertFilter("/v1/auth/profile", beego.BeforeExec, middleware.CheckAuthorization)
  20 + beego.InsertFilter("/v1/user/*", beego.BeforeExec, middleware.InspectRoleAccess(""))
  21 + beego.InsertFilter("/v1/role/*", beego.BeforeExec, middleware.InspectRoleAccess(""))
  22 + beego.InsertFilter("/v1/project_module/*", beego.BeforeExec, middleware.InspectRoleAccess(""))
  23 + beego.InsertFilter("/v1/project_module_version/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*"))
  24 + beego.InsertFilter("/v1/project_module_files/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*"))
  25 + beego.InsertFilter("/v1/rbac/*", beego.BeforeExec, middleware.InspectRoleAccess("/role/*"))
26 } 26 }
@@ -13,20 +13,20 @@ type ProjectModuleController struct { @@ -13,20 +13,20 @@ type ProjectModuleController struct {
13 13
14 // CreateProjectModule 14 // CreateProjectModule
15 // CreateProjectModule execute command create ProjectModule 15 // CreateProjectModule execute command create ProjectModule
16 -func (this *ProjectModuleController) CreateProjectModule() { 16 +func (controller *ProjectModuleController) CreateProjectModule() {
17 var ( 17 var (
18 msg *protocol.ResponseMessage 18 msg *protocol.ResponseMessage
19 svr = project_module.NewProjectModuleService(nil) 19 svr = project_module.NewProjectModuleService(nil)
20 request *protocolx.CreateProjectModuleRequest 20 request *protocolx.CreateProjectModuleRequest
21 ) 21 )
22 defer func() { 22 defer func() {
23 - this.Resp(msg) 23 + controller.Resp(msg)
24 }() 24 }()
25 - if err := this.JsonUnmarshal(&request); err != nil { 25 + if err := controller.JsonUnmarshal(&request); err != nil {
26 msg = protocol.NewResponseMessage(2, "") 26 msg = protocol.NewResponseMessage(2, "")
27 return 27 return
28 } 28 }
29 - header := this.GetRequestHeader(this.Ctx) 29 + header := controller.GetRequestHeader(controller.Ctx)
30 data, err := svr.CreateProjectModule(header, request) 30 data, err := svr.CreateProjectModule(header, request)
31 if err != nil { 31 if err != nil {
32 log.Error(err) 32 log.Error(err)
@@ -36,20 +36,21 @@ func (this *ProjectModuleController) CreateProjectModule() { @@ -36,20 +36,21 @@ func (this *ProjectModuleController) CreateProjectModule() {
36 36
37 // UpdateProjectModule 37 // UpdateProjectModule
38 // UpdateProjectModule execute command update ProjectModule 38 // UpdateProjectModule execute command update ProjectModule
39 -func (this *ProjectModuleController) UpdateProjectModule() { 39 +func (controller *ProjectModuleController) UpdateProjectModule() {
40 var ( 40 var (
41 msg *protocol.ResponseMessage 41 msg *protocol.ResponseMessage
42 svr = project_module.NewProjectModuleService(nil) 42 svr = project_module.NewProjectModuleService(nil)
43 request *protocolx.UpdateProjectModuleRequest 43 request *protocolx.UpdateProjectModuleRequest
44 ) 44 )
45 defer func() { 45 defer func() {
46 - this.Resp(msg) 46 + controller.Resp(msg)
47 }() 47 }()
48 - if err := this.JsonUnmarshal(&request); err != nil { 48 + if err := controller.JsonUnmarshal(&request); err != nil {
49 msg = protocol.NewResponseMessage(2, "") 49 msg = protocol.NewResponseMessage(2, "")
50 return 50 return
51 } 51 }
52 - header := this.GetRequestHeader(this.Ctx) 52 + request.Id, _ = controller.GetInt64(":projectModuleId")
  53 + header := controller.GetRequestHeader(controller.Ctx)
53 data, err := svr.UpdateProjectModule(header, request) 54 data, err := svr.UpdateProjectModule(header, request)
54 if err != nil { 55 if err != nil {
55 log.Error(err) 56 log.Error(err)
@@ -59,17 +60,17 @@ func (this *ProjectModuleController) UpdateProjectModule() { @@ -59,17 +60,17 @@ func (this *ProjectModuleController) UpdateProjectModule() {
59 60
60 // GetProjectModule 61 // GetProjectModule
61 // GetProjectModule execute query get ProjectModule 62 // GetProjectModule execute query get ProjectModule
62 -func (this *ProjectModuleController) GetProjectModule() { 63 +func (controller *ProjectModuleController) GetProjectModule() {
63 var ( 64 var (
64 msg *protocol.ResponseMessage 65 msg *protocol.ResponseMessage
65 svr = project_module.NewProjectModuleService(nil) 66 svr = project_module.NewProjectModuleService(nil)
66 request = &protocolx.GetProjectModuleRequest{} 67 request = &protocolx.GetProjectModuleRequest{}
67 ) 68 )
68 defer func() { 69 defer func() {
69 - this.Resp(msg) 70 + controller.Resp(msg)
70 }() 71 }()
71 - request.Id, _ = this.GetInt64(":projectModuleId")  
72 - header := this.GetRequestHeader(this.Ctx) 72 + request.Id, _ = controller.GetInt64(":projectModuleId")
  73 + header := controller.GetRequestHeader(controller.Ctx)
73 data, err := svr.GetProjectModule(header, request) 74 data, err := svr.GetProjectModule(header, request)
74 if err != nil { 75 if err != nil {
75 log.Error(err) 76 log.Error(err)
@@ -79,20 +80,17 @@ func (this *ProjectModuleController) GetProjectModule() { @@ -79,20 +80,17 @@ func (this *ProjectModuleController) GetProjectModule() {
79 80
80 // DeleteProjectModule 81 // DeleteProjectModule
81 // DeleteProjectModule execute command delete ProjectModule 82 // DeleteProjectModule execute command delete ProjectModule
82 -func (this *ProjectModuleController) DeleteProjectModule() { 83 +func (controller *ProjectModuleController) DeleteProjectModule() {
83 var ( 84 var (
84 msg *protocol.ResponseMessage 85 msg *protocol.ResponseMessage
85 svr = project_module.NewProjectModuleService(nil) 86 svr = project_module.NewProjectModuleService(nil)
86 - request *protocolx.DeleteProjectModuleRequest 87 + request = &protocolx.DeleteProjectModuleRequest{}
87 ) 88 )
88 defer func() { 89 defer func() {
89 - this.Resp(msg) 90 + controller.Resp(msg)
90 }() 91 }()
91 - if err := this.JsonUnmarshal(&request); err != nil {  
92 - msg = protocol.NewResponseMessage(2, "")  
93 - return  
94 - }  
95 - header := this.GetRequestHeader(this.Ctx) 92 + request.Id, _ = controller.GetInt64(":projectModuleId")
  93 + header := controller.GetRequestHeader(controller.Ctx)
96 data, err := svr.DeleteProjectModule(header, request) 94 data, err := svr.DeleteProjectModule(header, request)
97 if err != nil { 95 if err != nil {
98 log.Error(err) 96 log.Error(err)
@@ -102,23 +100,25 @@ func (this *ProjectModuleController) DeleteProjectModule() { @@ -102,23 +100,25 @@ func (this *ProjectModuleController) DeleteProjectModule() {
102 100
103 // ListProjectModule 101 // ListProjectModule
104 // ListProjectModule execute query list ProjectModule 102 // ListProjectModule execute query list ProjectModule
105 -func (this *ProjectModuleController) ListProjectModule() { 103 +func (controller *ProjectModuleController) ListProjectModule() {
106 var ( 104 var (
107 msg *protocol.ResponseMessage 105 msg *protocol.ResponseMessage
108 svr = project_module.NewProjectModuleService(nil) 106 svr = project_module.NewProjectModuleService(nil)
109 - request *protocolx.ListProjectModuleRequest 107 + request = &protocolx.ListProjectModuleRequest{}
110 ) 108 )
111 defer func() { 109 defer func() {
112 - this.Resp(msg) 110 + controller.Resp(msg)
113 }() 111 }()
114 - if err := this.JsonUnmarshal(&request); err != nil { 112 + if err := controller.JsonUnmarshal(&request); err != nil {
115 msg = protocol.NewResponseMessage(2, "") 113 msg = protocol.NewResponseMessage(2, "")
116 return 114 return
117 } 115 }
118 - header := this.GetRequestHeader(this.Ctx) 116 + request.PageNumber, _ = controller.GetInt("pageNumber")
  117 + request.PageSize, _ = controller.GetInt("pageSize")
  118 + header := controller.GetRequestHeader(controller.Ctx)
119 data, err := svr.ListProjectModule(header, request) 119 data, err := svr.ListProjectModule(header, request)
120 if err != nil { 120 if err != nil {
121 log.Error(err) 121 log.Error(err)
122 } 122 }
123 - msg = protocol.NewResponseMessageData(data, err) 123 + msg = protocol.NewResponseMessageListData(data, err)
124 } 124 }
@@ -52,6 +52,7 @@ func (controller *ProjectModuleFilesController) UpdateProjectModuleFiles() { @@ -52,6 +52,7 @@ func (controller *ProjectModuleFilesController) UpdateProjectModuleFiles() {
52 msg = protocol.NewResponseMessage(2, "") 52 msg = protocol.NewResponseMessage(2, "")
53 return 53 return
54 } 54 }
  55 + request.Id, _ = controller.GetInt64(":projectModuleFilesId")
55 header := controller.GetRequestHeader(controller.Ctx) 56 header := controller.GetRequestHeader(controller.Ctx)
56 data, err := svr.UpdateProjectModuleFiles(header, request) 57 data, err := svr.UpdateProjectModuleFiles(header, request)
57 if err != nil { 58 if err != nil {
@@ -66,15 +67,12 @@ func (controller *ProjectModuleFilesController) GetProjectModuleFiles() { @@ -66,15 +67,12 @@ func (controller *ProjectModuleFilesController) GetProjectModuleFiles() {
66 var ( 67 var (
67 msg *protocol.ResponseMessage 68 msg *protocol.ResponseMessage
68 svr = project_module_files.NewProjectModuleFilesService(nil) 69 svr = project_module_files.NewProjectModuleFilesService(nil)
69 - request *protocolx.GetProjectModuleFilesRequest 70 + request = &protocolx.GetProjectModuleFilesRequest{}
70 ) 71 )
71 defer func() { 72 defer func() {
72 controller.Resp(msg) 73 controller.Resp(msg)
73 }() 74 }()
74 - if err := controller.JsonUnmarshal(&request); err != nil {  
75 - msg = protocol.NewResponseMessage(2, "")  
76 - return  
77 - } 75 + request.Id, _ = controller.GetInt64(":projectModuleFilesId")
78 header := controller.GetRequestHeader(controller.Ctx) 76 header := controller.GetRequestHeader(controller.Ctx)
79 data, err := svr.GetProjectModuleFiles(header, request) 77 data, err := svr.GetProjectModuleFiles(header, request)
80 if err != nil { 78 if err != nil {
@@ -89,15 +87,12 @@ func (controller *ProjectModuleFilesController) DeleteProjectModuleFiles() { @@ -89,15 +87,12 @@ func (controller *ProjectModuleFilesController) DeleteProjectModuleFiles() {
89 var ( 87 var (
90 msg *protocol.ResponseMessage 88 msg *protocol.ResponseMessage
91 svr = project_module_files.NewProjectModuleFilesService(nil) 89 svr = project_module_files.NewProjectModuleFilesService(nil)
92 - request *protocolx.DeleteProjectModuleFilesRequest 90 + request = &protocolx.DeleteProjectModuleFilesRequest{}
93 ) 91 )
94 defer func() { 92 defer func() {
95 controller.Resp(msg) 93 controller.Resp(msg)
96 }() 94 }()
97 - if err := controller.JsonUnmarshal(&request); err != nil {  
98 - msg = protocol.NewResponseMessage(2, "")  
99 - return  
100 - } 95 + request.Id, _ = controller.GetInt64(":projectModuleFilesId")
101 header := controller.GetRequestHeader(controller.Ctx) 96 header := controller.GetRequestHeader(controller.Ctx)
102 data, err := svr.DeleteProjectModuleFiles(header, request) 97 data, err := svr.DeleteProjectModuleFiles(header, request)
103 if err != nil { 98 if err != nil {
@@ -119,6 +114,7 @@ func (controller *ProjectModuleFilesController) ListProjectModuleFiles() { @@ -119,6 +114,7 @@ func (controller *ProjectModuleFilesController) ListProjectModuleFiles() {
119 }() 114 }()
120 request.ProjectModuleVersionId, _ = controller.GetInt64("projectModuleVersionId") 115 request.ProjectModuleVersionId, _ = controller.GetInt64("projectModuleVersionId")
121 request.ProjectModuleId, _ = controller.GetInt64("projectModuleId") 116 request.ProjectModuleId, _ = controller.GetInt64("projectModuleId")
  117 + request.StructType = controller.GetString("structType")
122 header := controller.GetRequestHeader(controller.Ctx) 118 header := controller.GetRequestHeader(controller.Ctx)
123 data, err := svr.ListProjectModuleFiles(header, request) 119 data, err := svr.ListProjectModuleFiles(header, request)
124 if err != nil { 120 if err != nil {
@@ -104,15 +104,14 @@ func (controller *UserController) ListUser() { @@ -104,15 +104,14 @@ func (controller *UserController) ListUser() {
104 var ( 104 var (
105 msg *protocol.ResponseMessage 105 msg *protocol.ResponseMessage
106 svr = user.NewUserService(nil) 106 svr = user.NewUserService(nil)
107 - request *protocolx.ListUserRequest 107 + request = &protocolx.ListUserRequest{}
108 ) 108 )
109 defer func() { 109 defer func() {
110 controller.Resp(msg) 110 controller.Resp(msg)
111 }() 111 }()
112 - if err := controller.JsonUnmarshal(&request); err != nil {  
113 - msg = protocol.NewResponseMessage(2, "")  
114 - return  
115 - } 112 + request.PageNumber, _ = controller.GetInt("pageNumber")
  113 + request.PageSize, _ = controller.GetInt("pageSize")
  114 + request.SearchByText = controller.GetString("searchByText")
116 header := controller.GetRequestHeader(controller.Ctx) 115 header := controller.GetRequestHeader(controller.Ctx)
117 data, err := svr.ListUser(header, request) 116 data, err := svr.ListUser(header, request)
118 if err != nil { 117 if err != nil {
@@ -6,9 +6,9 @@ import ( @@ -6,9 +6,9 @@ import (
6 ) 6 )
7 7
8 func init() { 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") 9 + beego.Router("/v1/access/", &controllers.AccessController{}, "POST:CreateAccess")
  10 + beego.Router("/v1/access/:accessId", &controllers.AccessController{}, "PUT:UpdateAccess")
  11 + beego.Router("/v1/access/:accessId", &controllers.AccessController{}, "GET:GetAccess")
  12 + beego.Router("/v1/access/:accessId", &controllers.AccessController{}, "DELETE:DeleteAccess")
  13 + beego.Router("/v1/access/", &controllers.AccessController{}, "GET:ListAccess")
14 } 14 }
@@ -6,9 +6,9 @@ import ( @@ -6,9 +6,9 @@ import (
6 ) 6 )
7 7
8 func init() { 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/captcha-init", &controllers.AuthController{}, "post:CaptchaInit")  
13 - beego.Router("/auth/changePassword", &controllers.AuthController{}, "post:ChangePassword") 9 + beego.Router("/v1/auth/login", &controllers.AuthController{}, "post:Login")
  10 + beego.Router("/v1/auth/logout", &controllers.AuthController{}, "post:Logout")
  11 + beego.Router("/v1/auth/profile", &controllers.AuthController{}, "post:Profile")
  12 + beego.Router("/v1/auth/captcha-init", &controllers.AuthController{}, "post:CaptchaInit")
  13 + beego.Router("/v1/auth/changePassword", &controllers.AuthController{}, "post:ChangePassword")
14 } 14 }
@@ -6,9 +6,9 @@ import ( @@ -6,9 +6,9 @@ import (
6 ) 6 )
7 7
8 func init() { 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") 9 + beego.Router("/v1/menu/", &controllers.MenuController{}, "POST:CreateMenu")
  10 + beego.Router("/v1/menu/:menuId", &controllers.MenuController{}, "PUT:UpdateMenu")
  11 + beego.Router("/v1/menu/:menuId", &controllers.MenuController{}, "GET:GetMenu")
  12 + beego.Router("/v1/menu/:menuId", &controllers.MenuController{}, "DELETE:DeleteMenu")
  13 + beego.Router("/v1/menu/", &controllers.MenuController{}, "GET:ListMenu")
14 } 14 }
@@ -6,11 +6,11 @@ import ( @@ -6,11 +6,11 @@ import (
6 ) 6 )
7 7
8 func init() { 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") 9 + beego.Router("/v1/project_module_files/", &controllers.ProjectModuleFilesController{}, "POST:CreateProjectModuleFiles")
  10 + beego.Router("/v1/project_module_files/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "PUT:UpdateProjectModuleFiles")
  11 + beego.Router("/v1/project_module_files/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "GET:GetProjectModuleFiles")
  12 + beego.Router("/v1/project_module_files/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "DELETE:DeleteProjectModuleFiles")
  13 + beego.Router("/v1/project_module_files/", &controllers.ProjectModuleFilesController{}, "GET:ListProjectModuleFiles")
14 14
15 - beego.Router("/project_module_files/import", &controllers.ProjectModuleFilesController{}, "post:Import") 15 + beego.Router("/v1/project_module_files/import", &controllers.ProjectModuleFilesController{}, "post:Import")
16 } 16 }
@@ -6,9 +6,9 @@ import ( @@ -6,9 +6,9 @@ import (
6 ) 6 )
7 7
8 func init() { 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") 9 + beego.Router("/v1/project_module/", &controllers.ProjectModuleController{}, "POST:CreateProjectModule")
  10 + beego.Router("/v1/project_module/:projectModuleId", &controllers.ProjectModuleController{}, "PUT:UpdateProjectModule")
  11 + beego.Router("/v1/project_module/:projectModuleId", &controllers.ProjectModuleController{}, "GET:GetProjectModule")
  12 + beego.Router("/v1/project_module/:projectModuleId", &controllers.ProjectModuleController{}, "DELETE:DeleteProjectModule")
  13 + beego.Router("/v1/project_module/", &controllers.ProjectModuleController{}, "GET:ListProjectModule")
14 } 14 }
@@ -6,9 +6,9 @@ import ( @@ -6,9 +6,9 @@ import (
6 ) 6 )
7 7
8 func init() { 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") 9 + beego.Router("/v1/project_module_version/", &controllers.ProjectModuleVersionController{}, "POST:CreateProjectModuleVersion")
  10 + beego.Router("/v1/project_module_version/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "PUT:UpdateProjectModuleVersion")
  11 + beego.Router("/v1/project_module_version/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "GET:GetProjectModuleVersion")
  12 + beego.Router("/v1/project_module_version/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "DELETE:DeleteProjectModuleVersion")
  13 + beego.Router("/v1/project_module_version/", &controllers.ProjectModuleVersionController{}, "GET:ListProjectModuleVersion")
14 } 14 }
@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 ) 6 )
7 7
8 func init() { 8 func init() {
9 - beego.Router("/rbac/access", &controllers.RbacController{}, "get:Access")  
10 - beego.Router("/rbac/roleAccess/:roleId", &controllers.RbacController{}, "get:RoleAccess")  
11 - beego.Router("/rbac/setRoleAccess", &controllers.RbacController{}, "post:SetRoleAccess") 9 + beego.Router("/v1/rbac/access", &controllers.RbacController{}, "get:Access")
  10 + beego.Router("/v1/rbac/roleAccess/:roleId", &controllers.RbacController{}, "get:RoleAccess")
  11 + beego.Router("/v1/rbac/setRoleAccess", &controllers.RbacController{}, "post:SetRoleAccess")
12 } 12 }
@@ -6,9 +6,9 @@ import ( @@ -6,9 +6,9 @@ import (
6 ) 6 )
7 7
8 func init() { 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") 9 + beego.Router("/v1/role/", &controllers.RoleController{}, "POST:CreateRole")
  10 + beego.Router("/v1/role/:roleId", &controllers.RoleController{}, "PUT:UpdateRole")
  11 + beego.Router("/v1/role/:roleId", &controllers.RoleController{}, "GET:GetRole")
  12 + beego.Router("/v1/role/:roleId", &controllers.RoleController{}, "DELETE:DeleteRole")
  13 + beego.Router("/v1/role/", &controllers.RoleController{}, "GET:ListRole")
14 } 14 }
@@ -6,9 +6,9 @@ import ( @@ -6,9 +6,9 @@ import (
6 ) 6 )
7 7
8 func init() { 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") 9 + beego.Router("/v1/user/", &controllers.UserController{}, "POST:CreateUser")
  10 + beego.Router("/v1/user/:userId", &controllers.UserController{}, "PUT:UpdateUser")
  11 + beego.Router("/v1/user/:userId", &controllers.UserController{}, "GET:GetUser")
  12 + beego.Router("/v1/user/:userId", &controllers.UserController{}, "DELETE:DeleteUser")
  13 + beego.Router("/v1/user/", &controllers.UserController{}, "GET:ListUser")
14 } 14 }
@@ -7,9 +7,9 @@ import ( @@ -7,9 +7,9 @@ import (
7 7
8 type CreateProjectModuleRequest struct { 8 type CreateProjectModuleRequest struct {
9 // 项目名称 9 // 项目名称
10 - ProjectName string `json:"projectName,omitempty"` 10 + ProjectName string `json:"projectName,omitempty" valid:"Required"`
11 // 项目唯一键值 11 // 项目唯一键值
12 - ProjectKey string `json:"projectKey,omitempty"` 12 + ProjectKey string `json:"projectKey,omitempty" valid:"Required"`
13 // 项目描述信息 13 // 项目描述信息
14 Description string `json:"description,omitempty"` 14 Description string `json:"description,omitempty"`
15 } 15 }
@@ -7,7 +7,7 @@ import ( @@ -7,7 +7,7 @@ import (
7 7
8 type DeleteProjectModuleRequest struct { 8 type DeleteProjectModuleRequest struct {
9 // 唯一标识 9 // 唯一标识
10 - Id int64 `json:"id,omitempty"` 10 + Id int64 `json:"id,omitempty" valid:"Required"`
11 } 11 }
12 12
13 func (DeleteProjectModuleRequest *DeleteProjectModuleRequest) ValidateCommand() error { 13 func (DeleteProjectModuleRequest *DeleteProjectModuleRequest) ValidateCommand() error {
@@ -6,13 +6,14 @@ import ( @@ -6,13 +6,14 @@ import (
6 ) 6 )
7 7
8 type UpdateProjectModuleRequest struct { 8 type UpdateProjectModuleRequest struct {
  9 + Id int64 `json:"-" valid:"Required"`
9 // 项目名称 10 // 项目名称
10 - ProjectName string `json:"projectName,omitempty"` 11 + ProjectName string `json:"projectName,omitempty" valid:"Required"`
11 // 项目唯一键值 12 // 项目唯一键值
12 - ProjectKey string `json:"projectKey,omitempty"` 13 + ProjectKey string `json:"projectKey,omitempty" valid:"Required"`
13 // 项目描述信息 14 // 项目描述信息
14 Description string `json:"description,omitempty"` 15 Description string `json:"description,omitempty"`
15 - // 状态 0:正常 1:删除 16 + // 状态 1:正常 2:删除
16 Status int `json:"status,omitempty"` 17 Status int `json:"status,omitempty"`
17 } 18 }
18 19
@@ -6,6 +6,8 @@ import ( @@ -6,6 +6,8 @@ import (
6 ) 6 )
7 7
8 type ListProjectModuleRequest struct { 8 type ListProjectModuleRequest struct {
  9 + PageSize int `json:"pageSize" valid:"Required"`
  10 + PageNumber int `json:"pageNumber" valid:"Required"`
9 } 11 }
10 12
11 func (ListProjectModuleRequest *ListProjectModuleRequest) ValidateCommand() error { 13 func (ListProjectModuleRequest *ListProjectModuleRequest) ValidateCommand() error {
@@ -3,6 +3,7 @@ package project_module @@ -3,6 +3,7 @@ package project_module
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/astaxie/beego/validation" 5 "github.com/astaxie/beego/validation"
  6 + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
6 ) 7 )
7 8
8 type ListProjectModuleResponse struct { 9 type ListProjectModuleResponse struct {
@@ -21,3 +22,20 @@ func (ListProjectModuleResponse *ListProjectModuleResponse) ValidateCommand() er @@ -21,3 +22,20 @@ func (ListProjectModuleResponse *ListProjectModuleResponse) ValidateCommand() er
21 } 22 }
22 return nil 23 return nil
23 } 24 }
  25 +
  26 +func (ListProjectModuleResponse *ListProjectModuleResponse) LoadDto(projectModules []*domain.ProjectModule) interface{} {
  27 + retSlice := make([]map[string]interface{}, 0)
  28 + for _, m := range projectModules {
  29 + retMap := map[string]interface{}{
  30 + "id": m.Id,
  31 + "projectName": m.ProjectName,
  32 + "projectKey": m.ProjectKey,
  33 + "description": m.Description,
  34 + "status": m.Status,
  35 + "createTime": m.CreateTime.Local().Format("2006-01-02 15:04:05"),
  36 + "updateTime": m.UpdateTime.Local().Format("2006-01-02 15:04:05"),
  37 + }
  38 + retSlice = append(retSlice, retMap)
  39 + }
  40 + return retSlice
  41 +}
@@ -6,16 +6,17 @@ import ( @@ -6,16 +6,17 @@ import (
6 ) 6 )
7 7
8 type UpdateProjectModuleFilesRequest struct { 8 type UpdateProjectModuleFilesRequest struct {
  9 + Id int64
  10 + // 父级编号
  11 + ParentId int64 `json:"parentId"`
9 // 文件类型 1:文件夹 2:文件 12 // 文件类型 1:文件夹 2:文件
10 - FileType int `json:"fileType,omitempty"` 13 + //FileType int `json:"fileType,omitempty"`
11 // 文件名称 14 // 文件名称
12 FileName string `json:"fileName,omitempty"` 15 FileName string `json:"fileName,omitempty"`
13 - // 文件键值  
14 - FileKey string `json:"fileKey,omitempty"`  
15 // 代码块 16 // 代码块
16 CodeBlock string `json:"codeBlock,omitempty"` 17 CodeBlock string `json:"codeBlock,omitempty"`
17 // 排序 18 // 排序
18 - Sort int `json:"sort,omitempty"` 19 + //Sort int `json:"sort,omitempty"`
19 // 备注信息 20 // 备注信息
20 Remark string `json:"remark,omitempty"` 21 Remark string `json:"remark,omitempty"`
21 } 22 }
@@ -10,11 +10,23 @@ type ListProjectModuleFilesRequest struct { @@ -10,11 +10,23 @@ type ListProjectModuleFilesRequest struct {
10 ProjectModuleId int64 `json:"projectModuleId,omitempty" valid:"Required"` 10 ProjectModuleId int64 `json:"projectModuleId,omitempty" valid:"Required"`
11 // 项目模块版本编号 11 // 项目模块版本编号
12 ProjectModuleVersionId int64 `json:"projectModuleVersionId,omitempty" valid:"Required"` 12 ProjectModuleVersionId int64 `json:"projectModuleVersionId,omitempty" valid:"Required"`
  13 + // 返回结构类型 tree list 默认list
  14 + StructType string `json:"structType,omitempty"`
  15 + // 按父级Id排序
  16 + SortByParentId string `json:"sortByParentId,omitempty"`
  17 + // 按Id排序
  18 + SortById string `json:"sortById,omitempty"`
13 } 19 }
14 20
15 func (ListProjectModuleFilesRequest *ListProjectModuleFilesRequest) ValidateCommand() error { 21 func (ListProjectModuleFilesRequest *ListProjectModuleFilesRequest) ValidateCommand() error {
16 valid := validation.Validation{} 22 valid := validation.Validation{}
17 b, err := valid.Valid(ListProjectModuleFilesRequest) 23 b, err := valid.Valid(ListProjectModuleFilesRequest)
  24 + if len(ListProjectModuleFilesRequest.SortByParentId) == 0 {
  25 + ListProjectModuleFilesRequest.SortByParentId = "ASC"
  26 + }
  27 + if len(ListProjectModuleFilesRequest.SortById) == 0 {
  28 + ListProjectModuleFilesRequest.SortById = "ASC"
  29 + }
18 if err != nil { 30 if err != nil {
19 return err 31 return err
20 } 32 }
@@ -3,6 +3,7 @@ package project_module_files @@ -3,6 +3,7 @@ package project_module_files
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/astaxie/beego/validation" 5 "github.com/astaxie/beego/validation"
  6 + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
6 ) 7 )
7 8
8 type ListProjectModuleFilesResponse struct { 9 type ListProjectModuleFilesResponse struct {
@@ -21,3 +22,47 @@ func (ListProjectModuleFilesResponse *ListProjectModuleFilesResponse) ValidateCo @@ -21,3 +22,47 @@ func (ListProjectModuleFilesResponse *ListProjectModuleFilesResponse) ValidateCo
21 } 22 }
22 return nil 23 return nil
23 } 24 }
  25 +
  26 +type ModuleFiles struct {
  27 + *ModuleFile
  28 + List []*ModuleFiles `json:"list"`
  29 +}
  30 +type ModuleFile struct {
  31 + // 唯一标识
  32 + Id int64 `json:"id"`
  33 + // 项目编号
  34 + //ProjectModuleId int64 `json:"projectModuleId"`
  35 + // 项目版本编号
  36 + //ProjectModuleVersionId int64 `json:"projectModuleVersionId"`
  37 + // 文件类型 1:文件夹 2:文件
  38 + FileType int `json:"fileType"`
  39 + // 文件名称
  40 + FileName string `json:"fileName"`
  41 + // 文件键值
  42 + //FileKey string `json:"fileKey"`
  43 + // 代码块
  44 + CodeBlock string `json:"-"`
  45 + // 父级编号
  46 + ParentId int64 `json:"parentId"`
  47 + // 排序
  48 + //Sort int `json:"sort"`
  49 + // 备注信息
  50 + //Remark string `json:"remark"`
  51 + // 创建时间
  52 + //CreateTime time.Time `json:"createTime"`
  53 + // 更新时间
  54 + //UpdateTime time.Time `json:"updateTime"`
  55 + // 当前文件相对路径 a/b/c
  56 + Path string `json:"path"`
  57 +}
  58 +
  59 +func NewModuleFile(m *domain.ProjectModuleFiles) *ModuleFile {
  60 + return &ModuleFile{
  61 + Id: m.Id,
  62 + FileType: m.FileType,
  63 + FileName: m.FileName,
  64 + ParentId: m.ParentId,
  65 + Path: m.Path,
  66 + CodeBlock: m.CodeBlock,
  67 + }
  68 +}
@@ -6,14 +6,15 @@ import ( @@ -6,14 +6,15 @@ import (
6 ) 6 )
7 7
8 type ListUserRequest struct { 8 type ListUserRequest struct {
9 - PageSize int `json:"pageSize"`  
10 - PageNumber int `json:"pageNumber"` 9 + SearchByText string `json:"searchByText,omitempty"` //按名称搜索
  10 + PageSize int `json:"pageSize" valid:"Required"`
  11 + PageNumber int `json:"pageNumber" valid:"Required"`
11 } 12 }
12 13
13 func (ListUserRequest *ListUserRequest) ValidateCommand() error { 14 func (ListUserRequest *ListUserRequest) ValidateCommand() error {
14 valid := validation.Validation{} 15 valid := validation.Validation{}
15 - if ListUserRequest.PageNumber == 0 {  
16 - ListUserRequest.PageNumber = 20 16 + if ListUserRequest.PageSize == 0 {
  17 + ListUserRequest.PageSize = 20
17 } 18 }
18 b, err := valid.Valid(ListUserRequest) 19 b, err := valid.Valid(ListUserRequest)
19 if err != nil { 20 if err != nil {