feat:完善信息
This commit is contained in:
82
app/api/admin/controller/technology/project.go
Normal file
82
app/api/admin/controller/technology/project.go
Normal file
@ -0,0 +1,82 @@
|
||||
package technology
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Project struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type ProjectHandle func(session *session.Admin) *Project
|
||||
|
||||
type (
|
||||
// ProjectInstance 项目信息
|
||||
ProjectInstance struct {
|
||||
ID string `json:"id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
*model2.TechnologyProject
|
||||
Area string `json:"area"`
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Project) Instance(tenantID uint64, title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mTechnologyProject := model.NewTechnologyProject()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("p.tenant_id", c.TenantID))
|
||||
}
|
||||
if tenantID > 0 {
|
||||
where = append(where, model2.NewWhere("p.tenant_id", tenantID))
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("p.name", title))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mTechnologyProject.Projects(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ProjectInstance, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &ProjectInstance{
|
||||
ID: v.GetEncodeID(), TenantID: v.GetEncodeTenantID(),
|
||||
TechnologyProject: v.TechnologyProject, Area: v.FormatBasic(),
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Project) Delete(id uint64) error {
|
||||
mTechnologyProject := model.NewTechnologyProject()
|
||||
mTechnologyProject.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyProject.TechnologyProject, []string{"id", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,产品信息不存在或已被删除")
|
||||
}
|
||||
if c.TenantID > 0 && c.TenantID != mTechnologyProject.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
return model2.Delete(mTechnologyProject.TechnologyProject)
|
||||
}
|
||||
|
||||
func NewProject() ProjectHandle {
|
||||
return func(session *session.Admin) *Project {
|
||||
return &Project{session}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user