package webfacade import ( "git.ichub.com/general/webcli120/goconfig/base/basedto" "git.ichub.com/general/webcli120/goconfig/base/baseindex" "git.ichub.com/general/webcli120/goweb/page" "github.com/olivere/elastic/v7" webreq2 "icd/cms/baseindex/webreq" ) // Default // DefaultOf func Default[T baseindex.IndexMapping]() *WebFacade[T] { return &WebFacade[T]{ Meta: webreq2.DefaultMeta[T](), Cmd: webreq2.DefaultCmd[T](), WebRequest: webreq2.Default[T](), } } func DefaultOf[T baseindex.IndexMapping](generalQ elastic.Query) *WebFacade[T] { var q = Default[T]() q.Query(generalQ) return q } type WebFacade[T baseindex.IndexMapping] struct { Meta *webreq2.MetaRequest[T] Cmd *webreq2.CmdRequest[T] *webreq2.WebRequest[T] } func (self *WebFacade[T]) MetaDropIndex() *basedto.IchubResult { return self.Meta.MetaDropIndex() } func (self *WebFacade[T]) MetaCreateIndex() *basedto.IchubResult { return self.Meta.MetaCreateIndex() } func (self *WebFacade[T]) MetaIndexExists() *basedto.IchubResult { return self.Meta.MetaIndexExists() } func (self *WebFacade[T]) CreateIndexIfNotExist() *basedto.IchubResult { return self.Meta.CreateIndexIfNotExist() } func (self *WebFacade[T]) CreateIndexesIfNotExist() *basedto.IchubResult { return self.Meta.CreateIndexesIfNotExist() } func (self *WebFacade[T]) MetaGetMapping() *basedto.IchubResult { return self.Meta.MetaGetMapping() } func (self *WebFacade[T]) WebSaveIndex(id any) *basedto.IchubResult { return self.Cmd.WebSaveIndex(id) } func (self *WebFacade[T]) Save(id any, doc map[string]any) *basedto.IchubResult { return self.Cmd.Save(id, doc) } func (self *WebFacade[T]) SaveStru(id any, stru any) *basedto.IchubResult { return self.Cmd.SaveStru(id, stru) } func (self *WebFacade[T]) CmsExistId(id string) *page.PageResult { return self.Cmd.CmsExistId(id) } func (self *WebFacade[T]) SaveIndex(indexTable baseindex.IndexIface) *basedto.IchubResult { return self.Cmd.SaveIndex(indexTable) } func (self *WebFacade[T]) UpdataParam2Script(fieldAsParams map[string]interface{}) string { return self.Cmd.UpdataParam2Script(fieldAsParams) } func (self *WebFacade[T]) BulkUpsert() *basedto.IchubResult { return self.Cmd.BulkUpsert() } func (self *WebFacade[T]) UpdateByQueryParam(fieldAsParams map[string]any) *basedto.IchubResult { return self.Cmd.UpdateByQueryParam(fieldAsParams) } func (self *WebFacade[T]) UpdateByQuery(updateClause string, fieldParams map[string]any) *basedto.IchubResult { return self.Cmd.UpdateByQuery(updateClause, fieldParams) } func (self *WebFacade[T]) UpdateIndex(doc baseindex.IndexIface) *basedto.IchubResult { return self.Cmd.UpdateIndex(doc) } func (self *WebFacade[T]) UpdateStru(ids any, doc any) *basedto.IchubResult { return self.Cmd.UpdateStru(ids, doc) } func (self *WebFacade[T]) Update(ids any, doc map[string]any) *basedto.IchubResult { return self.Cmd.Update(ids, doc) } func (self *WebFacade[T]) Update2Err(id any, doc map[string]any) error { return self.Cmd.Update2Err(id, doc) } func (self *WebFacade[T]) DeleteByQuery() *basedto.IchubResult { return self.Cmd.DeleteByQuery() } func (self *WebFacade[T]) Delete(id any) *basedto.IchubResult { return self.Cmd.Delete(id) } func (self *WebFacade[T]) BulkDelete(ids ...any) *basedto.IchubResult { return self.Cmd.BulkDelete(ids...) }
package webfacade import ( "git.ichub.com/general/webcli120/goconfig/ichublog/golog" "github.com/olivere/elastic/v7" "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "icd/basic/common" "icd/cms/shop/model" "testing" ) type TestWebFacadeSuite struct { suite.Suite *WebFacade[*model.CmsColumnEs] } func TestWebFacadeSuites(t *testing.T) { suite.Run(t, new(TestWebFacadeSuite)) } func (suite *TestWebFacadeSuite) SetupSuite() { logrus.Info(" setup suite") if common.Env == "" { common.Env = "test" } //patches = gomonkey.ApplyGlobalVar(&common.Env, "test") suite.WebFacade = Default[*model.CmsColumnEs]() } func (suite *TestWebFacadeSuite) TearDownSuite() { logrus.Info(" teardown suite") } func (suite *TestWebFacadeSuite) SetupTest() { logrus.Info(" setup test") } func (suite *TestWebFacadeSuite) TearDownTest() { logrus.Info(" teardown test") } func (suite *TestWebFacadeSuite) Test001_GeneralQuery() { var q = suite.WebRequest q.Query(elastic.NewMatchAllQuery()) q.SetPageSize(2) var result = q.GeneralQuery() golog.Info(result) } func (suite *TestWebFacadeSuite) Test002_WebRequest() { var cmd = suite.Cmd //DefaultCmd[*CmsListEs]() cmd.EsMust().EsTerm("content_id", 895864411552153601) updateInfo := make(map[string]interface{}) updateInfo["user_name"] = "abc" var result = cmd.UpdateByQueryParam(updateInfo) golog.Info(result) }
INFO[2024-10-1026 15:42:21]C:/Users/admin/go/pkg/mod/git.ichub.com/general/[email protected]/goconfig/base/goutils/go_log.go:88 git.ichub.com/general/webcli120/goconfig/base/goutils.Info() {
"code": 200,
"msg": "成功",
"request_id": "5afea2a8-89ed-4aab-8d5e-b0e4536dcc36",
"hosturl": "http://192.168.27.144:88/query",
"total": 10000,
"page_size": 2,
"current": 1,
"cmd_name": "ES_HTTPCLI_QUERY_SOURCE",
"cmd_type": 39,
"data_highlight": [],
"data": [
{
"column_id": 760282443997511681,
"shop_id": 760282429351821313,
"editor_id": 760282429651124225,
"ad_editor_id": 760282429651124225,
"publisher_spu_id": 0,
"layout_id": 760282443897634817,
"spu_categ_shop_categ_id": 1,
"parent_id": 0,
"name": "芯闻",
"code": "",
"slug": "",
"description": "",
"path": "",
"IsVirtual": false,
"is_fixed": true,
"is_default": false,
"domain": "",
"resource_name": "",
"active": true,
"list_order": 560,
"seo_title": "",
"seo_tag": "",
"seo_description": "",
"topic": "",
"created_at": "2022-05-09T09:56:28.83203Z",
"created_by": -1,
"updated_at": "2022-05-09T09:56:28.83203Z",
"updated_at_int": 1652090188,
"visit_count": 0,
"read_count": 0,
"like_count": 0,
"content_count": 0,
"collect_count": 0,
"share_count": 0,
"comment_count": 0,
"keyword_id": null,
"reply_count": 0,
"parent_name": "",
"updated_by": 0,
"deleted_at": "0001-01-01T00:00:00Z",
"deleted_by": 0,
"banner": "",
"content_list": "",
"sidebar1": "",
"sidebar2": "",
"sidebar3": "",
"sidebar4": "",
"sidebar5": "",
"sidebar6": "",
"advertising_banner": 0,
"advertising_content": 0,
"advertising_newest": 0,
"advertising_hot": 0,
"advertising_recommend": 0,
"advertising_notice": 0,
"advertising_content_details": 0,
"advertising_content_display_page": 0,
"layout_type_id": 1,
"editor_id_name": "百岁山",
"is_platform": false,
"ad_editor_name": "百岁山",
"advertising_banner_name": "",
"advertising_content_name": "",
"advertising_newest_name": "",
"advertising_hot_name": "",
"advertising_recommend_name": "",
"advertising_notice_name": "",
"advertising_content_details_name": "",
"advertising_content_display_page_name": "",
"column_name": "",
"content_name": "",
"content_type": 0,
"publishing_at": null,
"author_member_id": 0,
"author_member_name": "",
"content_id": 0,
"sub_action": 0,
"publishing_id": 0,
"cms_slide_slot": null,
"layout_name": "方案1",
"user_id": 0,
"type": 0,
"is_first": true,
"is_unified": false,
"option": "",
"contribution_count": 0,
"publish_count": 1,
"reprint_count": 0,
"circulate_count": 0,
"advert_count": 0,
"msg_count": 0,
"content_layout": "",
"column_layout": ""
},
{
"column_id": 760518700528599041,
"shop_id": 760518694247366657,
"editor_id": 760518694449905665,
"ad_editor_id": 760518694449905665,
"publisher_spu_id": 0,
"layout_id": 760518700411289601,
"spu_categ_shop_categ_id": 1,
"parent_id": 0,
"name": "芯闻",
"code": "",
"slug": "",
"description": "",
"path": "",
"IsVirtual": false,
"is_fixed": true,
"is_default": false,
"domain": "",
"resource_name": "",
"active": true,
"list_order": 566,
"seo_title": "",
"seo_tag": "",
"seo_description": "",
"topic": "",
"created_at": "2022-05-10T05:58:08.569582Z",
"created_by": -1,
"updated_at": "2022-05-10T05:58:08.562549008Z",
"updated_at_int": 1652162288,
"visit_count": 0,
"read_count": 0,
"like_count": 0,
"content_count": 0,
"collect_count": 0,
"share_count": 0,
"comment_count": 0,
"keyword_id": null,
"reply_count": 0,
"parent_name": "",
"updated_by": 0,
"deleted_at": "0001-01-01T00:00:00Z",
"deleted_by": 0,
"banner": "",
"content_list": "",
"sidebar1": "",
"sidebar2": "",
"sidebar3": "",
"sidebar4": "",
"sidebar5": "",
"sidebar6": "",
"advertising_banner": 0,
"advertising_content": 0,
"advertising_newest": 0,
"advertising_hot": 0,
"advertising_recommend": 0,
"advertising_notice": 0,
"advertising_content_details": 0,
"advertising_content_display_page": 0,
"layout_type_id": 1,
"editor_id_name": "张晓晓",
"is_platform": false,
"ad_editor_name": "张晓晓",
"advertising_banner_name": "",
"advertising_content_name": "",
"advertising_newest_name": "",
"advertising_hot_name": "",
"advertising_recommend_name": "",
"advertising_notice_name": "",
"advertising_content_details_name": "",
"advertising_content_display_page_name": "",
"column_name": "",
"content_name": "",
"content_type": 0,
"publishing_at": null,
"author_member_id": 0,
"author_member_name": "",
"content_id": 0,
"sub_action": 0,
"publishing_id": 0,
"cms_slide_slot": null,
"layout_name": "方案1",
"user_id": 0,
"type": 0,
"is_first": false,
"is_unified": false,
"option": "",
"contribution_count": 0,
"publish_count": 1,
"reprint_count": 0,
"circulate_count": 0,
"advert_count": 0,
"msg_count": 0,
"content_layout": "",
"column_layout": ""
}
]
}
INFO[2024-10-1026 15:42:21]D:/gitlab.ichub.com/cms/icd/cms/baseindex/webfacade/web_facade_test.go:41 icd/cms/baseindex/webfacade.(*TestWebFacadeSuite).TearDownTest() teardown test
INFO[2024-10-1026 15:42:21]D:/gitlab.ichub.com/cms/icd/cms/baseindex/webfacade/web_facade_test.go:33 icd/cms/baseindex/webfacade.(*TestWebFacadeSuite).TearDownSuite() teardown suite
--- PASS: TestWebFacadeSuites/Test001_GeneralQuery (0.12s)
PASS
Process finished with the exit code 0