Files
2021-12-22 14:11:14 +08:00

101 lines
2.7 KiB
Go

package technology
import (
"SciencesServer/app/api/website/model"
"SciencesServer/app/basic/controller"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/session"
"errors"
"fmt"
"time"
)
type Demand struct {
*session.Enterprise
}
type DemandHandle func(session *session.Enterprise) *Demand
type (
// DemandInfo 需求基本信息
DemandInfo struct {
ID string `json:"id"`
Kinds []string `json:"kinds"`
Industrys []string `json:"industrys"`
Deadline time.Time `json:"deadline"`
}
// DemandDetailInfo 需求详细信息
DemandDetailInfo struct {
ID string `json:"id"`
*model2.TechnologyDemand
Kinds []string `json:"kinds"`
Industrys []string `json:"industrys"`
}
)
// Instance 需求信息
func (c *Demand) Instance(title, industry, kind string, page, pageSize int) (*controller.ReturnPages, error) {
mTechnologyDemand := model.NewTechnologyDemand()
out := make([]*model2.TechnologyDemand, 0)
var count int64
where := []*model2.ModelWhereOrder{
&model2.ModelWhereOrder{
Where: model2.NewWhere("status", model2.TechnologyDemandStatusForAgree),
Order: model2.NewOrder("id", model2.OrderModeToDesc),
},
}
if title != "" {
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhere("title", title)})
}
if industry != "" {
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhereCondition("industry", "LIKE",
"%"+fmt.Sprintf(`"%v`, industry)+"%")})
}
if kind != "" {
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhereLike("kind", kind)})
}
err := model2.PagesFields(mTechnologyDemand.TechnologyDemand, &out, []string{}, 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(), Kinds: v.GetKindAttribute(),
Industrys: v.GetIndustryAttribute(), Deadline: v.Deadline,
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
}
// 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(),
TechnologyDemand: mTechnologyDemand.TechnologyDemand,
Kinds: mTechnologyDemand.GetKindAttribute(),
Industrys: mTechnologyDemand.GetIndustryAttribute(),
}, nil
}
func NewDemand() DemandHandle {
return func(session *session.Enterprise) *Demand {
return &Demand{Enterprise: session}
}
}