From 91c9a2c7f91a05f7a4f121d8ba8ef3bdcd29c727 Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Fri, 26 Mar 2021 13:42:12 +0800 Subject: [PATCH] =?UTF-8?q?fix=F0=9F=90=9B=20=EF=BC=9A=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E6=A8=A1=E5=9D=97=E9=97=AE=E9=A2=98=EF=BC=88?= =?UTF-8?q?#357=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/models/syscategory.go | 6 +- app/admin/models/syscontent.go | 118 ++------------------------ app/admin/service/dto/sys_category.go | 21 ++--- app/admin/service/dto/sys_content.go | 12 +-- 4 files changed, 25 insertions(+), 132 deletions(-) diff --git a/app/admin/models/syscategory.go b/app/admin/models/syscategory.go index b04973d1..219394ca 100644 --- a/app/admin/models/syscategory.go +++ b/app/admin/models/syscategory.go @@ -8,8 +8,8 @@ type SysCategory struct { models.Model Name string `json:"name" gorm:"type:varchar(255);comment:名称"` // Img string `json:"img" gorm:"type:varchar(255);comment:图标"` // - Sort string `json:"sort" gorm:"type:int(4);comment:排序"` // - Status string `json:"status" gorm:"type:int(1);comment:状态"` // + Sort int `json:"sort" gorm:"type:int(4);comment:排序"` // + Status int `json:"status" gorm:"type:int(1);comment:状态"` // Remark string `json:"remark" gorm:"type:varchar(255);comment:备注"` // models.ControlBy models.ModelTime @@ -26,4 +26,4 @@ func (e *SysCategory) Generate() models.ActiveRecord { func (e *SysCategory) GetId() interface{} { return e.Id -} +} \ No newline at end of file diff --git a/app/admin/models/syscontent.go b/app/admin/models/syscontent.go index 420dd5f3..093d2ba1 100644 --- a/app/admin/models/syscontent.go +++ b/app/admin/models/syscontent.go @@ -5,22 +5,24 @@ import ( ) type SysContent struct { - Id int `json:"id" gorm:"type:int(11);primaryKey;autoIncrement"` // id - CateId string `json:"cateId" gorm:"type:int(11);comment:分类id"` + models.Model + CateId int `json:"cateId" gorm:"type:int(11);comment:分类id"` Name string `json:"name" gorm:"type:varchar(255);comment:名称"` - Status string `json:"status" gorm:"type:int(1);comment:状态"` + Status int `json:"status" gorm:"type:int(1);comment:状态"` Img string `json:"img" gorm:"type:varchar(255);comment:图片"` Content string `json:"content" gorm:"type:text;comment:内容"` Remark string `json:"remark" gorm:"type:varchar(255);comment:备注"` - Sort string `json:"sort" gorm:"type:int(4);comment:排序"` + Sort int `json:"sort" gorm:"type:int(4);comment:排序"` models.ControlBy models.ModelTime } +// TableName func (SysContent) TableName() string { return "sys_content" } +// Generate func (e *SysContent) Generate() models.ActiveRecord { o := *e return &o @@ -28,110 +30,4 @@ func (e *SysContent) Generate() models.ActiveRecord { func (e *SysContent) GetId() interface{} { return e.Id -} - -//// 创建SysContent -//func (e *SysContent) Create() (SysContent, error) { -// var doc SysContent -// result := orm.Eloquent.Table(e.TableName()).Create(&e) -// if result.Error != nil { -// err := result.Error -// return doc, err -// } -// doc = *e -// return doc, nil -//} -// -//// 获取SysContent -//func (e *SysContent) Get() (SysContent, error) { -// var doc SysContent -// table := orm.Eloquent.Table(e.TableName()) -// -// if e.Id != 0 { -// table = table.Where("id = ?", e.Id) -// } -// -// if e.CateId != "" { -// table = table.Where("cate_id = ?", e.CateId) -// } -// -// if e.Name != "" { -// table = table.Where("name like ?", "%"+e.Name+"%") -// } -// -// if e.Status != "" { -// table = table.Where("status = ?", e.Status) -// } -// -// if err := table.First(&doc).Error; err != nil { -// return doc, err -// } -// return doc, nil -//} -// -//// 获取SysContent带分页 -//func (e *SysContent) GetPage(pageSize int, pageIndex int) ([]SysContent, int, error) { -// var doc []SysContent -// -// table := orm.Eloquent.Table(e.TableName()) -// -// if e.CateId != "" { -// table = table.Where("cate_id = ?", e.CateId) -// } -// -// if e.Name != "" { -// table = table.Where("name like ?", "%"+e.Name+"%") -// } -// -// if e.Status != "" { -// table = table.Where("status = ?", e.Status) -// } -// -// // 数据权限控制(如果不需要数据权限请将此处去掉) -// dataPermission := new(system.DataPermission) -// dataPermission.UserId, _ = tools.StringToInt(e.DataScope) -// table, err := dataPermission.GetDataScope(e.TableName(), table) -// if err != nil { -// return nil, 0, err -// } -// var count int64 -// -// if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil { -// return nil, 0, err -// } -// //table.Where("`deleted_at` IS NULL").Count(&count) -// return doc, int(count), nil -//} -// -//// 更新SysContent -//func (e *SysContent) Update(id int) (update SysContent, err error) { -// if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).First(&update).Error; err != nil { -// return -// } -// -// //参数1:是要修改的数据 -// //参数2:是修改的数据 -// if err = orm.Eloquent.Table(e.TableName()).Model(&update).Where("id = ?", id).Updates(&e).Error; err != nil { -// return -// } -// return -//} -// -//// 删除SysContent -//func (e *SysContent) Delete(id int) (success bool, err error) { -// if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).Delete(&SysContent{}).Error; err != nil { -// success = false -// return -// } -// success = true -// return -//} -// -////批量删除 -//func (e *SysContent) BatchDelete(id []int) (Result bool, err error) { -// if err = orm.Eloquent.Table(e.TableName()).Where("id in (?)", id).Delete(&SysContent{}).Error; err != nil { -// return -// } -// Result = true -// return -//} +} \ No newline at end of file diff --git a/app/admin/service/dto/sys_category.go b/app/admin/service/dto/sys_category.go index 74632f15..7925f680 100644 --- a/app/admin/service/dto/sys_category.go +++ b/app/admin/service/dto/sys_category.go @@ -12,8 +12,8 @@ import ( type SysCategorySearch struct { dto.Pagination `search:"-"` Name string `form:"name" search:"type:exact;column:name;table:sys_category" comment:"名称"` - - Status string `form:"status" search:"type:exact;column:status;table:sys_category" comment:"状态"` + Status string `form:"status" search:"type:exact;column:status;table:sys_category" comment:"状态"` + CateId int `form:"cateId" search:"type:exact;column:cate_id;table:sys_category" comment:"分类id"` } func (m *SysCategorySearch) GetNeedSearch() interface{} { @@ -35,16 +35,11 @@ func (m *SysCategorySearch) Generate() dto.Index { } type SysCategoryControl struct { - ID int `uri:"Id" comment:"标识"` // 标识 - - Name string `json:"name" comment:"名称"` - - Img string `json:"img" comment:"图标"` - - Sort string `json:"sort" comment:"排序"` - - Status string `json:"status" comment:"状态"` - + ID int `uri:"Id" comment:"标识"` + Name string `json:"name" comment:"名称"` + Img string `json:"img" comment:"图标"` + Sort int `json:"sort" comment:"排序"` + Status int `json:"status" comment:"状态"` Remark string `json:"remark" comment:"备注"` } @@ -93,4 +88,4 @@ func (s *SysCategoryById) Generate() dto.Control { func (s *SysCategoryById) GenerateM() (common.ActiveRecord, error) { return &models.SysCategory{}, nil -} +} \ No newline at end of file diff --git a/app/admin/service/dto/sys_content.go b/app/admin/service/dto/sys_content.go index 9d75f7a3..0a639793 100644 --- a/app/admin/service/dto/sys_content.go +++ b/app/admin/service/dto/sys_content.go @@ -11,6 +11,8 @@ import ( type SysContentSearch struct { dto.Pagination `search:"-"` + Name string `form:"name" search:"type:exact;column:name;table:sys_category" comment:"名称"` + Status string `form:"status" search:"type:exact;column:status;table:sys_category" comment:"状态"` } func (m *SysContentSearch) GetNeedSearch() interface{} { @@ -33,13 +35,13 @@ func (m *SysContentSearch) Generate() dto.Index { type SysContentControl struct { ID int `uri:"ID" comment:""` // - CateId string `json:"cateId" comment:""` + CateId int `json:"cateId" comment:""` Name string `json:"name" comment:""` - Status string `json:"status" comment:""` + Status int `json:"status" comment:""` Img string `json:"img" comment:""` Content string `json:"content" comment:""` Remark string `json:"remark" comment:""` - Sort string `json:"sort" comment:""` + Sort int `json:"sort" comment:""` } func (s *SysContentControl) Bind(ctx *gin.Context) error { @@ -63,7 +65,7 @@ func (s *SysContentControl) Generate() dto.Control { func (s *SysContentControl) GenerateM() (common.ActiveRecord, error) { return &models.SysContent{ - Id: s.ID, + Model: common.Model{s.ID}, CateId: s.CateId, Name: s.Name, Status: s.Status, @@ -89,4 +91,4 @@ func (s *SysContentById) Generate() dto.Control { func (s *SysContentById) GenerateM() (common.ActiveRecord, error) { return &models.SysContent{}, nil -} +} \ No newline at end of file