feat:完善项目管理,增加专家列表信息
This commit is contained in:
@ -1,30 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/controller/identity"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Identity struct{}
|
||||
|
||||
// Expert 专家信息
|
||||
func (*Identity) Expert(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := identity.NewInstance()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Expert(form.Name, form.Mobile, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Identity) Company(c *gin.Context) {
|
||||
|
||||
}
|
@ -190,3 +190,20 @@ func (*Manage) CompanyProduct(c *gin.Context) {
|
||||
Product(form.Convert(), form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
// 专家信息
|
||||
|
||||
func (*Manage) Expert(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewExpert()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Instance(form.Name, form.Mobile, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -1,64 +0,0 @@
|
||||
package identity
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
)
|
||||
|
||||
type Instance struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type InstanceHandle func(session *session.Enterprise, local string) *Instance
|
||||
|
||||
type (
|
||||
// InstanceForExpert 专家信息
|
||||
InstanceForExpert struct {
|
||||
ID string `json:"id"`
|
||||
*model.UserIdentityForExpert
|
||||
}
|
||||
)
|
||||
|
||||
// Expert 专家列表
|
||||
func (c *Instance) Expert(name, mobile string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mUserIdentity := model.NewUserIdentity()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("m.name", name))
|
||||
}
|
||||
if mobile != "" {
|
||||
where = append(where, model2.NewWhereLike("u.mobile", mobile))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mUserIdentity.Expert(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]*InstanceForExpert, 0)
|
||||
|
||||
for _, v := range out {
|
||||
mUserIdentity.ID = v.ID
|
||||
|
||||
list = append(list, &InstanceForExpert{
|
||||
ID: mUserIdentity.GetEncodeID(), UserIdentityForExpert: v,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *session.Enterprise, local string) *Instance {
|
||||
return &Instance{
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
137
app/api/enterprise/controller/manage/expert.go
Normal file
137
app/api/enterprise/controller/manage/expert.go
Normal file
@ -0,0 +1,137 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Expert struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type ExpertHandle func(session *session.Enterprise, local string) *Expert
|
||||
|
||||
type ExpertInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model.ManageExpertInfo
|
||||
Industrys []string `json:"industrys"`
|
||||
}
|
||||
|
||||
// research 研究机构专家信息
|
||||
func (c *Expert) research(page, pageSize int, count *int64, where ...*model2.ModelWhere) ([]*model.ManageExpertInfo, error) {
|
||||
if len(where) <= 0 {
|
||||
where = make([]*model2.ModelWhere, 0)
|
||||
}
|
||||
// 研究科技下存在专家
|
||||
// 实验室下存在专家
|
||||
mUserResearch := model.NewUserResearch()
|
||||
|
||||
_, 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
|
||||
}
|
||||
// 查询科研机构下所有实验室
|
||||
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 = 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()
|
||||
|
||||
out := make([]*model.ManageExpertInfo, 0)
|
||||
|
||||
if out, err = mManageExpert.Experts(page, pageSize, count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// laboratory 实验室专家信息
|
||||
func (c *Expert) laboratory(page, pageSize int, count *int64, where ...*model2.ModelWhere) ([]*model.ManageExpertInfo, error) {
|
||||
if len(where) <= 0 {
|
||||
where = make([]*model2.ModelWhere, 0)
|
||||
}
|
||||
// 实验室信息
|
||||
mManageLaboratory := model.NewManageLaboratory()
|
||||
|
||||
_, err := model2.FirstField(mManageLaboratory.ManageLaboratory, []string{"id", "research_id"},
|
||||
model2.NewWhere("uid", c.UID), model2.NewWhere("invalid_status", model2.InvalidStatusForNot))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
where = append(where, model2.NewWhere("e.laboratory_id = ?", mManageLaboratory.ID))
|
||||
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
out := make([]*model.ManageExpertInfo, 0)
|
||||
|
||||
if out, err = mManageExpert.Experts(page, pageSize, count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Instance 专家信息
|
||||
func (c *Expert) Instance(name, mobile string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("e.name", name))
|
||||
}
|
||||
if mobile != "" {
|
||||
where = append(where, model2.NewWhereLike("e.mobile", mobile))
|
||||
}
|
||||
out := make([]*model.ManageExpertInfo, 0)
|
||||
|
||||
var err error
|
||||
|
||||
var count int64
|
||||
// 科研机构
|
||||
if c.Identity == config.TenantUserIdentityForResearch {
|
||||
out, err = c.research(page, pageSize, &count, where...)
|
||||
// 实验室
|
||||
} else if c.Identity == config.TenantUserIdentityForLaboratory {
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ExpertInfo, 0)
|
||||
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
for _, v := range out {
|
||||
mManageExpert.Industry = v.Industry
|
||||
|
||||
list = append(list, &ExpertInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ManageExpertInfo: v,
|
||||
Industrys: mManageExpert.GetIndustryAttribute(),
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func NewExpert() ExpertHandle {
|
||||
return func(session *session.Enterprise, local string) *Expert {
|
||||
return &Expert{
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Project 项目列表
|
||||
type Project struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
|
@ -1,11 +1,53 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ManageExpert struct {
|
||||
*model.ManageExpert
|
||||
}
|
||||
|
||||
// ManageExpertInfo 专家信息
|
||||
type ManageExpertInfo struct {
|
||||
model.Model
|
||||
Name string `json:"name"`
|
||||
Mobile string `json:"mobile"`
|
||||
Industry string `json:"-"`
|
||||
VisitCount int `json:"visit_count"`
|
||||
SettledAt time.Time `json:"settled_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.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))
|
||||
|
||||
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([]*ManageExpertInfo, 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()}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/utils"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Gender struct {
|
||||
@ -90,6 +91,7 @@ const (
|
||||
type Examine struct {
|
||||
ExamineStatus ExamineStatusKind `gorm:"column:examine_status;type:tinyint(1);default:0;comment:审核状态(0:审核中,1:审核通过,2:审核拒绝)" json:"examine_status"`
|
||||
ExamineRemark string `gorm:"column:examine_remark;type:varchar(255);default:'';comment:审核备注" json:"examine_remark"`
|
||||
ExamineAt time.Time `gorm:"column:examine_at;type:datetime;default:null;comment:审核时间" json:"examine_at"`
|
||||
}
|
||||
|
||||
// ExamineStatusKind 审核状态
|
||||
|
20
app/common/model/manage_expert_visit.go
Normal file
20
app/common/model/manage_expert_visit.go
Normal file
@ -0,0 +1,20 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
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"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *ManageExpertVisit) TableName() string {
|
||||
return "manage_expert_visit"
|
||||
}
|
||||
|
||||
func NewManageExpertVisit() *ManageExpertVisit {
|
||||
return &ManageExpertVisit{}
|
||||
}
|
@ -192,3 +192,15 @@ func TestA(t *testing.T) {
|
||||
err := mysql.Table(NewSysIndustry().TableName()).Create(out).Error
|
||||
t.Log(err)
|
||||
}
|
||||
|
||||
func TestNewUserInstance(t *testing.T) {
|
||||
mysql := mysql()
|
||||
out := make([]string, 0)
|
||||
|
||||
mysql.Table(NewUserInstance().TableName()).
|
||||
Where("is_deleted = ?", DeleteStatusForNot).
|
||||
Where(fmt.Sprintf("id IN (%v) OR id IN (%v)", strings.Join([]string{"1"}, ","), strings.Join([]string{"2"}, ","))).
|
||||
Pluck("id", &out)
|
||||
t.Log(out)
|
||||
t.Log(len(out))
|
||||
}
|
||||
|
@ -5,9 +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"`
|
||||
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"`
|
||||
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"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
18
app/common/model/user_assets.go
Normal file
18
app/common/model/user_assets.go
Normal file
@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
// UserAssets 用户资产数据模型
|
||||
type UserAssets struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
Currency float64 `gorm:"column:currency;decimal(10,2);default:0;comment:货币-创新币" json:"currency"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *UserAssets) TableName() string {
|
||||
return "user_assets"
|
||||
}
|
||||
|
||||
func NewUserAssets() *UserAssets {
|
||||
return &UserAssets{}
|
||||
}
|
@ -243,12 +243,7 @@ func registerEnterpriseAPI(app *gin.Engine) {
|
||||
manageV1.POST("/equipment/delete", _api.EquipmentDelete)
|
||||
manageV1.POST("/company/detail", _api.CompanyDetail)
|
||||
manageV1.POST("/company/product", _api.CompanyProduct)
|
||||
}
|
||||
// Identity 身份信息
|
||||
identityV1 := v1.Group("/config")
|
||||
{
|
||||
_api := new(api2.Identity)
|
||||
identityV1.POST("/expert", _api.Expert)
|
||||
manageV1.POST("/expert", _api.Expert)
|
||||
}
|
||||
// Activity 活动信息
|
||||
activityV1 := v1.Group("/activity")
|
||||
|
@ -1,10 +1,15 @@
|
||||
package utils
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestToSnake(t *testing.T) {
|
||||
src := []int{1, 2, 3, 4, 5, 6}
|
||||
t.Log(src)
|
||||
ReverseSlice(src)
|
||||
t.Log(src)
|
||||
//src := []int{1, 2, 3, 4, 5, 6}
|
||||
//t.Log(src)
|
||||
//ReverseSlice(src)
|
||||
//t.Log(src)
|
||||
t.Log(fmt.Sprintf("SELECT * FROM sys_user WHERE id IN (%v)", strings.Join([]string{"1", "2", "3"}, ",")))
|
||||
}
|
||||
|
Reference in New Issue
Block a user