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

View File

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

View File

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

View File

@ -16,10 +16,12 @@ fi
CONFIG_FILE="config/config.yaml"
BRANCH="master"
BOT="All"
CRON="start"
if [ "$MODE" = "dev" ]; then
CONFIG_FILE="config/config_test.yaml"
BOT="zltx"
BRANCH="test"
CRON="close"
fi
git fetch origin
@ -47,6 +49,8 @@ docker run -itd \
-v ./cache:/app/cache \
-v ./tmpl:/app/tmpl \
-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}

View File

@ -188,11 +188,11 @@ func (g *GroupConfigBiz) handleReport(ctx context.Context, rec *entitys.Recogniz
if _err != nil {
return _err
}
reports = append(reports, repo...)
rechargeReport, _err := g.rechargeDailyReport(ctx, t, product, nil)
if _err != nil || len(repo) == 0 {
if _err != nil {
return _err
}
reports = append(reports, repo...)
reports = append(reports, rechargeReport...)
case "report_daily_recharge":
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))
}
return nil
}

View File

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

View File

@ -195,48 +195,49 @@ type GetManagerAndDefaultLossReasonResponse struct {
}
type GetManagerAndDefaultLossReasonResponseList struct {
ResellerInfo *GetManagerAndDefaultLossReasonResponse_ResellerInfo `json:"GetManagerAndDefaultLossReasonResponse_ResellerInfo,omitempty"`
ProductList []*GetManagerAndDefaultLossReasonResponse_ProductList `json:"GetManagerAndDefaultLossReasonResponse_ProductList,omitempty"`
ResellerInfo *GetManagerAndDefaultLossReasonResponse_ResellerInfo `json:"resellerInfo,omitempty"`
ProductList []*GetManagerAndDefaultLossReasonResponse_ProductList `json:"productList,omitempty"`
}
type GetManagerAndDefaultLossReasonResponse_ResellerInfo struct {
ResellerId int32 `json:"reseller_id,omitempty"`
AfterSaleName string `json:"after_sale_name,omitempty"`
ResellerId int32 `json:"resellerId,omitempty"`
AfterSaleName string `json:"AfterSaleName,omitempty"`
}
type GetManagerAndDefaultLossReasonResponse_ProductList struct {
ProductId int32 `json:"product_id,omitempty"`
LossReason string `json:"loss_reason,omitempty"`
ProductId int32 `json:"productId,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 官方商品列表
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)
if err != nil {
@ -244,7 +245,7 @@ func GetManagerAndDefaultLossReasonApi(param *GetManagerAndDefaultLossReasonRequ
}
req := &l_request.Request{
Url: reqUrl + "/admin/reseller/resellerAuthProduct/getManagerAndDefaultLossReason",
Url: reqUrl,
Method: http.MethodPost,
Json: reqParam,
Headers: map[string]string{

View File

@ -189,34 +189,34 @@ func (b *BbxtTools) StatisOursProductLossSum(ctx context.Context, now time.Time,
report = make([]*ReportRes, 3)
timeCh := now.Format("1月2日15点")
//总量生成excel
//if len(total) > 0 {
// 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, "")
// if err != nil {
// return
// }
// report[0] = &ReportRes{
// ReportName: "分销商负利润统计",
// Title: "截至" + timeCh + "利润累计亏损" + fmt.Sprintf("%.2f", totalSum),
// Path: filePath,
// Data: total,
// }
//}
if len(total) > 0 {
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, "")
if err != nil {
return
}
report[0] = &ReportRes{
ReportName: "分销商负利润统计",
Title: "截至" + timeCh + "利润累计亏损" + fmt.Sprintf("%.2f", totalSum),
Path: filePath,
Data: total,
}
}
//if len(gt) > 0 {
// filePath := b.cacheDir + "/kshj_gt" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
// title := "截至" + timeCh + "亏损500以上的分销商和产品"
// err = b.resellerDetailFillExcelV2(b.excelTempDir+"/"+"kshj_gt.xlsx", filePath, gt, title)
// if err != nil {
// return
// }
// report[1] = &ReportRes{
// ReportName: "负利润分析(亏损500以上)",
// Title: "截至" + timeCh + "亏损500以上利润累计亏损" + fmt.Sprintf("%.2f", totalSum500),
// Path: filePath,
// Data: total,
// }
//}
if len(gt) > 0 {
filePath := b.cacheDir + "/kshj_gt" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
title := "截至" + timeCh + "亏损500以上的分销商和产品"
err = b.resellerDetailFillExcelV2(b.excelTempDir+"/"+"kshj_gt.xlsx", filePath, gt, title)
if err != nil {
return
}
report[1] = &ReportRes{
ReportName: "负利润分析(亏损500以上)",
Title: "截至" + timeCh + "亏损500以上利润累计亏损" + fmt.Sprintf("%.2f", totalSum500),
Path: filePath,
Data: total,
}
}
if len(totalDetail) > 0 {
err = initFunc(ctx, now, totalDetail, b)
@ -269,7 +269,7 @@ func (b *BbxtTools) GetResellerLossMannagerAndLossReasonFromApi(ctx context.Cont
}
res, err := GetManagerAndDefaultLossReasonApi(&GetManagerAndDefaultLossReasonRequest{
Param: resellerMap,
}, b.login.GetToken(ctx), b.config.ZLTX.ReqUrl)
}, b.login.GetToken(ctx), b.config.Tools.ZltxResellerAuthProductToManagerAndDefaultLossReason.BaseURL)
if err != nil {
return nil, err
}
@ -286,6 +286,9 @@ func (b *BbxtTools) GetResellerLossMannagerAndLossReasonFromApi(ctx context.Cont
if _, ex := relationMap[v.ResellerInfo.ResellerId].Products[vv.ProductId]; !ex {
continue
}
if len(vv.LossReason) == 0 {
continue
}
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
dayDate := day.Format(time.DateOnly)
cond := builder.NewCond()
cond = cond.And(builder.Eq{"`index`": IndexLossSumDetail})
cond = cond.And(builder.Eq{"`key`": dayDate})
cond = cond.And(builder.Eq{"cache_index": IndexLossSumDetail})
cond = cond.And(builder.Eq{"cache_key": dayDate})
var cache model.AiReportDailyCache
err := reportDailyCacheImpl.GetOneBySearchToStrut(&cond, &cache)
@ -125,9 +125,9 @@ func GetReportCache(ctx context.Context, day time.Time, totalDetail []*ResellerL
return err
}
cache = model.AiReportDailyCache{
Key: dayDate,
Index: IndexLossSumDetail,
Value: pkg.JsonStringIgonErr(ResellerProductRelation),
CacheKey: dayDate,
CacheIndex: IndexLossSumDetail,
Value: pkg.JsonStringIgonErr(ResellerProductRelation),
}
_, err = reportDailyCacheImpl.Add(&cache)
if err != nil {

Binary file not shown.

Binary file not shown.