Bläddra i källkod

数据列表查询

WH01243 2 år sedan
förälder
incheckning
fe8a17a8ef
7 ändrade filer med 56 tillägg och 14 borttagningar
  1. 2 0
      go.mod
  2. 1 0
      go.sum
  3. 2 2
      rpc/pb/publicservice.pb.go
  4. 1 1
      rpc/pb/publicservice_grpc.pb.go
  5. 7 7
      rpc/publicservice.go
  6. 1 0
      rpc/publicservice.proto
  7. 42 4
      rpc/service/datasmt.go

+ 2 - 0
go.mod

@@ -4,6 +4,7 @@ go 1.20
 
 require (
 	app.yhyue.com/moapp/jybase v0.0.0-20230614085041-f8f20842d5cb
+	github.com/stretchr/testify v1.8.4
 	github.com/zeromicro/go-zero v1.5.3
 	google.golang.org/grpc v1.56.1
 	google.golang.org/protobuf v1.30.0
@@ -46,6 +47,7 @@ require (
 	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
 	github.com/openzipkin/zipkin-go v0.4.1 // indirect
 	github.com/pelletier/go-toml/v2 v2.0.8 // indirect
+	github.com/pmezard/go-difflib v1.0.0 // indirect
 	github.com/prometheus/client_golang v1.15.1 // indirect
 	github.com/prometheus/client_model v0.3.0 // indirect
 	github.com/prometheus/common v0.42.0 // indirect

+ 1 - 0
go.sum

@@ -480,6 +480,7 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
 github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
 github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=

+ 2 - 2
rpc/pb/publicservice.pb.go

@@ -2,8 +2,8 @@
 
 // Code generated by protoc-gen-go. DO NOT EDIT.
 // versions:
-// 	protoc-gen-go v1.27.1
-// 	protoc        v3.20.0--rc2
+// 	protoc-gen-go v1.28.1
+// 	protoc        v3.15.1
 // source: publicservice.proto
 
 package pb

+ 1 - 1
rpc/pb/publicservice_grpc.pb.go

@@ -1,7 +1,7 @@
 // Code generated by protoc-gen-go-grpc. DO NOT EDIT.
 // versions:
 // - protoc-gen-go-grpc v1.2.0
-// - protoc             v3.20.0--rc2
+// - protoc             v3.15.1
 // source: publicservice.proto
 
 package pb

+ 7 - 7
rpc/publicservice.go

@@ -17,26 +17,26 @@ import (
 )
 
 var configFile = flag.String("f", "etc/publicservice.yaml", "the config file")
+var C config.Config
 
 func main() {
 	flag.Parse()
 
-	var c config.Config
-	conf.MustLoad(*configFile, &c)
+	conf.MustLoad(*configFile, &C)
 	//初始化数据库
-	db.Init(c)
-	ctx := svc.NewServiceContext(c)
+	db.Init(C)
+	ctx := svc.NewServiceContext(C)
 	svr := server.NewDatasmtServer(ctx)
 
-	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
+	s := zrpc.MustNewServer(C.RpcServerConf, func(grpcServer *grpc.Server) {
 		pb.RegisterDatasmtServer(grpcServer, svr)
 
-		if c.Mode == service.DevMode || c.Mode == service.TestMode {
+		if C.Mode == service.DevMode || C.Mode == service.TestMode {
 			reflection.Register(grpcServer)
 		}
 	})
 	defer s.Stop()
 
-	fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
+	fmt.Printf("Starting rpc server at %s...\n", C.ListenOn)
 	s.Start()
 }

+ 1 - 0
rpc/publicservice.proto

@@ -37,6 +37,7 @@ message DatasmtRespDetail {
   string data_example = 6;      //数据示例图片路径
 }
 
+
 service datasmt {
   //列表
   rpc List(DatasmtReqList) returns(DatasmtRespList);

+ 42 - 4
rpc/service/datasmt.go

@@ -1,18 +1,56 @@
 package service
 
 import (
+	"app.yhyue.com/moapp/jybase/common"
+	"fmt"
+	"jygit.jydev.jianyu360.cn/ApplicationCenter/publicService/rpc/db"
 	"jygit.jydev.jianyu360.cn/ApplicationCenter/publicService/rpc/pb"
+	"strings"
+)
+
+const (
+	DATA_SUPERMARKET = "data_supermarket"
 )
 
 type DataSmt struct {
 }
 
-//
-func (d *DataSmt) List(searchValue, dataType string, pageNum int) *pb.DatasmtRespList {
-	return &pb.DatasmtRespList{}
+// 列表数据
+func (d *DataSmt) List(searchValue, dataType string, pageNum, pageSize int) *pb.DatasmtRespList {
+	result := pb.DatasmtRespList{}
+	//数据查询
+	data := &[]map[string]interface{}{}
+	querySql := "select  id,name,data_type,format,clear_status from  %s where %s ORDER BY serial_number  limit %d ,%d "
+	queryStrArr := []string{}
+	if searchValue != "" {
+		queryStrArr = append(queryStrArr, fmt.Sprintf("name  LIKE '%%s%' "), searchValue)
+	}
+	if dataType != "" {
+		queryStrArr = append(queryStrArr, fmt.Sprintf("data_type  = '%s' "), dataType)
+	}
+	querySql = fmt.Sprintf(querySql, DATA_SUPERMARKET, strings.Join(queryStrArr, " and "), (pageNum-1)*pageSize, pageNum*pageSize)
+	data = db.Mysql_BaseService.SelectBySql(querySql)
+	if data != nil && len(*data) > 0 {
+		//数据出出力
+	}
+	//总数查询
+	countQuerySql := "select  count(id) from  %s where %s "
+	countQuerySql = fmt.Sprintf(countQuerySql, DATA_SUPERMARKET, strings.Join(queryStrArr, " and "))
+	//count := db.Mysql_BaseService.CountBySql(countQuerySql)
+	//热搜词处理
+	hotKeySql := fmt.Sprintf("select GROUP_CONCAT(keyword) as keyword from  %s   ORDER BY serial_number LIMIT 0,8", DATA_SUPERMARKET)
+	hotData := db.Mysql_BaseService.SelectBySql(hotKeySql)
+	if hotData != nil && len(*hotData) > 0 {
+		result.HotKeys = strings.Split(common.InterfaceToStr((*hotData)[0]["keyword"]), ",")
+	}
+	//包含字段说明
+	//result.FieldIllustrate=c
+
+	return &result
+
 }
 
-//
+// 详情
 func (d *DataSmt) Detail(id string) *pb.DatasmtRespDetail {
 	return &pb.DatasmtRespDetail{}
 }