feat:完善项目
This commit is contained in:
@ -1,6 +1,12 @@
|
||||
package technology
|
||||
|
||||
import "SciencesServer/app/session"
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Demand struct {
|
||||
*session.Admin
|
||||
@ -8,12 +14,92 @@ type Demand struct {
|
||||
|
||||
type DemandHandle func(session *session.Admin) *Demand
|
||||
|
||||
func (c *Demand) Instance(tenantID uint64, page, pageSize int) {
|
||||
type (
|
||||
// DemandInfo 需求信息
|
||||
DemandInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model.TechnologyDemandInfo
|
||||
Area string `json:"area"`
|
||||
}
|
||||
// DemandDetailInfo 需求详细信息
|
||||
DemandDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
*model2.TechnologyDemand
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Demand) Instance(tenantID uint64, title string, kind, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mTechnologyDemand := model.NewTechnologyDemand()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("d.tenant_id", c.TenantID))
|
||||
}
|
||||
if tenantID > 0 {
|
||||
where = append(where, model2.NewWhere("d.tenant_id", tenantID))
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("d.title", title))
|
||||
}
|
||||
if kind > 0 {
|
||||
where = append(where, model2.NewWhere("d.kind", kind))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mTechnologyDemand.Demand(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*DemandInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &DemandInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
TechnologyDemandInfo: v,
|
||||
Area: v.FormatBasic(),
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func (c *Demand) Delete() {
|
||||
// Detail 详细信息
|
||||
func (c *Demand) Detail(id uint64) (*DemandDetailInfo, error) {
|
||||
mTechnologyDemand := model.NewTechnologyDemand()
|
||||
mTechnologyDemand.ID = id
|
||||
|
||||
isExist, err := model2.First(mTechnologyDemand.TechnologyDemand)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,需求信息不存在或已被删除")
|
||||
}
|
||||
return &DemandDetailInfo{
|
||||
ID: mTechnologyDemand.GetEncodeID(),
|
||||
TenantID: mTechnologyDemand.GetEncodeTenantID(),
|
||||
TechnologyDemand: mTechnologyDemand.TechnologyDemand,
|
||||
}, err
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Demand) Delete(id uint64) error {
|
||||
mTechnologyDemand := model.NewTechnologyDemand()
|
||||
mTechnologyDemand.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyDemand.TechnologyDemand, []string{"id", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,需求信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mTechnologyDemand.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
return model2.Delete(mTechnologyDemand.TechnologyDemand)
|
||||
}
|
||||
|
||||
func NewDemand() DemandHandle {
|
||||
|
Reference in New Issue
Block a user