diff --git a/app/api/website/api/es.go b/app/api/website/api/es.go index 35f8515..4ff564c 100644 --- a/app/api/website/api/es.go +++ b/app/api/website/api/es.go @@ -11,6 +11,7 @@ type ES struct{} func (*ES) Create(c *gin.Context) { form := &struct { ID uint64 `json:"id" form:"id"` + Identity int `json:"identity" form:"identity"` Title string `json:"title" form:"title"` Keyword string `json:"keyword" form:"keyword"` Research string `json:"research" form:"research"` @@ -19,8 +20,9 @@ func (*ES) Create(c *gin.Context) { api.APIFailure(err.(error))(c) return } - manage := service.NewManage( + manage := service.NewESManage( service.WithManageID(form.ID), + service.WithManageIdentity(form.Identity), service.WithManageTitle(form.Title), service.WithManageKeyword(form.Keyword), service.WithManageResearch(form.Research), @@ -30,13 +32,19 @@ func (*ES) Create(c *gin.Context) { func (*ES) Search(c *gin.Context) { 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 { api.APIFailure(err.(error))(c) return } - manage := service.NewManage() - data, err := manage.Search(1, 10, form.Params) + manage := service.NewESManage(service.WithManageIdentity(form.Identity), + 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) } diff --git a/app/api/website/api/manage.go b/app/api/website/api/manage.go new file mode 100644 index 0000000..3bbbb80 --- /dev/null +++ b/app/api/website/api/manage.go @@ -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) +} diff --git a/app/api/website/controller/manage/company.go b/app/api/website/controller/manage/company.go new file mode 100644 index 0000000..b3c743e --- /dev/null +++ b/app/api/website/controller/manage/company.go @@ -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} + } +} diff --git a/app/api/website/controller/manage/search.go b/app/api/website/controller/manage/search.go index 789483d..c0d0ab9 100644 --- a/app/api/website/controller/manage/search.go +++ b/app/api/website/controller/manage/search.go @@ -5,6 +5,7 @@ import ( "SciencesServer/app/basic/config" model2 "SciencesServer/app/common/model" "SciencesServer/app/service" + config2 "SciencesServer/config" "errors" ) @@ -27,6 +28,7 @@ var searchIdentityHandle = map[int]func(ids []uint64) (interface{}, error){ config.TenantUserIdentityForAgent: company, } +// company 公司信息 func company(ids []uint64) (interface{}, error) { mManageCompany := model.NewManageCompany() out := make([]*model2.ManageCompany, 0) @@ -39,7 +41,17 @@ func company(ids []uint64) (interface{}, error) { }); err != nil { 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) { @@ -87,20 +99,24 @@ func laboratory(ids []uint64) (interface{}, error) { return out, nil } -func (c *Search) Launch(identity int, params string) (interface{}, error) { - manage := service.NewManage() - - _params := map[string]interface{}{ - "title": params, "keyword": params, "research": params, - } - data, err := manage.Search(1, 1, _params) +func (c *Search) Launch(identity int, param, industry string, page, pageSize int) (interface{}, error) { + manage := service.NewESManage( + service.WithManageIdentity(identity), + service.WithManageTitle(param), + service.WithManageIndustry(industry), + service.WithManageKeyword(param), + service.WithManageResearch(param), + ) + out, err := manage.Search(page, pageSize) if err != nil { return nil, err + } else if out == nil { + return nil, nil } ids := make([]uint64, 0) - for _, v := range data.([]*service.Manage) { + for _, v := range out.([]*service.ESManage) { if v.Identity != identity { continue } diff --git a/app/api/website/model/manage_company.go b/app/api/website/model/manage_company.go index 34ce79e..84c7b0b 100644 --- a/app/api/website/model/manage_company.go +++ b/app/api/website/model/manage_company.go @@ -1,11 +1,54 @@ package model -import "SciencesServer/app/common/model" +import ( + "SciencesServer/app/common/model" + "SciencesServer/serve/orm" + "fmt" +) type ManageCompany struct { *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 { return &ManageCompany{model.NewManageCompany()} } diff --git a/app/common/model/manage_agent.go b/app/common/model/manage_agent.go index eeee27c..f0d99f0 100644 --- a/app/common/model/manage_agent.go +++ b/app/common/model/manage_agent.go @@ -13,7 +13,7 @@ type ManageAgent struct { 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"` 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:"-"` 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"` diff --git a/app/common/model/manage_expert.go b/app/common/model/manage_expert.go index f6cbe8e..c114716 100644 --- a/app/common/model/manage_expert.go +++ b/app/common/model/manage_expert.go @@ -22,7 +22,7 @@ type ManageExpert struct { Title string `gorm:"column:title;type:varchar(50);default:'';comment:职称" json:"title"` Gender 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"` Research string `gorm:"column:research;type:varchar(255);default:'';comment:研究信息" json:"research"` Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"` diff --git a/app/common/model/manage_laboratory.go b/app/common/model/manage_laboratory.go index 8c3e1a0..203a82f 100644 --- a/app/common/model/manage_laboratory.go +++ b/app/common/model/manage_laboratory.go @@ -15,7 +15,7 @@ type ManageLaboratory struct { Area Url string `gorm:"column:url;type:varchar(255);default:'';comment:实验室网站" json:"url"` 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"` Research string `gorm:"column:research;type:varchar(255);default:'';comment:研究信息" json:"research"` Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"` diff --git a/app/common/model/manage_research.go b/app/common/model/manage_research.go index 71cde31..d659ba6 100644 --- a/app/common/model/manage_research.go +++ b/app/common/model/manage_research.go @@ -13,7 +13,7 @@ type ManageResearch struct { Image Area 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"` Research string `gorm:"column:research;type:varchar(255);default:'';comment:研究信息" json:"research"` Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"` diff --git a/app/common/model/sys_patent_classify.go b/app/common/model/sys_patent_classify.go index e285a35..a0a1995 100644 --- a/app/common/model/sys_patent_classify.go +++ b/app/common/model/sys_patent_classify.go @@ -4,7 +4,7 @@ package model type SysPatentClassify struct { Model 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"` ModelDeleted ModelAt diff --git a/app/common/model/technology_demand.go b/app/common/model/technology_demand.go index 9405890..9e1c0cf 100644 --- a/app/common/model/technology_demand.go +++ b/app/common/model/technology_demand.go @@ -15,7 +15,7 @@ type TechnologyDemand struct { Kind string `gorm:"column:kind;type:varchar(50);default:'';comment:需求类别" json:"-"` Name string `gorm:"column:name;type:varchar(30);default:'';comment:联系人" json:"name"` 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"` 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"` diff --git a/app/common/model/technology_prodcut.go b/app/common/model/technology_prodcut.go index e9744e8..58d5741 100644 --- a/app/common/model/technology_prodcut.go +++ b/app/common/model/technology_prodcut.go @@ -14,7 +14,7 @@ type TechnologyProduct struct { Image Video string `gorm:"column:video;type:varchar(255);default:'';comment:视频地址" json:"video"` 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:"-"` 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"` diff --git a/app/service/es.go b/app/service/es.go deleted file mode 100644 index 31f6481..0000000 --- a/app/service/es.go +++ /dev/null @@ -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 -} diff --git a/app/service/es_manage.go b/app/service/es_manage.go new file mode 100644 index 0000000..c257588 --- /dev/null +++ b/app/service/es_manage.go @@ -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 +} diff --git a/app/service/es_patent.go b/app/service/es_patent.go new file mode 100644 index 0000000..65670c8 --- /dev/null +++ b/app/service/es_patent.go @@ -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 +} diff --git a/router/address.go b/router/address.go index 7ff61db..7cd7626 100644 --- a/router/address.go +++ b/router/address.go @@ -66,6 +66,14 @@ func registerAPI(app *gin.Engine) { serviceV1.GET("/innovate/kind", _api.InnovateKind) 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 技术信息管理 technologyV1 := v1.Group("/technology") { diff --git a/serve/es/es_test.go b/serve/es/es_test.go index e765c85..ffc8cd7 100644 --- a/serve/es/es_test.go +++ b/serve/es/es_test.go @@ -108,7 +108,6 @@ func TestNewInstance2(t *testing.T) { function := func(src interface{}) { obj := reflect.ValueOf(src).Interface() t.Log(obj) - var a interface{} = &Manage{ID: 123123} out := make([]interface{}, 0) diff --git a/serve/es/serve.go b/serve/es/serve.go index dbbd61e..dd69136 100644 --- a/serve/es/serve.go +++ b/serve/es/serve.go @@ -7,39 +7,57 @@ import ( "reflect" ) +type ( + // SearchParams 搜索参数 + SearchParams struct { + MustParams map[string]interface{} + ShouldParams map[string]interface{} + } +) + // Create 创建操作 func Create(index string, body []byte) error { _, err := client.Index(). Index(index). + //Id(fmt.Sprintf("%d", 1)). BodyJson(string(body)). Do(context.Background()) return err } // 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() - for k, v := range params { - query.Should(elastic.NewMatchQuery(k, v)) + 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)) + } + } } - service := client.Search().Index(index).Pretty(true).Query(query) + service := client.Search().Index(index) if page > 0 && pageSize > 0 { // 游标分页 - service.From((page - 1) * pageSize) - service.Size(pageSize) + service = service.From((page - 1) * pageSize).Size(pageSize) } - result, err := service.Do(context.Background()) + result, err := service.Pretty(true).Query(query).Do(context.Background()) if err != nil { return nil, err } out := make([]interface{}, 0) + _type := reflect.TypeOf(src) + for _, hit := range result.Hits.Hits { - data := new(interface{}) - reflect.DeepEqual(data, src) + data := reflect.New(_type).Interface() if err = json.Unmarshal(hit.Source, data); err != nil { return nil, err @@ -48,3 +66,9 @@ func Search(src interface{}, index string, params map[string]interface{}, page, } return out, err } + +// Delete 删除操作 +func Delete(index string) error { + _, err := client.DeleteIndex(index).Do(context.Background()) + return err +}