作者 yangfu

增加:

1.增加日志记录
2.权限过期时间修改
3.客户端版本管理
4.操作日志
正在显示 48 个修改的文件 包含 1698 行增加10 行删除
... ... @@ -12,4 +12,4 @@ require (
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.3 => F:\go\src\learn_project\gocomm
... ...
... ... @@ -2,6 +2,9 @@ package main
import (
"github.com/astaxie/beego"
"github.com/tiptok/gocomm/config"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/redis"
... ... @@ -13,5 +16,10 @@ func main() {
}()
beego.BConfig.CopyRequestBody = true
log.InitLog(config.Logger{
Filename: constant.LOG_File,
Level: constant.LOG_LEVEL,
})
beego.Run()
}
... ...
... ... @@ -46,7 +46,7 @@ func (svr *AuthService) Login(header *protocol.RequestHeader, request *protocolx
err = protocol.NewCustomMessage(1, "密码有误!")
return
}
token, _ := common.GenerateToken(fmt.Sprintf("%v", user.Id), user.Passwd)
token, _ := common.GenerateToken(fmt.Sprintf("%v", user.Id), user.Passwd, common.WithExpire(domain.TokenExpire), common.WithAddData(map[string]interface{}{"UserName": user.Name}))
rsp.Access = map[string]interface{}{
"accessToken": "Bearer " + token,
"expiresIn": domain.TokenExpire,
... ... @@ -165,6 +165,7 @@ func (svr *AuthService) CaptchaInit(header *protocol.RequestHeader, request *pro
func (svr *AuthService) ChangePassword(header *protocol.RequestHeader, request *protocolx.ChangePasswordRequest) (rsp *protocolx.ChangePasswordResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
UserRepository, _ = factory.CreateUserRepository(transactionContext)
)
rsp = &protocolx.ChangePasswordResponse{}
if err = request.ValidateCommand(); err != nil {
... ... @@ -178,6 +179,20 @@ func (svr *AuthService) ChangePassword(header *protocol.RequestHeader, request *
transactionContext.RollbackTransaction()
}()
var user *domain.Users
if user, err = UserRepository.FindOne(map[string]interface{}{"phone": request.Phone}); err != nil {
err = protocol.NewCustomMessage(1, "用户不存在")
return
}
if user.Passwd != request.OldPwd {
err = protocol.NewCustomMessage(1, "旧密码输入有误")
return
}
user.Passwd = request.NewPwd
if _, err = UserRepository.Save(user); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -76,7 +76,7 @@ func (svr *CacheService) ValidUserAccess(userId int64, object string, method str
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))
//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
... ...
package client_version
import (
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/client_version"
"time"
)
type ClientVersionService struct {
}
func (svr *ClientVersionService) CreateClientVersion(header *protocol.RequestHeader, request *protocolx.CreateClientVersionRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.CreateClientVersionResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
newClientVersion := &domain.ClientVersion{
Commiter: header.UserId,
ProjectName: request.ProjectName,
Version: request.Version,
Title: request.Title,
Remark: request.Remark,
ClientPackageInfo: request.ClientPackageInfo,
CreateTime: time.Now(),
}
var ClientVersionRepository, _ = factory.CreateClientVersionRepository(transactionContext)
if m, err := ClientVersionRepository.Save(newClientVersion); err != nil {
return nil, err
} else {
rsp = m
}
err = transactionContext.CommitTransaction()
return
}
func (svr *ClientVersionService) UpdateClientVersion(header *protocol.RequestHeader, request *protocolx.UpdateClientVersionRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.UpdateClientVersionResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ClientVersionRepository, _ = factory.CreateClientVersionRepository(transactionContext)
var clientVersion *domain.ClientVersion
if clientVersion, err = ClientVersionRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
return
}
if err = clientVersion.Update(common.ObjectToMap(request)); err != nil {
return
}
if clientVersion, err = ClientVersionRepository.Save(clientVersion); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
func (svr *ClientVersionService) GetClientVersion(header *protocol.RequestHeader, request *protocolx.GetClientVersionRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.GetClientVersionResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ClientVersionRepository, _ = factory.CreateClientVersionRepository(transactionContext)
var clientVersion *domain.ClientVersion
if clientVersion, err = ClientVersionRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
rsp = clientVersion
err = transactionContext.CommitTransaction()
return
}
func (svr *ClientVersionService) DeleteClientVersion(header *protocol.RequestHeader, request *protocolx.DeleteClientVersionRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.DeleteClientVersionResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ClientVersionRepository, _ = factory.CreateClientVersionRepository(transactionContext)
var clientVersion *domain.ClientVersion
if clientVersion, err = ClientVersionRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if clientVersion, err = ClientVersionRepository.Remove(clientVersion); err != nil {
return
}
rsp = clientVersion
err = transactionContext.CommitTransaction()
return
}
func (svr *ClientVersionService) ListClientVersion(header *protocol.RequestHeader, request *protocolx.ListClientVersionRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.ListClientVersionResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var ClientVersionRepository, _ = factory.CreateClientVersionRepository(transactionContext)
var clientVersion []*domain.ClientVersion
var total int64
if total, clientVersion, err = ClientVersionRepository.Find(common.ObjectToMap(request)); err != nil {
return
}
rsp = map[string]interface{}{
"totalRow": total,
"pageNumber": (request.Offset + request.Limit) / request.Limit,
"list": utils.LoadCustomField(clientVersion, "Id", "ProjectName", "Version", "Title", "Remark", "CreateTime"),
}
err = transactionContext.CommitTransaction()
return
}
func NewClientVersionService(options map[string]interface{}) *ClientVersionService {
svr := &ClientVersionService{}
return svr
}
... ...
... ... @@ -37,3 +37,11 @@ func CreateRoleRepository(transactionContext *transaction.TransactionContext) (d
func CreateUserRepository(transactionContext *transaction.TransactionContext) (domain.UsersRepository, error) {
return repository.NewUserRepository(transactionContext)
}
func CreateClientVersionRepository(transactionContext *transaction.TransactionContext) (domain.ClientVersionRepository, error) {
return repository.NewClientVersionRepository(transactionContext)
}
func CreateOperatorLogRepository(transactionContext *transaction.TransactionContext) (domain.OperatorLogRepository, error) {
return repository.NewOperatorLogRepository(transactionContext)
}
... ...
package operator_log
import (
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/operator_log"
)
type OperatorLogService struct {
}
func (svr *OperatorLogService) CreateOperatorLog(header *protocol.RequestHeader, request *protocolx.CreateOperatorLogRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.CreateOperatorLogResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
newOperatorLog := &domain.OperatorLog{
Operator: request.Commiter,
Code: request.Code,
Content: request.Content,
}
var OperatorLogRepository, _ = factory.CreateOperatorLogRepository(transactionContext)
if m, err := OperatorLogRepository.Save(newOperatorLog); err != nil {
return nil, err
} else {
rsp = m
}
err = transactionContext.CommitTransaction()
return
}
func (svr *OperatorLogService) UpdateOperatorLog(header *protocol.RequestHeader, request *protocolx.UpdateOperatorLogRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.UpdateOperatorLogResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var OperatorLogRepository, _ = factory.CreateOperatorLogRepository(transactionContext)
var operatorLog *domain.OperatorLog
if operatorLog, err = OperatorLogRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if err = operatorLog.Update(common.ObjectToMap(request)); err != nil {
return
}
if operatorLog, err = OperatorLogRepository.Save(operatorLog); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
func (svr *OperatorLogService) GetOperatorLog(header *protocol.RequestHeader, request *protocolx.GetOperatorLogRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.GetOperatorLogResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var OperatorLogRepository, _ = factory.CreateOperatorLogRepository(transactionContext)
var operatorLog *domain.OperatorLog
if operatorLog, err = OperatorLogRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
rsp = operatorLog
err = transactionContext.CommitTransaction()
return
}
func (svr *OperatorLogService) DeleteOperatorLog(header *protocol.RequestHeader, request *protocolx.DeleteOperatorLogRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.DeleteOperatorLogResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var OperatorLogRepository, _ = factory.CreateOperatorLogRepository(transactionContext)
var operatorLog *domain.OperatorLog
if operatorLog, err = OperatorLogRepository.FindOne(common.ObjectToMap(request)); err != nil {
return
}
if operatorLog, err = OperatorLogRepository.Remove(operatorLog); err != nil {
return
}
rsp = operatorLog
err = transactionContext.CommitTransaction()
return
}
func (svr *OperatorLogService) ListOperatorLog(header *protocol.RequestHeader, request *protocolx.ListOperatorLogRequest) (rsp interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.ListOperatorLogResponse{}
if err = request.ValidateCommand(); err != nil {
err = protocol.NewCustomMessage(2, err.Error())
return
}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var OperatorLogRepository, _ = factory.CreateOperatorLogRepository(transactionContext)
var operatorLog []*domain.OperatorLog
var total int64
if total, operatorLog, err = OperatorLogRepository.Find(common.ObjectToMap(request)); err != nil {
return
}
rsp = map[string]interface{}{
"total": total,
"list": utils.LoadCustomField(operatorLog, "Id", "Operator", "Content", "CreateTime"),
}
err = transactionContext.CommitTransaction()
return
}
func NewOperatorLogService(options map[string]interface{}) *OperatorLogService {
svr := &OperatorLogService{}
return svr
}
... ...
package project_module_files
import (
"bytes"
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
... ... @@ -109,7 +110,25 @@ func (svr *ProjectModuleFilesService) UpdateProjectModuleFiles(header *protocol.
}
// TODO:移动文件文件夹时pid变更,底下路径需要都变掉
// TODO:变更记录
// 变更记录
var OperatorLogRepository, _ = factory.CreateOperatorLogRepository(transactionContext)
//var UserRepository, _ = factory.CreateUserRepository(transactionContext)
//user, _ := UserRepository.FindOne(map[string]interface{}{"id": header.UserId})
//if user == nil {
// return
//}
var OpLog *domain.OperatorLog = &domain.OperatorLog{
UserId: header.UserId,
Operator: header.UserName,
Code: domain.LogCodeEditModuleFile,
ResourceId: request.Id,
Content: changeLog(request, projectModuleFiles),
CreateTime: time.Now(),
}
if _, err = OperatorLogRepository.Save(OpLog); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
... ... @@ -361,6 +380,19 @@ func traverse(list []*protocolx.ModuleFiles, file *domain.ProjectModuleFiles) {
}
return
}
func changeLog(request *protocolx.UpdateProjectModuleFilesRequest, old *domain.ProjectModuleFiles) string {
buf := bytes.NewBuffer(nil)
if len(request.FileName) > 0 {
buf.WriteString(" 修改文件名为:" + request.FileName + "\n")
}
if len(request.Remark) > 0 {
buf.WriteString(" 修改描述信息为:" + request.Remark + "\n")
}
if len(request.CodeBlock) > 0 {
buf.WriteString(" 修改模板代码")
}
return buf.String()
}
func NewProjectModuleFilesService(options map[string]interface{}) *ProjectModuleFilesService {
svr := &ProjectModuleFilesService{}
return svr
... ...
package constant
import (
"os"
)
const SERVICE_NAME = "godevp"
var LOG_LEVEL = "debug"
var LOG_File = "app.log"
var MMM_SMS_SERVICE_HOST = "https://sms.fjmaimaimai.com:9897"
//0:正式版 1:开发版 2:体验版
func init() {
if os.Getenv("LOG_LEVEL") != "" {
LOG_LEVEL = os.Getenv("LOG_LEVEL")
}
}
... ...
package domain
const TokenExpire = 3 * 3600
const TokenExpire = 24 * 3600
... ...
package domain
import "time"
// ClientVersion
type ClientVersion struct {
// 唯一标识
Id int64 `json:"id"`
// 提交人
Commiter int64 `json:"commiter"`
// 项目名称
ProjectName string `json:"projectName"`
// 版本号
Version string `json:"version"`
// 标题
Title string `json:"title"`
// 其他备注信息
Remark string `json:"remark"`
// 客户端安装包信息
ClientPackageInfo []*ClientPackageInfo `json:"clientPackageInfo"`
// 创建时间
CreateTime time.Time `json:"createTime"`
}
type ClientVersionRepository interface {
Save(dm *ClientVersion) (*ClientVersion, error)
Remove(dm *ClientVersion) (*ClientVersion, error)
FindOne(queryOptions map[string]interface{}) (*ClientVersion, error)
Find(queryOptions map[string]interface{}) (int64, []*ClientVersion, error)
}
func (m *ClientVersion) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *ClientVersion) Update(data map[string]interface{}) error {
if projectName, ok := data["projectName"]; ok {
m.ProjectName = projectName.(string)
}
if version, ok := data["version"]; ok {
m.Version = version.(string)
}
if title, ok := data["title"]; ok {
m.Title = title.(string)
}
if remark, ok := data["remark"]; ok {
m.Remark = remark.(string)
}
if clientPackageInfo, ok := data["clientPackageInfo"]; ok {
m.ClientPackageInfo = clientPackageInfo.([]*ClientPackageInfo)
}
return nil
}
... ...
package domain
import "time"
const (
LogCodeEditModuleFile = "EditModuleFile"
)
// OperatorLog
type OperatorLog struct {
// 唯一标识
Id int64 `json:"id"`
// 用户编号
UserId int64 `json:"userId"`
// 提交人
Operator string `json:"operator"`
// 日志编号码 : EditModuleFile
Code string `json:"code"`
// 关联资源id
ResourceId int64 `json:"resourceId"`
// 变更内容
Content string `json:"content"`
// 创建时间
CreateTime time.Time `json:"createTime"`
}
type OperatorLogRepository interface {
Save(dm *OperatorLog) (*OperatorLog, error)
Remove(dm *OperatorLog) (*OperatorLog, error)
FindOne(queryOptions map[string]interface{}) (*OperatorLog, error)
Find(queryOptions map[string]interface{}) (int64, []*OperatorLog, error)
}
func (m *OperatorLog) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *OperatorLog) Update(data map[string]interface{}) error {
return nil
}
... ...
package domain
// ClientPackageInfo
type ClientPackageInfo struct {
// 文件名称
FileName string `json:"fileName"`
// 文件路径
Path string `json:"path"`
}
... ...
... ... @@ -34,6 +34,8 @@ func init() {
(*models.Role)(nil),
(*models.RoleAccess)(nil),
(*models.Users)(nil),
(*models.ClientVersion)(nil),
(*models.OperatorLog)(nil),
} {
err := DB.CreateTable(model, &orm.CreateTableOptions{
Temp: false,
... ...
package models
import (
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"time"
)
// ClientVersion
type ClientVersion struct {
tableName struct{} `pg:"client_version"`
// 唯一标识
Id int64
// 提交人
Commiter int64 `pg:",use_zero"`
// 项目名称
ProjectName string
// 版本号
Version string
// 标题
Title string
// 其他备注信息
Remark string
// 客户端安装包信息
ClientPackageInfo []*domain.ClientPackageInfo
// 创建时间
CreateTime time.Time
}
... ...
package models
import "time"
// OperatorLog
type OperatorLog struct {
tableName struct{} `pg:"operator_log"`
// 唯一标识
Id int64
// 用户编号
UserId int64
// 操作人
Operator string
// 日志编号码 : EditModuleFile
Code string
// 关联资源id
ResourceId int64
// 变更内容
Content string
// 创建时间
CreateTime time.Time
}
... ...
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/constant"
"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 (
cacheClientVersionIdKey = func(id int64) string {
return fmt.Sprintf("%v:cache:ClientVersion:id:%v", constant.POSTGRESQL_DB_NAME, id)
// 不需要执行缓存时,key设置为空
// return ""
}
)
type ClientVersionRepository struct {
*cache.CachedRepository
transactionContext *transaction.TransactionContext
}
func (repository *ClientVersionRepository) Save(dm *domain.ClientVersion) (*domain.ClientVersion, error) {
var (
err error
m = &models.ClientVersion{}
tx = repository.transactionContext.PgTx
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if err = tx.Insert(m); err != nil {
return nil, err
}
dm.Id = m.Id
return dm, nil
}
queryFunc := func() (interface{}, error) {
return nil, tx.Update(m)
}
if _, err = repository.Query(queryFunc, cacheClientVersionIdKey(dm.Id)); err != nil {
return nil, err
}
return dm, nil
}
func (repository *ClientVersionRepository) Remove(ClientVersion *domain.ClientVersion) (*domain.ClientVersion, error) {
var (
tx = repository.transactionContext.PgTx
ClientVersionModel = &models.ClientVersion{Id: ClientVersion.Identify().(int64)}
)
queryFunc := func() (interface{}, error) {
return tx.Model(ClientVersionModel).Where("id = ?", ClientVersion.Id).Delete()
}
if _, err := repository.Query(queryFunc, cacheClientVersionIdKey(ClientVersion.Id)); err != nil {
return ClientVersion, err
}
return ClientVersion, nil
}
func (repository *ClientVersionRepository) FindOne(queryOptions map[string]interface{}) (*domain.ClientVersion, error) {
tx := repository.transactionContext.PgDd
ClientVersionModel := new(models.ClientVersion)
queryFunc := func() (interface{}, error) {
query := NewQuery(tx.Model(ClientVersionModel), queryOptions)
query.SetWhere("id = ?", "id")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
return ClientVersionModel, nil
}
var options []cache.QueryOption
if _, ok := queryOptions["id"]; !ok {
options = append(options, cache.WithNoCacheFlag())
} else {
ClientVersionModel.Id = queryOptions["id"].(int64)
}
if err := repository.QueryCache(cacheClientVersionIdKey(ClientVersionModel.Id), ClientVersionModel, queryFunc, options...); err != nil {
return nil, err
}
if ClientVersionModel.Id == 0 {
return nil, fmt.Errorf("query row not found")
}
return repository.transformPgModelToDomainModel(ClientVersionModel)
}
func (repository *ClientVersionRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ClientVersion, error) {
tx := repository.transactionContext.PgTx
var ClientVersionModels []*models.ClientVersion
ClientVersions := make([]*domain.ClientVersion, 0)
query := NewQuery(tx.Model(&ClientVersionModels), queryOptions).
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime").
SetLimit()
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, ClientVersions, err
}
for _, ClientVersionModel := range ClientVersionModels {
if ClientVersion, err := repository.transformPgModelToDomainModel(ClientVersionModel); err != nil {
return 0, ClientVersions, err
} else {
ClientVersions = append(ClientVersions, ClientVersion)
}
}
return int64(query.AffectRow), ClientVersions, nil
}
func (repository *ClientVersionRepository) transformPgModelToDomainModel(ClientVersionModel *models.ClientVersion) (*domain.ClientVersion, error) {
m := &domain.ClientVersion{}
err := common.GobModelTransform(m, ClientVersionModel)
return m, err
}
func NewClientVersionRepository(transactionContext *transaction.TransactionContext) (*ClientVersionRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &ClientVersionRepository{transactionContext: transactionContext, CachedRepository: cache.NewDefaultCachedRepository()}, nil
}
... ...
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/constant"
"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 (
cacheOperatorLogIdKey = func(id int64) string {
return fmt.Sprintf("%v:cache:OperatorLog:id:%v", constant.POSTGRESQL_DB_NAME, id)
// 不需要执行缓存时,key设置为空
// return ""
}
)
type OperatorLogRepository struct {
*cache.CachedRepository
transactionContext *transaction.TransactionContext
}
func (repository *OperatorLogRepository) Save(dm *domain.OperatorLog) (*domain.OperatorLog, error) {
var (
err error
m = &models.OperatorLog{}
tx = repository.transactionContext.PgTx
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if err = tx.Insert(m); err != nil {
return nil, err
}
return dm, nil
}
queryFunc := func() (interface{}, error) {
return nil, tx.Update(m)
}
if _, err = repository.Query(queryFunc, cacheOperatorLogIdKey(dm.Id)); err != nil {
return nil, err
}
return dm, nil
}
func (repository *OperatorLogRepository) Remove(OperatorLog *domain.OperatorLog) (*domain.OperatorLog, error) {
var (
tx = repository.transactionContext.PgTx
OperatorLogModel = &models.OperatorLog{Id: OperatorLog.Identify().(int64)}
)
queryFunc := func() (interface{}, error) {
return tx.Model(OperatorLogModel).Where("id = ?", OperatorLog.Id).Delete()
}
if _, err := repository.Query(queryFunc, cacheOperatorLogIdKey(OperatorLog.Id)); err != nil {
return OperatorLog, err
}
return OperatorLog, nil
}
func (repository *OperatorLogRepository) FindOne(queryOptions map[string]interface{}) (*domain.OperatorLog, error) {
tx := repository.transactionContext.PgDd
OperatorLogModel := new(models.OperatorLog)
queryFunc := func() (interface{}, error) {
query := NewQuery(tx.Model(OperatorLogModel), queryOptions)
query.SetWhere("id = ?", "id")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
return OperatorLogModel, nil
}
var options []cache.QueryOption
if _, ok := queryOptions["id"]; !ok {
options = append(options, cache.WithNoCacheFlag())
} else {
OperatorLogModel.Id = queryOptions["id"].(int64)
}
if err := repository.QueryCache(cacheOperatorLogIdKey(OperatorLogModel.Id), OperatorLogModel, queryFunc, options...); err != nil {
return nil, err
}
if OperatorLogModel.Id == 0 {
return nil, fmt.Errorf("query row not found")
}
return repository.transformPgModelToDomainModel(OperatorLogModel)
}
func (repository *OperatorLogRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.OperatorLog, error) {
tx := repository.transactionContext.PgTx
var OperatorLogModels []*models.OperatorLog
OperatorLogs := make([]*domain.OperatorLog, 0)
query := NewQuery(tx.Model(&OperatorLogModels), queryOptions).
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime").SetLimit()
query.SetWhere("resource_id=?", "resourceId")
query.SetWhere("id<?", "lastId")
query.SetOrder("id", "sortById").SetLimit()
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, OperatorLogs, err
}
for _, OperatorLogModel := range OperatorLogModels {
if OperatorLog, err := repository.transformPgModelToDomainModel(OperatorLogModel); err != nil {
return 0, OperatorLogs, err
} else {
OperatorLogs = append(OperatorLogs, OperatorLog)
}
}
return int64(query.AffectRow), OperatorLogs, nil
}
func (repository *OperatorLogRepository) transformPgModelToDomainModel(OperatorLogModel *models.OperatorLog) (*domain.OperatorLog, error) {
m := &domain.OperatorLog{}
err := common.GobModelTransform(m, OperatorLogModel)
return m, err
}
func NewOperatorLogRepository(transactionContext *transaction.TransactionContext) (*OperatorLogRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &OperatorLogRepository{transactionContext: transactionContext, CachedRepository: cache.NewDefaultCachedRepository()}, nil
}
... ...
... ... @@ -16,10 +16,14 @@ func init() {
AllowCredentials: true,
}))
beego.InsertFilter("/*", beego.BeforeExec, middleware.CreateRequstLogFilter())
beego.InsertFilter("/*", beego.AfterExec, middleware.CreateResponseLogFilter(), false)
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/client_version/*", 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/*"))
... ...
... ... @@ -33,17 +33,24 @@ func (controller *BaseController) Resp(msg *protocol.ResponseMessage) {
}
func (controller BaseController) GetLimitInfo() (offset int, limit int) {
offset, _ = controller.GetInt("offset")
limit, _ = controller.GetInt("limit")
offset, _ = controller.GetInt("pageNumber")
limit, _ = controller.GetInt("pageSize")
if offset > 0 {
offset = (offset - 1) * limit
}
return
}
//获取请求头信息
func (controller *BaseController) GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
h := &protocol.RequestHeader{}
if ctx.Input.GetData("x-mmm-id") != nil {
v := ctx.Input.GetData("x-mmm-id")
if v := ctx.Input.GetData("x-mmm-id"); v != nil {
h.UserId = int64(v.(int))
}
if v := ctx.Input.GetData("x-mmm-uname"); v != nil {
h.UserName = v.(string)
}
return h
}
... ...
package controllers
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/client_version"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/client_version"
)
type ClientVersionController struct {
BaseController
}
// CreateClientVersion
// CreateClientVersion execute command create ClientVersion
func (controller *ClientVersionController) CreateClientVersion() {
var (
msg *protocol.ResponseMessage
svr = client_version.NewClientVersionService(nil)
request *protocolx.CreateClientVersionRequest
)
defer func() {
controller.Resp(msg)
}()
if err := controller.JsonUnmarshal(&request); err != nil {
msg = protocol.NewResponseMessage(2, err.Error())
return
}
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.CreateClientVersion(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewResponseMessageData(data, err)
}
// UpdateClientVersion
// UpdateClientVersion execute command update ClientVersion
func (controller *ClientVersionController) UpdateClientVersion() {
var (
msg *protocol.ResponseMessage
svr = client_version.NewClientVersionService(nil)
request = &protocolx.UpdateClientVersionRequest{}
)
defer func() {
controller.Resp(msg)
}()
request.Id, _ = controller.GetInt64(":clientVersionId")
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.UpdateClientVersion(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewResponseMessageData(data, err)
}
// GetClientVersion
// GetClientVersion execute query get ClientVersion
func (controller *ClientVersionController) GetClientVersion() {
var (
msg *protocol.ResponseMessage
svr = client_version.NewClientVersionService(nil)
request = &protocolx.GetClientVersionRequest{}
)
defer func() {
controller.Resp(msg)
}()
request.Id, _ = controller.GetInt64(":clientVersionId")
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.GetClientVersion(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewResponseMessageData(data, err)
}
// DeleteClientVersion
// DeleteClientVersion execute command delete ClientVersion
func (controller *ClientVersionController) DeleteClientVersion() {
var (
msg *protocol.ResponseMessage
svr = client_version.NewClientVersionService(nil)
request = &protocolx.DeleteClientVersionRequest{}
)
defer func() {
controller.Resp(msg)
}()
request.Id, _ = controller.GetInt64(":clientVersionId")
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.DeleteClientVersion(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewResponseMessageData(data, err)
}
// ListClientVersion
// ListClientVersion execute query list ClientVersion
func (controller *ClientVersionController) ListClientVersion() {
var (
msg *protocol.ResponseMessage
svr = client_version.NewClientVersionService(nil)
request = &protocolx.ListClientVersionRequest{}
)
defer func() {
controller.Resp(msg)
}()
request.Offset, request.Limit = controller.GetLimitInfo()
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.ListClientVersion(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewResponseMessageListData(data, err)
}
... ...
package controllers
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/operator_log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/operator_log"
)
type OperatorLogController struct {
BaseController
}
// CreateOperatorLog
// CreateOperatorLog execute command create OperatorLog
func (controller *OperatorLogController) CreateOperatorLog() {
var (
msg *protocol.ResponseMessage
svr = operator_log.NewOperatorLogService(nil)
request *protocolx.CreateOperatorLogRequest
)
defer func() {
controller.Resp(msg)
}()
if err := controller.JsonUnmarshal(&request); err != nil {
msg = protocol.NewResponseMessage(2, err.Error())
return
}
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.CreateOperatorLog(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewResponseMessageData(data, err)
}
// UpdateOperatorLog
// UpdateOperatorLog execute command update OperatorLog
func (controller *OperatorLogController) UpdateOperatorLog() {
var (
msg *protocol.ResponseMessage
svr = operator_log.NewOperatorLogService(nil)
request *protocolx.UpdateOperatorLogRequest
)
defer func() {
controller.Resp(msg)
}()
if err := controller.JsonUnmarshal(&request); err != nil {
msg = protocol.NewResponseMessage(2, err.Error())
return
}
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.UpdateOperatorLog(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewResponseMessageData(data, err)
}
// GetOperatorLog
// GetOperatorLog execute query get OperatorLog
func (controller *OperatorLogController) GetOperatorLog() {
var (
msg *protocol.ResponseMessage
svr = operator_log.NewOperatorLogService(nil)
request *protocolx.GetOperatorLogRequest
)
defer func() {
controller.Resp(msg)
}()
if err := controller.JsonUnmarshal(&request); err != nil {
msg = protocol.NewResponseMessage(2, err.Error())
return
}
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.GetOperatorLog(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewResponseMessageData(data, err)
}
// DeleteOperatorLog
// DeleteOperatorLog execute command delete OperatorLog
func (controller *OperatorLogController) DeleteOperatorLog() {
var (
msg *protocol.ResponseMessage
svr = operator_log.NewOperatorLogService(nil)
request *protocolx.DeleteOperatorLogRequest
)
defer func() {
controller.Resp(msg)
}()
if err := controller.JsonUnmarshal(&request); err != nil {
msg = protocol.NewResponseMessage(2, err.Error())
return
}
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.DeleteOperatorLog(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewResponseMessageData(data, err)
}
// ListOperatorLog
// ListOperatorLog execute query list OperatorLog
func (controller *OperatorLogController) ListOperatorLog() {
var (
msg *protocol.ResponseMessage
svr = operator_log.NewOperatorLogService(nil)
request = &protocolx.ListOperatorLogRequest{}
)
defer func() {
controller.Resp(msg)
}()
//if err := controller.JsonUnmarshal(&request); err != nil {
// msg = protocol.NewResponseMessage(2,err.Error())
// return
//}
request.Offset, request.Limit = controller.GetLimitInfo()
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.ListOperatorLog(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewResponseMessageData(data, err)
}
... ...
package middleware
import (
"encoding/json"
"errors"
"fmt"
"github.com/astaxie/beego/context"
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/cachex"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
"strconv"
"strings"
"time"
)
var (
... ... @@ -43,6 +47,7 @@ func CheckAuthorization(ctx *context.Context) {
}
userId, _ := strconv.Atoi(claim.Username)
ctx.Input.SetData("x-mmm-id", userId)
ctx.Input.SetData("x-mmm-uname", claim.AddData["UserName"])
return
}
... ... @@ -92,3 +97,26 @@ func InspectRoleAccess(parentObject string, skipUrl ...string) func(*context.Con
CheckRoleAccess(c, c.Input.URL(), c.Input.Method())
}
}
func CreateRequstLogFilter() func(ctx *context.Context) {
return func(ctx *context.Context) {
requestId := fmt.Sprintf("%v.%v.%v ", ctx.Input.Method(), ctx.Input.URI(), time.Now().UnixNano())
ctx.Request.Header.Add("requestId", requestId)
var body string = "{}"
if ctx.Input.GetData("requestBody") != nil {
body = string(ctx.Input.GetData("requestBody").([]byte))
}
log.Debug(fmt.Sprintf("====>Recv RequestId:%s \nBodyData:%s", requestId, body))
}
}
func CreateResponseLogFilter() func(ctx *context.Context) {
return func(ctx *context.Context) {
requestId := ctx.Request.Header.Get("requestId")
body, _ := json.Marshal(ctx.Input.GetData("outputData"))
if len(body) > 1000 {
body = body[:1000]
}
log.Debug(fmt.Sprintf("<====Send User:%v RequestId:%v BodyData:%s", ctx.Input.GetData("x-mmm-id"), requestId, body))
}
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/v1/client_version/", &controllers.ClientVersionController{}, "POST:CreateClientVersion")
beego.Router("/v1/client_version/:clientVersionId", &controllers.ClientVersionController{}, "PUT:UpdateClientVersion")
beego.Router("/v1/client_version/:clientVersionId", &controllers.ClientVersionController{}, "GET:GetClientVersion")
beego.Router("/v1/client_version/:clientVersionId", &controllers.ClientVersionController{}, "DELETE:DeleteClientVersion")
beego.Router("/v1/client_version/", &controllers.ClientVersionController{}, "GET:ListClientVersion")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/controllers"
)
func init() {
//beego.Router("/v1/operator_log/", &controllers.OperatorLogController{}, "POST:CreateOperatorLog")
//beego.Router("/v1/operator_log/:operatorLogId", &controllers.OperatorLogController{}, "PUT:UpdateOperatorLog")
//beego.Router("/v1/operator_log/:operatorLogId", &controllers.OperatorLogController{}, "GET:GetOperatorLog")
//beego.Router("/v1/operator_log/:operatorLogId", &controllers.OperatorLogController{}, "DELETE:DeleteOperatorLog")
beego.Router("/v1/operator_log/", &controllers.OperatorLogController{}, "GET:ListOperatorLog")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
)
func init() {
beego.SetStaticPath("/log", constant.LOG_File)
}
... ...
package auth
import (
"errors"
"fmt"
"github.com/astaxie/beego/validation"
)
type ChangePasswordRequest struct {
Phone string `json:"phone" valid:"Required"`
OldPwd string `json:"oldPassword" valid:"Required"`
NewPwd string `json:"newPassword" valid:"Required"`
}
func (ChangePasswordRequest *ChangePasswordRequest) ValidateCommand() error {
... ... @@ -14,6 +18,9 @@ func (ChangePasswordRequest *ChangePasswordRequest) ValidateCommand() error {
if err != nil {
return err
}
if ChangePasswordRequest.OldPwd == ChangePasswordRequest.NewPwd {
return errors.New("新旧密码不能相同")
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
... ...
package client_version
import (
"fmt"
"github.com/astaxie/beego/validation"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
)
type CreateClientVersionRequest struct {
// 提交人
//Commiter int64 `json:"commiter,omitempty"`
// 项目名称
ProjectName string `json:"projectName,omitempty"`
// 版本号
Version string `json:"version,omitempty"`
// 标题
Title string `json:"title,omitempty"`
// 其他备注信息
Remark string `json:"remark,omitempty"`
// 客户端安装包信息
ClientPackageInfo []*domain.ClientPackageInfo `json:"clientPackageInfo,omitempty"`
}
func (CreateClientVersionRequest *CreateClientVersionRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(CreateClientVersionRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package client_version
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type CreateClientVersionResponse struct {
}
func (CreateClientVersionResponse *CreateClientVersionResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(CreateClientVersionResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package client_version
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type DeleteClientVersionRequest struct {
// 唯一标识
Id int64 `json:"id,omitempty"`
}
func (DeleteClientVersionRequest *DeleteClientVersionRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(DeleteClientVersionRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package client_version
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type DeleteClientVersionResponse struct {
}
func (DeleteClientVersionResponse *DeleteClientVersionResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(DeleteClientVersionResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package client_version
import (
"fmt"
"github.com/astaxie/beego/validation"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
)
type UpdateClientVersionRequest struct {
Id int64 `json:"-"`
// 提交人
Commiter int64 `json:"commiter,omitempty"`
// 项目名称
ProjectName int64 `json:"projectName,omitempty"`
// 版本号
Version string `json:"version,omitempty"`
// 标题
Title string `json:"title,omitempty"`
// 其他备注信息
Remark string `json:"remark,omitempty"`
// 客户端安装包信息
ClientPackageInfo []*domain.ClientPackageInfo `json:"clientPackageInfo,omitempty"`
}
func (UpdateClientVersionRequest *UpdateClientVersionRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(UpdateClientVersionRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package client_version
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type UpdateClientVersionResponse struct {
}
func (UpdateClientVersionResponse *UpdateClientVersionResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(UpdateClientVersionResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package client_version
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetClientVersionRequest struct {
// 唯一标识
Id int64 `json:"id,omitempty" valid:"Required"`
}
func (GetClientVersionRequest *GetClientVersionRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(GetClientVersionRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package client_version
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetClientVersionResponse struct {
}
func (GetClientVersionResponse *GetClientVersionResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(GetClientVersionResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package client_version
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListClientVersionRequest struct {
Offset int `json:"offset"`
Limit int `json:"limit"`
}
func (ListClientVersionRequest *ListClientVersionRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(ListClientVersionRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package client_version
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListClientVersionResponse struct {
}
func (ListClientVersionResponse *ListClientVersionResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(ListClientVersionResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package operator_log
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type CreateOperatorLogRequest struct {
// 提交人
Commiter string `json:"commiter,omitempty"`
// 日志编号码 : EditModuleFile
Code string `json:"code,omitempty"`
// 变更内容
Content string `json:"content,omitempty"`
}
func (CreateOperatorLogRequest *CreateOperatorLogRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(CreateOperatorLogRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package operator_log
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type CreateOperatorLogResponse struct {
}
func (CreateOperatorLogResponse *CreateOperatorLogResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(CreateOperatorLogResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package operator_log
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type DeleteOperatorLogRequest struct {
// 唯一标识
Id int64 `json:"id,omitempty"`
}
func (DeleteOperatorLogRequest *DeleteOperatorLogRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(DeleteOperatorLogRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package operator_log
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type DeleteOperatorLogResponse struct {
}
func (DeleteOperatorLogResponse *DeleteOperatorLogResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(DeleteOperatorLogResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package operator_log
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type UpdateOperatorLogRequest struct {
// 用户编号
UserId int64 `json:"userId,omitempty"`
// 提交人
Commiter string `json:"commiter,omitempty"`
// 日志编号码 : EditModuleFile
Code string `json:"code,omitempty"`
// 关联资源id
ResourceId int64 `json:"resourceId,omitempty"`
// 变更内容
Content string `json:"content,omitempty"`
}
func (UpdateOperatorLogRequest *UpdateOperatorLogRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(UpdateOperatorLogRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package operator_log
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type UpdateOperatorLogResponse struct {
}
func (UpdateOperatorLogResponse *UpdateOperatorLogResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(UpdateOperatorLogResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package operator_log
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetOperatorLogRequest struct {
// 唯一标识
Id int64 `json:"id,omitempty"`
}
func (GetOperatorLogRequest *GetOperatorLogRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(GetOperatorLogRequest)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package operator_log
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetOperatorLogResponse struct {
}
func (GetOperatorLogResponse *GetOperatorLogResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(GetOperatorLogResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package operator_log
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListOperatorLogRequest struct {
SortById string `json:"sortById,omitempty"`
LastId int64 `json:"lastId,omitempty"`
ResourceId int64 `json:"resourceId,omitempty"`
Offset int `json:"offset"`
Limit int `json:"limit"`
}
func (ListOperatorLogRequest *ListOperatorLogRequest) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(ListOperatorLogRequest)
ListOperatorLogRequest.SortById = "DESC"
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package operator_log
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListOperatorLogResponse struct {
}
func (ListOperatorLogResponse *ListOperatorLogResponse) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(ListOperatorLogResponse)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -131,5 +131,6 @@ var errmessge ErrorMap = map[int]string{
}
type RequestHeader struct {
UserId int64 //UserId 唯一标识
UserId int64 //UserId 唯一标识
UserName string
}
... ...