From ade9ec8c73fb6904ff5abef1356052de27170575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E4=BA=AE?= Date: Fri, 8 Mar 2024 18:13:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=AE=B1=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20`mongodb`=20=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 9 + README.md | 8 +- RELEASE.md | 9 +- go.mod | 16 +- go.sum | 29 +- internal/module/api.go | 2 + internal/module/module_mongodb/api.go | 524 +++++++++++------------ internal/module/module_toolbox/worker.go | 45 +- package.json | 2 +- 9 files changed, 363 insertions(+), 281 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0c15d3e..41b60f46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# 2.6.11 + +## Version 2.6.11 (2024/3/8) + +发布功能 + +* 工具箱 添加 `mongodb` 支持 + + # 2.6.10 ## Version 2.6.10 (2024/3/5) diff --git a/README.md b/README.md index c4d99e5f..afcbda9a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Team · IDE -Team IDE 集成MySql、Oracle、金仓、达梦、神通等数据库、SSH、FTP、Redis、Zookeeper、Kafka、Elasticsearch、小工具等管理工具 +Team IDE 集成MySql、Oracle、金仓、达梦、神通等数据库、SSH、FTP、Redis、Zookeeper、Kafka、Elasticsearch、Mongodb、小工具等管理工具 [![Code](https://img.shields.io/badge/Code-TeamIDE-red)](https://github.com/team-ide/teamide) [![License](https://img.shields.io/badge/License-Apache--2.0%20License-blue)](https://github.com/team-ide/teamide/blob/main/LICENSE) @@ -38,6 +38,7 @@ Team IDE 集成MySql、Oracle、金仓、达梦、神通等数据库、SSH、FTP * JSON、Yaml转换 **完成** * 时间长转换 **完成** * Base64、MD5等 **完成** + * 二维码生成 **完成** * Thrift * 添加thrift模块,配置thrift文件目录 **完成** * 展示所有thrift服务、方法等 **完成** @@ -45,6 +46,11 @@ Team IDE 集成MySql、Oracle、金仓、达梦、神通等数据库、SSH、FTP * 性能测试,测试报告,图表展示TPS、AVG、Min、Max、T90、T99等 **完成** * SSH隧道 * Mysql、Redis、Zookeeper支持SSH隧道连接,选择SSH后,填写127.0.0.1则连接到SSH本地相应资源 **完成** +* Mongodb + * 库管理 **完成** + * 集合管理 **完成** + * 集合索引编辑 **完成** + * 集合数据查询、新增、修改、删除 **完成** ## 语言 diff --git a/RELEASE.md b/RELEASE.md index ea94c224..a65af194 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,10 +1,7 @@ -# 2.6.10 +# 2.6.11 -## Version 2.6.10 (2024/3/5) +## Version 2.6.11 (2024/3/8) 发布功能 -* redis支持乱码key的查询、更新、删除 -* 小工具添加二维码生成 -* 终端部分SSH服务器下载结束后报错会自动关闭客户端问题修复 -* 客户端模式启动服务使用 `127.0.0.1` 只能本地打开 +* 工具箱 添加 `mongodb` 支持 diff --git a/go.mod b/go.mod index 2bf2131b..45cbc13c 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 //replace ( // github.com/team-ide/go-dialect v1.9.19 => ../go-dialect -// github.com/team-ide/go-tool v1.2.9 => ../go-tool +// github.com/team-ide/go-tool v1.2.12 => ../go-tool //) require ( @@ -20,8 +20,9 @@ require ( github.com/tealeg/xlsx v1.0.5 github.com/team-ide/cron v1.0.1 github.com/team-ide/go-dialect v1.9.19 - github.com/team-ide/go-tool v1.2.10 + github.com/team-ide/go-tool v1.2.12 github.com/team-ide/goja v1.0.2 + go.mongodb.org/mongo-driver v1.14.0 go.uber.org/zap v1.26.0 golang.org/x/crypto v0.18.0 golang.org/x/net v0.20.0 @@ -33,9 +34,10 @@ require ( gitee.com/opengauss/openGauss-connector-go-pq v1.0.4 // indirect github.com/Shopify/sarama v1.38.1 // indirect github.com/andybalholm/cascadia v1.3.1 // indirect - github.com/bytedance/sonic v1.9.1 // indirect + github.com/bytedance/sonic v1.11.2 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect + github.com/chenzhuoyu/iasm v0.9.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dlclark/regexp2 v1.7.0 // indirect @@ -80,6 +82,7 @@ require ( github.com/mattn/go-sqlite3 v1.14.16 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect github.com/olivere/elastic/v7 v7.0.32 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/pierrec/lz4/v4 v4.1.17 // indirect @@ -95,9 +98,14 @@ require ( github.com/tklauser/numcpus v0.6.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect go.uber.org/multierr v1.10.0 // indirect golang.org/x/arch v0.3.0 // indirect + golang.org/x/sync v0.2.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect diff --git a/go.sum b/go.sum index fb04f32f..77a7995b 100644 --- a/go.sum +++ b/go.sum @@ -12,14 +12,18 @@ github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEq github.com/apache/thrift v0.17.0 h1:cMd2aj52n+8VoAtvSvLn4kDC3aZ6IAkBuqWQ2IDu7wo= github.com/apache/thrift v0.17.0/go.mod h1:OLxhMRJxomX+1I/KUw03qoV3mMz16BwaKI+d4fPBx7Q= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= -github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= +github.com/bytedance/sonic v1.11.2 h1:ywfwo0a/3j9HR8wsYGWsIWl2mvRsI950HyoxiBERw5A= +github.com/bytedance/sonic v1.11.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= +github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo= +github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic= github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -141,6 +145,7 @@ github.com/klauspost/compress v1.15.14/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrD github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -167,6 +172,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/mssola/user_agent v0.6.0 h1:uwPR4rtWlCHRFyyP9u2KOV0u8iQXmS7Z7feTrstQwk4= github.com/mssola/user_agent v0.6.0/go.mod h1:TTPno8LPY3wAIEKRpAtkdMT0f8SE24pLRGPahjCH4uw= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= @@ -223,8 +230,8 @@ github.com/team-ide/go-driver v1.3.4 h1:FXlX2KmeV0zGlk4QGEg+ECjcN/BX1I9zYDF6DnSf github.com/team-ide/go-driver v1.3.4/go.mod h1:UhcuTAQRnvBUZXJeOA06eGJDeTqScJyfhyjpyzh3lxg= github.com/team-ide/go-interpreter v0.1.2 h1:m2C973+Wmp0GJ8khjZJfTjDCs9uRKCnMjm7is6+UkUo= github.com/team-ide/go-interpreter v0.1.2/go.mod h1:te6P2p8hjs7dB90D8SNsiOPPMwte/KFceES5ddmasjE= -github.com/team-ide/go-tool v1.2.10 h1:J1e0Z5y3XlZnWpxTPGGuV4gqMs8XUTbe38qfRgvBF14= -github.com/team-ide/go-tool v1.2.10/go.mod h1:1KuU/j9bKWCrpl4R18lNaT4RFfZoCKP2tzHi9/1WQs8= +github.com/team-ide/go-tool v1.2.12 h1:iuWx9FvllxxOL2w6fvk9QMIBx6vyXylqoaXQvlmw7kA= +github.com/team-ide/go-tool v1.2.12/go.mod h1:1KuU/j9bKWCrpl4R18lNaT4RFfZoCKP2tzHi9/1WQs8= github.com/team-ide/goja v1.0.2 h1:AyTbZ+9JKPSAsq90YDEV7g6htbuwN/gntYQptfbAQTo= github.com/team-ide/goja v1.0.2/go.mod h1:Sd/GNJgfOpBvXEGIy2JgJden3hW+WWayjZwC8EATRTM= github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho= @@ -237,9 +244,19 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80= +go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= @@ -285,6 +302,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= +golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -365,4 +383,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/internal/module/api.go b/internal/module/api.go index 10bc75e6..9601984f 100644 --- a/internal/module/api.go +++ b/internal/module/api.go @@ -19,6 +19,7 @@ import ( "teamide/internal/module/module_kafka" "teamide/internal/module/module_log" "teamide/internal/module/module_login" + "teamide/internal/module/module_mongodb" "teamide/internal/module/module_node" "teamide/internal/module/module_power" "teamide/internal/module/module_redis" @@ -182,6 +183,7 @@ func (this_ *Api) GetApis() (apis []*base.ApiWorker, err error) { apis = append(apis, module_setting.NewApi(this_.settingService).GetApis()...) apis = append(apis, module_thrift.NewApi(this_.toolboxService).GetApis()...) apis = append(apis, module_javascript.NewApi(this_.toolboxService).GetApis()...) + apis = append(apis, module_mongodb.NewApi(this_.toolboxService).GetApis()...) return } diff --git a/internal/module/module_mongodb/api.go b/internal/module/module_mongodb/api.go index 379634f8..953c49d8 100644 --- a/internal/module/module_mongodb/api.go +++ b/internal/module/module_mongodb/api.go @@ -1,11 +1,17 @@ package module_mongodb import ( + "encoding/json" "github.com/gin-gonic/gin" - "github.com/team-ide/go-tool/elasticsearch" + "github.com/team-ide/go-tool/mongodb" "github.com/team-ide/go-tool/util" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" "go.uber.org/zap" - "sync" + "reflect" + "strconv" "teamide/internal/module/module_toolbox" "teamide/pkg/base" ) @@ -21,62 +27,65 @@ func NewApi(toolboxService *module_toolbox.ToolboxService) *api { } var ( - Power = base.AppendPower(&base.PowerAction{Action: "mongodb", Text: "Mongodb", ShouldLogin: true, StandAlone: true}) - check = base.AppendPower(&base.PowerAction{Action: "check", Text: "Mongodb测试", ShouldLogin: true, StandAlone: true, Parent: Power}) - infoPower = base.AppendPower(&base.PowerAction{Action: "info", Text: "Mongodb信息", ShouldLogin: true, StandAlone: true, Parent: Power}) - indexesPower = base.AppendPower(&base.PowerAction{Action: "indexes", Text: "ES索引查询", ShouldLogin: true, StandAlone: true, Parent: Power}) - indexStatPower = base.AppendPower(&base.PowerAction{Action: "indexStat", Text: "ES索引状态", ShouldLogin: true, StandAlone: true, Parent: Power}) - createIndexPower = base.AppendPower(&base.PowerAction{Action: "createIndex", Text: "ES创建索引", ShouldLogin: true, StandAlone: true, Parent: Power}) - deleteIndexPower = base.AppendPower(&base.PowerAction{Action: "deleteIndex", Text: "ES删除索引", ShouldLogin: true, StandAlone: true, Parent: Power}) - getMappingPower = base.AppendPower(&base.PowerAction{Action: "getMapping", Text: "ES索引信息查询", ShouldLogin: true, StandAlone: true, Parent: Power}) - putMappingPower = base.AppendPower(&base.PowerAction{Action: "putMapping", Text: "ES索引修改", ShouldLogin: true, StandAlone: true, Parent: Power}) - searchPower = base.AppendPower(&base.PowerAction{Action: "search", Text: "ES搜索", ShouldLogin: true, StandAlone: true, Parent: Power}) - scrollPower = base.AppendPower(&base.PowerAction{Action: "scroll", Text: "ES滚动搜索", ShouldLogin: true, StandAlone: true, Parent: Power}) - requestPower = base.AppendPower(&base.PowerAction{Action: "request", Text: "ES HTTP请求", ShouldLogin: true, StandAlone: true, Parent: Power}) - insertDataPower = base.AppendPower(&base.PowerAction{Action: "insertData", Text: "ES插入数据", ShouldLogin: true, StandAlone: true, Parent: Power}) - updateDataPower = base.AppendPower(&base.PowerAction{Action: "updateData", Text: "ES修改数据", ShouldLogin: true, StandAlone: true, Parent: Power}) - deleteDataPower = base.AppendPower(&base.PowerAction{Action: "deleteData", Text: "ES删除数据", ShouldLogin: true, StandAlone: true, Parent: Power}) - reindexPower = base.AppendPower(&base.PowerAction{Action: "reindex", Text: "ES复制索引", ShouldLogin: true, StandAlone: true, Parent: Power}) - indexAliasPower = base.AppendPower(&base.PowerAction{Action: "indexAlias", Text: "ES索引别名", ShouldLogin: true, StandAlone: true, Parent: Power}) - importPower = base.AppendPower(&base.PowerAction{Action: "import", Text: "ES导入", ShouldLogin: true, StandAlone: true, Parent: Power}) - exportPower = base.AppendPower(&base.PowerAction{Action: "export", Text: "ES导出", ShouldLogin: true, StandAlone: true, Parent: Power}) - taskListPower = base.AppendPower(&base.PowerAction{Action: "taskList", Text: "ES任务列表", ShouldLogin: true, StandAlone: true, Parent: Power}) - taskStatusPower = base.AppendPower(&base.PowerAction{Action: "taskStatus", Text: "ES任务状态", ShouldLogin: true, StandAlone: true, Parent: Power}) - taskStopPower = base.AppendPower(&base.PowerAction{Action: "taskStop", Text: "ES任务停止", ShouldLogin: true, StandAlone: true, Parent: Power}) - taskCleanPower = base.AppendPower(&base.PowerAction{Action: "taskClean", Text: "ES任务清理", ShouldLogin: true, StandAlone: true, Parent: Power}) - closePower = base.AppendPower(&base.PowerAction{Action: "close", Text: "ES关闭", ShouldLogin: true, StandAlone: true, Parent: Power}) + Power = base.AppendPower(&base.PowerAction{Action: "mongodb", Text: "Mongodb", ShouldLogin: true, StandAlone: true}) + check = base.AppendPower(&base.PowerAction{Action: "check", Text: "Mongodb测试", ShouldLogin: true, StandAlone: true, Parent: Power}) + info = base.AppendPower(&base.PowerAction{Action: "info", Text: "Mongodb信息", ShouldLogin: true, StandAlone: true, Parent: Power}) + + database = base.AppendPower(&base.PowerAction{Action: "database", Text: "库", ShouldLogin: true, StandAlone: true, Parent: Power}) + databaseList = base.AppendPower(&base.PowerAction{Action: "list", Text: "列表", ShouldLogin: true, StandAlone: true, Parent: database}) + databaseDelete = base.AppendPower(&base.PowerAction{Action: "delete", Text: "删除", ShouldLogin: true, StandAlone: true, Parent: database}) + databaseDataTrim = base.AppendPower(&base.PowerAction{Action: "dataTrim", Text: "清空数据", ShouldLogin: true, StandAlone: true, Parent: database}) + + collection = base.AppendPower(&base.PowerAction{Action: "collection", Text: "集合", ShouldLogin: true, StandAlone: true, Parent: Power}) + collectionList = base.AppendPower(&base.PowerAction{Action: "list", Text: "列表", ShouldLogin: true, StandAlone: true, Parent: collection}) + collectionDelete = base.AppendPower(&base.PowerAction{Action: "delete", Text: "删除", ShouldLogin: true, StandAlone: true, Parent: collection}) + collectionCreate = base.AppendPower(&base.PowerAction{Action: "create", Text: "创建", ShouldLogin: true, StandAlone: true, Parent: collection}) + collectionDataTrim = base.AppendPower(&base.PowerAction{Action: "dataTrim", Text: "清空数据", ShouldLogin: true, StandAlone: true, Parent: collection}) + + index = base.AppendPower(&base.PowerAction{Action: "index", Text: "索引", ShouldLogin: true, StandAlone: true, Parent: Power}) + indexList = base.AppendPower(&base.PowerAction{Action: "list", Text: "列表", ShouldLogin: true, StandAlone: true, Parent: index}) + indexDelete = base.AppendPower(&base.PowerAction{Action: "delete", Text: "删除", ShouldLogin: true, StandAlone: true, Parent: index}) + indexCreate = base.AppendPower(&base.PowerAction{Action: "create", Text: "创建", ShouldLogin: true, StandAlone: true, Parent: index}) + + insert = base.AppendPower(&base.PowerAction{Action: "insert", Text: "插入", ShouldLogin: true, StandAlone: true, Parent: Power}) + update = base.AppendPower(&base.PowerAction{Action: "update", Text: "更新", ShouldLogin: true, StandAlone: true, Parent: Power}) + delete_ = base.AppendPower(&base.PowerAction{Action: "delete", Text: "删除", ShouldLogin: true, StandAlone: true, Parent: Power}) + deleteById = base.AppendPower(&base.PowerAction{Action: "deleteById", Text: "删除", ShouldLogin: true, StandAlone: true, Parent: Power}) + queryPage = base.AppendPower(&base.PowerAction{Action: "queryPage", Text: "分页查询", ShouldLogin: true, StandAlone: true, Parent: Power}) + + closePower = base.AppendPower(&base.PowerAction{Action: "close", Text: "关闭", ShouldLogin: true, StandAlone: true, Parent: Power}) ) func (this_ *api) GetApis() (apis []*base.ApiWorker) { apis = append(apis, &base.ApiWorker{Power: check, Do: this_.check}) - apis = append(apis, &base.ApiWorker{Power: infoPower, Do: this_.info}) - apis = append(apis, &base.ApiWorker{Power: indexesPower, Do: this_.indexes}) - apis = append(apis, &base.ApiWorker{Power: indexStatPower, Do: this_.indexStat}) - apis = append(apis, &base.ApiWorker{Power: createIndexPower, Do: this_.createIndex}) - apis = append(apis, &base.ApiWorker{Power: deleteIndexPower, Do: this_.deleteIndex}) - apis = append(apis, &base.ApiWorker{Power: getMappingPower, Do: this_.getMapping}) - apis = append(apis, &base.ApiWorker{Power: putMappingPower, Do: this_.putMapping}) - apis = append(apis, &base.ApiWorker{Power: searchPower, Do: this_.search}) - apis = append(apis, &base.ApiWorker{Power: scrollPower, Do: this_.scroll}) - apis = append(apis, &base.ApiWorker{Power: requestPower, Do: this_.request}) - apis = append(apis, &base.ApiWorker{Power: insertDataPower, Do: this_.insertData}) - apis = append(apis, &base.ApiWorker{Power: updateDataPower, Do: this_.updateData}) - apis = append(apis, &base.ApiWorker{Power: deleteDataPower, Do: this_.deleteData}) - apis = append(apis, &base.ApiWorker{Power: reindexPower, Do: this_.reindex}) - apis = append(apis, &base.ApiWorker{Power: indexAliasPower, Do: this_.indexAlias}) - apis = append(apis, &base.ApiWorker{Power: importPower, Do: this_._import}) - apis = append(apis, &base.ApiWorker{Power: exportPower, Do: this_.export}) - apis = append(apis, &base.ApiWorker{Power: taskStatusPower, Do: this_.taskStatus, NotRecodeLog: true}) - apis = append(apis, &base.ApiWorker{Power: taskListPower, Do: this_.taskList}) - apis = append(apis, &base.ApiWorker{Power: taskStopPower, Do: this_.taskStop}) - apis = append(apis, &base.ApiWorker{Power: taskCleanPower, Do: this_.taskClean}) + apis = append(apis, &base.ApiWorker{Power: info, Do: this_.info}) + + apis = append(apis, &base.ApiWorker{Power: databaseList, Do: this_.databases}) + apis = append(apis, &base.ApiWorker{Power: databaseDelete, Do: this_.databaseDelete}) + apis = append(apis, &base.ApiWorker{Power: databaseDataTrim, Do: this_.databaseDataTrim}) + + apis = append(apis, &base.ApiWorker{Power: collectionList, Do: this_.collections}) + apis = append(apis, &base.ApiWorker{Power: collectionCreate, Do: this_.collectionCreate}) + apis = append(apis, &base.ApiWorker{Power: collectionDelete, Do: this_.collectionDelete}) + apis = append(apis, &base.ApiWorker{Power: collectionDataTrim, Do: this_.collectionDataTrim}) + + apis = append(apis, &base.ApiWorker{Power: indexList, Do: this_.indexList}) + apis = append(apis, &base.ApiWorker{Power: indexDelete, Do: this_.indexDelete}) + apis = append(apis, &base.ApiWorker{Power: indexCreate, Do: this_.indexCreate}) + + apis = append(apis, &base.ApiWorker{Power: insert, Do: this_.insert}) + apis = append(apis, &base.ApiWorker{Power: update, Do: this_.update}) + apis = append(apis, &base.ApiWorker{Power: delete_, Do: this_.delete}) + apis = append(apis, &base.ApiWorker{Power: deleteById, Do: this_.deleteById}) + apis = append(apis, &base.ApiWorker{Power: queryPage, Do: this_.queryPage}) + apis = append(apis, &base.ApiWorker{Power: closePower, Do: this_.close}) return } -func (this_ *api) getConfig(requestBean *base.RequestBean, c *gin.Context) (config *elasticsearch.Config, err error) { - config = &elasticsearch.Config{} +func (this_ *api) getConfig(requestBean *base.RequestBean, c *gin.Context) (config *mongodb.Config, err error) { + config = &mongodb.Config{} _, err = this_.toolboxService.BindConfig(requestBean, c, config) if err != nil { return @@ -84,22 +93,22 @@ func (this_ *api) getConfig(requestBean *base.RequestBean, c *gin.Context) (conf return } -func getService(esConfig *elasticsearch.Config) (res elasticsearch.IService, err error) { - key := "elasticsearch-" + esConfig.Url - if esConfig.Username != "" { - key += "-" + base.GetMd5String(key+esConfig.Username) +func getService(config *mongodb.Config) (res mongodb.IService, err error) { + key := "mongodb-" + config.Address + if config.Username != "" { + key += "-" + base.GetMd5String(key+config.Username) } - if esConfig.Password != "" { - key += "-" + base.GetMd5String(key+esConfig.Password) + if config.Password != "" { + key += "-" + base.GetMd5String(key+config.Password) } - if esConfig.CertPath != "" { - key += "-" + base.GetMd5String(key+esConfig.CertPath) + if config.CertPath != "" { + key += "-" + base.GetMd5String(key+config.CertPath) } var serviceInfo *base.ServiceInfo serviceInfo, err = base.GetService(key, func() (res *base.ServiceInfo, err error) { - var s elasticsearch.IService - s, err = elasticsearch.New(esConfig) + var s mongodb.IService + s, err = mongodb.New(config) if err != nil { util.Logger.Error("getService error", zap.Any("key", key), zap.Error(err)) if s != nil { @@ -107,7 +116,7 @@ func getService(esConfig *elasticsearch.Config) (res elasticsearch.IService, err } return } - _, err = s.Info() + _, err = s.Count("_check_for_service_", "_check_for_service_", &map[string]interface{}{}) if err != nil { util.Logger.Error("getService error", zap.Any("key", key), zap.Error(err)) if s != nil { @@ -126,26 +135,28 @@ func getService(esConfig *elasticsearch.Config) (res elasticsearch.IService, err if err != nil { return } - res = serviceInfo.Service.(elasticsearch.IService) + res = serviceInfo.Service.(mongodb.IService) serviceInfo.SetLastUseTime() return } type BaseRequest struct { - WorkerId string `json:"workerId"` - IndexName string `json:"indexName"` - Id string `json:"id"` - Mapping map[string]interface{} `json:"mapping"` - PageIndex int `json:"pageIndex"` - PageSize int `json:"pageSize"` - ScrollId string `json:"scrollId"` - Doc interface{} `json:"doc"` - SourceIndexName string `json:"sourceIndexName"` - DestIndexName string `json:"destIndexName"` - AliasName string `json:"aliasName"` - WhereList []*elasticsearch.Where `json:"whereList"` - OrderList []*elasticsearch.Order `json:"orderList"` - TaskId string `json:"taskId"` + WorkerId string `json:"workerId"` + DatabaseName string `json:"databaseName"` + CollectionName string `json:"collectionName"` + IndexName string `json:"indexName"` + Keys bson.D `json:"keys"` + Filter map[string]interface{} `json:"filter"` + Sort bson.D `json:"sort"` + Id string `json:"id"` + IdType string `json:"idType"` + PageIndex int64 `json:"pageIndex"` + PageSize int64 `json:"pageSize"` + Doc string `json:"doc"` + IsObjectID bool `json:"isObjectID"` + ObjectIDKey string `json:"objectIDKey"` + IndexType string `json:"indexType"` + ExpireAfterSeconds int32 `json:"expireAfterSeconds"` } func (this_ *api) check(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { @@ -161,24 +172,24 @@ func (this_ *api) check(requestBean *base.RequestBean, c *gin.Context) (res inte return } +func (this_ *api) close(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + + return +} func (this_ *api) info(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return } - service, err := getService(config) + _, err = getService(config) if err != nil { return } - res, err = service.Info() - if err != nil { - return - } return } -func (this_ *api) indexes(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { +func (this_ *api) databases(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -188,14 +199,15 @@ func (this_ *api) indexes(requestBean *base.RequestBean, c *gin.Context) (res in return } - res, err = service.Indexes() + res, _, err = service.Databases() if err != nil { return } return } -func (this_ *api) indexStat(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + +func (this_ *api) databaseDelete(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -210,7 +222,7 @@ func (this_ *api) indexStat(requestBean *base.RequestBean, c *gin.Context) (res return } - res, err = service.IndexStat(request.IndexName) + err = service.DatabaseDelete(request.DatabaseName) if err != nil { return } @@ -218,7 +230,7 @@ func (this_ *api) indexStat(requestBean *base.RequestBean, c *gin.Context) (res return } -func (this_ *api) createIndex(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { +func (this_ *api) databaseDataTrim(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -233,13 +245,22 @@ func (this_ *api) createIndex(requestBean *base.RequestBean, c *gin.Context) (re return } - err = service.CreateIndex(request.IndexName, request.Mapping) + collections, err := service.Collections(request.DatabaseName) if err != nil { return } + + for _, one := range collections { + _, err = service.DeleteMany(request.DatabaseName, one.Name, bson.M{}) + if err != nil { + return + } + } + return } -func (this_ *api) deleteIndex(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + +func (this_ *api) collections(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -254,13 +275,15 @@ func (this_ *api) deleteIndex(requestBean *base.RequestBean, c *gin.Context) (re return } - err = service.DeleteIndex(request.IndexName) + res, err = service.Collections(request.DatabaseName) if err != nil { return } + return } -func (this_ *api) getMapping(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + +func (this_ *api) collectionCreate(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -275,13 +298,14 @@ func (this_ *api) getMapping(requestBean *base.RequestBean, c *gin.Context) (res return } - res, err = service.GetMapping(request.IndexName) + err = service.CollectionCreate(request.DatabaseName, request.CollectionName) if err != nil { return } return } -func (this_ *api) putMapping(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + +func (this_ *api) collectionDelete(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -296,13 +320,14 @@ func (this_ *api) putMapping(requestBean *base.RequestBean, c *gin.Context) (res return } - err = service.PutMapping(request.IndexName, request.Mapping) + err = service.CollectionDelete(request.DatabaseName, request.CollectionName) if err != nil { return } return } -func (this_ *api) search(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + +func (this_ *api) collectionDataTrim(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -317,13 +342,15 @@ func (this_ *api) search(requestBean *base.RequestBean, c *gin.Context) (res int return } - res, err = service.Search(request.IndexName, request.PageIndex, request.PageSize, request.WhereList, request.OrderList) + _, err = service.DeleteMany(request.DatabaseName, request.CollectionName, bson.M{}) if err != nil { return } + return } -func (this_ *api) scroll(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + +func (this_ *api) indexList(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -338,13 +365,14 @@ func (this_ *api) scroll(requestBean *base.RequestBean, c *gin.Context) (res int return } - res, err = service.Scroll(request.IndexName, request.ScrollId, request.PageSize, request.WhereList, request.OrderList) + res, err = service.Indexes(request.DatabaseName, request.CollectionName) if err != nil { return } return } -func (this_ *api) request(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + +func (this_ *api) indexDelete(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -354,22 +382,19 @@ func (this_ *api) request(requestBean *base.RequestBean, c *gin.Context) (res in return } - request := elasticsearch.PerformRequestOptions{} - if !base.RequestJSON(&request, c) { + request := &BaseRequest{} + if !base.RequestJSON(request, c) { return } - response, err := service.PerformRequest(request) + err = service.IndexDelete(request.DatabaseName, request.CollectionName, request.IndexName) if err != nil { return } - data := make(map[string]interface{}) - res = data - data["header"] = response.Header - data["body"] = string(response.Body) return } -func (this_ *api) insertData(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + +func (this_ *api) indexCreate(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -383,14 +408,26 @@ func (this_ *api) insertData(requestBean *base.RequestBean, c *gin.Context) (res if !base.RequestJSON(request, c) { return } + i := mongo.IndexModel{} + i.Keys = request.Keys + i.Options = &options.IndexOptions{} + if request.IndexName != "" { + i.Options.SetName(request.IndexName) + } + if request.IndexType == "unique" { + i.Options.SetUnique(true) + } else if request.IndexType == "expireAfterSeconds" { + i.Options.SetExpireAfterSeconds(request.ExpireAfterSeconds) + } - res, err = service.Insert(request.IndexName, request.Id, request.Doc) + res, err = service.IndexCreate(request.DatabaseName, request.CollectionName, i) if err != nil { return } return } -func (this_ *api) updateData(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + +func (this_ *api) insert(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -405,13 +442,61 @@ func (this_ *api) updateData(requestBean *base.RequestBean, c *gin.Context) (res return } - res, err = service.Update(request.IndexName, request.Id, request.Doc) + data := map[string]interface{}{} + err = util.JSONDecodeUseNumber([]byte(request.Doc), &data) + if err != nil { + return + } + res, err = service.Insert(request.DatabaseName, request.CollectionName, data) if err != nil { return } return } -func (this_ *api) deleteData(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + +func (this_ *BaseRequest) getID() interface{} { + switch this_.IdType { + case "M", "map": + data := map[string]interface{}{} + err := util.JSONDecodeUseNumber([]byte(this_.Id), &data) + if err == nil { + return data + } + break + case "primitive.ObjectID", "ObjectID": + if v, e := primitive.ObjectIDFromHex(this_.Id); e == nil { + return v + } + break + case "int64", "int32", "int16", "int8": + if v, e := strconv.ParseInt(this_.Id, 10, 64); e == nil { + switch this_.IdType { + case "int32": + return int32(v) + case "int16": + return int16(v) + case "int8": + return int8(v) + default: + return v + } + } + break + case "float64", "float32": + if v, e := strconv.ParseFloat(this_.Id, 64); e == nil { + switch this_.IdType { + case "float32": + return float32(v) + default: + return v + } + } + break + } + return this_.Id +} + +func (this_ *api) update(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -426,34 +511,25 @@ func (this_ *api) deleteData(requestBean *base.RequestBean, c *gin.Context) (res return } - res, err = service.Delete(request.IndexName, request.Id) - if err != nil { - return - } - return -} -func (this_ *api) reindex(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { - config, err := this_.getConfig(requestBean, c) - if err != nil { - return - } - service, err := getService(config) + var id = request.getID() + data := map[string]interface{}{} + err = util.JSONDecodeUseNumber([]byte(request.Doc), &data) if err != nil { return } - request := &BaseRequest{} - if !base.RequestJSON(request, c) { - return - } + delete(data, "_id") - res, err = service.Reindex(request.SourceIndexName, request.DestIndexName) + res, err = service.Update(request.DatabaseName, request.CollectionName, id, bson.M{ + "$set": data, + }) if err != nil { return } return } -func (this_ *api) indexAlias(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + +func (this_ *api) queryPage(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -468,14 +544,53 @@ func (this_ *api) indexAlias(requestBean *base.RequestBean, c *gin.Context) (res return } - res, err = service.IndexAlias(request.IndexName, request.DestIndexName) + if request.IsObjectID && request.ObjectIDKey != "" && request.Filter[request.ObjectIDKey] != nil { + v, e := primitive.ObjectIDFromHex(util.GetStringValue(request.Filter[request.ObjectIDKey])) + if e == nil { + request.Filter[request.ObjectIDKey] = v + } + } + + page := &mongodb.Page{ + PageSize: request.PageSize, + PageNo: request.PageIndex, + } + opts := options.Find() + opts.SetSort(request.Sort) + result, err := service.QueryMapPageResult(request.DatabaseName, request.CollectionName, request.Filter, page, opts) if err != nil { return } + + res = result + var list []interface{} + + var bs []byte + for _, one := range result.List { + item := one.(map[string]interface{}) + d := map[string]interface{}{} + bs, err = json.MarshalIndent(item, "", " ") + if err != nil { + return + } + if _id, ok := item["_id"]; ok { + typeName := reflect.TypeOf(_id).Name() + if typeName == "ObjectID" { + id := _id.(primitive.ObjectID) + d["_id"] = id.Hex() + } else { + d["_id"] = util.GetStringValue(_id) + } + d["_id_type"] = typeName + } + d["value"] = string(bs) + list = append(list, d) + } + result.List = list return } -func (this_ *api) _import(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { +func (this_ *api) delete(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { config, err := this_.getConfig(requestBean, c) if err != nil { return @@ -485,159 +600,44 @@ func (this_ *api) _import(requestBean *base.RequestBean, c *gin.Context) (res in return } - var request = &BaseRequest{} + request := &BaseRequest{} if !base.RequestJSON(request, c) { return } - var task = &elasticsearch.ImportTask{} - if !base.RequestJSON(task, c) { - return + if request.IsObjectID && request.ObjectIDKey != "" && request.Filter[request.ObjectIDKey] != nil { + v, e := primitive.ObjectIDFromHex(util.GetStringValue(request.Filter[request.ObjectIDKey])) + if e == nil { + request.Filter[request.ObjectIDKey] = v + } } - - task.Service = service - elasticsearch.StartImportTask(task) - addWorkerTask(request.WorkerId, task.TaskId) - res = task - - return -} - -func (this_ *api) export(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { - //config, err := this_.getConfig(requestBean, c) - //if err != nil { - // return - //} - //service, err := getService(config) - //if err != nil { - // return - //} - // - //var task = &elasticsearch.ImportTask{} - //if !base.RequestJSON(task, c) { - // return - //} - // - //task.Service = service - //elasticsearch.StartImportTask(task) - //res = task - - return -} - -func (this_ *api) taskStatus(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { - - var request = &BaseRequest{} - if !base.RequestJSON(request, c) { + res, err = service.DeleteOne(request.DatabaseName, request.CollectionName, request.Filter) + if err != nil { return } - - res = elasticsearch.GetTask(request.TaskId) return } -func (this_ *api) taskStop(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { - - var request = &BaseRequest{} - if !base.RequestJSON(request, c) { +func (this_ *api) deleteById(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { + config, err := this_.getConfig(requestBean, c) + if err != nil { return } - - elasticsearch.StopTask(request.TaskId) - return -} - -func (this_ *api) taskClean(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { - - var request = &BaseRequest{} - if !base.RequestJSON(request, c) { + service, err := getService(config) + if err != nil { return } - removeWorkerTask(request.WorkerId, request.TaskId) - return -} - -func (this_ *api) taskList(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { - - var request = &BaseRequest{} + request := &BaseRequest{} if !base.RequestJSON(request, c) { return } - res = getWorkerTasks(request.WorkerId) - return -} - -func (this_ *api) close(requestBean *base.RequestBean, c *gin.Context) (res interface{}, err error) { - var request = &BaseRequest{} - if !base.RequestJSON(request, c) { + res, err = service.DeleteOne(request.DatabaseName, request.CollectionName, bson.M{ + "_id": request.getID(), + }) + if err != nil { return } - removeWorkerTasks(request.WorkerId) - return -} - -var ( - workerTasksCache = map[string][]string{} - workerTasksCacheLock = &sync.Mutex{} -) - -func addWorkerTask(workerId string, taskId string) { - workerTasksCacheLock.Lock() - defer workerTasksCacheLock.Unlock() - taskIds := workerTasksCache[workerId] - if util.StringIndexOf(taskIds, taskId) < 0 { - taskIds = append(taskIds, taskId) - workerTasksCache[workerId] = taskIds - } - return -} - -func getWorkerTasks(workerId string) (taskList []*elasticsearch.Task) { - workerTasksCacheLock.Lock() - defer workerTasksCacheLock.Unlock() - taskIds := workerTasksCache[workerId] - for _, id := range taskIds { - task := elasticsearch.GetTask(id) - if task != nil { - taskList = append(taskList, task) - } - } - return -} - -func removeWorkerTasks(workerId string) { - workerTasksCacheLock.Lock() - defer workerTasksCacheLock.Unlock() - taskIds := workerTasksCache[workerId] - for _, taskId := range taskIds { - elasticsearch.StopTask(taskId) - elasticsearch.CleanTask(taskId) - } - delete(workerTasksCache, workerId) - return -} - -func removeWorkerTask(workerId string, taskId string) { - workerTasksCacheLock.Lock() - defer workerTasksCacheLock.Unlock() - - elasticsearch.StopTask(taskId) - elasticsearch.CleanTask(taskId) - - taskIds := workerTasksCache[workerId] - var newIds []string - for _, id := range taskIds { - if id != taskId { - newIds = append(newIds, id) - } - } - taskIds = newIds - if len(taskIds) == 0 { - delete(workerTasksCache, workerId) - } else { - workerTasksCache[workerId] = taskIds - } return } diff --git a/internal/module/module_toolbox/worker.go b/internal/module/module_toolbox/worker.go index 81fb790e..4fbe4116 100644 --- a/internal/module/module_toolbox/worker.go +++ b/internal/module/module_toolbox/worker.go @@ -7,6 +7,7 @@ import ( "github.com/team-ide/go-tool/db" "github.com/team-ide/go-tool/elasticsearch" "github.com/team-ide/go-tool/kafka" + "github.com/team-ide/go-tool/mongodb" "github.com/team-ide/go-tool/redis" "github.com/team-ide/go-tool/util" "github.com/team-ide/go-tool/zookeeper" @@ -132,6 +133,16 @@ func (this_ *ToolboxService) FormatOption(toolboxData *ToolboxModel) (err error) } } break + case mongodbWorker_: + if optionMap["password"] != nil { + str, ok := optionMap["password"].(string) + if ok { + optionMap["password"] = this_.EncryptOptionAttr(str) + } else { + delete(optionMap, "password") + } + } + break } optionBytes, err = json.Marshal(optionMap) @@ -320,6 +331,12 @@ func (this_ *ToolboxService) BindConfigByOption(option string, config interface{ } conf.Password = this_.DecryptOptionAttr(conf.Password) break + case *mongodb.Config: + if conf.CertPath != "" { + conf.CertPath = this_.GetFilesFile(conf.CertPath) + } + conf.Password = this_.DecryptOptionAttr(conf.Password) + break } if err != nil { return @@ -364,8 +381,10 @@ var ( zookeeperWorker_ = zookeeperWorker() elasticsearchWorker_ = elasticsearchWorker() kafkaWorker_ = kafkaWorker() - thriftWorker_ = thriftWorker() - otherWorker_ = otherWorker() + mongodbWorker_ = mongodbWorker() + + thriftWorker_ = thriftWorker() + otherWorker_ = otherWorker() ) func init() { @@ -375,6 +394,7 @@ func init() { *toolboxTypes = append(*toolboxTypes, zookeeperWorker_) *toolboxTypes = append(*toolboxTypes, elasticsearchWorker_) *toolboxTypes = append(*toolboxTypes, kafkaWorker_) + *toolboxTypes = append(*toolboxTypes, mongodbWorker_) *toolboxTypes = append(*toolboxTypes, thriftWorker_) //*toolboxTypes = append(*toolboxTypes, otherWorker_) } @@ -783,6 +803,27 @@ func zookeeperWorker() *ToolboxType { return worker_ } +func mongodbWorker() *ToolboxType { + worker_ := &ToolboxType{ + Name: "mongodb", + Text: "Mongodb", + ConfigForm: &form.Form{ + Fields: []*form.Field{ + { + Label: "连接地址(127.0.0.1:27017)", Name: "address", DefaultValue: "127.0.0.1:27017", + Rules: []*form.Rule{ + {Required: true, Message: "连接地址不能为空"}, + }, + }, + {Label: "Username", Name: "username", Col: 12}, + {Label: "Password", Name: "password", Type: "password", Col: 12, ShowPlaintextBtn: true}, + {Label: "Cert", Name: "certPath", Type: "file", Placeholder: "请上传Cert"}, + }, + }, + } + + return worker_ +} func thriftWorker() *ToolboxType { worker_ := &ToolboxType{ Name: "thrift", diff --git a/package.json b/package.json index 0ce0497f..4842d5b2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name": "TeamIDE", - "version": "2.6.10", + "version": "2.6.11", "main": "./dist/main/main.js" }