作者 陈志颖

fix:共创申请查询参数修复

@@ -54,6 +54,8 @@ spec: @@ -54,6 +54,8 @@ spec:
54 env: 54 env:
55 - name: LOG_LEVEL 55 - name: LOG_LEVEL
56 value: "debug" 56 value: "debug"
  57 + - name: LOG_FRAMEWORK
  58 + value: "beego"
57 - name: LOG_TYPE 59 - name: LOG_TYPE
58 value: "file" 60 value: "file"
59 - name: ERROR_BASE_CODE 61 - name: ERROR_BASE_CODE
@@ -61,7 +63,7 @@ spec: @@ -61,7 +63,7 @@ spec:
61 - name: ERROR_BASE_CODE_MULTIPLE 63 - name: ERROR_BASE_CODE_MULTIPLE
62 value: "1000" 64 value: "1000"
63 - name: ENABLE_KAFKA_LOG 65 - name: ENABLE_KAFKA_LOG
64 - value: "true" 66 + value: "false"
65 - name: USER_MODULE_HOST 67 - name: USER_MODULE_HOST
66 value: "http://allied-creation-user-dev.fjmaimaimai.com" 68 value: "http://allied-creation-user-dev.fjmaimaimai.com"
67 - name: REDIS_HOST 69 - name: REDIS_HOST
1 package main 1 package main
2 2
3 import ( 3 import (
  4 + "fmt"
4 "github.com/beego/beego/v2/server/web" 5 "github.com/beego/beego/v2/server/web"
  6 + "github.com/linmadan/egglib-go/log/logrus"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
5 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant" 8 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
6 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" 9 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
7 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log" 11 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
8 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego" 12 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego"
9 ) 13 )
10 14
11 func main() { 15 func main() {
12 // web主服务 16 // web主服务
13 - //if constant.ENABLE_KAFKA_LOG {  
14 - // w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOSTS, constant.TOPIC_LOG_STASH, false)  
15 - // log.Logger.AddHook(w)  
16 - //} 17 + if constant.ENABLE_KAFKA_LOG {
  18 + w, err := logrus.NewKafkaWriter(constant.KAFKA_HOSTS, constant.TOPIC_LOG_STASH, false)
  19 + if err != nil {
  20 + log.Logger.Error(err.Error())
  21 + }
  22 + log.Logger.AddHook(w)
  23 + }
  24 +
  25 + fmt.Printf("Server running at:%d\n", web.BConfig.Listen.HTTPPort)
  26 +
17 web.Run() 27 web.Run()
18 } 28 }
@@ -5,7 +5,8 @@ import "os" @@ -5,7 +5,8 @@ import "os"
5 const SERVICE_NAME = "allied-creation-cooperation" 5 const SERVICE_NAME = "allied-creation-cooperation"
6 6
7 // LOG_TYPE 日志相关设置 7 // LOG_TYPE 日志相关设置
8 -var LOG_TYPE = "terminal" // file, terminal, es 8 +var LOG_TYPE = "terminal" // file, terminal, es
  9 +var LOG_FRAMEWORK = "beego" // beego logrus
9 var LOG_LEVEL = "debug" 10 var LOG_LEVEL = "debug"
10 var LOG_FILE = "app.log" 11 var LOG_FILE = "app.log"
11 var LOG_PREFIX = "[allied-creation-cooperation]" 12 var LOG_PREFIX = "[allied-creation-cooperation]"
@@ -23,6 +24,9 @@ func init() { @@ -23,6 +24,9 @@ func init() {
23 if os.Getenv("LOG_LEVEL") != "" { 24 if os.Getenv("LOG_LEVEL") != "" {
24 LOG_LEVEL = os.Getenv("LOG_LEVEL") 25 LOG_LEVEL = os.Getenv("LOG_LEVEL")
25 } 26 }
  27 + if os.Getenv("LOG_FRAMEWORK") != "" {
  28 + LOG_FRAMEWORK = os.Getenv("LOG_FRAMEWORK")
  29 + }
26 if os.Getenv("LOG_FILE") != "" { 30 if os.Getenv("LOG_FILE") != "" {
27 LOG_FILE = os.Getenv("LOG_FILE") 31 LOG_FILE = os.Getenv("LOG_FILE")
28 } 32 }
@@ -2,23 +2,27 @@ package constant @@ -2,23 +2,27 @@ package constant
2 2
3 import "os" 3 import "os"
4 4
5 -// kafka 地址 5 +// KAFKA_HOSTS kafka 地址
6 var KAFKA_HOSTS = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092" 6 var KAFKA_HOSTS = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092"
7 7
8 -// kafka topic log stash 8 +// TOPIC_LOG_STASH kafka topic log stash
9 var TOPIC_LOG_STASH = "go_stash_dev" 9 var TOPIC_LOG_STASH = "go_stash_dev"
10 10
11 -// 是否启用日志收集 (本地不启用) 11 +// ENABLE_KAFKA_LOG 是否启用日志收集 (本地不启用)
12 var ENABLE_KAFKA_LOG = false 12 var ENABLE_KAFKA_LOG = false
13 13
14 func init() { 14 func init() {
15 - //if os.Getenv("KAFKA_HOSTS") != "" {  
16 - // KAFKA_HOSTS = os.Getenv("KAFKA_HOSTS")  
17 - //}  
18 - //if os.Getenv("TOPIC_LOG_STASH") != "" {  
19 - // POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH")  
20 - //} 15 + if os.Getenv("KAFKA_HOSTS") != "" {
  16 + KAFKA_HOSTS = os.Getenv("KAFKA_HOSTS")
  17 + }
  18 + if os.Getenv("TOPIC_LOG_STASH") != "" {
  19 + POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH")
  20 + }
21 if os.Getenv("ENABLE_KAFKA_LOG") != "" { 21 if os.Getenv("ENABLE_KAFKA_LOG") != "" {
22 - ENABLE_KAFKA_LOG = true 22 + if os.Getenv("ENABLE_KAFKA_LOG") == "true" {
  23 + ENABLE_KAFKA_LOG = true
  24 + } else if os.Getenv("ENABLE_KAFKA_LOG") == "false" {
  25 + ENABLE_KAFKA_LOG = false
  26 + }
23 } 27 }
24 } 28 }
@@ -248,7 +248,7 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string @@ -248,7 +248,7 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
248 if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 { 248 if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
249 query.Where(`(cooperation_application.cooperation_application_applicant->>'userBaseId' ='?')`, userBaseId) 249 query.Where(`(cooperation_application.cooperation_application_applicant->>'userBaseId' ='?')`, userBaseId)
250 } 250 }
251 - if isCanceled, ok := queryOptions["isCanceled"]; ok && isCanceled.(int32) != 3 { 251 + if isCanceled, ok := queryOptions["isCanceled"]; ok && isCanceled.(int32) != 0 {
252 query.Where("is_canceled = ?", isCanceled) 252 query.Where("is_canceled = ?", isCanceled)
253 } 253 }
254 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { 254 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
@@ -26,7 +26,6 @@ type BeegoLog struct { @@ -26,7 +26,6 @@ type BeegoLog struct {
26 } 26 }
27 27
28 func (logger *BeegoLog) AddHook(write io.Writer) { 28 func (logger *BeegoLog) AddHook(write io.Writer) {
29 - panic("implement me")  
30 } 29 }
31 30
32 func (logger *BeegoLog) SetServiceName(serviceName string) { 31 func (logger *BeegoLog) SetServiceName(serviceName string) {
@@ -2,25 +2,22 @@ package log @@ -2,25 +2,22 @@ package log
2 2
3 import ( 3 import (
4 "github.com/linmadan/egglib-go/log" 4 "github.com/linmadan/egglib-go/log"
  5 + "github.com/linmadan/egglib-go/log/logrus"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
6 ) 7 )
7 8
8 var Logger log.Logger 9 var Logger log.Logger
9 10
10 func init() { 11 func init() {
11 - //Logger = logrus.NewLogrusLogger()  
12 - //Logger.SetServiceName(constant.SERVICE_NAME)  
13 - //Logger.SetLevel(constant.LOG_LEVEL)  
14 -  
15 - if constant.LOG_TYPE == "es" {  
16 - Logger = NewServerLog()  
17 - Logger.SetServiceName(constant.SERVICE_NAME)  
18 - Logger.SetLevel(constant.LOG_LEVEL)  
19 - } else { 12 + if constant.LOG_FRAMEWORK == "beego" {
20 Logger = NewBeegoLog(LoggerConfig{ 13 Logger = NewBeegoLog(LoggerConfig{
21 Filename: constant.LOG_FILE, 14 Filename: constant.LOG_FILE,
22 Level: 7, 15 Level: 7,
23 MaxSize: 1024 * 1024 * 2, 16 MaxSize: 1024 * 1024 * 2,
24 }) 17 })
  18 + } else if constant.LOG_FRAMEWORK == "logrus" {
  19 + Logger = logrus.NewLogrusLogger()
  20 + Logger.SetServiceName(constant.SERVICE_NAME)
  21 + Logger.SetLevel(constant.LOG_LEVEL)
25 } 22 }
26 } 23 }
1 -package log  
2 -  
3 -import (  
4 - "fmt"  
5 - "github.com/olivere/elastic/v7"  
6 - "github.com/sirupsen/logrus"  
7 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"  
8 - "gopkg.in/sohlich/elogrus.v7"  
9 - "io"  
10 - "os"  
11 -)  
12 -  
13 -type ServerLog struct {  
14 - serviceName string  
15 - logrus *logrus.Logger  
16 -}  
17 -  
18 -func (logger *ServerLog) AddHook(write io.Writer) {  
19 - panic("implement me")  
20 -}  
21 -  
22 -func (logger *ServerLog) SetServiceName(serviceName string) {  
23 - logger.serviceName = serviceName  
24 -}  
25 -  
26 -func (logger *ServerLog) SetLevel(level string) {  
27 - switch level {  
28 - case "trace":  
29 - logger.logrus.Level = logrus.TraceLevel  
30 - case "debug":  
31 - logger.logrus.Level = logrus.DebugLevel  
32 - case "info":  
33 - logger.logrus.Level = logrus.InfoLevel  
34 - case "warn":  
35 - logger.logrus.Level = logrus.WarnLevel  
36 - case "error":  
37 - logger.logrus.Level = logrus.ErrorLevel  
38 - case "fatal":  
39 - logger.logrus.Level = logrus.FatalLevel  
40 - case "panic":  
41 - logger.logrus.Level = logrus.PanicLevel  
42 - default:  
43 - logger.logrus.Level = logrus.DebugLevel  
44 - }  
45 -}  
46 -  
47 -func (logger *ServerLog) Trace(msg string, appends ...map[string]interface{}) {  
48 - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})  
49 - for _, append := range appends {  
50 - contextLogger = contextLogger.WithFields(append)  
51 - }  
52 - contextLogger.Trace(msg)  
53 -}  
54 -  
55 -func (logger *ServerLog) Debug(msg string, appends ...map[string]interface{}) {  
56 - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})  
57 - for _, append := range appends {  
58 - contextLogger = contextLogger.WithFields(append)  
59 - }  
60 - contextLogger.Debug(msg)  
61 -}  
62 -  
63 -func (logger *ServerLog) Info(msg string, appends ...map[string]interface{}) {  
64 - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})  
65 - for _, append := range appends {  
66 - contextLogger = contextLogger.WithFields(append)  
67 - }  
68 - contextLogger.Info(msg)  
69 -}  
70 -  
71 -func (logger *ServerLog) Warn(msg string, appends ...map[string]interface{}) {  
72 - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})  
73 - for _, append := range appends {  
74 - contextLogger = contextLogger.WithFields(append)  
75 - }  
76 - contextLogger.Warn(msg)  
77 -}  
78 -  
79 -func (logger *ServerLog) Error(msg string, appends ...map[string]interface{}) {  
80 - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})  
81 - for _, append := range appends {  
82 - contextLogger = contextLogger.WithFields(append)  
83 - }  
84 - contextLogger.Error(msg)  
85 -}  
86 -  
87 -func (logger *ServerLog) Fatal(msg string, appends ...map[string]interface{}) {  
88 - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})  
89 - for _, append := range appends {  
90 - contextLogger = contextLogger.WithFields(append)  
91 - }  
92 - contextLogger.Fatal(msg)  
93 -}  
94 -  
95 -func (logger *ServerLog) Panic(msg string, appends ...map[string]interface{}) {  
96 - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})  
97 - for _, append := range appends {  
98 - contextLogger = contextLogger.WithFields(append)  
99 - }  
100 - contextLogger.Panic(msg)  
101 -}  
102 -  
103 -func NewServerLog() *ServerLog {  
104 - logger := logrus.New()  
105 - logger.Formatter = &logrus.JSONFormatter{  
106 - TimestampFormat: "2006-01-02 15:04:05",  
107 - PrettyPrint: true,  
108 - }  
109 - if constant.LOG_TYPE == "file" {  
110 - file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666)  
111 - if err == nil {  
112 - _ = file.Truncate(1024 * 1024 * 2)  
113 - logger.Out = file  
114 - } else {  
115 - logger.Info("Failed to log to file, using default stderr")  
116 - }  
117 - } else if constant.LOG_TYPE == "es" {  
118 - url := fmt.Sprintf("http://%s:%s", "es.chenzhiying.asia", "80")  
119 - client, err := elastic.NewClient(elastic.SetURL(url), elastic.SetSniff(false))  
120 - if err != nil {  
121 - //log.Panic(err)  
122 - panic(err)  
123 - }  
124 - hook, err := elogrus.NewAsyncElasticHook(client, "es.chenzhiying.asia", logrus.DebugLevel, "boss-appointment")  
125 - if err != nil {  
126 - //log.Panic(err)  
127 - panic(err)  
128 - }  
129 - logger.Hooks.Add(hook)  
130 - } else {  
131 - logger.Out = os.Stdout  
132 - }  
133 - return &ServerLog{  
134 - logrus: logger,  
135 - }  
136 -}