积分计算(pointgrowth)
一、数据库表
SqlServer
MemberData.dbo.mem_point_growth_rule
- 记录微信用户的成长值积分等基本信息(219.127.77.96:1433;databaseName=MALL)
字段名 |
# |
Type |
Length |
非空 |
Identity |
缺省 |
Description |
id |
1 |
varchar |
255 |
true |
false |
NULL |
id |
crt_date |
2 |
datetime2 |
8 |
7 |
27 |
false |
false |
crt_user |
3 |
varchar |
255 |
false |
false |
NULL |
创建人 |
last_update |
4 |
datetime2 |
8 |
7 |
27 |
false |
false |
action |
5 |
varchar |
255 |
false |
false |
NULL |
行为 |
growth_rule |
6 |
varchar |
255 |
false |
false |
NULL |
成长值规则 |
point_rule |
7 |
varchar |
255 |
false |
false |
NULL |
积分值规则 |
running |
8 |
int |
4 |
NULL |
10 |
false |
false |
table_name |
9 |
varchar |
255 |
false |
false |
NULL |
表名 |
terminal_code |
10 |
varchar |
255 |
false |
false |
NULL |
终端编号 |
terminal_name |
11 |
varchar |
255 |
false |
false |
NULL |
终端名称 |
time_task_clock |
12 |
int |
4 |
NULL |
10 |
false |
false |
time_task_cycle |
13 |
varchar |
255 |
false |
false |
NULL |
执行周期 |
using_growth_rule |
14 |
int |
4 |
NULL |
10 |
false |
false |
using_point_rule |
15 |
int |
4 |
NULL |
10 |
false |
false |
MemberData.dbo.mem_weixin_user_info
- 记录微信用户的成长值积分等基本信息(219.127.77.96:1433;databaseName=MemberData)
字段名 |
# |
Type |
Length |
非空 |
Identity |
缺省 |
Description |
id |
1 |
varchar |
255 |
true |
false |
NULL |
id |
city |
2 |
varchar |
255 |
false |
false |
NULL |
市 |
country |
3 |
varchar |
255 |
false |
false |
NULL |
国家 |
groupid |
4 |
int |
4 |
false |
false |
NULL |
公众号分组 |
headimgurl |
5 |
varchar |
255 |
false |
false |
NULL |
头像url |
language |
6 |
varchar |
255 |
false |
false |
NULL |
语言 |
nickname |
7 |
varchar |
255 |
false |
false |
NULL |
昵称 |
openid |
8 |
varchar |
255 |
false |
false |
NULL |
openid |
province |
9 |
varchar |
255 |
false |
false |
NULL |
省 |
qr_scene |
10 |
int |
4 |
NULL |
10 |
false |
false |
qr_scene_str |
11 |
varchar |
255 |
false |
false |
NULL |
二维码 |
remark |
12 |
varchar |
255 |
false |
false |
NULL |
备注 |
secret_phone |
13 |
varchar |
255 |
false |
false |
NULL |
加密手机号 |
sex |
14 |
int |
4 |
NULL |
10 |
false |
false |
subscribe |
15 |
int |
4 |
NULL |
10 |
false |
false |
subscribe_scene |
16 |
varchar |
255 |
false |
false |
NULL |
订阅场景 |
subscribe_time |
17 |
int |
4 |
NULL |
10 |
false |
false |
tagid_list |
18 |
varchar |
255 |
false |
false |
NULL |
标签列表 |
unionid |
19 |
varchar |
255 |
false |
false |
NULL |
唯一标识 |
unsubscribe_time |
20 |
int |
4 |
NULL |
10 |
false |
false |
growth |
21 |
int |
4 |
NULL |
10 |
false |
false |
growth_update_date |
22 |
datetime2 |
8 |
7 |
27 |
false |
false |
point |
23 |
int |
4 |
NULL |
10 |
false |
false |
point_update_date |
24 |
datetime2 |
8 |
7 |
27 |
false |
false |
consignee |
25 |
varchar |
255 |
false |
false |
NULL |
收件人 |
version |
27 |
bigint |
8 |
NULL |
19 |
false |
false |
secret_phone1 |
28 |
varchar |
100 |
false |
false |
NULL |
加密手机号1 |
MemberData.dbo.mem_user_calculation_log
- 记录已计算过积分的订单(219.128.77.86:4133;databaseName=Mall)
字段名 |
# |
Type |
Length |
非空 |
Identity |
缺省 |
Description |
id |
1 |
varchar |
20 |
false |
false |
NULL |
id |
OrdersCode |
2 |
varchar |
50 |
false |
false |
NULL |
订单编号 |
crt_date |
3 |
datetime |
8 |
false |
false |
NULL |
订单创建时间 |
last_update |
4 |
datetime |
8 |
false |
false |
NULL |
订单最后修改时间 |
ElasticSearch
elasticsearch节点基本信息
node |
ip地址 |
端口 |
账号 |
密码 |
es-node-1 |
192.168.50.32 |
9300 |
|
|
es-node-2 |
192.168.50.41 |
9300 |
|
|
es-node-4 |
192.168.50.39 |
9300 |
|
|
es-node-5 |
192.168.50.41 |
9301 |
|
|
mem_user_point_log
字段 |
类型 |
描述 |
字段 |
类型 |
描述 |
id |
keyword |
id |
origin |
date |
|
crtDate |
date |
创建时间 |
payment |
keyword |
加密手机号 |
lastUpdate |
date |
最后修改时间 |
remark |
keyword |
加密手机号1 |
action |
keyword |
行为 |
secretPhone |
text |
终端行为 |
balance |
integer |
积分值 |
terminalAction |
integer |
终端编号 |
dataCode |
keyword |
订单编号 |
terminalCode |
text |
终端名称 |
discountedPrice |
integer |
优惠价 |
terminalName |
integer |
增加或减少的积分值 |
increase |
boolean |
是否增加 |
transportCost |
keyword |
备注 |
orderAmount |
integer |
订单金额 |
value |
keyword |
备注 |
secretPhone1 |
keyword |
加密手机号1 |
|
|
|
mem_user_growth_log
字段 |
类型 |
描述 |
字段 |
类型 |
描述 |
id |
keyword |
id |
origin |
integer |
原积分 |
crtDate |
date |
创建时间 |
remark |
keyword |
备注 |
lastUpdate |
date |
最后修改时间 |
secretPhone |
keyword |
加密手机号 |
action |
keyword |
行为 |
terminalAction |
text |
终端行为 |
balance |
integer |
当前积分 |
terminalCode |
integer |
终端编号 |
dataCode |
keyword |
订单编号 |
terminalName |
text |
终端名称 |
increase |
boolean |
是否增加 |
value |
integer |
增加或减少的积分值 |
secretPhone1 |
keyword |
加密手机号1 |
|
|
|
二、积分成长值计算
程序流程
start=>start: 程序开始执行
end=>end: 定时任务结束
readRule=>operation: 定时读取规则
op2=>operation: Stuff|current
isRunning=>condition: running是否为1
createTask=>operation: 创建定时任务
runTask=>operation: 运行定时任务
isExist=>condition: 平台任务是否存在
isExist1=>condition: 平台任务是否存在
deleteTask=>operation: 删除任务池中平台对应的任务
start->readRule->isRunning
isRunning(yes, right)->isExist1
isRunning(no, left)->isExist
isExist(yes)->deleteTask(left)->readRule
isExist(no)->readRule(left)
isExist1(yes)->runTask
isExist1(no)->createTask->runTask->end
数据流
graph TD
start[开始] --> sp1[程序执行]
sp1 --> sp2[sqlserverMaster mem_point_growth_rule表]
sp1 --> sp3[sqlserverSlave Orders mem_user_calculation_log表]
sp2 --> sp4[计算程序]
sp3 --> sp4[计算程序]
sp4 --> sp5[kafka队列]
sp4 --> sp7[sqlserverMaster mem_weixin_user_info表]
sp4 --> sp8[sqlserverSlave mem_user_calculation_log表]
sp5 --> sp6[elasticsearh mem_user_point_log表]
sp5 --> sp10[elasticsearh mem_user_growth_log表]
程序代码
类功能描述
位置 |
类名 |
描述 |
com.lj.pointgrowth.algorithm |
Snowflake |
雪花算法生成唯一ID(弃用) |
|
SnowflakeIdWorker |
雪花算法生成唯一ID |
com.lj.pointgrowth.config |
MybatisPlusConfig |
MybatisPlus开启乐观锁配置 |
KafkaConsumerConfig |
Kafka消费者配置,设置成批量消费 |
|
KafkaListeners |
kafka监听器,控制消费者消费数据 |
|
KafkaProducerConfig |
Kafka生产者者配置,设置成批量发送 |
|
KafkaSender |
kafaka生产者 |
|
com.lj.pointgrowth.pojo |
Orders |
订单实体类 |
|
PointGrowthRule |
积分成长值规则实体类 |
|
UserCalculationLog |
已计算用户实体类 |
|
UserGrowthLog |
用户成长值实体类 |
|
UserPointLog |
用户积分实体类 |
|
WeixinUserInfo |
微信用户实体类 |
com.lj.pointgrowth.mapper |
OrdersMapper |
Orders持久类 |
|
PointGrowthRuleMapper |
PointGrowthRule持久类 |
|
UserCalculationLogMapper |
UserCalculationLog持久类 |
|
WeixinUserInfoMapper |
WeixinUserInfo持久类 |
com.lj.pointgrowth.quaetz |
JobFactory |
JobFactory用于创建定时任务实例 |
|
QuartzConfigration |
定义quartz调度工厂 |
|
QuartzManager |
定时任务控制器,负责定时任务增删改查 |
|
ScheduleRefreshDatabase |
读取数据库信息,创建定时任务 |
com.lj.pointgrowth.repository |
UserGrowthLogRepository |
UserGrowthLog Es持久类 |
|
UserPointLogRepository |
UserPointLog Es持久类 |
com.lj.pointgrowth.schedule |
ScheduledJob |
定时任务实体类 |
|
ScheduleJobInfo |
定时任务信息类 |
com.lj.pointgrowth.service.impl |
OrdersServiceImpl |
Orders业务类 |
|
PointGrowthCalculateServiceImpl |
积分成长值计算业务类(核心) |
|
PointGrowthRuleServiceImpl |
积分成长规则业务类 |
|
UserCalculationLogServiceImpl |
UserCalculationLog业务类 |
|
UserGrowthLogServiceImpl |
UserGrowthLog业务类 |
|
UserPointLogServiceImpl |
UserPointLog业务类 |
|
WeixinUserInfoServiceImpl |
WeixinUserInfo业务类 |
com.lj.pointgrowth.utils |
DateUtils |
日期相关工具类 |
|
SqlUtils |
sql相关工具类 |
com.lj.pointgrowth.vo |
OrdersVo |
orders vo对象 |
com.lj.pointgrowth |
PointgrowthApplication |
主启动类 |
sparingboot mybatisplus动态数据源配置
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>2.4.1</version>
</dependency>
spring:
datasource:
#动态数据源配置
hikari:
minimum-idle: 4
maximum-pool-size: 16
connection-timeout: 10000
idle-timeout: 30000
connection-init-sql: set names utf8mb4
dynamic:
#主数据源
primary: master
datasource:
#数据源a01
master:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://219.128.77.96:1433;databaseName=MemberData;
username: *******
password: *******
#数据源a02
slave_1:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://219.128.77.86:1433;databaseName=Mall;
username: *******
password: *******
#mybatis-plush配置
mybatis-plus:
#别名包
type-aliases-package: com.lj.pointgrowth.pojo
#引入映射文件
mapper-locations: classpath:/static/mybatis/mappers/*.xml
#开启驼峰映射
configuration:
map-underscore-to-camel-case: false
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
springboot与kafka整合
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
spring:
kafka:
listener:
missing-topics-fatal: false
bootstrap-servers: 139.159.192.185:9092
# bootstrap-servers: 192.168.198.129:9092,192.168.198.130:9092,192.168.198.131:9092
producer:
bootstrap-servers: 139.159.192.185:9092
acks: 1
# 重试次数
retries: 3
linger-ms: 10
# 批量发送的消息数量
batch-size: 16384
# 32MB的批处理缓冲区
buffer-memory: 33554432
# 默认主题
defaultTopic: math
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
properties:
sasl.mechanism: PLAIN
security.protocol: SASL_PLAINTEXT
sasl.jaas.config: org.apache.kafka.common.security.plain.PlainLoginModule required username="mooc" password="360lj2019!@#";
consumer:
bootstrap-servers: 139.159.192.185:9092
#消费监听器容器并发数
concurrency: 3
group-id: test
# 最早未被消费的offset
auto-offset-reset: earliest
# 批量一次最大拉取数据量
max-poll-records: 300
# 自动提交
enable-auto-commit: false
#如何设置为自动提交(enable.auto.commit=true),这里设置自动提交周期
auto-commit-interval: 1000
session-timeout-ms: 30000
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
properties:
sasl.mechanism: PLAIN
security.protocol: SASL_PLAINTEXT
sasl.jaas.config: org.apache.kafka.common.security.plain.PlainLoginModule required username="mooc" password="360lj2019!@#";
sparingboot整合elasticsearch
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
spring:
elasticsearch:
rest:
uris: http://192.168.50.41:9200
项目打包部署
添加打包插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
mvn打包及部署
服务器端口:192.168.50.41:8091
目录 192.168.50.41/usr/local/src/pointgrowth
mvn clean package -Dmaven.test.skip=true
nohup java -jar pointgrowth-0.0.1-SNAPSHOT.jar > log.file 2>&1 &
备注
作者:hsw
时间:2020-03-24
邮箱:13422048613@163.com