feat:完善项目管理,增加科研机构下实验室列表信息
This commit is contained in:
@ -207,3 +207,17 @@ func (*Manage) Expert(c *gin.Context) {
|
||||
Instance(form.Name, form.Mobile, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) ResearchLaboratory(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"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)).
|
||||
Laboratory(form.Name, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
@ -32,11 +33,13 @@ func (c *Expert) research(page, pageSize int, count *int64, where ...*model2.Mod
|
||||
// 实验室下存在专家
|
||||
mUserResearch := model.NewUserResearch()
|
||||
|
||||
_, err := model2.FirstField(mUserResearch.UserResearch, []string{"id", "research_id"},
|
||||
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()
|
||||
@ -107,6 +110,7 @@ func (c *Expert) Instance(name, mobile string, page, pageSize int) (*controller.
|
||||
out, err = c.research(page, pageSize, &count, where...)
|
||||
// 实验室
|
||||
} else if c.Identity == config.TenantUserIdentityForLaboratory {
|
||||
out, err = c.laboratory(page, pageSize, &count, where...)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
32
app/api/enterprise/controller/manage/laboratory.go
Normal file
32
app/api/enterprise/controller/manage/laboratory.go
Normal file
@ -0,0 +1,32 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"SciencesServer/app/basic/controller"
|
||||
"SciencesServer/app/session"
|
||||
)
|
||||
|
||||
type Laboratory struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type LaboratoryHandle func(session *session.Enterprise, local string) *Laboratory
|
||||
|
||||
func (c *Laboratory) Instance() (*controller.ReturnPages, error) {
|
||||
//mManageLaboratory := model.NewManageLaboratory()
|
||||
|
||||
//out := make([]*model2.ManageLaboratory, 0)
|
||||
|
||||
//model2.PagesFields(mManageLaboratory.ManageLaboratory, &out)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func NewLaboratory() LaboratoryHandle {
|
||||
return func(session *session.Enterprise, local string) *Laboratory {
|
||||
return &Laboratory{
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
75
app/api/enterprise/controller/manage/research.go
Normal file
75
app/api/enterprise/controller/manage/research.go
Normal file
@ -0,0 +1,75 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Research struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type ResearchHandle func(session *session.Enterprise, local string) *Research
|
||||
|
||||
type (
|
||||
// ResearchLaboratory 科研机构下实验室信息
|
||||
ResearchLaboratory struct {
|
||||
ID string `json:"id"`
|
||||
*model.ManageLaboratoryInfo
|
||||
Industrys []string `json:"industrys"`
|
||||
}
|
||||
)
|
||||
|
||||
// Laboratory 实验室信息
|
||||
func (c *Research) Laboratory(title string, page, pageSize int) (*controller.ReturnPages, 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("操作错误,无权限查看")
|
||||
}
|
||||
where := []*model2.ModelWhere{model2.NewWhere("research_id", mUserResearch.ResearchID)}
|
||||
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("title", title))
|
||||
}
|
||||
mManageLaboratory := model.NewManageLaboratory()
|
||||
|
||||
out := make([]*model.ManageLaboratoryInfo, 0)
|
||||
|
||||
var count int64
|
||||
|
||||
if out, err = mManageLaboratory.Laboratory(page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ResearchLaboratory, 0)
|
||||
|
||||
for _, v := range out {
|
||||
mManageLaboratory.Industry = v.Industry
|
||||
|
||||
list = append(list, &ResearchLaboratory{
|
||||
ID: v.GetEncodeID(),
|
||||
ManageLaboratoryInfo: v,
|
||||
Industrys: mManageLaboratory.GetIndustryAttribute(),
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func NewResearch() ResearchHandle {
|
||||
return func(session *session.Enterprise, local string) *Research {
|
||||
return &Research{
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ type ManageExpertInfo struct {
|
||||
// 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.visit_count", "e.examine_at AS settled_at").
|
||||
Select("e.id", "e.name", "e.mobile", "e.industry", "v.count AS visit_count", "e.examine_at AS settled_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS v ON e.id = v.expert_id AND v.is_deleted = %d",
|
||||
model.NewManageExpertVisit().TableName(), model.DeleteStatusForNot))
|
||||
|
||||
|
@ -1,11 +1,51 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ManageLaboratory struct {
|
||||
*model.ManageLaboratory
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
// 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").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON l.uid = u.uuid", model.NewUserInstance().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS v ON l.id = v.laboratory_id AND v.is_deleted = %d",
|
||||
model.NewManageLaboratoryVisit().TableName(), model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT laboratory_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY laboratory_id) AS c ON l.id = c.laboratory_id",
|
||||
model.NewManageLaboratoryCollect().TableName(), model.DeleteStatusForNot))
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ManageLaboratoryInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("l.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewManageLaboratory() *ManageLaboratory {
|
||||
return &ManageLaboratory{model.NewManageLaboratory()}
|
||||
}
|
||||
|
@ -2,11 +2,12 @@ package model
|
||||
|
||||
import "time"
|
||||
|
||||
// ManageExpertVisit 专家浏览记录数据模型
|
||||
type ManageExpertVisit struct {
|
||||
Model
|
||||
ExpertID uint64 `gorm:"column:expert_id;index:idx_product_visit_product;type:int(11);default:0;comment:专家ID" json:"-"`
|
||||
VisitCount int `gorm:"column:visit_count;type:int(8);default:0;comment:浏览次数" json:"visit_count"`
|
||||
VisitAt time.Time `gorm:"column:visit_at;type:datetime;not null;comment:浏览时间" json:"visit_at"`
|
||||
ExpertID uint64 `gorm:"column:expert_id;index:idx_expert_visit_expert;type:int(11);default:0;comment:专家ID" json:"-"`
|
||||
Count int `gorm:"column:count;type:int(8);default:0;comment:浏览次数" json:"count"`
|
||||
Date time.Time `gorm:"column:date;type:datetime;not null;comment:浏览时间" json:"date"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
18
app/common/model/manage_laboratory_collect.go
Normal file
18
app/common/model/manage_laboratory_collect.go
Normal file
@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
// ManageLaboratoryCollect 实验室收藏数据模型
|
||||
type ManageLaboratoryCollect struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
LaboratoryID uint64 `gorm:"column:laboratory_id;type:int(11);default:0;comment:实验室ID" json:"-"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *ManageLaboratoryCollect) TableName() string {
|
||||
return "manage_laboratory_collect"
|
||||
}
|
||||
|
||||
func NewManageLaboratoryCollect() *ManageLaboratoryCollect {
|
||||
return &ManageLaboratoryCollect{}
|
||||
}
|
21
app/common/model/manage_laboratory_visit.go
Normal file
21
app/common/model/manage_laboratory_visit.go
Normal file
@ -0,0 +1,21 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// ManageLaboratoryVisit 实验室浏览记录数据模型
|
||||
type ManageLaboratoryVisit struct {
|
||||
Model
|
||||
LaboratoryID uint64 `gorm:"column:laboratory_id;index:idx_laboratory_visit_laboratory;type:int(11);default:0;comment:实验室ID" json:"-"`
|
||||
Count int `gorm:"column:count;type:int(8);default:0;comment:浏览次数" json:"count"`
|
||||
Date time.Time `gorm:"column:date;type:datetime;not null;comment:浏览时间" json:"date"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *ManageLaboratoryVisit) TableName() string {
|
||||
return "manage_laboratory_visit"
|
||||
}
|
||||
|
||||
func NewManageLaboratoryVisit() *ManageLaboratoryVisit {
|
||||
return &ManageLaboratoryVisit{}
|
||||
}
|
@ -5,10 +5,10 @@ import "time"
|
||||
// TechnologyProductVisit 技术产品访问数据模型
|
||||
type TechnologyProductVisit struct {
|
||||
Model
|
||||
ProductID uint64 `gorm:"column:product_id;index:idx_product_visit_product;type:int(11);default:0;comment:科技产品ID" json:"product_id"`
|
||||
CompanyID uint64 `gorm:"column:company_id;type:int(11);default:0;comment:公司ID" json:"company_id"`
|
||||
VisitCount int `gorm:"column:visit_count;type:int(8);default:0;comment:浏览次数" json:"visit_count"`
|
||||
VisitAt time.Time `gorm:"column:visit_at;type:datetime;not null;comment:浏览时间" json:"visit_at"`
|
||||
ProductID uint64 `gorm:"column:product_id;index:idx_product_visit_product;type:int(11);default:0;comment:科技产品ID" json:"product_id"`
|
||||
CompanyID uint64 `gorm:"column:company_id;type:int(11);default:0;comment:公司ID" json:"company_id"`
|
||||
Count int `gorm:"column:count;type:int(8);default:0;comment:浏览次数" json:"count"`
|
||||
Date time.Time `gorm:"column:date;type:datetime;not null;comment:浏览时间" json:"date"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
@ -244,6 +244,7 @@ func registerEnterpriseAPI(app *gin.Engine) {
|
||||
manageV1.POST("/company/detail", _api.CompanyDetail)
|
||||
manageV1.POST("/company/product", _api.CompanyProduct)
|
||||
manageV1.POST("/expert", _api.Expert)
|
||||
manageV1.POST("/research/laboratory", _api.ResearchLaboratory)
|
||||
}
|
||||
// Activity 活动信息
|
||||
activityV1 := v1.Group("/activity")
|
||||
|
Reference in New Issue
Block a user