Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
dj
/
rpc-mindworkplate
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f84c10c3
authored
Jun 24, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:新增跑历史录音ai标签定时任务
1 parent
ee25e4f9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
273 additions
and
8 deletions
rpc-dj-mindworkplate/src/main/java/cn/com/glsx/dj/mindworkplate/job/HistoricalCustomerTagJob.java
rpc-dj-mindworkplate/src/main/java/cn/com/glsx/dj/mindworkplate/mapper/InspectionCustomerTagMapper.java
rpc-dj-mindworkplate/src/main/java/cn/com/glsx/dj/mindworkplate/service/ConversationDateService.java
rpc-dj-mindworkplate/src/main/java/cn/com/glsx/dj/mindworkplate/service/InspectionCustomerTagService.java
rpc-dj-mindworkplate/src/main/resources/META-INF/orm/InspectionCustomerTagMapper.xml
rpc-dj-mindworkplate/src/test/java/cn/com/glsx/dj/mindworkplate/service/HistoricalCustomerTagServiceTest.java
rpc-dj-mindworkplate/src/main/java/cn/com/glsx/dj/mindworkplate/job/HistoricalCustomerTagJob.java
0 → 100644
View file @
f84c10c
package
cn
.
com
.
glsx
.
dj
.
mindworkplate
.
job
;
import
cn.com.glsx.dj.mindworkplate.service.InspectionCustomerTagService
;
import
com.dangdang.ddframe.job.api.ShardingContext
;
import
com.dangdang.ddframe.job.api.simple.SimpleJob
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.env.Environment
;
/**
* 历史客户标签分析定时任务
* 用于批量处理历史数据的客户标签分析
*/
@Slf4j
@ElasticJobConf
(
name
=
"HistoricalCustomerTagJob"
,
cron
=
"0 0 2 * * ?"
,
description
=
"历史客户标签分析任务"
,
overwrite
=
false
)
public
class
HistoricalCustomerTagJob
implements
SimpleJob
{
@Autowired
private
Environment
environment
;
@Autowired
private
InspectionCustomerTagService
inspectionCustomerTagService
;
@Override
public
void
execute
(
ShardingContext
shardingContext
)
{
log
.
info
(
"----------历史客户标签分析任务开始----------"
);
// 读取配置参数
String
enabled
=
environment
.
getProperty
(
"historical.customer.tag.job.enabled"
);
String
startTime
=
environment
.
getProperty
(
"historical.customer.tag.job.startTime"
);
String
endTime
=
environment
.
getProperty
(
"historical.customer.tag.job.endTime"
);
// 检查是否启用
if
(!
"true"
.
equalsIgnoreCase
(
enabled
))
{
log
.
info
(
"历史客户标签分析任务未启用,跳过执行。配置项:historical.customer.tag.job.enabled={}"
,
enabled
);
return
;
}
// 检查时间范围参数
if
(
StringUtils
.
isEmpty
(
startTime
)
||
StringUtils
.
isEmpty
(
endTime
))
{
log
.
warn
(
"历史客户标签分析任务配置不完整,startTime={}, endTime={},跳过执行"
,
startTime
,
endTime
);
return
;
}
log
.
info
(
"历史客户标签分析任务配置:startTime={}, endTime={}"
,
startTime
,
endTime
);
try
{
int
processedCount
=
inspectionCustomerTagService
.
processHistoricalTags
(
startTime
,
endTime
);
log
.
info
(
"----------历史客户标签分析任务结束,处理批次数量:{}----------"
,
processedCount
);
}
catch
(
Exception
e
)
{
log
.
error
(
"历史客户标签分析任务执行异常"
,
e
);
}
}
}
rpc-dj-mindworkplate/src/main/java/cn/com/glsx/dj/mindworkplate/mapper/InspectionCustomerTagMapper.java
View file @
f84c10c
...
@@ -2,6 +2,7 @@ package cn.com.glsx.dj.mindworkplate.mapper;
...
@@ -2,6 +2,7 @@ package cn.com.glsx.dj.mindworkplate.mapper;
import
cn.com.glsx.dj.mindworkplate.dto.InspectionCustomerTagDTO
;
import
cn.com.glsx.dj.mindworkplate.dto.InspectionCustomerTagDTO
;
import
cn.com.glsx.dj.mindworkplate.dto.InspectionCustomerTagPageRequestDTO
;
import
cn.com.glsx.dj.mindworkplate.dto.InspectionCustomerTagPageRequestDTO
;
import
cn.com.glsx.dj.mindworkplate.model.ConversationBatch
;
import
cn.com.glsx.dj.mindworkplate.model.InspectionCustomerTag
;
import
cn.com.glsx.dj.mindworkplate.model.InspectionCustomerTag
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
...
@@ -47,4 +48,14 @@ public interface InspectionCustomerTagMapper extends OreMapper<InspectionCustome
...
@@ -47,4 +48,14 @@ public interface InspectionCustomerTagMapper extends OreMapper<InspectionCustome
*/
*/
List
<
InspectionCustomerTagDTO
>
selectByPhoneNumbers
(
@Param
(
"phoneNumbers"
)
List
<
String
>
phoneNumbers
,
List
<
InspectionCustomerTagDTO
>
selectByPhoneNumbers
(
@Param
(
"phoneNumbers"
)
List
<
String
>
phoneNumbers
,
@Param
(
"resultFlag"
)
Integer
resultFlag
);
@Param
(
"resultFlag"
)
Integer
resultFlag
);
/**
* 查询指定时间范围内未处理的批次(未在inspection_customer_tag表中存在记录)
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 未处理的批次列表
*/
List
<
ConversationBatch
>
findUnprocessedBatchesByTimeRange
(
@Param
(
"startTime"
)
String
startTime
,
@Param
(
"endTime"
)
String
endTime
);
}
}
rpc-dj-mindworkplate/src/main/java/cn/com/glsx/dj/mindworkplate/service/ConversationDateService.java
View file @
f84c10c
...
@@ -438,13 +438,11 @@ public class ConversationDateService {
...
@@ -438,13 +438,11 @@ public class ConversationDateService {
log
.
warn
(
"第{}个批次的对话内容长度为0,conversationId={},batchId={}"
,
num
,
conversationBatch
.
getConversationId
(),
conversationBatch
.
getId
());
log
.
warn
(
"第{}个批次的对话内容长度为0,conversationId={},batchId={}"
,
num
,
conversationBatch
.
getConversationId
(),
conversationBatch
.
getId
());
return
;
return
;
}
}
// 新增:提交客户标签分析(仅轻改业务 checkType=2)
// 新增:提交客户标签分析
if
(
conversationBatch
.
getCheckType
()
!=
null
&&
conversationBatch
.
getCheckType
()
==
2
)
{
try
{
try
{
inspectionCustomerTagService
.
submitCustomerTagAnalysis
(
conversationBatch
,
sb
.
toString
());
inspectionCustomerTagService
.
submitCustomerTagAnalysis
(
conversationBatch
,
sb
.
toString
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"提交客户标签分析任务异常,batchId={}"
,
conversationBatch
.
getId
(),
e
);
log
.
error
(
"提交客户标签分析任务异常,batchId={}"
,
conversationBatch
.
getId
(),
e
);
}
}
}
//调用大模型接口获取质检结果信息
//调用大模型接口获取质检结果信息
log
.
info
(
"请求参数:{}"
,
sb
);
log
.
info
(
"请求参数:{}"
,
sb
);
...
...
rpc-dj-mindworkplate/src/main/java/cn/com/glsx/dj/mindworkplate/service/InspectionCustomerTagService.java
View file @
f84c10c
...
@@ -2,11 +2,12 @@ package cn.com.glsx.dj.mindworkplate.service;
...
@@ -2,11 +2,12 @@ package cn.com.glsx.dj.mindworkplate.service;
import
cn.com.glsx.dj.mindworkplate.client.CustomerTagApiClient
;
import
cn.com.glsx.dj.mindworkplate.client.CustomerTagApiClient
;
import
cn.com.glsx.dj.mindworkplate.client.CustomerTagResult
;
import
cn.com.glsx.dj.mindworkplate.client.CustomerTagResult
;
import
cn.com.glsx.dj.mindworkplate.dto.InspectionCustomerTagDTO
;
import
cn.com.glsx.dj.mindworkplate.dto.InspectionCustomerTagByPhonesRequestDTO
;
import
cn.com.glsx.dj.mindworkplate.dto.InspectionCustomerTagByPhonesRequestDTO
;
import
cn.com.glsx.dj.mindworkplate.dto.InspectionCustomerTagDTO
;
import
cn.com.glsx.dj.mindworkplate.dto.InspectionCustomerTagPageRequestDTO
;
import
cn.com.glsx.dj.mindworkplate.dto.InspectionCustomerTagPageRequestDTO
;
import
cn.com.glsx.dj.mindworkplate.mapper.InspectionCustomerTagMapper
;
import
cn.com.glsx.dj.mindworkplate.mapper.InspectionCustomerTagMapper
;
import
cn.com.glsx.dj.mindworkplate.model.ConversationBatch
;
import
cn.com.glsx.dj.mindworkplate.model.ConversationBatch
;
import
cn.com.glsx.dj.mindworkplate.model.ConversationDetail
;
import
cn.com.glsx.dj.mindworkplate.model.InspectionCustomerTag
;
import
cn.com.glsx.dj.mindworkplate.model.InspectionCustomerTag
;
import
cn.com.glsx.framework.core.beans.rpc.RpcPagination
;
import
cn.com.glsx.framework.core.beans.rpc.RpcPagination
;
import
cn.com.glsx.scrm.equity.enums.DeleteFlagEnum
;
import
cn.com.glsx.scrm.equity.enums.DeleteFlagEnum
;
...
@@ -18,6 +19,7 @@ import org.springframework.stereotype.Service;
...
@@ -18,6 +19,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
...
@@ -35,6 +37,9 @@ public class InspectionCustomerTagService {
...
@@ -35,6 +37,9 @@ public class InspectionCustomerTagService {
@Autowired
@Autowired
private
CustomerTagApiClient
customerTagApiClient
;
private
CustomerTagApiClient
customerTagApiClient
;
@Autowired
private
InspectionConversationDetailExtService
inspectionConversationDetailExtService
;
/**
/**
* 提交客户标签分析任务
* 提交客户标签分析任务
*
*
...
@@ -162,4 +167,81 @@ public class InspectionCustomerTagService {
...
@@ -162,4 +167,81 @@ public class InspectionCustomerTagService {
log
.
info
(
"查询完成,结果数量={}"
,
list
.
size
());
log
.
info
(
"查询完成,结果数量={}"
,
list
.
size
());
return
list
;
return
list
;
}
}
/**
* 处理历史客户标签分析
* 查询指定时间范围内未处理的批次,并提交客户标签分析任务
*
* @param startTime 开始时间(格式:yyyy-MM-dd HH:mm:ss)
* @param endTime 结束时间(格式:yyyy-MM-dd HH:mm:ss)
* @return 处理的批次数量
*/
public
int
processHistoricalTags
(
String
startTime
,
String
endTime
)
{
log
.
info
(
"开始处理历史客户标签分析,时间范围:{} ~ {}"
,
startTime
,
endTime
);
// 查询未处理的批次
List
<
ConversationBatch
>
unprocessedBatches
=
inspectionCustomerTagMapper
.
findUnprocessedBatchesByTimeRange
(
startTime
,
endTime
);
if
(
CollectionUtils
.
isEmpty
(
unprocessedBatches
))
{
log
.
info
(
"未找到需要处理的批次"
);
return
0
;
}
log
.
info
(
"找到 {} 个未处理的批次"
,
unprocessedBatches
.
size
());
int
successCount
=
0
;
int
failCount
=
0
;
for
(
ConversationBatch
batch
:
unprocessedBatches
)
{
try
{
// 获取录音文本内容
String
recordingText
=
getRecordingText
(
batch
);
if
(
recordingText
==
null
||
recordingText
.
isEmpty
())
{
log
.
warn
(
"批次 {} 的录音文本内容为空,跳过"
,
batch
.
getId
());
continue
;
}
// 提交客户标签分析任务
submitCustomerTagAnalysis
(
batch
,
recordingText
);
successCount
++;
log
.
info
(
"批次 {} 处理成功"
,
batch
.
getId
());
}
catch
(
Exception
e
)
{
failCount
++;
log
.
error
(
"处理批次 {} 失败"
,
batch
.
getId
(),
e
);
// 继续处理下一个批次
}
}
log
.
info
(
"历史客户标签分析处理完成,成功:{},失败:{}"
,
successCount
,
failCount
);
return
successCount
;
}
/**
* 获取批次的录音文本内容
*
* @param batch 批次信息
* @return 录音文本内容
*/
private
String
getRecordingText
(
ConversationBatch
batch
)
{
List
<
ConversationDetail
>
conversationDetails
=
inspectionConversationDetailExtService
.
listByBatchId
(
Arrays
.
asList
(
batch
.
getId
()));
if
(
CollectionUtils
.
isEmpty
(
conversationDetails
))
{
return
null
;
}
StringBuilder
sb
=
new
StringBuilder
();
for
(
ConversationDetail
detail
:
conversationDetails
)
{
Long
offset
=
detail
.
getMergedOffset
();
String
offsetStr
=
offset
!=
null
?
formatSeconds
(
offset
)
:
"00:00:00"
;
sb
.
append
(
String
.
format
(
"%s %s:%s\n"
,
offsetStr
,
detail
.
getRole
(),
detail
.
getContent
()));
}
return
sb
.
toString
();
}
/**
* 格式化秒数为 HH:mm:ss 格式
*/
private
String
formatSeconds
(
long
seconds
)
{
long
hours
=
seconds
/
3600
;
long
minutes
=
(
seconds
%
3600
)
/
60
;
long
secs
=
seconds
%
60
;
return
String
.
format
(
"%02d:%02d:%02d"
,
hours
,
minutes
,
secs
);
}
}
}
rpc-dj-mindworkplate/src/main/resources/META-INF/orm/InspectionCustomerTagMapper.xml
View file @
f84c10c
...
@@ -127,4 +127,63 @@
...
@@ -127,4 +127,63 @@
ORDER BY t.created_date DESC
ORDER BY t.created_date DESC
</select>
</select>
<!-- ConversationBatch ResultMap for historical tag job -->
<resultMap
id=
"ConversationBatchResultMap"
type=
"cn.com.glsx.dj.mindworkplate.model.ConversationBatch"
>
<id
column=
"id"
property=
"id"
jdbcType=
"INTEGER"
/>
<result
column=
"conversation_id"
property=
"conversationId"
jdbcType=
"INTEGER"
/>
<result
column=
"task_id"
property=
"taskId"
jdbcType=
"INTEGER"
/>
<result
column=
"num"
property=
"num"
jdbcType=
"INTEGER"
/>
<result
column=
"start_time"
property=
"startTime"
jdbcType=
"VARCHAR"
/>
<result
column=
"end_time"
property=
"endTime"
jdbcType=
"VARCHAR"
/>
<result
column=
"duration"
property=
"duration"
jdbcType=
"VARCHAR"
/>
<result
column=
"file_url"
property=
"fileUrl"
jdbcType=
"VARCHAR"
/>
<result
column=
"estimated_result"
property=
"estimatedResult"
jdbcType=
"VARCHAR"
/>
<result
column=
"score"
property=
"score"
jdbcType=
"DECIMAL"
/>
<result
column=
"digest"
property=
"digest"
jdbcType=
"VARCHAR"
/>
<result
column=
"quality_inspection"
property=
"qualityInspection"
jdbcType=
"VARCHAR"
/>
<result
column=
"created_by"
property=
"createdBy"
jdbcType=
"VARCHAR"
/>
<result
column=
"created_date"
property=
"createdDate"
jdbcType=
"TIMESTAMP"
/>
<result
column=
"updated_by"
property=
"updatedBy"
jdbcType=
"VARCHAR"
/>
<result
column=
"updated_date"
property=
"updatedDate"
jdbcType=
"TIMESTAMP"
/>
<result
column=
"deleted_flag"
property=
"deletedFlag"
jdbcType=
"CHAR"
/>
<result
column=
"che_taskId"
property=
"cheTaskId"
jdbcType=
"VARCHAR"
/>
<result
column=
"che_result_flag"
property=
"cheResultFlag"
jdbcType=
"INTEGER"
/>
<result
column=
"che_err_message"
property=
"cheErrMessage"
jdbcType=
"VARCHAR"
/>
<result
column=
"record_id"
property=
"recordId"
jdbcType=
"INTEGER"
/>
</resultMap>
<!-- 查询指定时间范围内未处理的批次 -->
<select
id=
"findUnprocessedBatchesByTimeRange"
resultMap=
"ConversationBatchResultMap"
>
SELECT
cb.id,
cb.conversation_id,
cb.task_id,
cb.num,
cb.start_time,
cb.end_time,
cb.duration,
cb.file_url,
cb.estimated_result,
cb.score,
cb.digest,
cb.quality_inspection,
cb.created_by,
cb.created_date,
cb.updated_by,
cb.updated_date,
cb.deleted_flag,
cb.che_taskId,
cb.che_result_flag,
cb.che_err_message,
cb.record_id
FROM inspection_conversation_batch cb
INNER JOIN inspection_conversation_date cd ON cb.conversation_id = cd.id
LEFT JOIN inspection_customer_tag ict ON cb.id = ict.batch_id
WHERE cd.created_date BETWEEN #{startTime} AND #{endTime}
AND ict.id IS NULL
AND cd.deleted_flag = 'N'
AND cb.record_id IS NOT NULL
ORDER BY cd.created_date ASC
</select>
</mapper>
</mapper>
rpc-dj-mindworkplate/src/test/java/cn/com/glsx/dj/mindworkplate/service/HistoricalCustomerTagServiceTest.java
0 → 100644
View file @
f84c10c
package
cn
.
com
.
glsx
.
dj
.
mindworkplate
.
service
;
import
cn.com.glsx.dj.mindworkplate.Main
;
import
cn.com.glsx.dj.mindworkplate.mapper.InspectionCustomerTagMapper
;
import
cn.com.glsx.dj.mindworkplate.model.ConversationBatch
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
/**
* 历史客户标签分析服务测试
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
Main
.
class
)
public
class
HistoricalCustomerTagServiceTest
extends
BaseServiceTest
{
@Autowired
private
InspectionCustomerTagMapper
inspectionCustomerTagMapper
;
@Autowired
private
InspectionCustomerTagService
inspectionCustomerTagService
;
/**
* 测试查询未处理的批次
*/
@Test
public
void
testFindUnprocessedBatchesByTimeRange
()
{
String
startTime
=
"2024-01-01 00:00:00"
;
String
endTime
=
"2026-07-01 00:00:00"
;
List
<
ConversationBatch
>
batches
=
inspectionCustomerTagMapper
.
findUnprocessedBatchesByTimeRange
(
startTime
,
endTime
);
assertNotNull
(
"查询结果不应为null"
,
batches
);
System
.
out
.
println
(
"查询到未处理批次数量: "
+
batches
.
size
());
if
(!
batches
.
isEmpty
())
{
ConversationBatch
first
=
batches
.
get
(
0
);
System
.
out
.
println
(
"第一个批次ID: "
+
first
.
getId
()
+
", recordId: "
+
first
.
getRecordId
());
}
}
/**
* 测试处理历史标签分析
*/
@Test
public
void
testProcessHistoricalTags
()
{
String
startTime
=
"2024-01-01 00:00:00"
;
String
endTime
=
"2026-07-01 00:00:00"
;
int
count
=
inspectionCustomerTagService
.
processHistoricalTags
(
startTime
,
endTime
);
System
.
out
.
println
(
"处理完成的批次数量: "
+
count
);
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment