feat:完善项目管理

This commit is contained in:
henry
2021-12-13 14:05:11 +08:00
parent a512713ba6
commit 4e1f179af7
6 changed files with 125 additions and 9 deletions

View File

@ -22,14 +22,22 @@ type ManageExpertInfo struct {
SettledAt time.Time `json:"settled_at"`
}
type ManageExpertCompanyVisitInfo struct {
ManageExpertInfo
CompanyName string `json:"company_name"`
VisitAt time.Time `json:"visit_at"`
}
// Experts 专家信息
func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertInfo, error) {
db := orm.GetDB().Table(m.TableName()+" e").
Select("e.id", "e.name", "e.mobile", "e.industry", "v.count AS visit_count", "e.examine_at AS settled_at").
Select("e.id", "e.name", "e.mobile", "e.industry", "v.count AS visit_count", "c.count AS collect_count",
"e.examine_at AS settled_at").
Joins(fmt.Sprintf("LEFT JOIN (SELECT expert_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY expert_id) AS v ON e.id = v.expert_id",
model.NewManageExpertVisit().TableName(), model.DeleteStatusForNot)).
Joins(fmt.Sprintf("LEFT JOIN (SELECT expert_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY expert_id) AS c ON e.id = c.expert_id",
model.NewManageExpertCollect().TableName(), model.DeleteStatusForNot))
model.NewManageExpertCollect().TableName(), model.DeleteStatusForNot)).
Where("e.examine_status = ? AND e.is_deleted = ?", model.ExamineStatusForAgree, model.DeleteStatusForNot)
if len(where) > 0 {
for _, v := range where {
@ -51,6 +59,38 @@ func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model
return out, nil
}
// CompanyVisit 公司浏览记录
func (m *ManageExpert) CompanyVisit(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertCompanyVisitInfo, error) {
db := orm.GetDB().Table(m.TableName()+" e").
Select("e.id", "e.name", "e.mobile", "e.industry", "v.count AS visit_count", "v.date AS visit_at",
"c.name AS company_name").
Joins(fmt.Sprintf("LEFT JOIN %s AS v ON e.id = v.expert_id AND v.is_deleted = %d",
model.NewManageExpertVisit().TableName(), model.DeleteStatusForNot)).
Joins(fmt.Sprintf("LEFT JOIN %s AS u_c ON v.uid = u_c.uid AND u_c.invalid_status = %d",
model.NewUserCompany().TableName(), model.InvalidStatusForNot)).
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u_c.company_id = c.id", model.NewManageCompany().TableName())).
Where("e.examine_status = ? AND e.is_deleted = ?", model.ExamineStatusForAgree, model.DeleteStatusForNot)
if len(where) > 0 {
for _, v := range where {
if v.Condition == "" {
db.Where(v.Value)
continue
}
db = db.Where(v.Condition, v.Value)
}
}
out := make([]*ManageExpertCompanyVisitInfo, 0)
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := db.Order("e.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
}
func NewManageExpert() *ManageExpert {
return &ManageExpert{model.NewManageExpert()}
}

View File

@ -4,6 +4,7 @@ import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
"time"
)
type ManageLaboratory struct {
@ -12,18 +13,20 @@ type ManageLaboratory struct {
type ManageLaboratoryInfo struct {
model.Model
Name string `json:"name"`
Industry string `json:"-"`
Username string `json:"username"`
Mobile string `json:"mobile"`
VisitCount int `json:"visit_count"`
CollectCount int `json:"collect_count"`
Name string `json:"name"`
Industry string `json:"-"`
Username string `json:"username"`
Mobile string `json:"mobile"`
VisitCount int `json:"visit_count"`
CollectCount int `json:"collect_count"`
SettledAt time.Time `json:"settled_at"`
}
// Laboratory 实验室信息
func (m *ManageLaboratory) Laboratory(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageLaboratoryInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS l").
Select("l.id", "l.name", "l.industry", "u.name AS username", "u.mobile", "v.count AS visit_count", "c.count AS collect_count").
Select("l.id", "l.name", "l.industry", "u.name AS username", "u.mobile", "v.count AS visit_count",
"c.count AS collect_count", "l.examine_at AS settled_at").
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON l.uid = u.uuid", model.NewUserInstance().TableName())).
Joins(fmt.Sprintf("LEFT JOIN (SELECT laboratory_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY laboratory_id) AS v ON l.id = v.laboratory_id",
model.NewManageLaboratoryVisit().TableName(), model.DeleteStatusForNot)).

View File

@ -6,6 +6,10 @@ type ManageResearch struct {
*model.ManageResearch
}
func (m *ManageResearch) Expert() {
}
func NewManageResearch() *ManageResearch {
return &ManageResearch{model.NewManageResearch()}
}