Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
dj
/
rpc-dj-strategy
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit fa1031f0
authored
Jul 06, 2026
by
叶立庆
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'v5.8.3' into 'master'
上线合并 See merge request
!6
2 parents
32ffa29a
98236597
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
147 additions
and
5 deletions
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/consts/CommonConstants.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/job/CustomerClassRefreshJob.java
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/service/CustomerTagProfileService.java
rpc-dj-strategy-api/src/main/java/cn/com/glsx/dj/strategy/consts/CommonConstants.java
View file @
fa1031f
...
...
@@ -17,5 +17,11 @@ public class CommonConstants {
*/
public
static
final
String
TAG_CATEGORY_PRODUCT
=
"INIT_C3"
;
/** 批量查询每批大小 */
public
static
final
int
BATCH_SIZE
=
200
;
/** 客户分类: A / B / C */
public
static
final
String
CLASS_A
=
"A"
;
public
static
final
String
CLASS_B
=
"B"
;
public
static
final
String
CLASS_C
=
"C"
;
}
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/job/CustomerClassRefreshJob.java
0 → 100644
View file @
fa1031f
package
cn
.
com
.
glsx
.
dj
.
strategy
.
job
;
import
cn.com.glsx.dj.strategy.service.CustomerTagProfileService
;
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
java.time.LocalDate
;
import
java.time.format.DateTimeFormatter
;
/**
* 客户分类刷新任务
* <p>
* 每天凌晨5点执行, 查询指定日期有标签变动的客户, 重新计算客户分类(A/B/C)并更新到 customer_info 表。
* <br>
* 支持传参: 传入日期 yyyy-MM-dd 查询该日期的变动数据, 不传则默认昨天。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/07/03
*/
@Slf4j
@ElasticJobConf
(
name
=
"CustomerClassRefreshJob"
,
cron
=
"0 0 5 * * ?"
,
description
=
"客户分类刷新任务"
,
overwrite
=
false
)
public
class
CustomerClassRefreshJob
implements
SimpleJob
{
@Autowired
private
CustomerTagProfileService
customerTagProfileService
;
private
static
final
DateTimeFormatter
FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
@Override
public
void
execute
(
ShardingContext
shardingContext
)
{
String
date
=
resolveDate
(
shardingContext
.
getJobParameter
());
log
.
info
(
"----------------客户分类刷新任务开始, date={}-----------------"
,
date
);
try
{
customerTagProfileService
.
refreshCustomerClass
(
date
);
}
catch
(
Exception
e
)
{
log
.
error
(
"客户分类刷新任务异常, date={}"
,
date
,
e
);
}
log
.
info
(
"----------------客户分类刷新任务结束, date={}-----------------"
,
date
);
}
/**
* 解析日期参数: 有传参则使用, 否则默认昨天
*/
private
String
resolveDate
(
String
jobParameter
)
{
if
(
StringUtils
.
isNotBlank
(
jobParameter
))
{
return
jobParameter
.
trim
();
}
return
LocalDate
.
now
().
minusDays
(
1
).
format
(
FORMATTER
);
}
}
rpc-dj-strategy/src/main/java/cn/com/glsx/dj/strategy/service/CustomerTagProfileService.java
View file @
fa1031f
package
cn
.
com
.
glsx
.
dj
.
strategy
.
service
;
import
cn.com.glsx.dj.smartcarlife.dto.CustomerInfoDTO
;
import
cn.com.glsx.dj.smartcarlife.dto.CustomerSimpleInfoDTO
;
import
cn.com.glsx.dj.smartcarlife.remote.CustomerInfoRemote
;
import
cn.com.glsx.dj.strategy.consts.CommonConstants
;
import
cn.com.glsx.dj.strategy.dto.CarSeriesDetailDTO
;
import
cn.com.glsx.dj.strategy.dto.CustomerProfileRespDTO
;
import
cn.com.glsx.dj.strategy.enums.CustomerTagEnum
;
...
...
@@ -21,10 +23,8 @@ import org.springframework.util.CollectionUtils;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* 客户标签画像服务
...
...
@@ -174,7 +174,7 @@ public class CustomerTagProfileService {
}
/**
* 查询
昨天
有变动的标签画像(含名称,合并查询)
* 查询
指定日期
有变动的标签画像(含名称,合并查询)
*/
public
List
<
CustomerProfileRespDTO
>
queryYesterdayChangedProfiles
(
String
date
)
{
List
<
String
>
phoneList
=
customerTagProfileMapper
.
selectYesterdayChangedPhones
(
date
);
...
...
@@ -184,6 +184,87 @@ public class CustomerTagProfileService {
return
customerTagProfileMapper
.
selectByPhoneList
(
phoneList
);
}
/**
* 刷新客户分类 (定时任务调用)
* <p>
* 1. 查询指定日期变动手机号 → 分批查询画像 → 计算分类 → 批量更新
*/
public
void
refreshCustomerClass
(
String
date
)
{
log
.
info
(
"刷新客户分类开始, date={}"
,
date
);
// 1. 查询变动手机号
List
<
String
>
phoneList
=
customerTagProfileMapper
.
selectYesterdayChangedPhones
(
date
);
if
(
CollectionUtils
.
isEmpty
(
phoneList
))
{
log
.
info
(
"{} 无标签变动, 跳过刷新"
,
date
);
return
;
}
log
.
info
(
"{} 有标签变动的手机号数量: {}"
,
date
,
phoneList
.
size
());
// 2. 分批查询画像 + 计算分类 + 更新
int
totalBatches
=
(
phoneList
.
size
()
+
CommonConstants
.
BATCH_SIZE
-
1
)
/
CommonConstants
.
BATCH_SIZE
;
for
(
int
i
=
0
;
i
<
phoneList
.
size
();
i
+=
CommonConstants
.
BATCH_SIZE
)
{
int
end
=
Math
.
min
(
i
+
CommonConstants
.
BATCH_SIZE
,
phoneList
.
size
());
List
<
String
>
batchPhones
=
phoneList
.
subList
(
i
,
end
);
int
batchNo
=
i
/
CommonConstants
.
BATCH_SIZE
+
1
;
// 查询画像
List
<
CustomerProfileRespDTO
>
batchProfiles
=
customerTagProfileMapper
.
selectByPhoneList
(
batchPhones
);
Map
<
String
,
List
<
CustomerProfileRespDTO
>>
phoneGroup
=
batchProfiles
.
stream
()
.
collect
(
java
.
util
.
stream
.
Collectors
.
groupingBy
(
CustomerProfileRespDTO:
:
getPhone
));
// 计算分类
List
<
CustomerInfoDTO
>
updateList
=
new
ArrayList
<>();
for
(
String
phone
:
batchPhones
)
{
List
<
CustomerProfileRespDTO
>
profiles
=
phoneGroup
.
getOrDefault
(
phone
,
java
.
util
.
Collections
.
emptyList
());
CustomerInfoDTO
infoDTO
=
new
CustomerInfoDTO
();
infoDTO
.
setCustomerPhone
(
phone
);
infoDTO
.
setCustomerClass
(
calcCustomerClass
(
profiles
));
updateList
.
add
(
infoDTO
);
}
// 一次RPC批量更新
try
{
customerInfoRemote
.
batchUpdateCustomerClass
(
updateList
);
}
catch
(
Exception
e
)
{
log
.
error
(
"批量更新客户分类失败, batch={}, size={}"
,
batchNo
,
batchPhones
.
size
(),
e
);
}
log
.
info
(
"批次 {}/{} 完成, size={}"
,
batchNo
,
totalBatches
,
batchPhones
.
size
());
}
log
.
info
(
"刷新客户分类完成, total={}"
,
phoneList
.
size
());
}
/**
* 计算客户分类 (A/B/C)
*
* @param profileList 该客户的标签画像列表
* @return A / B / C
*/
public
String
calcCustomerClass
(
List
<
CustomerProfileRespDTO
>
profileList
)
{
if
(
CollectionUtils
.
isEmpty
(
profileList
))
{
return
CommonConstants
.
CLASS_C
;
}
// 规则0: 只有产品标签、无行为标签 → 直接A类 (有订单无录音)
boolean
hasProduct
=
profileList
.
stream
()
.
anyMatch
(
p
->
CommonConstants
.
TAG_CATEGORY_BEHAVIOR
.
equals
(
p
.
getCategoryCode
()));
boolean
hasBehavior
=
profileList
.
stream
()
.
anyMatch
(
p
->
CommonConstants
.
TAG_CATEGORY_PRODUCT
.
equals
(
p
.
getCategoryCode
()));
if
(
hasProduct
&&
!
hasBehavior
)
{
return
CommonConstants
.
CLASS_A
;
}
// 规则1: 按客户总分判定
int
totalScore
=
profileList
.
stream
()
.
mapToInt
(
p
->
p
.
getScore
()
!=
null
?
p
.
getScore
()
:
0
)
.
sum
();
if
(
totalScore
>
70
)
return
CommonConstants
.
CLASS_A
;
if
(
totalScore
>=
50
)
return
CommonConstants
.
CLASS_B
;
return
CommonConstants
.
CLASS_C
;
}
/**
* 执行客户标签画像全量同步
*
...
...
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