feat:完善项目
This commit is contained in:
@ -3,7 +3,9 @@ package api
|
||||
import (
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type ES struct{}
|
||||
@ -57,5 +59,9 @@ func (*ES) Search(c *gin.Context) {
|
||||
service.WithPatentIndustry(form.Industry),
|
||||
)
|
||||
data, err := manage.Search(1, 10)
|
||||
|
||||
for _, v := range data.([]interface{}) {
|
||||
fmt.Println(reflect.TypeOf(v).String())
|
||||
}
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
24
app/api/website/api/search.go
Normal file
24
app/api/website/api/search.go
Normal file
@ -0,0 +1,24 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/controller"
|
||||
"SciencesServer/app/basic/api"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Search struct{}
|
||||
|
||||
func (*Search) Launch(c *gin.Context) {
|
||||
form := &struct {
|
||||
Mode int `json:"mode" form:"mode" binding:"required"`
|
||||
Keyword string `json:"keyword" form:"keyword" 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 := controller.NewSearch()().Launch(form.Mode, form.Keyword, form.Industry, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
@ -31,14 +31,7 @@ func (*Sys) Banner(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (*Sys) About(c *gin.Context) {
|
||||
form := &struct {
|
||||
NavigationID string `json:"navigation_id" form:"navigation_id"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := sys.NewAbout()(api.GetTenantID()(c).(uint64)).Instance((&api.IDStringForm{ID: form.NavigationID}).Convert())
|
||||
data, err := sys.NewAbout()(api.GetTenantID()(c).(uint64)).Instance()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
config2 "SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
@ -9,6 +10,7 @@ import (
|
||||
"SciencesServer/config"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -31,7 +33,8 @@ type (
|
||||
ActivityDetail struct {
|
||||
ID string `json:"id"`
|
||||
*model.ActivityInstanceDetail
|
||||
JoinStatus bool `json:"join_status"`
|
||||
Industry string `json:"industry"`
|
||||
IsJoin bool `json:"is_join"`
|
||||
}
|
||||
)
|
||||
|
||||
@ -70,21 +73,21 @@ func (c *Activity) Instance(title, industry string, status, page, pageSize int)
|
||||
list := make([]*ActivityInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
v.Image.Image = v.Image.Analysis(config.SystemConfig[config.SysImageDomain])
|
||||
|
||||
data := &ActivityInfo{
|
||||
ID: v.GetEncodeID(), ActivityInstanceInfo: v, IsJoin: v.JoinID > 0, Status: 2,
|
||||
}
|
||||
|
||||
if now.After(v.BeginAt) {
|
||||
if now.Before(v.BeginAt) {
|
||||
data.Status = 1
|
||||
goto CONTINUE
|
||||
}
|
||||
|
||||
if now.Before(v.FinishAt) {
|
||||
if now.After(v.FinishAt) {
|
||||
data.Status = 3
|
||||
goto CONTINUE
|
||||
}
|
||||
CONTINUE:
|
||||
|
||||
list = append(list, data)
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
@ -99,12 +102,19 @@ func (c *Activity) Detail(id uint64) (*ActivityDetail, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mActivityInstance.Image.Image = mActivityInstance.Image.Analysis(config.SystemConfig[config.SysImageDomain])
|
||||
out.Image.Image = out.Image.Analysis(config.SystemConfig[config.SysImageDomain])
|
||||
|
||||
industrys := make([]string, 0)
|
||||
|
||||
for _, v := range out.GetIndustryAttribute() {
|
||||
industrys = append(industrys, config2.GetIndustryInfo(v, "-", "-"))
|
||||
}
|
||||
|
||||
return &ActivityDetail{
|
||||
ID: out.GetEncodeID(),
|
||||
ActivityInstanceDetail: out,
|
||||
JoinStatus: out.JoinID > 0.,
|
||||
Industry: strings.Join(industrys, ";"),
|
||||
IsJoin: out.JoinID > 0.,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
59
app/api/website/controller/search.go
Normal file
59
app/api/website/controller/search.go
Normal file
@ -0,0 +1,59 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/service"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Search struct{}
|
||||
|
||||
type SearchHandle func() *Search
|
||||
|
||||
var searchHandle = map[int]func(int, int, string, string) (interface{}, error){
|
||||
1: searchCompany,
|
||||
}
|
||||
|
||||
// searchCompany 公司搜索
|
||||
func searchCompany(page, pageSize int, keyword, industry string) (interface{}, error) {
|
||||
manage := service.NewESManage(
|
||||
service.WithManageIdentity(config.TenantUserIdentityForCompany),
|
||||
service.WithManageTitle(keyword),
|
||||
service.WithManageKeyword(keyword),
|
||||
service.WithManageResearch(keyword),
|
||||
)
|
||||
if industry != "" {
|
||||
manage.Industry = industry
|
||||
}
|
||||
out, err := manage.Search(page, pageSize, nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids := make([]uint64, 0)
|
||||
|
||||
for _, v := range out.([]interface{}) {
|
||||
val := v.(*service.ESManage)
|
||||
ids = append(ids, val.ID)
|
||||
}
|
||||
if len(ids) <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Launch 发起搜索
|
||||
func (c *Search) Launch(mode int, keyword, industry string, page, pageSize int) (interface{}, error) {
|
||||
handle, has := searchHandle[mode]
|
||||
|
||||
if !has {
|
||||
return nil, errors.New("操作错误,未知的搜索模式")
|
||||
}
|
||||
return handle(page, pageSize, keyword, industry)
|
||||
}
|
||||
|
||||
func NewSearch() SearchHandle {
|
||||
return func() *Search {
|
||||
return &Search{}
|
||||
}
|
||||
}
|
@ -14,9 +14,10 @@ type AboutHandle func(tenantID uint64) *About
|
||||
type (
|
||||
// AboutInfo 基本信息
|
||||
AboutInfo struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Children []*AboutInfo `json:"children"`
|
||||
}
|
||||
// AboutNavigationInfo 导航栏信息
|
||||
AboutNavigationInfo struct {
|
||||
@ -25,17 +26,32 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (c *About) tree(src []*model2.SysAbout, parentID uint64) []*AboutInfo {
|
||||
out := make([]*AboutInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &AboutInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
Title: v.Title,
|
||||
Content: v.Content,
|
||||
Children: nil,
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Instance 关于信息
|
||||
func (c *About) Instance(parentID uint64) (*AboutInfo, error) {
|
||||
func (c *About) Instance() ([]*AboutInfo, error) {
|
||||
mSysAbout := model.NewSysAbout()
|
||||
|
||||
if isExist, err := model2.FirstField(mSysAbout.SysAbout, []string{"id", "title", "content"},
|
||||
model2.NewWhere("parent_id", parentID)); err != nil {
|
||||
out := make([]*model2.SysAbout, 0)
|
||||
|
||||
if err := model2.ScanFields(mSysAbout.SysAbout, &out, []string{"id", "title", "content"}); err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, nil
|
||||
}
|
||||
return &AboutInfo{ID: mSysAbout.GetEncodeID(), Title: mSysAbout.Title, Content: mSysAbout.Content}, nil
|
||||
return c.tree(out, 0), nil
|
||||
}
|
||||
|
||||
// Navigation 导航栏
|
||||
|
@ -14,6 +14,7 @@ type ActivityInstance struct {
|
||||
ContactMobile string `gorm:"column:contact_mobile;type:varchar(15);default:'';comment:联系方式" json:"contact_mobile"`
|
||||
Image
|
||||
Area
|
||||
Description string `gorm:"column:description;type:varchar(255);comment:描述" json:"description"`
|
||||
Industry string `gorm:"column:industry;type:varchar(255);comment:所属领域;行业信息" json:"-"`
|
||||
Amount float64 `gorm:"column:amount;type:decimal(10,2);default:0;comment:活动收费金额" json:"amount"`
|
||||
Content string `gorm:"column:content;type:text;comment:活动详情" json:"content"`
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"SciencesServer/serve/es"
|
||||
"SciencesServer/serve/logger"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ESAchievement struct {
|
||||
@ -24,7 +25,7 @@ func (this *ESAchievement) Create() error {
|
||||
this.Title = this.Industry + " - " + this.Title
|
||||
}
|
||||
_bytes, _ := json.Marshal(this)
|
||||
return es.Create(this.Index(), _bytes)
|
||||
return es.Create(this.Index(), fmt.Sprintf("%d", this.ID), _bytes)
|
||||
}
|
||||
|
||||
func (this *ESAchievement) Search(page, pageSize int) (interface{}, error) {
|
||||
|
@ -27,7 +27,7 @@ func (this *ESManage) Index() string {
|
||||
|
||||
func (this *ESManage) Create() error {
|
||||
_bytes, _ := json.Marshal(this)
|
||||
return es.Create(this.Index(), _bytes)
|
||||
return es.Create(this.Index(), fmt.Sprintf("%d", this.ID), _bytes)
|
||||
}
|
||||
|
||||
func (this *ESManage) Search(page, pageSize int, params map[string]interface{}) (interface{}, error) {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"SciencesServer/serve/es"
|
||||
"SciencesServer/serve/logger"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ESPatent struct {
|
||||
@ -20,7 +21,11 @@ func (this *ESPatent) Index() string {
|
||||
|
||||
func (this *ESPatent) Create() error {
|
||||
_bytes, _ := json.Marshal(this)
|
||||
return es.Create(this.Index(), _bytes)
|
||||
return es.Create(this.Index(), fmt.Sprintf("%d", this.ID), _bytes)
|
||||
}
|
||||
|
||||
func (this *ESPatent) Update() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *ESPatent) Search(page, pageSize int) (interface{}, error) {
|
||||
|
@ -35,6 +35,12 @@ func registerAPI(app *gin.Engine) {
|
||||
indexV1.GET("/distribution/achievement", _api.DistributionAchievement)
|
||||
indexV1.GET("/distribution/company", _api.DistributionCompany)
|
||||
}
|
||||
// Search 搜索管理
|
||||
searchV1 := v1.Group("/search")
|
||||
{
|
||||
_api := new(api2.Search)
|
||||
searchV1.POST("", _api.Launch)
|
||||
}
|
||||
// Config 首页信息管理
|
||||
configV1 := v1.Group("/config")
|
||||
{
|
||||
@ -71,7 +77,7 @@ func registerAPI(app *gin.Engine) {
|
||||
sysV1.GET("/navigation", _api.Navigation)
|
||||
sysV1.GET("/agreement", _api.Agreement)
|
||||
sysV1.GET("/agreement/detail", _api.AgreementDetail)
|
||||
sysV1.POST("/about", _api.About)
|
||||
sysV1.GET("/about", _api.About)
|
||||
sysV1.GET("/about/navigation", _api.AboutNavigation)
|
||||
sysV1.GET("/industry", _api.Industry)
|
||||
}
|
||||
|
@ -17,15 +17,25 @@ type (
|
||||
)
|
||||
|
||||
// Create 创建操作
|
||||
func Create(index string, body []byte) error {
|
||||
func Create(index, id string, body []byte) error {
|
||||
_, err := client.Index().
|
||||
Index(index).
|
||||
//Id(fmt.Sprintf("%d", 1)).
|
||||
Id(id).
|
||||
BodyJson(string(body)).
|
||||
Do(context.Background())
|
||||
return err
|
||||
}
|
||||
|
||||
// Update 更新操作
|
||||
func Update(index, id string, body []byte) error {
|
||||
_, err := client.Update().
|
||||
Index(index).
|
||||
Id(id).
|
||||
Doc(string(body)).
|
||||
Do(context.Background())
|
||||
return err
|
||||
}
|
||||
|
||||
// Search 搜索操作
|
||||
func Search(src interface{}, index string, params *SearchParams, page, pageSize int) ([]interface{}, error) {
|
||||
query := elastic.NewBoolQuery()
|
||||
|
Reference in New Issue
Block a user