WH01243 1 gadu atpakaļ
revīzija
c2b3a39b99

+ 6 - 0
README.md

@@ -0,0 +1,6 @@
+CRM应用程序,只提供api服务
+
+goctl api go -api bicenter.api -dir .
+
+go test -v -coverprofile=coverage
+go tool cover -html=coverage -o coverage.html

+ 28 - 0
api/bicenter.api

@@ -0,0 +1,28 @@
+syntax = "v1"
+type (
+	Reply {
+		Error_code int64       `json:"error_code"`
+		Error_msg  string      `json:"error_msg"`
+		Data       interface{} `json:"data"`
+	}
+	SqlManageReq {
+		Id     int64   `json:"id"`
+		Params []Param `json:"params"`
+	}
+	Param {
+		Value string `json:"value"`
+		Type  string `json:"type"`
+	}
+	MyInfoReq {
+		Bid string `json:"bid "`
+		Sid string `json:"sid "`
+	}
+)
+service biCenter {
+	@doc "bi通用接口"
+	@handler sqlManage
+	post /bi_service/sql_manage (SqlManageReq) returns (Reply)
+	@doc "用户身份"
+	@handler Myinfo
+	post /bi_service/myinfo (MyInfoReq) returns (Reply)
+}

+ 31 - 0
api/bicenter.go

@@ -0,0 +1,31 @@
+package main
+
+import (
+	"flag"
+	"fmt"
+
+	"biCenter/api/internal/config"
+	"biCenter/api/internal/handler"
+	"biCenter/api/internal/svc"
+
+	"github.com/zeromicro/go-zero/core/conf"
+	"github.com/zeromicro/go-zero/rest"
+)
+
+var configFile = flag.String("f", "etc/bicenter.yaml", "the config file")
+
+func main() {
+	flag.Parse()
+
+	var c config.Config
+	conf.MustLoad(*configFile, &c)
+
+	server := rest.MustNewServer(c.RestConf)
+	defer server.Stop()
+
+	ctx := svc.NewServiceContext(c)
+	handler.RegisterHandlers(server, ctx)
+
+	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
+	server.Start()
+}

+ 142 - 0
api/common/initconfig.go

@@ -0,0 +1,142 @@
+package common
+
+import (
+	"flag"
+	"log"
+	"strings"
+
+	"app.yhyue.com/moapp/jybase/mongodb"
+	"app.yhyue.com/moapp/jybase/mysql"
+	"app.yhyue.com/moapp/jybase/redis"
+	"bp.jydev.jianyu360.cn/BaseService/fileCenter/rpc/filecenter"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/config"
+	"bp.jydev.jianyu360.cn/CRM/application/entity"
+	"bp.jydev.jianyu360.cn/CRM/baseCenter/rpc/basecenter"
+	"github.com/zeromicro/go-zero/core/conf"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+var configFile = flag.String("fs", "etc/bicenter.yaml", "the config file")
+var C config.Config
+
+var logFile = flag.String("lf", "etc/logs.yaml", "the config file")
+var logc entity.Logc
+
+var dbFile = flag.String("df", "etc/db.yaml", "the db file")
+var DB config.Db
+
+var (
+	MgoBidding    mongodb.MongodbSim
+	MgoEnt        mongodb.MongodbSim
+	MainMysql     *mysql.Mysql
+	BaseMysql     *mysql.Mysql
+	CrmMysql      *mysql.Mysql
+	Mgo           mongodb.MongodbSim
+	UserCenterRpc usercenter.UserCenter
+	FileCenterRpc filecenter.FileCenter
+	BaseCenterRpc basecenter.BaseCenter
+)
+
+func init() {
+	conf.MustLoad(*configFile, &C)
+	log.Println("初始化配置") //
+
+	//初始化日志信息
+	conf.MustLoad(*logFile, &logc)
+	if len(logc.Level) > 0 {
+		for _, v := range logc.Level {
+			logx.MustSetup(logx.LogConf{
+				Mode:     logc.Mode,
+				Path:     logc.Path,
+				Level:    v,
+				KeepDays: logc.KeepDays,
+			})
+			logx.Info(v, "--日志记录")
+		}
+	}
+
+	conf.MustLoad(*dbFile, &DB)
+	//初始化mysql
+	if DB.Mysql.Main.Address != "" {
+		log.Println("--初始化 main mysql--")
+		MainMysql = &mysql.Mysql{
+			Address:      DB.Mysql.Main.Address,
+			UserName:     DB.Mysql.Main.UserName,
+			PassWord:     DB.Mysql.Main.Password,
+			DBName:       DB.Mysql.Main.DbName,
+			MaxOpenConns: DB.Mysql.Main.MaxOpenConns,
+			MaxIdleConns: DB.Mysql.Main.MaxIdleConns,
+		}
+		MainMysql.Init()
+	}
+	if DB.Mysql.BaseService.Address != "" {
+		log.Println("--初始化 base mysql--")
+		BaseMysql = &mysql.Mysql{
+			Address:      DB.Mysql.BaseService.Address,
+			UserName:     DB.Mysql.BaseService.UserName,
+			PassWord:     DB.Mysql.BaseService.Password,
+			DBName:       DB.Mysql.BaseService.DbName,
+			MaxOpenConns: DB.Mysql.BaseService.MaxOpenConns,
+			MaxIdleConns: DB.Mysql.BaseService.MaxIdleConns,
+		}
+		BaseMysql.Init()
+	}
+	if DB.Mysql.CrmService.Address != "" {
+		log.Println("--初始化 crm mysql--")
+		CrmMysql = &mysql.Mysql{
+			Address:      DB.Mysql.CrmService.Address,
+			UserName:     DB.Mysql.CrmService.UserName,
+			PassWord:     DB.Mysql.CrmService.Password,
+			DBName:       DB.Mysql.CrmService.DbName,
+			MaxOpenConns: DB.Mysql.CrmService.MaxOpenConns,
+			MaxIdleConns: DB.Mysql.CrmService.MaxIdleConns,
+		}
+		CrmMysql.Init()
+	}
+	//初始化数据库配置
+	rm := DB.Redis
+	if len(rm.Addr) > 0 {
+		logx.Info("--初始化 redis--")
+		redis.InitRedisBySize(strings.Join(rm.Addr, ","), 100, 30, 300)
+	}
+	if DB.Mongo.Main.Address != "" {
+		logx.Info("--初始化 mongodb--")
+		Mgo = mongodb.MongodbSim{
+			MongodbAddr: DB.Mongo.Main.Address,
+			Size:        DB.Mongo.Main.Size,
+			DbName:      DB.Mongo.Main.DbName,
+		}
+		Mgo.InitPool()
+	}
+	if DB.Mongo.Bidding.Address != "" {
+		logx.Info("--初始化 mongodb Bidding --")
+		MgoBidding = mongodb.MongodbSim{
+			MongodbAddr: DB.Mongo.Bidding.Address,
+			Size:        DB.Mongo.Bidding.Size,
+			DbName:      DB.Mongo.Bidding.DbName,
+			Password:    DB.Mongo.Bidding.Password,
+			UserName:    DB.Mongo.Bidding.UserName,
+		}
+		MgoBidding.InitPool()
+	}
+	if DB.Mongo.Ent.Address != "" {
+		logx.Info("--初始化 mongodb ent --")
+		MgoEnt = mongodb.MongodbSim{
+			MongodbAddr: DB.Mongo.Ent.Address,
+			Size:        DB.Mongo.Ent.Size,
+			DbName:      DB.Mongo.Ent.DbName,
+			Password:    DB.Mongo.Ent.Password,
+			UserName:    DB.Mongo.Ent.UserName,
+		}
+		MgoEnt.InitPool()
+	}
+	//初始化 elasticsearch
+	if DB.Es.Addr != "" {
+		log.Println("--初始化 elasticsearch--")
+		NewEs(DB.Es.Version, DB.Es.Addr, DB.Es.Size, DB.Es.UserName, DB.Es.Password)
+	}
+	//UserCenterRpc = usercenter.NewUserCenter(zrpc.MustNewClient(C.UserCenterRpc))
+	//FileCenterRpc = filecenter.NewFileCenter(zrpc.MustNewClient(C.FileCenterRpc))
+	//BaseCenterRpc = basecenter.NewBaseCenter(zrpc.MustNewClient(C.BaseCenterRpc))
+}

+ 8 - 0
api/etc/bicenter.yaml

@@ -0,0 +1,8 @@
+Name: biCenter
+Host: 0.0.0.0
+Port: 8888
+
+Gateway:
+  ServerCode: biService
+  Etcd:
+    - 127.0.0.1:2379

+ 21 - 0
api/etc/db.yaml

@@ -0,0 +1,21 @@
+redis:
+    session:
+        - session=127.0.0.1:6379
+mongo:
+    bidding:
+        address: 192.168.3.206:27002
+        size: 5
+        dbName: qfw_data
+        collection: bidding
+        collection_change: bidding_back
+        userName: jyDevGroup
+        password: jy@DevGroup
+    ent:
+        address: 192.168.3.206:27002
+        size: 5
+        dbName: mixdata
+        replSet: ""
+        collection: qyxy
+        collection_change: qyxy_change
+        userName: jyDevGroup
+        password: jy@DevGroup

+ 6 - 0
api/etc/logs.yaml

@@ -0,0 +1,6 @@
+Mode: file
+Path: ./logs
+Level:
+  - info
+  - error
+KeepDays: 10

+ 30 - 0
api/internal/config/config.go

@@ -0,0 +1,30 @@
+package config
+
+import (
+	"bp.jydev.jianyu360.cn/CRM/application/entity"
+	"github.com/zeromicro/go-zero/rest"
+	"github.com/zeromicro/go-zero/zrpc"
+)
+
+type Config struct {
+	rest.RestConf
+	Gateway struct {
+		ServerCode string
+		Etcd       []string
+	}
+	UserCenterRpc     zrpc.RpcClientConf
+	FileCenterRpc     zrpc.RpcClientConf
+	OssBucketName     string
+	OssUrl            string
+	BaseCenterRpc     zrpc.RpcClientConf
+	StationMailHref   string
+	StationMailAction string
+	TestId            string
+}
+
+type Db struct {
+	Mysql entity.Mysql      `json:"mysql"`
+	Redis entity.RedisStuct `json:"redis"`
+	Mongo entity.Mongo      `json:"mongo"`
+	Es    entity.EsStruct   `json:"es"`
+}

+ 28 - 0
api/internal/handler/myinfohandler.go

@@ -0,0 +1,28 @@
+package handler
+
+import (
+	"net/http"
+
+	"biCenter/api/internal/logic"
+	"biCenter/api/internal/svc"
+	"biCenter/api/internal/types"
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func MyinfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.MyInfoReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := logic.NewMyinfoLogic(r.Context(), svcCtx)
+		resp, err := l.Myinfo(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 27 - 0
api/internal/handler/routes.go

@@ -0,0 +1,27 @@
+// Code generated by goctl. DO NOT EDIT.
+package handler
+
+import (
+	"net/http"
+
+	"biCenter/api/internal/svc"
+
+	"github.com/zeromicro/go-zero/rest"
+)
+
+func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
+	server.AddRoutes(
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/bi_service/sql_manage",
+				Handler: sqlManageHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/bi_service/myinfo",
+				Handler: MyinfoHandler(serverCtx),
+			},
+		},
+	)
+}

+ 28 - 0
api/internal/handler/sqlmanagehandler.go

@@ -0,0 +1,28 @@
+package handler
+
+import (
+	"net/http"
+
+	"biCenter/api/internal/logic"
+	"biCenter/api/internal/svc"
+	"biCenter/api/internal/types"
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func sqlManageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.SqlManageReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := logic.NewSqlManageLogic(r.Context(), svcCtx)
+		resp, err := l.SqlManage(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 30 - 0
api/internal/logic/myinfologic.go

@@ -0,0 +1,30 @@
+package logic
+
+import (
+	"context"
+
+	"biCenter/api/internal/svc"
+	"biCenter/api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type MyinfoLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewMyinfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MyinfoLogic {
+	return &MyinfoLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *MyinfoLogic) Myinfo(req *types.MyInfoReq) (resp *types.Reply, err error) {
+	// todo: add your logic here and delete this line
+
+	return
+}

+ 30 - 0
api/internal/logic/sqlmanagelogic.go

@@ -0,0 +1,30 @@
+package logic
+
+import (
+	"context"
+
+	"biCenter/api/internal/svc"
+	"biCenter/api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type SqlManageLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewSqlManageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SqlManageLogic {
+	return &SqlManageLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *SqlManageLogic) SqlManage(req *types.SqlManageReq) (resp *types.Reply, err error) {
+	// todo: add your logic here and delete this line
+
+	return
+}

+ 15 - 0
api/internal/svc/servicecontext.go

@@ -0,0 +1,15 @@
+package svc
+
+import (
+	"biCenter/api/internal/config"
+)
+
+type ServiceContext struct {
+	Config config.Config
+}
+
+func NewServiceContext(c config.Config) *ServiceContext {
+	return &ServiceContext{
+		Config: c,
+	}
+}

+ 23 - 0
api/internal/types/types.go

@@ -0,0 +1,23 @@
+// Code generated by goctl. DO NOT EDIT.
+package types
+
+type Reply struct {
+	Error_code int64       `json:"error_code"`
+	Error_msg  string      `json:"error_msg"`
+	Data       interface{} `json:"data"`
+}
+
+type SqlManageReq struct {
+	Id     int64   `json:"id"`
+	Params []Param `json:"params"`
+}
+
+type Param struct {
+	Value string `json:"value"`
+	Type  string `json:"type"`
+}
+
+type MyInfoReq struct {
+	Bid string `json:"bid "`
+	Sid string `json:"sid "`
+}

+ 3 - 0
go.mod

@@ -0,0 +1,3 @@
+module biCenter
+
+go 1.20