46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package model
|
||
|
||
import (
|
||
"SciencesServer/app/common/model"
|
||
"SciencesServer/serve/orm"
|
||
"fmt"
|
||
"time"
|
||
)
|
||
|
||
type ManageCompany struct {
|
||
*model.ManageCompany
|
||
}
|
||
|
||
// ManageCompanyInfo 公司信息,包含公司下需求信息
|
||
type ManageCompanyInfo struct {
|
||
model.Model
|
||
Name string `json:"name"`
|
||
SettledAt time.Time `json:"settled_at"`
|
||
}
|
||
|
||
func (m *ManageCompany) Company(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageCompanyInfo, error) {
|
||
// TODO:未完成功能
|
||
db := orm.GetDB().Table(m.TableName()+" AS c").
|
||
Select("c.id", "c.name", "c.industry", "c.examine_at AS settled_at").
|
||
Joins(fmt.Sprintf("LEFT JOIN (SELECT * FROM %s AS u_c)"))
|
||
|
||
if len(where) > 0 {
|
||
for _, v := range where {
|
||
db = db.Where(v.Condition, v.Value)
|
||
}
|
||
}
|
||
out := make([]*ManageCompanyInfo, 0)
|
||
|
||
if err := db.Count(count).Error; err != nil {
|
||
return nil, err
|
||
}
|
||
if err := db.Order("c.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||
return nil, err
|
||
}
|
||
return out, nil
|
||
}
|
||
|
||
func NewManageCompany() *ManageCompany {
|
||
return &ManageCompany{model.NewManageCompany()}
|
||
}
|