feat: 优化报表功能与商品配置
This commit is contained in:
parent
5d120a6c05
commit
86713dbb1a
|
|
@ -17,6 +17,7 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"ai_scheduler/internal/config"
|
||||
"context"
|
||||
|
|
@ -142,10 +143,14 @@ func (d *DingTalkBotBiz) handleSingleChat(ctx context.Context, requireData *enti
|
|||
|
||||
func (d *DingTalkBotBiz) handleGroupChat(ctx context.Context, requireData *entitys.RequireDataDingTalkBot) (err error) {
|
||||
group, err := d.initGroup(ctx, requireData.Req.ConversationId, requireData.Req.ConversationTitle, requireData.Req.RobotCode)
|
||||
|
||||
//宏
|
||||
err, isFinal := d.Macro(ctx, requireData, group)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if isFinal {
|
||||
return
|
||||
}
|
||||
requireData.ID = group.GroupID
|
||||
groupTools, err := d.getGroupTools(ctx, group)
|
||||
if err != nil {
|
||||
|
|
@ -159,6 +164,59 @@ func (d *DingTalkBotBiz) handleGroupChat(ctx context.Context, requireData *entit
|
|||
return d.handleMatch(ctx, rec)
|
||||
}
|
||||
|
||||
func (d *DingTalkBotBiz) Macro(ctx context.Context, requireData *entitys.RequireDataDingTalkBot, group *model.AiBotGroup) (err error, isFinish bool) {
|
||||
content := processString(requireData.Req.Text.Content)
|
||||
|
||||
if strings.Contains(content, "[利润同比报表]商品修改:") {
|
||||
// 提取冒号后的内容
|
||||
if parts := strings.SplitN(content, ":", 2); len(parts) == 2 {
|
||||
itemInfo := strings.TrimSpace(parts[1])
|
||||
log.Infof("商品修改信息: %s", itemInfo)
|
||||
group.ProductName = itemInfo
|
||||
cond := builder.NewCond()
|
||||
cond = cond.And(builder.Eq{"group_id": group.GroupID})
|
||||
err = d.botGroupImpl.UpdateByCond(&cond, group)
|
||||
if err != nil {
|
||||
entitys.ResText(requireData.Ch, "", fmt.Sprintf("修改失败:%v", err))
|
||||
}
|
||||
entitys.ResText(requireData.Ch, "", "修改成功")
|
||||
isFinish = true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(content, "[利润同比报表]商品列表") {
|
||||
// 提取冒号后的内容
|
||||
if len(group.ProductName) == 0 {
|
||||
entitys.ResText(requireData.Ch, "", "暂未设置")
|
||||
} else {
|
||||
entitys.ResText(requireData.Ch, "", group.ProductName)
|
||||
isFinish = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func processString(s string) string {
|
||||
// 1. 替换中文逗号为英文逗号
|
||||
s = strings.ReplaceAll(s, ",", ",")
|
||||
|
||||
// 2. 过滤控制字符(如 \n, \t, \r 等)
|
||||
var result []rune
|
||||
for _, char := range s {
|
||||
// 判断是否是控制字符(ASCII < 32 或 = 127)
|
||||
if !unicode.IsControl(char) {
|
||||
// 如果需要完全移除 \n 和 \t,可以改成:
|
||||
// if !unicode.IsControl(char)
|
||||
result = append(result, char)
|
||||
}
|
||||
}
|
||||
|
||||
return string(result)
|
||||
}
|
||||
|
||||
func (d *DingTalkBotBiz) initGroup(ctx context.Context, conversationId string, conversationTitle string, robotCode string) (group *model.AiBotGroup, err error) {
|
||||
group, err = d.botGroupImpl.GetByConversationIdAndRobotCode(conversationId, robotCode)
|
||||
if err != nil {
|
||||
|
|
@ -478,13 +536,18 @@ func (d *DingTalkBotBiz) HandleStreamRes(ctx context.Context, data *chatbot.BotC
|
|||
return
|
||||
}
|
||||
|
||||
func (d *DingTalkBotBiz) GetReportLists(ctx context.Context) (reports []*bbxt.ReportRes, err error) {
|
||||
func (d *DingTalkBotBiz) GetReportLists(ctx context.Context, group *model.AiBotGroup) (reports []*bbxt.ReportRes, err error) {
|
||||
|
||||
reportList, err := bbxt.NewBbxtTools()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
reports, err = reportList.DailyReport(time.Now(), []string{"官方-爱奇艺-星钻季卡", "官方-爱奇艺-星钻半年卡", "官方--腾讯-年卡", "官方--爱奇艺-月卡"}, d.ossClient)
|
||||
var product []string
|
||||
if group.ProductName != "" {
|
||||
product = strings.Split(group.ProductName, ",")
|
||||
}
|
||||
//[]string{"官方-爱奇艺-星钻季卡", "官方-爱奇艺-星钻半年卡", "官方--腾讯-年卡", "官方--爱奇艺-月卡"}
|
||||
reports, err = reportList.DailyReport(time.Now(), product, d.ossClient)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -582,7 +645,7 @@ func (d *DingTalkBotBiz) SaveHis(ctx context.Context, requireData *entitys.Requi
|
|||
}
|
||||
|
||||
func (d *DingTalkBotBiz) defaultPrompt() string {
|
||||
|
||||
now := time.Now().Format(time.DateTime)
|
||||
return `[system] 你是一个智能路由系统,核心职责是 **精准解析用户意图并路由至对应任务模块**。请严格遵循以下规则:
|
||||
[rule]
|
||||
1. **返回格式**:
|
||||
|
|
@ -605,5 +668,6 @@ func (d *DingTalkBotBiz) defaultPrompt() string {
|
|||
|
||||
4. 格式强制要求:
|
||||
-所有字段值必须是**字符串**(包括 confidence)。
|
||||
-parameters 必须是 **转义后的 JSON 字符串**(如 "{\"product_name\": \"京东月卡\"}")。`
|
||||
-parameters 必须是 **转义后的 JSON 字符串**(如 "{\"product_name\": \"京东月卡\"}")。
|
||||
当前时间:` + now
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,14 +12,15 @@ const TableNameAiBotGroup = "ai_bot_group"
|
|||
|
||||
// AiBotGroup mapped from table <ai_bot_group>
|
||||
type AiBotGroup struct {
|
||||
GroupID int32 `gorm:"column:group_id;primaryKey;autoIncrement:true" json:"group_id"`
|
||||
ConversationID string `gorm:"column:conversation_id;not null;comment:会话ID" json:"conversation_id"` // 会话ID
|
||||
RobotCode string `gorm:"column:robot_code;not null;comment:绑定机器人code" json:"robot_code"` // 绑定机器人code
|
||||
Title string `gorm:"column:title;not null;comment:群名称" json:"title"` // 群名称
|
||||
ToolList string `gorm:"column:tool_list;not null;comment:开通工具列表" json:"tool_list"` // 开通工具列表
|
||||
Status int32 `gorm:"column:status;not null;default:1" json:"status"`
|
||||
DeleteAt *time.Time `gorm:"column:delete_at" json:"delete_at"`
|
||||
CreateAt time.Time `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"`
|
||||
GroupID int32 `gorm:"column:group_id;primaryKey;autoIncrement:true" json:"group_id"`
|
||||
ConversationID string `gorm:"column:conversation_id;not null;comment:会话ID" json:"conversation_id"` // 会话ID
|
||||
RobotCode string `gorm:"column:robot_code;not null;comment:绑定机器人code" json:"robot_code"` // 绑定机器人code
|
||||
Title string `gorm:"column:title;not null;comment:群名称" json:"title"` // 群名称
|
||||
ToolList string `gorm:"column:tool_list;not null;comment:开通工具列表" json:"tool_list"` // 开通工具列表
|
||||
ProductName string `gorm:"column:product_name;not null;comment:针对报表商品筛选快速实现,后期优化" json:"product_name"` // 针对报表商品筛选快速实现,后期优化
|
||||
Status int32 `gorm:"column:status;not null;default:1" json:"status"`
|
||||
DeleteAt time.Time `gorm:"column:delete_at" json:"delete_at"`
|
||||
CreateAt time.Time `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"`
|
||||
}
|
||||
|
||||
// TableName AiBotGroup's table name
|
||||
|
|
|
|||
|
|
@ -13,16 +13,16 @@ const TableNameAiBotTool = "ai_bot_tools"
|
|||
// AiBotTool mapped from table <ai_bot_tools>
|
||||
type AiBotTool struct {
|
||||
ToolID int32 `gorm:"column:tool_id;primaryKey;autoIncrement:true" json:"tool_id"`
|
||||
PermissionType int32 `gorm:"column:permission_type;not null;comment:类型,1为公共工具,不需要进行权限管理,反之则为2" json:"permission_type"` // 类型,1为公共工具,不需要进行权限管理,反之则为2
|
||||
Config string `gorm:"column:config;not null;comment:类型下所需路由以及参数" json:"config"` // 类型下所需路由以及参数
|
||||
PermissionType int32 `gorm:"column:permission_type;not null;default:1;comment:类型,1为公共工具,不需要进行权限管理,反之则为2" json:"permission_type"` // 类型,1为公共工具,不需要进行权限管理,反之则为2
|
||||
Config string `gorm:"column:config;comment:类型下所需路由以及参数" json:"config"` // 类型下所需路由以及参数
|
||||
Type int32 `gorm:"column:type;not null;default:3" json:"type"`
|
||||
Name string `gorm:"column:name;not null;default:1;comment:工具名称" json:"name"` // 工具名称
|
||||
Name string `gorm:"column:name;not null;comment:工具名称" json:"name"` // 工具名称
|
||||
Index string `gorm:"column:index;not null;comment:索引" json:"index"` // 索引
|
||||
Desc string `gorm:"column:desc;not null;comment:工具描述" json:"desc"` // 工具描述
|
||||
TempPrompt string `gorm:"column:temp_prompt;not null;comment:提示词模板" json:"temp_prompt"` // 提示词模板
|
||||
CreateAt time.Time `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
Status int32 `gorm:"column:status;not null" json:"status"`
|
||||
Status int32 `gorm:"column:status;not null;default:1" json:"status"`
|
||||
DeleteAt time.Time `gorm:"column:delete_at" json:"delete_at"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,12 +21,13 @@ func NewCronService(config *config.Config, dingTalkBotBiz *biz.DingTalkBotBiz) *
|
|||
}
|
||||
|
||||
func (d *CronService) CronReportSend(ctx context.Context) error {
|
||||
reports, err := d.dingTalkBotBiz.GetReportLists(ctx)
|
||||
|
||||
groupId := 28
|
||||
groupInfo, err := d.dingTalkBotBiz.GetGroupInfo(ctx, groupId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupId := 28
|
||||
groupInfo, err := d.dingTalkBotBiz.GetGroupInfo(ctx, groupId)
|
||||
reports, err := d.dingTalkBotBiz.GetReportLists(ctx, &groupInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,3 +189,9 @@ func (k DataTemp) UpdateByCond(cond *builder.Cond, data interface{}) (err error)
|
|||
err = model.Where(query).Updates(data).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (k DataTemp) UpdateById(id int32, data interface{}) (err error) {
|
||||
err = k.Db.Model(k.Model).Where("id = ?", id).Updates(data).Error
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue