作者 tangxuhui

代码调整

package command
import (
"fmt"
"reflect"
"strings"
"time"
// type CreateCompanyCommand struct {
// // 企业名称
// CompanyName string `cname:"企业名称" json:"companyName" valid:"Required"`
// // 规模
// Scale string `cname:"规模" json:"scale" valid:"Required"`
// // 公司Logo地址
// Logo string `cname:"公司Logo地址" json:"logo" valid:"Required"`
// // 公司地址
// Address string `cname:"公司地址" json:"address" valid:"Required"`
// // 所属行业
// IndustryCategory string `cname:"所属行业" json:"industryCategory" valid:"Required"`
// // 联系人
// Contacts string `cname:"联系人" json:"contacts" valid:"Required"`
// // 注册时间
// RegisteredTime time.Time `cname:"注册时间" json:"registeredTime,omitempty"`
// // 注册状态 1:已注册 2:待认证 3:已认证
// Status int `cname:"注册状态 1:已注册 2:待认证 3:已认证" json:"status,omitempty"`
// }
"github.com/beego/beego/v2/core/validation"
)
// func (createCompanyCommand *CreateCompanyCommand) Valid(validation *validation.Validation) {
type CreateCompanyCommand struct {
// 企业名称
CompanyName string `cname:"企业名称" json:"companyName" valid:"Required"`
// 规模
Scale string `cname:"规模" json:"scale" valid:"Required"`
// 公司Logo地址
Logo string `cname:"公司Logo地址" json:"logo" valid:"Required"`
// 公司地址
Address string `cname:"公司地址" json:"address" valid:"Required"`
// 所属行业
IndustryCategory string `cname:"所属行业" json:"industryCategory" valid:"Required"`
// 联系人
Contacts string `cname:"联系人" json:"contacts" valid:"Required"`
// 注册时间
RegisteredTime time.Time `cname:"注册时间" json:"registeredTime,omitempty"`
// 注册状态 1:已注册 2:待认证 3:已认证
Status int `cname:"注册状态 1:已注册 2:待认证 3:已认证" json:"status,omitempty"`
}
// }
func (createCompanyCommand *CreateCompanyCommand) Valid(validation *validation.Validation) {
}
func (createCompanyCommand *CreateCompanyCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createCompanyCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createCompanyCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
// func (createCompanyCommand *CreateCompanyCommand) ValidateCommand() error {
// valid := validation.Validation{}
// b, err := valid.Valid(createCompanyCommand)
// if err != nil {
// return err
// }
// if !b {
// elem := reflect.TypeOf(createCompanyCommand).Elem()
// for _, validErr := range valid.Errors {
// field, isExist := elem.FieldByName(validErr.Field)
// if isExist {
// return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
// } else {
// return fmt.Errorf(validErr.Message)
// }
// }
// }
// return nil
// }
... ...
package command
import (
"fmt"
"reflect"
"strings"
// type ListCompanyCustomizeMenusCommand struct {
// // 企业id
// CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"`
// // 菜单类别 web app
// MenuCategory string `cname:"菜单类别" json:"menuCategory,omitempty" valid:"Required"`
// }
"github.com/beego/beego/v2/core/validation"
)
// func (listCompanyCustomizeMenusCommand *ListCompanyCustomizeMenusCommand) Valid(validation *validation.Validation) {
type ListCompanyCustomizeMenusCommand struct {
// 企业id
CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"`
// 菜单类别 web app
MenuCategory string `cname:"菜单类别" json:"menuCategory,omitempty" valid:"Required"`
}
// }
func (listCompanyCustomizeMenusCommand *ListCompanyCustomizeMenusCommand) Valid(validation *validation.Validation) {
}
func (listCompanyCustomizeMenusCommand *ListCompanyCustomizeMenusCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(listCompanyCustomizeMenusCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listCompanyCustomizeMenusCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
// func (listCompanyCustomizeMenusCommand *ListCompanyCustomizeMenusCommand) ValidateCommand() error {
// valid := validation.Validation{}
// b, err := valid.Valid(listCompanyCustomizeMenusCommand)
// if err != nil {
// return err
// }
// if !b {
// elem := reflect.TypeOf(listCompanyCustomizeMenusCommand).Elem()
// for _, validErr := range valid.Errors {
// field, isExist := elem.FieldByName(validErr.Field)
// if isExist {
// return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
// } else {
// return fmt.Errorf(validErr.Message)
// }
// }
// }
// return nil
// }
... ...
package command
import (
"fmt"
"reflect"
"strings"
// type RemoveCompanyCommand struct {
// // 企业id
// CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"`
// }
"github.com/beego/beego/v2/core/validation"
)
// func (removeCompanyCommand *RemoveCompanyCommand) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
// }
type RemoveCompanyCommand struct {
// 企业id
CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"`
}
func (removeCompanyCommand *RemoveCompanyCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeCompanyCommand *RemoveCompanyCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeCompanyCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeCompanyCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
// func (removeCompanyCommand *RemoveCompanyCommand) ValidateCommand() error {
// valid := validation.Validation{}
// b, err := valid.Valid(removeCompanyCommand)
// if err != nil {
// return err
// }
// if !b {
// elem := reflect.TypeOf(removeCompanyCommand).Elem()
// for _, validErr := range valid.Errors {
// field, isExist := elem.FieldByName(validErr.Field)
// if isExist {
// return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
// } else {
// return fmt.Errorf(validErr.Message)
// }
// }
// }
// return nil
// }
... ...
package command
import (
"fmt"
"reflect"
"strings"
// type UpdateCompanyCustomizeMenusCommand struct {
// // 企业id
// CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"`
// // 菜单编号
// MenuId int64 `cname:"菜单编号" json:"menuId" valid:"Required"`
// // 菜单名称
// //MenuName string `cname:"菜单名称" json:"menuName" valid:"Required"`
// // 菜单别名
// MenuAlias string `cname:"菜单别名" json:"menuAlias" valid:"Required"`
// // 排序
// Sort int `cname:"排序" json:"sort" valid:"Required"`
// }
"github.com/beego/beego/v2/core/validation"
)
// func (updateCompanyCustomizeMenusCommand *UpdateCompanyCustomizeMenusCommand) Valid(validation *validation.Validation) {
// //validation.SetError("CustomValid", "未实现的自定义认证")
// }
type UpdateCompanyCustomizeMenusCommand struct {
// 企业id
CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"`
// 菜单编号
MenuId int64 `cname:"菜单编号" json:"menuId" valid:"Required"`
// 菜单名称
//MenuName string `cname:"菜单名称" json:"menuName" valid:"Required"`
// 菜单别名
MenuAlias string `cname:"菜单别名" json:"menuAlias" valid:"Required"`
// 排序
Sort int `cname:"排序" json:"sort" valid:"Required"`
}
func (updateCompanyCustomizeMenusCommand *UpdateCompanyCustomizeMenusCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCompanyCustomizeMenusCommand *UpdateCompanyCustomizeMenusCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCompanyCustomizeMenusCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateCompanyCustomizeMenusCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
// func (updateCompanyCustomizeMenusCommand *UpdateCompanyCustomizeMenusCommand) ValidateCommand() error {
// valid := validation.Validation{}
// b, err := valid.Valid(updateCompanyCustomizeMenusCommand)
// if err != nil {
// return err
// }
// if !b {
// elem := reflect.TypeOf(updateCompanyCustomizeMenusCommand).Elem()
// for _, validErr := range valid.Errors {
// field, isExist := elem.FieldByName(validErr.Field)
// if isExist {
// return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
// } else {
// return fmt.Errorf(validErr.Message)
// }
// }
// }
// return nil
// }
... ...
package query
import (
"fmt"
"reflect"
"strings"
// type ListCompanyQuery struct {
// // 查询偏离量
// Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// // 查询限制
// Limit int `cname:"查询限制" json:"limit" valid:"Required"`
// }
"github.com/beego/beego/v2/core/validation"
)
// func (listCompanyQuery *ListCompanyQuery) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
// }
type ListCompanyQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
}
func (listCompanyQuery *ListCompanyQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listCompanyQuery *ListCompanyQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listCompanyQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listCompanyQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
// func (listCompanyQuery *ListCompanyQuery) ValidateQuery() error {
// valid := validation.Validation{}
// b, err := valid.Valid(listCompanyQuery)
// if err != nil {
// return err
// }
// if !b {
// elem := reflect.TypeOf(listCompanyQuery).Elem()
// for _, validErr := range valid.Errors {
// field, isExist := elem.FieldByName(validErr.Field)
// if isExist {
// return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
// } else {
// return fmt.Errorf(validErr.Message)
// }
// }
// }
// return nil
// }
... ...
... ... @@ -12,9 +12,9 @@ type CompanyService struct {
}
// 创建企业
func (companyService *CompanyService) CreateCompany(createCompanyCommand *command.CreateCompanyCommand) (interface{}, error) {
return nil, nil
}
// func (companyService *CompanyService) CreateCompany(createCompanyCommand *command.CreateCompanyCommand) (interface{}, error) {
// return nil, nil
// }
// 返回企业
func (companyService *CompanyService) GetCompany(getCompanyQuery *query.GetCompanyQuery) (interface{}, error) {
... ... @@ -22,19 +22,19 @@ func (companyService *CompanyService) GetCompany(getCompanyQuery *query.GetCompa
}
// 返回企业列表
func (companyService *CompanyService) ListCompany(listCompanyQuery *query.ListCompanyQuery) (interface{}, error) {
return nil, nil
}
// func (companyService *CompanyService) ListCompany(listCompanyQuery *query.ListCompanyQuery) (interface{}, error) {
// return nil, nil
// }
// 返回自定义菜单列表(匹配有设置的菜单)
func (companyService *CompanyService) ListCompanyCustomizeMenus(listCompanyCustomizeMenusCommand *command.ListCompanyCustomizeMenusCommand) (interface{}, error) {
return nil, nil
}
// func (companyService *CompanyService) ListCompanyCustomizeMenus(listCompanyCustomizeMenusCommand *command.ListCompanyCustomizeMenusCommand) (interface{}, error) {
// return nil, nil
// }
// 移除企业
func (companyService *CompanyService) RemoveCompany(removeCompanyCommand *command.RemoveCompanyCommand) (interface{}, error) {
return nil, nil
}
// func (companyService *CompanyService) RemoveCompany(removeCompanyCommand *command.RemoveCompanyCommand) (interface{}, error) {
// return nil, nil
// }
// 更新企业
func (companyService *CompanyService) UpdateCompany(updateCompanyCommand *command.UpdateCompanyCommand) (interface{}, error) {
... ... @@ -53,9 +53,9 @@ func (companyService *CompanyService) UpdateCompany(updateCompanyCommand *comman
}
// 更新自定义菜单
func (companyService *CompanyService) UpdateCompanyCustomizeMenus(updateCompanyCustomizeMenusCommand *command.UpdateCompanyCustomizeMenusCommand) (interface{}, error) {
return nil, nil
}
// func (companyService *CompanyService) UpdateCompanyCustomizeMenus(updateCompanyCustomizeMenusCommand *command.UpdateCompanyCustomizeMenusCommand) (interface{}, error) {
// return nil, nil
// }
func NewCompanyService(options map[string]interface{}) *CompanyService {
newCompanyService := &CompanyService{}
... ...
... ... @@ -10,13 +10,13 @@ type CompanyController struct {
baseController
}
func (controller *CompanyController) CreateCompany() {
companyService := service.NewCompanyService(nil)
createCompanyCommand := &command.CreateCompanyCommand{}
controller.Unmarshal(createCompanyCommand)
data, err := companyService.CreateCompany(createCompanyCommand)
controller.Response(data, err)
}
// func (controller *CompanyController) CreateCompany() {
// companyService := service.NewCompanyService(nil)
// createCompanyCommand := &command.CreateCompanyCommand{}
// controller.Unmarshal(createCompanyCommand)
// data, err := companyService.CreateCompany(createCompanyCommand)
// controller.Response(data, err)
// }
func (controller *CompanyController) UpdateCompany() {
companyService := service.NewCompanyService(nil)
... ... @@ -36,40 +36,40 @@ func (controller *CompanyController) GetCompany() {
controller.Response(data, err)
}
func (controller *CompanyController) RemoveCompany() {
companyService := service.NewCompanyService(nil)
removeCompanyCommand := &command.RemoveCompanyCommand{}
controller.Unmarshal(removeCompanyCommand)
companyId, _ := controller.GetInt64(":companyId")
removeCompanyCommand.CompanyId = companyId
data, err := companyService.RemoveCompany(removeCompanyCommand)
controller.Response(data, err)
}
// func (controller *CompanyController) RemoveCompany() {
// companyService := service.NewCompanyService(nil)
// removeCompanyCommand := &command.RemoveCompanyCommand{}
// controller.Unmarshal(removeCompanyCommand)
// companyId, _ := controller.GetInt64(":companyId")
// removeCompanyCommand.CompanyId = companyId
// data, err := companyService.RemoveCompany(removeCompanyCommand)
// controller.Response(data, err)
// }
func (controller *CompanyController) ListCompany() {
companyService := service.NewCompanyService(nil)
listCompanyQuery := &query.ListCompanyQuery{}
data, err := companyService.ListCompany(listCompanyQuery)
controller.Response(data, err)
}
// func (controller *CompanyController) ListCompany() {
// companyService := service.NewCompanyService(nil)
// listCompanyQuery := &query.ListCompanyQuery{}
// data, err := companyService.ListCompany(listCompanyQuery)
// controller.Response(data, err)
// }
func (controller *CompanyController) ListCompanyCustomizeMenus() {
companyService := service.NewCompanyService(nil)
listCompanyCustomizeMenusCommand := &command.ListCompanyCustomizeMenusCommand{}
controller.Unmarshal(listCompanyCustomizeMenusCommand)
companyId, _ := controller.GetInt64(":companyId")
listCompanyCustomizeMenusCommand.CompanyId = companyId
listCompanyCustomizeMenusCommand.MenuCategory = controller.GetString("menuCategory")
data, err := companyService.ListCompanyCustomizeMenus(listCompanyCustomizeMenusCommand)
controller.Response(data, err)
}
// func (controller *CompanyController) ListCompanyCustomizeMenus() {
// companyService := service.NewCompanyService(nil)
// listCompanyCustomizeMenusCommand := &command.ListCompanyCustomizeMenusCommand{}
// controller.Unmarshal(listCompanyCustomizeMenusCommand)
// companyId, _ := controller.GetInt64(":companyId")
// listCompanyCustomizeMenusCommand.CompanyId = companyId
// listCompanyCustomizeMenusCommand.MenuCategory = controller.GetString("menuCategory")
// data, err := companyService.ListCompanyCustomizeMenus(listCompanyCustomizeMenusCommand)
// controller.Response(data, err)
// }
func (controller *CompanyController) UpdateCompanyCustomizeMenus() {
companyService := service.NewCompanyService(nil)
updateCompanyCustomizeMenusCommand := &command.UpdateCompanyCustomizeMenusCommand{}
controller.Unmarshal(updateCompanyCustomizeMenusCommand)
companyId, _ := controller.GetInt64(":companyId")
updateCompanyCustomizeMenusCommand.CompanyId = companyId
data, err := companyService.UpdateCompanyCustomizeMenus(updateCompanyCustomizeMenusCommand)
controller.Response(data, err)
}
// func (controller *CompanyController) UpdateCompanyCustomizeMenus() {
// companyService := service.NewCompanyService(nil)
// updateCompanyCustomizeMenusCommand := &command.UpdateCompanyCustomizeMenusCommand{}
// controller.Unmarshal(updateCompanyCustomizeMenusCommand)
// companyId, _ := controller.GetInt64(":companyId")
// updateCompanyCustomizeMenusCommand.CompanyId = companyId
// data, err := companyService.UpdateCompanyCustomizeMenus(updateCompanyCustomizeMenusCommand)
// controller.Response(data, err)
// }
... ...