Ai
1 Star 1 Fork 0

water/goweb

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
entity_dto.go 2.05 KB
一键复制 编辑 原始数据 按行查看 历史
leijmdas 提交于 2025-01-19 14:06 +08:00 . add
package metaentity
import (
"gitee.com/leijmdas/gobase/goconfig/common/base/basedata"
"gitee.com/leijmdas/gobase/goconfig/common/base/basedto"
"gitee.com/leijmdas/gobase/goconfig/common/base/fileutils"
"gitee.com/leijmdas/gobase/goconfig/common/base/stringutils"
"gitee.com/leijmdas/gobase/goconfig/common/golog"
"sort"
"strings"
)
const (
SortByType = "type"
SortByName = "name"
)
type EntityDto struct {
basedto.BaseEntity
EntityName string
Fields []*EntityField
SortBy string
*basedata.DataPath
StrategyType int
CodeDto
}
func NewEntityDto() *EntityDto {
var entity = &EntityDto{
Fields: make([]*EntityField, 0),
DataPath: basedata.FindBeanDataPath(),
SortBy: SortByName,
}
entity.InitProxy(entity)
return entity
}
func (self *EntityDto) ToGoEntityName(trimPre bool) string {
var entityName = self.EntityName
if trimPre {
var index = strings.Split(self.EntityName, "_")[1:]
entityName = strings.Join(index, "_")
}
return stringutils.Case2Camel(entityName)
}
func (self *EntityDto) ToGoEntityNameEs(trimPre bool) string {
return self.ToGoEntityName(trimPre) + "Es"
}
func (self *EntityDto) ToGoEntityNameEsCase(trimPre bool) string {
return stringutils.Camel2Case(self.ToGoEntityNameEs(trimPre))
}
func (self *EntityDto) SortByType() {
self.SortBy = SortByType
}
func (self *EntityDto) SortByName() {
self.SortBy = SortByName
}
func (self *EntityDto) Write2File(file string, code string) error {
golog.Info(file, " EntityDtoc code:", code)
return fileutils.WriteBytesFile(file, []byte(code))
}
func (self *EntityDto) SortFields() {
var funSort = func(i, j int) bool {
return self.Fields[i].SortField(self.SortBy, self.Fields[j].EntityGofield)
}
sort.Slice(self.Fields, funSort)
}
func (self *EntityDto) NewField(fileldName, fieldType string) *EntityField {
return NewEntityField(self.StrategyType, fileldName, fieldType)
}
func (self *EntityDto) AppendField(fileldName, fieldType string) *EntityField {
var field = self.NewField(fileldName, fieldType)
field.ToGo()
self.Fields = append(self.Fields, field)
return field
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/leijmdas/goweb.git
git@gitee.com:leijmdas/goweb.git
leijmdas
goweb
goweb
v1.6.111

搜索帮助