作者 yangfu

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

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