Compare commits
No commits in common. "master" and "feature/rzy/bug_optimization_submit_and_order_search" have entirely different histories.
master
...
feature/rz
|
|
@ -5,9 +5,6 @@ server:
|
|||
|
||||
ollama:
|
||||
base_url: "http://172.17.0.1:11434"
|
||||
# model: "qwen3:8b"
|
||||
# generate_model: "qwen3:8b"
|
||||
# mapping_model: "qwen3:8b"
|
||||
model: "qwen3-coder:480b-cloud"
|
||||
generate_model: "qwen3-coder:480b-cloud"
|
||||
mapping_model: "deepseek-v3.2:cloud"
|
||||
|
|
@ -39,7 +36,7 @@ sys:
|
|||
channel_pool_len: 100
|
||||
channel_pool_size: 32
|
||||
llm_pool_len: 5
|
||||
heartbeat_interval: 300
|
||||
heartbeat_interval: 30
|
||||
key: report-api
|
||||
pollSize: 5 #连接池大小,不配置,或配置为0表示不启用连接池
|
||||
minIdleConns: 2 #最小空闲连接数
|
||||
|
|
@ -149,7 +146,7 @@ eino_tools:
|
|||
# == 通用工具 ==
|
||||
# 表格转图片
|
||||
excel2pic:
|
||||
base_url: "http://192.168.6.115:8010/api/v1/convert"
|
||||
base_url: "http://excel2pic:8000/api/v1/convert"
|
||||
|
||||
dingtalk:
|
||||
api_key: "dingsbbntrkeiyazcfdg"
|
||||
|
|
|
|||
|
|
@ -88,8 +88,6 @@ tools:
|
|||
zltxOrderAfterSaleResellerBatch:
|
||||
enabled: true
|
||||
base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/afterSales/reseller_pre_ai"
|
||||
zltxResellerAuthProductToManagerAndDefaultLossReason:
|
||||
base_url: "https://revcl.1688sup.com/api/admin/reseller/resellerAuthProduct/getManagerAndDefaultLossReason"
|
||||
|
||||
# eino tool 配置
|
||||
eino_tools:
|
||||
|
|
|
|||
|
|
@ -26,11 +26,12 @@ coze:
|
|||
|
||||
lsxd:
|
||||
# 统一登录
|
||||
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"
|
||||
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"
|
||||
|
||||
|
||||
sys:
|
||||
session_len: 6
|
||||
|
|
@ -141,7 +142,7 @@ eino_tools:
|
|||
# == 通用工具 ==
|
||||
# 表格转图片
|
||||
excel2pic:
|
||||
base_url: "http://192.168.6.115:8010/api/v1/convert"
|
||||
base_url: "http://192.168.6.109:8010/api/v1/convert"
|
||||
|
||||
dingtalk:
|
||||
api_key: "dingsbbntrkeiyazcfdg"
|
||||
|
|
|
|||
|
|
@ -312,38 +312,6 @@ func (d *DingTalkBotBiz) SendReport(ctx context.Context, groupInfo *model.AiBotG
|
|||
return
|
||||
}
|
||||
|
||||
// SendReports 发送多个报告
|
||||
func (d *DingTalkBotBiz) SendReports(ctx context.Context, groupInfo *model.AiBotGroup, reports []*bbxt.ReportRes) (err error) {
|
||||
if len(reports) == 0 {
|
||||
return errors.New("report is empty")
|
||||
}
|
||||
|
||||
title := fmt.Sprintf("截止%s日报", time.Now().Format("1月2日15点"))
|
||||
reportChan := make(chan string, len(reports)*2)
|
||||
writeCount := 0
|
||||
for _, v := range reports {
|
||||
if v == nil {
|
||||
continue
|
||||
}
|
||||
reportChan <- fmt.Sprintf("**%s**", v.Title)
|
||||
reportChan <- fmt.Sprintf("", v.Url)
|
||||
writeCount += 2
|
||||
}
|
||||
close(reportChan)
|
||||
if writeCount == 0 {
|
||||
return errors.New("report is empty")
|
||||
}
|
||||
err = d.HandleStreamRes(ctx, &chatbot.BotCallbackDataModel{
|
||||
RobotCode: groupInfo.RobotCode,
|
||||
ConversationType: constants.ConversationTypeGroup,
|
||||
ConversationId: groupInfo.ConversationID,
|
||||
Text: chatbot.BotCallbackDataTextModel{
|
||||
Content: title,
|
||||
},
|
||||
}, reportChan)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *DingTalkBotBiz) GetGroupInfo(ctx context.Context, groupId int) (group model.AiBotGroup, err error) {
|
||||
|
||||
cond := builder.NewCond()
|
||||
|
|
|
|||
|
|
@ -98,12 +98,14 @@ func (g *GroupConfigBiz) GetReportLists(ctx context.Context, groupConfig *model.
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//追加电商充值系统统计 - 返回统一使用[]*bbxt.ReportRes
|
||||
rechargeReports, err := g.rechargeDailyReport(ctx, time.Now(), nil, g.ossClient)
|
||||
if err != nil || len(rechargeReports) == 0 {
|
||||
return
|
||||
}
|
||||
reports = append(rechargeReports, reports...)
|
||||
|
||||
reports = append(reports, rechargeReports...)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
@ -173,7 +175,7 @@ func (g *GroupConfigBiz) handleReport(ctx context.Context, rec *entitys.Recogniz
|
|||
if _err != nil {
|
||||
return _err
|
||||
}
|
||||
reports = append(reports, repo)
|
||||
reports = append(reports, repo...)
|
||||
case "report_sales_analysis":
|
||||
product := strings.Split(groupConfig.ProductName, ",")
|
||||
repo, _err := rep.GetStatisOfficialProductSum(t, product)
|
||||
|
|
@ -198,9 +200,8 @@ func (g *GroupConfigBiz) handleReport(ctx context.Context, rec *entitys.Recogniz
|
|||
if _err != nil {
|
||||
return _err
|
||||
}
|
||||
reports = append(reports, rechargeReport...)
|
||||
reports = append(reports, repo...)
|
||||
|
||||
reports = append(reports, rechargeReport...)
|
||||
case "report_daily_recharge":
|
||||
product := strings.Split(groupConfig.ProductName, ",")
|
||||
repo, _err := g.rechargeDailyReport(ctx, t, product, nil)
|
||||
|
|
|
|||
|
|
@ -115,7 +115,6 @@ func (s *SendCardClient) NewCard(ctx context.Context, cardSend *CardSend) error
|
|||
s.processContentChannel(ctx, cardSend, cardInstanceId.String(), client)
|
||||
}()
|
||||
wg.Wait()
|
||||
log.Info("处理通道结束")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -164,7 +163,7 @@ func (s *SendCardClient) processContentChannel(ctx context.Context, cardSend *Ca
|
|||
|
||||
var (
|
||||
contentBuilder strings.Builder
|
||||
lastUpdate = time.Now()
|
||||
lastUpdate time.Time
|
||||
)
|
||||
for {
|
||||
|
||||
|
|
@ -174,7 +173,6 @@ func (s *SendCardClient) processContentChannel(ctx context.Context, cardSend *Ca
|
|||
// 通道关闭,发送最终内容
|
||||
if contentBuilder.Len() > 0 {
|
||||
if err := s.updateCardContent(ctx, cardSend, cardInstanceId, contentBuilder.String(), client); err != nil {
|
||||
log.Info("contentBuilder.Len()修改失败1")
|
||||
s.logger.Errorf("更新卡片失败1:%s", err.Error())
|
||||
}
|
||||
}
|
||||
|
|
@ -183,7 +181,6 @@ func (s *SendCardClient) processContentChannel(ctx context.Context, cardSend *Ca
|
|||
contentBuilder.WriteString(content)
|
||||
if contentBuilder.Len() > 0 {
|
||||
if err := s.updateCardContent(ctx, cardSend, cardInstanceId, contentBuilder.String(), client); err != nil {
|
||||
log.Info("contentBuilder.Len()修改失败2")
|
||||
s.logger.Errorf("更新卡片失败2:%s", err.Error())
|
||||
}
|
||||
}
|
||||
|
|
@ -191,12 +188,10 @@ func (s *SendCardClient) processContentChannel(ctx context.Context, cardSend *Ca
|
|||
|
||||
case <-heartbeatTicker.C:
|
||||
if time.Now().Unix()-lastUpdate.Unix() >= HeardBeatX {
|
||||
log.Infof("心跳超时,当前时间:%d,最后时间:%d", time.Now().Unix(), lastUpdate.Unix())
|
||||
return
|
||||
}
|
||||
|
||||
case <-ctx.Done():
|
||||
log.Info("send_card上下文失效")
|
||||
s.logger.Info("context canceled, stop channel processing")
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ func LoadConfigWithEnv() (*Config, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
viper.SetConfigFile(modularDir + "/config/config.yaml")
|
||||
viper.SetConfigFile(modularDir + "/config/config_env.yaml")
|
||||
viper.SetConfigType("yaml")
|
||||
// 读取配置文件
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ func (w *statisticsOursProduct) formatContext(ctx context.Context, input *Statis
|
|||
Time: time.Now(),
|
||||
StartTime: startTime,
|
||||
EndTime: endTime,
|
||||
Title: fmt.Sprintf("截止 %s 电商系统亏损100以上我们的商品统计", endTimeStr),
|
||||
Title: fmt.Sprintf("截止 %s 亏损100以上我们的商品统计", endTimeStr),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ollama/ollama/api"
|
||||
)
|
||||
|
|
@ -44,12 +43,11 @@ func (c *Client) ToolSelect(ctx context.Context, messages []api.Message, tools [
|
|||
|
||||
// 构建聊天请求
|
||||
req := &api.ChatRequest{
|
||||
Model: c.config.Model,
|
||||
Messages: messages,
|
||||
Stream: new(bool), // 设置为false,不使用流式响应
|
||||
Think: &api.ThinkValue{Value: false},
|
||||
Tools: tools,
|
||||
KeepAlive: &api.Duration{Duration: 24 * time.Hour},
|
||||
Model: c.config.Model,
|
||||
Messages: messages,
|
||||
Stream: new(bool), // 设置为false,不使用流式响应
|
||||
Think: &api.ThinkValue{Value: false},
|
||||
Tools: tools,
|
||||
}
|
||||
err = c.client.Chat(ctx, req, func(resp api.ChatResponse) error {
|
||||
res = resp
|
||||
|
|
|
|||
|
|
@ -50,18 +50,12 @@ func (d *CronService) CronReportSendDingTalk(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// for _, report := range reports {
|
||||
// err = d.dingTalkBotBiz.SendReport(ctx, &groupInfo, report)
|
||||
// if err != nil {
|
||||
// log.Error(err)
|
||||
// continue
|
||||
// }
|
||||
// }
|
||||
|
||||
err = d.dingTalkBotBiz.SendReports(ctx, &groupInfo, reports)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return err
|
||||
for _, report := range reports {
|
||||
err = d.dingTalkBotBiz.SendReport(ctx, &groupInfo, report)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,15 +64,9 @@ func (d *DingBotService) runBackgroundTasks(ctx context.Context, data *chatbot.B
|
|||
g.Go(func() error {
|
||||
defer func() {
|
||||
// 确保通道最终关闭
|
||||
log.Println("流式处理协程关闭")
|
||||
|
||||
close(resChan)
|
||||
}()
|
||||
err := d.dingTalkBotBiz.HandleStreamRes(ctx, data, resChan)
|
||||
if err != nil {
|
||||
log.Println("流式回复产生错误,错误:", err.Error())
|
||||
}
|
||||
return err
|
||||
return d.dingTalkBotBiz.HandleStreamRes(ctx, data, resChan)
|
||||
})
|
||||
|
||||
// 2. 业务处理协程(负责关闭requireData.Ch)
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ func run() {
|
|||
// 初始化Ollama服务
|
||||
ollamaService := llm_service.NewOllamaGenerate(client, utils_vllmClient, configConfig, chatHisImpl)
|
||||
// 初始化工具管理器
|
||||
manager := tools.NewManager(configConfig, client, rdb)
|
||||
manager := tools.NewManager(configConfig, client)
|
||||
// 初始化钉钉联系人客户端
|
||||
contactClient, _ := dingtalk.NewContactClient(configConfig)
|
||||
// 初始化钉钉记事本客户端
|
||||
|
|
@ -120,10 +120,8 @@ func run() {
|
|||
group := qywx.NewGroup(botGroupQywxImpl, qywxAuth)
|
||||
other := qywx.NewOther(qywxAuth)
|
||||
qywxAppBiz := biz.NewQywxAppBiz(configConfig, botGroupQywxImpl, group, other)
|
||||
reportDailyCacheImpl := impl.NewReportDailyCacheImpl(db)
|
||||
macro := do.NewMacro(botGroupImpl, reportDailyCacheImpl, configConfig, rdb)
|
||||
groupConfigBiz := biz.NewGroupConfigBiz(toolRegis, utils_ossClient, botGroupConfigImpl, registry, configConfig, impl.NewReportDailyCacheImpl(db), rdb, macro, manager, handle)
|
||||
dingTalkBotBiz := biz.NewDingTalkBotBiz(doDo, handle, botConfigImpl, botGroupImpl, user, botChatHisImpl, reportDailyCacheImpl, manager, configConfig, sendCardClient, groupConfigBiz, macro)
|
||||
groupConfigBiz := biz.NewGroupConfigBiz(toolRegis, utils_ossClient, botGroupConfigImpl, registry, configConfig, impl.NewReportDailyCacheImpl(db), rdb)
|
||||
dingTalkBotBiz := biz.NewDingTalkBotBiz(doDo, handle, botConfigImpl, botGroupImpl, user, botChatHisImpl, impl.NewReportDailyCacheImpl(db), manager, configConfig, sendCardClient, groupConfigBiz)
|
||||
// 初始化钉钉机器人服务
|
||||
cronService = NewCronService(configConfig, dingTalkBotBiz, qywxAppBiz, groupConfigBiz)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ import (
|
|||
"sort"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -39,8 +37,6 @@ var ResellerBlackListProduct = []string{
|
|||
"蓝星严选连续包月",
|
||||
"通钱-2025年12月",
|
||||
"彦浩同行",
|
||||
"运营部测试专用",
|
||||
"彦浩直客商户",
|
||||
}
|
||||
|
||||
type BbxtTools struct {
|
||||
|
|
@ -95,7 +91,9 @@ func (b *BbxtTools) DailyReport(
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
reports = append(reports, profitRankingSum, statisOfficialProductSum, statisOfficialProductSumDecline, productLossReport)
|
||||
reports = append(reports, productLossReport...)
|
||||
reports = append(reports, profitRankingSum, statisOfficialProductSum, statisOfficialProductSumDecline)
|
||||
|
||||
if ossClient != nil {
|
||||
uploader := NewUploader(ossClient, b.config)
|
||||
for _, report := range reports {
|
||||
|
|
@ -137,9 +135,7 @@ func (b *BbxtTools) ResellerLossSort(ctx context.Context, now time.Time) ([]*Res
|
|||
reseller := resellerMap[info.ResellerId]
|
||||
|
||||
// 累加经销商总亏损
|
||||
num1 := decimal.NewFromFloat(reseller.Total)
|
||||
num2 := decimal.NewFromFloat(info.Loss)
|
||||
reseller.Total, _ = num1.Add(num2).Round(2).Float64()
|
||||
reseller.Total += info.Loss
|
||||
|
||||
// 检查产品是否已存在
|
||||
if _, ok := reseller.ProductLoss[info.OursProductId]; !ok {
|
||||
|
|
@ -213,66 +209,61 @@ func (b *BbxtTools) ResellerLossToMapResellerLossSumProductRelation(totalDetail
|
|||
}
|
||||
|
||||
// StatisOursProductLossSum 负利润分析
|
||||
func (b *BbxtTools) StatisOursProductLossSum(ctx context.Context, now time.Time, initFunc LossSumInitFunc) (report *ReportRes, err error) {
|
||||
func (b *BbxtTools) StatisOursProductLossSum(ctx context.Context, now time.Time, initFunc LossSumInitFunc) (report []*ReportRes, err error) {
|
||||
resellers, err := b.ResellerLossSort(ctx, now)
|
||||
var (
|
||||
total [][]string
|
||||
//gt []*ResellerLoss
|
||||
total [][]string
|
||||
gt []*ResellerLoss
|
||||
totalDetail []*ResellerLoss
|
||||
totalSum = decimal.NewFromFloat(0)
|
||||
//totalSum500 float64
|
||||
totalSum float64
|
||||
totalSum500 float64
|
||||
)
|
||||
// 构建分组
|
||||
for _, v := range resellers {
|
||||
if slices.Contains(ResellerBlackListProduct, v.ResellerName) {
|
||||
continue
|
||||
}
|
||||
if v.Total <= -100 {
|
||||
if v.Total <= -100 && !slices.Contains(ResellerBlackListProduct, v.ResellerName) {
|
||||
total = append(total, []string{
|
||||
fmt.Sprintf("%s", v.ResellerName),
|
||||
fmt.Sprintf("%.2f", v.Total),
|
||||
})
|
||||
|
||||
totalSum += v.Total
|
||||
totalDetail = append(totalDetail, v)
|
||||
}
|
||||
num := decimal.NewFromFloat(v.Total)
|
||||
totalSum = totalSum.Add(num).Round(2)
|
||||
//if v.Total <= -500 && !slices.Contains(ResellerBlackListProduct, v.ResellerName) {
|
||||
// gt = append(gt, v)
|
||||
// totalSum500 += v.Total
|
||||
//}
|
||||
if v.Total <= -500 && !slices.Contains(ResellerBlackListProduct, v.ResellerName) {
|
||||
gt = append(gt, v)
|
||||
totalSum500 += v.Total
|
||||
}
|
||||
}
|
||||
//report = make([]*ReportRes, 3)
|
||||
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(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(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(totalDetail) > 0 {
|
||||
err = initFunc(ctx, now, totalDetail, b)
|
||||
|
|
@ -280,15 +271,14 @@ func (b *BbxtTools) StatisOursProductLossSum(ctx context.Context, now time.Time,
|
|||
return
|
||||
}
|
||||
filePath := b.cacheDir + "/kshj_total_ana" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
|
||||
totalSumFloat64, _ := totalSum.Float64()
|
||||
title := "截至" + timeCh + "利润累计亏损" + fmt.Sprintf("%.2f", totalSumFloat64) + ",亏损100以上利润原因如下"
|
||||
title := "截至" + timeCh + "亏损100以上的分销商&产品负利润原因"
|
||||
err = b.resellerDetailFillExcelAna(b.excelTempDir+"/"+"kshj_total_ana.xlsx", filePath, totalDetail, title)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
report = &ReportRes{
|
||||
report[2] = &ReportRes{
|
||||
ReportName: "负利润分析(亏损100以上)",
|
||||
Title: title,
|
||||
Title: "截至" + timeCh + "亏损100以上利润原因",
|
||||
Path: filePath,
|
||||
Data: total,
|
||||
}
|
||||
|
|
@ -413,6 +403,10 @@ func (b *BbxtTools) GetProfitRankingSum(now time.Time) (report *ReportRes, err e
|
|||
|
||||
// GetStatisOfficialProductSum 销量同比分析
|
||||
func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []string) (report *ReportRes, err error) {
|
||||
var productMap = make(map[string]int)
|
||||
for k, v := range productName {
|
||||
productMap[v] = k
|
||||
}
|
||||
ct := []string{
|
||||
time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Format("2006-01-02 15:04:05"),
|
||||
adjustedTime(now),
|
||||
|
|
@ -434,11 +428,7 @@ func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []str
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建临时map存储产品数据
|
||||
productDataMap := make(map[string][]string)
|
||||
var productNamesInResult []string
|
||||
|
||||
var total = make([][]string, len(ids))
|
||||
for _, v := range data.OfficialProductSum {
|
||||
var (
|
||||
yeterDatyDiff string
|
||||
|
|
@ -454,8 +444,7 @@ func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []str
|
|||
} else {
|
||||
lastWeekDiff = fmt.Sprintf("%s↓%d", GreenStyle, v.HistoryTwoDiff)
|
||||
}
|
||||
|
||||
rowData := []string{
|
||||
total[productMap[v.OfficialProductName]] = []string{
|
||||
fmt.Sprintf("%s", v.OfficialProductName),
|
||||
fmt.Sprintf("%d", v.CurrentNum),
|
||||
fmt.Sprintf("%d", v.HistoryOneNum),
|
||||
|
|
@ -464,20 +453,7 @@ func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []str
|
|||
lastWeekDiff,
|
||||
}
|
||||
|
||||
// 存储到map中,key为产品名
|
||||
productDataMap[v.OfficialProductName] = rowData
|
||||
productNamesInResult = append(productNamesInResult, v.OfficialProductName)
|
||||
}
|
||||
|
||||
// 按照productName的顺序构建total
|
||||
var total [][]string
|
||||
|
||||
for _, name := range productName {
|
||||
if rowData, exists := productDataMap[name]; exists {
|
||||
total = append(total, rowData)
|
||||
}
|
||||
}
|
||||
|
||||
timeCh := now.Format("1月2日15点")
|
||||
title := "截至" + timeCh + "销售同比分析"
|
||||
//总量生成excel
|
||||
|
|
|
|||
|
|
@ -79,22 +79,14 @@ func Test_GetStatisOfficialProductSumDecline(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_GetStatisOfficialProductSum(t *testing.T) {
|
||||
run()
|
||||
|
||||
configs := configConfig
|
||||
o, err := NewBbxtTools(nil, lsxd.NewLogin(configs, utils.NewRdb(configConfig)))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s := "官方--腾讯-周卡,官方--腾讯-月卡,官方--腾讯-季卡,官方--腾讯-年卡,官方--优酷周卡,官方--优酷月卡,官方--优酷季卡,官方--优酷年卡,官方--爱奇艺-周卡,官方--爱奇艺-月卡,官方--爱奇艺-季卡,官方--爱奇艺-年卡,官方--芒果-PC周卡,官方--芒果-PC月卡,官方--芒果-PC季卡,官方--美团外卖红包5元,官方--美团外卖红包10元,官方--QQ音乐-绿钻月卡,官方--饿了么超级会员月卡,官方--网易云黑胶vip月卡,官方--喜马拉雅巅峰会员月卡"
|
||||
now := time.Now()
|
||||
noon := time.Date(
|
||||
now.Year(),
|
||||
now.Month(),
|
||||
now.Day(),
|
||||
12, 0, 0, 0,
|
||||
now.Location(),
|
||||
)
|
||||
report, err := o.GetStatisOfficialProductSum(noon, strings.Split(s, ","))
|
||||
s := "官方--美团外卖红包5元,官方--美团外卖红包10元,官方--饿了么超级会员月卡,官方--网易云黑胶vip月卡,官方--喜马拉雅巅峰会员月卡,官方--芒果-PC季卡,官方--芒果-PC月卡,官方--芒果-PC周卡,官方--腾讯-周卡,官方--优酷周卡,官方--QQ音乐-绿钻月卡,官方--爱奇艺-周卡,官方--腾讯-月卡,官方--腾讯-季卡,官方--腾讯-年卡,官方--优酷月卡,官方--优酷季卡,官方--优酷年卡,官方--爱奇艺-月卡,官方--爱奇艺-季卡,官方--爱奇艺-年卡"
|
||||
report, err := o.GetStatisOfficialProductSum(time.Now(), strings.Split(s, ","))
|
||||
|
||||
t.Log(report, err)
|
||||
|
||||
|
|
|
|||
|
|
@ -343,17 +343,14 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
|||
|
||||
styleD3, err := f.GetCellStyle(sheet, fmt.Sprintf("D%d", tplRowData))
|
||||
if err != nil {
|
||||
styleD3 = 0
|
||||
styleC3 = 0
|
||||
}
|
||||
|
||||
styleE3, err := f.GetCellStyle(sheet, fmt.Sprintf("E%d", tplRowData))
|
||||
if err != nil {
|
||||
styleE3 = 0
|
||||
}
|
||||
styleF3, err := f.GetCellStyle(sheet, fmt.Sprintf("F%d", tplRowData))
|
||||
if err != nil {
|
||||
styleF3 = 0
|
||||
styleC3 = 0
|
||||
}
|
||||
|
||||
rowHeightData, err := f.GetRowHeight(sheet, tplRowData)
|
||||
if err != nil {
|
||||
rowHeightData = 20
|
||||
|
|
@ -375,15 +372,11 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
|||
}
|
||||
styleTotalD, err := f.GetCellStyle(sheet, fmt.Sprintf("D%d", tplRowTotal))
|
||||
if err != nil {
|
||||
styleTotalD = 0
|
||||
styleTotalC = 0
|
||||
}
|
||||
styleTotalE, err := f.GetCellStyle(sheet, fmt.Sprintf("E%d", tplRowTotal))
|
||||
if err != nil {
|
||||
styleTotalE = 0
|
||||
}
|
||||
styleTotalF, err := f.GetCellStyle(sheet, fmt.Sprintf("F%d", tplRowTotal))
|
||||
if err != nil {
|
||||
styleTotalF = 0
|
||||
styleTotalC = 0
|
||||
}
|
||||
rowHeightTotal, err := f.GetRowHeight(sheet, tplRowTotal)
|
||||
if err != nil {
|
||||
|
|
@ -415,9 +408,8 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
|||
f.SetCellValue(sheet, fmt.Sprintf("A%d", currentRow), reseller.ResellerName)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("B%d", currentRow), p.ProductName)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("C%d", currentRow), p.Loss)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("D%d", currentRow), reseller.Total)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("E%d", currentRow), reseller.Manager)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("F%d", currentRow), p.LossReason)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("D%d", currentRow), reseller.Manager)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("E%d", currentRow), p.LossReason)
|
||||
// 设置样式
|
||||
if styleA3 != 0 {
|
||||
f.SetCellStyle(sheet, fmt.Sprintf("A%d", currentRow), fmt.Sprintf("A%d", currentRow), styleA3)
|
||||
|
|
@ -434,9 +426,7 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
|||
if styleE3 != 0 {
|
||||
f.SetCellStyle(sheet, fmt.Sprintf("E%d", currentRow), fmt.Sprintf("E%d", currentRow), styleE3)
|
||||
}
|
||||
if styleF3 != 0 {
|
||||
f.SetCellStyle(sheet, fmt.Sprintf("F%d", currentRow), fmt.Sprintf("F%d", currentRow), styleF3)
|
||||
}
|
||||
|
||||
totalLoss += p.Loss
|
||||
currentRow++
|
||||
}
|
||||
|
|
@ -446,7 +436,6 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
|||
if endRow > startRow {
|
||||
f.MergeCell(sheet, fmt.Sprintf("A%d", startRow), fmt.Sprintf("A%d", endRow))
|
||||
f.MergeCell(sheet, fmt.Sprintf("D%d", startRow), fmt.Sprintf("D%d", endRow))
|
||||
f.MergeCell(sheet, fmt.Sprintf("E%d", startRow), fmt.Sprintf("E%d", endRow))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +447,7 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
|||
|
||||
f.SetCellValue(sheet, fmt.Sprintf("A%d", currentRow), "合计")
|
||||
// B列留空,C列填充总亏损
|
||||
f.SetCellValue(sheet, fmt.Sprintf("D%d", currentRow), totalLoss)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("C%d", currentRow), totalLoss)
|
||||
|
||||
// 设置合计行样式
|
||||
if styleTotalA != 0 {
|
||||
|
|
@ -476,9 +465,7 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
|||
if styleTotalE != 0 {
|
||||
f.SetCellStyle(sheet, fmt.Sprintf("E%d", currentRow), fmt.Sprintf("E%d", currentRow), styleTotalE)
|
||||
}
|
||||
if styleTotalF != 0 {
|
||||
f.SetCellStyle(sheet, fmt.Sprintf("F%d", currentRow), fmt.Sprintf("F%d", currentRow), styleTotalF)
|
||||
}
|
||||
|
||||
// 取消合并合计行的A、B列
|
||||
// f.MergeCell(sheet, fmt.Sprintf("A%d", currentRow), fmt.Sprintf("B%d", currentRow))
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue