test
This commit is contained in:
1 parent
677cdb7821
commit
bc648c3f2f
60 files changed
+2319
-550
No files matched your search
@@ -0,0 +1,89 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
"go-admin/common/log"
|
||||
common "go-admin/common/models"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
type ScolSearch struct {
|
||||
dto.Pagination `search:"-"`
|
||||
Name string `form:"name" search:"type:contains;column:name;table:scol" comment:"名称"`
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (m *ScolSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
func (m *ScolSearch) Bind(ctx *gin.Context) error {
|
||||
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||
err := ctx.ShouldBind(m)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %s", msgID, err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *ScolSearch) Generate() dto.Index {
|
||||
o := *m
|
||||
return &o
|
||||
}
|
||||
|
||||
type ScolControl struct {
|
||||
|
||||
ID uint `uri:"ID" comment:""` //
|
||||
|
||||
Name string `json:"name" comment:"名称"`
|
||||
|
||||
}
|
||||
|
||||
func (s *ScolControl) Bind(ctx *gin.Context) error {
|
||||
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||
err := ctx.ShouldBindUri(s)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
|
||||
return err
|
||||
}
|
||||
err = ctx.ShouldBind(s)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *ScolControl) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *ScolControl) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.Scol{
|
||||
|
||||
Model: gorm.Model{ID: s.ID},
|
||||
Name: s.Name,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *ScolControl) GetId() interface{} {
|
||||
return s.ID
|
||||
}
|
||||
|
||||
type ScolById struct {
|
||||
dto.ObjectById
|
||||
}
|
||||
|
||||
func (s *ScolById) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *ScolById) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.Scol{}, nil
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
"go-admin/common/log"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
|
||||
type StudentSearch struct {
|
||||
dto.Pagination `search:"-"`
|
||||
Name string `form:"name" search:"type:exact;column:name;table:student" comment:"姓名"`
|
||||
}
|
||||
|
||||
func (m *StudentSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
func (m *StudentSearch) Bind(ctx *gin.Context) error {
|
||||
err := ctx.Bind(m)
|
||||
if err != nil {
|
||||
log.Errorf("MsgID[%s] Bind error: %#v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *StudentSearch) Generate() dto.Index {
|
||||
o := *m
|
||||
return &o
|
||||
}
|
||||
|
||||
type StudentControl struct {
|
||||
ID uint `uri:"ID" comment:""` //
|
||||
Name string `json:"name" comment:"姓名"`
|
||||
}
|
||||
|
||||
func (s *StudentControl) Bind(ctx *gin.Context) error {
|
||||
err := ctx.BindUri(s)
|
||||
if err != nil {
|
||||
log.Errorf("MsgID[%s] Bind error: %#v", err)
|
||||
return err
|
||||
}
|
||||
err = ctx.Bind(s)
|
||||
if err != nil {
|
||||
log.Errorf("MsgID[%s] Bind error: %#v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *StudentControl) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *StudentControl) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.Student{
|
||||
|
||||
Model: gorm.Model{ID: s.ID},
|
||||
Name: s.Name,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *StudentControl) GetId() interface{} {
|
||||
return s.ID
|
||||
}
|
||||
|
||||
type StudentById struct {
|
||||
dto.ObjectById
|
||||
}
|
||||
|
||||
func (s *StudentById) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *StudentById) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.Student{}, nil
|
||||
}
|
||||
|
||||
type StudentItem struct {
|
||||
gorm.Model
|
||||
common.ControlBy
|
||||
Name string `json:"name" gorm:"type:varchar(255);comment:姓名"` //
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func (m *SysJobSearch) Generate() dto.Index {
|
||||
}
|
||||
|
||||
type SysJobControl struct {
|
||||
JobId int `json:"jobId"`
|
||||
JobId uint `json:"jobId"`
|
||||
JobName string `json:"jobName" validate:"required"` // 名称
|
||||
JobGroup string `json:"jobGroup"` // 任务分组
|
||||
JobType int `json:"jobType"` // 任务类型
|
||||
@@ -93,7 +93,7 @@ func (s *SysJobById) GenerateM() (common.ActiveRecord, error) {
|
||||
}
|
||||
|
||||
type SysJobItem struct {
|
||||
JobId int `json:"jobId"`
|
||||
JobId uint `json:"jobId"`
|
||||
JobName string `json:"jobName" validate:"required"` // 名称
|
||||
JobGroup string `json:"jobGroup"` // 任务分组
|
||||
JobType int `json:"jobType"` // 任务类型
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/actions"
|
||||
cDto "go-admin/common/dto"
|
||||
"go-admin/common/log"
|
||||
common "go-admin/common/models"
|
||||
"go-admin/common/service"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Scol struct {
|
||||
service.Service
|
||||
}
|
||||
|
||||
// GetScolPage 获取Scol列表
|
||||
func (e *Scol) GetScolPage(c cDto.Index, p *actions.DataPermission, list *[]models.Scol, count *int64) error {
|
||||
var err error
|
||||
var data models.Scol
|
||||
msgID := e.MsgID
|
||||
|
||||
err = e.Orm.Table(data.TableName()).
|
||||
Scopes(
|
||||
cDto.MakeCondition(c.GetNeedSearch()),
|
||||
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
||||
actions.Permission(data.TableName(), p),
|
||||
).
|
||||
Find(list).Limit(-1).Offset(-1).
|
||||
Count(count).Error
|
||||
if err != nil {
|
||||
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetScol 获取Scol对象
|
||||
func (e *Scol) GetScol(c cDto.Control, p *actions.DataPermission, m *common.ActiveRecord) error {
|
||||
var err error
|
||||
var data models.Scol
|
||||
msgID := e.MsgID
|
||||
|
||||
db := e.Orm.Table(data.TableName()).
|
||||
Scopes(
|
||||
actions.Permission(data.TableName(), p),
|
||||
).Where(c.GetId()).First(m)
|
||||
err = db.Error
|
||||
|
||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
err = errors.New("查看对象不存在或无权查看")
|
||||
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||
return err
|
||||
}
|
||||
if db.Error != nil {
|
||||
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InsertScol 创建Scol对象
|
||||
func (e *Scol) InsertScol(model common.ActiveRecord) error {
|
||||
var err error
|
||||
var data models.Scol
|
||||
msgID := e.MsgID
|
||||
|
||||
err = e.Orm.Table(data.TableName()).
|
||||
Create(model).Error
|
||||
if err != nil {
|
||||
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateScol 修改Scol对象
|
||||
func (e *Scol) UpdateScol(c common.ActiveRecord, p *actions.DataPermission) error {
|
||||
var err error
|
||||
var data models.Scol
|
||||
msgID := e.MsgID
|
||||
|
||||
db := e.Orm.Table(data.TableName()).
|
||||
Scopes(
|
||||
actions.Permission(data.TableName(), p),
|
||||
).Where(c.GetId()).Updates(c)
|
||||
if db.Error != nil {
|
||||
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||
return err
|
||||
}
|
||||
if db.RowsAffected == 0 {
|
||||
return errors.New("无权更新该数据")
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveScol 删除Scol
|
||||
func (e *Scol) RemoveScol(d cDto.Control, c common.ActiveRecord, p *actions.DataPermission) error {
|
||||
var err error
|
||||
var data models.Scol
|
||||
msgID := e.MsgID
|
||||
|
||||
db := e.Orm.Table(data.TableName()).
|
||||
Scopes(
|
||||
actions.Permission(data.TableName(), p),
|
||||
).Where(d.GetId()).Delete(c)
|
||||
if db.Error != nil {
|
||||
err = db.Error
|
||||
log.Errorf("MsgID[%s] Delete error: %s", msgID, err)
|
||||
return err
|
||||
}
|
||||
if db.RowsAffected == 0 {
|
||||
err = errors.New("无权删除该数据")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/app/admin/service/dto"
|
||||
"go-admin/common/actions"
|
||||
cDto "go-admin/common/dto"
|
||||
"go-admin/common/log"
|
||||
common "go-admin/common/models"
|
||||
"go-admin/common/service"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Student struct {
|
||||
service.Service
|
||||
}
|
||||
|
||||
// GetStudentPage 获取student列表
|
||||
func (e *Student) GetStudentPage(c cDto.Index, p *actions.DataPermission, list *[]models.Student, count *int64) error {
|
||||
var err error
|
||||
var data models.Student
|
||||
msgID := e.MsgID
|
||||
|
||||
err = e.Orm.Table(data.TableName()).
|
||||
Scopes(
|
||||
cDto.MakeCondition(c.GetNeedSearch()),
|
||||
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
||||
actions.Permission(data.TableName(), p),
|
||||
).
|
||||
Find(list).Limit(-1).Offset(-1).
|
||||
Count(count).Error
|
||||
if err != nil {
|
||||
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetStudent 获取student对象
|
||||
func (e *Student) GetStudent(c *dto.StudentSearch, p *actions.DataPermission, model *common.ActiveRecord) error {
|
||||
var err error
|
||||
var data models.Student
|
||||
msgID := e.MsgID
|
||||
|
||||
db := e.Orm.Table(data.TableName()).
|
||||
Scopes(
|
||||
cDto.MakeCondition(c.GetNeedSearch()),
|
||||
actions.Permission(data.TableName(), p),
|
||||
).
|
||||
First(model)
|
||||
err = db.Error
|
||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
err = errors.New("查看对象不存在或无权查看")
|
||||
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||
return err
|
||||
}
|
||||
if db.Error != nil {
|
||||
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InsertStudent 创建student对象
|
||||
func (e *Student) InsertStudent(model common.ActiveRecord) error {
|
||||
var err error
|
||||
var data models.Student
|
||||
msgID := e.MsgID
|
||||
|
||||
err = e.Orm.Table(data.TableName()).
|
||||
Create(model).Error
|
||||
if err != nil {
|
||||
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateStudent 修改student对象
|
||||
func (e *Student) UpdateStudent(c common.ActiveRecord, p *actions.DataPermission) error {
|
||||
var err error
|
||||
var data models.Student
|
||||
msgID := e.MsgID
|
||||
|
||||
db := e.Orm.Table(data.TableName()).
|
||||
Scopes(
|
||||
actions.Permission(data.TableName(), p),
|
||||
).Where(c.GetId()).Updates(c)
|
||||
if db.Error != nil {
|
||||
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||
return err
|
||||
}
|
||||
if db.RowsAffected == 0 {
|
||||
return errors.New("无权更新该数据")
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveStudent 删除student
|
||||
func (e *Student) RemoveStudent(c common.ActiveRecord, p *actions.DataPermission) error {
|
||||
var err error
|
||||
var data models.Student
|
||||
msgID := e.MsgID
|
||||
|
||||
db := e.Orm.Table(data.TableName()).
|
||||
Scopes(
|
||||
actions.Permission(data.TableName(), p),
|
||||
).Where(c.GetId()).Delete(c)
|
||||
if db.Error != nil {
|
||||
err = db.Error
|
||||
log.Errorf("MsgID[%s] Delete error: %s", msgID, err)
|
||||
return err
|
||||
}
|
||||
if db.RowsAffected == 0 {
|
||||
err = errors.New("无权删除该数据")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user