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

@ -221,3 +221,17 @@ func (*Manage) ResearchLaboratory(c *gin.Context) {
Laboratory(form.Name, form.Page, form.PageSize)
api.APIResponse(err, data)(c)
}
func (*Manage) ResearchVisit(c *gin.Context) {
form := &struct {
CompanyName string `json:"company_name" form:"company_name"`
api.PageForm
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := manage.NewResearch()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
Visit(form.Page, form.PageSize)
api.APIResponse(err, data)(c)
}

View File

@ -6,6 +6,8 @@ import (
model2 "SciencesServer/app/common/model"
"SciencesServer/app/session"
"errors"
"fmt"
"strings"
)
type Research struct {
@ -22,6 +24,11 @@ type (
*model.ManageLaboratoryInfo
Industrys []string `json:"industrys"`
}
// ResearchVisit 浏览信息
ResearchVisit struct {
ID string `json:"id"`
*model.ManageExpertCompanyVisitInfo
}
)
// Laboratory 实验室信息
@ -65,6 +72,53 @@ func (c *Research) Laboratory(title string, page, pageSize int) (*controller.Ret
return &controller.ReturnPages{Data: list, Count: count}, nil
}
// Visit 访问记录
func (c *Research) Visit(page, pageSize int) (interface{}, error) {
// 获取当前科研机构下所有的专家人员
mUserResearch := model.NewUserResearch()
isExist, err := model2.FirstField(mUserResearch.UserResearch, []string{"id", "research_id"},
model2.NewWhere("uid", c.UID), model2.NewWhere("invalid_status", model2.InvalidStatusForNot))
if err != nil {
return nil, err
} else if !isExist {
return nil, errors.New("操作错误,无权限查看")
}
// 查询科研机构下所有实验室
mManageLaboratory := model.NewManageLaboratory()
// 用String去接受参数
laboratoryIDs := make([]string, 0)
if err = model2.Pluck(mManageLaboratory.ManageLaboratory, "id", &laboratoryIDs,
model2.NewWhere("research_id", mUserResearch.ResearchID)); err != nil {
return nil, err
}
where := make([]*model2.ModelWhere, 0)
where = append(where, model2.NewWhere("e.research_id = ?", mUserResearch.ResearchID),
model2.NewWhereValue(fmt.Sprintf("(e.laboratory_id = %d) OR (e.laboratory_id IN (%v))",
0, strings.Join(laboratoryIDs, ","))))
mManageExpert := model.NewManageExpert()
var count int64
out := make([]*model.ManageExpertCompanyVisitInfo, 0)
if out, err = mManageExpert.CompanyVisit(page, pageSize, &count, where...); err != nil {
return nil, err
}
list := make([]*ResearchVisit, 0)
for _, v := range out {
list = append(list, &ResearchVisit{
ID: v.GetEncodeID(),
ManageExpertCompanyVisitInfo: v,
})
}
return &controller.ReturnPages{Data: list, Count: count}, err
}
func NewResearch() ResearchHandle {
return func(session *session.Enterprise, local string) *Research {
return &Research{

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()}
}

View File

@ -245,6 +245,7 @@ func registerEnterpriseAPI(app *gin.Engine) {
manageV1.POST("/company/product", _api.CompanyProduct)
manageV1.POST("/expert", _api.Expert)
manageV1.POST("/research/laboratory", _api.ResearchLaboratory)
manageV1.POST("/research/visit", _api.ResearchVisit)
}
// Activity 活动信息
activityV1 := v1.Group("/activity")