feat:优化信息,完善es查询,完善网站首页公司信息查询
This commit is contained in:
@ -11,6 +11,7 @@ type ES struct{}
|
|||||||
func (*ES) Create(c *gin.Context) {
|
func (*ES) Create(c *gin.Context) {
|
||||||
form := &struct {
|
form := &struct {
|
||||||
ID uint64 `json:"id" form:"id"`
|
ID uint64 `json:"id" form:"id"`
|
||||||
|
Identity int `json:"identity" form:"identity"`
|
||||||
Title string `json:"title" form:"title"`
|
Title string `json:"title" form:"title"`
|
||||||
Keyword string `json:"keyword" form:"keyword"`
|
Keyword string `json:"keyword" form:"keyword"`
|
||||||
Research string `json:"research" form:"research"`
|
Research string `json:"research" form:"research"`
|
||||||
@ -19,8 +20,9 @@ func (*ES) Create(c *gin.Context) {
|
|||||||
api.APIFailure(err.(error))(c)
|
api.APIFailure(err.(error))(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
manage := service.NewManage(
|
manage := service.NewESManage(
|
||||||
service.WithManageID(form.ID),
|
service.WithManageID(form.ID),
|
||||||
|
service.WithManageIdentity(form.Identity),
|
||||||
service.WithManageTitle(form.Title),
|
service.WithManageTitle(form.Title),
|
||||||
service.WithManageKeyword(form.Keyword),
|
service.WithManageKeyword(form.Keyword),
|
||||||
service.WithManageResearch(form.Research),
|
service.WithManageResearch(form.Research),
|
||||||
@ -30,13 +32,19 @@ func (*ES) Create(c *gin.Context) {
|
|||||||
|
|
||||||
func (*ES) Search(c *gin.Context) {
|
func (*ES) Search(c *gin.Context) {
|
||||||
form := &struct {
|
form := &struct {
|
||||||
Params map[string]interface{} `json:"params" form:"params"`
|
Identity int `json:"identity" form:"identity" binding:"required"`
|
||||||
|
Industry string `json:"industry" form:"industry"`
|
||||||
|
Param string `json:"param" form:"params"`
|
||||||
}{}
|
}{}
|
||||||
if err := api.Bind(form)(c); err != nil {
|
if err := api.Bind(form)(c); err != nil {
|
||||||
api.APIFailure(err.(error))(c)
|
api.APIFailure(err.(error))(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
manage := service.NewManage()
|
manage := service.NewESManage(service.WithManageIdentity(form.Identity),
|
||||||
data, err := manage.Search(1, 10, form.Params)
|
service.WithManageTitle(form.Param),
|
||||||
|
service.WithManageIndustry(form.Industry),
|
||||||
|
service.WithManageKeyword(form.Param),
|
||||||
|
service.WithManageResearch(form.Param))
|
||||||
|
data, err := manage.Search(1, 1)
|
||||||
api.APIResponse(err, data)(c)
|
api.APIResponse(err, data)(c)
|
||||||
}
|
}
|
||||||
|
49
app/api/website/api/manage.go
Normal file
49
app/api/website/api/manage.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/api/website/controller/manage"
|
||||||
|
"SciencesServer/app/basic/api"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Manage struct{}
|
||||||
|
|
||||||
|
func (*Manage) Search(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
Identity int `json:"identity" form:"identity" binding:"required"`
|
||||||
|
Param string `json:"param" form:"param" binding:"required"`
|
||||||
|
Industry string `json:"industry" form:"industry"`
|
||||||
|
api.PageForm
|
||||||
|
}{}
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := manage.NewSearch()().Launch(form.Identity, form.Param, form.Industry, form.Page, form.PageSize)
|
||||||
|
api.APIResponse(err, data)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Manage) Company(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
CompanyID string `json:"company_id" form:"company_id" binding:"required"`
|
||||||
|
}{}
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := manage.NewCompany()(nil).Instance((&api.IDStringForm{ID: form.CompanyID}).Convert())
|
||||||
|
api.APIResponse(err, data)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Manage) CompanyProduct(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
CompanyID string `json:"company_id" form:"company_id" binding:"required"`
|
||||||
|
api.PageForm
|
||||||
|
}{}
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := manage.NewCompany()(nil).Product((&api.IDStringForm{ID: form.CompanyID}).Convert(), form.Page, form.PageSize)
|
||||||
|
api.APIResponse(err, data)(c)
|
||||||
|
}
|
94
app/api/website/controller/manage/company.go
Normal file
94
app/api/website/controller/manage/company.go
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package manage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/api/website/model"
|
||||||
|
"SciencesServer/app/basic/controller"
|
||||||
|
model2 "SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/app/session"
|
||||||
|
config2 "SciencesServer/config"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Company struct {
|
||||||
|
*session.Enterprise
|
||||||
|
}
|
||||||
|
|
||||||
|
type CompanyHandle func(session *session.Enterprise) *Company
|
||||||
|
|
||||||
|
type (
|
||||||
|
// CompanyBasicInfo 公司基本信息
|
||||||
|
CompanyBasicInfo struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Kind model2.ManageCompanyKind `json:"kind"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Image string `json:"image"`
|
||||||
|
Product string `json:"product"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
Keywords []string `json:"keywords"`
|
||||||
|
}
|
||||||
|
// CompanyInstanceInfo 公司信息
|
||||||
|
CompanyInstanceInfo struct {
|
||||||
|
CompanyBasicInfo
|
||||||
|
Industrys []string `json:"industrys"`
|
||||||
|
Directions []string `json:"directions"`
|
||||||
|
Introduce string `json:"introduce"`
|
||||||
|
}
|
||||||
|
// CompanyProductInfo 公司产品信息
|
||||||
|
CompanyProductInfo struct {
|
||||||
|
*model.ManageCompanyProduct
|
||||||
|
ID string `json:"id"`
|
||||||
|
Industrys []string `json:"industrys"`
|
||||||
|
Keywords []string `json:"keywords"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Instance 公司企业信息
|
||||||
|
func (c *Company) Instance(id uint64) (*CompanyInstanceInfo, error) {
|
||||||
|
mManageCompany := model.NewManageCompany()
|
||||||
|
mManageCompany.ID = id
|
||||||
|
|
||||||
|
if isExist, err := model2.First(mManageCompany.ManageCompany); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if !isExist {
|
||||||
|
return nil, errors.New("操作错误,公司信息不存在或已被删除")
|
||||||
|
}
|
||||||
|
return &CompanyInstanceInfo{
|
||||||
|
CompanyBasicInfo: CompanyBasicInfo{
|
||||||
|
ID: mManageCompany.GetEncodeID(), Kind: mManageCompany.Kind, Name: mManageCompany.Name,
|
||||||
|
Image: mManageCompany.Image.Analysis(config2.SettingInfo.Domain),
|
||||||
|
Url: mManageCompany.Url,
|
||||||
|
Keywords: mManageCompany.GetKeywordAttribute(),
|
||||||
|
},
|
||||||
|
Industrys: mManageCompany.GetIndustryAttribute(),
|
||||||
|
Directions: mManageCompany.GetDirectionAttribute(),
|
||||||
|
Introduce: mManageCompany.Introduce,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Product 产品信息
|
||||||
|
func (c *Company) Product(id uint64, page, pageSize int) (*controller.ReturnPages, error) {
|
||||||
|
mManageCompany := model.NewManageCompany()
|
||||||
|
var count int64
|
||||||
|
out, err := mManageCompany.Product(id, c.UID, page, pageSize, &count)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
list := make([]*CompanyProductInfo, 0)
|
||||||
|
|
||||||
|
for _, v := range out {
|
||||||
|
list = append(list, &CompanyProductInfo{
|
||||||
|
ManageCompanyProduct: v,
|
||||||
|
ID: v.GetEncodeID(),
|
||||||
|
Industrys: v.GetIndustryAttribute(),
|
||||||
|
Keywords: v.GetKeywordAttribute(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCompany() CompanyHandle {
|
||||||
|
return func(session *session.Enterprise) *Company {
|
||||||
|
return &Company{session}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import (
|
|||||||
"SciencesServer/app/basic/config"
|
"SciencesServer/app/basic/config"
|
||||||
model2 "SciencesServer/app/common/model"
|
model2 "SciencesServer/app/common/model"
|
||||||
"SciencesServer/app/service"
|
"SciencesServer/app/service"
|
||||||
|
config2 "SciencesServer/config"
|
||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ var searchIdentityHandle = map[int]func(ids []uint64) (interface{}, error){
|
|||||||
config.TenantUserIdentityForAgent: company,
|
config.TenantUserIdentityForAgent: company,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// company 公司信息
|
||||||
func company(ids []uint64) (interface{}, error) {
|
func company(ids []uint64) (interface{}, error) {
|
||||||
mManageCompany := model.NewManageCompany()
|
mManageCompany := model.NewManageCompany()
|
||||||
out := make([]*model2.ManageCompany, 0)
|
out := make([]*model2.ManageCompany, 0)
|
||||||
@ -39,7 +41,17 @@ func company(ids []uint64) (interface{}, error) {
|
|||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return out, nil
|
list := make([]*CompanyBasicInfo, 0)
|
||||||
|
|
||||||
|
for _, v := range out {
|
||||||
|
list = append(list, &CompanyBasicInfo{
|
||||||
|
ID: v.GetEncodeID(), Kind: v.Kind, Name: v.Name,
|
||||||
|
Image: v.Image.Analysis(config2.SettingInfo.Domain),
|
||||||
|
Url: v.Url,
|
||||||
|
Keywords: v.GetKeywordAttribute(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func expert(ids []uint64) (interface{}, error) {
|
func expert(ids []uint64) (interface{}, error) {
|
||||||
@ -87,20 +99,24 @@ func laboratory(ids []uint64) (interface{}, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Search) Launch(identity int, params string) (interface{}, error) {
|
func (c *Search) Launch(identity int, param, industry string, page, pageSize int) (interface{}, error) {
|
||||||
manage := service.NewManage()
|
manage := service.NewESManage(
|
||||||
|
service.WithManageIdentity(identity),
|
||||||
_params := map[string]interface{}{
|
service.WithManageTitle(param),
|
||||||
"title": params, "keyword": params, "research": params,
|
service.WithManageIndustry(industry),
|
||||||
}
|
service.WithManageKeyword(param),
|
||||||
data, err := manage.Search(1, 1, _params)
|
service.WithManageResearch(param),
|
||||||
|
)
|
||||||
|
out, err := manage.Search(page, pageSize)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if out == nil {
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
ids := make([]uint64, 0)
|
ids := make([]uint64, 0)
|
||||||
|
|
||||||
for _, v := range data.([]*service.Manage) {
|
for _, v := range out.([]*service.ESManage) {
|
||||||
if v.Identity != identity {
|
if v.Identity != identity {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,54 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "SciencesServer/app/common/model"
|
import (
|
||||||
|
"SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/serve/orm"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
type ManageCompany struct {
|
type ManageCompany struct {
|
||||||
*model.ManageCompany
|
*model.ManageCompany
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ManageCompanyProduct 产品信息
|
||||||
|
type ManageCompanyProduct struct {
|
||||||
|
*model.TechnologyProduct
|
||||||
|
VisitCount int `json:"visit_count"`
|
||||||
|
IsCollect uint64 `json:"is_collect"`
|
||||||
|
CollectCount int `json:"collect_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Product 产品信息
|
||||||
|
func (m *ManageCompany) Product(id, uid uint64, page, pageSize int, count *int64) ([]*ManageCompanyProduct, error) {
|
||||||
|
mTechnologyProductCollect := model.NewTechnologyProductCollect()
|
||||||
|
|
||||||
|
db := orm.GetDB().Table(model.NewUserCompany().TableName()+" u_c").
|
||||||
|
Select("p.id", "p.title", "p.image", "p.industry", "p.maturity", "p.lead_standard", "p.cooperation_mode",
|
||||||
|
"p.keyword", "v.count AS visit_count", "IFNULL(c_u.id, 0) AS is_collect", "c.count AS collect_count").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS p ON u_c.uid = p.uid AND p.shelf_status = %d AND p.status = %d AND p.is_deleted = %d",
|
||||||
|
model.NewTechnologyProduct().TableName(), model.ShelfStatusForUp, model.TechnologyProductStatusForAgree, model.DeleteStatusForNot)).
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN (SELECT product_id, SUM(count) AS count FROM %s WHERE is_deleted = %d GROUP BY product_id) AS v ON p.id = v.product_id",
|
||||||
|
model.NewTechnologyProductVisit().TableName(), model.DeleteStatusForNot)).
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN (SELECT product_id, COUNT(count) AS count FROM %s WHERE is_deleted = %d GROUP BY product_id) AS c ON p.id = c.product_id",
|
||||||
|
mTechnologyProductCollect.TableName(), model.DeleteStatusForNot)).
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS c_u ON p.id = c_u.product_id AND c_u.uid = %d AND c_u.is_deleted = %d",
|
||||||
|
mTechnologyProductCollect.TableName(), uid, model.DeleteStatusForNot)).
|
||||||
|
Joins(fmt.Sprintf("")).
|
||||||
|
Where("u_c.company_id = ?", id).
|
||||||
|
Where("u_c.invalid_status = ?", model.InvalidStatusForNot).
|
||||||
|
Where("u_c.is_deleted = ?", model.DeleteStatusForNot)
|
||||||
|
|
||||||
|
out := make([]*ManageCompanyProduct, 0)
|
||||||
|
|
||||||
|
if err := db.Count(count).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
func NewManageCompany() *ManageCompany {
|
func NewManageCompany() *ManageCompany {
|
||||||
return &ManageCompany{model.NewManageCompany()}
|
return &ManageCompany{model.NewManageCompany()}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ type ManageAgent struct {
|
|||||||
Mobile string `gorm:"column:mobile;type:varchar(15);default:'';comment:联系方式" json:"mobile"`
|
Mobile string `gorm:"column:mobile;type:varchar(15);default:'';comment:联系方式" json:"mobile"`
|
||||||
IDCard string `gorm:"column:id_card;type:varchar(18);default:'';comment:身份证号" json:"id_card"`
|
IDCard string `gorm:"column:id_card;type:varchar(18);default:'';comment:身份证号" json:"id_card"`
|
||||||
IDImage string `gorm:"column:id_image;type:text;comment:身份证图片" json:"-"`
|
IDImage string `gorm:"column:id_image;type:text;comment:身份证图片" json:"-"`
|
||||||
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"industry"`
|
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"-"`
|
||||||
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';comment:关键词" json:"-"`
|
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';comment:关键词" json:"-"`
|
||||||
WorkExperience string `gorm:"column:work_experience;type:varchar(255);default:'';comment:工作经历" json:"work_experience"`
|
WorkExperience string `gorm:"column:work_experience;type:varchar(255);default:'';comment:工作经历" json:"work_experience"`
|
||||||
WorkPlace string `gorm:"column:work_place;type:varchar(255);default:0;comment:工作地点" json:"work_place"`
|
WorkPlace string `gorm:"column:work_place;type:varchar(255);default:0;comment:工作地点" json:"work_place"`
|
||||||
|
@ -22,7 +22,7 @@ type ManageExpert struct {
|
|||||||
Title string `gorm:"column:title;type:varchar(50);default:'';comment:职称" json:"title"`
|
Title string `gorm:"column:title;type:varchar(50);default:'';comment:职称" json:"title"`
|
||||||
Gender
|
Gender
|
||||||
WorkAt time.Time `gorm:"column:work_at;type:date;not null;comment:从业时间" json:"work_at"`
|
WorkAt time.Time `gorm:"column:work_at;type:date;not null;comment:从业时间" json:"work_at"`
|
||||||
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"industry"`
|
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"-"`
|
||||||
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';comment:关键词" json:"keyword"`
|
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';comment:关键词" json:"keyword"`
|
||||||
Research string `gorm:"column:research;type:varchar(255);default:'';comment:研究信息" json:"research"`
|
Research string `gorm:"column:research;type:varchar(255);default:'';comment:研究信息" json:"research"`
|
||||||
Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"`
|
Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"`
|
||||||
|
@ -15,7 +15,7 @@ type ManageLaboratory struct {
|
|||||||
Area
|
Area
|
||||||
Url string `gorm:"column:url;type:varchar(255);default:'';comment:实验室网站" json:"url"`
|
Url string `gorm:"column:url;type:varchar(255);default:'';comment:实验室网站" json:"url"`
|
||||||
Position string `gorm:"column:position;type:varchar(50);default:'';comment:坐标" json:"-"`
|
Position string `gorm:"column:position;type:varchar(50);default:'';comment:坐标" json:"-"`
|
||||||
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"industry"`
|
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"-"`
|
||||||
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';comment:关键词" json:"keyword"`
|
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';comment:关键词" json:"keyword"`
|
||||||
Research string `gorm:"column:research;type:varchar(255);default:'';comment:研究信息" json:"research"`
|
Research string `gorm:"column:research;type:varchar(255);default:'';comment:研究信息" json:"research"`
|
||||||
Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"`
|
Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"`
|
||||||
|
@ -13,7 +13,7 @@ type ManageResearch struct {
|
|||||||
Image
|
Image
|
||||||
Area
|
Area
|
||||||
Position string `gorm:"column:position;type:varchar(50);default:'';comment:坐标" json:"-"`
|
Position string `gorm:"column:position;type:varchar(50);default:'';comment:坐标" json:"-"`
|
||||||
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:所属领域;行业信息" json:"industry"`
|
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:所属领域;行业信息" json:"-"`
|
||||||
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';comment:关键词" json:"keyword"`
|
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';comment:关键词" json:"keyword"`
|
||||||
Research string `gorm:"column:research;type:varchar(255);default:'';comment:研究信息" json:"research"`
|
Research string `gorm:"column:research;type:varchar(255);default:'';comment:研究信息" json:"research"`
|
||||||
Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"`
|
Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"`
|
||||||
|
@ -4,7 +4,7 @@ package model
|
|||||||
type SysPatentClassify struct {
|
type SysPatentClassify struct {
|
||||||
Model
|
Model
|
||||||
IPC string `gorm:"column:ipc;type:varchar(18);default:'';comment:IPC主分类号" json:"ipc"`
|
IPC string `gorm:"column:ipc;type:varchar(18);default:'';comment:IPC主分类号" json:"ipc"`
|
||||||
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"industry"`
|
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:行业领域" json:"-"`
|
||||||
IndustryDetail string `gorm:"column:industry_detail;type:varchar(255);default:'';comment:详细行业领域,包含父级领域信息" json:"industry_detail"`
|
IndustryDetail string `gorm:"column:industry_detail;type:varchar(255);default:'';comment:详细行业领域,包含父级领域信息" json:"industry_detail"`
|
||||||
ModelDeleted
|
ModelDeleted
|
||||||
ModelAt
|
ModelAt
|
||||||
|
@ -15,7 +15,7 @@ type TechnologyDemand struct {
|
|||||||
Kind string `gorm:"column:kind;type:varchar(50);default:'';comment:需求类别" json:"-"`
|
Kind string `gorm:"column:kind;type:varchar(50);default:'';comment:需求类别" json:"-"`
|
||||||
Name string `gorm:"column:name;type:varchar(30);default:'';comment:联系人" json:"name"`
|
Name string `gorm:"column:name;type:varchar(30);default:'';comment:联系人" json:"name"`
|
||||||
Mobile string `gorm:"column:mobile;type:varchar(15);default:'';comment:联系方式" json:"mobile"`
|
Mobile string `gorm:"column:mobile;type:varchar(15);default:'';comment:联系方式" json:"mobile"`
|
||||||
Industry string `gorm:"column:industry;type:varchar(255);comment:所属领域;行业信息" json:"industry"`
|
Industry string `gorm:"column:industry;type:varchar(255);comment:所属领域;行业信息" json:"-"`
|
||||||
Introduce string `gorm:"column:introduce;type:text;comment:需求描述" json:"introduce"`
|
Introduce string `gorm:"column:introduce;type:text;comment:需求描述" json:"introduce"`
|
||||||
Budget float64 `gorm:"column:budget;type:decimal(10,2);default:0;comment:投产预算" json:"budget"`
|
Budget float64 `gorm:"column:budget;type:decimal(10,2);default:0;comment:投产预算" json:"budget"`
|
||||||
BudgetMode TechnologyDemandBudgetMode `gorm:"column:budget_mode;type:tinyint(1);default:1;comment:预算模式(1:具体金额,2:面议)" json:"budget_mode"`
|
BudgetMode TechnologyDemandBudgetMode `gorm:"column:budget_mode;type:tinyint(1);default:1;comment:预算模式(1:具体金额,2:面议)" json:"budget_mode"`
|
||||||
|
@ -14,7 +14,7 @@ type TechnologyProduct struct {
|
|||||||
Image
|
Image
|
||||||
Video string `gorm:"column:video;type:varchar(255);default:'';comment:视频地址" json:"video"`
|
Video string `gorm:"column:video;type:varchar(255);default:'';comment:视频地址" json:"video"`
|
||||||
Material string `gorm:"column:material;type:varchar(255);default:'';comment:证明材料" json:"material"`
|
Material string `gorm:"column:material;type:varchar(255);default:'';comment:证明材料" json:"material"`
|
||||||
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:所属领域;行业信息" json:"industry"`
|
Industry string `gorm:"column:industry;type:varchar(255);default:'';comment:所属领域;行业信息" json:"-"`
|
||||||
Customer string `gorm:"column:customer;type:varchar(255);default:'';comment:应用客户" json:"-"`
|
Customer string `gorm:"column:customer;type:varchar(255);default:'';comment:应用客户" json:"-"`
|
||||||
Maturity config.TechnologyMaturity `gorm:"column:maturity;type:tinyint(1);default:0;comment:技术成熟度" json:"maturity"`
|
Maturity config.TechnologyMaturity `gorm:"column:maturity;type:tinyint(1);default:0;comment:技术成熟度" json:"maturity"`
|
||||||
LeadStandard TechnologyProductLeadStandard `gorm:"column:lead_standard;type:tinyint(1);default:0;comment:领先标准" json:"lead_standard"`
|
LeadStandard TechnologyProductLeadStandard `gorm:"column:lead_standard;type:tinyint(1);default:0;comment:领先标准" json:"lead_standard"`
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"SciencesServer/serve/es"
|
|
||||||
"encoding/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Manage struct {
|
|
||||||
ID uint64 `json:"id"` // ID
|
|
||||||
Identity int `json:"identity"` // 身份信息
|
|
||||||
Title string `json:"title"` // 名称
|
|
||||||
Keyword string `json:"keyword"` // 关键词
|
|
||||||
Research string `json:"research"` // 研究方向
|
|
||||||
}
|
|
||||||
|
|
||||||
type ManageOption func(manage *Manage)
|
|
||||||
|
|
||||||
func (c *Manage) Index() string {
|
|
||||||
return "es_manage_index"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Manage) Create() error {
|
|
||||||
_bytes, _ := json.Marshal(this)
|
|
||||||
return es.Create(this.Index(), _bytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Manage) Search(page, pageSize int, condition map[string]interface{}) (interface{}, error) {
|
|
||||||
return es.Search(this, this.Index(), condition, page, pageSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithManageID(id uint64) ManageOption {
|
|
||||||
return func(manage *Manage) {
|
|
||||||
manage.ID = id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithManageTitle(title string) ManageOption {
|
|
||||||
return func(manage *Manage) {
|
|
||||||
manage.Title = title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithManageKeyword(keyword string) ManageOption {
|
|
||||||
return func(manage *Manage) {
|
|
||||||
manage.Keyword = keyword
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithManageResearch(research string) ManageOption {
|
|
||||||
return func(manage *Manage) {
|
|
||||||
manage.Research = research
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewManage(options ...ManageOption) *Manage {
|
|
||||||
out := new(Manage)
|
|
||||||
|
|
||||||
for _, option := range options {
|
|
||||||
option(out)
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
106
app/service/es_manage.go
Normal file
106
app/service/es_manage.go
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/serve/es"
|
||||||
|
"SciencesServer/serve/logger"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ESManage struct {
|
||||||
|
ID uint64 `json:"id"` // ID
|
||||||
|
Identity int `json:"identity"` // 身份信息
|
||||||
|
Industry string `json:"industry"` // 行业领域
|
||||||
|
Title string `json:"title"` // 名称
|
||||||
|
Keyword string `json:"keyword"` // 关键词
|
||||||
|
Research string `json:"research"` // 研究方向
|
||||||
|
}
|
||||||
|
|
||||||
|
type ESManageOption func(manage *ESManage)
|
||||||
|
|
||||||
|
func (this *ESManage) Index() string {
|
||||||
|
if this.Identity > 0 {
|
||||||
|
return fmt.Sprintf("es_manage_index_%d", this.Identity)
|
||||||
|
}
|
||||||
|
return "es_manage_index"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ESManage) Create() error {
|
||||||
|
if this.Industry != "" {
|
||||||
|
this.Title = this.Industry + " - " + this.Title
|
||||||
|
}
|
||||||
|
_bytes, _ := json.Marshal(this)
|
||||||
|
return es.Create(this.Index(), _bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ESManage) Search(page, pageSize int) (interface{}, error) {
|
||||||
|
mustParams := make(map[string]interface{}, 0)
|
||||||
|
shouldParams := make(map[string]interface{}, 0)
|
||||||
|
|
||||||
|
if this.Title != "" {
|
||||||
|
shouldParams["title"] = this.Title
|
||||||
|
}
|
||||||
|
if this.Industry != "" {
|
||||||
|
mustParams["title"] = this.Industry
|
||||||
|
}
|
||||||
|
if this.Keyword != "" {
|
||||||
|
shouldParams["keyword"] = this.Keyword
|
||||||
|
}
|
||||||
|
if this.Research != "" {
|
||||||
|
shouldParams["research"] = this.Research
|
||||||
|
}
|
||||||
|
out, err := es.Search(this, this.Index(), &es.SearchParams{
|
||||||
|
MustParams: mustParams,
|
||||||
|
ShouldParams: shouldParams,
|
||||||
|
}, page, pageSize)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.ErrorF("查询ES信息错误:【%s】", err)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithManageID(id uint64) ESManageOption {
|
||||||
|
return func(manage *ESManage) {
|
||||||
|
manage.ID = id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithManageIdentity(identity int) ESManageOption {
|
||||||
|
return func(manage *ESManage) {
|
||||||
|
manage.Identity = identity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithManageTitle(title string) ESManageOption {
|
||||||
|
return func(manage *ESManage) {
|
||||||
|
manage.Title = title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithManageIndustry(industry string) ESManageOption {
|
||||||
|
return func(manage *ESManage) {
|
||||||
|
manage.Industry = industry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithManageKeyword(keyword string) ESManageOption {
|
||||||
|
return func(manage *ESManage) {
|
||||||
|
manage.Keyword = keyword
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithManageResearch(research string) ESManageOption {
|
||||||
|
return func(manage *ESManage) {
|
||||||
|
manage.Research = research
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewESManage(options ...ESManageOption) *ESManage {
|
||||||
|
out := new(ESManage)
|
||||||
|
|
||||||
|
for _, option := range options {
|
||||||
|
option(out)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
63
app/service/es_patent.go
Normal file
63
app/service/es_patent.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/serve/es"
|
||||||
|
"SciencesServer/serve/logger"
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ESPatent struct {
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Industry string `json:"industry"` // 行业领域
|
||||||
|
}
|
||||||
|
|
||||||
|
type ESPatentOption func(patent *ESPatent)
|
||||||
|
|
||||||
|
func (this *ESPatent) Index() string {
|
||||||
|
return "es_patent_index"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ESPatent) Create() error {
|
||||||
|
_bytes, _ := json.Marshal(this)
|
||||||
|
return es.Create(this.Index(), _bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ESPatent) Search(page, pageSize int, params map[string]interface{}) (interface{}, error) {
|
||||||
|
out, err := es.Search(this, this.Index(), &es.SearchParams{
|
||||||
|
MustParams: nil,
|
||||||
|
ShouldParams: params,
|
||||||
|
}, page, pageSize)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.ErrorF("查询ES信息错误:【%s】", err)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithPatentID(id uint64) ESPatentOption {
|
||||||
|
return func(patent *ESPatent) {
|
||||||
|
patent.ID = id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithPatentTitle(title string) ESPatentOption {
|
||||||
|
return func(patent *ESPatent) {
|
||||||
|
patent.Title = title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithPatentIndustry(industry string) ESPatentOption {
|
||||||
|
return func(patent *ESPatent) {
|
||||||
|
patent.Industry = industry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewESPatent(options ...ESPatentOption) *ESPatent {
|
||||||
|
out := new(ESPatent)
|
||||||
|
|
||||||
|
for _, v := range options {
|
||||||
|
v(out)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
@ -66,6 +66,14 @@ func registerAPI(app *gin.Engine) {
|
|||||||
serviceV1.GET("/innovate/kind", _api.InnovateKind)
|
serviceV1.GET("/innovate/kind", _api.InnovateKind)
|
||||||
serviceV1.POST("/innovate/detail", _api.InnovateDetail)
|
serviceV1.POST("/innovate/detail", _api.InnovateDetail)
|
||||||
}
|
}
|
||||||
|
// Manage 服务管理
|
||||||
|
manageV1 := v1.Group("/manage")
|
||||||
|
{
|
||||||
|
_api := new(api2.Manage)
|
||||||
|
manageV1.POST("/search", _api.Search)
|
||||||
|
manageV1.POST("/company", _api.Company)
|
||||||
|
manageV1.POST("/company/product", _api.CompanyProduct)
|
||||||
|
}
|
||||||
//Technology 技术信息管理
|
//Technology 技术信息管理
|
||||||
technologyV1 := v1.Group("/technology")
|
technologyV1 := v1.Group("/technology")
|
||||||
{
|
{
|
||||||
|
@ -108,7 +108,6 @@ func TestNewInstance2(t *testing.T) {
|
|||||||
function := func(src interface{}) {
|
function := func(src interface{}) {
|
||||||
obj := reflect.ValueOf(src).Interface()
|
obj := reflect.ValueOf(src).Interface()
|
||||||
t.Log(obj)
|
t.Log(obj)
|
||||||
|
|
||||||
var a interface{} = &Manage{ID: 123123}
|
var a interface{} = &Manage{ID: 123123}
|
||||||
|
|
||||||
out := make([]interface{}, 0)
|
out := make([]interface{}, 0)
|
||||||
|
@ -7,39 +7,57 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// SearchParams 搜索参数
|
||||||
|
SearchParams struct {
|
||||||
|
MustParams map[string]interface{}
|
||||||
|
ShouldParams map[string]interface{}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// Create 创建操作
|
// Create 创建操作
|
||||||
func Create(index string, body []byte) error {
|
func Create(index string, body []byte) error {
|
||||||
_, err := client.Index().
|
_, err := client.Index().
|
||||||
Index(index).
|
Index(index).
|
||||||
|
//Id(fmt.Sprintf("%d", 1)).
|
||||||
BodyJson(string(body)).
|
BodyJson(string(body)).
|
||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search 搜索操作
|
// Search 搜索操作
|
||||||
func Search(src interface{}, index string, params map[string]interface{}, page, pageSize int) ([]interface{}, error) {
|
func Search(src interface{}, index string, params *SearchParams, page, pageSize int) ([]interface{}, error) {
|
||||||
query := elastic.NewBoolQuery()
|
query := elastic.NewBoolQuery()
|
||||||
|
|
||||||
for k, v := range params {
|
if params != nil {
|
||||||
|
if params.MustParams != nil && len(params.MustParams) > 0 {
|
||||||
|
for k, v := range params.MustParams {
|
||||||
|
query.Must(elastic.NewMatchQuery(k, v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if params.ShouldParams != nil && len(params.ShouldParams) > 0 {
|
||||||
|
for k, v := range params.ShouldParams {
|
||||||
query.Should(elastic.NewMatchQuery(k, v))
|
query.Should(elastic.NewMatchQuery(k, v))
|
||||||
}
|
}
|
||||||
service := client.Search().Index(index).Pretty(true).Query(query)
|
}
|
||||||
|
}
|
||||||
|
service := client.Search().Index(index)
|
||||||
|
|
||||||
if page > 0 && pageSize > 0 {
|
if page > 0 && pageSize > 0 {
|
||||||
// 游标分页
|
// 游标分页
|
||||||
service.From((page - 1) * pageSize)
|
service = service.From((page - 1) * pageSize).Size(pageSize)
|
||||||
service.Size(pageSize)
|
|
||||||
}
|
}
|
||||||
result, err := service.Do(context.Background())
|
result, err := service.Pretty(true).Query(query).Do(context.Background())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
out := make([]interface{}, 0)
|
out := make([]interface{}, 0)
|
||||||
|
|
||||||
|
_type := reflect.TypeOf(src)
|
||||||
|
|
||||||
for _, hit := range result.Hits.Hits {
|
for _, hit := range result.Hits.Hits {
|
||||||
data := new(interface{})
|
data := reflect.New(_type).Interface()
|
||||||
reflect.DeepEqual(data, src)
|
|
||||||
|
|
||||||
if err = json.Unmarshal(hit.Source, data); err != nil {
|
if err = json.Unmarshal(hit.Source, data); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -48,3 +66,9 @@ func Search(src interface{}, index string, params map[string]interface{}, page,
|
|||||||
}
|
}
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete 删除操作
|
||||||
|
func Delete(index string) error {
|
||||||
|
_, err := client.DeleteIndex(index).Do(context.Background())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user