fix: 优化配置和API处理逻辑

This commit is contained in:
renzhiyuan 2026-01-15 14:12:27 +08:00
parent 7f704b3cb1
commit 941827ce41
11 changed files with 90 additions and 80 deletions

View File

@ -12,6 +12,7 @@ import (
func main() { func main() {
configPath := flag.String("config", "./config/config_test.yaml", "Path to configuration file") configPath := flag.String("config", "./config/config_test.yaml", "Path to configuration file")
onBot := flag.String("bot", "", "bot start") onBot := flag.String("bot", "", "bot start")
cron := flag.String("cron", "", "close")
flag.Parse() flag.Parse()
ctx := context.Background() ctx := context.Background()
bc, err := config.LoadConfig(*configPath) bc, err := config.LoadConfig(*configPath)
@ -29,7 +30,7 @@ func main() {
//钉钉机器人 //钉钉机器人
app.DingBotServer.Run(ctx, *onBot) app.DingBotServer.Run(ctx, *onBot)
//定时任务 - 测试环境不启用 //定时任务 - 测试环境不启用
if configPath != nil && *configPath == "./config/config.yaml" { if *cron == "start" {
app.Cron.Run(ctx) app.Cron.Run(ctx)
} }

View File

@ -108,6 +108,8 @@ tools:
base_url: "https://api.coze.cn" base_url: "https://api.coze.cn"
api_key: "7583905168607100978" api_key: "7583905168607100978"
api_secret: "pat_eEN0BdLNDughEtABjJJRYTW71olvDU0qUbfQUeaPc2NnYWO8HeyNoui5aR9z0sSZ" api_secret: "pat_eEN0BdLNDughEtABjJJRYTW71olvDU0qUbfQUeaPc2NnYWO8HeyNoui5aR9z0sSZ"
zltxResellerAuthProductToManagerAndDefaultLossReason:
base_url: "https://revcl.1688sup.com/api/admin/resellerAuthProductToManagerAndDefaultLossReason"
# eino tool 配置 # eino tool 配置
eino_tools: eino_tools:

View File

@ -26,14 +26,12 @@ coze:
lsxd: lsxd:
# 统一登录 # 统一登录
login_url: "http://api.test.user.1688sup.com/v1/login/phone" login_url: "https://api.user.1688sup.com/v1/login/phone"
phone: "OFJ8UpqOlI7+w3Qklf36ZA==" phone: "ORlviZN7N06W2+WKLe76xg=="
password: "tEbFegH/DRRh6LutFb7o3g==" password: "V5Uh8C4bamEM6UQZh4TCeQ=="
code: "123456" code: "456789"
check_token_url: "http://api.test.user.1688sup.com/v1/user/welcome" check_token_url: "https://api.user.1688sup.com/v1/user/welcome"
zltx:
req_url: "https://gateway.dev.cdlsxd.cn/zltx_api"
sys: sys:
session_len: 6 session_len: 6
@ -106,6 +104,8 @@ tools:
base_url: "https://api.coze.cn" base_url: "https://api.coze.cn"
api_key: "7583905168607100978" api_key: "7583905168607100978"
api_secret: "pat_eEN0BdLNDughEtABjJJRYTW71olvDU0qUbfQUeaPc2NnYWO8HeyNoui5aR9z0sSZ" api_secret: "pat_eEN0BdLNDughEtABjJJRYTW71olvDU0qUbfQUeaPc2NnYWO8HeyNoui5aR9z0sSZ"
zltxResellerAuthProductToManagerAndDefaultLossReason:
base_url: "https://revcl.1688sup.com/api/admin/reseller/resellerAuthProduct/getManagerAndDefaultLossReason"
# eino tool 配置 # eino tool 配置
eino_tools: eino_tools:

View File

@ -16,10 +16,12 @@ fi
CONFIG_FILE="config/config.yaml" CONFIG_FILE="config/config.yaml"
BRANCH="master" BRANCH="master"
BOT="All" BOT="All"
CRON="start"
if [ "$MODE" = "dev" ]; then if [ "$MODE" = "dev" ]; then
CONFIG_FILE="config/config_test.yaml" CONFIG_FILE="config/config_test.yaml"
BOT="zltx" BOT="zltx"
BRANCH="test" BRANCH="test"
CRON="close"
fi fi
git fetch origin git fetch origin
@ -47,6 +49,8 @@ docker run -itd \
-v ./cache:/app/cache \ -v ./cache:/app/cache \
-v ./tmpl:/app/tmpl \ -v ./tmpl:/app/tmpl \
-v ./go.mod:/app/go.mod \ -v ./go.mod:/app/go.mod \
"${CONTAINER_NAME}" ./server --config "./${CONFIG_FILE}" --bot "${BOT}" "${CONTAINER_NAME}" ./server \
--config "./${CONFIG_FILE}" --bot "${BOT}" --cron "${CRON}"
docker logs -f ${CONTAINER_NAME} docker logs -f ${CONTAINER_NAME}

View File

@ -188,11 +188,11 @@ func (g *GroupConfigBiz) handleReport(ctx context.Context, rec *entitys.Recogniz
if _err != nil { if _err != nil {
return _err return _err
} }
reports = append(reports, repo...)
rechargeReport, _err := g.rechargeDailyReport(ctx, t, product, nil) rechargeReport, _err := g.rechargeDailyReport(ctx, t, product, nil)
if _err != nil || len(repo) == 0 { if _err != nil {
return _err return _err
} }
reports = append(reports, repo...)
reports = append(reports, rechargeReport...) reports = append(reports, rechargeReport...)
case "report_daily_recharge": case "report_daily_recharge":
product := strings.Split(groupConfig.ProductName, ",") product := strings.Split(groupConfig.ProductName, ",")
@ -223,7 +223,6 @@ func (g *GroupConfigBiz) handleReport(ctx context.Context, rec *entitys.Recogniz
} }
entitys.ResText(rec.Ch, "", fmt.Sprintf("%s![图片](%s)", report.Title, report.Url)) entitys.ResText(rec.Ch, "", fmt.Sprintf("%s![图片](%s)", report.Title, report.Url))
} }
return nil return nil
} }

View File

@ -27,7 +27,6 @@ type Config struct {
LLM LLM `mapstructure:"llm"` LLM LLM `mapstructure:"llm"`
Dingtalk DingtalkConfig `mapstructure:"dingtalk"` Dingtalk DingtalkConfig `mapstructure:"dingtalk"`
Qywx QywxConfig `mapstructure:"qywx"` Qywx QywxConfig `mapstructure:"qywx"`
ZLTX ZLTX `mapstructure:"zltx"`
} }
type ZLTX struct { type ZLTX struct {
@ -197,6 +196,7 @@ type ToolsConfig struct {
CozeExpress ToolConfig `mapstructure:"cozeExpress"` CozeExpress ToolConfig `mapstructure:"cozeExpress"`
// Coze 公司查询工具 // Coze 公司查询工具
CozeCompany ToolConfig `mapstructure:"cozeCompany"` CozeCompany ToolConfig `mapstructure:"cozeCompany"`
ZltxResellerAuthProductToManagerAndDefaultLossReason ToolConfig `mapstructure:"zltxResellerAuthProductToManagerAndDefaultLossReason"`
} }
// ToolConfig 单个工具配置 // ToolConfig 单个工具配置

View File

@ -195,48 +195,49 @@ type GetManagerAndDefaultLossReasonResponse struct {
} }
type GetManagerAndDefaultLossReasonResponseList struct { type GetManagerAndDefaultLossReasonResponseList struct {
ResellerInfo *GetManagerAndDefaultLossReasonResponse_ResellerInfo `json:"GetManagerAndDefaultLossReasonResponse_ResellerInfo,omitempty"` ResellerInfo *GetManagerAndDefaultLossReasonResponse_ResellerInfo `json:"resellerInfo,omitempty"`
ProductList []*GetManagerAndDefaultLossReasonResponse_ProductList `json:"GetManagerAndDefaultLossReasonResponse_ProductList,omitempty"` ProductList []*GetManagerAndDefaultLossReasonResponse_ProductList `json:"productList,omitempty"`
} }
type GetManagerAndDefaultLossReasonResponse_ResellerInfo struct { type GetManagerAndDefaultLossReasonResponse_ResellerInfo struct {
ResellerId int32 `json:"reseller_id,omitempty"` ResellerId int32 `json:"resellerId,omitempty"`
AfterSaleName string `json:"after_sale_name,omitempty"` AfterSaleName string `json:"AfterSaleName,omitempty"`
} }
type GetManagerAndDefaultLossReasonResponse_ProductList struct { type GetManagerAndDefaultLossReasonResponse_ProductList struct {
ProductId int32 `json:"product_id,omitempty"` ProductId int32 `json:"productId,omitempty"`
LossReason string `json:"loss_reason,omitempty"` LossReason string `json:"lossReason,omitempty"`
} }
//return []*GetManagerAndDefaultLossReasonResponseList{
//{
//ResellerInfo: &GetManagerAndDefaultLossReasonResponse_ResellerInfo{
//ResellerId: 25009,
//AfterSaleName: "张三",
//},
//ProductList: []*GetManagerAndDefaultLossReasonResponse_ProductList{
//{
//ProductId: 129,
//LossReason: "小米钱包h5-QQ音乐绿钻季卡原因",
//},
//{
//ProductId: 2218,
//LossReason: "小米钱包h5-百度网盘新vip会员月卡原因",
//},
//{
//ProductId: 3226,
//LossReason: "小米钱包h5-腾讯视频月卡-小米钱包2024原因",
//},
//{
//ProductId: 3364,
//LossReason: "小米钱包h5-腾讯视频月卡-0元直充原因",
//},
//},
//},
//}, nil
// GetStatisFilterOfficialProductApi 官方商品列表 // GetStatisFilterOfficialProductApi 官方商品列表
func GetManagerAndDefaultLossReasonApi(param *GetManagerAndDefaultLossReasonRequest, token string, reqUrl string) ([]*GetManagerAndDefaultLossReasonResponseList, error) { func GetManagerAndDefaultLossReasonApi(param *GetManagerAndDefaultLossReasonRequest, token string, reqUrl string) ([]*GetManagerAndDefaultLossReasonResponseList, error) {
return []*GetManagerAndDefaultLossReasonResponseList{
{
ResellerInfo: &GetManagerAndDefaultLossReasonResponse_ResellerInfo{
ResellerId: 25009,
AfterSaleName: "张三",
},
ProductList: []*GetManagerAndDefaultLossReasonResponse_ProductList{
{
ProductId: 129,
LossReason: "小米钱包h5-QQ音乐绿钻季卡原因",
},
{
ProductId: 2218,
LossReason: "小米钱包h5-百度网盘新vip会员月卡原因",
},
{
ProductId: 3226,
LossReason: "小米钱包h5-腾讯视频月卡-小米钱包2024原因",
},
{
ProductId: 3364,
LossReason: "小米钱包h5-腾讯视频月卡-0元直充原因",
},
},
},
}, nil
reqParam, err := util.StructToMap(param) reqParam, err := util.StructToMap(param)
if err != nil { if err != nil {
@ -244,7 +245,7 @@ func GetManagerAndDefaultLossReasonApi(param *GetManagerAndDefaultLossReasonRequ
} }
req := &l_request.Request{ req := &l_request.Request{
Url: reqUrl + "/admin/reseller/resellerAuthProduct/getManagerAndDefaultLossReason", Url: reqUrl,
Method: http.MethodPost, Method: http.MethodPost,
Json: reqParam, Json: reqParam,
Headers: map[string]string{ Headers: map[string]string{

View File

@ -189,34 +189,34 @@ func (b *BbxtTools) StatisOursProductLossSum(ctx context.Context, now time.Time,
report = make([]*ReportRes, 3) report = make([]*ReportRes, 3)
timeCh := now.Format("1月2日15点") timeCh := now.Format("1月2日15点")
//总量生成excel //总量生成excel
//if len(total) > 0 { if len(total) > 0 {
// filePath := b.cacheDir + "/kshj_total" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx" filePath := b.cacheDir + "/kshj_total" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
// err = b.SimpleFillExcelWithTitle(b.excelTempDir+"/"+"kshj_total.xlsx", filePath, total, "") err = b.SimpleFillExcelWithTitle(b.excelTempDir+"/"+"kshj_total.xlsx", filePath, total, "")
// if err != nil { if err != nil {
// return return
// } }
// report[0] = &ReportRes{ report[0] = &ReportRes{
// ReportName: "分销商负利润统计", ReportName: "分销商负利润统计",
// Title: "截至" + timeCh + "利润累计亏损" + fmt.Sprintf("%.2f", totalSum), Title: "截至" + timeCh + "利润累计亏损" + fmt.Sprintf("%.2f", totalSum),
// Path: filePath, Path: filePath,
// Data: total, Data: total,
// } }
//} }
//if len(gt) > 0 { if len(gt) > 0 {
// filePath := b.cacheDir + "/kshj_gt" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx" filePath := b.cacheDir + "/kshj_gt" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
// title := "截至" + timeCh + "亏损500以上的分销商和产品" title := "截至" + timeCh + "亏损500以上的分销商和产品"
// err = b.resellerDetailFillExcelV2(b.excelTempDir+"/"+"kshj_gt.xlsx", filePath, gt, title) err = b.resellerDetailFillExcelV2(b.excelTempDir+"/"+"kshj_gt.xlsx", filePath, gt, title)
// if err != nil { if err != nil {
// return return
// } }
// report[1] = &ReportRes{ report[1] = &ReportRes{
// ReportName: "负利润分析(亏损500以上)", ReportName: "负利润分析(亏损500以上)",
// Title: "截至" + timeCh + "亏损500以上利润累计亏损" + fmt.Sprintf("%.2f", totalSum500), Title: "截至" + timeCh + "亏损500以上利润累计亏损" + fmt.Sprintf("%.2f", totalSum500),
// Path: filePath, Path: filePath,
// Data: total, Data: total,
// } }
//} }
if len(totalDetail) > 0 { if len(totalDetail) > 0 {
err = initFunc(ctx, now, totalDetail, b) err = initFunc(ctx, now, totalDetail, b)
@ -269,7 +269,7 @@ func (b *BbxtTools) GetResellerLossMannagerAndLossReasonFromApi(ctx context.Cont
} }
res, err := GetManagerAndDefaultLossReasonApi(&GetManagerAndDefaultLossReasonRequest{ res, err := GetManagerAndDefaultLossReasonApi(&GetManagerAndDefaultLossReasonRequest{
Param: resellerMap, Param: resellerMap,
}, b.login.GetToken(ctx), b.config.ZLTX.ReqUrl) }, b.login.GetToken(ctx), b.config.Tools.ZltxResellerAuthProductToManagerAndDefaultLossReason.BaseURL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -286,6 +286,9 @@ func (b *BbxtTools) GetResellerLossMannagerAndLossReasonFromApi(ctx context.Cont
if _, ex := relationMap[v.ResellerInfo.ResellerId].Products[vv.ProductId]; !ex { if _, ex := relationMap[v.ResellerInfo.ResellerId].Products[vv.ProductId]; !ex {
continue continue
} }
if len(vv.LossReason) == 0 {
continue
}
relationMap[v.ResellerInfo.ResellerId].Products[vv.ProductId].LossReason = vv.LossReason relationMap[v.ResellerInfo.ResellerId].Products[vv.ProductId].LossReason = vv.LossReason
} }
} }

View File

@ -111,8 +111,8 @@ func GetReportCache(ctx context.Context, day time.Time, totalDetail []*ResellerL
var ResellerProductRelation map[int32]*ResellerLossSumProductRelation var ResellerProductRelation map[int32]*ResellerLossSumProductRelation
dayDate := day.Format(time.DateOnly) dayDate := day.Format(time.DateOnly)
cond := builder.NewCond() cond := builder.NewCond()
cond = cond.And(builder.Eq{"`index`": IndexLossSumDetail}) cond = cond.And(builder.Eq{"cache_index": IndexLossSumDetail})
cond = cond.And(builder.Eq{"`key`": dayDate}) cond = cond.And(builder.Eq{"cache_key": dayDate})
var cache model.AiReportDailyCache var cache model.AiReportDailyCache
err := reportDailyCacheImpl.GetOneBySearchToStrut(&cond, &cache) err := reportDailyCacheImpl.GetOneBySearchToStrut(&cond, &cache)
@ -125,8 +125,8 @@ func GetReportCache(ctx context.Context, day time.Time, totalDetail []*ResellerL
return err return err
} }
cache = model.AiReportDailyCache{ cache = model.AiReportDailyCache{
Key: dayDate, CacheKey: dayDate,
Index: IndexLossSumDetail, CacheIndex: IndexLossSumDetail,
Value: pkg.JsonStringIgonErr(ResellerProductRelation), Value: pkg.JsonStringIgonErr(ResellerProductRelation),
} }
_, err = reportDailyCacheImpl.Add(&cache) _, err = reportDailyCacheImpl.Add(&cache)

Binary file not shown.

Binary file not shown.