作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-cooperation into dev
... ... @@ -54,6 +54,8 @@ spec:
env:
- name: LOG_LEVEL
value: "debug"
- name: LOG_FRAMEWORK
value: "beego"
- name: LOG_TYPE
value: "file"
- name: ERROR_BASE_CODE
... ... @@ -61,7 +63,7 @@ spec:
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: ENABLE_KAFKA_LOG
value: "true"
value: "false"
- name: USER_MODULE_HOST
value: "http://allied-creation-user-dev.fjmaimaimai.com"
- name: REDIS_HOST
... ...
package main
import (
"fmt"
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/log/logrus"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego"
)
func main() {
// web主服务
//if constant.ENABLE_KAFKA_LOG {
// w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOSTS, constant.TOPIC_LOG_STASH, false)
// log.Logger.AddHook(w)
//}
if constant.ENABLE_KAFKA_LOG {
w, err := logrus.NewKafkaWriter(constant.KAFKA_HOSTS, constant.TOPIC_LOG_STASH, false)
if err != nil {
log.Logger.Error(err.Error())
}
log.Logger.AddHook(w)
}
fmt.Printf("Server running at:%d\n", web.BConfig.Listen.HTTPPort)
web.Run()
}
... ...
... ... @@ -18,6 +18,10 @@ type CooperationContractByUndertakerDto struct {
CooperationContractNumber string `json:"cooperationContractNumber"`
// 项目合约名称
CooperationContractName string `json:"cooperationContractName"`
// 项目合约状态
CooperationContractStatus int32 `json:"cooperationContractStatus"`
// 共创描述
CooperationContractDescription string `json:"cooperationContractDescription"`
// 合同附件
Attachment []*domain.Attachment `json:"attachment"`
// 发起人姓名
... ... @@ -37,6 +41,8 @@ func (dto *CooperationContractByUndertakerDto) LoadDto(contractByUndertaker *mod
dto.UndertakerPhone = contractByUndertaker.UndertakerPhone
dto.CooperationContractNumber = contractByUndertaker.CooperationContractNumber
dto.CooperationContractName = contractByUndertaker.CooperationContractName
dto.CooperationContractStatus = contractByUndertaker.ContractStatus
dto.CooperationContractDescription = contractByUndertaker.CooperationContractDescription
dto.Attachment = contractByUndertaker.ContractAttachment
dto.SponsorName = contractByUndertaker.CooperationContractSponsor.UserName
if contractByUndertaker.Department != nil {
... ...
... ... @@ -836,7 +836,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC
if count, cooperationContractByUndertakers, err := cooperationContractDao.SearchCooperationContractByUndertaker(tool_funs.SimpleStructToMap(searchCooperationContractByUndertakerQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractByUndertakerDtos := []*dto.CooperationContractByUndertakerDto{}
cooperationContractByUndertakerDtos := make([]*dto.CooperationContractByUndertakerDto, 0)
for _, cooperationContractByUndertaker := range cooperationContractByUndertakers {
cooperationContractByUndertakerDto := &dto.CooperationContractByUndertakerDto{}
if err := cooperationContractByUndertakerDto.LoadDto(cooperationContractByUndertaker); err != nil {
... ...
... ... @@ -130,8 +130,9 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
}
// 查找合约
var cooperationContractsMap map[string]*domain.CooperationContract
cooperationContractsMap := make(map[string]*domain.CooperationContract)
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"offsetLimit": false,
"companyId": createDividendsOrderCommand.CompanyId,
"orgId": createDividendsOrderCommand.OrgId,
}); err != nil {
... ... @@ -317,7 +318,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
// 查找合约
var cooperationContractsMap map[string]*domain.CooperationContract
cooperationContractsMap := make(map[string]*domain.CooperationContract)
countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"offsetLimit": false,
"companyId": importDividendsOrderCommand.CompanyId,
... ...
... ... @@ -143,8 +143,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
}
// 查找合约
var cooperationContractsMap map[string]*domain.CooperationContract
cooperationContractsMap := make(map[string]*domain.CooperationContract)
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"offsetLimit": false,
"companyId": createDividendsReturnedOrderCommand.CompanyId,
"orgId": createDividendsReturnedOrderCommand.OrgId,
}); err != nil {
... ... @@ -366,7 +367,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
}
// 查找合约
var cooperationContractsMap map[string]*domain.CooperationContract
cooperationContractsMap := make(map[string]*domain.CooperationContract)
countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"offsetLimit": false,
"companyId": importDividendsReturnedOrderCommand.CompanyId,
... ...
... ... @@ -6,6 +6,7 @@ const SERVICE_NAME = "allied-creation-cooperation"
// LOG_TYPE 日志相关设置
var LOG_TYPE = "terminal" // file, terminal, es
var LOG_FRAMEWORK = "beego" // beego logrus
var LOG_LEVEL = "debug"
var LOG_FILE = "app.log"
var LOG_PREFIX = "[allied-creation-cooperation]"
... ... @@ -23,6 +24,9 @@ func init() {
if os.Getenv("LOG_LEVEL") != "" {
LOG_LEVEL = os.Getenv("LOG_LEVEL")
}
if os.Getenv("LOG_FRAMEWORK") != "" {
LOG_FRAMEWORK = os.Getenv("LOG_FRAMEWORK")
}
if os.Getenv("LOG_FILE") != "" {
LOG_FILE = os.Getenv("LOG_FILE")
}
... ...
... ... @@ -2,23 +2,27 @@ package constant
import "os"
// kafka 地址
// KAFKA_HOSTS kafka 地址
var KAFKA_HOSTS = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092"
// kafka topic log stash
// TOPIC_LOG_STASH kafka topic log stash
var TOPIC_LOG_STASH = "go_stash_dev"
// 是否启用日志收集 (本地不启用)
// ENABLE_KAFKA_LOG 是否启用日志收集 (本地不启用)
var ENABLE_KAFKA_LOG = false
func init() {
//if os.Getenv("KAFKA_HOSTS") != "" {
// KAFKA_HOSTS = os.Getenv("KAFKA_HOSTS")
//}
//if os.Getenv("TOPIC_LOG_STASH") != "" {
// POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH")
//}
if os.Getenv("KAFKA_HOSTS") != "" {
KAFKA_HOSTS = os.Getenv("KAFKA_HOSTS")
}
if os.Getenv("TOPIC_LOG_STASH") != "" {
POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH")
}
if os.Getenv("ENABLE_KAFKA_LOG") != "" {
if os.Getenv("ENABLE_KAFKA_LOG") == "true" {
ENABLE_KAFKA_LOG = true
} else if os.Getenv("ENABLE_KAFKA_LOG") == "false" {
ENABLE_KAFKA_LOG = false
}
}
}
... ...
... ... @@ -25,7 +25,7 @@ type CooperationContractByUndertaker struct {
Department *domain.Department `comment:"共创合约发起部门"`
// 组织机构
Org *domain.Org `comment:"组织机构"`
// 共创合约状态
// 共创合约状态 1正常,2关闭
ContractStatus int32 `comment:"共创合约状态"`
// 共创模式名称
CooperationModeName string `comment:"共创合约名称"`
... ...
... ... @@ -248,9 +248,11 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
query.Where(`(cooperation_application.cooperation_application_applicant->>'userBaseId' ='?')`, userBaseId)
}
if isCanceled, ok := queryOptions["isCanceled"]; ok && isCanceled.(int32) != 3 {
if isCanceled, ok := queryOptions["isCanceled"]; ok && isCanceled.(int32) != 0 {
if isCanceled.(int32) != 3 {
query.Where("is_canceled = ?", isCanceled)
}
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
... ...
... ... @@ -26,7 +26,6 @@ type BeegoLog struct {
}
func (logger *BeegoLog) AddHook(write io.Writer) {
panic("implement me")
}
func (logger *BeegoLog) SetServiceName(serviceName string) {
... ...
... ... @@ -2,25 +2,22 @@ package log
import (
"github.com/linmadan/egglib-go/log"
"github.com/linmadan/egglib-go/log/logrus"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
)
var Logger log.Logger
func init() {
//Logger = logrus.NewLogrusLogger()
//Logger.SetServiceName(constant.SERVICE_NAME)
//Logger.SetLevel(constant.LOG_LEVEL)
if constant.LOG_TYPE == "es" {
Logger = NewServerLog()
Logger.SetServiceName(constant.SERVICE_NAME)
Logger.SetLevel(constant.LOG_LEVEL)
} else {
if constant.LOG_FRAMEWORK == "beego" {
Logger = NewBeegoLog(LoggerConfig{
Filename: constant.LOG_FILE,
Level: 7,
MaxSize: 1024 * 1024 * 2,
})
} else if constant.LOG_FRAMEWORK == "logrus" {
Logger = logrus.NewLogrusLogger()
Logger.SetServiceName(constant.SERVICE_NAME)
Logger.SetLevel(constant.LOG_LEVEL)
}
}
... ...
package log
import (
"fmt"
"github.com/olivere/elastic/v7"
"github.com/sirupsen/logrus"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
"gopkg.in/sohlich/elogrus.v7"
"io"
"os"
)
type ServerLog struct {
serviceName string
logrus *logrus.Logger
}
func (logger *ServerLog) AddHook(write io.Writer) {
panic("implement me")
}
func (logger *ServerLog) SetServiceName(serviceName string) {
logger.serviceName = serviceName
}
func (logger *ServerLog) SetLevel(level string) {
switch level {
case "trace":
logger.logrus.Level = logrus.TraceLevel
case "debug":
logger.logrus.Level = logrus.DebugLevel
case "info":
logger.logrus.Level = logrus.InfoLevel
case "warn":
logger.logrus.Level = logrus.WarnLevel
case "error":
logger.logrus.Level = logrus.ErrorLevel
case "fatal":
logger.logrus.Level = logrus.FatalLevel
case "panic":
logger.logrus.Level = logrus.PanicLevel
default:
logger.logrus.Level = logrus.DebugLevel
}
}
func (logger *ServerLog) Trace(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Trace(msg)
}
func (logger *ServerLog) Debug(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Debug(msg)
}
func (logger *ServerLog) Info(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Info(msg)
}
func (logger *ServerLog) Warn(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Warn(msg)
}
func (logger *ServerLog) Error(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Error(msg)
}
func (logger *ServerLog) Fatal(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Fatal(msg)
}
func (logger *ServerLog) Panic(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Panic(msg)
}
func NewServerLog() *ServerLog {
logger := logrus.New()
logger.Formatter = &logrus.JSONFormatter{
TimestampFormat: "2006-01-02 15:04:05",
PrettyPrint: true,
}
if constant.LOG_TYPE == "file" {
file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666)
if err == nil {
_ = file.Truncate(1024 * 1024 * 2)
logger.Out = file
} else {
logger.Info("Failed to log to file, using default stderr")
}
} else if constant.LOG_TYPE == "es" {
url := fmt.Sprintf("http://%s:%s", "es.chenzhiying.asia", "80")
client, err := elastic.NewClient(elastic.SetURL(url), elastic.SetSniff(false))
if err != nil {
//log.Panic(err)
panic(err)
}
hook, err := elogrus.NewAsyncElasticHook(client, "es.chenzhiying.asia", logrus.DebugLevel, "boss-appointment")
if err != nil {
//log.Panic(err)
panic(err)
}
logger.Hooks.Add(hook)
} else {
logger.Out = os.Stdout
}
return &ServerLog{
logrus: logger,
}
}